Commit Graph

334 Commits

Author SHA1 Message Date
Milan 4b6d97e4db Fix CI, clippy and feedback
Signed-off-by: Milan <milan@mdaverde.com>
2022-12-14 15:46:54 -05:00
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>
2022-12-14 15:25:11 -05:00
Dmitry Savintsev 055d94f58b fix uninlined_format_args clippy issues 2022-12-05 17:03:26 +01:00
Andre Fredette abb75ba029 Make doc fixes
Signed-off-by: Andre Fredette <afredette@redhat.com>
2022-11-17 17:38:48 -05:00
Andre Fredette a3e3e80698 Support both attach() and attach_with_options() for SchedClassifier
Signed-off-by: Andre Fredette <afredette@redhat.com>
2022-11-09 14:01:19 -05:00
Andre Fredette af3de84b08 Use a struct for setting priority and handle in SchedClassfier attach
Use a struct called TcOptions for setting priority and handle in SchedClassifier attach

struct TcOptions implements the Default trait, so for the simple use
case in which the defaults are acceptable, we can call attach as
follows:
attach(“eth0”, TcAttachType::Ingress, TcOptions::default())

To specify all options:
attach(“eth0”, TcAttachType::Ingress, TcOptions { priority: (50), handle: (3) })

Or, some options:
attach(“eth0”, TcAttachType::Ingress, TcOptions { priority: (50), ..Default::default() })

Signed-off-by: Andre Fredette <afredette@redhat.com>
2022-10-24 17:36:52 -04:00
Andre Fredette ac07608b79 Support using handle in tc programs
Implements step 1 of https://github.com/aya-rs/aya/issues/414.

- Adds handle to the SchedClassifier attach API
- Saves handle in the TcLink sruct and uses it when detaching programs

NOTE: this changes the API, so it will require a bump in the Aya version.

Signed-off-by: Andre Fredette <afredette@redhat.com>
2022-10-24 13:22:37 -04:00
Andrew Stoycos f3262e87bd Make map APIs return an option
switch map() and map_mut() from returning a
`Result` to an `Option` since it's just getting
a value from a Hashmap, and to stay in line with
the Programs API.

Remove `MapError::MapNotFound`

Signed-off-by: Andrew Stoycos <astoycos@redhat.com>
2022-10-20 11:42:53 -04:00
Andrew Stoycos 898a14d425 Use SockMapFd
Create a new type called `SockMapFd` which is
solely used when a program needs to attach
to a socket map. In the future this same
tatic could be used for other use cases
so we may make this more generic.

Signed-off-by: Andrew Stoycos <astoycos@redhat.com>
2022-10-17 16:22:08 -04:00
Andrew Stoycos 1aefa2e5e6 Core refactor of Map API
Build completing tests passing

Refactor the Map API to better align
with the aya programs API.  Specifically
remove all internal locking mechanisms
and custom Deref/DerefMut implementations.
They are replaced with a Map enum
and AsRef/AsMut implementations.

All Try_From implementations have been moved
to standardized enums, with a slightly
special one for PerfEventArray's.

Also cleanup/fix all associated tests and
documentation.

Signed-off-by: Andrew Stoycos <astoycos@redhat.com>
2022-10-17 16:22:08 -04:00
Dave Tucker 95e8c78db8 docs: Add labels for optional features
Following the lead of crates like tokio and nix, we now annotate APIs
that require optional features. This helps in cases where a user wants
to have an `AsyncPerfEventArray` which is documented on crates.io, but
it's not obvious that you have to enable the `async` feature.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2022-10-05 12:47:05 +00:00
Dave Tucker 5693fb9941 aya: Rename from_pinned and from_path to from_pin
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2022-09-09 09:24:39 +00:00
Andrew Stoycos 8a9cbf179f Add from_pinned and from_fd methods
Add `from_pinned` to allow loading BPF maps
from pinned points in the bpffs and
`from_fd` to allow loading BPF maps from
RawFds aquired via some other means eg
a unix socket.

These functions return an
aya::Map which has not been used previously
but will be the future abstraction once
all bpf maps are represented as an enum.

Signed-off-by: Andrew Stoycos <astoycos@redhat.com>
2022-09-08 15:57:55 -04:00
Dave Tucker 7c244e1f65 tests: Add integration test for pinning lifecycle
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2022-09-08 19:34:42 +00:00
Dave Tucker f961cbb3d4 aya: Replace From<FdLink> for XdpLink with TryFrom
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2022-09-07 16:23:46 +00:00
Dave Tucker 6af2053cf3 aya: Rename bpf_obj_get_info_by_id
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2022-09-07 16:23:42 +00:00
Dave Tucker 4b5b9ab3d9 aya: More pinning fixes
This commit fixes a bug and adds some missing lifecycle APIs.

1. Adds PinnedLink::from_path to create a pinned link from bpffs
2. Adds From<PinnedLink> for FdLink to allow for ^ to be converted
3. Adds From<FdLink> for XdpLink

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2022-09-06 13:48:51 +00:00
Dave Tucker 18584e2259 aya: Fix segfault in define_link_wrapper
The From<$wrapper> for $base implemention is refers to itself,
eventually causing a segfault.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2022-09-05 17:33:31 +00:00
Dave Tucker 4826bf7f74 Merge pull request #366 from dave-tucker/pin-redux-2
aya: Fix Link Pinning
2022-08-31 17:07:49 +01:00
Dave Tucker 4c1d645aa6 aya: Fix Link Pinning
1. Removes OwnedLink
2. Allows Links to be converted into FdLink
3. Introduces a PinnedLink type to handle wrap FdLink when pinned and
   support un-pinning

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2022-08-31 14:34:41 +00:00
Alessandro Decina b95adc3135 Merge pull request #371 from conectado/verifier-log-level
aya: expose BPF verifier log level configuration
2022-08-29 19:03:14 +01:00
conectado 3211646aef aya: expose BPF verifier log level configuration 2022-08-27 21:20:59 -03:00
Michal Rostecki 944d6b8a16 Change from Rust edition 2018 to 2021
Rust 2021 adds more core prelude imports, including `TryFrom` and
`TryInto`.

Signed-off-by: Michal Rostecki <vadorovsky@gmail.com>
2022-08-27 21:14:47 +01:00
Andre Fredette 207c689f56 Add support for setting priority for classifier programs
Addresses issue #358

Signed-off-by: Andre Fredette <afredette@redhat.com>
2022-08-05 23:03:52 +01:00
Dave Tucker 34ba2bc048 aya: Use PinError for all pinning errors
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2022-08-02 09:11:39 +00:00
Dave Tucker 64f8a434d2 aya: Implement FdLink::pin()
This allows for FdLinks to also be pinned to BpfFs.
In order for it to be called, the user would first call
`take_link` to get the underlying link. This can then
be destructured to an FdLink where FdLink::pin() may be called.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2022-07-28 19:04:08 +00:00
Dave Tucker 5726b6d044 aya: Allow pin to be used on all programs
This allows for `pin` to be called as `Xdp::pin()` or
Program::pin() - the same way that unload() can be used.
This simplifies the use of this API.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2022-07-28 19:04:08 +00:00
Michal Rostecki 3d592d0f29 aya: Raise the RLIMIT_MEMLOCK warning only if failed to create a map
Also, mention that setting the RLIMIT_MEMLOCK to a higher value is an
option.

Signed-off-by: Michal Rostecki <vadorovsky@gmail.com>
2022-07-08 17:30:42 +02:00
Michal Rostecki bebe98e670 aya: Raise the warning when RMILIT_MEMLOCK is not RLIM_INFINITY
Kernels before 5.11 don't use cgroup accounting, so they might reach the
RLIMIT_MEMLOCK when creating maps. After this change, we raise a warning
recommending to raise the RLIMIT_MEMLOCK.
2022-07-05 11:53:38 +02:00
Dave Tucker 004f3dd664 aya: Improve Extension Docs
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2022-06-25 15:53:47 +01:00
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>
2022-06-25 15:53:47 +01:00
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>
2022-06-25 15:53:47 +01:00
Dave Tucker fd52bfeadc aya: Implement attach_to_link for XDP
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2022-06-25 15:53:35 +01:00
Dave Tucker 7b21a2d17e aya: Implement BPF_PROG_TYPE_CGROUP_SOCK
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2022-06-09 02:13:06 +01:00
Dave Tucker 0cd1e51476 aya: Unload programs on drop
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2022-06-06 16:17:25 +01:00
Dave Tucker b2a6f00212 aya: Rename forget_link to take_link
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2022-06-06 12:57:05 +01:00
Davide Bertola e2685c98d8 Program unload API (#264)
aya: add `program.unload()` API
2022-06-03 08:42:33 +01:00
Dave Tucker 2226b89ceb aya: Add support for BPF_PROG_TYPE_SK_LOOKUP
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2022-05-29 09:14:00 +01:00
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>
2022-05-24 13:12:45 +01:00
Dave Tucker ba312c48d5 xtask: Add all crates to sidebar
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2022-05-20 19:14:06 +01:00
Kenjiro Nakayama e68d734c68 Add support for BPF_PROG_TYPE_CGROUP_SOCKOPT (#268) 2022-05-20 22:48:28 +10:00
Alessandro Decina 63b6286bd9 Merge pull request #263 from nak3/cgroup-skb-attach-type
Set attach type during load for BPF_PROG_TYPE_CGROUP_SKB
2022-05-20 13:23:35 +10:00
Kenjiro Nakayama 5d228695a4 Use map() 2022-05-20 10:51:47 +09:00
Dave Tucker af54b6c818 aya: Add BPF_PROG_TYPE_CGROUP_SOCK_ADDR
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2022-05-19 23:16:07 +01:00
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.
2022-05-19 23:21:51 +09:00
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
2022-05-17 21:52:43 +10:00
Dave Tucker 8069ad14d0 aya: Implement forget_link
Fixes #51

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2022-05-12 18:51:12 +01:00
Dave Tucker cdaa3af5ae clippy: Fix lint against latest nightly
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2022-05-07 00:34:56 +01:00
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.
2022-05-02 05:33:31 +00:00
Hi120ki ab462533c7 fix typo in aya/src/programs/fentry.rs 2022-03-06 22:29:02 +09:00