18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci#include <linux/bpf.h>
38c2ecf20Sopenharmony_ci
48c2ecf20Sopenharmony_ci#include <bpf/bpf_helpers.h>
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_cistruct {
78c2ecf20Sopenharmony_ci	__uint(type, BPF_MAP_TYPE_PROG_ARRAY);
88c2ecf20Sopenharmony_ci	__uint(max_entries, 3);
98c2ecf20Sopenharmony_ci	__uint(key_size, sizeof(__u32));
108c2ecf20Sopenharmony_ci	__uint(value_size, sizeof(__u32));
118c2ecf20Sopenharmony_ci} jmp_table SEC(".maps");
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci#define TAIL_FUNC(x) 				\
148c2ecf20Sopenharmony_ci	SEC("classifier/" #x)			\
158c2ecf20Sopenharmony_ci	int bpf_func_##x(struct __sk_buff *skb)	\
168c2ecf20Sopenharmony_ci	{					\
178c2ecf20Sopenharmony_ci		return x;			\
188c2ecf20Sopenharmony_ci	}
198c2ecf20Sopenharmony_ciTAIL_FUNC(0)
208c2ecf20Sopenharmony_ciTAIL_FUNC(1)
218c2ecf20Sopenharmony_ciTAIL_FUNC(2)
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ciSEC("classifier")
248c2ecf20Sopenharmony_ciint entry(struct __sk_buff *skb)
258c2ecf20Sopenharmony_ci{
268c2ecf20Sopenharmony_ci	/* Multiple locations to make sure we patch
278c2ecf20Sopenharmony_ci	 * all of them.
288c2ecf20Sopenharmony_ci	 */
298c2ecf20Sopenharmony_ci	bpf_tail_call_static(skb, &jmp_table, 0);
308c2ecf20Sopenharmony_ci	bpf_tail_call_static(skb, &jmp_table, 0);
318c2ecf20Sopenharmony_ci	bpf_tail_call_static(skb, &jmp_table, 0);
328c2ecf20Sopenharmony_ci	bpf_tail_call_static(skb, &jmp_table, 0);
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci	bpf_tail_call_static(skb, &jmp_table, 1);
358c2ecf20Sopenharmony_ci	bpf_tail_call_static(skb, &jmp_table, 1);
368c2ecf20Sopenharmony_ci	bpf_tail_call_static(skb, &jmp_table, 1);
378c2ecf20Sopenharmony_ci	bpf_tail_call_static(skb, &jmp_table, 1);
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci	bpf_tail_call_static(skb, &jmp_table, 2);
408c2ecf20Sopenharmony_ci	bpf_tail_call_static(skb, &jmp_table, 2);
418c2ecf20Sopenharmony_ci	bpf_tail_call_static(skb, &jmp_table, 2);
428c2ecf20Sopenharmony_ci	bpf_tail_call_static(skb, &jmp_table, 2);
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci	return 3;
458c2ecf20Sopenharmony_ci}
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_cichar __license[] SEC("license") = "GPL";
488c2ecf20Sopenharmony_ciint _version SEC("version") = 1;
49