Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * This program is free software; you can redistribute it and/or
0004  * modify it under the terms of version 2 of the GNU General Public
0005  * License as published by the Free Software Foundation.
0006  */
0007 #include <linux/bpf.h>
0008 #include <linux/if_ether.h>
0009 #include <bpf/bpf_helpers.h>
0010 
0011 int _version SEC("version") = 1;
0012 
0013 SEC("xdp.frags")
0014 int xdp_adjust_frags(struct xdp_md *xdp)
0015 {
0016     __u8 *data_end = (void *)(long)xdp->data_end;
0017     __u8 *data = (void *)(long)xdp->data;
0018     __u8 val[16] = {};
0019     __u32 offset;
0020     int err;
0021 
0022     if (data + sizeof(__u32) > data_end)
0023         return XDP_DROP;
0024 
0025     offset = *(__u32 *)data;
0026     err = bpf_xdp_load_bytes(xdp, offset, val, sizeof(val));
0027     if (err < 0)
0028         return XDP_DROP;
0029 
0030     if (val[0] != 0xaa || val[15] != 0xaa) /* marker */
0031         return XDP_DROP;
0032 
0033     val[0] = 0xbb; /* update the marker */
0034     val[15] = 0xbb;
0035     err = bpf_xdp_store_bytes(xdp, offset, val, sizeof(val));
0036     if (err < 0)
0037         return XDP_DROP;
0038 
0039     return XDP_PASS;
0040 }
0041 
0042 char _license[] SEC("license") = "GPL";