diff options
author | phk <phk@FreeBSD.org> | 1999-06-19 18:42:31 +0000 |
---|---|---|
committer | phk <phk@FreeBSD.org> | 1999-06-19 18:42:31 +0000 |
commit | 1048fa73010ca9dfb0cfba83b166fcfa2ef994be (patch) | |
tree | 32836c1e0c0e6d5d181e3dd1260ec5097dfa0a32 /sys/net | |
parent | d99f3d7a9346a2099e09e6afbacee7bffacdbdaa (diff) | |
download | FreeBSD-src-1048fa73010ca9dfb0cfba83b166fcfa2ef994be.zip FreeBSD-src-1048fa73010ca9dfb0cfba83b166fcfa2ef994be.tar.gz |
Add a new interface ioctl, to return "aux status".
This is inteded for to allow ifconfig to print various unstructured
information from an interface.
The data is returned from the kernel in ASCII form, see the comment in
if.h for some technicalities.
Canonical cut&paste example to be found in if_tun.c
Initial use:
Now tun* interfaces tell the PID of the process which opened them.
Future uses could be (volounteers welcome!):
Have ppp/slip interfaces tell which tty they use.
Make sync interfaces return their media state: red/yellow/blue
alarm, timeslot assignment and so on.
Make ethernets warn about missing heartbeats and/or cables
Diffstat (limited to 'sys/net')
-rw-r--r-- | sys/net/if.c | 7 | ||||
-rw-r--r-- | sys/net/if.h | 16 | ||||
-rw-r--r-- | sys/net/if_tun.c | 12 | ||||
-rw-r--r-- | sys/net/if_tunvar.h | 3 |
4 files changed, 34 insertions, 4 deletions
diff --git a/sys/net/if.c b/sys/net/if.c index d51afcd..c6f5c5e 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * @(#)if.c 8.3 (Berkeley) 1/4/94 - * $Id: if.c,v 1.71 1999/06/06 09:17:49 phk Exp $ + * $Id: if.c,v 1.72 1999/06/06 09:28:01 phk Exp $ */ #include "opt_compat.h" @@ -604,6 +604,7 @@ ifioctl(so, cmd, data, p) { register struct ifnet *ifp; register struct ifreq *ifr; + struct ifstat *ifs; int error; switch (cmd) { @@ -731,6 +732,10 @@ ifioctl(so, cmd, data, p) getmicrotime(&ifp->if_lastchange); return error; + case SIOCGIFSTATUS: + ifs = (struct ifstat *)data; + ifs->ascii[0] = '\0'; + case SIOCGIFMEDIA: case SIOCGIFGENERIC: if (ifp->if_ioctl == 0) diff --git a/sys/net/if.h b/sys/net/if.h index a639bc2..13048b0 100644 --- a/sys/net/if.h +++ b/sys/net/if.h @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * @(#)if.h 8.1 (Berkeley) 6/10/93 - * $Id: if.h,v 1.52 1999/05/08 07:00:04 phk Exp $ + * $Id: if.h,v 1.53 1999/06/06 09:17:51 phk Exp $ */ #ifndef _NET_IF_H_ @@ -197,6 +197,20 @@ struct ifmediareq { int ifm_count; /* # entries in ifm_ulist array */ int *ifm_ulist; /* media words */ }; + +/* + * Structure used to retrieve aux status data from interfaces. + * kernel suppliers to this interface should respect the formatting + * needed by ifconfig(8): each line starts with a TAB and ends with + * a newline. The canonical example to copy&past is in if_tun.c + */ + +#define IFSTATMAX 800 /* 10 lines of text */ +struct ifstat { + char ifs_name[IFNAMSIZ]; /* if name, e.g. "en0" */ + char ascii[IFSTATMAX+1]; +}; + /* * Structure used in SIOCGIFCONF request. * Used to retrieve interface configuration diff --git a/sys/net/if_tun.c b/sys/net/if_tun.c index caff2d4..8d16b7d 100644 --- a/sys/net/if_tun.c +++ b/sys/net/if_tun.c @@ -173,6 +173,7 @@ tunopen(dev, flag, mode, p) tp = &tunctl[unit]; if (tp->tun_flags & TUN_OPEN) return EBUSY; + tp->tun_pid = p->p_pid; ifp = &tp->tun_if; tp->tun_flags |= TUN_OPEN; TUNDEBUG("%s%d: open\n", ifp->if_name, ifp->if_unit); @@ -196,6 +197,7 @@ tunclose(dev, foo, bar, p) struct mbuf *m; tp->tun_flags &= ~TUN_OPEN; + tp->tun_pid = 0; /* * junk all pending output @@ -276,11 +278,19 @@ tunifioctl(ifp, cmd, data) u_long cmd; caddr_t data; { - register struct ifreq *ifr = (struct ifreq *)data; + struct ifreq *ifr = (struct ifreq *)data; + struct tun_softc *tp = &tunctl[ifp->if_unit]; + struct ifstat *ifs; int error = 0, s; s = splimp(); switch(cmd) { + case SIOCGIFSTATUS: + ifs = (struct ifstat *)data; + if (tp->tun_pid) + sprintf(ifs->ascii + strlen(ifs->ascii), + "\tOpened by PID %d\n", tp->tun_pid); + return(0); case SIOCSIFADDR: tuninit(ifp->if_unit); TUNDEBUG("%s%d: address set\n", diff --git a/sys/net/if_tunvar.h b/sys/net/if_tunvar.h index 496c4fb..8a0e9b5 100644 --- a/sys/net/if_tunvar.h +++ b/sys/net/if_tunvar.h @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: if_tunvar.h,v 1.3 1998/11/11 10:56:05 truckman Exp $ + * $Id: if_tunvar.h,v 1.4 1999/03/24 21:20:12 des Exp $ */ #ifndef _NET_IF_TUNVAR_H_ @@ -42,6 +42,7 @@ struct tun_softc { #define TUN_READY (TUN_OPEN | TUN_INITED) + pid_t tun_pid; /* PID of process to open */ struct ifnet tun_if; /* the interface */ struct sigio *tun_sigio; /* information for async I/O */ struct selinfo tun_rsel; /* read select */ |