Commit 9004054b authored by Geliang Tang's avatar Geliang Tang Committed by Martin KaFai Lau

selftests/bpf: Use connect_fd_to_fd in sk_lookup

This patch uses public helper connect_fd_to_fd() exported in
network_helpers.h instead of using getsockname() + connect() in
run_lookup_prog() in prog_tests/sk_lookup.c. This can simplify
the code.
Signed-off-by: default avatarGeliang Tang <tanggeliang@kylinos.cn>
Link: https://lore.kernel.org/r/7077c277cde5a1864cdc244727162fb75c8bb9c5.1720515893.git.tanggeliang@kylinos.cnSigned-off-by: default avatarMartin KaFai Lau <martin.lau@kernel.org>
parent d9810c43
...@@ -633,9 +633,6 @@ static void run_lookup_prog(const struct test *t) ...@@ -633,9 +633,6 @@ static void run_lookup_prog(const struct test *t)
* BPF socket lookup. * BPF socket lookup.
*/ */
if (t->reuseport_has_conns) { if (t->reuseport_has_conns) {
struct sockaddr_storage addr = {};
socklen_t len = sizeof(addr);
/* Add an extra socket to reuseport group */ /* Add an extra socket to reuseport group */
reuse_conn_fd = make_server(t->sotype, t->listen_at.ip, reuse_conn_fd = make_server(t->sotype, t->listen_at.ip,
t->listen_at.port, t->listen_at.port,
...@@ -643,12 +640,9 @@ static void run_lookup_prog(const struct test *t) ...@@ -643,12 +640,9 @@ static void run_lookup_prog(const struct test *t)
if (reuse_conn_fd < 0) if (reuse_conn_fd < 0)
goto close; goto close;
/* Connect the extra socket to itself */ /* Connect the extra socket to itself */
err = getsockname(reuse_conn_fd, (void *)&addr, &len); err = connect_fd_to_fd(reuse_conn_fd, reuse_conn_fd, 0);
if (CHECK(err, "getsockname", "errno %d\n", errno)) if (!ASSERT_OK(err, "connect_fd_to_fd"))
goto close;
err = connect(reuse_conn_fd, (void *)&addr, len);
if (CHECK(err, "connect", "errno %d\n", errno))
goto close; goto close;
} }
......
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