From patchwork Wed May 22 09:23:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13670642 X-Patchwork-Delegate: bpf@iogearbox.net Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E184B8060D; Wed, 22 May 2024 09:24:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716369848; cv=none; b=GeSLS6NEgjJxd3dvp7jfvNgYq2VNDVRiLbpmwWW0LigFguNPZEPLfwH1fJlhzQ377BoSit5pQzLiNfwuLmocQtexxfe+yejY1qapopFzVjBRyFleLJOIMx2Q7usVvA655+hm3twUpw084GQiwrGvBhl/+d8+FFGFXTFzZ7ye+c4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716369848; c=relaxed/simple; bh=z/rJWlSUZ4/YuGyhiu6hcQQN4WWNf6a84wS8YU3ikvI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rO4FlTx4oFnsYOYuLt561aX3eLWsjfkvWYlWzykBLlmPGmE0IRUwj5iIKQUx/ZwZKCfDZ2dgS1q3lmraxH7fu3w1vtF0TUql7VFt5cPtr30v33G0VaxXDeR3CPzkTdQlKgZ+590a/SXByzHmdM4n552WKyGvPoq8uv954bsvi8M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=PLTUw4Rq; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="PLTUw4Rq" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6C803C4AF07; Wed, 22 May 2024 09:24:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716369847; bh=z/rJWlSUZ4/YuGyhiu6hcQQN4WWNf6a84wS8YU3ikvI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PLTUw4RqI3OwYclbij2g0e3wAOP2UpxQnsLpvY6FUjFXMZpwF5v+AWjzgsX/dCSZF +6XyyT90TPLV1WxA+DI4Q36KwqTvaQgpkSC3pXPxaVqnW1kQLsY7jcSMfFyC09e9g7 AjFAne2OU/hB/n+qfG2sLuCtJjiw/dzjY7irATVRidBpNMsn1t1j8Dl49vSCnfAGdj Nwc0Am/zY1n+sS1elfNmp2Pwmp9ELVvnFqJ0Pl4giAE/y+OoL+FSQD/J3NeltdjTYp 000MKDyjYiHEeqjKS3cJjFbgHo/t0KU5cnwsWaadNMEsN4G8wsYV/Om7mUGi914kSB q7NXhCr6qti9A== From: Geliang Tang To: Andrii Nakryiko , Eduard Zingerman , Mykola Lysenko , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Shuah Khan Cc: Geliang Tang , bpf@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH bpf-next v3 1/8] selftests/bpf: Drop struct post_socket_opts Date: Wed, 22 May 2024 17:23:43 +0800 Message-ID: <532ae86cf0978107d6b9e80f682e0efd0a3515cb.1716369375.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net From: Geliang Tang It's not possible to have one generic/common "struct post_socket_opts" for all tests. It's better to have the individual test define its own callback opts struct. So this patch drops struct post_socket_opts, and changes the second parameter of post_socket_cb as "void *" type. Signed-off-by: Geliang Tang --- tools/testing/selftests/bpf/network_helpers.c | 2 +- tools/testing/selftests/bpf/network_helpers.h | 4 +--- tools/testing/selftests/bpf/prog_tests/sockopt_inherit.c | 2 +- tools/testing/selftests/bpf/test_tcp_check_syncookie_user.c | 4 ++-- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c index 35250e6cde7f..4d776b78929c 100644 --- a/tools/testing/selftests/bpf/network_helpers.c +++ b/tools/testing/selftests/bpf/network_helpers.c @@ -133,7 +133,7 @@ int start_server(int family, int type, const char *addr_str, __u16 port, return __start_server(type, (struct sockaddr *)&addr, addrlen, &opts); } -static int reuseport_cb(int fd, const struct post_socket_opts *opts) +static int reuseport_cb(int fd, void *opts) { int on = 1; diff --git a/tools/testing/selftests/bpf/network_helpers.h b/tools/testing/selftests/bpf/network_helpers.h index 883c7ea9d8d5..40011e0f584b 100644 --- a/tools/testing/selftests/bpf/network_helpers.h +++ b/tools/testing/selftests/bpf/network_helpers.h @@ -21,8 +21,6 @@ typedef __u16 __sum16; #define VIP_NUM 5 #define MAGIC_BYTES 123 -struct post_socket_opts {}; - struct network_helper_opts { const char *cc; int timeout_ms; @@ -30,7 +28,7 @@ struct network_helper_opts { bool noconnect; int type; int proto; - int (*post_socket_cb)(int fd, const struct post_socket_opts *opts); + int (*post_socket_cb)(int fd, void *opts); }; /* ipv4 test vector */ diff --git a/tools/testing/selftests/bpf/prog_tests/sockopt_inherit.c b/tools/testing/selftests/bpf/prog_tests/sockopt_inherit.c index 1d3a20f01b60..7cd8be2780ca 100644 --- a/tools/testing/selftests/bpf/prog_tests/sockopt_inherit.c +++ b/tools/testing/selftests/bpf/prog_tests/sockopt_inherit.c @@ -70,7 +70,7 @@ static void *server_thread(void *arg) return (void *)(long)err; } -static int custom_cb(int fd, const struct post_socket_opts *opts) +static int custom_cb(int fd, void *opts) { char buf; int err; diff --git a/tools/testing/selftests/bpf/test_tcp_check_syncookie_user.c b/tools/testing/selftests/bpf/test_tcp_check_syncookie_user.c index 7b5fc98838cd..aebc58c24dc5 100644 --- a/tools/testing/selftests/bpf/test_tcp_check_syncookie_user.c +++ b/tools/testing/selftests/bpf/test_tcp_check_syncookie_user.c @@ -139,14 +139,14 @@ static int run_test(int server_fd, int results_fd, bool xdp) return ret; } -static int v6only_true(int fd, const struct post_socket_opts *opts) +static int v6only_true(int fd, void *opts) { int mode = true; return setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &mode, sizeof(mode)); } -static int v6only_false(int fd, const struct post_socket_opts *opts) +static int v6only_false(int fd, void *opts) { int mode = false; From patchwork Wed May 22 09:23:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13670643 X-Patchwork-Delegate: bpf@iogearbox.net Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4BA9980BE5; Wed, 22 May 2024 09:24:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716369852; cv=none; b=NpBoznD6UZx9rX+YFKEpxw5T0ofs8rATZ3OKaHehtERKEt2aPvnJFREAxVCMujfNQguxUerGGhqE7eDMFJzwGZVVfcgRr2/ZjJVwLyhxESaCZP7X50NiCTiTdr5Il182zz7ZlwaN+DaNj3jNMwyV3k6xeSTe3Tk+hSsqIHrIspQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716369852; c=relaxed/simple; bh=aw4b+dSxu58yXyiIl+8w1U5H7G3nx61BwulciyQj4jg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rufBy1jzM2DpO5SMBa/D/n1rxzGjv+0Ti/2GRiwnSaZ6DTame3s9iHcuy54QU/+1VB68JtIdgIQoL6NH7qy/qrPlZm8NtzPBf1b8ToeGPaPk4dy7+7gVbDJwua7rPjbeHKXA7Hsg7VK879sHiVpNdp3yClThqf+wT7WREZQ09aY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qnPGESlu; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="qnPGESlu" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F176DC32781; Wed, 22 May 2024 09:24:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716369852; bh=aw4b+dSxu58yXyiIl+8w1U5H7G3nx61BwulciyQj4jg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qnPGESlux6DZLdL0FXxG+5amQAxZRApbI/sAIu5KAhe4oJE8rH0dBn4bZzjPd00EH gyU0h6Okj/OtVf/71pWikgqYzYeu4eisQPri3gtoRR1MGt5329R4NMU5gFskmIftHP UYYD77rrwwWAqLNvo4crlfFla72DtjzV9LVfk0VhWrVoHf6kWaJr3F0Uj8VYyuU3Qr PGO68EVTxTg6Qx7/SqFMmINxy53ihwh99yxw48/gU6CdMLyjypiTNc54tt/wCXEBzr HPMbsBw9/89PeJKtQKSDbNr/XXXLd41mXjueoWVbUJOz4Ispg04F+QT0BJqdWaquaT lXLGH7bYlOtmA== From: Geliang Tang To: Andrii Nakryiko , Eduard Zingerman , Mykola Lysenko , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Shuah Khan Cc: Geliang Tang , bpf@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH bpf-next v3 2/8] selftests/bpf: Drop type parameter of start_server_addr Date: Wed, 22 May 2024 17:23:44 +0800 Message-ID: <65dd42dd91d678740e9c05e32852f5e01ba2b7bc.1716369375.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net From: Geliang Tang Since "type" is a struct member of network_helper_opts, it makes sense to drop the "type" parameter of start_server_addr() and __start_server() helpers, using opts->type instead in the helpers. If no network_helper_opts is set, use SOCK_STREAM as default socket type. Signed-off-by: Geliang Tang --- tools/testing/selftests/bpf/network_helpers.c | 15 +++++++++------ tools/testing/selftests/bpf/network_helpers.h | 2 +- .../selftests/bpf/prog_tests/cls_redirect.c | 5 ++++- tools/testing/selftests/bpf/prog_tests/mptcp.c | 2 +- .../testing/selftests/bpf/prog_tests/sk_assign.c | 8 +++++--- .../selftests/bpf/prog_tests/sockopt_inherit.c | 2 +- .../selftests/bpf/test_tcp_check_syncookie_user.c | 6 +++--- 7 files changed, 24 insertions(+), 16 deletions(-) diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c index 4d776b78929c..129ac90e4528 100644 --- a/tools/testing/selftests/bpf/network_helpers.c +++ b/tools/testing/selftests/bpf/network_helpers.c @@ -80,9 +80,10 @@ int settimeo(int fd, int timeout_ms) #define save_errno_close(fd) ({ int __save = errno; close(fd); errno = __save; }) -static int __start_server(int type, const struct sockaddr *addr, socklen_t addrlen, +static int __start_server(const struct sockaddr *addr, socklen_t addrlen, const struct network_helper_opts *opts) { + int type = opts->type ? : SOCK_STREAM; int fd; fd = socket(addr->sa_family, type, opts->proto); @@ -122,6 +123,7 @@ int start_server(int family, int type, const char *addr_str, __u16 port, int timeout_ms) { struct network_helper_opts opts = { + .type = type, .timeout_ms = timeout_ms, }; struct sockaddr_storage addr; @@ -130,7 +132,7 @@ int start_server(int family, int type, const char *addr_str, __u16 port, if (make_sockaddr(family, addr_str, port, &addr, &addrlen)) return -1; - return __start_server(type, (struct sockaddr *)&addr, addrlen, &opts); + return __start_server((struct sockaddr *)&addr, addrlen, &opts); } static int reuseport_cb(int fd, void *opts) @@ -144,6 +146,7 @@ int *start_reuseport_server(int family, int type, const char *addr_str, __u16 port, int timeout_ms, unsigned int nr_listens) { struct network_helper_opts opts = { + .type = type, .timeout_ms = timeout_ms, .post_socket_cb = reuseport_cb, }; @@ -162,7 +165,7 @@ int *start_reuseport_server(int family, int type, const char *addr_str, if (!fds) return NULL; - fds[0] = __start_server(type, (struct sockaddr *)&addr, addrlen, &opts); + fds[0] = __start_server((struct sockaddr *)&addr, addrlen, &opts); if (fds[0] == -1) goto close_fds; nr_fds = 1; @@ -171,7 +174,7 @@ int *start_reuseport_server(int family, int type, const char *addr_str, goto close_fds; for (; nr_fds < nr_listens; nr_fds++) { - fds[nr_fds] = __start_server(type, (struct sockaddr *)&addr, addrlen, &opts); + fds[nr_fds] = __start_server((struct sockaddr *)&addr, addrlen, &opts); if (fds[nr_fds] == -1) goto close_fds; } @@ -183,13 +186,13 @@ int *start_reuseport_server(int family, int type, const char *addr_str, return NULL; } -int start_server_addr(int type, const struct sockaddr_storage *addr, socklen_t len, +int start_server_addr(const struct sockaddr_storage *addr, socklen_t len, const struct network_helper_opts *opts) { if (!opts) opts = &default_opts; - return __start_server(type, (struct sockaddr *)addr, len, opts); + return __start_server((struct sockaddr *)addr, len, opts); } void free_fds(int *fds, unsigned int nr_close_fds) diff --git a/tools/testing/selftests/bpf/network_helpers.h b/tools/testing/selftests/bpf/network_helpers.h index 40011e0f584b..9de84a8d00fd 100644 --- a/tools/testing/selftests/bpf/network_helpers.h +++ b/tools/testing/selftests/bpf/network_helpers.h @@ -53,7 +53,7 @@ int start_server(int family, int type, 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, +int start_server_addr(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(int type, const struct sockaddr_storage *addr, socklen_t len, diff --git a/tools/testing/selftests/bpf/prog_tests/cls_redirect.c b/tools/testing/selftests/bpf/prog_tests/cls_redirect.c index 34b59f6baca1..53b81651a6fa 100644 --- a/tools/testing/selftests/bpf/prog_tests/cls_redirect.c +++ b/tools/testing/selftests/bpf/prog_tests/cls_redirect.c @@ -62,11 +62,14 @@ static bool fill_addr_port(const struct sockaddr *sa, struct addr_port *ap) static bool set_up_conn(const struct sockaddr *addr, socklen_t len, int type, int *server, int *conn, struct tuple *tuple) { + struct network_helper_opts opts = { + .type = type, + }; struct sockaddr_storage ss; socklen_t slen = sizeof(ss); struct sockaddr *sa = (struct sockaddr *)&ss; - *server = start_server_addr(type, (struct sockaddr_storage *)addr, len, NULL); + *server = start_server_addr((struct sockaddr_storage *)addr, len, &opts); if (*server < 0) return false; diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing/selftests/bpf/prog_tests/mptcp.c index 4472aa404da0..eff1adf8cbc9 100644 --- a/tools/testing/selftests/bpf/prog_tests/mptcp.c +++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c @@ -110,7 +110,7 @@ static int start_mptcp_server(int family, const char *addr_str, __u16 port, if (make_sockaddr(family, addr_str, port, &addr, &addrlen)) return -1; - return start_server_addr(SOCK_STREAM, &addr, addrlen, &opts); + return start_server_addr(&addr, addrlen, &opts); } static int verify_tsk(int map_fd, int client_fd) diff --git a/tools/testing/selftests/bpf/prog_tests/sk_assign.c b/tools/testing/selftests/bpf/prog_tests/sk_assign.c index 0b9bd1d6f7cc..517d1186e386 100644 --- a/tools/testing/selftests/bpf/prog_tests/sk_assign.c +++ b/tools/testing/selftests/bpf/prog_tests/sk_assign.c @@ -255,6 +255,9 @@ void test_sk_assign(void) for (i = 0; i < ARRAY_SIZE(tests) && !READ_ONCE(stop); i++) { struct test_sk_cfg *test = &tests[i]; + struct network_helper_opts opts = { + .type = test->type, + }; const struct sockaddr *addr; const int zero = 0; int err; @@ -263,9 +266,8 @@ void test_sk_assign(void) continue; prepare_addr(test->addr, test->family, BIND_PORT, false); addr = (const struct sockaddr *)test->addr; - server = start_server_addr(test->type, - (const struct sockaddr_storage *)addr, - test->len, NULL); + server = start_server_addr((const struct sockaddr_storage *)addr, + test->len, &opts); if (server == -1) goto close; diff --git a/tools/testing/selftests/bpf/prog_tests/sockopt_inherit.c b/tools/testing/selftests/bpf/prog_tests/sockopt_inherit.c index 7cd8be2780ca..d2b2e0924bc4 100644 --- a/tools/testing/selftests/bpf/prog_tests/sockopt_inherit.c +++ b/tools/testing/selftests/bpf/prog_tests/sockopt_inherit.c @@ -121,7 +121,7 @@ static void run_test(int cgroup_fd) if (!ASSERT_OK_PTR(link_setsockopt, "cg-attach-setsockopt")) goto close_bpf_object; - server_fd = start_server_addr(SOCK_STREAM, (struct sockaddr_storage *)&addr, + server_fd = start_server_addr((struct sockaddr_storage *)&addr, sizeof(addr), &opts); if (!ASSERT_GE(server_fd, 0, "start_server")) goto close_bpf_object; diff --git a/tools/testing/selftests/bpf/test_tcp_check_syncookie_user.c b/tools/testing/selftests/bpf/test_tcp_check_syncookie_user.c index aebc58c24dc5..6265f44ae3a4 100644 --- a/tools/testing/selftests/bpf/test_tcp_check_syncookie_user.c +++ b/tools/testing/selftests/bpf/test_tcp_check_syncookie_user.c @@ -197,19 +197,19 @@ int main(int argc, char **argv) addr6dual.sin6_addr = in6addr_any; addr6dual.sin6_port = 0; - server = start_server_addr(SOCK_STREAM, (struct sockaddr_storage *)&addr4, + server = start_server_addr((struct sockaddr_storage *)&addr4, sizeof(addr4), NULL); if (server == -1) goto err; opts.post_socket_cb = v6only_true; - server_v6 = start_server_addr(SOCK_STREAM, (struct sockaddr_storage *)&addr6, + server_v6 = start_server_addr((struct sockaddr_storage *)&addr6, sizeof(addr6), &opts); if (server_v6 == -1) goto err; opts.post_socket_cb = v6only_false; - server_dual = start_server_addr(SOCK_STREAM, (struct sockaddr_storage *)&addr6dual, + server_dual = start_server_addr((struct sockaddr_storage *)&addr6dual, sizeof(addr6dual), &opts); if (server_dual == -1) goto err; From patchwork Wed May 22 09:23:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13670644 X-Patchwork-Delegate: bpf@iogearbox.net Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 556B280628; Wed, 22 May 2024 09:24:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716369857; cv=none; b=eQd0aXGma30eGqTE/kNhZY1ioKhcjoeft4N1wqsdJEBMG+NjWvDcmFFyjJGTVVqe0bKtmpn9DB0Kh7//8eRmqbM6IkC+VpSrH8+cp+60hTfG7RiAdlciQJ2mnZeO7jBilmwObXMWXeVMF6++E7+t29YOLu8/6MrsneXwLxBxvPc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716369857; c=relaxed/simple; bh=S/fDyRS/qFaLSf3W47dPHYaUIN1UVdtWS1DjVLUGGMY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pKl2SaODwCbRkt/4aAI9uYClBEoI2Nbxi4mYXfH/tyFUrnk5atRL1NGjf0p7FQBXFIRG3z69FMW8ICrJyYbUxBWm0Kb1hTejDGhe8gp1Dl/LyL0C8vl/t+SAxmoSVePzIfnxxEBozfTAWk1uRDyT1sVXhxgm2J/UjU2ZLnoSnMs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=rWtPhZv5; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="rWtPhZv5" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B0B62C4AF07; Wed, 22 May 2024 09:24:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716369856; bh=S/fDyRS/qFaLSf3W47dPHYaUIN1UVdtWS1DjVLUGGMY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rWtPhZv5JE/bfXW0sE2/pzyAhpejRLf6vl73zBka2PhqwFup7001S8apU2reQ555H FsaDpBI41SRbGxksVml2UrfIEmpq1OL5moSMXLDqhhfqbPzb2HSQ0Y4UNdctP25e/b wMgooEWDllXapfPrDPGDHEEWLHQemGR8eUEhIEbVRM6d7ymVEDYjjD/EgHKDGNNVdC L2G+eAp019q0YEdd6Pu/+Ec2S0fNTgF7FuaKthuotx1N091ibsVlKIWvA0l+GYaseK BsVfSRs6b0Df7zc+Wb/aEEL+kEjvuFIcEttMP4fwMNli6UwCkQ/lakihyaVRT//6CV 0q1HSDm0aCT8Q== From: Geliang Tang To: Andrii Nakryiko , Eduard Zingerman , Mykola Lysenko , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Shuah Khan Cc: Geliang Tang , bpf@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH bpf-next v3 3/8] selftests/bpf: Drop type parameter of connect_to_addr Date: Wed, 22 May 2024 17:23:45 +0800 Message-ID: <3a0ac6ce2cfd09df244dff1766af57861bc7598c.1716369375.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net From: Geliang Tang Since "type" is a struct member of network_helper_opts, it makes sense to drop the "type" parameter of connect_to_addr() helper, using opts->type instead in this helper. If no network_helper_opts is set, use SOCK_STREAM as default socket type. Signed-off-by: Geliang Tang --- tools/testing/selftests/bpf/network_helpers.c | 4 ++-- tools/testing/selftests/bpf/network_helpers.h | 2 +- .../selftests/bpf/prog_tests/cls_redirect.c | 2 +- .../selftests/bpf/prog_tests/sk_assign.c | 5 +++- .../selftests/bpf/prog_tests/sock_addr.c | 23 ++++++++++++------- 5 files changed, 23 insertions(+), 13 deletions(-) diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c index 129ac90e4528..49e807ffcccb 100644 --- a/tools/testing/selftests/bpf/network_helpers.c +++ b/tools/testing/selftests/bpf/network_helpers.c @@ -268,7 +268,7 @@ static int connect_fd_to_addr(int fd, return 0; } -int connect_to_addr(int type, const struct sockaddr_storage *addr, socklen_t addrlen, +int connect_to_addr(const struct sockaddr_storage *addr, socklen_t addrlen, const struct network_helper_opts *opts) { int fd; @@ -276,7 +276,7 @@ int connect_to_addr(int type, const struct sockaddr_storage *addr, socklen_t add if (!opts) opts = &default_opts; - fd = socket(addr->ss_family, type, opts->proto); + fd = socket(addr->ss_family, opts->type ? : SOCK_STREAM, opts->proto); if (fd < 0) { log_err("Failed to create client socket"); return -1; diff --git a/tools/testing/selftests/bpf/network_helpers.h b/tools/testing/selftests/bpf/network_helpers.h index 9de84a8d00fd..c925c771bd98 100644 --- a/tools/testing/selftests/bpf/network_helpers.h +++ b/tools/testing/selftests/bpf/network_helpers.h @@ -56,7 +56,7 @@ int *start_reuseport_server(int family, int type, const char *addr_str, int start_server_addr(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(int type, const struct sockaddr_storage *addr, socklen_t len, +int connect_to_addr(const struct sockaddr_storage *addr, socklen_t len, const struct network_helper_opts *opts); int connect_to_fd(int server_fd, int timeout_ms); int connect_to_fd_opts(int server_fd, const struct network_helper_opts *opts); diff --git a/tools/testing/selftests/bpf/prog_tests/cls_redirect.c b/tools/testing/selftests/bpf/prog_tests/cls_redirect.c index 53b81651a6fa..1f1b9f0c2ffc 100644 --- a/tools/testing/selftests/bpf/prog_tests/cls_redirect.c +++ b/tools/testing/selftests/bpf/prog_tests/cls_redirect.c @@ -76,7 +76,7 @@ static bool set_up_conn(const struct sockaddr *addr, socklen_t len, int type, if (CHECK_FAIL(getsockname(*server, sa, &slen))) goto close_server; - *conn = connect_to_addr(type, (struct sockaddr_storage *)sa, slen, NULL); + *conn = connect_to_addr((struct sockaddr_storage *)sa, slen, &opts); if (*conn < 0) goto close_server; diff --git a/tools/testing/selftests/bpf/prog_tests/sk_assign.c b/tools/testing/selftests/bpf/prog_tests/sk_assign.c index 517d1186e386..91f65b407f3a 100644 --- a/tools/testing/selftests/bpf/prog_tests/sk_assign.c +++ b/tools/testing/selftests/bpf/prog_tests/sk_assign.c @@ -109,12 +109,15 @@ rcv_msg(int srv_client, int type) static int run_test(int server_fd, const struct sockaddr *addr, socklen_t len, int type) { + struct network_helper_opts opts = { + .type = type, + }; int client = -1, srv_client = -1; char buf[] = "testing"; in_port_t port; int ret = 1; - client = connect_to_addr(type, (struct sockaddr_storage *)addr, len, NULL); + client = connect_to_addr((struct sockaddr_storage *)addr, len, &opts); if (client == -1) { perror("Cannot connect to server"); goto out; diff --git a/tools/testing/selftests/bpf/prog_tests/sock_addr.c b/tools/testing/selftests/bpf/prog_tests/sock_addr.c index b880c564a204..244686d582cb 100644 --- a/tools/testing/selftests/bpf/prog_tests/sock_addr.c +++ b/tools/testing/selftests/bpf/prog_tests/sock_addr.c @@ -224,12 +224,12 @@ static int kernel_getpeername(int fd, struct sockaddr *addr, socklen_t *addrlen) return sock_addr_op("kernel_getpeername", addr, addrlen, true); } -int kernel_connect_to_addr(int type, const struct sockaddr_storage *addr, socklen_t addrlen, +int kernel_connect_to_addr(const struct sockaddr_storage *addr, socklen_t addrlen, const struct network_helper_opts *opts) { int err; - if (!ASSERT_OK(kernel_init_sock(addr->ss_family, type, 0), + if (!ASSERT_OK(kernel_init_sock(addr->ss_family, opts->type, 0), "kernel_init_sock")) goto err; @@ -278,7 +278,7 @@ int kernel_start_server(int family, int type, const char *addr_str, __u16 port, } struct sock_ops { - int (*connect_to_addr)(int type, const struct sockaddr_storage *addr, + int (*connect_to_addr)(const struct sockaddr_storage *addr, socklen_t addrlen, const struct network_helper_opts *opts); int (*start_server)(int family, int type, const char *addr_str, @@ -2284,6 +2284,9 @@ static int test_bind(struct sock_addr_test *test) { struct sockaddr_storage expected_addr; socklen_t expected_addr_len = sizeof(struct sockaddr_storage); + struct network_helper_opts opts = { + .type = test->socket_type, + }; int serv = -1, client = -1, err; serv = test->ops->start_server(test->socket_family, test->socket_type, @@ -2306,7 +2309,7 @@ static int test_bind(struct sock_addr_test *test) goto cleanup; /* Try to connect to server just in case */ - client = connect_to_addr(test->socket_type, &expected_addr, expected_addr_len, NULL); + client = connect_to_addr(&expected_addr, expected_addr_len, &opts); if (!ASSERT_GE(client, 0, "connect_to_addr")) goto cleanup; @@ -2327,6 +2330,9 @@ static int test_connect(struct sock_addr_test *test) socklen_t addr_len = sizeof(struct sockaddr_storage), expected_addr_len = sizeof(struct sockaddr_storage), expected_src_addr_len = sizeof(struct sockaddr_storage); + struct network_helper_opts opts = { + .type = test->socket_type, + }; int serv = -1, client = -1, err; serv = start_server(test->socket_family, test->socket_type, @@ -2339,8 +2345,7 @@ static int test_connect(struct sock_addr_test *test) if (!ASSERT_EQ(err, 0, "make_sockaddr")) goto cleanup; - client = test->ops->connect_to_addr(test->socket_type, &addr, addr_len, - NULL); + client = test->ops->connect_to_addr(&addr, addr_len, &opts); if (client < 0) { err = errno; goto err; @@ -2519,6 +2524,9 @@ static int test_getpeername(struct sock_addr_test *test) struct sockaddr_storage addr, expected_addr; socklen_t addr_len = sizeof(struct sockaddr_storage), expected_addr_len = sizeof(struct sockaddr_storage); + struct network_helper_opts opts = { + .type = test->socket_type, + }; int serv = -1, client = -1, err; serv = start_server(test->socket_family, test->socket_type, @@ -2531,8 +2539,7 @@ static int test_getpeername(struct sock_addr_test *test) if (!ASSERT_EQ(err, 0, "make_sockaddr")) goto cleanup; - client = test->ops->connect_to_addr(test->socket_type, &addr, addr_len, - NULL); + client = test->ops->connect_to_addr(&addr, addr_len, &opts); if (!ASSERT_GE(client, 0, "connect_to_addr")) goto cleanup; From patchwork Wed May 22 09:23:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13670645 X-Patchwork-Delegate: bpf@iogearbox.net Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 946FB80C03; Wed, 22 May 2024 09:24:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716369861; cv=none; b=nekrY8UWotMXM9ILwUZtQwf/vTp2k/loJYOEh8Q928Nay7eSW6DxFDIux2enV7CsM8xz71+4maW1C3URYmsiAWPtz7sTDiCGuGMpzqJhBUon4sAPfHel69cm6fqJpSThdeaggnx2xAeVPZOXWUzx0pgkKZ0KkoArrv8gzS52JT0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716369861; c=relaxed/simple; bh=0yBmu5S5ncLuzNMn+4w/iLpPYelZ07NCKFaB4AGxemg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iARhnOq/wcFAd7/eQIxc7ACL0/N1/KMubYnrOIZ/UAMUq1HtTO/ri19XasbS7BRTkRFHcaOVHY9FgYQhS8JXsfbtJUqqHGJarxGHsXkpfJoKNw0q1Abl38hLa5Dvp26jpsdFLKBVlW43OGIsTeMJRKD0IbfUUvrGqduFNsilR6w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=aW4QyOBu; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="aW4QyOBu" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 61AE7C32781; Wed, 22 May 2024 09:24:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716369861; bh=0yBmu5S5ncLuzNMn+4w/iLpPYelZ07NCKFaB4AGxemg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aW4QyOBuMteAXpL+Wh8xt3a/7IQzX0h+PSw8x7JI+1Iu0+XYd6Lm4g+XlJ0HIfqhT 426GsKxkkNyg1Db+aWC56tcnhbpAGRkUdtlxkjJWf2+lmjLdH5ap3FVhFNkl3Wl4Xt 0dJxkL4P/cQv4aq6mlf6UPJZGSU86o+oRHF69wwTjI7szCiDzQzZ/oE/yP+NC+ebwi GxpnTw1h10GODmmJNFIgJgfLFn6aHYAec4vnx++mh5RuhWrXcUvDzGB4O2zggCw8ZU Ttt+54TqewGwwvyWmDIE6XLDSrDfN/5ic88fVX5BiipOc+GGm48Ow6kb6w8obgLel5 vUxQEc5WeWmlw== From: Geliang Tang To: Andrii Nakryiko , Eduard Zingerman , Mykola Lysenko , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Shuah Khan Cc: Geliang Tang , bpf@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH bpf-next v3 4/8] selftests/bpf: Add start_server_str helper Date: Wed, 22 May 2024 17:23:46 +0800 Message-ID: <8adde24c5e1637aee65f9dd8e9710a7ca8d3f930.1716369375.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net From: Geliang Tang It's a tech debt that start_server() does not take the "opts" argument. It's pretty handy to have start_server() as a helper that takes string address. So this patch creates a new helper start_server_str(). Then start_server() can be a wrapper of it. Signed-off-by: Geliang Tang --- tools/testing/selftests/bpf/network_helpers.c | 22 ++++++++++++++----- tools/testing/selftests/bpf/network_helpers.h | 2 ++ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c index 49e807ffcccb..ba80005d2d7a 100644 --- a/tools/testing/selftests/bpf/network_helpers.c +++ b/tools/testing/selftests/bpf/network_helpers.c @@ -119,6 +119,21 @@ static int __start_server(const struct sockaddr *addr, socklen_t addrlen, return -1; } +int start_server_str(int family, const char *addr_str, __u16 port, + 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 __start_server((struct sockaddr *)&addr, addrlen, opts); +} + int start_server(int family, int type, const char *addr_str, __u16 port, int timeout_ms) { @@ -126,13 +141,8 @@ int start_server(int family, int type, const char *addr_str, __u16 port, .type = type, .timeout_ms = timeout_ms, }; - struct sockaddr_storage addr; - socklen_t addrlen; - - if (make_sockaddr(family, addr_str, port, &addr, &addrlen)) - return -1; - return __start_server((struct sockaddr *)&addr, addrlen, &opts); + return start_server_str(family, addr_str, port, &opts); } static int reuseport_cb(int fd, void *opts) diff --git a/tools/testing/selftests/bpf/network_helpers.h b/tools/testing/selftests/bpf/network_helpers.h index c925c771bd98..d1d28d4f92bd 100644 --- a/tools/testing/selftests/bpf/network_helpers.h +++ b/tools/testing/selftests/bpf/network_helpers.h @@ -48,6 +48,8 @@ struct ipv6_packet { extern struct ipv6_packet pkt_v6; int settimeo(int fd, int timeout_ms); +int start_server_str(int family, const char *addr_str, __u16 port, + const struct network_helper_opts *opts); int start_server(int family, int type, const char *addr, __u16 port, int timeout_ms); int *start_reuseport_server(int family, int type, const char *addr_str, From patchwork Wed May 22 09:23:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13670646 X-Patchwork-Delegate: bpf@iogearbox.net Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7839C80BF8; Wed, 22 May 2024 09:24:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716369866; cv=none; b=nVI7hzJxblGKCfGYZ34vTbm84NSzFgjAEHvxmpk8QtIbmsd5jz9NcW5QSX+Gc5+0FuevMFAjZ8a0ovbvkEKzbkNuXVQSlWK9x7cmGuUc3T032zmMkJpJ90iO8G32Or9F/SadMAQiF5g1eC7WvYxME+PW15GV0Z9HMjZVt65zwAc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716369866; c=relaxed/simple; bh=RnkdV6dycMgmK7cMeR5oZeYT1Vjyur0S4P1x8cMxaLk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fNRKUSZAEOtTu4KtSXvnNI4LH7JkKhv8CN5gK/4KaRA6sUFLmN/99sDoTvX217Zzr1aLrjokXyALGH6P6kETzejDVGbayrfwevmS4KopCz/LWE1kNq79/ceKYqWNCgb32YyuTMoDwBrYDdIFL/8VQQxo6uVrMzbwZA7zBnKGpUI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=etf/SUSn; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="etf/SUSn" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F3898C4AF08; Wed, 22 May 2024 09:24:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716369866; bh=RnkdV6dycMgmK7cMeR5oZeYT1Vjyur0S4P1x8cMxaLk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=etf/SUSnV5YqDCpAWsV1PZ5obdPv24KUX5ArO1UQzIzkJl0h6E0p8ehsuWvOfgx9d DGDZhPMoqex4Vi9E2yPF9u2DHp6dfLCGq2HZBtoCbk/iYiJkuH6VPHEmTQCm5LTjAC I09VFSCxnD9RpPMGsJU9PvRpSMx6M2MTqvTPkEg1m1/0Hnj6diKGvRb9Hsm914Dw2J soARCj3hDS7hEPrwyKQNMZS+SA8MtbitrImMonkKgHqDkqUS+7yu8hbrrqGqiwJtFV OHnUfRneEY2ovnFKHJg2JkaLJ1syHnJVBxPJ705gfJMsNQLiXu66q7lPzpx0bDlw8T BmjOh/PlaGvGg== From: Geliang Tang To: Andrii Nakryiko , Eduard Zingerman , Mykola Lysenko , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Shuah Khan Cc: Geliang Tang , bpf@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH bpf-next v3 5/8] selftests/bpf: Use post_socket_cb in connect_to_fd_opts Date: Wed, 22 May 2024 17:23:47 +0800 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net From: Geliang Tang Since the post_socket_cb() callback is added in struct network_helper_opts, it's make sense to use it not only in __start_server(), but also in connect_to_fd_opts(). Then it can be used to set TCP_CONGESTION sockopt. Add a "void *" type member cb_opts into struct network_helper_opts, and add a new struct named cb_opts in prog_tests/bpf_tcp_ca.c, then cc can be moved into struct cb_opts from network_helper_opts. Define a new callback cc_cb() to set TCP_CONGESTION sockopt, and set it to post_socket_cb pointer. Signed-off-by: Geliang Tang --- tools/testing/selftests/bpf/network_helpers.c | 5 ++--- tools/testing/selftests/bpf/network_helpers.h | 2 +- .../selftests/bpf/prog_tests/bpf_tcp_ca.c | 18 +++++++++++++++++- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c index ba80005d2d7a..6f80c0285464 100644 --- a/tools/testing/selftests/bpf/network_helpers.c +++ b/tools/testing/selftests/bpf/network_helpers.c @@ -351,9 +351,8 @@ int connect_to_fd_opts(int server_fd, const struct network_helper_opts *opts) if (settimeo(fd, opts->timeout_ms)) goto error_close; - if (opts->cc && opts->cc[0] && - setsockopt(fd, SOL_TCP, TCP_CONGESTION, opts->cc, - strlen(opts->cc) + 1)) + if (opts->post_socket_cb && + opts->post_socket_cb(fd, opts->cb_opts)) goto error_close; if (!opts->noconnect) diff --git a/tools/testing/selftests/bpf/network_helpers.h b/tools/testing/selftests/bpf/network_helpers.h index d1d28d4f92bd..24c873963742 100644 --- a/tools/testing/selftests/bpf/network_helpers.h +++ b/tools/testing/selftests/bpf/network_helpers.h @@ -22,13 +22,13 @@ typedef __u16 __sum16; #define MAGIC_BYTES 123 struct network_helper_opts { - const char *cc; int timeout_ms; bool must_fail; bool noconnect; int type; int proto; int (*post_socket_cb)(int fd, void *opts); + void *cb_opts; }; /* ipv4 test vector */ 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 0aca02532794..c9dd2a3d3218 100644 --- a/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c +++ b/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c @@ -23,6 +23,10 @@ static const unsigned int total_bytes = 10 * 1024 * 1024; static int expected_stg = 0xeB9F; +struct cb_opts { + const char *cc; +}; + static int settcpca(int fd, const char *tcp_ca) { int err; @@ -81,6 +85,14 @@ static void do_test(const char *tcp_ca, const struct bpf_map *sk_stg_map) close(fd); } +static int cc_cb(int fd, void *opts) +{ + struct cb_opts *cb_opts = (struct cb_opts *)opts; + + return setsockopt(fd, SOL_TCP, TCP_CONGESTION, cb_opts->cc, + strlen(cb_opts->cc) + 1); +} + static void test_cubic(void) { struct bpf_cubic *cubic_skel; @@ -171,9 +183,13 @@ static void test_invalid_license(void) static void test_dctcp_fallback(void) { int err, lfd = -1, cli_fd = -1, srv_fd = -1; - struct network_helper_opts opts = { + struct cb_opts cb_opts = { .cc = "cubic", }; + struct network_helper_opts opts = { + .post_socket_cb = cc_cb, + .cb_opts = &cb_opts, + }; struct bpf_dctcp *dctcp_skel; struct bpf_link *link = NULL; char srv_cc[16]; From patchwork Wed May 22 09:23:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13670647 X-Patchwork-Delegate: bpf@iogearbox.net Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C7A4052F7A; Wed, 22 May 2024 09:24:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716369870; cv=none; b=h/2XhxJDWezuxMhtFcGpSSJHRVRK2lu1C8QNGGfKxtuRztmGkmueCZc13JaAiStkVAr1dSBcnRLXU+H9iHcezf4i8S2JiEQ++izY7gpfUhzaGu8lDP2sApV9Q7ogOBAOFVDh1rrWczajjM4XdmtfsvMfnhpiy/Id32ufFpIhVc4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716369870; c=relaxed/simple; bh=m3eJxMY93EofUeax/nDvC7+IU5f6NpmmZwJW3UpwAVk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nP5bZHZyW5UW88OkilRUYqJ3sfaRRQ5YJMyOs6NA8TdIQC3LGWtarwQEPlDlpWjyIm0bfc+8DgMUXWa2PfCrLaTp6y1Z6mLAhPAePhfqFm66YAqYMpyQBPjj64CueKa/5ffaGkF/l1BfHxLaKvOEdejwYaTm6ohXITwGQB5be9I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ILK+9PIB; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ILK+9PIB" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9FB96C2BD11; Wed, 22 May 2024 09:24:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716369870; bh=m3eJxMY93EofUeax/nDvC7+IU5f6NpmmZwJW3UpwAVk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ILK+9PIByLOp2pojkNaqyBVjlB/pDaiP5HiKOBK59+tlNdBJRK9o/756J3mNZoivg daOAHu5AvosEd7QwfAfwALhAC9AJxP49OR8P3f17hywEGUK4UW+n1kTEvbneBW+vXv BWf2Xt4CUUu15NYZB9J3yVZmTf7+7szOyrVwSq2pS+EB/rp2kOfqG6HoYG42F7Oc1H 2uOIzAd1phJB4DFhS6VCmHh9wq0jdc1x2wIhhD79Lei34qpS93w7XyN/Sh/EpQg/wc 9aa+ohGpxjO/nDV7eYfSZKJHd1kfUp6yg4NWJtWO0Fttv0S3kERaOaJtQM0+YZ+kvm 460dB3H59xdFg== From: Geliang Tang To: Andrii Nakryiko , Eduard Zingerman , Mykola Lysenko , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Shuah Khan Cc: Geliang Tang , bpf@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH bpf-next v3 6/8] selftests/bpf: Use start_server_str in bpf_tcp_ca Date: Wed, 22 May 2024 17:23:48 +0800 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net From: Geliang Tang This patch uses new helper start_server_str() in do_test() in 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 cb_opts and 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 --- tools/testing/selftests/bpf/network_helpers.c | 3 +- .../selftests/bpf/prog_tests/bpf_tcp_ca.c | 66 +++++++++++++++---- 2 files changed, 57 insertions(+), 12 deletions(-) diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c index 6f80c0285464..fae4add78f4d 100644 --- a/tools/testing/selftests/bpf/network_helpers.c +++ b/tools/testing/selftests/bpf/network_helpers.c @@ -95,7 +95,8 @@ static int __start_server(const struct sockaddr *addr, socklen_t addrlen, 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 c9dd2a3d3218..d37364c5beac 100644 --- a/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c +++ b/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c @@ -38,12 +38,14 @@ 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 cb_opts *co = (struct cb_opts *)opts->cb_opts; int lfd = -1, fd = -1; int err; - lfd = start_server(AF_INET6, SOCK_STREAM, NULL, 0, 0); + lfd = start_server_str(AF_INET6, NULL, 0, opts); if (!ASSERT_NEQ(lfd, -1, "socket")) return; @@ -53,7 +55,7 @@ static void do_test(const char *tcp_ca, const struct bpf_map *sk_stg_map) return; } - if (settcpca(lfd, tcp_ca) || settcpca(fd, tcp_ca)) + if (settcpca(fd, co->cc)) goto done; if (sk_stg_map) { @@ -95,6 +97,13 @@ static int cc_cb(int fd, void *opts) static void test_cubic(void) { + struct cb_opts cb_opts = { + .cc = "bpf_cubic", + }; + struct network_helper_opts opts = { + .post_socket_cb = cc_cb, + .cb_opts = &cb_opts, + }; struct bpf_cubic *cubic_skel; struct bpf_link *link; @@ -108,7 +117,7 @@ static void test_cubic(void) return; } - do_test("bpf_cubic", NULL); + do_test(&opts, NULL); ASSERT_EQ(cubic_skel->bss->bpf_cubic_acked_called, 1, "pkts_acked called"); @@ -118,6 +127,13 @@ static void test_cubic(void) static void test_dctcp(void) { + struct cb_opts cb_opts = { + .cc = "bpf_dctcp", + }; + struct network_helper_opts opts = { + .post_socket_cb = cc_cb, + .cb_opts = &cb_opts, + }; struct bpf_dctcp *dctcp_skel; struct bpf_link *link; @@ -131,7 +147,7 @@ static void test_dctcp(void) return; } - do_test("bpf_dctcp", dctcp_skel->maps.sk_stg_map); + do_test(&opts, dctcp_skel->maps.sk_stg_map); ASSERT_EQ(dctcp_skel->bss->stg_result, expected_stg, "stg_result"); bpf_link__destroy(link); @@ -313,6 +329,13 @@ static void test_unsupp_cong_op(void) static void test_update_ca(void) { + struct cb_opts cb_opts = { + .cc = "tcp_ca_update", + }; + struct network_helper_opts opts = { + .post_socket_cb = cc_cb, + .cb_opts = &cb_opts, + }; struct tcp_ca_update *skel; struct bpf_link *link; int saved_ca1_cnt; @@ -325,14 +348,14 @@ static void test_update_ca(void) link = bpf_map__attach_struct_ops(skel->maps.ca_update_1); ASSERT_OK_PTR(link, "attach_struct_ops"); - do_test("tcp_ca_update", NULL); + do_test(&opts, NULL); saved_ca1_cnt = skel->bss->ca1_cnt; ASSERT_GT(saved_ca1_cnt, 0, "ca1_ca1_cnt"); err = bpf_link__update_map(link, skel->maps.ca_update_2); ASSERT_OK(err, "update_map"); - do_test("tcp_ca_update", NULL); + do_test(&opts, NULL); ASSERT_EQ(skel->bss->ca1_cnt, saved_ca1_cnt, "ca2_ca1_cnt"); ASSERT_GT(skel->bss->ca2_cnt, 0, "ca2_ca2_cnt"); @@ -342,6 +365,13 @@ static void test_update_ca(void) static void test_update_wrong(void) { + struct cb_opts cb_opts = { + .cc = "tcp_ca_update", + }; + struct network_helper_opts opts = { + .post_socket_cb = cc_cb, + .cb_opts = &cb_opts, + }; struct tcp_ca_update *skel; struct bpf_link *link; int saved_ca1_cnt; @@ -354,14 +384,14 @@ static void test_update_wrong(void) link = bpf_map__attach_struct_ops(skel->maps.ca_update_1); ASSERT_OK_PTR(link, "attach_struct_ops"); - do_test("tcp_ca_update", NULL); + do_test(&opts, NULL); saved_ca1_cnt = skel->bss->ca1_cnt; ASSERT_GT(saved_ca1_cnt, 0, "ca1_ca1_cnt"); err = bpf_link__update_map(link, skel->maps.ca_wrong); ASSERT_ERR(err, "update_map"); - do_test("tcp_ca_update", NULL); + do_test(&opts, NULL); ASSERT_GT(skel->bss->ca1_cnt, saved_ca1_cnt, "ca2_ca1_cnt"); bpf_link__destroy(link); @@ -370,6 +400,13 @@ static void test_update_wrong(void) static void test_mixed_links(void) { + struct cb_opts cb_opts = { + .cc = "tcp_ca_update", + }; + struct network_helper_opts opts = { + .post_socket_cb = cc_cb, + .cb_opts = &cb_opts, + }; struct tcp_ca_update *skel; struct bpf_link *link, *link_nl; int err; @@ -384,7 +421,7 @@ static void test_mixed_links(void) link = bpf_map__attach_struct_ops(skel->maps.ca_update_1); ASSERT_OK_PTR(link, "attach_struct_ops"); - do_test("tcp_ca_update", NULL); + do_test(&opts, NULL); ASSERT_GT(skel->bss->ca1_cnt, 0, "ca1_ca1_cnt"); err = bpf_link__update_map(link, skel->maps.ca_no_link); @@ -471,6 +508,13 @@ static void test_tcp_ca_kfunc(void) static void test_cc_cubic(void) { + struct cb_opts cb_opts = { + .cc = "bpf_cc_cubic", + }; + struct network_helper_opts opts = { + .post_socket_cb = cc_cb, + .cb_opts = &cb_opts, + }; struct bpf_cc_cubic *cc_cubic_skel; struct bpf_link *link; @@ -484,7 +528,7 @@ static void test_cc_cubic(void) return; } - do_test("bpf_cc_cubic", NULL); + do_test(&opts, NULL); bpf_link__destroy(link); bpf_cc_cubic__destroy(cc_cubic_skel); From patchwork Wed May 22 09:23:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13670648 X-Patchwork-Delegate: bpf@iogearbox.net Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 721E052F7A; Wed, 22 May 2024 09:24:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716369875; cv=none; b=e/VbT+HoqfWXwhMee25ho9S+IvNx4JymKZwDMxy+vv7lvkpuqOb1WNH3ELlAy2xi298KVihh+6DHnaAOxSibUjnZyWvS+V8MbaEUvIl8QwyAndaP2BTyiHdEr5x2wJSatOw+v/ITZz/BbaLWdDp6FHHULmKyrer9EpQ7PaC8XD0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716369875; c=relaxed/simple; bh=7FPy0KDQHIWeqc+5k9gaSyK1bXx3Y9TG9QDXFqEZs/M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=peyhrbnLnhiDu27i7eQps4dxy6b7QF4cpSdh9NdCV5D6W0VC9V0SaT0He7AqCacvXcuV4bHYxx/V+gYjd7w9zk6JaAeAaZnOGD0eEXvnD6RgRtWOWmCNcpW6AXLLv1czFWrwq1CmB/0XaB4s7MCRMtwN96dhfP4Zqusdg3tmrv4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GI43Yi0V; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="GI43Yi0V" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3BAD3C32781; Wed, 22 May 2024 09:24:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716369875; bh=7FPy0KDQHIWeqc+5k9gaSyK1bXx3Y9TG9QDXFqEZs/M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GI43Yi0Vx9bMWCeqT6ioaygyVrd1jApymhzoY1NnJ0ahYPA6hmSQHIgfbpQu+v+V+ PvgQ0fSWlKwxlpwDjfmaZQymFdhoVaJCVXqxEvCJwoEmC8nnMuT4SIk9Vqi6LZGbH+ F7wNDl1yQpDhnkPpPZRMt19yfvDw8qiAJMUxZxdOugVWjy6o/TbUOyWvnyYjQKtEs9 bc2VIyv+ViRlrkDjrHDel8nGyY2di3pOB9xsnMhJTjybAAmXuE9o4ugtu9xE1u3yDz c4ebdwdUXOFauKd3TFIXnnHqCCH/xpvCKATJSbiL/WzG2OdHbcsqxZI1n0CMuVjObT 7DIU8+kgf+XzQ== From: Geliang Tang To: Andrii Nakryiko , Eduard Zingerman , Mykola Lysenko , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Shuah Khan Cc: Geliang Tang , bpf@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH bpf-next v3 7/8] selftests/bpf: Use connect_to_fd_opts in do_test in bpf_tcp_ca Date: Wed, 22 May 2024 17:23:49 +0800 Message-ID: <21f2e0b294480147fff1deb97e82cad389351815.1716369375.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net From: Geliang Tang This patch uses connect_to_fd_opts() instead of using connect_fd_to_fd() and settcpca() in do_test() in prog_tests/bpf_tcp_ca.c to accept a struct network_helper_opts argument. Then define a dctcp dedicated post_socket_cb callback stg_post_socket_cb(), invoking both cc_cb() and bpf_map_update_elem() in it, and set it in test_dctcp(). For passing map_fd into stg_post_socket_cb() callback, a new member map_fd is added in struct cb_opts. Signed-off-by: Geliang Tang --- .../selftests/bpf/prog_tests/bpf_tcp_ca.c | 36 +++++++++---------- 1 file changed, 16 insertions(+), 20 deletions(-) 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 d37364c5beac..4c85b443a78c 100644 --- a/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c +++ b/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c @@ -25,6 +25,7 @@ static int expected_stg = 0xeB9F; struct cb_opts { const char *cc; + int map_fd; }; static int settcpca(int fd, const char *tcp_ca) @@ -41,7 +42,6 @@ static int settcpca(int fd, const char *tcp_ca) static void do_test(const struct network_helper_opts *opts, const struct bpf_map *sk_stg_map) { - struct cb_opts *co = (struct cb_opts *)opts->cb_opts; int lfd = -1, fd = -1; int err; @@ -49,25 +49,9 @@ static void do_test(const struct network_helper_opts *opts, if (!ASSERT_NEQ(lfd, -1, "socket")) return; - fd = socket(AF_INET6, SOCK_STREAM, 0); - if (!ASSERT_NEQ(fd, -1, "socket")) { - close(lfd); - return; - } - - if (settcpca(fd, co->cc)) - goto done; - - if (sk_stg_map) { - err = bpf_map_update_elem(bpf_map__fd(sk_stg_map), &fd, - &expected_stg, BPF_NOEXIST); - if (!ASSERT_OK(err, "bpf_map_update_elem(sk_stg_map)")) - goto done; - } - /* connect to server */ - err = connect_fd_to_fd(fd, lfd, 0); - if (!ASSERT_NEQ(err, -1, "connect")) + fd = connect_to_fd_opts(lfd, opts); + if (!ASSERT_NEQ(fd, -1, "connect_to_fd_opts")) goto done; if (sk_stg_map) { @@ -125,13 +109,24 @@ static void test_cubic(void) bpf_cubic__destroy(cubic_skel); } +static int stg_post_socket_cb(int fd, void *opts) +{ + struct cb_opts *cb_opts = (struct cb_opts *)opts; + int err; + + err = cc_cb(fd, opts); + if (err) + return err; + return bpf_map_update_elem(cb_opts->map_fd, &fd, &expected_stg, BPF_NOEXIST); +} + static void test_dctcp(void) { struct cb_opts cb_opts = { .cc = "bpf_dctcp", }; struct network_helper_opts opts = { - .post_socket_cb = cc_cb, + .post_socket_cb = stg_post_socket_cb, .cb_opts = &cb_opts, }; struct bpf_dctcp *dctcp_skel; @@ -147,6 +142,7 @@ static void test_dctcp(void) return; } + cb_opts.map_fd = bpf_map__fd(dctcp_skel->maps.sk_stg_map); do_test(&opts, dctcp_skel->maps.sk_stg_map); ASSERT_EQ(dctcp_skel->bss->stg_result, expected_stg, "stg_result"); From patchwork Wed May 22 09:23:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13670649 X-Patchwork-Delegate: bpf@iogearbox.net Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 27BB652F7A; Wed, 22 May 2024 09:24:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716369880; cv=none; b=GRQ1k8a29r5/wePNXcEDb+EuUiAlfHtc4GOMqRZk1xDRjNT7TXa1uaWmVeGcsbzHHiBFOS5jJoeJbaXAl4k9muaNf7H1wiDYgvYuKoubY/Zd6MWqMkyvG/JMp1Otj7SJDZMhzuZgEz86FnTNwdjXfaqog2+1ZvFKnv0wcfHkcWs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716369880; c=relaxed/simple; bh=Zdu/GQ2eDLEDmVhEZflA/e0Wxzw69IlRiSbUB+pGWDQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Gjtznn7ibiBIThYucl6+U7NfUWZcsQDTlAf3uik0/wUTQmn7xhPZFE8Bq2Lj2DcQEIBD7rZjxd7JGUPgJkPGnnoij4tC2CzoIpHdqMh+G8AxCG+d8SdvUT7v8rp/0yi5qVm3W9GeOg0iQKQ0GZkqMaVDf0lm42P6U2+6WE7FjSE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hvKWyUjg; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="hvKWyUjg" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D381CC4AF0B; Wed, 22 May 2024 09:24:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716369880; bh=Zdu/GQ2eDLEDmVhEZflA/e0Wxzw69IlRiSbUB+pGWDQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hvKWyUjgak+W2k5T9Wtd9qDAnET2zz1F5zebAFkshMKk18FT0p77zWGAhXDJDsuSp cgTxwzj5odZSzMoTimKUXArjYPVrJ4N8BvIjmP4YSZ6cTUz64XEGmXsCuEYpOBYo/5 oRqbtaAjKrZoTLf8LNGcELes9g191Y/GttfGU5GD4/Lhk0YLEVOHTCVCRgWN0iNLAD jIWs3KdN6dA+FJtwJkXe11DMyYr3Oi7au73xMAwBGxCVAoJLfjuLu2ZwobIGwV5vQK huOmcpSPu5tQmVXSnrFTRuebVxiNGePtS0VobKeYBrUvUVEzzkw7KfqhxeTcnCsBJu 2KUgDeq83Az+A== From: Geliang Tang To: Andrii Nakryiko , Eduard Zingerman , Mykola Lysenko , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Shuah Khan Cc: Geliang Tang , bpf@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH bpf-next v3 8/8] selftests/bpf: Add post_connect_cb callback Date: Wed, 22 May 2024 17:23:50 +0800 Message-ID: <6f4609d9f3b294ad5944cfb4f0fcce86c074a3f5.1716369375.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net From: Geliang Tang For getting rid of the second parameter of do_test(), this patch adds a new callback post_connect_cb in struct network_helper_opts, it will be invoked after connect_fd_to_addr() in connect_to_fd_opts(). Then define a dctcp dedicated post_connect_cb callback, invoking bpf_map_lookup_elem() in it, named stg_post_connect_cb() and set it in test_dctcp(). Signed-off-by: Geliang Tang --- tools/testing/selftests/bpf/network_helpers.c | 7 ++- tools/testing/selftests/bpf/network_helpers.h | 1 + .../selftests/bpf/prog_tests/bpf_tcp_ca.c | 44 ++++++++++--------- 3 files changed, 30 insertions(+), 22 deletions(-) diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c index fae4add78f4d..c61da0a3197d 100644 --- a/tools/testing/selftests/bpf/network_helpers.c +++ b/tools/testing/selftests/bpf/network_helpers.c @@ -356,10 +356,15 @@ int connect_to_fd_opts(int server_fd, const struct network_helper_opts *opts) opts->post_socket_cb(fd, opts->cb_opts)) goto error_close; - if (!opts->noconnect) + if (!opts->noconnect) { if (connect_fd_to_addr(fd, &addr, addrlen, opts->must_fail)) goto error_close; + if (opts->post_connect_cb && + opts->post_connect_cb(fd, opts->cb_opts)) + goto error_close; + } + return fd; error_close: diff --git a/tools/testing/selftests/bpf/network_helpers.h b/tools/testing/selftests/bpf/network_helpers.h index 24c873963742..15b6a01c54c1 100644 --- a/tools/testing/selftests/bpf/network_helpers.h +++ b/tools/testing/selftests/bpf/network_helpers.h @@ -28,6 +28,7 @@ struct network_helper_opts { int type; int proto; int (*post_socket_cb)(int fd, void *opts); + int (*post_connect_cb)(int fd, void *opts); void *cb_opts; }; 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 4c85b443a78c..467774dd9dd9 100644 --- a/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c +++ b/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c @@ -39,11 +39,9 @@ static int settcpca(int fd, const char *tcp_ca) return 0; } -static void do_test(const struct network_helper_opts *opts, - const struct bpf_map *sk_stg_map) +static void do_test(const struct network_helper_opts *opts) { int lfd = -1, fd = -1; - int err; lfd = start_server_str(AF_INET6, NULL, 0, opts); if (!ASSERT_NEQ(lfd, -1, "socket")) @@ -54,16 +52,6 @@ static void do_test(const struct network_helper_opts *opts, if (!ASSERT_NEQ(fd, -1, "connect_to_fd_opts")) goto done; - if (sk_stg_map) { - int tmp_stg; - - err = bpf_map_lookup_elem(bpf_map__fd(sk_stg_map), &fd, - &tmp_stg); - if (!ASSERT_ERR(err, "bpf_map_lookup_elem(sk_stg_map)") || - !ASSERT_EQ(errno, ENOENT, "bpf_map_lookup_elem(sk_stg_map)")) - goto done; - } - ASSERT_OK(send_recv_data(lfd, fd, total_bytes), "send_recv_data"); done: @@ -101,7 +89,7 @@ static void test_cubic(void) return; } - do_test(&opts, NULL); + do_test(&opts); ASSERT_EQ(cubic_skel->bss->bpf_cubic_acked_called, 1, "pkts_acked called"); @@ -120,6 +108,19 @@ static int stg_post_socket_cb(int fd, void *opts) return bpf_map_update_elem(cb_opts->map_fd, &fd, &expected_stg, BPF_NOEXIST); } +static int stg_post_connect_cb(int fd, void *opts) +{ + struct cb_opts *cb_opts = (struct cb_opts *)opts; + int tmp_stg; + int err; + + err = bpf_map_lookup_elem(cb_opts->map_fd, &fd, &tmp_stg); + if (!ASSERT_ERR(err, "bpf_map_lookup_elem(sk_stg_map)") || + !ASSERT_EQ(errno, ENOENT, "bpf_map_lookup_elem(sk_stg_map)")) + return err; + return 0; +} + static void test_dctcp(void) { struct cb_opts cb_opts = { @@ -127,6 +128,7 @@ static void test_dctcp(void) }; struct network_helper_opts opts = { .post_socket_cb = stg_post_socket_cb, + .post_connect_cb = stg_post_connect_cb, .cb_opts = &cb_opts, }; struct bpf_dctcp *dctcp_skel; @@ -143,7 +145,7 @@ static void test_dctcp(void) } cb_opts.map_fd = bpf_map__fd(dctcp_skel->maps.sk_stg_map); - do_test(&opts, dctcp_skel->maps.sk_stg_map); + do_test(&opts); ASSERT_EQ(dctcp_skel->bss->stg_result, expected_stg, "stg_result"); bpf_link__destroy(link); @@ -344,14 +346,14 @@ static void test_update_ca(void) link = bpf_map__attach_struct_ops(skel->maps.ca_update_1); ASSERT_OK_PTR(link, "attach_struct_ops"); - do_test(&opts, NULL); + do_test(&opts); saved_ca1_cnt = skel->bss->ca1_cnt; ASSERT_GT(saved_ca1_cnt, 0, "ca1_ca1_cnt"); err = bpf_link__update_map(link, skel->maps.ca_update_2); ASSERT_OK(err, "update_map"); - do_test(&opts, NULL); + do_test(&opts); ASSERT_EQ(skel->bss->ca1_cnt, saved_ca1_cnt, "ca2_ca1_cnt"); ASSERT_GT(skel->bss->ca2_cnt, 0, "ca2_ca2_cnt"); @@ -380,14 +382,14 @@ static void test_update_wrong(void) link = bpf_map__attach_struct_ops(skel->maps.ca_update_1); ASSERT_OK_PTR(link, "attach_struct_ops"); - do_test(&opts, NULL); + do_test(&opts); saved_ca1_cnt = skel->bss->ca1_cnt; ASSERT_GT(saved_ca1_cnt, 0, "ca1_ca1_cnt"); err = bpf_link__update_map(link, skel->maps.ca_wrong); ASSERT_ERR(err, "update_map"); - do_test(&opts, NULL); + do_test(&opts); ASSERT_GT(skel->bss->ca1_cnt, saved_ca1_cnt, "ca2_ca1_cnt"); bpf_link__destroy(link); @@ -417,7 +419,7 @@ static void test_mixed_links(void) link = bpf_map__attach_struct_ops(skel->maps.ca_update_1); ASSERT_OK_PTR(link, "attach_struct_ops"); - do_test(&opts, NULL); + do_test(&opts); ASSERT_GT(skel->bss->ca1_cnt, 0, "ca1_ca1_cnt"); err = bpf_link__update_map(link, skel->maps.ca_no_link); @@ -524,7 +526,7 @@ static void test_cc_cubic(void) return; } - do_test(&opts, NULL); + do_test(&opts); bpf_link__destroy(link); bpf_cc_cubic__destroy(cc_cubic_skel);