32 #include "net/ipv6/uip-ds6.h"
37 #include "net/nbr-table.h"
59 LIST(defaultrouterlist);
62 #if UIP_DS6_NOTIFICATIONS
63 LIST(notificationlist);
66 static int num_routes = 0;
69 #define DEBUG DEBUG_PRINT
72 static void rm_routelist_callback(nbr_table_item_t *ptr);
74 #if DEBUG != DEBUG_NONE
76 assert_nbr_routes_list_sane(
void)
85 count < UIP_DS6_ROUTE_NB * 2;
89 if(count > UIP_DS6_ROUTE_NB) {
90 printf(
"uip-ds6-route.c: assert_nbr_routes_list_sane route list is in infinite loop\n");
95 if(count < num_routes) {
96 printf(
"uip-ds6-route.c: assert_nbr_routes_list_sane too few entries on route list: should be %d, is %d, max %d\n",
97 num_routes, count, UIP_CONF_MAX_ROUTES);
102 #if UIP_DS6_NOTIFICATIONS
104 call_route_callback(
int event, uip_ipaddr_t *route,
105 uip_ipaddr_t *nexthop)
108 struct uip_ds6_notification *n;
112 if(event == UIP_DS6_NOTIFICATION_DEFRT_ADD ||
113 event == UIP_DS6_NOTIFICATION_DEFRT_RM) {
118 n->callback(event, route, nexthop, num);
123 uip_ds6_notification_add(
struct uip_ds6_notification *n,
124 uip_ds6_notification_callback c)
133 uip_ds6_notification_rm(
struct uip_ds6_notification *n)
144 nbr_table_register(nbr_routes,
145 (nbr_table_callback *)rm_routelist_callback);
150 #if UIP_DS6_NOTIFICATIONS
160 route->neighbor_routes);
203 uint8_t longestmatch;
205 PRINTF(
"uip-ds6-route: Looking up route for ");
215 if(r->length >= longestmatch &&
216 uip_ipaddr_prefixcmp(addr, &r->ipaddr, r->length)) {
217 longestmatch = r->length;
222 if(found_route !=
NULL) {
223 PRINTF(
"uip-ds6-route: Found route: ");
226 PRINT6ADDR(uip_ds6_route_nexthop(found_route));
229 PRINTF(
"uip-ds6-route: No route found\n");
232 if(found_route !=
NULL) {
246 uip_ipaddr_t *nexthop)
251 #if DEBUG != DEBUG_NONE
252 assert_nbr_routes_list_sane();
257 if(nexthop_lladdr ==
NULL) {
258 PRINTF(
"uip_ds6_route_add: neighbor link-local address unknown for ");
269 PRINTF(
"uip_ds6_route_add: old route already found, updating this one instead: ");
284 PRINTF(
"uip_ds6_route_add: dropping route to ");
285 PRINT6ADDR(&oldest->ipaddr);
299 routes = nbr_table_get_from_lladdr(nbr_routes,
300 (linkaddr_t *)nexthop_lladdr);
308 routes = nbr_table_add_lladdr(nbr_routes,
309 (linkaddr_t *)nexthop_lladdr);
313 PRINTF(
"uip_ds6_route_add: could not allocate neighbor table entry\n");
325 PRINTF(
"uip_ds6_route_add: could not allocate route\n");
335 PRINTF(
"uip_ds6_route_add: could not allocate neighbor route list entry\n");
343 r->neighbor_routes = routes;
346 PRINTF(
"uip_ds6_route_add num %d\n", num_routes);
352 #ifdef UIP_DS6_ROUTE_STATE_TYPE
356 PRINTF(
"uip_ds6_route_add: adding route: ");
361 ANNOTATE(
"#L %u 1;blue\n", nexthop->u8[
sizeof(uip_ipaddr_t) - 1]);
363 #if UIP_DS6_NOTIFICATIONS
364 call_route_callback(UIP_DS6_NOTIFICATION_ROUTE_ADD, ipaddr, nexthop);
367 #if DEBUG != DEBUG_NONE
368 assert_nbr_routes_list_sane();
378 #if DEBUG != DEBUG_NONE
379 assert_nbr_routes_list_sane();
381 if(route !=
NULL && route->neighbor_routes !=
NULL) {
383 PRINTF(
"uip_ds6_route_rm: removing route: ");
384 PRINT6ADDR(&route->ipaddr);
391 for(neighbor_route =
list_head(route->neighbor_routes->route_list);
392 neighbor_route !=
NULL && neighbor_route->route != route;
395 if(neighbor_route ==
NULL) {
396 PRINTF(
"uip_ds6_route_rm: neighbor_route was NULL for ");
397 uip_debug_ipaddr_print(&route->ipaddr);
400 list_remove(route->neighbor_routes->route_list, neighbor_route);
404 PRINTF(
"uip_ds6_route_rm: removing neighbor too\n");
405 nbr_table_remove(nbr_routes, route->neighbor_routes->route_list);
408 memb_free(&neighborroutememb, neighbor_route);
412 PRINTF(
"uip_ds6_route_rm num %d\n", num_routes);
414 #if UIP_DS6_NOTIFICATIONS
415 call_route_callback(UIP_DS6_NOTIFICATION_ROUTE_RM,
416 &route->ipaddr, uip_ds6_route_nexthop(route));
418 #if 0 //(DEBUG & DEBUG_ANNOTATE) == DEBUG_ANNOTATE
425 uip_ipaddr_t *nextr, *nextroute;
426 nextr = uip_ds6_route_nexthop(r);
427 nextroute = uip_ds6_route_nexthop(route);
430 uip_ipaddr_cmp(nextr, nextroute)) {
435 ANNOTATE(
"#L %u 0\n", uip_ds6_route_nexthop(route)->u8[
sizeof(uip_ipaddr_t) - 1]);
439 #if DEBUG != DEBUG_NONE
440 assert_nbr_routes_list_sane();
448 #if DEBUG != DEBUG_NONE
449 assert_nbr_routes_list_sane();
451 PRINTF(
"uip_ds6_route_rm_routelist\n");
452 if(routes !=
NULL && routes->route_list !=
NULL) {
459 nbr_table_remove(nbr_routes, routes);
461 #if DEBUG != DEBUG_NONE
462 assert_nbr_routes_list_sane();
467 rm_routelist_callback(nbr_table_item_t *ptr)
473 uip_ds6_route_rm_by_nexthop(uip_ipaddr_t *nexthop)
480 routes = nbr_table_get_from_lladdr(nbr_routes,
481 (linkaddr_t *)nexthop_lladdr);
482 rm_routelist(routes);
490 #if DEBUG != DEBUG_NONE
491 assert_nbr_routes_list_sane();
494 PRINTF(
"uip_ds6_defrt_add\n");
499 PRINTF(
"uip_ds6_defrt_add: could not add default route to ");
501 PRINTF(
", out of memory\n");
504 PRINTF(
"uip_ds6_defrt_add: adding default route to ");
520 ANNOTATE(
"#L %u 1\n", ipaddr->u8[
sizeof(uip_ipaddr_t) - 1]);
522 #if UIP_DS6_NOTIFICATIONS
523 call_route_callback(UIP_DS6_NOTIFICATION_DEFRT_ADD, ipaddr, ipaddr);
526 #if DEBUG != DEBUG_NONE
527 assert_nbr_routes_list_sane();
538 #if DEBUG != DEBUG_NONE
539 assert_nbr_routes_list_sane();
547 PRINTF(
"Removing default route\n");
550 ANNOTATE(
"#L %u 0\n", defrt->ipaddr.u8[
sizeof(uip_ipaddr_t) - 1]);
551 #if UIP_DS6_NOTIFICATIONS
552 call_route_callback(UIP_DS6_NOTIFICATION_DEFRT_RM,
553 &defrt->ipaddr, &defrt->ipaddr);
558 #if DEBUG != DEBUG_NONE
559 assert_nbr_routes_list_sane();
571 if(uip_ipaddr_cmp(&d->ipaddr, ipaddr)) {
589 PRINTF(
"Defrt, IP address ");
590 PRINT6ADDR(&d->ipaddr);
593 if(bestnbr !=
NULL && bestnbr->state != NBR_INCOMPLETE) {
594 PRINTF(
"Defrt found, IP address ");
595 PRINT6ADDR(&d->ipaddr);
600 PRINTF(
"Defrt INCOMPLETE found, IP address ");
601 PRINT6ADDR(&d->ipaddr);
616 PRINTF(
"uip_ds6_defrt_periodic: defrt lifetime expired\n");