test_skb_ctx.c 516 字节
Newer Older
1 2 3
// SPDX-License-Identifier: GPL-2.0

#include <linux/bpf.h>
4
#include <bpf/bpf_helpers.h>
5 6 7 8 9 10 11 12 13 14 15 16 17 18

int _version SEC("version") = 1;
char _license[] SEC("license") = "GPL";

SEC("skb_ctx")
int process(struct __sk_buff *skb)
{
	#pragma clang loop unroll(full)
	for (int i = 0; i < 5; i++) {
		if (skb->cb[i] != i + 1)
			return 1;
		skb->cb[i]++;
	}
	skb->priority++;
19
	skb->tstamp++;
20
	skb->mark++;
21

22 23 24 25
	if (skb->wire_len != 100)
		return 1;
	if (skb->gso_segs != 8)
		return 1;
26 27
	if (skb->gso_size != 10)
		return 1;
28

29 30
	return 0;
}