#xdp #bindings

sys libxdp-sys

Rust bindings for libxdp

5 releases

Uses new Rust 2024

0.2.4+1.6.0 Feb 4, 2026
0.2.3+1.5.6 Oct 9, 2025
0.2.2+1.5.5 Sep 8, 2025
0.2.1+1.4.3 Jan 27, 2025
0.0.2 May 9, 2021

#1431 in Unix APIs

Download history 439/week @ 2026-02-17 264/week @ 2026-02-24 329/week @ 2026-03-03 303/week @ 2026-03-10 288/week @ 2026-03-17 282/week @ 2026-03-24 161/week @ 2026-03-31 440/week @ 2026-04-07 230/week @ 2026-04-14 242/week @ 2026-04-21 178/week @ 2026-04-28 385/week @ 2026-05-05 1601/week @ 2026-05-12 5893/week @ 2026-05-19 4865/week @ 2026-05-26 10154/week @ 2026-06-02

22,597 downloads per month
Used in 11 crates (2 directly)

LGPL-2.1 OR BSD-2-Clause

3MB
45K SLoC

C 41K SLoC // 0.1% comments Shell 2.5K SLoC // 0.1% comments Rust 376 SLoC // 0.0% comments Python 361 SLoC // 0.0% comments RPM Specfile 136 SLoC // 0.0% comments Emacs Lisp 53 SLoC // 0.1% comments BASH 45 SLoC // 0.1% comments

Contains (ELF exe/lib, 20KB) src/prebuilt_ebpf/xdp-dispatcher.o, (ELF exe/lib, 8KB) src/prebuilt_ebpf/xsk_def_xdp_prog.o, (ELF exe/lib, 8KB) src/prebuilt_ebpf/xsk_def_xdp_prog_5.3.o

libxdp-sys

Rust FFI bindings for the libxdp C library, enabling safe and efficient interaction with XDP (eXpress Data Path) features from Rust.

Overview

libxdp-sys provides low-level, auto-generated Rust bindings to the libxdp C library. These bindings allow Rust programs to interact with XDP objects, manage XDP programs, and utilize advanced networking features exposed by libxdp.

This crate is intended for use as a building block for higher-level Rust libraries and applications that require direct access to XDP functionality. It is not a high-level API; instead, it exposes the raw C interface as closely as possible.

Features

  • Bindings to libxdp and related XDP/BPF types and functions
  • Optional vendored build of libbpf via the vendored feature
  • By default uses precompiled BPF objects via the use_precompiled_bpf feature
  • Compatible with modern Rust editions

Usage

Add libxdp-sys to your Cargo.toml:

[dependencies]
libxdp-sys = "0.2"

Enable optional features as needed:

[features]
vendored = ["libbpf-sys/vendored"]
vendored-libelf = ["libbpf-sys/vendored-libelf"]
use_precompiled_bpf = [] # Use precompiled BPF objects instead of building at compile time

use_precompiled_bpf Feature

If you enable the use_precompiled_bpf feature, the crate will use prebuilt BPF object files (found in src/prebuilt_ebpf) instead of compiling BPF code during the build process. This can speed up builds and improve reproducibility, especially in CI environments or when cross-compiling.

Example usage:

use libxdp_sys::*;

// Access a constant
let headroom = XDP_PACKET_HEADROOM;

// Use a struct and call a method
let insn = bpf_insn {
	code: BPF_LD as u8,
	_bitfield_align_1: [],
	_bitfield_1: bpf_insn::new_bitfield_1(1, 2),
	off: 0,
	imm: 0,
};
let dst_reg = insn.dst_reg();

Building

This crate uses a build.rs script to generate bindings at build time. For most users, enabling the vendored feature will build libbpf from source automatically.

Testing

Run integration tests with:

cargo test

License

libxdp-sys is dual-licensed under LGPL-2.1 or BSD-2-Clause, matching the upstream libxdp library.

Authors

Dependencies

~11MB
~244K SLoC