test_xdp_adjust_tail_grow.c (906B)
1// SPDX-License-Identifier: GPL-2.0 2#include <linux/bpf.h> 3#include <bpf/bpf_helpers.h> 4 5SEC("xdp") 6int _xdp_adjust_tail_grow(struct xdp_md *xdp) 7{ 8 void *data_end = (void *)(long)xdp->data_end; 9 void *data = (void *)(long)xdp->data; 10 int data_len = bpf_xdp_get_buff_len(xdp); 11 int offset = 0; 12 13 /* Data length determine test case */ 14 15 if (data_len == 54) { /* sizeof(pkt_v4) */ 16 offset = 4096; /* test too large offset */ 17 } else if (data_len == 74) { /* sizeof(pkt_v6) */ 18 offset = 40; 19 } else if (data_len == 64) { 20 offset = 128; 21 } else if (data_len == 128) { 22 /* Max tail grow 3520 */ 23 offset = 4096 - 256 - 320 - data_len; 24 } else if (data_len == 9000) { 25 offset = 10; 26 } else if (data_len == 9001) { 27 offset = 4096; 28 } else { 29 return XDP_ABORTED; /* No matching test */ 30 } 31 32 if (bpf_xdp_adjust_tail(xdp, offset)) 33 return XDP_DROP; 34 return XDP_TX; 35} 36 37char _license[] SEC("license") = "GPL";