diff options
| author | Jordan Rife <[email protected]> | 2024-05-10 19:02:26 +0000 |
|---|---|---|
| committer | Alexei Starovoitov <[email protected]> | 2024-05-13 00:10:41 +0000 |
| commit | 8eaf8056a44b28a7b198aa699e35854bbec2c452 (patch) | |
| tree | bfaf6231145318930d61fed08e34f4e6fabfb1e2 /tools/testing/selftests/bpf/progs/sendmsg6_prog.c | |
| parent | selftests/bpf: Migrate sendmsg6 v4 mapped address tests (diff) | |
| download | kernel-8eaf8056a44b28a7b198aa699e35854bbec2c452.tar.gz kernel-8eaf8056a44b28a7b198aa699e35854bbec2c452.zip | |
selftests/bpf: Migrate wildcard destination rewrite test
Migrate test case from bpf/test_sock_addr.c ensuring that sendmsg
respects when sendmsg6 hooks rewrite the destination IP with the IPv6
wildcard IP, [::].
Signed-off-by: Jordan Rife <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Alexei Starovoitov <[email protected]>
Diffstat (limited to 'tools/testing/selftests/bpf/progs/sendmsg6_prog.c')
| -rw-r--r-- | tools/testing/selftests/bpf/progs/sendmsg6_prog.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/tools/testing/selftests/bpf/progs/sendmsg6_prog.c b/tools/testing/selftests/bpf/progs/sendmsg6_prog.c index 7611d9e17dd1..36a7f960799f 100644 --- a/tools/testing/selftests/bpf/progs/sendmsg6_prog.c +++ b/tools/testing/selftests/bpf/progs/sendmsg6_prog.c @@ -85,6 +85,26 @@ int sendmsg_v6_v4mapped_prog(struct bpf_sock_addr *ctx) } SEC("cgroup/sendmsg6") +int sendmsg_v6_wildcard_prog(struct bpf_sock_addr *ctx) +{ + /* Rewrite source. */ + ctx->msg_src_ip6[0] = bpf_htonl(SRC_REWRITE_IP6_0); + ctx->msg_src_ip6[1] = bpf_htonl(SRC_REWRITE_IP6_1); + ctx->msg_src_ip6[2] = bpf_htonl(SRC_REWRITE_IP6_2); + ctx->msg_src_ip6[3] = bpf_htonl(SRC_REWRITE_IP6_3); + + /* Rewrite destination. */ + ctx->user_ip6[0] = bpf_htonl(0); + ctx->user_ip6[1] = bpf_htonl(0); + ctx->user_ip6[2] = bpf_htonl(0); + ctx->user_ip6[3] = bpf_htonl(0); + + ctx->user_port = bpf_htons(DST_REWRITE_PORT6); + + return 1; +} + +SEC("cgroup/sendmsg6") int sendmsg_v6_preserve_dst_prog(struct bpf_sock_addr *ctx) { return 1; |
