Esempio n. 1
0
/*---------------------------------------------------------------------------*/
void
uip_ds6_neighbor_periodic(void)
{
  /* Periodic processing on neighbors */
  uip_ds6_nbr_t *nbr = nbr_table_head(ds6_neighbors);
  while(nbr != NULL) {
    switch(nbr->state) {
    case NBR_REACHABLE:
      if(stimer_expired(&nbr->reachable)) {
        PRINTF("REACHABLE: moving to STALE (");
        PRINT6ADDR(&nbr->ipaddr);
        PRINTF(")\n");
        nbr->state = NBR_STALE;
      }
      break;
#if UIP_ND6_SEND_NA
    case NBR_INCOMPLETE:
      if(nbr->nscount >= UIP_ND6_MAX_MULTICAST_SOLICIT) {
        uip_ds6_nbr_rm(nbr);
      } else if(stimer_expired(&nbr->sendns) && (uip_len == 0)) {
        nbr->nscount++;
        PRINTF("NBR_INCOMPLETE: NS %u\n", nbr->nscount);
        uip_nd6_ns_output(NULL, NULL, &nbr->ipaddr);
        stimer_set(&nbr->sendns, uip_ds6_if.retrans_timer / 1000);
      }
      break;
    case NBR_DELAY:
      if(stimer_expired(&nbr->reachable)) {
        nbr->state = NBR_PROBE;
        nbr->nscount = 0;
        PRINTF("DELAY: moving to PROBE\n");
        stimer_set(&nbr->sendns, 0);
      }
      break;
    case NBR_PROBE:
      if(nbr->nscount >= UIP_ND6_MAX_UNICAST_SOLICIT) {
        uip_ds6_defrt_t *locdefrt;
        PRINTF("PROBE END\n");
        if((locdefrt = uip_ds6_defrt_lookup(&nbr->ipaddr)) != NULL) {
          if (!locdefrt->isinfinite) {
            uip_ds6_defrt_rm(locdefrt);
          }
        }
        uip_ds6_nbr_rm(nbr);
      } else if(stimer_expired(&nbr->sendns) && (uip_len == 0)) {
        nbr->nscount++;
        PRINTF("PROBE: NS %u\n", nbr->nscount);
        uip_nd6_ns_output(NULL, &nbr->ipaddr, &nbr->ipaddr);
        stimer_set(&nbr->sendns, uip_ds6_if.retrans_timer / 1000);
      }
      break;
#endif /* UIP_ND6_SEND_NA */
    default:
      break;
    }
    nbr = nbr_table_next(ds6_neighbors, nbr);
  }
}
Esempio n. 2
0
static httpd_cgi_call_t *
webserver_network_nbr_rm(struct httpd_state *s)
{
  uip_ds6_nbr_t *neighbor;
  uip_ipaddr_t ipaddr;
  webserver_result_title = "Network";
  webserver_result_text = "Delete neighbor: Neighbor not found";
  if(s->query && uiplib_ipaddrconv(s->query, &ipaddr) != 0) {
    neighbor = uip_ds6_nbr_lookup(&ipaddr);
    if (neighbor) {
      uip_ds6_nbr_rm(neighbor);
      webserver_result_text = "Neighbor deleted";
    }
  }
  return &webserver_result_page;
}
Esempio n. 3
0
/*---------------------------------------------------------------------------*/
static void
rs_input(void)
{

    PRINTF("Received RS from");
    PRINT6ADDR(&UIP_IP_BUF->srcipaddr);
    PRINTF("to");
    PRINT6ADDR(&UIP_IP_BUF->destipaddr);
    PRINTF("\n");
    UIP_STAT(++uip_stat.nd6.recv);


#if UIP_CONF_IPV6_CHECKS
    /*
     * Check hop limit / icmp code
     * target address must not be multicast
     * if the NA is solicited, dest must not be multicast
     */
    if((UIP_IP_BUF->ttl != UIP_ND6_HOP_LIMIT) || (UIP_ICMP_BUF->icode != 0)) {
        PRINTF("RS received is bad\n");
        goto discard;
    }
#endif /*UIP_CONF_IPV6_CHECKS */

    /* Only valid option is Source Link-Layer Address option any thing
       else is discarded */
    nd6_opt_offset = UIP_ND6_RS_LEN;
    nd6_opt_llao = NULL;

    while(uip_l3_icmp_hdr_len + nd6_opt_offset < uip_len) {
#if UIP_CONF_IPV6_CHECKS
        if(UIP_ND6_OPT_HDR_BUF->len == 0) {
            PRINTF("RS received is bad\n");
            goto discard;
        }
#endif /*UIP_CONF_IPV6_CHECKS */
        switch (UIP_ND6_OPT_HDR_BUF->type) {
        case UIP_ND6_OPT_SLLAO:
            nd6_opt_llao = (uint8_t *)UIP_ND6_OPT_HDR_BUF;
            break;
        default:
            PRINTF("ND option not supported in RS\n");
            break;
        }
        nd6_opt_offset += (UIP_ND6_OPT_HDR_BUF->len << 3);
    }
    /* Options processing: only SLLAO */
    if(nd6_opt_llao != NULL) {
#if UIP_CONF_IPV6_CHECKS
        if(uip_is_addr_unspecified(&UIP_IP_BUF->srcipaddr)) {
            PRINTF("RS received is bad\n");
            goto discard;
        } else {
#endif /*UIP_CONF_IPV6_CHECKS */
            /* Copy link address to a uip_lladdr_t first
             * to ensure the second argument to uip_ds6_nbr_add is word-aligned */
            uip_lladdr_t lladdr;
            memcpy(&lladdr, &nd6_opt_llao[UIP_ND6_OPT_DATA_OFFSET], UIP_LLADDR_LEN);
            if((nbr = uip_ds6_nbr_lookup(&UIP_IP_BUF->srcipaddr)) == NULL) {
                /* we need to add the neighbor */
                uip_ds6_nbr_add(&UIP_IP_BUF->srcipaddr, &lladdr, 0, NBR_STALE);
            } else {
                /* If LL address changed, set neighbor state to stale */
                if(memcmp(&nd6_opt_llao[UIP_ND6_OPT_DATA_OFFSET],
                          uip_ds6_nbr_get_ll(nbr), UIP_LLADDR_LEN) != 0) {
                    uip_ds6_nbr_t nbr_data = *nbr;
                    uip_ds6_nbr_rm(nbr);
                    nbr = uip_ds6_nbr_add(&UIP_IP_BUF->srcipaddr, &lladdr, 0, NBR_STALE);
                    nbr->reachable = nbr_data.reachable;
                    nbr->sendns = nbr_data.sendns;
                    nbr->nscount = nbr_data.nscount;
                }
                nbr->isrouter = 0;
            }
#if UIP_CONF_IPV6_CHECKS
        }
#endif /*UIP_CONF_IPV6_CHECKS */
    }

    /* Schedule a sollicited RA */
    uip_ds6_send_ra_sollicited();

discard:
    uip_clear_buf();
    return;
}
Esempio n. 4
0
/*---------------------------------------------------------------------------*/
uip_ds6_nbr_t *
uip_ds6_nbr_add(uip_ipaddr_t *ipaddr, uip_lladdr_t *lladdr,
                uint8_t isrouter, uint8_t state)
{
  int r;

  r = uip_ds6_list_loop
     ((uip_ds6_element_t *)uip_ds6_nbr_cache, UIP_DS6_NBR_NB,
      sizeof(uip_ds6_nbr_t), ipaddr, 128,
      (uip_ds6_element_t **)&locnbr);

  if(r == FREESPACE) {
    locnbr->isused = 1;
    uip_ipaddr_copy(&locnbr->ipaddr, ipaddr);
    if(lladdr != NULL) {
      memcpy(&locnbr->lladdr, lladdr, UIP_LLADDR_LEN);
    } else {
      memset(&locnbr->lladdr, 0, UIP_LLADDR_LEN);
    }
    locnbr->isrouter = isrouter;
    locnbr->state = state;
#if UIP_CONF_IPV6_QUEUE_PKT
    uip_packetqueue_new(&locnbr->packethandle);
#endif /* UIP_CONF_IPV6_QUEUE_PKT */
    /* timers are set separately, for now we put them in expired state */
    stimer_set(&locnbr->reachable, 0);
    stimer_set(&locnbr->sendns, 0);
    locnbr->nscount = 0;
    PRINTF("Adding neighbor with ip addr ");
    PRINT6ADDR(ipaddr);
    PRINTF("link addr ");
    PRINTLLADDR((&(locnbr->lladdr)));
    PRINTF("state %u\n", state);
    NEIGHBOR_STATE_CHANGED(locnbr);

    locnbr->last_lookup = clock_time();
    return locnbr;
  } else if(r == NOSPACE) {
    /* We did not find any empty slot on the neighbor list, so we need
       to remove one old entry to make room. */
    uip_ds6_nbr_t *n, *oldest;
    clock_time_t oldest_time;

    oldest = NULL;
    oldest_time = clock_time();

    for(n = uip_ds6_nbr_cache;
        n < &uip_ds6_nbr_cache[UIP_DS6_NBR_NB];
        n++) {
      if(n->isused) {
        if(n->last_lookup < oldest_time) {
          oldest = n;
          oldest_time = n->last_lookup;
        }
      }
    }
    if(oldest != NULL) {
      uip_ds6_nbr_rm(oldest);
      return uip_ds6_nbr_add(ipaddr, lladdr, isrouter, state);
    }
  }
  PRINTF("uip_ds6_nbr_add drop\n");
  return NULL;
}
Esempio n. 5
0
/*---------------------------------------------------------------------------*/
void
uip_ds6_periodic(void)
{

  /* Periodic processing on unicast addresses */
  for(locaddr = uip_ds6_if.addr_list;
      locaddr < uip_ds6_if.addr_list + UIP_DS6_ADDR_NB; locaddr++) {
    if(locaddr->isused) {
      if((!locaddr->isinfinite) && (stimer_expired(&locaddr->vlifetime))) {
        uip_ds6_addr_rm(locaddr);
#if UIP_ND6_DEF_MAXDADNS > 0
      } else if((locaddr->state == ADDR_TENTATIVE)
                && (locaddr->dadnscount <= uip_ds6_if.maxdadns)
                && (timer_expired(&locaddr->dadtimer))
                && (uip_len == 0)) {
        uip_ds6_dad(locaddr);
#endif /* UIP_ND6_DEF_MAXDADNS > 0 */
      }
    }
  }

  /* Periodic processing on default routers */
  for(locdefrt = uip_ds6_defrt_list;
      locdefrt < uip_ds6_defrt_list + UIP_DS6_DEFRT_NB; locdefrt++) {
    if((locdefrt->isused) && (!locdefrt->isinfinite) &&
       (stimer_expired(&(locdefrt->lifetime)))) {
      uip_ds6_defrt_rm(locdefrt);
    }
  }

#if !UIP_CONF_ROUTER
  /* Periodic processing on prefixes */
  for(locprefix = uip_ds6_prefix_list;
      locprefix < uip_ds6_prefix_list + UIP_DS6_PREFIX_NB;
      locprefix++) {
    if(locprefix->isused && !locprefix->isinfinite
       && stimer_expired(&(locprefix->vlifetime))) {
      uip_ds6_prefix_rm(locprefix);
    }
  }
#endif /* !UIP_CONF_ROUTER */

  /* Periodic processing on neighbors */
  for(locnbr = uip_ds6_nbr_cache;
      locnbr < uip_ds6_nbr_cache + UIP_DS6_NBR_NB;
      locnbr++) {
    if(locnbr->isused) {
      switch(locnbr->state) {
      case NBR_INCOMPLETE:
        if(locnbr->nscount >= UIP_ND6_MAX_MULTICAST_SOLICIT) {
          uip_ds6_nbr_rm(locnbr);
        } else if(stimer_expired(&locnbr->sendns) && (uip_len == 0)) {
          locnbr->nscount++;
          PRINTF("NBR_INCOMPLETE: NS %u\n", locnbr->nscount);
          uip_nd6_ns_output(NULL, NULL, &locnbr->ipaddr);
          stimer_set(&locnbr->sendns, uip_ds6_if.retrans_timer / 1000);
        }
        break;
      case NBR_REACHABLE:
        if(stimer_expired(&locnbr->reachable)) {
          PRINTF("REACHABLE: moving to STALE (");
          PRINT6ADDR(&locnbr->ipaddr);
          PRINTF(")\n");
          locnbr->state = NBR_STALE;
        }
        break;
      case NBR_DELAY:
        if(stimer_expired(&locnbr->reachable)) {
          locnbr->state = NBR_PROBE;
          locnbr->nscount = 0;
          PRINTF("DELAY: moving to PROBE\n");
          stimer_set(&locnbr->sendns, 0);
        }
        break;
      case NBR_PROBE:
        if(locnbr->nscount >= UIP_ND6_MAX_UNICAST_SOLICIT) {
          PRINTF("PROBE END\n");
          if((locdefrt = uip_ds6_defrt_lookup(&locnbr->ipaddr)) != NULL) {
            if (!locdefrt->isinfinite) {
              uip_ds6_defrt_rm(locdefrt);
            }
          }
          uip_ds6_nbr_rm(locnbr);
        } else if(stimer_expired(&locnbr->sendns) && (uip_len == 0)) {
          locnbr->nscount++;
          PRINTF("PROBE: NS %u\n", locnbr->nscount);
          uip_nd6_ns_output(NULL, &locnbr->ipaddr, &locnbr->ipaddr);
          stimer_set(&locnbr->sendns, uip_ds6_if.retrans_timer / 1000);
        }
        break;
      default:
        break;
      }
    }
  }

#if UIP_CONF_ROUTER & UIP_ND6_SEND_RA
  /* Periodic RA sending */
  if(stimer_expired(&uip_ds6_timer_ra) && (uip_len == 0)) {
    uip_ds6_send_ra_periodic();
  }
#endif /* UIP_CONF_ROUTER & UIP_ND6_SEND_RA */
  etimer_reset(&uip_ds6_timer_periodic);
  return;
}
Esempio n. 6
0
/** Periodic processing on neighbors */
void
uip_ds6_neighbor_periodic(void)
{
  uip_ds6_nbr_t *nbr = nbr_table_head(ds6_neighbors);
  while(nbr != NULL) {
    switch(nbr->state) {
    case NBR_REACHABLE:
      if(stimer_expired(&nbr->reachable)) {
#if UIP_CONF_IPV6_RPL
        /* when a neighbor leave its REACHABLE state and is a default router,
           instead of going to STALE state it enters DELAY state in order to
           force a NUD on it. Otherwise, if there is no upward traffic, the
           node never knows if the default router is still reachable. This
           mimics the 6LoWPAN-ND behavior.
         */
        if(uip_ds6_defrt_lookup(&nbr->ipaddr) != NULL) {
          PRINTF("REACHABLE: defrt moving to DELAY (");
          PRINT6ADDR(&nbr->ipaddr);
          PRINTF(")\n");
          nbr->state = NBR_DELAY;
          stimer_set(&nbr->reachable, UIP_ND6_DELAY_FIRST_PROBE_TIME);
          nbr->nscount = 0;
        } else {
          PRINTF("REACHABLE: moving to STALE (");
          PRINT6ADDR(&nbr->ipaddr);
          PRINTF(")\n");
          nbr->state = NBR_STALE;
        }
#else /* UIP_CONF_IPV6_RPL */
        PRINTF("REACHABLE: moving to STALE (");
        PRINT6ADDR(&nbr->ipaddr);
        PRINTF(")\n");
        nbr->state = NBR_STALE;
#endif /* UIP_CONF_IPV6_RPL */
      }
      break;
    case NBR_INCOMPLETE:
      if(nbr->nscount >= UIP_ND6_MAX_MULTICAST_SOLICIT) {
        uip_ds6_nbr_rm(nbr);
      } else if(stimer_expired(&nbr->sendns) && (uip_len == 0)) {
        nbr->nscount++;
        PRINTF("NBR_INCOMPLETE: NS %u\n", nbr->nscount);
        uip_nd6_ns_output(NULL, NULL, &nbr->ipaddr);
        stimer_set(&nbr->sendns, uip_ds6_if.retrans_timer / 1000);
      }
      break;
    case NBR_DELAY:
      if(stimer_expired(&nbr->reachable)) {
        nbr->state = NBR_PROBE;
        nbr->nscount = 0;
        PRINTF("DELAY: moving to PROBE\n");
        stimer_set(&nbr->sendns, 0);
      }
      break;
    case NBR_PROBE:
      if(nbr->nscount >= UIP_ND6_MAX_UNICAST_SOLICIT) {
        uip_ds6_defrt_t *locdefrt;
        PRINTF("PROBE END\n");
        if((locdefrt = uip_ds6_defrt_lookup(&nbr->ipaddr)) != NULL) {
          if (!locdefrt->isinfinite) {
            uip_ds6_defrt_rm(locdefrt);
          }
        }
        uip_ds6_nbr_rm(nbr);
      } else if(stimer_expired(&nbr->sendns) && (uip_len == 0)) {
        nbr->nscount++;
        PRINTF("PROBE: NS %u\n", nbr->nscount);
        uip_nd6_ns_output(NULL, &nbr->ipaddr, &nbr->ipaddr);
        stimer_set(&nbr->sendns, uip_ds6_if.retrans_timer / 1000);
      }
      break;
    default:
      break;
    }
    nbr = nbr_table_next(ds6_neighbors, nbr);
  }
}
Esempio n. 7
0
/*---------------------------------------------------------------------------*/
httpd_simple_script_t
httpd_simple_get_script(const char *name)
{
  static uip_ds6_route_t *r;
  static char filename[HTTPD_PATHLEN];
  static int i;

  strcpy(filename, slip_config_www_root);
  strcat(filename, "/");
  strcat(filename, name);

  redirect = 0;

  if(strcmp(name, "index.html") == 0 || strcmp(name, "") == 0) {
    return generate_index;
#if CONTIKI_TARGET_NATIVE
  } else if (access(filename, R_OK) == 0) {
      return send_file;
#endif
#if CETIC_NODE_INFO
  } else if(strcmp(name, "sensors.html") == 0) {
    return generate_sensors;
#endif
  } else if(strcmp(name, "rpl.html") == 0) {
    return generate_rpl;
  } else if(strcmp(name, "network.html") == 0) {
    return generate_network;
  } else if(strcmp(name, "config.html") == 0) {
    return generate_config;
  } else if(strcmp(name, "statistics.html") == 0) {
    return generate_statistics;
  } else if ((nvm_data.global_flags & CETIC_GLOBAL_DISABLE_CONFIG) == 0) {
    if(strcmp(name, "rpl-gr") == 0) {
#if UIP_CONF_IPV6_RPL
      rpl_repair_root(RPL_DEFAULT_INSTANCE);
#endif
      return generate_rpl;
    } else if(memcmp(name, "route_rm?", 9) == 0) {
      redirect = 1;
      i = atoi(name + 9);
      for(r = uip_ds6_route_list_head(); r != NULL; r = list_item_next(r), --i) {
        if(i == 0) {
          uip_ds6_route_rm(r);
          break;
        }
      }
      return generate_network;
    } else if(memcmp(name, "nbr_rm?", 7) == 0) {
      redirect = 1;
      uip_ds6_nbr_rm(&uip_ds6_nbr_cache[atoi(name + 7)]);
      return generate_network;
    } else if(memcmp(name, "config?", 7) == 0) {
      if(update_config(name + 7)) {
        return generate_config;
      } else {
        return generate_reboot;
      }
    } else {
      return generate_404;
    }
  } else {
    return generate_404;
  }
}
Esempio n. 8
0
/*---------------------------------------------------------------------------*/
uip_ds6_nbr_t *
uip_ds6_nbr_add(uip_ipaddr_t * ipaddr, uip_lladdr_t * lladdr,
                u8_t isrouter, u8_t state)
{
  int r;

  r = uip_ds6_list_loop
     ((uip_ds6_element_t *) uip_ds6_nbr_cache, UIP_DS6_NBR_NB,
      sizeof(uip_ds6_nbr_t), ipaddr, 128,
      (uip_ds6_element_t **) &locnbr);
  //  printf("r %d\n", r);

  if(r == FREESPACE) {
    locnbr->isused = 1;
    uip_ipaddr_copy(&(locnbr->ipaddr), ipaddr);
    if(lladdr != NULL) {
      memcpy(&(locnbr->lladdr), lladdr, UIP_LLADDR_LEN);
    } else {
      memset(&(locnbr->lladdr), 0, UIP_LLADDR_LEN);
    }
    locnbr->isrouter = isrouter;
    locnbr->state = state;
    /* timers are set separately, for now we put them in expired state */
    stimer_set(&(locnbr->reachable), 0);
    stimer_set(&(locnbr->sendns), 0);
    locnbr->nscount = 0;
    PRINTF("Adding neighbor with ip addr");
    PRINT6ADDR(ipaddr);
    PRINTF("link addr");
    PRINTLLADDR((&(locnbr->lladdr)));
    PRINTF("state %u\n", state);
    NEIGHBOR_STATE_CHANGED(locnbr);

    locnbr->last_lookup = clock_time();
    //    printf("add %p\n", locnbr);
    return locnbr;
  } else if(r == NOSPACE) {
    /* We did not find any empty slot on the neighbor list, so we need
       to remove one old entry to make room. */
    uip_ds6_nbr_t *n, *oldest;
    clock_time_t oldest_time;

    oldest = NULL;
    oldest_time = clock_time();

    for(n = uip_ds6_nbr_cache;
        n < &uip_ds6_nbr_cache[UIP_DS6_NBR_NB];
        n++) {
      if(n->isused) {
        if((n->last_lookup < oldest_time) && (uip_ds6_is_nbr_garbage_collectible(n))) {
        	/* We do not want to remove any non-garbage-collectible entry */
          oldest = n;
          oldest_time = n->last_lookup;
        }
      }
    }
    if(oldest != NULL) {
      //      printf("rm3\n");
      uip_ds6_nbr_rm(oldest);
      locdefrt = uip_ds6_defrt_lookup(&oldest->ipaddr);
      uip_ds6_defrt_rm(locdefrt);
      uip_ds6_reg_cleanup_defrt(locdefrt);
			return uip_ds6_nbr_add(ipaddr, lladdr, isrouter, state);
    }
  }
  PRINTF("uip_ds6_nbr_add drop\n");
  return NULL;
}
Esempio n. 9
0
/*---------------------------------------------------------------------------*/
void
uip_ds6_periodic(void)
{
	/* This flag signals whether we allow or not to send a packet in the current 
	 * invocation. */
  u8_t allow_output = 1;

  /* minimum lifetime */
  min_lifetime = 0xFFFFFFFF;
  /* router with minimum lifetime */
  min_defrt = NULL;
	
	/* Periodic processing on registrations */
	for(locreg = uip_ds6_reg_list;
      locreg < uip_ds6_reg_list + UIP_DS6_REG_LIST_SIZE; locreg++) {
  	if (locreg->isused) {
  		if (stimer_expired(&locreg->reg_lifetime)) {
  			uip_ds6_reg_rm(locreg);
  		} else if (allow_output) {
  			/* If no output is allowed, it is pointless to enter here in this invocation */
  			if (uip_ds6_if.registration_in_progress) {
  				/* There is a registration in progress */
  				if ((locreg == uip_ds6_if.registration_in_progress) && 
  						(timer_expired(&locreg->registration_timer))) {
	      		/* We already sent a NS message for this address but there has been no response */
	      		if(locreg->reg_count >= UIP_ND6_MAX_UNICAST_SOLICIT) {
			  			/* NUD failed. Signal the need for next-hop determination by deleting the 
			   			 * NCE (RFC 4861) */
			   			uip_ds6_reg_rm(locreg); 
			  			/* And then, delete neighbor and corresponding router (as hosts only keep
			  			 * NCEs for routers in 6lowpan-nd) */ 
			  			locnbr = uip_ds6_nbr_lookup(&locreg->defrt->ipaddr); 
			  			uip_ds6_nbr_rm(locnbr);
			  			uip_ds6_defrt_rm(locreg->defrt);
			  			/* Since we are deleting a default router, we must delete also all 
			  			 * registrations with that router.
			  			 * Be careful here, uip_ds6_reg_cleanup_defrt() modifies the value of locreg!*/
			  			uip_ds6_reg_cleanup_defrt(locreg->defrt);
		      		/* We will also need to start sending RS, as specified in I-D.ietf-6lowpan-nd 
		      		 * for NUD failure case */
		      		uip_ds6_send_rs(NULL);
		      		uip_ds6_if.registration_in_progress = NULL;
  					} else {
  						locreg->reg_count++;
		      		timer_restart(&locreg->registration_timer);
		   	 			uip_nd6_ns_output(&locreg->addr->ipaddr, &locreg->defrt->ipaddr, 
		          			            &locreg->defrt->ipaddr, 1, UIP_ND6_REGISTRATION_LIFETIME);
 						}
  					allow_output = 0; /* Prevent this invocation from sending anything else */
  				}
  			} else {
  				/* There are no registrations in progress, let's see this entry needs (re)registration
  				 * or deletion */
  				if ((locreg->state == REG_GARBAGE_COLLECTIBLE) || 
  						(locreg->state == REG_TO_BE_UNREGISTERED) || 
  						((locreg->state == REG_REGISTERED) && 
	 						(stimer_remaining(&locreg->reg_lifetime) < stimer_elapsed(&locreg->reg_lifetime)))) {
 						/* Issue (re)registration */
				  	uip_ds6_if.registration_in_progress = locreg;
				  	locreg->reg_count++;
				  	timer_set(&locreg->registration_timer, (uip_ds6_if.retrans_timer / 1000) * (CLOCK_SECOND /* FIXME @@@jwg!!!!*/+250));
				  	if (locreg->state == REG_TO_BE_UNREGISTERED) {
					  	uip_nd6_ns_output(&locreg->addr->ipaddr, &locreg->defrt->ipaddr, 
				      	   			        &locreg->defrt->ipaddr, 1, 0);
				  	} else {
				  		uip_nd6_ns_output(&locreg->addr->ipaddr, &locreg->defrt->ipaddr, 
				      	   			        &locreg->defrt->ipaddr, 1, UIP_ND6_REGISTRATION_LIFETIME);
				  	}   	   			       
			      allow_output = 0; /* Prevent this invocation from sending anything else */
  				}
  			}
  		}
  	}
  }

  
  /* Periodic processing on unicast addresses */
  for(locaddr = uip_ds6_if.addr_list;
      locaddr < uip_ds6_if.addr_list + UIP_DS6_ADDR_NB; locaddr++) {
    if(locaddr->isused) {
      if((!locaddr->isinfinite) && (stimer_expired(&locaddr->vlifetime))) {
        uip_ds6_addr_rm(locaddr);
      } else if (allow_output) {
        if (stimer_remaining(&locaddr->vlifetime) < min_lifetime) {
          min_lifetime = stimer_remaining(&locaddr->vlifetime);
          min_defrt = locaddr->defrt;
        }
      }
    }
  }
  
  /* Periodic processing on default routers */
	if (uip_ds6_defrt_choose() == NULL) {
	  if (allow_output) {
	    /* If default router list is empty, start sending RS */
	    uip_ds6_send_rs(NULL);
	    allow_output = 0; /* Prevent this invocation from sending anything else */
	  }
	} else {
    for(locdefrt = uip_ds6_defrt_list;
        locdefrt < uip_ds6_defrt_list + UIP_DS6_DEFRT_NB; locdefrt++) {
      if((locdefrt->isused) && (!locdefrt->isinfinite)) {
        if (stimer_expired(&(locdefrt->lifetime))) {
          uip_ds6_defrt_rm(locdefrt);
          /* If default router list is empty, we will start sending RS in
           * the next invocation of ds6_periodic() */
        } else {
          if (allow_output) {
            if (stimer_remaining(&locdefrt->lifetime) < min_lifetime) {
              min_lifetime = stimer_remaining(&locdefrt->lifetime);
              min_defrt = locdefrt;
            }
          }
        }
      }
    }
	}
	
#if !UIP_CONF_ROUTER
  /* Periodic processing on prefixes */
  for (locprefix = uip_ds6_prefix_list;
      locprefix < uip_ds6_prefix_list + UIP_DS6_PREFIX_NB; locprefix++) {
    if((locprefix->isused) && (!locprefix->isinfinite)) {
    	if (stimer_expired(&locprefix->vlifetime)) {
      	uip_ds6_prefix_rm(locprefix);
    	} else if (allow_output) {
    		if (stimer_remaining(&locprefix->vlifetime) < min_lifetime) {
    			min_lifetime = stimer_remaining(&locprefix->vlifetime);
    			min_defrt = locprefix->defrt;
    		}
    	}
    }
  }
#endif /* !UIP_CONF_ROUTER */

#if CONF_6LOWPAN_ND_6CO
	/* Periodic processing on contexts */
  for(loccontext = uip_ds6_addr_context_table;
      loccontext < uip_ds6_addr_context_table + SICSLOWPAN_CONF_MAX_ADDR_CONTEXTS; loccontext++) {
    if(loccontext->state != NOT_IN_USE) {
    	if (stimer_expired(&loccontext->vlifetime)) {
    		if (loccontext->state != EXPIRED) {
    			loccontext->state = IN_USE_UNCOMPRESS_ONLY;
    			stimer_set(&loccontext->vlifetime, 2 * loccontext->defrt_lifetime);
    		} else {
      		uip_ds6_context_rm(loccontext);
    		}
    	} else if (allow_output) {
    		if (stimer_remaining(&loccontext->vlifetime) < min_lifetime) {
    			min_lifetime = stimer_remaining(&loccontext->vlifetime);
    			min_defrt = loccontext->defrt;
    		}
    	}
    }
  }
#endif /* CONF_6LOWPAN_ND_6CO */

	/* Start sending RS well before the minimum of the lifetimes (def. router, 
	 * context, or prefix) expires */
	if ((allow_output) && (min_lifetime < UIP_DS6_LIFETIME_THRESHOLD)) {
	  /* Start sending RSs to the router with minimum lifetime (if possible) */
		uip_ds6_send_rs(min_defrt);
		allow_output = 0;
	}

  /* Periodic processing on neighbors */
  for(locnbr = uip_ds6_nbr_cache; locnbr < uip_ds6_nbr_cache + UIP_DS6_NBR_NB;
      locnbr++) {
    if(locnbr->isused) {
      switch (locnbr->state) {
#if UIP_CONF_ROUTER
/* There can not be INCOMPLETE NCEs in a host in 6lowpan-nd */
      case NBR_INCOMPLETE:
    		if (allow_output) {  
	        if(locnbr->nscount >= UIP_ND6_MAX_MULTICAST_SOLICIT) {
	          uip_ds6_nbr_rm(locnbr);
	        } else if(stimer_expired(&(locnbr->sendns))) {
	          locnbr->nscount++;
	          PRINTF("NBR_INCOMPLETE: NS %u\n", locnbr->nscount);
	          uip_nd6_ns_output(NULL, NULL, &locnbr->ipaddr);
	          stimer_set(&(locnbr->sendns), uip_ds6_if.retrans_timer / 1000);
						allow_output = 0;
	        }
    		}  
        break;
#endif /* UIP_CONF_ROUTER */
      case NBR_REACHABLE:
        if(stimer_expired(&(locnbr->reachable))) {
          PRINTF("REACHABLE: moving to STALE (");
          PRINT6ADDR(&locnbr->ipaddr);
          PRINTF(")\n");
          locnbr->state = NBR_STALE;
          NEIGHBOR_STATE_CHANGED(locnbr);
        }
        break;
      case NBR_DELAY:
    		if (allow_output) {  
	        if(stimer_expired(&(locnbr->reachable))) {
	          locnbr->state = NBR_PROBE;
	          locnbr->nscount = 1;
	          NEIGHBOR_STATE_CHANGED(locnbr);
	          PRINTF("DELAY: moving to PROBE + NS %u\n", locnbr->nscount);
	          uip_nd6_ns_output(NULL, &locnbr->ipaddr, &locnbr->ipaddr, 0, 0);
	          stimer_set(&(locnbr->sendns), uip_ds6_if.retrans_timer / 1000);
	          allow_output = 0;
	        }
    		}  
        break;
      case NBR_PROBE:
    		if (allow_output) {  
	        if(locnbr->nscount >= UIP_ND6_MAX_UNICAST_SOLICIT) {
	          PRINTF("PROBE END \n");
	          if((locdefrt = uip_ds6_defrt_lookup(&locnbr->ipaddr)) != NULL) {
	            uip_ds6_defrt_rm(locdefrt);
	          }
	          uip_ds6_nbr_rm(locnbr);
	        } else if(stimer_expired(&(locnbr->sendns))) {
	          locnbr->nscount++;
	          PRINTF("PROBE: NS %u\n", locnbr->nscount);
	          uip_nd6_ns_output(NULL, &locnbr->ipaddr, &locnbr->ipaddr, 0, 0);
	          stimer_set(&(locnbr->sendns), uip_ds6_if.retrans_timer / 1000);
	          allow_output = 0;
	        }
    		}  
        break;
      default:
        break;
      }
    }
  }

#if UIP_CONF_ROUTER & UIP_ND6_SEND_RA 
  /* Periodic RA sending */
  if(stimer_expired(&uip_ds6_timer_ra)) {
    uip_ds6_send_ra_periodic();
  }
#endif /* UIP_CONF_ROUTER & UIP_ND6_SEND_RA */
  etimer_reset(&uip_ds6_timer_periodic);
  return;
}