Module Name:    src
Committed By:   roy
Date:           Wed Sep 23 02:09:18 UTC 2020

Modified Files:
        src/sbin/ifconfig: ifconfig.8 ifconfig.c

Log Message:
ifconfig: teach carrier test about ifi_link_state from SIOCGIFDATA

Because not all interfaces support media.


To generate a diff of this commit:
cvs rdiff -u -r1.119 -r1.120 src/sbin/ifconfig/ifconfig.8
cvs rdiff -u -r1.243 -r1.244 src/sbin/ifconfig/ifconfig.c

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/ifconfig.8
diff -u src/sbin/ifconfig/ifconfig.8:1.119 src/sbin/ifconfig/ifconfig.8:1.120
--- src/sbin/ifconfig/ifconfig.8:1.119	Mon Jul  8 03:04:15 2019
+++ src/sbin/ifconfig/ifconfig.8	Wed Sep 23 02:09:18 2020
@@ -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 @@ not appear to be connected to a network,
 .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.
+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.
-Not all interface drivers support media
-status reporting.
 .Pp
 If the
 .Fl m

Index: src/sbin/ifconfig/ifconfig.c
diff -u src/sbin/ifconfig/ifconfig.c:1.243 src/sbin/ifconfig/ifconfig.c:1.244
--- src/sbin/ifconfig/ifconfig.c:1.243	Tue Sep 22 14:14:17 2020
+++ src/sbin/ifconfig/ifconfig.c	Wed Sep 23 02:09:18 2020
@@ -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 @@ setifmtu(prop_dictionary_t env, prop_dic
 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) {
 		/*

Reply via email to