1 // SPDX-License-Identifier: GPL-2.0 2 /* Copyright (c) 2022 Intel */ 3 4 #include <linux/bpf.h> 5 #include <bpf/bpf_helpers.h> 6 7 struct { 8 __uint(type, BPF_MAP_TYPE_XSKMAP); 9 __uint(max_entries, 1); 10 __uint(key_size, sizeof(int)); 11 __uint(value_size, sizeof(int)); 12 } xsk SEC(".maps"); 13 14 static unsigned int idx; 15 16 SEC("xdp") int xsk_def_prog(struct xdp_md *xdp) 17 { 18 return bpf_redirect_map(&xsk, 0, XDP_DROP); 19 } 20 21 SEC("xdp") int xsk_xdp_drop(struct xdp_md *xdp) 22 { 23 /* Drop every other packet */ 24 if (idx++ % 2) 25 return XDP_DROP; 26 27 return bpf_redirect_map(&xsk, 0, XDP_DROP); 28 } 29 30 char _license[] SEC("license") = "GPL"; 31