From 725420f86e8e29527b4643ab913898186e6b0b24 Mon Sep 17 00:00:00 2001 From: Oleg Hahm Date: Wed, 12 Aug 2015 19:04:43 +0200 Subject: [PATCH] WIP: multiple instances of FIB --- sys/auto_init/auto_init.c | 8 - sys/include/net/fib.h | 29 +-- sys/include/net/ng_ipv6.h | 8 + sys/net/network_layer/fib/fib.c | 171 +++++++++--------- sys/net/network_layer/ng_ipv6/ng_ipv6.c | 16 ++ sys/net/network_layer/ng_ndp/ng_ndp.c | 6 +- .../network_layer/ng_ndp/node/ng_ndp_node.c | 6 +- sys/shell/commands/sc_fib.c | 11 +- 8 files changed, 140 insertions(+), 115 deletions(-) diff --git a/sys/auto_init/auto_init.c b/sys/auto_init/auto_init.c index 1186180b51154..7f9ff604254e5 100644 --- a/sys/auto_init/auto_init.c +++ b/sys/auto_init/auto_init.c @@ -85,10 +85,6 @@ #include "dev_eth_autoinit.h" #endif -#ifdef MODULE_FIB -#include "net/fib.h" -#endif - #define ENABLE_DEBUG (0) #include "debug.h" @@ -153,10 +149,6 @@ void auto_init(void) DEBUG("Auto init UDP module.\n"); ng_udp_init(); #endif -#ifdef MODULE_FIB - DEBUG("Auto init FIB module.\n"); - fib_init(); -#endif /* initialize network devices */ diff --git a/sys/include/net/fib.h b/sys/include/net/fib.h index 4e2ed4a9d4196..bebcb1060fe9d 100644 --- a/sys/include/net/fib.h +++ b/sys/include/net/fib.h @@ -22,6 +22,7 @@ #ifndef FIB_H_ #define FIB_H_ +#include "net/fib/table.h" #include "kernel_types.h" #include "timex.h" @@ -29,6 +30,11 @@ extern "C" { #endif +/** + * @brief maximum number of FIB tables entries handled + */ +#define FIB_MAX_FIB_TABLE_ENTRIES (20) + /** * @brief Routing Protocol (RP) message content to request/reply notification */ @@ -62,12 +68,12 @@ typedef struct fib_destination_set_entry_t { /** * @brief initializes all FIB entries with 0 */ -void fib_init(void); +void fib_init(fib_entry_t table[]); /** * @brief de-initializes the FIB entries */ -void fib_deinit(void); +void fib_deinit(fib_entry_t table[]); /** * @brief Registration of a routing protocol handler function @@ -98,8 +104,9 @@ int fib_register_rp(uint8_t *prefix, size_t prefix_addr_type_size); * -ENOMEM if the entry cannot be created due to insufficient RAM * -EFAULT if dst and/or next_hop is not a valid pointer */ -int fib_add_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, +int fib_add_entry(fib_entry_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); /** @@ -116,7 +123,7 @@ int fib_add_entry(kernel_pid_t iface_id, uint8_t *dst, size_t dst_size, uint32_t * -ENOMEM if the entry cannot be updated due to insufficient RAM * -EFAULT if dst and/or next_hop is not a valid pointer */ -int fib_update_entry(uint8_t *dst, size_t dst_size, +int fib_update_entry(fib_entry_t table[], uint8_t *dst, size_t dst_size, uint8_t *next_hop, size_t next_hop_size, uint32_t next_hop_flags, uint32_t lifetime); @@ -126,7 +133,7 @@ int fib_update_entry(uint8_t *dst, size_t dst_size, * @param[in] dst the destination address * @param[in] dst_size the destination address size */ -void fib_remove_entry(uint8_t *dst, size_t dst_size); +void fib_remove_entry(fib_entry_t table[], uint8_t *dst, size_t dst_size); /** * @brief provides a next hop for a given destination @@ -147,7 +154,7 @@ void fib_remove_entry(uint8_t *dst, size_t dst_size); * -EFAULT if dst and/or next_hop is not a valid pointer * -EINVAL if one of the other passed out pointers is NULL */ -int fib_get_next_hop(kernel_pid_t *iface_id, +int fib_get_next_hop(fib_entry_t table[], kernel_pid_t *iface_id, uint8_t *next_hop, size_t *next_hop_size, uint32_t* next_hop_flags, uint8_t *dst, size_t dst_size, uint32_t dst_flags); @@ -169,14 +176,14 @@ int fib_get_next_hop(kernel_pid_t *iface_id, * The actual needed size is stored then in dst_set_size, * however the required size may change in between calls. */ -int fib_get_destination_set(uint8_t *prefix, size_t prefix_size, +int fib_get_destination_set(fib_entry_t table[], uint8_t *prefix, size_t prefix_size, fib_destination_set_entry_t *dst_set, size_t* dst_set_size); /** * @brief returns the actual number of used FIB entries */ -int fib_get_num_used_entries(void); +int fib_get_num_used_entries(fib_entry_t table[]); /** * @brief Prints the kernel_pid_t for all registered RRPs @@ -186,12 +193,12 @@ void fib_print_notify_rrp(void); /** * @brief Prints the FIB content (does not print the entries) */ -void fib_print_fib_table(void); +void fib_print_fib_table(fib_entry_t table[]); /** * @brief Prints the FIB content */ -void fib_print_routes(void); +void fib_print_routes(fib_entry_t table[]); #if FIB_DEVEL_HELPER /** diff --git a/sys/include/net/ng_ipv6.h b/sys/include/net/ng_ipv6.h index 990be25e37cc9..d1c78064d2c78 100644 --- a/sys/include/net/ng_ipv6.h +++ b/sys/include/net/ng_ipv6.h @@ -38,6 +38,10 @@ #include "net/ng_ipv6/nc.h" #include "net/ng_ipv6/netif.h" +#ifdef MODULE_FIB +#include "net/fib.h" +#endif + #ifdef __cplusplus extern "C" { #endif @@ -73,6 +77,10 @@ extern "C" { */ extern kernel_pid_t ng_ipv6_pid; +extern fib_entry_t ng_ipv6_fib_table[FIB_MAX_FIB_TABLE_ENTRIES]; + +extern fib_entry_t ng_ipv6_dest_cache[FIB_MAX_FIB_TABLE_ENTRIES]; + /** * @brief Initialization of the IPv6 thread. * diff --git a/sys/net/network_layer/fib/fib.c b/sys/net/network_layer/fib/fib.c index 951f824eee7be..642139f10f24f 100644 --- a/sys/net/network_layer/fib/fib.c +++ b/sys/net/network_layer/fib/fib.c @@ -77,15 +77,11 @@ static kernel_pid_t notify_rp[FIB_MAX_REGISTERED_RP]; */ static universal_address_container_t* prefix_rp[FIB_MAX_REGISTERED_RP]; -/** - * @brief maximum number of FIB tables entries handled - */ -#define FIB_MAX_FIB_TABLE_ENTRIES (20) /** * @brief array of the FIB tables */ -static fib_entry_t fib_table[FIB_MAX_FIB_TABLE_ENTRIES]; +//static fib_entry_t fib_table[FIB_MAX_FIB_TABLE_ENTRIES]; /** * @brief convert given ms to a point in time from now on in the future @@ -112,7 +108,7 @@ static void fib_ms_to_timex(uint32_t ms, timex_t *timex) * 1 if we found the exact address next-hop * -EHOSTUNREACH if no fitting next-hop is available */ -static int fib_find_entry(uint8_t *dst, size_t dst_size, +static int fib_find_entry(fib_entry_t table[], uint8_t *dst, size_t dst_size, fib_entry_t **entry_arr, size_t *entry_arr_size) { timex_t now; @@ -134,36 +130,36 @@ static int fib_find_entry(uint8_t *dst, size_t dst_size, for (size_t i = 0; i < FIB_MAX_FIB_TABLE_ENTRIES; ++i) { /* autoinvalidate if the entry lifetime is not set to not expire */ - if ((fib_table[i].lifetime.seconds != FIB_LIFETIME_NO_EXPIRE) - || (fib_table[i].lifetime.microseconds != FIB_LIFETIME_NO_EXPIRE)) { + if ((table[i].lifetime.seconds != FIB_LIFETIME_NO_EXPIRE) + || (table[i].lifetime.microseconds != FIB_LIFETIME_NO_EXPIRE)) { /* check if the lifetime expired */ - if (timex_cmp(now, fib_table[i].lifetime) > -1) { + if (timex_cmp(now, table[i].lifetime) > -1) { /* remove this entry if its lifetime expired */ - fib_table[i].lifetime.seconds = 0; - fib_table[i].lifetime.microseconds = 0; - fib_table[i].global_flags = 0; - fib_table[i].next_hop_flags = 0; - fib_table[i].iface_id = KERNEL_PID_UNDEF; - - if (fib_table[i].global != NULL) { - universal_address_rem(fib_table[i].global); - fib_table[i].global = NULL; + table[i].lifetime.seconds = 0; + table[i].lifetime.microseconds = 0; + table[i].global_flags = 0; + table[i].next_hop_flags = 0; + table[i].iface_id = KERNEL_PID_UNDEF; + + if (table[i].global != NULL) { + universal_address_rem(table[i].global); + table[i].global = NULL; } - if (fib_table[i].next_hop != NULL) { - universal_address_rem(fib_table[i].next_hop); - fib_table[i].next_hop = NULL; + if (table[i].next_hop != NULL) { + universal_address_rem(table[i].next_hop); + table[i].next_hop = NULL; } } } - if ((prefix_size < (dst_size<<3)) && (fib_table[i].global != NULL)) { + if ((prefix_size < (dst_size<<3)) && (table[i].global != NULL)) { - int ret_comp = universal_address_compare(fib_table[i].global, dst, &match_size); + int ret_comp = universal_address_compare(table[i].global, dst, &match_size); /* If we found an exact match */ if (ret_comp == 0 || (is_all_zeros_addr && match_size == 0)) { - entry_arr[0] = &(fib_table[i]); + entry_arr[0] = &(table[i]); *entry_arr_size = 1; /* we will not find a better one so we return */ return 1; @@ -171,7 +167,7 @@ static int fib_find_entry(uint8_t *dst, size_t dst_size, else { /* we try to find the most fitting prefix */ if (ret_comp == 1) { - entry_arr[0] = &(fib_table[i]); + entry_arr[0] = &(table[i]); /* we could find a better one so we move on */ ret = 0; @@ -239,32 +235,32 @@ static int fib_upd_entry(fib_entry_t *entry, * @return 0 on success * -ENOMEM if no new entry can be created */ -static int fib_create_entry(kernel_pid_t iface_id, +static int fib_create_entry(fib_entry_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 < FIB_MAX_FIB_TABLE_ENTRIES; ++i) { - if (fib_table[i].lifetime.seconds == 0 && fib_table[i].lifetime.microseconds == 0) { + if (table[i].lifetime.seconds == 0 && table[i].lifetime.microseconds == 0) { - fib_table[i].global = universal_address_add(dst, dst_size); + 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 (table[i].global != NULL) { + table[i].global_flags = dst_flags; + table[i].next_hop = universal_address_add(next_hop, next_hop_size); + table[i].next_hop_flags = next_hop_flags; } - if (fib_table[i].next_hop != NULL) { + if (table[i].next_hop != NULL) { /* everything worked fine */ - fib_table[i].iface_id = iface_id; + table[i].iface_id = iface_id; if (lifetime < FIB_LIFETIME_NO_EXPIRE) { - fib_ms_to_timex(lifetime, &fib_table[i].lifetime); + fib_ms_to_timex(lifetime, &table[i].lifetime); } else { - fib_table[i].lifetime.seconds = FIB_LIFETIME_NO_EXPIRE; - fib_table[i].lifetime.microseconds = FIB_LIFETIME_NO_EXPIRE; + table[i].lifetime.seconds = FIB_LIFETIME_NO_EXPIRE; + table[i].lifetime.microseconds = FIB_LIFETIME_NO_EXPIRE; } return 0; @@ -350,8 +346,9 @@ static int fib_signal_rp(uint8_t *dst, size_t dst_size, uint32_t dst_flags) return ret; } -int fib_add_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, +int fib_add_entry(fib_entry_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) { mutex_lock(&mtx_access); @@ -365,14 +362,14 @@ int fib_add_entry(kernel_pid_t iface_id, uint8_t *dst, size_t dst_size, uint32_t return -EFAULT; } - int ret = fib_find_entry(dst, dst_size, &(entry[0]), &count); + int ret = fib_find_entry(table, dst, dst_size, &(entry[0]), &count); if (ret == 1) { /* we must take the according entry and update the values */ ret = fib_upd_entry(entry[0], next_hop, next_hop_size, next_hop_flags, lifetime); } else { - ret = fib_create_entry(iface_id, dst, dst_size, dst_flags, + ret = fib_create_entry(table, iface_id, dst, dst_size, dst_flags, next_hop, next_hop_size, next_hop_flags, lifetime); } @@ -380,7 +377,7 @@ int fib_add_entry(kernel_pid_t iface_id, uint8_t *dst, size_t dst_size, uint32_t return ret; } -int fib_update_entry(uint8_t *dst, size_t dst_size, +int fib_update_entry(fib_entry_t table[], uint8_t *dst, size_t dst_size, uint8_t *next_hop, size_t next_hop_size, uint32_t next_hop_flags, uint32_t lifetime) { @@ -396,7 +393,7 @@ int fib_update_entry(uint8_t *dst, size_t dst_size, return -EFAULT; } - if (fib_find_entry(dst, dst_size, &(entry[0]), &count) == 1) { + if (fib_find_entry(table, dst, dst_size, &(entry[0]), &count) == 1) { DEBUG("[fib_update_entry] found entry: %p\n", (void *)(entry[0])); /* we must take the according entry and update the values */ ret = fib_upd_entry(entry[0], next_hop, next_hop_size, next_hop_flags, lifetime); @@ -412,14 +409,14 @@ int fib_update_entry(uint8_t *dst, size_t dst_size, return ret; } -void fib_remove_entry(uint8_t *dst, size_t dst_size) +void fib_remove_entry(fib_entry_t table[], uint8_t *dst, size_t dst_size) { mutex_lock(&mtx_access); DEBUG("[fib_remove_entry]\n"); size_t count = 1; fib_entry_t *entry[count]; - int ret = fib_find_entry(dst, dst_size, &(entry[0]), &count); + int ret = fib_find_entry(table, dst, dst_size, &(entry[0]), &count); if (ret == 1) { /* we must take the according entry and update the values */ @@ -435,7 +432,7 @@ void fib_remove_entry(uint8_t *dst, size_t dst_size) mutex_unlock(&mtx_access); } -int fib_get_next_hop(kernel_pid_t *iface_id, +int fib_get_next_hop(fib_entry_t table[], kernel_pid_t *iface_id, uint8_t *next_hop, size_t *next_hop_size, uint32_t *next_hop_flags, uint8_t *dst, size_t dst_size, uint32_t dst_flags) { @@ -456,13 +453,13 @@ int fib_get_next_hop(kernel_pid_t *iface_id, return -EFAULT; } - int ret = fib_find_entry(dst, dst_size, &(entry[0]), &count); + int ret = fib_find_entry(table, dst, dst_size, &(entry[0]), &count); if (!(ret == 0 || ret == 1)) { /* notify all responsible RPs for unknown next-hop for the destination address */ if (fib_signal_rp(dst, dst_size, dst_flags) == 0) { count = 1; /* now lets see if the RRPs have found a valid next-hop */ - ret = fib_find_entry(dst, dst_size, &(entry[0]), &count); + ret = fib_find_entry(table, dst, dst_size, &(entry[0]), &count); } } @@ -487,7 +484,7 @@ int fib_get_next_hop(kernel_pid_t *iface_id, return 0; } -int fib_get_destination_set(uint8_t *prefix, size_t prefix_size, +int fib_get_destination_set(fib_entry_t table[], uint8_t *prefix, size_t prefix_size, fib_destination_set_entry_t *dst_set, size_t* dst_set_size) { mutex_lock(&mtx_access); @@ -495,12 +492,12 @@ int fib_get_destination_set(uint8_t *prefix, size_t prefix_size, size_t found_entries = 0; for (size_t i = 0; i < FIB_MAX_FIB_TABLE_ENTRIES; ++i) { - if ((fib_table[i].global != NULL) && - (universal_address_compare_prefix(fib_table[i].global, prefix, prefix_size<<3) >= 0)) { + if ((table[i].global != NULL) && + (universal_address_compare_prefix(table[i].global, prefix, prefix_size<<3) >= 0)) { if( (dst_set != NULL) && (found_entries < *dst_set_size) ) { /* set the size to full byte usage */ dst_set[found_entries].dest_size = sizeof(dst_set[found_entries].dest); - universal_address_get_address(fib_table[i].global, + universal_address_get_address(table[i].global, dst_set[found_entries].dest, &dst_set[found_entries].dest_size); } @@ -521,7 +518,7 @@ int fib_get_destination_set(uint8_t *prefix, size_t prefix_size, return ret; } -void fib_init(void) +void fib_init(fib_entry_t table[]) { DEBUG("[fib_init] hello. Initializing some stuff.\n"); mutex_lock(&mtx_access); @@ -532,20 +529,20 @@ void fib_init(void) } for (size_t i = 0; i < FIB_MAX_FIB_TABLE_ENTRIES; ++i) { - fib_table[i].iface_id = 0; - fib_table[i].lifetime.seconds = 0; - fib_table[i].lifetime.microseconds = 0; - fib_table[i].global_flags = 0; - fib_table[i].global = NULL; - fib_table[i].next_hop_flags = 0; - fib_table[i].next_hop = NULL; + table[i].iface_id = 0; + table[i].lifetime.seconds = 0; + table[i].lifetime.microseconds = 0; + table[i].global_flags = 0; + table[i].global = NULL; + table[i].next_hop_flags = 0; + table[i].next_hop = NULL; } universal_address_init(); mutex_unlock(&mtx_access); } -void fib_deinit(void) +void fib_deinit(fib_entry_t table[]) { DEBUG("[fib_deinit] hello. De-Initializing stuff.\n"); mutex_lock(&mtx_access); @@ -558,13 +555,13 @@ void fib_deinit(void) notify_rp_pos = 0; for (size_t i = 0; i < FIB_MAX_FIB_TABLE_ENTRIES; ++i) { - fib_table[i].iface_id = 0; - fib_table[i].lifetime.seconds = 0; - fib_table[i].lifetime.microseconds = 0; - fib_table[i].global_flags = 0; - fib_table[i].global = NULL; - fib_table[i].next_hop_flags = 0; - fib_table[i].next_hop = NULL; + table[i].iface_id = 0; + table[i].lifetime.seconds = 0; + table[i].lifetime.microseconds = 0; + table[i].global_flags = 0; + table[i].global = NULL; + table[i].next_hop_flags = 0; + table[i].next_hop = NULL; } universal_address_reset(); @@ -596,13 +593,13 @@ int fib_register_rp(uint8_t *prefix, size_t prefix_addr_type_size) return 0; } -int fib_get_num_used_entries(void) +int fib_get_num_used_entries(fib_entry_t table[]) { mutex_lock(&mtx_access); size_t used_entries = 0; for (size_t i = 0; i < FIB_MAX_FIB_TABLE_ENTRIES; ++i) { - used_entries += (size_t)(fib_table[i].global != NULL); + used_entries += (size_t)(table[i].global != NULL); } mutex_unlock(&mtx_access); @@ -622,18 +619,18 @@ void fib_print_notify_rp(void) mutex_unlock(&mtx_access); } -void fib_print_fib_table(void) +void fib_print_fib_table(fib_entry_t table[]) { mutex_lock(&mtx_access); for (size_t i = 0; i < FIB_MAX_FIB_TABLE_ENTRIES; ++i) { - printf("[fib_print_fib_table] %d) iface_id: %d, global: %p, next hop: %p, lifetime: %d.%d\n", \ + printf("[fib_print_table] %d) iface_id: %d, global: %p, next hop: %p, lifetime: %d.%d\n", \ (int)i, \ - (int)fib_table[i].iface_id, \ - (void *)fib_table[i].global, \ - (void *)fib_table[i].next_hop, \ - (int)fib_table[i].lifetime.seconds, \ - (int)fib_table[i].lifetime.microseconds); + (int)table[i].iface_id, \ + (void *)table[i].global, \ + (void *)table[i].next_hop, \ + (int)table[i].lifetime.seconds, \ + (int)table[i].lifetime.microseconds); } mutex_unlock(&mtx_access); @@ -670,7 +667,7 @@ static void fib_print_address(universal_address_container_t *entry) } } -void fib_print_routes(void) +void fib_print_routes(fib_entry_t table[]) { mutex_lock(&mtx_access); printf("%-" NG_FIB_ADDR_PRINT_LENS "s %-6s %-" NG_FIB_ADDR_PRINT_LENS "s %-6s %-16s Interface\n" @@ -680,16 +677,16 @@ void fib_print_routes(void) vtimer_now(&now); 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_print_address(fib_table[i].global); - printf(" 0x%04"PRIx32" ", fib_table[i].global_flags); - fib_print_address(fib_table[i].next_hop); - printf(" 0x%04"PRIx32" ", fib_table[i].next_hop_flags); + if (table[i].lifetime.seconds != 0 || table[i].lifetime.microseconds != 0) { + fib_print_address(table[i].global); + printf(" 0x%04"PRIx32" ", table[i].global_flags); + fib_print_address(table[i].next_hop); + printf(" 0x%04"PRIx32" ", table[i].next_hop_flags); - if ((fib_table[i].lifetime.seconds != FIB_LIFETIME_NO_EXPIRE) - || (fib_table[i].lifetime.microseconds != FIB_LIFETIME_NO_EXPIRE)) { + if ((table[i].lifetime.seconds != FIB_LIFETIME_NO_EXPIRE) + || (table[i].lifetime.microseconds != FIB_LIFETIME_NO_EXPIRE)) { - timex_t tm = timex_sub(fib_table[i].lifetime, now); + timex_t tm = timex_sub(table[i].lifetime, now); /* we must interpret the values as signed */ if ((int32_t)tm.seconds < 0 @@ -704,7 +701,7 @@ void fib_print_routes(void) printf("%-16s ", "NEVER"); } - printf("%d\n", (int)fib_table[i].iface_id); + printf("%d\n", (int)table[i].iface_id); } } diff --git a/sys/net/network_layer/ng_ipv6/ng_ipv6.c b/sys/net/network_layer/ng_ipv6/ng_ipv6.c index d0cd6e16ccc69..f2db140befcc1 100644 --- a/sys/net/network_layer/ng_ipv6/ng_ipv6.c +++ b/sys/net/network_layer/ng_ipv6/ng_ipv6.c @@ -41,6 +41,17 @@ static char _stack[NG_IPV6_STACK_SIZE + THREAD_EXTRA_STACKSIZE_PRINTF]; static char _stack[NG_IPV6_STACK_SIZE]; #endif +#ifdef MODULE_FIB +#include "net/fib.h" +#include "net/fib/table.h" +/** + * @brief array of the FIB tables + */ +fib_entry_t ng_ipv6_fib_table[FIB_MAX_FIB_TABLE_ENTRIES]; + +fib_entry_t ng_ipv6_dest_cache[FIB_MAX_FIB_TABLE_ENTRIES]; +#endif + #if ENABLE_DEBUG static char addr_str[IPV6_ADDR_MAX_STR_LEN]; #endif @@ -69,6 +80,11 @@ kernel_pid_t ng_ipv6_init(void) CREATE_STACKTEST, _event_loop, NULL, "ipv6"); } +#ifdef MODULE_FIB + fib_init(ng_ipv6_fib_table); + fib_init(ng_ipv6_dest_cache); +#endif + return ng_ipv6_pid; } diff --git a/sys/net/network_layer/ng_ndp/ng_ndp.c b/sys/net/network_layer/ng_ndp/ng_ndp.c index 816d35e454eb6..9979edd88d2a8 100644 --- a/sys/net/network_layer/ng_ndp/ng_ndp.c +++ b/sys/net/network_layer/ng_ndp/ng_ndp.c @@ -34,6 +34,10 @@ #include "net/ng_ndp.h" #define ENABLE_DEBUG (0) +#ifdef MODULE_FIB +#include "net/fib/table.h" +#endif + #include "debug.h" #if ENABLE_DEBUG @@ -313,7 +317,7 @@ void ng_ndp_retrans_nbr_sol(ng_ipv6_nc_t *nc_entry) nc_entry->iface); #ifdef MODULE_FIB - fib_remove_entry((uint8_t *) & (nc_entry->ipv6_addr), sizeof(ipv6_addr_t)); + fib_remove_entry(ng_ipv6_dest_cache, (uint8_t *) & (nc_entry->ipv6_addr), sizeof(ipv6_addr_t)); #endif ng_ipv6_nc_remove(nc_entry->iface, &nc_entry->ipv6_addr); } diff --git a/sys/net/network_layer/ng_ndp/node/ng_ndp_node.c b/sys/net/network_layer/ng_ndp/node/ng_ndp_node.c index 87992be8cabb6..f2dad7c1bb1ed 100644 --- a/sys/net/network_layer/ng_ndp/node/ng_ndp_node.c +++ b/sys/net/network_layer/ng_ndp/node/ng_ndp_node.c @@ -70,7 +70,7 @@ kernel_pid_t ng_ndp_node_next_hop_l2addr(uint8_t *l2addr, uint8_t *l2addr_len, ipv6_addr_t next_hop_actual; /* FIB copies address into this variable */ if ((next_hop_ip == NULL) && - (fib_get_next_hop(&iface, next_hop_actual.u8, &next_hop_size, + (fib_get_next_hop(ng_ipv6_dest_cache, &iface, next_hop_actual.u8, &next_hop_size, &next_hop_flags, (uint8_t *)dst, sizeof(ipv6_addr_t), 0) >= 0) && (next_hop_size == sizeof(ipv6_addr_t))) { @@ -96,7 +96,7 @@ kernel_pid_t ng_ndp_node_next_hop_l2addr(uint8_t *l2addr, uint8_t *l2addr_len, #ifdef MODULE_FIB /* We don't care if FIB is full, this is just for efficiency * for later sends */ - fib_add_entry(iface, (uint8_t *)dst, sizeof(ipv6_addr_t), 0, + fib_add_entry(ng_ipv6_dest_cache, iface, (uint8_t *)dst, sizeof(ipv6_addr_t), 0, (uint8_t *)next_hop_ip, sizeof(ipv6_addr_t), 0, FIB_LIFETIME_NO_EXPIRE); #endif @@ -108,7 +108,7 @@ kernel_pid_t ng_ndp_node_next_hop_l2addr(uint8_t *l2addr, uint8_t *l2addr_len, #ifdef MODULE_FIB /* We don't care if FIB is full, this is just for efficiency for later * sends */ - fib_add_entry(iface, (uint8_t *)dst, sizeof(ipv6_addr_t), 0, + fib_add_entry(ng_ipv6_dest_cache, iface, (uint8_t *)dst, sizeof(ipv6_addr_t), 0, (uint8_t *)next_hop_ip, sizeof(ipv6_addr_t), 0, FIB_LIFETIME_NO_EXPIRE); #endif diff --git a/sys/shell/commands/sc_fib.c b/sys/shell/commands/sc_fib.c index 9f36f6a970b56..c04444344038d 100644 --- a/sys/shell/commands/sc_fib.c +++ b/sys/shell/commands/sc_fib.c @@ -28,6 +28,7 @@ #include "net/ng_netif.h" #endif #include "net/fib.h" +#include "net/ng_ipv6.h" #define INFO1_TXT "fibroute add via [dev ]" #define INFO2_TXT " [lifetime ]" @@ -103,14 +104,14 @@ static void _fib_add(const char *dest, const char *next, kernel_pid_t pid, uint3 nxt_flags = AF_INET; } - fib_add_entry(pid, dst, dst_size, dst_flags, nxt, nxt_size, nxt_flags, lifetime); + fib_add_entry(ng_ipv6_fib_table, pid, dst, dst_size, dst_flags, nxt, nxt_size, nxt_flags, lifetime); } int _fib_route_handler(int argc, char **argv) { /* e.g. fibroute right now dont care about the adress/protocol family */ if (argc == 1) { - fib_print_routes(); + fib_print_routes(ng_ipv6_fib_table); return 0; } @@ -137,13 +138,13 @@ int _fib_route_handler(int argc, char **argv) /* e.g. fibroute del */ if (argc == 3) { if (inet_pton(AF_INET6, argv[2], tmp_ipv6_dst)) { - fib_remove_entry(tmp_ipv6_dst, IN6ADDRSZ); + fib_remove_entry(ng_ipv6_fib_table, tmp_ipv6_dst, IN6ADDRSZ); } else if (inet_pton(AF_INET, argv[2], tmp_ipv4_dst)) { - fib_remove_entry(tmp_ipv4_dst, INADDRSZ); + fib_remove_entry(ng_ipv6_fib_table, tmp_ipv4_dst, INADDRSZ); } else { - fib_remove_entry((uint8_t *)argv[2], (strlen(argv[2]))); + fib_remove_entry(ng_ipv6_fib_table, (uint8_t *)argv[2], (strlen(argv[2]))); } return 0;