Skip to content

An XDP program to reflect ethernet frames.

License

Notifications You must be signed in to change notification settings

vmuxIO/xdp-reflector

 
 

Repository files navigation

xdp-reflector

An XDP program to reflect ethernet frames.

Performance

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.

Dependencies

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

Building

Just hit make:

make

Deploying

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

Remarks

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.

Reflector variant: pure_reflector

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

License

This project is distributed under MIT license.

About

An XDP program to reflect ethernet frames.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C 100.0%