Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sbin/ifconfig Move the INET6 specific code for wait_dad_exec...
details: https://anonhg.NetBSD.org/src/rev/aabc5792c0bb
branches: trunk
changeset: 337653:aabc5792c0bb
user: roy <roy%NetBSD.org@localhost>
date: Wed Apr 22 17:42:22 2015 +0000
description:
Move the INET6 specific code for wait_dad_exec() into af_inet6
by using a new afswtch hook af_addr_tentative.
diffstat:
sbin/ifconfig/af_inet6.c | 24 +++++++++++++++++++++---
sbin/ifconfig/ifconfig.c | 35 +++++++++--------------------------
sbin/ifconfig/util.h | 1 +
3 files changed, 31 insertions(+), 29 deletions(-)
diffs (146 lines):
diff -r 0ee059546ac8 -r aabc5792c0bb sbin/ifconfig/af_inet6.c
--- a/sbin/ifconfig/af_inet6.c Wed Apr 22 17:38:33 2015 +0000
+++ b/sbin/ifconfig/af_inet6.c Wed Apr 22 17:42:22 2015 +0000
@@ -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 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 @@
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 @@
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)
{
diff -r 0ee059546ac8 -r aabc5792c0bb sbin/ifconfig/ifconfig.c
--- a/sbin/ifconfig/ifconfig.c Wed Apr 22 17:38:33 2015 +0000
+++ b/sbin/ifconfig/ifconfig.c Wed Apr 22 17:42:22 2015 +0000
@@ -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 @@
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 @@
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;
- }
+ 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;
}
if (!waiting)
break;
@@ -572,7 +556,6 @@
}
freeifaddrs(ifaddrs);
-#endif
exit(EXIT_SUCCESS);
}
diff -r 0ee059546ac8 -r aabc5792c0bb sbin/ifconfig/util.h
--- a/sbin/ifconfig/util.h Wed Apr 22 17:38:33 2015 +0000
+++ b/sbin/ifconfig/util.h Wed Apr 22 17:42:22 2015 +0000
@@ -13,6 +13,7 @@
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;
};
Home |
Main Index |
Thread Index |
Old Index