Exemplo n.º 1
0
Arquivo: fib.c Projeto: JiapengLi/RIOT
/**
 * @brief creates a new FIB entry with the provided parameters
 *
 * @param[in] iface_id       the interface ID
 * @param[in] dst            the destination address
 * @param[in] dst_size       the destination address size
 * @param[in] dst_flags      the destination address flags
 * @param[in] next_hop       the next hop address
 * @param[in] next_hop_size  the next hop address size
 * @param[in] next_hop_flags the next-hop address flags
 * @param[in] lifetime       the lifetime in ms
 *
 * @return 0 on success
 *         -ENOMEM if no new entry can be created
 */
static int fib_create_entry(kernel_pid_t iface_id,
                            uint8_t *dst, size_t dst_size, uint32_t dst_flags,
                            uint8_t *next_hop, size_t next_hop_size, uint32_t next_hop_flags,
                            uint32_t lifetime)
{
    for (size_t i = 0; i < FIB_MAX_FIB_TABLE_ENTRIES; ++i) {
        if (fib_table[i].lifetime.seconds == 0 && fib_table[i].lifetime.microseconds == 0) {

            fib_table[i].global = universal_address_add(dst, dst_size);

            if (fib_table[i].global != NULL) {
                fib_table[i].global_flags = dst_flags;
                fib_table[i].next_hop = universal_address_add(next_hop, next_hop_size);
                fib_table[i].next_hop_flags = next_hop_flags;
            }

            if (fib_table[i].next_hop != NULL) {
                /* everything worked fine */
                fib_table[i].iface_id = iface_id;

                if (lifetime < FIB_LIFETIME_NO_EXPIRE) {
                    fib_ms_to_timex(lifetime, &fib_table[i].lifetime);
                }
                else {
                    fib_table[i].lifetime.seconds = FIB_LIFETIME_NO_EXPIRE;
                    fib_table[i].lifetime.microseconds = FIB_LIFETIME_NO_EXPIRE;
                }

                return 0;
            }
        }
    }

    return -ENOMEM;
}
Exemplo n.º 2
0
Arquivo: fib.c Projeto: daniel-k/RIOT
/**
 * @brief creates a new FIB entry with the provided parameters
 *
 * @param[in] table          the FIB table to create the entry in
 * @param[in] iface_id       the interface ID
 * @param[in] dst            the destination address
 * @param[in] dst_size       the destination address size
 * @param[in] dst_flags      the destination address flags
 * @param[in] next_hop       the next hop address
 * @param[in] next_hop_size  the next hop address size
 * @param[in] next_hop_flags the next-hop address flags
 * @param[in] lifetime       the lifetime in ms
 *
 * @return 0 on success
 *         -ENOMEM if no new entry can be created
 */
static int fib_create_entry(fib_table_t *table, kernel_pid_t iface_id,
                            uint8_t *dst, size_t dst_size, uint32_t dst_flags,
                            uint8_t *next_hop, size_t next_hop_size, uint32_t
                            next_hop_flags, uint32_t lifetime)
{
    for (size_t i = 0; i < table->size; ++i) {
        if (table->entries[i].lifetime == 0) {

            table->entries[i].global = universal_address_add(dst, dst_size);

            if (table->entries[i].global != NULL) {
                table->entries[i].global_flags = dst_flags;
                table->entries[i].next_hop = universal_address_add(next_hop, next_hop_size);
                table->entries[i].next_hop_flags = next_hop_flags;
            }

            if (table->entries[i].next_hop != NULL) {
                /* everything worked fine */
                table->entries[i].iface_id = iface_id;

                if (lifetime != (uint32_t) FIB_LIFETIME_NO_EXPIRE) {
                    fib_lifetime_to_absolute(lifetime, &table->entries[i].lifetime);
                }
                else {
                    table->entries[i].lifetime = FIB_LIFETIME_NO_EXPIRE;
                }

                return 0;
            }
        }
    }

    return -ENOMEM;
}
Exemplo n.º 3
0
Arquivo: fib.c Projeto: daniel-k/RIOT
/**
 * @brief updates the next hop the lifetime and the interface id for a given entry
 *
 * @param[in] entry          the entry to be updated
 * @param[in] next_hop       the next hop address to be updated
 * @param[in] next_hop_size  the next hop address size
 * @param[in] next_hop_flags the next-hop address flags
 * @param[in] lifetime       the lifetime in ms
 *
 * @return 0 if the entry has been updated
 *         -ENOMEM if the entry cannot be updated due to insufficient RAM
 */
static int fib_upd_entry(fib_entry_t *entry, uint8_t *next_hop,
                         size_t next_hop_size, uint32_t next_hop_flags,
                         uint32_t lifetime)
{
    universal_address_container_t *container = universal_address_add(next_hop, next_hop_size);

    if (container == NULL) {
        return -ENOMEM;
    }

    universal_address_rem(entry->next_hop);
    entry->next_hop = container;
    entry->next_hop_flags = next_hop_flags;

    if (lifetime != (uint32_t)FIB_LIFETIME_NO_EXPIRE) {
        fib_lifetime_to_absolute(lifetime, &entry->lifetime);
    }
    else {
        entry->lifetime = FIB_LIFETIME_NO_EXPIRE;
    }

    return 0;
}
Exemplo n.º 4
0
Arquivo: fib.c Projeto: robby14/RIOT
int fib_register_rp(uint8_t *prefix, size_t prefix_addr_type_size)
{
    mutex_lock(&mtx_access);

    if (notify_rp_pos >= FIB_MAX_REGISTERED_RP) {
        mutex_unlock(&mtx_access);
        return -ENOMEM;
    }

    if ((prefix == NULL) || (prefix_addr_type_size == 0)) {
        mutex_unlock(&mtx_access);
        return -EINVAL;
    }

    if (notify_rp_pos < FIB_MAX_REGISTERED_RP) {
        notify_rp[notify_rp_pos] = sched_active_pid;
        universal_address_container_t *container = universal_address_add(prefix, prefix_addr_type_size);
        prefix_rp[notify_rp_pos] = container;
        notify_rp_pos++;
    }

    mutex_unlock(&mtx_access);
    return 0;
}