Re: [PATCH bpf-next v11 6/9] selftests/bpf: Use connect_fd_to_fd in sk_lookup

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 7/9/24 2:16 AM, Geliang Tang wrote:
From: Geliang Tang <tanggeliang@xxxxxxxxxx>

This patch uses public helper connect_fd_to_fd() exported in
network_helpers.h instead of using getsockname() + connect() in
run_lookup_prog() in prog_tests/sk_lookup.c. This can simplify
the code.

Signed-off-by: Geliang Tang <tanggeliang@xxxxxxxxxx>
---
  tools/testing/selftests/bpf/prog_tests/sk_lookup.c | 11 ++---------
  1 file changed, 2 insertions(+), 9 deletions(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/sk_lookup.c b/tools/testing/selftests/bpf/prog_tests/sk_lookup.c
index 386e482be617..ad3f943cc2bd 100644
--- a/tools/testing/selftests/bpf/prog_tests/sk_lookup.c
+++ b/tools/testing/selftests/bpf/prog_tests/sk_lookup.c
@@ -633,9 +633,6 @@ static void run_lookup_prog(const struct test *t)
  	 * BPF socket lookup.
  	 */
  	if (t->reuseport_has_conns) {
-		struct sockaddr_storage addr = {};
-		socklen_t len = sizeof(addr);
-
  		/* Add an extra socket to reuseport group */
  		reuse_conn_fd = make_server(t->sotype, t->listen_at.ip,
  					    t->listen_at.port,
@@ -643,12 +640,8 @@ static void run_lookup_prog(const struct test *t)
  		if (reuse_conn_fd < 0)
  			goto close;
- /* Connect the extra socket to itself */

This comment is still valid after this change.

-		err = getsockname(reuse_conn_fd, (void *)&addr, &len);
-		if (CHECK(err, "getsockname", "errno %d\n", errno))
-			goto close;
-		err = connect(reuse_conn_fd, (void *)&addr, len);
-		if (CHECK(err, "connect", "errno %d\n", errno))
+		err = connect_fd_to_fd(reuse_conn_fd, reuse_conn_fd, 0);
+		if (!ASSERT_OK(err, "connect_fd_to_fd"))
  			goto close;
  	}





[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux