summaryrefslogtreecommitdiffstats
path: root/sbin
diff options
context:
space:
mode:
authordelphij <delphij@FreeBSD.org>2009-11-11 21:30:58 +0000
committerdelphij <delphij@FreeBSD.org>2009-11-11 21:30:58 +0000
commit13a19ef806aacb68fca8a06969fe760e790cf191 (patch)
treeeea1594231338258764b9d2c6a5b8c04a07d0269 /sbin
parent7f8b0bd4a81476d4906f4ec7983d3328593bebde (diff)
downloadFreeBSD-src-13a19ef806aacb68fca8a06969fe760e790cf191.zip
FreeBSD-src-13a19ef806aacb68fca8a06969fe760e790cf191.tar.gz
Add interface description capability as inspired by OpenBSD.
MFC after: 3 months
Diffstat (limited to 'sbin')
-rw-r--r--sbin/ifconfig/ifconfig.812
-rw-r--r--sbin/ifconfig/ifconfig.c53
2 files changed, 64 insertions, 1 deletions
diff --git a/sbin/ifconfig/ifconfig.8 b/sbin/ifconfig/ifconfig.8
index 220bd9f..211b1ef 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 November 11, 2009
.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
+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
+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 f05374c..e08bb4f 100644
--- a/sbin/ifconfig/ifconfig.c
+++ b/sbin/ifconfig/ifconfig.c
@@ -83,6 +83,8 @@ static const char rcsid[] =
struct ifreq ifr;
char name[IFNAMSIZ];
+char *descr = NULL;
+size_t descrlen = 64;
int setaddr;
int setmask;
int doalias;
@@ -822,6 +824,36 @@ 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;
+
+ newdescr = strdup(val);
+ if (newdescr == NULL) {
+ warn("no memory to set ifdescr");
+ return;
+ }
+ ifr.ifr_buffer.buffer = newdescr;
+ ifr.ifr_buffer.length = strlen(newdescr);
+ if (ioctl(s, SIOCSIFDESCR, (caddr_t)&ifr) < 0) {
+ warn("ioctl (set descr)");
+ free(newdescr);
+ return;
+ }
+ 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" \
@@ -866,6 +898,23 @@ status(const struct afswtch *afp, const struct sockaddr_dl *sdl,
printf(" mtu %d", ifr.ifr_mtu);
putchar('\n');
+ descr = reallocf(descr, descrlen);
+ if (descr != NULL) {
+ do {
+ 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;
+ }
+ if (errno == ENAMETOOLONG) {
+ descrlen *= 2;
+ descr = reallocf(descr, descrlen);
+ }
+ } while (errno == ENAMETOOLONG);
+ }
+
if (ioctl(s, SIOCGIFCAP, (caddr_t)&ifr) == 0) {
if (ifr.ifr_curcap != 0) {
printb("\toptions", ifr.ifr_curcap, IFCAPBITS);
@@ -1035,6 +1084,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),
OpenPOWER on IntegriCloud