@@ -229,25 +229,19 @@ static int make_server(int sotype, const char *ip, int port,
return -1;
}
-static int make_client(int sotype, const char *ip, int port)
+static int make_client(int sotype, const char *ip, int port, int expect_errno)
{
- struct sockaddr_storage addr = {0};
- int err, fd;
-
- fd = make_socket(sotype, ip, port, &addr);
- if (fd < 0)
- return -1;
+ int fd;
- err = connect(fd, (void *)&addr, inetaddr_len(&addr));
- if (CHECK(err, "make_client", "connect")) {
+ fd = connect_to_addr_str(is_ipv6(ip) ? AF_INET6 : AF_INET,
+ sotype, ip, port, NULL);
+ if (CHECK(fd < 0 && (!expect_errno || errno != expect_errno),
+ "make_client", "connect_to_addr_str")) {
log_err("failed to connect client socket");
- goto fail;
+ return -1;
}
return fd;
-fail:
- close(fd);
- return -1;
}
static __u64 socket_cookie(int fd)
@@ -646,7 +640,7 @@ static void run_lookup_prog(const struct test *t)
goto close;
}
- client_fd = make_client(t->sotype, t->connect_to.ip, t->connect_to.port);
+ client_fd = make_client(t->sotype, t->connect_to.ip, t->connect_to.port, 0);
if (client_fd < 0)
goto close;
@@ -1152,7 +1146,7 @@ static void run_sk_assign_connected(struct test_sk_lookup *skel,
if (server_fd < 0)
return;
- connected_fd = make_client(sotype, EXT_IP4, EXT_PORT);
+ connected_fd = make_client(sotype, EXT_IP4, EXT_PORT, 0);
if (connected_fd < 0)
goto out_close_server;
@@ -1166,7 +1160,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 = make_client(sotype, EXT_IP4, EXT_PORT, 0);
if (client_fd < 0)
goto out_unlink_prog;
if (sotype == SOCK_DGRAM) {