Commit 9c598a83 authored by Geliang Tang's avatar Geliang Tang Committed by Martin KaFai Lau

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: default avatarGeliang Tang <tanggeliang@kylinos.cn>
Link: https://lore.kernel.org/r/2f01d48fa026467926738debe554ac452c19b86f.1713427236.git.tanggeliang@kylinos.cnSigned-off-by: default avatarMartin KaFai Lau <martin.lau@kernel.org>
parent 462e5e2a
...@@ -52,6 +52,8 @@ struct ipv6_packet pkt_v6 = { ...@@ -52,6 +52,8 @@ struct ipv6_packet pkt_v6 = {
.tcp.doff = 5, .tcp.doff = 5,
}; };
static const struct network_helper_opts default_opts;
int settimeo(int fd, int timeout_ms) int settimeo(int fd, int timeout_ms)
{ {
struct timeval timeout = { .tv_sec = 3 }; struct timeval timeout = { .tv_sec = 3 };
...@@ -185,6 +187,16 @@ int *start_reuseport_server(int family, int type, const char *addr_str, ...@@ -185,6 +187,16 @@ int *start_reuseport_server(int family, int type, const char *addr_str,
return NULL; 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) void free_fds(int *fds, unsigned int nr_close_fds)
{ {
if (fds) { if (fds) {
...@@ -278,8 +290,6 @@ int connect_to_addr(const struct sockaddr_storage *addr, socklen_t addrlen, int ...@@ -278,8 +290,6 @@ int connect_to_addr(const struct sockaddr_storage *addr, socklen_t addrlen, int
return -1; return -1;
} }
static const struct network_helper_opts default_opts;
int connect_to_fd_opts(int server_fd, const struct network_helper_opts *opts) int connect_to_fd_opts(int server_fd, const struct network_helper_opts *opts)
{ {
struct sockaddr_storage addr; struct sockaddr_storage addr;
......
...@@ -53,6 +53,8 @@ int start_mptcp_server(int family, const char *addr, __u16 port, ...@@ -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, int *start_reuseport_server(int family, int type, const char *addr_str,
__u16 port, int timeout_ms, __u16 port, int timeout_ms,
unsigned int nr_listens); 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); 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_addr(const struct sockaddr_storage *addr, socklen_t len, int type);
int connect_to_fd(int server_fd, int timeout_ms); int connect_to_fd(int server_fd, int timeout_ms);
......
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