Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sbin/ifconfig ifconfig: teach carrier test about ifi_link_st...



details:   https://anonhg.NetBSD.org/src/rev/e990c5a6a787
branches:  trunk
changeset: 955185:e990c5a6a787
user:      roy <roy%NetBSD.org@localhost>
date:      Wed Sep 23 02:09:18 2020 +0000

description:
ifconfig: teach carrier test about ifi_link_state from SIOCGIFDATA

Because not all interfaces support media.

diffstat:

 sbin/ifconfig/ifconfig.8 |  17 +++++++++++------
 sbin/ifconfig/ifconfig.c |  19 ++++++++++++-------
 2 files changed, 23 insertions(+), 13 deletions(-)

diffs (85 lines):

diff -r 07f616c62b0a -r e990c5a6a787 sbin/ifconfig/ifconfig.8
--- a/sbin/ifconfig/ifconfig.8  Wed Sep 23 00:52:49 2020 +0000
+++ b/sbin/ifconfig/ifconfig.8  Wed Sep 23 02:09:18 2020 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: ifconfig.8,v 1.119 2019/07/08 03:04:15 msaitoh Exp $
+.\"    $NetBSD: ifconfig.8,v 1.120 2020/09/23 02:09:18 roy Exp $
 .\"
 .\" Copyright (c) 1983, 1991, 1993
 .\"    The Regents of the University of California.  All rights reserved.
@@ -29,7 +29,7 @@
 .\"
 .\"     @(#)ifconfig.8 8.4 (Berkeley) 6/1/94
 .\"
-.Dd July 8, 2019
+.Dd September 23, 2020
 .Dt IFCONFIG 8
 .Os
 .Sh NAME
@@ -757,12 +757,17 @@
 .Nm
 will exit with status of 1
 .Pq false ;
-otherwise, it will exit with a
-zero
+otherwise, it will exit with a zero
 .Pq true
 exit status.
-Not all interface drivers support media
-status reporting.
+For interface drivers that do not support media status reporting.
+then if the link state is not reported to be up,
+.Nm
+will exit with a status of 1
+.Pq false ;
+otherwise, it will exit with a zero
+.Pq true
+exit status.
 .Pp
 If the
 .Fl m
diff -r 07f616c62b0a -r e990c5a6a787 sbin/ifconfig/ifconfig.c
--- a/sbin/ifconfig/ifconfig.c  Wed Sep 23 00:52:49 2020 +0000
+++ b/sbin/ifconfig/ifconfig.c  Wed Sep 23 02:09:18 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ifconfig.c,v 1.243 2020/09/22 14:14:17 roy Exp $       */
+/*     $NetBSD: ifconfig.c,v 1.244 2020/09/23 02:09:18 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.243 2020/09/22 14:14:17 roy Exp $");
+__RCSID("$NetBSD: ifconfig.c,v 1.244 2020/09/23 02:09:18 roy Exp $");
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -1213,16 +1213,21 @@
 static int
 carrier(prop_dictionary_t env)
 {
-       struct ifmediareq ifmr;
-
-       memset(&ifmr, 0, sizeof(ifmr));
+       struct ifmediareq ifmr = { .ifm_status = 0 };
 
        if (direct_ioctl(env, SIOCGIFMEDIA, &ifmr) == -1) {
                /*
                 * Interface doesn't support SIOC{G,S}IFMEDIA;
-                * assume ok.
+                * check link state.
                 */
-               return EXIT_SUCCESS;
+               struct ifdatareq ifdr = { .ifdr_data.ifi_link_state = 0 };
+
+               if (direct_ioctl(env, SIOCGIFDATA, &ifdr) == -1)
+                       return EXIT_FAILURE;
+               if (ifdr.ifdr_data.ifi_link_state == LINK_STATE_UP)
+                       return EXIT_SUCCESS;
+               else
+                       return EXIT_FAILURE;
        }
        if ((ifmr.ifm_status & IFM_AVALID) == 0) {
                /*



Home | Main Index | Thread Index | Old Index