selftests/bpf: Test [::] -> [::1] rewrite in sys_sendmsg in test_sock_addr
authorAndrey Ignatov <rdna@fb.com>
Fri, 4 Jan 2019 09:07:08 +0000 (01:07 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 27 Feb 2019 09:08:52 +0000 (10:08 +0100)
commitfc396828a4e6432eed50312a7bd381b1daf8a3d8
tree3d72dc3d0340fe43153cd1d56d6c8bef13df6658
parent8b0d641e6152fabf740b39f5765a0185e941c281
selftests/bpf: Test [::] -> [::1] rewrite in sys_sendmsg in test_sock_addr

[ Upstream commit 976b4f3a4646fbf0d189caca25f91f82e4be4b5a ]

Test that sys_sendmsg BPF hook doesn't break sys_sendmsg behaviour to
rewrite destination IPv6 = [::] with [::1] (BSD'ism).

Two test cases are added:

1) User passes dst IPv6 = [::] and BPF_CGROUP_UDP6_SENDMSG program
   doesn't touch it.

2) User passes dst IPv6 != [::], but BPF_CGROUP_UDP6_SENDMSG program
   rewrites it with [::].

In both cases [::1] is used by sys_sendmsg code eventually and datagram
is sent successfully for unconnected UDP socket.

Example of relevant output:
  Test case: sendmsg6: set dst IP = [::] (BSD'ism) .. [PASS]
  Test case: sendmsg6: preserve dst IP = [::] (BSD'ism) .. [PASS]

Signed-off-by: Andrey Ignatov <rdna@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
tools/testing/selftests/bpf/test_sock_addr.c