[SLOF] [PATCH 2/6] net-snk: Fix the check for link-local addresses when receiving RAs
Thomas Huth
thuth at redhat.com
Thu Jan 14 10:10:35 AEDT 2016
The code that checks whether the router advertisments contain only
a link-local address has a bug: It must check the full first 10 bits
of the address, not only the first 9 bits. Otherwise, site-local
addresses (which start with 0xFEC0...) are also recognized as
link-local, which is wrong, of course.
Fix it by also introducing a proper wrapper functions for link-local
addresses (which will be used in a later patch, too).
Signed-off-by: Thomas Huth <thuth at redhat.com>
---
clients/net-snk/app/netlib/icmpv6.c | 4 ++--
clients/net-snk/app/netlib/ipv6.h | 7 +++++++
2 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/clients/net-snk/app/netlib/icmpv6.c b/clients/net-snk/app/netlib/icmpv6.c
index be6cc11..940b834 100644
--- a/clients/net-snk/app/netlib/icmpv6.c
+++ b/clients/net-snk/app/netlib/icmpv6.c
@@ -78,8 +78,8 @@ handle_prefixoption (uint8_t *option)
prefix_option = (struct option_prefix *) option;
memcpy( &(prefix.addr), &(prefix_option->prefix.addr), IPV6_ADDR_LENGTH);
- /* Link-local adresses in RAs are nonsense */
- if ( (IPV6_LL_PREFIX & (prefix_option->prefix.part.prefix)) == IPV6_LL_PREFIX )
+ /* Link-local adresses in RAs are nonsense */
+ if (ip6_is_linklocal(&prefix))
return;
if (prefix_option->preferred_lifetime > prefix_option->valid_lifetime)
diff --git a/clients/net-snk/app/netlib/ipv6.h b/clients/net-snk/app/netlib/ipv6.h
index b496364..963a1b0 100644
--- a/clients/net-snk/app/netlib/ipv6.h
+++ b/clients/net-snk/app/netlib/ipv6.h
@@ -26,6 +26,7 @@
#define IPV6_ADDR_LENGTH 16 /* Size of IPv6 adress in bytes */
#define IPV6_LL_PREFIX 0xFE80000000000000ULL
+#define IPV6_LL_PREFIX_MASK 0xFFC0000000000000ULL
#define IPV6_SOLIC_NODE_PREFIX 0xFF02000000000000ULL
#define IPV6_SOLIC_NODE_IFACE_ID 0x00000001FF000000ULL
@@ -179,6 +180,12 @@ void * ip6_prefix2addr (ip6_addr_t prefix);
/* Compare IPv6 adresses */
int8_t ip6_cmp( ip6_addr_t *ip_1, ip6_addr_t *ip_2 );
+/* Check if it is a link-local address */
+static inline int ip6_is_linklocal(ip6_addr_t *ip)
+{
+ return (ip->part.prefix & IPV6_LL_PREFIX_MASK) == IPV6_LL_PREFIX;
+}
+
/* Check if prefix is already in our list */
int8_t unknown_prefix (ip6_addr_t *ip);
--
1.8.3.1
More information about the SLOF
mailing list