Made the code more conforming to the Contiki style.

This commit is contained in:
Nicolas Tsiftes 2011-03-16 13:35:44 +01:00
parent 65366d10c1
commit c461266524
2 changed files with 98 additions and 107 deletions

View file

@ -174,46 +174,46 @@ uip_ds6_periodic(void)
#if !UIP_CONF_ROUTER #if !UIP_CONF_ROUTER
/* Periodic processing on prefixes */ /* Periodic processing on prefixes */
for(locprefix = uip_ds6_prefix_list; for(locprefix = uip_ds6_prefix_list;
locprefix < uip_ds6_prefix_list + UIP_DS6_PREFIX_NB; locprefix++) { locprefix < uip_ds6_prefix_list + UIP_DS6_PREFIX_NB;
if((locprefix->isused) && (!locprefix->isinfinite) locprefix++) {
&& (stimer_expired(&(locprefix->vlifetime)))) { if(locprefix->isused && !locprefix->isinfinite
&& stimer_expired(&(locprefix->vlifetime))) {
uip_ds6_prefix_rm(locprefix); uip_ds6_prefix_rm(locprefix);
} }
} }
#endif /* !UIP_CONF_ROUTER */ #endif /* !UIP_CONF_ROUTER */
/* Periodic processing on neighbors */ /* Periodic processing on neighbors */
for(locnbr = uip_ds6_nbr_cache; locnbr < uip_ds6_nbr_cache + UIP_DS6_NBR_NB; for(locnbr = uip_ds6_nbr_cache;
locnbr < uip_ds6_nbr_cache + UIP_DS6_NBR_NB;
locnbr++) { locnbr++) {
if(locnbr->isused) { if(locnbr->isused) {
switch(locnbr->state) { switch(locnbr->state) {
case NBR_INCOMPLETE: case NBR_INCOMPLETE:
if(locnbr->nscount >= UIP_ND6_MAX_MULTICAST_SOLICIT) { if(locnbr->nscount >= UIP_ND6_MAX_MULTICAST_SOLICIT) {
uip_ds6_nbr_rm(locnbr); uip_ds6_nbr_rm(locnbr);
} else if(stimer_expired(&(locnbr->sendns))) { } else if(stimer_expired(&locnbr->sendns)) {
locnbr->nscount++; locnbr->nscount++;
PRINTF("NBR_INCOMPLETE: NS %u\n", locnbr->nscount); PRINTF("NBR_INCOMPLETE: NS %u\n", locnbr->nscount);
uip_nd6_ns_output(NULL, NULL, &locnbr->ipaddr); uip_nd6_ns_output(NULL, NULL, &locnbr->ipaddr);
stimer_set(&(locnbr->sendns), uip_ds6_if.retrans_timer / 1000); stimer_set(&locnbr->sendns, uip_ds6_if.retrans_timer / 1000);
} }
break; break;
case NBR_REACHABLE: case NBR_REACHABLE:
if(stimer_expired(&(locnbr->reachable))) { if(stimer_expired(&locnbr->reachable)) {
PRINTF("REACHABLE: moving to STALE ("); PRINTF("REACHABLE: moving to STALE (");
PRINT6ADDR(&locnbr->ipaddr); PRINT6ADDR(&locnbr->ipaddr);
PRINTF(")\n"); PRINTF(")\n");
locnbr->state = NBR_STALE; locnbr->state = NBR_STALE;
/* NEIGHBOR_STATE_CHANGED(locnbr); */
} }
break; break;
case NBR_DELAY: case NBR_DELAY:
if(stimer_expired(&(locnbr->reachable))) { if(stimer_expired(&locnbr->reachable)) {
locnbr->state = NBR_PROBE; locnbr->state = NBR_PROBE;
locnbr->nscount = 1; locnbr->nscount = 1;
/* NEIGHBOR_STATE_CHANGED(locnbr); */
PRINTF("DELAY: moving to PROBE + NS %u\n", locnbr->nscount); PRINTF("DELAY: moving to PROBE + NS %u\n", locnbr->nscount);
uip_nd6_ns_output(NULL, &locnbr->ipaddr, &locnbr->ipaddr); uip_nd6_ns_output(NULL, &locnbr->ipaddr, &locnbr->ipaddr);
stimer_set(&(locnbr->sendns), uip_ds6_if.retrans_timer / 1000); stimer_set(&locnbr->sendns, uip_ds6_if.retrans_timer / 1000);
} }
break; break;
case NBR_PROBE: case NBR_PROBE:
@ -223,11 +223,11 @@ uip_ds6_periodic(void)
uip_ds6_defrt_rm(locdefrt); uip_ds6_defrt_rm(locdefrt);
} }
uip_ds6_nbr_rm(locnbr); uip_ds6_nbr_rm(locnbr);
} else if(stimer_expired(&(locnbr->sendns))) { } else if(stimer_expired(&locnbr->sendns)) {
locnbr->nscount++; locnbr->nscount++;
PRINTF("PROBE: NS %u\n", locnbr->nscount); PRINTF("PROBE: NS %u\n", locnbr->nscount);
uip_nd6_ns_output(NULL, &locnbr->ipaddr, &locnbr->ipaddr); uip_nd6_ns_output(NULL, &locnbr->ipaddr, &locnbr->ipaddr);
stimer_set(&(locnbr->sendns), uip_ds6_if.retrans_timer / 1000); stimer_set(&locnbr->sendns, uip_ds6_if.retrans_timer / 1000);
} }
break; break;
default: default:
@ -260,9 +260,8 @@ uip_ds6_list_loop(uip_ds6_element_t * list, uint8_t size,
element < element <
(uip_ds6_element_t *)((uint8_t *)list + (size * elementsize)); (uip_ds6_element_t *)((uint8_t *)list + (size * elementsize));
element = (uip_ds6_element_t *)((uint8_t *)element + elementsize)) { element = (uip_ds6_element_t *)((uint8_t *)element + elementsize)) {
// printf("+ %p %d\n", &element->isused, element->isused);
if(element->isused) { if(element->isused) {
if(uip_ipaddr_prefixcmp(&(element->ipaddr), ipaddr, ipaddrlen)) { if(uip_ipaddr_prefixcmp(&element->ipaddr, ipaddr, ipaddrlen)) {
*out_element = element; *out_element = element;
return FOUND; return FOUND;
} }
@ -271,11 +270,7 @@ uip_ds6_list_loop(uip_ds6_element_t * list, uint8_t size,
} }
} }
if(*out_element != NULL) { return *out_element != NULL ? FREESPACE : NOSPACE;
return FREESPACE;
} else {
return NOSPACE;
}
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
@ -289,15 +284,14 @@ uip_ds6_nbr_add(uip_ipaddr_t * ipaddr, uip_lladdr_t * lladdr,
((uip_ds6_element_t *)uip_ds6_nbr_cache, UIP_DS6_NBR_NB, ((uip_ds6_element_t *)uip_ds6_nbr_cache, UIP_DS6_NBR_NB,
sizeof(uip_ds6_nbr_t), ipaddr, 128, sizeof(uip_ds6_nbr_t), ipaddr, 128,
(uip_ds6_element_t **)&locnbr); (uip_ds6_element_t **)&locnbr);
// printf("r %d\n", r);
if(r == FREESPACE) { if(r == FREESPACE) {
locnbr->isused = 1; locnbr->isused = 1;
uip_ipaddr_copy(&(locnbr->ipaddr), ipaddr); uip_ipaddr_copy(&locnbr->ipaddr, ipaddr);
if(lladdr != NULL) { if(lladdr != NULL) {
memcpy(&(locnbr->lladdr), lladdr, UIP_LLADDR_LEN); memcpy(&locnbr->lladdr, lladdr, UIP_LLADDR_LEN);
} else { } else {
memset(&(locnbr->lladdr), 0, UIP_LLADDR_LEN); memset(&locnbr->lladdr, 0, UIP_LLADDR_LEN);
} }
locnbr->isrouter = isrouter; locnbr->isrouter = isrouter;
locnbr->state = state; locnbr->state = state;
@ -305,8 +299,8 @@ uip_ds6_nbr_add(uip_ipaddr_t * ipaddr, uip_lladdr_t * lladdr,
uip_packetqueue_new(&locnbr->packethandle); uip_packetqueue_new(&locnbr->packethandle);
#endif /* UIP_CONF_IPV6_QUEUE_PKT */ #endif /* UIP_CONF_IPV6_QUEUE_PKT */
/* timers are set separately, for now we put them in expired state */ /* timers are set separately, for now we put them in expired state */
stimer_set(&(locnbr->reachable), 0); stimer_set(&locnbr->reachable, 0);
stimer_set(&(locnbr->sendns), 0); stimer_set(&locnbr->sendns, 0);
locnbr->nscount = 0; locnbr->nscount = 0;
PRINTF("Adding neighbor with ip addr "); PRINTF("Adding neighbor with ip addr ");
PRINT6ADDR(ipaddr); PRINT6ADDR(ipaddr);
@ -316,7 +310,6 @@ uip_ds6_nbr_add(uip_ipaddr_t * ipaddr, uip_lladdr_t * lladdr,
NEIGHBOR_STATE_CHANGED(locnbr); NEIGHBOR_STATE_CHANGED(locnbr);
locnbr->last_lookup = clock_time(); locnbr->last_lookup = clock_time();
// printf("add %p\n", locnbr);
return locnbr; return locnbr;
} else if(r == NOSPACE) { } else if(r == NOSPACE) {
/* We did not find any empty slot on the neighbor list, so we need /* We did not find any empty slot on the neighbor list, so we need
@ -338,7 +331,6 @@ uip_ds6_nbr_add(uip_ipaddr_t * ipaddr, uip_lladdr_t * lladdr,
} }
} }
if(oldest != NULL) { if(oldest != NULL) {
// printf("rm3\n");
uip_ds6_nbr_rm(oldest); uip_ds6_nbr_rm(oldest);
return uip_ds6_nbr_add(ipaddr, lladdr, isrouter, state); return uip_ds6_nbr_add(ipaddr, lladdr, isrouter, state);
} }
@ -354,7 +346,6 @@ uip_ds6_nbr_rm(uip_ds6_nbr_t *nbr)
if(nbr != NULL) { if(nbr != NULL) {
nbr->isused = 0; nbr->isused = 0;
#if UIP_CONF_IPV6_QUEUE_PKT #if UIP_CONF_IPV6_QUEUE_PKT
// printf("rm %p\n", &nbr->isused);
uip_packetqueue_free(&nbr->packethandle); uip_packetqueue_free(&nbr->packethandle);
#endif /* UIP_CONF_IPV6_QUEUE_PKT */ #endif /* UIP_CONF_IPV6_QUEUE_PKT */
NEIGHBOR_STATE_CHANGED(nbr); NEIGHBOR_STATE_CHANGED(nbr);
@ -384,9 +375,9 @@ uip_ds6_defrt_add(uip_ipaddr_t *ipaddr, unsigned long interval)
sizeof(uip_ds6_defrt_t), ipaddr, 128, sizeof(uip_ds6_defrt_t), ipaddr, 128,
(uip_ds6_element_t **)&locdefrt) == FREESPACE) { (uip_ds6_element_t **)&locdefrt) == FREESPACE) {
locdefrt->isused = 1; locdefrt->isused = 1;
uip_ipaddr_copy(&(locdefrt->ipaddr), ipaddr); uip_ipaddr_copy(&locdefrt->ipaddr, ipaddr);
if(interval != 0) { if(interval != 0) {
stimer_set(&(locdefrt->lifetime), interval); stimer_set(&locdefrt->lifetime, interval);
locdefrt->isinfinite = 0; locdefrt->isinfinite = 0;
} else { } else {
locdefrt->isinfinite = 1; locdefrt->isinfinite = 1;
@ -440,7 +431,7 @@ uip_ds6_defrt_choose(void)
PRINT6ADDR(&locdefrt->ipaddr); PRINT6ADDR(&locdefrt->ipaddr);
PRINTF("\n"); PRINTF("\n");
bestnbr = uip_ds6_nbr_lookup(&locdefrt->ipaddr); bestnbr = uip_ds6_nbr_lookup(&locdefrt->ipaddr);
if((bestnbr != NULL) && (bestnbr->state != NBR_INCOMPLETE)) { if(bestnbr != NULL && bestnbr->state != NBR_INCOMPLETE) {
PRINTF("Defrt found, IP address "); PRINTF("Defrt found, IP address ");
PRINT6ADDR(&locdefrt->ipaddr); PRINT6ADDR(&locdefrt->ipaddr);
PRINTF("\n"); PRINTF("\n");
@ -468,7 +459,7 @@ uip_ds6_prefix_add(uip_ipaddr_t * ipaddr, uint8_t ipaddrlen,
sizeof(uip_ds6_prefix_t), ipaddr, ipaddrlen, sizeof(uip_ds6_prefix_t), ipaddr, ipaddrlen,
(uip_ds6_element_t **)&locprefix) == FREESPACE) { (uip_ds6_element_t **)&locprefix) == FREESPACE) {
locprefix->isused = 1; locprefix->isused = 1;
uip_ipaddr_copy(&(locprefix->ipaddr), ipaddr); uip_ipaddr_copy(&locprefix->ipaddr, ipaddr);
locprefix->length = ipaddrlen; locprefix->length = ipaddrlen;
locprefix->advertise = advertise; locprefix->advertise = advertise;
locprefix->l_a_reserved = flags; locprefix->l_a_reserved = flags;
@ -496,7 +487,7 @@ uip_ds6_prefix_add(uip_ipaddr_t * ipaddr, uint8_t ipaddrlen,
sizeof(uip_ds6_prefix_t), ipaddr, ipaddrlen, sizeof(uip_ds6_prefix_t), ipaddr, ipaddrlen,
(uip_ds6_element_t **)&locprefix) == FREESPACE) { (uip_ds6_element_t **)&locprefix) == FREESPACE) {
locprefix->isused = 1; locprefix->isused = 1;
uip_ipaddr_copy(&(locprefix->ipaddr), ipaddr); uip_ipaddr_copy(&locprefix->ipaddr, ipaddr);
locprefix->length = ipaddrlen; locprefix->length = ipaddrlen;
if(interval != 0) { if(interval != 0) {
stimer_set(&(locprefix->vlifetime), interval); stimer_set(&(locprefix->vlifetime), interval);
@ -615,7 +606,7 @@ uip_ds6_get_link_local(int8_t state)
{ {
for(locaddr = uip_ds6_if.addr_list; for(locaddr = uip_ds6_if.addr_list;
locaddr < uip_ds6_if.addr_list + UIP_DS6_ADDR_NB; locaddr++) { locaddr < uip_ds6_if.addr_list + UIP_DS6_ADDR_NB; locaddr++) {
if((locaddr->isused) && (state == -1 || locaddr->state == state) if(locaddr->isused && (state == -1 || locaddr->state == state)
&& (uip_is_addr_link_local(&locaddr->ipaddr))) { && (uip_is_addr_link_local(&locaddr->ipaddr))) {
return locaddr; return locaddr;
} }
@ -634,7 +625,7 @@ uip_ds6_get_global(int8_t state)
{ {
for(locaddr = uip_ds6_if.addr_list; for(locaddr = uip_ds6_if.addr_list;
locaddr < uip_ds6_if.addr_list + UIP_DS6_ADDR_NB; locaddr++) { locaddr < uip_ds6_if.addr_list + UIP_DS6_ADDR_NB; locaddr++) {
if((locaddr->isused) && (state == -1 || locaddr->state == state) if(locaddr->isused && (state == -1 || locaddr->state == state)
&& !(uip_is_addr_link_local(&locaddr->ipaddr))) { && !(uip_is_addr_link_local(&locaddr->ipaddr))) {
return locaddr; return locaddr;
} }
@ -747,7 +738,7 @@ uip_ds6_route_lookup(uip_ipaddr_t * destipaddr)
PRINT6ADDR(&locrt->nexthop); PRINT6ADDR(&locrt->nexthop);
PRINTF("\n"); PRINTF("\n");
} else { } else {
PRINTF("DS6: No route found ...\n"); PRINTF("DS6: No route found\n");
} }
return locrt; return locrt;
@ -755,10 +746,9 @@ uip_ds6_route_lookup(uip_ipaddr_t * destipaddr)
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
uip_ds6_route_t * uip_ds6_route_t *
uip_ds6_route_add(uip_ipaddr_t * ipaddr, u8_t length, uip_ipaddr_t * nexthop, uip_ds6_route_add(uip_ipaddr_t *ipaddr, uint8_t length, uip_ipaddr_t *nexthop,
u8_t metric) uint8_t metric)
{ {
if(uip_ds6_list_loop if(uip_ds6_list_loop
((uip_ds6_element_t *)uip_ds6_routing_table, UIP_DS6_ROUTE_NB, ((uip_ds6_element_t *)uip_ds6_routing_table, UIP_DS6_ROUTE_NB,
sizeof(uip_ds6_route_t), ipaddr, length, sizeof(uip_ds6_route_t), ipaddr, length,
@ -775,7 +765,6 @@ uip_ds6_route_add(uip_ipaddr_t * ipaddr, u8_t length, uip_ipaddr_t * nexthop,
PRINT6ADDR(nexthop); PRINT6ADDR(nexthop);
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]);
} }
return locroute; return locroute;
@ -790,9 +779,10 @@ uip_ds6_route_rm(uip_ds6_route_t *route)
/* 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) */
for(locroute = uip_ds6_routing_table; for(locroute = uip_ds6_routing_table;
locroute < uip_ds6_routing_table + UIP_DS6_ROUTE_NB; locroute++) { locroute < uip_ds6_routing_table + UIP_DS6_ROUTE_NB;
if((locroute->isused) && uip_ipaddr_cmp(&locroute->nexthop, &route->nexthop)) { locroute++) {
/* we did find another link using the specific nexthop, so keep the #L */ if(locroute->isused && uip_ipaddr_cmp(&locroute->nexthop, &route->nexthop)) {
/* we found another link using the specific nexthop, so keep the #L */
return; return;
} }
} }
@ -804,8 +794,9 @@ void
uip_ds6_route_rm_by_nexthop(uip_ipaddr_t *nexthop) uip_ds6_route_rm_by_nexthop(uip_ipaddr_t *nexthop)
{ {
for(locroute = uip_ds6_routing_table; for(locroute = uip_ds6_routing_table;
locroute < uip_ds6_routing_table + UIP_DS6_ROUTE_NB; locroute++) { locroute < uip_ds6_routing_table + UIP_DS6_ROUTE_NB;
if((locroute->isused) && uip_ipaddr_cmp(&locroute->nexthop, nexthop)) { locroute++) {
if(locroute->isused && uip_ipaddr_cmp(&locroute->nexthop, nexthop)) {
locroute->isused = 0; locroute->isused = 0;
} }
} }
@ -825,9 +816,9 @@ uip_ds6_select_src(uip_ipaddr_t *src, uip_ipaddr_t *dst)
for(locaddr = uip_ds6_if.addr_list; for(locaddr = uip_ds6_if.addr_list;
locaddr < uip_ds6_if.addr_list + UIP_DS6_ADDR_NB; locaddr++) { locaddr < uip_ds6_if.addr_list + UIP_DS6_ADDR_NB; locaddr++) {
/* Only preferred global (not link-local) addresses */ /* Only preferred global (not link-local) addresses */
if((locaddr->isused) && (locaddr->state == ADDR_PREFERRED) && if(locaddr->isused && locaddr->state == ADDR_PREFERRED &&
(!uip_is_addr_link_local(&locaddr->ipaddr))) { !uip_is_addr_link_local(&locaddr->ipaddr)) {
n = get_match_length(dst, &(locaddr->ipaddr)); n = get_match_length(dst, &locaddr->ipaddr);
if(n >= best) { if(n >= best) {
best = n; best = n;
matchaddr = locaddr; matchaddr = locaddr;

View file

@ -373,7 +373,7 @@ uip_ds6_aaddr_t *uip_ds6_aaddr_lookup(uip_ipaddr_t *ipaddr);
/** @{ */ /** @{ */
uip_ds6_route_t *uip_ds6_route_lookup(uip_ipaddr_t *destipaddr); uip_ds6_route_t *uip_ds6_route_lookup(uip_ipaddr_t *destipaddr);
uip_ds6_route_t *uip_ds6_route_add(uip_ipaddr_t *ipaddr, uint8_t length, uip_ds6_route_t *uip_ds6_route_add(uip_ipaddr_t *ipaddr, uint8_t length,
uip_ipaddr_t *next_hop, u8_t metric); uip_ipaddr_t *next_hop, uint8_t metric);
void uip_ds6_route_rm(uip_ds6_route_t *route); void uip_ds6_route_rm(uip_ds6_route_t *route);
void uip_ds6_route_rm_by_nexthop(uip_ipaddr_t *nexthop); void uip_ds6_route_rm_by_nexthop(uip_ipaddr_t *nexthop);