Make DS6 route notifications optional.

This commit is contained in:
lebrush 2013-05-15 12:11:56 +02:00
parent a445c4020d
commit 6eafa08313
2 changed files with 26 additions and 1 deletions

View file

@ -45,12 +45,16 @@ MEMB(routememb, uip_ds6_route_t, UIP_DS6_ROUTE_NB);
LIST(defaultrouterlist); LIST(defaultrouterlist);
MEMB(defaultroutermemb, uip_ds6_defrt_t, UIP_DS6_DEFRT_NB); MEMB(defaultroutermemb, uip_ds6_defrt_t, UIP_DS6_DEFRT_NB);
#if UIP_DS6_NOTIFICATIONS
LIST(notificationlist); LIST(notificationlist);
#endif
#undef DEBUG
#define DEBUG DEBUG_NONE #define DEBUG DEBUG_NONE
#include "net/uip-debug.h" #include "net/uip-debug.h"
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#if UIP_DS6_NOTIFICATIONS
static void static void
call_route_callback(int event, uip_ipaddr_t *route, call_route_callback(int event, uip_ipaddr_t *route,
uip_ipaddr_t *nexthop) uip_ipaddr_t *nexthop)
@ -85,6 +89,7 @@ uip_ds6_notification_rm(struct uip_ds6_notification *n)
{ {
list_remove(notificationlist, n); list_remove(notificationlist, n);
} }
#endif
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void void
uip_ds6_route_init(void) uip_ds6_route_init(void)
@ -95,7 +100,9 @@ uip_ds6_route_init(void)
memb_init(&defaultroutermemb); memb_init(&defaultroutermemb);
list_init(defaultrouterlist); list_init(defaultrouterlist);
#if UIP_DS6_NOTIFICATIONS
list_init(notificationlist); list_init(notificationlist);
#endif
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
uip_ds6_route_t * uip_ds6_route_t *
@ -192,7 +199,9 @@ uip_ds6_route_add(uip_ipaddr_t *ipaddr, uint8_t length,
PRINTF("\n"); PRINTF("\n");
ANNOTATE("#L %u 1;blue\n", nexthop->u8[sizeof(uip_ipaddr_t) - 1]); ANNOTATE("#L %u 1;blue\n", nexthop->u8[sizeof(uip_ipaddr_t) - 1]);
#if UIP_DS6_NOTIFICATIONS
call_route_callback(UIP_DS6_NOTIFICATION_ROUTE_ADD, ipaddr, nexthop); call_route_callback(UIP_DS6_NOTIFICATION_ROUTE_ADD, ipaddr, nexthop);
#endif
return r; return r;
} }
@ -212,8 +221,10 @@ uip_ds6_route_rm(uip_ds6_route_t *route)
PRINTF("uip_ds6_route_rm num %d\n", list_length(routelist)); PRINTF("uip_ds6_route_rm num %d\n", list_length(routelist));
#if UIP_DS6_NOTIFICATIONS
call_route_callback(UIP_DS6_NOTIFICATION_ROUTE_RM, call_route_callback(UIP_DS6_NOTIFICATION_ROUTE_RM,
&route->ipaddr, &route->nexthop); &route->ipaddr, &route->nexthop);
#endif
#if (DEBUG & DEBUG_ANNOTATE) == DEBUG_ANNOTATE #if (DEBUG & DEBUG_ANNOTATE) == DEBUG_ANNOTATE
/* we need to check if this was the last route towards "nexthop" */ /* we need to check if this was the last route towards "nexthop" */
/* if so - remove that link (annotation) */ /* if so - remove that link (annotation) */
@ -241,8 +252,10 @@ uip_ds6_route_rm_by_nexthop(uip_ipaddr_t *nexthop)
while(r != NULL) { while(r != NULL) {
if(uip_ipaddr_cmp(&r->nexthop, nexthop)) { if(uip_ipaddr_cmp(&r->nexthop, nexthop)) {
list_remove(routelist, r); list_remove(routelist, r);
#if UIP_DS6_NOTIFICATIONS
call_route_callback(UIP_DS6_NOTIFICATION_ROUTE_RM, call_route_callback(UIP_DS6_NOTIFICATION_ROUTE_RM,
&r->ipaddr, &r->nexthop); &r->ipaddr, &r->nexthop);
#endif
r = list_head(routelist); r = list_head(routelist);
} else { } else {
r = list_item_next(r); r = list_item_next(r);
@ -282,7 +295,9 @@ uip_ds6_defrt_add(uip_ipaddr_t *ipaddr, unsigned long interval)
ANNOTATE("#L %u 1\n", ipaddr->u8[sizeof(uip_ipaddr_t) - 1]); ANNOTATE("#L %u 1\n", ipaddr->u8[sizeof(uip_ipaddr_t) - 1]);
#if UIP_DS6_NOTIFICATIONS
call_route_callback(UIP_DS6_NOTIFICATION_DEFRT_ADD, ipaddr, ipaddr); call_route_callback(UIP_DS6_NOTIFICATION_DEFRT_ADD, ipaddr, ipaddr);
#endif
return d; return d;
} }
@ -300,8 +315,10 @@ uip_ds6_defrt_rm(uip_ds6_defrt_t *defrt)
list_remove(defaultrouterlist, defrt); list_remove(defaultrouterlist, defrt);
memb_free(&defaultroutermemb, defrt); memb_free(&defaultroutermemb, defrt);
ANNOTATE("#L %u 0\n", defrt->ipaddr.u8[sizeof(uip_ipaddr_t) - 1]); ANNOTATE("#L %u 0\n", defrt->ipaddr.u8[sizeof(uip_ipaddr_t) - 1]);
#if UIP_DS6_NOTIFICATIONS
call_route_callback(UIP_DS6_NOTIFICATION_DEFRT_RM, call_route_callback(UIP_DS6_NOTIFICATION_DEFRT_RM,
&defrt->ipaddr, &defrt->ipaddr); &defrt->ipaddr, &defrt->ipaddr);
#endif
return; return;
} }
} }

View file

@ -34,7 +34,13 @@
void uip_ds6_route_init(void); void uip_ds6_route_init(void);
#ifndef UIP_CONF_UIP_DS6_NOTIFICATIONS
#define UIP_DS6_NOTIFICATIONS 1
#else
#define UIP_DS6_NOTIFICATIONS UIP_CONF_UIP_DS6_NOTIFICATIONS
#endif
#if UIP_DS6_NOTIFICATIONS
/* Event constants for the uip-ds6 route notification interface. The /* Event constants for the uip-ds6 route notification interface. The
notification interface allows for a user program to be notified via notification interface allows for a user program to be notified via
a callback when a route has been added or removed and when the a callback when a route has been added or removed and when the
@ -55,8 +61,10 @@ struct uip_ds6_notification {
void uip_ds6_notification_add(struct uip_ds6_notification *n, void uip_ds6_notification_add(struct uip_ds6_notification *n,
uip_ds6_notification_callback c); uip_ds6_notification_callback c);
/*--------------------------------------------------*/
void uip_ds6_notification_rm(struct uip_ds6_notification *n);
/*--------------------------------------------------*/
#endif
/* Routing table */ /* Routing table */
#ifndef UIP_CONF_MAX_ROUTES #ifndef UIP_CONF_MAX_ROUTES