Skip to main content

Crate push_packet

Crate push_packet 

Source
Expand description

push-packet is a high-level, extensible packet routing library built on eBPF with aya. It is intended to be a simple, yet flexible foundation for traffic analysis applications and network-stack bypass.

§Example: Tap into a network interface, and copy all packets to userspace.

let mut tap = Tap::builder("wlp3s0")
    .rule(Rule::source_cidr("0.0.0.0/0").action(Action::Copy { take: None }))
    .build()?;

let mut rx = tap.copy_receiver()?;
while let Ok(event) = rx.recv() {
    println!("Received packet of length {}", event.packet_len());
}

§Example: Tap into an interface, add and remove rules dynamically.

let mut tap = Tap::builder("wlp3s0")
    // Set force_enabled on the copy config so we can use copy rules later.
    .copy_config(CopyConfig::default().force_enabled())
    .build()?;

// call add_rule to get a RuleId
let drop_rule_id = tap.add_rule(
    Rule::protocol(Protocol::Tcp)
        .source_cidr("127.0.0.1")
        .source_port(3000..4000)
        .action(Action::Drop),
)?;

// [traffic dropped]

// Remove a rule with RuleId
tap.remove_rule(drop_rule_id)?;

// Read some traffic instead
tap.add_rule(
    Rule::source_cidr("127.0.0.1")
        .source_port(3001)
        .action(Action::COPY_ALL),
)?;

let mut rx = tap.copy_receiver()?;
while let Ok(event) = rx.recv() {
    println!("Received packet of length {}", event.packet_len());
}

Re-exports§

pub use channels::ChannelError;
pub use rules::RuleError;

Modules§

channels
Defines channels for copying and routing packets to userspace with BPF_RING_BUG and AF_XDP
engine
Defines Engine traits.
events
Defines various packet events.
rules
Rule definitions and builders.

Structs§

CopyConfig
Optional configuration for copying packets.
Interface
A network interface
RouteConfig
Optional configuration for routing packets.
Tap
Taps into a network interface. This struct stores all eBPF primitives required for the specific combination of Actions and the Engine. It defaults to using a LinearEngine.
TapBuilder
Builder for a Tap.

Enums§

Error
FrameKind

Traits§

Loader
This trait enforces organizational principles for configuring and loading Ebpf components. This should be implemented on configuration structs, in a builder pattern, using load(self, ebpf: &mut Ebpf) instead of the common build(self).