Message ID | 04e41d6e3158b294a30ae6bf93a856b63832d65a.1720083019.git.tanggeliang@kylinos.cn |
---|---|
State | New |
Headers | show |
Series | use network helpers, part 8 | expand |
On Thu, 2024-07-04 at 16:59 +0800, Geliang Tang wrote: > From: Geliang Tang <tanggeliang@kylinos.cn> > > 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@kylinos.cn> > --- > .../selftests/bpf/prog_tests/sk_lookup.c | 20 +++++++++-------- > -- > 1 file changed, 10 insertions(+), 10 deletions(-) > > diff --git a/tools/testing/selftests/bpf/prog_tests/sk_lookup.c > b/tools/testing/selftests/bpf/prog_tests/sk_lookup.c > index ef4a3db34c5f..7c42ebff80a4 100644 > --- a/tools/testing/selftests/bpf/prog_tests/sk_lookup.c > +++ b/tools/testing/selftests/bpf/prog_tests/sk_lookup.c > @@ -231,23 +231,23 @@ 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}; > + socklen_t len; > int err, fd; > > - fd = make_socket(sotype, ip, port, &addr); > - if (fd < 0) > + err = make_sockaddr(family, ip, port, &addr, &len); > + if (!ASSERT_OK(err, "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; > - } > + fd = connect_to_addr(sotype, &addr, len, &opts); > + if (!ASSERT_GE(fd, 0, "connect_to_addr")) Sorry, this line breaks CI. Changes Requested. -Geliang > + return -1; > > return fd; > -fail: > - close(fd); > - return -1; > } > > static __u64 socket_cookie(int fd)
diff --git a/tools/testing/selftests/bpf/prog_tests/sk_lookup.c b/tools/testing/selftests/bpf/prog_tests/sk_lookup.c index ef4a3db34c5f..7c42ebff80a4 100644 --- a/tools/testing/selftests/bpf/prog_tests/sk_lookup.c +++ b/tools/testing/selftests/bpf/prog_tests/sk_lookup.c @@ -231,23 +231,23 @@ 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}; + socklen_t len; int err, fd; - fd = make_socket(sotype, ip, port, &addr); - if (fd < 0) + err = make_sockaddr(family, ip, port, &addr, &len); + if (!ASSERT_OK(err, "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; - } + fd = connect_to_addr(sotype, &addr, len, &opts); + if (!ASSERT_GE(fd, 0, "connect_to_addr")) + return -1; return fd; -fail: - close(fd); - return -1; } static __u64 socket_cookie(int fd)