Module Name: src Committed By: roy Date: Wed Apr 22 17:42:22 UTC 2015
Modified Files: src/sbin/ifconfig: af_inet6.c ifconfig.c util.h Log Message: Move the INET6 specific code for wait_dad_exec() into af_inet6 by using a new afswtch hook af_addr_tentative. To generate a diff of this commit: cvs rdiff -u -r1.31 -r1.32 src/sbin/ifconfig/af_inet6.c cvs rdiff -u -r1.233 -r1.234 src/sbin/ifconfig/ifconfig.c cvs rdiff -u -r1.10 -r1.11 src/sbin/ifconfig/util.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sbin/ifconfig/af_inet6.c diff -u src/sbin/ifconfig/af_inet6.c:1.31 src/sbin/ifconfig/af_inet6.c:1.32 --- src/sbin/ifconfig/af_inet6.c:1.31 Tue Jan 20 22:13:19 2015 +++ src/sbin/ifconfig/af_inet6.c Wed Apr 22 17:42:22 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: af_inet6.c,v 1.31 2015/01/20 22:13:19 roy Exp $ */ +/* $NetBSD: af_inet6.c,v 1.32 2015/04/22 17:42:22 roy Exp $ */ /* * Copyright (c) 1983, 1993 @@ -31,7 +31,7 @@ #include <sys/cdefs.h> #ifndef lint -__RCSID("$NetBSD: af_inet6.c,v 1.31 2015/01/20 22:13:19 roy Exp $"); +__RCSID("$NetBSD: af_inet6.c,v 1.32 2015/04/22 17:42:22 roy Exp $"); #endif /* not lint */ #include <sys/param.h> @@ -72,6 +72,7 @@ static int setia6vltime_impl(prop_dictio static int setia6lifetime(prop_dictionary_t, int64_t, time_t *, uint32_t *); static void in6_status(prop_dictionary_t, prop_dictionary_t, bool); +static bool in6_addr_tentative(struct ifaddrs *ifa); static struct usage_func usage; static cmdloop_branch_t branch[2]; @@ -101,7 +102,8 @@ struct pkw inet6 = PKW_INITIALIZER(&inet static struct afswtch in6af = { .af_name = "inet6", .af_af = AF_INET6, .af_status = in6_status, - .af_addr_commit = in6_commit_address + .af_addr_commit = in6_commit_address, + .af_addr_tentative = in6_addr_tentative }; static int @@ -474,6 +476,22 @@ in6_commit_address(prop_dictionary_t env commit_address(env, oenv, &in6param); } +static bool +in6_addr_tentative(struct ifaddrs *ifa) +{ + int s; + struct in6_ifreq ifr; + + if ((s = getsock(AF_INET6)) == -1) + err(EXIT_FAILURE, "%s: getsock", __func__); + memset(&ifr, 0, sizeof(ifr)); + strncpy(ifr.ifr_name, ifa->ifa_name, sizeof(ifr.ifr_name)); + ifr.ifr_addr = *(struct sockaddr_in6 *)ifa->ifa_addr; + if (ioctl(s, SIOCGIFAFLAG_IN6, &ifr) == -1) + err(EXIT_FAILURE, "SIOCGIFAFLAG_IN6"); + return ifr.ifr_ifru.ifru_flags6 & IN6_IFF_TENTATIVE ? true : false; +} + static void in6_usage(prop_dictionary_t env) { Index: src/sbin/ifconfig/ifconfig.c diff -u src/sbin/ifconfig/ifconfig.c:1.233 src/sbin/ifconfig/ifconfig.c:1.234 --- src/sbin/ifconfig/ifconfig.c:1.233 Fri Sep 12 08:54:26 2014 +++ src/sbin/ifconfig/ifconfig.c Wed Apr 22 17:42:22 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: ifconfig.c,v 1.233 2014/09/12 08:54:26 martin Exp $ */ +/* $NetBSD: ifconfig.c,v 1.234 2015/04/22 17:42:22 roy Exp $ */ /*- * Copyright (c) 1997, 1998, 2000 The NetBSD Foundation, Inc. @@ -63,7 +63,7 @@ #ifndef lint __COPYRIGHT("@(#) Copyright (c) 1983, 1993\ The Regents of the University of California. All rights reserved."); -__RCSID("$NetBSD: ifconfig.c,v 1.233 2014/09/12 08:54:26 martin Exp $"); +__RCSID("$NetBSD: ifconfig.c,v 1.234 2015/04/22 17:42:22 roy Exp $"); #endif /* not lint */ #include <sys/param.h> @@ -515,14 +515,12 @@ no_cmds_exec(prop_dictionary_t env, prop static int wait_dad_exec(prop_dictionary_t env, prop_dictionary_t oenv) { -#ifdef INET6 bool waiting; struct ifaddrs *ifaddrs, *ifa; - struct in6_ifreq ifr6; - int s; const struct timespec ts = { .tv_sec = 0, .tv_nsec = WAIT_DAD }; const struct timespec add = { .tv_sec = wflag_secs, .tv_nsec = 0}; struct timespec now, end = { .tv_sec = wflag_secs, .tv_nsec = 0}; + const struct afswtch *afp; if (wflag_secs) { if (clock_gettime(CLOCK_MONOTONIC, &now) == -1) @@ -538,27 +536,13 @@ wait_dad_exec(prop_dictionary_t env, pro for (ifa = ifaddrs; ifa; ifa = ifa->ifa_next) { if (ifa->ifa_addr == NULL) continue; - switch (ifa->ifa_addr->sa_family) { - case AF_INET6: - memset(&ifr6, 0, sizeof(ifr6)); - strncpy(ifr6.ifr_name, - ifa->ifa_name, sizeof(ifr6.ifr_name)); - ifr6.ifr_addr = - *(struct sockaddr_in6 *)ifa->ifa_addr; - if ((s = getsock(AF_INET6)) == -1) - err(EXIT_FAILURE, - "%s: getsock", __func__); - if (ioctl(s, SIOCGIFAFLAG_IN6, &ifr6) == -1) - err(EXIT_FAILURE, "SIOCGIFAFLAG_IN6"); - if (ifr6.ifr_ifru.ifru_flags6 & - IN6_IFF_TENTATIVE) - { - waiting = true; - break; - } - } - if (waiting) + afp = lookup_af_bynum(ifa->ifa_addr->sa_family); + if (afp && afp->af_addr_tentative && + afp->af_addr_tentative(ifa)) + { + waiting = true; break; + } } if (!waiting) break; @@ -572,7 +556,6 @@ wait_dad_exec(prop_dictionary_t env, pro } freeifaddrs(ifaddrs); -#endif exit(EXIT_SUCCESS); } Index: src/sbin/ifconfig/util.h diff -u src/sbin/ifconfig/util.h:1.10 src/sbin/ifconfig/util.h:1.11 --- src/sbin/ifconfig/util.h:1.10 Sat Oct 19 00:35:30 2013 +++ src/sbin/ifconfig/util.h Wed Apr 22 17:42:22 2015 @@ -13,6 +13,7 @@ struct afswtch { short af_af; void (*af_status)(prop_dictionary_t, prop_dictionary_t, bool); void (*af_addr_commit)(prop_dictionary_t, prop_dictionary_t); + bool (*af_addr_tentative)(struct ifaddrs *); SIMPLEQ_ENTRY(afswtch) af_next; };