brintos

brintos / linux-shallow public Read only

0
0
Text · 1.0 KiB · ca68c03 Raw
53 lines · c
1// SPDX-License-Identifier: GPL-2.02/* Copyright (c) 2018 Facebook3 *4 * This program is free software; you can redistribute it and/or5 * modify it under the terms of version 2 of the GNU General Public6 * License as published by the Free Software Foundation.7 */8#include <linux/bpf.h>9#include <linux/if_ether.h>10#include <bpf/bpf_helpers.h>11 12SEC("xdp")13int _xdp_adjust_tail_shrink(struct xdp_md *xdp)14{15	__u8 *data_end = (void *)(long)xdp->data_end;16	__u8 *data = (void *)(long)xdp->data;17	int offset = 0;18 19	switch (bpf_xdp_get_buff_len(xdp)) {20	case 54:21		/* sizeof(pkt_v4) */22		offset = 256; /* shrink too much */23		break;24	case 9000:25		/* non-linear buff test cases */26		if (data + 1 > data_end)27			return XDP_DROP;28 29		switch (data[0]) {30		case 0:31			offset = 10;32			break;33		case 1:34			offset = 4100;35			break;36		case 2:37			offset = 8200;38			break;39		default:40			return XDP_DROP;41		}42		break;43	default:44		offset = 20;45		break;46	}47	if (bpf_xdp_adjust_tail(xdp, 0 - offset))48		return XDP_DROP;49	return XDP_TX;50}51 52char _license[] SEC("license") = "GPL";53