1 // SPDX-License-Identifier: GPL-2.0 2 #include <linux/bpf.h> 3 #include <bpf/bpf_helpers.h> 4 #include "bpf_legacy.h" 5 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"); 12 13 __noinline 14 int subprog_tail2(struct __sk_buff *skb) 15 { 16 volatile char arr[64] = {}; 17 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); 22 23 return skb->len; 24 } 25 26 static __noinline 27 int subprog_tail(struct __sk_buff *skb) 28 { 29 volatile char arr[64] = {}; 30 31 bpf_tail_call_static(skb, &jmp_table, 0); 32 33 return skb->len * 2; 34 } 35 36 SEC("classifier/0") 37 int bpf_func_0(struct __sk_buff *skb) 38 { 39 volatile char arr[128] = {}; 40 41 return subprog_tail2(skb); 42 } 43 44 SEC("classifier/1") 45 int bpf_func_1(struct __sk_buff *skb) 46 { 47 volatile char arr[128] = {}; 48 49 return skb->len * 3; 50 } 51 52 SEC("classifier") 53 int entry(struct __sk_buff *skb) 54 { 55 volatile char arr[128] = {}; 56 57 return subprog_tail(skb); 58 } 59 60 char __license[] SEC("license") = "GPL"; 61 int _version SEC("version") = 1; 62