#xdp #ebpf

sys libxdp-sys

Rust bindings for libxdp

5 releases

Uses new Rust 2024

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.2.0 Oct 20, 2023
0.0.2 May 9, 2021

#617 in Unix APIs

Download history 4171/week @ 2025-08-27 3345/week @ 2025-09-03 5021/week @ 2025-09-10 1119/week @ 2025-09-17 228/week @ 2025-09-24 228/week @ 2025-10-01 478/week @ 2025-10-08 320/week @ 2025-10-15 351/week @ 2025-10-22 390/week @ 2025-10-29 296/week @ 2025-11-05 669/week @ 2025-11-12 414/week @ 2025-11-19 146/week @ 2025-11-26 171/week @ 2025-12-03 104/week @ 2025-12-10

954 downloads per month
Used in xsk-rs

LGPL-2.1 OR BSD-2-Clause

3MB
47K SLoC

C 43K SLoC // 0.1% comments Shell 3K SLoC // 0.1% comments Rust 406 SLoC // 0.0% comments Python 361 SLoC // 0.0% comments RPM Specfile 150 SLoC // 0.0% comments Emacs Lisp 53 SLoC // 0.1% comments BASH 45 SLoC // 0.1% comments

Contains (ELF exe/lib, 9KB) src/prebuilt_ebpf/xsk_def_xdp_prog_5.3.o, (ELF exe/lib, 1KB) src/prebuilt_ebpf/xdp-dispatcher.o, (ELF exe/lib, 8KB) src/prebuilt_ebpf/xsk_def_xdp_prog.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