Commit Graph

53 Commits (84e5e2894f226f4b2c7cb637a6f44d5773b927e6)

Author SHA1 Message Date
Michal Rostecki 33baf7ef22 aya-bpf/maps: Add `get_ptr` and `get_mut_ptr` methods to Array
Signed-off-by: Michal Rostecki <vadorovsky@gmail.com>
Ricky Han fbfbedb6a8 cargo fmt
Ricky Han e9ec257328 Add test case
Hengqi Chen e12e8a9ded aya-bpf/maps: Create LPMTrie with BPF_F_NO_PREALLOC
The Linux kernel requires BPF_F_NO_PREALLOC on creating LPMTrie ([0]).
Add BPF_F_NO_PREALLOC flag in LPMTrie constructor.

Closes .

  [0]: https://github.com/torvalds/linux/blob/9e6b19a66d9b/kernel/bpf/lpm_trie.c#L551

Signed-off-by: Hengqi Chen <chenhengqi@outlook.com>
Gabi 14bad9ba92
aya-bpf: minor fix lpm_trie::key docs
Dave Tucker 6ab7148731 bpf: Only use never type with rust nightly
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
Michal Rostecki ee15fbbbc5 bpf: Use `then_some` instead of `then(|| [...])`
This change fixes the `unnecessary_lazy_evaluations` clippy warning.

Signed-off-by: Michal Rostecki <vadorovsky@gmail.com>
tirex 741c35f555 Restore previous check for bpf_get_stackid
tirex 42c4d5c3af Temporary change return value condition to avoid problems with possibly (not aware) cast from int to long
tirex 5b1a3ed866 Fix return value for map removing/deleting
Tatsuyuki Ishi 5e24cf7a29
bpf: Remove unnecessary Sync bound on PerCpuArray<T>
Alessandro Decina 82cd3e695a ebpf: PerCpuArray: remove get_mut() and add get_ptr() and get_ptr_mut()
get_mut() wasn't sound as it allowed creating multiple mutable
references.
Tatsuyuki Ishi 41c6b56142 bpf: Replace map types to use &self, remove HashMap::get_mut
The bpf_map_defs are now wrapped with UnsafeCell, which also happens to
provide a cozy way to get a *mut pointer. An UnsafeCell isn't strictly
required as the struct fields are practically opaque to us, but using an
UnsafeCell follows the general best practices against miscompilation and
also prevents some obvious errors.

HashMap::get_mut was removed because the idea is completely unsound.
Previous users should wrap their data with UnsafeCell instead or use
atomics.

Closes: https://github.com/aya-rs/aya/issues/233
Alessandro Decina 16337001e4
Merge pull request from nak3/add-BPF_MAP_TYPE_BLOOM_FILTER
Add support for BPF_MAP_TYPE_BLOOM_FILTER
Kenjiro Nakayama c5d5695a71 Add missing BPF_MAP_TYPE_STACK in BPF code
Currently BPF_MAP_TYPE_STACK is supported by user code (`aya/src/maps/stack.rs`),
but it does not support the BPF_MAP_TYPE_STACK BPF code.

This patch fixes it.
Dave Tucker 74704c3b28 bpf: Support BPF_PROG_TYPE_SK_LOOKUP
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
Kenjiro Nakayama c4262f793d Add support for BPF_MAP_TYPE_BLOOM_FILTER
This patch adds support for `BPF_MAP_TYPE_BLOOM_FILTER`.
Dave Tucker 4a32e7d985 clippy: fix new lints on nightly
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
Alessandro Decina ecd6a6e96b bpf: hash_map: add get_mut() method
Nimrod Shneor d0b6daa091 Add LPMTrie Map to aya-bpf for BPF programs
William Findlay df26fd94a7
bpf/program_array: use never type, add unsafe flag, and document safety
William Findlay ff14493751
bpf/maps: implement ProgramArray
This PR implements the ProgramArray map type in aya-bpf. Includes a convenient tail_call
method that wraps the bpf_tail_call helper.
Thia Wyrod b655cf973f
aya-bpf: remove unnecessary unsafe markers on map functions.
Map lookup and deletion can yield stale keys and values by virtue of
sharing a data structure with userspace programs and other BPF programs
which can modify it. However, all accesses remain perfectly safe and will
not cause memory corruption or data races.
Alessandro Decina 8043451973 bpf: re-export Lru hash maps from aya_bpf::maps
Alessandro Decina c0f695c4b6 bpf: Add LruHashMap and LruPerCpuHashMap
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>
Dave Tucker 2a8ba55b7e bpf: Implement redirect for skbs on sockmap/sockhash
This implements redirect_skb and renames redirect to redirect_msg

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
Alessandro Decina 4116442cda bpf: PerfEventByteArray: remove unused import
Alessandro Decina 0220a4192c bpf: add PerfEventByteArray
Similar to PerfEventArray but allows to output variable length byte
slices
Alessandro Decina 23a70382b2 bpf: PerfEventArray: tweak output API
Alessandro Decina ea91fe08d3 bpf: rename PerfMap to PerfEventArray
Dave Tucker 69041954cb bpf: Added pinned constructor to maps
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
Alessandro Decina 269be03a89 bpf: add PerCpuArray
Alessandro Decina a68ff47246 aya-bpf, aya-bpf-bindings: fix clippy lints
Tw 55ba0538f2
bpf: add support for tracepoint program ()
This patch add initial support for tracepoint program type.
Hope you enjoy.

Signed-off-by: Tw <wei.tan@intel.com>
Tw d1b7b024dc bpf: fix a minor bug due to stackid allocation
The type casting introduces an allocation, this will cause compiling failure when linking final bpf target.
So remove this casting to fix this issue.

BTW, the following is the failure I met:

= note: 07:24:12 [ERROR] fatal error: "unable to allocate function return #1"
          PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace.
          Stack dump:
          0.    Running pass 'Function Pass Manager' on module 'trace_bpf-001a275b17e9eb12'.
          1.    Running pass 'BPF DAG->DAG Pattern Instruction Selection' on function '@_ZN7aya_bpf4maps11stack_trace10StackTrace11get_stackid17h32b649bc3780c0aaE'

Signed-off-by: Tw <wei.tan@intel.com>
Tw fd20bd5e23 bpf: add support for STACK_TRACE map
This path support initial support for BPF_MAP_TYPE_STACK_TRACE.

Signed-off-by: Tw <wei.tan@intel.com>
Alessandro Decina 122a5306e7 aya, aya-bpf-bindings: regenerate bindings
Alessandro Decina 8cd669ca9a xtask: fix include paths for kernel headers bundled with libbpf
Alessandro Decina 67d35cc1d3 bpf: fix PerfMap::output() API when appending context data
map.output(&ctx, &data, nr_bytes) can be used to append nr_bytes from
the current context to the &data event.
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.
Alessandro Decina 240c65507b bpf: add HashMap::remove()
Alessandro Decina 696ae6079c bpf: Add HashMap::pinned API
Alessandro Decina bf4892d0db bpf: add support for Queue and SockMap maps
Alessandro Decina 575e85c412 bpf: add id and pinning fields to bpf_map_def
Alessandro Decina ab8d512b60 bpf: add HashMap::insert
Alessandro Decina 4febbc3fae bpf: perf_map: fix type error
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.
Alessandro Decina 1b314ded2f bpf: add SockHash::redirect
Alessandro Decina e11edc072b bpf: add more bindings
Initial support for Array, HashMap and SockHash maps, and for SkSkb,
SkMsg, SockOps and XDP programs.