diff mbox series

[bpf-next,v3,3/8] selftests/bpf: Drop type parameter of connect_to_addr

Message ID 3a0ac6ce2cfd09df244dff1766af57861bc7598c.1716369375.git.tanggeliang@kylinos.cn (mailing list archive)
State Superseded
Delegated to: BPF
Headers show
Series use network helpers, part 5 | expand

Checks

Context Check Description
bpf/vmtest-bpf-next-VM_Test-43 success Logs for x86_64-llvm-18 / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-44 success Logs for x86_64-llvm-18 / test (test_verifier, false, 360) / test_verifier on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-45 success Logs for x86_64-llvm-18 / veristat
bpf/vmtest-bpf-next-PR success PR summary
bpf/vmtest-bpf-next-VM_Test-5 success Logs for aarch64-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-1 success Logs for ShellCheck
bpf/vmtest-bpf-next-VM_Test-0 success Logs for Lint
bpf/vmtest-bpf-next-VM_Test-2 success Logs for Unittests
bpf/vmtest-bpf-next-VM_Test-3 success Logs for Validate matrix.py
bpf/vmtest-bpf-next-VM_Test-9 success Logs for aarch64-gcc / test (test_verifier, false, 360) / test_verifier on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-11 success Logs for s390x-gcc / build / build for s390x with gcc
bpf/vmtest-bpf-next-VM_Test-10 success Logs for aarch64-gcc / veristat
bpf/vmtest-bpf-next-VM_Test-4 success Logs for aarch64-gcc / build / build for aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-12 success Logs for s390x-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-17 success Logs for s390x-gcc / veristat
bpf/vmtest-bpf-next-VM_Test-18 success Logs for set-matrix
bpf/vmtest-bpf-next-VM_Test-19 success Logs for x86_64-gcc / build / build for x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-20 success Logs for x86_64-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-28 success Logs for x86_64-llvm-17 / build / build for x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-29 success Logs for x86_64-llvm-17 / build-release / build for x86_64 with llvm-17 and -O2 optimization
bpf/vmtest-bpf-next-VM_Test-34 success Logs for x86_64-llvm-17 / veristat
bpf/vmtest-bpf-next-VM_Test-35 success Logs for x86_64-llvm-18 / build / build for x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-36 success Logs for x86_64-llvm-18 / build-release / build for x86_64 with llvm-18 and -O2 optimization
bpf/vmtest-bpf-next-VM_Test-42 success Logs for x86_64-llvm-18 / veristat
bpf/vmtest-bpf-next-VM_Test-7 success Logs for aarch64-gcc / test (test_progs, false, 360) / test_progs on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-6 success Logs for aarch64-gcc / test (test_maps, false, 360) / test_maps on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-8 success Logs for aarch64-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-13 success Logs for s390x-gcc / test (test_maps, false, 360) / test_maps on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-14 success Logs for s390x-gcc / test (test_progs, false, 360) / test_progs on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-15 success Logs for s390x-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-16 success Logs for s390x-gcc / test (test_verifier, false, 360) / test_verifier on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-21 success Logs for x86_64-gcc / test (test_maps, false, 360) / test_maps on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-22 success Logs for x86_64-gcc / test (test_progs, false, 360) / test_progs on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-23 success Logs for x86_64-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-24 success Logs for x86_64-gcc / test (test_progs_no_alu32_parallel, true, 30) / test_progs_no_alu32_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-25 success Logs for x86_64-gcc / test (test_progs_parallel, true, 30) / test_progs_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-26 success Logs for x86_64-gcc / test (test_verifier, false, 360) / test_verifier on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-27 success Logs for x86_64-gcc / veristat / veristat on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-30 success Logs for x86_64-llvm-17 / test (test_maps, false, 360) / test_maps on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-31 success Logs for x86_64-llvm-17 / test (test_progs, false, 360) / test_progs on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-32 success Logs for x86_64-llvm-17 / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-33 success Logs for x86_64-llvm-17 / test (test_verifier, false, 360) / test_verifier on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-37 success Logs for x86_64-llvm-18 / test (test_maps, false, 360) / test_maps on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-38 success Logs for x86_64-llvm-18 / test (test_progs, false, 360) / test_progs on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-39 success Logs for x86_64-llvm-18 / test (test_progs_cpuv4, false, 360) / test_progs_cpuv4 on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-40 success Logs for x86_64-llvm-18 / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-41 success Logs for x86_64-llvm-18 / test (test_verifier, false, 360) / test_verifier on x86_64 with llvm-18
netdev/tree_selection success Clearly marked for bpf-next
netdev/apply fail Patch does not apply to bpf-next-0

Commit Message

Geliang Tang May 22, 2024, 9:23 a.m. UTC
From: Geliang Tang <tanggeliang@kylinos.cn>

Since "type" is a struct member of network_helper_opts, it makes sense
to drop the "type" parameter of connect_to_addr() helper, using opts->type
instead in this helper.

If no network_helper_opts is set, use SOCK_STREAM as default socket type.

Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
 tools/testing/selftests/bpf/network_helpers.c |  4 ++--
 tools/testing/selftests/bpf/network_helpers.h |  2 +-
 .../selftests/bpf/prog_tests/cls_redirect.c   |  2 +-
 .../selftests/bpf/prog_tests/sk_assign.c      |  5 +++-
 .../selftests/bpf/prog_tests/sock_addr.c      | 23 ++++++++++++-------
 5 files changed, 23 insertions(+), 13 deletions(-)
diff mbox series

Patch

diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c
index 129ac90e4528..49e807ffcccb 100644
--- a/tools/testing/selftests/bpf/network_helpers.c
+++ b/tools/testing/selftests/bpf/network_helpers.c
@@ -268,7 +268,7 @@  static int connect_fd_to_addr(int fd,
 	return 0;
 }
 
-int connect_to_addr(int type, const struct sockaddr_storage *addr, socklen_t addrlen,
+int connect_to_addr(const struct sockaddr_storage *addr, socklen_t addrlen,
 		    const struct network_helper_opts *opts)
 {
 	int fd;
@@ -276,7 +276,7 @@  int connect_to_addr(int type, const struct sockaddr_storage *addr, socklen_t add
 	if (!opts)
 		opts = &default_opts;
 
-	fd = socket(addr->ss_family, type, opts->proto);
+	fd = socket(addr->ss_family, opts->type ? : SOCK_STREAM, opts->proto);
 	if (fd < 0) {
 		log_err("Failed to create client socket");
 		return -1;
diff --git a/tools/testing/selftests/bpf/network_helpers.h b/tools/testing/selftests/bpf/network_helpers.h
index 9de84a8d00fd..c925c771bd98 100644
--- a/tools/testing/selftests/bpf/network_helpers.h
+++ b/tools/testing/selftests/bpf/network_helpers.h
@@ -56,7 +56,7 @@  int *start_reuseport_server(int family, int type, const char *addr_str,
 int start_server_addr(const struct sockaddr_storage *addr, socklen_t len,
 		      const struct network_helper_opts *opts);
 void free_fds(int *fds, unsigned int nr_close_fds);
-int connect_to_addr(int type, const struct sockaddr_storage *addr, socklen_t len,
+int connect_to_addr(const struct sockaddr_storage *addr, socklen_t len,
 		    const struct network_helper_opts *opts);
 int connect_to_fd(int server_fd, int timeout_ms);
 int connect_to_fd_opts(int server_fd, const struct network_helper_opts *opts);
diff --git a/tools/testing/selftests/bpf/prog_tests/cls_redirect.c b/tools/testing/selftests/bpf/prog_tests/cls_redirect.c
index 53b81651a6fa..1f1b9f0c2ffc 100644
--- a/tools/testing/selftests/bpf/prog_tests/cls_redirect.c
+++ b/tools/testing/selftests/bpf/prog_tests/cls_redirect.c
@@ -76,7 +76,7 @@  static bool set_up_conn(const struct sockaddr *addr, socklen_t len, int type,
 	if (CHECK_FAIL(getsockname(*server, sa, &slen)))
 		goto close_server;
 
-	*conn = connect_to_addr(type, (struct sockaddr_storage *)sa, slen, NULL);
+	*conn = connect_to_addr((struct sockaddr_storage *)sa, slen, &opts);
 	if (*conn < 0)
 		goto close_server;
 
diff --git a/tools/testing/selftests/bpf/prog_tests/sk_assign.c b/tools/testing/selftests/bpf/prog_tests/sk_assign.c
index 517d1186e386..91f65b407f3a 100644
--- a/tools/testing/selftests/bpf/prog_tests/sk_assign.c
+++ b/tools/testing/selftests/bpf/prog_tests/sk_assign.c
@@ -109,12 +109,15 @@  rcv_msg(int srv_client, int type)
 static int
 run_test(int server_fd, const struct sockaddr *addr, socklen_t len, int type)
 {
+	struct network_helper_opts opts = {
+		.type = type,
+	};
 	int client = -1, srv_client = -1;
 	char buf[] = "testing";
 	in_port_t port;
 	int ret = 1;
 
-	client = connect_to_addr(type, (struct sockaddr_storage *)addr, len, NULL);
+	client = connect_to_addr((struct sockaddr_storage *)addr, len, &opts);
 	if (client == -1) {
 		perror("Cannot connect to server");
 		goto out;
diff --git a/tools/testing/selftests/bpf/prog_tests/sock_addr.c b/tools/testing/selftests/bpf/prog_tests/sock_addr.c
index b880c564a204..244686d582cb 100644
--- a/tools/testing/selftests/bpf/prog_tests/sock_addr.c
+++ b/tools/testing/selftests/bpf/prog_tests/sock_addr.c
@@ -224,12 +224,12 @@  static int kernel_getpeername(int fd, struct sockaddr *addr, socklen_t *addrlen)
 	return sock_addr_op("kernel_getpeername", addr, addrlen, true);
 }
 
-int kernel_connect_to_addr(int type, const struct sockaddr_storage *addr, socklen_t addrlen,
+int kernel_connect_to_addr(const struct sockaddr_storage *addr, socklen_t addrlen,
 			   const struct network_helper_opts *opts)
 {
 	int err;
 
-	if (!ASSERT_OK(kernel_init_sock(addr->ss_family, type, 0),
+	if (!ASSERT_OK(kernel_init_sock(addr->ss_family, opts->type, 0),
 		       "kernel_init_sock"))
 		goto err;
 
@@ -278,7 +278,7 @@  int kernel_start_server(int family, int type, const char *addr_str, __u16 port,
 }
 
 struct sock_ops {
-	int (*connect_to_addr)(int type, const struct sockaddr_storage *addr,
+	int (*connect_to_addr)(const struct sockaddr_storage *addr,
 			       socklen_t addrlen,
 			       const struct network_helper_opts *opts);
 	int (*start_server)(int family, int type, const char *addr_str,
@@ -2284,6 +2284,9 @@  static int test_bind(struct sock_addr_test *test)
 {
 	struct sockaddr_storage expected_addr;
 	socklen_t expected_addr_len = sizeof(struct sockaddr_storage);
+	struct network_helper_opts opts = {
+		.type = test->socket_type,
+	};
 	int serv = -1, client = -1, err;
 
 	serv = test->ops->start_server(test->socket_family, test->socket_type,
@@ -2306,7 +2309,7 @@  static int test_bind(struct sock_addr_test *test)
 		goto cleanup;
 
 	/* Try to connect to server just in case */
-	client = connect_to_addr(test->socket_type, &expected_addr, expected_addr_len, NULL);
+	client = connect_to_addr(&expected_addr, expected_addr_len, &opts);
 	if (!ASSERT_GE(client, 0, "connect_to_addr"))
 		goto cleanup;
 
@@ -2327,6 +2330,9 @@  static int test_connect(struct sock_addr_test *test)
 	socklen_t addr_len = sizeof(struct sockaddr_storage),
 		  expected_addr_len = sizeof(struct sockaddr_storage),
 		  expected_src_addr_len = sizeof(struct sockaddr_storage);
+	struct network_helper_opts opts = {
+		.type = test->socket_type,
+	};
 	int serv = -1, client = -1, err;
 
 	serv = start_server(test->socket_family, test->socket_type,
@@ -2339,8 +2345,7 @@  static int test_connect(struct sock_addr_test *test)
 	if (!ASSERT_EQ(err, 0, "make_sockaddr"))
 		goto cleanup;
 
-	client = test->ops->connect_to_addr(test->socket_type, &addr, addr_len,
-					    NULL);
+	client = test->ops->connect_to_addr(&addr, addr_len, &opts);
 	if (client < 0) {
 		err = errno;
 		goto err;
@@ -2519,6 +2524,9 @@  static int test_getpeername(struct sock_addr_test *test)
 	struct sockaddr_storage addr, expected_addr;
 	socklen_t addr_len = sizeof(struct sockaddr_storage),
 		  expected_addr_len = sizeof(struct sockaddr_storage);
+	struct network_helper_opts opts = {
+		.type = test->socket_type,
+	};
 	int serv = -1, client = -1, err;
 
 	serv = start_server(test->socket_family, test->socket_type,
@@ -2531,8 +2539,7 @@  static int test_getpeername(struct sock_addr_test *test)
 	if (!ASSERT_EQ(err, 0, "make_sockaddr"))
 		goto cleanup;
 
-	client = test->ops->connect_to_addr(test->socket_type, &addr, addr_len,
-					    NULL);
+	client = test->ops->connect_to_addr(&addr, addr_len, &opts);
 	if (!ASSERT_GE(client, 0, "connect_to_addr"))
 		goto cleanup;