diff mbox series

[bpf-next,v5,4/6] selftests/bpf: Drop noconnect from network_helper_opts

Message ID 03185ae444b4fc91a3729df1f6f274ae5273aa67.1718765123.git.tanggeliang@kylinos.cn
State New
Headers show
Series use network helpers, part 7 | expand

Commit Message

Geliang Tang June 19, 2024, 2:51 a.m. UTC
From: Geliang Tang <tanggeliang@kylinos.cn>

In test_bpf_ip_check_defrag_ok(), the new helper client_socket() can be
used to replace connect_to_fd_opts() with "noconnect" opts, and the strcut
member "noconnect" of network_helper_opts can be dropped now, always
connect to server in connect_to_fd_opts().

Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
 tools/testing/selftests/bpf/network_helpers.c            | 5 ++---
 tools/testing/selftests/bpf/network_helpers.h            | 1 -
 tools/testing/selftests/bpf/prog_tests/ip_check_defrag.c | 9 ++++-----
 3 files changed, 6 insertions(+), 9 deletions(-)

Comments

Eduard Zingerman June 20, 2024, 10:51 p.m. UTC | #1
On Wed, 2024-06-19 at 10:51 +0800, Geliang Tang wrote:

Oops, sorry, missed two places that should be changed.
Please keep my ack if you respin.

[...]

> diff --git a/tools/testing/selftests/bpf/prog_tests/ip_check_defrag.c b/tools/testing/selftests/bpf/prog_tests/ip_check_defrag.c
> index 1607a05bf2c2..e73da3de5bf6 100644
> --- a/tools/testing/selftests/bpf/prog_tests/ip_check_defrag.c
> +++ b/tools/testing/selftests/bpf/prog_tests/ip_check_defrag.c

[...]

> @@ -200,7 +199,7 @@ void test_bpf_ip_check_defrag_ok(bool ipv6)
>  	nstoken = open_netns(NS0);
>  	if (!ASSERT_OK_PTR(nstoken, "setns ns0"))
>  		goto out;
> -	client_tx_fd = connect_to_fd_opts(srv_fd, SOCK_RAW, &tx_ops);
> +	client_tx_fd = client_socket(family, SOCK_RAW, &tx_ops);
>  	close_netns(nstoken);
>  	if (!ASSERT_GE(client_tx_fd, 0, "connect_to_fd_opts"))

The ASSERT string should be changed.

>  		goto out;
> @@ -209,7 +208,7 @@ void test_bpf_ip_check_defrag_ok(bool ipv6)
>  	nstoken = open_netns(NS0);
>  	if (!ASSERT_OK_PTR(nstoken, "setns ns0"))
>  		goto out;
> -	client_rx_fd = connect_to_fd_opts(srv_fd, SOCK_DGRAM, &rx_opts);
> +	client_rx_fd = client_socket(family, SOCK_DGRAM, &rx_opts);
>  	close_netns(nstoken);
>  	if (!ASSERT_GE(client_rx_fd, 0, "connect_to_fd_opts"))

The ASSERT string should be changed.

>  		goto out;
diff mbox series

Patch

diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c
index 5f8214e2880d..44c2c8fa542a 100644
--- a/tools/testing/selftests/bpf/network_helpers.c
+++ b/tools/testing/selftests/bpf/network_helpers.c
@@ -318,9 +318,8 @@  int connect_to_addr(int type, const struct sockaddr_storage *addr, socklen_t add
 		return -1;
 	}
 
-	if (!opts->noconnect)
-		if (connect_fd_to_addr(fd, addr, addrlen, opts->must_fail))
-			goto error_close;
+	if (connect_fd_to_addr(fd, addr, addrlen, opts->must_fail))
+		goto error_close;
 
 	return fd;
 
diff --git a/tools/testing/selftests/bpf/network_helpers.h b/tools/testing/selftests/bpf/network_helpers.h
index e89eadfb02d6..9ea36524b9db 100644
--- a/tools/testing/selftests/bpf/network_helpers.h
+++ b/tools/testing/selftests/bpf/network_helpers.h
@@ -24,7 +24,6 @@  typedef __u16 __sum16;
 struct network_helper_opts {
 	int timeout_ms;
 	bool must_fail;
-	bool noconnect;
 	int proto;
 	int (*post_socket_cb)(int fd, void *opts);
 	void *cb_opts;
diff --git a/tools/testing/selftests/bpf/prog_tests/ip_check_defrag.c b/tools/testing/selftests/bpf/prog_tests/ip_check_defrag.c
index 1607a05bf2c2..e73da3de5bf6 100644
--- a/tools/testing/selftests/bpf/prog_tests/ip_check_defrag.c
+++ b/tools/testing/selftests/bpf/prog_tests/ip_check_defrag.c
@@ -158,14 +158,13 @@  static int send_frags6(int client)
 
 void test_bpf_ip_check_defrag_ok(bool ipv6)
 {
+	int family = ipv6 ? AF_INET6 : AF_INET;
 	struct network_helper_opts rx_opts = {
 		.timeout_ms = 1000,
-		.noconnect = true,
 	};
 	struct network_helper_opts tx_ops = {
 		.timeout_ms = 1000,
 		.proto = IPPROTO_RAW,
-		.noconnect = true,
 	};
 	struct sockaddr_storage caddr;
 	struct ip_check_defrag *skel;
@@ -191,7 +190,7 @@  void test_bpf_ip_check_defrag_ok(bool ipv6)
 	nstoken = open_netns(NS1);
 	if (!ASSERT_OK_PTR(nstoken, "setns ns1"))
 		goto out;
-	srv_fd = start_server(ipv6 ? AF_INET6 : AF_INET, SOCK_DGRAM, NULL, SERVER_PORT, 0);
+	srv_fd = start_server(family, SOCK_DGRAM, NULL, SERVER_PORT, 0);
 	close_netns(nstoken);
 	if (!ASSERT_GE(srv_fd, 0, "start_server"))
 		goto out;
@@ -200,7 +199,7 @@  void test_bpf_ip_check_defrag_ok(bool ipv6)
 	nstoken = open_netns(NS0);
 	if (!ASSERT_OK_PTR(nstoken, "setns ns0"))
 		goto out;
-	client_tx_fd = connect_to_fd_opts(srv_fd, SOCK_RAW, &tx_ops);
+	client_tx_fd = client_socket(family, SOCK_RAW, &tx_ops);
 	close_netns(nstoken);
 	if (!ASSERT_GE(client_tx_fd, 0, "connect_to_fd_opts"))
 		goto out;
@@ -209,7 +208,7 @@  void test_bpf_ip_check_defrag_ok(bool ipv6)
 	nstoken = open_netns(NS0);
 	if (!ASSERT_OK_PTR(nstoken, "setns ns0"))
 		goto out;
-	client_rx_fd = connect_to_fd_opts(srv_fd, SOCK_DGRAM, &rx_opts);
+	client_rx_fd = client_socket(family, SOCK_DGRAM, &rx_opts);
 	close_netns(nstoken);
 	if (!ASSERT_GE(client_rx_fd, 0, "connect_to_fd_opts"))
 		goto out;