Make vlan(4) loadable, unloadable, and clonable. As a side effect,

interfaces must now always enable VLAN support.

Reviewed by:	jlemon
MFC after:	3 weeks
This commit is contained in:
Brooks Davis 2001-09-05 21:10:28 +00:00
parent 914da7d0d3
commit 9d4fe4b2b0
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=83115
10 changed files with 206 additions and 164 deletions

View File

@ -32,7 +32,7 @@
.Nm vlan
.Nd IEEE 802.1Q VLAN network interface
.Sh SYNOPSIS
.Cd device vlan Op Ar count
.Cd device vlan
.\"
.Sh DESCRIPTION
The

View File

@ -87,8 +87,6 @@
* if the user selects an MTU larger than 8152 (8170 - 18).
*/
#include "vlan.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/sockio.h>
@ -102,11 +100,8 @@
#include <net/ethernet.h>
#include <net/if_dl.h>
#include <net/if_media.h>
#if NVLAN > 0
#include <net/if_types.h>
#include <net/if_vlan_var.h>
#endif
#include <net/bpf.h>
@ -1335,16 +1330,14 @@ static void nge_rxeof(sc)
m->m_pkthdr.csum_data = 0xffff;
}
#if NVLAN > 0
/*
* If we received a packet with a vlan tag, pass it
* to vlan_input() instead of ether_input().
*/
if (extsts & NGE_RXEXTSTS_VLANPKT) {
vlan_input_tag(eh, m, extsts & NGE_RXEXTSTS_VTCI);
VLAN_INPUT_TAG(ifp, eh, m, extsts & NGE_RXEXTSTS_VTCI);
continue;
}
#endif
ether_input(ifp, eh, m);
}
@ -1539,14 +1532,12 @@ static int nge_encap(sc, m_head, txidx)
struct nge_desc *f = NULL;
struct mbuf *m;
int frag, cur, cnt = 0;
#if NVLAN > 0
struct ifvlan *ifv = NULL;
if ((m_head->m_flags & (M_PROTO1|M_PKTHDR)) == (M_PROTO1|M_PKTHDR) &&
m_head->m_pkthdr.rcvif != NULL &&
m_head->m_pkthdr.rcvif->if_type == IFT_L2VLAN)
ifv = m_head->m_pkthdr.rcvif->if_softc;
#endif
/*
* Start packing the mbufs in this chain into
@ -1588,12 +1579,10 @@ static int nge_encap(sc, m_head, txidx)
NGE_TXEXTSTS_UDPCSUM;
}
#if NVLAN > 0
if (ifv != NULL) {
sc->nge_ldata->nge_tx_list[cur].nge_extsts |=
(NGE_TXEXTSTS_VLANPKT|ifv->ifv_tag);
}
#endif
sc->nge_ldata->nge_tx_list[cur].nge_mbuf = m_head;
sc->nge_ldata->nge_tx_list[cur].nge_ctl &= ~NGE_CMDSTS_MORE;
@ -1754,15 +1743,13 @@ static void nge_init(xsc)
*/
CSR_WRITE_4(sc, NGE_VLAN_IP_RXCTL, NGE_VIPRXCTL_IPCSUM_ENB);
#if NVLAN > 0
/*
* If VLAN support is enabled, tell the chip to detect
* and strip VLAN tag info from received frames. The tag
* will be provided in the extsts field in the RX descriptors.
* Tell the chip to detect and strip VLAN tag info from
* received frames. The tag will be provided in the extsts
* field in the RX descriptors.
*/
NGE_SETBIT(sc, NGE_VLAN_IP_RXCTL,
NGE_VIPRXCTL_TAG_DETECT_ENB|NGE_VIPRXCTL_TAG_STRIP_ENB);
#endif
/* Set TX configuration */
CSR_WRITE_4(sc, NGE_TX_CFG, NGE_TXCFG);
@ -1772,14 +1759,11 @@ static void nge_init(xsc)
*/
CSR_WRITE_4(sc, NGE_VLAN_IP_TXCTL, NGE_VIPTXCTL_CSUM_PER_PKT);
#if NVLAN > 0
/*
* If VLAN support is enabled, tell the chip to insert
* VLAN tags on a per-packet basis as dictated by the
* code in the frame encapsulation routine.
* Tell the chip to insert VLAN tags on a per-packet basis as
* dictated by the code in the frame encapsulation routine.
*/
NGE_SETBIT(sc, NGE_VLAN_IP_TXCTL, NGE_VIPTXCTL_TAG_PER_PKT);
#endif
/* Set full/half duplex mode. */
if ((mii->mii_media_active & IFM_GMASK) == IFM_FDX) {

View File

@ -78,8 +78,6 @@
* - Andrew Gallatin for providing FreeBSD/Alpha support.
*/
#include "vlan.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/sockio.h>
@ -94,13 +92,10 @@
#include <net/ethernet.h>
#include <net/if_dl.h>
#include <net/if_media.h>
#include <net/bpf.h>
#if NVLAN > 0
#include <net/if_types.h>
#include <net/if_vlan_var.h>
#endif
#include <net/bpf.h>
#include <netinet/in_systm.h>
#include <netinet/in.h>
@ -1334,9 +1329,7 @@ static int ti_gibinit(sc)
if (sc->arpcom.ac_if.if_hwassist)
rcb->ti_flags |= TI_RCB_FLAG_TCP_UDP_CKSUM |
TI_RCB_FLAG_IP_CKSUM | TI_RCB_FLAG_NO_PHDR_CKSUM;
#if NVLAN > 0
rcb->ti_flags |= TI_RCB_FLAG_VLAN_ASSIST;
#endif
/* Set up the jumbo receive ring. */
rcb = &sc->ti_rdata->ti_info.ti_jumbo_rx_rcb;
@ -1347,9 +1340,7 @@ static int ti_gibinit(sc)
if (sc->arpcom.ac_if.if_hwassist)
rcb->ti_flags |= TI_RCB_FLAG_TCP_UDP_CKSUM |
TI_RCB_FLAG_IP_CKSUM | TI_RCB_FLAG_NO_PHDR_CKSUM;
#if NVLAN > 0
rcb->ti_flags |= TI_RCB_FLAG_VLAN_ASSIST;
#endif
/*
* Set up the mini ring. Only activated on the
@ -1367,9 +1358,7 @@ static int ti_gibinit(sc)
if (sc->arpcom.ac_if.if_hwassist)
rcb->ti_flags |= TI_RCB_FLAG_TCP_UDP_CKSUM |
TI_RCB_FLAG_IP_CKSUM | TI_RCB_FLAG_NO_PHDR_CKSUM;
#if NVLAN > 0
rcb->ti_flags |= TI_RCB_FLAG_VLAN_ASSIST;
#endif
/*
* Set up the receive return ring.
@ -1403,9 +1392,7 @@ static int ti_gibinit(sc)
rcb->ti_flags = 0;
else
rcb->ti_flags = TI_RCB_FLAG_HOST_RING;
#if NVLAN > 0
rcb->ti_flags |= TI_RCB_FLAG_VLAN_ASSIST;
#endif
if (sc->arpcom.ac_if.if_hwassist)
rcb->ti_flags |= TI_RCB_FLAG_TCP_UDP_CKSUM |
TI_RCB_FLAG_IP_CKSUM | TI_RCB_FLAG_NO_PHDR_CKSUM;
@ -1738,22 +1725,18 @@ static void ti_rxeof(sc)
u_int32_t rxidx;
struct ether_header *eh;
struct mbuf *m = NULL;
#if NVLAN > 0
u_int16_t vlan_tag = 0;
int have_tag = 0;
#endif
cur_rx =
&sc->ti_rdata->ti_rx_return_ring[sc->ti_rx_saved_considx];
rxidx = cur_rx->ti_idx;
TI_INC(sc->ti_rx_saved_considx, TI_RETURN_RING_CNT);
#if NVLAN > 0
if (cur_rx->ti_flags & TI_BDFLAG_VLAN_TAG) {
have_tag = 1;
vlan_tag = cur_rx->ti_vlan_tag & 0xfff;
}
#endif
if (cur_rx->ti_flags & TI_BDFLAG_JUMBO_RING) {
TI_INC(sc->ti_jumbo, TI_JUMBO_RX_RING_CNT);
@ -1815,17 +1798,15 @@ static void ti_rxeof(sc)
m->m_pkthdr.csum_data = cur_rx->ti_tcp_udp_cksum;
}
#if NVLAN > 0
/*
* If we received a packet with a vlan tag, pass it
* to vlan_input() instead of ether_input().
*/
if (have_tag) {
vlan_input_tag(eh, m, vlan_tag);
VLAN_INPUT_TAG(ifp, eh, m, vlan_tag);
have_tag = vlan_tag = 0;
continue;
}
#endif
ether_input(ifp, eh, m);
}
@ -1963,14 +1944,12 @@ static int ti_encap(sc, m_head, txidx)
struct mbuf *m;
u_int32_t frag, cur, cnt = 0;
u_int16_t csum_flags = 0;
#if NVLAN > 0
struct ifvlan *ifv = NULL;
if ((m_head->m_flags & (M_PROTO1|M_PKTHDR)) == (M_PROTO1|M_PKTHDR) &&
m_head->m_pkthdr.rcvif != NULL &&
m_head->m_pkthdr.rcvif->if_type == IFT_L2VLAN)
ifv = m_head->m_pkthdr.rcvif->if_softc;
#endif
m = m_head;
cur = frag = *txidx;
@ -2013,14 +1992,14 @@ static int ti_encap(sc, m_head, txidx)
TI_HOSTADDR(f->ti_addr) = vtophys(mtod(m, vm_offset_t));
f->ti_len = m->m_len;
f->ti_flags = csum_flags;
#if NVLAN > 0
if (ifv != NULL) {
f->ti_flags |= TI_BDFLAG_VLAN_TAG;
f->ti_vlan_tag = ifv->ifv_tag & 0xfff;
} else {
f->ti_vlan_tag = 0;
}
#endif
/*
* Sanity check: avoid coming within 16 descriptors
* of the end of the ring.

View File

@ -39,8 +39,6 @@
* Driver for 3c990 (Typhoon) Ethernet ASIC
*/
#include "vlan.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/sockio.h>
@ -54,6 +52,7 @@
#include <net/ethernet.h>
#include <net/if_dl.h>
#include <net/if_types.h>
#include <net/if_vlan_var.h>
#include <netinet/in.h>
#include <netinet/in_systm.h>
@ -66,10 +65,6 @@
#include <net/bpf.h>
#if NVLAN > 0
#include <net/if_vlan_var.h>
#endif
#include <vm/vm.h> /* for vtophys */
#include <vm/pmap.h> /* for vtophys */
#include <machine/clock.h> /* for DELAY */
@ -809,14 +804,11 @@ txp_rx_reclaim(sc, r)
/* Remove header from mbuf and pass it on. */
m_adj(m, sizeof(struct ether_header));
#if NVLAN > 0
if (rxd->rx_stat & RX_STAT_VLAN) {
if (vlan_input_tag(eh, m,
htons(rxd->rx_vlan >> 16)) < 0)
ifp->if_noproto++;
VLAN_INPUT_TAG(ifp, eh, m, htons(rxd->rx_vlan >> 16));
goto next;
}
#endif
ether_input(ifp, eh, m);
next:
@ -1317,9 +1309,7 @@ txp_start(ifp)
struct mbuf *m, *m0;
struct txp_swdesc *sd;
u_int32_t firstprod, firstcnt, prod, cnt;
#if NVLAN > 0
struct ifvlan *ifv;
#endif
if ((ifp->if_flags & (IFF_RUNNING | IFF_OACTIVE)) != IFF_RUNNING)
return;
@ -1356,14 +1346,13 @@ txp_start(ifp)
if (++cnt >= (TX_ENTRIES - 4))
goto oactive;
#if NVLAN > 0
if ((m->m_flags & (M_PROTO1|M_PKTHDR)) == (M_PROTO1|M_PKTHDR) &&
m->m_pkthdr.rcvif != NULL) {
ifv = m->m_pkthdr.rcvif->if_softc;
txd->tx_pflags = TX_PFLAGS_VLAN |
(htons(ifv->ifv_tag) << TX_PFLAGS_VLANTAG_S);
}
#endif
if (m->m_pkthdr.csum_flags & CSUM_IP)
txd->tx_pflags |= TX_PFLAGS_IPCKSUM;
@ -1879,12 +1868,10 @@ txp_capabilities(sc)
sc->sc_tx_capability = ext->ext_1 & OFFLOAD_MASK;
sc->sc_rx_capability = ext->ext_2 & OFFLOAD_MASK;
#if NVLAN > 0
if (rsp->rsp_par2 & rsp->rsp_par3 & OFFLOAD_VLAN) {
sc->sc_tx_capability |= OFFLOAD_VLAN;
sc->sc_rx_capability |= OFFLOAD_VLAN;
}
#endif
#if 0
/* not ready yet */

View File

@ -0,0 +1,12 @@
# $FreeBSD$
.PATH: ${.CURDIR}/../../net
KMOD= if_vlan
SRCS= if_vlan.c opt_inet.h
NOMAN=
opt_inet.h:
echo "#define INET 1" > ${.TARGET}
.include <bsd.kmod.mk>

View File

@ -99,6 +99,41 @@ extern int (*ng_ether_output_p)(struct ifnet *ifp, struct mbuf **mp);
extern void (*ng_ether_attach_p)(struct ifnet *ifp);
extern void (*ng_ether_detach_p)(struct ifnet *ifp);
extern int (*vlan_input_p)(struct ether_header *eh, struct mbuf *m);
extern int (*vlan_input_tag_p)(struct ether_header *eh, struct mbuf *m,
u_int16_t t);
#define _VLAN_INPUT(ifp, eh, m) do { \
if (vlan_input_p != NULL) { \
if ((*vlan_input_p)(eh, m) == -1) \
(ifp)->if_noproto++; \
} else { \
m_free(m); \
(ifp)->if_noproto++; \
} \
} while (0)
#define VLAN_INPUT(ifp, eh, m) do { \
/* XXX: lock */ \
_VLAN_INPUT(ifp, eh, m); \
/* XXX: unlock */ \
} while (0)
#define _VLAN_INPUT_TAG(ifp, eh, m, t) do { \
if (vlan_input_tag_p != NULL) { \
if ((*vlan_input_tag_p)(eh, m, t) == -1) \
(ifp)->if_noproto++; \
} else { \
m_free(m); \
(ifp)->if_noproto++; \
} \
} while (0)
#define VLAN_INPUT_TAG(ifp, eh, m, t) do { \
/* XXX: lock */ \
_VLAN_INPUT_TAG(ifp, eh, m, t); \
/* XXX: unlock */ \
} while (0)
#else /* _KERNEL */
#include <sys/cdefs.h>

View File

@ -101,11 +101,6 @@ extern u_char aarp_org_code[3];
#include <net/bridge.h>
#endif
#include "vlan.h"
#if NVLAN > 0
#include <net/if_vlan_var.h>
#endif /* NVLAN > 0 */
/* netgraph node hooks for ng_ether(4) */
void (*ng_ether_input_p)(struct ifnet *ifp,
struct mbuf **mp, struct ether_header *eh);
@ -115,6 +110,10 @@ int (*ng_ether_output_p)(struct ifnet *ifp, struct mbuf **mp);
void (*ng_ether_attach_p)(struct ifnet *ifp);
void (*ng_ether_detach_p)(struct ifnet *ifp);
int (*vlan_input_p)(struct ether_header *eh, struct mbuf *m);
int (*vlan_input_tag_p)(struct ether_header *eh, struct mbuf *m,
u_int16_t t);
static int ether_resolvemulti __P((struct ifnet *, struct sockaddr **,
struct sockaddr *));
u_char etherbroadcastaddr[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
@ -524,14 +523,6 @@ ether_demux(ifp, eh, m)
ether_type = ntohs(eh->ether_type);
#if NVLAN > 0
if (ether_type == vlan_proto) {
if (vlan_input(eh, m) < 0)
ifp->if_data.ifi_noproto++;
return;
}
#endif /* NVLAN > 0 */
switch (ether_type) {
#ifdef INET
case ETHERTYPE_IP:
@ -582,6 +573,9 @@ ether_demux(ifp, eh, m)
aarpinput(IFP2AC(ifp), m); /* XXX */
return;
#endif NETATALK
case ETHERTYPE_VLAN:
VLAN_INPUT(ifp, eh, m);
return;
default:
#ifdef IPX
if (ef_inputp && ef_inputp(ifp, eh, m) == 0)

View File

@ -54,7 +54,6 @@
* tag value that goes with it.
*/
#include "vlan.h"
#include "opt_inet.h"
#include <sys/param.h>
@ -67,6 +66,8 @@
#include <sys/sockio.h>
#include <sys/sysctl.h>
#include <sys/systm.h>
#include <machine/bus.h> /* XXX: Shouldn't really be required! */
#include <sys/rman.h>
#include <net/bpf.h>
#include <net/ethernet.h>
@ -81,23 +82,32 @@
#include <netinet/if_ether.h>
#endif
#define VLANNAME "vlan"
#define VLAN_MAXUNIT 0x7fff /* ifp->if_unit is only 15 bits */
SYSCTL_DECL(_net_link);
SYSCTL_NODE(_net_link, IFT_L2VLAN, vlan, CTLFLAG_RW, 0, "IEEE 802.1Q VLAN");
SYSCTL_NODE(_net_link_vlan, PF_LINK, link, CTLFLAG_RW, 0, "for consistency");
u_int vlan_proto = ETHERTYPE_VLAN;
SYSCTL_INT(_net_link_vlan_link, VLANCTL_PROTO, proto, CTLFLAG_RW, &vlan_proto,
0, "Ethernet protocol used for VLAN encapsulation");
static struct ifvlan ifv_softc[NVLAN];
static MALLOC_DEFINE(M_VLAN, "vlan", "802.1Q Virtual LAN Interface");
static struct rman vlanunits[1];
static LIST_HEAD(, ifvlan) ifv_list;
static int vlan_clone_create(struct if_clone *, int *);
static void vlan_clone_destroy(struct ifnet *);
static void vlan_start(struct ifnet *ifp);
static void vlan_ifinit(void *foo);
static int vlan_input(struct ether_header *eh, struct mbuf *m);
static int vlan_input_tag(struct ether_header *eh, struct mbuf *m,
u_int16_t t);
static int vlan_ioctl(struct ifnet *ifp, u_long cmd, caddr_t addr);
static int vlan_setmulti(struct ifnet *ifp);
static int vlan_unconfig(struct ifnet *ifp);
static int vlan_config(struct ifvlan *ifv, struct ifnet *p);
struct if_clone vlan_cloner =
IF_CLONE_INITIALIZER("vlan", vlan_clone_create, vlan_clone_destroy);
/*
* Program our multicast filter. What we're actually doing is
* programming the multicast filter of the parent. This has the
@ -142,14 +152,14 @@ vlan_setmulti(struct ifnet *ifp)
if (error)
return(error);
SLIST_REMOVE_HEAD(&sc->vlan_mc_listhead, mc_entries);
free(mc, M_DEVBUF);
free(mc, M_VLAN);
}
/* Now program new ones. */
TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
if (ifma->ifma_addr->sa_family != AF_LINK)
continue;
mc = malloc(sizeof(struct vlan_mc_entry), M_DEVBUF, M_WAITOK);
mc = malloc(sizeof(struct vlan_mc_entry), M_VLAN, M_WAITOK);
bcopy(LLADDR((struct sockaddr_dl *)ifma->ifma_addr),
(char *)&mc->mc_addr, ETHER_ADDR_LEN);
SLIST_INSERT_HEAD(&sc->vlan_mc_listhead, mc, mc_entries);
@ -163,44 +173,40 @@ vlan_setmulti(struct ifnet *ifp)
return(0);
}
static void
vlaninit(void)
{
int i;
for (i = 0; i < NVLAN; i++) {
struct ifnet *ifp = &ifv_softc[i].ifv_if;
ifp->if_softc = &ifv_softc[i];
ifp->if_name = "vlan";
ifp->if_unit = i;
/* NB: flags are not set here */
ifp->if_linkmib = &ifv_softc[i].ifv_mib;
ifp->if_linkmiblen = sizeof ifv_softc[i].ifv_mib;
/* NB: mtu is not set here */
ifp->if_init = vlan_ifinit;
ifp->if_start = vlan_start;
ifp->if_ioctl = vlan_ioctl;
ifp->if_output = ether_output;
ifp->if_snd.ifq_maxlen = ifqmaxlen;
ether_ifattach(ifp, ETHER_BPF_SUPPORTED);
/* Now undo some of the damage... */
ifp->if_data.ifi_type = IFT_L2VLAN;
ifp->if_data.ifi_hdrlen = EVL_ENCAPLEN;
}
}
static int
vlan_modevent(module_t mod, int type, void *data)
{
int err;
switch (type) {
case MOD_LOAD:
vlaninit();
vlanunits->rm_type = RMAN_ARRAY;
vlanunits->rm_descr = "configurable if_vlan units";
err = rman_init(vlanunits);
if (err != 0)
return (err);
err = rman_manage_region(vlanunits, 0, VLAN_MAXUNIT);
if (err != 0) {
printf("%s: vlanunits: rman_manage_region: Failed %d\n",
VLANNAME, err);
rman_fini(vlanunits);
return (err);
}
LIST_INIT(&ifv_list);
vlan_input_p = vlan_input;
vlan_input_tag_p = vlan_input_tag;
if_clone_attach(&vlan_cloner);
break;
case MOD_UNLOAD:
printf("if_vlan module unload - not possible for this module type\n");
return EINVAL;
if_clone_detach(&vlan_cloner);
vlan_input_p = NULL;
vlan_input_tag_p = NULL;
while (!LIST_EMPTY(&ifv_list))
vlan_clone_destroy(&LIST_FIRST(&ifv_list)->ifv_if);
err = rman_fini(vlanunits);
if (err != 0)
return (err);
break;
}
return 0;
}
@ -213,6 +219,80 @@ static moduledata_t vlan_mod = {
DECLARE_MODULE(if_vlan, vlan_mod, SI_SUB_PSEUDO, SI_ORDER_ANY);
static int
vlan_clone_create(struct if_clone *ifc, int *unit)
{
struct resource *r;
struct ifvlan *ifv;
struct ifnet *ifp;
int s;
if (*unit > VLAN_MAXUNIT)
return (ENXIO);
if (*unit < 0) {
r = rman_reserve_resource(vlanunits, 0, VLAN_MAXUNIT, 1,
RF_ALLOCATED | RF_ACTIVE, NULL);
if (r == NULL)
return (ENOSPC);
*unit = rman_get_start(r);
} else {
r = rman_reserve_resource(vlanunits, *unit, *unit, 1,
RF_ALLOCATED | RF_ACTIVE, NULL);
if (r == NULL)
return (EEXIST);
}
ifv = malloc(sizeof(struct ifvlan), M_VLAN, M_WAITOK);
memset(ifv, 0, sizeof(struct ifvlan));
ifp = &ifv->ifv_if;
SLIST_INIT(&ifv->vlan_mc_listhead);
s = splnet();
LIST_INSERT_HEAD(&ifv_list, ifv, ifv_list);
splx(s);
ifp->if_softc = ifv;
ifp->if_name = "vlan";
ifp->if_unit = *unit;
ifv->r_unit = r;
/* NB: flags are not set here */
ifp->if_linkmib = &ifv->ifv_mib;
ifp->if_linkmiblen = sizeof ifv->ifv_mib;
/* NB: mtu is not set here */
ifp->if_init = vlan_ifinit;
ifp->if_start = vlan_start;
ifp->if_ioctl = vlan_ioctl;
ifp->if_output = ether_output;
ifp->if_snd.ifq_maxlen = ifqmaxlen;
ether_ifattach(ifp, ETHER_BPF_SUPPORTED);
/* Now undo some of the damage... */
ifp->if_data.ifi_type = IFT_L2VLAN;
ifp->if_data.ifi_hdrlen = EVL_ENCAPLEN;
return (0);
}
static void
vlan_clone_destroy(struct ifnet *ifp)
{
struct ifvlan *ifv = ifp->if_softc;
int s;
int err;
s = splnet();
LIST_REMOVE(ifv, ifv_list);
vlan_unconfig(ifp);
splx(s);
ether_ifdetach(ifp, ETHER_BPF_SUPPORTED);
err = rman_release_resource(ifv->r_unit);
KASSERT(err == 0, ("Unexpected error freeing resource"));
free(ifv, M_VLAN);
}
static void
vlan_ifinit(void *foo)
{
@ -294,7 +374,7 @@ vlan_start(struct ifnet *ifp)
sizeof(struct ether_header));
evl = mtod(m, struct ether_vlan_header *);
evl->evl_proto = evl->evl_encap_proto;
evl->evl_encap_proto = htons(vlan_proto);
evl->evl_encap_proto = htons(ETHERTYPE_VLAN);
evl->evl_tag = htons(ifv->ifv_tag);
#ifdef DEBUG
printf("vlan_start: %*D\n", sizeof *evl,
@ -316,19 +396,18 @@ vlan_start(struct ifnet *ifp)
return;
}
int
static int
vlan_input_tag(struct ether_header *eh, struct mbuf *m, u_int16_t t)
{
int i;
struct ifvlan *ifv;
for (i = 0; i < NVLAN; i++) {
ifv = &ifv_softc[i];
for (ifv = LIST_FIRST(&ifv_list); ifv != NULL;
ifv = LIST_NEXT(ifv, ifv_list)) {
if (ifv->ifv_tag == t)
break;
}
if (i >= NVLAN || (ifv->ifv_if.if_flags & IFF_UP) == 0) {
if (ifv !=NULL || (ifv->ifv_if.if_flags & IFF_UP) == 0) {
m_free(m);
return -1; /* So the parent can take note */
}
@ -345,21 +424,20 @@ vlan_input_tag(struct ether_header *eh, struct mbuf *m, u_int16_t t)
return 0;
}
int
static int
vlan_input(struct ether_header *eh, struct mbuf *m)
{
int i;
struct ifvlan *ifv;
for (i = 0; i < NVLAN; i++) {
ifv = &ifv_softc[i];
for (ifv = LIST_FIRST(&ifv_list); ifv != NULL;
ifv = LIST_NEXT(ifv, ifv_list)) {
if (m->m_pkthdr.rcvif == ifv->ifv_p
&& (EVL_VLANOFTAG(ntohs(*mtod(m, u_int16_t *)))
== ifv->ifv_tag))
break;
}
if (i >= NVLAN || (ifv->ifv_if.if_flags & IFF_UP) == 0) {
if (ifv != NULL || (ifv->ifv_if.if_flags & IFF_UP) == 0) {
m_freem(m);
return -1; /* so ether_input can take note */
}
@ -462,7 +540,7 @@ vlan_unconfig(struct ifnet *ifp)
if (error)
return(error);
SLIST_REMOVE_HEAD(&ifv->vlan_mc_listhead, mc_entries);
free(mc, M_DEVBUF);
free(mc, M_VLAN);
}
}

View File

@ -47,6 +47,8 @@ struct ifvlan {
u_int16_t ifvm_tag; /* tag to apply on packets leaving if */
} ifv_mib;
SLIST_HEAD(__vlan_mchead, vlan_mc_entry) vlan_mc_listhead;
LIST_ENTRY(ifvlan) ifv_list;
struct resource *r_unit; /* resource allocated for this unit */
};
#define ifv_if ifv_ac.ac_if
#define ifv_tag ifv_mib.ifvm_tag
@ -78,12 +80,4 @@ struct vlanreq {
#define SIOCSETVLAN SIOCSIFGENERIC
#define SIOCGETVLAN SIOCGIFGENERIC
#ifdef _KERNEL
/* shared with if_ethersubr.c: */
extern u_int vlan_proto;
extern int vlan_input(struct ether_header *eh, struct mbuf *m);
extern int vlan_input_tag(struct ether_header *eh,
struct mbuf *m, u_int16_t t);
#endif
#endif /* _NET_IF_VLAN_VAR_H_ */

View File

@ -78,8 +78,6 @@
* - Andrew Gallatin for providing FreeBSD/Alpha support.
*/
#include "vlan.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/sockio.h>
@ -94,13 +92,10 @@
#include <net/ethernet.h>
#include <net/if_dl.h>
#include <net/if_media.h>
#include <net/bpf.h>
#if NVLAN > 0
#include <net/if_types.h>
#include <net/if_vlan_var.h>
#endif
#include <net/bpf.h>
#include <netinet/in_systm.h>
#include <netinet/in.h>
@ -1334,9 +1329,7 @@ static int ti_gibinit(sc)
if (sc->arpcom.ac_if.if_hwassist)
rcb->ti_flags |= TI_RCB_FLAG_TCP_UDP_CKSUM |
TI_RCB_FLAG_IP_CKSUM | TI_RCB_FLAG_NO_PHDR_CKSUM;
#if NVLAN > 0
rcb->ti_flags |= TI_RCB_FLAG_VLAN_ASSIST;
#endif
/* Set up the jumbo receive ring. */
rcb = &sc->ti_rdata->ti_info.ti_jumbo_rx_rcb;
@ -1347,9 +1340,7 @@ static int ti_gibinit(sc)
if (sc->arpcom.ac_if.if_hwassist)
rcb->ti_flags |= TI_RCB_FLAG_TCP_UDP_CKSUM |
TI_RCB_FLAG_IP_CKSUM | TI_RCB_FLAG_NO_PHDR_CKSUM;
#if NVLAN > 0
rcb->ti_flags |= TI_RCB_FLAG_VLAN_ASSIST;
#endif
/*
* Set up the mini ring. Only activated on the
@ -1367,9 +1358,7 @@ static int ti_gibinit(sc)
if (sc->arpcom.ac_if.if_hwassist)
rcb->ti_flags |= TI_RCB_FLAG_TCP_UDP_CKSUM |
TI_RCB_FLAG_IP_CKSUM | TI_RCB_FLAG_NO_PHDR_CKSUM;
#if NVLAN > 0
rcb->ti_flags |= TI_RCB_FLAG_VLAN_ASSIST;
#endif
/*
* Set up the receive return ring.
@ -1403,9 +1392,7 @@ static int ti_gibinit(sc)
rcb->ti_flags = 0;
else
rcb->ti_flags = TI_RCB_FLAG_HOST_RING;
#if NVLAN > 0
rcb->ti_flags |= TI_RCB_FLAG_VLAN_ASSIST;
#endif
if (sc->arpcom.ac_if.if_hwassist)
rcb->ti_flags |= TI_RCB_FLAG_TCP_UDP_CKSUM |
TI_RCB_FLAG_IP_CKSUM | TI_RCB_FLAG_NO_PHDR_CKSUM;
@ -1738,22 +1725,18 @@ static void ti_rxeof(sc)
u_int32_t rxidx;
struct ether_header *eh;
struct mbuf *m = NULL;
#if NVLAN > 0
u_int16_t vlan_tag = 0;
int have_tag = 0;
#endif
cur_rx =
&sc->ti_rdata->ti_rx_return_ring[sc->ti_rx_saved_considx];
rxidx = cur_rx->ti_idx;
TI_INC(sc->ti_rx_saved_considx, TI_RETURN_RING_CNT);
#if NVLAN > 0
if (cur_rx->ti_flags & TI_BDFLAG_VLAN_TAG) {
have_tag = 1;
vlan_tag = cur_rx->ti_vlan_tag & 0xfff;
}
#endif
if (cur_rx->ti_flags & TI_BDFLAG_JUMBO_RING) {
TI_INC(sc->ti_jumbo, TI_JUMBO_RX_RING_CNT);
@ -1815,17 +1798,15 @@ static void ti_rxeof(sc)
m->m_pkthdr.csum_data = cur_rx->ti_tcp_udp_cksum;
}
#if NVLAN > 0
/*
* If we received a packet with a vlan tag, pass it
* to vlan_input() instead of ether_input().
*/
if (have_tag) {
vlan_input_tag(eh, m, vlan_tag);
VLAN_INPUT_TAG(ifp, eh, m, vlan_tag);
have_tag = vlan_tag = 0;
continue;
}
#endif
ether_input(ifp, eh, m);
}
@ -1963,14 +1944,12 @@ static int ti_encap(sc, m_head, txidx)
struct mbuf *m;
u_int32_t frag, cur, cnt = 0;
u_int16_t csum_flags = 0;
#if NVLAN > 0
struct ifvlan *ifv = NULL;
if ((m_head->m_flags & (M_PROTO1|M_PKTHDR)) == (M_PROTO1|M_PKTHDR) &&
m_head->m_pkthdr.rcvif != NULL &&
m_head->m_pkthdr.rcvif->if_type == IFT_L2VLAN)
ifv = m_head->m_pkthdr.rcvif->if_softc;
#endif
m = m_head;
cur = frag = *txidx;
@ -2013,14 +1992,14 @@ static int ti_encap(sc, m_head, txidx)
TI_HOSTADDR(f->ti_addr) = vtophys(mtod(m, vm_offset_t));
f->ti_len = m->m_len;
f->ti_flags = csum_flags;
#if NVLAN > 0
if (ifv != NULL) {
f->ti_flags |= TI_BDFLAG_VLAN_TAG;
f->ti_vlan_tag = ifv->ifv_tag & 0xfff;
} else {
f->ti_vlan_tag = 0;
}
#endif
/*
* Sanity check: avoid coming within 16 descriptors
* of the end of the ring.