From 7543a315d882308d72be69e1a207f521fad9bc02 Mon Sep 17 00:00:00 2001 From: Brad Smith Date: Sun, 17 Apr 2005 23:02:03 +0000 Subject: - In vlan_input()/vlan_input_tag(), always mask off all but the VLID bits from tags extracted from received frames. (Some drivers may already do this masking internally, but doing it here doesn't hurt and insures consistency.) - In vlan_ioctl(), don't let the user set a VLAN ID value with anything besides the VLID bits set, otherwise we will have trouble matching an interface in vlan_input() later. - Set the interface speed back to zero after ether_ifattach(). RFC 2863 says: "For a sub-layer which has no concept of bandwidth, [ifSpeed] should be zero." - Do not call if_down() on a parent interface if it's already down. From FreeBSD Tested by camield@ and Alexey E. Suslikov ok camield@ --- sys/net/if_vlan.c | 29 ++++++++++++++--------------- sys/net/if_vlan_var.h | 5 +++-- 2 files changed, 17 insertions(+), 17 deletions(-) (limited to 'sys/net') diff --git a/sys/net/if_vlan.c b/sys/net/if_vlan.c index c0ba967e844..105f254c215 100644 --- a/sys/net/if_vlan.c +++ b/sys/net/if_vlan.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_vlan.c,v 1.48 2005/03/25 03:23:51 brad Exp $ */ +/* $OpenBSD: if_vlan.c,v 1.49 2005/04/17 23:02:02 brad Exp $ */ /* * Copyright 1998 Massachusetts Institute of Technology * @@ -88,7 +88,6 @@ LIST_HEAD(, ifvlan) *vlan_tagh; void vlan_start (struct ifnet *ifp); int vlan_ioctl (struct ifnet *ifp, u_long cmd, caddr_t addr); -int vlan_setmulti (struct ifnet *ifp); int vlan_unconfig (struct ifnet *ifp); int vlan_config (struct ifvlan *, struct ifnet *, u_int16_t); void vlanattach (int count); @@ -139,8 +138,8 @@ vlan_clone_create(struct if_clone *ifc, int unit) IFQ_SET_READY(&ifp->if_snd); if_attach(ifp); ether_ifattach(ifp); - /* Now undo some of the damage... */ + ifp->if_baudrate = 0; ifp->if_type = IFT_8021_VLAN; ifp->if_hdrlen = EVL_ENCAPLEN; @@ -403,6 +402,7 @@ vlan_config(struct ifvlan *ifv, struct ifnet *p, u_int16_t tag) return EPROTONOSUPPORT; if (ifv->ifv_p) return EBUSY; + ifv->ifv_p = p; if (p->if_capabilities & IFCAP_VLAN_MTU) @@ -429,12 +429,6 @@ vlan_config(struct ifvlan *ifv, struct ifnet *p, u_int16_t tag) */ ifv->ifv_if.if_type = p->if_type; - /* - * Inherit baudrate from the parent. An SNMP agent would use this - * information. - */ - ifv->ifv_if.if_baudrate = p->if_baudrate; - /* * If the parent interface can do hardware-assisted * VLAN encapsulation, then propagate its hardware- @@ -609,20 +603,25 @@ vlan_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data) if (vlr.vlr_parent[0] == '\0') { s = splimp(); vlan_unconfig(ifp); - if_down(ifp); - ifp->if_flags &= ~(IFF_UP|IFF_RUNNING); + if (ifp->if_flags & IFF_UP) + if_down(ifp); + ifp->if_flags &= ~IFF_RUNNING; splx(s); break; } - if (vlr.vlr_tag != EVL_VLANOFTAG(vlr.vlr_tag)) { - error = EINVAL; /* check for valid tag */ - break; - } pr = ifunit(vlr.vlr_parent); if (pr == NULL) { error = ENOENT; break; } + /* + * Don't let the caller set up a VLAN tag with + * anything except VLID bits. + */ + if (vlr.vlr_tag & ~EVL_VLID_MASK) { + error = EINVAL; + break; + } error = vlan_config(ifv, pr, vlr.vlr_tag); if (error) break; diff --git a/sys/net/if_vlan_var.h b/sys/net/if_vlan_var.h index 63ba2ff39bc..cefe543a032 100644 --- a/sys/net/if_vlan_var.h +++ b/sys/net/if_vlan_var.h @@ -1,4 +1,4 @@ -/* $OpenBSD: if_vlan_var.h,v 1.11 2004/02/12 18:07:29 henning Exp $ */ +/* $OpenBSD: if_vlan_var.h,v 1.12 2005/04/17 23:02:02 brad Exp $ */ /* * Copyright 1998 Massachusetts Institute of Technology @@ -71,7 +71,8 @@ struct ether_vlan_header { u_int16_t evl_proto; }; -#define EVL_VLANOFTAG(tag) ((tag) & 4095) +#define EVL_VLID_MASK 0x0FFF +#define EVL_VLANOFTAG(tag) ((tag) & EVL_VLID_MASK) #define EVL_PRIOFTAG(tag) (((tag) >> 13) & 7) #define EVL_ENCAPLEN 4 /* length in octets of encapsulation */ -- cgit v1.2.3