selftests/bpf: Add start_server_addr helper
In order to pair up with connect_to_addr(), this patch adds a new helper start_server_addr(), which is a wrapper of __start_server(). It accepts an argument 'addr' of 'struct sockaddr_storage' type instead of a string type argument like start_server(), and a network_helper_opts argument as the last one. Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn> Link: https://lore.kernel.org/r/2f01d48fa026467926738debe554ac452c19b86f.1713427236.git.tanggeliang@kylinos.cn Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
This commit is contained in:
parent
462e5e2a59
commit
9c598a83b7
@ -52,6 +52,8 @@ struct ipv6_packet pkt_v6 = {
|
||||
.tcp.doff = 5,
|
||||
};
|
||||
|
||||
static const struct network_helper_opts default_opts;
|
||||
|
||||
int settimeo(int fd, int timeout_ms)
|
||||
{
|
||||
struct timeval timeout = { .tv_sec = 3 };
|
||||
@ -185,6 +187,16 @@ close_fds:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int start_server_addr(int type, const struct sockaddr_storage *addr, socklen_t len,
|
||||
const struct network_helper_opts *opts)
|
||||
{
|
||||
if (!opts)
|
||||
opts = &default_opts;
|
||||
|
||||
return __start_server(type, 0, (struct sockaddr *)addr, len,
|
||||
opts->timeout_ms, 0);
|
||||
}
|
||||
|
||||
void free_fds(int *fds, unsigned int nr_close_fds)
|
||||
{
|
||||
if (fds) {
|
||||
@ -278,8 +290,6 @@ error_close:
|
||||
return -1;
|
||||
}
|
||||
|
||||
static const struct network_helper_opts default_opts;
|
||||
|
||||
int connect_to_fd_opts(int server_fd, const struct network_helper_opts *opts)
|
||||
{
|
||||
struct sockaddr_storage addr;
|
||||
|
@ -53,6 +53,8 @@ int start_mptcp_server(int family, const char *addr, __u16 port,
|
||||
int *start_reuseport_server(int family, int type, const char *addr_str,
|
||||
__u16 port, int timeout_ms,
|
||||
unsigned int nr_listens);
|
||||
int start_server_addr(int type, const struct sockaddr_storage *addr, socklen_t len,
|
||||
const struct network_helper_opts *opts);
|
||||
void free_fds(int *fds, unsigned int nr_close_fds);
|
||||
int connect_to_addr(const struct sockaddr_storage *addr, socklen_t len, int type);
|
||||
int connect_to_fd(int server_fd, int timeout_ms);
|
||||
|
Loading…
x
Reference in New Issue
Block a user