From nobody@FreeBSD.org  Thu Nov 11 17:18:59 2010
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id B6003106566B
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 11 Nov 2010 17:18:59 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id 8AA858FC13
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 11 Nov 2010 17:18:59 +0000 (UTC)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.3/8.14.3) with ESMTP id oABHIx9G040120
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 11 Nov 2010 17:18:59 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id oABHIx0H040119;
	Thu, 11 Nov 2010 17:18:59 GMT
	(envelope-from nobody)
Message-Id: <201011111718.oABHIx0H040119@www.freebsd.org>
Date: Thu, 11 Nov 2010 17:18:59 GMT
From: Rozhuk Ivan <rozhuk.im@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: encapsulate vlan in ng_ether before output to if
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         152141
>Category:       kern
>Synopsis:       [vlan] [patch] encapsulate vlan in ng_ether before output to if
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-net
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          maintainer-update
>Submitter-Id:   current-users
>Arrival-Date:   Thu Nov 11 17:20:08 UTC 2010
>Closed-Date:    
>Last-Modified:  Sun Feb 13 14:57:01 UTC 2011
>Originator:     Rozhuk Ivan
>Release:        9.0-CURRENT
>Organization:
>Environment:
FreeBSD firewall 9.0-CURRENT FreeBSD 9.0-CURRENT #9: Sun Oct 31 16:36:54 IRKT 2010     root@firewall:/usr/obj/usr/src/sys/RIMx64  amd64
>Description:
ether_input decapsulate vlan from ethernet header and
add M_VLANTAG flag to mbuff
set m->m_pkthdr.ether_vtag

then packet transmited to ng_ether_input

but(!)
ng_ether_rcv_lower does not encapsulate vlan tag before send packet

if_bridge - encapsulate
>How-To-Repeat:

>Fix:
/*
 * Handle an mbuf received on the "lower" or "orphan" hook.
 */
static int
ng_ether_rcv_lower(hook_p hook, item_p item)
{
	struct mbuf *m;
	const node_p node = NG_HOOK_NODE(hook);
	const priv_p priv = NG_NODE_PRIVATE(node);
 	struct ifnet *const ifp = priv->ifp;

	NGI_GET_M(item, m);
	NG_FREE_ITEM(item);

	/* Check whether interface is ready for packets */

	if (!((ifp->if_flags & IFF_UP) &&
	    (ifp->if_drv_flags & IFF_DRV_RUNNING))) {
		NG_FREE_M(m);
		return (ENETDOWN);
	}

	/* Make sure header is fully pulled up */
	if (m->m_pkthdr.len < sizeof(struct ether_header)) {
		NG_FREE_M(m);
		return (EINVAL);
	}
	if (m->m_len < sizeof(struct ether_header)
	    && (m = m_pullup(m, sizeof(struct ether_header))) == NULL)
		return (ENOBUFS);

	/* Drop in the MAC address if desired */
	if (priv->autoSrcAddr) {

		/* Make the mbuf writable if it's not already */
		if (!M_WRITABLE(m)
		    && (m = m_pullup(m, sizeof(struct ether_header))) == NULL)
			return (ENOBUFS);

		/* Overwrite source MAC address */
		bcopy(IF_LLADDR(ifp),
		    mtod(m, struct ether_header *)->ether_shost,
		    ETHER_ADDR_LEN);
	}

	/*
	 * If underlying interface can not do VLAN tag insertion itself
	 * then attach a packet tag that holds it.
	 */
	if ((m->m_flags & M_VLANTAG) &&
	    (ifp->if_capenable & IFCAP_VLAN_HWTAGGING) == 0) {
		m = ether_vlanencap(m, m->m_pkthdr.ether_vtag);
		if (m == NULL) {
			ifp->if_oerrors++;
			return (ENOBUFS);
		}
		m->m_flags &= ~M_VLANTAG;
	}

	/* Send it on its way */
	return ether_output_frame(ifp, m);
}


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->freebsd-net 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Fri Nov 12 21:31:41 UTC 2010 
Responsible-Changed-Why:  
Affects networking code. 

To submitter: is the code you included a patch, or a test case?  It is not 
clear to me. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=152141 

From: Mark Linimon <linimon@lonesome.com>
To: bug-followup@FreeBSD.org
Cc:  
Subject: kern/152141: [vlan] encapsulate vlan in ng_ether before output to
 if
Date: Sun, 13 Feb 2011 08:46:38 -0600

 ----- Forwarded message from Rozhuk Ivan <Rozhuk_I@mail.ru> -----
 
 From: "Rozhuk Ivan" <Rozhuk_I@mail.ru>
 To: <linimon@freebsd.org>
 Subject: kern/152141: [vlan] encapsulate vlan in ng_ether before output
 	to if
 Date: Tue, 16 Nov 2010 01:16:48 +0800
 
 This is a patched version of original function
 
 code
 	/*
 	 * If underlying interface can not do VLAN tag insertion itself
 	 * then attach a packet tag that holds it.
 	 */
 	if ((m->m_flags & M_VLANTAG) &&
 	    (ifp->if_capenable & IFCAP_VLAN_HWTAGGING) == 0) {
 		m = ether_vlanencap(m, m->m_pkthdr.ether_vtag);
 		if (m == NULL) {
 			ifp->if_oerrors++;
 			return (ENOBUFS);
 		}
 		m->m_flags &= ~M_VLANTAG;
 	}
 
 
 was added.
 
 Iam does not test this path - haven’t net with vlan support.
 
 Code was taken from if_bridge and adapted.
  
 --
 Rozhuk Ivan
 
 ----- End forwarded message -----
>Unformatted:
