Commit Graph

429 Commits (1db17d5ad3b804ef2048123ea0c79ab22d00f1b3)

Author SHA1 Message Date
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>
2 years ago
Dave Tucker ce79de7ff6 aya: Fix is_perf_link_supported
This was mistakenly comparing the exit code of the syscall, which is
always -1 and not the corresponding error-code. Added unit tests to
ensure we don't regress.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2 years ago
Dave Tucker 7479c1dd6c aya: More discrete feature logging
Just use the Debug formatter vs. printing a message for each probe.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2 years ago
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>
2 years ago
Dave Tucker 763b92a2e0 aya: Add probe for bpf_link_create for perf programs
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2 years ago
Dave Tucker ce22ca668f aya: Make features a lazy_static
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2 years ago
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>
2 years ago
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>
2 years ago
Alessandro Decina cfa693bc3b
Merge pull request #515 from alessandrod/fix-lru-hash
aya: fix Lru and LruPerCpu hash maps
2 years ago
Alessandro Decina c22014c757 aya: fix Lru and LruPerCpu hash maps
They were broken by https://github.com/aya-rs/aya/pull/397
2 years ago
Andrew Stoycos 52e625060e
Support BTF key/value specification for all maps
Fix a bug which was resulting in `ENOTSUPP` following
the `BPF_MAP_CREATE` Syscall.  This fix was initially
found by libbpf maintainers in:
https://github.com/libbpf/libbpf/issues/355.

Signed-off-by: Andrew Stoycos <astoycos@redhat.com>
2 years ago
Alessandro Decina 22d79312f7
Merge pull request #445 from anfredette/tc-link-recon
Support reconstruction of `SchedClassifierLink`
2 years ago
Andre Fredette 7c24296b5d Address review comments from @alessandrod
Signed-off-by: Andre Fredette <afredette@redhat.com>
2 years ago
banditopazzo 48fdf5a250 chore: tracefs review fixes 2 years ago
banditopazzo c6c4ac7eea feat: get_tracefs function 2 years ago
Andre Fredette d43879d991 Updates after rebase due to changes in define_link_wrapper
Signed-off-by: Andre Fredette <afredette@redhat.com>
2 years ago
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>
2 years ago
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>
2 years ago
Andre Fredette 65f5b76593 Address review comments
Signed-off-by: Andre Fredette <afredette@redhat.com>
2 years ago
Andre Fredette 849796c420 rename SchedClassifierLink:new() to new_tc_link()
Avoids name confilct with pr #462

Signed-off-by: Andre Fredette <afredette@redhat.com>
2 years ago
Andre Fredette 67efc33414 Additional edits to SchedClassifierLink documentation.
Signed-off-by: Andre Fredette <afredette@redhat.com>
2 years ago
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>
2 years ago
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>
2 years ago
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>
2 years ago
Andrew Stoycos 1899d5f4fd Expose inner errors
Currently aya will just report a standard outer level
error on failure.  Ensure that we also report the inner
error condition back to the user

Signed-off-by: Andrew Stoycos <astoycos@redhat.com>
2 years ago
Michal Rostecki dad75f45ac Update Tokio and inventory
Signed-off-by: Michal Rostecki <vadorovsky@gmail.com>
2 years ago
Shenghui Ye 9c451a3357 aya-obj: update documentation and versioning info
- Set the version number of `aya-obj` to `0.1.0`.
- Update the description of the `aya-obj` crate.
- Add a section in README and rustdoc warning about the unstable API.
2 years ago
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
2 years ago
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
2 years ago
Shenghui Ye 81bc307dce aya-obj: migrate bindgen destination
Aya::obj depends on bindgen generated files, and we start
by migrating bindgen generated files.

This commit adds the new aya-obj crate to the workplace
and migrates generated files into the crate. We use core
instead of std in an effort to make the final crate no_std.

Bindgen was run against libbpf v1.0.1.

Refs: #473
2 years ago
Alessandro Decina c6f93b1775 btf relocs: don't panic on failed relocation
Error out instead of panicing when we can't find a compatible target
candidate for a relocation.
2 years ago
Alessandro Decina aba99ea4b1 btf: make btf::RelocationError private
BpfError::RelocationError type erases the inner error so no need to
export the type.
2 years ago
Alessandro Decina 12e422b211 btf: fix regression computing pointer sizes
Computing pointer sizes was broken in #285
2 years ago
ajwerner 1a22792ee7 Resolve symbol address for PIE executables
See https://github.com/foniod/redbpf/pull/308 for a similar change.
2 years ago
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.
2 years ago
Michal Rostecki 9f5d157628
Merge pull request #461 from FallingSnow/main
Add ability to iterate over LpmTrie keys and matches
2 years ago
Ayrton Sparling 10ac5957c1
Fix LpnTrieKeys -> LpmTrieKeys typo 2 years ago
Milan 925504f230 Fix doctest issue 2 years ago
Milan 4b6d97e4db Fix CI, clippy and feedback
Signed-off-by: Milan <milan@mdaverde.com>
2 years ago
Milan 8f1163a400 Add support for BPF_PROG_TYPE_CGROUP_DEVICE
Kernel 4.15 added a new eBPF program that can
be used with cgroup v2 to control & observe device
access (e.g. read, write, mknod) - `BPF_PROG_TYPE_CGROUP_DEVICE`.

We add the ability to create these programs with the `cgroup_device`
proc macro which creates the `cgroup/dev` link section. Device
details are available to the eBPF program in `DeviceContext`.

The userspace representation is provided with the `CgroupDevice`
structure.

Fixes: #212
Signed-off-by: Milan <milan@mdaverde.com>
2 years ago
Ayrton Sparling a44f054bec fix formatting 2 years ago
Ayrton Sparling 1368eb94e7 Remove old test 2 years ago
Ayrton Sparling 9a3682e793 Add ability to iterate over lpmtrie key matches 2 years ago
Ayrton Sparling 8fe64aef1f Fix lpmtrie iter returning nothing 2 years ago
Alexis Bauvin 51bb50ed8e maps: add missing TryFrom<Map> for HashMap, PerCpuHashMap and LpmTrie 2 years ago
Ayrton Sparling e4182a9eab Iterate lpmtrie 2 years ago
Dmitry Savintsev 055d94f58b fix uninlined_format_args clippy issues 2 years ago
dependabot[bot] 1fe7bba070
build(deps): update object requirement from 0.29 to 0.30
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.29.0...0.30.0)

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

Signed-off-by: dependabot[bot] <support@github.com>
2 years ago
Michal Rostecki 9382de75cc
Merge pull request #452 from vadorovsky/fix-lint
Fix clippy error
2 years ago
Michal Rostecki 176d61ae23 Fix clippy error
`'local` lifetime can be elided to `'_` which triggers:

https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes

Signed-off-by: Michal Rostecki <vadorovsky@gmail.com>
2 years ago