summaryrefslogtreecommitdiffstats
path: root/if.c
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2016-09-16 15:49:01 +0000
committerRoy Marples <roy@marples.name>2016-09-16 15:49:01 +0000
commitb0601fe4165e342848c344faf2e08720db5fa271 (patch)
tree35a23064feb1fe237cbc934fa2f0cf55c0e8f0b3 /if.c
parentba13abcc97a2f606a2d7ea85832cd90e7a3cad06 (diff)
downloaddhcpcd-b0601fe4165e342848c344faf2e08720db5fa271.tar.xz
One BSD in the future will include address flags in ifa_msghdr.
A libc in the future will include address flags in ifaddrs. Although this does make the code a bit more #ifdef messy, the end result is a smaller binary, and less ioctls to make.
Diffstat (limited to 'if.c')
-rw-r--r--if.c30
1 files changed, 28 insertions, 2 deletions
diff --git a/if.c b/if.c
index 6a311ef8..fcfdf3da 100644
--- a/if.c
+++ b/if.c
@@ -198,12 +198,16 @@ static void if_learnaddrs(struct dhcpcd_ctx *ctx, struct if_head *ifs,
#ifdef INET6
struct sockaddr_in6 *sin6, *net6;
#endif
+ int addrflags;
for (ifa = ifaddrs; ifa; ifa = ifa->ifa_next) {
if (ifa->ifa_addr == NULL)
continue;
if ((ifp = if_find(ifs, ifa->ifa_name)) == NULL)
continue;
+#ifdef HAVE_IFADDRS_ADDRFLAGS
+ addrflags = (int)ifa->ifa_addrflags;
+#endif
switch(ifa->ifa_addr->sa_family) {
#ifdef INET
case AF_INET:
@@ -213,9 +217,21 @@ static void if_learnaddrs(struct dhcpcd_ctx *ctx, struct if_head *ifs,
brd = (void *)ifa->ifa_dstaddr;
else
brd = (void *)ifa->ifa_broadaddr;
+#ifndef HAVE_IFADDRS_ADDRFLAGS
+ addrflags = if_addrflags(ifp, &addr->sin_addr,
+ ifa->ifa_name);
+ if (addrflags == -1) {
+ if (errno != EEXIST)
+ logger(ctx, LOG_ERR,
+ "%s: if_addrflags: %s: %m",
+ __func__,
+ inet_ntoa(addr->sin_addr));
+ continue;
+ }
+#endif
ipv4_handleifa(ctx, RTM_NEWADDR, ifs, ifa->ifa_name,
&addr->sin_addr, &net->sin_addr,
- brd ? &brd->sin_addr : NULL);
+ brd ? &brd->sin_addr : NULL, addrflags);
break;
#endif
#ifdef INET6
@@ -228,9 +244,19 @@ static void if_learnaddrs(struct dhcpcd_ctx *ctx, struct if_head *ifs,
sin6->sin6_addr.s6_addr[2] =
sin6->sin6_addr.s6_addr[3] = '\0';
#endif
+#ifndef HAVE_IFADDRS_ADDRFLAGS
+ addrflags = if_addrflags6(ifp, &sin6->sin6_addr,
+ ifa->ifa_name);
+ if (addrflags == -1) {
+ if (errno != EEXIST)
+ logger(ctx, LOG_ERR,
+ "%s: if_addrflags6: %m", __func__);
+ continue;
+ }
+#endif
ipv6_handleifa(ctx, RTM_NEWADDR, ifs,
ifa->ifa_name, &sin6->sin6_addr,
- ipv6_prefixlen(&net6->sin6_addr));
+ ipv6_prefixlen(&net6->sin6_addr), addrflags);
break;
#endif
}