summaryrefslogtreecommitdiff
path: root/sbin
diff options
context:
space:
mode:
authorMarkus Friedl <markus@cvs.openbsd.org>2003-12-03 13:28:37 +0000
committerMarkus Friedl <markus@cvs.openbsd.org>2003-12-03 13:28:37 +0000
commitee094fb2268b4ec5b4578e092ebe3ee2e45edcf1 (patch)
treed3f59fb0f52617ee5e76ea2b9ba787611a2c8b0a /sbin
parent2e49ee4565faccd70bff97b38a2bd521089f6d62 (diff)
add support for ifconfig clone; from netbsd; ok deraadt, henning
Diffstat (limited to 'sbin')
-rw-r--r--sbin/ifconfig/ifconfig.812
-rw-r--r--sbin/ifconfig/ifconfig.c52
2 files changed, 60 insertions, 4 deletions
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);
}