treewide: define and use macro IN6_IS_ADDR_ULA
authorHans Dedecker <dedeckeh@gmail.com>
Fri, 10 Feb 2017 16:03:49 +0000 (17:03 +0100)
committerHans Dedecker <dedeckeh@gmail.com>
Fri, 10 Feb 2017 16:13:41 +0000 (17:13 +0100)
Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
src/ndp.c
src/odhcpd.h
src/router.c

index 427547dad9995899d54ac341bd0c36cc32bb017c..586658846f87b1367d0dda63823d1e558fbe6c40 100644 (file)
--- a/src/ndp.c
+++ b/src/ndp.c
@@ -328,8 +328,8 @@ static void setup_route(struct in6_addr *addr, struct interface *iface, bool add
 static int prefixcmp(const void *va, const void *vb)
 {
        const struct odhcpd_ipaddr *a = va, *b = vb;
-       uint32_t a_pref = ((a->addr.s6_addr[0] & 0xfe) != 0xfc) ? a->preferred : 1;
-       uint32_t b_pref = ((b->addr.s6_addr[0] & 0xfe) != 0xfc) ? b->preferred : 1;
+       uint32_t a_pref = IN6_IS_ADDR_ULA(&a->addr) ? 1 : a->preferred;
+       uint32_t b_pref = IN6_IS_ADDR_ULA(&b->addr) ? 1 : b->preferred;
        return (a_pref < b_pref) ? 1 : (a_pref > b_pref) ? -1 : 0;
 }
 
index fb78ec0eee7812ac1fbe557c3e0797c853e19da2..ceef0bfb0e380f25dff75593fcfcb0f36de0450a 100644 (file)
@@ -57,6 +57,7 @@
 #define ALL_IPV6_ROUTERS {{{0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02}}}
 
+#define IN6_IS_ADDR_ULA(a) (((a)->s6_addr32[0] & htonl(0xfe000000)) == htonl(0xfc000000))
 
 struct interface;
 struct nl_sock;
index e11fa012a9cc753f634d2b72f876b13153d97d2b..36267bea6d36269ac96866e83cb6484d776096d6 100644 (file)
@@ -309,7 +309,7 @@ static uint64_t send_router_advert(struct interface *iface, const struct in6_add
                uint32_t this_lifetime = TIME_LEFT(addr->valid, now);
                if (this_lifetime > UINT16_MAX)
                        this_lifetime = UINT16_MAX;
-               if (((addr->addr.s6_addr[0] & 0xfe) != 0xfc || iface->default_router)
+               if ((!IN6_IS_ADDR_ULA(&addr->addr) || iface->default_router)
                                && adv.h.nd_ra_router_lifetime
                                && ntohs(adv.h.nd_ra_router_lifetime) < this_lifetime) {
                        adv.h.nd_ra_router_lifetime = htons(this_lifetime);