Commit 63a51820 authored by Geliang Tang's avatar Geliang Tang Committed by Martin KaFai Lau

selftests/bpf: Use connect_to_addr in sk_assign

This patch uses public helper connect_to_addr() exported in
network_helpers.h instead of the local defined function connect_to_server()
in prog_tests/sk_assign.c. This can avoid duplicate code.

The code that sets SO_SNDTIMEO timeout as timeo_sec (3s) can be dropped,
since connect_to_addr() sets default timeout as 3s.
Signed-off-by: default avatarGeliang Tang <tanggeliang@kylinos.cn>
Link: https://lore.kernel.org/r/98fdd384872bda10b2adb052e900a2212c9047b9.1713427236.git.tanggeliang@kylinos.cnSigned-off-by: default avatarMartin KaFai Lau <martin.lau@kernel.org>
parent 805b4d90
...@@ -23,8 +23,6 @@ ...@@ -23,8 +23,6 @@
#define NS_SELF "/proc/self/ns/net" #define NS_SELF "/proc/self/ns/net"
#define SERVER_MAP_PATH "/sys/fs/bpf/tc/globals/server_map" #define SERVER_MAP_PATH "/sys/fs/bpf/tc/globals/server_map"
static const struct timeval timeo_sec = { .tv_sec = 3 };
static const size_t timeo_optlen = sizeof(timeo_sec);
static int stop, duration; static int stop, duration;
static bool static bool
...@@ -74,28 +72,6 @@ configure_stack(void) ...@@ -74,28 +72,6 @@ configure_stack(void)
return true; return true;
} }
static int
connect_to_server(const struct sockaddr *addr, socklen_t len, int type)
{
int fd = -1;
fd = socket(addr->sa_family, type, 0);
if (CHECK_FAIL(fd == -1))
goto out;
if (CHECK_FAIL(setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, &timeo_sec,
timeo_optlen)))
goto close_out;
if (CHECK_FAIL(connect(fd, addr, len)))
goto close_out;
goto out;
close_out:
close(fd);
fd = -1;
out:
return fd;
}
static in_port_t static in_port_t
get_port(int fd) get_port(int fd)
{ {
...@@ -138,7 +114,7 @@ run_test(int server_fd, const struct sockaddr *addr, socklen_t len, int type) ...@@ -138,7 +114,7 @@ run_test(int server_fd, const struct sockaddr *addr, socklen_t len, int type)
in_port_t port; in_port_t port;
int ret = 1; int ret = 1;
client = connect_to_server(addr, len, type); client = connect_to_addr(type, (struct sockaddr_storage *)addr, len, NULL);
if (client == -1) { if (client == -1) {
perror("Cannot connect to server"); perror("Cannot connect to server");
goto out; goto out;
......
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