diff options
| author | Roy Marples <roy@marples.name> | 2015-05-01 12:34:07 +0000 |
|---|---|---|
| committer | Roy Marples <roy@marples.name> | 2015-05-01 12:34:07 +0000 |
| commit | c37a324e88ba54650abef7aea0e02795b978c80f (patch) | |
| tree | 85a6880ee260d5c83db415cbc26dde4d9ca7aa20 /if.c | |
| parent | bee534494cdd5891de0aee4e62500437cc3e3af2 (diff) | |
| download | dhcpcd-c37a324e88ba54650abef7aea0e02795b978c80f.tar.xz | |
Move address learning into a separate function for future use.
Diffstat (limited to 'if.c')
| -rw-r--r-- | if.c | 117 |
1 files changed, 62 insertions, 55 deletions
@@ -160,6 +160,67 @@ if_hasconf(struct dhcpcd_ctx *ctx, const char *ifname) return 0; } +static void if_learnaddrs1(struct dhcpcd_ctx *ctx, struct if_head *ifs, + struct ifaddrs *ifaddrs) +{ + struct ifaddrs *ifa; + struct interface *ifp; +#ifdef INET + const struct sockaddr_in *addr, *net, *dst; +#endif +#ifdef INET6 + struct sockaddr_in6 *sin6, *net6; +#endif + int ifa_flags; + + + for (ifa = ifaddrs; ifa; ifa = ifa->ifa_next) { + if (ifa->ifa_addr == NULL) + continue; + if ((ifp = if_find(ifs, ifa->ifa_name)) == NULL) + continue; + switch(ifa->ifa_addr->sa_family) { +#ifdef INET + case AF_INET: + addr = (const struct sockaddr_in *) + (void *)ifa->ifa_addr; + net = (const struct sockaddr_in *) + (void *)ifa->ifa_netmask; + if (ifa->ifa_flags & IFF_POINTOPOINT) + dst = (const struct sockaddr_in *) + (void *)ifa->ifa_dstaddr; + else + dst = NULL; + ifa_flags = if_addrflags(&addr->sin_addr, ifp); + ipv4_handleifa(ctx, RTM_NEWADDR, ifs, ifa->ifa_name, + &addr->sin_addr, + &net->sin_addr, + dst ? &dst->sin_addr : NULL, ifa_flags); + break; +#endif +#ifdef INET6 + case AF_INET6: + sin6 = (struct sockaddr_in6 *)(void *)ifa->ifa_addr; + net6 = (struct sockaddr_in6 *)(void *)ifa->ifa_netmask; +#ifdef __KAME__ + if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) + /* Remove the scope from the address */ + sin6->sin6_addr.s6_addr[2] = + sin6->sin6_addr.s6_addr[3] = '\0'; +#endif + ifa_flags = if_addrflags6(&sin6->sin6_addr, ifp); + if (ifa_flags != -1) + ipv6_handleifa(ctx, RTM_NEWADDR, ifs, + ifa->ifa_name, + &sin6->sin6_addr, + ipv6_prefixlen(&net6->sin6_addr), + ifa_flags); + break; +#endif + } + } +} + struct if_head * if_discover(struct dhcpcd_ctx *ctx, int argc, char * const *argv) { @@ -171,15 +232,6 @@ if_discover(struct dhcpcd_ctx *ctx, int argc, char * const *argv) #ifdef __linux__ char ifn[IF_NAMESIZE]; #endif -#ifdef INET - const struct sockaddr_in *addr; - const struct sockaddr_in *net; - const struct sockaddr_in *dst; -#endif -#ifdef INET6 - struct sockaddr_in6 *sin6, *net6; - int ifa_flags; -#endif #ifdef AF_LINK const struct sockaddr_dl *sdl; #ifdef SIOCGIFPRIORITY @@ -475,52 +527,7 @@ if_discover(struct dhcpcd_ctx *ctx, int argc, char * const *argv) TAILQ_INSERT_TAIL(ifs, ifp, next); } - for (ifa = ifaddrs; ifa; ifa = ifa->ifa_next) { - if (ifa->ifa_addr == NULL) - continue; - if ((ifp = if_find(ifs, ifa->ifa_name)) == NULL) - continue; - switch(ifa->ifa_addr->sa_family) { -#ifdef INET - case AF_INET: - addr = (const struct sockaddr_in *) - (void *)ifa->ifa_addr; - net = (const struct sockaddr_in *) - (void *)ifa->ifa_netmask; - if (ifa->ifa_flags & IFF_POINTOPOINT) - dst = (const struct sockaddr_in *) - (void *)ifa->ifa_dstaddr; - else - dst = NULL; - ifa_flags = if_addrflags(&addr->sin_addr, ifp); - ipv4_handleifa(ctx, RTM_NEWADDR, ifs, ifa->ifa_name, - &addr->sin_addr, - &net->sin_addr, - dst ? &dst->sin_addr : NULL, ifa_flags); - break; -#endif -#ifdef INET6 - case AF_INET6: - sin6 = (struct sockaddr_in6 *)(void *)ifa->ifa_addr; - net6 = (struct sockaddr_in6 *)(void *)ifa->ifa_netmask; -#ifdef __KAME__ - if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) - /* Remove the scope from the address */ - sin6->sin6_addr.s6_addr[2] = - sin6->sin6_addr.s6_addr[3] = '\0'; -#endif - ifa_flags = if_addrflags6(&sin6->sin6_addr, ifp); - if (ifa_flags != -1) - ipv6_handleifa(ctx, RTM_NEWADDR, ifs, - ifa->ifa_name, - &sin6->sin6_addr, - ipv6_prefixlen(&net6->sin6_addr), - ifa_flags); - break; -#endif - } - } - + if_learnaddrs1(ctx, ifs, ifaddrs); freeifaddrs(ifaddrs); #ifdef SIOCGIFPRIORITY |
