From owner-freebsd-net@FreeBSD.ORG Sat Feb 10 18:28:44 2007 Return-Path: X-Original-To: freebsd-net@freebsd.org Delivered-To: freebsd-net@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 0766616A400 for ; Sat, 10 Feb 2007 18:28:44 +0000 (UTC) (envelope-from bms@FreeBSD.org) Received: from out5.smtp.messagingengine.com (out5.smtp.messagingengine.com [66.111.4.29]) by mx1.freebsd.org (Postfix) with ESMTP id BE0FB13C49D for ; Sat, 10 Feb 2007 18:28:43 +0000 (UTC) (envelope-from bms@FreeBSD.org) Received: from out1.internal (unknown [10.202.2.149]) by out1.messagingengine.com (Postfix) with ESMTP id 10F511AA5A4 for ; Sat, 10 Feb 2007 13:28:42 -0500 (EST) Received: from heartbeat1.messagingengine.com ([10.202.2.160]) by out1.internal (MEProxy); Sat, 10 Feb 2007 13:28:42 -0500 X-Sasl-enc: nYCcm0Awt1WYZ47eo33+ireFqi32xCj4vaNwqvrTLVt/ 1171132121 Received: from [192.168.123.18] (82-35-112-254.cable.ubr07.dals.blueyonder.co.uk [82.35.112.254]) by mail.messagingengine.com (Postfix) with ESMTP id 638F42A45C for ; Sat, 10 Feb 2007 13:28:41 -0500 (EST) Message-ID: <45CE0ED9.1010905@FreeBSD.org> Date: Sat, 10 Feb 2007 18:28:41 +0000 From: "Bruce M. Simpson" User-Agent: Thunderbird 1.5.0.9 (X11/20070125) MIME-Version: 1.0 To: freebsd-net@freebsd.org References: <45CDFA18.3030102@incunabulum.net> In-Reply-To: <45CDFA18.3030102@incunabulum.net> Content-Type: multipart/mixed; boundary="------------010103080400010007000103" Subject: [PATCH] Part 2 of low level 802.1p priority support X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 10 Feb 2007 18:28:44 -0000 This is a multi-part message in MIME format. --------------010103080400010007000103 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit This updated patch moves VLAN tag decapsulation into if_ethersubr.c and always uses M_VLANTAG, which is also passed to the upper layer. Tests with ping: fxp (no VLAN_HWTAGGING support) OK msk (VLAN_HWTAGGING enabled) OK msk (VLAN_HWTAGGING disanabled) FAIL I am concerned that this may need review and testing to support situations where we do nested VLANs or with bridge(4) before it can be committed. Further testing with drivers is needed (I can't be 100% sure it fails with msk(4) because something strange is happening when vlan tagging is turned off). Perhaps Pyun knows? Regards, BMS --------------010103080400010007000103 Content-Type: text/x-patch; name="8021q-part2.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="8021q-part2.diff" Index: if_ethersubr.c =================================================================== RCS file: /home/ncvs/src/sys/net/if_ethersubr.c,v retrieving revision 1.222 diff -u -p -r1.222 if_ethersubr.c --- if_ethersubr.c 24 Dec 2006 08:52:13 -0000 1.222 +++ if_ethersubr.c 10 Feb 2007 18:16:54 -0000 @@ -701,43 +701,50 @@ post_stats: } } #endif - /* - * Check to see if the device performed the VLAN decapsulation and - * provided us with the tag. + * If the device did not perform decapsulation of the 802.1q VLAN + * header itself, do this now, and tag the mbuf with M_VLANTAG. + * Remove the 802.1q header by copying the Ethernet addresses over + * it and adjusting the beginning of the data in the mbuf. + * Re-inspect the ether_type field so we do the right thing + * for VLAN 0. */ - if (m->m_flags & M_VLANTAG) { - /* - * If no VLANs are configured, drop. - */ - if (ifp->if_vlantrunk == NULL) { - ifp->if_noproto++; - m_freem(m); + if ((ether_type == ETHERTYPE_VLAN) && !(m->m_flags & M_VLANTAG)) { + struct ether_vlan_header *evl; + + if (m->m_len < sizeof(*evl) && + (m = m_pullup(m, sizeof(*evl))) == NULL) { + if_printf(ifp, "cannot pullup VLAN header\n"); return; } - /* - * vlan_input() will either recursively call ether_input() - * or drop the packet. - */ - KASSERT(vlan_input_p != NULL,("ether_input: VLAN not loaded!")); - (*vlan_input_p)(ifp, m); - return; + + evl = mtod(m, struct ether_vlan_header *); + m->m_pkthdr.ether_vtag = ntohs(evl->evl_tag); + m->m_flags |= M_VLANTAG; + bcopy((char *)evl, (char *)evl + ETHER_VLAN_ENCAP_LEN, + ETHER_HDR_LEN - ETHER_TYPE_LEN); + m_adj(m, ETHER_VLAN_ENCAP_LEN); + /* We need to see the inner type field in case of reentry. */ + eh = mtod(m, struct ether_header *); + ether_type = ntohs(eh->ether_type); } /* - * Handle protocols that expect to have the Ethernet header - * (and possibly FCS) intact. + * Deal with numbered 802.1q VLANs, by passing these frames to + * the VLAN input handler. Frames destined for VLAN 0 are for + * the main input path. Otherwise, drop frames with VLAN tags. */ - switch (ether_type) { - case ETHERTYPE_VLAN: + if ((m->m_flags & M_VLANTAG) && + EVL_VLANOFTAG(m->m_pkthdr.ether_vtag) != EVL_VLAN_ZERO) { if (ifp->if_vlantrunk != NULL) { - KASSERT(vlan_input_p,("ether_input: VLAN not loaded!")); + KASSERT(vlan_input_p, + ("ether_input: VLAN not loaded!")); (*vlan_input_p)(ifp, m); } else { ifp->if_noproto++; m_freem(m); + return; } - return; } /* Strip off Ethernet header. */ Index: if_vlan.c =================================================================== RCS file: /home/ncvs/src/sys/net/if_vlan.c,v retrieving revision 1.117 diff -u -p -r1.117 if_vlan.c --- if_vlan.c 30 Dec 2006 21:10:25 -0000 1.117 +++ if_vlan.c 10 Feb 2007 18:16:54 -0000 @@ -911,51 +911,9 @@ vlan_input(struct ifnet *ifp, struct mbu uint16_t tag; KASSERT(trunk != NULL, ("%s: no trunk", __func__)); + KASSERT((m->m_flags & M_VLANTAG),("%s: M_VLANTAG not set", __func__)); - if (m->m_flags & M_VLANTAG) { - /* - * Packet is tagged, but m contains a normal - * Ethernet frame; the tag is stored out-of-band. - */ - tag = EVL_VLANOFTAG(m->m_pkthdr.ether_vtag); - m->m_flags &= ~M_VLANTAG; - } else { - struct ether_vlan_header *evl; - - /* - * Packet is tagged in-band as specified by 802.1q. - */ - switch (ifp->if_type) { - case IFT_ETHER: - if (m->m_len < sizeof(*evl) && - (m = m_pullup(m, sizeof(*evl))) == NULL) { - if_printf(ifp, "cannot pullup VLAN header\n"); - return; - } - evl = mtod(m, struct ether_vlan_header *); - tag = EVL_VLANOFTAG(ntohs(evl->evl_tag)); - - /* - * Remove the 802.1q header by copying the Ethernet - * addresses over it and adjusting the beginning of - * the data in the mbuf. The encapsulated Ethernet - * type field is already in place. - */ - bcopy((char *)evl, (char *)evl + ETHER_VLAN_ENCAP_LEN, - ETHER_HDR_LEN - ETHER_TYPE_LEN); - m_adj(m, ETHER_VLAN_ENCAP_LEN); - break; - - default: -#ifdef INVARIANTS - panic("%s: %s has unsupported if_type %u", - __func__, ifp->if_xname, ifp->if_type); -#endif - m_freem(m); - ifp->if_noproto++; - return; - } - } + tag = EVL_VLANOFTAG(m->m_pkthdr.ether_vtag); TRUNK_RLOCK(trunk); #ifdef VLAN_ARRAY Index: if_vlan_var.h =================================================================== RCS file: /home/ncvs/src/sys/net/if_vlan_var.h,v retrieving revision 1.25 diff -u -p -r1.25 if_vlan_var.h --- if_vlan_var.h 17 Sep 2006 13:33:29 -0000 1.25 +++ if_vlan_var.h 10 Feb 2007 18:16:54 -0000 @@ -43,6 +43,7 @@ struct ether_vlan_header { #define EVL_VLID_MASK 0x0FFF #define EVL_VLANOFTAG(tag) ((tag) & EVL_VLID_MASK) #define EVL_PRIOFTAG(tag) (((tag) >> 13) & 7) +#define EVL_VLAN_ZERO 0 /* 802.1p priority frames use VLAN 0. */ /* sysctl(3) tags, for compatibility purposes */ #define VLANCTL_PROTO 1 --------------010103080400010007000103--