.. | .. |
---|
4 | 4 | * XDP monitor tool, based on tracepoints |
---|
5 | 5 | */ |
---|
6 | 6 | #include <uapi/linux/bpf.h> |
---|
7 | | -#include "bpf_helpers.h" |
---|
| 7 | +#include <bpf/bpf_helpers.h> |
---|
8 | 8 | |
---|
9 | | -struct bpf_map_def SEC("maps") redirect_err_cnt = { |
---|
10 | | - .type = BPF_MAP_TYPE_PERCPU_ARRAY, |
---|
11 | | - .key_size = sizeof(u32), |
---|
12 | | - .value_size = sizeof(u64), |
---|
13 | | - .max_entries = 2, |
---|
| 9 | +struct { |
---|
| 10 | + __uint(type, BPF_MAP_TYPE_PERCPU_ARRAY); |
---|
| 11 | + __type(key, u32); |
---|
| 12 | + __type(value, u64); |
---|
| 13 | + __uint(max_entries, 2); |
---|
14 | 14 | /* TODO: have entries for all possible errno's */ |
---|
15 | | -}; |
---|
| 15 | +} redirect_err_cnt SEC(".maps"); |
---|
16 | 16 | |
---|
17 | 17 | #define XDP_UNKNOWN XDP_REDIRECT + 1 |
---|
18 | | -struct bpf_map_def SEC("maps") exception_cnt = { |
---|
19 | | - .type = BPF_MAP_TYPE_PERCPU_ARRAY, |
---|
20 | | - .key_size = sizeof(u32), |
---|
21 | | - .value_size = sizeof(u64), |
---|
22 | | - .max_entries = XDP_UNKNOWN + 1, |
---|
23 | | -}; |
---|
| 18 | +struct { |
---|
| 19 | + __uint(type, BPF_MAP_TYPE_PERCPU_ARRAY); |
---|
| 20 | + __type(key, u32); |
---|
| 21 | + __type(value, u64); |
---|
| 22 | + __uint(max_entries, XDP_UNKNOWN + 1); |
---|
| 23 | +} exception_cnt SEC(".maps"); |
---|
24 | 24 | |
---|
25 | 25 | /* Tracepoint format: /sys/kernel/debug/tracing/events/xdp/xdp_redirect/format |
---|
26 | 26 | * Code in: kernel/include/trace/events/xdp.h |
---|
.. | .. |
---|
129 | 129 | }; |
---|
130 | 130 | #define MAX_CPUS 64 |
---|
131 | 131 | |
---|
132 | | -struct bpf_map_def SEC("maps") cpumap_enqueue_cnt = { |
---|
133 | | - .type = BPF_MAP_TYPE_PERCPU_ARRAY, |
---|
134 | | - .key_size = sizeof(u32), |
---|
135 | | - .value_size = sizeof(struct datarec), |
---|
136 | | - .max_entries = MAX_CPUS, |
---|
137 | | -}; |
---|
| 132 | +struct { |
---|
| 133 | + __uint(type, BPF_MAP_TYPE_PERCPU_ARRAY); |
---|
| 134 | + __type(key, u32); |
---|
| 135 | + __type(value, struct datarec); |
---|
| 136 | + __uint(max_entries, MAX_CPUS); |
---|
| 137 | +} cpumap_enqueue_cnt SEC(".maps"); |
---|
138 | 138 | |
---|
139 | | -struct bpf_map_def SEC("maps") cpumap_kthread_cnt = { |
---|
140 | | - .type = BPF_MAP_TYPE_PERCPU_ARRAY, |
---|
141 | | - .key_size = sizeof(u32), |
---|
142 | | - .value_size = sizeof(struct datarec), |
---|
143 | | - .max_entries = 1, |
---|
144 | | -}; |
---|
| 139 | +struct { |
---|
| 140 | + __uint(type, BPF_MAP_TYPE_PERCPU_ARRAY); |
---|
| 141 | + __type(key, u32); |
---|
| 142 | + __type(value, struct datarec); |
---|
| 143 | + __uint(max_entries, 1); |
---|
| 144 | +} cpumap_kthread_cnt SEC(".maps"); |
---|
145 | 145 | |
---|
146 | 146 | /* Tracepoint: /sys/kernel/debug/tracing/events/xdp/xdp_cpumap_enqueue/format |
---|
147 | 147 | * Code in: kernel/include/trace/events/xdp.h |
---|
.. | .. |
---|
210 | 210 | return 0; |
---|
211 | 211 | } |
---|
212 | 212 | |
---|
213 | | -struct bpf_map_def SEC("maps") devmap_xmit_cnt = { |
---|
214 | | - .type = BPF_MAP_TYPE_PERCPU_ARRAY, |
---|
215 | | - .key_size = sizeof(u32), |
---|
216 | | - .value_size = sizeof(struct datarec), |
---|
217 | | - .max_entries = 1, |
---|
218 | | -}; |
---|
| 213 | +struct { |
---|
| 214 | + __uint(type, BPF_MAP_TYPE_PERCPU_ARRAY); |
---|
| 215 | + __type(key, u32); |
---|
| 216 | + __type(value, struct datarec); |
---|
| 217 | + __uint(max_entries, 1); |
---|
| 218 | +} devmap_xmit_cnt SEC(".maps"); |
---|
219 | 219 | |
---|
220 | 220 | /* Tracepoint: /sys/kernel/debug/tracing/events/xdp/xdp_devmap_xmit/format |
---|
221 | 221 | * Code in: kernel/include/trace/events/xdp.h |
---|
222 | 222 | */ |
---|
223 | 223 | struct devmap_xmit_ctx { |
---|
224 | 224 | u64 __pad; // First 8 bytes are not accessible by bpf code |
---|
225 | | - int map_id; // offset:8; size:4; signed:1; |
---|
| 225 | + int from_ifindex; // offset:8; size:4; signed:1; |
---|
226 | 226 | u32 act; // offset:12; size:4; signed:0; |
---|
227 | | - u32 map_index; // offset:16; size:4; signed:0; |
---|
| 227 | + int to_ifindex; // offset:16; size:4; signed:1; |
---|
228 | 228 | int drops; // offset:20; size:4; signed:1; |
---|
229 | 229 | int sent; // offset:24; size:4; signed:1; |
---|
230 | | - int from_ifindex; // offset:28; size:4; signed:1; |
---|
231 | | - int to_ifindex; // offset:32; size:4; signed:1; |
---|
232 | | - int err; // offset:36; size:4; signed:1; |
---|
| 230 | + int err; // offset:28; size:4; signed:1; |
---|
233 | 231 | }; |
---|
234 | 232 | |
---|
235 | 233 | SEC("tracepoint/xdp/xdp_devmap_xmit") |
---|