1*6007b23cSBjörn Töpel #define BPF_SOCK_ADDR_STORE(field, off, res, err, flgs) \ 28b45063cSStanislav Fomichev { \ 38b45063cSStanislav Fomichev "wide store to bpf_sock_addr." #field "[" #off "]", \ 48b45063cSStanislav Fomichev .insns = { \ 58b45063cSStanislav Fomichev BPF_MOV64_IMM(BPF_REG_0, 1), \ 68b45063cSStanislav Fomichev BPF_STX_MEM(BPF_DW, BPF_REG_1, BPF_REG_0, \ 78b45063cSStanislav Fomichev offsetof(struct bpf_sock_addr, field[off])), \ 88b45063cSStanislav Fomichev BPF_EXIT_INSN(), \ 98b45063cSStanislav Fomichev }, \ 108b45063cSStanislav Fomichev .result = res, \ 118b45063cSStanislav Fomichev .prog_type = BPF_PROG_TYPE_CGROUP_SOCK_ADDR, \ 128b45063cSStanislav Fomichev .expected_attach_type = BPF_CGROUP_UDP6_SENDMSG, \ 138b45063cSStanislav Fomichev .errstr = err, \ 14*6007b23cSBjörn Töpel .flags = flgs, \ 158b45063cSStanislav Fomichev } 168b45063cSStanislav Fomichev 178b45063cSStanislav Fomichev /* user_ip6[0] is u64 aligned */ 188b45063cSStanislav Fomichev BPF_SOCK_ADDR_STORE(user_ip6, 0, ACCEPT, 19*6007b23cSBjörn Töpel NULL, 0), 208b45063cSStanislav Fomichev BPF_SOCK_ADDR_STORE(user_ip6, 1, REJECT, 21*6007b23cSBjörn Töpel "invalid bpf_context access off=12 size=8", 22*6007b23cSBjörn Töpel F_NEEDS_EFFICIENT_UNALIGNED_ACCESS), 238b45063cSStanislav Fomichev BPF_SOCK_ADDR_STORE(user_ip6, 2, ACCEPT, 24*6007b23cSBjörn Töpel NULL, 0), 258b45063cSStanislav Fomichev BPF_SOCK_ADDR_STORE(user_ip6, 3, REJECT, 26*6007b23cSBjörn Töpel "invalid bpf_context access off=20 size=8", 27*6007b23cSBjörn Töpel F_NEEDS_EFFICIENT_UNALIGNED_ACCESS), 288b45063cSStanislav Fomichev 298b45063cSStanislav Fomichev /* msg_src_ip6[0] is _not_ u64 aligned */ 308b45063cSStanislav Fomichev BPF_SOCK_ADDR_STORE(msg_src_ip6, 0, REJECT, 31*6007b23cSBjörn Töpel "invalid bpf_context access off=44 size=8", 32*6007b23cSBjörn Töpel F_NEEDS_EFFICIENT_UNALIGNED_ACCESS), 338b45063cSStanislav Fomichev BPF_SOCK_ADDR_STORE(msg_src_ip6, 1, ACCEPT, 34*6007b23cSBjörn Töpel NULL, 0), 358b45063cSStanislav Fomichev BPF_SOCK_ADDR_STORE(msg_src_ip6, 2, REJECT, 36*6007b23cSBjörn Töpel "invalid bpf_context access off=52 size=8", 37*6007b23cSBjörn Töpel F_NEEDS_EFFICIENT_UNALIGNED_ACCESS), 388b45063cSStanislav Fomichev BPF_SOCK_ADDR_STORE(msg_src_ip6, 3, REJECT, 39*6007b23cSBjörn Töpel "invalid bpf_context access off=56 size=8", 0), 408b45063cSStanislav Fomichev 418b45063cSStanislav Fomichev #undef BPF_SOCK_ADDR_STORE 427dd8d611SStanislav Fomichev 43*6007b23cSBjörn Töpel #define BPF_SOCK_ADDR_LOAD(field, off, res, err, flgs) \ 447dd8d611SStanislav Fomichev { \ 457dd8d611SStanislav Fomichev "wide load from bpf_sock_addr." #field "[" #off "]", \ 467dd8d611SStanislav Fomichev .insns = { \ 477dd8d611SStanislav Fomichev BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1, \ 487dd8d611SStanislav Fomichev offsetof(struct bpf_sock_addr, field[off])), \ 497dd8d611SStanislav Fomichev BPF_MOV64_IMM(BPF_REG_0, 1), \ 507dd8d611SStanislav Fomichev BPF_EXIT_INSN(), \ 517dd8d611SStanislav Fomichev }, \ 527dd8d611SStanislav Fomichev .result = res, \ 537dd8d611SStanislav Fomichev .prog_type = BPF_PROG_TYPE_CGROUP_SOCK_ADDR, \ 547dd8d611SStanislav Fomichev .expected_attach_type = BPF_CGROUP_UDP6_SENDMSG, \ 557dd8d611SStanislav Fomichev .errstr = err, \ 56*6007b23cSBjörn Töpel .flags = flgs, \ 577dd8d611SStanislav Fomichev } 587dd8d611SStanislav Fomichev 597dd8d611SStanislav Fomichev /* user_ip6[0] is u64 aligned */ 607dd8d611SStanislav Fomichev BPF_SOCK_ADDR_LOAD(user_ip6, 0, ACCEPT, 61*6007b23cSBjörn Töpel NULL, 0), 627dd8d611SStanislav Fomichev BPF_SOCK_ADDR_LOAD(user_ip6, 1, REJECT, 63*6007b23cSBjörn Töpel "invalid bpf_context access off=12 size=8", 64*6007b23cSBjörn Töpel F_NEEDS_EFFICIENT_UNALIGNED_ACCESS), 657dd8d611SStanislav Fomichev BPF_SOCK_ADDR_LOAD(user_ip6, 2, ACCEPT, 66*6007b23cSBjörn Töpel NULL, 0), 677dd8d611SStanislav Fomichev BPF_SOCK_ADDR_LOAD(user_ip6, 3, REJECT, 68*6007b23cSBjörn Töpel "invalid bpf_context access off=20 size=8", 69*6007b23cSBjörn Töpel F_NEEDS_EFFICIENT_UNALIGNED_ACCESS), 707dd8d611SStanislav Fomichev 717dd8d611SStanislav Fomichev /* msg_src_ip6[0] is _not_ u64 aligned */ 727dd8d611SStanislav Fomichev BPF_SOCK_ADDR_LOAD(msg_src_ip6, 0, REJECT, 73*6007b23cSBjörn Töpel "invalid bpf_context access off=44 size=8", 74*6007b23cSBjörn Töpel F_NEEDS_EFFICIENT_UNALIGNED_ACCESS), 757dd8d611SStanislav Fomichev BPF_SOCK_ADDR_LOAD(msg_src_ip6, 1, ACCEPT, 76*6007b23cSBjörn Töpel NULL, 0), 777dd8d611SStanislav Fomichev BPF_SOCK_ADDR_LOAD(msg_src_ip6, 2, REJECT, 78*6007b23cSBjörn Töpel "invalid bpf_context access off=52 size=8", 79*6007b23cSBjörn Töpel F_NEEDS_EFFICIENT_UNALIGNED_ACCESS), 807dd8d611SStanislav Fomichev BPF_SOCK_ADDR_LOAD(msg_src_ip6, 3, REJECT, 81*6007b23cSBjörn Töpel "invalid bpf_context access off=56 size=8", 0), 827dd8d611SStanislav Fomichev 837dd8d611SStanislav Fomichev #undef BPF_SOCK_ADDR_LOAD 84