@@ -80,9 +80,10 @@ int settimeo(int fd, int timeout_ms)
#define save_errno_close(fd) ({ int __save = errno; close(fd); errno = __save; })
-static int __start_server(int type, const struct sockaddr *addr, socklen_t addrlen,
+static int __start_server(const struct sockaddr *addr, socklen_t addrlen,
const struct network_helper_opts *opts)
{
+ int type = opts->type ? : SOCK_STREAM;
int fd;
fd = socket(addr->sa_family, type, opts->proto);
@@ -122,6 +123,7 @@ int start_server(int family, int type, const char *addr_str, __u16 port,
int timeout_ms)
{
struct network_helper_opts opts = {
+ .type = type,
.timeout_ms = timeout_ms,
};
struct sockaddr_storage addr;
@@ -130,7 +132,7 @@ int start_server(int family, int type, const char *addr_str, __u16 port,
if (make_sockaddr(family, addr_str, port, &addr, &addrlen))
return -1;
- return __start_server(type, (struct sockaddr *)&addr, addrlen, &opts);
+ return __start_server((struct sockaddr *)&addr, addrlen, &opts);
}
static int reuseport_cb(int fd, void *opts)
@@ -144,6 +146,7 @@ int *start_reuseport_server(int family, int type, const char *addr_str,
__u16 port, int timeout_ms, unsigned int nr_listens)
{
struct network_helper_opts opts = {
+ .type = type,
.timeout_ms = timeout_ms,
.post_socket_cb = reuseport_cb,
};
@@ -162,7 +165,7 @@ int *start_reuseport_server(int family, int type, const char *addr_str,
if (!fds)
return NULL;
- fds[0] = __start_server(type, (struct sockaddr *)&addr, addrlen, &opts);
+ fds[0] = __start_server((struct sockaddr *)&addr, addrlen, &opts);
if (fds[0] == -1)
goto close_fds;
nr_fds = 1;
@@ -171,7 +174,7 @@ int *start_reuseport_server(int family, int type, const char *addr_str,
goto close_fds;
for (; nr_fds < nr_listens; nr_fds++) {
- fds[nr_fds] = __start_server(type, (struct sockaddr *)&addr, addrlen, &opts);
+ fds[nr_fds] = __start_server((struct sockaddr *)&addr, addrlen, &opts);
if (fds[nr_fds] == -1)
goto close_fds;
}
@@ -183,13 +186,13 @@ int *start_reuseport_server(int family, int type, const char *addr_str,
return NULL;
}
-int start_server_addr(int type, const struct sockaddr_storage *addr, socklen_t len,
+int start_server_addr(const struct sockaddr_storage *addr, socklen_t len,
const struct network_helper_opts *opts)
{
if (!opts)
opts = &default_opts;
- return __start_server(type, (struct sockaddr *)addr, len, opts);
+ return __start_server((struct sockaddr *)addr, len, opts);
}
void free_fds(int *fds, unsigned int nr_close_fds)
@@ -53,7 +53,7 @@ int start_server(int family, int type, const char *addr, __u16 port,
int *start_reuseport_server(int family, int type, const char *addr_str,
__u16 port, int timeout_ms,
unsigned int nr_listens);
-int start_server_addr(int type, const struct sockaddr_storage *addr, socklen_t len,
+int start_server_addr(const struct sockaddr_storage *addr, socklen_t len,
const struct network_helper_opts *opts);
void free_fds(int *fds, unsigned int nr_close_fds);
int connect_to_addr(int type, const struct sockaddr_storage *addr, socklen_t len,
@@ -62,11 +62,14 @@ static bool fill_addr_port(const struct sockaddr *sa, struct addr_port *ap)
static bool set_up_conn(const struct sockaddr *addr, socklen_t len, int type,
int *server, int *conn, struct tuple *tuple)
{
+ struct network_helper_opts opts = {
+ .type = type,
+ };
struct sockaddr_storage ss;
socklen_t slen = sizeof(ss);
struct sockaddr *sa = (struct sockaddr *)&ss;
- *server = start_server_addr(type, (struct sockaddr_storage *)addr, len, NULL);
+ *server = start_server_addr((struct sockaddr_storage *)addr, len, &opts);
if (*server < 0)
return false;
@@ -110,7 +110,7 @@ static int start_mptcp_server(int family, const char *addr_str, __u16 port,
if (make_sockaddr(family, addr_str, port, &addr, &addrlen))
return -1;
- return start_server_addr(SOCK_STREAM, &addr, addrlen, &opts);
+ return start_server_addr(&addr, addrlen, &opts);
}
static int verify_tsk(int map_fd, int client_fd)
@@ -255,6 +255,9 @@ void test_sk_assign(void)
for (i = 0; i < ARRAY_SIZE(tests) && !READ_ONCE(stop); i++) {
struct test_sk_cfg *test = &tests[i];
+ struct network_helper_opts opts = {
+ .type = test->type,
+ };
const struct sockaddr *addr;
const int zero = 0;
int err;
@@ -263,9 +266,8 @@ void test_sk_assign(void)
continue;
prepare_addr(test->addr, test->family, BIND_PORT, false);
addr = (const struct sockaddr *)test->addr;
- server = start_server_addr(test->type,
- (const struct sockaddr_storage *)addr,
- test->len, NULL);
+ server = start_server_addr((const struct sockaddr_storage *)addr,
+ test->len, &opts);
if (server == -1)
goto close;
@@ -121,7 +121,7 @@ static void run_test(int cgroup_fd)
if (!ASSERT_OK_PTR(link_setsockopt, "cg-attach-setsockopt"))
goto close_bpf_object;
- server_fd = start_server_addr(SOCK_STREAM, (struct sockaddr_storage *)&addr,
+ server_fd = start_server_addr((struct sockaddr_storage *)&addr,
sizeof(addr), &opts);
if (!ASSERT_GE(server_fd, 0, "start_server"))
goto close_bpf_object;
@@ -197,19 +197,19 @@ int main(int argc, char **argv)
addr6dual.sin6_addr = in6addr_any;
addr6dual.sin6_port = 0;
- server = start_server_addr(SOCK_STREAM, (struct sockaddr_storage *)&addr4,
+ server = start_server_addr((struct sockaddr_storage *)&addr4,
sizeof(addr4), NULL);
if (server == -1)
goto err;
opts.post_socket_cb = v6only_true;
- server_v6 = start_server_addr(SOCK_STREAM, (struct sockaddr_storage *)&addr6,
+ server_v6 = start_server_addr((struct sockaddr_storage *)&addr6,
sizeof(addr6), &opts);
if (server_v6 == -1)
goto err;
opts.post_socket_cb = v6only_false;
- server_dual = start_server_addr(SOCK_STREAM, (struct sockaddr_storage *)&addr6dual,
+ server_dual = start_server_addr((struct sockaddr_storage *)&addr6dual,
sizeof(addr6dual), &opts);
if (server_dual == -1)
goto err;