Netdev Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
To: Xie He <xie.he.0141@gmail.com>
Cc: "David S. Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>,
John Ogness <john.ogness@linutronix.de>,
Mao Wenan <maowenan@huawei.com>,
Eric Dumazet <edumazet@google.com>,
Or Cohen <orcohen@paloaltonetworks.com>,
Arnd Bergmann <arnd@arndb.de>,
Network Development <netdev@vger.kernel.org>,
linux-kernel <linux-kernel@vger.kernel.org>,
Willem de Bruijn <willemdebruijn.kernel@gmail.com>,
Eric Dumazet <eric.dumazet@gmail.com>,
Brian Norris <briannorris@chromium.org>,
Cong Wang <xiyou.wangcong@gmail.com>
Subject: Re: [PATCH net] net/packet: Fix a comment about hard_header_len and headroom allocation
Date: Mon, 7 Sep 2020 11:40:21 +0200 [thread overview]
Message-ID: <CA+FuTSfOeMB7Wv1t12VCTOqPYcTLq2WKdG4AJUO=gxotVRZiQw@mail.gmail.com> (raw)
In-Reply-To: <20200906031827.16819-1-xie.he.0141@gmail.com>
On Sun, Sep 6, 2020 at 5:18 AM Xie He <xie.he.0141@gmail.com> wrote:
>
> This comment is outdated and no longer reflects the actual implementation
> of af_packet.c.
If it was previously true, can you point to a commit that changes the behavior?
>
> Reasons for the new comment:
>
> 1.
>
> In this file, the function packet_snd first reserves a headroom of
> length (dev->hard_header_len + dev->needed_headroom).
> Then if the socket is a SOCK_DGRAM socket, it calls dev_hard_header,
> which calls dev->header_ops->create, to create the link layer header.
> If the socket is a SOCK_RAW socket, it "un-reserves" a headroom of
> length (dev->hard_header_len), and checks if the user has provided a
> header of length (dev->hard_header_len) (in dev_validate_header).
Not entirely, a header greater than dev->min_header_len that passes
dev_validate_header.
> This shows the developers of af_packet.c expect hard_header_len to
> be consistent with header_ops.
>
> 2.
>
> In this file, the function packet_sendmsg_spkt has a FIXME comment.
> That comment states that prepending an LL header internally in a driver
> is considered a bug. I believe this bug can be fixed by setting
> hard_header_len to 0, making the internal header completely invisible
> to af_packet.c (and requesting the headroom in needed_headroom instead).
Ack.
> 3.
>
> There is a commit for a WiFi driver:
> commit 9454f7a895b8 ("mwifiex: set needed_headroom, not hard_header_len")
> According to the discussion about it at:
> https://patchwork.kernel.org/patch/11407493/
> The author tried to set the WiFi driver's hard_header_len to the Ethernet
> header length, and request additional header space internally needed by
> setting needed_headroom. This means this usage is already adopted by
> driver developers.
>
> Cc: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
> Cc: Eric Dumazet <eric.dumazet@gmail.com>
> Cc: Brian Norris <briannorris@chromium.org>
> Cc: Cong Wang <xiyou.wangcong@gmail.com>
> Signed-off-by: Xie He <xie.he.0141@gmail.com>
> ---
> net/packet/af_packet.c | 15 +++++++++------
> 1 file changed, 9 insertions(+), 6 deletions(-)
>
> diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
> index 2b33e977a905..c808c76efa71 100644
> --- a/net/packet/af_packet.c
> +++ b/net/packet/af_packet.c
> @@ -93,12 +93,15 @@
>
> /*
> Assumptions:
> - - if device has no dev->hard_header routine, it adds and removes ll header
> - inside itself. In this case ll header is invisible outside of device,
> - but higher levels still should reserve dev->hard_header_len.
> - Some devices are enough clever to reallocate skb, when header
> - will not fit to reserved space (tunnel), another ones are silly
> - (PPP).
> + - If the device has no dev->header_ops, there is no LL header visible
> + outside of the device. In this case, its hard_header_len should be 0.
Such a constraint is more robustly captured with a compile time
BUILD_BUG_ON check. Please do add a comment that summarizes why the
invariant holds.
More about the older comment, but if reusing: it's not entirely clear
to me what "outside of the device" means. The upper layers that
receive data from the device and send data to it, including
packet_snd, I suppose? Not the lower layers, clearly. Maybe that can
be more specific.
> + The device may prepend its own header internally. In this case, its
> + needed_headroom should be set to the space needed for it to add its
> + internal header.
> + For example, a WiFi driver pretending to be an Ethernet driver should
> + set its hard_header_len to be the Ethernet header length, and set its
> + needed_headroom to be (the real WiFi header length - the fake Ethernet
> + header length).
> - packet socket receives packets with pulled ll header,
> so that SOCK_RAW should push it back.
>
> --
> 2.25.1
>
next prev parent reply other threads:[~2020-09-07 9:41 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-06 3:18 Xie He
2020-09-07 9:40 ` Willem de Bruijn [this message]
2020-09-08 0:07 ` Xie He
2020-09-08 8:55 ` Willem de Bruijn
2020-09-08 11:27 ` Xie He
2020-09-08 13:55 ` 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='CA+FuTSfOeMB7Wv1t12VCTOqPYcTLq2WKdG4AJUO=gxotVRZiQw@mail.gmail.com' \
--to=willemdebruijn.kernel@gmail.com \
--cc=arnd@arndb.de \
--cc=briannorris@chromium.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=eric.dumazet@gmail.com \
--cc=john.ogness@linutronix.de \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maowenan@huawei.com \
--cc=netdev@vger.kernel.org \
--cc=orcohen@paloaltonetworks.com \
--cc=xie.he.0141@gmail.com \
--cc=xiyou.wangcong@gmail.com \
--subject='Re: [PATCH net] net/packet: Fix a comment about hard_header_len and headroom allocation' \
/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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).