@@ -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;