18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci#include <linux/bpf.h>
38c2ecf20Sopenharmony_ci#include <bpf/bpf_helpers.h>
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_cistruct {
68c2ecf20Sopenharmony_ci	__uint(type, BPF_MAP_TYPE_PROG_ARRAY);
78c2ecf20Sopenharmony_ci	__uint(max_entries, 3);
88c2ecf20Sopenharmony_ci	__uint(key_size, sizeof(__u32));
98c2ecf20Sopenharmony_ci	__uint(value_size, sizeof(__u32));
108c2ecf20Sopenharmony_ci} jmp_table SEC(".maps");
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_cistatic volatile int count;
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci__noinline
158c2ecf20Sopenharmony_ciint subprog_tail_2(struct __sk_buff *skb)
168c2ecf20Sopenharmony_ci{
178c2ecf20Sopenharmony_ci	bpf_tail_call_static(skb, &jmp_table, 2);
188c2ecf20Sopenharmony_ci	return skb->len * 3;
198c2ecf20Sopenharmony_ci}
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci__noinline
228c2ecf20Sopenharmony_ciint subprog_tail_1(struct __sk_buff *skb)
238c2ecf20Sopenharmony_ci{
248c2ecf20Sopenharmony_ci	bpf_tail_call_static(skb, &jmp_table, 1);
258c2ecf20Sopenharmony_ci	return skb->len * 2;
268c2ecf20Sopenharmony_ci}
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci__noinline
298c2ecf20Sopenharmony_ciint subprog_tail(struct __sk_buff *skb)
308c2ecf20Sopenharmony_ci{
318c2ecf20Sopenharmony_ci	bpf_tail_call_static(skb, &jmp_table, 0);
328c2ecf20Sopenharmony_ci	return skb->len;
338c2ecf20Sopenharmony_ci}
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ciSEC("classifier/1")
368c2ecf20Sopenharmony_ciint bpf_func_1(struct __sk_buff *skb)
378c2ecf20Sopenharmony_ci{
388c2ecf20Sopenharmony_ci	return subprog_tail_2(skb);
398c2ecf20Sopenharmony_ci}
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ciSEC("classifier/2")
428c2ecf20Sopenharmony_ciint bpf_func_2(struct __sk_buff *skb)
438c2ecf20Sopenharmony_ci{
448c2ecf20Sopenharmony_ci	count++;
458c2ecf20Sopenharmony_ci	return subprog_tail_2(skb);
468c2ecf20Sopenharmony_ci}
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ciSEC("classifier/0")
498c2ecf20Sopenharmony_ciint bpf_func_0(struct __sk_buff *skb)
508c2ecf20Sopenharmony_ci{
518c2ecf20Sopenharmony_ci	return subprog_tail_1(skb);
528c2ecf20Sopenharmony_ci}
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ciSEC("classifier")
558c2ecf20Sopenharmony_ciint entry(struct __sk_buff *skb)
568c2ecf20Sopenharmony_ci{
578c2ecf20Sopenharmony_ci	return subprog_tail(skb);
588c2ecf20Sopenharmony_ci}
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_cichar __license[] SEC("license") = "GPL";
618c2ecf20Sopenharmony_ciint _version SEC("version") = 1;
62