1 // SPDX-License-Identifier: GPL-2.0 2 3 #include "vmlinux.h" 4 #include <bpf/bpf_helpers.h> 5 6 int xdpf_sz; 7 int sinfo_sz; 8 int data_len; 9 int pull_len; 10 11 #define XDP_PACKET_HEADROOM 256 12 13 SEC("xdp.frags") 14 int xdp_find_sizes(struct xdp_md *ctx) 15 { 16 xdpf_sz = sizeof(struct xdp_frame); 17 sinfo_sz = __PAGE_SIZE - XDP_PACKET_HEADROOM - 18 (ctx->data_end - ctx->data); 19 20 return XDP_PASS; 21 } 22 23 SEC("xdp.frags") 24 int xdp_pull_data_prog(struct xdp_md *ctx) 25 { 26 __u8 *data_end = (void *)(long)ctx->data_end; 27 __u8 *data = (void *)(long)ctx->data; 28 __u8 *val_p; 29 int err; 30 31 if (data_len != data_end - data) 32 return XDP_DROP; 33 34 err = bpf_xdp_pull_data(ctx, pull_len); 35 if (err) 36 return XDP_DROP; 37 38 val_p = (void *)(long)ctx->data + 1024; 39 if (val_p + 1 > (void *)(long)ctx->data_end) 40 return XDP_DROP; 41 42 if (*val_p != 0xbb) 43 return XDP_DROP; 44 45 return XDP_PASS; 46 } 47 48 char _license[] SEC("license") = "GPL"; 49