WIP FPC-III support
[linux/fpc-iii.git] / tools / testing / selftests / bpf / progs / tailcall_bpf2bpf3.c
blob0d5482bea6c9b9c65c1775a9e12fe6e83626da42
1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/bpf.h>
3 #include <bpf/bpf_helpers.h>
4 #include "bpf_legacy.h"
6 struct {
7 __uint(type, BPF_MAP_TYPE_PROG_ARRAY);
8 __uint(max_entries, 2);
9 __uint(key_size, sizeof(__u32));
10 __uint(value_size, sizeof(__u32));
11 } jmp_table SEC(".maps");
13 __noinline
14 int subprog_tail2(struct __sk_buff *skb)
16 volatile char arr[64] = {};
18 if (load_word(skb, 0) || load_half(skb, 0))
19 bpf_tail_call_static(skb, &jmp_table, 10);
20 else
21 bpf_tail_call_static(skb, &jmp_table, 1);
23 return skb->len;
26 static __noinline
27 int subprog_tail(struct __sk_buff *skb)
29 volatile char arr[64] = {};
31 bpf_tail_call_static(skb, &jmp_table, 0);
33 return skb->len * 2;
36 SEC("classifier/0")
37 int bpf_func_0(struct __sk_buff *skb)
39 volatile char arr[128] = {};
41 return subprog_tail2(skb);
44 SEC("classifier/1")
45 int bpf_func_1(struct __sk_buff *skb)
47 volatile char arr[128] = {};
49 return skb->len * 3;
52 SEC("classifier")
53 int entry(struct __sk_buff *skb)
55 volatile char arr[128] = {};
57 return subprog_tail(skb);
60 char __license[] SEC("license") = "GPL";
61 int _version SEC("version") = 1;