Commit Graph

334 Commits

Author SHA1 Message Date
Tamir Duberstein e38eac6352 aya: appease new nightly clippy lints
```
  error: unnecessary qualification
     --> aya/src/maps/ring_buf.rs:434:22
      |
  434 |                 ptr: ptr::NonNull::new(ptr).ok_or(
      |                      ^^^^^^^^^^^^^^^^^
      |
  note: the lint level is defined here
     --> aya/src/lib.rs:72:5
      |
  72  |     unused_qualifications,
      |     ^^^^^^^^^^^^^^^^^^^^^
  help: remove the unnecessary path segments
      |
  434 -                 ptr: ptr::NonNull::new(ptr).ok_or(
  434 +                 ptr: NonNull::new(ptr).ok_or(
      |

  error: unnecessary qualification
     --> aya/src/maps/mod.rs:225:21
      |
  225 |     let mut limit = std::mem::MaybeUninit::<rlimit>::uninit();
      |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      |
  help: remove the unnecessary path segments
      |
  225 -     let mut limit = std::mem::MaybeUninit::<rlimit>::uninit();
  225 +     let mut limit = mem::MaybeUninit::<rlimit>::uninit();
      |

  error: unnecessary qualification
     --> aya/src/programs/mod.rs:614:9
      |
  614 |         crate::obj::Program {
      |         ^^^^^^^^^^^^^^^^^^^
      |
  help: remove the unnecessary path segments
      |
  614 -         crate::obj::Program {
  614 +         obj::Program {
      |

  error: unnecessary qualification
     --> aya/src/util.rs:373:14
      |
  373 |     unsafe { std::slice::from_raw_parts(bpf_name.as_ptr() as
      *const _, length) }
      |              ^^^^^^^^^^^^^^^^^^^^^^^^^^
      |
  help: remove the unnecessary path segments
      |
  373 -     unsafe { std::slice::from_raw_parts(bpf_name.as_ptr() as
      *const _, length) }
  373 +     unsafe { slice::from_raw_parts(bpf_name.as_ptr() as *const _,
      length) }
      |

  error: unnecessary qualification
      --> aya/src/maps/mod.rs:1130:47
       |
  1130 |                     .copy_from_slice(unsafe {
       std::mem::transmute(TEST_NAME) });
       |                                               ^^^^^^^^^^^^^^^^^^^
       |
  note: the lint level is defined here
      --> aya/src/lib.rs:72:5
       |
  72   |     unused_qualifications,
       |     ^^^^^^^^^^^^^^^^^^^^^
  help: remove the unnecessary path segments
       |
  1130 -                     .copy_from_slice(unsafe {
       std::mem::transmute(TEST_NAME) });
  1130 +                     .copy_from_slice(unsafe {
       mem::transmute(TEST_NAME) });
       |
```
2024-03-05 09:01:33 +00:00
Dave Tucker 770a95e077 chore: Appease clippy unused imports
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2024-02-19 14:37:54 +00:00
Tamir Duberstein 963dd13219 Appease rustc dead_code lint
Some of these are legit, others are false positives. I've filed
https://github.com/rust-lang/rust/issues/120770 for the latter.
2024-02-08 11:23:37 +01:00
Alessandro Decina 2be705bfa0 aya/programs: reformat to please rustfmt 2024-02-06 18:22:35 +11:00
Alessandro Decina 9b4f87646d Reorder imports a bit 2024-02-06 18:08:33 +11:00
Alessandro Decina d570450a0c aya/programs: export some missing modules
Previously we were only re-exporting the program types from these, so
links and other pub types were not exported.
2024-02-06 18:08:04 +11:00
Alessandro Decina 0f6a734392 aya: perf_event: add inherit argument to attach() 2024-01-30 07:20:16 +11:00
Alessandro Decina 2257cbeccb tc: add SchedClassifier::attach_to_link
Similar to Xdp::attach_to_link, can be used to replace/upgrade the
program attached to a link.
2024-01-02 16:30:48 +11:00
Alessandro Decina b13645b13d tc: add SchedClassifierLink::attach_type() getter
The link already exposes priority() and handle(). Expose attach_type()
too.
2024-01-02 16:30:48 +11:00
Adam Preuss 15faca8b2e aya: extracting program and map names with the same function 2023-11-19 10:12:51 +11:00
Tamir Duberstein d16e607fd4 rustfmt: group_imports = "StdExternalCrate"
High time we stop debating this; let the robots do the work.
2023-09-27 16:36:03 -04:00
Andrés Medina 0a6a2674fa aya: Fix program loading on kernels with a patch > 255 2023-09-27 13:13:51 -04:00
Alessandro Decina 7f9ce062f4 Merge pull request #527 from Tuetuopay/xdpmaps
Implement XDP map types
2023-09-25 08:22:48 +07:00
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>
2023-09-22 12:21:45 -04:00
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.
2023-09-22 13:10:02 +02:00
Andrew Stoycos 0b6ea313de Merge pull request #782 from astoycos/prog-info
aya: add program_info() api to `Program`
2023-09-18 12:56:28 -04:00
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.
2023-09-18 10:22:55 -04:00
astoycos 6ab7475fa6 aya: add program_info() api to program
Add a new api to the outer level `Program` structure which
allows users to get the program's kernel info before casting
it to an explicit program variant.

Signed-off-by: astoycos <astoycos@redhat.com>
2023-09-18 08:20:28 -04:00
Tamir Duberstein 8668436787 Merge pull request #772 from aya-rs/link-owned
programs: ProgAttachLink and LircLink hold owned FDs
2023-08-31 11:18:08 -04:00
Tamir Duberstein 204d02022a programs: ProgAttachLink and LircLink hold owned FDs
Updates #612.
2023-08-29 17:54:26 -04:00
Tamir Duberstein cee0265b52 netlink: use OwnedFd
Updates #612.
2023-08-29 17:38:55 -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 1ccfdbc175 aya: support non-UTF8 probing
Fixes #751.
2023-08-24 12:03:49 -04:00
Tamir Duberstein 0bba9b14b0 maps,programs: avoid path UTF-8 assumptions 2023-08-24 09:46:31 -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 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.
2023-08-15 16:28:36 -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 d88ca62aaa programs: Plug attach_btf_obj_fd leak
`ProgramData::attach_btf_obj_fd` is now owned.  This means that
`ProgramData` now closes the file descriptor on drop.

Updates #612.
2023-08-11 10:13:56 -04:00
Tamir Duberstein 5ac186299b sys: refactor btf_obj_get_info_by_fd to share code 2023-08-10 18:40:29 -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
Andrés Medina 8ebf0ac327 aya: Use OwnedFd in FdLink. 2023-08-02 12:29:26 -04:00
Andrew Werner 81fb4e5568 uprobe: refactor target resolution
This attempts to do fewer lossy conversions and to avoid some
allocations.
2023-08-02 10:51:25 -04:00
Andrew Werner dcc6b84a88 programs/uprobe: extract library path resolving
The function is extracted so that a test could be written. This test is
valid on linux-gnu targets, and it doesn't need any special privileges.
This is in anticipation of removing the code that uses this functionality
(seemingly incidentally) from integration tests.
2023-08-02 10:27:44 -04:00
Tamir Duberstein 368ddf10c4 Merge pull request #712 from aya-rs/loaded-links
integration-test: remove bpftool dependency
2023-08-02 08:46:15 -04:00
Tamir Duberstein 30faa5f68f Add links iterator
This is not yet exposed in documentation, but is complete enough for use
in tests, removing the dependency on bpftool.

Updates #645.
2023-08-01 20:36:08 -04:00
Tamir Duberstein 89ef97e848 aya: preallocate the vector
This code badly needs tests :(
2023-08-01 19:12:28 -04:00
Tamir Duberstein 7bb9b7f5a5 programs: plug file descriptor leak
This leaked a file descriptor if bpf_prog_get_info_by_fd failed.
2023-08-01 18:33:41 -04:00
Tamir Duberstein b1404e9a73 sys: push error construction up 2023-08-01 18:33:40 -04:00
Tamir Duberstein a0af7e0b2f programs: make loaded_programs opaque 2023-08-01 18:33:38 -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 6f3cce75cf test: s/assert!(.*) ==/assert_eq!\1,/
One case manually adjusted to `assert_matches!`.
2023-08-01 11:22:03 -04:00
Tamir Duberstein 0ec9afdb07 Reduce state cardinality from 4 to 2
Encode into the type system the fact that PerfLink::probe_kind and
PerfLink::event_alias are present or absent together.
2023-07-31 19:26:34 -04:00
Andrés Medina dbfba18dac aya: Return OwnedFd for perf_event_open.
This fixes a file descriptor leak when creating a link of
BPF_PERF_EVENT attach type.
2023-07-31 15:42:55 -07:00
Tamir Duberstein 8961be9526 Do not escape newlines on Err(LoadError).unwrap()
Wrap verifier logs in a newtype whose `Debug` impl emits unescaped
newlines. This improves ergonomics in tests where we `Result::unwrap()`
those load errors; when these fail today they emit the errors with
newlines escaped, making them incredibly difficult to read.
2023-07-28 17:15:36 -04:00
Andrés Medina ea96c29ccb aya: Use Arc<OwnedFd> when loading BTF fd
This fixes an existing file descriptor leak when there is BTF data in
the loaded object.

To avoid lifetime issues while having minimal impact to UX the
`OwnedFd` returned from the BPF_BTF_LOAD syscall will be wrapped in an
`Arc` and shared accross the programs and maps of the loaded BPF
file.
2023-07-28 12:55:54 -07:00
Andrés Medina c63d9904f7 Replace std::os::unix::io for std::os::fd
This is just taking https://github.com/aya-rs/aya/pull/633 to its
logical conclusion. Because `std::os::fd` was only introduced as a
module in Rust v1.66.0 I have also updated the `Cargo.toml` of the
`aya` package to reflect the true MSRV. Note that this commit is *not*
the cause for this MSRV bump, that was done by a previous commit, this
commit is just making it explicit in the `Cargo.toml`
2023-07-27 22:08:59 -07:00
Tamir Duberstein 76c78e3bf8 sys: bpf_prog_get_fd_by_id returns OwnedFd 2023-07-25 19:26:18 -04:00
Dave Tucker 764eb309b0 Clippy fixes for latest nightly
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2023-07-18 14:02:26 +01:00