Date: Fri, 23 Mar 2007 20:05:22 +0300 (MSK) From: Dmitri Alenitchev <dmitri@dworlds.ru> To: FreeBSD-gnats-submit@FreeBSD.org Subject: kern/110720: [patch] support for interface descriptions Message-ID: <20070323170522.5C0671EA652@opay.ru> Resent-Message-ID: <200703231700.l2NH0AVD074642@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 110720 >Category: kern >Synopsis: [patch] support for interface descriptions >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Fri Mar 23 17:00:10 GMT 2007 >Closed-Date: >Last-Modified: >Originator: Dmitri Alenitchev >Release: >Organization: Digital Worlds J.S.C. >Environment: >Description: support for interface descriptions. this can be used to label interfaces in situations where they may otherwise be difficult to identify (e.g. machines with many active interfaces) >How-To-Repeat: >Fix: --- interface_descriptions.diff begins here --- Index: sbin/ifconfig/ifconfig.8 =================================================================== RCS file: /home/ncvs/src/sbin/ifconfig/ifconfig.8,v retrieving revision 1.95.2.17 diff -u -r1.95.2.17 ifconfig.8 --- sbin/ifconfig/ifconfig.8 3 Nov 2006 09:14:24 -0000 1.95.2.17 +++ sbin/ifconfig/ifconfig.8 23 Mar 2007 16:49:03 -0000 @@ -245,6 +245,11 @@ extra console error logging. .It Fl debug Disable driver dependent debugging code. +.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 identify +.Pq e.g. machines with many active interfaces . .It Cm promisc Put interface into permanently promiscuous mode. .It Fl promisc Index: sbin/ifconfig/ifconfig.c =================================================================== RCS file: /home/ncvs/src/sbin/ifconfig/ifconfig.c,v retrieving revision 1.113.2.5 diff -u -r1.113.2.5 ifconfig.c --- sbin/ifconfig/ifconfig.c 18 Mar 2006 21:59:22 -0000 1.113.2.5 +++ sbin/ifconfig/ifconfig.c 23 Mar 2007 16:49:04 -0000 @@ -790,6 +790,15 @@ printname = 0; } +static void +setifdesc(const char *val, int dummy __unused, int s, + const struct afswtch *afp) +{ + ifr.ifr_data = strdup(val); + if (ioctl(s, SIOCSIFDESCR, (caddr_t)&ifr) < 0) + warn("SIOCSIFDESCR"); +} + /* * Expand the compacted form of addresses as returned via the * configuration read via sysctl(). @@ -1050,6 +1059,8 @@ DEF_CMD("noicmp", IFF_LINK1, setifflags), DEF_CMD_ARG("mtu", setifmtu), DEF_CMD_ARG("name", setifname), + DEF_CMD_ARG("description", setifdesc), + DEF_CMD_ARG("descr", setifdesc), }; static __constructor void Index: sbin/ifconfig/ifmedia.c =================================================================== RCS file: /home/ncvs/src/sbin/ifconfig/ifmedia.c,v retrieving revision 1.19.2.2 diff -u -r1.19.2.2 ifmedia.c --- sbin/ifconfig/ifmedia.c 31 Aug 2006 21:01:41 -0000 1.19.2.2 +++ sbin/ifconfig/ifmedia.c 23 Mar 2007 16:49:05 -0000 @@ -106,7 +106,16 @@ media_status(int s) { struct ifmediareq ifmr; + struct ifreq ifrdesc; int *media_list, i; + char *ifdescr[IFDESCRSIZE]; + + (void) memset(&ifrdesc, 0, sizeof(ifrdesc)); + (void) 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); (void) memset(&ifmr, 0, sizeof(ifmr)); (void) strncpy(ifmr.ifm_name, name, sizeof(ifmr.ifm_name)); Index: sys/net/if.c =================================================================== RCS file: /home/ncvs/src/sys/net/if.c,v retrieving revision 1.234.2.17 diff -u -r1.234.2.17 if.c --- sys/net/if.c 6 Oct 2006 20:26:05 -0000 1.234.2.17 +++ sys/net/if.c 23 Mar 2007 16:49:22 -0000 @@ -1233,7 +1233,9 @@ int error = 0; int new_flags, temp_flags; size_t namelen, onamelen; + size_t bytesdone; char new_name[IFNAMSIZ]; + char ifdescrbuf[IFDESCRSIZE]; struct ifaddr *ifa; struct sockaddr_dl *sdl; @@ -1497,6 +1499,23 @@ 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: + error = suser(td); + if (error) + 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: error = ENOIOCTL; break; Index: sys/net/if.h =================================================================== RCS file: /home/ncvs/src/sys/net/if.h,v retrieving revision 1.96.2.4 diff -u -r1.96.2.4 if.h --- sys/net/if.h 15 Feb 2006 03:37:15 -0000 1.96.2.4 +++ sys/net/if.h 23 Mar 2007 16:49:22 -0000 @@ -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. */ Index: sys/net/if_var.h =================================================================== RCS file: /home/ncvs/src/sys/net/if_var.h,v retrieving revision 1.98.2.6 diff -u -r1.98.2.6 if_var.h --- sys/net/if_var.h 6 Oct 2006 20:26:05 -0000 1.98.2.6 +++ sys/net/if_var.h 23 Mar 2007 16:49:22 -0000 @@ -136,6 +136,7 @@ u_short if_nvlans; /* number of active vlans */ int if_flags; /* up/down, broadcast, etc. */ int if_capabilities; /* interface capabilities */ + char if_description[IFDESCRSIZE]; /* interface description */ int if_capenable; /* enabled features */ void *if_linkmib; /* link-type-specific MIB data */ size_t if_linkmiblen; /* length of above data */ Index: sys/sys/sockio.h =================================================================== RCS file: /home/ncvs/src/sys/sys/sockio.h,v retrieving revision 1.28.2.1 diff -u -r1.28.2.1 sockio.h --- sys/sys/sockio.h 15 Feb 2006 03:37:15 -0000 1.28.2.1 +++ sys/sys/sockio.h 23 Mar 2007 16:49:24 -0000 @@ -117,4 +117,7 @@ #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_ */ --- interface_descriptions.diff ends here --- >Release-Note: >Audit-Trail: >Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20070323170522.5C0671EA652>