Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 #include <linux/bpf.h>
0003 #include <bpf/bpf_helpers.h>
0004 #include "bpf_legacy.h"
0005 
0006 struct {
0007     __uint(type, BPF_MAP_TYPE_PROG_ARRAY);
0008     __uint(max_entries, 1);
0009     __uint(key_size, sizeof(__u32));
0010     __uint(value_size, sizeof(__u32));
0011 } jmp_table SEC(".maps");
0012 
0013 static __noinline
0014 int subprog_tail(struct __sk_buff *skb)
0015 {
0016     if (load_byte(skb, 0))
0017         bpf_tail_call_static(skb, &jmp_table, 1);
0018     else
0019         bpf_tail_call_static(skb, &jmp_table, 0);
0020     return 1;
0021 }
0022 
0023 int count = 0;
0024 
0025 SEC("tc")
0026 int classifier_0(struct __sk_buff *skb)
0027 {
0028     count++;
0029     return subprog_tail(skb);
0030 }
0031 
0032 SEC("tc")
0033 int entry(struct __sk_buff *skb)
0034 {
0035     bpf_tail_call_static(skb, &jmp_table, 0);
0036 
0037     return 0;
0038 }
0039 
0040 char __license[] SEC("license") = "GPL";