From 6568d94902090adbd89e9318c7a57d025d1ba2bb Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 5 Feb 2015 09:43:29 -0600 Subject: [PATCH] ICMPv6: Add logic to behave like a router (if so configured): NuttX will not send the router advertisement message in response to any router solicitation messages. --- arch/arm/src/stm32/stm32_eth.c | 9 +++++++++ arch/arm/src/tiva/tm4c_ethernet.c | 9 +++++++++ net/icmpv6/icmpv6.h | 22 ++++++++++++++++++++++ net/icmpv6/icmpv6_input.c | 17 +++++++++++++++++ 4 files changed, 57 insertions(+) diff --git a/arch/arm/src/stm32/stm32_eth.c b/arch/arm/src/stm32/stm32_eth.c index d41e25ee69..ddb268c666 100644 --- a/arch/arm/src/stm32/stm32_eth.c +++ b/arch/arm/src/stm32/stm32_eth.c @@ -3537,6 +3537,15 @@ static void stm32_ipv6multicast(FAR struct stm32_ethmac_s *priv) (void)stm32_addmac(dev, g_ipv6_ethallnodes.ether_addr_octet); #endif /* CONFIG_NET_ICMPv6_AUTOCONF */ +#ifdef CONFIG_NET_ICMPv6_ROUTER + /* Add the IPv6 all link-local routers Ethernet address. This is the + * address that we expect to receive ICMPv6 Router Solicitation + * packets. + */ + + (void)stm32_addmac(dev, g_ipv6_ethallrouters.ether_addr_octet); + +#endif /* CONFIG_NET_ICMPv6_ROUTER */ } #endif /* CONFIG_NET_ICMPv6 */ diff --git a/arch/arm/src/tiva/tm4c_ethernet.c b/arch/arm/src/tiva/tm4c_ethernet.c index 71bad04081..a30377cb1a 100644 --- a/arch/arm/src/tiva/tm4c_ethernet.c +++ b/arch/arm/src/tiva/tm4c_ethernet.c @@ -3995,6 +3995,15 @@ static void tiva_ipv6multicast(FAR struct tiva_ethmac_s *priv) (void)tiva_addmac(dev, g_ipv6_ethallnodes.ether_addr_octet); #endif /* CONFIG_NET_ICMPv6_AUTOCONF */ +#ifdef CONFIG_NET_ICMPv6_ROUTER + /* Add the IPv6 all link-local routers Ethernet address. This is the + * address that we expect to receive ICMPv6 Router Solicitation + * packets. + */ + + (void)tiva_addmac(dev, g_ipv6_ethallrouters.ether_addr_octet); + +#endif /* CONFIG_NET_ICMPv6_ROUTER */ } #endif /* CONFIG_NET_ICMPv6 */ diff --git a/net/icmpv6/icmpv6.h b/net/icmpv6/icmpv6.h index 53d345fe9c..1a6c7d7b56 100644 --- a/net/icmpv6/icmpv6.h +++ b/net/icmpv6/icmpv6.h @@ -273,6 +273,28 @@ void icmpv6_rsolicit(FAR struct net_driver_s *dev); void icmpv6_advertise(FAR struct net_driver_s *dev, const net_ipv6addr_t destipaddr); +/**************************************************************************** + * Name: icmpv6_radvertise + * + * Description: + * Send an ICMPv6 Router Advertisement + * + * Parameters: + * dev - The device driver structure containing the outgoing ICMPv6 packet + * buffer + * + * Return: + * None + * + * Assumptions: + * The network is locked + * + ****************************************************************************/ + +#ifdef CONFIG_NET_ICMPv6_ROUTER +void icmpv6_radvertise(FAR struct net_driver_s *dev); +#endif + /**************************************************************************** * Function: icmpv6_wait_setup * diff --git a/net/icmpv6/icmpv6_input.c b/net/icmpv6/icmpv6_input.c index 3ed539ce78..f6e30008bd 100644 --- a/net/icmpv6/icmpv6_input.c +++ b/net/icmpv6/icmpv6_input.c @@ -194,6 +194,23 @@ void icmpv6_input(FAR struct net_driver_s *dev) } break; +#ifdef CONFIG_NET_ICMPv6_ROUTER + /* Check if we received a Router Solicitation */ + + case ICMPV6_ROUTER_SOLICIT: + { + /* Just give a knee-jerk Router Advertisement in respond with no + * further examination of the Router Solicitation. + */ + + icmpv6_radvertise(dev); + + /* All statistics have been updated. Nothing to do but exit. */ + + return; + } +#endif + #ifdef CONFIG_NET_ICMPv6_AUTOCONF /* Check if we received a Router Advertisement */