Commit Graph

46 Commits (4d0cbc88105898e98053ba28d7a2dab3fcc9f0f6)

Author SHA1 Message Date
Tamir Duberstein d16e607fd4
rustfmt: group_imports = "StdExternalCrate"
High time we stop debating this; let the robots do the work.
12 months ago
Tamir Duberstein 6d06e2bf3a
Include ~all crates in default members
Several tests were not running due to being omitted from this list.
1 year ago
Tamir Duberstein 4fef255823
disallow (some) as conversions
See https://rust-lang.github.io/rust-clippy/master/#/as_conversions.
1 year ago
Kenjiro Nakayama 7dfabd07a7 Add pt_regs handling in aya-bpf/args.rs for riscv64
This patch introduces `pt_regs` handling in aya-bpf/args.rs
for the riscv64 architecture. The current CI is disabled
for riscv64 because this implementation is missing.
1 year ago
Kabir Kwatra 92f9c43230
feat(bpf+sk_skb): wrap `change_proto` helper 1 year ago
Alessandro Decina 556463a85f ebpf: SkbBuff: add some accessors 2 years ago
Tuetuopay 890e8c9340 bpf: fix set_mark by not copying __sk_buff
Such an assignment in two parts (first deref in `unsafe`, then field
access outside of `unsafe`) is bogus: the deref "returned" by the
`unsafe` block actually creates a copy of the `__sk_buff` struct because
it implements `Copy`. The mark value is written to the `mark` field of
the copy, and not the real `__sk_buff`.

Change it to do it all in the `unsafe` block.

The same is done for the `.len()` getter to avoid copying the whole
`__sk_buff` struct for a 32 bit field. Although such a copy should be
optimized out by the compiler, it's better to help it do so.
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
abhijeetbhagat 6c813b8c38 fix all clippy warnings 2 years ago
Michal Rostecki 895f96e971 ebpf: Add TcContext for classifier programs
This change separates the previous `SkBuffContext` into three structs:

* `SkBuff` which is a wrapper around `__sk_buff` which contains all
  possible methods operating on it.
* `SkBuffContext` which is a program context for programs which
  **cannot** access `__sk_buff` directly and instead can only use
  `load_bytes`.
* `TcContext` which is a classifier context which can access `__sk_buff`
  directly, hence exposes `data` and `data_end`.

Signed-off-by: Michal Rostecki <vadorovsky@gmail.com>
2 years ago
Hengqi Chen c713dde061 aya-bpf/programs: Add `pull_data` method to SKB context
The pull_data method is used to ensure that all the required bytes
are available in the linear portion of the skb.

Signed-off-by: Hengqi Chen <chenhengqi@outlook.com>
2 years ago
Michal Rostecki c6e1d56684 bpf: Add `load_bytes` method to SKB context
This new method allows to load bytes into the given bytes slice, not
requiring to alloate the memory on stack. It can be used with
PerCpuArrays.

Example:

https://github.com/vadorovsky/aya-examples/blob/main/tc-bytes/tc-bytes-ebpf/src/main.rs

Signed-off-by: Michal Rostecki <vadorovsky@gmail.com>
2 years ago
Alessandro Decina 150dc1b610
Merge pull request #326 from NoneTirex/fix-map-delete-return-value
Change condititon for some bpf helpers
2 years ago
tirex caa66cabac Add missing inline macro to xdp methods 2 years ago
tirex 42c4d5c3af Temporary change return value condition to avoid problems with possibly (not aware) cast from int to long 2 years ago
Dave Tucker 6f51b616e1 bpf: Implement BPF_PROG_TYPE_CGROUP_SOCK
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2 years ago
Dave Tucker 9d18a48c3c bpf: Add accessors to SockOpsContext
Allow getting family, remote/local v4/v6 addresses and the remote and
local ports.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2 years ago
Dave Tucker 74704c3b28 bpf: Support BPF_PROG_TYPE_SK_LOOKUP
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
Dave Tucker 2bac924464 bpf: Add support for BPF_PROG_TYPE_CGROUP_SOCK_ADDR
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
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
tirex f1f7185dab Set skb_buff visbility to pub 2 years ago
Alessandro Decina f75d968657
Merge pull request #239 from nak3/pub-ops
aya-bpf: expose bpf_sock_ops of SockOpsContext
3 years ago
Kenjiro Nakayama 360560ec4e aya-bpf: expose sk_msg_md of SkMsgContext
This patch expose sk_msg_md of SkMsgContext.
3 years ago
Kenjiro Nakayama 6bc5a4d82d aya-bpf: expose bpf_sock_ops of SockOpsContext
This patch expose bpf_sock_ops of `SockOpsContext`.
3 years ago
Michal Rostecki 34d74fcd3b bpf: sk_buff: Add get_socket_uid method to SkBuffContext
This change exposes the BPF helper bpf_socket_get_uid as a public method
of SkBuffContext, which allows to get the owner UID of the socket
associated to the sk_buff stored in the context.

Signed-off-by: Michal Rostecki <vadorovsky@gmail.com>
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
Thia Wyrod d280b856bd
aya-bpf: expose xdp_md of XdpContext and add metadata functions. 3 years ago
Dave Tucker 8a6fe4a640 bpf: Rename SkSkbContext to SkBuffContext
This is necessary since the context is used in many other program types
and not just in SK_SKB programs.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
3 years ago
William Findlay 89dee1a114
aya-bpf: implement argument coercion for pt_regs and BTF programs
Implements argument and return value coercion helpers for:
    - LSM programs
    - BTF tracepoints
    - [ku]{ret}probes

Signed-off-by: William Findlay <william@williamfindlay.com>
3 years ago
William Findlay 6539cbb555
aya/aya-bpf: implement btf tracepoint 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
Markus Stange c39dff6025 Add support for PerfEvent programs. 3 years ago
Alessandro Decina a68ff47246 aya-bpf, aya-bpf-bindings: fix clippy lints 3 years ago
Tw 55ba0538f2
bpf: add support for tracepoint program (#29)
This patch add initial support for tracepoint program type.
Hope you enjoy.

Signed-off-by: Tw <wei.tan@intel.com>
3 years ago
Alessandro Decina 5dfd27dbd0 bpf: fix some clippy warnings 3 years ago
Alessandro Decina ef39e0ebd2 bpf: sk_skb: add ::cb() and ::cb_mut() to work with skb->cb 3 years ago
Alessandro Decina ec5822d78e bpf: sk_skb: wrap more helpers 3 years ago
Alessandro Decina 73c48a5029 bpf: add support for BPF_PROG_TYPE_CGROUP_SKB programs
Example:

fn cgroup_skb_egress(skb: SkSkbContext) -> i32 {
    // allow data to go through
    1
}
3 years ago
Alessandro Decina 97c96383bd bpf: improve SockOpsContext API 3 years ago
Alessandro Decina cb3d71429c bpf: improve SkMsgContext API 3 years ago
Alessandro Decina 8f55cd728c bpf: SkSkbContext: add ::l3_csum_replace 3 years ago
Alessandro Decina 8e6f447e9b bpf: sk_skb: add helper methods
This adds support for skb_store_bytes, skb_load_bytes and
l4_csum_replace to SkSkbContext.
3 years ago
Alessandro Decina e11edc072b bpf: add more bindings
Initial support for Array, HashMap and SockHash maps, and for SkSkb,
SkMsg, SockOps and XDP programs.
3 years ago
Alessandro Decina 7815711196 bpf: add aya-bpf-bindings
Move the generated bindings to aya-bpf-bindings.
4 years ago
Alessandro Decina cdf960aaa1 bpf: initial bpf bindings 4 years ago