summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjoshua stein <jcs@cvs.openbsd.org>2004-05-29 17:54:47 +0000
committerjoshua stein <jcs@cvs.openbsd.org>2004-05-29 17:54:47 +0000
commit4d102c539fde3c0ed85b6e72d7762111b986fdb3 (patch)
treecb546f34b9a8cba2250874c4d51940e2382efd28
parent25f31fc4bbca56a9826d5afd73ecf39068e32148 (diff)
introduce SIOCSIFDESCR and SIOCGIFDESCR to maintain interface
descriptions, configurable with ifconfig help from various, ok deraadt@
-rw-r--r--sbin/ifconfig/ifconfig.811
-rw-r--r--sbin/ifconfig/ifconfig.c25
-rw-r--r--share/man/man4/netintro.410
-rw-r--r--share/man/man5/hostname.if.54
-rw-r--r--sys/net/if.c21
-rw-r--r--sys/net/if.h8
-rw-r--r--sys/sys/sockio.h5
7 files changed, 75 insertions, 9 deletions
diff --git a/sbin/ifconfig/ifconfig.8 b/sbin/ifconfig/ifconfig.8
index 618e11de1cc..dc7a9681257 100644
--- a/sbin/ifconfig/ifconfig.8
+++ b/sbin/ifconfig/ifconfig.8
@@ -1,4 +1,4 @@
-.\" $OpenBSD: ifconfig.8,v 1.81 2004/05/18 10:54:07 otto Exp $
+.\" $OpenBSD: ifconfig.8,v 1.82 2004/05/29 17:54:46 jcs Exp $
.\" $NetBSD: ifconfig.8,v 1.11 1996/01/04 21:27:29 pk Exp $
.\" $FreeBSD: ifconfig.8,v 1.16 1998/02/01 07:03:29 steve Exp $
.\"
@@ -314,6 +314,11 @@ allow you to respecify the host portion.
.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.
@@ -692,6 +697,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:
.Pp
diff --git a/sbin/ifconfig/ifconfig.c b/sbin/ifconfig/ifconfig.c
index 088650850cb..b329e6b0157 100644
--- a/sbin/ifconfig/ifconfig.c
+++ b/sbin/ifconfig/ifconfig.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ifconfig.c,v 1.99 2004/05/18 10:54:07 otto Exp $ */
+/* $OpenBSD: ifconfig.c,v 1.100 2004/05/29 17:54:46 jcs Exp $ */
/* $NetBSD: ifconfig.c,v 1.40 1997/10/01 02:19:43 enami Exp $ */
/*
@@ -77,7 +77,7 @@ static const char copyright[] =
#if 0
static const char sccsid[] = "@(#)ifconfig.c 8.2 (Berkeley) 2/16/94";
#else
-static const char rcsid[] = "$OpenBSD: ifconfig.c,v 1.99 2004/05/18 10:54:07 otto Exp $";
+static const char rcsid[] = "$OpenBSD: ifconfig.c,v 1.100 2004/05/29 17:54:46 jcs Exp $";
#endif
#endif /* not lint */
@@ -163,6 +163,7 @@ void setifaddr(const char *, int);
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 @@ const struct cmd {
{ "-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 @@ setifbroadaddr(const char *addr, int ignored)
}
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 @@ status(int link, struct sockaddr_dl *sdl)
{
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 @@ status(int link, struct sockaddr_dl *sdl)
(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 @@ usage(void)
"\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"
diff --git a/share/man/man4/netintro.4 b/share/man/man4/netintro.4
index 2679029d85b..522d33cedc3 100644
--- a/share/man/man4/netintro.4
+++ b/share/man/man4/netintro.4
@@ -1,4 +1,4 @@
-.\" $OpenBSD: netintro.4,v 1.23 2003/11/09 16:06:07 jmc Exp $
+.\" $OpenBSD: netintro.4,v 1.24 2004/05/29 17:54:46 jcs Exp $
.\" $NetBSD: netintro.4,v 1.4 1995/10/19 08:03:40 jtc Exp $
.\"
.\" Copyright (c) 1983, 1990, 1991, 1993
@@ -238,6 +238,14 @@ Get interface address for protocol family.
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
diff --git a/share/man/man5/hostname.if.5 b/share/man/man5/hostname.if.5
index 7f19e96ae6c..eb39b089ca9 100644
--- a/share/man/man5/hostname.if.5
+++ b/share/man/man5/hostname.if.5
@@ -1,4 +1,4 @@
-.\" $OpenBSD: hostname.if.5,v 1.36 2004/05/26 14:19:55 otto Exp $
+.\" $OpenBSD: hostname.if.5,v 1.37 2004/05/29 17:54:46 jcs Exp $
.\" $NetBSD: hosts.5,v 1.4 1994/11/30 19:31:20 jtc Exp $
.\"
.\" Copyright (c) 1983, 1991, 1993
@@ -85,7 +85,7 @@ Other network setup:
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
diff --git a/sys/net/if.c b/sys/net/if.c
index 831a76336a1..1beb9f670e0 100644
--- a/sys/net/if.c
+++ b/sys/net/if.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if.c,v 1.87 2004/04/28 01:20:29 deraadt Exp $ */
+/* $OpenBSD: if.c,v 1.88 2004/05/29 17:54:45 jcs Exp $ */
/* $NetBSD: if.c,v 1.35 1996/05/07 05:26:04 thorpej Exp $ */
/*
@@ -1117,7 +1117,9 @@ ifioctl(so, cmd, data, p)
{
struct ifnet *ifp;
struct ifreq *ifr;
+ char ifdescrbuf[IFDESCRSIZE];
int error = 0;
+ size_t bytesdone;
short oif_flags;
switch (cmd) {
@@ -1231,6 +1233,23 @@ ifioctl(so, cmd, data, p)
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:
if (so->so_proto == 0)
return (EOPNOTSUPP);
diff --git a/sys/net/if.h b/sys/net/if.h
index 98ec6ef3eaa..283ef39a693 100644
--- a/sys/net/if.h
+++ b/sys/net/if.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: if.h,v 1.52 2004/05/18 21:10:14 brad Exp $ */
+/* $OpenBSD: if.h,v 1.53 2004/05/29 17:54:45 jcs Exp $ */
/* $NetBSD: if.h,v 1.23 1996/05/07 02:40:27 thorpej Exp $ */
/*
@@ -165,6 +165,11 @@ TAILQ_HEAD(ifnet_head, ifnet); /* the actual queue head */
#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 @@ struct ifnet { /* and the entries */
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) */
diff --git a/sys/sys/sockio.h b/sys/sys/sockio.h
index e78f68b9e94..bc16dff5daa 100644
--- a/sys/sys/sockio.h
+++ b/sys/sys/sockio.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: sockio.h,v 1.24 2003/12/08 09:09:03 markus Exp $ */
+/* $OpenBSD: sockio.h,v 1.25 2004/05/29 17:54:45 jcs Exp $ */
/* $NetBSD: sockio.h,v 1.5 1995/08/23 00:40:47 thorpej Exp $ */
/*-
@@ -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_ */