diff options
author | delphij <delphij@FreeBSD.org> | 2010-01-27 00:30:07 +0000 |
---|---|---|
committer | delphij <delphij@FreeBSD.org> | 2010-01-27 00:30:07 +0000 |
commit | d9a0cd0982402f9faf826972323ba7e2c92d4da2 (patch) | |
tree | ff676986c0098bc03f0b66a25fb89a62e45f8b53 /sbin | |
parent | f58131e1e486131bc5b10b4db8adfbfb58a6db5f (diff) | |
download | FreeBSD-src-d9a0cd0982402f9faf826972323ba7e2c92d4da2.zip FreeBSD-src-d9a0cd0982402f9faf826972323ba7e2c92d4da2.tar.gz |
Revised revision 199201 (add interface description capability as inspired
by OpenBSD), based on comments from many, including rwatson, jhb, brooks
and others.
Sponsored by: iXsystems, Inc.
MFC after: 1 month
Diffstat (limited to 'sbin')
-rw-r--r-- | sbin/ifconfig/ifconfig.8 | 12 | ||||
-rw-r--r-- | sbin/ifconfig/ifconfig.c | 60 |
2 files changed, 70 insertions, 2 deletions
diff --git a/sbin/ifconfig/ifconfig.8 b/sbin/ifconfig/ifconfig.8 index 220bd9f..539cbdf 100644 --- a/sbin/ifconfig/ifconfig.8 +++ b/sbin/ifconfig/ifconfig.8 @@ -28,7 +28,7 @@ .\" From: @(#)ifconfig.8 8.3 (Berkeley) 1/5/94 .\" $FreeBSD$ .\" -.Dd September 23, 2009 +.Dd January 26, 2010 .Dt IFCONFIG 8 .Os .Sh NAME @@ -258,6 +258,12 @@ Disable permanently promiscuous mode. Another name for the .Fl alias parameter. +.It Cm description Ar value , Cm descr Ar value +Specify a description of the interface. +This can be used to label interfaces in situations where they may +otherwise be difficult to distinguish. +.It Cm -description , Cm -descr +Clear the interface description. .It Cm down Mark an interface .Dq down . @@ -2512,6 +2518,10 @@ Configure the interface to use 100baseTX, full duplex Ethernet media options: .Dl # ifconfig xl0 media 100baseTX mediaopt full-duplex .Pp +Label the em0 interface as an uplink: +.Pp +.Dl # ifconfig em0 description \&"Uplink to Gigabit Switch 2\&" +.Pp Create the software network interface .Li gif1 : .Dl # ifconfig gif1 create diff --git a/sbin/ifconfig/ifconfig.c b/sbin/ifconfig/ifconfig.c index b77a277..5dc0871 100644 --- a/sbin/ifconfig/ifconfig.c +++ b/sbin/ifconfig/ifconfig.c @@ -44,7 +44,6 @@ static const char rcsid[] = #include <sys/param.h> #include <sys/ioctl.h> #include <sys/socket.h> -#include <sys/sysctl.h> #include <sys/time.h> #include <sys/module.h> #include <sys/linker.h> @@ -83,6 +82,8 @@ static const char rcsid[] = struct ifreq ifr; char name[IFNAMSIZ]; +char *descr = NULL; +size_t descrlen = 64; int setaddr; int setmask; int doalias; @@ -838,6 +839,40 @@ setifname(const char *val, int dummy __unused, int s, free(newname); } +/* ARGSUSED */ +static void +setifdescr(const char *val, int dummy __unused, int s, + const struct afswtch *afp) +{ + char *newdescr; + + ifr.ifr_buffer.length = strlen(val) + 1; + if (ifr.ifr_buffer.length == 1) { + ifr.ifr_buffer.buffer = newdescr = NULL; + ifr.ifr_buffer.length = 0; + } else { + newdescr = strdup(val); + ifr.ifr_buffer.buffer = newdescr; + if (newdescr == NULL) { + warn("no memory to set ifdescr"); + return; + } + } + + if (ioctl(s, SIOCSIFDESCR, (caddr_t)&ifr) < 0) + warn("ioctl (set descr)"); + + free(newdescr); +} + +/* ARGSUSED */ +static void +unsetifdescr(const char *val, int value, int s, const struct afswtch *afp) +{ + + setifdescr("", 0, s, 0); +} + #define IFFBITS \ "\020\1UP\2BROADCAST\3DEBUG\4LOOPBACK\5POINTOPOINT\6SMART\7RUNNING" \ "\10NOARP\11PROMISC\12ALLMULTI\13OACTIVE\14SIMPLEX\15LINK0\16LINK1\17LINK2" \ @@ -882,6 +917,25 @@ status(const struct afswtch *afp, const struct sockaddr_dl *sdl, printf(" mtu %d", ifr.ifr_mtu); putchar('\n'); + for (;;) { + if ((descr = reallocf(descr, descrlen)) != NULL) { + ifr.ifr_buffer.buffer = descr; + ifr.ifr_buffer.length = descrlen; + if (ioctl(s, SIOCGIFDESCR, &ifr) == 0) { + if (strlen(descr) > 0) + printf("\tdescription: %s\n", descr); + break; + } else if (errno == ENAMETOOLONG) + descrlen = ifr.ifr_buffer.length; + else + break; + } else { + warn("unable to allocate memory for interface" + "description"); + break; + } + }; + if (ioctl(s, SIOCGIFCAP, (caddr_t)&ifr) == 0) { if (ifr.ifr_curcap != 0) { printb("\toptions", ifr.ifr_curcap, IFCAPBITS); @@ -1051,6 +1105,10 @@ static struct cmd basic_cmds[] = { DEF_CMD("-arp", IFF_NOARP, setifflags), DEF_CMD("debug", IFF_DEBUG, setifflags), DEF_CMD("-debug", -IFF_DEBUG, setifflags), + DEF_CMD_ARG("description", setifdescr), + DEF_CMD_ARG("descr", setifdescr), + DEF_CMD("-description", 0, unsetifdescr), + DEF_CMD("-descr", 0, unsetifdescr), DEF_CMD("promisc", IFF_PPROMISC, setifflags), DEF_CMD("-promisc", -IFF_PPROMISC, setifflags), DEF_CMD("add", IFF_UP, notealias), |