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, 1);
9 __uint(key_size, sizeof(__u32));
10 __uint(value_size, sizeof(__u32));
11 } jmp_table SEC(".maps");
12
13 static __noinline
subprog_tail(struct __sk_buff * skb)14 int subprog_tail(struct __sk_buff *skb)
15 {
16 if (load_byte(skb, 0))
17 bpf_tail_call_static(skb, &jmp_table, 1);
18 else
19 bpf_tail_call_static(skb, &jmp_table, 0);
20 return 1;
21 }
22
23 int count = 0;
24
25 SEC("tc")
classifier_0(struct __sk_buff * skb)26 int classifier_0(struct __sk_buff *skb)
27 {
28 count++;
29 return subprog_tail(skb);
30 }
31
32 SEC("tc")
entry(struct __sk_buff * skb)33 int entry(struct __sk_buff *skb)
34 {
35 bpf_tail_call_static(skb, &jmp_table, 0);
36
37 return 0;
38 }
39
40 char __license[] SEC("license") = "GPL";
41