From 6d1a4f16a412035086aa72201de22616a8283d64 Mon Sep 17 00:00:00 2001 From: Justin Pettit Date: Sat, 25 Jun 2016 22:22:02 -0700 Subject: [PATCH] packets: Add in6_is_lla() function. 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 Acked-by: Ben Pfaff --- lib/packets.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/packets.h b/lib/packets.h index 0d7cfc878..8f11e2c05 100644 --- a/lib/packets.h +++ b/lib/packets.h @@ -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) { -- 2.20.1