Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /* Copyright (c) 2020 Facebook */
0003 #include <stddef.h>
0004 #include <linux/bpf.h>
0005 #include <bpf/bpf_helpers.h>
0006 
0007 #ifndef MAX_STACK
0008 #define MAX_STACK (512 - 3 * 32 + 8)
0009 #endif
0010 
0011 static __attribute__ ((noinline))
0012 int f0(int var, struct __sk_buff *skb)
0013 {
0014     return skb->len;
0015 }
0016 
0017 __attribute__ ((noinline))
0018 int f1(struct __sk_buff *skb)
0019 {
0020     volatile char buf[MAX_STACK] = {};
0021 
0022     return f0(0, skb) + skb->len;
0023 }
0024 
0025 int f3(int, struct __sk_buff *skb, int);
0026 
0027 __attribute__ ((noinline))
0028 int f2(int val, struct __sk_buff *skb)
0029 {
0030     return f1(skb) + f3(val, skb, 1);
0031 }
0032 
0033 __attribute__ ((noinline))
0034 int f3(int val, struct __sk_buff *skb, int var)
0035 {
0036     volatile char buf[MAX_STACK] = {};
0037 
0038     return skb->ifindex * val * var;
0039 }
0040 
0041 SEC("tc")
0042 int test_cls(struct __sk_buff *skb)
0043 {
0044     return f0(1, skb) + f1(skb) + f2(2, skb) + f3(3, skb, 4);
0045 }