18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci#include <linux/bpf.h>
38c2ecf20Sopenharmony_ci#include <bpf/bpf_helpers.h>
48c2ecf20Sopenharmony_ci#include "bpf_legacy.h"
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_cistruct {
78c2ecf20Sopenharmony_ci	__uint(type, BPF_MAP_TYPE_PROG_ARRAY);
88c2ecf20Sopenharmony_ci	__uint(max_entries, 1);
98c2ecf20Sopenharmony_ci	__uint(key_size, sizeof(__u32));
108c2ecf20Sopenharmony_ci	__uint(value_size, sizeof(__u32));
118c2ecf20Sopenharmony_ci} jmp_table SEC(".maps");
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_cistatic __noinline
148c2ecf20Sopenharmony_ciint subprog_tail(struct __sk_buff *skb)
158c2ecf20Sopenharmony_ci{
168c2ecf20Sopenharmony_ci	if (load_byte(skb, 0))
178c2ecf20Sopenharmony_ci		bpf_tail_call_static(skb, &jmp_table, 1);
188c2ecf20Sopenharmony_ci	else
198c2ecf20Sopenharmony_ci		bpf_tail_call_static(skb, &jmp_table, 0);
208c2ecf20Sopenharmony_ci	return 1;
218c2ecf20Sopenharmony_ci}
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_cistatic volatile int count;
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ciSEC("classifier/0")
268c2ecf20Sopenharmony_ciint bpf_func_0(struct __sk_buff *skb)
278c2ecf20Sopenharmony_ci{
288c2ecf20Sopenharmony_ci	count++;
298c2ecf20Sopenharmony_ci	return subprog_tail(skb);
308c2ecf20Sopenharmony_ci}
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ciSEC("classifier")
338c2ecf20Sopenharmony_ciint entry(struct __sk_buff *skb)
348c2ecf20Sopenharmony_ci{
358c2ecf20Sopenharmony_ci	bpf_tail_call_static(skb, &jmp_table, 0);
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ci	return 0;
388c2ecf20Sopenharmony_ci}
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_cichar __license[] SEC("license") = "GPL";
418c2ecf20Sopenharmony_ciint _version SEC("version") = 1;
42