An XDP program to reflect ethernet frames.
With MoonGen I achieved about 1.6 Mpps on an Intel 82599-based NIC. I'm not entirely sure yet if and how one can achieve the 14 Mpps that would max out the 10 Gbps throughput of the card.
Initialize the libbpf submodule with:
git submodule update --init
Then install the remaining dependencies with:
sudo apt install -y clang llvm libelf-dev libpcap-dev gcc-multilib build-essential linux-headers-$(uname -r)
For installation instructions for non-Debian systems see XDP tutorial's setup instructions
Just hit make
:
make
Due to the simplicity of this XDP program, it does not come with an extra
loader. You can simply use the ip
tool for this.
To attach the reflector to a device use:
sudo ip link set <DEV> xdpgeneric obj reflector.o sec xdp
And to remove it again use:
sudo ip link set <DEV> xdpgeneric off
This is quite a tiny and almost trivial project. I wrote it because I needed a fast reflector to take MoonGen measurements on non-PCI devices in QEMU guests. Apart from such usecases it can serve as a minimal sample project for XDP programs.
This project is similarly structured as the XDP tutorial, which is a great resource for learning XDP prorgamming.
The normal reflector properly switches the src and dst MAC address before sending the packet back into the network.
As a variant, pure_reflector
does not touch MAC addresses.
It can be used to reflect packets back into the network that don't belong to this host.
For that compile it with your local hosts MAC address (so that these packet are not reflected), and allow the host to accept packets destined for other hosts.
rm pure_reflector.o
make pure_reflector.o OUR_MAC="{ 0x77, 0x96, 0x91, 0xb3, 0x8b, 0x77}"
sudo ip link set <DEV> promisc on
sudo ip link set <DEV> xdpgeneric obj pure_reflector.o sec xdp
This project is distributed under MIT license.