Rewrote the uIP IPv6 route handling code. Instead of being nested deeply inside the uip-ds6.c file, the route management code is now in a separate file, uip-ds6-route.c. This file presents a lib/list.h API for the routes, which makes the route list much easier to use. Additionally, the uip-ds6-route.c file adds a callback API that invokes a callback when routes are added and removed.
This commit is contained in:
parent
b2063953ba
commit
afe13b22bc
6 changed files with 579 additions and 106 deletions
|
@ -354,12 +354,10 @@ int
|
|||
rpl_set_default_route(rpl_instance_t *instance, uip_ipaddr_t *from)
|
||||
{
|
||||
if(instance->def_route != NULL) {
|
||||
if(instance->def_route->isused) {
|
||||
PRINTF("RPL: Removing default route through ");
|
||||
PRINT6ADDR(&instance->def_route->ipaddr);
|
||||
PRINTF("\n");
|
||||
uip_ds6_defrt_rm(instance->def_route);
|
||||
}
|
||||
PRINTF("RPL: Removing default route through ");
|
||||
PRINT6ADDR(&instance->def_route->ipaddr);
|
||||
PRINTF("\n");
|
||||
uip_ds6_defrt_rm(instance->def_route);
|
||||
instance->def_route = NULL;
|
||||
}
|
||||
|
||||
|
@ -373,6 +371,13 @@ rpl_set_default_route(rpl_instance_t *instance, uip_ipaddr_t *from)
|
|||
if(instance->def_route == NULL) {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
PRINTF("RPL: Removing default route\n");
|
||||
if(instance->def_route != NULL) {
|
||||
uip_ds6_defrt_rm(instance->def_route);
|
||||
} else {
|
||||
PRINTF("RPL: Not actually removing default route, since instance had no default route\n");
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
@ -691,12 +696,10 @@ rpl_nullify_parent(rpl_dag_t *dag, rpl_parent_t *parent)
|
|||
dag->rank = INFINITE_RANK;
|
||||
if(dag->joined) {
|
||||
if(dag->instance->def_route != NULL) {
|
||||
if(dag->instance->def_route->isused) {
|
||||
PRINTF("RPL: Removing default route ");
|
||||
PRINT6ADDR(&parent->addr);
|
||||
PRINTF("\n");
|
||||
uip_ds6_defrt_rm(dag->instance->def_route);
|
||||
}
|
||||
PRINTF("RPL: Removing default route ");
|
||||
PRINT6ADDR(&parent->addr);
|
||||
PRINTF("\n");
|
||||
uip_ds6_defrt_rm(dag->instance->def_route);
|
||||
dag->instance->def_route = NULL;
|
||||
}
|
||||
dao_output(parent, RPL_ZERO_LIFETIME);
|
||||
|
@ -715,12 +718,11 @@ rpl_move_parent(rpl_dag_t *dag_src, rpl_dag_t *dag_dst, rpl_parent_t *parent)
|
|||
dag_src->preferred_parent = NULL;
|
||||
dag_src->rank = INFINITE_RANK;
|
||||
if(dag_src->joined && dag_src->instance->def_route != NULL) {
|
||||
if(dag_src->instance->def_route->isused) {
|
||||
PRINTF("RPL: Removing default route ");
|
||||
PRINT6ADDR(&parent->addr);
|
||||
PRINTF("\n");
|
||||
uip_ds6_defrt_rm(dag_src->instance->def_route);
|
||||
}
|
||||
PRINTF("RPL: Removing default route ");
|
||||
PRINT6ADDR(&parent->addr);
|
||||
PRINTF("\n");
|
||||
printf("rpl_move_parent\n");
|
||||
uip_ds6_defrt_rm(dag_src->instance->def_route);
|
||||
dag_src->instance->def_route = NULL;
|
||||
}
|
||||
} else if(dag_src->joined) {
|
||||
|
|
|
@ -56,21 +56,21 @@
|
|||
rpl_stats_t rpl_stats;
|
||||
#endif
|
||||
|
||||
/************************************************************************/
|
||||
extern uip_ds6_route_t uip_ds6_routing_table[UIP_DS6_ROUTE_NB];
|
||||
/************************************************************************/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
rpl_purge_routes(void)
|
||||
{
|
||||
int i;
|
||||
uip_ds6_route_t *r;
|
||||
|
||||
for(i = 0; i < UIP_DS6_ROUTE_NB; i++) {
|
||||
if(uip_ds6_routing_table[i].isused) {
|
||||
if(uip_ds6_routing_table[i].state.lifetime <= 1) {
|
||||
uip_ds6_route_rm(&uip_ds6_routing_table[i]);
|
||||
} else {
|
||||
uip_ds6_routing_table[i].state.lifetime--;
|
||||
}
|
||||
r = uip_ds6_route_list_head();
|
||||
|
||||
while(r != NULL) {
|
||||
if(r->state.lifetime <= 1) {
|
||||
uip_ds6_route_rm(r);
|
||||
r = uip_ds6_route_list_head();
|
||||
} else {
|
||||
r->state.lifetime--;
|
||||
r = list_item_next(r);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -78,11 +78,16 @@ rpl_purge_routes(void)
|
|||
void
|
||||
rpl_remove_routes(rpl_dag_t *dag)
|
||||
{
|
||||
int i;
|
||||
uip_ds6_route_t *r;
|
||||
|
||||
for(i = 0; i < UIP_DS6_ROUTE_NB; i++) {
|
||||
if(uip_ds6_routing_table[i].state.dag == dag) {
|
||||
uip_ds6_route_rm(&uip_ds6_routing_table[i]);
|
||||
r = uip_ds6_route_list_head();
|
||||
|
||||
while(r != NULL) {
|
||||
if(r->state.dag == dag) {
|
||||
uip_ds6_route_rm(r);
|
||||
r = uip_ds6_route_list_head();
|
||||
} else {
|
||||
r = list_item_next(r);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -90,6 +95,22 @@ rpl_remove_routes(rpl_dag_t *dag)
|
|||
void
|
||||
rpl_remove_routes_by_nexthop(uip_ipaddr_t *nexthop, rpl_dag_t *dag)
|
||||
{
|
||||
uip_ds6_route_t *r;
|
||||
|
||||
r = uip_ds6_route_list_head();
|
||||
|
||||
while(r != NULL) {
|
||||
if(uip_ipaddr_cmp(&r->nexthop, nexthop) &&
|
||||
r->state.dag == dag) {
|
||||
uip_ds6_route_rm(r);
|
||||
r = uip_ds6_route_list_head();
|
||||
} else {
|
||||
r = list_item_next(r);
|
||||
}
|
||||
}
|
||||
ANNOTATE("#L %u 0\n", nexthop->u8[sizeof(uip_ipaddr_t) - 1]);
|
||||
|
||||
#if 0
|
||||
uip_ds6_route_t *locroute;
|
||||
|
||||
for(locroute = uip_ds6_routing_table;
|
||||
|
@ -102,6 +123,7 @@ rpl_remove_routes_by_nexthop(uip_ipaddr_t *nexthop, rpl_dag_t *dag)
|
|||
}
|
||||
}
|
||||
ANNOTATE("#L %u 0\n",nexthop->u8[sizeof(uip_ipaddr_t) - 1]);
|
||||
#endif /* 0 */
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
uip_ds6_route_t *
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue