From owner-freebsd-net@FreeBSD.ORG Thu Aug 13 10:46:18 2009 Return-Path: Delivered-To: freebsd-net@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id EA59D106564A for ; Thu, 13 Aug 2009 10:46:17 +0000 (UTC) (envelope-from delphij@delphij.net) Received: from tarsier.delphij.net (delphij-pt.tunnel.tserv2.fmt.ipv6.he.net [IPv6:2001:470:1f03:2c9::2]) by mx1.freebsd.org (Postfix) with ESMTP id 215208FC47 for ; Thu, 13 Aug 2009 10:46:17 +0000 (UTC) Received: from tarsier.geekcn.org (tarsier.geekcn.org [211.166.10.233]) (using TLSv1 with cipher ADH-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by tarsier.delphij.net (Postfix) with ESMTPS id 4DD755C025 for ; Thu, 13 Aug 2009 18:46:16 +0800 (CST) Received: from localhost (tarsier.geekcn.org [211.166.10.233]) by tarsier.geekcn.org (Postfix) with ESMTP id 07A0A55CDC2D; Thu, 13 Aug 2009 18:46:16 +0800 (CST) X-Virus-Scanned: amavisd-new at geekcn.org Received: from tarsier.geekcn.org ([211.166.10.233]) by localhost (mail.geekcn.org [211.166.10.233]) (amavisd-new, port 10024) with ESMTP id hiZ62lUeApFs; Thu, 13 Aug 2009 18:45:22 +0800 (CST) Received: from charlie.delphij.net (c-67-188-2-183.hsd1.ca.comcast.net [67.188.2.183]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by tarsier.geekcn.org (Postfix) with ESMTPSA id 1CE5E55CDC1F; Thu, 13 Aug 2009 18:45:14 +0800 (CST) DomainKey-Signature: a=rsa-sha1; s=default; d=delphij.net; c=nofws; q=dns; h=message-id:date:from:reply-to:organization:user-agent: mime-version:to:subject:x-enigmail-version:openpgp:content-type; b=FwapPwgnh3mdEKa2rQBQCB1u09aBI76D6IZXBGkKteRSMaafcpRTR5gProAD/PUVg DXj28lXMdi/tTXK0xlsuw== Message-ID: <4A83EEA8.5080202@delphij.net> Date: Thu, 13 Aug 2009 03:44:56 -0700 From: Xin LI Organization: The FreeBSD Project User-Agent: Thunderbird 2.0.0.22 (X11/20090803) MIME-Version: 1.0 To: freebsd-net@freebsd.org X-Enigmail-Version: 0.96.0 OpenPGP: id=18EDEBA0; url=http://www.delphij.net/delphij.asc Content-Type: multipart/mixed; boundary="------------090505000704070004090000" Subject: RFC: interface description X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: d@delphij.net List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 13 Aug 2009 10:46:18 -0000 This is a multi-part message in MIME format. --------------090505000704070004090000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi guys, While playing with some OpenBSD installation I found that they have an interesting feature - adding description to a NIC. This is useful for system administrators to "tag" the interface, also, the ladvd program has a feature to use the SIOCSIFDESCR ioctl to document the remote CDP peer like: em0: flags=8843 metric 0 mtu 1500 ether 00:11:22:33:44:55 description: connected to myrouter.home (CDP) [...] The attached patch ported the feature to FreeBSD. Cheers, - -- Xin LI http://www.delphij.net/ FreeBSD - The Power to Serve! -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.12 (FreeBSD) iEYEARECAAYFAkqD7qgACgkQi+vbBBjt66CF+QCeO6INwh3S1T/LvhIUTjZ/Ix4H zQkAniftv+SQ+irEcnItGHTbLH0HyUez =cEsJ -----END PGP SIGNATURE----- --------------090505000704070004090000 Content-Type: text/plain; name="ifdescr.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="ifdescr.diff" Index: sbin/ifconfig/ifconfig.8 =================================================================== --- sbin/ifconfig/ifconfig.8 (revision 196163) +++ sbin/ifconfig/ifconfig.8 (working copy) @@ -28,7 +28,7 @@ .\" From: @(#)ifconfig.8 8.3 (Berkeley) 1/5/94 .\" $FreeBSD$ .\" -.Dd July 8, 2009 +.Dd September 14, 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 . @@ -2443,6 +2449,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 Index: sbin/ifconfig/ifconfig.c =================================================================== --- sbin/ifconfig/ifconfig.c (revision 196163) +++ sbin/ifconfig/ifconfig.c (working copy) @@ -83,6 +83,7 @@ static const char rcsid[] = struct ifreq ifr; char name[IFNAMSIZ]; +char descr[IFDESCRSIZE]; int setaddr; int setmask; int doalias; @@ -822,6 +823,36 @@ setifname(const char *val, int dummy __unused, int 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_data = newdescr; + if (ioctl(s, SIOCSIFDESCR, (caddr_t)&ifr) < 0) { + warn("ioctl (set descr)"); + free(newdescr); + return; + } + strlcpy(descr, newdescr, sizeof(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" \ @@ -866,6 +897,11 @@ status(const struct afswtch *afp, const struct soc printf(" mtu %d", ifr.ifr_mtu); putchar('\n'); + ifr.ifr_data = (caddr_t)&descr; + if (ioctl(s, SIOCGIFDESCR, &ifr) == 0 && + strlen(ifr.ifr_data) > 0) + printf("\tdescription: %s\n", ifr.ifr_data); + if (ioctl(s, SIOCGIFCAP, (caddr_t)&ifr) == 0) { if (ifr.ifr_curcap != 0) { printb("\toptions", ifr.ifr_curcap, IFCAPBITS); @@ -1035,6 +1071,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), Index: share/man/man4/netintro.4 =================================================================== --- share/man/man4/netintro.4 (revision 196163) +++ share/man/man4/netintro.4 (working copy) @@ -32,7 +32,7 @@ .\" @(#)netintro.4 8.2 (Berkeley) 11/30/93 .\" $FreeBSD$ .\" -.Dd June 18, 2004 +.Dd September 15, 2009 .Dt NETINTRO 4 .Os .Sh NAME @@ -277,6 +277,15 @@ and fields of the .Vt ifreq structure, respectively. +.It Dv SIOCGIFDESCR Fa "struct ifreq *" +Get the interface description, returned in the +.Va ifru_data +field. +.It Dv SIOCSIFDESCR Fa "struct ifreq *" +Set the interface description to the value of the +.Va ifru_data +field, limited to the size of +.Dv IFDESCRSIZE . .It Dv SIOCSIFFLAGS Set interface flags field. If the interface is marked down, Index: sys/kern/kern_jail.c =================================================================== --- sys/kern/kern_jail.c (revision 196163) +++ sys/kern/kern_jail.c (working copy) @@ -3437,6 +3437,7 @@ prison_priv_check(struct ucred *cred, int priv) case PRIV_NET_SETIFMETRIC: case PRIV_NET_SETIFPHYS: case PRIV_NET_SETIFMAC: + case PRIV_NET_SETIFDESCR: case PRIV_NET_ADDMULTI: case PRIV_NET_DELMULTI: case PRIV_NET_HWIOCTL: Index: sys/net/if.c =================================================================== --- sys/net/if.c (revision 196163) +++ sys/net/if.c (working copy) @@ -1927,6 +1927,7 @@ ifhwioctl(u_long cmd, struct ifnet *ifp, caddr_t d int new_flags, temp_flags; size_t namelen, onamelen; char new_name[IFNAMSIZ]; + char ifdescrbuf[IFDESCRSIZE]; struct ifaddr *ifa; struct sockaddr_dl *sdl; @@ -1965,6 +1966,25 @@ ifhwioctl(u_long cmd, struct ifnet *ifp, caddr_t d ifr->ifr_phys = ifp->if_physical; break; + case SIOCGIFDESCR: + bzero(ifdescrbuf, sizeof(ifdescrbuf)); + strlcpy(ifdescrbuf, ifp->if_description, IFDESCRSIZE); + error = copyout(ifdescrbuf, ifr->ifr_data, IFDESCRSIZE); + break; + + case SIOCSIFDESCR: + error = priv_check(td, PRIV_NET_SETIFDESCR); + if (error) + return (error); + error = copyinstr(ifr->ifr_data, ifdescrbuf, + IFDESCRSIZE, NULL); + if (error == 0) { + bzero(ifp->if_description, IFDESCRSIZE); + strlcpy(ifp->if_description, ifdescrbuf, IFDESCRSIZE); + getmicrotime(&ifp->if_lastchange); + } + break; + case SIOCSIFFLAGS: error = priv_check(td, PRIV_NET_SETIFFLAGS); if (error) Index: sys/net/if.h =================================================================== --- sys/net/if.h (revision 196163) +++ sys/net/if.h (working copy) @@ -60,6 +60,10 @@ struct ifnet; #define IFNAMSIZ IF_NAMESIZE #define IF_MAXUNIT 0x7fff /* historical value */ #endif + +/* Length of interface description, including terminating '\0'. */ +#define IFDESCRSIZE 64 + #if __BSD_VISIBLE /* Index: sys/net/if_var.h =================================================================== --- sys/net/if_var.h (revision 196163) +++ sys/net/if_var.h (working copy) @@ -197,6 +197,7 @@ struct ifnet { void *if_pf_kif; void *if_lagg; /* lagg glue */ u_char if_alloctype; /* if_type at time of allocation */ + char if_description[IFDESCRSIZE]; /* interface description */ /* * Spare fields are added so that we can modify sensitive data Index: sys/sys/priv.h =================================================================== --- sys/sys/priv.h (revision 196163) +++ sys/sys/priv.h (working copy) @@ -335,6 +335,7 @@ #define PRIV_NET_LAGG 415 /* Administer lagg interface. */ #define PRIV_NET_GIF 416 /* Administer gif interface. */ #define PRIV_NET_SETIFVNET 417 /* Move interface to vnet. */ +#define PRIV_NET_SETIFDESCR 418 /* Set interface description. */ /* * 802.11-related privileges. --------------090505000704070004090000--