summaryrefslogtreecommitdiffstats
path: root/sbin/ifconfig
diff options
context:
space:
mode:
authorwpaul <wpaul@FreeBSD.org>1999-03-15 01:22:01 +0000
committerwpaul <wpaul@FreeBSD.org>1999-03-15 01:22:01 +0000
commita1b49dc15234a4ca3eddd3dbaac7e6d80043d7a2 (patch)
treede4c7718db9bff5c4c1c6635b83317b350228286 /sbin/ifconfig
parent4d1fbb5a8a943b33b0b23a9117eaf12e5fa71f90 (diff)
downloadFreeBSD-src-a1b49dc15234a4ca3eddd3dbaac7e6d80043d7a2.zip
FreeBSD-src-a1b49dc15234a4ca3eddd3dbaac7e6d80043d7a2.tar.gz
Grrr... botched remote commit. Let's try this again: vlan updates,
take two.
Diffstat (limited to 'sbin/ifconfig')
-rw-r--r--sbin/ifconfig/Makefile8
-rw-r--r--sbin/ifconfig/ifconfig.845
-rw-r--r--sbin/ifconfig/ifconfig.c41
-rw-r--r--sbin/ifconfig/ifconfig.h7
-rw-r--r--sbin/ifconfig/ifvlan.c156
5 files changed, 246 insertions, 11 deletions
diff --git a/sbin/ifconfig/Makefile b/sbin/ifconfig/Makefile
index 0ff6ea0..ae1760f 100644
--- a/sbin/ifconfig/Makefile
+++ b/sbin/ifconfig/Makefile
@@ -1,5 +1,5 @@
# From: @(#)Makefile 8.1 (Berkeley) 6/5/93
-# $Id: Makefile,v 1.9 1997/02/22 14:32:32 peter Exp $
+# $Id: Makefile,v 1.10 1997/05/04 06:27:45 peter Exp $
PROG= ifconfig
SRCS= ifconfig.c
@@ -8,10 +8,14 @@ SRCS= ifconfig.c
SRCS+= ifmedia.c
CFLAGS+=-DUSE_IF_MEDIA
+#comment out to exclude SIOC[GS]ETVLAN support
+SRCS+= ifvlan.c
+CFLAGS+=-DUSE_VLANS
+
MAN8= ifconfig.8
DPADD= ${LIBIPX}
LDADD= -lipx
COPTS= -DNS -Wall -Wmissing-prototypes -Wcast-qual -Wwrite-strings \
- -Wnested-externs
+ -Wnested-externs -I..
.include <bsd.prog.mk>
diff --git a/sbin/ifconfig/ifconfig.8 b/sbin/ifconfig/ifconfig.8
index 44bb3d6..b797e1f 100644
--- a/sbin/ifconfig/ifconfig.8
+++ b/sbin/ifconfig/ifconfig.8
@@ -30,7 +30,7 @@
.\" SUCH DAMAGE.
.\"
.\" From: @(#)ifconfig.8 8.3 (Berkeley) 1/5/94
-.\" $Id: ifconfig.8,v 1.17 1998/06/08 02:00:45 danny Exp $
+.\" $Id: ifconfig.8,v 1.18 1998/07/06 06:53:42 charnier Exp $
.\"
.Dd February 13, 1996
.Dt IFCONFIG 8
@@ -200,6 +200,49 @@ list of available options.
.It Fl mediaopt Ar opts
If the driver supports the media selection system, disable the
specified media options on the interface.
+.It Cm vlan Ar vlan_tag
+If the interface is a vlan pseudo interface, set the vlan tag value
+to
+.Ar vlan_tag .
+This value is a 16-bit number which is used to create an 802.1Q
+vlan header for packets sent from the vlan interface. Note that
+.Cm vlan
+and
+.Cm vlandev
+must both be set at the same time.
+.It Cm vlandev Ar iface
+If the interface is a vlan pseudo device, associate physical interface
+.Ar iface
+with it. Packets transmitted through the vlan interface will be
+diverted to the specified physical interface
+.Ar iface
+with 802.1Q vlan encapsulation. Packets with 802.1Q encapsulation received
+by the parent interface with the correct vlan tag will be diverted to
+the associated vlan pseudo-interface. The vlan interface is assigned a
+copy of the parent interface's flags and the parent's ethernet address.
+The
+.Cm vlandev
+and
+.Cm vlan
+must both be set at the same time. If the vlan interface already has
+a physical interface associated with it, this command will fail. To
+change the association to another physical interface, the existing
+association must be cleared first.
+.Pp
+Note: if the
+.Ar link0
+flag is set on the vlan interface, the vlan pseudo
+interface's behavior changes: the
+.Ar link0
+tells the vlan interface that the
+parent interface supports insertion and extraction of vlan tags on its
+own (usually in firmware) and that it should pass packets to and from
+the parent unaltered.
+.It Fl vlandev Ar iface
+If the driver is a vlan pseudo device, disassociate the physical interface
+.Ar iface
+from it. This breaks the link between the vlan interface and its parent,
+clears its vlan tag, flags and its link address and shuts the interface down.
.It Cm metric Ar n
Set the routing metric of the interface to
.Ar n ,
diff --git a/sbin/ifconfig/ifconfig.c b/sbin/ifconfig/ifconfig.c
index 68eee80..74dfa01 100644
--- a/sbin/ifconfig/ifconfig.c
+++ b/sbin/ifconfig/ifconfig.c
@@ -42,7 +42,7 @@ static const char copyright[] =
static char sccsid[] = "@(#)ifconfig.c 8.2 (Berkeley) 2/16/94";
#endif
static const char rcsid[] =
- "$Id: ifconfig.c,v 1.37 1998/07/06 19:54:39 bde Exp $";
+ "$Id: ifconfig.c,v 1.38 1998/08/07 06:36:53 phk Exp $";
#endif /* not lint */
#include <sys/param.h>
@@ -166,6 +166,11 @@ struct cmd {
{ "mediaopt", NEXTARG, setmediaopt },
{ "-mediaopt", NEXTARG, unsetmediaopt },
#endif
+#ifdef USE_VLANS
+ { "vlan", NEXTARG, setvlantag },
+ { "vlandev", NEXTARG, setvlandev },
+ { "-vlandev", NEXTARG, unsetvlandev },
+#endif
{ "normal", -IFF_LINK0, setifflags },
{ "compress", IFF_LINK0, setifflags },
{ "noicmp", IFF_LINK1, setifflags },
@@ -217,6 +222,9 @@ struct afswtch {
#ifdef USE_IF_MEDIA
{ "media", AF_INET, media_status, NULL }, /* XXX not real!! */
#endif
+#ifdef USE_VLANS
+ { "vlan", AF_INET, media_status, NULL }, /* XXX not real!! */
+#endif
#endif
{ 0, 0, 0, 0 }
};
@@ -632,6 +640,11 @@ setifdstaddr(addr, param, s, afp)
(*afp->af_getaddr)(addr, DSTADDR);
}
+/*
+ * Note: doing an SIOCIGIFFLAGS scribbles on the union portion
+ * of the ifreq structure, which may confuse other parts of ifconfig.
+ * Make a private copy so we can avoid that.
+ */
void
setifflags(vname, value, s, afp)
const char *vname;
@@ -639,20 +652,24 @@ setifflags(vname, value, s, afp)
int s;
const struct afswtch *afp;
{
- if (ioctl(s, SIOCGIFFLAGS, (caddr_t)&ifr) < 0) {
+ struct ifreq my_ifr;
+
+ bcopy((char *)&ifr, (char *)&my_ifr, sizeof(struct ifreq));
+
+ if (ioctl(s, SIOCGIFFLAGS, (caddr_t)&my_ifr) < 0) {
Perror("ioctl (SIOCGIFFLAGS)");
exit(1);
}
- strncpy(ifr.ifr_name, name, sizeof (ifr.ifr_name));
- flags = ifr.ifr_flags;
+ strncpy(my_ifr.ifr_name, name, sizeof (my_ifr.ifr_name));
+ flags = my_ifr.ifr_flags;
if (value < 0) {
value = -value;
flags &= ~value;
} else
flags |= value;
- ifr.ifr_flags = flags;
- if (ioctl(s, SIOCSIFFLAGS, (caddr_t)&ifr) < 0)
+ my_ifr.ifr_flags = flags;
+ if (ioctl(s, SIOCSIFFLAGS, (caddr_t)&my_ifr) < 0)
Perror(vname);
}
@@ -753,6 +770,9 @@ status(afp, addrcount, sdl, ifm, ifam)
#ifdef USE_IF_MEDIA
afp->af_status != media_status &&
#endif
+#ifdef USE_VLANS
+ afp->af_status != vlan_status &&
+#endif
afp->af_status != ether_status) {
p = afp;
(*p->af_status)(s, &info);
@@ -762,6 +782,9 @@ status(afp, addrcount, sdl, ifm, ifam)
#ifdef USE_IF_MEDIA
p->af_status != media_status &&
#endif
+#ifdef USE_VLANS
+ p->af_status != vlan_status &&
+#endif
p->af_status != ether_status)
(*p->af_status)(s, &info);
}
@@ -774,8 +797,12 @@ status(afp, addrcount, sdl, ifm, ifam)
if (allfamilies || afp->af_status == media_status)
media_status(s, NULL);
#endif
+#ifdef USE_VLANS
+ if (allfamilies || afp->af_status == vlan_status)
+ vlan_status(s, NULL);
+#endif
if (!allfamilies && !p && afp->af_status != media_status &&
- afp->af_status != ether_status)
+ afp->af_status != ether_status && afp->af_status != vlan_status)
warnx("%s has no %s interface address!", name, afp->af_name);
close(s);
diff --git a/sbin/ifconfig/ifconfig.h b/sbin/ifconfig/ifconfig.h
index 85555e3..e2df8f5 100644
--- a/sbin/ifconfig/ifconfig.h
+++ b/sbin/ifconfig/ifconfig.h
@@ -31,7 +31,7 @@
*
* so there!
*
- * $Id: ifconfig.h,v 1.2 1997/05/10 14:47:35 peter Exp $
+ * $Id: ifconfig.h,v 1.3 1997/05/10 17:14:53 peter Exp $
*/
extern struct ifreq ifr;
@@ -44,3 +44,8 @@ extern void setmedia(const char *, int, int, const struct afswtch *rafp);
extern void setmediaopt(const char *, int, int, const struct afswtch *rafp);
extern void unsetmediaopt(const char *, int, int, const struct afswtch *rafp);
extern void media_status(int s, struct rt_addrinfo *);
+
+extern void setvlantag(const char *, int, int, const struct afswtch *rafp);
+extern void setvlandev(const char *, int, int, const struct afswtch *rafp);
+extern void unsetvlandev(const char *, int, int, const struct afswtch *rafp);
+extern void vlan_status(int s, struct rt_addrinfo *);
diff --git a/sbin/ifconfig/ifvlan.c b/sbin/ifconfig/ifvlan.c
new file mode 100644
index 0000000..27014e4
--- /dev/null
+++ b/sbin/ifconfig/ifvlan.c
@@ -0,0 +1,156 @@
+/*
+ * Copyright (c) 1999
+ * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Bill Paul.
+ * 4. Neither the name of the author nor the names of any co-contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $Id$
+ */
+
+#include <sys/param.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+#include <sys/sockio.h>
+#include <sys/mbuf.h>
+
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <net/ethernet.h>
+#include <net/if.h>
+#include <net/if_var.h>
+#include <net/if_vlan_var.h>
+#include <net/route.h>
+
+#include <ctype.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <err.h>
+#include <errno.h>
+
+#include "ifconfig.h"
+
+#ifndef lint
+static const char rcsid[] =
+ "$Id$";
+#endif
+static int __tag = 0;
+static int __have_tag = 0;
+
+void vlan_status(s, info)
+ int s;
+ struct rt_addrinfo *info __unused;
+{
+ struct vlanreq vreq;
+
+ bzero((char *)&vreq, sizeof(struct vlanreq));
+ ifr.ifr_data = (caddr_t)&vreq;
+
+ if (ioctl(s, SIOCGETVLAN, (caddr_t)&ifr) == -1)
+ return;
+
+ printf("\tvlan: %d parent interface: %s\n",
+ vreq.vlr_tag, vreq.vlr_parent[0] == '\0' ?
+ "<none>" : vreq.vlr_parent);
+
+ return;
+}
+
+void setvlantag(val, d, s, afp)
+ const char *val;
+ int d, s;
+ const struct afswtch *afp;
+{
+ u_int16_t tag;
+ struct vlanreq vreq;
+
+ __tag = tag = atoi(val);
+ __have_tag = 1;
+
+ bzero((char *)&vreq, sizeof(struct vlanreq));
+ ifr.ifr_data = (caddr_t)&vreq;
+
+ if (ioctl(s, SIOCGETVLAN, (caddr_t)&ifr) == -1)
+ err(1, "SIOCGETVLAN");
+
+ vreq.vlr_tag = tag;
+
+ if (ioctl(s, SIOCSETVLAN, (caddr_t)&ifr) == -1)
+ err(1, "SIOCSETVLAN");
+
+ return;
+}
+
+void setvlandev(val, d, s, afp)
+ const char *val;
+ int d, s;
+ const struct afswtch *afp;
+{
+ struct vlanreq vreq;
+
+ if (!__have_tag)
+ errx(1, "must specify both vlan tag and device");
+
+ bzero((char *)&vreq, sizeof(struct vlanreq));
+ ifr.ifr_data = (caddr_t)&vreq;
+
+ if (ioctl(s, SIOCGETVLAN, (caddr_t)&ifr) == -1)
+ err(1, "SIOCGETVLAN");
+
+ strncpy(vreq.vlr_parent, val, sizeof(vreq.vlr_parent));
+ vreq.vlr_tag = __tag;
+
+ if (ioctl(s, SIOCSETVLAN, (caddr_t)&ifr) == -1)
+ err(1, "SIOCSETVLAN");
+
+ return;
+}
+
+void unsetvlandev(val, d, s, afp)
+ const char *val;
+ int d, s;
+ const struct afswtch *afp;
+{
+ struct vlanreq vreq;
+
+ bzero((char *)&vreq, sizeof(struct vlanreq));
+ ifr.ifr_data = (caddr_t)&vreq;
+
+ if (ioctl(s, SIOCGETVLAN, (caddr_t)&ifr) == -1)
+ err(1, "SIOCGETVLAN");
+
+ bzero((char *)&vreq.vlr_parent, sizeof(vreq.vlr_parent));
+ vreq.vlr_tag = 0;
+
+ if (ioctl(s, SIOCSETVLAN, (caddr_t)&ifr) == -1)
+ err(1, "SIOCSETVLAN");
+
+ return;
+}
OpenPOWER on IntegriCloud