summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormarkus <markus@openbsd.org>2003-12-03 13:28:36 +0000
committermarkus <markus@openbsd.org>2003-12-03 13:28:36 +0000
commite087dc571428a5593683920ca7950e680f5ee185 (patch)
tree3c034148be6cded6e68e1bd7794d91e505431ae5
parentsupport for network interface "cloning", e.g. gif(4) via ifconfig(8) (diff)
downloadwireguard-openbsd-e087dc571428a5593683920ca7950e680f5ee185.tar.xz
wireguard-openbsd-e087dc571428a5593683920ca7950e680f5ee185.zip
add support for ifconfig clone; from netbsd; ok deraadt, henning
-rw-r--r--etc/netstart8
-rw-r--r--sbin/ifconfig/ifconfig.812
-rw-r--r--sbin/ifconfig/ifconfig.c52
3 files changed, 66 insertions, 6 deletions
diff --git a/etc/netstart b/etc/netstart
index 8780589b61f..c1a6c2ae172 100644
--- a/etc/netstart
+++ b/etc/netstart
@@ -1,6 +1,6 @@
#!/bin/sh -
#
-# $OpenBSD: netstart,v 1.88 2003/10/20 17:53:32 david Exp $
+# $OpenBSD: netstart,v 1.89 2003/12/03 13:28:36 markus Exp $
# Returns true if $1 contains only alphanumerics
isalphanumeric() {
@@ -27,7 +27,11 @@ ifstart() {
ifconfig $if > /dev/null 2>&1
if [ "$?" != "0" ]; then
- return
+ # Try to create interface if it does not exist
+ ifconfig $if create > /dev/null 2>&1
+ if [ "$?" != "0" ]; then
+ return
+ fi
fi
# Now parse the hostname.* file
diff --git a/sbin/ifconfig/ifconfig.8 b/sbin/ifconfig/ifconfig.8
index cc797197041..c1a65834531 100644
--- a/sbin/ifconfig/ifconfig.8
+++ b/sbin/ifconfig/ifconfig.8
@@ -1,4 +1,4 @@
-.\" $OpenBSD: ifconfig.8,v 1.71 2003/10/26 07:10:54 mcbride Exp $
+.\" $OpenBSD: ifconfig.8,v 1.72 2003/12/03 13:28:36 markus Exp $
.\" $NetBSD: ifconfig.8,v 1.11 1996/01/04 21:27:29 pk Exp $
.\" $FreeBSD: ifconfig.8,v 1.16 1998/02/01 07:03:29 steve Exp $
.\"
@@ -215,6 +215,10 @@ Both addresses must be of the same family.
.It Cm deletetunnel
Removes the source and destination tunnel addresses,
configured onto a tunnel interface.
+.It Cm create
+Create the specified network pseudo-device.
+.It Cm destroy
+Destroy the specified network pseudo-device.
.It Cm ipdst
This is used to specify an Internet host who is willing to receive
ip packets encapsulating NS packets bound for a remote network.
@@ -599,6 +603,12 @@ and vlan parent device fxp0.
.Pp
.It Cm # ifconfig carp0 vhid 1 192.168.10.1
Configure the carp0 interface for IP address 192.168.10.1, virtual host ID 1.
+.Pp
+.It Cm # ifconfig gif1 create
+Create the gif1 network interface.
+.Pp
+.It Cm # ifconfig gif1 destroy
+Destroy the gif1 network interface.
.El
.Sh DIAGNOSTICS
Messages indicating the specified interface does not exist, the
diff --git a/sbin/ifconfig/ifconfig.c b/sbin/ifconfig/ifconfig.c
index 6c0c1568974..50f332046c0 100644
--- a/sbin/ifconfig/ifconfig.c
+++ b/sbin/ifconfig/ifconfig.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ifconfig.c,v 1.83 2003/11/09 06:04:17 mcbride Exp $ */
+/* $OpenBSD: ifconfig.c,v 1.84 2003/12/03 13:28:36 markus Exp $ */
/* $NetBSD: ifconfig.c,v 1.40 1997/10/01 02:19:43 enami Exp $ */
/*
@@ -77,7 +77,7 @@ static const char copyright[] =
#if 0
static const char sccsid[] = "@(#)ifconfig.c 8.2 (Berkeley) 2/16/94";
#else
-static const char rcsid[] = "$OpenBSD: ifconfig.c,v 1.83 2003/11/09 06:04:17 mcbride Exp $";
+static const char rcsid[] = "$OpenBSD: ifconfig.c,v 1.84 2003/12/03 13:28:36 markus Exp $";
#endif
#endif /* not lint */
@@ -192,6 +192,8 @@ void setia6eui64(const char *, int);
void checkatrange(struct sockaddr_at *);
void setmedia(const char *, int);
void setmediaopt(const char *, int);
+void clone_create(const char *, int);
+void clone_destroy(const char *, int);
void unsetmediaopt(const char *, int);
void setmediainst(const char *, int);
void setvlantag(const char *, int);
@@ -295,6 +297,11 @@ const struct cmd {
{ "giftunnel", NEXTARG2, 0, NULL, settunnel } ,
{ "tunnel", NEXTARG2, 0, NULL, settunnel } ,
{ "deletetunnel", 0, 0, deletetunnel } ,
+#if 0
+ /* XXX `create' special-cased below */
+ { "create", 0, 0, clone_create } ,
+#endif
+ { "destroy", 0, 0, clone_destroy } ,
{ "link0", IFF_LINK0, 0, setifflags } ,
{ "-link0", -IFF_LINK0, 0, setifflags } ,
{ "link1", IFF_LINK1, 0, setifflags } ,
@@ -448,6 +455,16 @@ main(int argc, char *argv[])
in6_addreq.ifra_lifetime.ia6t_pltime = ND6_INFINITE_LIFETIME;
in6_addreq.ifra_lifetime.ia6t_vltime = ND6_INFINITE_LIFETIME;
#endif
+ /*
+ * NOTE: We must special-case the `create' command right
+ * here as we would otherwise fail in getinfo().
+ */
+ if (argc > 0 && strcmp(argv[0], "create") == 0) {
+ clone_create(argv[0], 0);
+ argc--, argv++;
+ if (argc == 0)
+ exit(0);
+ }
if (getinfo(&ifr) < 0)
exit(1);
@@ -756,6 +773,33 @@ printif(struct ifreq *ifrm, int ifaliases)
#endif
}
+/*ARGSUSED*/
+void
+clone_create(addr, param)
+ const char *addr;
+ int param;
+{
+
+ /* We're called early... */
+ getsock(AF_INET);
+
+ (void) strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
+ if (ioctl(s, SIOCIFCREATE, &ifr) == -1)
+ err(1, "SIOCIFCREATE");
+}
+
+/*ARGSUSED*/
+void
+clone_destroy(addr, param)
+ const char *addr;
+ int param;
+{
+
+ (void) strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
+ if (ioctl(s, SIOCIFDESTROY, &ifr) == -1)
+ err(1, "SIOCIFDESTROY");
+}
+
#define RIDADDR 0
#define ADDR 1
#define MASK 2
@@ -2501,7 +2545,9 @@ usage(void)
"\t[ -802.2 | -802.3 | -802.2tr | -snap | -EtherII ]\n"
"\t[ link0 | -link0 ] [ link1 | -link1 ] [ link2 | -link2 ]\n"
" ifconfig [-a | -A | -am | -Am] [ af ]\n"
- " ifconfig -m interface [af]\n");
+ " ifconfig -m interface [af]\n"
+ " ifconfig interface create\n"
+ " ifconfig interface destroy\n");
exit(1);
}