packets: Add in6_is_lla() function.
authorJustin Pettit <jpettit@ovn.org>
Sun, 26 Jun 2016 05:22:02 +0000 (22:22 -0700)
committerJustin Pettit <jpettit@ovn.org>
Wed, 20 Jul 2016 05:18:35 +0000 (22:18 -0700)
Checks whether the supplied IPv6 address is a link local address.

This will have a caller in a future commit.

Signed-off-by: Justin Pettit <jpettit@ovn.org>
Acked-by: Ben Pfaff <blp@ovn.org>
lib/packets.h

index 0d7cfc8..8f11e2c 100644 (file)
@@ -980,6 +980,18 @@ in6_generate_lla(struct eth_addr ea, struct in6_addr *lla)
     taddr->be16[7] = ea.be16[2];
 }
 
+/* Returns true if 'addr' is a link local address.  Otherwise, false. */
+static inline bool
+in6_is_lla(struct in6_addr *addr)
+{
+#ifdef s6_addr32
+    return addr->s6_addr32[0] == htonl(0xfe800000) && !(addr->s6_addr32[1]);
+#else
+    return addr->s6_addr[0] == htons(0xfe80) &&
+         !(addr->s6_addr[1] | addr->s6_addr[2] | addr->s6_addr[3]);
+#endif
+}
+
 static inline void
 ipv6_multicast_to_ethernet(struct eth_addr *eth, const struct in6_addr *ip6)
 {