Split VLAN configuration bits out into a separate file.

This commit is contained in:
thorpej 2005-03-19 03:53:55 +00:00
parent 9740d8d0b2
commit 0fded9bea2
4 changed files with 196 additions and 104 deletions

View File

@ -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 @@ LDADD+=-lutil
SRCS= ifconfig.c
SRCS+= agr.c
SRCS+= vlan.c
.include <bsd.prog.mk>

View File

@ -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 @@ __COPYRIGHT("@(#) Copyright (c) 1983, 1993\n\
#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 @@ __RCSID("$NetBSD: ifconfig.c,v 1.154 2005/03/18 14:30:08 yamt Exp $");
#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 @@ __RCSID("$NetBSD: ifconfig.c,v 1.154 2005/03/18 14:30:08 yamt Exp $");
#include <util.h>
#include "agr.h"
#include "vlan.h"
struct ifreq ifr, ridreq;
struct ifaliasreq addreq __attribute__((aligned(4)));
@ -150,7 +150,6 @@ int aflag, bflag, Cflag, dflag, lflag, mflag, sflag, uflag, vflag, zflag;
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 setmediainst(const char *, int);
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 iso_getaddr(const char *, int);
void ieee80211_statistics(void);
void ieee80211_status(void);
void tunnel_status(void);
void vlan_status(void);
/* Known address families */
struct afswtch {
@ -976,80 +971,6 @@ deletetunnel(const char *vname, int param)
err(EXIT_FAILURE, "SIOCDIFPHYADDR");
}
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)
{
@ -2138,27 +2059,6 @@ tunnel_status(void)
printf("\ttunnel inet%s %s --> %s\n", ver, psrcaddr, pdstaddr);
}
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)
{

156
sbin/ifconfig/vlan.c Normal file
View File

@ -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));
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;
assertifname(ifr.ifr_name);
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
vlan_status(void)
{
struct vlanreq vlr;
if (checkifname(ifr.ifr_name))
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);
}

35
sbin/ifconfig/vlan.h Normal file
View File

@ -0,0 +1,35 @@
/* $NetBSD: vlan.h,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.
*/
void setvlan(const char *, int);
void setvlanif(const char *, int);
void unsetvlanif(const char *, int);
void vlan_status(void);