-
I am trying to better understand XDP, and tried to create a simple example using bpf_redirect_map to redirect traffic from one network namespace to another controlled by a DEVMAP that I manipulate from userspace. I detailed my approach at https://github.com/bewing/xdp-redirect-map I have confirmed that traffic is being redirected (I don't see anything when using tcpdump on the main NS veth interface), but I can't tell where it's going -- it should be mapped to the other outside veth interface, and be delivered into the other network namespace, but tcpdump there doesn't show the traffic arriving. Am I making a mistake in index/interface selection or DEVMAP population? Or am I running into a limitation in XDP as it relates to veth drivers? Kernel version is 5.15.0-52-generic FWIW, trying to insert |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hey @bewing, this doesn't look related to anything in the library specifically, but I'll try to give some pointers because everything's so clearly presented. :) When dealing with undocumented bpf features (as most of them are), the kernel selftests usually contain an example use case or two that can provide some clarity. In the case of devmap, there's https://elixir.bootlin.com/linux/latest/source/samples/bpf/xdp_redirect_map.bpf.c (and The way you populate the map from userspace seems fine, there's not really a possibility for mismatching byte order (ifindex is pulled from the kernel, processed in a native Go program and written back to a map in the same kernel), and I'm not sure what When dealing with XDP, it's important to keep in mind you're essentially moving raw packet data (including headers) from one interface buffer to the other, bypassing the network stack in doing so, so you're fully responsible for getting that packet into a state in which it 'makes sense' for it to arrive in the destination netns. In this case, I'd suspect the destination MAC (and IP?) of the packet are set to that of an interface in the host namespace, and when XDP makes it magically appear in the receive queue of the target veth and kicks off packet delivery, the network stack has no idea what to do with the packet, meaning it will be dropped/freed. Look into reverse-path filtering (Linux Hope this helps! |
Beta Was this translation helpful? Give feedback.
Hey @bewing, this doesn't look related to anything in the library specifically, but I'll try to give some pointers because everything's so clearly presented. :)
When dealing with undocumented bpf features (as most of them are), the kernel selftests usually contain an example use case or two that can provide some clarity. In the case of devmap, there's https://elixir.bootlin.com/linux/latest/source/samples/bpf/xdp_redirect_map.bpf.c (and
xdp_redirect_map_user.c
for the userspace counterpart)The way you populate the map from userspace seems fine, there's not really a possibility for mismatching byte order (ifindex is pulled from the kernel, processed in a native Go program and written back…