Commit Graph

1780 Commits (main)
 

Author SHA1 Message Date
Alessandro Decina b87f4b9642
Merge pull request #1029 from aya-rs/fix/ci-linux-kernel-version
Fix linux kernel version in gh ci runners
6 days ago
Davide Bertola e775f8329b Fix linux kernel version in gh ci runners 7 days ago
Alessandro Decina 2cd35769dc
Merge pull request #1023 from l2dy/fdlink/sockops
aya: use FdLink in SockOps programs
1 week ago
Zero King c44f8b0f5b aya: use FdLink in SockOps programs
See: https://github.com/aya-rs/aya/issues/987
1 week 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
2 weeks ago
Alessandro Decina 635ed3baed
Merge pull request #1020 from l2dy/sockops-ctx
aya-ebpf: Add set_reply accessor to SockOpsContext
2 weeks ago
Zero King 95e1763e30 aya-ebpf: Add set_reply accessor to SockOpsContext 2 weeks ago
Alessandro Decina 40f303205f
Merge pull request #985 from reyzell/main
Add the option to support multiple and overrideable programs per cgroup
2 weeks 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`).
2 weeks ago
Alessandro Decina 9406601cf9
Merge pull request #1018 from tyrone-wu/codegen/bpf_perf_event_type
codegen: add `bpf_perf_event_type` enum bindings
2 weeks 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`.
2 weeks ago
Alessandro Decina 15eb935bce
Merge pull request #1007 from tyrone-wu/aya/info-api
aya,aya-obj,integration-test: add better support in `ProgramInfo` & `MapInfo` for old kernels
2 weeks 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.
2 weeks 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`.
2 weeks 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 weeks 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
3 weeks 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
3 weeks ago
Alessandro Decina ab5e688fd4
Merge pull request #974 from Billy99/billy99-arch-ppc64-s390x
aya: add archs powerpc64 and s390x to aya
3 weeks 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 weeks 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 weeks 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 weeks 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 weeks ago
Tamir Duberstein 4362020691 Simplify doctest 3 weeks 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 weeks ago
Andrew Stoycos 47b0dde395
Merge pull request #1013 from astoycos/bump-int
Add a 6.10 linux kernel to the virtualized testing in CI
4 weeks 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>
4 weeks 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.
1 month 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.
1 month 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>
1 month ago
Tamir Duberstein 23ece3d794 public-api: regenerate
See https://github.com/rust-lang/rust/pull/126877, I think.
1 month ago
Dave Tucker bdbd0423f8
Merge pull request #1010 from aya-rs/codegen
Update libbpf to b07dfe3b2a6cb0905e883510f22f9f7c0bb66d0d
1 month ago
Dave Tucker 9a138870f3 chore(xtask): Bless API changes
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
1 month 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
1 month ago
Dave Tucker 2a459a4005
Merge pull request #1006 from astoycos/tcx-return
codegen: add `tcx_action_base` enum to bindings
1 month ago
astoycos a52ad4ba2a codegen: add `tcx_action_base` enum to bindings
Signed-off-by: astoycos <astoycos@gmail.com>
1 month ago
Tamir Duberstein 41619933d6 Revert "Remove unused `allow(dead_code)`"
This reverts commit 5397c1ca4b.
1 month 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>
2 months ago
Michal Rostecki e575712c59 chore: Add comments in `*_wrong_map` tests 2 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>
2 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>
2 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.
2 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.
2 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.
2 months ago
Tamir Duberstein 4025861780 Don't hardcode /usr/local/opt 2 months ago
Tamir Duberstein 28545d3331 Use macos-13 2 months ago
Tamir Duberstein 247486cb7d Remove stale workaround 2 months ago
Tamir Duberstein 5397c1ca4b Remove unused `allow(dead_code)`
See 31fe9628cf.
2 months ago
Michal Rostecki 6dab7176f5 chore: Bless public API 2 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`.
2 months ago
ajwerner 2cd9858ea9
Merge pull request #991 from l2dy/typo-1
docs(aya): fix typo
2 months ago