From: Chengen Du <chengen.du@canonical.com>
To: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
pabeni@redhat.com, kaber@trash.net, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH v6] af_packet: Handle outgoing VLAN packets without hardware offloading
Date: Wed, 12 Jun 2024 16:47:02 +0800 [thread overview]
Message-ID: <CAPza5qe8KAjjZsZdTupXx27kvdPzhBNcDC=Nk5Xjc4O2obEAAA@mail.gmail.com> (raw)
In-Reply-To: <666789d3d9d2a_bf52c294e9@willemb.c.googlers.com.notmuch>
Hi Willem,
On Tue, Jun 11, 2024 at 7:18 AM Willem de Bruijn
<willemdebruijn.kernel@gmail.com> wrote:
>
> Chengen Du wrote:
> > Hi Willem,
> >
> > I'm sorry, but I would like to confirm the issue further.
> >
> > On Mon, Jun 10, 2024 at 4:19 AM Willem de Bruijn
> > <willemdebruijn.kernel@gmail.com> wrote:
> > >
> > > Chengen Du wrote:
> > > > The issue initially stems from libpcap. The ethertype will be overwritten
> > > > as the VLAN TPID if the network interface lacks hardware VLAN offloading.
> > > > In the outbound packet path, if hardware VLAN offloading is unavailable,
> > > > the VLAN tag is inserted into the payload but then cleared from the sk_buff
> > > > struct. Consequently, this can lead to a false negative when checking for
> > > > the presence of a VLAN tag, causing the packet sniffing outcome to lack
> > > > VLAN tag information (i.e., TCI-TPID). As a result, the packet capturing
> > > > tool may be unable to parse packets as expected.
> > > >
> > > > The TCI-TPID is missing because the prb_fill_vlan_info() function does not
> > > > modify the tp_vlan_tci/tp_vlan_tpid values, as the information is in the
> > > > payload and not in the sk_buff struct. The skb_vlan_tag_present() function
> > > > only checks vlan_all in the sk_buff struct. In cooked mode, the L2 header
> > > > is stripped, preventing the packet capturing tool from determining the
> > > > correct TCI-TPID value. Additionally, the protocol in SLL is incorrect,
> > > > which means the packet capturing tool cannot parse the L3 header correctly.
> > > >
> > > > Link: https://github.com/the-tcpdump-group/libpcap/issues/1105
> > > > Link: https://lore.kernel.org/netdev/20240520070348.26725-1-chengen.du@canonical.com/T/#u
> > > > Fixes: 393e52e33c6c ("packet: deliver VLAN TCI to userspace")
> > > > Cc: stable@vger.kernel.org
> > > > Signed-off-by: Chengen Du <chengen.du@canonical.com>
> > >
> > > Overall, solid.
> > >
> > > > ---
> > > > net/packet/af_packet.c | 57 ++++++++++++++++++++++++++++++++++++++++--
> > > > 1 file changed, 55 insertions(+), 2 deletions(-)
> > > >
> > > > diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
> > > > index ea3ebc160e25..8cffbe1f912d 100644
> > > > --- a/net/packet/af_packet.c
> > > > +++ b/net/packet/af_packet.c
> > > > @@ -538,6 +538,43 @@ static void *packet_current_frame(struct packet_sock *po,
> > > > return packet_lookup_frame(po, rb, rb->head, status);
> > > > }
> > > >
> > > > +static u16 vlan_get_tci(struct sk_buff *skb)
> > > > +{
> > > > + struct vlan_hdr vhdr, *vh;
> > > > + u8 *skb_orig_data = skb->data;
> > > > + int skb_orig_len = skb->len;
> > > > +
> > > > + skb_push(skb, skb->data - skb_mac_header(skb));
> > > > + vh = skb_header_pointer(skb, ETH_HLEN, sizeof(vhdr), &vhdr);
> > >
> > > Don't harcode Ethernet.
> > >
> > > According to documentation VLANs are used with other link layers.
> > >
> > > More importantly, in practice PF_PACKET allows inserting this
> > > skb->protocol on any device.
> > >
> > > We don't use link layer specific constants anywhere in the packet
> > > socket code for this reason. But instead dev->hard_header_len.
> > >
> > > One caveat there is variable length link layer headers, where
> > > dev->min_header_len != dev->hard_header_len. Will just have to fail
> > > on those.
> >
> > Thank you for pointing out this error. I would like to confirm if I
> > need to use dev->hard_header_len to get the correct header length and
> > return zero if dev->min_header_len != dev->hard_header_len to handle
> > variable-length link layer headers. Is there something I
> > misunderstand, or are there other aspects I need to consider further?
>
> That's right.
>
> The min_header_len != hard_header_len check is annoying and may seem
> pedantic. But it's the only way to trust that the next header starts
> at hard_header_len.
Thank you for your advice.
I have implemented the modification, but I found that the
(min_header_len != hard_header_len) check results in unexpected
behavior in the following test scenario:
ip link add link ens18 ens18.24 type vlan proto 802.1ad id 24
ip link add link ens18.24 ens18.24.25 type vlan proto 802.1Q id 25
ifconfig ens18.24 1.0.24.1/24
ifconfig ens18.24.25 1.0.25.1/24
ping -n 1.0.25.3 > /dev/null 2>&1 &
tcpdump -nn -i any -y LINUX_SLL -Q out not tcp and not udp
While receiving a packet from ens18.24.25 (802.1Q), the min_header_len
and hard_header_len are 14 and 18, respectively.
This check results in the TCI being 0 instead of 25.
Should we skip this check to display the correct value, or is there
another check that can achieve the same purpose?
next prev parent reply other threads:[~2024-06-12 8:47 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-08 2:53 [PATCH v6] af_packet: Handle outgoing VLAN packets without hardware offloading Chengen Du
2024-06-08 3:07 ` Chengen Du
2024-06-09 20:21 ` Willem de Bruijn
2024-06-10 15:33 ` Chengen Du
2024-06-10 23:23 ` Willem de Bruijn
2024-06-09 20:19 ` Willem de Bruijn
2024-06-10 15:06 ` Chengen Du
2024-06-10 23:18 ` Willem de Bruijn
2024-06-12 8:47 ` Chengen Du [this message]
2024-06-12 14:07 ` Willem de Bruijn
2024-06-13 13:47 ` Chengen Du
2024-06-14 9:39 ` Willem de Bruijn
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='CAPza5qe8KAjjZsZdTupXx27kvdPzhBNcDC=Nk5Xjc4O2obEAAA@mail.gmail.com' \
--to=chengen.du@canonical.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kaber@trash.net \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=stable@vger.kernel.org \
--cc=willemdebruijn.kernel@gmail.com \
/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