Commit Graph

39 Commits

Author SHA1 Message Date
Tamir Duberstein
2f8759cc62 Dial the lints to 100 2026-01-29 10:02:48 -05:00
Tamir Duberstein
0d1193720b doc: generate docs in macro
Remove a bunch of repetition and missing links.
2025-08-11 16:35:21 -04:00
Dave Tucker
2b0dcfbd09 feat: Allow conversions to Program from ProgramInfo
Allow for a ProgramInfo to be converted into one of the program types
that we support. This allows for a user of Aya access to reattach,
pin or unload a program that was either, previously loaded, or was
loaded by another process.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2025-03-24 13:09:13 +00:00
Tamir Duberstein
f0a9f19ddc Bump edition to 2024
Change FromRawTracepointArgs::arg to return T rather than *const T which
seems to have been returning a dangling pointer.

Arguably this is not strictly necessary; edition 2024 seems to be
focused on increased strictness around unsafe code which doesn't unlock
new functionality for our users. That said, this work revealed an
apparent bug (see above) that we wouldn't otherwise catch due to
allow-by-default lints.
2025-03-04 10:43:56 -05:00
Tyrone Wu
665d4f20bb chore: remove aya_obj -> obj alias
When `aya::obj` was migrated to be its own crate `aya-obj`, the `obj`
alias was created to preserve existing imports that relied on
`crate::obj`.

This resulted in 3 ways to import `aya-obj` objects:
- `use aya_obj::*`
- `use obj::*`
- `use crate::obj::*`

The `obj` alias is now removed to avoid confusion, and all `obj` imports
are funneled through `aya_obj`.
2025-02-03 16:30:23 +01:00
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.
2025-01-14 09:40:00 -05:00
Tamir Duberstein
119049f2a2 Define {detach,take_link} in macro when possible 2024-11-24 12:25:55 -05:00
Michal Rostecki
85c73af1fe doc(aya): Improve the description of take_link methods
Don't mix the tenses.
2024-11-24 16:27:44 +01:00
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>
2024-10-09 16:31:40 +07:00
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`).
2024-09-04 09:45:10 +00:00
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.
2024-07-29 10:42:22 +02:00
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>
2024-03-05 11:53:12 +00:00
Tamir Duberstein
204d02022a programs: ProgAttachLink and LircLink hold owned FDs
Updates #612.
2023-08-29 17:54:26 -04:00
Andrés Medina
6895b1e2ed aya: Use AsFd when attaching fds to programs
This is a breaking change but adds another level of safety to ensure
the file descriptor we receive is valid. Additionally, this allows
aya to internally easily duplicate this file descriptor using std
library methods instead of manually calling `dup` which doesn't
duplicate with the CLOSE_ON_EXEC flag that is standard pratice to
avoid leaking the file descriptor when exec'ing.
2023-08-29 09:58:33 -04:00
Andrés Medina
d2e74e562d aya: Use BorrowedFd when using the program fd in sys/bpf.rs
This commit reveals but does not address a file descriptor leak in
LircLink2::query. This function returns a list of `LircLink`s where
each of them have a program file descriptor that is not going to be
closed. This commit does not add this leak; it merely makes it louder
in the code.
2023-08-29 09:55:38 -04:00
Tamir Duberstein
abda239d63 aya: deny various allow-by-default lints
Notably:
- clippy::use_self: replaced many T with Self.
- single_use_lifetimes: removed some single use lifetimes.
- unreachable_pub: removed some unreachable pub items.
- unused_crate_dependencies: removed unused futures,parking_lot deps.
- unused_qualifications: found a potential `crate` vs `$crate` bug.
- let_underscore_drop: not enabled, seems to trigger false positives.
- missing_copy_implementations: not enabled, unclear if we want this.
- unsafe_op_in_unsafe_fn: not enabled, unclear if we want this.
- unused_results: not enabled, needs many fixes (but I think wanted).
2023-08-23 16:26:35 -04:00
Tamir Duberstein
504fd1df0a programs: ProgramFd is owned
`ProgramData::fd` is now a `ProgramFd`. This means that `ProgramData`
now closes the file descriptor on drop. In the future we might consider
making `ProgramFd` hold a `BorrowedFd` but this requires API design work
due to overlapping borrows.

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

`ProgramFd` is now returned by reference and implements `try_clone` to
allow callers to avoid file descriptor cloning when desired.

This is an API breaking change.

Updates #612.
2023-08-14 11:36:15 -04:00
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>
2023-08-11 14:04:20 -04:00
Tamir Duberstein
c7a19bcefb sys: add map_ids to bpf_prog_get_info_by_fd
Allows the caller to pass a slice which the kernel will populate with
map ids used by the program.
2023-08-10 18:19:24 -04:00
Tamir Duberstein
b1404e9a73 sys: push error construction up 2023-08-01 18:33:40 -04:00
Tamir Duberstein
de8519a380 sys: extract common SyscallError
We currently have 4 copies of this.
2023-08-01 18:33:37 -04:00
Tamir Duberstein
76c78e3bf8 sys: bpf_prog_get_fd_by_id returns OwnedFd 2023-07-25 19:26:18 -04:00
Tamir Duberstein
27120b328a aya: don't allocate static strings 2023-07-10 11:52:37 -04:00
ajwerner
65d10f9ffc aya: replace os::unix::prelude with os::fd 2023-06-30 14:19:19 -04:00
Dave Tucker
6af2053cf3 aya: Rename bpf_obj_get_info_by_id
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2022-09-07 16:23:42 +00:00
Dave Tucker
4826bf7f74 Merge pull request #366 from dave-tucker/pin-redux-2
aya: Fix Link Pinning
2022-08-31 17:07:49 +01:00
Dave Tucker
4c1d645aa6 aya: Fix Link Pinning
1. Removes OwnedLink
2. Allows Links to be converted into FdLink
3. Introduces a PinnedLink type to handle wrap FdLink when pinned and
   support un-pinning

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2022-08-31 14:34:41 +00:00
Michal Rostecki
944d6b8a16 Change from Rust edition 2018 to 2021
Rust 2021 adds more core prelude imports, including `TryFrom` and
`TryInto`.

Signed-off-by: Michal Rostecki <vadorovsky@gmail.com>
2022-08-27 21:14:47 +01:00
Dave Tucker
b2a6f00212 aya: Rename forget_link to take_link
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2022-06-06 12:57:05 +01:00
Dave Tucker
824baf9d64 aya: Export program modules
This allows access to XdpLink, XdpLinkId etc... which is currently
unavailable since these modules are private

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2022-05-24 13:12:45 +01:00
Dave Tucker
8069ad14d0 aya: Implement forget_link
Fixes #51

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2022-05-12 18:51:12 +01:00
Alessandro Decina
cb57d10d25 aya: rework links
Remove LinkRef and remove the Rc<RefCell<_>> that was used to store
type-erased link values in ProgramData. Among other things, this allows
`Bpf` to be `Send`, which makes it easier to use it with async runtimes.

Change the link API to:

    let link_id = prog.attach(...)?;
    ...
    prog.detach(link_id)?;

Link ids are strongly typed, so it's impossible to eg:

    let link_id = uprobe.attach(...)?;
    xdp.detach(link_id);

As it would result in a compile time error.

Links are still stored inside ProgramData, and unless detached
explicitly, they are automatically detached when the parent program gets
dropped.
2022-05-02 05:33:31 +00:00
Thia Wyrod
f56dd0a70b aya: eliminate name duplication in maps and programs.
Map and ProgramData objects had unnecessarily cloned strings for their
names, despite them being just as easily available to external users via
bpf.maps() and bpf.programs().
2021-12-04 20:54:18 -08:00
Dave Tucker
9426f36f79 Implement Pinning For Programs and Maps
This commit adds 2 new methods to aya::sys
- bpf_pin_object
- bpf_get_object

Which allow the pinning and retrieval of programs/maps to bpffs.

It adds a `Program.pin` API, such that a loaded program can be pinned.
For map pinning, the user must ensure the `pinning u32` in the
`bpf_map_def` is set to 1, maps will be pinned using a new builder API.

BpfLoader::new().map_pin_path("/sys/fs/bpf/myapp").load_file("myapp.o")

This will pin all maps whose definition requests pinning to path + name.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2021-09-28 23:31:29 +10:00
Alessandro Decina
66a12ffcf7 aya: programs: tweak LircMode2::query doc. 2021-07-31 01:05:08 +00:00
Sean Young
81e07e9661 Implement query for lirc programs (#32)
Signed-off-by: Sean Young <sean@mess.org>
2021-07-28 08:53:32 +10:00
Arnabjyoti Kalita
35f15f70e0 aya: add minimum kernel version for each map and program type (#18) 2021-06-26 21:17:39 +10:00
Sean Young
1196ba1dcc Fix doctest and run them during CI
Signed-off-by: Sean Young <sean@mess.org>
2021-06-17 12:14:53 +01:00
Sean Young
b49ba69d09 Add support for lirc programs
Signed-off-by: Sean Young <sean@mess.org>
2021-06-16 11:47:03 +01:00