From b6402d5a68e3fefffd1fe1930d8a29b59e2c014b Mon Sep 17 00:00:00 2001 From: Hengqi Chen Date: Tue, 30 Aug 2022 12:02:41 +0000 Subject: [PATCH] aya-bpf/maps: Add skb_output/xdp_output to PerfEventArray `skb_output` and `xdp_output` are simple wrappers around the existing `output_at_index` method. With these wrappers, we can easily submit the raw data blob held by `struct __sk_buff *`/`struct xdp_md *` to a PerfEventArray. Signed-off-by: Hengqi Chen --- bpf/aya-bpf/src/maps/perf/perf_event_array.rs | 8 ++++++++ bpf/aya-bpf/src/maps/perf/perf_event_byte_array.rs | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/bpf/aya-bpf/src/maps/perf/perf_event_array.rs b/bpf/aya-bpf/src/maps/perf/perf_event_array.rs index c881a885..cb0e9383 100644 --- a/bpf/aya-bpf/src/maps/perf/perf_event_array.rs +++ b/bpf/aya-bpf/src/maps/perf/perf_event_array.rs @@ -66,4 +66,12 @@ impl PerfEventArray { ); } } + + pub fn skb_output(&self, ctx: &C, skb_len: u32, data: &T) { + self.output_at_index(ctx, BPF_F_CURRENT_CPU as u32, data, skb_len) + } + + pub fn xdp_output(&self, ctx: &C, xdp_len: u32, data: &T) { + self.output_at_index(ctx, BPF_F_CURRENT_CPU as u32, data, xdp_len) + } } diff --git a/bpf/aya-bpf/src/maps/perf/perf_event_byte_array.rs b/bpf/aya-bpf/src/maps/perf/perf_event_byte_array.rs index 46c3613f..00b57039 100644 --- a/bpf/aya-bpf/src/maps/perf/perf_event_byte_array.rs +++ b/bpf/aya-bpf/src/maps/perf/perf_event_byte_array.rs @@ -63,4 +63,12 @@ impl PerfEventByteArray { ); } } + + pub fn skb_output(&self, ctx: &C, skb_len: u32, data: &[u8]) { + self.output_at_index(ctx, BPF_F_CURRENT_CPU as u32, data, skb_len) + } + + pub fn xdp_output(&self, ctx: &C, xdp_len: u32, data: &[u8]) { + self.output_at_index(ctx, BPF_F_CURRENT_CPU as u32, data, xdp_len) + } }