Magnus Karlsson | 2e5d72c | 2019-11-07 18:47:37 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | #include <linux/bpf.h> |
Toke Høiland-Jørgensen | 7cf245a | 2020-01-20 14:06:49 +0100 | [diff] [blame] | 3 | #include <bpf/bpf_helpers.h> |
Magnus Karlsson | 2e5d72c | 2019-11-07 18:47:37 +0100 | [diff] [blame] | 4 | #include "xdpsock.h" |
| 5 | |
| 6 | /* This XDP program is only needed for the XDP_SHARED_UMEM mode. |
| 7 | * If you do not use this mode, libbpf can supply an XDP program for you. |
| 8 | */ |
| 9 | |
| 10 | struct { |
| 11 | __uint(type, BPF_MAP_TYPE_XSKMAP); |
| 12 | __uint(max_entries, MAX_SOCKS); |
| 13 | __uint(key_size, sizeof(int)); |
| 14 | __uint(value_size, sizeof(int)); |
| 15 | } xsks_map SEC(".maps"); |
| 16 | |
| 17 | static unsigned int rr; |
| 18 | |
| 19 | SEC("xdp_sock") int xdp_sock_prog(struct xdp_md *ctx) |
| 20 | { |
| 21 | rr = (rr + 1) & (MAX_SOCKS - 1); |
| 22 | |
| 23 | return bpf_redirect_map(&xsks_map, rr, XDP_DROP); |
| 24 | } |