Skip to content

Commit 5059c73

Browse files
Geliang TangMartin KaFai Lau
authored andcommitted
selftests/bpf: Use connect_to_fd in sockopt_inherit
This patch uses public helper connect_to_fd() exported in network_helpers.h instead of the local defined function connect_to_server() in prog_tests/sockopt_inherit.c. This can avoid duplicate code. Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn> Link: https://lore.kernel.org/r/71db79127cc160b0643fd9a12c70ae019ae076a1.1714907662.git.tanggeliang@kylinos.cn Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
1 parent 49e1fa8 commit 5059c73

1 file changed

Lines changed: 1 addition & 30 deletions

File tree

tools/testing/selftests/bpf/prog_tests/sockopt_inherit.c

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,35 +10,6 @@
1010
#define CUSTOM_INHERIT2 1
1111
#define CUSTOM_LISTENER 2
1212

13-
static int connect_to_server(int server_fd)
14-
{
15-
struct sockaddr_storage addr;
16-
socklen_t len = sizeof(addr);
17-
int fd;
18-
19-
fd = socket(AF_INET, SOCK_STREAM, 0);
20-
if (fd < 0) {
21-
log_err("Failed to create client socket");
22-
return -1;
23-
}
24-
25-
if (getsockname(server_fd, (struct sockaddr *)&addr, &len)) {
26-
log_err("Failed to get server addr");
27-
goto out;
28-
}
29-
30-
if (connect(fd, (const struct sockaddr *)&addr, len) < 0) {
31-
log_err("Fail to connect to server");
32-
goto out;
33-
}
34-
35-
return fd;
36-
37-
out:
38-
close(fd);
39-
return -1;
40-
}
41-
4213
static int verify_sockopt(int fd, int optname, const char *msg, char expected)
4314
{
4415
socklen_t optlen = 1;
@@ -164,7 +135,7 @@ static void run_test(int cgroup_fd)
164135
pthread_cond_wait(&server_started, &server_started_mtx);
165136
pthread_mutex_unlock(&server_started_mtx);
166137

167-
client_fd = connect_to_server(server_fd);
138+
client_fd = connect_to_fd(server_fd, 0);
168139
if (!ASSERT_GE(client_fd, 0, "connect_to_server"))
169140
goto close_server_fd;
170141

0 commit comments

Comments
 (0)