Merge pull request #2073 from cetic/pr-fix-send-na

Fix semantic of UIP_ND6_SEND_NA and add UIP_ND6_SEND_NS
This commit is contained in:
Nicolas Tsiftes 2017-01-20 13:18:43 +01:00 committed by GitHub
commit 5eb2ac15ff
19 changed files with 75 additions and 61 deletions

View file

@ -211,7 +211,7 @@
#define UIP_CONF_ND6_SEND_RA (NETSTACK_CONF_WITH_IPV6 && !UIP_CONF_IPV6_RPL)
#endif /* UIP_CONF_ND6_SEND_RA */
/* UIP_CONF_ND6_SEND_NA enables standard IPv6 Neighbor Discovery Protocol.
/* UIP_CONF_ND6_SEND_NS enables standard IPv6 Neighbor Discovery Protocol.
We enable it by default when IPv6 is used without RPL.
With RPL, the neighbor cache (link-local IPv6 <-> MAC address mapping)
is fed whenever receiving DIO and DAO messages. This is always sufficient
@ -221,9 +221,15 @@
neighbor to us is weak, if DIO transmissions are suppressed (Trickle
timer) or if the neighbor chooses not to transmit DIOs because it is
a leaf node or for any reason. */
#ifndef UIP_CONF_ND6_SEND_NS
#define UIP_CONF_ND6_SEND_NS (NETSTACK_CONF_WITH_IPV6 && !UIP_CONF_IPV6_RPL)
#endif /* UIP_CONF_ND6_SEND_NS */
/* UIP_CONF_ND6_SEND_NA allows to still comply with NDP even if the host does
not perform NUD or DAD processes. By default it is activated so the host
can still communicate with a full NDP peer. */
#ifndef UIP_CONF_ND6_SEND_NA
#define UIP_CONF_ND6_SEND_NA (NETSTACK_CONF_WITH_IPV6 && !UIP_CONF_IPV6_RPL)
#endif /* UIP_CONF_ND6_SEND_NA */
#define UIP_CONF_ND6_SEND_NA (NETSTACK_CONF_WITH_IPV6)
#endif /* UIP_CONF_ND6_SEND_NS */
/*---------------------------------------------------------------------------*/
/* 6lowpan configuration options.

View file

@ -662,7 +662,7 @@ tcpip_ipv6_output(void)
nbr = uip_ds6_nbr_lookup(nexthop);
if(nbr == NULL) {
#if UIP_ND6_SEND_NA
#if UIP_ND6_SEND_NS
if((nbr = uip_ds6_nbr_add(nexthop, NULL, 0, NBR_INCOMPLETE, NBR_TABLE_REASON_IPV6_ND, NULL)) == NULL) {
uip_clear_buf();
PRINTF("tcpip_ipv6_output: failed to add neighbor to cache\n");
@ -691,13 +691,13 @@ tcpip_ipv6_output(void)
nbr->nscount = 1;
/* Send the first NS try from here (multicast destination IP address). */
}
#else /* UIP_ND6_SEND_NA */
#else /* UIP_ND6_SEND_NS */
PRINTF("tcpip_ipv6_output: neighbor not in cache\n");
uip_len = 0;
return;
#endif /* UIP_ND6_SEND_NA */
#endif /* UIP_ND6_SEND_NS */
} else {
#if UIP_ND6_SEND_NA
#if UIP_ND6_SEND_NS
if(nbr->state == NBR_INCOMPLETE) {
PRINTF("tcpip_ipv6_output: nbr cache entry incomplete\n");
#if UIP_CONF_IPV6_QUEUE_PKT
@ -719,7 +719,7 @@ tcpip_ipv6_output(void)
nbr->nscount = 0;
PRINTF("tcpip_ipv6_output: nbr cache entry stale moving to delay\n");
}
#endif /* UIP_ND6_SEND_NA */
#endif /* UIP_ND6_SEND_NS */
tcpip_output(uip_ds6_nbr_get_ll(nbr));

View file

@ -88,14 +88,14 @@ uip_ds6_nbr_add(const uip_ipaddr_t *ipaddr, const uip_lladdr_t *lladdr,
, reason, data);
if(nbr) {
uip_ipaddr_copy(&nbr->ipaddr, ipaddr);
#if UIP_ND6_SEND_NA || UIP_ND6_SEND_RA || !UIP_CONF_ROUTER
#if UIP_ND6_SEND_RA || !UIP_CONF_ROUTER
nbr->isrouter = isrouter;
#endif /* UIP_ND6_SEND_NA || UIP_ND6_SEND_RA || !UIP_CONF_ROUTER */
#endif /* UIP_ND6_SEND_RA || !UIP_CONF_ROUTER */
nbr->state = state;
#if UIP_CONF_IPV6_QUEUE_PKT
uip_packetqueue_new(&nbr->packethandle);
#endif /* UIP_CONF_IPV6_QUEUE_PKT */
#if UIP_ND6_SEND_NA
#if UIP_ND6_SEND_NS
if(nbr->state == NBR_REACHABLE) {
stimer_set(&nbr->reachable, UIP_ND6_REACHABLE_TIME / 1000);
} else {
@ -104,7 +104,7 @@ uip_ds6_nbr_add(const uip_ipaddr_t *ipaddr, const uip_lladdr_t *lladdr,
}
stimer_set(&nbr->sendns, 0);
nbr->nscount = 0;
#endif /* UIP_ND6_SEND_NA */
#endif /* UIP_ND6_SEND_NS */
PRINTF("Adding neighbor with ip addr ");
PRINT6ADDR(ipaddr);
PRINTF(" link addr ");
@ -245,7 +245,7 @@ uip_ds6_link_neighbor_callback(int status, int numtx)
#endif /* UIP_DS6_LL_NUD */
}
#if UIP_ND6_SEND_NA
#if UIP_ND6_SEND_NS
/*---------------------------------------------------------------------------*/
/** Periodic processing on neighbors */
void
@ -326,7 +326,6 @@ uip_ds6_neighbor_periodic(void)
}
}
/*---------------------------------------------------------------------------*/
#if UIP_ND6_SEND_NA
void
uip_ds6_nbr_refresh_reachable_state(const uip_ipaddr_t *ipaddr)
{
@ -338,7 +337,6 @@ uip_ds6_nbr_refresh_reachable_state(const uip_ipaddr_t *ipaddr)
stimer_set(&nbr->reachable, UIP_ND6_REACHABLE_TIME / 1000);
}
}
#endif /* UIP_ND6_SEND_NA */
/*---------------------------------------------------------------------------*/
uip_ds6_nbr_t *
uip_ds6_get_least_lifetime_neighbor(void)
@ -358,6 +356,6 @@ uip_ds6_get_least_lifetime_neighbor(void)
}
return nbr_expiring;
}
#endif /* UIP_ND6_SEND_NA */
#endif /* UIP_ND6_SEND_NS */
/*---------------------------------------------------------------------------*/
/** @} */

View file

@ -69,11 +69,11 @@ typedef struct uip_ds6_nbr {
uip_ipaddr_t ipaddr;
uint8_t isrouter;
uint8_t state;
#if UIP_ND6_SEND_NA || UIP_ND6_SEND_RA
#if UIP_ND6_SEND_NS || UIP_ND6_SEND_RA
struct stimer reachable;
struct stimer sendns;
uint8_t nscount;
#endif /* UIP_ND6_SEND_NA || UIP_ND6_SEND_RA */
#endif /* UIP_ND6_SEND_NS || UIP_ND6_SEND_RA */
#if UIP_CONF_IPV6_QUEUE_PKT
struct uip_packetqueue_handle packethandle;
#define UIP_DS6_NBR_PACKET_LIFETIME CLOCK_SECOND * 4
@ -98,7 +98,7 @@ void uip_ds6_link_neighbor_callback(int status, int numtx);
void uip_ds6_neighbor_periodic(void);
int uip_ds6_nbr_num(void);
#if UIP_ND6_SEND_NA
#if UIP_ND6_SEND_NS
/**
* \brief Refresh the reachable state of a neighbor. This function
* may be called when a node receives an IPv6 message that confirms the
@ -107,7 +107,7 @@ int uip_ds6_nbr_num(void);
* should be refreshed.
*/
void uip_ds6_nbr_refresh_reachable_state(const uip_ipaddr_t *ipaddr);
#endif /* UIP_ND6_SEND_NA */
#endif /* UIP_ND6_SEND_NS */
/**
* \brief

View file

@ -187,9 +187,9 @@ uip_ds6_periodic(void)
}
#endif /* !UIP_CONF_ROUTER */
#if UIP_ND6_SEND_NA
#if UIP_ND6_SEND_NS
uip_ds6_neighbor_periodic();
#endif /* UIP_ND6_SEND_RA */
#endif /* UIP_ND6_SEND_NS */
#if UIP_CONF_ROUTER && UIP_ND6_SEND_RA
/* Periodic RA sending */

View file

@ -116,13 +116,16 @@ void uip_log(char *msg);
#define UIP_ND6_OPT_RDNSS_BUF ((uip_nd6_opt_dns *)&uip_buf[uip_l2_l3_icmp_hdr_len + nd6_opt_offset])
/** @} */
#if UIP_ND6_SEND_NA || UIP_ND6_SEND_RA || !UIP_CONF_ROUTER
#if UIP_ND6_SEND_NS || UIP_ND6_SEND_NA || UIP_ND6_SEND_RA || !UIP_CONF_ROUTER
static uint8_t nd6_opt_offset; /** Offset from the end of the icmpv6 header to the option in uip_buf*/
static uint8_t *nd6_opt_llao; /** Pointer to llao option in uip_buf */
static uip_ds6_nbr_t *nbr; /** Pointer to a nbr cache entry*/
static uip_ds6_defrt_t *defrt; /** Pointer to a router list entry */
static uip_ds6_addr_t *addr; /** Pointer to an interface address */
#endif /* UIP_ND6_SEND_NA || UIP_ND6_SEND_RA || !UIP_CONF_ROUTER */
#endif /* UIP_ND6_SEND_NS || UIP_ND6_SEND_NA || UIP_ND6_SEND_RA || !UIP_CONF_ROUTER */
#if UIP_ND6_SEND_NS || UIP_ND6_SEND_RA || !UIP_CONF_ROUTER
static uip_ds6_defrt_t *defrt; /** Pointer to a router list entry */
#endif /* UIP_ND6_SEND_NS || UIP_ND6_SEND_RA || !UIP_CONF_ROUTER */
#if !UIP_CONF_ROUTER // TBD see if we move it to ra_input
static uip_nd6_opt_prefix_info *nd6_opt_prefix_info; /** Pointer to prefix information option in uip_buf */
@ -366,6 +369,7 @@ discard:
/*------------------------------------------------------------------*/
#if UIP_ND6_SEND_NS
void
uip_nd6_ns_output(uip_ipaddr_t * src, uip_ipaddr_t * dest, uip_ipaddr_t * tgt)
{
@ -428,7 +432,9 @@ uip_nd6_ns_output(uip_ipaddr_t * src, uip_ipaddr_t * dest, uip_ipaddr_t * tgt)
PRINTF("\n");
return;
}
#if UIP_ND6_SEND_NA
#endif /* UIP_ND6_SEND_NS */
#if UIP_ND6_SEND_NS
/*------------------------------------------------------------------*/
/**
* Neighbor Advertisement Processing
@ -603,7 +609,7 @@ discard:
uip_clear_buf();
return;
}
#endif /* UIP_ND6_SEND_NA */
#endif /* UIP_ND6_SEND_NS */
#if UIP_CONF_ROUTER
#if UIP_ND6_SEND_RA
@ -1097,6 +1103,8 @@ discard:
#if UIP_ND6_SEND_NA
UIP_ICMP6_HANDLER(ns_input_handler, ICMP6_NS, UIP_ICMP6_HANDLER_CODE_ANY,
ns_input);
#endif
#if UIP_ND6_SEND_NS
UIP_ICMP6_HANDLER(na_input_handler, ICMP6_NA, UIP_ICMP6_HANDLER_CODE_ANY,
na_input);
#endif
@ -1114,19 +1122,16 @@ UIP_ICMP6_HANDLER(ra_input_handler, ICMP6_RA, UIP_ICMP6_HANDLER_CODE_ANY,
void
uip_nd6_init()
{
#if UIP_ND6_SEND_NA
/* Only handle NSs if we are prepared to send out NAs */
uip_icmp6_register_input_handler(&ns_input_handler);
/*
* Only handle NAs if we are prepared to send out NAs.
* This is perhaps logically incorrect, but this condition was present in
* uip_process and we keep it until proven wrong
*/
uip_icmp6_register_input_handler(&na_input_handler);
#endif
#if UIP_ND6_SEND_NS
/*
* Only handle NAs if we are prepared to send out NSs. */
uip_icmp6_register_input_handler(&na_input_handler);
#endif
#if UIP_CONF_ROUTER && UIP_ND6_SEND_RA
/* Only accept RS if we are a router and happy to send out RAs */

View file

@ -86,6 +86,11 @@
#else
#define UIP_ND6_SEND_RA UIP_CONF_ND6_SEND_RA
#endif
#ifndef UIP_CONF_ND6_SEND_NS
#define UIP_ND6_SEND_NS 1 /* enable/disable NS sending */
#else
#define UIP_ND6_SEND_NS UIP_CONF_ND6_SEND_NS
#endif
#ifndef UIP_CONF_ND6_SEND_NA
#define UIP_ND6_SEND_NA 1 /* enable/disable NA sending */
#else
@ -125,7 +130,7 @@
#if UIP_CONF_LL_802154
#define UIP_ND6_DEF_MAXDADNS 0
#else /* UIP_CONF_LL_802154 */
#define UIP_ND6_DEF_MAXDADNS UIP_ND6_SEND_NA
#define UIP_ND6_DEF_MAXDADNS UIP_ND6_SEND_NS
#endif /* UIP_CONF_LL_802154 */
#else /* UIP_CONF_ND6_DEF_MAXDADNS */
#define UIP_ND6_DEF_MAXDADNS UIP_CONF_ND6_DEF_MAXDADNS

View file

@ -85,9 +85,9 @@
#include "rpl/rpl-private.h"
#endif
#if UIP_ND6_SEND_NA
#if UIP_ND6_SEND_NS
#include "net/ipv6/uip-ds6-nbr.h"
#endif /* UIP_ND6_SEND_NA */
#endif /* UIP_ND6_SEND_NS */
#include <string.h>
@ -1156,11 +1156,11 @@ uip_process(uint8_t flag)
}
/* Refresh neighbor state after receiving a unicast message */
#if UIP_ND6_SEND_NA
#if UIP_ND6_SEND_NS
if(!uip_is_addr_mcast(&UIP_IP_BUF->destipaddr)) {
uip_ds6_nbr_refresh_reachable_state(&UIP_IP_BUF->srcipaddr);
}
#endif /* UIP_ND6_SEND_NA */
#endif /* UIP_ND6_SEND_NS */
#if UIP_CONF_ROUTER
/*

View file

@ -215,13 +215,13 @@ rpl_parent_is_reachable(rpl_parent_t *p) {
if(p == NULL || p->dag == NULL || p->dag->instance == NULL || p->dag->instance->of == NULL) {
return 0;
} else {
#ifndef UIP_CONF_ND6_SEND_NA
#if UIP_ND6_SEND_NS
uip_ds6_nbr_t *nbr = rpl_get_nbr(p);
/* Exclude links to a neighbor that is not reachable at a NUD level */
if(nbr == NULL || nbr->state != NBR_REACHABLE) {
return 0;
}
#endif /* UIP_CONF_ND6_SEND_NA */
#endif /* UIP_ND6_SEND_NS */
/* If we don't have fresh link information, assume the parent is reachable. */
return !rpl_parent_is_fresh(p) || p->dag->instance->of->parent_has_usable_link(p);
}
@ -877,7 +877,7 @@ best_parent(rpl_dag_t *dag, int fresh_only)
continue;
}
#ifndef UIP_CONF_ND6_SEND_NA
#if UIP_ND6_SEND_NS
{
uip_ds6_nbr_t *nbr = rpl_get_nbr(p);
/* Exclude links to a neighbor that is not reachable at a NUD level */
@ -885,7 +885,7 @@ best_parent(rpl_dag_t *dag, int fresh_only)
continue;
}
}
#endif /* UIP_CONF_ND6_SEND_NA */
#endif /* UIP_ND6_SEND_NS */
/* Now we have an acceptable parent, check if it is the new best */
best = of->best_parent(best, p);

View file

@ -281,11 +281,11 @@ rpl_ipv6_neighbor_callback(uip_ds6_nbr_t *nbr)
PRINTF("RPL: Neighbor state changed for ");
PRINT6ADDR(&nbr->ipaddr);
#if UIP_ND6_SEND_NA || UIP_ND6_SEND_RA
#if UIP_ND6_SEND_NS || UIP_ND6_SEND_RA
PRINTF(", nscount=%u, state=%u\n", nbr->nscount, nbr->state);
#else /* UIP_ND6_SEND_NA || UIP_ND6_SEND_RA */
#else /* UIP_ND6_SEND_NS || UIP_ND6_SEND_RA */
PRINTF(", state=%u\n", nbr->state);
#endif /* UIP_ND6_SEND_NA || UIP_ND6_SEND_RA */
#endif /* UIP_ND6_SEND_NS || UIP_ND6_SEND_RA */
for(instance = &instance_table[0], end = instance + RPL_MAX_INSTANCES; instance < end; ++instance) {
if(instance->used == 1 ) {
p = rpl_find_parent_any_dag(instance, &nbr->ipaddr);

View file

@ -45,6 +45,6 @@
#define BUTTON_SENSOR_CONF_ON 1
#define UIP_CONF_ICMP6 1
#define RIMESTATS_CONF_ENABLED 1
#define UIP_CONF_ND6_SEND_NA 1
#define UIP_CONF_ND6_SEND_NS 1
#endif /* PROJECT_CONF_H_ */

View file

@ -4,5 +4,5 @@ all: $(CONTIKI_PROJECT)
CONTIKI = ../../..
CONTIKI_WITH_IPV6 = 1
CFLAGS += -DUIP_CONF_ND6_SEND_NA=1
CFLAGS += -DUIP_CONF_ND6_SEND_NS=1
include $(CONTIKI)/Makefile.include

View file

@ -155,8 +155,8 @@
#define RPL_NS_CONF_LINK_NUM 8
#undef NBR_TABLE_CONF_MAX_NEIGHBORS
#define NBR_TABLE_CONF_MAX_NEIGHBORS 8
#undef UIP_CONF_ND6_SEND_NA
#define UIP_CONF_ND6_SEND_NA 0
#undef UIP_CONF_ND6_SEND_NS
#define UIP_CONF_ND6_SEND_NS 0
#undef SICSLOWPAN_CONF_FRAG
#define SICSLOWPAN_CONF_FRAG 0

View file

@ -116,9 +116,9 @@
#define RPL_CONF_MAX_INSTANCES 1 /* default 1 */
#define RPL_CONF_MAX_DAG_PER_INSTANCE 1 /* default 2 */
/* No RA, No NA */
#undef UIP_CONF_ND6_SEND_NA
#define UIP_CONF_ND6_SEND_NA 0
/* No RA, No NS */
#undef UIP_CONF_ND6_SEND_NS
#define UIP_CONF_ND6_SEND_NS 0
#undef UIP_CONF_ND6_SEND_RA
#define UIP_CONF_ND6_SEND_RA 0

View file

@ -2,5 +2,5 @@ all: udp-server udp-client
CONTIKI = ../..
CONTIKI_WITH_IPV6 = 1
CFLAGS += -DUIP_CONF_ND6_SEND_NA=1
CFLAGS += -DUIP_CONF_ND6_SEND_NS=1
include $(CONTIKI)/Makefile.include

View file

@ -109,7 +109,7 @@
/* ND and Routing */
#define UIP_CONF_ROUTER 0 /**< BLE master role, which allows for routing, isn't supported. */
#define UIP_CONF_ND6_SEND_NA 1
#define UIP_CONF_ND6_SEND_NS 1
#define UIP_CONF_IP_FORWARD 0 /**< No packet forwarding. */
#define UIP_CONF_ND6_REACHABLE_TIME 600000

View file

@ -157,7 +157,7 @@
#endif /* UIP_CONF_MAX_ROUTES */
#define UIP_CONF_ND6_SEND_RA 0
#define UIP_CONF_ND6_SEND_NA 0
#define UIP_CONF_ND6_SEND_NS 0
#define UIP_CONF_ND6_REACHABLE_TIME 600000
#define UIP_CONF_ND6_RETRANS_TIMER 10000

View file

@ -1,5 +1,5 @@
#undef UIP_CONF_ND6_SEND_NA
#define UIP_CONF_ND6_SEND_NA 1
#undef UIP_CONF_ND6_SEND_NS
#define UIP_CONF_ND6_SEND_NS 1
#ifdef BUFSIZE
#undef UIP_CONF_BUFFER_SIZE

View file

@ -1,5 +1,5 @@
#undef UIP_CONF_ND6_SEND_NA
#define UIP_CONF_ND6_SEND_NA 1
#undef UIP_CONF_ND6_SEND_NS
#define UIP_CONF_ND6_SEND_NS 1
#ifdef BUFSIZE
#undef UIP_CONF_BUFFER_SIZE