Re: [PATCH] packet.7: add description of zero protocol for socket

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
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@xxxxxxxxx>
    Link: linux-man@
<https://lore.kernel.org/linux-man/CAMW=dumhWDu6LdhaQCJMskA4yNRBtOHs4iyrG6TP7xRv28AVWA@xxxxxxxxxxxxxx/>
    Cowritten-by: Alejandro Colomar <alx.manpages@xxxxxxxxx>
    Signed-off-by: Alejandro Colomar <alx.manpages@xxxxxxxxx>
    Signed-off-by Grzegorz Szpetkowski <gszpetkowski@xxxxxxxxx>:

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/



[Index of Archives]     [Kernel Documentation]     [Netdev]     [Linux Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux