From 1d3da44991fc6ccfc77db59aa71b8f73d10ab9e2 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sat, 8 Mar 2014 21:35:17 +0000 Subject: [PATCH] Register generic ICMPv6 handlers for IPv6 ND --- core/net/ipv6/uip-nd6.c | 93 ++++++++++++++++++++++++++++++++++------- core/net/ipv6/uip-nd6.h | 38 +---------------- core/net/ipv6/uip6.c | 1 + 3 files changed, 82 insertions(+), 50 deletions(-) diff --git a/core/net/ipv6/uip-nd6.c b/core/net/ipv6/uip-nd6.c index 2eb47f176..f2e601fed 100644 --- a/core/net/ipv6/uip-nd6.c +++ b/core/net/ipv6/uip-nd6.c @@ -126,8 +126,6 @@ static uip_ds6_prefix_t *prefix; /** Pointer to a prefix list entry */ 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 */ - - /*------------------------------------------------------------------*/ /* create a llao */ static void @@ -143,8 +141,8 @@ create_llao(uint8_t *llao, uint8_t type) { /*------------------------------------------------------------------*/ -void -uip_nd6_ns_input(void) +static void +ns_input(void) { uint8_t flags; PRINTF("Received NS from "); @@ -388,12 +386,26 @@ uip_nd6_ns_output(uip_ipaddr_t * src, uip_ipaddr_t * dest, uip_ipaddr_t * tgt) PRINTF("\n"); return; } - - - /*------------------------------------------------------------------*/ -void -uip_nd6_na_input(void) +/** + * Neighbor Advertisement Processing + * + * we might have to send a pkt that had been buffered while address + * resolution was performed (if we support buffering, see UIP_CONF_QUEUE_PKT) + * + * As per RFC 4861, on link layer that have addresses, TLLAO options MUST be + * included when responding to multicast solicitations, SHOULD be included in + * response to unicast (here we assume it is for now) + * + * NA can be received after sending NS for DAD, Address resolution or NUD. Can + * be unsolicited as well. + * It can trigger update of the state of the neighbor in the neighbor cache, + * router in the router list. + * If the NS was for DAD, it means DAD failed + * + */ +static void +na_input(void) { uint8_t is_llchange; uint8_t is_router; @@ -548,8 +560,8 @@ discard: #if UIP_CONF_ROUTER #if UIP_ND6_SEND_RA /*---------------------------------------------------------------------------*/ -void -uip_nd6_rs_input(void) +static void +rs_input(void) { PRINTF("Received RS from"); @@ -761,11 +773,18 @@ uip_nd6_rs_output(void) PRINTF("\n"); return; } - - /*---------------------------------------------------------------------------*/ +/* + * Process a Router Advertisement + * + * - Possible actions when receiving a RA: add router to router list, + * recalculate reachable time, update link hop limit, update retrans timer. + * - If MTU option: update MTU. + * - If SLLAO option: update entry in neighbor cache + * - If prefix option: start autoconf, add prefix to prefix list + */ void -uip_nd6_ra_input(void) +ra_input(void) { PRINTF("Received RA from"); PRINT6ADDR(&UIP_IP_BUF->srcipaddr); @@ -969,6 +988,52 @@ discard: return; } #endif /* !UIP_CONF_ROUTER */ +/*------------------------------------------------------------------*/ +/* ICMPv6 input handlers */ +#if UIP_ND6_SEND_NA +UIP_ICMP6_HANDLER(ns_input_handler, ICMP6_NS, UIP_ICMP6_HANDLER_CODE_ANY, + ns_input); +UIP_ICMP6_HANDLER(na_input_handler, ICMP6_NA, UIP_ICMP6_HANDLER_CODE_ANY, + na_input); +#endif +#if UIP_CONF_ROUTER && UIP_ND6_SEND_RA +UIP_ICMP6_HANDLER(rs_input_handler, ICMP6_RS, UIP_ICMP6_HANDLER_CODE_ANY, + rs_input); +#endif + +#if !UIP_CONF_ROUTER +UIP_ICMP6_HANDLER(ra_input_handler, ICMP6_RA, UIP_ICMP6_HANDLER_CODE_ANY, + ra_input); +#endif +/*---------------------------------------------------------------------------*/ +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_CONF_ROUTER && UIP_ND6_SEND_RA + /* Only accept RS if we are a router and happy to send out RAs */ + uip_icmp6_register_input_handler(&rs_input_handler); +#endif + +#if !UIP_CONF_ROUTER + /* Only process RAs if we are not a router */ + uip_icmp6_register_input_handler(&ra_input_handler); +#endif +} +/*---------------------------------------------------------------------------*/ /** @} */ #endif /* UIP_CONF_IPV6 */ diff --git a/core/net/ipv6/uip-nd6.h b/core/net/ipv6/uip-nd6.h index d6719ae33..b3ee3a1d5 100644 --- a/core/net/ipv6/uip-nd6.h +++ b/core/net/ipv6/uip-nd6.h @@ -337,34 +337,8 @@ uip_nd6_ns_input(void); void uip_nd6_ns_output(uip_ipaddr_t *src, uip_ipaddr_t *dest, uip_ipaddr_t *tgt); -/** - * \brief Process a Neighbor Advertisement - * - * we might have to send a pkt that had been buffered while address - * resolution was performed (if we support buffering, see UIP_CONF_QUEUE_PKT) - * - * As per RFC 4861, on link layer that have addresses, TLLAO options MUST be - * included when responding to multicast solicitations, SHOULD be included in - * response to unicast (here we assume it is for now) - * - * NA can be received after sending NS for DAD, Address resolution or NUD. Can - * be unsolicited as well. - * It can trigger update of the state of the neighbor in the neighbor cache, - * router in the router list. - * If the NS was for DAD, it means DAD failed - * - */ -void -uip_nd6_na_input(void); - #if UIP_CONF_ROUTER #if UIP_ND6_SEND_RA -/** - * \brief Process a Router Solicitation - * - */ -void uip_nd6_rs_input(void); - /** * \brief send a Router Advertisement * @@ -388,17 +362,9 @@ void uip_nd6_ra_output(uip_ipaddr_t *dest); void uip_nd6_rs_output(void); /** - * - * \brief process a Router Advertisement - * - * - Possible actions when receiving a RA: add router to router list, - * recalculate reachable time, update link hop limit, update retrans timer. - * - If MTU option: update MTU. - * - If SLLAO option: update entry in neighbor cache - * - If prefix option: start autoconf, add prefix to prefix list + * \brief Initialise the uIP ND core */ -void -uip_nd6_ra_input(void); +void uip_nd6_init(void); /** @} */ diff --git a/core/net/ipv6/uip6.c b/core/net/ipv6/uip6.c index e515df43b..746b31ab2 100644 --- a/core/net/ipv6/uip6.c +++ b/core/net/ipv6/uip6.c @@ -412,6 +412,7 @@ uip_init(void) uip_ds6_init(); uip_icmp6_init(); + uip_nd6_init(); #if UIP_TCP for(c = 0; c < UIP_LISTENPORTS; ++c) {