Subject: Re: [PATCH RFC v2] net: xdp: allow for layer 3 packets in generic skb handler

From: Toke Høiland-Jørgensen <[email-masked]>
Date: Mon, 27 Apr 2020 22:08:58 +0200

"Jason A. Donenfeld" <[email-masked]> writes:

> On Mon, Apr 27, 2020 at 8:45 AM David Ahern <[email-masked]> wrote:
>>
>> On 4/27/20 4:22 AM, Jason A. Donenfeld wrote:
>> > @@ -4544,6 +4544,13 @@ static u32 netif_receive_generic_xdp(struct sk_buff *skb,
>> >        * header.
>> >        */
>> >       mac_len = skb->data - skb_mac_header(skb);
>> > +     if (!mac_len) {
>> > +             add_eth_hdr = true;
>> > +             mac_len = sizeof(struct ethhdr);
>> > +             *((struct ethhdr *)skb_push(skb, mac_len)) = (struct ethhdr) {
>> > +                     .h_proto = skb->protocol
>> > +             };
>>
>> please use a temp variable and explicit setting of the fields; that is
>> not pleasant to read and can not be more performant than a more direct
>>
>>                 eth_zero_addr(eth->h_source);
>>                 eth_zero_addr(eth->h_dest);
>>                 eth->h_proto = skb->protocol;
>
> Ack, will change for the non-RFC v3 patch. I need to actually figure
> out how to test this thing first though...

You could try the xdp-filter application in this repo:

https://github.com/xdp-project/xdp-tools

(make sure you use --recurse-submodules when you clone it)

That will allow you to install simple IP- and port-based filters; should
be enough to check that XDP programs will correctly match the packet
contents, I think?

-Toke