Commit Graph

1519 Commits (e68fa14d71610c1163a1112a4a62b55456d3f7e6)
 

Author SHA1 Message Date
Tamir Duberstein 72afd877b5
integration-test: clang-format C files 1 year ago
Tamir Duberstein bcbb7e08fa
Cargo.toml: Remove default-features settings
These are all set to false at the root.
1 year ago
Tamir Duberstein 761e4ddbe3
Merge pull request #726 from aya-rs/btf-iter-alloc
btf: avoid multiple vector allocations
1 year ago
Tamir Duberstein 826e0e5050
btf: use Self instead of restating the type 1 year ago
Tamir Duberstein 2a054d76ae
btf: avoid multiple vector allocations
Rather than creating an empty vector and iteratively appending - which
might induce intermediate allocations - create an ExactSizeIterator and
collect it into a vector, which should produce exactly one allocation.
1 year ago
Dave Tucker 1979da92a7
Merge pull request #721 from dave-tucker/fix-funcinfo
aya: Fix (func|line)_info multiple progs in section
1 year ago
Dave Tucker 79ea64ca7f aya: Fix (func|line)_info multiple progs in section
This commit fixes the (func|line)_info when we have multiple programs in
the same section. The integration test reloc.bpf.c serves as our test
case here. This required filtering down the (func|line)_info to only
that in scope of the current symbol + then adjusting the offets to
appease the kernel.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
1 year ago
Tamir Duberstein bd5442a1de
Merge pull request #709 from nrxus/fd-link-owned-fd
aya: Use OwnedFd in FdLink. (#709)
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
ajwerner ef6308b640
Merge pull request #718 from ajwerner/better-code
uprobe: refactor target resolution
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 79c9489a4f integration-test: attach uprobes to self
For unclear reasons, two of the integration tests related to uprobes
were resolving a symbol in libc. The integration-test binary can be
built statically, in which case it would not load or reference libc.
Statically linking the integration tests and running them in a VM
without a userland is a convenient mechanism to exercise the tests
against different kernel versions.

The fact that the statically linked integration-test binary does not
load libc is not the only reason these tests failed in such an
environment. In fact, the logic to look in the process's memory
maps was not running (because no pid was being passed).

Separate logic to determine which object file to use when attempting
to resolve a symbol for attaching a uprobe changes its behavior based
on whether that target is an absolute path. If the target is not an
absolute path, the code searches through the LdSoCache. This cache does
not always exist in linux systems; when an attach call is made with a
relative path target and there is no /etc/ld.so.cache file, the attach
call will fail. This commit does not change that behavior, it merely
sidesteps it.
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
Tamir Duberstein b1bf61ca61
Merge pull request #716 from aya-rs/prealloc-vec
aya: preallocate the vector
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
Dave Tucker 677e7bda4a aya-obj: Propagate sleepable into ProgramSection
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
1 year ago
Dave Tucker 7eebdcbdeb aya-bpf-macros: Cleanup and remove required_args
This commit cleans up the recently refactored aya-bpf-macros
to be a little easier to maintain:

Cosmetic changes:

1. The flow of the parse function is the same in each file
2. Useless if !attrs.is_empty() guards were removed
3. The compile error when cgroup_sock programs have an invalid
   attach_type was in the wrong location

Functional changes:

1. Remove pop_required_arg. All args are optional and making them
   required was a mistake on my part. We may revisit this later.
2. Rename pop_arg to pop_string_arg
3. Implement pop_bool_arg to allow for single idents to be mixed with
   our key/value pair syntax in macro attributes. This is used for
   `sleepable` and `frags` in XDP programs.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
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 f095c591af
Merge pull request #714 from aya-rs/dry-btf-load
sys: avoid repeating BPF_BTF_LOAD dance
1 year ago
Tamir Duberstein 7ee6f52a74
sys: avoid repeating BPF_BTF_LOAD dance 1 year ago
Tamir Duberstein 3692e53ff0
Merge pull request #706 from aya-rs/reloc-tests
integration-test: Remove runtime toolchain deps
1 year ago
Tamir Duberstein dca5e6c167
integration-test: Remove runtime toolchain deps
Move the use of clang and llvm-objcopy from run-time to build-time. This
allows the integration tests to run on VMs with simpler userlands.

Create a new CI job to build the integration tests separately from
running them. Ship them from that job to the runner job using github
actions artifacts.
1 year ago
Tamir Duberstein 5a398504cf
test: appease shellcheck 1 year ago
Tamir Duberstein 571c38b1c6
test: add some #[track_caller] annotations 1 year ago
Tamir Duberstein 6f3cce75cf
test: s/assert!(.*) ==/assert_eq!\1,/
One case manually adjusted to `assert_matches!`.
1 year ago
ajwerner afacfddd8b
Merge pull request #710 from ajwerner/move-rustversion-to-workspace
bpf: move rustversion build dep to workspace
1 year ago
Andrew Werner 9f0e83726f bpf: move rustversion build dep to workspace
All the other dependencies are at the workspace level other than this
one.
1 year ago
Tamir Duberstein 4c3219f754
Merge pull request #707 from aya-rs/one-option-not-two
Reduce state cardinality from 4 to 2
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
Tamir Duberstein 445cb8b463
Merge pull request #701 from nrxus/perf-event-owned-fd
aya: Return `OwnedFd` for `perf_event_open`.
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
Dave Tucker e833a71b02
Merge pull request #413 from dave-tucker/fix-names-once-and-for-all
aya: fix names once and for all
1 year ago
Tamir Duberstein 868a9b00b3
Merge pull request #704 from aya-rs/better-panic
all: better panic messages
1 year ago
Dave Tucker 6d92119fbc integration-test: Add test for 2 progs in same section
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
1 year ago
Dave Tucker c72aab5f7b aya-bpf-macros: Refactor for ease of testing
The aya-bpf-macros needed refactoring for:

1. Ease of testing
2. To be consistent with when we use K/V args vs. idents
3. To deprecate the use of `name` to change the exported name of a
   function - we now use the symbol table.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
1 year ago
Dave Tucker bf7fdff1ce aya: Find programs using the symbol table
This makes a few changes to the way that Aya reads the ELF object
files.

1. To find programs in a section, we use the symbols table. This allows
   for cases where multiple programs could appear in the same section.
2. When parsing our ELF file we build symbols_by_section_index as an
   optimization as we use it for legacy maps, BTF maps and now programs.

As a result of theses changes the "NAME" used in `bpf.prog_mut("NAME")`
is now ALWAYS the same as the function name in the eBPF code, making the
user experience more consistent.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
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
Tamir Duberstein f705eabe66
Merge pull request #696 from Tuetuopay/tests-netns
test: add the possibility to run a test inside a network namespace
1 year ago