Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sbin/ifconfig Split VLAN configuration bits out into a separ...
details: https://anonhg.NetBSD.org/src/rev/5fe4708156d7
branches: trunk
changeset: 579598:5fe4708156d7
user: thorpej <thorpej%NetBSD.org@localhost>
date: Sat Mar 19 03:53:55 2005 +0000
description:
Split VLAN configuration bits out into a separate file.
diffstat:
sbin/ifconfig/Makefile | 3 +-
sbin/ifconfig/ifconfig.c | 106 +-------------------------------
sbin/ifconfig/vlan.c | 156 +++++++++++++++++++++++++++++++++++++++++++++++
sbin/ifconfig/vlan.h | 35 ++++++++++
4 files changed, 196 insertions(+), 104 deletions(-)
diffs (truncated from 384 to 300 lines):
diff -r b0a687e79461 -r 5fe4708156d7 sbin/ifconfig/Makefile
--- a/sbin/ifconfig/Makefile Sat Mar 19 00:43:17 2005 +0000
+++ b/sbin/ifconfig/Makefile Sat Mar 19 03:53:55 2005 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.18 2005/03/18 11:11:51 yamt Exp $
+# $NetBSD: Makefile,v 1.19 2005/03/19 03:53:55 thorpej Exp $
# @(#)Makefile 8.1 (Berkeley) 6/5/93
.include <bsd.own.mk>
@@ -21,5 +21,6 @@
SRCS= ifconfig.c
SRCS+= agr.c
+SRCS+= vlan.c
.include <bsd.prog.mk>
diff -r b0a687e79461 -r 5fe4708156d7 sbin/ifconfig/ifconfig.c
--- a/sbin/ifconfig/ifconfig.c Sat Mar 19 00:43:17 2005 +0000
+++ b/sbin/ifconfig/ifconfig.c Sat Mar 19 03:53:55 2005 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ifconfig.c,v 1.154 2005/03/18 14:30:08 yamt Exp $ */
+/* $NetBSD: ifconfig.c,v 1.155 2005/03/19 03:53:55 thorpej Exp $ */
/*-
* Copyright (c) 1997, 1998, 2000 The NetBSD Foundation, Inc.
@@ -76,7 +76,7 @@
#if 0
static char sccsid[] = "@(#)ifconfig.c 8.2 (Berkeley) 2/16/94";
#else
-__RCSID("$NetBSD: ifconfig.c,v 1.154 2005/03/18 14:30:08 yamt Exp $");
+__RCSID("$NetBSD: ifconfig.c,v 1.155 2005/03/19 03:53:55 thorpej Exp $");
#endif
#endif /* not lint */
@@ -90,7 +90,6 @@
#include <net/if_ether.h>
#include <net80211/ieee80211.h>
#include <net80211/ieee80211_ioctl.h>
-#include <net/if_vlanvar.h>
#include <netinet/in.h>
#include <netinet/in_var.h>
#ifdef INET6
@@ -122,6 +121,7 @@
#include <util.h>
#include "agr.h"
+#include "vlan.h"
struct ifreq ifr, ridreq;
struct ifaliasreq addreq __attribute__((aligned(4)));
@@ -150,7 +150,6 @@
int Lflag;
#endif
int explicit_prefix = 0;
-u_int vlan_tag = (u_int)-1;
struct ifcapreq g_ifcr;
int g_ifcr_updated;
@@ -195,9 +194,6 @@
void clone_create(const char *, int);
void clone_destroy(const char *, int);
void fixnsel(struct sockaddr_iso *);
-void setvlan(const char *, int);
-void setvlanif(const char *, int);
-void unsetvlanif(const char *, int);
int main(int, char *[]);
/*
@@ -367,7 +363,6 @@
void ieee80211_statistics(void);
void ieee80211_status(void);
void tunnel_status(void);
-void vlan_status(void);
/* Known address families */
struct afswtch {
@@ -977,80 +972,6 @@
}
void
-setvlan(const char *val, int d)
-{
- struct vlanreq vlr;
-
- if (strncmp(ifr.ifr_name, "vlan", 4) != 0 ||
- !isdigit((unsigned char)ifr.ifr_name[4]))
- errx(EXIT_FAILURE,
- "``vlan'' valid only with vlan(4) interfaces");
-
- vlan_tag = atoi(val);
-
- memset(&vlr, 0, sizeof(vlr));
- ifr.ifr_data = (void *)&vlr;
-
- if (ioctl(s, SIOCGETVLAN, &ifr) == -1)
- err(EXIT_FAILURE, "SIOCGETVLAN");
-
- vlr.vlr_tag = vlan_tag;
-
- if (ioctl(s, SIOCSETVLAN, &ifr) == -1)
- err(EXIT_FAILURE, "SIOCSETVLAN");
-}
-
-void
-setvlanif(const char *val, int d)
-{
- struct vlanreq vlr;
-
- if (strncmp(ifr.ifr_name, "vlan", 4) != 0 ||
- !isdigit((unsigned char)ifr.ifr_name[4]))
- errx(EXIT_FAILURE,
- "``vlanif'' valid only with vlan(4) interfaces");
-
- if (vlan_tag == (u_int)-1)
- errx(EXIT_FAILURE,
- "must specify both ``vlan'' and ``vlanif''");
-
- memset(&vlr, 0, sizeof(vlr));
- ifr.ifr_data = (void *)&vlr;
-
- if (ioctl(s, SIOCGETVLAN, &ifr) == -1)
- err(EXIT_FAILURE, "SIOCGETVLAN");
-
- strlcpy(vlr.vlr_parent, val, sizeof(vlr.vlr_parent));
- vlr.vlr_tag = vlan_tag;
-
- if (ioctl(s, SIOCSETVLAN, &ifr) == -1)
- err(EXIT_FAILURE, "SIOCSETVLAN");
-}
-
-void
-unsetvlanif(const char *val, int d)
-{
- struct vlanreq vlr;
-
- if (strncmp(ifr.ifr_name, "vlan", 4) != 0 ||
- !isdigit((unsigned char)ifr.ifr_name[4]))
- errx(EXIT_FAILURE,
- "``vlanif'' valid only with vlan(4) interfaces");
-
- memset(&vlr, 0, sizeof(vlr));
- ifr.ifr_data = (void *)&vlr;
-
- if (ioctl(s, SIOCGETVLAN, &ifr) == -1)
- err(EXIT_FAILURE, "SIOCGETVLAN");
-
- vlr.vlr_parent[0] = '\0';
- vlr.vlr_tag = 0;
-
- if (ioctl(s, SIOCSETVLAN, &ifr) == -1)
- err(EXIT_FAILURE, "SIOCSETVLAN");
-}
-
-void
setifnetmask(const char *addr, int d)
{
(*afp->af_getaddr)(addr, MASK);
@@ -2139,27 +2060,6 @@
}
void
-vlan_status(void)
-{
- struct vlanreq vlr;
-
- if (strncmp(ifr.ifr_name, "vlan", 4) != 0 ||
- !isdigit((unsigned char)ifr.ifr_name[4]))
- return;
-
- memset(&vlr, 0, sizeof(vlr));
- ifr.ifr_data = (void *)&vlr;
-
- if (ioctl(s, SIOCGETVLAN, &ifr) == -1)
- return;
-
- if (vlr.vlr_tag || vlr.vlr_parent[0] != '\0')
- printf("\tvlan: %d parent: %s\n",
- vlr.vlr_tag, vlr.vlr_parent[0] == '\0' ?
- "<none>" : vlr.vlr_parent);
-}
-
-void
in_alias(struct ifreq *creq)
{
struct sockaddr_in *iasin;
diff -r b0a687e79461 -r 5fe4708156d7 sbin/ifconfig/vlan.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sbin/ifconfig/vlan.c Sat Mar 19 03:53:55 2005 +0000
@@ -0,0 +1,156 @@
+/* $NetBSD: vlan.c,v 1.1 2005/03/19 03:53:55 thorpej Exp $ */
+
+/*
+ * Copyright (c) 1983, 1993
+ * The Regents of the University of California. 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. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 THE REGENTS OR CONTRIBUTORS 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.
+ */
+
+#include <sys/cdefs.h>
+#ifndef lint
+__RCSID("$NetBSD: vlan.c,v 1.1 2005/03/19 03:53:55 thorpej Exp $");
+#endif /* not lint */
+
+#include <sys/param.h>
+#include <sys/ioctl.h>
+
+#include <net/if.h>
+#include <net/if_ether.h>
+#include <net/if_vlanvar.h>
+
+#include <ctype.h>
+#include <err.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "vlan.h"
+
+extern struct ifreq ifr;
+extern int s;
+
+static u_int vlan_tag = (u_int)-1;
+
+static int
+checkifname(const char *name)
+{
+
+ return strncmp(name, "vlan", 4) != 0 ||
+ !isdigit((unsigned char)name[4]);
+}
+
+static void
+assertifname(const char *name)
+{
+
+ if (checkifname(name)) {
+ errx(EXIT_FAILURE, "valid only with vlan(4) interfaces");
+ }
+}
+
+void
+setvlan(const char *val, int d)
+{
+ struct vlanreq vlr;
+
+ assertifname(ifr.ifr_name);
+
+ vlan_tag = atoi(val);
+
+ memset(&vlr, 0, sizeof(vlr));
+ ifr.ifr_data = (void *)&vlr;
+ if (ioctl(s, SIOCGETVLAN, &ifr) == -1)
+ err(EXIT_FAILURE, "SIOCGETVLAN");
+
+ vlr.vlr_tag = vlan_tag;
+
+ if (ioctl(s, SIOCSETVLAN, &ifr) == -1)
+ err(EXIT_FAILURE, "SIOCSETVLAN");
+}
+
+void
+setvlanif(const char *val, int d)
+{
+ struct vlanreq vlr;
+
+ assertifname(ifr.ifr_name);
+
+ if (vlan_tag == (u_int)-1)
+ errx(EXIT_FAILURE,
+ "must specify both ``vlan'' and ``vlanif''");
+
+ memset(&vlr, 0, sizeof(vlr));
+ ifr.ifr_data = (void *)&vlr;
+
+ if (ioctl(s, SIOCGETVLAN, &ifr) == -1)
+ err(EXIT_FAILURE, "SIOCGETVLAN");
+
+ strlcpy(vlr.vlr_parent, val, sizeof(vlr.vlr_parent));
Home |
Main Index |
Thread Index |
Old Index