Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 21 Jan 2016 16:11:20 +0000 (UTC)
From:      Hartmut Brandt <harti@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r294507 - head/contrib/bsnmp/snmp_mibII
Message-ID:  <201601211611.u0LGBKkV086754@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: harti
Date: Thu Jan 21 16:11:20 2016
New Revision: 294507
URL: https://svnweb.freebsd.org/changeset/base/294507

Log:
  Fill the ifAlias leaf of the ifXTable with the interface description
  if there is one available and it fits into the maximum size (64 characters).

Modified:
  head/contrib/bsnmp/snmp_mibII/mibII.c
  head/contrib/bsnmp/snmp_mibII/mibII.h
  head/contrib/bsnmp/snmp_mibII/mibII_interfaces.c

Modified: head/contrib/bsnmp/snmp_mibII/mibII.c
==============================================================================
--- head/contrib/bsnmp/snmp_mibII/mibII.c	Thu Jan 21 15:27:44 2016	(r294506)
+++ head/contrib/bsnmp/snmp_mibII/mibII.c	Thu Jan 21 16:11:20 2016	(r294507)
@@ -443,6 +443,7 @@ mib_fetch_ifmib(struct mibif *ifp)
 	size_t len;
 	void *newmib;
 	struct ifmibdata oldmib = ifp->mib;
+	struct ifreq irr;
 
 	if (fetch_generic_mib(ifp, &oldmib) == -1)
 		return (-1);
@@ -514,6 +515,18 @@ mib_fetch_ifmib(struct mibif *ifp)
 	}
 
   out:
+	strncpy(irr.ifr_name, ifp->name, sizeof(irr.ifr_name));
+	irr.ifr_buffer.buffer = MIBIF_PRIV(ifp)->alias;
+	irr.ifr_buffer.length = sizeof(MIBIF_PRIV(ifp)->alias);
+	if (ioctl(mib_netsock, SIOCGIFDESCR, &irr) == -1) {
+		MIBIF_PRIV(ifp)->alias[0] = 0;
+		if (errno != ENOMSG)
+			syslog(LOG_WARNING, "SIOCGIFDESCR (%s): %m", ifp->name);
+	} else if (irr.ifr_buffer.buffer == NULL) {
+		MIBIF_PRIV(ifp)->alias[0] = 0;
+		syslog(LOG_WARNING, "SIOCGIFDESCR (%s): too long (%zu)",
+		    ifp->name, irr.ifr_buffer.length);
+	}
 	ifp->mibtick = get_ticks();
 	return (0);
 }

Modified: head/contrib/bsnmp/snmp_mibII/mibII.h
==============================================================================
--- head/contrib/bsnmp/snmp_mibII/mibII.h	Thu Jan 21 15:27:44 2016	(r294506)
+++ head/contrib/bsnmp/snmp_mibII/mibII.h	Thu Jan 21 16:11:20 2016	(r294507)
@@ -57,6 +57,9 @@
 #include "snmp_mibII.h"
 #include "mibII_tree.h"
 
+/* maximum size of the interface alias */
+static const u_int MIBIF_ALIAS_SIZE = 64 + 1;
+
 /*
  * Interface list and flags.
  */
@@ -77,6 +80,9 @@ struct mibif_private {
 	uint64_t	hc_opackets;
 	uint64_t	hc_imcasts;
 	uint64_t	hc_ipackets;
+
+	/* this should be made public */
+	char		alias[MIBIF_ALIAS_SIZE];
 };
 #define	MIBIF_PRIV(IFP) ((struct mibif_private *)((IFP)->private))
 

Modified: head/contrib/bsnmp/snmp_mibII/mibII_interfaces.c
==============================================================================
--- head/contrib/bsnmp/snmp_mibII/mibII_interfaces.c	Thu Jan 21 15:27:44 2016	(r294506)
+++ head/contrib/bsnmp/snmp_mibII/mibII_interfaces.c	Thu Jan 21 16:11:20 2016	(r294507)
@@ -528,7 +528,7 @@ op_ifxtable(struct snmp_context *ctx, st
 		break;
 
 	  case LEAF_ifAlias:
-		ret = string_get(value, "", -1);
+		ret = string_get(value, MIBIF_PRIV(ifp)->alias, -1);
 		break;
 
 	  case LEAF_ifCounterDiscontinuityTime:



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