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

selftests/bpf: Drop inetaddr_len in sk_lookup

No need to use a dedicated helper inetaddr_len() to get the length of
the IPv4 or IPv6 address, it can be got by make_sockaddr(), this patch
drops it.
Signed-off-by: default avatarGeliang Tang <tanggeliang@kylinos.cn>
Link: https://lore.kernel.org/r/32e2a4122921051da38a6e4fbb2ebee5f0af5a4e.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 01c2f776
......@@ -106,12 +106,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 setsockopts(int fd, void *opts)
{
struct cb_opts *co = (struct cb_opts *)opts;
......@@ -810,6 +804,7 @@ static void drop_on_lookup(const struct test *t)
struct sockaddr_storage dst = {};
int client_fd, server_fd, err;
struct bpf_link *lookup_link;
socklen_t len;
ssize_t n;
lookup_link = attach_lookup_prog(t->lookup_prog);
......@@ -825,10 +820,10 @@ static void drop_on_lookup(const struct test *t)
if (!ASSERT_OK_FD(client_fd, "client_socket"))
goto close_srv;
err = make_sockaddr(family, t->connect_to.ip, t->connect_to.port, &dst, NULL);
err = make_sockaddr(family, t->connect_to.ip, t->connect_to.port, &dst, &len);
if (!ASSERT_OK(err, "make_sockaddr"))
goto close_all;
err = connect(client_fd, (void *)&dst, inetaddr_len(&dst));
err = connect(client_fd, (void *)&dst, len);
if (t->sotype == SOCK_DGRAM) {
err = send_byte(client_fd);
if (err)
......@@ -927,6 +922,7 @@ static void drop_on_reuseport(const struct test *t)
struct sockaddr_storage dst = { 0 };
int client, server1, server2, err;
struct bpf_link *lookup_link;
socklen_t len;
ssize_t n;
lookup_link = attach_lookup_prog(t->lookup_prog);
......@@ -952,10 +948,10 @@ static void drop_on_reuseport(const struct test *t)
if (!ASSERT_OK_FD(client, "client_socket"))
goto close_srv2;
err = make_sockaddr(family, t->connect_to.ip, t->connect_to.port, &dst, NULL);
err = make_sockaddr(family, t->connect_to.ip, t->connect_to.port, &dst, &len);
if (!ASSERT_OK(err, "make_sockaddr"))
goto close_all;
err = connect(client, (void *)&dst, inetaddr_len(&dst));
err = connect(client, (void *)&dst, len);
if (t->sotype == SOCK_DGRAM) {
err = send_byte(client);
if (err)
......@@ -1169,6 +1165,7 @@ static void run_multi_prog_lookup(const struct test_multi_prog *t)
int map_fd, server_fd, client_fd;
struct bpf_link *link1, *link2;
int prog_idx, done, err;
socklen_t len;
map_fd = bpf_map__fd(t->run_map);
......@@ -1202,10 +1199,10 @@ static void run_multi_prog_lookup(const struct test_multi_prog *t)
if (!ASSERT_OK_FD(client_fd, "client_socket"))
goto out_close_server;
err = make_sockaddr(AF_INET, EXT_IP4, EXT_PORT, &dst, NULL);
err = make_sockaddr(AF_INET, EXT_IP4, EXT_PORT, &dst, &len);
if (!ASSERT_OK(err, "make_sockaddr"))
goto out_close_client;
err = connect(client_fd, (void *)&dst, inetaddr_len(&dst));
err = connect(client_fd, (void *)&dst, len);
if (CHECK(err && !t->expect_errno, "connect",
"unexpected error %d\n", errno))
goto out_close_client;
......
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