Commit Graph

226 Commits (main)

Author SHA1 Message Date
Andrew Werner 628b7fb022 aya::programs::uprobe: add support for cookies
Fixes #1132.

Note that this change does not add support in the public API for kprobes
or tracepoints, but it's a trivial matter of plumbing.

Along the way, the Uprobe::attach API is cleaned up to make the
attachment location more coherent. The logic being: if we're going to be
breaking the API anyway, may as well clean it up a bit.

Furthermore, the aya::sys::bpf_link_attach function is cleaned up by
properly modeling the the union in the final field with a rust enum.
1 week ago
Mike Rostecki f34d355d7d bpf: Handle raw tracepoint arguments
Provide an `arg()` method in `RawTracepointArgs` wrapper of
`bpf_raw_tracepoint_args` and also in `RawTracepointContext`, so
it's directly available in raw tracepoint programs.

The methods and traits implemented here are unsafe. There is no
way to reliably check the number of available arguments, so
requesting a non-existing one leads to undefined behavior.
2 weeks ago
Tamir Duberstein d1457acc6d ci: cache downloads
We're seeing 429 from Github trying to download gen_init_cpio, so cache
it using actions cache. Since I'm here add this for kernel images as
well to save time waiting on slow Debian servers.
4 weeks ago
Tamir Duberstein b01bc3f49b Use Result in integration-test's build script
Something of an experiment.
2 months ago
Tamir Duberstein 2b2af44915 Extract aya-build for building eBPF crates
We'll use this in the template and book to avoid duplicating all the
code.
2 months ago
Tamir Duberstein e0c4948e36 Extract integration-common for shared types 2 months ago
Tamir Duberstein c5172def75 Avoid reading env needlessly 2 months ago
Tamir Duberstein 806783c0fc Remove integration-ebp/rust-toolchain
Centralize the knowledge in build.rs instead.
2 months ago
Tamir Duberstein fd00b39f09 Enable unwinding in userspace
Unwinding gives us more information, so we shouldn't disable it
globally. It is already disabled for BPF targets via the target configs
in rustc itself.

This complicates the clippy invocation somewhat, so put it in a shell
script for developer as well as CI use.
2 months ago
Tamir Duberstein 964d63ab37 Remove stale comment
The panic has been fixed.
2 months ago
Tamir Duberstein 5ab67dce08
Use TargetKind enum and Target::is_proc_macro
These are added in cargo_metadata 0.19.0.
2 months ago
Michal Rostecki bf2164c92f feat(aya): Add iterator program type
BPF iterators[0] are a way to dump kernel data into user-space and an
alternative to `/proc` filesystem.

This change adds support for BPF iterators on the user-space side. It
provides a possibility to retrieve the outputs of BPF iterator programs
both from sync and async Rust code.

[0] https://docs.kernel.org/bpf/bpf_iterators.html
2 months ago
Michal Rostecki 0b58d3eb6d bpf: Add `bpf_strncmp` helper
The `bpf_strncmp` helper allows for better string comparison in eBPF
programs.

Added in https://github.com/torvalds/linux/commit/c5fb19937455095573a19.
2 months ago
Tamir Duberstein 2e4650e5a5 integration: alphabetize 2 months ago
Dave Tucker 2791badd94 Release aya v0.13.1
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
3 months ago
Dave Tucker c6a34cade1 Release aya-obj v0.2.1
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
3 months ago
Dave Tucker adf16e2102 test: Reproduce relocation bug
Users have reported issues with programs failing the verifier when they
are attempting to read or write to variables that the compiler places in
the .bss section. Add a test that places variables in each section and
exercises read and write operations on them.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
3 months ago
Tamir Duberstein 758a4f9d1e Remove workspace members from workspace.dependencies
Doesn't make much sense to have them here.
3 months ago
Dave Tucker 0e70838b0f Release aya-log v0.2.1
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
3 months ago
Dave Tucker c169b727e6 Release aya-obj v0.2.0, aya v0.13.0, safety bump aya v0.13.0
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
3 months ago
astoycos 5478cac008 feat(aya): Implement TCX
This commit adds the initial support for TCX
bpf links. This is a new, multi-program, attachment
type allows for the caller to specify where
they would like to be attached relative to other
programs at the attachment point using the LinkOrder
type.

Signed-off-by: astoycos <astoycos@redhat.com>
Co-authored-by: Andre Fredette <afredette@redhat.com>
Co-authored-by: Dave Tucker <dave@dtucker.co.uk>
Co-authored-by: Tamir Duberstein <tamird@gmail.com>
3 months ago
Tamir Duberstein 0f163633e3 Appease clippy
See https://github.com/rust-lang/rust/pull/130778.

```
warning: empty line after doc comment
  --> test/integration-ebpf/build.rs:16:1
   |
16 | / /// [bindeps]: https://doc.rust-lang.org/nightly/cargo/reference/unstable.html?highlight=feature#artifact-dependencies
17 | |
   | |_
18 |   fn main() {
   |   --------- the comment documents this function
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#empty_line_after_doc_comments
   = note: `#[warn(clippy::empty_line_after_doc_comments)]` on by default
   = help: if the empty line is unintentional remove it

error: empty line after doc comment
  --> aya/src/maps/bloom_filter.rs:34:1
   |
34 | / /// ```
35 | |
   | |_
...
38 |   pub struct BloomFilter<T, V: Pod> {
   |   --------------------------------- the comment documents this struct
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#empty_line_after_doc_comments
note: the lint level is defined here
  --> aya/src/lib.rs:41:5
   |
41 |     clippy::all,
   |     ^^^^^^^^^^^
   = note: `#[deny(clippy::empty_line_after_doc_comments)]` implied by `#[deny(clippy::all)]`
   = help: if the empty line is unintentional remove it

error: empty line after doc comment
  --> aya/src/maps/lpm_trie.rs:46:1
   |
46 | / /// ```
47 | |
   | |_
...
50 |   pub struct LpmTrie<T, K, V> {
   |   --------------------------- the comment documents this struct
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#empty_line_after_doc_comments
   = help: if the empty line is unintentional remove it

warning: empty line after doc comment
  --> test/integration-test/build.rs:38:1
   |
38 | / /// [bindeps]: https://doc.rust-lang.org/nightly/cargo/reference/unstable.html?highlight=feature#artifact-dependencies
39 | |
   | |_
40 |   fn main() {
   |   --------- the comment documents this function
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#empty_line_after_doc_comments
   = note: `#[warn(clippy::empty_line_after_doc_comments)]` on by default
   = help: if the empty line is unintentional remove it

warning: calling `CStr::new` with a byte string literal
  --> test/integration-test/src/tests/xdp.rs:45:20
   |
45 |         .from_name(CStr::from_bytes_with_nul(b"lo\0").unwrap())
   |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use a `c""` literal: `c"lo"`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_c_str_literals
   = note: `#[warn(clippy::manual_c_str_literals)]` on by default
```
4 months ago
Tamir Duberstein f498a1b7a9 Remove assertion that doesn't work in macOS HVF 4 months ago
Tamir Duberstein 5b29008691 Appease `static_mut_refs`
Made stricter in https://github.com/rust-lang/rust/commit/5ba6db1b648d9.
4 months ago
dependabot[bot] 11d953fee8 build(deps): bump the cargo-crates group with 2 updates
Updates the requirements on [rbpf](https://github.com/qmonnet/rbpf) and [network-types](https://github.com/vadorovsky/network-types) to permit the latest version.

Updates `rbpf` to 0.2.0
- [Commits](https://github.com/qmonnet/rbpf/compare/v0.2.0...v0.2.0)

Updates `network-types` to 0.0.7
- [Release notes](https://github.com/vadorovsky/network-types/releases)
- [Changelog](https://github.com/vadorovsky/network-types/blob/main/CHANGELOG.md)
- [Commits](https://github.com/vadorovsky/network-types/compare/v0.0.6...v0.0.7)

---
updated-dependencies:
- dependency-name: rbpf
  dependency-type: direct:production
  dependency-group: cargo-crates
- dependency-name: network-types
  dependency-type: direct:production
  dependency-group: cargo-crates
...

Signed-off-by: dependabot[bot] <support@github.com>
4 months ago
tyrone-wu 02d1db5fc0 aya: remove unwrap and NonZero* in info
Addresses the feedback from #1007:
- remove panic from `unwrap` and `expect`
- Option<NonZero*> => Option<int> with `0` mapping to `None`

Refs: #1007
4 months ago
tyrone-wu fbb09304a2
aya,int-test: revamp MapInfo be more friendly with older kernels
Adds detection for whether a field is available in `MapInfo`:
- For `map_type()`, we treturn new enum `MapType` instead of the integer
  representation.
- For fields that can't be zero, we return `Option<NonZero*>` type.
- For `name_as_str()`, it now uses the feature probe `bpf_name()` to
  detect if field is available.
  Although the feature probe checks for program name, it can also be
  used for map name since they were both introduced in the same commit.
5 months ago
tyrone-wu 88f5ac3114
aya,obj,int-test: revamp ProgramInfo be more friendly with older kernels
Purpose of this commit is to add detections for whether a field is
available in `ProgramInfo`.
- For `program_type()`, we return the new enum `ProgramType` instead of
  the integer representation.
- For fields that we know cannot be zero, we return `Option<NonZero*>`
  type.
- For `name_as_str()`, it now also uses the feature probe `bpf_name()`
  to detect if field is available or not.
- Two additional feature probes are added for the fields:
  - `prog_info_map_ids()` probe -> `map_ids()` field
  - `prog_info_gpl_compatible()` probe -> `gpl_compatible()` field

With the `prog_info_map_ids()` probe, the previous implementation that
I had for `bpf_prog_get_info_by_fd()` is shortened to use the probe
instead of having to make 2 potential syscalls.

The `test_loaded_at()` test is also moved into info tests since it is
better related to the info tests.

`aya::programs::Programs::prog_type(&self)` now returns `ProgramType`
instead of the generated FFI from aya-obj.

Also previously, `loaded_programs()` could be accessed either through
`aya` or `aya::programs`. To avoid confusion and duplicate export of
the item, the function should now only be exposed through
`aya::programs`.
5 months ago
tyrone-wu cb8e478800
aya,integration-test: improve integration tests for info API
Improves the existing integraiton tests for `loaded_programs()` and
`loaded_maps()` in consideration for older kernels:
  - Opt for `SocketFilter` program in tests since XDP requires v4.8 and
    fragments requires v5.18.
  - For assertion tests, first perform the assertion, if the assertion
    fails, then it checks the host kernel version to see if it is above
    the minimum version requirement. If not, then continue with test,
    otherwise fail.
    For assertions that are skipped, they're logged in stderr which can
    be observed with `-- --nocapture`.

This also fixes the `bpf_prog_get_info_by_fd()` call for kernels below
v4.15. If calling syscall  on kernels below v4.15, it can produce an
`E2BIG` error  because `check_uarg_tail_zero()` expects the entire
struct to all-zero bytes (which is caused from the map info).

Instead, we first attempt the syscall with the map info filled, if it
returns `E2BIG`, then perform syscall again with empty closure.

Also adds doc for which version a kernel feature was introduced for
better  awareness.

The tests have been verified kernel versions:
  - 4.13.0
  - 4.15.0
  - 6.1.0
5 months ago
tyrone-wu a25f501ece
aya: expose run_time_ns and run_cnt fields in ProgramInfo
Added functions to expose `run_time_ns` & `run_cnt` statistics from
ProgramInfo/bpf_prog_info.
5 months ago
Michal Rostecki a75fc2f769 aya-log: Allow logging `core::net::Ipv4Addr` and `core::net::Ipv6Addr`
IP address types are available in `core`, so they can be used also in
eBPF programs. This change adds support of these types in aya-log.

* Add implementation of `WriteTuBuf` to these types.
* Support these types in `Ipv4Formatter` and `Ipv6Formatter`.
* Support them with `DisplayHint::Ip`.
* Add support for formatting `[u8; 4]`, to be able to handle
  `Ipv4Addr::octets`.
6 months ago
Wouter Dullaert fb0a339adf feat(aya-ebpf): Add integration test for memmove implementation 7 months ago
Tamir Duberstein 683cedfe48 Appease clippy
warning: doc list item missing indentation
  --> test/integration-test/build.rs:20:5
   |
20 | /// prevent their use for the time being.
   |     ^
   |
   = help: if this is supposed to be its own paragraph, add a blank line
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#doc_lazy_continuation
   = note: `#[warn(clippy::doc_lazy_continuation)]` on by default
help: indent this line
   |
20 | ///   prevent their use for the time being.
   |     ++
8 months ago
tyrone-wu 6988dac159 test/integration-ebpf: added integration tests for kretprobe & uretprobe
Added integration test methods for kretprobe and uretprobe with their
appropriate contexts.
9 months ago
Tamir Duberstein ac58601fb9 Revert "Disable false-positive clippy lint"
This reverts commit b552c83300.

Upstream fixed the false positive in
https://github.com/rust-lang/rust-clippy/commit/62fd1d5377c0bb917761b9f.
9 months ago
Tamir Duberstein b552c83300 Disable false-positive clippy lint
See https://github.com/rust-lang/rust-clippy/issues/12537.
10 months ago
Dave Tucker 8c79b71bd5 feat(aya): Rename Bpf to Ebpf
And BpfLoader to EbpfLoader.
This also adds type aliases to preserve the use of the old names, making
updating to a new Aya release less of a burden. These aliases are marked
as deprecated since we'll likely remove them in a later release.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
11 months ago
Dave Tucker a93e354620 feat(aya-log): Rename BpfLogger to EbpfLogger
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
11 months ago
Dave Tucker 41c61560ea chore(aya-ebpf): Rename bpf -> ebpf
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
11 months ago
Dave Tucker 022aff96aa chore: Rename bpf dir to ebpf
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
11 months ago
Dave Tucker 0e99fa0f34 Release aya-obj v0.1.0, aya v0.12.0, safety bump aya-log v0.2.0 11 months ago
Dave Tucker 13b1fc63ef chore: Don't use path deps in workspace
This moves the path dependencies back into the per-crate Cargo.toml.
It is required such that the release tooling can correctly calculate
which version constraints require changing when we perform a release.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
11 months ago
Dave Tucker b3e7ef741c chore: Use the cargo workspace package table
This allows for inheritance of common fields from the workspace root.
The following fields have been made common:

- authors
- license
- repository
- homepage
- edition

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
11 months ago
Dave Tucker 0c58bb66b6 integration-test: Fix build.rs output
The cargo::warning seems to ignore output after a newline.
Iterate over the entire rendered message and print it line-by-line.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
11 months ago
Michal Rostecki c05a3b69b7 aya-obj: Handle lack of match of enum variants correctly
When comparing `local_spec` with `target_spec` for enum relocations,
we can encounter a situation when a matchinng variant in a candidate
spec doesn't exist.

Before this change, such case wasn't handled explicitly, therefore
resulted in returning currently constructed `target_spec` at the
end. The problem is that such `target_spec` was, due to lack of
match, incomplete. It didn't contain any `accessors` nor `parts`.

Later usage of such incomplete `target_spec` was leading to panics,
since the code operating on enums' `target_spec` expects at least
one `accessor` to be available.

Fixes #868
12 months ago
astoycos b1769678f4 aya/maps: pin for (async)perf_event_array
Implement pinning for perf_event_array and async_perf_event_array.
Additionally make the core MapData.pin method operate on a reference
rather than a mutable reference.

Signed-off-by: astoycos <astoycos@redhat.com>
1 year ago
arctic-alpaca c89c95bc0b tests: change AF_XDP test `PacketMap` repr to `C` 1 year ago
lyuts 34ffde48ee tests: update instructions on setting up and running tests
- Update the list of required packages.
- Update the command for executing tests in a VM.
1 year ago
Alessandro Decina cc60ca77b9
Merge pull request #819 from Tuetuopay:test-afxdp
tests: add AF_XDP test using xdpilone
1 year ago
Adam Preuss 4d24d1cfe8 aya: add MapInfo struct following the same pattern as ProgramInfo
This makes the APIs for loading maps and programs more similar.
1 year ago