diff options
| author | Roy Marples <roy@marples.name> | 2017-12-07 17:01:39 +0000 |
|---|---|---|
| committer | Roy Marples <roy@marples.name> | 2017-12-07 17:01:39 +0000 |
| commit | b86b4ac47fa09edafa6ce3c009751557fe1a6138 (patch) | |
| tree | f24378f908a0b6a9be1f937cb63319a6a2842d83 /src/if.c | |
| parent | 1394cd9a65be98a3afb278f6d523dc262a721334 (diff) | |
| download | dhcpcd-b86b4ac47fa09edafa6ce3c009751557fe1a6138.tar.xz | |
dhcp6: don't listen on IPv6 addresses when not using DHCP6
To achieve this we need to learn the addresses AFTER the interface
configuration has been loaded.
Diffstat (limited to 'src/if.c')
| -rw-r--r-- | src/if.c | 32 |
1 files changed, 19 insertions, 13 deletions
@@ -190,8 +190,9 @@ if_hasconf(struct dhcpcd_ctx *ctx, const char *ifname) return 0; } -static void if_learnaddrs(struct dhcpcd_ctx *ctx, struct if_head *ifs, - struct ifaddrs *ifaddrs) +void +if_learnaddrs(struct dhcpcd_ctx *ctx, struct if_head *ifs, + struct ifaddrs **ifaddrs) { struct ifaddrs *ifa; struct interface *ifp; @@ -203,7 +204,7 @@ static void if_learnaddrs(struct dhcpcd_ctx *ctx, struct if_head *ifs, #endif int addrflags; - for (ifa = ifaddrs; ifa; ifa = ifa->ifa_next) { + for (ifa = *ifaddrs; ifa; ifa = ifa->ifa_next) { if (ifa->ifa_addr == NULL) continue; if ((ifp = if_find(ifs, ifa->ifa_name)) == NULL) @@ -262,6 +263,9 @@ static void if_learnaddrs(struct dhcpcd_ctx *ctx, struct if_head *ifs, #endif } } + + freeifaddrs(*ifaddrs); + *ifaddrs = NULL; } bool @@ -283,9 +287,10 @@ if_valid_hwaddr(const uint8_t *hwaddr, size_t hwlen) } struct if_head * -if_discover(struct dhcpcd_ctx *ctx, int argc, char * const *argv) +if_discover(struct dhcpcd_ctx *ctx, struct ifaddrs **ifaddrs, + int argc, char * const *argv) { - struct ifaddrs *ifaddrs, *ifa; + struct ifaddrs *ifa; int i; unsigned int active; struct if_head *ifs; @@ -307,14 +312,17 @@ if_discover(struct dhcpcd_ctx *ctx, int argc, char * const *argv) const struct sockaddr_ll *sll; #endif - if (getifaddrs(&ifaddrs) == -1) + if ((ifs = malloc(sizeof(*ifs))) == NULL) { + logerr(__func__); return NULL; - - if ((ifs = malloc(sizeof(*ifs))) == NULL) - goto failed; + } TAILQ_INIT(ifs); + if (getifaddrs(ifaddrs) == -1) { + logerr(__func__); + goto out; + } - for (ifa = ifaddrs; ifa; ifa = ifa->ifa_next) { + for (ifa = *ifaddrs; ifa; ifa = ifa->ifa_next) { if (ifa->ifa_addr != NULL) { #ifdef AF_LINK if (ifa->ifa_addr->sa_family != AF_LINK) @@ -565,9 +573,7 @@ if_discover(struct dhcpcd_ctx *ctx, int argc, char * const *argv) TAILQ_INSERT_TAIL(ifs, ifp, next); } - if_learnaddrs(ctx, ifs, ifaddrs); -failed: - freeifaddrs(ifaddrs); +out: return ifs; } |
