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?