Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
xsk-rs
A Rust interface for Linux AF_XDP sockets using libxdp.
For more information please see the networking docs or a more detailed overview.
Initially inspired by Jesse DuMond's OCaml implementation.
Examples
A few may be found in the examples
directory. A simple example of
moving bytes between two sockets via a veth pair can be found in
examples/hello_xdp.rs
, while a slightly more complex example of
sending and receiving eth frames (also via a veth pair) is in
examples/dev2_to_dev1.rs
, which includes a single-threaded and
multi-threaded implementation. Note that neither example will be
indicative of actual performance, since binding the sockets to the
veth pair means that packets will pass through the kernel network
stack.
An example with shared UMEM is in examples/shared_umem.rs
.
Running tests / examples
Root permissions may be required to run the tests or examples, since
they require a veth pair to be set up. However to avoid running cargo
under root
it's best to first build the tests/examples and run the
binaries directly.
# tests
cargo build --tests
sudo run_all_tests.sh
# examples
cargo build --examples --release
sudo target/release/examples/hello_xdp
sudo target/release/examples/dev1_to_dev2 -- [FLAGS] [OPTIONS]
Compatibility
Tested on a 64-bit machine running Linux kernel version 6.5.0.
Safety
There is a fair amount of unsafe involved when using this library, and so the potential for disaster, however if you keep in mind the following then there should hopefully be few avenues for catastrophe:
- When a frame / address has been submitted to the fill queue or tx ring, do not use it again until you have consumed it from either the completion queue or rx ring.
- Do not use one UMEM's frame descriptors to access frames of another, different UMEM.
Usage
The below example sends a packet from one interface to another.
use ;
use ;
const ETHERNET_PACKET: = ;