@@ -15,6 +15,7 @@
#include <unistd.h>
#include "test_progs.h"
+#include "network_helpers.h"
#define BIND_PORT 1234
#define CONNECT_PORT 4321
@@ -73,30 +74,6 @@ configure_stack(void)
return true;
}
-static int
-start_server(const struct sockaddr *addr, socklen_t len, int type)
-{
- int fd;
-
- fd = socket(addr->sa_family, type, 0);
- if (CHECK_FAIL(fd == -1))
- goto out;
- if (CHECK_FAIL(setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &timeo_sec,
- timeo_optlen)))
- goto close_out;
- if (CHECK_FAIL(bind(fd, addr, len) == -1))
- goto close_out;
- if (type == SOCK_STREAM && CHECK_FAIL(listen(fd, 128) == -1))
- goto close_out;
-
- goto out;
-close_out:
- close(fd);
- fd = -1;
-out:
- return fd;
-}
-
static int
connect_to_server(const struct sockaddr *addr, socklen_t len, int type)
{
@@ -302,15 +279,15 @@ void test_sk_assign(void)
for (i = 0; i < ARRAY_SIZE(tests) && !READ_ONCE(stop); i++) {
struct test_sk_cfg *test = &tests[i];
- const struct sockaddr *addr;
+ const struct sockaddr_storage *addr;
const int zero = 0;
int err;
if (!test__start_subtest(test->name))
continue;
prepare_addr(test->addr, test->family, BIND_PORT, false);
- addr = (const struct sockaddr *)test->addr;
- server = start_server(addr, test->len, test->type);
+ addr = (const struct sockaddr_storage *)test->addr;
+ server = start_server_addr(test->type, addr, test->len);
if (server == -1)
goto close;
@@ -323,7 +300,7 @@ void test_sk_assign(void)
/* connect to unbound ports */
prepare_addr(test->addr, test->family, CONNECT_PORT,
test->rewrite_addr);
- if (run_test(server, addr, test->len, test->type))
+ if (run_test(server, test->addr, test->len, test->type))
goto close;
close(server);