[ovs-dev] [ovn-ipv6 20/26] packets: Add in6_is_lla() function.

Justin Pettit jpettit at ovn.org
Wed Jul 20 05:16:12 UTC 2016


> On Jul 13, 2016, at 12:57 PM, Ben Pfaff <blp at ovn.org> wrote:
> 
> On Mon, Jul 11, 2016 at 11:56:50PM -0700, Justin Pettit wrote:
>> This will have a caller in a future commit.
>> 
>> Signed-off-by: Justin Pettit <jpettit at ovn.org>
> 
>> +static inline bool
>> +in6_is_lla(struct in6_addr *addr)
>> +{
>> +    return addr->s6_addr32[0] == htonl(0xfe800000) && !(addr->s6_addr32[1]);
>> +}
> 
> One more thing: not all implementations have s6_addr32, so we probably
> need a fallback.

Good point.  I've addressed that as well as your previous comments.

--Justin


-=-=-=-=-=-=-=-=-=-

diff --git a/lib/packets.h b/lib/packets.h
index 02028c9..8f11e2c 100644
--- a/lib/packets.h
+++ b/lib/packets.h
@@ -980,10 +980,16 @@ 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





More information about the dev mailing list