# $Id: openbsd-interface_descriptions.diff,v 1.1 2004/05/29 17:32:21 jcs Exp $ # XXX: committed # # support for interface descriptions under openbsd, manipulated through new # ioctl calls # # by joshua stein # # to apply patch: # # cd /usr/src # patch -p0 < /path/to/this/diff # make includes # (recompile, install, and boot to a new kernel) # cd /usr/src/sbin/ifconfig # make # sudo make install # # interface descriptions are created with "ifconfig description blah": # # $> ifconfig em0 description "cisco 2480 uplink" # # and can be seen with ifconfig: # # $> ifconfig em0 # em0: flags=8843 mtu 1500 # address: 00:0a:e4:22:83:51 # description: cisco 2480 uplink # media: Ethernet autoselect (100baseTX half-duplex) # [...] # Index: sys/sys/sockio.h =================================================================== RCS file: /cvs/src/sys/sys/sockio.h,v retrieving revision 1.24 diff -u -r1.24 sockio.h --- sys/sys/sockio.h 8 Dec 2003 09:09:03 -0000 1.24 +++ sys/sys/sockio.h 29 May 2004 17:31:39 -0000 @@ -143,4 +143,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_ */ Index: sys/net/if.h =================================================================== RCS file: /cvs/src/sys/net/if.h,v retrieving revision 1.52 diff -u -r1.52 if.h --- sys/net/if.h 18 May 2004 21:10:14 -0000 1.52 +++ sys/net/if.h 29 May 2004 17:31:39 -0000 @@ -165,6 +165,11 @@ #define IFNAMSIZ 16 #define IF_NAMESIZE IFNAMSIZ +/* + * Length of interface description, including terminating '\0'. + */ +#define IFDESCRSIZE 64 + struct ifnet { /* and the entries */ void *if_softc; /* lower-level data for this if */ TAILQ_ENTRY(ifnet) if_list; /* all struct ifnets are chained */ @@ -180,6 +185,7 @@ short if_flags; /* up/down, broadcast, etc. */ struct if_data if_data; /* stats and other data about if */ int if_capabilities; /* interface capabilities */ + char if_description[IFDESCRSIZE]; /* interface description */ /* procedure handles */ /* output routine (enqueue) */ Index: sys/net/if.c =================================================================== RCS file: /cvs/src/sys/net/if.c,v retrieving revision 1.87 diff -u -r1.87 if.c --- sys/net/if.c 28 Apr 2004 01:20:29 -0000 1.87 +++ sys/net/if.c 29 May 2004 17:31:40 -0000 @@ -1117,7 +1117,9 @@ { struct ifnet *ifp; struct ifreq *ifr; + char ifdescrbuf[IFDESCRSIZE]; int error = 0; + size_t bytesdone; short oif_flags; switch (cmd) { @@ -1229,6 +1231,23 @@ if (ifp->if_ioctl == 0) return (EOPNOTSUPP); error = (*ifp->if_ioctl)(ifp, cmd, data); + break; + + case SIOCGIFDESCR: + strlcpy(ifdescrbuf, ifp->if_description, IFDESCRSIZE); + error = copyoutstr(ifdescrbuf, ifr->ifr_data, IFDESCRSIZE, + &bytesdone); + break; + + case SIOCSIFDESCR: + if ((error = suser(p, 0)) != 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: Index: share/man/man4/netintro.4 =================================================================== RCS file: /cvs/src/share/man/man4/netintro.4,v retrieving revision 1.23 diff -u -r1.23 netintro.4 --- share/man/man4/netintro.4 9 Nov 2003 16:06:07 -0000 1.23 +++ share/man/man4/netintro.4 29 May 2004 17:31:40 -0000 @@ -238,6 +238,14 @@ Get point to point address for protocol family and interface. .It Dv SIOCGIFBRDADDR Get broadcast address for protocol family and interface. +.It Dv SIOCGIFDESCR +Get interface description, returned in the +.Ar ifru_data +field. +.It Dv SIOCSIFDESCR +Set interface description to the value of the +.Ar ifru_data +field, limited to the size of IFDESCRSIZE. .It Dv SIOCSIFFLAGS Set interface flags field. If the interface is marked down, any processes currently routing packets Index: sbin/ifconfig/ifconfig.c =================================================================== RCS file: /cvs/src/sbin/ifconfig/ifconfig.c,v retrieving revision 1.99 diff -u -r1.99 ifconfig.c --- sbin/ifconfig/ifconfig.c 18 May 2004 10:54:07 -0000 1.99 +++ sbin/ifconfig/ifconfig.c 29 May 2004 17:31:40 -0000 @@ -163,6 +163,7 @@ void setifdstaddr(const char *, int); void setifflags(const char *, int); void setifbroadaddr(const char *, int); +void setifdesc(const char *, int); void setifipdst(const char *, int); void setifmetric(const char *, int); void setifmtu(const char *, int); @@ -317,6 +318,8 @@ { "-mediaopt", NEXTARG, A_MEDIAOPTCLR, unsetmediaopt }, { "instance", NEXTARG, A_MEDIAINST, setmediainst }, { "inst", NEXTARG, A_MEDIAINST, setmediainst }, + { "description", NEXTARG, 0, setifdesc }, + { "descr", NEXTARG, 0, setifdesc }, { NULL, /*src*/ 0, 0, setifaddr }, { NULL, /*dst*/ 0, 0, setifdstaddr }, { NULL, /*illegal*/0, 0, NULL }, @@ -871,6 +874,14 @@ } void +setifdesc(const char *val, int ignored) +{ + ifr.ifr_data = (caddr_t)val; + if (ioctl(s, SIOCSIFDESCR, &ifr) < 0) + warn("SIOCSIFDESCR"); +} + +void setifipdst(const char *addr, int ignored) { in_getaddr(addr, DSTADDR); @@ -1667,7 +1678,9 @@ { const struct afswtch *p = afp; struct ifmediareq ifmr; + struct ifreq ifrdesc; int *media_list, i; + char *ifdescr[IFDESCRSIZE]; printf("%s: ", name); printb("flags", flags, IFFBITS); @@ -1680,6 +1693,13 @@ (void)printf("\taddress: %s\n", ether_ntoa( (struct ether_addr *)LLADDR(sdl))); + (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); + vlan_status(); carp_status(); pfsync_status(); @@ -2540,6 +2560,7 @@ "\t[[-]alias] [[-]arp] [broadcast addr]\n" "\t[[-]debug] [delete] [up] [down] [ipdst addr]\n" "\t[tunnel src_address dest_address] [deletetunnel]\n" + "\t[description value]\n" "\t[[-]link0] [[-]link1] [[-]link2]\n" "\t[media type] [[-]mediaopt opts] [instance minst]\n" "\t[mtu value] [metric nhops] [netmask mask] [prefixlen n]\n" Index: sbin/ifconfig/ifconfig.8 =================================================================== RCS file: /cvs/src/sbin/ifconfig/ifconfig.8,v retrieving revision 1.81 diff -u -r1.81 ifconfig.8 --- sbin/ifconfig/ifconfig.8 18 May 2004 10:54:07 -0000 1.81 +++ sbin/ifconfig/ifconfig.8 29 May 2004 17:31:40 -0000 @@ -314,6 +314,11 @@ .It Cm deletetunnel Removes the source and destination tunnel addresses, configured onto a tunnel interface. +.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 Ar dest_address Specify the address of the correspondent on the other end of a point-to-point link. @@ -691,6 +696,10 @@ Configure the xl0 interface to use 100baseTX, full duplex: .Pp .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 Configure the vlan0 interface for IP address 192.168.254.1, vlan tag 4, and vlan parent device fxp0: Index: share/man/man5/hostname.if.5 =================================================================== RCS file: /cvs/src/share/man/man5/hostname.if.5,v retrieving revision 1.36 diff -u -r1.36 hostname.if.5 --- share/man/man5/hostname.if.5 26 May 2004 14:19:55 -0000 1.36 +++ share/man/man5/hostname.if.5 29 May 2004 17:31:40 -0000 @@ -85,7 +85,7 @@ A typical file contains only one line, but more extensive files are possible, for example: .Bd -literal -offset indent -inet 10.0.1.12 255.255.255.0 10.0.1.255 media 100baseTX +inet 10.0.1.12 255.255.255.0 10.0.1.255 media 100baseTX description Uplink inet alias 10.0.1.13 255.255.255.255 10.0.1.13 inet alias 10.0.1.14 255.255.255.255 NONE inet alias 10.0.1.15 255.255.255.255