xref: /linux/tools/testing/selftests/bpf/progs/tailcall_bpf2bpf2.c (revision 4fd18fc38757217c746aa063ba9e4729814dc737)
1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/bpf.h>
3 #include <bpf/bpf_helpers.h>
4 #include "bpf_legacy.h"
5 
6 struct {
7 	__uint(type, BPF_MAP_TYPE_PROG_ARRAY);
8 	__uint(max_entries, 1);
9 	__uint(key_size, sizeof(__u32));
10 	__uint(value_size, sizeof(__u32));
11 } jmp_table SEC(".maps");
12 
13 static __noinline
14 int subprog_tail(struct __sk_buff *skb)
15 {
16 	if (load_byte(skb, 0))
17 		bpf_tail_call_static(skb, &jmp_table, 1);
18 	else
19 		bpf_tail_call_static(skb, &jmp_table, 0);
20 	return 1;
21 }
22 
23 static volatile int count;
24 
25 SEC("classifier/0")
26 int bpf_func_0(struct __sk_buff *skb)
27 {
28 	count++;
29 	return subprog_tail(skb);
30 }
31 
32 SEC("classifier")
33 int entry(struct __sk_buff *skb)
34 {
35 	bpf_tail_call_static(skb, &jmp_table, 0);
36 
37 	return 0;
38 }
39 
40 char __license[] SEC("license") = "GPL";
41 int _version SEC("version") = 1;
42