File: test_xdp_pull_data.c

package info (click to toggle)
linux 6.18.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,742,096 kB
  • sloc: ansic: 26,781,576; asm: 272,087; sh: 148,750; python: 79,244; makefile: 57,741; perl: 36,527; xml: 19,542; cpp: 5,911; yacc: 4,939; lex: 2,950; awk: 1,607; sed: 30; ruby: 25
file content (48 lines) | stat: -rw-r--r-- 883 bytes parent folder | download | duplicates (7)
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// SPDX-License-Identifier: GPL-2.0

#include "vmlinux.h"
#include <bpf/bpf_helpers.h>

int xdpf_sz;
int sinfo_sz;
int data_len;
int pull_len;

#define XDP_PACKET_HEADROOM 256

SEC("xdp.frags")
int xdp_find_sizes(struct xdp_md *ctx)
{
	xdpf_sz = sizeof(struct xdp_frame);
	sinfo_sz = __PAGE_SIZE - XDP_PACKET_HEADROOM -
		   (ctx->data_end - ctx->data);

	return XDP_PASS;
}

SEC("xdp.frags")
int xdp_pull_data_prog(struct xdp_md *ctx)
{
	__u8 *data_end = (void *)(long)ctx->data_end;
	__u8 *data = (void *)(long)ctx->data;
	__u8 *val_p;
	int err;

	if (data_len != data_end - data)
		return XDP_DROP;

	err = bpf_xdp_pull_data(ctx, pull_len);
	if (err)
		return XDP_DROP;

	val_p = (void *)(long)ctx->data + 1024;
	if (val_p + 1 > (void *)(long)ctx->data_end)
		return XDP_DROP;

	if (*val_p != 0xbb)
		return XDP_DROP;

	return XDP_PASS;
}

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