Extend the socket assign test program to also validate that connections to foreign addresses may also be proxied to a user agent via this mechanism. Signed-off-by: Joe Stringer <joe@xxxxxxxxxxx> --- tools/testing/selftests/bpf/test_sk_assign.c | 13 +++++++++++++ tools/testing/selftests/bpf/test_sk_assign.sh | 3 +++ 2 files changed, 16 insertions(+) diff --git a/tools/testing/selftests/bpf/test_sk_assign.c b/tools/testing/selftests/bpf/test_sk_assign.c index cba5f8b2b7fd..4b7b9bbe7859 100644 --- a/tools/testing/selftests/bpf/test_sk_assign.c +++ b/tools/testing/selftests/bpf/test_sk_assign.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 // Copyright (c) 2018 Facebook // Copyright (c) 2019 Cloudflare +// Copyright (c) 2020 Isovalent. Inc. #include <string.h> #include <stdlib.h> @@ -17,6 +18,8 @@ #include "bpf_rlimit.h" #include "cgroup_helpers.h" +#define TEST_DADDR (0xC0A80203) + static int start_server(const struct sockaddr *addr, socklen_t len) { int fd; @@ -161,6 +164,16 @@ int main(int argc, char **argv) addr4.sin_port = htons(4321); addr6.sin6_port = htons(4321); + if (run_test(server, (const struct sockaddr *)&addr4, sizeof(addr4))) + goto out; + + if (run_test(server_v6, (const struct sockaddr *)&addr6, sizeof(addr6))) + goto out; + + /* Connect to unbound addresses */ + addr4.sin_addr.s_addr = htonl(TEST_DADDR); + addr6.sin6_addr.s6_addr32[3] = htonl(TEST_DADDR); + if (run_test(server, (const struct sockaddr *)&addr4, sizeof(addr4))) goto out; diff --git a/tools/testing/selftests/bpf/test_sk_assign.sh b/tools/testing/selftests/bpf/test_sk_assign.sh index 62eae9255491..de1df4e438de 100755 --- a/tools/testing/selftests/bpf/test_sk_assign.sh +++ b/tools/testing/selftests/bpf/test_sk_assign.sh @@ -12,6 +12,9 @@ if [[ -z $(ip netns identify $$) ]]; then exec ../net/in_netns.sh "$0" "$@" fi +ip route add local default dev lo +ip -6 route add local default dev lo + tc qdisc add dev lo clsact tc filter add dev lo ingress bpf direct-action object-file ./test_sk_assign.o \ section "sk_assign_test" -- 2.20.1