Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 24 Sep 2019 06:31:56 +0000 (UTC)
From:      Konstantin Belousov <kib@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org
Subject:   svn commit: r352648 - stable/12/sbin/ifconfig
Message-ID:  <201909240631.x8O6VuOk026315@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kib
Date: Tue Sep 24 06:31:56 2019
New Revision: 352648
URL: https://svnweb.freebsd.org/changeset/base/352648

Log:
  MFC r352459:
  ifconfig: add report of the string from SIOCGIFDOWNREASON.
  
  Sponsored by:	Mellanox Technologies

Modified:
  stable/12/sbin/ifconfig/ifmedia.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/sbin/ifconfig/ifmedia.c
==============================================================================
--- stable/12/sbin/ifconfig/ifmedia.c	Tue Sep 24 06:30:34 2019	(r352647)
+++ stable/12/sbin/ifconfig/ifmedia.c	Tue Sep 24 06:31:56 2019	(r352648)
@@ -80,6 +80,7 @@
 #include <err.h>
 #include <errno.h>
 #include <fcntl.h>
+#include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -110,18 +111,20 @@ static void
 media_status(int s)
 {
 	struct ifmediareq ifmr;
+	struct ifdownreason ifdr;
 	int *media_list, i;
-	int xmedia = 1;
+	bool no_carrier, xmedia;
 
 	(void) memset(&ifmr, 0, sizeof(ifmr));
 	(void) strlcpy(ifmr.ifm_name, name, sizeof(ifmr.ifm_name));
+	xmedia = true;
 
 	/*
 	 * Check if interface supports extended media types.
 	 */
 	if (ioctl(s, SIOCGIFXMEDIA, (caddr_t)&ifmr) < 0)
-		xmedia = 0;
-	if (xmedia == 0 && ioctl(s, SIOCGIFMEDIA, (caddr_t)&ifmr) < 0) {
+		xmedia = false;
+	if (!xmedia && ioctl(s, SIOCGIFMEDIA, (caddr_t)&ifmr) < 0) {
 		/*
 		 * Interface doesn't support SIOC{G,S}IFMEDIA.
 		 */
@@ -158,6 +161,7 @@ media_status(int s)
 	putchar('\n');
 
 	if (ifmr.ifm_status & IFM_AVALID) {
+		no_carrier = false;
 		printf("\tstatus: ");
 		switch (IFM_TYPE(ifmr.ifm_active)) {
 		case IFM_ETHER:
@@ -165,7 +169,7 @@ media_status(int s)
 			if (ifmr.ifm_status & IFM_ACTIVE)
 				printf("active");
 			else
-				printf("no carrier");
+				no_carrier = true;
 			break;
 
 		case IFM_IEEE80211:
@@ -176,8 +180,26 @@ media_status(int s)
 				else
 					printf("running");
 			} else
-				printf("no carrier");
+				no_carrier = true;
 			break;
+		}
+		if (no_carrier) {
+			printf("no carrier");
+			memset(&ifdr, 0, sizeof(ifdr));
+			strlcpy(ifdr.ifdr_name, name, sizeof(ifdr.ifdr_name));
+			if (ioctl(s, SIOCGIFDOWNREASON, (caddr_t)&ifdr) == 0) {
+				switch (ifdr.ifdr_reason) {
+				case IFDR_REASON_MSG:
+					printf(" (%s)", ifdr.ifdr_msg);
+					break;
+				case IFDR_REASON_VENDOR:
+					printf(" (vendor code %d)",
+					    ifdr.ifdr_vendor);
+					break;
+				default:
+					break;
+				}
+			}
 		}
 		putchar('\n');
 	}



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201909240631.x8O6VuOk026315>