Commit Graph

172 Commits (main)

Author SHA1 Message Date
Dave Tucker 2791badd94 Release aya v0.13.1
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
1 week ago
Dave Tucker c6a34cade1 Release aya-obj v0.2.1
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
1 week 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>
1 week ago
Tamir Duberstein 758a4f9d1e Remove workspace members from workspace.dependencies
Doesn't make much sense to have them here.
4 weeks ago
Dave Tucker 0e70838b0f Release aya-log v0.2.1
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
1 month 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>
1 month 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>
1 month 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
```
1 month ago
Tamir Duberstein f498a1b7a9 Remove assertion that doesn't work in macOS HVF 2 months ago
Tamir Duberstein 5b29008691 Appease `static_mut_refs`
Made stricter in https://github.com/rust-lang/rust/commit/5ba6db1b648d9.
2 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
2 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.
2 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`.
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
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
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
Wouter Dullaert fb0a339adf feat(aya-ebpf): Add integration test for memmove implementation 4 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.
   |     ++
6 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.
7 months ago
Tamir Duberstein b552c83300 Disable false-positive clippy lint
See https://github.com/rust-lang/rust-clippy/issues/12537.
8 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>
8 months ago
Dave Tucker a93e354620 feat(aya-log): Rename BpfLogger to EbpfLogger
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
8 months ago
Dave Tucker 0e99fa0f34 Release aya-obj v0.1.0, aya v0.12.0, safety bump aya-log v0.2.0 9 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>
9 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>
9 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>
9 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
10 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>
12 months ago
arctic-alpaca c89c95bc0b tests: change AF_XDP test `PacketMap` repr to `C` 12 months ago
Alessandro Decina cc60ca77b9
Merge pull request #819 from Tuetuopay:test-afxdp
tests: add AF_XDP test using xdpilone
12 months 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.
12 months ago
Tuetuopay e148ce1af3 tests/xdp: don't leak memory in AF_XDP test 1 year ago
Tuetuopay aa5ff517e7 tests: add AF_XDP test using xdpilone 1 year ago
Tamir Duberstein fa6f5e2532
github: run integration tests on local kernel
This tests on 6.2.0-1012-azure (see
https://github.com/actions/runner-images/releases/tag/ubuntu22%2F20231001.1).
1 year ago
Alessandro Decina d679a973ca integration-tests: enable logs
Use test_log::test so setting RUST_LOG=aya=debug works and it's easier
to debug failures.
1 year ago
Alessandro Decina 2227223a96 aya-log: fix hygiene
Before this change we leaked some bindings to the calling scope, so for
instance logging a variable named "len" led to a compile error.
1 year ago
Andrew Werner e2cf734490 aya: Implement RingBuf
This implements the userspace binding for RingBuf.

Instead of streaming the samples as heap buffers, the process_ring
function takes a callback to which we pass the event's byte region,
roughly following [libbpf]'s API design. This avoids a copy and allows
marking the consumer pointer in a timely manner.

[libbpf]: https://github.com/libbpf/libbpf/blob/master/src/ringbuf.c

Additionally, integration tests are added to demonstrate the usage
of the new APIs and to ensure that they work end-to-end.

Co-authored-by: William Findlay <william@williamfindlay.com>
Co-authored-by: Tatsuyuki Ishi <ishitatsuyuki@gmail.com>
1 year ago
astoycos 82039144bd integration-test: Add map pinning coverage
Add coverage to the new public api's for
map pinning (pin and unpin) which can be called
on the generic aya::Map type OR explit map types.

Additionally add coverage for the new libbpf
LIBBPF_PIN_BY_NAME behavior.

Signed-off-by: astoycos <astoycos@redhat.com>
1 year ago
Tamir Duberstein 81268b7ac1
integration/xdp: increase timeout to 60 seconds
There's absolutely no reason to have a short timeout here. This has
resulted in at least one flake:
https://github.com/aya-rs/bpf-linker/actions/runs/6384472390/job/17327196576.
1 year ago
Tamir Duberstein 062ebfdc68
integration/xdp: use kernel-allocated port 1 year ago
Tamir Duberstein 64d9799efc
integration/xdp: reduce repetition 1 year ago
Andrew Werner da832e479d integration-test: deflake test_loaded_at
The test could fail due to the lack of clock monotonicity. This PR
deflakes the test by adding retries.

See
https://github.com/aya-rs/aya/actions/runs/6340369670/job/17221591723.
1 year ago
Tamir Duberstein d16e607fd4
rustfmt: group_imports = "StdExternalCrate"
High time we stop debating this; let the robots do the work.
1 year ago
Tamir Duberstein 15de14383d
integration-test: build eBPF for the proper arch
Prior to this change we neglected to build integration-ebpf for the
correct target architecture, resulting in test failures on arm64.
1 year ago
Tamir Duberstein 8cee3f8b01
integration-test: distinguish between success and noop
These tests previously produced the same result on certain failures as
they did on success.
1 year ago
Alessandro Decina 7f9ce062f4
Merge pull request #527 from Tuetuopay/xdpmaps
Implement XDP map types
1 year ago
astoycos dffff1ce6b integration-test: fix load time and add test
Time since boot is defined as the UNIX_EPOCH plus the duration
since boot. which is realtime - boottime NOT boottime - realtime.

Add a integration test to ensure this doesn't happen again.

Signed-off-by: astoycos <astoycos@redhat.com>
1 year ago
Tuetuopay c6754c614e maps/xdp: use ProgramFd instead of impl AsRawFd
Not having a generic here allows to pass `None` without specifying the
actual type you don't care about.
1 year ago
Tuetuopay 0647927e32 xdp: add support for chained xdp programs in {cpu,dev}map
set/insert functions can now take an optional bpf program fd to run once
the packet has been redirected from the main probe
1 year ago
Tuetuopay 139f382638 aya: add support for map-bound XDP programs
Such programs are to be bound to cpumap or devmap instead of the usual
network interfaces.
1 year ago