Commit Graph

261 Commits (main)

Author SHA1 Message Date
tamird 29b821376e public-api: regenerate 3 days ago
Tamir Duberstein 356cf45914 Use Set (instead of Map) to hold links
This uses hashbrown instead of std because the latter relies on Borrow
which requires a reference; hashbrown's Equivalent is more flexible.
4 days ago
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 78ee9a4634 Avoid useless conversions
Use native C types to avoid platform-dependent conversions.
3 weeks ago
Michal Rostecki 4f0559f2af chore: Fix cippy errors 3 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 cc2da4a2a4 ci: download gen_init_cpio with authentication
The raw endpoint[0] now[1] seems to return HTTP 429 on the first request
and unauthenticated API limits are exceeded after one request (so one of
ubuntu/macos builders fails). Hopefully this works with authentication.

Link: https://raw.githubusercontent.com/torvalds/linux/refs/heads/master/usr/gen_init_cpio.c [0]
Link: https://github.com/orgs/community/discussions/146957 [1]
1 month 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 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 1de7e728b6 Allow aya-ebpf to clippy with stable rust
The const-assert crate doesn't even compile with stable rust, so we
shouldn't depend on it. Instead we replicate its functionality behind
cfg(unstable) which is set at build time based on the toolchain in use.
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
Tamir Duberstein 119049f2a2 Define `{detach,take_link}` in macro when possible 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
banditopazzo a16755089b Avoid warning with `allow_unsupported_maps`
Remove the warning log altogether; either it's an error or it isn't.
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
dependabot[bot] f20a09d053
build(deps): update public-api requirement in the cargo-crates group
Updates the requirements on [public-api](https://github.com/cargo-public-api/cargo-public-api) to permit the latest version.

Updates `public-api` to 0.40.0
- [Release notes](https://github.com/cargo-public-api/cargo-public-api/releases)
- [Changelog](https://github.com/cargo-public-api/cargo-public-api/blob/main/CHANGELOG.md)
- [Commits](https://github.com/cargo-public-api/cargo-public-api/compare/public-api-v0.40.0...public-api-v0.40.0)

---
updated-dependencies:
- dependency-name: public-api
  dependency-type: direct:production
  dependency-group: cargo-crates
...

Signed-off-by: dependabot[bot] <support@github.com>
2 months ago
tamird e423fce58f public-api: regenerate 2 months ago
tamird 5075adc01d public-api: regenerate 2 months ago
Tamir Duberstein e3bfeb9dd6 Allow QEMU to fall back 3 months ago
Tamir Duberstein f9b34fe76f qemu: remove bios argument
I did this for arm64 because we'd get a black screen without it but I
have now confirmed that console=ttyAMA0 solves that problem.

I don't remember why I did it for x86.
3 months ago
dave-tucker f8ad84c3d3 [codegen] Update libbpf to 80b16457cb23db4d633b17ba0305f29daa2eb307
Update libbpf to 80b16457cb23db4d633b17ba0305f29daa2eb307

Files changed:
M	aya-obj/src/generated/btf_internal_bindings.rs
M	aya-obj/src/generated/linux_bindings_aarch64.rs
M	aya-obj/src/generated/linux_bindings_armv7.rs
M	aya-obj/src/generated/linux_bindings_powerpc64.rs
M	aya-obj/src/generated/linux_bindings_riscv64.rs
M	aya-obj/src/generated/linux_bindings_s390x.rs
M	aya-obj/src/generated/linux_bindings_x86_64.rs
3 months ago
Tyrone Wu 366c599c20 codegen: cgroup_iter_order NFPROTO* nf_inet_hooks
Adds the following to codegen:
- `bpf_cgroup_iter_order`: used in `bpf_link_info.iter.group.order`
- `NFPROTO_*`: used in `bpf_link_info.netfilter.pf`
- `nf_inet_hooks`: used in `bpf_link_info.netfilter.hooknum`

Include `linux/netfilter.h` in `linux_wrapper.h` for `NFPROTO_*` and
`nf_inet_hooks` to generate.
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
dependabot[bot] 1d272f38bd build(deps): update hashbrown requirement in the cargo-crates group
Updates the requirements on [hashbrown](https://github.com/rust-lang/hashbrown) to permit the latest version.

Updates `hashbrown` to 0.15.0
- [Changelog](https://github.com/rust-lang/hashbrown/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rust-lang/hashbrown/compare/v0.14.3...v0.15.0)

---
updated-dependencies:
- dependency-name: hashbrown
  dependency-type: direct:production
  dependency-group: cargo-crates
...

Signed-off-by: dependabot[bot] <support@github.com>
3 months ago
GrigorenkoPV 55ed9e0546
fix(aya-log): print &[u8] using full width (#1008)
Otherwise `&[1u8, 0u8]` cannot be distinguished from `&[0x10u8]` (they both become 10)
4 months ago
Tamir Duberstein e992c280cb Replace `Arc` with `&'static` 4 months ago
Tamir Duberstein f3b2744072 Reduce duplication in `{nr,possible}_cpus` 4 months ago
Zero King c44f8b0f5b aya: use FdLink in SockOps programs
See: https://github.com/aya-rs/aya/issues/987
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
Zero King 95e1763e30 aya-ebpf: Add set_reply accessor to SockOpsContext 5 months ago
Harvo Jones f790685d75 Add the option to support multiple and overrideable programs per cgroup
This change allows multiple BPF programs to attach to a cgroup (via the option
`CgroupAttachMode::AllowMultiple`), and allows a program to specify that it can be
overridden by one in a sub-cgroup (via the option `CgroupAttachMode::AllowOverride`).
5 months ago
tyrone-wu ea1130449b
codegen: add `bpf_perf_event_type` enum bindings
Adds the `bpf_perf_event_type` enum to FFI bindings, which is being used
in the `perf_event.type` field in `bpf_link_info`.
5 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 1634fa7188
aya-obj: add conversion u32 to enum type for prog, link, & attach type
Add conversion from u32 to program type, link type, and attach type.
Additionally, remove duplicate match statement for u32 conversion to
`BPF_MAP_TYPE_BLOOM_FILTER` & `BPF_MAP_TYPE_CGRP_STORAGE`.

New error `InvalidTypeBinding<T>` is created to represent when a
parsed/received value binding to a type is invalid.
This is used in the new conversions added here, and also replaces
`InvalidMapTypeError` in `TryFrom` for `bpf_map_type`.
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
tyrone-wu fa6af6a204
aya,aya-obj: add BPF_ENABLE_STATS syscall function
Add bpf syscall function for BPF_ENABLE_STATS to enable stats tracking
for benchmarking purposes.

Additionally, move `#[cfg(test)]` annotation around the `Drop` trait
instead. Having separate functions causes some complications when
needing ownership/moving of the inner value `OwnedFd` when `Drop` is
manually implemented.
5 months ago
Tamir Duberstein 23ece3d794 public-api: regenerate
See https://github.com/rust-lang/rust/pull/126877, I think.
5 months ago
Dave Tucker 9a138870f3 chore(xtask): Bless API changes
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
5 months ago
astoycos a52ad4ba2a codegen: add `tcx_action_base` enum to bindings
Signed-off-by: astoycos <astoycos@gmail.com>
5 months ago
Dave Tucker 3d57d358e4 fix(aya): Fix PerfEventArray resize logic
There was a logic bug in the previously merged patch where we
set the correctly calculated max_entries size with the original.

To fix this and prevent regressions a unit test was added.
This highlighted that the original map definition needs to be
mutated in order for the max_entries change to be properly applied.

As such, this resize logic moved out of aya::sys into aya::maps

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
6 months ago
Dave Tucker ef0d1253ef fix(ebpf): Remove PerfEventArray::with_max_entries
This API doesn't make sense as the max_entries needs to be set to the
number of online CPUs by the loader.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
6 months ago
Michal Rostecki 6dab7176f5 chore: Bless public API 6 months ago
dave-tucker 8d7446e011 [codegen] Update libbpf to 686f600bca59e107af4040d0838ca2b02c14ff50
Update libbpf to 686f600bca59e107af4040d0838ca2b02c14ff50

Files changed:
M	aya-obj/src/generated/linux_bindings_aarch64.rs
M	aya-obj/src/generated/linux_bindings_armv7.rs
M	aya-obj/src/generated/linux_bindings_powerpc64.rs
M	aya-obj/src/generated/linux_bindings_riscv64.rs
M	aya-obj/src/generated/linux_bindings_s390x.rs
M	aya-obj/src/generated/linux_bindings_x86_64.rs

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
6 months ago
tyrone-wu 86e279ef0a
codegen: add bpf_stats_type
Added `bpf_stats_type` enum to codegen bindings.

Refs: #959
6 months ago
Wouter Dullaert b8a22fa040 feat(aya-ebpf): Add memmove to the public-api 7 months ago
dependabot[bot] d581431d9a
build(deps): update public-api requirement in the cargo-crates group
Updates the requirements on [public-api](https://github.com/Enselic/cargo-public-api) to permit the latest version.

Updates `public-api` to 0.35.1
- [Release notes](https://github.com/Enselic/cargo-public-api/releases)
- [Changelog](https://github.com/Enselic/cargo-public-api/blob/main/rustdoc-json/CHANGELOG.md)
- [Commits](https://github.com/Enselic/cargo-public-api/compare/public-api-v0.35.0...public-api-v0.35.1)

---
updated-dependencies:
- dependency-name: public-api
  dependency-type: direct:production
  dependency-group: cargo-crates
...

Signed-off-by: dependabot[bot] <support@github.com>
7 months ago
dave-tucker 8b50a6a573 [codegen] Update libbpf to c1a6c770c46c6e78ad6755bf596c23a4e6f6b216
Update libbpf to c1a6c770c46c6e78ad6755bf596c23a4e6f6b216

Files changed:
M	aya-obj/src/generated/linux_bindings_aarch64.rs
M	aya-obj/src/generated/linux_bindings_armv7.rs
A	aya-obj/src/generated/linux_bindings_powerpc64.rs
M	aya-obj/src/generated/linux_bindings_riscv64.rs
A	aya-obj/src/generated/linux_bindings_s390x.rs
M	aya-obj/src/generated/linux_bindings_x86_64.rs
M	ebpf/aya-ebpf-bindings/src/aarch64/bindings.rs
M	ebpf/aya-ebpf-bindings/src/armv7/bindings.rs
A	ebpf/aya-ebpf-bindings/src/powerpc64/bindings.rs
A	ebpf/aya-ebpf-bindings/src/powerpc64/helpers.rs
M	ebpf/aya-ebpf-bindings/src/riscv64/bindings.rs
A	ebpf/aya-ebpf-bindings/src/s390x/bindings.rs
A	ebpf/aya-ebpf-bindings/src/s390x/helpers.rs
M	ebpf/aya-ebpf-bindings/src/x86_64/bindings.rs

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
7 months ago