Re: [PATCH bpf-next v2 2/4] selftests/bpf: Use start_server_addr in bpf_tcp_ca

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

 



On 5/14/24 9:20 PM, Geliang Tang wrote:
From: Geliang Tang <tanggeliang@xxxxxxxxxx>

This patch uses start_server_addr() in do_test() in prog_tests/bpf_tcp_ca.c
to accept a struct network_helper_opts argument instead of using
start_server() and settcpca(). Then change the type of the first paramenter
of do_test() into a struct network_helper_opts one.

Define its own opts for each test, set its own cc name into cb_opts.cc, and
cc_cb() into post_socket_cb callback, then pass it to do_test().

opts->cb_opts needs to be passed to post_socket_cb() in __start_server().

Signed-off-by: Geliang Tang <tanggeliang@xxxxxxxxxx>
---
  tools/testing/selftests/bpf/network_helpers.c |  2 +-
  .../selftests/bpf/prog_tests/bpf_tcp_ca.c     | 52 +++++++++++++++----
  2 files changed, 42 insertions(+), 12 deletions(-)

diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c
index d97f8a669b38..6864af665508 100644
--- a/tools/testing/selftests/bpf/network_helpers.c
+++ b/tools/testing/selftests/bpf/network_helpers.c
@@ -94,7 +94,7 @@ static int __start_server(int type, const struct sockaddr *addr, socklen_t addrl
  	if (settimeo(fd, opts->timeout_ms))
  		goto error_close;
- if (opts->post_socket_cb && opts->post_socket_cb(fd, NULL)) {
+	if (opts->post_socket_cb && opts->post_socket_cb(fd, &opts->cb_opts)) {
  		log_err("Failed to call post_socket_cb");
  		goto error_close;
  	}
diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c b/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c
index 9bc909fa0833..25961ce850cb 100644
--- a/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c
+++ b/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c
@@ -34,12 +34,18 @@ static int settcpca(int fd, const char *tcp_ca)
  	return 0;
  }
-static void do_test(const char *tcp_ca, const struct bpf_map *sk_stg_map)
+static void do_test(const struct network_helper_opts *opts,
+		    const struct bpf_map *sk_stg_map)
  {
+	struct sockaddr_storage addr;
  	int lfd = -1, fd = -1;
+	socklen_t addrlen;
  	int err;
- lfd = start_server(AF_INET6, SOCK_STREAM, NULL, 0, 0);
+	if (make_sockaddr(AF_INET6, NULL, 0, &addr, &addrlen))
+		return;
+
+	lfd = start_server_addr(SOCK_STREAM, &addr, addrlen, opts);

It is a tech debt that start_server does not take the "opts" argument.
It is pretty handy to have start_server as a helper that takes string address.

How about create a start_server_str() and start using it in this set. The other existing start_server() usages can be retired later.

int start_server_str(int family, int type, const char *addr, __u16 port,
		     const struct network_helper_opts *opts);





[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