Last active
December 25, 2015 18:59
-
-
Save aguirrem/7024890 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ip_ds6_route_t * | |
uip_ds6_route_add(uip_ipaddr_t *ipaddr, uint8_t length, | |
uip_ipaddr_t *nexthop) | |
{ | |
uip_ds6_route_t *r; | |
#if DEBUG != DEBUG_NONE | |
assert_nbr_routes_list_sane(); | |
#endif /* DEBUG != DEBUG_NONE */ | |
/* Get link-layer address of next hop, make sure it is in neighbor table */ | |
uip_lladdr_t *nexthop_lladdr = uip_ds6_nbr_lladdr_from_ipaddr(nexthop); | |
if(nexthop_lladdr == NULL) { | |
PRINTF("uip_ds6_route_add: neighbor link-local address unknown "); | |
PRINT6ADDR(ipaddr); | |
PRINTF("\n"); | |
return NULL; | |
} | |
/* First make sure that we don't add a route twice. If we find an | |
existing route for our destination, we'll just update the old | |
one. */ | |
r = uip_ds6_route_lookup(ipaddr); | |
if(r != NULL) { | |
PRINTF("uip_ds6_route_add: old route already found, updating this one instead: "); | |
PRINT6ADDR(ipaddr); | |
PRINTF("\n"); | |
} else { | |
struct uip_ds6_route_neighbor_routes *routes; | |
/* If there is no routing entry, create one */ | |
/* Every neighbor on our neighbor table holds a struct | |
uip_ds6_route_neighbor_routes which holds a list of routes that | |
go through the neighbor. We add our route entry to this list. | |
We first check to see if we already have this neighbor in our | |
nbr_route table. If so, the neighbor already has a route entry | |
list. | |
*/ | |
routes = nbr_table_get_from_lladdr(nbr_routes, | |
(rimeaddr_t *)nexthop_lladdr); | |
if(routes == NULL) { | |
/* If the neighbor did not have an entry in our neighbor table, | |
we create one. The nbr_table_add_lladdr() function returns a | |
pointer to a pointer that we may use for our own purposes. We | |
initialize this pointer with the list of routing entries that | |
are attached to this neighbor. */ | |
routes = nbr_table_add_lladdr(nbr_routes, | |
(rimeaddr_t *)nexthop_lladdr); | |
if(routes == NULL) { | |
PRINTF("uip_ds6_route_add: could not allocate a neighbor table entri for new route to "); | |
PRINT6ADDR(ipaddr); | |
PRINTF(", dropping it\n"); | |
return NULL; | |
} | |
LIST_STRUCT_INIT(routes, route_list); | |
} | |
/* Allocate a routing entry and populate it. */ | |
r = memb_alloc(&routememb); | |
if(r == NULL) { | |
PRINTF("uip_ds6_route_add: could not allocate memory for new route to "); | |
PRINT6ADDR(ipaddr); | |
PRINTF(", dropping it\n"); | |
return NULL; | |
} | |
/* Add the route to this neighbor */ | |
list_add(routes->route_list, r); | |
num_routes++; | |
PRINTF("uip_ds6_route_add num %d\n", num_routes); | |
r->routes = routes; | |
#if UIP_DS6_NOTIFICATIONS | |
call_route_callback(UIP_DS6_NOTIFICATION_ROUTE_ADD, ipaddr, nexthop); | |
#endif | |
PRINTF("uip_ds6_route_add: adding route: "); | |
PRINT6ADDR(ipaddr); | |
PRINTF(" via "); | |
PRINT6ADDR(nexthop); | |
PRINTF("\n"); | |
ANNOTATE("#L %u 1;blue\n", nexthop->u8[sizeof(uip_ipaddr_t) - 1]); | |
} | |
uip_ipaddr_copy(&(r->ipaddr), ipaddr); | |
r->length = length; | |
r->new_flag = 1; | |
#ifdef UIP_DS6_ROUTE_STATE_TYPE | |
memset(&r->state, 0, sizeof(UIP_DS6_ROUTE_STATE_TYPE)); | |
#endif | |
#if DEBUG != DEBUG_NONE | |
assert_nbr_routes_list_sane(); | |
#endif /* DEBUG != DEBUG_NONE */ | |
return r; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment