From patchwork Fri May 24 03:21: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: 13672637 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 1BB491BF53; Fri, 24 May 2024 03:22:22 +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=1716520943; cv=none; b=eP/gJLdLuPEo2G3R1M8u3yr2YYFVDWZDvjNc6aYS4K3DxGEHqPV7bXScqAL1A9jqu45KNqEYxRWFPLa4NChzcHEe3pLNtlfpEBy26QdgGVcJZOc6c3UnmGzSDB7Q3dz24PAPpuC/zNrML4ZDI3cS9oBjJSg0RVgHzGHxueB3CZ0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716520943; c=relaxed/simple; bh=z/rJWlSUZ4/YuGyhiu6hcQQN4WWNf6a84wS8YU3ikvI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CB/eh6qYi2VZxGGlgTW29dsEMKw1VbLXGPmcLW2R/z/lILXglJe17Z88eIzgyho7cZuesLbp2KYGRvnneEdobtptRwJL0duFSnWvFFvhyp0xt4ViwRLBHS+DurzAuuqKhBKgrnyws3YthOYgOUPtPLY/RzUp0REAKGUiDbTj9Ls= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GKd2KeLS; 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="GKd2KeLS" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9C339C4AF07; Fri, 24 May 2024 03:22:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716520942; bh=z/rJWlSUZ4/YuGyhiu6hcQQN4WWNf6a84wS8YU3ikvI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GKd2KeLSaP8qNgqdu8PUYki8jmah2GN8vEw7MEMleKEfHTG0dX6qI1RaEbjF6Sa8q l0CWgru/8Kz4eIoeaj3aT4LmPotNB96QaAl/NvWq9Ms0RE3ODC9PQcYFVSsdCbSAsX lWuhl4lQ08ginOzvrLvA851KLxane6D2r7TP8vOVvMkdLgAJ9qUP3hMafQrifxRBGp VvFcLTxVcJnf7FUgbGr3ArSMVtC/sgYU14IsyFK9ii3gyEnRI1It+o11K0O/MjHJrA fEqbKZ+c1lflRTrl4EbjlhHYY4X9UifVAOP8MZd/00RP87BCNURVKQiWAzozKyQSNV GCxAShM+JU3+w== 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 v4 1/6] selftests/bpf: Drop struct post_socket_opts Date: Fri, 24 May 2024 11:21:49 +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 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 Fri May 24 03:21: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: 13672638 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 986961EF01; Fri, 24 May 2024 03:22:33 +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=1716520953; cv=none; b=soguBufa1BZeHyJP6Bo/04/Zn1XZ+kLeKSNdYNVjtte7Aj8t1Jf839YEJ5DhYeBXOvkNDUKtMaHljkI5h/oR2yrCuAibDloC25FHBhV5baCQPP0+MOCzGRfCe/q3VfUjSh9kjx34vFNL5YV2G4u3oVDEIR5pYHMwjmXyPTaOD2w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716520953; c=relaxed/simple; bh=394h3Q9cvyh41rfbfaAmL8bMBRnTOy6D4vSWMspn9Og=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XixLBcJI8r/YGojg/nMnnNgh+4bufKjK7N+rk7bIiVVz+fNVC0JpopBR0lOe2idhousNN8gHrhSSNrxamYtT75GCOB8+c6Vw++umSu75oLqkj7oE/qQLo4lvcZcNngdXq7bowaqi4Ukd1HoOr7B42GEHcuF1QxfFEdo+G+OlbTs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NyM0WhOw; 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="NyM0WhOw" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 463B0C2BD10; Fri, 24 May 2024 03:22:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716520953; bh=394h3Q9cvyh41rfbfaAmL8bMBRnTOy6D4vSWMspn9Og=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NyM0WhOwkkwvl/vJvKmaTvOmMGxbGykI6Bhd0j8CTHBG8jYn7vhPRvk5csEuAmkNc dKn5FLA8GI3rHxl3tBUxG9mgmKWSZAjumHbFkGQKxeuRJqp8Bzv0E7lKIVEgPwpMsz pfRaHg5tbvN3dsgxoTuG24+/6YqzmX58Wi90SjXxcgm8jmvfwEppxmyKvzJhztfr74 5i9U8JsqjjpFOqeE9w2s05MFQS9CtCDpDESM6LhjX/7ADmGO66fXvTdEvUPs8Sp9EY LKifP1KZBzA6NzKjhPTMswvIyQfzEUKqaD62yi0HpW1o/2PHACsv9K1CpMs+sJvXTa lhIT6MESs1ddw== 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 v4 2/6] selftests/bpf: Add start_server_str helper Date: Fri, 24 May 2024 11:21:50 +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 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 4d776b78929c..0e8266f439e4 100644 --- a/tools/testing/selftests/bpf/network_helpers.c +++ b/tools/testing/selftests/bpf/network_helpers.c @@ -118,19 +118,29 @@ static int __start_server(int type, const struct sockaddr *addr, socklen_t addrl return -1; } -int start_server(int family, int type, const char *addr_str, __u16 port, - int timeout_ms) +int start_server_str(int family, int type, const char *addr_str, __u16 port, + const struct network_helper_opts *opts) { - struct network_helper_opts opts = { - .timeout_ms = timeout_ms, - }; 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(type, (struct sockaddr *)&addr, addrlen, &opts); + return __start_server(type, (struct sockaddr *)&addr, addrlen, opts); +} + +int start_server(int family, int type, const char *addr_str, __u16 port, + int timeout_ms) +{ + struct network_helper_opts opts = { + .timeout_ms = timeout_ms, + }; + + return start_server_str(family, type, 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 40011e0f584b..4e3e6afe7d3a 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, int type, 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 Fri May 24 03:21:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13672639 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 B7B5D12E4A; Fri, 24 May 2024 03:22:39 +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=1716520959; cv=none; b=mUvTZasHaT2fHXSWgmIou7+wyypxX0R4Zsa5Z4/fT0WjmeJ2MAsH3CvMWnl7CF6PGPZFCrqTH7Dm+sI3A1196ezJQOkJrdu/RHxhWEDxgEIHyC4Yx9k37i/wjru76/vYddl3avUs0GbQJHweIGovk8NTJjPfz6witjbLRMKXQY0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716520959; c=relaxed/simple; bh=CLRazJ30wBSFi8ItYaU0PAXfU6G5vkeUSfRYkSnwNKw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uttn2CcMRlmKOT44DaYC9aFUQ+aqT2WKWzvSAjQbjAcMcUGf82MwHwFwEFhcPOf2lYkQEJZtDg/TXc7xPtouxaLeZmtOPDNd2bmd460XpVATZ4ExKfjgrvWWerA2+MH6Vb0JxnoiId8BAxyvLJVi6H4m9bCqSr+DZnQKLgSGdXo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=JyF6D0qq; 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="JyF6D0qq" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CCB0BC2BD10; Fri, 24 May 2024 03:22:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716520959; bh=CLRazJ30wBSFi8ItYaU0PAXfU6G5vkeUSfRYkSnwNKw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JyF6D0qq5lsnIdDEKbHGoeqE8UNqgtjeRcqn3CxGxJjXJDRfXhoy6CHiNN4BGLgmZ mKJR/zc+CswAqwDv1tet+5Lfip3RR4FvWiRWH8mDoJmUckz+tDDpnoeoVTMVimazUG 6SkFDas5XxoVushx/3MYtb0ctRTaJ7XIZsf4j4VirJN4Et4pxd0WyRTsSlQ23cn0+y JLbiqQJnmYHR18UjikOH01F1hIJSA5gWvAq4Wv43ohuPHmpwZ0tNEcIHFAidm708Zo PBIVwXuaIHC07aS4tH1nM+S3dDdXPKJsfd5JU4VUj4c4dQQDVBrHaJAuJtE8C0c7O7 s0Lwr3pNqjdRA== 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 v4 3/6] selftests/bpf: Use post_socket_cb in connect_to_fd_opts Date: Fri, 24 May 2024 11:21:51 +0800 Message-ID: <34180b520025f700f65d23b41148109e4214c697.1716520609.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 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 0e8266f439e4..8502917b6c7b 100644 --- a/tools/testing/selftests/bpf/network_helpers.c +++ b/tools/testing/selftests/bpf/network_helpers.c @@ -348,9 +348,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 4e3e6afe7d3a..11eea8e2e4f1 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 Fri May 24 03:21:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13672640 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 149CD1BF53; Fri, 24 May 2024 03:22:53 +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=1716520973; cv=none; b=D2GJrmcNPPVqE/UOif0RqeXuNCsrpyhLHdzHJ47v/5Q31sMbbVNXVAEao2tROdJmytgdk9pbBfH48xzrmTjuIwwU3cNEmBfytKqj2/9QBJwqXA+257d42YQPUUkk/4YYykpWtjtUWYnMCmhfuvOdcoubGbuDbC1zZOqHwR3a4Wg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716520973; c=relaxed/simple; bh=4gFrJjn73No2Tb27jEAkn6v78eXxc4YltjWezwMOPYI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=q9FExzigrXSFREVby1/qY06ChTUgaLQZZDPtL3NtFv/JIX9LkxKk1EhvQuZ+H2EhhihChRJFEVvJebsg1dat/9VDj4qFkOsVKCbuLsh+ty0zxw5QxGXvwXE+yFjVvOnzw93WFaxxRQdD8PbibOMFJZa/lMqXfRpwAHy13pFt3y4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ce8XiSpe; 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="ce8XiSpe" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 01501C2BD10; Fri, 24 May 2024 03:22:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716520972; bh=4gFrJjn73No2Tb27jEAkn6v78eXxc4YltjWezwMOPYI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ce8XiSpedDhL3WFPT35xoSjTPAohi3UuM5q3U9qezsRP+NUCx0qFesF7z59SKCNmG 1jxegRI7ZjZORehjXi68YpwDpQrc1QrkrZR+W6mUItrHO1v8CwV3OPtX/snzacqKlr AjR6jDEuIkmFnGkXCsjL8SKGAX8JoNeVf5CLAUxnR93Q6/0sZbmUP4/cHODIWF9CWJ K2T4PaBicLGEP3oBpBzQYZWP88m/ZsS07lKnUVphEU+xUEd+gpRGh9YLoOAi4P2DDs op+2wvxyYsbZDg1Rc2rudrIg2vVUd0PR9Uc2wxkv7SN5KjAlAq+d0bC4nf/OMMz7oM 02fkbgX4Wg9wQ== 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 v4 4/6] selftests/bpf: Use start_server_str in bpf_tcp_ca Date: Fri, 24 May 2024 11:21:52 +0800 Message-ID: <7c462740879edc7356608e392a1a7b736af82bbd.1716520609.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 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 8502917b6c7b..e20caef06aae 100644 --- a/tools/testing/selftests/bpf/network_helpers.c +++ b/tools/testing/selftests/bpf/network_helpers.c @@ -94,7 +94,8 @@ 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 c9dd2a3d3218..123fcd5a0af6 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, SOCK_STREAM, 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 Fri May 24 03:21:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13672641 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 EC32512E4A; Fri, 24 May 2024 03:22:59 +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=1716520980; cv=none; b=igitpyr6h6k8wp8FpUQ9sYrtKTWLYuatFmcNe42zt4vG0X2DP0xP5zbmdm0TnImtVkuAAvMHAHzLZPIrYlrASqsbSIqFevQu5IIxuDaU5agBb9HVHAy0fiNcBYTZ9+8J21gohdzhnhG85F+S4Nj50KhUko9Dvmoh8u7mAZcvnUs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716520980; c=relaxed/simple; bh=XubIlQa9dUdgYfINAo4rCVeAEaVUHHlfByfj9erdbmg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Nquj/98YXZaIAPhXgiJk42/056qWV6qbGVYxsd64r5/uYB+QcB8kWzJzNgFecgXNbgnEgu+webPh5Or8GxNQFxeyVt8nvUX09I+1gv5ZX0ZKHP1x8IWxDhuZyGF30DfQfyfHVDxTTY0MIrmOdd7PJwIjJclsB2fDZQ1zNa/yafw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lZLN3Pii; 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="lZLN3Pii" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 93B28C32786; Fri, 24 May 2024 03:22:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716520979; bh=XubIlQa9dUdgYfINAo4rCVeAEaVUHHlfByfj9erdbmg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lZLN3PiimnU6vqS0P/FC3HKQLVLx2h3ZgAjbF71W/JURA4Zo37h330PwfXmwTV2I2 ZzmSzIFHuM+Wy+wR0xuuelehkWl0/52HQA7Dg8j3TCLMyRnhcrjGXd8JDTdbxJJ+7m 7R50jGXmsa5yy8ZGUkIhmDRbo1oIULBcCU2NIZi4URqOessKBOg0PghP+Xyp2eRYHB z0FqHaTtuPzZ7hjzS+61LYW74Zxd/UqvarSK30cRpWRYk9ovjh+CR5JrWHOpuSE+Dn TPq9lzbpkPrQev9WTzO8fPJa9xARUcolRZ3pqh2OUvNeftc0Tr65oFfVpiTvQkAD6/ yiJt6EQE4Vw0w== 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 v4 5/6] selftests/bpf: Use connect_to_fd_opts in do_test in bpf_tcp_ca Date: Fri, 24 May 2024 11:21:53 +0800 Message-ID: <76e2826d3ff4c5d4b147923d4742ca4b96e0308b.1716520609.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 123fcd5a0af6..cde796f82206 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 Fri May 24 03:21:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13672642 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 29B091DA4E; Fri, 24 May 2024 03:23:06 +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=1716520986; cv=none; b=VMvkNlJ+8qm6uKzB2LuFclZyzLJs5ILRGXBUOs1je23bNyKltsWT0sXTtkOcp7HtUqkGn6MtZuBpG2lBu0/c05R0BSGHFbZUSQqpEg4xLnT4qvrkZRzGgX6FnoFa0b9jhhz7DhLsAkGDsqEA3uvktufmfRso0lB38N0Cuiv4Pvw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716520986; c=relaxed/simple; bh=zYQ/Nf8RsYjrjdtiVDNHYzDvXVz4aQsUcEHXVFX7htc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZamJKqYVkEJNVcNDpTQq0Mno/x+8eOVD2msHHISo5+T018Iub88rQk+R3Gm+cMRrVw5ZLGFY6gkSNHTRbseQ1pPPQhm09reZn3lQxWDEp0r6SLTtfS0D/YVU6tK1NRUEtpuk6w1w5LGWOqNhRn4te0t0D7imlvow1qrkBgWzvT4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=JtlAbsa1; 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="JtlAbsa1" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 10E81C32781; Fri, 24 May 2024 03:22:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716520986; bh=zYQ/Nf8RsYjrjdtiVDNHYzDvXVz4aQsUcEHXVFX7htc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JtlAbsa1dvhwifQieYoiFMiXlZMMWS30f4GbUu1I+P9jwhRFCjF/9lFO4zDQ0isfC +C4tHP/iieDqcrj/VPPuojshsgXUvCCjkaaqf95wc+LxapuLQoh7+PajdiLLG+eOkk 9QFg9hjGqbb7utJdTE06iEhmfR62WkxGbTXcxhT2HCBAC/mDcnUFvu2F9WTwqaiOzc nL+SnZuoibs/DRzUmT8SzykqxNTqTFAODHksjcmIqfTgNK4JXRnZ2sBzTL1LhwoR0C 7cE1RVCf8mz7ulmzQjsnT7F6ABxesPZjnVeiGf8EX60IDC2iUDUYVTWjkWnATXuqMq /UwMgz30Gj0fQ== 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 v4 6/6] selftests/bpf: Add post_connect_cb callback Date: Fri, 24 May 2024 11:21:54 +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 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 e20caef06aae..75589597c17e 100644 --- a/tools/testing/selftests/bpf/network_helpers.c +++ b/tools/testing/selftests/bpf/network_helpers.c @@ -353,10 +353,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 11eea8e2e4f1..b387e8142f3c 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 cde796f82206..a2501e5aaa7d 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, SOCK_STREAM, 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);