Commit Graph

414 Commits (d43879d99177c33c5d33827d8a3c7572841dd9df)

Author SHA1 Message Date
dependabot[bot] 661a21570f
build(deps): update object requirement from 0.28 to 0.29
Updates the requirements on [object](https://github.com/gimli-rs/object) to permit the latest version.
- [Release notes](https://github.com/gimli-rs/object/releases)
- [Changelog](https://github.com/gimli-rs/object/blob/master/CHANGELOG.md)
- [Commits](https://github.com/gimli-rs/object/compare/0.28.0...0.29.0)

---
updated-dependencies:
- dependency-name: object
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2 years ago
Alessandro Decina a301a56316
Merge pull request #328 from drewkett/map-update-no-key
Have bpf_map_update_elem take Option<&K> for key
2 years ago
Dave Tucker 004f3dd664 aya: Improve Extension Docs
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2 years ago
Dave Tucker 9e85b92323 aya: Add Extension::attach_to_program()
This allows for Extension programs already loaded to the kernel to be
attached to another program that is BTF-compatible with the one provided
at `load()` time

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2 years ago
Dave Tucker b4413322e3 aya: Replace ProgramFd trait with struct
This removes the ProgramFd trait with a struct that wraps a RawFd.
Program::fd() has been implemented as well as fd() for each Program
Type. This allows for a better API than requiring the use of the
ProgramFd trait.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2 years ago
Dave Tucker fd52bfeadc aya: Implement attach_to_link for XDP
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2 years ago
Dave Tucker ccb189784f aya: Add support for bpf_link_update
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2 years ago
Andrew Burkett 36edf09254 Have bpf_map_update_elem take Option<&K> for key
bpf_map_update_elem is used in lieu of bpf_map_push_elem to maintain support for kernel version < 4.20. The kernel expects a null pointer for the key for this use case. With this change, if you pass None as key to `bpf_map_update_elem`, it will pass null as key.
2 years ago
Dave Tucker 623579a47f aya: Add Map::fd() function to return a MapFd
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2 years ago
Dave Tucker 2b98259be7 readme: Add crabby, sync with aya/README.md
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2 years ago
Dave Tucker 713cd4e858 docs: Add crabby logo
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2 years ago
Dave Tucker 7b21a2d17e aya: Implement BPF_PROG_TYPE_CGROUP_SOCK
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2 years ago
Dave Tucker 0cd1e51476 aya: Unload programs on drop
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2 years ago
Alessandro Decina d85b36f6d8 (cargo-release) version 0.11.0 2 years ago
Dave Tucker b2a6f00212 aya: Rename forget_link to take_link
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2 years ago
dave-tucker bbb34b3285 [codegen] Update libbpf to 4eb6485c08867edaa5a0a81c64ddb23580420340Update libbpf to 4eb6485c08867edaa5a0a81c64ddb23580420340
Files changed:\nM	aya/src/generated/linux_bindings_aarch64.rs
M	aya/src/generated/linux_bindings_armv7.rs
M	aya/src/generated/linux_bindings_riscv64.rs
M	aya/src/generated/linux_bindings_x86_64.rs
2 years ago
Davide Bertola e2685c98d8
Program unload API (#264)
aya: add `program.unload()` API
2 years ago
Alessandro Decina 16337001e4
Merge pull request #286 from nak3/add-BPF_MAP_TYPE_BLOOM_FILTER
Add support for BPF_MAP_TYPE_BLOOM_FILTER
2 years ago
Kenjiro Nakayama c192817a59 Fix typo, take & to query the value 2 years ago
Dave Tucker 2226b89ceb aya: Add support for BPF_PROG_TYPE_SK_LOOKUP
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2 years ago
Kenjiro Nakayama c4262f793d Add support for BPF_MAP_TYPE_BLOOM_FILTER
This patch adds support for `BPF_MAP_TYPE_BLOOM_FILTER`.
2 years ago
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>
2 years ago
dave-tucker 4767664d5d [codegen] Update libbpf to 47595c2f08aece55baaf21ed0b72f5c5abf2cb5eUpdate libbpf to 47595c2f08aece55baaf21ed0b72f5c5abf2cb5e
Files changed:\nM	aya/src/generated/linux_bindings_riscv64.rs
M	bpf/aya-bpf-bindings/src/riscv64/bindings.rs
M	bpf/aya-bpf-bindings/src/riscv64/getters.rs
M	bpf/aya-bpf-bindings/src/riscv64/helpers.rs
2 years ago
Dave Tucker edaa70b5ba riscv scaffolding for codegen
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2 years ago
Dave Tucker 4a32e7d985 clippy: fix new lints on nightly
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2 years ago
Dave Tucker ba312c48d5 xtask: Add all crates to sidebar
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2 years ago
Kenjiro Nakayama e68d734c68
Add support for BPF_PROG_TYPE_CGROUP_SOCKOPT (#268) 2 years ago
Alessandro Decina 63b6286bd9
Merge pull request #263 from nak3/cgroup-skb-attach-type
Set attach type during load for BPF_PROG_TYPE_CGROUP_SKB
2 years ago
alessandrod 7f7c78ad6b [codegen] Update libbpf to 86eb09863c1c0177e99c2c703092042d3cdba910Update libbpf to 86eb09863c1c0177e99c2c703092042d3cdba910
Files changed:\nM	aya/src/generated/linux_bindings_aarch64.rs
M	aya/src/generated/linux_bindings_armv7.rs
M	aya/src/generated/linux_bindings_x86_64.rs
M	bpf/aya-bpf-bindings/src/aarch64/bindings.rs
M	bpf/aya-bpf-bindings/src/aarch64/getters.rs
M	bpf/aya-bpf-bindings/src/aarch64/helpers.rs
M	bpf/aya-bpf-bindings/src/armv7/bindings.rs
M	bpf/aya-bpf-bindings/src/armv7/getters.rs
M	bpf/aya-bpf-bindings/src/armv7/helpers.rs
M	bpf/aya-bpf-bindings/src/x86_64/bindings.rs
M	bpf/aya-bpf-bindings/src/x86_64/getters.rs
M	bpf/aya-bpf-bindings/src/x86_64/helpers.rs
2 years ago
Kenjiro Nakayama 5d228695a4 Use map() 2 years ago
Dave Tucker af54b6c818 aya: Add BPF_PROG_TYPE_CGROUP_SOCK_ADDR
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2 years ago
Kenjiro Nakayama 29c10fafb7 Set attach type during load for BPF_PROG_TYPE_CGROUP_SKB
As per title, this patch sets `expected_attach_type` during load.
2 years ago
Kenjiro Nakayama f721021a0a
Add support for BPF_PROG_TYPE_CGROUP_SYSCTL (#256)
* Add support for BPF_PROG_TYPE_CGROUP_SYSCTL

This patch adds support for `BPF_PROG_TYPE_CGROUP_SYSCTL`.

* Parse unnamed macro

* Fix docs
2 years ago
Dave Tucker 8069ad14d0 aya: Implement forget_link
Fixes #51

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2 years ago
Dave Tucker cdaa3af5ae clippy: Fix lint against latest nightly
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2 years ago
Dave Tucker d1f2215193 aya: Relocate maps using symbol_index
Since we support multiple maps in the same section, the section_index is
no longer a unique way to identify maps. This commit uses the symbol
index as the identifier, but falls back to section_index for rodata
and bss maps since we don't retrieve the symbol_index during parsing.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2 years ago
Alessandro Decina 4e57d1fe32 aya: revert version to 0.10.7
The world isn't ready to have pre-releases in git
2 years ago
dave-tucker d6ca3e1ae7 [codegen] Update libbpf to 3a4e26307d0f9b227e3ebd28b443a1a715e4e17dUpdate libbpf to 3a4e26307d0f9b227e3ebd28b443a1a715e4e17d
Files changed:\nM	aya/src/generated/linux_bindings_aarch64.rs
M	aya/src/generated/linux_bindings_armv7.rs
M	aya/src/generated/linux_bindings_x86_64.rs
M	bpf/aya-bpf-bindings/src/aarch64/bindings.rs
M	bpf/aya-bpf-bindings/src/aarch64/getters.rs
M	bpf/aya-bpf-bindings/src/aarch64/helpers.rs
M	bpf/aya-bpf-bindings/src/armv7/bindings.rs
M	bpf/aya-bpf-bindings/src/armv7/getters.rs
M	bpf/aya-bpf-bindings/src/armv7/helpers.rs
M	bpf/aya-bpf-bindings/src/x86_64/bindings.rs
M	bpf/aya-bpf-bindings/src/x86_64/getters.rs
M	bpf/aya-bpf-bindings/src/x86_64/helpers.rs
2 years ago
Dave Tucker b039ac524e
Merge pull request #249 from alessandrod/new-links
aya: rework links
2 years ago
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.
2 years ago
Dave Tucker f357be7db4 aya: Support multiple maps in map sections
This commit uses the symbol table to discover all maps inside an ELF
section. Instead of doing what libbpf does - divide the section data
in to equal sized chunks - we read in to section data using the
symbol address and offset, thus allowing us to support definitions
of varying lengths.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2 years ago
Alessandro Decina ad1636d2e7 aya: perf_buffer: call BytesMut::reserve() internally
This changes PerfBuffer::read_events() to call BytesMut::reserve()
internally, and deprecates PerfBufferError::MoreSpaceNeeded.

This makes for a more ergonomic API, and allows for a more idiomatic
usage of BytesMut. For example consider:

    let mut buffers = vec![BytesMut::with_capacity(N), ...];
    loop {
        let events = oob_cpu_buf.read_events(&mut buffers).unwrap();
        for buf in &mut buffers[..events.read] {
            let sub: Bytes = buf.split_off(n).into();
            process_sub_buf(sub);
        }
        ...
    }

This is a common way to process perf bufs, where a sub buffer is split
off from the original buffer and then processed. In the next iteration
of the loop when it's time to read again, two things can happen:

- if processing of the sub buffer is complete and `sub` has been
dropped, read_events() will call buf.reserve(sample_size) and hit a fast
path in BytesMut that will just restore the original capacity of the
buffer (assuming sample_size <= N).

- if processing of the sub buffer hasn't ended (eg the buffer has been
stored or is being processed in another thread),
buf.reserve(sample_size) will actually allocate the new memory required
to read the sample.

In other words, calling buf.reserve(sample_size) inside read_events()
simplifies doing zero-copy processing of buffers in many cases.
2 years ago
Alessandro Decina f01497e021 (cargo-release) version 0.10.7 3 years ago
Alessandro Decina 9a642d373f aya: fix lint errors 3 years ago
Alessandro Decina d690710337
Merge pull request #228 from nak3/fix-socket_filter
Fix socket_filter section match
3 years ago
Alessandro Decina 3dc9308c8e
Merge pull request #229 from dave-tucker/fix_cgroup_skb_attach_v2
aya: Fix Loading from cgroup/skb sections
3 years ago
Alessandro Decina 02c376ceb7
Merge pull request #224 from Tuetuopay/pod-arrays
aya: implement Pod for arrays of Pod types
3 years ago
Alessandro Decina 5269ab5b1c
Merge pull request #238 from vadorovsky/fix-doc-set-global
bpf: Improve documentation of set_global method
3 years ago
Michal Rostecki 7dd2e3d1f8 bpf: Improve documentation of set_global method
Use `static` instead of `const` and mention the necessity of using
`core::ptr::read_volatile`.

Signed-off-by: Michal Rostecki <vadorovsky@gmail.com>
3 years ago
Hi120ki ab462533c7 fix typo in aya/src/programs/fentry.rs 3 years ago
Kenjiro Nakayama 5725a97648 Fix unit test 3 years ago
Kenjiro Nakayama 9e41317ca6 Fix socket_filter section match
`BPF_PROG_TYPE_SOCKET_FILTER` program expands the sectionname's kind with `socket` not `socket_filter`.
So current eBPF program with socket filter always fails.

This patch fixes it.

Fix https://github.com/aya-rs/aya/issues/227
3 years ago
Daniil Bondarev 49e998dc7e
Fix typo in aya/README.md 3 years ago
Dave Tucker 5ee1321765 aya: Fix Loading from cgroup/skb sections
fa037a88e2 allowed for cgroup skb programs
that did not specify an attach direction to use the cgroup/skb section
name per the convention established in libbpf. It did not add the
necessary code to load programs from those sections which is added in
this commit

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
3 years ago
Tuetuopay 08211f6132 aya: implement Pod for arrays of Pod types
If a type is POD (meaning it can be converted to a byte array), then an
array of such type is POD.

Signed-off-by: Tuetuopay <tuetuopay@me.com>
3 years ago
dependabot[bot] ab7eed2759
build(deps): update parking_lot requirement from 0.11.1 to 0.12.0
Updates the requirements on [parking_lot](https://github.com/Amanieu/parking_lot) to permit the latest version.
- [Release notes](https://github.com/Amanieu/parking_lot/releases)
- [Changelog](https://github.com/Amanieu/parking_lot/blob/master/CHANGELOG.md)
- [Commits](https://github.com/Amanieu/parking_lot/compare/0.11.1...0.12.0)

---
updated-dependencies:
- dependency-name: parking_lot
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
3 years ago
Nimrod Shneor c6e66d8080 Fix #128: Add support for BPF_MAP_TYPE_LPM_TRIE map 3 years ago
Alessandro Decina 6316748ec1
Merge pull request #179 from dave-tucker/btf_datasec_name
btf: Replace / in DATASEC before load to kernel
3 years ago
Alessandro Decina f169a3fc6b aya: fix func_info/line_info offsets
Given the new start instruction offset, rebase func_infos and
line_infos.
3 years ago
Alessandro Decina 8202105b7d aya: relocate .text references
Handle relocations against .text symbols in all instructions not just
calls. Makes it so that let x = &some_function triggers linking of
some_function in the current program and handles the resulting
relocation accordingly.

Among other things, enables the use of bpf_for_each_map_elem.
3 years ago
Dave Tucker 825bb3ad20 btf: Replace / in DATASEC before load to kernel
This replaces the / character with a . which is allowed in the kernel
names. Not allowing a forward slash is perhaps a kernel bug, but lets
fix it up here as it's commonly used for Aya

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
3 years ago
Dave Tucker 99fa85eab8 btf: fix match arms
Don't match on kind and use if let...
Match on the BtfType

Fixes: #178

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
3 years ago
Dave Tucker 326825aab0 tests: add a test for each BTF fix
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
3 years ago
Alessandro Decina 4efc2061a8 btf: fix borrow check errors 3 years ago
Dave Tucker a1b46ece05 aya: Merge Fixup and Sanitzation to single step
Aya will now perform sanitzation and fixups in a single phase, requiring
only one pass over the BTF. This modifies the parsed BTF in place.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
3 years ago
Dave Tucker 5d8b279265 aya: Fix BTF verifier output
Currently errors can occur if the verifier output is > buffer as we get
ENOMEM. We should only provide a log_buf if initial load failed, then
retry up to 10 times to get full verifier output.

To DRY this logic it has been moved to a function so its shared with
program loading

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>

one verifier loop to rule them all

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
3 years ago
Dave Tucker d9496df3a7
Merge pull request #173 from alessandrod/func-proto-fixup
Add fixup for FuncProto
3 years ago
Alessandro Decina 7ad0524283 btf: fix sanitization if BTF_FUNC_GLOBAL is not supported
The lower 16 bits were not actually being cleared.
3 years ago
Alessandro Decina 9ba2e147a1 btf: fixup func protos
If an argument has a type, it must also have a name, see btf_func_check
in the kernel.

Given:

SEC("lsm/syslog")
int BPF_PROG(syslog_audit, int type, int ret_prev)
{
        return 0;
}

Fixes:

error: BTF error: the BPF_BTF_LOAD syscall failed. Verifier output: magic: 0xeb9f
version: 1
flags: 0x0
hdr_len: 24
type_off: 0
type_len: 76
str_off: 76
str_len: 128
btf_total_size: 228
[1] FUNC_PROTO (anon) return=2 args=(3 (anon))
[2] INT int size=4 bits_offset=0 nr_bits=32 encoding=SIGNED
[3] PTR (anon) type_id=4
[4] INT long long unsigned int size=8 bits_offset=0 nr_bits=64 encoding=(none)
[5] FUNC syslog_audit type_id=1
[5] FUNC syslog_audit type_id=1 Invalid arg#1
: Invalid argument (os error 22)
3 years ago
Alessandro Decina 89b5dd32ed btf: run fixup in place 3 years ago
Alessandro Decina b45a160bb0
Merge pull request #168 from dave-tucker/decl_tag
btf: Add support for BTF_TYPE_KIND_{TAG,DECL_TAG}
3 years ago
Dave Tucker 8f9a32ff10 aya: Fix name truncation
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
3 years ago
Dave Tucker 437432cdd6 aya: Truncate long program names
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
3 years ago
Dave Tucker 5d9ff70498 btf: Add support for BTF_TYPE_KIND_{TAG,DECL_TAG}
Adds support for two new BTF kinds including feature probes and BTF
sanitization

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
3 years ago
Alessandro Decina 1492d85a7b
Merge pull request #169 from dave-tucker/fix_array_relo
aya: Fix BTF type resolution for Arrays and Ints
3 years ago
Alessandro Decina 6a91fdf5a7
Merge pull request #157 from dave-tucker/doc-aya
aya: document the public api
3 years ago
Dave Tucker 686ce45f93 aya: Fix BTF type resolution for Arrays and Ints
The union of `size` and `type` is unused in BTF_KIND_ARRAY.
Type information of elements is in the btf_array struct that follows in
the type_ field while the index type is in the index_type field.

For BTF_KIND_INT, only the offset should be compared and size and
signedness should be ignored.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
3 years ago
dave-tucker 324c679a41 Update libbpf to be89b28f96be426e30a2b0c5312d13b30ee518c7 3 years ago
Alessandro Decina 4e9bc32a3d aya: maps: rename from_pinned() to open_pinned() 3 years ago
Alessandro Decina f12054a00d
Merge pull request #165 from dave-tucker/prog_pinned
aya: Retrieve program from pinned path
3 years ago
Dave Tucker abc8d27440 aya: Retrieve program from pinned path
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
3 years ago
dave-tucker 0619f80090 Update libbpf to 22411acc4b2c846868fd570b2d9f3b016d2af2cb 3 years ago
Dave Tucker 83cfe56fe7 aya: allocate func/line_info buffers outside if
the pointer isn't valid in the current code!

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
3 years ago
Dave Tucker bca01580e7 aya: document the public api
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
3 years ago
Dave Tucker 877c76043a btf: Add fixup for PTR types from Rust
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
3 years ago
Dave Tucker 5c6131afba Add BPF_PROG_TYPE_EXT
This requires loading the BTF to kernel when loading all programs as
well as implementing Extension program type

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
3 years ago
Dave Tucker 379bb313b1 obj: Add Btf::to_bytes
This allows for parsed BTF to be re-encoded such that it could be loaded
in to the kernel. It moves bytes_of to the utils package. We could use
Object::bytes_of, but this requires the impl of the Pod trait on
generated code.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
3 years ago
Dave Tucker 65a0b83205 Mark .rodata maps as readonly and freeze on load
This commit marks .rodata maps as BPF_F_RDONLY_PROG when loaded to
prevent a BPF program mutating them.

Initial map data is populated by the loader using the new
`BpfLoader::set_global()` API. The loader will mark
is marked as frozen using bpf_map_freeze to prevent map data
being changed from userspace.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
3 years ago
Dave Tucker 2b7dda766f btf: Fix for rename of BPF_ -> BPF_CORE_
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
3 years ago
dave-tucker 05d4bc39ea Update libbpf to 19656636a9b9a2de1f71fa3135709295c16701cc 3 years ago
Michal Rostecki 7e2fcd1d6d Support for fentry and fexit programs
fentry and fexit programs are similar to kprobe and kretprobe, but they
are newer and they have practically zero overhead to call before or
after kernel function. Also, fexit programs are focused on access to
arguments rather than the return value.

Those kind of programs were introduced in the following patchset:

https://lwn.net/Articles/804112/

Signed-off-by: Michal Rostecki <mrostecki@opensuse.org>
3 years ago
dependabot[bot] 54b0c67795 build(deps): update object requirement from 0.27 to 0.28
Updates the requirements on [object](https://github.com/gimli-rs/object) to permit the latest version.
- [Release notes](https://github.com/gimli-rs/object/releases)
- [Changelog](https://github.com/gimli-rs/object/blob/master/CHANGELOG.md)
- [Commits](https://github.com/gimli-rs/object/compare/0.27.0...0.28.1)

---
updated-dependencies:
- dependency-name: object
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
3 years ago
Ubuntu 24a292f605 Implement Pod for u128 3 years ago
dave-tucker 17d43cd6f8 Update libbpf to 93e89b34740c509406e948c78a404dd2fba67b8b 3 years ago
Alessandro Decina 26d188c659
Merge pull request #125 from dave-tucker/btf
obj: Improve section detection
3 years ago
Thia Wyrod 18970369e2
aya: Remove unnecessary unsafe markers on map iteration.
Map iteration can yield stale keys and values by virtue of sharing a
data structure with BPF programs which can modify it. However, all
accesses remain perfectly safe and will not cause memory corruption or
data races.
3 years ago
Alessandro Decina 07a6016ebb
Merge pull request #120 from eero-thia/thia/dedup
aya: eliminate name duplication in maps and programs.
3 years ago
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().
3 years ago
Will bb8a813eef aya: use correct program name when relocating 3 years ago
Dave Tucker e4d9774bf7 obj: Improve section detection
This commit improves section detection.
Previously, a section named "xdp_metadata" would be interpretted as a
program section, which is incorrect. This commit first attempts to
identify a BPF section by name, then by section.kind() ==
SectionKind::Text (executable code). The computed section kind is
stored in the Section so variants can be easily matched on later.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
3 years ago
Thia Wyrod daa7ea6d0d
aya: remove unnecessary usage of &dyn trait in favor of impl trait.
This should improve performance in most situations by eliminating
unnecessary fat pointer indirection.
3 years ago
Alessandro Decina 98b36b23bc
Merge pull request #116 from eero-thia/thia/close
aya: close file descriptors on Map drop.
3 years ago
Alessandro Decina 2955ca1d1f
Merge pull request #121 from eero-thia/thia/programs_mut
aya: programs_mut iterator to complement programs.
3 years ago
Thia Wyrod c7f8db9a0b
aya: programs_mut iterator to complement programs. 3 years ago
Thia Wyrod 1584bc47bd
aya: close file descriptors on Map drop. 3 years ago
Thia Wyrod f8f17a09fb
aya: expand include_bytes_aligned to accept expressions.
This allows one to this macro with literal expressions involving macros
such as concat! and env!.
3 years ago
Alessandro Decina 6db30fad9c
Merge pull request #108 from deverton/kprobe-debugfs
Support k/uprobes on older kernels.
3 years ago
Dan Everton 0e84610976
Refactoring after feedback. 3 years ago
Rust Plumber 761cb79fe3
aya: fix test warnings (#111) 3 years ago
Dan Everton 606c3267c4
Support pid filtering in debugfs 3 years ago
Dan Everton 1dc75542b4
Handle probe entry offsets 3 years ago
Dan Everton 4e6aeb2e69
Merge branch 'main' into kprobe-debugfs 3 years ago
Dan Everton 3dff6e8555
Updates based on feedback 3 years ago
Dan Everton 4277205e9d
Use current kernel version as default if not specified
When a BPF program doesn't specify the target kernel version, the
most compatible option is to set the program kernel version to match
the currently running kernel.
3 years ago
Dan Everton 42c9737d47
Functional detach of debugfs probes. 3 years ago
Dan Everton a4faabcf93
Fix event_alias comparison when looking in event list 3 years ago
Dan Everton 84fa2197ec
Don't duplicate perf_attach code and formatting 3 years ago
Dan Everton d0321bd1ee
Attempt auto detach of probe for debugfs 3 years ago
Dan Everton 34aa790a91
Support k/uprobes on older kernels.
Prior to kernel 4.17 probes were attached via debugfs and this patch
attempts to make that work.

Tested on kernel 4.14.
3 years ago
Dan Everton 07e3824aa4
chore: formatting 3 years ago
Dan Everton 49f6a8e819
Stub `kernel_version` for tests 3 years ago
Dan Everton d966881e46
Fix lint issues 3 years ago
Dan Everton fc0861105a
fix: make maps compatible with kernel <= 4.14
In kernel 4.15 and additional parameter was added to allow maps to have
names but using this breaks on older kernels.

This change makes it so the name is only added on kernels 4.15 and
newer.
3 years ago
Alessandro Decina 182182d840 (cargo-release) version 0.10.6 3 years ago
Dave Tucker 352e54b724 obj: fix name parsing for sk_skb sections
This commit fixes name parsing of sk_skb sections such that both named
and unnamed variants will work correctly.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
3 years ago
alessandrod 4a7f47d93a Update libbpf to 16dfb4ffe4aed03fafc00e0557b1ce1310a09731 3 years ago
Tobias Klauser 2136f05461 aya: netlink: use NETLINK_EXT_ACK from libc crate
NETLINK_EXT_ACK is available since libc crate version 0.2.105, see
https://github.com/rust-lang/libc/releases/tag/0.2.105
3 years ago
William Findlay 1e6b1afbe4
aya/obj: fix incorrect section size for .bss 3 years ago
William Findlay 27d803b634
aya/maps: improve map errors to be more descriptive 3 years ago
William Findlay 6b6d4af932
aya/programs/lsm: pass Btf by reference instead of loading new Btf in Lsm::load 3 years ago
William Findlay 6539cbb555
aya/aya-bpf: implement btf tracepoint programs 3 years ago
Alessandro Decina 140005d9e3
Merge pull request #68 from vadorovsky/lsm
Add support for raw tracepoint and LSM programs
3 years ago
William Findlay 169478c863 Add support for raw tracepoint and LSM programs
This change adds support for the following program types:

* raw tracepoint
* LSM

Supporting LSM programs involved a necessity of supporting more
load_attrs for the BPF_PROG_LOAD operation, concretely:

* expected_attach_type - for LSM programs, it has always to be set to
  BPF_LSM_MAC
* attach_btf_obj_fd - it's often used to reference the file descriptor of
  program's BTF info, altough in case of LSM programs, it only has to
  contain the value 0, which means the vmlinux object file (usually
  /sys/kernel/btf/vmlinux)
* attach_btf_id - ID of the BTF object, which in case of LSM programs is
  the ID of the function (the LSM hook)

The example of LSM program using that functionality can be found here:

https://github.com/vadorovsky/aya-example-lsm

Fixes: #9
Signed-off-by: William Findlay <william@williamfindlay.com>
Signed-off-by: Michal Rostecki <mrostecki@opensuse.org>
3 years ago
William Findlay 99f6f9e14d
aya: fix include_bytes_aligned! macro to work in some corner cases
I found a corner case in my own development workflow that caused the existing macro to not
work properly. The following changes appear to fix things. Ideally, we could add some test
cases to CI to prevent regressions.  This would require creating a dedicated directory to
hold test cases so that we can "include" them at compile time.
3 years ago
Alessandro Decina a94774755f
Merge pull request #76 from willfindlay/load_include_bytes
aya: introduce include_bytes_aligned!() macro
3 years ago
William Findlay 4df4e9c14e
aya: introduce include_bytes_aligned!() macro
This is a helper macro that can be used to include bytes at compile-time that can then be
used in Bpf::load(). Unlike std's include_bytes!(), this macro also ensures that the
resulting byte array is correctly aligned so that it can be parsed as an ELF binary.

Signed-off-by: William Findlay <william@williamfindlay.com>
3 years ago
alessandrod 03e9935358 Bump libbpf to 92c1e61a605410b16d6330fdd4a7a4e03add86d4
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
3 years ago
dependabot[bot] c99dcfb9d3 build(deps): update object requirement from 0.26 to 0.27
Updates the requirements on [object](https://github.com/gimli-rs/object) to permit the latest version.
- [Release notes](https://github.com/gimli-rs/object/releases)
- [Changelog](https://github.com/gimli-rs/object/blob/master/CHANGELOG.md)
- [Commits](https://github.com/gimli-rs/object/compare/0.26.0...0.27.0)

---
updated-dependencies:
- dependency-name: object
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
3 years ago
Alessandro Decina 4152e8b1a4 (cargo-release) version 0.10.5 3 years ago
Alessandro Decina 59a1854a6b aya: fix call relocation bug
Take the section offset into account when looking up relocation entries
3 years ago
Dave Tucker dc4b928ec5 miri: Disable Stacked Borrows and skip some tests
The perf_buffer code fails due to stacked borrows, skip this for now.
munmap isn't supported by miri.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
3 years ago
Alessandro Decina 52c51895ba aya: fix clippy 3 years ago
Alessandro Decina 64e3fb4cc8 aya: improve docs a bit and make BpfLoader default to loading BTF if available 3 years ago
Alessandro Decina 5f8f18e3a1 aya: loader: take BTF info as reference
Allows sharing the same BTF info across many loaders
3 years ago
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>
3 years ago
Alessandro Decina a7f5b3775d (cargo-release) version 0.10.4 3 years ago
Dave Tucker a10a7b3bf2 bump obj to 0.26
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
3 years ago
Alessandro Decina 98361a4c93 aya: minor PerfEvent API tweaks 3 years ago
Alessandro Decina b0a05e759e aya: run xtask codegen aya 3 years ago
Markus Stange c39dff6025 Add support for PerfEvent programs. 3 years ago