AF_XDP: No packets for socket with queue-id 0 even though every packet is redirect

試著忘記壹切 提交于 2020-04-18 05:43:15

问题


I am based on this tutorial: https://github.com/xdp-project/xdp-tutorial/tree/master/advanced03-AF_XDP

I create a socket with Queue-ID 0 in userspace. In my kernel af-xdp program I filter for UDP-packets and redirect them to the userspace socket via a xskmap.

Because I obviously want the userspace-program to receive packets, I redirect the packets in the kernel program to index 0:

int index = 0;
if (bpf_map_lookup_elem(&xsks_map, &index)) {
    return bpf_redirect_map(&xsks_map, index, 0);
} else {
    bpf_printk("Didn't find connected socket for index %d!\n", index);
}

I don't get the error message Didn't find connected socket for index 0! via sudo cat /sys/kernel/debug/tracing/trace_pipe but I don't receive any packets either in userspace!

If I just continue to run the program and simultaneously add an ethtool-rule like this:

sudo ethtool -N <eth> flow-type udp4 dst-ip <ip> action 0

my userspace program suddenly starts to receive packets and the error message goes away.

I thought that the kernel program would receive every packet sent to that interface but somehow that's not the case. What did I do wrong?


回答1:


So this was discussed on IRC (#xdp, Freenode) and the xdp-newbies mailing list. Reporting here for the record.

The answer is that you did nothing wrong: With AF_XDP, a socket receives the packets from one hardware queue. You could have several sockets receiving packets from one queue, but you cannot have, as of this writing, one socket receiving on more than one queue. This is by design.

In your case, the Queue-ID: 0 that you associate to your socket indicates that it will receives packet from queue 0. This is why you don't see all packets received by the NIC before routing all flows to queue 0.

Reference for the ML discussion: link. Credits to Björn and Toke.



来源:https://stackoverflow.com/questions/60603415/af-xdp-no-packets-for-socket-with-queue-id-0-even-though-every-packet-is-redire

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!