Commit Graph

334 Commits

Author SHA1 Message Date
Tamir Duberstein 961f45da37 Replace matches with assert_matches
The matches crate has been archived now that `matches!` is in std.
However `assert_matches!` is still unstable in std, and the
assert_matches crate provides a more expressive form:

```
assert_matches!(foo, Ok(bar) => {
  assert_eq!(bar, baz);
});
```
2023-07-14 13:02:02 -04:00
Tamir Duberstein 5407d4a9a1 Don't use env::tempdir
This can cause test pollution. Create a new temp directory on each run.
2023-07-14 11:05:09 -04:00
Tamir Duberstein fa91fb4f59 Remove "async" feature
This feature is equivalent to async_tokio || async_std; removing it
avoids warnings emitted during `cargo hack check --feature-powerset`
where async is selected without either of the other features.

Use cargo hack to ensure clippy runs on the powerset of features.
2023-07-14 11:05:07 -04:00
Andrew Stoycos 80b371f6d1 add FdLink documentation and example
Signed-off-by: Andrew Stoycos <astoycos@redhat.com>
2023-07-12 22:09:42 -04:00
Andrew Stoycos 58895db9b4 Implement FdLink conversions
Implement TryFrom functions to convert Fdlink to PerfLink/TracePointLink/
KprobeLink, and UprobeLink and vice-versa.

This allows us to pin taken links for perf programs, ultimately
ensuring the link isn't dropped when the loading process exits.

Signed-off-by: Andrew Stoycos <astoycos@redhat.com>
2023-07-12 21:53:27 -04:00
Tamir Duberstein e621a09181 Clippy over tests and integration-ebpf
Replace all `assert!(matches!(..))` with `assert_matches!(..)`.

Remove the now-unused build-integration-test xtask command whose logic
doesn't match that of the build-and-run command.
2023-07-12 11:54:27 -04:00
Tamir Duberstein 6bceb1c3da Invert comparison
Incorrectly inverted in b611038d5b.
2023-07-11 16:52:06 -04:00
Tamir Duberstein cc2bc0acc1 Remove procfs dependency 2023-07-10 21:35:20 -04:00
Tamir Duberstein b5ebcb7cc5 Remove verifier log special case 2023-07-10 21:24:16 -04:00
Tamir Duberstein b45a5bb71b Get verifier logs when loading programs 2023-07-10 15:43:00 -04:00
Tamir Duberstein 6b94b2080d Hide details of VerifierLog
This type is really only used by one function.
2023-07-10 15:25:29 -04:00
Tamir Duberstein b611038d5b Use procfs crate for kernel version parsing
This allows the logic to be shared between aya and the integration tests
without exposing additional public API surface.
2023-07-10 15:25:26 -04:00
Tamir Duberstein 27120b328a aya: don't allocate static strings 2023-07-10 11:52:37 -04:00
Tamir Duberstein ff86f1385c Remove dependency on bpftool in integration tests 2023-07-06 17:09:34 -04:00
Dave Tucker 47f764c191 aya: Make Features part of the public API
This commit adds a new probe for bpf_attach_cookie, which would be used
to implement USDT probes. Since USDT probes aren't currently supported,
we this triggers a dead_code warning in clippy.

There are cases where exposing FEATURES - our lazy static - is actually
helpful to users of the library. For example, they may wish to choose to
load a different version of their bytecode based on current features.
Or, in the case of an orchestrator like bpfd, we might want to allow
users to describe which features their program needs and return nice
error message is one or more nodes in their cluster doesn't support the
necessary feature set.

To do this without breaking the API, we make all the internal members of
the `Features` and `BtfFeatures` structs private, and add accessors for
them. We then add a `features()` API to avoid leaking the
lazy_static.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2023-07-02 16:05:55 +01:00
ajwerner 65d10f9ffc aya: replace os::unix::prelude with os::fd 2023-06-30 14:19:19 -04:00
Mary 49c6f5d122 aya: Fix uprobe support on 4.16 and lower
Fix uprobe support on Ubuntu 18.04.
2023-06-05 15:36:44 +02:00
Mary 8e9f395eab aya: Add support for old ld.so.cache format
This fix uprobe support on Debian 10. (and possibly others)
This implement support to parse the original libc5 format.
2023-06-02 17:07:31 +02:00
Alexis (Poliorcetics) Bourget 243986c1da fix: Relax unnecessarily strict atomic ordering on probe event_alias 2023-06-01 16:39:34 +02:00
Mary e9be3d9023 aya: Make probe event_alias unique
This fixes issues when trying to attach the same kernel function multiple times on 4.17 and lower (possibly upper too?)
2023-06-01 14:57:55 +02:00
Mary 9e1109b3ce aya: Move program's functions to the same map 2023-05-03 17:12:44 +02:00
Tamir Duberstein ae8a95b0ee build(deps): update bitflags requirement from 1.2.1 to 2.2.1
Updates the requirements on [bitflags](https://github.com/bitflags/bitflags) to permit the latest version.
- [Release notes](https://github.com/bitflags/bitflags/releases)
- [Changelog](https://github.com/bitflags/bitflags/blob/main/CHANGELOG.md)
- [Commits](https://github.com/bitflags/bitflags/compare/1.2.1...2.2.1)
2023-04-27 17:53:02 -04:00
drewvis 8f64cf8cd5 Added code check comment 2023-03-25 10:20:58 -04:00
drewvis 3a2c0cd1dd Add check for empty tracefs mounts 2023-03-25 10:20:58 -04:00
Mikhail Trishchenkov ce60854934 Don't leak libc types 2023-03-20 21:47:24 +07:00
Mikhail Trishchenkov 896e3ab313 Fix formatting 2023-03-20 16:11:13 +07:00
Mikhail Trishchenkov 676b5cdc0d Rename method and fix comment 2023-03-20 14:00:55 +07:00
Mikhail Trishchenkov 2e3c1779be aya: Allow to attach XDP probe by interface index 2023-03-20 12:20:46 +07:00
Dave Tucker de4905a24b aya: Add loaded_programs() API to list all loaded programs
This uses a Programs iterator to yield all loaded bpf programs using
bpf_prog_get_next_id.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2023-02-23 08:57:23 +00:00
Dave Tucker d0b3d3b2fa aya: Enable bpf_link for perf_attach programs
This adds support for bpf_link to PerfEvent, Tracepoint, Kprobe and
Uprobe programs.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2023-02-12 11:24:30 +00:00
Dave Tucker a18693b42d aya: Add support for multibuffer programs
This adds support for loading XDP programs that are multi-buffer
capable, which is signalled using the xdp.frags section name. When this
is set, we should set the BPF_F_XDP_HAS_FRAGS flag when loading the
program into the kernel.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2023-02-09 14:19:50 +00:00
Dave Tucker 7a720ab0c1 aya: Add from_pin for Programs
This commit adds from_pin() which allows the creation of a Program
from a path on bpffs. This is useful to be able to call `attach` or
other APIs for programs that are already loaded to the kernel.

This differs from #444 since it implements this on the concrete program
type, not the Program enum, allowing the user to pass in any additional
context that isn't available from bpf_prog_info.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2023-02-09 00:07:22 +00:00
Alessandro Decina 22d79312f7 Merge pull request #445 from anfredette/tc-link-recon
Support reconstruction of `SchedClassifierLink`
2023-01-31 08:51:00 +11:00
Andre Fredette 7c24296b5d Address review comments from @alessandrod
Signed-off-by: Andre Fredette <afredette@redhat.com>
2023-01-30 10:03:38 -05:00
banditopazzo 48fdf5a250 chore: tracefs review fixes 2023-01-26 14:07:45 +01:00
banditopazzo c6c4ac7eea feat: get_tracefs function 2023-01-26 14:07:45 +01:00
Andre Fredette d43879d991 Updates after rebase due to changes in define_link_wrapper
Signed-off-by: Andre Fredette <afredette@redhat.com>
2023-01-25 15:12:21 -05:00
Andre Fredette 6766532341 Remove SchedClassifierLink description
It was redundant with the one provided in define_link_wrapper

Signed-off-by: Andre Fredette <afredette@redhat.com>
2023-01-25 14:12:11 -05:00
Andre Fredette 2972d462a5 Address review comments
- Rename `new_tc_link` to `attached`
- Simplified example for `attached`

The following was not requested in reviews:
- Moved example from `SchedClassifierLink` tor
  `SchedClassifierLink::attached' since we're only showing an
  example of that one method

Signed-off-by: Andre Fredette <afredette@redhat.com>
2023-01-25 14:12:11 -05:00
Andre Fredette 65f5b76593 Address review comments
Signed-off-by: Andre Fredette <afredette@redhat.com>
2023-01-25 14:12:11 -05:00
Andre Fredette 849796c420 rename SchedClassifierLink:new() to new_tc_link()
Avoids name confilct with pr #462

Signed-off-by: Andre Fredette <afredette@redhat.com>
2023-01-25 14:12:11 -05:00
Andre Fredette 67efc33414 Additional edits to SchedClassifierLink documentation.
Signed-off-by: Andre Fredette <afredette@redhat.com>
2023-01-25 14:12:11 -05:00
Andre Fredette 6563e6cc06 Combine updates to SchedClassifierLink example made by Dave Tucker
Co-authored-by: Dave Tucker <dave@dtucker.co.uk>
Signed-off-by: Andre Fredette <afredette@redhat.com>
2023-01-25 14:12:11 -05:00
Andre Fredette c3a8400e4d Add example for SchedClassifierLink::new()
Also modified the impl a bit to work as described in the example.

Signed-off-by: Andre Fredette <afredette@redhat.com>
2023-01-25 14:12:11 -05:00
Andre Fredette f46fd17cc3 Support reconstruction of SchedClassifierLink
This is the proposed solution for Step 2 of issue #414

“For cases where you have done program.take_link() to manage
ownership of TcLink we need an API similar to PinnedLink::from_pin
that can reconstruct a TcLink”

As long as a user application continues to run after executing
`take_link()`, the `SchedClassifierLink` returned can be used to
detach the program.  However, if we want to handle cases where the
application exits or crashes, we need a way to save and reconstruct
the link, and to do that, we also need to know the information
required for the reconstruction -- namely, the `interface`,
`attach_type`, `priority`, and `handle`.  The user knows the first
two because they are required to execute `attach()` in the first
place; however, the user will not know the others if they let the
system choose them.

This pr solves the problems by adding an `impl` for
`SchedClassifierLink` with an accessor for `tc_options` and a `new()`
function.

Signed-off-by: Andre Fredette <afredette@redhat.com>
2023-01-25 14:12:11 -05:00
Shenghui Ye e52497cb9c aya-obj: add basic documentation to public members
Types relevant to maps are moved into aya_obj::maps.
Some members are marked `pub(crate)` again.

Refs: #473
2023-01-02 11:37:59 +08:00
Shenghui Ye ac49827e20 aya-obj: migrate aya::obj into a separate crate
To split the crate into two, several changes were made:
1. Most `pub(crate)` are now `pub` to allow access from Aya;
2. Parts of BpfError are merged into, for example, RelocationError;
3. BTF part of Features is moved into the new crate;
4. `#![deny(missing_docs)]` is removed temporarily;
5. Some other code gets moved into the new crate, mainly:
   - aya::{bpf_map_def, BtfMapDef, PinningType},
   - aya::programs::{CgroupSock*AttachType},

The new crate is currenly allowing missing_docs. Member visibility
will be adjusted later to minimize exposure of implementation details.

Refs: #473
2023-01-02 11:34:30 +08:00
ajwerner 1a22792ee7 Resolve symbol address for PIE executables
See https://github.com/foniod/redbpf/pull/308 for a similar change.
2022-12-29 08:09:29 +11:00
Alessandro Decina b3ae7786d3 aya: fix detaching links on drop
https://github.com/aya-rs/aya/pull/366 broke detaching links on drop for
everything but FdLink. This restores detach on drop for all links.
2022-12-26 22:29:17 +11:00
Milan 925504f230 Fix doctest issue 2022-12-15 12:51:21 -05:00