1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//! eBPF socket filter integration via AsFd.
//!
//! This example demonstrates how to attach an eBPF program to a netring
//! capture socket using the `aya` crate. All netring handles implement
//! `AsFd`, enabling external eBPF attachment without raw file descriptors.
//!
//! **This example requires the `aya` crate** (not a netring dependency).
//! It is provided as documentation of the integration pattern.
//!
//! ```toml
//! [dependencies]
//! netring = "0.1"
//! aya = "0.13"
//! ```
//!
//! ## Usage Pattern
//!
//! ```rust,ignore
//! use aya::programs::SocketFilter;
//! use netring::Capture;
//! use std::os::fd::AsFd;
//!
//! // Load your compiled eBPF program
//! let mut bpf = aya::Ebpf::load_file("my_filter.o")?;
//! let prog: &mut SocketFilter = bpf.program_mut("my_filter")?.try_into()?;
//! prog.load()?;
//!
//! // Create a capture and attach the eBPF program via AsFd
//! let cap = Capture::new("eth0")?;
//! prog.attach(cap.as_fd())?;
//!
//! // Only packets passing the eBPF filter arrive
//! for pkt in cap.packets() {
//! println!("{} bytes (filtered)", pkt.len());
//! }
//! ```
use AsFd;