From novel@FreeBSD.org  Sun Jul 17 17:34:59 2005
Return-Path: <novel@FreeBSD.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 9ECE116A41C
	for <FreeBSD-gnats-submit@freebsd.org>; Sun, 17 Jul 2005 17:34:59 +0000 (GMT)
	(envelope-from novel@FreeBSD.org)
Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 610BB43D46
	for <FreeBSD-gnats-submit@freebsd.org>; Sun, 17 Jul 2005 17:34:59 +0000 (GMT)
	(envelope-from novel@FreeBSD.org)
Received: from freefall.freebsd.org (novel@localhost [127.0.0.1])
	by freefall.freebsd.org (8.13.3/8.13.3) with ESMTP id j6HHYxa8051259
	for <FreeBSD-gnats-submit@freebsd.org>; Sun, 17 Jul 2005 17:34:59 GMT
	(envelope-from novel@freefall.freebsd.org)
Received: (from novel@localhost)
	by freefall.freebsd.org (8.13.3/8.13.1/Submit) id j6HHYxmD051258;
	Sun, 17 Jul 2005 17:34:59 GMT
	(envelope-from novel)
Message-Id: <200507171734.j6HHYxmD051258@freefall.freebsd.org>
Date: Sun, 17 Jul 2005 17:34:59 GMT
From: Roman Bogorodskiy <novel@freebsd.org>
Reply-To: Roman Bogorodskiy <novel@freebsd.org>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: [ patch ] add network interfaces labeling support
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         83622
>Category:       kern
>Synopsis:       [net] [patch] add network interfaces labeling support
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    brooks
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sun Jul 17 17:40:15 GMT 2005
>Closed-Date:    Wed Apr 27 11:27:00 UTC 2011
>Last-Modified:  Wed Apr 27 11:27:00 UTC 2011
>Originator:     Roman Bogorodskiy
>Release:        FreeBSD 4.11-STABLE i386
>Organization:
>Environment:
System: FreeBSD freefall.freebsd.org 4.11-STABLE FreeBSD 4.11-STABLE #16: Sat Feb 26 00:02:03 GMT 2005 kensmith@freefall.freebsd.org:/c/src/sys/compile/FREEFALL i386


>Description:
        This patch inspired by and based on work of OpenBSD people. It allows
        setting description (label) for network interfaces. For example:

        $> sudo ifconfig lo0 descr "loopback device"
        $> ifconfig lo0
        lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
                description: loopback device
                inet 127.0.0.1 netmask 0xff000000
                inet6 ::1 prefixlen 128
                inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1
        $>

        That may be useful when you have a lot of interfaces.

        Attached diff contains patch for kernel and ifconfig(8). You can also
        get it here:
        http://people.freebsd.org/~novel/patches/freebsd/if_descr.polished.diff

>How-To-Repeat:
>Fix:

diff -ru src.bak/sbin/ifconfig/ifconfig.c src/sbin/ifconfig/ifconfig.c
--- src.bak/sbin/ifconfig/ifconfig.c	Sun Jul 17 17:47:09 2005
+++ src/sbin/ifconfig/ifconfig.c	Sun Jul 17 18:55:49 2005
@@ -726,6 +726,14 @@
 }
 
 void
+setifdesc(const char *val, int dummy __unused, int s, const struct afswtch *afp)
+{
+	ifr.ifr_data = (caddr_t)val;
+	if (ioctl(s, SIOCSIFDESCR, &ifr) < 0)
+		warn("SIOCSIFDESCR");
+}
+		
+void
 setifcap(const char *vname, int value, int s, const struct afswtch *afp)
 {
 
@@ -829,6 +837,8 @@
 	struct	rt_addrinfo info;
 	int allfamilies, s;
 	struct ifstat ifs;
+	struct ifreq ifrdesc;
+	char ifdescr[IFDESCRSIZE];
 
 	if (afp == NULL) {
 		allfamilies = 1;
@@ -851,6 +861,13 @@
 		printf(" mtu %ld", ifm->ifm_data.ifi_mtu);
 	putchar('\n');
 
+	memset(&ifrdesc, 0, sizeof(ifrdesc));
+        strlcpy(ifrdesc.ifr_name, name, sizeof(ifrdesc.ifr_name));
+        ifrdesc.ifr_data = (caddr_t)&ifdescr;
+        if (ioctl(s, SIOCGIFDESCR, &ifrdesc) == 0 &&
+            strlen(ifrdesc.ifr_data))
+                printf("\tdescription: %s\n", ifrdesc.ifr_data);
+	
 	if (ioctl(s, SIOCGIFCAP, (caddr_t)&ifr) == 0) {
 		if (ifr.ifr_curcap != 0) {
 			printb("\toptions", ifr.ifr_curcap, IFCAPBITS);
@@ -1025,6 +1042,8 @@
 	DEF_CMD_ARG("metric",			setifmetric),
 	DEF_CMD_ARG("broadcast",		setifbroadaddr),
 	DEF_CMD_ARG("ipdst",			setifipdst),
+	DEF_CMD_ARG("description",		setifdesc),
+	DEF_CMD_ARG("descr",			setifdesc),
 	DEF_CMD_ARG2("tunnel",			settunnel),
 	DEF_CMD("deletetunnel", 0,		deletetunnel),
 	DEF_CMD("link0",	IFF_LINK0,	setifflags),
diff -ru src.bak/sbin/ifconfig/ifconfig.h src/sbin/ifconfig/ifconfig.h
--- src.bak/sbin/ifconfig/ifconfig.h	Sun Jul 17 17:47:09 2005
+++ src/sbin/ifconfig/ifconfig.h	Sun Jul 17 18:54:44 2005
@@ -134,6 +134,7 @@
 extern	int setipdst;
 
 void	setifcap(const char *, int value, int s, const struct afswtch *);
+void	setifdesc(const char *, int, int, const struct afswtch *);
 
 void	Perror(const char *cmd);
 void	printb(const char *s, unsigned value, const char *bits);
diff -ru src.bak/sys/net/if.c src/sys/net/if.c
--- src.bak/sys/net/if.c	Sun Jul 17 17:46:40 2005
+++ src/sys/net/if.c	Sun Jul 17 17:54:31 2005
@@ -1224,7 +1224,9 @@
 {
 	struct ifreq *ifr;
 	struct ifstat *ifs;
+	char ifdescrbuf[IFDESCRSIZE];
 	int error = 0;
+	size_t bytesdone;
 	int new_flags;
 	size_t namelen, onamelen;
 	char new_name[IFNAMSIZ];
@@ -1484,6 +1486,22 @@
 			return (error);
 		error = if_setlladdr(ifp,
 		    ifr->ifr_addr.sa_data, ifr->ifr_addr.sa_len);
+		break;
+
+	case SIOCGIFDESCR:
+		strlcpy(ifdescrbuf, ifp->if_description, IFDESCRSIZE);
+		error = copyout(ifdescrbuf, ifr->ifr_data, IFDESCRSIZE);
+		break;
+
+	case SIOCSIFDESCR:
+		if ((error = suser(td)) != 0)
+			return (error);
+		error = copyinstr(ifr->ifr_data, ifdescrbuf,
+			IFDESCRSIZE, &bytesdone);
+		if (error == 0) {
+			(void)memset(ifp->if_description, 0, IFDESCRSIZE);
+			strlcpy(ifp->if_description, ifdescrbuf, IFDESCRSIZE);
+		}
 		break;
 
 	default:
diff -ru src.bak/sys/net/if.h src/sys/net/if.h
--- src.bak/sys/net/if.h	Sun Jul 17 17:46:40 2005
+++ src/sys/net/if.h	Sun Jul 17 17:52:35 2005
@@ -63,6 +63,11 @@
 #if __BSD_VISIBLE
 
 /*
+ + * Length of interface description, including terminating '\0'.
+ */
+#define        IFDESCRSIZE     64
+
+/*
  * Structure used to query names of interface cloners.
  */
 
diff -ru src.bak/sys/net/if_var.h src/sys/net/if_var.h
--- src.bak/sys/net/if_var.h	Sun Jul 17 17:46:41 2005
+++ src/sys/net/if_var.h	Sun Jul 17 17:52:35 2005
@@ -137,6 +137,7 @@
 	int	if_flags;		/* up/down, broadcast, etc. */
 	int	if_capabilities;	/* interface capabilities */
 	int	if_capenable;		/* enabled features */
+	char    if_description[IFDESCRSIZE]; /* interface description */
 	void	*if_linkmib;		/* link-type-specific MIB data */
 	size_t	if_linkmiblen;		/* length of above data */
 	struct	if_data if_data;
diff -ru src.bak/sys/sys/sockio.h src/sys/sys/sockio.h
--- src.bak/sys/sys/sockio.h	Sun Jul 17 17:46:49 2005
+++ src/sys/sys/sockio.h	Sun Jul 17 17:52:35 2005
@@ -114,4 +114,8 @@
 #define	SIOCIFDESTROY	 _IOW('i', 121, struct ifreq)	/* destroy clone if */
 #define	SIOCIFGCLONERS	_IOWR('i', 120, struct if_clonereq) /* get cloners */
 
+#define        SIOCSIFDESCR     _IOW('i', 128, struct ifreq)   /* set ifnet descr */
+#define        SIOCGIFDESCR    _IOWR('i', 129, struct ifreq)   /* get ifnet descr */
+
+
 #endif /* !_SYS_SOCKIO_H_ */
>Release-Note:
>Audit-Trail:

From: Robert Watson <rwatson@FreeBSD.org>
To: Roman Bogorodskiy <novel@FreeBSD.org>
Cc: FreeBSD-gnats-submit@FreeBSD.org
Subject: Re: kern/83622: [ patch ] add network interfaces labeling support
Date: Sun, 17 Jul 2005 20:58:54 +0100 (BST)

 On Sun, 17 Jul 2005, Roman Bogorodskiy wrote:
 
 > +	case SIOCGIFDESCR:
 > +		strlcpy(ifdescrbuf, ifp->if_description, IFDESCRSIZE);
 > +		error = copyout(ifdescrbuf, ifr->ifr_data, IFDESCRSIZE);
 > +		break;
 
 No comment on the patch as a whole just now, but...
 
 You should bzero the buffer first, or risk leaking kernel memory (which 
 might include sensitive information, such as passwords that were in socket 
 buffers) to untrusted user space processes.
 
 Robert N M Watson

From: Roman Bogorodskiy <novel@FreeBSD.org>
To: bug-followup@FreeBSD.org, novel@FreeBSD.org,
        Robert Watson <rwatson@FreeBSD.org>
Cc:  
Subject: Re: kern/83622: [ patch ] add network interfaces labeling support
Date: Mon, 18 Jul 2005 11:33:28 +0000

 I've updated the code to call bzero() before copyout() as suggested
 by rwatson. New patch is here:
 http://people.freebsd.org/~novel/patches/freebsd/if_descr2.diff
 
 Roman Bogorodskiy

From: Brooks Davis <brooks@one-eyed-alien.net>
To: Roman Bogorodskiy <novel@freebsd.org>
Cc: FreeBSD-gnats-submit@freebsd.org
Subject: Re: kern/83622: [ patch ] add network interfaces labeling support
Date: Mon, 18 Jul 2005 10:40:53 -0700

 This seems like an intresting and useful feature.  I'd like to see the
 storage malloc'd instead of stuffed in the ifnet.  There's no sense
 in using 64 bytes in ever ifnet when I suspect most people won't ever
 use this feature.  It would also avoid hardcoding a limit in ifconfig
 (you'll want to restrict overall size, probably to MAX_PHYS).  To
 maintain ABI compatability, the ifnet entry should be placed at the end
 of struct ifnet.  That's required for RELENG_6 and I'd like to keep HEAD
 ABI compatable with RELENG_6 at least until 6.0-RELEASE.  On the nikpick
 front, strlen returns a length, not a boolen.  Any reason for skipping
 to 128 and 129 in the ioctls?  Updates to the ifconfig(8) and ifnet(9)
 manpages will also be needed before a commit can happen.
 
 Thanks for your submission.
 
 -- Brooks

From: "Bjoern A. Zeeb" <bzeeb+freebsd@zabbadoz.net>
To: FreeBSD-gnats-submit@FreeBSD.org
Cc:  
Subject: Re: kern/83622: [ patch ] add network interfaces labeling support
Date: Mon, 18 Jul 2005 20:16:16 +0000 (UTC)

 I am realy unsure about stuffing such data into kernel.
 It's 'nice' but not more.
 
 Usually high level CLIs give the ability to set interface
 descriptions and show them...
 
 I case we'll do it I think we should take RFC2233 ifAlias
 into account.
 

From: Roman Bogorodskiy <bogorodskiy@gmail.com>
To: Brooks Davis <brooks@one-eyed-alien.net>
Cc: Roman Bogorodskiy <novel@freebsd.org>, FreeBSD-gnats-submit@freebsd.org
Subject: Re: kern/83622: [ patch ] add network interfaces labeling support
Date: Tue, 19 Jul 2005 14:18:53 +0400

 --azLHFNyN32YCQGCU
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 Content-Transfer-Encoding: quoted-printable
 
  Brooks wrote:
 
 > This seems like an intresting and useful feature.  I'd like to see the
 > storage malloc'd instead of stuffed in the ifnet.  There's no sense
 > in using 64 bytes in ever ifnet when I suspect most people won't ever
 > use this feature.  It would also avoid hardcoding a limit in ifconfig
 > (you'll want to restrict overall size, probably to MAX_PHYS).  To
 
 Well, I think 64 bytes is not a big problem (I assume nobody's using
 5.x, 6.x and 7.x on hardware where few kilobytes make sense). Anyway,
 I'd be glad to see an example of malloc'ing storage for it.
 
 > maintain ABI compatability, the ifnet entry should be placed at the end
 > of struct ifnet.  That's required for RELENG_6 and I'd like to keep HEAD
 > ABI compatable with RELENG_6 at least until 6.0-RELEASE.  On the nikpick
 
 That's no problem to fix it.=20
 
 > front, strlen returns a length, not a boolen.  Any reason for skipping
 > to 128 and 129 in the ioctls?  Updates to the ifconfig(8) and ifnet(9)
 > manpages will also be needed before a commit can happen.
 
 That's also not a problem.
 
 Roman Bogorodskiy
 
 --azLHFNyN32YCQGCU
 Content-Type: application/pgp-signature
 Content-Disposition: inline
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.4.1 (FreeBSD)
 
 iQCVAwUBQtzTjYB0WzgdqspGAQJpfgQAjWpciVutTSChTnzf7U2YaaQu1EYpIkcD
 cCdsyPlOswvD1+A1JSxRzhG+b2MqWWJSJc2ZnjPZoXIbUEu0ucioyvjLGkO/a/eL
 FL2TvvfIZe0r+DCtxP/afe8D5yEVHDuOFAqzjIaTLYYenVqs61yLbs5tN7sKJ6rY
 KxbrmXmP2zw=
 =bPB/
 -----END PGP SIGNATURE-----
 
 --azLHFNyN32YCQGCU--

From: Brooks Davis <brooks@one-eyed-alien.net>
To: Roman Bogorodskiy <bogorodskiy@gmail.com>
Cc: Brooks Davis <brooks@one-eyed-alien.net>,
        Roman Bogorodskiy <novel@freebsd.org>,
        FreeBSD-gnats-submit@freebsd.org
Subject: Re: kern/83622: [ patch ] add network interfaces labeling support
Date: Tue, 19 Jul 2005 07:19:42 -0700

 On Tue, Jul 19, 2005 at 02:18:53PM +0400, Roman Bogorodskiy wrote:
 >  Brooks wrote:
 > 
 > > This seems like an intresting and useful feature.  I'd like to see the
 > > storage malloc'd instead of stuffed in the ifnet.  There's no sense
 > > in using 64 bytes in ever ifnet when I suspect most people won't ever
 > > use this feature.  It would also avoid hardcoding a limit in ifconfig
 > > (you'll want to restrict overall size, probably to MAX_PHYS).  To
 > 
 > Well, I think 64 bytes is not a big problem (I assume nobody's using
 > 5.x, 6.x and 7.x on hardware where few kilobytes make sense). Anyway,
 > I'd be glad to see an example of malloc'ing storage for it.
 
 64 bytes isn't a big deal, but it adds up.  You can currently have up to
 2^15-1 interfaces and I'd like to eliminate that restriction at some
 point.  Some of the work Sam Leffler is doing and the directions he is
 pushing the 802.11 code in argue for keeping ifnet from growing too
 much.  I don't mind adding 4-8 bytes for the pointer, but most people
 either won't use this feature or won't use 64-byte strings so using
 malloc could save a fair bit of space.
 
 Malloc works the same as in userland except that it takes a couple extra
 arguements and there is no realloc so you have to implement that by
 hand.  See the malloc(9) manpage.  Use the M_IFNET malloc type (used in
 if_alloc in RELENG_6 and HEAD.
 
 -- Brooks

From: Roman Bogorodskiy <novel@FreeBSD.org>
To: bug-followup@FreeBSD.org
Cc: Brooks Davis <brooks@one-eyed-alien.net>,
        Robert Watson <rwatson@FreeBSD.org>
Subject: Re: kern/83622: [patch] add network interfaces labeling support
Date: Thu, 24 Aug 2006 18:03:28 +0400

 --BOKacYhQ+x31HxR3
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 Content-Transfer-Encoding: quoted-printable
 
 Hi,
 
 I have updated the patch to work on RELENG_6. Here's it:
 http://people.freebsd.org/~novel/patches/freebsd/ifdescr_20060824_1_RELENG_=
 6.diff
 
 About a year ago brooks@ gave me a lot of helpful advises and now it
 allocates descriptions dynamicly.
 
 If it's not clear how that feature can be useful, we have a server with
 a lot of vlans:
 
 r1[~]# ifconfig | grep "^vlan"|wc -l
       36
 r1[~]#=20
 
 It's very hard to remember what is what.
 It can be usefull with mpd's up and down script as well.
 
 --BOKacYhQ+x31HxR3
 Content-Type: application/pgp-signature
 Content-Disposition: inline
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.4.5 (FreeBSD)
 
 iQCVAwUBRO2xsIB0WzgdqspGAQJ8YAQArTbJf86YAJ4ggq/f7kuo7I+99FjY4N1M
 Bok6VFdtN+jYdQ0myuntqrglzeTeNJ/6HJ1qrH8jhhFQc/+Do6dDP6Fps4FT3vbP
 7eKTqXXx2ojoEQx/cAsC/2GZP5xYGs1l0TOKTaTfnWJ090HC1cg0TfiduRC26icK
 asNjJZb/30c=
 =F/8a
 -----END PGP SIGNATURE-----
 
 --BOKacYhQ+x31HxR3--

From: Brooks Davis <brooks@one-eyed-alien.net>
To: bug-followup@freebsd.org, novel@freebsd.org
Cc:  
Subject: Re: kern/83622: [patch] add network interfaces labeling support
Date: Sun, 11 Mar 2007 18:30:19 +0900

 I'd like to see ifr_data replaced with a pointer+size which would allow using 
 a single malloc and avoid hard coding the maximum size at 64-bytes (I'd use 
 MAXPHYS instead).  Here's a (totally untested concept patch if you want to 
 give it a try.  I keep meaning to do it, but haven't gotten around to it.
 
 -- Brooks
 
 Index: if.h
 ===================================================================
 RCS file: /usr/cvs/src/sys/net/if.h,v
 retrieving revision 1.105
 diff -u -p -r1.105 if.h
 --- if.h	6 Sep 2006 21:51:58 -0000	1.105
 +++ if.h	11 Mar 2007 09:18:09 -0000
 @@ -283,6 +283,10 @@ struct	ifreq {
  		struct	sockaddr ifru_addr;
  		struct	sockaddr ifru_dstaddr;
  		struct	sockaddr ifru_broadaddr;
 +		struct {
 +			voidd	*data;
 +			size_t	len;
 +		}	ifru_sdata;
  		short	ifru_flags[2];
  		short	ifru_index;
  		int	ifru_metric;
 @@ -295,6 +299,8 @@ struct	ifreq {
  #define	ifr_addr	ifr_ifru.ifru_addr	/* address */
  #define	ifr_dstaddr	ifr_ifru.ifru_dstaddr	/* other end of p-to-p link */
  #define	ifr_broadaddr	ifr_ifru.ifru_broadaddr	/* broadcast address */
 +#define	ifr_sdata	ifr_ifru.ifru_sdata.data /* sized data pointer */
 +#define	ifr_sdatalen	ifr_ifru.ifru_sdata.len	/* sized data length */
  #define	ifr_flags	ifr_ifru.ifru_flags[0]	/* flags (low 16 bits) */
  #define	ifr_flagshigh	ifr_ifru.ifru_flags[1]	/* flags (high 16 bits) */
  #define	ifr_metric	ifr_ifru.ifru_metric	/* metric */
  

From: "Andrey V. Elsukov" <bu7cher@yandex.ru>
To: bug-followup@FreeBSD.org
Cc: novel@freebsd.org, Brooks Davis <brooks@one-eyed-alien.net>
Subject: Re: kern/83622: [net] [patch] add network interfaces labeling support
Date: Wed, 24 Oct 2007 11:51:38 +0400

 Hi, All.
 
 What you think about this idea:
 we can have config file, for example /etc/interfaces (similar to
 /etc/networks) and put each description into this file.
 ifconfig will lookup description from this file and show it.
 With this we don't needed any kernel changes..
 
 -- 
 WBR, Andrey V. Elsukov
Responsible-Changed-From-To: freebsd-bugs->brooks 
Responsible-Changed-By: rwatson 
Responsible-Changed-When: Tue Feb 3 23:16:17 UTC 2009 
Responsible-Changed-Why:  
Assign to brooks at his request. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=83622 
State-Changed-From-To: open->closed 
State-Changed-By: ae 
State-Changed-When: Wed Apr 27 11:24:32 UTC 2011 
State-Changed-Why:  
The similar functional is already committed to head/ and stable/8 branches. 
Thanks! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=83622 
>Unformatted:
