summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Gwynne <dlg@cvs.openbsd.org>2016-03-02 00:00:17 +0000
committerDavid Gwynne <dlg@cvs.openbsd.org>2016-03-02 00:00:17 +0000
commit6863931862625459ea6e1b97753cf81dc3f3da9f (patch)
tree16bf1cb803e6e14a8f2562d5b8a3eb2c8b60d53f
parent2237579a02b77be82339d6362b48fa36a02118e1 (diff)
provide generic ioctls for managing an interfaces parent
in the future this will subsume the individual vlandev, carpdev, pppoedev, foodev options for things like vlan, carp, pppoe, etc. inspired by vnetid ok mpi@ jmatthew@
-rw-r--r--sbin/ifconfig/ifconfig.c53
-rw-r--r--sys/net/if.c5
-rw-r--r--sys/net/if.h8
-rw-r--r--sys/sys/sockio.h6
4 files changed, 68 insertions, 4 deletions
diff --git a/sbin/ifconfig/ifconfig.c b/sbin/ifconfig/ifconfig.c
index e2e55aee124..d237a5d0b37 100644
--- a/sbin/ifconfig/ifconfig.c
+++ b/sbin/ifconfig/ifconfig.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ifconfig.c,v 1.315 2016/01/13 09:35:45 stsp Exp $ */
+/* $OpenBSD: ifconfig.c,v 1.316 2016/03/02 00:00:16 dlg Exp $ */
/* $NetBSD: ifconfig.c,v 1.40 1997/10/01 02:19:43 enami Exp $ */
/*
@@ -181,6 +181,9 @@ void settunnelinst(const char *, int);
void settunnelttl(const char *, int);
void setvnetid(const char *, int);
void delvnetid(const char *, int);
+void setifparent(const char *, int);
+void delifparent(const char *, int);
+void getifparent(void);
#ifdef INET6
void setia6flags(const char *, int);
void setia6pltime(const char *, int);
@@ -412,6 +415,8 @@ const struct cmd {
{ "tunnelttl", NEXTARG, 0, settunnelttl } ,
{ "vnetid", NEXTARG, 0, setvnetid },
{ "-vnetid", 0, 0, delvnetid },
+ { "parent", NEXTARG, 0, setifparent },
+ { "-parent", 1, 0, delifparent },
{ "pppoedev", NEXTARG, 0, setpppoe_dev },
{ "pppoesvc", NEXTARG, 0, setpppoe_svc },
{ "-pppoesvc", 1, 0, setpppoe_svc },
@@ -2938,6 +2943,7 @@ status(int link, struct sockaddr_dl *sdl, int ls)
printf("\tpatch: %s\n", ifname);
#endif
vlan_status();
+ getifparent();
#ifndef SMALL
carp_status();
pfsync_status();
@@ -3393,6 +3399,51 @@ delvnetid(const char *ignored, int alsoignored)
}
void
+setifparent(const char *id, int param)
+{
+ struct if_parent ifp;
+
+ if (strlcpy(ifp.ifp_name, name, sizeof(ifp.ifp_name)) >=
+ sizeof(ifp.ifp_name))
+ errx(1, "parent: name too long");
+
+ if (strlcpy(ifp.ifp_parent, id, sizeof(ifp.ifp_parent)) >=
+ sizeof(ifp.ifp_parent))
+ errx(1, "parent: parent too long");
+
+ if (ioctl(s, SIOCSIFPARENT, (caddr_t)&ifp) < 0)
+ warn("SIOCSIFPARENT");
+}
+
+/* ARGSUSED */
+void
+delifparent(const char *ignored, int alsoignored)
+{
+ if (ioctl(s, SIOCDIFPARENT, &ifr) < 0)
+ warn("SIOCDIFPARENT");
+}
+
+void
+getifparent(void)
+{
+ struct if_parent ifp;
+ const char *parent = "none";
+
+ memset(&ifp, 0, sizeof(ifp));
+ if (strlcpy(ifp.ifp_name, name, sizeof(ifp.ifp_name)) >=
+ sizeof(ifp.ifp_name))
+ errx(1, "parent: name too long");
+
+ if (ioctl(s, SIOCGIFPARENT, (caddr_t)&ifp) == -1) {
+ if (errno != EADDRNOTAVAIL)
+ return;
+ } else
+ parent = ifp.ifp_parent;
+
+ printf("\tparent: %s\n", parent);
+}
+
+void
mpe_status(void)
{
struct shim_hdr shim;
diff --git a/sys/net/if.c b/sys/net/if.c
index 5c9d1773d4a..0823badc37f 100644
--- a/sys/net/if.c
+++ b/sys/net/if.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if.c,v 1.426 2016/02/28 15:46:19 naddy Exp $ */
+/* $OpenBSD: if.c,v 1.427 2016/03/02 00:00:16 dlg Exp $ */
/* $NetBSD: if.c,v 1.35 1996/05/07 05:26:04 thorpej Exp $ */
/*
@@ -1754,6 +1754,8 @@ ifioctl(struct socket *so, u_long cmd, caddr_t data, struct proc *p)
case SIOCSIFMEDIA:
case SIOCSVNETID:
case SIOCSIFPAIR:
+ case SIOCSIFPARENT:
+ case SIOCDIFPARENT:
if ((error = suser(p, 0)) != 0)
return (error);
/* FALLTHROUGH */
@@ -1765,6 +1767,7 @@ ifioctl(struct socket *so, u_long cmd, caddr_t data, struct proc *p)
case SIOCGIFMEDIA:
case SIOCGVNETID:
case SIOCGIFPAIR:
+ case SIOCGIFPARENT:
if (ifp->if_ioctl == 0)
return (EOPNOTSUPP);
error = (*ifp->if_ioctl)(ifp, cmd, data);
diff --git a/sys/net/if.h b/sys/net/if.h
index 8d7e3906e69..3d3569d960e 100644
--- a/sys/net/if.h
+++ b/sys/net/if.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: if.h,v 1.175 2015/12/05 19:04:37 deraadt Exp $ */
+/* $OpenBSD: if.h,v 1.176 2016/03/02 00:00:16 dlg Exp $ */
/* $NetBSD: if.h,v 1.23 1996/05/07 02:40:27 thorpej Exp $ */
/*
@@ -444,6 +444,12 @@ struct if_afreq {
sa_family_t ifar_af;
};
+/* SIOC[SG]IFPARENT */
+struct if_parent {
+ char ifp_name[IFNAMSIZ];
+ char ifp_parent[IFNAMSIZ];
+};
+
#include <net/if_arp.h>
#ifdef _KERNEL
diff --git a/sys/sys/sockio.h b/sys/sys/sockio.h
index 1e9739c9418..cd7f83ad491 100644
--- a/sys/sys/sockio.h
+++ b/sys/sys/sockio.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: sockio.h,v 1.62 2015/10/24 10:52:05 reyk Exp $ */
+/* $OpenBSD: sockio.h,v 1.63 2016/03/02 00:00:16 dlg Exp $ */
/* $NetBSD: sockio.h,v 1.5 1995/08/23 00:40:47 thorpej Exp $ */
/*-
@@ -199,6 +199,10 @@
#define SIOCSIFPAIR _IOW('i', 176, struct ifreq) /* set paired if */
#define SIOCGIFPAIR _IOWR('i', 177, struct ifreq) /* get paired if */
+#define SIOCSIFPARENT _IOW('i', 178, struct if_parent) /* set parent if */
+#define SIOCGIFPARENT _IOWR('i', 179, struct if_parent) /* get parent if */
+#define SIOCDIFPARENT _IOW('i', 180, struct ifreq) /* del parent if */
+
#define SIOCSVH _IOWR('i', 245, struct ifreq) /* set carp param */
#define SIOCGVH _IOWR('i', 246, struct ifreq) /* get carp param */