summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorHenning Brauer <henning@cvs.openbsd.org>2005-06-12 00:41:34 +0000
committerHenning Brauer <henning@cvs.openbsd.org>2005-06-12 00:41:34 +0000
commit74b3a519f7c73314c1514d9fbf22c8dd6cebad8d (patch)
tree093348e3d0fe5db40e36630ddea59444f4c8fd7f /sys
parentaf0efa7ccb2bbf2231a0630eb91facc24e5d4f96 (diff)
add SIOCGIFGMEMB ioctl, returns a list of all interfaces who are member of
the given group, markus ok
Diffstat (limited to 'sys')
-rw-r--r--sys/net/if.c48
-rw-r--r--sys/net/if.h10
-rw-r--r--sys/sys/sockio.h3
3 files changed, 56 insertions, 5 deletions
diff --git a/sys/net/if.c b/sys/net/if.c
index 8cc996aa18f..36ccbee3ecd 100644
--- a/sys/net/if.c
+++ b/sys/net/if.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if.c,v 1.132 2005/06/08 07:36:50 henning Exp $ */
+/* $OpenBSD: if.c,v 1.133 2005/06/12 00:41:33 henning Exp $ */
/* $NetBSD: if.c,v 1.35 1996/05/07 05:26:04 thorpej Exp $ */
/*
@@ -136,6 +136,9 @@ int if_detached_ioctl(struct ifnet *, u_long, caddr_t);
int if_detached_init(struct ifnet *);
void if_detached_watchdog(struct ifnet *);
+int if_getgroup(caddr_t, struct ifnet *);
+int if_getgroupmembers(caddr_t);
+
int if_clone_list(struct if_clonereq *);
struct if_clone *if_clone_lookup(const char *, int *);
@@ -1194,6 +1197,8 @@ ifioctl(struct socket *so, u_long cmd, caddr_t data, struct proc *p)
if_clone_destroy(ifr->ifr_name));
case SIOCIFGCLONERS:
return (if_clone_list((struct if_clonereq *)data));
+ case SIOCGIFGMEMB:
+ return (if_getgroupmembers(data));
}
ifp = ifunit(ifr->ifr_name);
@@ -1715,6 +1720,47 @@ if_getgroup(caddr_t data, struct ifnet *ifp)
return (0);
}
+/*
+ * Stores all members of a group in memory pointed to by data
+ */
+int
+if_getgroupmembers(caddr_t data)
+{
+ struct ifgroupreq *ifgr = (struct ifgroupreq *)data;
+ struct ifg_group *ifg;
+ struct ifg_member *ifgm;
+ struct ifg_req ifgrq, *ifgp;
+ int len, error;
+
+ TAILQ_FOREACH(ifg, &ifg_head, ifg_next)
+ if (!strcmp(ifg->ifg_group, ifgr->ifgr_name))
+ break;
+ if (ifg == NULL)
+ return (ENOENT);
+
+ if (ifgr->ifgr_len == 0) {
+ TAILQ_FOREACH(ifgm, &ifg->ifg_members, ifgm_next)
+ ifgr->ifgr_len += sizeof(ifgrq);
+ return (0);
+ }
+
+ len = ifgr->ifgr_len;
+ ifgp = ifgr->ifgr_groups;
+ TAILQ_FOREACH(ifgm, &ifg->ifg_members, ifgm_next) {
+ if (len < sizeof(ifgrq))
+ return (EINVAL);
+ strlcpy(ifgrq.ifgrq_member, ifgm->ifgm_ifp->if_xname,
+ sizeof(ifgrq.ifgrq_member));
+ if ((error = copyout((caddr_t)&ifgrq, (caddr_t)ifgp,
+ sizeof(struct ifg_req))))
+ return (error);
+ len -= sizeof(ifgrq);
+ ifgp++;
+ }
+
+ return (0);
+}
+
void
if_group_routechange(struct sockaddr *dst, struct sockaddr *mask)
{
diff --git a/sys/net/if.h b/sys/net/if.h
index 97207738034..510173c05d0 100644
--- a/sys/net/if.h
+++ b/sys/net/if.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: if.h,v 1.73 2005/06/07 18:21:44 henning Exp $ */
+/* $OpenBSD: if.h,v 1.74 2005/06/12 00:41:33 henning Exp $ */
/* $NetBSD: if.h,v 1.23 1996/05/07 02:40:27 thorpej Exp $ */
/*
@@ -447,7 +447,12 @@ struct ifg_list {
};
struct ifg_req {
- char ifgrq_group[IFNAMSIZ];
+ union {
+ char ifgrqu_group[IFNAMSIZ];
+ char ifgrqu_member[IFNAMSIZ];
+ } ifgrq_ifgrqu;
+#define ifgrq_group ifgrq_ifgrqu.ifgrqu_group
+#define ifgrq_member ifgrq_ifgrqu.ifgrqu_member
};
/*
@@ -690,7 +695,6 @@ int ifioctl(struct socket *, u_long, caddr_t, struct proc *);
int ifpromisc(struct ifnet *, int);
int if_addgroup(struct ifnet *, const char *);
int if_delgroup(struct ifnet *, const char *);
-int if_getgroup(caddr_t, struct ifnet *);
void if_group_routechange(struct sockaddr *, struct sockaddr *);
struct ifnet *ifunit(const char *);
diff --git a/sys/sys/sockio.h b/sys/sys/sockio.h
index 2c584f487f8..de5f35ba620 100644
--- a/sys/sys/sockio.h
+++ b/sys/sys/sockio.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: sockio.h,v 1.34 2005/05/26 22:37:35 henning Exp $ */
+/* $OpenBSD: sockio.h,v 1.35 2005/06/12 00:41:33 henning Exp $ */
/* $NetBSD: sockio.h,v 1.5 1995/08/23 00:40:47 thorpej Exp $ */
/*-
@@ -144,6 +144,7 @@
#define SIOCAIFGROUP _IOW('i', 135, struct ifgroupreq) /* add an ifgroup */
#define SIOCGIFGROUP _IOWR('i', 136, struct ifgroupreq) /* get ifgroups */
#define SIOCDIFGROUP _IOW('i', 137, struct ifgroupreq) /* delete ifgroup */
+#define SIOCGIFGMEMB _IOWR('i', 138, struct ifgroupreq) /* get members */
#define SIOCSIFDESCR _IOW('i', 128, struct ifreq) /* set ifnet descr */
#define SIOCGIFDESCR _IOWR('i', 129, struct ifreq) /* get ifnet descr */