From: "Alejandro Colomar (man-pages)" <alx.manpages@gmail.com>
To: Grzegorz Szpetkowski <gszpetkowski@gmail.com>
Cc: mtk.manpages@gmail.com, linux-man@vger.kernel.org
Subject: Re: [PATCH] packet.7: add description of zero protocol for socket
Date: Sat, 12 Feb 2022 21:34:53 +0100 [thread overview]
Message-ID: <b5bcb372-2e20-d3f0-e466-07764e8ceb71@gmail.com> (raw)
In-Reply-To: <CAMW=dunREq3s3+pZTSfKrUbS8igqidiVJd0qnZ3NPJ-5-160Og@mail.gmail.com>
Hi Grzegorz,
On 2/12/22 20:44, Grzegorz Szpetkowski wrote:
> Yes, this sounds right to me as well.
> Attaching in git diff -u form:
I applied the following patch
<http://www.alejandro-colomar.es/src/alx/linux/man-pages/man-pages.git/commit/?id=015e7241b392713f145f94cdfa9c2a68fbcb7f1d>.
Cheers,
Alex
commit 015e7241b392713f145f94cdfa9c2a68fbcb7f1d (HEAD -> main)
Author: Grzegorz Szpetkowski <gszpetkowski@gmail.com>
Date: Tue Jan 25 16:22:17 2022 +0100
packet.7: add description of zero protocol for socket
According to packet(7), whenever raw packet is created by
socket(), it's immediately running, meaning that internal
packet_rcv() handler will be triggered and socket buffer will
begin allocation of sk_buff until sk_rcvbuf limit is reached.
However, by examination of kernel's internal handler
packet_create() it looks that kernel handles case of zero protocol
in a special manner. When packet_create() is called with arg
protocol = 0, __register_prot_hook is not executed, meaning
running state is still 0 and most notably, packet handler is not
added to kernel list (vide dev_add_pack).
I found this behavior invaluable for solving a subtle issue. When
process creates raw packet socket to listen for (let's say) all
protocols, but limited to a single network interface, then while
this interface can set by bind, it may to be too late due to
preemption (e.g. if real-time scheduling is used) and/or high-rate
of packets on other interfaces, meaning that undesired packets
(any count) may be pulled into the socket buffer.
The idea is that protocol zero means no packets on receive and an
optional call to bind with nonzero sll_procol will act "as if" the
originating socket API was called with this (nonzero) protocol.
The call to bind(2) is optional. As an example, if user intends
to treat the socket as Tx-only, then bind(2) may be skipped.
Reported-by: Grzegorz Szpetkowski <gszpetkowski@gmail.com>
Link: linux-man@
<https://lore.kernel.org/linux-man/CAMW=dumhWDu6LdhaQCJMskA4yNRBtOHs4iyrG6TP7xRv28AVWA@mail.gmail.com/>
Cowritten-by: Alejandro Colomar <alx.manpages@gmail.com>
Signed-off-by: Alejandro Colomar <alx.manpages@gmail.com>
Signed-off-by Grzegorz Szpetkowski <gszpetkowski@gmail.com>:
diff --git a/man7/packet.7 b/man7/packet.7
index effed18c7..182f628a4 100644
--- a/man7/packet.7
+++ b/man7/packet.7
@@ -47,6 +47,14 @@ is set to
then all protocols are received.
All incoming packets of that protocol type will be passed to the packet
socket before they are passed to the protocols implemented in the kernel.
+If
+.I protocol
+is set to zero,
+no packets are received.
+.BR bind (2)
+can optionally be called with a nonzero
+.IR sll_protocol
+to start receiving packets for the protocols specified.
.PP
In order to create a packet socket, a process must have the
.B CAP_NET_RAW
--
Alejandro Colomar
Linux man-pages comaintainer; https://www.kernel.org/doc/man-pages/
http://www.alejandro-colomar.es/
prev parent reply other threads:[~2022-02-12 20:34 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-25 15:22 [PATCH] packet.7: add description of zero protocol for socket Grzegorz Szpetkowski
2022-01-30 10:48 ` Grzegorz Szpetkowski
2022-02-12 20:17 ` Alejandro Colomar (man-pages)
2022-02-09 20:29 ` Alejandro Colomar (man-pages)
2022-02-09 20:32 ` Alejandro Colomar (man-pages)
[not found] ` <CAMW=du=BAp_jkLKvhca3=Sv6NDSA+XdUQREhRB+2XfzsLn_x0w@mail.gmail.com>
[not found] ` <09084d8d-5416-2bc1-0e59-cea44111b375@gmail.com>
2022-02-12 19:44 ` Grzegorz Szpetkowski
2022-02-12 20:34 ` Alejandro Colomar (man-pages) [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=b5bcb372-2e20-d3f0-e466-07764e8ceb71@gmail.com \
--to=alx.manpages@gmail.com \
--cc=gszpetkowski@gmail.com \
--cc=linux-man@vger.kernel.org \
--cc=mtk.manpages@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