Re: [PATCH bpf-next v6 8/9] selftests/bpf: Use connect_to_addr in sk_lookup

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

 



On 6/28/24 6:20 PM, Geliang Tang wrote:
From: Geliang Tang <tanggeliang@xxxxxxxxxx>

Use public network helpers make_sockaddr() and connect_to_addr() instead
of using the local defined function make_socket() and connect().

This make_socket() can be dropped latter.

Signed-off-by: Geliang Tang <tanggeliang@xxxxxxxxxx>
---
  .../selftests/bpf/prog_tests/sk_lookup.c      | 20 +++++++------------
  1 file changed, 7 insertions(+), 13 deletions(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/sk_lookup.c b/tools/testing/selftests/bpf/prog_tests/sk_lookup.c
index 38382dffe997..005776f5964e 100644
--- a/tools/testing/selftests/bpf/prog_tests/sk_lookup.c
+++ b/tools/testing/selftests/bpf/prog_tests/sk_lookup.c
@@ -231,23 +231,17 @@ static int make_server(int sotype, const char *ip, int port,
static int make_client(int sotype, const char *ip, int port)
  {
+	int family = is_ipv6(ip) ? AF_INET6 : AF_INET;
+	struct network_helper_opts opts = {
+		.timeout_ms = IO_TIMEOUT_SEC,
+	};
  	struct sockaddr_storage addr = {0};
-	int err, fd;
+	socklen_t len;
- fd = make_socket(sotype, ip, port, &addr);
-	if (fd < 0)
+	if (make_sockaddr(family, ip, port, &addr, &len))

Depending on the callers of make_client ASSERT or not,
I suspect it is easier to ASSERT here to signal the error in make_sockaddr.

  		return -1;
- err = connect(fd, (void *)&addr, inetaddr_len(&addr));
-	if (CHECK(err, "make_client", "connect")) {
-		log_err("failed to connect client socket");
-		goto fail;
-	}
-
-	return fd;
-fail:
-	close(fd);
-	return -1;
+	return connect_to_addr(sotype, &addr, len, &opts);

same here for the connect_to_addr().

pw-bot: cr

  }
static __u64 socket_cookie(int fd)





[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