summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorHans Dedecker <dedeckeh@gmail.com>2017-02-10 17:03:49 +0100
committerHans Dedecker <dedeckeh@gmail.com>2017-02-10 17:13:41 +0100
commit68ee0b59040625d2ab5830b1c1cc8eca2da0dcf1 (patch)
tree29422737a037cc2f99b67b86eccd50098484fb4b /src
parentfa57225cb62b43adffc37a50c3dbd3fa7d225b0b (diff)
treewide: define and use macro IN6_IS_ADDR_ULA
Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/ndp.c4
-rw-r--r--src/odhcpd.h1
-rw-r--r--src/router.c2
3 files changed, 4 insertions, 3 deletions
diff --git a/src/ndp.c b/src/ndp.c
index 427547d..5866588 100644
--- 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;
}
diff --git a/src/odhcpd.h b/src/odhcpd.h
index fb78ec0..ceef0bf 100644
--- a/src/odhcpd.h
+++ b/src/odhcpd.h
@@ -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;
diff --git a/src/router.c b/src/router.c
index e11fa01..36267be 100644
--- a/src/router.c
+++ b/src/router.c
@@ -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);