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
54
55
56
57
58
59
60
61
62
63
// Copyright 2019 Authors of Red Sift
//
// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
// http://opensource.org/licenses/MIT>, at your option. This file may not be
// copied, modified, or distributed except according to those terms.
/*!
Rust API to write eBPF programs.
# Overview
`redbpf-probes` is part of the [redbpf](https://github.com/redsift/redbpf)
project. It provides an idiomatic Rust API to write programs that can be
compiled to eBPF bytecode and executed by the linux in-kernel eBPF virtual
machine.
This crate is expected to be used with the companion
[`redbpf-macros`](https://ingraind.org/api/redbpf_macros/) crate - a
collection of procedural macros used to reduce the amount of boilerplate
needed to produce eBPF programs.
To streamline the process of working with eBPF programs even further,
`redbpf` also provides [`cargo-bpf`](https://ingraind.org/api/cargo_bpf/) -
a cargo subcommand to simplify creating and building eBPF programs.
# Example
This is what `redbpf_probes` and `redbpf_macros` look like in action:
```no_run
#![no_std]
#![no_main]
use redbpf_probes::xdp::prelude::*;
program!(0xFFFFFFFE, "GPL");
#[xdp]
pub fn block_port_80(ctx: XdpContext) -> XdpResult {
if let Ok(transport) = ctx.transport() {
if transport.dest() == 80 {
return Ok(XdpAction::Drop);
}
}
Ok(XdpAction::Pass)
}
```
*/