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
This commit is contained in:
phk 1999-06-19 18:42:31 +00:00
parent d99f3d7a93
commit 1048fa7301
6 changed files with 43 additions and 6 deletions

View File

@ -42,7 +42,7 @@ static const char copyright[] =
static char sccsid[] = "@(#)ifconfig.c 8.2 (Berkeley) 2/16/94";
#endif
static const char rcsid[] =
"$Id: ifconfig.c,v 1.39 1999/03/15 01:22:01 wpaul Exp $";
"$Id: ifconfig.c,v 1.40 1999/06/06 09:17:30 phk Exp $";
#endif /* not lint */
#include <sys/param.h>
@ -720,6 +720,7 @@ status(afp, addrcount, sdl, ifm, ifam)
const struct afswtch *p = NULL;
struct rt_addrinfo info;
int allfamilies, s;
struct ifstat ifs;
if (afp == NULL) {
allfamilies = 1;
@ -757,6 +758,10 @@ status(afp, addrcount, sdl, ifm, ifam)
printf(" mtu %d", mtu);
putchar('\n');
strncpy(ifs.ifs_name, name, sizeof ifs.ifs_name);
if (ioctl(s, SIOCGIFSTATUS, &ifs) == 0)
printf("%s", ifs.ascii);
while (addrcount > 0) {
info.rti_addrs = ifam->ifam_addrs;

View File

@ -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)

View File

@ -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

View File

@ -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",

View File

@ -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 */

View File

@ -31,7 +31,7 @@
* SUCH DAMAGE.
*
* @(#)sockio.h 8.1 (Berkeley) 3/28/94
* $Id: sockio.h,v 1.10 1997/05/03 21:05:03 peter Exp $
* $Id: sockio.h,v 1.11 1997/10/07 07:39:40 joerg Exp $
*/
#ifndef _SYS_SOCKIO_H_
@ -85,4 +85,6 @@
#define SIOCSIFGENERIC _IOW('i', 57, struct ifreq) /* generic IF set op */
#define SIOCGIFGENERIC _IOWR('i', 58, struct ifreq) /* generic IF get op */
#define SIOCGIFSTATUS _IOWR('i', 59, struct ifstat) /* get IF status */
#endif /* !_SYS_SOCKIO_H_ */