问题
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