Add a SIOCGIFCLONERS ioctl, which fetches a list of network
interface cloners from the kernel.
This commit is contained in:
parent
2ebdfcd251
commit
9c881e00cb
44
sys/net/if.c
44
sys/net/if.c
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: if.c,v 1.66 2000/07/19 06:00:39 onoe Exp $ */
|
||||
/* $NetBSD: if.c,v 1.67 2000/07/20 18:40:27 thorpej Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1999, 2000 The NetBSD Foundation, Inc.
|
||||
|
@ -150,8 +150,10 @@ extern void nd6_setmtu __P((struct ifnet *));
|
|||
int if_rt_walktree __P((struct radix_node *, void *));
|
||||
|
||||
struct if_clone *if_clone_lookup __P((const char *, int *));
|
||||
int if_clone_list __P((struct if_clonereq *));
|
||||
|
||||
LIST_HEAD(, if_clone) if_cloners = LIST_HEAD_INITIALIZER(if_cloners);
|
||||
int if_cloners_count;
|
||||
|
||||
/*
|
||||
* Network interface utility routines.
|
||||
|
@ -578,6 +580,7 @@ if_clone_attach(ifc)
|
|||
{
|
||||
|
||||
LIST_INSERT_HEAD(&if_cloners, ifc, ifc_list);
|
||||
if_cloners_count++;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -589,6 +592,42 @@ if_clone_detach(ifc)
|
|||
{
|
||||
|
||||
LIST_REMOVE(ifc, ifc_list);
|
||||
if_cloners_count--;
|
||||
}
|
||||
|
||||
/*
|
||||
* Provide list of interface cloners to userspace.
|
||||
*/
|
||||
int
|
||||
if_clone_list(ifcr)
|
||||
struct if_clonereq *ifcr;
|
||||
{
|
||||
char outbuf[IFNAMSIZ], *dst;
|
||||
struct if_clone *ifc;
|
||||
int count, error = 0;
|
||||
|
||||
ifcr->ifcr_total = if_cloners_count;
|
||||
if ((dst = ifcr->ifcr_buffer) == NULL) {
|
||||
/* Just asking how many there are. */
|
||||
return (0);
|
||||
}
|
||||
|
||||
if (ifcr->ifcr_count < 0)
|
||||
return (EINVAL);
|
||||
|
||||
count = (if_cloners_count < ifcr->ifcr_count) ?
|
||||
if_cloners_count : ifcr->ifcr_count;
|
||||
|
||||
for (ifc = LIST_FIRST(&if_cloners); ifc != NULL && count != 0;
|
||||
ifc = LIST_NEXT(ifc, ifc_list), count--, dst += IFNAMSIZ) {
|
||||
strncpy(outbuf, ifc->ifc_name, IFNAMSIZ);
|
||||
outbuf[IFNAMSIZ - 1] = '\0'; /* sanity */
|
||||
error = copyout(outbuf, dst, IFNAMSIZ);
|
||||
if (error)
|
||||
break;
|
||||
}
|
||||
|
||||
return (error);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1032,6 +1071,9 @@ ifioctl(so, cmd, data, p)
|
|||
return ((cmd == SIOCIFCREATE) ?
|
||||
if_clone_create(ifr->ifr_name) :
|
||||
if_clone_destroy(ifr->ifr_name));
|
||||
|
||||
case SIOCIFGCLONERS:
|
||||
return (if_clone_list((struct if_clonereq *)data));
|
||||
}
|
||||
|
||||
ifp = ifunit(ifr->ifr_name);
|
||||
|
|
25
sys/net/if.h
25
sys/net/if.h
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: if.h,v 1.52 2000/07/04 19:09:17 thorpej Exp $ */
|
||||
/* $NetBSD: if.h,v 1.53 2000/07/20 18:40:27 thorpej Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1999, 2000 The NetBSD Foundation, Inc.
|
||||
|
@ -116,6 +116,13 @@ struct socket;
|
|||
struct ether_header;
|
||||
struct ifnet;
|
||||
|
||||
/*
|
||||
* Length of interface external name, including terminating '\0'.
|
||||
* Note: this is the same size as a generic device's external name.
|
||||
*/
|
||||
#define IFNAMSIZ 16
|
||||
#define IF_NAMESIZE IFNAMSIZ
|
||||
|
||||
/*
|
||||
* Structure describing a `cloning' interface.
|
||||
*/
|
||||
|
@ -131,6 +138,15 @@ struct if_clone {
|
|||
#define IF_CLONE_INITIALIZER(name, create, destroy) \
|
||||
{ { 0 }, name, sizeof(name) - 1, create, destroy }
|
||||
|
||||
/*
|
||||
* Structure used to query names of interface cloners.
|
||||
*/
|
||||
struct if_clonereq {
|
||||
int ifcr_total; /* total cloners (out) */
|
||||
int ifcr_count; /* room for this many in user buffer */
|
||||
char *ifcr_buffer; /* buffer for cloner names */
|
||||
};
|
||||
|
||||
/*
|
||||
* Structure defining statistics and other data kept regarding a network
|
||||
* interface.
|
||||
|
@ -199,13 +215,6 @@ struct if_data14 {
|
|||
*/
|
||||
TAILQ_HEAD(ifnet_head, ifnet); /* the actual queue head */
|
||||
|
||||
/*
|
||||
* Length of interface external name, including terminating '\0'.
|
||||
* Note: this is the same size as a generic device's external name.
|
||||
*/
|
||||
#define IFNAMSIZ 16
|
||||
#define IF_NAMESIZE IFNAMSIZ
|
||||
|
||||
struct ifnet { /* and the entries */
|
||||
void *if_softc; /* lower-level data for this if */
|
||||
TAILQ_ENTRY(ifnet) if_list; /* all struct ifnets are chained */
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: sockio.h,v 1.12 2000/07/02 00:20:49 thorpej Exp $ */
|
||||
/* $NetBSD: sockio.h,v 1.13 2000/07/20 18:40:26 thorpej Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1982, 1986, 1990, 1993, 1994
|
||||
|
@ -101,5 +101,6 @@
|
|||
parameters */
|
||||
#define SIOCIFCREATE _IOW('i', 122, struct ifreq) /* create clone if */
|
||||
#define SIOCIFDESTROY _IOW('i', 121, struct ifreq) /* destroy clone if */
|
||||
#define SIOCIFGCLONERS _IOWR('i', 120, struct if_clonereq) /* get cloners */
|
||||
|
||||
#endif /* !_SYS_SOCKIO_H_ */
|
||||
|
|
Loading…
Reference in New Issue