From: Geliang Tang tanggeliang@kylinos.cn
v8: - only patch 8 updated, to fix errors reported by CI.
v7: - address Martin's comments in v6. (thanks) - use MAX(opts->backlog, 0) instead of opts->backlog. - use connect_to_fd_opts instead connect_to_fd. - more ASSERT_* to check errors.
v6: - update patch 6 as Daniel suggested. (thanks)
v5: - keep make_server and make_client as Eduard suggested.
v4: - a new patch to use make_sockaddr in sockmap_ktls. - a new patch to close fd in error path in drop_on_reuseport. - drop make_server() in patch 7. - drop make_client() too in patch 9.
v3: - a new patch to add backlog for network_helper_opts. - use start_server_str in sockmap_ktls now, not start_server.
v2: - address Eduard's comments in v1. (thanks) - fix errors reported by CI.
This patch set uses network helpers in sockmap_ktls and sk_lookup, and drop three local helpers tcp_server(), inetaddr_len() and make_socket() in them.
Geliang Tang (9): selftests/bpf: Add backlog for network_helper_opts selftests/bpf: Use start_server_str in sockmap_ktls selftests/bpf: Use connect_to_fd_opts in sockmap_ktls selftests/bpf: Use make_sockaddr in sockmap_ktls selftests/bpf: Close fd in error path in drop_on_reuseport selftests/bpf: Use start_server_str in sk_lookup selftests/bpf: Use connect_to_fd_opts in sk_lookup selftests/bpf: Use connect_to_addr in sk_lookup selftests/bpf: Drop make_socket in sk_lookup
tools/testing/selftests/bpf/network_helpers.c | 2 +- tools/testing/selftests/bpf/network_helpers.h | 4 + .../selftests/bpf/prog_tests/sk_lookup.c | 152 +++++++----------- .../selftests/bpf/prog_tests/sockmap_ktls.c | 53 ++---- 4 files changed, 76 insertions(+), 135 deletions(-)
From: Geliang Tang tanggeliang@kylinos.cn
Some callers expect __start_server() helper to pass their own "backlog" value to listen() instead of the default of 1. So this patch adds struct member "backlog" for network_helper_opts to allow callers to set "backlog" value via start_server_str() helper.
listen(fd, 0 /* backlog */) can be used to enforce syncookie. Meaning backlog 0 is a legit value.
Using 0 as a default and changing it to 1 here is fine. It makes the test program easier to write for the common case. Enforcing syncookie mode by using backlog 0 is a niche use case but it should at least have a way for the caller to do that.
Signed-off-by: Geliang Tang tanggeliang@kylinos.cn --- tools/testing/selftests/bpf/network_helpers.c | 2 +- tools/testing/selftests/bpf/network_helpers.h | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c index 44c2c8fa542a..e0cba4178e41 100644 --- a/tools/testing/selftests/bpf/network_helpers.c +++ b/tools/testing/selftests/bpf/network_helpers.c @@ -106,7 +106,7 @@ static int __start_server(int type, const struct sockaddr *addr, socklen_t addrl }
if (type == SOCK_STREAM) { - if (listen(fd, 1) < 0) { + if (listen(fd, opts->backlog ? MAX(opts->backlog, 0) : 1) < 0) { log_err("Failed to listed on socket"); goto error_close; } diff --git a/tools/testing/selftests/bpf/network_helpers.h b/tools/testing/selftests/bpf/network_helpers.h index 9ea36524b9db..4f26bfc2dbf5 100644 --- a/tools/testing/selftests/bpf/network_helpers.h +++ b/tools/testing/selftests/bpf/network_helpers.h @@ -25,6 +25,10 @@ struct network_helper_opts { int timeout_ms; bool must_fail; int proto; + /* The backlog argument for listen(), defines the maximum length to which + * the queue of pending connections for sockfd may grow. + */ + int backlog; int (*post_socket_cb)(int fd, void *opts); void *cb_opts; };
From: Geliang Tang tanggeliang@kylinos.cn
Include network_helpers.h in prog_tests/sockmap_ktls.c, use public network helper start_server_str() instead of local defined function tcp_server(). This can avoid duplicate code.
Technically, this is not a one-for-one replacement, as start_server_str() also does bind(). But the difference does not seem to matter.
Acked-by: Eduard Zingerman eddyz87@gmail.com Signed-off-by: Geliang Tang tanggeliang@kylinos.cn --- .../selftests/bpf/prog_tests/sockmap_ktls.c | 23 +++++-------------- 1 file changed, 6 insertions(+), 17 deletions(-)
diff --git a/tools/testing/selftests/bpf/prog_tests/sockmap_ktls.c b/tools/testing/selftests/bpf/prog_tests/sockmap_ktls.c index 2d0796314862..32be112967a5 100644 --- a/tools/testing/selftests/bpf/prog_tests/sockmap_ktls.c +++ b/tools/testing/selftests/bpf/prog_tests/sockmap_ktls.c @@ -6,25 +6,11 @@
#include <netinet/tcp.h> #include "test_progs.h" +#include "network_helpers.h"
#define MAX_TEST_NAME 80 #define TCP_ULP 31
-static int tcp_server(int family) -{ - int err, s; - - s = socket(family, SOCK_STREAM, 0); - if (!ASSERT_GE(s, 0, "socket")) - return -1; - - err = listen(s, SOMAXCONN); - if (!ASSERT_OK(err, "listen")) - return -1; - - return s; -} - static int disconnect(int fd) { struct sockaddr unspec = { AF_UNSPEC }; @@ -35,12 +21,15 @@ static int disconnect(int fd) /* Disconnect (unhash) a kTLS socket after removing it from sockmap. */ static void test_sockmap_ktls_disconnect_after_delete(int family, int map) { + struct network_helper_opts opts = { + .backlog = SOMAXCONN, + }; struct sockaddr_storage addr = {0}; socklen_t len = sizeof(addr); int err, cli, srv, zero = 0;
- srv = tcp_server(family); - if (srv == -1) + srv = start_server_str(family, SOCK_STREAM, NULL, 0, &opts); + if (!ASSERT_GE(srv, 0, "start_server_str")) return;
err = getsockname(srv, (struct sockaddr *)&addr, &len);
From: Geliang Tang tanggeliang@kylinos.cn
Use public network helper connect_to_fd_opts() instead of open-coding it in prog_tests/sockmap_ktls.c. This can avoid duplicate code.
Acked-by: Eduard Zingerman eddyz87@gmail.com Signed-off-by: Geliang Tang tanggeliang@kylinos.cn --- .../selftests/bpf/prog_tests/sockmap_ktls.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-)
diff --git a/tools/testing/selftests/bpf/prog_tests/sockmap_ktls.c b/tools/testing/selftests/bpf/prog_tests/sockmap_ktls.c index 32be112967a5..a794aa688ab5 100644 --- a/tools/testing/selftests/bpf/prog_tests/sockmap_ktls.c +++ b/tools/testing/selftests/bpf/prog_tests/sockmap_ktls.c @@ -24,26 +24,16 @@ static void test_sockmap_ktls_disconnect_after_delete(int family, int map) struct network_helper_opts opts = { .backlog = SOMAXCONN, }; - struct sockaddr_storage addr = {0}; - socklen_t len = sizeof(addr); int err, cli, srv, zero = 0;
srv = start_server_str(family, SOCK_STREAM, NULL, 0, &opts); if (!ASSERT_GE(srv, 0, "start_server_str")) return;
- err = getsockname(srv, (struct sockaddr *)&addr, &len); - if (!ASSERT_OK(err, "getsockopt")) - goto close_srv; - - cli = socket(family, SOCK_STREAM, 0); - if (!ASSERT_GE(cli, 0, "socket")) + cli = connect_to_fd_opts(srv, SOCK_STREAM, NULL); + if (!ASSERT_GE(cli, 0, "connect_to_fd_opts")) goto close_srv;
- err = connect(cli, (struct sockaddr *)&addr, len); - if (!ASSERT_OK(err, "connect")) - goto close_cli; - err = bpf_map_update_elem(map, &zero, &cli, 0); if (!ASSERT_OK(err, "bpf_map_update_elem")) goto close_cli;
From: Geliang Tang tanggeliang@kylinos.cn
This patch uses public helper make_sockaddr() exported in network_helpers.h instead of open-coding in sockmap_ktls.c. This can avoid duplicate code.
Acked-by: Eduard Zingerman eddyz87@gmail.com Signed-off-by: Geliang Tang tanggeliang@kylinos.cn --- .../selftests/bpf/prog_tests/sockmap_ktls.c | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-)
diff --git a/tools/testing/selftests/bpf/prog_tests/sockmap_ktls.c b/tools/testing/selftests/bpf/prog_tests/sockmap_ktls.c index a794aa688ab5..3c223601e8b6 100644 --- a/tools/testing/selftests/bpf/prog_tests/sockmap_ktls.c +++ b/tools/testing/selftests/bpf/prog_tests/sockmap_ktls.c @@ -59,23 +59,11 @@ static void test_sockmap_ktls_update_fails_when_sock_has_ulp(int family, int map { struct sockaddr_storage addr = {}; socklen_t len = sizeof(addr); - struct sockaddr_in6 *v6; - struct sockaddr_in *v4; int err, s, zero = 0;
- switch (family) { - case AF_INET: - v4 = (struct sockaddr_in *)&addr; - v4->sin_family = AF_INET; - break; - case AF_INET6: - v6 = (struct sockaddr_in6 *)&addr; - v6->sin6_family = AF_INET6; - break; - default: - PRINT_FAIL("unsupported socket family %d", family); + err = make_sockaddr(family, NULL, 0, &addr, &len); + if (!ASSERT_OK(err, "make_sockaddr")) return; - }
s = socket(family, SOCK_STREAM, 0); if (!ASSERT_GE(s, 0, "socket"))
From: Geliang Tang tanggeliang@kylinos.cn
Server 1 fd should be closed in the error path when update_lookup_map() fails. This patch fixes it by goto "close_srv1" instead of "detach" lable in that case.
Acked-by: Eduard Zingerman eddyz87@gmail.com Signed-off-by: Geliang Tang tanggeliang@kylinos.cn --- tools/testing/selftests/bpf/prog_tests/sk_lookup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/testing/selftests/bpf/prog_tests/sk_lookup.c b/tools/testing/selftests/bpf/prog_tests/sk_lookup.c index 597d0467a926..de2466547efe 100644 --- a/tools/testing/selftests/bpf/prog_tests/sk_lookup.c +++ b/tools/testing/selftests/bpf/prog_tests/sk_lookup.c @@ -994,7 +994,7 @@ static void drop_on_reuseport(const struct test *t)
err = update_lookup_map(t->sock_map, SERVER_A, server1); if (err) - goto detach; + goto close_srv1;
/* second server on destination address we should never reach */ server2 = make_server(t->sotype, t->connect_to.ip, t->connect_to.port,
From: Geliang Tang tanggeliang@kylinos.cn
This patch uses public helper start_server_addr() instead of local defined function make_server() in prog_tests/sk_lookup.c to avoid duplicate code.
Add a helper setsockopts() to set SOL_CUSTOM sockopt looply, set it to setsockopt pointer of struct network_helper_opts, and pass it to start_server_addr().
Acked-by: Eduard Zingerman eddyz87@gmail.com Signed-off-by: Geliang Tang tanggeliang@kylinos.cn --- .../selftests/bpf/prog_tests/sk_lookup.c | 58 +++++++++++-------- 1 file changed, 34 insertions(+), 24 deletions(-)
diff --git a/tools/testing/selftests/bpf/prog_tests/sk_lookup.c b/tools/testing/selftests/bpf/prog_tests/sk_lookup.c index de2466547efe..d03ea3e64a2e 100644 --- a/tools/testing/selftests/bpf/prog_tests/sk_lookup.c +++ b/tools/testing/selftests/bpf/prog_tests/sk_lookup.c @@ -77,6 +77,12 @@ struct test { bool reuseport_has_conns; /* Add a connected socket to reuseport group */ };
+struct cb_opts { + int family; + int sotype; + bool reuseport; +}; + static __u32 duration; /* for CHECK macro */
static bool is_ipv6(const char *ip) @@ -142,19 +148,14 @@ static int make_socket(int sotype, const char *ip, int port, return fd; }
-static int make_server(int sotype, const char *ip, int port, - struct bpf_program *reuseport_prog) +static int setsockopts(int fd, void *opts) { - struct sockaddr_storage addr = {0}; + struct cb_opts *co = (struct cb_opts *)opts; const int one = 1; - int err, fd = -1; - - fd = make_socket(sotype, ip, port, &addr); - if (fd < 0) - return -1; + int err = 0;
/* Enabled for UDPv6 sockets for IPv4-mapped IPv6 to work. */ - if (sotype == SOCK_DGRAM) { + if (co->sotype == SOCK_DGRAM) { err = setsockopt(fd, SOL_IP, IP_RECVORIGDSTADDR, &one, sizeof(one)); if (CHECK(err, "setsockopt(IP_RECVORIGDSTADDR)", "failed\n")) { @@ -163,7 +164,7 @@ static int make_server(int sotype, const char *ip, int port, } }
- if (sotype == SOCK_DGRAM && addr.ss_family == AF_INET6) { + if (co->sotype == SOCK_DGRAM && co->family == AF_INET6) { err = setsockopt(fd, SOL_IPV6, IPV6_RECVORIGDSTADDR, &one, sizeof(one)); if (CHECK(err, "setsockopt(IPV6_RECVORIGDSTADDR)", "failed\n")) { @@ -172,7 +173,7 @@ static int make_server(int sotype, const char *ip, int port, } }
- if (sotype == SOCK_STREAM) { + if (co->sotype == SOCK_STREAM) { err = setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)); if (CHECK(err, "setsockopt(SO_REUSEADDR)", "failed\n")) { @@ -181,7 +182,7 @@ static int make_server(int sotype, const char *ip, int port, } }
- if (reuseport_prog) { + if (co->reuseport) { err = setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &one, sizeof(one)); if (CHECK(err, "setsockopt(SO_REUSEPORT)", "failed\n")) { @@ -190,19 +191,28 @@ static int make_server(int sotype, const char *ip, int port, } }
- err = bind(fd, (void *)&addr, inetaddr_len(&addr)); - if (CHECK(err, "bind", "failed\n")) { - log_err("failed to bind listen socket"); - goto fail; - } +fail: + return err; +}
- if (sotype == SOCK_STREAM) { - err = listen(fd, SOMAXCONN); - if (CHECK(err, "make_server", "listen")) { - log_err("failed to listen on port %d", port); - goto fail; - } - } +static int make_server(int sotype, const char *ip, int port, + struct bpf_program *reuseport_prog) +{ + struct cb_opts cb_opts = { + .family = is_ipv6(ip) ? AF_INET6 : AF_INET, + .sotype = sotype, + .reuseport = reuseport_prog, + }; + struct network_helper_opts opts = { + .backlog = SOMAXCONN, + .post_socket_cb = setsockopts, + .cb_opts = &cb_opts, + }; + int err, fd; + + fd = start_server_str(cb_opts.family, sotype, ip, port, &opts); + if (!ASSERT_GE(fd, 0, "start_server_str")) + return -1;
/* Late attach reuseport prog so we can have one init path */ if (reuseport_prog) {
From: Geliang Tang tanggeliang@kylinos.cn
This patch uses public helper connect_to_fd_opts() exported in network_helpers.h instead of using make_socket() and connect() in prog_tests/sk_lookup.c. This can simplify the code.
Signed-off-by: Geliang Tang tanggeliang@kylinos.cn --- .../selftests/bpf/prog_tests/sk_lookup.c | 25 +++++++++++-------- 1 file changed, 15 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 d03ea3e64a2e..ef4a3db34c5f 100644 --- a/tools/testing/selftests/bpf/prog_tests/sk_lookup.c +++ b/tools/testing/selftests/bpf/prog_tests/sk_lookup.c @@ -874,7 +874,9 @@ static void test_redirect_lookup(struct test_sk_lookup *skel)
static void drop_on_lookup(const struct test *t) { - struct sockaddr_storage dst = {}; + struct network_helper_opts opts = { + .timeout_ms = IO_TIMEOUT_SEC, + }; int client_fd, server_fd, err; struct bpf_link *lookup_link; ssize_t n; @@ -888,12 +890,11 @@ static void drop_on_lookup(const struct test *t) if (server_fd < 0) goto detach;
- client_fd = make_socket(t->sotype, t->connect_to.ip, - t->connect_to.port, &dst); + client_fd = connect_to_fd_opts(server_fd, t->sotype, &opts); if (client_fd < 0) goto close_srv;
- err = connect(client_fd, (void *)&dst, inetaddr_len(&dst)); + err = 0; if (t->sotype == SOCK_DGRAM) { err = send_byte(client_fd); if (err) @@ -988,7 +989,9 @@ static void test_drop_on_lookup(struct test_sk_lookup *skel)
static void drop_on_reuseport(const struct test *t) { - struct sockaddr_storage dst = { 0 }; + struct network_helper_opts opts = { + .timeout_ms = IO_TIMEOUT_SEC, + }; int client, server1, server2, err; struct bpf_link *lookup_link; ssize_t n; @@ -1012,12 +1015,11 @@ static void drop_on_reuseport(const struct test *t) if (server2 < 0) goto close_srv1;
- client = make_socket(t->sotype, t->connect_to.ip, - t->connect_to.port, &dst); + client = connect_to_fd_opts(server2, t->sotype, &opts); if (client < 0) goto close_srv2;
- err = connect(client, (void *)&dst, inetaddr_len(&dst)); + err = 0; if (t->sotype == SOCK_DGRAM) { err = send_byte(client); if (err) @@ -1158,13 +1160,16 @@ static void run_sk_assign_connected(struct test_sk_lookup *skel, int sotype) { int err, client_fd, connected_fd, server_fd; + struct network_helper_opts opts = { + .timeout_ms = IO_TIMEOUT_SEC, + }; struct bpf_link *lookup_link;
server_fd = make_server(sotype, EXT_IP4, EXT_PORT, NULL); if (server_fd < 0) return;
- connected_fd = make_client(sotype, EXT_IP4, EXT_PORT); + connected_fd = connect_to_fd_opts(server_fd, sotype, &opts); if (connected_fd < 0) goto out_close_server;
@@ -1178,7 +1183,7 @@ static void run_sk_assign_connected(struct test_sk_lookup *skel, goto out_close_connected;
/* Try to redirect TCP SYN / UDP packet to a connected socket */ - client_fd = make_client(sotype, EXT_IP4, EXT_PORT); + client_fd = connect_to_fd_opts(server_fd, sotype, &opts); if (client_fd < 0) goto out_unlink_prog; if (sotype == SOCK_DGRAM) {
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 | 22 ++++++++----------- 1 file changed, 9 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 ef4a3db34c5f..a436ed8b34e0 100644 --- a/tools/testing/selftests/bpf/prog_tests/sk_lookup.c +++ b/tools/testing/selftests/bpf/prog_tests/sk_lookup.c @@ -231,23 +231,19 @@ 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; + int err;
- 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; - } - - return fd; -fail: - close(fd); - return -1; + return connect_to_addr(sotype, &addr, len, &opts); }
static __u64 socket_cookie(int fd)
On 7/4/24 7:58 PM, 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 | 22 ++++++++----------- 1 file changed, 9 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 ef4a3db34c5f..a436ed8b34e0 100644 --- a/tools/testing/selftests/bpf/prog_tests/sk_lookup.c +++ b/tools/testing/selftests/bpf/prog_tests/sk_lookup.c @@ -231,23 +231,19 @@ 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;
- int err;
- 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;
- }
- return fd;
-fail:
- close(fd);
- return -1;
- return connect_to_addr(sotype, &addr, len, &opts);
You mentioned in v7 that ASSERT on the return value of the connect_to_addr() breaks the test.
However, the original code does CHECK which calls test__fail(). There are multiple tests call make_client() and some of them don't expect make_client() to fail. It is obvious that the failure will be hidden without the ASSERT. Something else needs to be adjusted for this refactoring. Please take a closer look first instead of hiding the potential future errors to pass the CI.
pw-bot: cr
} static __u64 socket_cookie(int fd)
From: Geliang Tang tanggeliang@kylinos.cn
Use local helper make_client() instead of using make_socket() and connect(). Then make_socket() and inetaddr_len() can be dropped now.
Signed-off-by: Geliang Tang tanggeliang@kylinos.cn --- .../selftests/bpf/prog_tests/sk_lookup.c | 45 +------------------ 1 file changed, 2 insertions(+), 43 deletions(-)
diff --git a/tools/testing/selftests/bpf/prog_tests/sk_lookup.c b/tools/testing/selftests/bpf/prog_tests/sk_lookup.c index a436ed8b34e0..c18bdcd1099e 100644 --- a/tools/testing/selftests/bpf/prog_tests/sk_lookup.c +++ b/tools/testing/selftests/bpf/prog_tests/sk_lookup.c @@ -108,46 +108,6 @@ static int attach_reuseport(int sock_fd, struct bpf_program *reuseport_prog) return 0; }
-static socklen_t inetaddr_len(const struct sockaddr_storage *addr) -{ - return (addr->ss_family == AF_INET ? sizeof(struct sockaddr_in) : - addr->ss_family == AF_INET6 ? sizeof(struct sockaddr_in6) : 0); -} - -static int make_socket(int sotype, const char *ip, int port, - struct sockaddr_storage *addr) -{ - struct timeval timeo = { .tv_sec = IO_TIMEOUT_SEC }; - int err, family, fd; - - family = is_ipv6(ip) ? AF_INET6 : AF_INET; - err = make_sockaddr(family, ip, port, addr, NULL); - if (CHECK(err, "make_address", "failed\n")) - return -1; - - fd = socket(addr->ss_family, sotype, 0); - if (CHECK(fd < 0, "socket", "failed\n")) { - log_err("failed to make socket"); - return -1; - } - - err = setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, &timeo, sizeof(timeo)); - if (CHECK(err, "setsockopt(SO_SNDTIMEO)", "failed\n")) { - log_err("failed to set SNDTIMEO"); - close(fd); - return -1; - } - - err = setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &timeo, sizeof(timeo)); - if (CHECK(err, "setsockopt(SO_RCVTIMEO)", "failed\n")) { - log_err("failed to set RCVTIMEO"); - close(fd); - return -1; - } - - return fd; -} - static int setsockopts(int fd, void *opts) { struct cb_opts *co = (struct cb_opts *)opts; @@ -1228,7 +1188,6 @@ struct test_multi_prog {
static void run_multi_prog_lookup(const struct test_multi_prog *t) { - struct sockaddr_storage dst = {}; int map_fd, server_fd, client_fd; struct bpf_link *link1, *link2; int prog_idx, done, err; @@ -1261,11 +1220,11 @@ static void run_multi_prog_lookup(const struct test_multi_prog *t) if (err) goto out_close_server;
- client_fd = make_socket(SOCK_STREAM, EXT_IP4, EXT_PORT, &dst); + client_fd = make_client(SOCK_STREAM, EXT_IP4, EXT_PORT); if (client_fd < 0) goto out_close_server;
- err = connect(client_fd, (void *)&dst, inetaddr_len(&dst)); + err = 0; if (CHECK(err && !t->expect_errno, "connect", "unexpected error %d\n", errno)) goto out_close_client;
linux-kselftest-mirror@lists.linaro.org