mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-05-02 08:39:08 -04:00
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: Geliang Tang <tanggeliang@kylinos.cn> Link: https://lore.kernel.org/r/058199d7ab46802249dae066ca22c98f6be508ee.1721475357.git.tanggeliang@kylinos.cn Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org> Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
This commit is contained in:
committed by
Andrii Nakryiko
parent
aa8ebb270c
commit
af994e31b7
@@ -229,27 +229,6 @@ static int make_server(int sotype, const char *ip, int port,
|
||||
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)
|
||||
{
|
||||
__u64 cookie;
|
||||
@@ -646,8 +625,9 @@ 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);
|
||||
if (client_fd < 0)
|
||||
client_fd = connect_to_addr_str(is_ipv6(t->connect_to.ip) ? AF_INET6 : AF_INET,
|
||||
t->sotype, t->connect_to.ip, t->connect_to.port, NULL);
|
||||
if (!ASSERT_OK_FD(client_fd, "connect_to_addr_str"))
|
||||
goto close;
|
||||
|
||||
if (t->sotype == SOCK_STREAM)
|
||||
@@ -1152,8 +1132,8 @@ 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);
|
||||
if (connected_fd < 0)
|
||||
connected_fd = connect_to_addr_str(AF_INET, sotype, EXT_IP4, EXT_PORT, NULL);
|
||||
if (!ASSERT_OK_FD(connected_fd, "connect_to_addr_str"))
|
||||
goto out_close_server;
|
||||
|
||||
/* Put a connected socket in redirect map */
|
||||
@@ -1166,8 +1146,8 @@ 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);
|
||||
if (client_fd < 0)
|
||||
client_fd = connect_to_addr_str(AF_INET, sotype, EXT_IP4, EXT_PORT, NULL);
|
||||
if (!ASSERT_OK_FD(client_fd, "connect_to_addr_str"))
|
||||
goto out_unlink_prog;
|
||||
if (sotype == SOCK_DGRAM) {
|
||||
send_byte(client_fd);
|
||||
|
||||
Reference in New Issue
Block a user