Skip to contentSkip to conversation

Use start_server and connect_fd_to_fd

PATCH Superseded Geliang Tang 1 participant 3 messages Mar 26, 2024

Subsystems (4)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Geliang Tang

author reviewer
#0 lore raw

v3 cover Use start_server and connect_fd_to_fd

From: Geliang Tang <[email protected]>

v3:
- split v2 as two patches as Daniel suggested.
- The patch "selftests/bpf: Use start_server in bpf_tcp_ca" is merged by Daniel (thanks), but I forgot to drop 'settimeo(lfd, 0)' in it, so I send a squash-to patch to fix this.

Geliang Tang (2):
Squash to "selftests/bpf: Use start_server in bpf_tcp_ca" selftests/bpf: Use connect_fd_to_fd in bpf_tcp_ca

 tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)
Signature · 1 line
2.40.1
author reviewer
#1 lore raw

PATCH v3 1/2 Squash to "selftests/bpf: Use start_server in bpf_tcp_ca"

From: Geliang Tang <[email protected]>

Please add these lines into commit log:

'''
settimeo(lfd, 0) is invoked in start_server() already, drop the duplicate one.
'''

---
 tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c +1 -1
index 94cb22b01482..f44abb990804 100644
@@ -100,7 +100,7 @@ static void do_test(const char *tcp_ca, const struct bpf_map *sk_stg_map)
 	}
 
 	if (settcpca(lfd, tcp_ca) || settcpca(fd, tcp_ca) ||
-	    settimeo(lfd, 0) || settimeo(fd, 0))
+	    settimeo(fd, 0))
 		goto done;
 
 	err = getsockname(lfd, (struct sockaddr *)&sa6, &addrlen);
Signature · 1 line
2.40.1
author reviewer
#2 lore raw

PATCH v3 2/2 selftests/bpf: Use connect_fd_to_fd in bpf_tcp_ca

In reply to Geliang Tang

From: Geliang Tang <[email protected]>

To simplify the code, use BPF selftests helper connect_fd_to_fd() in bpf_tcp_ca.c instead of open-coding it. This helper is defined in network_helpers.c, and exported in network_helpers.h, which is already included in bpf_tcp_ca.c.

settimeo(fd, 0) is invoked in connect_fd_to_fd() already, drop the duplicate one.

---
 tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)
tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c +2 -9
index f44abb990804..3da3030c9365 100644
@@ -78,11 +78,9 @@ static void *server(void *arg)
 
 static void do_test(const char *tcp_ca, const struct bpf_map *sk_stg_map)
 {
-	struct sockaddr_in6 sa6 = {};
 	ssize_t nr_recv = 0, bytes = 0;
 	int lfd = -1, fd = -1;
 	pthread_t srv_thread;
-	socklen_t addrlen = sizeof(sa6);
 	void *thread_ret;
 	char batch[1500];
 	int err;
@@ -99,12 +97,7 @@ static void do_test(const char *tcp_ca, const struct bpf_map *sk_stg_map)
 		return;
 	}
 
-	if (settcpca(lfd, tcp_ca) || settcpca(fd, tcp_ca) ||
-	    settimeo(fd, 0))
-		goto done;
-
-	err = getsockname(lfd, (struct sockaddr *)&sa6, &addrlen);
-	if (!ASSERT_NEQ(err, -1, "getsockname"))
+	if (settcpca(lfd, tcp_ca) || settcpca(fd, tcp_ca))
 		goto done;
 
 	if (sk_stg_map) {
@@ -115,7 +108,7 @@ static void do_test(const char *tcp_ca, const struct bpf_map *sk_stg_map)
 	}
 
 	/* connect to server */
-	err = connect(fd, (struct sockaddr *)&sa6, addrlen);
+	err = connect_fd_to_fd(fd, lfd, 0);
 	if (!ASSERT_NEQ(err, -1, "connect"))
 		goto done;
 
Signature · 1 line
2.40.1