OSDN Git Service

selftests/bpf: Add connect_fd_to_fd, connect_wait net helpers
authorAndrey Ignatov <rdna@fb.com>
Thu, 14 May 2020 20:03:48 +0000 (13:03 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Fri, 15 May 2020 01:41:08 +0000 (18:41 -0700)
commit383724e17ab02d8e440def7792c4e151b13ef4d4
tree10dec16b5626e4108805d9ae34a56e5f0f5c1aef
parentf307fa2cb4c935f7f1ff0aeb880c7b44fb9a642b
selftests/bpf: Add connect_fd_to_fd, connect_wait net helpers

Add two new network helpers.

connect_fd_to_fd connects an already created client socket fd to address
of server fd. Sometimes it's useful to separate client socket creation
and connecting this socket to a server, e.g. if client socket has to be
created in a cgroup different from that of server cgroup.

Additionally connect_to_fd is now implemented using connect_fd_to_fd,
both helpers don't treat EINPROGRESS as an error and let caller decide
how to proceed with it.

connect_wait is a helper to work with non-blocking client sockets so
that if connect_to_fd or connect_fd_to_fd returned -1 with errno ==
EINPROGRESS, caller can wait for connect to finish or for connection
timeout. The helper returns -1 on error, 0 on timeout (1sec,
hard-coded), and positive number on success.

Signed-off-by: Andrey Ignatov <rdna@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Yonghong Song <yhs@fb.com>
Link: https://lore.kernel.org/bpf/1403fab72300f379ca97ead4820ae43eac4414ef.1589486450.git.rdna@fb.com
tools/testing/selftests/bpf/network_helpers.c
tools/testing/selftests/bpf/network_helpers.h