2020-11-18 08:16:40 +01:00
# define BPF_SOCK_ADDR_STORE(field, off, res, err, flgs) \
2019-07-15 09:39:54 -07:00
{ \
" wide store to bpf_sock_addr. " # field " [ " # off " ] " , \
. insns = { \
BPF_MOV64_IMM ( BPF_REG_0 , 1 ) , \
BPF_STX_MEM ( BPF_DW , BPF_REG_1 , BPF_REG_0 , \
offsetof ( struct bpf_sock_addr , field [ off ] ) ) , \
BPF_EXIT_INSN ( ) , \
} , \
. result = res , \
. prog_type = BPF_PROG_TYPE_CGROUP_SOCK_ADDR , \
. expected_attach_type = BPF_CGROUP_UDP6_SENDMSG , \
. errstr = err , \
2020-11-18 08:16:40 +01:00
. flags = flgs , \
2019-07-15 09:39:54 -07:00
}
/* user_ip6[0] is u64 aligned */
BPF_SOCK_ADDR_STORE ( user_ip6 , 0 , ACCEPT ,
2020-11-18 08:16:40 +01:00
NULL , 0 ) ,
2019-07-15 09:39:54 -07:00
BPF_SOCK_ADDR_STORE ( user_ip6 , 1 , REJECT ,
2020-11-18 08:16:40 +01:00
" invalid bpf_context access off=12 size=8 " ,
F_NEEDS_EFFICIENT_UNALIGNED_ACCESS ) ,
2019-07-15 09:39:54 -07:00
BPF_SOCK_ADDR_STORE ( user_ip6 , 2 , ACCEPT ,
2020-11-18 08:16:40 +01:00
NULL , 0 ) ,
2019-07-15 09:39:54 -07:00
BPF_SOCK_ADDR_STORE ( user_ip6 , 3 , REJECT ,
2020-11-18 08:16:40 +01:00
" invalid bpf_context access off=20 size=8 " ,
F_NEEDS_EFFICIENT_UNALIGNED_ACCESS ) ,
2019-07-15 09:39:54 -07:00
/* msg_src_ip6[0] is _not_ u64 aligned */
BPF_SOCK_ADDR_STORE ( msg_src_ip6 , 0 , REJECT ,
2020-11-18 08:16:40 +01:00
" invalid bpf_context access off=44 size=8 " ,
F_NEEDS_EFFICIENT_UNALIGNED_ACCESS ) ,
2019-07-15 09:39:54 -07:00
BPF_SOCK_ADDR_STORE ( msg_src_ip6 , 1 , ACCEPT ,
2020-11-18 08:16:40 +01:00
NULL , 0 ) ,
2019-07-15 09:39:54 -07:00
BPF_SOCK_ADDR_STORE ( msg_src_ip6 , 2 , REJECT ,
2020-11-18 08:16:40 +01:00
" invalid bpf_context access off=52 size=8 " ,
F_NEEDS_EFFICIENT_UNALIGNED_ACCESS ) ,
2019-07-15 09:39:54 -07:00
BPF_SOCK_ADDR_STORE ( msg_src_ip6 , 3 , REJECT ,
2020-11-18 08:16:40 +01:00
" invalid bpf_context access off=56 size=8 " , 0 ) ,
2019-07-15 09:39:54 -07:00
# undef BPF_SOCK_ADDR_STORE
2019-07-15 09:39:55 -07:00
2020-11-18 08:16:40 +01:00
# define BPF_SOCK_ADDR_LOAD(field, off, res, err, flgs) \
2019-07-15 09:39:55 -07:00
{ \
" wide load from bpf_sock_addr. " # field " [ " # off " ] " , \
. insns = { \
BPF_LDX_MEM ( BPF_DW , BPF_REG_0 , BPF_REG_1 , \
offsetof ( struct bpf_sock_addr , field [ off ] ) ) , \
BPF_MOV64_IMM ( BPF_REG_0 , 1 ) , \
BPF_EXIT_INSN ( ) , \
} , \
. result = res , \
. prog_type = BPF_PROG_TYPE_CGROUP_SOCK_ADDR , \
. expected_attach_type = BPF_CGROUP_UDP6_SENDMSG , \
. errstr = err , \
2020-11-18 08:16:40 +01:00
. flags = flgs , \
2019-07-15 09:39:55 -07:00
}
/* user_ip6[0] is u64 aligned */
BPF_SOCK_ADDR_LOAD ( user_ip6 , 0 , ACCEPT ,
2020-11-18 08:16:40 +01:00
NULL , 0 ) ,
2019-07-15 09:39:55 -07:00
BPF_SOCK_ADDR_LOAD ( user_ip6 , 1 , REJECT ,
2020-11-18 08:16:40 +01:00
" invalid bpf_context access off=12 size=8 " ,
F_NEEDS_EFFICIENT_UNALIGNED_ACCESS ) ,
2019-07-15 09:39:55 -07:00
BPF_SOCK_ADDR_LOAD ( user_ip6 , 2 , ACCEPT ,
2020-11-18 08:16:40 +01:00
NULL , 0 ) ,
2019-07-15 09:39:55 -07:00
BPF_SOCK_ADDR_LOAD ( user_ip6 , 3 , REJECT ,
2020-11-18 08:16:40 +01:00
" invalid bpf_context access off=20 size=8 " ,
F_NEEDS_EFFICIENT_UNALIGNED_ACCESS ) ,
2019-07-15 09:39:55 -07:00
/* msg_src_ip6[0] is _not_ u64 aligned */
BPF_SOCK_ADDR_LOAD ( msg_src_ip6 , 0 , REJECT ,
2020-11-18 08:16:40 +01:00
" invalid bpf_context access off=44 size=8 " ,
F_NEEDS_EFFICIENT_UNALIGNED_ACCESS ) ,
2019-07-15 09:39:55 -07:00
BPF_SOCK_ADDR_LOAD ( msg_src_ip6 , 1 , ACCEPT ,
2020-11-18 08:16:40 +01:00
NULL , 0 ) ,
2019-07-15 09:39:55 -07:00
BPF_SOCK_ADDR_LOAD ( msg_src_ip6 , 2 , REJECT ,
2020-11-18 08:16:40 +01:00
" invalid bpf_context access off=52 size=8 " ,
F_NEEDS_EFFICIENT_UNALIGNED_ACCESS ) ,
2019-07-15 09:39:55 -07:00
BPF_SOCK_ADDR_LOAD ( msg_src_ip6 , 3 , REJECT ,
2020-11-18 08:16:40 +01:00
" invalid bpf_context access off=56 size=8 " , 0 ) ,
2019-07-15 09:39:55 -07:00
# undef BPF_SOCK_ADDR_LOAD