Commit Graph

194 Commits (3525560c4a98cb1c8f9ced749988e7bd030fc735)

Author SHA1 Message Date
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.
   |     ++
4 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.
5 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.
5 months ago
Tamir Duberstein b552c83300 Disable false-positive clippy lint
See https://github.com/rust-lang/rust-clippy/issues/12537.
6 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>
7 months ago
Dave Tucker a93e354620 feat(aya-log): Rename BpfLogger to EbpfLogger
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
7 months ago
Dave Tucker 41c61560ea chore(aya-ebpf): Rename bpf -> ebpf
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
7 months ago
Dave Tucker 022aff96aa chore: Rename bpf dir to ebpf
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
7 months ago
Dave Tucker 0e99fa0f34 Release aya-obj v0.1.0, aya v0.12.0, safety bump aya-log v0.2.0 7 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>
7 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>
7 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>
7 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
8 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>
10 months ago
arctic-alpaca c89c95bc0b tests: change AF_XDP test `PacketMap` repr to `C` 10 months 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.
10 months ago
Alessandro Decina cc60ca77b9
Merge pull request #819 from Tuetuopay:test-afxdp
tests: add AF_XDP test using xdpilone
10 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.
10 months ago
Dave Tucker 8780a50be1 .github: Add markdownlint
This adds a linter to catch common markdown formatting errors.
The linter used is markdownlint-cli2 which is available on all platforms
and has an associated Github Action to automate these checks in CI.

Configuration is checked in at .markdownlint-cli2.yaml.

You may run the check locally using `markdownlint-cli2`.
Or you may install the extension for VSCode:
DavidAnson.vscode-markdownlint

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
10 months ago
Tuetuopay e148ce1af3 tests/xdp: don't leak memory in AF_XDP test 11 months ago
Tuetuopay aa5ff517e7 tests: add AF_XDP test using xdpilone 11 months 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).
11 months 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.
11 months 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.
11 months 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>
11 months 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>
12 months 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.
12 months ago
Tamir Duberstein 062ebfdc68
integration/xdp: use kernel-allocated port 12 months ago
Tamir Duberstein 64d9799efc
integration/xdp: reduce repetition 12 months 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.
12 months ago
Tamir Duberstein d16e607fd4
rustfmt: group_imports = "StdExternalCrate"
High time we stop debating this; let the robots do the work.
12 months 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.
12 months ago
Tamir Duberstein ad460879ef
integration-test: replace macro with function
There's just no need for a macro here.
12 months 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.
12 months ago
Alessandro Decina 7f9ce062f4
Merge pull request #527 from Tuetuopay/xdpmaps
Implement XDP map types
1 year ago
Tuetuopay 579e3cee22 aya, bpf: misc fixes following review comments 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
Tuetuopay 4452364c41 macros: add 'map' option to xdp macro
This option allows to place the program in the specific sections to
chain programs with devmaps and cpumaps.
1 year ago
Tamir Duberstein f41592663c
maps: `MapFd` and `SockMapFd` are owned
`MapData::fd` is now a `MapFd`. This means that `MapData` now closes the
file descriptor on drop. In the future we might consider making `MapFd`
hold a `BorrowedFd` but this requires API design work due to overlapping
borrows.

Since `SockMapFd` is no longer `Copy`, attach methods to take it by
reference to allow callers to use it multiple times as they are
accustomed to doing.

`SockMapFd` implements `try_clone`. `MapFd` and `SockMapFd` are now
returned by reference to allow callers to avoid file descriptor cloning
when desired.

This is an API breaking change.

Updates #612.
1 year ago
Tamir Duberstein 0a144a0e69
integration-test: remove all sleeps 1 year ago
Tamir Duberstein ca2e43d318
integration-test: Remove cargo symlink workaround
https://github.com/rust-lang/cargo/pull/12369 fixed this bug and was
picked up in https://github.com/rust-lang/rust/pull/114027.
1 year ago
Tamir Duberstein 89bc255f1d
aya: MapData::fd is non-optional
The primary driver of change here is that `MapData::create` is now a
factory function that returns `Result<Self, _>` rather than mutating
`&mut self`. The remaining changes are consequences of that change, the
most notable of which is the removal of several errors which are no
longer possible.
1 year ago
Tamir Duberstein ae6526e59b
programs: `ProgramData::attach_prog_fd` is owned
This prevents a file descriptor leak when extensions are used.

This is an API breaking change.

Updates #612.
1 year ago
Andrew Stoycos e1a556894c
aya: add helper methods for ProgramInfo
- Add helper methods to get useful information from the ProgramInfo
object which is returned by the `loaded_programs()` API.  Specifically
this code mirrors the `bpftool prog` command in terms of useful fields.
- Add a new API macro to each aya `Program` type to allow us to fetch
its accompanying `ProgramInfo` metadata after its been loaded.
- Add a new ProgramInfo constructor that builds a new instance using
a raw fd.
- Add a smoke test for the loaded_programs() API as well as
all the relevant methods on the ProgramInfo type.

Signed-off-by: Andrew Stoycos <astoycos@redhat.com>
1 year ago
Tamir Duberstein 82a77bc83d
integration-test: Implement running on VMs
Implements running integration tests on multiple VMs with arbitrary
kernel images using `cargo xtask integration-test vm ...`.

This changes our coverage from 6.2 to 6.1 and 6.4.
1 year ago
Tamir Duberstein b6a6a81f95
integration-test: deflake log test
Wait for at least one log and increase the wait time 10x.
1 year ago
Tamir Duberstein 3cfd886dc5
log: annotate logging functions inlining
Some of these functions fail to compile when not inlined, so we should
be explicit.

Before deciding on this approach I tried various ways of making all
these functions #[inline(never)] to save instructions but I ran into
blockers:
- These functions currently return Result, which is a structure. This is
  not permitted in BPF.
- I tried inventing a newtype that is a #[repr(transparent)] wrapper of
  u16, and having these functions return that; however it seems that
  even if the object code is legal, the verifier will reject such
  functions because the BTF (if present, and it was in my local
  experiments) would indicate that the return is a structure.
- I tried having these functions return a plain u16 where 0 means error,
  but the verifier still rejected the BTF because the receiver (even if
  made into &self) is considered a structure, and forbidden.

We can eventually overcome these problems by "lying" in our BTF once
support for it matures in the bpf-linker repo (e.g. Option<NonZeroU16>
should be perfectly legal as it is guaranteed to be word-sized), but we
aren't there yet, and this is the safest thing we can do for now.
1 year ago