2010-03-12 16:19:19 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2006, Swedish Institute of Computer Science.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. Neither the name of the Institute nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
*/
|
2014-11-08 00:15:42 +00:00
|
|
|
|
|
|
|
/**
|
2017-09-29 20:18:48 +00:00
|
|
|
* \addtogroup uip
|
2015-02-15 18:02:07 +00:00
|
|
|
* @{
|
2014-11-08 00:15:42 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2015-02-15 18:02:07 +00:00
|
|
|
* \file
|
|
|
|
* IPv6 data structure manipulation.
|
|
|
|
* Comprises part of the Neighbor discovery (RFC 4861)
|
|
|
|
* and auto configuration (RFC 4862) state machines.
|
|
|
|
* \author Mathilde Durvy <mdurvy@cisco.com>
|
|
|
|
* \author Julien Abeille <jabeille@cisco.com>
|
2014-11-08 00:15:42 +00:00
|
|
|
*/
|
|
|
|
|
2010-03-12 16:19:19 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
2012-06-01 13:47:22 +00:00
|
|
|
#include <stddef.h>
|
2010-03-12 16:19:19 +00:00
|
|
|
#include "lib/random.h"
|
2013-11-22 08:17:54 +00:00
|
|
|
#include "net/ipv6/uip-nd6.h"
|
2017-12-10 15:19:27 +00:00
|
|
|
#include "net/ipv6/uip-ds6-nbr.h"
|
2013-11-22 08:17:54 +00:00
|
|
|
#include "net/ipv6/uip-ds6.h"
|
2016-06-20 14:35:09 +00:00
|
|
|
#include "net/ipv6/multicast/uip-mcast6.h"
|
2017-09-22 13:06:44 +00:00
|
|
|
#include "net/ipv6/uip-packetqueue.h"
|
2010-03-12 16:19:19 +00:00
|
|
|
|
2017-06-20 15:23:49 +00:00
|
|
|
/* Log configuration */
|
|
|
|
#include "sys/log.h"
|
2017-06-23 19:12:36 +00:00
|
|
|
#define LOG_MODULE "IPv6 DS"
|
2017-07-15 13:19:09 +00:00
|
|
|
#define LOG_LEVEL LOG_LEVEL_IPV6
|
2010-03-12 16:19:19 +00:00
|
|
|
|
2015-10-30 07:55:11 +00:00
|
|
|
struct etimer uip_ds6_timer_periodic; /**< Timer for maintenance of data structures */
|
2010-03-15 16:41:24 +00:00
|
|
|
|
2010-03-12 16:19:19 +00:00
|
|
|
#if UIP_CONF_ROUTER
|
2015-10-30 07:55:11 +00:00
|
|
|
struct stimer uip_ds6_timer_ra; /**< RA timer, to schedule RA sending */
|
2010-03-16 18:27:22 +00:00
|
|
|
#if UIP_ND6_SEND_RA
|
2015-10-30 07:55:11 +00:00
|
|
|
static uint8_t racount; /**< number of RA already sent */
|
|
|
|
static uint16_t rand_time; /**< random time value for timers */
|
2010-03-16 18:27:22 +00:00
|
|
|
#endif
|
2010-03-12 16:19:19 +00:00
|
|
|
#else /* UIP_CONF_ROUTER */
|
2015-10-30 07:55:11 +00:00
|
|
|
struct etimer uip_ds6_timer_rs; /**< RS timer, to schedule RS sending */
|
|
|
|
static uint8_t rscount; /**< number of rs already sent */
|
2010-03-12 16:19:19 +00:00
|
|
|
#endif /* UIP_CONF_ROUTER */
|
|
|
|
|
|
|
|
/** \name "DS6" Data structures */
|
|
|
|
/** @{ */
|
2015-10-30 07:55:11 +00:00
|
|
|
uip_ds6_netif_t uip_ds6_if; /**< The single interface */
|
|
|
|
uip_ds6_prefix_t uip_ds6_prefix_list[UIP_DS6_PREFIX_NB]; /**< Prefix list */
|
2010-03-15 16:41:24 +00:00
|
|
|
|
2012-06-01 13:47:22 +00:00
|
|
|
/* Used by Cooja to enable extraction of addresses from memory.*/
|
|
|
|
uint8_t uip_ds6_addr_size;
|
|
|
|
uint8_t uip_ds6_netif_addr_list_offset;
|
|
|
|
|
2010-03-12 16:19:19 +00:00
|
|
|
/** @} */
|
|
|
|
|
|
|
|
/* "full" (as opposed to pointer) ip address used in this file, */
|
2010-03-15 16:41:24 +00:00
|
|
|
static uip_ipaddr_t loc_fipaddr;
|
2010-03-12 16:19:19 +00:00
|
|
|
|
|
|
|
/* Pointers used in this file */
|
2010-03-15 16:41:24 +00:00
|
|
|
static uip_ds6_addr_t *locaddr;
|
|
|
|
static uip_ds6_maddr_t *locmaddr;
|
2015-10-04 20:32:12 +00:00
|
|
|
#if UIP_DS6_AADDR_NB
|
2010-03-15 16:41:24 +00:00
|
|
|
static uip_ds6_aaddr_t *locaaddr;
|
2015-10-04 20:32:12 +00:00
|
|
|
#endif /* UIP_DS6_AADDR_NB */
|
2010-03-15 16:41:24 +00:00
|
|
|
static uip_ds6_prefix_t *locprefix;
|
2010-03-12 16:19:19 +00:00
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
2010-03-15 16:41:24 +00:00
|
|
|
uip_ds6_init(void)
|
|
|
|
{
|
2012-11-26 18:53:38 +00:00
|
|
|
|
2013-07-03 17:32:26 +00:00
|
|
|
uip_ds6_neighbors_init();
|
2012-11-26 18:53:38 +00:00
|
|
|
uip_ds6_route_init();
|
|
|
|
|
2017-10-31 15:16:04 +00:00
|
|
|
LOG_INFO("Init: %u neighbors\n", NBR_TABLE_MAX_NEIGHBORS);
|
|
|
|
LOG_INFO("%u default routers\n", UIP_DS6_DEFRT_NB);
|
|
|
|
LOG_INFO("%u prefixes\n", UIP_DS6_PREFIX_NB);
|
|
|
|
LOG_INFO("%u routes\n", UIP_DS6_ROUTE_NB);
|
|
|
|
LOG_INFO("%u unicast addresses\n", UIP_DS6_ADDR_NB);
|
|
|
|
LOG_INFO("%u multicast addresses\n", UIP_DS6_MADDR_NB);
|
|
|
|
LOG_INFO("%u anycast addresses\n", UIP_DS6_AADDR_NB);
|
|
|
|
|
2010-06-14 13:51:13 +00:00
|
|
|
memset(uip_ds6_prefix_list, 0, sizeof(uip_ds6_prefix_list));
|
|
|
|
memset(&uip_ds6_if, 0, sizeof(uip_ds6_if));
|
2012-06-01 13:47:22 +00:00
|
|
|
uip_ds6_addr_size = sizeof(struct uip_ds6_addr);
|
|
|
|
uip_ds6_netif_addr_list_offset = offsetof(struct uip_ds6_netif, addr_list);
|
2010-03-15 16:41:24 +00:00
|
|
|
|
|
|
|
/* Set interface parameters */
|
2010-03-12 16:19:19 +00:00
|
|
|
uip_ds6_if.link_mtu = UIP_LINK_MTU;
|
|
|
|
uip_ds6_if.cur_hop_limit = UIP_TTL;
|
|
|
|
uip_ds6_if.base_reachable_time = UIP_ND6_REACHABLE_TIME;
|
|
|
|
uip_ds6_if.reachable_time = uip_ds6_compute_reachable_time();
|
|
|
|
uip_ds6_if.retrans_timer = UIP_ND6_RETRANS_TIMER;
|
|
|
|
uip_ds6_if.maxdadns = UIP_ND6_DEF_MAXDADNS;
|
|
|
|
|
|
|
|
/* Create link local address, prefix, multicast addresses, anycast addresses */
|
|
|
|
uip_create_linklocal_prefix(&loc_fipaddr);
|
|
|
|
#if UIP_CONF_ROUTER
|
|
|
|
uip_ds6_prefix_add(&loc_fipaddr, UIP_DEFAULT_PREFIX_LEN, 0, 0, 0, 0);
|
|
|
|
#else /* UIP_CONF_ROUTER */
|
|
|
|
uip_ds6_prefix_add(&loc_fipaddr, UIP_DEFAULT_PREFIX_LEN, 0);
|
|
|
|
#endif /* UIP_CONF_ROUTER */
|
|
|
|
uip_ds6_set_addr_iid(&loc_fipaddr, &uip_lladdr);
|
|
|
|
uip_ds6_addr_add(&loc_fipaddr, 0, ADDR_AUTOCONF);
|
|
|
|
|
|
|
|
uip_create_linklocal_allnodes_mcast(&loc_fipaddr);
|
|
|
|
uip_ds6_maddr_add(&loc_fipaddr);
|
|
|
|
#if UIP_CONF_ROUTER
|
|
|
|
uip_create_linklocal_allrouters_mcast(&loc_fipaddr);
|
|
|
|
uip_ds6_maddr_add(&loc_fipaddr);
|
|
|
|
#if UIP_ND6_SEND_RA
|
2010-03-15 16:41:24 +00:00
|
|
|
stimer_set(&uip_ds6_timer_ra, 2); /* wait to have a link local IP address */
|
2010-03-12 16:19:19 +00:00
|
|
|
#endif /* UIP_ND6_SEND_RA */
|
|
|
|
#else /* UIP_CONF_ROUTER */
|
2010-03-15 16:41:24 +00:00
|
|
|
etimer_set(&uip_ds6_timer_rs,
|
|
|
|
random_rand() % (UIP_ND6_MAX_RTR_SOLICITATION_DELAY *
|
|
|
|
CLOCK_SECOND));
|
2010-03-12 16:19:19 +00:00
|
|
|
#endif /* UIP_CONF_ROUTER */
|
|
|
|
etimer_set(&uip_ds6_timer_periodic, UIP_DS6_PERIOD);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
2010-03-15 16:41:24 +00:00
|
|
|
uip_ds6_periodic(void)
|
|
|
|
{
|
2011-07-11 11:24:17 +00:00
|
|
|
|
2010-03-12 16:19:19 +00:00
|
|
|
/* Periodic processing on unicast addresses */
|
2010-03-15 16:41:24 +00:00
|
|
|
for(locaddr = uip_ds6_if.addr_list;
|
|
|
|
locaddr < uip_ds6_if.addr_list + UIP_DS6_ADDR_NB; locaddr++) {
|
|
|
|
if(locaddr->isused) {
|
2010-03-12 16:19:19 +00:00
|
|
|
if((!locaddr->isinfinite) && (stimer_expired(&locaddr->vlifetime))) {
|
|
|
|
uip_ds6_addr_rm(locaddr);
|
2011-07-11 11:24:17 +00:00
|
|
|
#if UIP_ND6_DEF_MAXDADNS > 0
|
2010-03-15 16:41:24 +00:00
|
|
|
} else if((locaddr->state == ADDR_TENTATIVE)
|
|
|
|
&& (locaddr->dadnscount <= uip_ds6_if.maxdadns)
|
2012-02-01 16:55:41 +00:00
|
|
|
&& (timer_expired(&locaddr->dadtimer))
|
|
|
|
&& (uip_len == 0)) {
|
2010-03-12 16:19:19 +00:00
|
|
|
uip_ds6_dad(locaddr);
|
2011-07-11 11:24:17 +00:00
|
|
|
#endif /* UIP_ND6_DEF_MAXDADNS > 0 */
|
2010-03-12 16:19:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Periodic processing on default routers */
|
2012-11-26 18:53:38 +00:00
|
|
|
uip_ds6_defrt_periodic();
|
|
|
|
/* for(locdefrt = uip_ds6_defrt_list;
|
2010-03-15 16:41:24 +00:00
|
|
|
locdefrt < uip_ds6_defrt_list + UIP_DS6_DEFRT_NB; locdefrt++) {
|
2010-05-10 13:46:35 +00:00
|
|
|
if((locdefrt->isused) && (!locdefrt->isinfinite) &&
|
|
|
|
(stimer_expired(&(locdefrt->lifetime)))) {
|
2010-03-15 16:41:24 +00:00
|
|
|
uip_ds6_defrt_rm(locdefrt);
|
2010-03-12 16:19:19 +00:00
|
|
|
}
|
2012-11-26 18:53:38 +00:00
|
|
|
}*/
|
2010-03-12 16:19:19 +00:00
|
|
|
|
|
|
|
#if !UIP_CONF_ROUTER
|
|
|
|
/* Periodic processing on prefixes */
|
2010-03-15 16:41:24 +00:00
|
|
|
for(locprefix = uip_ds6_prefix_list;
|
2011-03-16 12:35:44 +00:00
|
|
|
locprefix < uip_ds6_prefix_list + UIP_DS6_PREFIX_NB;
|
|
|
|
locprefix++) {
|
|
|
|
if(locprefix->isused && !locprefix->isinfinite
|
|
|
|
&& stimer_expired(&(locprefix->vlifetime))) {
|
2010-03-12 16:19:19 +00:00
|
|
|
uip_ds6_prefix_rm(locprefix);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* !UIP_CONF_ROUTER */
|
|
|
|
|
2017-01-16 12:44:15 +00:00
|
|
|
#if UIP_ND6_SEND_NS
|
2013-07-03 17:32:26 +00:00
|
|
|
uip_ds6_neighbor_periodic();
|
2017-01-16 12:44:15 +00:00
|
|
|
#endif /* UIP_ND6_SEND_NS */
|
2010-03-12 16:19:19 +00:00
|
|
|
|
2014-12-03 15:35:36 +00:00
|
|
|
#if UIP_CONF_ROUTER && UIP_ND6_SEND_RA
|
2010-03-12 16:19:19 +00:00
|
|
|
/* Periodic RA sending */
|
2012-02-01 16:55:41 +00:00
|
|
|
if(stimer_expired(&uip_ds6_timer_ra) && (uip_len == 0)) {
|
2010-03-12 16:19:19 +00:00
|
|
|
uip_ds6_send_ra_periodic();
|
|
|
|
}
|
2014-12-03 15:35:36 +00:00
|
|
|
#endif /* UIP_CONF_ROUTER && UIP_ND6_SEND_RA */
|
2010-03-12 16:19:19 +00:00
|
|
|
etimer_reset(&uip_ds6_timer_periodic);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-03-15 16:41:24 +00:00
|
|
|
uint8_t
|
2011-03-16 12:35:44 +00:00
|
|
|
uip_ds6_list_loop(uip_ds6_element_t *list, uint8_t size,
|
|
|
|
uint16_t elementsize, uip_ipaddr_t *ipaddr,
|
|
|
|
uint8_t ipaddrlen, uip_ds6_element_t **out_element)
|
2010-03-15 16:41:24 +00:00
|
|
|
{
|
|
|
|
uip_ds6_element_t *element;
|
|
|
|
|
2017-06-10 12:35:39 +00:00
|
|
|
if(list == NULL || ipaddr == NULL || out_element == NULL) {
|
|
|
|
return NOSPACE;
|
|
|
|
}
|
|
|
|
|
2010-03-12 16:19:19 +00:00
|
|
|
*out_element = NULL;
|
|
|
|
|
2010-03-15 16:41:24 +00:00
|
|
|
for(element = list;
|
|
|
|
element <
|
2011-03-16 12:35:44 +00:00
|
|
|
(uip_ds6_element_t *)((uint8_t *)list + (size * elementsize));
|
|
|
|
element = (uip_ds6_element_t *)((uint8_t *)element + elementsize)) {
|
2010-03-12 16:19:19 +00:00
|
|
|
if(element->isused) {
|
2011-03-16 12:35:44 +00:00
|
|
|
if(uip_ipaddr_prefixcmp(&element->ipaddr, ipaddr, ipaddrlen)) {
|
2010-03-12 16:19:19 +00:00
|
|
|
*out_element = element;
|
|
|
|
return FOUND;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
*out_element = element;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-16 12:35:44 +00:00
|
|
|
return *out_element != NULL ? FREESPACE : NOSPACE;
|
2010-03-12 16:19:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
#if UIP_CONF_ROUTER
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-03-15 16:41:24 +00:00
|
|
|
uip_ds6_prefix_t *
|
2011-03-16 12:35:44 +00:00
|
|
|
uip_ds6_prefix_add(uip_ipaddr_t *ipaddr, uint8_t ipaddrlen,
|
2010-03-15 16:41:24 +00:00
|
|
|
uint8_t advertise, uint8_t flags, unsigned long vtime,
|
|
|
|
unsigned long ptime)
|
|
|
|
{
|
|
|
|
if(uip_ds6_list_loop
|
2011-03-16 12:35:44 +00:00
|
|
|
((uip_ds6_element_t *)uip_ds6_prefix_list, UIP_DS6_PREFIX_NB,
|
2010-03-15 16:41:24 +00:00
|
|
|
sizeof(uip_ds6_prefix_t), ipaddr, ipaddrlen,
|
2011-03-16 12:35:44 +00:00
|
|
|
(uip_ds6_element_t **)&locprefix) == FREESPACE) {
|
2010-03-12 16:19:19 +00:00
|
|
|
locprefix->isused = 1;
|
2011-03-16 12:35:44 +00:00
|
|
|
uip_ipaddr_copy(&locprefix->ipaddr, ipaddr);
|
2010-03-12 16:19:19 +00:00
|
|
|
locprefix->length = ipaddrlen;
|
|
|
|
locprefix->advertise = advertise;
|
|
|
|
locprefix->l_a_reserved = flags;
|
|
|
|
locprefix->vlifetime = vtime;
|
|
|
|
locprefix->plifetime = ptime;
|
2017-06-20 15:23:49 +00:00
|
|
|
LOG_INFO("Adding prefix ");
|
|
|
|
LOG_INFO_6ADDR(&locprefix->ipaddr);
|
2017-06-23 07:21:31 +00:00
|
|
|
LOG_INFO_("length %u, flags %x, Valid lifetime %lx, Preffered lifetime %lx\n",
|
2010-03-15 16:41:24 +00:00
|
|
|
ipaddrlen, flags, vtime, ptime);
|
2010-03-12 16:19:19 +00:00
|
|
|
return locprefix;
|
|
|
|
} else {
|
2017-06-20 15:23:49 +00:00
|
|
|
LOG_INFO("No more space in Prefix list\n");
|
2010-03-12 16:19:19 +00:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#else /* UIP_CONF_ROUTER */
|
2010-03-15 16:41:24 +00:00
|
|
|
uip_ds6_prefix_t *
|
2011-03-16 12:35:44 +00:00
|
|
|
uip_ds6_prefix_add(uip_ipaddr_t *ipaddr, uint8_t ipaddrlen,
|
2010-03-15 16:41:24 +00:00
|
|
|
unsigned long interval)
|
|
|
|
{
|
|
|
|
if(uip_ds6_list_loop
|
2011-03-16 12:35:44 +00:00
|
|
|
((uip_ds6_element_t *)uip_ds6_prefix_list, UIP_DS6_PREFIX_NB,
|
2010-03-15 16:41:24 +00:00
|
|
|
sizeof(uip_ds6_prefix_t), ipaddr, ipaddrlen,
|
2011-03-16 12:35:44 +00:00
|
|
|
(uip_ds6_element_t **)&locprefix) == FREESPACE) {
|
2010-03-12 16:19:19 +00:00
|
|
|
locprefix->isused = 1;
|
2011-03-16 12:35:44 +00:00
|
|
|
uip_ipaddr_copy(&locprefix->ipaddr, ipaddr);
|
2010-03-12 16:19:19 +00:00
|
|
|
locprefix->length = ipaddrlen;
|
2010-03-15 16:41:24 +00:00
|
|
|
if(interval != 0) {
|
|
|
|
stimer_set(&(locprefix->vlifetime), interval);
|
2010-03-12 16:19:19 +00:00
|
|
|
locprefix->isinfinite = 0;
|
|
|
|
} else {
|
|
|
|
locprefix->isinfinite = 1;
|
|
|
|
}
|
2017-06-20 15:23:49 +00:00
|
|
|
LOG_INFO("Adding prefix ");
|
|
|
|
LOG_INFO_6ADDR(&locprefix->ipaddr);
|
2017-06-23 07:21:31 +00:00
|
|
|
LOG_INFO_("length %u, vlifetime %lu\n", ipaddrlen, interval);
|
2014-06-17 09:38:07 +00:00
|
|
|
return locprefix;
|
2010-03-12 16:19:19 +00:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
#endif /* UIP_CONF_ROUTER */
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
2012-04-21 22:31:56 +00:00
|
|
|
uip_ds6_prefix_rm(uip_ds6_prefix_t *prefix)
|
2010-03-15 16:41:24 +00:00
|
|
|
{
|
2010-03-12 16:19:19 +00:00
|
|
|
if(prefix != NULL) {
|
|
|
|
prefix->isused = 0;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-03-15 16:41:24 +00:00
|
|
|
uip_ds6_prefix_t *
|
2011-03-16 12:35:44 +00:00
|
|
|
uip_ds6_prefix_lookup(uip_ipaddr_t *ipaddr, uint8_t ipaddrlen)
|
2010-03-15 16:41:24 +00:00
|
|
|
{
|
2010-03-23 14:21:04 +00:00
|
|
|
if(uip_ds6_list_loop((uip_ds6_element_t *)uip_ds6_prefix_list,
|
2015-10-30 10:41:59 +00:00
|
|
|
UIP_DS6_PREFIX_NB, sizeof(uip_ds6_prefix_t),
|
|
|
|
ipaddr, ipaddrlen,
|
|
|
|
(uip_ds6_element_t **)&locprefix) == FOUND) {
|
2010-03-12 16:19:19 +00:00
|
|
|
return locprefix;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-03-15 16:41:24 +00:00
|
|
|
uint8_t
|
2011-03-16 12:35:44 +00:00
|
|
|
uip_ds6_is_addr_onlink(uip_ipaddr_t *ipaddr)
|
2010-03-15 16:41:24 +00:00
|
|
|
{
|
|
|
|
for(locprefix = uip_ds6_prefix_list;
|
|
|
|
locprefix < uip_ds6_prefix_list + UIP_DS6_PREFIX_NB; locprefix++) {
|
2010-03-23 14:21:04 +00:00
|
|
|
if(locprefix->isused &&
|
|
|
|
uip_ipaddr_prefixcmp(&locprefix->ipaddr, ipaddr, locprefix->length)) {
|
2010-03-12 16:19:19 +00:00
|
|
|
return 1;
|
2010-03-15 16:41:24 +00:00
|
|
|
}
|
2010-03-12 16:19:19 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-03-15 16:41:24 +00:00
|
|
|
uip_ds6_addr_t *
|
2011-03-16 12:35:44 +00:00
|
|
|
uip_ds6_addr_add(uip_ipaddr_t *ipaddr, unsigned long vlifetime, uint8_t type)
|
2010-03-15 16:41:24 +00:00
|
|
|
{
|
|
|
|
if(uip_ds6_list_loop
|
2011-03-16 12:35:44 +00:00
|
|
|
((uip_ds6_element_t *)uip_ds6_if.addr_list, UIP_DS6_ADDR_NB,
|
2010-03-15 16:41:24 +00:00
|
|
|
sizeof(uip_ds6_addr_t), ipaddr, 128,
|
2011-03-16 12:35:44 +00:00
|
|
|
(uip_ds6_element_t **)&locaddr) == FREESPACE) {
|
2010-03-12 16:19:19 +00:00
|
|
|
locaddr->isused = 1;
|
|
|
|
uip_ipaddr_copy(&locaddr->ipaddr, ipaddr);
|
|
|
|
locaddr->type = type;
|
|
|
|
if(vlifetime == 0) {
|
|
|
|
locaddr->isinfinite = 1;
|
|
|
|
} else {
|
|
|
|
locaddr->isinfinite = 0;
|
|
|
|
stimer_set(&(locaddr->vlifetime), vlifetime);
|
|
|
|
}
|
2011-07-11 11:24:17 +00:00
|
|
|
#if UIP_ND6_DEF_MAXDADNS > 0
|
|
|
|
locaddr->state = ADDR_TENTATIVE;
|
2010-03-15 16:41:24 +00:00
|
|
|
timer_set(&locaddr->dadtimer,
|
|
|
|
random_rand() % (UIP_ND6_MAX_RTR_SOLICITATION_DELAY *
|
|
|
|
CLOCK_SECOND));
|
2010-03-12 16:19:19 +00:00
|
|
|
locaddr->dadnscount = 0;
|
2011-07-11 11:24:17 +00:00
|
|
|
#else /* UIP_ND6_DEF_MAXDADNS > 0 */
|
|
|
|
locaddr->state = ADDR_PREFERRED;
|
|
|
|
#endif /* UIP_ND6_DEF_MAXDADNS > 0 */
|
2010-03-12 16:19:19 +00:00
|
|
|
uip_create_solicited_node(ipaddr, &loc_fipaddr);
|
|
|
|
uip_ds6_maddr_add(&loc_fipaddr);
|
|
|
|
return locaddr;
|
|
|
|
}
|
2010-03-15 16:41:24 +00:00
|
|
|
return NULL;
|
2010-03-12 16:19:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-03-15 16:41:24 +00:00
|
|
|
void
|
2011-03-16 12:35:44 +00:00
|
|
|
uip_ds6_addr_rm(uip_ds6_addr_t *addr)
|
2010-03-15 16:41:24 +00:00
|
|
|
{
|
|
|
|
if(addr != NULL) {
|
2010-03-12 16:19:19 +00:00
|
|
|
uip_create_solicited_node(&addr->ipaddr, &loc_fipaddr);
|
|
|
|
if((locmaddr = uip_ds6_maddr_lookup(&loc_fipaddr)) != NULL) {
|
|
|
|
uip_ds6_maddr_rm(locmaddr);
|
|
|
|
}
|
|
|
|
addr->isused = 0;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-03-15 16:41:24 +00:00
|
|
|
uip_ds6_addr_t *
|
2011-03-16 12:35:44 +00:00
|
|
|
uip_ds6_addr_lookup(uip_ipaddr_t *ipaddr)
|
2010-03-15 16:41:24 +00:00
|
|
|
{
|
|
|
|
if(uip_ds6_list_loop
|
2011-03-16 12:35:44 +00:00
|
|
|
((uip_ds6_element_t *)uip_ds6_if.addr_list, UIP_DS6_ADDR_NB,
|
2010-03-15 16:41:24 +00:00
|
|
|
sizeof(uip_ds6_addr_t), ipaddr, 128,
|
2011-03-16 12:35:44 +00:00
|
|
|
(uip_ds6_element_t **)&locaddr) == FOUND) {
|
2010-03-12 16:19:19 +00:00
|
|
|
return locaddr;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-05-09 17:52:37 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
/*
|
|
|
|
* get a link local address -
|
|
|
|
* state = -1 => any address is ok. Otherwise state = desired state of addr.
|
|
|
|
* (TENTATIVE, PREFERRED, DEPRECATED)
|
|
|
|
*/
|
|
|
|
uip_ds6_addr_t *
|
2010-06-15 19:16:22 +00:00
|
|
|
uip_ds6_get_link_local(int8_t state)
|
|
|
|
{
|
2010-05-09 17:52:37 +00:00
|
|
|
for(locaddr = uip_ds6_if.addr_list;
|
|
|
|
locaddr < uip_ds6_if.addr_list + UIP_DS6_ADDR_NB; locaddr++) {
|
2011-03-16 12:35:44 +00:00
|
|
|
if(locaddr->isused && (state == -1 || locaddr->state == state)
|
2015-10-20 09:18:46 +00:00
|
|
|
&& (uip_is_addr_linklocal(&locaddr->ipaddr))) {
|
2010-05-09 17:52:37 +00:00
|
|
|
return locaddr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
2010-06-15 19:16:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
/*
|
|
|
|
* get a global address -
|
|
|
|
* state = -1 => any address is ok. Otherwise state = desired state of addr.
|
|
|
|
* (TENTATIVE, PREFERRED, DEPRECATED)
|
|
|
|
*/
|
|
|
|
uip_ds6_addr_t *
|
|
|
|
uip_ds6_get_global(int8_t state)
|
|
|
|
{
|
|
|
|
for(locaddr = uip_ds6_if.addr_list;
|
|
|
|
locaddr < uip_ds6_if.addr_list + UIP_DS6_ADDR_NB; locaddr++) {
|
2011-03-16 12:35:44 +00:00
|
|
|
if(locaddr->isused && (state == -1 || locaddr->state == state)
|
2015-10-20 09:18:46 +00:00
|
|
|
&& !(uip_is_addr_linklocal(&locaddr->ipaddr))) {
|
2010-06-15 19:16:22 +00:00
|
|
|
return locaddr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
2010-05-09 17:52:37 +00:00
|
|
|
}
|
|
|
|
|
2010-03-12 16:19:19 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-03-15 16:41:24 +00:00
|
|
|
uip_ds6_maddr_t *
|
2013-01-17 04:33:17 +00:00
|
|
|
uip_ds6_maddr_add(const uip_ipaddr_t *ipaddr)
|
2010-03-15 16:41:24 +00:00
|
|
|
{
|
|
|
|
if(uip_ds6_list_loop
|
2011-03-16 12:35:44 +00:00
|
|
|
((uip_ds6_element_t *)uip_ds6_if.maddr_list, UIP_DS6_MADDR_NB,
|
2013-01-17 04:33:17 +00:00
|
|
|
sizeof(uip_ds6_maddr_t), (void*)ipaddr, 128,
|
2011-03-16 12:35:44 +00:00
|
|
|
(uip_ds6_element_t **)&locmaddr) == FREESPACE) {
|
2010-03-12 16:19:19 +00:00
|
|
|
locmaddr->isused = 1;
|
|
|
|
uip_ipaddr_copy(&locmaddr->ipaddr, ipaddr);
|
|
|
|
return locmaddr;
|
|
|
|
}
|
2010-03-15 16:41:24 +00:00
|
|
|
return NULL;
|
2010-03-12 16:19:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-03-15 16:41:24 +00:00
|
|
|
void
|
2012-04-21 22:31:56 +00:00
|
|
|
uip_ds6_maddr_rm(uip_ds6_maddr_t *maddr)
|
2010-03-15 16:41:24 +00:00
|
|
|
{
|
2010-03-12 16:19:19 +00:00
|
|
|
if(maddr != NULL) {
|
|
|
|
maddr->isused = 0;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-03-15 16:41:24 +00:00
|
|
|
uip_ds6_maddr_t *
|
2013-01-17 04:33:17 +00:00
|
|
|
uip_ds6_maddr_lookup(const uip_ipaddr_t *ipaddr)
|
2010-03-15 16:41:24 +00:00
|
|
|
{
|
|
|
|
if(uip_ds6_list_loop
|
2011-03-16 12:35:44 +00:00
|
|
|
((uip_ds6_element_t *)uip_ds6_if.maddr_list, UIP_DS6_MADDR_NB,
|
2013-01-17 04:33:17 +00:00
|
|
|
sizeof(uip_ds6_maddr_t), (void*)ipaddr, 128,
|
2011-03-16 12:35:44 +00:00
|
|
|
(uip_ds6_element_t **)&locmaddr) == FOUND) {
|
2010-03-12 16:19:19 +00:00
|
|
|
return locmaddr;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-03-15 16:41:24 +00:00
|
|
|
uip_ds6_aaddr_t *
|
2011-03-16 12:35:44 +00:00
|
|
|
uip_ds6_aaddr_add(uip_ipaddr_t *ipaddr)
|
2010-03-15 16:41:24 +00:00
|
|
|
{
|
2015-10-04 20:32:12 +00:00
|
|
|
#if UIP_DS6_AADDR_NB
|
2010-03-15 16:41:24 +00:00
|
|
|
if(uip_ds6_list_loop
|
2011-03-16 12:35:44 +00:00
|
|
|
((uip_ds6_element_t *)uip_ds6_if.aaddr_list, UIP_DS6_AADDR_NB,
|
2010-03-15 16:41:24 +00:00
|
|
|
sizeof(uip_ds6_aaddr_t), ipaddr, 128,
|
2011-03-16 12:35:44 +00:00
|
|
|
(uip_ds6_element_t **)&locaaddr) == FREESPACE) {
|
2010-03-12 16:19:19 +00:00
|
|
|
locaaddr->isused = 1;
|
|
|
|
uip_ipaddr_copy(&locaaddr->ipaddr, ipaddr);
|
|
|
|
return locaaddr;
|
|
|
|
}
|
2015-10-04 20:32:12 +00:00
|
|
|
#endif /* UIP_DS6_AADDR_NB */
|
2010-03-15 16:41:24 +00:00
|
|
|
return NULL;
|
2010-03-12 16:19:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-03-15 16:41:24 +00:00
|
|
|
void
|
2012-04-21 22:31:56 +00:00
|
|
|
uip_ds6_aaddr_rm(uip_ds6_aaddr_t *aaddr)
|
2010-03-15 16:41:24 +00:00
|
|
|
{
|
2010-03-12 16:19:19 +00:00
|
|
|
if(aaddr != NULL) {
|
|
|
|
aaddr->isused = 0;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-03-15 16:41:24 +00:00
|
|
|
uip_ds6_aaddr_t *
|
2011-03-16 12:35:44 +00:00
|
|
|
uip_ds6_aaddr_lookup(uip_ipaddr_t *ipaddr)
|
2010-03-15 16:41:24 +00:00
|
|
|
{
|
2015-10-04 20:32:12 +00:00
|
|
|
#if UIP_DS6_AADDR_NB
|
2011-03-16 12:35:44 +00:00
|
|
|
if(uip_ds6_list_loop((uip_ds6_element_t *)uip_ds6_if.aaddr_list,
|
2015-10-30 10:41:59 +00:00
|
|
|
UIP_DS6_AADDR_NB, sizeof(uip_ds6_aaddr_t), ipaddr, 128,
|
|
|
|
(uip_ds6_element_t **)&locaaddr) == FOUND) {
|
2010-03-12 16:19:19 +00:00
|
|
|
return locaaddr;
|
|
|
|
}
|
2015-10-04 20:32:12 +00:00
|
|
|
#endif /* UIP_DS6_AADDR_NB */
|
2010-03-12 16:19:19 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
2010-03-23 14:21:04 +00:00
|
|
|
uip_ds6_select_src(uip_ipaddr_t *src, uip_ipaddr_t *dst)
|
2010-03-15 16:41:24 +00:00
|
|
|
{
|
|
|
|
uint8_t best = 0; /* number of bit in common with best match */
|
2010-03-12 16:19:19 +00:00
|
|
|
uint8_t n = 0;
|
2010-05-10 11:10:27 +00:00
|
|
|
uip_ds6_addr_t *matchaddr = NULL;
|
2010-03-15 16:41:24 +00:00
|
|
|
|
2015-10-20 09:18:46 +00:00
|
|
|
if(!uip_is_addr_linklocal(dst) && !uip_is_addr_mcast(dst)) {
|
2010-05-10 11:10:27 +00:00
|
|
|
/* find longest match */
|
2010-03-15 16:41:24 +00:00
|
|
|
for(locaddr = uip_ds6_if.addr_list;
|
|
|
|
locaddr < uip_ds6_if.addr_list + UIP_DS6_ADDR_NB; locaddr++) {
|
2010-09-23 18:17:27 +00:00
|
|
|
/* Only preferred global (not link-local) addresses */
|
2011-03-16 12:35:44 +00:00
|
|
|
if(locaddr->isused && locaddr->state == ADDR_PREFERRED &&
|
2015-10-20 09:18:46 +00:00
|
|
|
!uip_is_addr_linklocal(&locaddr->ipaddr)) {
|
2011-03-16 12:35:44 +00:00
|
|
|
n = get_match_length(dst, &locaddr->ipaddr);
|
2010-03-15 16:41:24 +00:00
|
|
|
if(n >= best) {
|
2010-03-12 16:19:19 +00:00
|
|
|
best = n;
|
|
|
|
matchaddr = locaddr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-11-11 11:51:25 +00:00
|
|
|
#if UIP_IPV6_MULTICAST
|
|
|
|
} else if(uip_is_addr_mcast_routable(dst)) {
|
|
|
|
matchaddr = uip_ds6_get_global(ADDR_PREFERRED);
|
|
|
|
#endif
|
2010-03-12 16:19:19 +00:00
|
|
|
} else {
|
2010-05-09 17:52:37 +00:00
|
|
|
matchaddr = uip_ds6_get_link_local(ADDR_PREFERRED);
|
2010-03-12 16:19:19 +00:00
|
|
|
}
|
|
|
|
|
2010-05-10 11:10:27 +00:00
|
|
|
/* use the :: (unspecified address) as source if no match found */
|
|
|
|
if(matchaddr == NULL) {
|
|
|
|
uip_create_unspecified(src);
|
|
|
|
} else {
|
|
|
|
uip_ipaddr_copy(src, &matchaddr->ipaddr);
|
|
|
|
}
|
2010-03-12 16:19:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-03-15 16:41:24 +00:00
|
|
|
void
|
2012-04-21 22:31:56 +00:00
|
|
|
uip_ds6_set_addr_iid(uip_ipaddr_t *ipaddr, uip_lladdr_t *lladdr)
|
2010-03-15 16:41:24 +00:00
|
|
|
{
|
2010-03-12 16:19:19 +00:00
|
|
|
/* We consider only links with IEEE EUI-64 identifier or
|
|
|
|
* IEEE 48-bit MAC addresses */
|
|
|
|
#if (UIP_LLADDR_LEN == 8)
|
|
|
|
memcpy(ipaddr->u8 + 8, lladdr, UIP_LLADDR_LEN);
|
|
|
|
ipaddr->u8[8] ^= 0x02;
|
|
|
|
#elif (UIP_LLADDR_LEN == 6)
|
|
|
|
memcpy(ipaddr->u8 + 8, lladdr, 3);
|
|
|
|
ipaddr->u8[11] = 0xff;
|
|
|
|
ipaddr->u8[12] = 0xfe;
|
2011-03-16 12:35:44 +00:00
|
|
|
memcpy(ipaddr->u8 + 13, (uint8_t *)lladdr + 3, 3);
|
2010-03-12 16:19:19 +00:00
|
|
|
ipaddr->u8[8] ^= 0x02;
|
|
|
|
#else
|
2010-03-15 16:41:24 +00:00
|
|
|
#error uip-ds6.c cannot build interface address when UIP_LLADDR_LEN is not 6 or 8
|
2010-03-12 16:19:19 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-06-16 13:57:24 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
|
|
|
uip_ds6_set_lladdr_from_iid(uip_lladdr_t *lladdr, const uip_ipaddr_t *ipaddr)
|
|
|
|
{
|
|
|
|
#if (UIP_LLADDR_LEN == 8)
|
|
|
|
memcpy(lladdr, ipaddr->u8 + 8, UIP_LLADDR_LEN);
|
|
|
|
lladdr->addr[0] ^= 0x02;
|
|
|
|
#else
|
|
|
|
#error uip-ds6.c cannot build lladdr address when UIP_LLADDR_LEN is not 8
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-03-12 16:19:19 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
uint8_t
|
2011-03-16 12:35:44 +00:00
|
|
|
get_match_length(uip_ipaddr_t *src, uip_ipaddr_t *dst)
|
2010-03-15 16:41:24 +00:00
|
|
|
{
|
2010-03-12 16:19:19 +00:00
|
|
|
uint8_t j, k, x_or;
|
|
|
|
uint8_t len = 0;
|
2010-03-15 16:41:24 +00:00
|
|
|
|
|
|
|
for(j = 0; j < 16; j++) {
|
2010-03-12 16:19:19 +00:00
|
|
|
if(src->u8[j] == dst->u8[j]) {
|
|
|
|
len += 8;
|
|
|
|
} else {
|
|
|
|
x_or = src->u8[j] ^ dst->u8[j];
|
2010-03-15 16:41:24 +00:00
|
|
|
for(k = 0; k < 8; k++) {
|
|
|
|
if((x_or & 0x80) == 0) {
|
|
|
|
len++;
|
2010-03-12 16:19:19 +00:00
|
|
|
x_or <<= 1;
|
2010-03-15 16:41:24 +00:00
|
|
|
} else {
|
2010-03-12 16:19:19 +00:00
|
|
|
break;
|
|
|
|
}
|
2010-03-15 16:41:24 +00:00
|
|
|
}
|
2010-03-12 16:19:19 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2011-07-11 11:24:17 +00:00
|
|
|
#if UIP_ND6_DEF_MAXDADNS > 0
|
2010-03-12 16:19:19 +00:00
|
|
|
void
|
2011-03-16 12:35:44 +00:00
|
|
|
uip_ds6_dad(uip_ds6_addr_t *addr)
|
2010-03-15 16:41:24 +00:00
|
|
|
{
|
2010-03-12 16:19:19 +00:00
|
|
|
/* send maxdadns NS for DAD */
|
|
|
|
if(addr->dadnscount < uip_ds6_if.maxdadns) {
|
|
|
|
uip_nd6_ns_output(NULL, NULL, &addr->ipaddr);
|
|
|
|
addr->dadnscount++;
|
2010-03-15 16:41:24 +00:00
|
|
|
timer_set(&addr->dadtimer,
|
|
|
|
uip_ds6_if.retrans_timer / 1000 * CLOCK_SECOND);
|
2010-03-12 16:19:19 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* If we arrive here it means DAD succeeded, otherwise the dad process
|
|
|
|
* would have been interrupted in ds6_dad_ns/na_input
|
|
|
|
*/
|
2017-06-20 15:23:49 +00:00
|
|
|
LOG_INFO("DAD succeeded, ipaddr: ");
|
|
|
|
LOG_INFO_6ADDR(&addr->ipaddr);
|
2017-06-23 07:21:31 +00:00
|
|
|
LOG_INFO_("\n");
|
2010-03-12 16:19:19 +00:00
|
|
|
|
|
|
|
addr->state = ADDR_PREFERRED;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-03-15 16:41:24 +00:00
|
|
|
/*
|
|
|
|
* Calling code must handle when this returns 0 (e.g. link local
|
|
|
|
* address can not be used).
|
|
|
|
*/
|
|
|
|
int
|
2012-04-21 22:31:56 +00:00
|
|
|
uip_ds6_dad_failed(uip_ds6_addr_t *addr)
|
2010-03-15 16:41:24 +00:00
|
|
|
{
|
2015-10-20 09:18:46 +00:00
|
|
|
if(uip_is_addr_linklocal(&addr->ipaddr)) {
|
2017-06-20 15:23:49 +00:00
|
|
|
LOG_ERR("Contiki shutdown, DAD for link local address failed\n");
|
2010-03-15 16:41:24 +00:00
|
|
|
return 0;
|
2010-03-12 16:19:19 +00:00
|
|
|
}
|
|
|
|
uip_ds6_addr_rm(addr);
|
2010-03-15 16:41:24 +00:00
|
|
|
return 1;
|
2010-03-12 16:19:19 +00:00
|
|
|
}
|
2011-07-11 11:24:17 +00:00
|
|
|
#endif /*UIP_ND6_DEF_MAXDADNS > 0 */
|
2010-03-12 16:19:19 +00:00
|
|
|
|
2011-07-11 11:24:17 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-03-15 16:41:24 +00:00
|
|
|
#if UIP_CONF_ROUTER
|
2010-03-12 16:19:19 +00:00
|
|
|
#if UIP_ND6_SEND_RA
|
|
|
|
void
|
2010-03-15 16:41:24 +00:00
|
|
|
uip_ds6_send_ra_sollicited(void)
|
|
|
|
{
|
2010-03-12 16:19:19 +00:00
|
|
|
/* We have a pb here: RA timer max possible value is 1800s,
|
|
|
|
* hence we have to use stimers. However, when receiving a RS, we
|
2010-03-15 16:41:24 +00:00
|
|
|
* should delay the reply by a random value between 0 and 500ms timers.
|
|
|
|
* stimers are in seconds, hence we cannot do this. Therefore we just send
|
|
|
|
* the RA (setting the timer to 0 below). We keep the code logic for
|
2010-03-12 16:19:19 +00:00
|
|
|
* the days contiki will support appropriate timers */
|
|
|
|
rand_time = 0;
|
2017-06-20 15:23:49 +00:00
|
|
|
LOG_INFO("Solicited RA, random time %u\n", rand_time);
|
2010-03-12 16:19:19 +00:00
|
|
|
|
2010-03-15 16:41:24 +00:00
|
|
|
if(stimer_remaining(&uip_ds6_timer_ra) > rand_time) {
|
|
|
|
if(stimer_elapsed(&uip_ds6_timer_ra) < UIP_ND6_MIN_DELAY_BETWEEN_RAS) {
|
2010-03-12 16:19:19 +00:00
|
|
|
/* Ensure that the RAs are rate limited */
|
|
|
|
/* stimer_set(&uip_ds6_timer_ra, rand_time +
|
|
|
|
UIP_ND6_MIN_DELAY_BETWEEN_RAS -
|
2010-03-15 16:41:24 +00:00
|
|
|
stimer_elapsed(&uip_ds6_timer_ra));
|
|
|
|
*/ } else {
|
|
|
|
stimer_set(&uip_ds6_timer_ra, rand_time);
|
2010-03-12 16:19:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
2010-03-15 16:41:24 +00:00
|
|
|
uip_ds6_send_ra_periodic(void)
|
|
|
|
{
|
|
|
|
if(racount > 0) {
|
|
|
|
/* send previously scheduled RA */
|
2010-03-12 16:19:19 +00:00
|
|
|
uip_nd6_ra_output(NULL);
|
2017-06-20 15:23:49 +00:00
|
|
|
LOG_INFO("Sending periodic RA\n");
|
2010-03-12 16:19:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rand_time = UIP_ND6_MIN_RA_INTERVAL + random_rand() %
|
2010-03-15 16:41:24 +00:00
|
|
|
(uint16_t) (UIP_ND6_MAX_RA_INTERVAL - UIP_ND6_MIN_RA_INTERVAL);
|
2017-06-20 15:23:49 +00:00
|
|
|
LOG_DBG("Random time 1 = %u\n", rand_time);
|
2010-03-12 16:19:19 +00:00
|
|
|
|
2010-03-15 16:41:24 +00:00
|
|
|
if(racount < UIP_ND6_MAX_INITIAL_RAS) {
|
|
|
|
if(rand_time > UIP_ND6_MAX_INITIAL_RA_INTERVAL) {
|
2010-03-12 16:19:19 +00:00
|
|
|
rand_time = UIP_ND6_MAX_INITIAL_RA_INTERVAL;
|
2017-06-20 15:23:49 +00:00
|
|
|
LOG_DBG("Random time 2 = %u\n", rand_time);
|
2010-03-12 16:19:19 +00:00
|
|
|
}
|
|
|
|
racount++;
|
|
|
|
}
|
2017-06-20 15:23:49 +00:00
|
|
|
LOG_DBG("Random time 3 = %u\n", rand_time);
|
2010-03-15 16:41:24 +00:00
|
|
|
stimer_set(&uip_ds6_timer_ra, rand_time);
|
2010-03-12 16:19:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* UIP_ND6_SEND_RA */
|
|
|
|
#else /* UIP_CONF_ROUTER */
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
2010-03-15 16:41:24 +00:00
|
|
|
uip_ds6_send_rs(void)
|
|
|
|
{
|
|
|
|
if((uip_ds6_defrt_choose() == NULL)
|
|
|
|
&& (rscount < UIP_ND6_MAX_RTR_SOLICITATIONS)) {
|
2017-06-20 15:23:49 +00:00
|
|
|
LOG_INFO("Sending RS %u\n", rscount);
|
2010-03-12 16:19:19 +00:00
|
|
|
uip_nd6_rs_output();
|
|
|
|
rscount++;
|
2010-03-15 16:41:24 +00:00
|
|
|
etimer_set(&uip_ds6_timer_rs,
|
|
|
|
UIP_ND6_RTR_SOLICITATION_INTERVAL * CLOCK_SECOND);
|
2010-03-12 16:19:19 +00:00
|
|
|
} else {
|
2017-06-20 15:23:49 +00:00
|
|
|
LOG_INFO("Router found ? (boolean): %u\n",
|
2010-03-15 16:41:24 +00:00
|
|
|
(uip_ds6_defrt_choose() != NULL));
|
2010-03-12 16:19:19 +00:00
|
|
|
etimer_stop(&uip_ds6_timer_rs);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* UIP_CONF_ROUTER */
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
uint32_t
|
|
|
|
uip_ds6_compute_reachable_time(void)
|
|
|
|
{
|
2010-03-15 16:41:24 +00:00
|
|
|
return (uint32_t) (UIP_ND6_MIN_RANDOM_FACTOR
|
|
|
|
(uip_ds6_if.base_reachable_time)) +
|
|
|
|
((uint16_t) (random_rand() << 8) +
|
|
|
|
(uint16_t) random_rand()) %
|
|
|
|
(uint32_t) (UIP_ND6_MAX_RANDOM_FACTOR(uip_ds6_if.base_reachable_time) -
|
|
|
|
UIP_ND6_MIN_RANDOM_FACTOR(uip_ds6_if.base_reachable_time));
|
2010-03-12 16:19:19 +00:00
|
|
|
}
|
2013-05-15 10:16:15 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2014-05-30 09:01:20 +00:00
|
|
|
|
|
|
|
/** @}*/
|