Commit af994e31 authored by Geliang Tang's avatar Geliang Tang Committed by Andrii Nakryiko

selftests/bpf: Drop make_client in sk_lookup

This patch uses the new helper connect_to_addr_str() in sk_lookup.c to
create the client socket and connect to the server, instead of using local
defined function make_client(). This local function can be dropped then.
Signed-off-by: default avatarGeliang Tang <tanggeliang@kylinos.cn>
Link: https://lore.kernel.org/r/058199d7ab46802249dae066ca22c98f6be508ee.1721475357.git.tanggeliang@kylinos.cnSigned-off-by: default avatarMartin KaFai Lau <martin.lau@kernel.org>
Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
parent aa8ebb27
...@@ -229,27 +229,6 @@ static int make_server(int sotype, const char *ip, int port, ...@@ -229,27 +229,6 @@ static int make_server(int sotype, const char *ip, int port,
return -1; return -1;
} }
static int make_client(int sotype, const char *ip, int port)
{
struct sockaddr_storage addr = {0};
int err, fd;
fd = make_socket(sotype, ip, port, &addr);
if (fd < 0)
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;
}
static __u64 socket_cookie(int fd) static __u64 socket_cookie(int fd)
{ {
__u64 cookie; __u64 cookie;
...@@ -646,8 +625,9 @@ static void run_lookup_prog(const struct test *t) ...@@ -646,8 +625,9 @@ static void run_lookup_prog(const struct test *t)
goto close; goto close;
} }
client_fd = make_client(t->sotype, t->connect_to.ip, t->connect_to.port); client_fd = connect_to_addr_str(is_ipv6(t->connect_to.ip) ? AF_INET6 : AF_INET,
if (client_fd < 0) t->sotype, t->connect_to.ip, t->connect_to.port, NULL);
if (!ASSERT_OK_FD(client_fd, "connect_to_addr_str"))
goto close; goto close;
if (t->sotype == SOCK_STREAM) if (t->sotype == SOCK_STREAM)
...@@ -1152,8 +1132,8 @@ static void run_sk_assign_connected(struct test_sk_lookup *skel, ...@@ -1152,8 +1132,8 @@ static void run_sk_assign_connected(struct test_sk_lookup *skel,
if (server_fd < 0) if (server_fd < 0)
return; return;
connected_fd = make_client(sotype, EXT_IP4, EXT_PORT); connected_fd = connect_to_addr_str(AF_INET, sotype, EXT_IP4, EXT_PORT, NULL);
if (connected_fd < 0) if (!ASSERT_OK_FD(connected_fd, "connect_to_addr_str"))
goto out_close_server; goto out_close_server;
/* Put a connected socket in redirect map */ /* Put a connected socket in redirect map */
...@@ -1166,8 +1146,8 @@ static void run_sk_assign_connected(struct test_sk_lookup *skel, ...@@ -1166,8 +1146,8 @@ static void run_sk_assign_connected(struct test_sk_lookup *skel,
goto out_close_connected; goto out_close_connected;
/* Try to redirect TCP SYN / UDP packet to a connected socket */ /* Try to redirect TCP SYN / UDP packet to a connected socket */
client_fd = make_client(sotype, EXT_IP4, EXT_PORT); client_fd = connect_to_addr_str(AF_INET, sotype, EXT_IP4, EXT_PORT, NULL);
if (client_fd < 0) if (!ASSERT_OK_FD(client_fd, "connect_to_addr_str"))
goto out_unlink_prog; goto out_unlink_prog;
if (sotype == SOCK_DGRAM) { if (sotype == SOCK_DGRAM) {
send_byte(client_fd); send_byte(client_fd);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment