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, 2); 88c2ecf20Sopenharmony_ci __uint(key_size, sizeof(__u32)); 98c2ecf20Sopenharmony_ci __uint(value_size, sizeof(__u32)); 108c2ecf20Sopenharmony_ci} jmp_table SEC(".maps"); 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci#define TAIL_FUNC(x) \ 138c2ecf20Sopenharmony_ci SEC("classifier/" #x) \ 148c2ecf20Sopenharmony_ci int bpf_func_##x(struct __sk_buff *skb) \ 158c2ecf20Sopenharmony_ci { \ 168c2ecf20Sopenharmony_ci return x; \ 178c2ecf20Sopenharmony_ci } 188c2ecf20Sopenharmony_ciTAIL_FUNC(0) 198c2ecf20Sopenharmony_ciTAIL_FUNC(1) 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_cistatic __noinline 228c2ecf20Sopenharmony_ciint subprog_tail(struct __sk_buff *skb) 238c2ecf20Sopenharmony_ci{ 248c2ecf20Sopenharmony_ci bpf_tail_call_static(skb, &jmp_table, 0); 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_ci return skb->len * 2; 278c2ecf20Sopenharmony_ci} 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_ciSEC("classifier") 308c2ecf20Sopenharmony_ciint entry(struct __sk_buff *skb) 318c2ecf20Sopenharmony_ci{ 328c2ecf20Sopenharmony_ci bpf_tail_call_static(skb, &jmp_table, 1); 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_ci return subprog_tail(skb); 358c2ecf20Sopenharmony_ci} 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_cichar __license[] SEC("license") = "GPL"; 388c2ecf20Sopenharmony_ciint _version SEC("version") = 1; 39