Skip to contentSkip to conversation

Use start_server and connect_fd_to_fd

PATCH Applied Geliang Tang 2 participants 4 messages Mar 26, 2024 – Mar 28, 2024

Subsystems (4)
lore
Share & tools
lore

Geliang Tang

author reviewer
#0 lore raw

v4 cover Use start_server and connect_fd_to_fd

From: Geliang Tang <[email protected]>

v4:
- Matt reminded me that I shouldn't send a square-to patch to BPF (thanks), so I update them into two patches in v4.

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):
selftests/bpf: Use connect_fd_to_fd in bpf_tcp_ca selftests/bpf: Drop settimeo in do_test

 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 v4 1/2 selftests/bpf: Use connect_fd_to_fd in bpf_tcp_ca

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.

---
 tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c +1 -7
index 94cb22b01482..5aa3ccdc1351 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;
@@ -103,10 +101,6 @@ static void do_test(const char *tcp_ca, const struct bpf_map *sk_stg_map)
 	    settimeo(lfd, 0) || settimeo(fd, 0))
 		goto done;
 
-	err = getsockname(lfd, (struct sockaddr *)&sa6, &addrlen);
-	if (!ASSERT_NEQ(err, -1, "getsockname"))
-		goto done;
-
 	if (sk_stg_map) {
 		err = bpf_map_update_elem(bpf_map__fd(sk_stg_map), &fd,
 					  &expected_stg, BPF_NOEXIST);
@@ -115,7 +109,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
author reviewer
#2 lore raw

PATCH v4 2/2 selftests/bpf: Drop settimeo in do_test

In reply to Geliang Tang

From: Geliang Tang <[email protected]>

settimeo is invoked in start_server() and in connect_fd_to_fd() already, no need to invoke settimeo(lfd, 0) and settimeo(fd, 0) in do_test() anymore. This patch drops them.

---
 tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c +1 -2
index 5aa3ccdc1351..3da3030c9365 100644
@@ -97,8 +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(lfd, 0) || settimeo(fd, 0))
+	if (settcpca(lfd, tcp_ca) || settcpca(fd, tcp_ca))
 		goto done;
 
 	if (sk_stg_map) {
Signature · 1 line
2.40.1
#3 lore raw
In reply to Geliang Tang
This series was applied to bpf/bpf-next.git (master) by Martin KaFai Lau <[email protected]>:

Hello:

This series was applied to bpf/bpf-next.git (master) by Martin KaFai Lau <[email protected]>:

Quoted 6 lines · On Tue, 26 Mar 2024 18:03:37 +0800 you wrote:

From: Geliang Tang <[email protected]>

v4:
- Matt reminded me that I shouldn't send a square-to patch to BPF (thanks), so I update them into two patches in v4.

Quoted 7 lines

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.

[...]

Here is the summary with links:
- [bpf-next,v4,1/2] selftests/bpf: Use connect_fd_to_fd in bpf_tcp_ca

    https://git.kernel.org/bpf/bpf-next/c/ed1697153d40
  - [bpf-next,v4,2/2] selftests/bpf: Drop settimeo in do_test
    https://git.kernel.org/bpf/bpf-next/c/9a3aa22de842

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html