Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.sbin/ifwatchd ifwatchd: Check link state if no media is ...
details: https://anonhg.NetBSD.org/src/rev/5888e5093ec1
branches: trunk
changeset: 944198:5888e5093ec1
user: roy <roy%NetBSD.org@localhost>
date: Wed Sep 23 02:32:04 2020 +0000
description:
ifwatchd: Check link state if no media is supported on initial ups.
We can check this via SIOCGIFDATA and ifi_link_state.
diffstat:
usr.sbin/ifwatchd/ifwatchd.c | 49 ++++++++++++++++++++++++++++++++++---------
1 files changed, 38 insertions(+), 11 deletions(-)
diffs (74 lines):
diff -r 2d4005b55498 -r 5888e5093ec1 usr.sbin/ifwatchd/ifwatchd.c
--- a/usr.sbin/ifwatchd/ifwatchd.c Wed Sep 23 02:09:18 2020 +0000
+++ b/usr.sbin/ifwatchd/ifwatchd.c Wed Sep 23 02:32:04 2020 +0000
@@ -1,6 +1,6 @@
-/* $NetBSD: ifwatchd.c,v 1.43 2018/03/07 10:06:41 roy Exp $ */
+/* $NetBSD: ifwatchd.c,v 1.44 2020/09/23 02:32:04 roy Exp $ */
#include <sys/cdefs.h>
-__RCSID("$NetBSD: ifwatchd.c,v 1.43 2018/03/07 10:06:41 roy Exp $");
+__RCSID("$NetBSD: ifwatchd.c,v 1.44 2020/09/23 02:32:04 roy Exp $");
/*-
* Copyright (c) 2002, 2003 The NetBSD Foundation, Inc.
@@ -536,6 +536,40 @@
return NULL;
}
+static bool
+has_carrier(int s, const char *ifname)
+{
+ struct ifmediareq ifmr = { .ifm_status = 0 };
+
+ strlcpy(ifmr.ifm_name, ifname, sizeof(ifmr.ifm_name));
+ if (ioctl(s, SIOCGIFMEDIA, &ifmr) == -1) {
+ struct ifdatareq ifdr = { .ifdr_data.ifi_link_state = 0 };
+
+ strlcpy(ifdr.ifdr_name, ifname, sizeof(ifdr.ifdr_name));
+ if (ioctl(s, SIOCGIFDATA, &ifdr) == -1) {
+ /* Should not be possible. */
+ return false;
+ }
+ if (ifdr.ifdr_data.ifi_link_state == LINK_STATE_UP)
+ return true;
+ else
+ return false;
+ }
+
+ if (!(ifmr.ifm_status & IFM_AVALID)) {
+ /*
+ * Interface doesn't report media-valid status.
+ * assume ok.
+ */
+ return true;
+ }
+
+ if (ifmr.ifm_status & IFM_ACTIVE)
+ return true;
+ else
+ return false;
+}
+
static void
run_initial_ups(void)
{
@@ -568,18 +602,11 @@
if (ifa == NULL)
continue;
if (ifa->sa_family == AF_LINK) {
- struct ifmediareq ifmr;
-
- memset(&ifmr, 0, sizeof(ifmr));
- strncpy(ifmr.ifm_name, ifd->ifname,
- sizeof(ifmr.ifm_name));
- if (ioctl(s, SIOCGIFMEDIA, &ifmr) != -1
- && (ifmr.ifm_status & IFM_AVALID)
- && (ifmr.ifm_status & IFM_ACTIVE)) {
+ if (has_carrier(s, ifd->ifname) == 0) {
invoke_script(ifd->ifname, CARRIER, NULL, NULL);
ifd->last_carrier_status =
LINK_STATE_UP;
- }
+ }
continue;
}
aflag = check_addrflags(ifa->sa_family, p->ifa_addrflags);
Home |
Main Index |
Thread Index |
Old Index