summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorharti <harti@FreeBSD.org>2006-01-04 12:57:09 +0000
committerharti <harti@FreeBSD.org>2006-01-04 12:57:09 +0000
commit9cca28b4d7b7042fa7f1bb73238dcc863592e044 (patch)
tree9883bdb48e4fc6a6de0d55496500f2dcaf3bc18c
parente426666183b577af4f703c82c374703a3b0ce946 (diff)
downloadFreeBSD-src-9cca28b4d7b7042fa7f1bb73238dcc863592e044.zip
FreeBSD-src-9cca28b4d7b7042fa7f1bb73238dcc863592e044.tar.gz
Add a new leaf to the net.link.generic.ifdata.%d sysctl to retrieve
the name and unit number assigned by the driver. This is needed by SNMP to find interfaces after they have been renamed. MFC after: 4 weeks
-rw-r--r--sys/net/if_mib.c19
-rw-r--r--sys/net/if_mib.h1
-rw-r--r--tools/tools/ifinfo/ifinfo.c29
3 files changed, 44 insertions, 5 deletions
diff --git a/sys/net/if_mib.c b/sys/net/if_mib.c
index c061e7f..dc2b8e1 100644
--- a/sys/net/if_mib.c
+++ b/sys/net/if_mib.c
@@ -75,6 +75,8 @@ sysctl_ifdata(SYSCTL_HANDLER_ARGS) /* XXX bad syntax! */
u_int namelen = arg2;
struct ifnet *ifp;
struct ifmibdata ifmd;
+ size_t dlen;
+ char *dbuf;
if (namelen != 2)
return EINVAL;
@@ -134,7 +136,22 @@ sysctl_ifdata(SYSCTL_HANDLER_ARGS) /* XXX bad syntax! */
error = SYSCTL_IN(req, ifp->if_linkmib, ifp->if_linkmiblen);
if (error)
return error;
-
+
+ case IFDATA_DRIVERNAME:
+ /* 20 is enough for 64bit ints */
+ dlen = strlen(ifp->if_dname) + 20 + 1;
+ if ((dbuf = malloc(dlen, M_TEMP, M_NOWAIT)) == NULL)
+ return (ENOMEM);
+ if (ifp->if_dunit == IF_DUNIT_NONE)
+ strcpy(dbuf, ifp->if_dname);
+ else
+ sprintf(dbuf, "%s%d", ifp->if_dname, ifp->if_dunit);
+
+ error = SYSCTL_OUT(req, dbuf, strlen(dbuf) + 1);
+ if (error == 0 && req->newptr != NULL)
+ error = EPERM;
+ free(dbuf, M_TEMP);
+ return (error);
}
return 0;
}
diff --git a/sys/net/if_mib.h b/sys/net/if_mib.h
index 445bd5b..e2b80c8 100644
--- a/sys/net/if_mib.h
+++ b/sys/net/if_mib.h
@@ -54,6 +54,7 @@ struct ifmibdata {
*/
#define IFDATA_GENERAL 1 /* generic stats for all kinds of ifaces */
#define IFDATA_LINKSPECIFIC 2 /* specific to the type of interface */
+#define IFDATA_DRIVERNAME 3 /* driver name and unit */
/*
* MIB tags at the net.link.generic.system level
diff --git a/tools/tools/ifinfo/ifinfo.c b/tools/tools/ifinfo/ifinfo.c
index 54ca164..22053c5 100644
--- a/tools/tools/ifinfo/ifinfo.c
+++ b/tools/tools/ifinfo/ifinfo.c
@@ -47,7 +47,7 @@
#include "ifinfo.h"
-static void printit(const struct ifmibdata *);
+static void printit(const struct ifmibdata *, const char *);
static const char *iftype(int);
static const char *ifphys(int, int);
static int isit(int, char **, const char *);
@@ -72,6 +72,7 @@ main(int argc, char **argv)
void *linkmib;
size_t linkmiblen;
printfcn pf;
+ char *dname;
while ((c = getopt(argc, argv, "l")) != -1) {
switch(c) {
@@ -110,7 +111,24 @@ main(int argc, char **argv)
if (!isit(argc - optind, argv + optind, ifmd.ifmd_name))
continue;
- printit(&ifmd);
+
+ dname = NULL;
+ len = 0;
+ name[5] = IFDATA_DRIVERNAME;
+ if (sysctl(name, 6, NULL, &len, 0, 0) < 0) {
+ warn("sysctl(net.link.ifdata.%d.drivername)", i);
+ } else {
+ if ((dname = malloc(len)) == NULL)
+ err(EX_OSERR, NULL);
+ if (sysctl(name, 6, dname, &len, 0, 0) < 0) {
+ warn("sysctl(net.link.ifdata.%d.drivername)",
+ i);
+ free(dname);
+ dname = NULL;
+ }
+ }
+ printit(&ifmd, dname);
+ free(dname);
if (dolink && (pf = findlink(ifmd.ifmd_data.ifi_type))) {
name[5] = IFDATA_LINKSPECIFIC;
if (sysctl(name, 6, 0, &linkmiblen, 0, 0) < 0)
@@ -135,9 +153,12 @@ main(int argc, char **argv)
}
static void
-printit(const struct ifmibdata *ifmd)
+printit(const struct ifmibdata *ifmd, const char *dname)
{
- printf("Interface %.*s:\n", IFNAMSIZ, ifmd->ifmd_name);
+ printf("Interface %.*s", IFNAMSIZ, ifmd->ifmd_name);
+ if (dname != NULL)
+ printf(" (%s)", dname);
+ printf(":\n");
printf("\tflags: %x\n", ifmd->ifmd_flags);
printf("\tpromiscuous listeners: %d\n", ifmd->ifmd_pcount);
printf("\tsend queue length: %d\n", ifmd->ifmd_snd_len);
OpenPOWER on IntegriCloud