Thread (10 messages) 10 messages, 4 authors, 2018-11-30

RE: Invalid transport_offset with AF_PACKET socket

From: Maxim Mikityanskiy <hidden>
Date: 2018-11-30 18:42:12

quoted
quoted
So it should return at least 18 and not 14.
Yes, the function does its best to return at least 18, but it silently
expects
quoted
skb_transport_offset to exceed 18. In normal conditions, it will be more
that
quoted
18, because it will be at least 14 + 20. But in my case, when I send a
packet
quoted
via an AF_PACKET socket, skb_transport_offset returns 14 (which is
nonsense),
quoted
and the driver uses this value, causing the hardware to fail, because it's
less
quoted
than 18.
Got it, so even if you copy 18 it is not sufficient ! if the packet is
ipv4 or ipv6
and the inline mode is set to  MLX5_INLINE_MODE_IP in the vport
context you must copy the IP headers as well !
Yes, I know that. That's why the driver uses skb_transport_offset - to include
the network header, but as skb_transport_offset returns a wrong offset, the IP
header doesn't get included. The thing is that with 14 bytes the driver even
fails to send a packet, and with 18 bytes and missing L3 header it seems to send
it, but it doesn't matter much, of course, we should pass the L3 header as well.
but what do you expect from AF_PACKET socket ? to parse each and every
packet and set skb_transport_offset ?
Not exactly.

First, AF_PACKET already parses each packet, and it even sets the transport
offset correctly if I specify the protocol in the third parameter of the
socket() call:

    socket(AF_PACKET, SOCK_RAW, htons(0x0800));

So, if called in a specific way, the AF_SOCKET does exactly that - it parses
each packet and sets the transport offset, but if the protocol is not specified
(0) in the third parameter, it fails to parse correctly.

Second, I don't expect that. It's absolutely OK if AF_PACKET tells the driver
that it failed to parse the packet, then the driver can guess the network
protocol and restart parsing itself. The driver knows the format of its L2
header and can look at the necessary field.

However, if AF_PACKET could ask the driver to guess the protocol, it would be a
little bit faster, because this way skb_probe_transport_header is only called
once, and the field lookup in the L2 header is O(1).
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help