Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.sbin/ifwatchd We already know the interface name, so don...
details: https://anonhg.NetBSD.org/src/rev/a478c1b09e9f
branches: trunk
changeset: 818299:a478c1b09e9f
user: roy <roy%NetBSD.org@localhost>
date: Thu Oct 06 10:30:31 2016 +0000
description:
We already know the interface name, so don't bother calling if_indextoname
to work it out again.
diffstat:
usr.sbin/ifwatchd/ifwatchd.c | 53 +++++++++++++++++++------------------------
1 files changed, 23 insertions(+), 30 deletions(-)
diffs (142 lines):
diff -r c87bc5db1163 -r a478c1b09e9f usr.sbin/ifwatchd/ifwatchd.c
--- a/usr.sbin/ifwatchd/ifwatchd.c Thu Oct 06 03:17:44 2016 +0000
+++ b/usr.sbin/ifwatchd/ifwatchd.c Thu Oct 06 10:30:31 2016 +0000
@@ -1,6 +1,6 @@
-/* $NetBSD: ifwatchd.c,v 1.36 2016/09/29 15:25:28 roy Exp $ */
+/* $NetBSD: ifwatchd.c,v 1.37 2016/10/06 10:30:31 roy Exp $ */
#include <sys/cdefs.h>
- __RCSID("$NetBSD: ifwatchd.c,v 1.36 2016/09/29 15:25:28 roy Exp $");
+ __RCSID("$NetBSD: ifwatchd.c,v 1.37 2016/10/06 10:30:31 roy Exp $");
/*-
* Copyright (c) 2002, 2003 The NetBSD Foundation, Inc.
@@ -63,8 +63,8 @@
static void dispatch(const void *, size_t);
static enum addrflag check_addrflags(int af, int addrflags);
static void check_addrs(const struct ifa_msghdr *ifam);
-static void invoke_script(const struct sockaddr *sa, const struct sockaddr *dst,
- enum event ev, int ifindex, const char *ifname_hint);
+static void invoke_script(const char *ifname, enum event ev,
+ const struct sockaddr *sa, const struct sockaddr *dst);
static void list_interfaces(const char *ifnames);
static void check_announce(const struct if_announcemsghdr *ifan);
static void check_carrier(const struct if_msghdr *ifm);
@@ -346,19 +346,26 @@
}
if ((ev == UP && aflag == READY) ||
(ev == DOWN && aflag == DETACHED /* XXX why DETACHED? */))
- invoke_script(ifa, brd, ev, ifd->index, ifd->ifname);
+ invoke_script(ifd->ifname, ev, ifa, brd);
}
}
static void
-invoke_script(const struct sockaddr *sa, const struct sockaddr *dest,
- enum event ev, int ifindex, const char *ifname_hint)
+invoke_script(const char *ifname, enum event ev,
+ const struct sockaddr *sa, const struct sockaddr *dest)
{
- char addr[NI_MAXHOST], daddr[NI_MAXHOST], ifname_buf[IFNAMSIZ];
- const char * volatile ifname;
+ char addr[NI_MAXHOST], daddr[NI_MAXHOST];
const char *script;
int status;
+ if (ifname == NULL)
+ return;
+
+ script = *scripts[ev];
+ if (script == NULL)
+ return;
+
+ addr[0] = daddr[0] = 0;
if (sa != NULL) {
if (sa->sa_len == 0) {
fprintf(stderr,
@@ -384,15 +391,7 @@
return;
}
}
- }
- addr[0] = daddr[0] = 0;
- ifname = if_indextoname(ifindex, ifname_buf);
- ifname = ifname ? ifname : ifname_hint;
- if (ifname == NULL)
- return;
-
- if (sa != NULL) {
if (getnameinfo(sa, sa->sa_len, addr, sizeof addr, NULL, 0,
NI_NUMERICHOST)) {
if (verbose)
@@ -400,6 +399,7 @@
return; /* this address can not be handled */
}
}
+
if (dest != NULL) {
if (getnameinfo(dest, dest->sa_len, daddr, sizeof daddr,
NULL, 0, NI_NUMERICHOST)) {
@@ -409,9 +409,6 @@
}
}
- script = *scripts[ev];
- if (script == NULL) return;
-
if (verbose)
(void) printf("calling: %s %s %s %s %s %s\n",
script, ifname, DummyTTY, DummySpeed, addr, daddr);
@@ -496,7 +493,7 @@
printf("unknown link status ignored\n");
return;
}
- invoke_script(NULL, NULL, ev, ifm->ifm_index, p->ifname);
+ invoke_script(p->ifname, ev, NULL, NULL);
p->last_carrier_status = carrier_status;
}
}
@@ -513,12 +510,10 @@
switch (ifan->ifan_what) {
case IFAN_ARRIVAL:
- invoke_script(NULL, NULL, ARRIVAL, p->index,
- NULL);
+ invoke_script(p->ifname, ARRIVAL, NULL, NULL);
break;
case IFAN_DEPARTURE:
- invoke_script(NULL, NULL, DEPARTURE, p->index,
- p->ifname);
+ invoke_script(p->ifname, DEPARTURE, NULL, NULL);
break;
default:
if (verbose)
@@ -592,8 +587,7 @@
ifa = p->ifa_addr;
if (ifa != NULL && ifa->sa_family == AF_LINK)
- invoke_script(NULL, NULL, ARRIVAL, ifd->index,
- NULL);
+ invoke_script(ifd->ifname, ARRIVAL, NULL, NULL);
if ((p->ifa_flags & IFF_UP) == 0)
continue;
@@ -608,8 +602,7 @@
if (ioctl(s, SIOCGIFMEDIA, &ifmr) != -1
&& (ifmr.ifm_status & IFM_AVALID)
&& (ifmr.ifm_status & IFM_ACTIVE)) {
- invoke_script(NULL, NULL, CARRIER,
- ifd->index, ifd->ifname);
+ invoke_script(ifd->ifname, CARRIER, NULL, NULL);
ifd->last_carrier_status =
LINK_STATE_UP;
}
@@ -618,7 +611,7 @@
aflag = check_addrflags(ifa->sa_family, p->ifa_addrflags);
if (aflag != READY)
continue;
- invoke_script(ifa, p->ifa_dstaddr, UP, ifd->index, ifd->ifname);
+ invoke_script(ifd->ifname, UP, ifa, p->ifa_dstaddr);
}
freeifaddrs(res);
out:
Home |
Main Index |
Thread Index |
Old Index