test_xdp_update_frags.c (1000B)
1// SPDX-License-Identifier: GPL-2.0 2/* 3 * This program is free software; you can redistribute it and/or 4 * modify it under the terms of version 2 of the GNU General Public 5 * License as published by the Free Software Foundation. 6 */ 7#include <linux/bpf.h> 8#include <linux/if_ether.h> 9#include <bpf/bpf_helpers.h> 10 11int _version SEC("version") = 1; 12 13SEC("xdp.frags") 14int xdp_adjust_frags(struct xdp_md *xdp) 15{ 16 __u8 *data_end = (void *)(long)xdp->data_end; 17 __u8 *data = (void *)(long)xdp->data; 18 __u8 val[16] = {}; 19 __u32 offset; 20 int err; 21 22 if (data + sizeof(__u32) > data_end) 23 return XDP_DROP; 24 25 offset = *(__u32 *)data; 26 err = bpf_xdp_load_bytes(xdp, offset, val, sizeof(val)); 27 if (err < 0) 28 return XDP_DROP; 29 30 if (val[0] != 0xaa || val[15] != 0xaa) /* marker */ 31 return XDP_DROP; 32 33 val[0] = 0xbb; /* update the marker */ 34 val[15] = 0xbb; 35 err = bpf_xdp_store_bytes(xdp, offset, val, sizeof(val)); 36 if (err < 0) 37 return XDP_DROP; 38 39 return XDP_PASS; 40} 41 42char _license[] SEC("license") = "GPL";