Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 #include <stddef.h>
0003 #include <linux/bpf.h>
0004 #include <bpf/bpf_helpers.h>
0005 
0006 struct Small {
0007     int x;
0008 };
0009 
0010 struct Big {
0011     int x;
0012     int y;
0013 };
0014 
0015 __noinline int foo(const struct Big *big)
0016 {
0017     if (!big)
0018         return 0;
0019 
0020     return bpf_get_prandom_u32() < big->y;
0021 }
0022 
0023 SEC("cgroup_skb/ingress")
0024 int test_cls(struct __sk_buff *skb)
0025 {
0026     const struct Small small = {.x = skb->len };
0027 
0028     return foo((struct Big *)&small) ? 1 : 0;
0029 }