2005-02-22 00:37:22 +03:00
|
|
|
/* $NetBSD: if_vlan.c,v 1.43 2005/02/21 21:37:22 christos Exp $ */
|
2000-09-28 02:40:54 +04:00
|
|
|
|
|
|
|
/*-
|
2001-04-07 22:41:42 +04:00
|
|
|
* Copyright (c) 2000, 2001 The NetBSD Foundation, Inc.
|
2000-09-28 02:40:54 +04:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
2000-10-04 03:50:52 +04:00
|
|
|
* by Andrew Doran, and by Jason R. Thorpe of Zembu Labs, Inc.
|
2000-09-28 02:40:54 +04:00
|
|
|
*
|
|
|
|
* 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 the NetBSD
|
|
|
|
* Foundation, Inc. and its contributors.
|
|
|
|
* 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 1998 Massachusetts Institute of Technology
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software and
|
|
|
|
* its documentation for any purpose and without fee is hereby
|
|
|
|
* granted, provided that both the above copyright notice and this
|
|
|
|
* permission notice appear in all copies, that both the above
|
|
|
|
* copyright notice and this permission notice appear in all
|
|
|
|
* supporting documentation, and that the name of M.I.T. not be used
|
|
|
|
* in advertising or publicity pertaining to distribution of the
|
|
|
|
* software without specific, written prior permission. M.I.T. makes
|
|
|
|
* no representations about the suitability of this software for any
|
|
|
|
* purpose. It is provided "as is" without express or implied
|
|
|
|
* warranty.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS
|
|
|
|
* ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
|
|
|
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
|
|
|
|
* SHALL M.I.T. 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.
|
|
|
|
*
|
|
|
|
* from FreeBSD: if_vlan.c,v 1.16 2000/03/26 15:21:40 charnier Exp
|
|
|
|
* via OpenBSD: if_vlan.c,v 1.4 2000/05/15 19:15:00 chris Exp
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* if_vlan.c - pseudo-device driver for IEEE 802.1Q virtual LANs. Might be
|
|
|
|
* extended some day to also handle IEEE 802.1P priority tagging. This is
|
|
|
|
* sort of sneaky in the implementation, since we need to pretend to be
|
|
|
|
* enough of an Ethernet implementation to make ARP work. The way we do
|
|
|
|
* this is by telling everyone that we are an Ethernet interface, and then
|
|
|
|
* catch the packets that ether_output() left on our output queue when it
|
|
|
|
* calls if_start(), rewrite them for use by the real outgoing interface,
|
|
|
|
* and ask it to send them.
|
|
|
|
*
|
|
|
|
* TODO:
|
|
|
|
*
|
|
|
|
* - Need some way to notify vlan interfaces when the parent
|
|
|
|
* interface changes MTU.
|
|
|
|
*/
|
|
|
|
|
2001-11-13 02:49:33 +03:00
|
|
|
#include <sys/cdefs.h>
|
2005-02-22 00:37:22 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.43 2005/02/21 21:37:22 christos Exp $");
|
2001-11-13 02:49:33 +03:00
|
|
|
|
2000-09-28 02:40:54 +04:00
|
|
|
#include "opt_inet.h"
|
|
|
|
#include "bpfilter.h"
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/queue.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/sockio.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
|
|
|
|
#if NBPFILTER > 0
|
|
|
|
#include <net/bpf.h>
|
|
|
|
#endif
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/if_dl.h>
|
|
|
|
#include <net/if_types.h>
|
|
|
|
#include <net/if_ether.h>
|
|
|
|
#include <net/if_vlanvar.h>
|
|
|
|
|
|
|
|
#ifdef INET
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/if_inarp.h>
|
|
|
|
#endif
|
|
|
|
|
2000-10-04 03:33:38 +04:00
|
|
|
struct vlan_mc_entry {
|
|
|
|
LIST_ENTRY(vlan_mc_entry) mc_entries;
|
|
|
|
/*
|
|
|
|
* A key to identify this entry. The mc_addr below can't be
|
|
|
|
* used since multiple sockaddr may mapped into the same
|
|
|
|
* ether_multi (e.g., AF_UNSPEC).
|
|
|
|
*/
|
|
|
|
union {
|
|
|
|
struct ether_multi *mcu_enm;
|
|
|
|
} mc_u;
|
|
|
|
struct sockaddr_storage mc_addr;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define mc_enm mc_u.mcu_enm
|
|
|
|
|
|
|
|
struct ifvlan {
|
|
|
|
union {
|
|
|
|
struct ethercom ifvu_ec;
|
|
|
|
} ifv_u;
|
|
|
|
struct ifnet *ifv_p; /* parent interface of this vlan */
|
|
|
|
struct ifv_linkmib {
|
|
|
|
const struct vlan_multisw *ifvm_msw;
|
|
|
|
int ifvm_encaplen; /* encapsulation length */
|
|
|
|
int ifvm_mtufudge; /* MTU fudged by this much */
|
|
|
|
int ifvm_mintu; /* min transmission unit */
|
|
|
|
u_int16_t ifvm_proto; /* encapsulation ethertype */
|
|
|
|
u_int16_t ifvm_tag; /* tag to apply on packets */
|
|
|
|
} ifv_mib;
|
|
|
|
LIST_HEAD(__vlan_mchead, vlan_mc_entry) ifv_mc_listhead;
|
|
|
|
LIST_ENTRY(ifvlan) ifv_list;
|
2000-11-09 08:57:38 +03:00
|
|
|
int ifv_flags;
|
2000-10-04 03:33:38 +04:00
|
|
|
};
|
|
|
|
|
2000-11-09 08:57:38 +03:00
|
|
|
#define IFVF_PROMISC 0x01 /* promiscuous mode enabled */
|
|
|
|
|
2000-10-04 03:33:38 +04:00
|
|
|
#define ifv_ec ifv_u.ifvu_ec
|
|
|
|
|
|
|
|
#define ifv_if ifv_ec.ec_if
|
|
|
|
|
|
|
|
#define ifv_msw ifv_mib.ifvm_msw
|
|
|
|
#define ifv_encaplen ifv_mib.ifvm_encaplen
|
|
|
|
#define ifv_mtufudge ifv_mib.ifvm_mtufudge
|
|
|
|
#define ifv_mintu ifv_mib.ifvm_mintu
|
|
|
|
#define ifv_tag ifv_mib.ifvm_tag
|
|
|
|
|
|
|
|
struct vlan_multisw {
|
|
|
|
int (*vmsw_addmulti)(struct ifvlan *, struct ifreq *);
|
|
|
|
int (*vmsw_delmulti)(struct ifvlan *, struct ifreq *);
|
|
|
|
void (*vmsw_purgemulti)(struct ifvlan *);
|
|
|
|
};
|
|
|
|
|
|
|
|
static int vlan_ether_addmulti(struct ifvlan *, struct ifreq *);
|
|
|
|
static int vlan_ether_delmulti(struct ifvlan *, struct ifreq *);
|
|
|
|
static void vlan_ether_purgemulti(struct ifvlan *);
|
|
|
|
|
|
|
|
const struct vlan_multisw vlan_ether_multisw = {
|
|
|
|
vlan_ether_addmulti,
|
|
|
|
vlan_ether_delmulti,
|
|
|
|
vlan_ether_purgemulti,
|
|
|
|
};
|
|
|
|
|
2000-09-28 02:40:54 +04:00
|
|
|
static int vlan_clone_create(struct if_clone *, int);
|
2004-12-04 21:31:43 +03:00
|
|
|
static int vlan_clone_destroy(struct ifnet *);
|
2000-09-28 02:40:54 +04:00
|
|
|
static int vlan_config(struct ifvlan *, struct ifnet *);
|
|
|
|
static int vlan_ioctl(struct ifnet *, u_long, caddr_t);
|
|
|
|
static void vlan_start(struct ifnet *);
|
2000-10-04 03:50:52 +04:00
|
|
|
static void vlan_unconfig(struct ifnet *);
|
2000-10-04 03:33:38 +04:00
|
|
|
|
|
|
|
void vlanattach(int);
|
2000-09-28 02:40:54 +04:00
|
|
|
|
|
|
|
/* XXX This should be a hash table with the tag as the basis of the key. */
|
|
|
|
static LIST_HEAD(, ifvlan) ifv_list;
|
|
|
|
|
|
|
|
struct if_clone vlan_cloner =
|
|
|
|
IF_CLONE_INITIALIZER("vlan", vlan_clone_create, vlan_clone_destroy);
|
|
|
|
|
2003-12-05 22:35:43 +03:00
|
|
|
/* Used to pad ethernet frames with < ETHER_MIN_LEN bytes */
|
|
|
|
static char vlan_zero_pad_buff[ETHER_MIN_LEN];
|
|
|
|
|
2000-09-28 02:40:54 +04:00
|
|
|
void
|
|
|
|
vlanattach(int n)
|
|
|
|
{
|
|
|
|
|
|
|
|
LIST_INIT(&ifv_list);
|
|
|
|
if_clone_attach(&vlan_cloner);
|
|
|
|
}
|
|
|
|
|
2001-01-29 04:51:05 +03:00
|
|
|
static void
|
|
|
|
vlan_reset_linkname(struct ifnet *ifp)
|
|
|
|
{
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We start out with a "802.1Q VLAN" type and zero-length
|
|
|
|
* addresses. When we attach to a parent interface, we
|
|
|
|
* inherit its type, address length, address, and data link
|
|
|
|
* type.
|
|
|
|
*/
|
|
|
|
|
|
|
|
ifp->if_type = IFT_L2VLAN;
|
|
|
|
ifp->if_addrlen = 0;
|
|
|
|
ifp->if_dlt = DLT_NULL;
|
|
|
|
if_alloc_sadl(ifp);
|
|
|
|
}
|
|
|
|
|
2000-09-28 02:40:54 +04:00
|
|
|
static int
|
|
|
|
vlan_clone_create(struct if_clone *ifc, int unit)
|
|
|
|
{
|
|
|
|
struct ifvlan *ifv;
|
|
|
|
struct ifnet *ifp;
|
2000-10-04 03:50:52 +04:00
|
|
|
int s;
|
2000-09-28 02:40:54 +04:00
|
|
|
|
2000-10-04 03:33:38 +04:00
|
|
|
ifv = malloc(sizeof(struct ifvlan), M_DEVBUF, M_WAITOK);
|
2000-09-28 02:40:54 +04:00
|
|
|
memset(ifv, 0, sizeof(struct ifvlan));
|
2000-10-04 10:51:12 +04:00
|
|
|
ifp = &ifv->ifv_if;
|
2000-09-28 11:20:56 +04:00
|
|
|
LIST_INIT(&ifv->ifv_mc_listhead);
|
2000-10-04 03:50:52 +04:00
|
|
|
|
|
|
|
s = splnet();
|
2000-09-28 02:40:54 +04:00
|
|
|
LIST_INSERT_HEAD(&ifv_list, ifv, ifv_list);
|
2000-10-04 03:50:52 +04:00
|
|
|
splx(s);
|
2000-09-28 02:40:54 +04:00
|
|
|
|
2004-04-21 22:40:37 +04:00
|
|
|
snprintf(ifp->if_xname, sizeof(ifp->if_xname), "%s%d", ifc->ifc_name,
|
|
|
|
unit);
|
2000-09-28 02:40:54 +04:00
|
|
|
ifp->if_softc = ifv;
|
|
|
|
ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
|
|
|
|
ifp->if_start = vlan_start;
|
|
|
|
ifp->if_ioctl = vlan_ioctl;
|
2001-04-07 22:41:42 +04:00
|
|
|
IFQ_SET_READY(&ifp->if_snd);
|
2000-09-28 02:40:54 +04:00
|
|
|
|
|
|
|
if_attach(ifp);
|
2001-01-29 04:51:05 +03:00
|
|
|
vlan_reset_linkname(ifp);
|
2000-09-28 02:40:54 +04:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2004-12-04 21:31:43 +03:00
|
|
|
static int
|
2000-09-28 02:40:54 +04:00
|
|
|
vlan_clone_destroy(struct ifnet *ifp)
|
|
|
|
{
|
2000-10-04 03:50:52 +04:00
|
|
|
struct ifvlan *ifv = ifp->if_softc;
|
2000-09-28 02:40:54 +04:00
|
|
|
int s;
|
|
|
|
|
2000-10-04 03:50:52 +04:00
|
|
|
s = splnet();
|
2000-09-28 02:40:54 +04:00
|
|
|
LIST_REMOVE(ifv, ifv_list);
|
|
|
|
vlan_unconfig(ifp);
|
2000-10-04 03:50:52 +04:00
|
|
|
splx(s);
|
2000-09-28 02:40:54 +04:00
|
|
|
|
|
|
|
if_detach(ifp);
|
|
|
|
free(ifv, M_DEVBUF);
|
2004-12-04 21:31:43 +03:00
|
|
|
|
|
|
|
return (0);
|
2000-09-28 02:40:54 +04:00
|
|
|
}
|
|
|
|
|
2000-10-04 03:50:52 +04:00
|
|
|
/*
|
|
|
|
* Configure a VLAN interface. Must be called at splnet().
|
|
|
|
*/
|
2000-09-28 02:40:54 +04:00
|
|
|
static int
|
|
|
|
vlan_config(struct ifvlan *ifv, struct ifnet *p)
|
|
|
|
{
|
2000-10-04 03:33:38 +04:00
|
|
|
struct ifnet *ifp = &ifv->ifv_if;
|
|
|
|
int error;
|
2000-09-28 02:40:54 +04:00
|
|
|
|
|
|
|
if (ifv->ifv_p != NULL)
|
|
|
|
return (EBUSY);
|
2000-10-04 03:33:38 +04:00
|
|
|
|
|
|
|
switch (p->if_type) {
|
|
|
|
case IFT_ETHER:
|
|
|
|
{
|
|
|
|
struct ethercom *ec = (void *) p;
|
|
|
|
|
|
|
|
ifv->ifv_msw = &vlan_ether_multisw;
|
|
|
|
ifv->ifv_encaplen = ETHER_VLAN_ENCAP_LEN;
|
|
|
|
ifv->ifv_mintu = ETHERMIN;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the parent supports the VLAN_MTU capability,
|
|
|
|
* i.e. can Tx/Rx larger than ETHER_MAX_LEN frames,
|
|
|
|
* enable it.
|
|
|
|
*/
|
|
|
|
if (ec->ec_nvlans++ == 0 &&
|
|
|
|
(ec->ec_capabilities & ETHERCAP_VLAN_MTU) != 0) {
|
|
|
|
/*
|
|
|
|
* Enable Tx/Rx of VLAN-sized frames.
|
|
|
|
*/
|
|
|
|
ec->ec_capenable |= ETHERCAP_VLAN_MTU;
|
|
|
|
if (p->if_flags & IFF_UP) {
|
|
|
|
struct ifreq ifr;
|
|
|
|
|
|
|
|
ifr.ifr_flags = p->if_flags;
|
|
|
|
error = (*p->if_ioctl)(p, SIOCSIFFLAGS,
|
|
|
|
(caddr_t) &ifr);
|
|
|
|
if (error) {
|
|
|
|
if (ec->ec_nvlans-- == 1)
|
|
|
|
ec->ec_capenable &=
|
|
|
|
~ETHERCAP_VLAN_MTU;
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ifv->ifv_mtufudge = 0;
|
|
|
|
} else if ((ec->ec_capabilities & ETHERCAP_VLAN_MTU) == 0) {
|
|
|
|
/*
|
|
|
|
* Fudge the MTU by the encapsulation size. This
|
|
|
|
* makes us incompatible with strictly compliant
|
|
|
|
* 802.1Q implementations, but allows us to use
|
|
|
|
* the feature with other NetBSD implementations,
|
|
|
|
* which might still be useful.
|
|
|
|
*/
|
|
|
|
ifv->ifv_mtufudge = ifv->ifv_encaplen;
|
|
|
|
}
|
|
|
|
|
2001-06-12 10:16:59 +04:00
|
|
|
/*
|
|
|
|
* If the parent interface can do hardware-assisted
|
|
|
|
* VLAN encapsulation, then propagate its hardware-
|
|
|
|
* assisted checksumming flags.
|
|
|
|
*/
|
|
|
|
if (ec->ec_capabilities & ETHERCAP_VLAN_HWTAGGING)
|
|
|
|
ifp->if_capabilities = p->if_capabilities &
|
|
|
|
(IFCAP_CSUM_IPv4|IFCAP_CSUM_TCPv4|
|
|
|
|
IFCAP_CSUM_UDPv4|IFCAP_CSUM_TCPv6|
|
|
|
|
IFCAP_CSUM_UDPv6);
|
|
|
|
|
2000-10-04 03:33:38 +04:00
|
|
|
/*
|
|
|
|
* We inherit the parent's Ethernet address.
|
|
|
|
*/
|
|
|
|
ether_ifattach(ifp, LLADDR(p->if_sadl));
|
|
|
|
ifp->if_hdrlen = sizeof(struct ether_vlan_header); /* XXX? */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
return (EPROTONOSUPPORT);
|
|
|
|
}
|
|
|
|
|
2000-09-28 02:40:54 +04:00
|
|
|
ifv->ifv_p = p;
|
2000-10-04 03:33:38 +04:00
|
|
|
ifv->ifv_if.if_mtu = p->if_mtu - ifv->ifv_mtufudge;
|
2000-11-12 22:39:42 +03:00
|
|
|
ifv->ifv_if.if_flags = p->if_flags &
|
2000-11-15 21:15:11 +03:00
|
|
|
(IFF_UP | IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST);
|
2000-09-28 02:40:54 +04:00
|
|
|
|
|
|
|
/*
|
2000-10-04 03:33:38 +04:00
|
|
|
* Inherit the if_type from the parent. This allows us
|
|
|
|
* to participate in bridges of that type.
|
2000-09-28 02:40:54 +04:00
|
|
|
*/
|
2000-10-04 03:33:38 +04:00
|
|
|
ifv->ifv_if.if_type = p->if_type;
|
|
|
|
|
2000-09-28 02:40:54 +04:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2000-10-04 03:50:52 +04:00
|
|
|
/*
|
|
|
|
* Unconfigure a VLAN interface. Must be called at splnet().
|
|
|
|
*/
|
|
|
|
static void
|
2000-09-28 02:40:54 +04:00
|
|
|
vlan_unconfig(struct ifnet *ifp)
|
|
|
|
{
|
2000-10-04 03:33:38 +04:00
|
|
|
struct ifvlan *ifv = ifp->if_softc;
|
2000-09-28 02:40:54 +04:00
|
|
|
|
2000-09-28 12:28:56 +04:00
|
|
|
if (ifv->ifv_p == NULL)
|
2000-10-04 03:50:52 +04:00
|
|
|
return;
|
2000-09-28 02:40:54 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Since the interface is being unconfigured, we need to empty the
|
|
|
|
* list of multicast groups that we may have joined while we were
|
|
|
|
* alive and remove them from the parent's list also.
|
|
|
|
*/
|
2000-10-04 03:33:38 +04:00
|
|
|
(*ifv->ifv_msw->vmsw_purgemulti)(ifv);
|
2000-09-28 02:40:54 +04:00
|
|
|
|
|
|
|
/* Disconnect from parent. */
|
2000-10-04 03:33:38 +04:00
|
|
|
switch (ifv->ifv_p->if_type) {
|
|
|
|
case IFT_ETHER:
|
|
|
|
{
|
|
|
|
struct ethercom *ec = (void *) ifv->ifv_p;
|
|
|
|
|
|
|
|
if (ec->ec_nvlans-- == 1) {
|
|
|
|
/*
|
|
|
|
* Disable Tx/Rx of VLAN-sized frames.
|
|
|
|
*/
|
|
|
|
ec->ec_capenable &= ~ETHERCAP_VLAN_MTU;
|
|
|
|
if (ifv->ifv_p->if_flags & IFF_UP) {
|
|
|
|
struct ifreq ifr;
|
|
|
|
|
|
|
|
ifr.ifr_flags = ifv->ifv_p->if_flags;
|
|
|
|
(void) (*ifv->ifv_p->if_ioctl)(ifv->ifv_p,
|
|
|
|
SIOCSIFFLAGS, (caddr_t) &ifr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ether_ifdetach(ifp);
|
2001-01-29 04:51:05 +03:00
|
|
|
vlan_reset_linkname(ifp);
|
2000-10-04 03:33:38 +04:00
|
|
|
break;
|
|
|
|
}
|
2000-09-28 02:40:54 +04:00
|
|
|
|
2000-10-04 03:33:38 +04:00
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
default:
|
|
|
|
panic("vlan_unconfig: impossible");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
ifv->ifv_p = NULL;
|
|
|
|
ifv->ifv_if.if_mtu = 0;
|
2000-11-09 08:57:38 +03:00
|
|
|
ifv->ifv_flags = 0;
|
2000-09-28 02:40:54 +04:00
|
|
|
|
2000-10-04 03:50:52 +04:00
|
|
|
if_down(ifp);
|
|
|
|
ifp->if_flags &= ~(IFF_UP|IFF_RUNNING);
|
2001-06-12 10:16:59 +04:00
|
|
|
ifp->if_capabilities = 0;
|
2000-10-04 03:50:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called when a parent interface is detaching; destroy any VLAN
|
|
|
|
* configuration for the parent interface.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
vlan_ifdetach(struct ifnet *p)
|
|
|
|
{
|
|
|
|
struct ifvlan *ifv;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
s = splnet();
|
|
|
|
|
|
|
|
for (ifv = LIST_FIRST(&ifv_list); ifv != NULL;
|
|
|
|
ifv = LIST_NEXT(ifv, ifv_list)) {
|
|
|
|
if (ifv->ifv_p == p)
|
|
|
|
vlan_unconfig(&ifv->ifv_if);
|
|
|
|
}
|
|
|
|
|
2000-09-28 02:40:54 +04:00
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
2000-11-09 08:57:38 +03:00
|
|
|
static int
|
|
|
|
vlan_set_promisc(struct ifnet *ifp)
|
|
|
|
{
|
|
|
|
struct ifvlan *ifv = ifp->if_softc;
|
2000-11-10 05:31:53 +03:00
|
|
|
int error = 0;
|
2000-11-09 08:57:38 +03:00
|
|
|
|
|
|
|
if ((ifp->if_flags & IFF_PROMISC) != 0) {
|
|
|
|
if ((ifv->ifv_flags & IFVF_PROMISC) == 0) {
|
|
|
|
error = ifpromisc(ifv->ifv_p, 1);
|
|
|
|
if (error == 0)
|
|
|
|
ifv->ifv_flags |= IFVF_PROMISC;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ((ifv->ifv_flags & IFVF_PROMISC) != 0) {
|
|
|
|
error = ifpromisc(ifv->ifv_p, 0);
|
|
|
|
if (error == 0)
|
|
|
|
ifv->ifv_flags &= ~IFVF_PROMISC;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2000-09-28 02:40:54 +04:00
|
|
|
static int
|
|
|
|
vlan_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
|
|
|
|
{
|
|
|
|
struct proc *p = curproc; /* XXX */
|
2000-10-04 03:50:52 +04:00
|
|
|
struct ifvlan *ifv = ifp->if_softc;
|
|
|
|
struct ifaddr *ifa = (struct ifaddr *) data;
|
|
|
|
struct ifreq *ifr = (struct ifreq *) data;
|
2000-09-28 02:40:54 +04:00
|
|
|
struct ifnet *pr;
|
|
|
|
struct vlanreq vlr;
|
|
|
|
struct sockaddr *sa;
|
2000-10-04 03:50:52 +04:00
|
|
|
int s, error = 0;
|
2000-09-28 02:40:54 +04:00
|
|
|
|
2000-10-04 03:50:52 +04:00
|
|
|
s = splnet();
|
2000-09-28 02:40:54 +04:00
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case SIOCSIFADDR:
|
2000-10-15 15:58:26 +04:00
|
|
|
if (ifv->ifv_p != NULL) {
|
|
|
|
ifp->if_flags |= IFF_UP;
|
2000-09-28 02:40:54 +04:00
|
|
|
|
2000-10-15 15:58:26 +04:00
|
|
|
switch (ifa->ifa_addr->sa_family) {
|
2000-09-28 02:40:54 +04:00
|
|
|
#ifdef INET
|
2000-10-15 15:58:26 +04:00
|
|
|
case AF_INET:
|
|
|
|
arp_ifinit(ifp, ifa);
|
|
|
|
break;
|
2000-09-28 02:40:54 +04:00
|
|
|
#endif
|
2000-10-15 15:58:26 +04:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
error = EINVAL;
|
2000-09-28 02:40:54 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCGIFADDR:
|
|
|
|
sa = (struct sockaddr *)&ifr->ifr_data;
|
2001-01-17 18:53:43 +03:00
|
|
|
memcpy(sa->sa_data, LLADDR(ifp->if_sadl), ifp->if_addrlen);
|
2000-09-28 02:40:54 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCSIFMTU:
|
|
|
|
if (ifv->ifv_p != NULL) {
|
2000-10-04 03:33:38 +04:00
|
|
|
if (ifr->ifr_mtu >
|
|
|
|
(ifv->ifv_p->if_mtu - ifv->ifv_mtufudge) ||
|
|
|
|
ifr->ifr_mtu <
|
|
|
|
(ifv->ifv_mintu - ifv->ifv_mtufudge))
|
2000-09-28 02:40:54 +04:00
|
|
|
error = EINVAL;
|
|
|
|
else
|
|
|
|
ifp->if_mtu = ifr->ifr_mtu;
|
|
|
|
} else
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCSETVLAN:
|
|
|
|
if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)
|
|
|
|
break;
|
|
|
|
if ((error = copyin(ifr->ifr_data, &vlr, sizeof(vlr))) != 0)
|
|
|
|
break;
|
|
|
|
if (vlr.vlr_parent[0] == '\0') {
|
|
|
|
vlan_unconfig(ifp);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (vlr.vlr_tag != EVL_VLANOFTAG(vlr.vlr_tag)) {
|
|
|
|
error = EINVAL; /* check for valid tag */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if ((pr = ifunit(vlr.vlr_parent)) == 0) {
|
|
|
|
error = ENOENT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if ((error = vlan_config(ifv, pr)) != 0)
|
|
|
|
break;
|
|
|
|
ifv->ifv_tag = vlr.vlr_tag;
|
|
|
|
ifp->if_flags |= IFF_RUNNING;
|
2000-11-09 08:57:38 +03:00
|
|
|
|
|
|
|
/* Update promiscuous mode, if necessary. */
|
|
|
|
vlan_set_promisc(ifp);
|
2000-09-28 02:40:54 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCGETVLAN:
|
|
|
|
memset(&vlr, 0, sizeof(vlr));
|
|
|
|
if (ifv->ifv_p != NULL) {
|
|
|
|
snprintf(vlr.vlr_parent, sizeof(vlr.vlr_parent), "%s",
|
|
|
|
ifv->ifv_p->if_xname);
|
|
|
|
vlr.vlr_tag = ifv->ifv_tag;
|
|
|
|
}
|
|
|
|
error = copyout(&vlr, ifr->ifr_data, sizeof(vlr));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCSIFFLAGS:
|
|
|
|
/*
|
2000-11-09 08:57:38 +03:00
|
|
|
* For promiscuous mode, we enable promiscuous mode on
|
|
|
|
* the parent if we need promiscuous on the VLAN interface.
|
2000-09-28 02:40:54 +04:00
|
|
|
*/
|
2000-11-09 08:57:38 +03:00
|
|
|
if (ifv->ifv_p != NULL)
|
|
|
|
error = vlan_set_promisc(ifp);
|
2000-09-28 02:40:54 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCADDMULTI:
|
2000-12-18 22:36:41 +03:00
|
|
|
error = (ifv->ifv_p != NULL) ?
|
|
|
|
(*ifv->ifv_msw->vmsw_addmulti)(ifv, ifr) : EINVAL;
|
2000-09-28 11:35:36 +04:00
|
|
|
break;
|
|
|
|
|
2000-09-28 02:40:54 +04:00
|
|
|
case SIOCDELMULTI:
|
2000-12-18 22:36:41 +03:00
|
|
|
error = (ifv->ifv_p != NULL) ?
|
|
|
|
(*ifv->ifv_msw->vmsw_delmulti)(ifv, ifr) : EINVAL;
|
2000-09-28 02:40:54 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
error = EINVAL;
|
|
|
|
}
|
|
|
|
|
2000-10-04 03:50:52 +04:00
|
|
|
splx(s);
|
|
|
|
|
2000-09-28 02:40:54 +04:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2000-10-04 03:33:38 +04:00
|
|
|
vlan_ether_addmulti(struct ifvlan *ifv, struct ifreq *ifr)
|
2000-09-28 02:40:54 +04:00
|
|
|
{
|
|
|
|
struct vlan_mc_entry *mc;
|
2000-09-28 11:20:56 +04:00
|
|
|
u_int8_t addrlo[ETHER_ADDR_LEN], addrhi[ETHER_ADDR_LEN];
|
2000-09-28 02:40:54 +04:00
|
|
|
int error;
|
|
|
|
|
2000-09-28 11:20:56 +04:00
|
|
|
if (ifr->ifr_addr.sa_len > sizeof(struct sockaddr_storage))
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
error = ether_addmulti(ifr, &ifv->ifv_ec);
|
|
|
|
if (error != ENETRESET)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is new multicast address. We have to tell parent
|
|
|
|
* about it. Also, remember this multicast address so that
|
|
|
|
* we can delete them on unconfigure.
|
|
|
|
*/
|
|
|
|
MALLOC(mc, struct vlan_mc_entry *, sizeof(struct vlan_mc_entry),
|
|
|
|
M_DEVBUF, M_NOWAIT);
|
|
|
|
if (mc == NULL) {
|
|
|
|
error = ENOMEM;
|
|
|
|
goto alloc_failed;
|
2000-09-28 02:40:54 +04:00
|
|
|
}
|
|
|
|
|
2000-09-28 11:20:56 +04:00
|
|
|
/*
|
|
|
|
* As ether_addmulti() returns ENETRESET, following two
|
|
|
|
* statement shouldn't fail.
|
|
|
|
*/
|
|
|
|
(void)ether_multiaddr(&ifr->ifr_addr, addrlo, addrhi);
|
|
|
|
ETHER_LOOKUP_MULTI(addrlo, addrhi, &ifv->ifv_ec, mc->mc_enm);
|
|
|
|
memcpy(&mc->mc_addr, &ifr->ifr_addr, ifr->ifr_addr.sa_len);
|
|
|
|
LIST_INSERT_HEAD(&ifv->ifv_mc_listhead, mc, mc_entries);
|
|
|
|
|
|
|
|
error = (*ifv->ifv_p->if_ioctl)(ifv->ifv_p, SIOCADDMULTI,
|
|
|
|
(caddr_t)ifr);
|
|
|
|
if (error != 0)
|
|
|
|
goto ioctl_failed;
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
ioctl_failed:
|
|
|
|
LIST_REMOVE(mc, mc_entries);
|
|
|
|
FREE(mc, M_DEVBUF);
|
|
|
|
alloc_failed:
|
|
|
|
(void)ether_delmulti(ifr, &ifv->ifv_ec);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2000-10-04 03:33:38 +04:00
|
|
|
vlan_ether_delmulti(struct ifvlan *ifv, struct ifreq *ifr)
|
2000-09-28 11:20:56 +04:00
|
|
|
{
|
|
|
|
struct ether_multi *enm;
|
|
|
|
struct vlan_mc_entry *mc;
|
|
|
|
u_int8_t addrlo[ETHER_ADDR_LEN], addrhi[ETHER_ADDR_LEN];
|
|
|
|
int error;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find a key to lookup vlan_mc_entry. We have to do this
|
|
|
|
* before calling ether_delmulti for obvious reason.
|
|
|
|
*/
|
|
|
|
if ((error = ether_multiaddr(&ifr->ifr_addr, addrlo, addrhi)) != 0)
|
|
|
|
return (error);
|
|
|
|
ETHER_LOOKUP_MULTI(addrlo, addrhi, &ifv->ifv_ec, enm);
|
|
|
|
|
|
|
|
error = ether_delmulti(ifr, &ifv->ifv_ec);
|
|
|
|
if (error != ENETRESET)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
/* We no longer use this multicast address. Tell parent so. */
|
|
|
|
error = (*ifv->ifv_p->if_ioctl)(ifv->ifv_p, SIOCDELMULTI,
|
|
|
|
(caddr_t)ifr);
|
|
|
|
if (error == 0) {
|
|
|
|
/* And forget about this address. */
|
|
|
|
for (mc = LIST_FIRST(&ifv->ifv_mc_listhead); mc != NULL;
|
|
|
|
mc = LIST_NEXT(mc, mc_entries)) {
|
|
|
|
if (mc->mc_enm == enm) {
|
|
|
|
LIST_REMOVE(mc, mc_entries);
|
|
|
|
FREE(mc, M_DEVBUF);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
KASSERT(mc != NULL);
|
|
|
|
} else
|
|
|
|
(void)ether_addmulti(ifr, &ifv->ifv_ec);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2002-06-11 10:00:57 +04:00
|
|
|
* Delete any multicast address we have asked to add from parent
|
2000-09-28 11:20:56 +04:00
|
|
|
* interface. Called when the vlan is being unconfigured.
|
|
|
|
*/
|
|
|
|
static void
|
2000-10-04 03:33:38 +04:00
|
|
|
vlan_ether_purgemulti(struct ifvlan *ifv)
|
2000-09-28 11:20:56 +04:00
|
|
|
{
|
|
|
|
struct ifnet *ifp = ifv->ifv_p; /* Parent. */
|
|
|
|
struct vlan_mc_entry *mc;
|
|
|
|
union {
|
|
|
|
struct ifreq ifreq;
|
|
|
|
struct {
|
|
|
|
char ifr_name[IFNAMSIZ];
|
2000-11-10 05:27:19 +03:00
|
|
|
struct sockaddr_storage ifr_ss;
|
2000-09-28 11:20:56 +04:00
|
|
|
} ifreq_storage;
|
|
|
|
} ifreq;
|
|
|
|
struct ifreq *ifr = &ifreq.ifreq;
|
|
|
|
|
|
|
|
memcpy(ifr->ifr_name, ifp->if_xname, IFNAMSIZ);
|
|
|
|
while ((mc = LIST_FIRST(&ifv->ifv_mc_listhead)) != NULL) {
|
|
|
|
memcpy(&ifr->ifr_addr, &mc->mc_addr, mc->mc_addr.ss_len);
|
|
|
|
(void)(*ifp->if_ioctl)(ifp, SIOCDELMULTI, (caddr_t)ifr);
|
|
|
|
LIST_REMOVE(mc, mc_entries);
|
|
|
|
FREE(mc, M_DEVBUF);
|
2000-09-28 02:40:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
vlan_start(struct ifnet *ifp)
|
|
|
|
{
|
2000-10-04 10:51:12 +04:00
|
|
|
struct ifvlan *ifv = ifp->if_softc;
|
|
|
|
struct ifnet *p = ifv->ifv_p;
|
2000-11-17 22:21:53 +03:00
|
|
|
struct ethercom *ec = (void *) ifv->ifv_p;
|
2000-09-28 02:40:54 +04:00
|
|
|
struct mbuf *m;
|
2001-04-07 22:41:42 +04:00
|
|
|
int error;
|
|
|
|
ALTQ_DECL(struct altq_pktattr pktattr;)
|
2000-09-28 02:40:54 +04:00
|
|
|
|
|
|
|
ifp->if_flags |= IFF_OACTIVE;
|
|
|
|
|
|
|
|
for (;;) {
|
2001-04-07 22:41:42 +04:00
|
|
|
IFQ_DEQUEUE(&ifp->if_snd, m);
|
2000-09-28 02:40:54 +04:00
|
|
|
if (m == NULL)
|
|
|
|
break;
|
|
|
|
|
2001-04-07 22:41:42 +04:00
|
|
|
#ifdef ALTQ
|
|
|
|
/*
|
|
|
|
* If ALTQ is enabled on the parent interface, do
|
|
|
|
* classification; the queueing discipline might
|
|
|
|
* not require classification, but might require
|
|
|
|
* the address family/header pointer in the pktattr.
|
|
|
|
*/
|
|
|
|
if (ALTQ_IS_ENABLED(&p->if_snd)) {
|
|
|
|
switch (p->if_type) {
|
|
|
|
case IFT_ETHER:
|
|
|
|
altq_etherclassify(&p->if_snd, m, &pktattr);
|
|
|
|
break;
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
default:
|
|
|
|
panic("vlan_start: impossible (altq)");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* ALTQ */
|
|
|
|
|
2000-09-28 02:40:54 +04:00
|
|
|
#if NBPFILTER > 0
|
|
|
|
if (ifp->if_bpf)
|
|
|
|
bpf_mtap(ifp->if_bpf, m);
|
|
|
|
#endif
|
|
|
|
/*
|
2000-11-17 22:21:53 +03:00
|
|
|
* If the parent can insert the tag itself, just mark
|
|
|
|
* the tag in the mbuf header.
|
2000-09-28 02:40:54 +04:00
|
|
|
*/
|
2000-11-17 22:21:53 +03:00
|
|
|
if (ec->ec_capabilities & ETHERCAP_VLAN_HWTAGGING) {
|
2003-01-17 11:11:49 +03:00
|
|
|
struct m_tag *mtag;
|
|
|
|
|
|
|
|
mtag = m_tag_get(PACKET_TAG_VLAN, sizeof(u_int),
|
|
|
|
M_NOWAIT);
|
|
|
|
if (mtag == NULL) {
|
2000-10-04 03:33:38 +04:00
|
|
|
ifp->if_oerrors++;
|
2000-11-17 22:21:53 +03:00
|
|
|
m_freem(m);
|
2000-10-04 03:33:38 +04:00
|
|
|
continue;
|
|
|
|
}
|
2003-01-17 11:11:49 +03:00
|
|
|
*(u_int *)(mtag + 1) = ifv->ifv_tag;
|
2003-09-09 18:22:19 +04:00
|
|
|
m_tag_prepend(m, mtag);
|
2000-11-17 22:21:53 +03:00
|
|
|
} else {
|
2000-10-04 03:33:38 +04:00
|
|
|
/*
|
2002-06-11 10:00:57 +04:00
|
|
|
* insert the tag ourselves
|
2000-10-04 03:33:38 +04:00
|
|
|
*/
|
2000-11-17 22:21:53 +03:00
|
|
|
M_PREPEND(m, ifv->ifv_encaplen, M_DONTWAIT);
|
|
|
|
if (m == NULL) {
|
|
|
|
printf("%s: unable to prepend encap header",
|
|
|
|
ifv->ifv_p->if_xname);
|
|
|
|
ifp->if_oerrors++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (p->if_type) {
|
|
|
|
case IFT_ETHER:
|
|
|
|
{
|
|
|
|
struct ether_vlan_header *evl;
|
|
|
|
|
|
|
|
if (m->m_len < sizeof(struct ether_vlan_header))
|
|
|
|
m = m_pullup(m,
|
|
|
|
sizeof(struct ether_vlan_header));
|
|
|
|
if (m == NULL) {
|
|
|
|
printf("%s: unable to pullup encap "
|
|
|
|
"header", ifv->ifv_p->if_xname);
|
|
|
|
ifp->if_oerrors++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Transform the Ethernet header into an
|
|
|
|
* Ethernet header with 802.1Q encapsulation.
|
|
|
|
*/
|
|
|
|
memmove(mtod(m, caddr_t),
|
|
|
|
mtod(m, caddr_t) + ifv->ifv_encaplen,
|
|
|
|
sizeof(struct ether_header));
|
|
|
|
evl = mtod(m, struct ether_vlan_header *);
|
|
|
|
evl->evl_proto = evl->evl_encap_proto;
|
|
|
|
evl->evl_encap_proto = htons(ETHERTYPE_VLAN);
|
|
|
|
evl->evl_tag = htons(ifv->ifv_tag);
|
2003-12-05 22:35:43 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* To cater for VLAN-aware layer 2 ethernet
|
|
|
|
* switches which may need to strip the tag
|
|
|
|
* before forwarding the packet, make sure
|
|
|
|
* the packet+tag is at least 68 bytes long.
|
|
|
|
* This is necessary because our parent will
|
|
|
|
* only pad to 64 bytes (ETHER_MIN_LEN) and
|
|
|
|
* some switches will not pad by themselves
|
|
|
|
* after deleting a tag.
|
|
|
|
*/
|
|
|
|
if (m->m_pkthdr.len <
|
|
|
|
(ETHER_MIN_LEN + ETHER_VLAN_ENCAP_LEN)) {
|
|
|
|
m_copyback(m, m->m_pkthdr.len,
|
|
|
|
(ETHER_MIN_LEN +
|
|
|
|
ETHER_VLAN_ENCAP_LEN) -
|
|
|
|
m->m_pkthdr.len,
|
|
|
|
vlan_zero_pad_buff);
|
|
|
|
}
|
2000-11-17 22:21:53 +03:00
|
|
|
break;
|
|
|
|
}
|
2000-10-04 03:33:38 +04:00
|
|
|
|
|
|
|
#ifdef DIAGNOSTIC
|
2000-11-17 22:21:53 +03:00
|
|
|
default:
|
|
|
|
panic("vlan_start: impossible");
|
2000-10-04 03:33:38 +04:00
|
|
|
#endif
|
2000-11-17 22:21:53 +03:00
|
|
|
}
|
2000-10-04 03:33:38 +04:00
|
|
|
}
|
2000-09-28 02:40:54 +04:00
|
|
|
|
|
|
|
/*
|
2000-10-04 03:33:38 +04:00
|
|
|
* Send it, precisely as the parent's output routine
|
2002-06-11 10:00:57 +04:00
|
|
|
* would have. We are already running at splnet.
|
2000-09-28 02:40:54 +04:00
|
|
|
*/
|
2001-04-07 22:41:42 +04:00
|
|
|
IFQ_ENQUEUE(&p->if_snd, m, &pktattr, error);
|
|
|
|
if (error) {
|
|
|
|
/* mbuf is already freed */
|
2000-09-28 02:40:54 +04:00
|
|
|
ifp->if_oerrors++;
|
|
|
|
continue;
|
|
|
|
}
|
2001-04-07 22:41:42 +04:00
|
|
|
|
2000-11-15 21:15:11 +03:00
|
|
|
ifp->if_opackets++;
|
If the parent interface is not IFF_RUNNING, do not call its start function.
This prevent a variety of fun panics, and therefore fixes PR 12932, PR 17561,
and PR 18376...
XXX
...however this is most definitely a hack. The real problem here is that there
is no callback to notify a "client" interface like vlan when a "parent"
interface's status changes, and therefore the vlan interface is always
IFF_RUNNING. This allows packets to be queued on vlan interface at any time.
We can't simply leave the packets on the vlan interface, either, because there
is no callback to dequeue them. And last, since it's always IFF_RUNNING, if
we just *toss* the packets, we lose gratuitous ARPs and DAD packets.
"This needs work," but at least it no longer bleeds.
2004-07-08 23:09:12 +04:00
|
|
|
if ((p->if_flags & (IFF_RUNNING|IFF_OACTIVE)) == IFF_RUNNING)
|
2000-10-04 10:51:12 +04:00
|
|
|
(*p->if_start)(p);
|
2000-09-28 02:40:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
ifp->if_flags &= ~IFF_OACTIVE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Given an Ethernet frame, find a valid vlan interface corresponding to the
|
2004-04-23 06:58:27 +04:00
|
|
|
* given source interface and tag, then run the real packet through the
|
|
|
|
* parent's input routine.
|
2000-09-28 02:40:54 +04:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
vlan_input(struct ifnet *ifp, struct mbuf *m)
|
|
|
|
{
|
|
|
|
struct ifvlan *ifv;
|
|
|
|
u_int tag;
|
2003-01-17 11:11:49 +03:00
|
|
|
struct m_tag *mtag;
|
2000-11-17 22:21:53 +03:00
|
|
|
|
2003-01-17 11:11:49 +03:00
|
|
|
mtag = m_tag_find(m, PACKET_TAG_VLAN, NULL);
|
|
|
|
if (mtag != NULL) {
|
|
|
|
/* m contains a normal ethernet frame, the tag is in mtag */
|
|
|
|
tag = *(u_int *)(mtag + 1);
|
|
|
|
m_tag_delete(m, mtag);
|
2000-11-17 22:21:53 +03:00
|
|
|
} else {
|
|
|
|
switch (ifp->if_type) {
|
|
|
|
case IFT_ETHER:
|
|
|
|
{
|
|
|
|
struct ether_vlan_header *evl;
|
2000-09-28 02:40:54 +04:00
|
|
|
|
2000-11-17 22:21:53 +03:00
|
|
|
if (m->m_len < sizeof(struct ether_vlan_header) &&
|
|
|
|
(m = m_pullup(m,
|
|
|
|
sizeof(struct ether_vlan_header))) == NULL) {
|
|
|
|
printf("%s: no memory for VLAN header, "
|
|
|
|
"dropping packet.\n", ifp->if_xname);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
evl = mtod(m, struct ether_vlan_header *);
|
|
|
|
KASSERT(ntohs(evl->evl_encap_proto) == ETHERTYPE_VLAN);
|
2000-10-04 03:33:38 +04:00
|
|
|
|
2000-11-17 22:21:53 +03:00
|
|
|
tag = EVL_VLANOFTAG(ntohs(evl->evl_tag));
|
2000-10-04 03:33:38 +04:00
|
|
|
|
2000-11-17 22:21:53 +03:00
|
|
|
/*
|
|
|
|
* Restore the original ethertype. We'll remove
|
|
|
|
* the encapsulation after we've found the vlan
|
|
|
|
* interface corresponding to the tag.
|
|
|
|
*/
|
|
|
|
evl->evl_encap_proto = evl->evl_proto;
|
|
|
|
break;
|
|
|
|
}
|
2000-09-28 02:40:54 +04:00
|
|
|
|
2000-11-17 22:21:53 +03:00
|
|
|
default:
|
|
|
|
tag = (u_int) -1; /* XXX GCC */
|
2000-10-04 03:33:38 +04:00
|
|
|
#ifdef DIAGNOSTIC
|
2000-11-17 22:21:53 +03:00
|
|
|
panic("vlan_input: impossible");
|
2000-10-04 03:33:38 +04:00
|
|
|
#endif
|
2000-11-17 22:21:53 +03:00
|
|
|
}
|
|
|
|
}
|
2000-09-28 02:40:54 +04:00
|
|
|
|
2005-02-22 00:37:22 +03:00
|
|
|
for (ifv = LIST_FIRST(&ifv_list); ifv != NULL;
|
|
|
|
ifv = LIST_NEXT(ifv, ifv_list))
|
|
|
|
if (ifp == ifv->ifv_p && tag == ifv->ifv_tag)
|
|
|
|
break;
|
|
|
|
|
2000-10-04 03:33:38 +04:00
|
|
|
if (ifv == NULL ||
|
|
|
|
(ifv->ifv_if.if_flags & (IFF_UP|IFF_RUNNING)) !=
|
|
|
|
(IFF_UP|IFF_RUNNING)) {
|
2003-10-02 11:13:57 +04:00
|
|
|
m_freem(m);
|
2000-10-04 10:51:12 +04:00
|
|
|
ifp->if_noproto++;
|
2000-09-28 02:40:54 +04:00
|
|
|
return;
|
|
|
|
}
|
2005-02-22 00:37:22 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Now, remove the encapsulation header. The original
|
|
|
|
* header has already been fixed up above.
|
|
|
|
*/
|
|
|
|
if (mtag == NULL) {
|
|
|
|
memmove(mtod(m, caddr_t) + ifv->ifv_encaplen,
|
|
|
|
mtod(m, caddr_t), sizeof(struct ether_header));
|
|
|
|
m_adj(m, ifv->ifv_encaplen);
|
|
|
|
}
|
|
|
|
|
2000-09-28 02:40:54 +04:00
|
|
|
m->m_pkthdr.rcvif = &ifv->ifv_if;
|
|
|
|
ifv->ifv_if.if_ipackets++;
|
|
|
|
|
|
|
|
#if NBPFILTER > 0
|
|
|
|
if (ifv->ifv_if.if_bpf)
|
|
|
|
bpf_mtap(ifv->ifv_if.if_bpf, m);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Pass it back through the parent's input routine. */
|
|
|
|
(*ifp->if_input)(&ifv->ifv_if, m);
|
|
|
|
}
|