Commit Graph

838 Commits (dfb03382f6884e49e972b8fe30e62a6eef25ca46)
 

Author SHA1 Message Date
Alessandro Decina cced3da5c8 Update to aya 0.10.5
Alessandro Decina 9ab9c80183 Simplify BpfLogger::init
Make BpfLogger::init(bpf) log using the default logger. Add
BpfLoger::init_with_logger(bpf, logger) for logging using a custom
logger instance.
Alessandro Decina 2ac433449c Minor tweaks to make the verifier's job easier
Alessandro Decina b14d4bab2f Switch to aya-ufmt
Alessandro Decina 22d8f86fbb Use aya_bpf::maps::PerfEventByteArray to output logs
Alessandro Decina 741957f945 Use aya_log_ebpf::ufmt instead of ::ufmt
Alessandro Decina 0d7ac3eb3e Add ufmt to readme
Alessandro Decina 5df853cfb0 Update readme
Alessandro Decina b29a061bce Initial commit
Alessandro Decina f9588a9daa
Merge pull request from athre0z/printk
bpf: add `bpf_printk!` helper
Joel Höner bfb5536f12 bpf: avoid stack-alloc for `fmt` in `bpf_printk!`
Joel Höner da13143c05 bpf: add `bpf_printk!` helper
The `bpf_printk!` macro is a helper providing a convenient way to invoke the
`bpf_trace_printk` and `bpf_trace_vprintk` BPF helpers. It is implemented as
a macro because it requires variadic arguments.
Michal Rostecki 6c9d814860
Merge pull request from vadorovsky/bpf-get-current-comm-u8
bpf: Change the result type of bpf_get_current_comm helper
Dave Tucker 73ee3cff70
Merge pull request from dave-tucker/btf-maps
Support Parsing of BTF Maps
Dave Tucker f976229477 Support BTF Maps
This commit allows for BTF maps in the .maps ELF section to be parsed.
It reads the necessary information from the BTF section of the ELF file.
While the btf_ids of Keys and Values types are stored, they are not (yet)
used.

When creating a BTF map, we pass the btf_key_type_id and
btf_value_type_id.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
Michal Rostecki 480f6180f5
Merge pull request from vadorovsky/skb-load-bytes
bpf: Add `load_bytes` method to SKB context
Michal Rostecki c6e1d56684 bpf: Add `load_bytes` method to SKB context
This new method allows to load bytes into the given bytes slice, not
requiring to alloate the memory on stack. It can be used with
PerCpuArrays.

Example:

https://github.com/vadorovsky/aya-examples/blob/main/tc-bytes/tc-bytes-ebpf/src/main.rs

Signed-off-by: Michal Rostecki <vadorovsky@gmail.com>
Michal Rostecki f08bb022f7
Merge pull request from vadorovsky/fix-lint
bpf: Use `then_some` instead of `then(|| [...])`
Michal Rostecki ee15fbbbc5 bpf: Use `then_some` instead of `then(|| [...])`
This change fixes the `unnecessary_lazy_evaluations` clippy warning.

Signed-off-by: Michal Rostecki <vadorovsky@gmail.com>
Michal Rostecki a3a96b8415 bpf: Change the result type of bpf_get_current_comm helper
Change it from `[i8; 16]` to `[u8; 18]`. `i8` arrays cannot be easily used in
Rust for converting to string (i.e. with `core::str::from_utf8_unchecked`)
and developers have to convert them themselves with unsafe code.

Using u8 arrays lets developers to just convert it with
`core::str::from_utf8_unchecked` without any limitations.

Example:

https://github.com/vadorovsky/aya-examples/blob/main/clone/clone-ebpf/src/main.rs

Signed-off-by: Michal Rostecki <vadorovsky@gmail.com>
Alessandro Decina 6f301ac9ca
Merge pull request from vadorovsky/str
bpf(helpers): Add *_str_bytes helpers
Alessandro Decina fa4347aae4
Merge pull request from vadorovsky/rlimit-v2
aya: Raise the RLIMIT_MEMLOCK warning only if failed to create a map
Michal Rostecki 3d592d0f29 aya: Raise the RLIMIT_MEMLOCK warning only if failed to create a map
Also, mention that setting the RLIMIT_MEMLOCK to a higher value is an
option.

Signed-off-by: Michal Rostecki <vadorovsky@gmail.com>
Dave Tucker a7fa938f1e
Merge pull request from vadorovsky/rlimit
aya: Raise the warning when RMILIT_MEMLOCK is not RLIM_INFINITY
Michal Rostecki bebe98e670 aya: Raise the warning when RMILIT_MEMLOCK is not RLIM_INFINITY
Kernels before 5.11 don't use cgroup accounting, so they might reach the
RLIMIT_MEMLOCK when creating maps. After this change, we raise a warning
recommending to raise the RLIMIT_MEMLOCK.
Dave Tucker 555833a79a
Merge pull request from dave-tucker/rust-runner
test: Replace RTF with Rust
Dave Tucker 79101e748a test: Replace RTF with Rust
This commit replaces the existing RTF test runner with a simple rust
binary package called - integration-test.

integration-test depends on integration-ebpf, which contains test eBPF
code written in Rust and C. `cargo xtask build-integration-test-ebpf`
can be used to build this code and supress rust-analyzer warnings. It
does require `bpf-linker`, but that is highly likely to be available to
developers of Aya. It also requires a checkout of `libbpf` to extract
headers like bpf-helpers.h.

Since everything is compiled into a single binary, it can be run
be run locally using `cargo xtask integration-test` or remotely using
`./run.sh` which re-uses the bash script from the old test framework
to spawn a VM in which to run the tests.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
Dave Tucker 6188c9dee3
Merge pull request from dave-tucker/clippy
clippy: Fix latest nightly lints
Dave Tucker 336faf553e clippy: Fix latest nightly lints
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
Dave Tucker 323170aa3f
Merge pull request from joshiste/fix/compat-pre-5.5
aya-bpf: use bpf_read_probe for reading pt_regs
Johannes Edmeier 2d79f22b40 aya-bpf: use bpf_read_probe for reading pt_regs
Linux Kernels < 5.5 don't support bpf_probe_read_kernel. Therefore
bpf_probe_read must be used for compatibility reasons.
Dave Tucker f2fb211634
Merge pull request from aya-rs/dependabot/cargo/object-0.29
build(deps): update object requirement from 0.28 to 0.29
Michal Rostecki 78e58b8960 bpf(helpers): Add *_str_bytes helpers
This change adds two new helpers:

* bpf_probe_read_user_str_bytes
* bpf_probe_read_kernel_str_bytes

Those new helpers are returning a bytes slice (`&[u8]`) with a length
equal to the length of probed, null-terminated string. When using those
helpers, users don't have to manually check for length and create such
slices themselves. They also make converting to `str` way more
convenient, for example:

```rust
let my_str = unsafe {
    core::str::from_utf8_unchecked(
        bpf_probe_read_user_str_bytes(user_ptr, &mut buf)?
    )
};
```

This change also deprecates the old helpers, since their names are
confusing (they have nothing to do with Rust `str`) and using them
requires writing boilerplate code (for checking the length and making
eBPF verifier happy):

* bpf_probe_read_user_str
* bpf_probe_read_kernel_str

Tested on:

516b29af68

Signed-off-by: Michal Rostecki <vadorovsky@gmail.com>
dependabot[bot] 661a21570f
build(deps): update object requirement from 0.28 to 0.29
Updates the requirements on [object](https://github.com/gimli-rs/object) to permit the latest version.
- [Release notes](https://github.com/gimli-rs/object/releases)
- [Changelog](https://github.com/gimli-rs/object/blob/master/CHANGELOG.md)
- [Commits](https://github.com/gimli-rs/object/compare/0.28.0...0.29.0)

---
updated-dependencies:
- dependency-name: object
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Alessandro Decina a301a56316
Merge pull request from drewkett/map-update-no-key
Have bpf_map_update_elem take Option<&K> for key
Alessandro Decina e5f455f238
Merge pull request from dave-tucker/bpfd
Add atomic replacement of XDP progs and multihoming of Extension progs
Dave Tucker 004f3dd664 aya: Improve Extension Docs
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
Dave Tucker 9e85b92323 aya: Add Extension::attach_to_program()
This allows for Extension programs already loaded to the kernel to be
attached to another program that is BTF-compatible with the one provided
at `load()` time

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
Dave Tucker b4413322e3 aya: Replace ProgramFd trait with struct
This removes the ProgramFd trait with a struct that wraps a RawFd.
Program::fd() has been implemented as well as fd() for each Program
Type. This allows for a better API than requiring the use of the
ProgramFd trait.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
Dave Tucker fd52bfeadc aya: Implement attach_to_link for XDP
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
Dave Tucker ccb189784f aya: Add support for bpf_link_update
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
Andrew Burkett 36edf09254 Have bpf_map_update_elem take Option<&K> for key
bpf_map_update_elem is used in lieu of bpf_map_push_elem to maintain support for kernel version < 4.20. The kernel expects a null pointer for the key for this use case. With this change, if you pass None as key to `bpf_map_update_elem`, it will pass null as key.
Alessandro Decina 150dc1b610
Merge pull request from NoneTirex/fix-map-delete-return-value
Change condititon for some bpf helpers
tirex caa66cabac Add missing inline macro to xdp methods
tirex 741c35f555 Restore previous check for bpf_get_stackid
tirex 42c4d5c3af Temporary change return value condition to avoid problems with possibly (not aware) cast from int to long
tirex 5b1a3ed866 Fix return value for map removing/deleting
Dave Tucker 623579a47f aya: Add Map::fd() function to return a MapFd
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
Dave Tucker 24597b15b7
Merge pull request from davibe/fix-linting-issues
Fix linting issues
Davide Bertola 7f33d67e8c xtask: fix linting warnings on docs()