Skip to content

Commit

Permalink
selftests/bpf: Use connect_fd_to_fd in sk_lookup
Browse files Browse the repository at this point in the history
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: Geliang Tang <[email protected]>
Link: https://lore.kernel.org/r/7077c277cde5a1864cdc244727162fb75c8bb9c5.1720515893.git.tanggeliang@kylinos.cn
Signed-off-by: Martin KaFai Lau <[email protected]>
  • Loading branch information
Geliang Tang authored and Martin KaFai Lau committed Jul 10, 2024
1 parent d9810c4 commit 9004054
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions tools/testing/selftests/bpf/prog_tests/sk_lookup.c
Original file line number Diff line number Diff line change
Expand Up @@ -633,22 +633,16 @@ static void run_lookup_prog(const struct test *t)
* BPF socket lookup.
*/
if (t->reuseport_has_conns) {
struct sockaddr_storage addr = {};
socklen_t len = sizeof(addr);

/* Add an extra socket to reuseport group */
reuse_conn_fd = make_server(t->sotype, t->listen_at.ip,
t->listen_at.port,
t->reuseport_prog);
if (reuse_conn_fd < 0)
goto close;

/* Connect the extra socket to itself */
err = getsockname(reuse_conn_fd, (void *)&addr, &len);
if (CHECK(err, "getsockname", "errno %d\n", errno))
goto close;
err = connect(reuse_conn_fd, (void *)&addr, len);
if (CHECK(err, "connect", "errno %d\n", errno))
/* Connect the extra socket to itself */
err = connect_fd_to_fd(reuse_conn_fd, reuse_conn_fd, 0);
if (!ASSERT_OK(err, "connect_fd_to_fd"))
goto close;
}

Expand Down

0 comments on commit 9004054

Please sign in to comment.