Commit Graph

534 Commits (c0a08276a69b943e96bd67af41fc1b99fc48100b)

Author SHA1 Message Date
Tamir Duberstein 5ac186299b
sys: refactor btf_obj_get_info_by_fd to share code 1 year ago
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.
1 year ago
Tamir Duberstein 5138c731a9
util: avoid vector allocation when parsing ksyms 1 year ago
Addison Crump ed777273b1
nuclear option: no symbol resolution in the crate 1 year ago
Dave Tucker e38e2566e3 aya, aya-obj: Implement ENUM64 fixups
This commit adds:

- A probe to see if the ENUM64 feature is supported
- Fixups for the use of signed enums, or enum64 types
  on systems where enum64 is not supported

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
1 year ago
Andrés Medina 8ebf0ac327
aya: Use OwnedFd in FdLink. 1 year ago
Dave Tucker e9153792f1
Merge pull request #720 from dave-tucker/programsection-noname
aya-obj: Remove name from ProgramSection
1 year ago
Addison Crump d8709de9f2
Extract trait SymbolResolver 1 year ago
Dave Tucker cca9b8f1a7 aya-obj: Remove name from ProgramSection
The name here is never used as we get the program name from the symbol
table instead.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
1 year ago
Andrew Werner 81fb4e5568 uprobe: refactor target resolution
This attempts to do fewer lossy conversions and to avoid some
allocations.
1 year ago
ajwerner de8604d011
Merge pull request #717 from ajwerner/no-libc-in-integration-tests
uprobe,integration-test: do not exercise dylib resolution in integration tests
1 year ago
Dave Tucker 77e9603976
Merge pull request #711 from dave-tucker/sleepable
Tidy up aya-bpf-macros (again)
1 year ago
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.
1 year ago
Tamir Duberstein 368ddf10c4
Merge pull request #712 from aya-rs/loaded-links
integration-test: remove bpftool dependency
1 year ago
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.
1 year ago
Dave Tucker 71737f5576 aya: Set BPF_F_SLEEPABLE for sleepable programs
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
1 year ago
Tamir Duberstein 89ef97e848
aya: preallocate the vector
This code badly needs tests :(
1 year ago
Tamir Duberstein 7bb9b7f5a5
programs: plug file descriptor leak
This leaked a file descriptor if bpf_prog_get_info_by_fd failed.
1 year ago
Tamir Duberstein b1404e9a73
sys: push error construction up 1 year ago
Tamir Duberstein a0af7e0b2f
programs: make `loaded_programs` opaque 1 year ago
Tamir Duberstein de8519a380
sys: extract common SyscallError
We currently have 4 copies of this.
1 year ago
Tamir Duberstein 4cb3ea6e8f
sys: `sys_bpf` takes mut ref
Some syscalls mutate the argument, we can't be passing an immutable
reference here.
1 year ago
Tamir Duberstein 7ee6f52a74
sys: avoid repeating BPF_BTF_LOAD dance 1 year ago
Tamir Duberstein 6f3cce75cf
test: s/assert!(.*) ==/assert_eq!\1,/
One case manually adjusted to `assert_matches!`.
1 year ago
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.
1 year ago
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.
1 year ago
Tamir Duberstein 868a9b00b3
Merge pull request #704 from aya-rs/better-panic
all: better panic messages
1 year ago
Tamir Duberstein 17f25a6793
all: better panic messages
Always include operands in failing assertions. Use assert_matches over
manual match + panic.
1 year ago
Tuetuopay c74813f8c5 test: add the possibility to run a test inside a network namespace
For tests that do networking operations, this allows to have a
clean-state network namespace and interfaces for each test. Mainly, this
avoids "device or resource busy" errors when reusing the loopback
interface across tests.
1 year ago
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.
1 year ago
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.
1 year ago
Andrés Medina 683a1cf2e4 aya: Make SysResult generic on Ok variant 1 year ago
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`
1 year ago
Tamir Duberstein 76c78e3bf8
sys: bpf_prog_get_fd_by_id returns OwnedFd 1 year ago
Mike Rostecki 96fa08bd82 cargo: Define dependencies on the workspace level
This way we will avoid version mismatches and make differences in
features across our crates clearer.
1 year ago
Dave Tucker 764eb309b0 Clippy fixes for latest nightly
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
1 year ago
Tamir Duberstein 35ed85a87f
Handle WSL kernel version strings
Fixes #654.
1 year ago
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);
});
```
1 year ago
Tamir Duberstein 61608e6458
Merge pull request #650 from aya-rs/test-cleanup
Remove async feature; misc test cleanup
1 year ago
Tamir Duberstein 5407d4a9a1
Don't use env::tempdir
This can cause test pollution. Create a new temp directory on each run.
1 year ago
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.
1 year ago
Mary 74b546827c aya: Ignore embedded BTF error if not truely required
This allows fallback to BTF manual relocation when BTF loading fail when not truely required.
1 year ago
Alessandro Decina 242d8c33c4 Fix build 1 year ago
Alessandro Decina eb60d65613
Merge pull request #520 from astoycos/unsupported-map
Add Unsupported Map type
1 year ago
Andrew Stoycos 80b371f6d1
add FdLink documentation and example
Signed-off-by: Andrew Stoycos <astoycos@redhat.com>
1 year ago
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>
1 year ago
Tamir Duberstein 8c61fc9ea6
integration-test: compile C probes using build.rs
- Add libbpf as a submodule. This prevents having to plumb its location
  around (which can't be passed to Cargo build scripts) and also
  controls the version against which codegen has run.
- Move bpf written in C to the integration-test crate and define
  constants for each probe.
- Remove magic; each C source file must be directly enumerated in the
  build script and in lib.rs.
1 year ago
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.
1 year ago
Tamir Duberstein a1e0130387
Type-erase KernelVersion::current error 1 year ago
Tamir Duberstein 6bceb1c3da
Invert comparison
Incorrectly inverted in b611038d5b.
1 year ago