* [PATCH] packet.7: add description of zero protocol for socket
@ 2022-01-25 15:22 Grzegorz Szpetkowski
2022-01-30 10:48 ` Grzegorz Szpetkowski
2022-02-09 20:29 ` Alejandro Colomar (man-pages)
0 siblings, 2 replies; 7+ messages in thread
From: Grzegorz Szpetkowski @ 2022-01-25 15:22 UTC (permalink / raw)
To: linux-man; +Cc: alx.manpages, mtk.manpages
Dear Maintainers,
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 proposed patch to define behavior when protocol is to zero with socket().
Please review.
Signed-off-by: Grzegorz Szpetkowski gszpetkowski@gmail.com
diff --git a/man7/packet.7 b/man7/packet.7
index 706efbb54..461444c43 100644
--- a/man7/packet.7
+++ b/man7/packet.7
@@ -47,6 +47,9 @@ 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.
+When protocol is set to zero, then no packets are received until
+.BR bind (2)
+specifies allowed protocol or to receive all protocols.
.PP
In order to create a packet socket, a process must have the
.B CAP_NET_RAW
Thanks,
Grzegorz
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] packet.7: add description of zero protocol for socket
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)
1 sibling, 1 reply; 7+ messages in thread
From: Grzegorz Szpetkowski @ 2022-01-30 10:48 UTC (permalink / raw)
To: linux-man; +Cc: alx.manpages, mtk.manpages
In addtion of preventing unwanted packets (from other interfaces)
being received between socket and bind, I've found another one. If
desired usage of the raw packet socket is egress-only, meaning user
doesn't want to receive any packet, then such a socket created with
protocol = 0 argument will save both CPU/memory resources of the
process, since Rx protocol handler won't be invoked upon reception of
packets and the associated Rx socket buffer won't be populated,
regardless of ingress traffic load This can be especially useful in
embedded applications.
Not sure if this can also be added to man, though.
Thanks,
Grzegorz
wt., 25 sty 2022 o 16:22 Grzegorz Szpetkowski <gszpetkowski@gmail.com>
napisał(a):
>
> Dear Maintainers,
>
> 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 proposed patch to define behavior when protocol is to zero with socket().
> Please review.
>
> Signed-off-by: Grzegorz Szpetkowski gszpetkowski@gmail.com
>
> diff --git a/man7/packet.7 b/man7/packet.7
> index 706efbb54..461444c43 100644
> --- a/man7/packet.7
> +++ b/man7/packet.7
> @@ -47,6 +47,9 @@ 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.
> +When protocol is set to zero, then no packets are received until
> +.BR bind (2)
> +specifies allowed protocol or to receive all protocols.
> .PP
> In order to create a packet socket, a process must have the
> .B CAP_NET_RAW
>
> Thanks,
> Grzegorz
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] packet.7: add description of zero protocol for socket
2022-01-30 10:48 ` Grzegorz Szpetkowski
@ 2022-02-12 20:17 ` Alejandro Colomar (man-pages)
0 siblings, 0 replies; 7+ messages in thread
From: Alejandro Colomar (man-pages) @ 2022-02-12 20:17 UTC (permalink / raw)
To: Grzegorz Szpetkowski; +Cc: mtk.manpages, linux-man
Hi Grzegorz,
On 1/30/22 11:48, Grzegorz Szpetkowski wrote:
> In addtion of preventing unwanted packets (from other interfaces)
> being received between socket and bind, I've found another one. If
> desired usage of the raw packet socket is egress-only, meaning user
> doesn't want to receive any packet, then such a socket created with
> protocol = 0 argument will save both CPU/memory resources of the
> process, since Rx protocol handler won't be invoked upon reception of
> packets and the associated Rx socket buffer won't be populated,
> regardless of ingress traffic load This can be especially useful in
> embedded applications.
>
> Not sure if this can also be added to man, though.
I'd say yes.
I'll merge the other patch, and them you can suggest a new one with this
information.
Thanks,
Alex
--
Alejandro Colomar
Linux man-pages comaintainer; https://www.kernel.org/doc/man-pages/
http://www.alejandro-colomar.es/
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] packet.7: add description of zero protocol for socket
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-09 20:29 ` Alejandro Colomar (man-pages)
2022-02-09 20:32 ` Alejandro Colomar (man-pages)
1 sibling, 1 reply; 7+ messages in thread
From: Alejandro Colomar (man-pages) @ 2022-02-09 20:29 UTC (permalink / raw)
To: Grzegorz Szpetkowski; +Cc: mtk.manpages, linux-man
Hello Grzegorz,
On 1/25/22 16:22, Grzegorz Szpetkowski wrote:
> Dear Maintainers,
>
> 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 proposed patch to define behavior when protocol is to zero with socket().
> Please review.
>
> Signed-off-by: Grzegorz Szpetkowski gszpetkowski@gmail.com
>
> diff --git a/man7/packet.7 b/man7/packet.7
> index 706efbb54..461444c43 100644
> --- a/man7/packet.7
> +++ b/man7/packet.7
> @@ -47,6 +47,9 @@ 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.
> +When protocol is set to zero, then no packets are received until
> +.BR bind (2)
> +specifies allowed protocol or to receive all protocols.man
There's something wrong in that line, or I'm not understanding it.
Could you please review it?
Thanks,
Alex
> .PP
> In order to create a packet socket, a process must have the
> .B CAP_NET_RAW
>
> Thanks,
> Grzegorz
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2022-02-12 20:34 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox