You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
Michal Rostecki f4b3a8cea0 ebpf: Change error types to `c_long`
All helper functions and context methods are returning `c_long` as an
error. Before this change, aya-template and book examples were adjusting
the error type in `try_*` functionns return type of the program. For
example, for XDP programs programs, which return `u32`, the type
returned by `try_*` functions, was `Result<u32, u32>`.

This approach is forcing people to write boilerplate code for casting
errors from `c_long` to the expected type, like:

```rust
MY_MAP.insert(k, v, 0).map_err(|_| 1u32)?;
```

This change solves that problem by:

* Using `Result<i32, c_long>` as a type for `try_*` functions for
  SKB-based programs and then replacing errors with `TC_ACT_SHOT` or
  `0` once in the main program function.
* Using `Result<u32, c_long>` as a type for `try_*` functions in `try_*`
  funnctions for XDP programs and then replacing errors with `XDP_ABORT`.
* Using either `Result<u32, c_long>` or `Result<i32, c_long>` as types
  in `try_*` functions for all other program types where the return value
  matters (LSM, sysctl etc.) and replacing the error either with `0` or
  `1` (depending on which number means "block the action" for particular
  type of program).
* Using `Result<(), c_long` for all other program types where the
  return value doesn't matter (kprobe, uprobe etc.).

So errors can be handled without casting, like:

```rust
MY_MAP.insert(k, v, 0)?;
```

The other change is fixing return values of cgroup_skb, sockopt and
sysctl programs (1 means "allow", 0 means "deny").

Signed-off-by: Michal Rostecki <vadorovsky@gmail.com>
2 years ago
.cargo Add xtask for building ebpf programs 3 years ago
.github/workflows Unpin Rust nightly 2 years ago
.vim lsp: use project-name instead of crate_name to generate Cargo.toml path 3 years ago
.vscode lsp: use project-name instead of crate_name to generate Cargo.toml path 3 years ago
xtask fail with descriptive message 2 years ago
{{project-name}} upgrade deps: tokio and anyhow 2 years ago
{{project-name}}-common adjust spacing to avoid VSCode changes on save 2 years ago
{{project-name}}-ebpf ebpf: Change error types to `c_long` 2 years ago
.gitignore Initial Commit 3 years ago
Cargo.toml Update dependency 2 years ago
README.md sync run nightly install directions with Book 2 years ago
cargo-generate.toml include and use clap only if needed 2 years ago
pre-script.rhai include and use clap only if needed 2 years ago
test.sh cargo-generate: sort program types 2 years ago

README.md

{{project-name}}

Prerequisites

  1. Install a rust stable toolchain: rustup install stable
  2. Install a rust nightly toolchain with the rust-src component: rustup toolchain install nightly --component rust-src
  3. Install bpf-linker: cargo install bpf-linker

Build eBPF

cargo xtask build-ebpf

To perform a release build you can use the --release flag. You may also change the target architecture with the --target flag.

Build Userspace

cargo build

Run

RUST_LOG=info cargo xtask run