Commit Graph

1767 Commits (88f5ac31142f1657b41b1ee0f217dcd9125b210a)
 

Author SHA1 Message Date
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`.
2 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`.
2 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
2 months ago
Alessandro Decina ab000ad7c3
Merge pull request #959 from tyrone-wu/aya/program_info_stats
aya,aya-obj: expose run_time_ns & run_cnt fields, and add bpf_enable_stats util function
2 months ago
Alessandro Decina ab5e688fd4
Merge pull request #974 from Billy99/billy99-arch-ppc64-s390x
aya: add archs powerpc64 and s390x to aya
2 months ago
Billy McFall 4dc4b5ccd4 test: adjust test to not use byte arrays
Where possible, replace the hardcoded byte arrays in the tests with the
structs they represent, then convert the structs to byte arrays.

Signed-off-by: Billy McFall <22157057+Billy99@users.noreply.github.com>
3 months ago
Billy McFall cd1db86fd4 aya: adjust bpf programs for big endian
In aya/src/sys/bpf.rs, there are several simple bpf programs written as
byte arrays. These need to be adjusted to account for big endian.

Signed-off-by: Billy McFall <22157057+Billy99@users.noreply.github.com>
3 months ago
Billy McFall b513af12e8 aya: add archs powerpc64 and s390x to aya
bpfman, a project using aya, has a requirement to support powerpc64 and
s390x architectures. Adding these two architectures to aya.

Signed-off-by: Billy McFall <22157057+Billy99@users.noreply.github.com>
3 months ago
Billy McFall eef7346fb2 test: adjust test byte arrays for big endian
Adding support for s390x (big endian architecture) and found that some
of the unit tests have structures and files implemented as byte arrays.
They are all coded as little endian and need a bug endian version to
work properly.

Signed-off-by: Billy McFall <22157057+Billy99@users.noreply.github.com>
3 months ago
Tamir Duberstein 4362020691 Simplify doctest 3 months ago
Tamir Duberstein bce3c4fb1d Appease nightly clippy
```
error: first doc comment paragraph is too long
  --> aya/src/programs/raw_trace_point.rs:12:1
   |
12 | / /// A program that can be attached at a pre-defined kernel trace point, but also
13 | | /// has an access to kernel internal arguments of trace points, which
14 | | /// differentiates them from traditional tracepoint eBPF programs.
15 | | ///
16 | | /// The kernel provides a set of pre-defined trace points that eBPF programs can
   | |_
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#too_long_first_doc_paragraph

error: first doc comment paragraph is too long
  --> ebpf/aya-ebpf/src/helpers.rs:1:1
   |
1  | / //! This module contains kernel helper functions that may be exposed to specific BPF
2  | | //! program types. These helpers can be used to perform common tasks, query and operate on
3  | | //! data exposed by the kernel, and perform some operations that would normally be denied
4  | | //! by the BPF verifier.
5  | | //!
6  | | //! Here, we provide some higher-level wrappers around the underlying kernel helpers, but
   | |_
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#too_long_first_doc_paragraph
```
3 months ago
Andrew Stoycos 47b0dde395
Merge pull request #1013 from astoycos/bump-int
Add a 6.10 linux kernel to the virtualized testing in CI
3 months ago
astoycos 25beb14ff0
run virtualized CI on multiple kernels
Ensure we download multiple kernel versions to run
our virtualized CI against.

Bump xdpilone version to fix bug on latest kernel.

Signed-off-by: astoycos <astoycos@gmail.com>
3 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.
3 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.
3 months ago
dependabot[bot] a54532f848 build(deps): bump the cargo-crates group across 1 directory with 2 updates
Updates the requirements on [bindgen](https://github.com/rust-lang/rust-bindgen) and [public-api](https://github.com/cargo-public-api/cargo-public-api) to permit the latest version.

Updates `bindgen` to 0.69.4
- [Release notes](https://github.com/rust-lang/rust-bindgen/releases)
- [Changelog](https://github.com/rust-lang/rust-bindgen/blob/main/CHANGELOG.md)
- [Commits](https://github.com/rust-lang/rust-bindgen/compare/v0.69.0...v0.69.4)

Updates `public-api` to 0.36.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/rustdoc-json/CHANGELOG.md)
- [Commits](https://github.com/cargo-public-api/cargo-public-api/compare/public-api-v0.36.0...public-api-v0.36.0)

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

Signed-off-by: dependabot[bot] <support@github.com>
3 months ago
Tamir Duberstein 23ece3d794 public-api: regenerate
See https://github.com/rust-lang/rust/pull/126877, I think.
3 months ago
Dave Tucker bdbd0423f8
Merge pull request #1010 from aya-rs/codegen
Update libbpf to b07dfe3b2a6cb0905e883510f22f9f7c0bb66d0d
3 months ago
Dave Tucker 9a138870f3 chore(xtask): Bless API changes
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
3 months ago
dave-tucker e2177278ae [codegen] Update libbpf to b07dfe3b2a6cb0905e883510f22f9f7c0bb66d0dUpdate libbpf to b07dfe3b2a6cb0905e883510f22f9f7c0bb66d0d
Files changed:
M	ebpf/aya-ebpf-bindings/src/aarch64/bindings.rs
M	ebpf/aya-ebpf-bindings/src/armv7/bindings.rs
M	ebpf/aya-ebpf-bindings/src/powerpc64/bindings.rs
M	ebpf/aya-ebpf-bindings/src/riscv64/bindings.rs
M	ebpf/aya-ebpf-bindings/src/s390x/bindings.rs
M	ebpf/aya-ebpf-bindings/src/x86_64/bindings.rs
3 months ago
Dave Tucker 2a459a4005
Merge pull request #1006 from astoycos/tcx-return
codegen: add `tcx_action_base` enum to bindings
3 months ago
astoycos a52ad4ba2a codegen: add `tcx_action_base` enum to bindings
Signed-off-by: astoycos <astoycos@gmail.com>
3 months ago
Tamir Duberstein 41619933d6 Revert "Remove unused `allow(dead_code)`"
This reverts commit 5397c1ca4b.
3 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>
3 months ago
Michal Rostecki e575712c59 chore: Add comments in `*_wrong_map` tests 3 months ago
Dave Tucker 25d986a26d fix(aya): Set PerfEventArray max_entries to nCPUs
Both libbpf and cilium/ebpf have will set the max_entries of a
BPF_MAP_TYPE_PERF_EVENT_ARRAY to the number of online CPUs if
it was omitted at map definition time. This adds that same
logic to Aya.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
3 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>
3 months ago
Tamir Duberstein e12fcf46cb Use MockableFd everywhere
Rust 1.80 contains https://github.com/rust-lang/rust/pull/124210,
causing tests which we skip under miri to segfault.
3 months ago
Michal Rostecki a167554b8b ci: Use apt repository with LLVM 18 explicitly
The unversioned one is suffering from LLVM 19 => 20 migration issues,
see llvm/llvm-project#100466.
4 months ago
Tamir Duberstein 956dd01375 Install Rust toolchain later
`brew` seems to be breaking the rustup installed by rust-toolchain:

```
==> Migrating formula rustup-init to rustup
==> Unlinking rustup-init
==> Moving rustup-init versions to /opt/homebrew/Cellar/rustup
==> Relinking rustup
```

Let's see if this fixes it.
4 months ago
Tamir Duberstein 4025861780 Don't hardcode /usr/local/opt 4 months ago
Tamir Duberstein 28545d3331 Use macos-13 4 months ago
Tamir Duberstein 247486cb7d Remove stale workaround 4 months ago
Tamir Duberstein 5397c1ca4b Remove unused `allow(dead_code)`
See 31fe9628cf.
4 months ago
Michal Rostecki 6dab7176f5 chore: Bless public API 4 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`.
4 months ago
ajwerner 2cd9858ea9
Merge pull request #991 from l2dy/typo-1
docs(aya): fix typo
4 months ago
Zero King f1773d5af4 docs(aya): fix typo 4 months ago
Dave Tucker 8015e10079
Merge pull request #989 from aya-rs/codegen
Update libbpf to 686f600bca59e107af4040d0838ca2b02c14ff50
4 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>
4 months ago
Dave Tucker 104f449c0f
Merge pull request #988 from tyrone-wu/codegen/bpf-stats-type
codegen: add `bpf_stats_type` to codegen
4 months ago
tyrone-wu 86e279ef0a
codegen: add bpf_stats_type
Added `bpf_stats_type` enum to codegen bindings.

Refs: #959
4 months ago
Dave Tucker d5414bf10c
Merge pull request #983 from ajwerner/fix-variable-name
aya::programs::uprobe: fix bad variable name
4 months ago
Andrew Werner d413e2f285 aya::programs::uprobe: fix bad variable name
The variable fn_name was very much *not* the fn_name, but rather the
object file path.
4 months ago
Wouter Dullaert b8a22fa040 feat(aya-ebpf): Add memmove to the public-api 4 months ago
Wouter Dullaert fb0a339adf feat(aya-ebpf): Add integration test for memmove implementation 4 months ago
Wouter Dullaert 7ad3926d99 feat(aya-ebpf): Implement memmove
The compiler will emit this function for certain operations, but aya
currently does not provide an implementation.
This leads to ebpf loading failures as the kernel can't find the symbol when
loading the program.

The implementation is based on https://github.com/rust-lang/compiler-builtins/blob/master/src/mem/mod.rs#L29-L40
and https://github.com/rust-lang/compiler-builtins/blob/master/src/mem/impls.rs#L128-L135
Only the simplest case has been implemented, none of the word optimizations,
since memcpy also doesn't seem to have them.
4 months ago
dependabot[bot] 09815d3c0c
Merge pull request #980 from aya-rs/dependabot/cargo/cargo-crates-95ee854e2a 4 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>
4 months ago
Tamir Duberstein bac059fd41 Bump kernel image revision
6.1.0-15 seems to have been pulled.
4 months ago