[PATCH bpf-next 05/15] selftests/bpf: Add send_to_addr_str helper

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Geliang Tang <tanggeliang@xxxxxxxxxx>

Similar to network helper connect_to_addr_str(), this patch adds a new
helper send_to_addr_str(). It uses make_sockaddr() to make a
sockaddr_storage type address from the "family", "addr_str" and "port"
parameters and passes it to send_to_addr().

Signed-off-by: Geliang Tang <tanggeliang@xxxxxxxxxx>
---
 tools/testing/selftests/bpf/network_helpers.c | 16 ++++++++++++++++
 tools/testing/selftests/bpf/network_helpers.h |  3 +++
 2 files changed, 19 insertions(+)

diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c
index 311c3a559414..a6c158718267 100644
--- a/tools/testing/selftests/bpf/network_helpers.c
+++ b/tools/testing/selftests/bpf/network_helpers.c
@@ -229,6 +229,22 @@ static int send_to_addr(int type, const void *data, size_t datalen, int flags,
 	return fd;
 }
 
+int send_to_addr_str(int family, int type, const char *addr_str, __u16 port,
+		     const void *data, size_t datalen, int flags,
+		     const struct network_helper_opts *opts)
+{
+	struct sockaddr_storage addr;
+	socklen_t addrlen;
+
+	if (!opts)
+		opts = &default_opts;
+
+	if (make_sockaddr(family, addr_str, port, &addr, &addrlen))
+		return -1;
+
+	return send_to_addr(type, data, datalen, flags, &addr, addrlen, opts);
+}
+
 int send_to_fd_opts(int server_fd, const void *data, size_t datalen, int flags,
 		    const struct network_helper_opts *opts)
 {
diff --git a/tools/testing/selftests/bpf/network_helpers.h b/tools/testing/selftests/bpf/network_helpers.h
index 19210a234bc1..ebed1fb1bd49 100644
--- a/tools/testing/selftests/bpf/network_helpers.h
+++ b/tools/testing/selftests/bpf/network_helpers.h
@@ -76,6 +76,9 @@ int connect_to_fd_opts(int server_fd, const struct network_helper_opts *opts);
 int connect_fd_to_fd(int client_fd, int server_fd, int timeout_ms);
 int send_to_fd_opts(int server_fd, const void *data, size_t datalen, int flags,
 		    const struct network_helper_opts *opts);
+int send_to_addr_str(int family, int type, const char *addr_str, __u16 port,
+		     const void *data, size_t datalen, int flags,
+		     const struct network_helper_opts *opts);
 int fastopen_connect(int server_fd, const char *data, unsigned int data_len,
 		     int timeout_ms);
 int make_sockaddr(int family, const char *addr_str, __u16 port,
-- 
2.43.0





[Index of Archives]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]

  Powered by Linux