1 // SPDX-License-Identifier: GPL-2.0
2 #include <netinet/in.h>
4 #include <bpf/bpf_helpers.h>
6 char _license
[] SEC("license") = "GPL";
7 __u32 _version
SEC("version") = 1;
9 SEC("cgroup/getsockopt/child")
10 int _getsockopt_child(struct bpf_sockopt
*ctx
)
12 __u8
*optval_end
= ctx
->optval_end
;
13 __u8
*optval
= ctx
->optval
;
15 if (ctx
->level
!= SOL_IP
|| ctx
->optname
!= IP_TOS
)
18 if (optval
+ 1 > optval_end
)
19 return 0; /* EPERM, bounds check */
21 if (optval
[0] != 0x80)
22 return 0; /* EPERM, unexpected optval from the kernel */
24 ctx
->retval
= 0; /* Reset system call return value to zero */
32 SEC("cgroup/getsockopt/parent")
33 int _getsockopt_parent(struct bpf_sockopt
*ctx
)
35 __u8
*optval_end
= ctx
->optval_end
;
36 __u8
*optval
= ctx
->optval
;
38 if (ctx
->level
!= SOL_IP
|| ctx
->optname
!= IP_TOS
)
41 if (optval
+ 1 > optval_end
)
42 return 0; /* EPERM, bounds check */
44 if (optval
[0] != 0x90)
45 return 0; /* EPERM, unexpected optval from the kernel */
47 ctx
->retval
= 0; /* Reset system call return value to zero */
55 SEC("cgroup/setsockopt")
56 int _setsockopt(struct bpf_sockopt
*ctx
)
58 __u8
*optval_end
= ctx
->optval_end
;
59 __u8
*optval
= ctx
->optval
;
61 if (ctx
->level
!= SOL_IP
|| ctx
->optname
!= IP_TOS
)
64 if (optval
+ 1 > optval_end
)
65 return 0; /* EPERM, bounds check */