1
2#include <linux/bpf.h>
3#include <bpf/bpf_helpers.h>
4#include "bpf_legacy.h"
5
6struct {
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
14int 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
26static __noinline
27int 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
36SEC("classifier/0")
37int bpf_func_0(struct __sk_buff *skb)
38{
39 volatile char arr[128] = {};
40
41 return subprog_tail2(skb);
42}
43
44SEC("classifier/1")
45int bpf_func_1(struct __sk_buff *skb)
46{
47 volatile char arr[128] = {};
48
49 return skb->len * 3;
50}
51
52SEC("classifier")
53int entry(struct __sk_buff *skb)
54{
55 volatile char arr[128] = {};
56
57 return subprog_tail(skb);
58}
59
60char __license[] SEC("license") = "GPL";
61int _version SEC("version") = 1;
62