public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Eric Woudstra <ericwouds@gmail.com>
Cc: Florian Westphal <fw@strlen.de>, Phil Sutter <phil@nwl.cc>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Simon Horman <horms@kernel.org>,
	netfilter-devel@vger.kernel.org, netdev@vger.kernel.org
Subject: Re: [PATCH v2 nf] netfilter: nf_flow_table_ip: Introduce nf_flow_vlan_push()
Date: Tue, 10 Mar 2026 11:33:44 +0100	[thread overview]
Message-ID: <aa_ziMdBBa1kHNhl@chamomile> (raw)
In-Reply-To: <5f8c4194-5066-4a55-898f-257bfdce4a6c@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 3099 bytes --]

On Tue, Mar 10, 2026 at 09:25:46AM +0100, Eric Woudstra wrote:
> 
> 
> On 3/9/26 10:22 PM, Florian Westphal wrote:
> > Eric Woudstra <ericwouds@gmail.com> wrote:
> > 
> > Hi Eric
> > 
> >> With double vlan tagged packets in the fastpath, getting the error:
> >>
> >> skb_vlan_push got skb with skb->data not at mac header (offset 18)
> >>
> >> Introduce nf_flow_vlan_push(), that can correctly push the inner vlan
> >> in the fastpath. It is closedly modelled on existing nf_flow_pppoe_push()
> >>
> >> Fixes: c653d5a78f34 ("netfilter: flowtable: inline vlan encapsulation in xmit path")
> >> Signed-off-by: Eric Woudstra <ericwouds@gmail.com>
> >   
> >> +static int nf_flow_vlan_push(struct sk_buff *skb, __be16 proto, u16 id)
> >> +{
> >> +	if (skb_vlan_tag_present(skb)) {
> >> +		struct vlan_hdr *vhdr;
> >> +
> >> +		if (skb_cow_head(skb, VLAN_HLEN))
> >> +			return -1;
> >> +
> >> +		__skb_push(skb, VLAN_HLEN);
> >> +		skb_reset_network_header(skb);
> >> +
> >> +		vhdr = (struct vlan_hdr *)(skb->data);
> >> +		vhdr->h_vlan_TCI = htons(id);
> >> +		vhdr->h_vlan_encapsulated_proto = skb->protocol;
> >> +		skb->protocol = proto;
> >> +	} else {
> >> +		__vlan_hwaccel_put_tag(skb, proto, id);
> >> +	}
> > 
> > I did not apply this because I'm not sure if this preserves correct tag
> > order.  Can you clarify?
> > 
> > Lets consider vlan-offload-doesn't-exist case.
> > 
> > First loop pushes vlan tag 1, we get:
> > 
> >   [vlan1][inet]
> 
> Always !skb_vlan_tag_present (all vlan tags are pulled before the push
> in the fastpath), so vlan1 is always stored in skb->vlan_all.
> 
> > 
> > 2nd items pushes vlan tag 2, we get:
> >   [vlan2][vlan1][inet]
> > 
> 
> The second is pushed directly [vlan2][inet]. At a later moment the
> contents of skb->vlan_all is pushed by SW. Ending up with
> [vlan1][vlan2][inet].
> 
> > Now lets consider with-offload.  We have one tag only, so we get 1 skb with hwaccel
> > tag in the sk_buff.  This is fine, HW will insert it for us.
> > 
> > But now lets consider two tags:
> > 
> > First loop pushes vlan1, we get the vlan1 tag in sk_buff vlan info.
> > Packet is: [inet].
> 
> Correct, so same as SW, vlan1 in skb->vlan_all.
> 
> > 
> > 2nd loop pushes vlan2, we get:
> > 	[vlan2][inet].
> > 
> 
> Correct, [vlan2][inet].
> 
> > Now, when packet is transmitted, where will the HW insert the tag?
> > 
> > [vlan1][vlan2][inet]?
> > Or will this be [vlan2][vlan1][inet]?
> 
> The contents of skb->vlan_all is pushed by HW. Ending up with
> [vlan1][vlan2][inet], same as SW.
> 
> Hope this is enough to clarify, but you can double-check it looking at
> nf_flow_tuple_encap(). With 2 vlan tags, the contents of skb->vlan_all,
> is always vlan1, the first in the encap array, which is the outer tag.

In your patch, if vlan offload is present, then this outer (second)
VLAN header is pushed with the outer vlan ID.

This goes against the assumption that the outer VLAN header is always
offloaded.

Probably it is easier to fix this by resetting the mac header (see
your patch).

But if you prefer, just fix your patch to be similar to
skb_vlan_push().

[-- Attachment #2: fix.patch --]
[-- Type: text/x-diff, Size: 523 bytes --]

diff --git a/net/netfilter/nf_flow_table_ip.c b/net/netfilter/nf_flow_table_ip.c
index 3fdb10d9bf7f..ab58ba0c5ff6 100644
--- a/net/netfilter/nf_flow_table_ip.c
+++ b/net/netfilter/nf_flow_table_ip.c
@@ -738,6 +738,9 @@ static int nf_flow_encap_push(struct sk_buff *skb,
 		switch (tuple->encap[i].proto) {
 		case htons(ETH_P_8021Q):
 		case htons(ETH_P_8021AD):
+			skb_reset_mac_header(skb);
+			skb_reset_mac_len(skb);
+
 			if (skb_vlan_push(skb, tuple->encap[i].proto,
 					  tuple->encap[i].id) < 0)
 				return -1;

      reply	other threads:[~2026-03-10 10:33 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-27 16:29 [PATCH v2 nf] netfilter: nf_flow_table_ip: Introduce nf_flow_vlan_push() Eric Woudstra
2026-03-09 21:22 ` Florian Westphal
2026-03-10  8:25   ` Eric Woudstra
2026-03-10 10:33     ` Pablo Neira Ayuso [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aa_ziMdBBa1kHNhl@chamomile \
    --to=pablo@netfilter.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=ericwouds@gmail.com \
    --cc=fw@strlen.de \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=phil@nwl.cc \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox