From 7c2bff0462e088ab2f4681c31f0db5712ecf0e5e Mon Sep 17 00:00:00 2001 From: Joakim Eriksson Date: Wed, 26 Aug 2015 18:17:29 +0200 Subject: [PATCH 1/3] added debug print for nbr-table-module --- core/net/nbr-table.c | 50 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/core/net/nbr-table.c b/core/net/nbr-table.c index 4c9fab4fb..6b990a020 100644 --- a/core/net/nbr-table.c +++ b/core/net/nbr-table.c @@ -40,6 +40,18 @@ #include "lib/list.h" #include "net/nbr-table.h" +#define DEBUG 0 +#if DEBUG +#include +#include "sys/ctimer.h" +static void handle_periodic_timer(void *ptr); +static struct ctimer periodic_timer; +static uint8_t initialized = 0; +#define PRINTF(...) printf(__VA_ARGS__) +#else +#define PRINTF(...) +#endif + /* List of link-layer addresses of the neighbors, used as key in the tables */ typedef struct nbr_table_key { struct nbr_table_key *next; @@ -143,6 +155,7 @@ static int nbr_set_bit(uint8_t *bitmap, nbr_table_t *table, nbr_table_item_t *item, int value) { int item_index = index_from_item(table, item); + if(table != NULL && item_index != -1) { if(value) { bitmap[item_index] |= 1 << table->index; @@ -229,6 +242,13 @@ nbr_table_allocate(void) int nbr_table_register(nbr_table_t *table, nbr_table_callback *callback) { +#if DEBUG + if(!initialized) { + initialized = 1; + /* schedule a debug printout per minute */ + ctimer_set(&periodic_timer, CLOCK_SECOND * 60, handle_periodic_timer, NULL); + } +#endif if(num_tables < MAX_NUM_TABLES) { table->index = num_tables++; table->callback = callback; @@ -331,6 +351,10 @@ nbr_table_remove(nbr_table_t *table, void *item) int nbr_table_lock(nbr_table_t *table, void *item) { +#if DEBUG + int i = index_from_item(table, item); + PRINTF("*** Lock %d\n", i); +#endif return nbr_set_bit(locked_map, table, item, 1); } /*---------------------------------------------------------------------------*/ @@ -338,6 +362,10 @@ nbr_table_lock(nbr_table_t *table, void *item) int nbr_table_unlock(nbr_table_t *table, void *item) { +#if DEBUG + int i = index_from_item(table, item); + PRINTF("*** Unlock %d\n", i); +#endif return nbr_set_bit(locked_map, table, item, 0); } /*---------------------------------------------------------------------------*/ @@ -348,3 +376,25 @@ nbr_table_get_lladdr(nbr_table_t *table, const void *item) nbr_table_key_t *key = key_from_item(table, item); return key != NULL ? &key->lladdr : NULL; } +/*---------------------------------------------------------------------------*/ +#if DEBUG +static void +handle_periodic_timer(void *ptr) +{ + int i, j; + /* Printout all neighbors and which tables they are used in */ + PRINTF("NBR TABLE:\n"); + for(i = 0; i < NBR_TABLE_MAX_NEIGHBORS; i++) { + if(used_map[i] > 0) { + PRINTF(" %02d %02d",i , key_from_index(i)->lladdr.u8[LINKADDR_SIZE - 1]); + for(j = 0; j < num_tables; j++) { + PRINTF(" [%d:%d]", (used_map[i] & (1 << j)) != 0, + (locked_map[i] & (1 << j)) != 0); + } + PRINTF("\n"); + } + } + ctimer_reset(&periodic_timer); +} +#endif + From 5dee80a253d4aa09d265f4ce95cc316b98364101 Mon Sep 17 00:00:00 2001 From: Joakim Eriksson Date: Wed, 26 Aug 2015 18:23:06 +0200 Subject: [PATCH 2/3] added locking of nexthop for routes to avoid the risk of nexthop removal --- core/net/ipv6/uip-ds6-route.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/core/net/ipv6/uip-ds6-route.c b/core/net/ipv6/uip-ds6-route.c index 49e3d3588..a5c00d384 100644 --- a/core/net/ipv6/uip-ds6-route.c +++ b/core/net/ipv6/uip-ds6-route.c @@ -367,6 +367,9 @@ uip_ds6_route_add(uip_ipaddr_t *ipaddr, uint8_t length, num_routes++; PRINTF("uip_ds6_route_add num %d\n", num_routes); + + /* lock this entry so that nexthop is not removed */ + nbr_table_lock(nbr_routes, routes); } uip_ipaddr_copy(&(r->ipaddr), ipaddr); @@ -423,7 +426,7 @@ uip_ds6_route_rm(uip_ds6_route_t *route) list_remove(route->neighbor_routes->route_list, neighbor_route); if(list_head(route->neighbor_routes->route_list) == NULL) { /* If this was the only route using this neighbor, remove the - neibhor from the table */ + neighbor from the table - this implicitly unlocks nexthop */ PRINTF("uip_ds6_route_rm: removing neighbor too\n"); nbr_table_remove(nbr_routes, route->neighbor_routes->route_list); } From 4d5c749cf704143ca5dd19e19c6af79b26235c82 Mon Sep 17 00:00:00 2001 From: Joakim Eriksson Date: Wed, 26 Aug 2015 18:24:54 +0200 Subject: [PATCH 3/3] removed locking of rpl-parent since it was never unlocked - moved to routing module --- core/net/rpl/rpl-dag.c | 6 ------ core/net/rpl/rpl-icmp6.c | 2 -- core/net/rpl/rpl-private.h | 3 --- 3 files changed, 11 deletions(-) diff --git a/core/net/rpl/rpl-dag.c b/core/net/rpl/rpl-dag.c index 767c58968..89be40184 100644 --- a/core/net/rpl/rpl-dag.c +++ b/core/net/rpl/rpl-dag.c @@ -1408,10 +1408,4 @@ rpl_process_dio(uip_ipaddr_t *from, rpl_dio_t *dio) p->dtsn = dio->dtsn; } /*---------------------------------------------------------------------------*/ -void -rpl_lock_parent(rpl_parent_t *p) -{ - nbr_table_lock(rpl_parents, p); -} -/*---------------------------------------------------------------------------*/ /** @} */ diff --git a/core/net/rpl/rpl-icmp6.c b/core/net/rpl/rpl-icmp6.c index 0a4488d13..c4db3c8fa 100644 --- a/core/net/rpl/rpl-icmp6.c +++ b/core/net/rpl/rpl-icmp6.c @@ -773,8 +773,6 @@ dao_input(void) PRINTF("RPL: Neighbor already in neighbor cache\n"); } - rpl_lock_parent(parent); - rep = rpl_add_route(dag, &prefix, prefixlen, &dao_sender_addr); if(rep == NULL) { RPL_STAT(rpl_stats.mem_overflows++); diff --git a/core/net/rpl/rpl-private.h b/core/net/rpl/rpl-private.h index b49d71089..a1adc0d6f 100644 --- a/core/net/rpl/rpl-private.h +++ b/core/net/rpl/rpl-private.h @@ -303,9 +303,6 @@ uip_ds6_route_t *rpl_add_route(rpl_dag_t *dag, uip_ipaddr_t *prefix, int prefix_len, uip_ipaddr_t *next_hop); void rpl_purge_routes(void); -/* Lock a parent in the neighbor cache. */ -void rpl_lock_parent(rpl_parent_t *p); - /* Objective function. */ rpl_of_t *rpl_find_of(rpl_ocp_t);