summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/bpf/test_adjust_tail.c
blob: 4cd5e860c9035e16cf140694ae3186a2b8008eea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/* SPDX-License-Identifier: GPL-2.0
 * Copyright (c) 2018 Facebook
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of version 2 of the GNU General Public
 * License as published by the Free Software Foundation.
 */
#include <linux/bpf.h>
#include <linux/if_ether.h>
#include "bpf_helpers.h"

int _version SEC("version") = 1;

SEC("xdp_adjust_tail")
int _xdp_adjust_tail(struct xdp_md *xdp)
{
	void *data_end = (void *)(long)xdp->data_end;
	void *data = (void *)(long)xdp->data;
	int offset = 0;

	if (data_end - data == 54)
		offset = 256;
	else
		offset = 20;
	if (bpf_xdp_adjust_tail(xdp, 0 - offset))
		return XDP_DROP;
	return XDP_TX;
}

char _license[] SEC("license") = "GPL";