From owner-freebsd-bugs@FreeBSD.ORG Sun Jul 17 17:40:16 2005 Return-Path: X-Original-To: freebsd-bugs@hub.freebsd.org Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 5140C16A41C for ; Sun, 17 Jul 2005 17:40:16 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id C8E8843D46 for ; Sun, 17 Jul 2005 17:40:15 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.3/8.13.3) with ESMTP id j6HHeF34051539 for ; Sun, 17 Jul 2005 17:40:15 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.3/8.13.1/Submit) id j6HHeFZl051538; Sun, 17 Jul 2005 17:40:15 GMT (envelope-from gnats) Resent-Date: Sun, 17 Jul 2005 17:40:15 GMT Resent-Message-Id: <200507171740.j6HHeFZl051538@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Roman Bogorodskiy Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 9ECE116A41C for ; 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 ; 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 ; 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 To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Cc: Subject: kern/83622: [ patch ] add network interfaces labeling support X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Roman Bogorodskiy List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 17 Jul 2005 17:40:16 -0000 >Number: 83622 >Category: kern >Synopsis: [ patch ] add network interfaces labeling support >Confidential: no >Severity: non-critical >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Sun Jul 17 17:40:15 GMT 2005 >Closed-Date: >Last-Modified: >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 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: >Unformatted: