summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorStuart Henderson <sthen@cvs.openbsd.org>2018-05-30 18:15:48 +0000
committerStuart Henderson <sthen@cvs.openbsd.org>2018-05-30 18:15:48 +0000
commitf6a03861dd0e165a998e18dbb3f83064e61f4cd6 (patch)
tree1b3e4762ec7c38abfe9270cd57083fb3c9bd6e68 /sys
parentf758e33efcca83330d5d96fde4881a14f7b6dff7 (diff)
Add SIOCGIFGLIST to fetch a list of interface groups on the system.
From Jan Klemkow, ok mpi@ tb@, ok/bugfix bluhm@
Diffstat (limited to 'sys')
-rw-r--r--sys/net/if.c44
-rw-r--r--sys/sys/sockio.h3
2 files changed, 45 insertions, 2 deletions
diff --git a/sys/net/if.c b/sys/net/if.c
index 0944ba05f16..53eba3f281c 100644
--- a/sys/net/if.c
+++ b/sys/net/if.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if.c,v 1.552 2018/05/17 11:04:14 tb Exp $ */
+/* $OpenBSD: if.c,v 1.553 2018/05/30 18:15:47 sthen Exp $ */
/* $NetBSD: if.c,v 1.35 1996/05/07 05:26:04 thorpej Exp $ */
/*
@@ -145,6 +145,7 @@ int if_getgroup(caddr_t, struct ifnet *);
int if_getgroupmembers(caddr_t);
int if_getgroupattribs(caddr_t);
int if_setgroupattribs(caddr_t);
+int if_getgrouplist(caddr_t);
void if_linkstate(struct ifnet *);
void if_linkstate_task(void *);
@@ -1851,6 +1852,7 @@ ifioctl(struct socket *so, u_long cmd, caddr_t data, struct proc *p)
case SIOCIFGCLONERS:
case SIOCGIFGMEMB:
case SIOCGIFGATTR:
+ case SIOCGIFGLIST:
case SIOCGIFFLAGS:
case SIOCGIFXFLAGS:
case SIOCGIFMETRIC:
@@ -2189,6 +2191,11 @@ ifioctl_get(u_long cmd, caddr_t data)
error = if_getgroupattribs(data);
NET_RUNLOCK();
return (error);
+ case SIOCGIFGLIST:
+ NET_RLOCK();
+ error = if_getgrouplist(data);
+ NET_RUNLOCK();
+ return (error);
}
ifp = ifunit(ifr->ifr_name);
@@ -2624,6 +2631,41 @@ if_setgroupattribs(caddr_t data)
return (0);
}
+/*
+ * Stores all groups in memory pointed to by data
+ */
+int
+if_getgrouplist(caddr_t data)
+{
+ struct ifgroupreq *ifgr = (struct ifgroupreq *)data;
+ struct ifg_group *ifg;
+ struct ifg_req ifgrq, *ifgp;
+ int len, error;
+
+ if (ifgr->ifgr_len == 0) {
+ TAILQ_FOREACH(ifg, &ifg_head, ifg_next)
+ ifgr->ifgr_len += sizeof(ifgrq);
+ return (0);
+ }
+
+ len = ifgr->ifgr_len;
+ ifgp = ifgr->ifgr_groups;
+ TAILQ_FOREACH(ifg, &ifg_head, ifg_next) {
+ if (len < sizeof(ifgrq))
+ return (EINVAL);
+ bzero(&ifgrq, sizeof ifgrq);
+ strlcpy(ifgrq.ifgrq_group, ifg->ifg_group,
+ sizeof(ifgrq.ifgrq_group));
+ 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/sys/sockio.h b/sys/sys/sockio.h
index b0ec48ae57c..207aceaccdf 100644
--- a/sys/sys/sockio.h
+++ b/sys/sys/sockio.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: sockio.h,v 1.75 2018/02/20 03:43:07 dlg Exp $ */
+/* $OpenBSD: sockio.h,v 1.76 2018/05/30 18:15:47 sthen Exp $ */
/* $NetBSD: sockio.h,v 1.5 1995/08/23 00:40:47 thorpej Exp $ */
/*-
@@ -129,6 +129,7 @@
#define SIOCGIFGMEMB _IOWR('i', 138, struct ifgroupreq) /* get members */
#define SIOCGIFGATTR _IOWR('i', 139, struct ifgroupreq) /* get ifgroup attribs */
#define SIOCSIFGATTR _IOW('i', 140, struct ifgroupreq) /* set ifgroup attribs */
+#define SIOCGIFGLIST _IOWR('i', 141, struct ifgroupreq) /* get ifgroup list */
#define SIOCSIFDESCR _IOW('i', 128, struct ifreq) /* set ifnet descr */
#define SIOCGIFDESCR _IOWR('i', 129, struct ifreq) /* get ifnet descr */