Commit Graph

294 Commits (069ecc1cc295c7caba1b8a9b417a99ca51864513)

Author SHA1 Message Date
Kenjiro Nakayama e68d734c68
Add support for BPF_PROG_TYPE_CGROUP_SOCKOPT (#268) 3 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
3 years ago
Kenjiro Nakayama 5d228695a4 Use map() 3 years ago
Dave Tucker af54b6c818 aya: Add BPF_PROG_TYPE_CGROUP_SOCK_ADDR
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
3 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.
3 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
3 years ago
Dave Tucker 8069ad14d0 aya: Implement forget_link
Fixes #51

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
3 years ago
Dave Tucker cdaa3af5ae clippy: Fix lint against latest nightly
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
3 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.
3 years ago
Hi120ki ab462533c7 fix typo in aya/src/programs/fentry.rs 4 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>
4 years ago
Dave Tucker 8f9a32ff10 aya: Fix name truncation
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
4 years ago
Dave Tucker 437432cdd6 aya: Truncate long program names
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
4 years ago
Alessandro Decina 6a91fdf5a7
Merge pull request #157 from dave-tucker/doc-aya
aya: document the public api
4 years ago
Dave Tucker abc8d27440 aya: Retrieve program from pinned path
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
4 years ago
Dave Tucker bca01580e7 aya: document the public api
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
4 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>
4 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>
4 years ago
Alessandro Decina 07a6016ebb
Merge pull request #120 from eero-thia/thia/dedup
aya: eliminate name duplication in maps and programs.
4 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().
4 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.
4 years ago
Dan Everton 0e84610976
Refactoring after feedback. 4 years ago
Dan Everton 606c3267c4
Support pid filtering in debugfs 4 years ago
Dan Everton 1dc75542b4
Handle probe entry offsets 4 years ago
Dan Everton 4e6aeb2e69
Merge branch 'main' into kprobe-debugfs 4 years ago
Dan Everton 3dff6e8555
Updates based on feedback 4 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.
4 years ago
Dan Everton 42c9737d47
Functional detach of debugfs probes. 4 years ago
Dan Everton a4faabcf93
Fix event_alias comparison when looking in event list 4 years ago
Dan Everton 84fa2197ec
Don't duplicate perf_attach code and formatting 4 years ago
Dan Everton d0321bd1ee
Attempt auto detach of probe for debugfs 4 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.
4 years ago
William Findlay 6b6d4af932
aya/programs/lsm: pass Btf by reference instead of loading new Btf in Lsm::load 4 years ago
William Findlay 6539cbb555
aya/aya-bpf: implement btf tracepoint programs 4 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>
4 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>
4 years ago
Dave Tucker a10a7b3bf2 bump obj to 0.26
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
4 years ago
Alessandro Decina 98361a4c93 aya: minor PerfEvent API tweaks 4 years ago
Markus Stange c39dff6025 Add support for PerfEvent programs. 4 years ago
Dave Tucker e9bad0b61d Make Clippy Happy
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
4 years ago
Alessandro Decina 66a12ffcf7 aya: programs: tweak LircMode2::query doc. 4 years ago
Sean Young 81e07e9661
Implement query for lirc programs (#32)
Signed-off-by: Sean Young <sean@mess.org>
4 years ago
Alessandro Decina fa2cbe2f82 aya: fix clippy warnings 4 years ago
Alessandro Decina c2a90c2c01 aya: tc: add qdisc_detach_program
qdisc_detach_program can be used to detach all the programs that have
the given name. It's useful when you want to detach programs that were
attached by some other process (eg. iproute2), or when you want to
detach programs that were previously left attached because the program
that attached them was killed.
4 years ago
Alessandro Decina d996a88de4 aya: fix formatting 4 years ago
Alessandro Decina 0878c4505a aya: fix clippy warnings 4 years ago
Alessandro Decina 9c8e78b7d4 aya: tc: make qdisc_add_clsact return io::Error 4 years ago
Alessandro Decina 08c71dfeb1 aya: kprobe: remove pid argument
Kprobes can only be attached globally. Per-pid logic needs to be
implemented on the BPF side with bpf_get_current_pid_tgid.
4 years ago
Arnabjyoti Kalita 35f15f70e0
aya: add minimum kernel version for each map and program type (#18) 4 years ago
Alessandro Decina bb15e82c1d aya: add missing load() in kprobe example
Fixes #17
4 years ago
Alessandro Decina 7f2ceaf12e aya: netlink: port TC code to using new nlattr utils 4 years ago
Sean Young 1196ba1dcc Fix doctest and run them during CI
Signed-off-by: Sean Young <sean@mess.org>
4 years ago
Sean Young b49ba69d09 Add support for lirc programs
Signed-off-by: Sean Young <sean@mess.org>
4 years ago
Alessandro Decina be0b7bbd83 Doc fixes 4 years ago
Alessandro Decina 768640dd46 aya: add doc aliases for maps and programs 4 years ago
Alessandro Decina 293e66af65 More docs 4 years ago
Alessandro Decina ad58e171ff aya: refactor tc code a bit and add docs 4 years ago
Alessandro Decina 11e21e83be More docs 4 years ago
Alessandro Decina 6c7df27bd0 More doc fixes 4 years ago
Alessandro Decina 2cda5dbbe7 aya: implement ProgramFd for CgroupSkb 4 years ago
Alessandro Decina 2d7b9b2e90 aya: fix CgroupSkb docs 4 years ago
Alessandro Decina 08a68faf8a aya: programs: add support for BPF_PROG_TYPE_CGROUP_SKB programs 4 years ago
Alessandro Decina fb3e2f7f9d aya: programs: fix detaching programs attached with bpf_prog_attach 4 years ago
Alessandro Decina 665802594c aya: programs: fix syscall name in errors 4 years ago
Arnabjyoti Kalita 6974d349e8
programs: add support for attaching and detaching TC programs
This change adds support for attaching TC programs directly from aya, without
having to use iproute2/tc.
4 years ago
Alessandro Decina 5effc972ac aya: add support for BPF_PROG_TYPE_SCHED_CLS programs 4 years ago
Alessandro Decina 30d2b25f11 aya: xdp: fix detaching on kernels older than 5.7
XDP_FLAGS_REPLACE was added in 5.7. Now for kernels >= 5.7 whenever we
detach an XDP program we pass along the program fd we expect to be
detaching. For older kernels, we just detach whatever is attached, which
is not great but it's the way the API worked pre XDP_FLAGS_REPLACE.
5 years ago
Alessandro Decina 607cf68a69 aya: xdp: set flags when attaching with netlink 5 years ago
Alessandro Decina 9e12c9324c aya: fix warnings 5 years ago
Alessandro Decina 9a24f20e6f aya: programs: rework load_program() retry code a bit 5 years ago
Alessandro Decina 144175434f aya: programs: add support for SkMsg programs 5 years ago
Alessandro Decina dad300c88b aya: maps: add SockHash 5 years ago
Alessandro Decina ca4b3bfc04 aya: add support for SockOps programs 5 years ago
Alessandro Decina b57cace941 aya: add support BPF_PROG_TYPE_SK_SKB programs and SockMaps 5 years ago
Alessandro Decina 0b3e532d7a aya: small doc fixes 5 years ago
Alessandro Decina 79f1b385a5 aya: more docs 5 years ago
Alessandro Decina 683a58ea6d aya: consolidate errors into ProgramError::SyscallError 5 years ago
Alessandro Decina ae863bc663 aya: split aya::programs::probe into ::kprobe and ::uprobe & add docs 5 years ago
Alessandro Decina 46e0a2ede4 aya: don't export VerifierLog 5 years ago
Alessandro Decina a92bfebf50 aya: remove TryInto magic from program()/program_mut() too
For programs it's actually useful being able to get the underlying
Program enum, for example when iterating/loading all the programs
5 years ago
Alessandro Decina ee05f9d949 aya: fix verifier log handling 5 years ago
Alessandro Decina 92b4ed2664 aya: add support for function calls 5 years ago
Alessandro Decina 286e117fe0 aya: add Program::name() and make ::prog_type() public 5 years ago
Alessandro Decina 29f2d9b2d9 aya: switch to rustified enums 5 years ago
Alessandro Decina 8327ffbb8d xdp: xdp BPF_LINK_CREATE was added in 5.9 5 years ago
Alessandro Decina f11df77f85 aya: implement missing bit of retprobes 5 years ago
Alessandro Decina 3e8a279a59 Fix build with musl 5 years ago
Alessandro Decina a3ab2eff57 Format fixes 5 years ago
Alessandro Decina 3abe9bb859 Fix RawFd import paths 5 years ago
Alessandro Decina 55d8bcf386 xdp: add support for attaching with custom xdp flags 5 years ago
Alessandro Decina d326038cf4 programs: rework ProgramError a bit
Move type specific errors to XdpError SocketFilterError etc.

Annotate all source errors with #[source]
5 years ago
Alessandro Decina f88ca1f1f1 programs: add internal API to create links 5 years ago
Alessandro Decina 160e0be6d6 Change the suffix of errors from *Failed to *Error 5 years ago
Alessandro Decina af8f769b50 Turn the project into a workspace, move code under aya/ 5 years ago