From patchwork Thu Apr 11 01:03:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13625256 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 6BFEE3201; Thu, 11 Apr 2024 01:03: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=1712797419; cv=none; b=jnYSyswpEMPuD/9EkWz7t5dnojbdsZfnbbH0Bj1YU1LqogpSRalkqRSf9roAO3LmXj6fe2AYa648fEDkxSuhd+IDyvRwcVPjm09h4s0Z0IGevte8DoWIGSot6LNSYswunMokUyQskWs7CFB9GXpoffmksX3ugs//mPcx/ufk3lY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712797419; c=relaxed/simple; bh=XKWe2SVlzlSokHo1aMPqJ8xIFb2FMSLePvMYzMc62os=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=qKYt8Bmi2WMC0FJ6tjud5EsezrqjfOU9tdIgvXho88HYAOzDKg37pFjkSfnYZVZs/nvY/HCyroC+yPLG0bBFaIOKoxnMtcY2US0ruoYlQP4t7OgqactB6hbJgf+cM739jLkM+eKkJXwfFrpIhFP//49cukbCzqnJqCaVm8SXV54= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=doD5D38k; 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="doD5D38k" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 87C08C433F1; Thu, 11 Apr 2024 01:03:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712797418; bh=XKWe2SVlzlSokHo1aMPqJ8xIFb2FMSLePvMYzMc62os=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=doD5D38kUsKugIG36BStnxb79muszQm61pnt0YdZ7JgTkcuajLtPJoIGgTX06x2w8 nr7isJhgBh8022kuZiK3WM1JvIky/HhWiEJkd10FdY+ygyDlAlW/SbnX5HrDzozUGM bYpvLlLq23EvA9sy7mxC4RJsEaizuK8PF+DcNMSRhRr/vZVJIUmU/JhinKCHpIllGg 3WM+M0tykxXmnjl2frLhplTWRs7r0xIhPdXN87AqZwJsZlTOXBNGfJYCozszW941Jv Sen4sSg0TyE2WCnA3SXXTCBvjBFwQDLFmJVm48/ux4G7epiUmLVMylm+IUFLncRqwE TZwjWpVnuPQlg== 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 v2 01/14] selftests/bpf: Add start_server_addr helper Date: Thu, 11 Apr 2024 09:03:09 +0800 Message-Id: <504f2687adeeeb15eba0038be473fa98a865a6d8.1712796967.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Geliang Tang In order to pair up with connect_to addr(), this patch adds a new helper start_server_addr(), which is a wrapper of __start_server(), and accepts an argument 'addr' of 'struct sockaddr' type instead of a string type argument like start_server(). Signed-off-by: Geliang Tang --- tools/testing/selftests/bpf/network_helpers.c | 5 +++++ tools/testing/selftests/bpf/network_helpers.h | 1 + 2 files changed, 6 insertions(+) diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c index ca16ef2b648e..7ddeb6698ec7 100644 --- a/tools/testing/selftests/bpf/network_helpers.c +++ b/tools/testing/selftests/bpf/network_helpers.c @@ -185,6 +185,11 @@ int *start_reuseport_server(int family, int type, const char *addr_str, return NULL; } +int start_server_addr(const struct sockaddr *addr, socklen_t addrlen, int type) +{ + return __start_server(type, 0, addr, addrlen, 0, 0); +} + void free_fds(int *fds, unsigned int nr_close_fds) { if (fds) { diff --git a/tools/testing/selftests/bpf/network_helpers.h b/tools/testing/selftests/bpf/network_helpers.h index 70f4e4c92733..89f59b65ce76 100644 --- a/tools/testing/selftests/bpf/network_helpers.h +++ b/tools/testing/selftests/bpf/network_helpers.h @@ -53,6 +53,7 @@ int start_mptcp_server(int family, 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(const struct sockaddr *addr, socklen_t addrlen, int type); void free_fds(int *fds, unsigned int nr_close_fds); int connect_to_addr(const struct sockaddr_storage *addr, socklen_t len, int type); int connect_to_fd(int server_fd, int timeout_ms); From patchwork Thu Apr 11 01:03:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13625257 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 B9D96EEDA; Thu, 11 Apr 2024 01:03:45 +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=1712797425; cv=none; b=JD3v++RAzumgOB6gglMRDW6Z6KKqwcbfxz9XiBFZHl5dqZZVvxCDkwp4UvjPFsjcFt8Jivfpdg5Bdj9bDcgD+qAXnyxJkb6UT4md6draoj4Vu7eWhj33bXFk68QDW6pHlFBB+Dw/s751goOEFVB+0KBREl6yXKMqhu3X3lMpfdk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712797425; c=relaxed/simple; bh=XWeh00IOXYJlftJnTBXDAKK+X/bhZEtWsLxktauMllw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=P/iAMMEDbfG9IW+jAWjUs4CAZ9wl2ypd1ptPhZagpF80aXLB0tnM7GjAvtleJi+DhFtzl50XZcIRC+uDIuCiZ7jjhyO7lI7r9WORujk//+V1YHB4sqDgPfFbWZAayxoXLgECE9AdU2MqEnyxQN8lIZ8VZtsz6jf5nkwuV9HN20Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=i8qP0ZxG; 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="i8qP0ZxG" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8D4EEC43394; Thu, 11 Apr 2024 01:03:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712797425; bh=XWeh00IOXYJlftJnTBXDAKK+X/bhZEtWsLxktauMllw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=i8qP0ZxG8bQCGCNgE0Nt1ezsPDmE0k9gphhviYpt6vwSRJFDcDBVD8ORori4jX19D t1vmGG3ZuQWYPl7u7aWsP5n6JuS3xDVIAP2AEETlZGJrv+K11PFjsgcwwFFFsucn9X LFSWzJ7LvMzPKVkVT1y5s4f1NNVNel0YFvOxLH+FZ6EPFm75vX2SdnkgvcU5c+xr7D irnDR/Ywnk+/NaNNgguQSI3TlI3SsUv4DioJtWnZnELy/0cHxFsoS+4pa7/G/WtI40 uZbE/Gz5tRwq1cMHAvX0klumHNEDuwzy+HoFC3EIQ9Tpi+0XpCsLlrUE76USZcWSIW 8OXOOcFVcXptg== 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 v2 02/14] selftests/bpf: Use start_server_addr in cls_redirect Date: Thu, 11 Apr 2024 09:03:10 +0800 Message-Id: <2634fdf2fd6b799be8e97091f8984b22dbaacd96.1712796967.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Geliang Tang Include network_helpers.h in prog_tests/cls_redirect.c, use the newly added public helper start_server_addr() instead of the local defined function start_server(). This can avoid duplicate code. Signed-off-by: Geliang Tang --- .../selftests/bpf/prog_tests/cls_redirect.c | 20 ++----------------- 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/cls_redirect.c b/tools/testing/selftests/bpf/prog_tests/cls_redirect.c index 2a55f717fc07..013051555ce6 100644 --- a/tools/testing/selftests/bpf/prog_tests/cls_redirect.c +++ b/tools/testing/selftests/bpf/prog_tests/cls_redirect.c @@ -10,6 +10,7 @@ #include #include +#include "network_helpers.h" #include "progs/test_cls_redirect.h" #include "test_cls_redirect.skel.h" @@ -35,23 +36,6 @@ struct tuple { struct addr_port dst; }; -static int start_server(const struct sockaddr *addr, socklen_t len, int type) -{ - int fd = socket(addr->sa_family, type, 0); - if (CHECK_FAIL(fd == -1)) - return -1; - if (CHECK_FAIL(bind(fd, addr, len) == -1)) - goto err; - if (type == SOCK_STREAM && CHECK_FAIL(listen(fd, 128) == -1)) - goto err; - - return fd; - -err: - close(fd); - return -1; -} - static int connect_to_server(const struct sockaddr *addr, socklen_t len, int type) { @@ -98,7 +82,7 @@ static bool set_up_conn(const struct sockaddr *addr, socklen_t len, int type, socklen_t slen = sizeof(ss); struct sockaddr *sa = (struct sockaddr *)&ss; - *server = start_server(addr, len, type); + *server = start_server_addr(addr, len, type); if (*server < 0) return false; From patchwork Thu Apr 11 01:03:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13625258 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 246E73201; Thu, 11 Apr 2024 01:03:52 +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=1712797432; cv=none; b=JfyPw/+z9iJktYimMOOTtFvFs6LeIWGCctYFehAgznk6CERWgLY+IGw0v15RNobWkypbg6dN2FFJ/zqoGdRVX/G3vuw/aDv8az00CNB/D69pxrEuvdDMLKEsYFXw/np1kVGtIGh0lZuZ2JOSVYYckvXGPSYRRqdDT3J7WmWfIq0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712797432; c=relaxed/simple; bh=UoddJk6fHo9GNGgLLytEAkLLAyBEiqpzG4m+11ozUEI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=A5xaaknP7NNNCERToUmTcy6IYE32wpwQwxq+WVUvSMsqvgqLgU+gCPp5yAICrSr+6uSt2sEuQftxOXRB45z44AeO16PmX1kWEjjMf2p/U+HUybJ1KqOYe1wWMxS+JEWzqY1GWcCK5ucgOwhItUGRic9zfdM9YAeWjDnA4IA3TJ0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ctBpuiSE; 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="ctBpuiSE" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3B79CC433F1; Thu, 11 Apr 2024 01:03:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712797432; bh=UoddJk6fHo9GNGgLLytEAkLLAyBEiqpzG4m+11ozUEI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ctBpuiSEdwBBYB/XB0RjiaBlAsjFIV7r72r5dphV2PkC7jHqnzm3pz5AqOgPELQst JUsyaZYp2kTT8kk7yE/QIXAWd8CI6jX+m0BkJK4t30UJrOqRT0RLCuzQXTqtL3a7dv q/D2jsQcj3QUc7x10Ietj7CnuPyFYUPh8Fs0AujBgC8ib9aKAPt0PGdcmbx9znO6er /3msrx048zic0UsRD4NFABCrP3d0cayQUdM+NZhBPRJjkkgLp3cmtRCv5+gXKNFNDc Uf1BDMbsdBB69tq3hzvM83zDYrD3qL5wZTkojRuKjVVcsflb3V2TWyXdehes934DWc Twm5I9mXU1Ftw== 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 v2 03/14] selftests/bpf: Use connect_to_addr in cls_redirect Date: Thu, 11 Apr 2024 09:03:11 +0800 Message-Id: <2a7bcd02707cedc3f9c2a52f81f531500f1d5edd.1712796967.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Geliang Tang This patch uses public helper connect_to_addr() exported in network_helpers.h instead of the local defined function connect_to_server() in prog_tests/cls_redirect.c. This can avoid duplicate code. Signed-off-by: Geliang Tang --- .../selftests/bpf/prog_tests/cls_redirect.c | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/cls_redirect.c b/tools/testing/selftests/bpf/prog_tests/cls_redirect.c index 013051555ce6..4b185b608fae 100644 --- a/tools/testing/selftests/bpf/prog_tests/cls_redirect.c +++ b/tools/testing/selftests/bpf/prog_tests/cls_redirect.c @@ -36,22 +36,6 @@ struct tuple { struct addr_port dst; }; -static int connect_to_server(const struct sockaddr *addr, socklen_t len, - int type) -{ - int fd = socket(addr->sa_family, type, 0); - if (CHECK_FAIL(fd == -1)) - return -1; - if (CHECK_FAIL(connect(fd, addr, len))) - goto err; - - return fd; - -err: - close(fd); - return -1; -} - static bool fill_addr_port(const struct sockaddr *sa, struct addr_port *ap) { const struct sockaddr_in6 *in6; @@ -89,7 +73,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_server(sa, slen, type); + *conn = connect_to_addr((struct sockaddr_storage *)sa, slen, type); if (*conn < 0) goto close_server; From patchwork Thu Apr 11 01:03:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13625259 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 3938F60DE9; Thu, 11 Apr 2024 01:03:58 +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=1712797439; cv=none; b=CHsPTXzlq0OM4SQEbbeHguWMFohhxkMlperLKaS6Mhz1Uejt7gwwskPeWOEbkEmQKWp2os4QsXikopS+CgBNdjV1BlShiPiuBhDg2eaIkIjTKs15C/YrqW5SIH2h4EZhNPfDBSGFSKsAC5h8332nMhFD2IrsGW+E7DUEcqpLU4c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712797439; c=relaxed/simple; bh=i0/HbyXy9mTe8xyzUPu5bCQ3pV8e1VXhg0MQMOhx8Ec=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ad+zV2trsyUwAnNOFRcb1MsPQOf3IbPu1AgdA+yQCDFd5rKueRsfpDa9UnomV7TZWvHCnonmAfZjFUuhzsV5y5lMeNAuAtCHYdOX6UcHwjRURZenYsaHL8lllPVmeVbMrKKQyizTp2X7gggHeOEvTzx2reG+vZNDWFTHNHb7L+s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=sYs5SeAW; 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="sYs5SeAW" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 81BA2C43394; Thu, 11 Apr 2024 01:03:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712797438; bh=i0/HbyXy9mTe8xyzUPu5bCQ3pV8e1VXhg0MQMOhx8Ec=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sYs5SeAWGu3DyudYWqSwG5WCFssiVEFzt/pbcVg+TkNVxLr1VBxQKNK/+Epo2cscK Gj8g/BBjCbWnirNTLwFfyM1Si16NKLs6SGGMfd4palXd9aGlWu4G+ZbzukVIKwoXZ5 6w1stlOs4gV3SKgkiJWqRrt/RNZdX4HdLqcwjYHn9XjSQa4Fpoy8cdNwayn2NkX8Zz a2+M82nLmAn2p2vHzqvHs9vFtgueQlrghn2/Q3Pmqw6qWKSn/sTgTNCRunDrauWX6k SGxF3yJrzGw/xmLmRZl4jM3VKDIe0Lb6fNErc9/QFHtzqRBkQuJB08sEzzvKuhnYbz XhQYHQC4KxMoQ== 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 v2 04/14] selftests/bpf: Use start_server_addr in sk_assign Date: Thu, 11 Apr 2024 09:03:12 +0800 Message-Id: <4aa58529b2bb841672176014a4f28d3ae2658caa.1712796967.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Geliang Tang Include network_helpers.h in prog_tests/sk_assign.c, use the newly added public helper start_server_addr() instead of the local defined function start_server(). This can avoid duplicate code. The code that sets SO_RCVTIMEO timeout as timeo_sec (3s) can be dropped, since start_server_addr() sets default timeout as 3s. Signed-off-by: Geliang Tang --- .../selftests/bpf/prog_tests/sk_assign.c | 27 ++----------------- 1 file changed, 2 insertions(+), 25 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/sk_assign.c b/tools/testing/selftests/bpf/prog_tests/sk_assign.c index 1374b626a985..130aafe8cff6 100644 --- a/tools/testing/selftests/bpf/prog_tests/sk_assign.c +++ b/tools/testing/selftests/bpf/prog_tests/sk_assign.c @@ -15,6 +15,7 @@ #include #include "test_progs.h" +#include "network_helpers.h" #define BIND_PORT 1234 #define CONNECT_PORT 4321 @@ -73,30 +74,6 @@ configure_stack(void) return true; } -static int -start_server(const struct sockaddr *addr, socklen_t len, int type) -{ - int fd; - - fd = socket(addr->sa_family, type, 0); - if (CHECK_FAIL(fd == -1)) - goto out; - if (CHECK_FAIL(setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &timeo_sec, - timeo_optlen))) - goto close_out; - if (CHECK_FAIL(bind(fd, addr, len) == -1)) - goto close_out; - if (type == SOCK_STREAM && CHECK_FAIL(listen(fd, 128) == -1)) - goto close_out; - - goto out; -close_out: - close(fd); - fd = -1; -out: - return fd; -} - static int connect_to_server(const struct sockaddr *addr, socklen_t len, int type) { @@ -310,7 +287,7 @@ 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->len, test->type); + server = start_server_addr(addr, test->len, test->type); if (server == -1) goto close; From patchwork Thu Apr 11 01:03:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13625260 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 846B15FDD2; Thu, 11 Apr 2024 01:04:05 +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=1712797445; cv=none; b=dnZwcBQQZM/goLERGV2GyXSBuwkXUYSVK0lbspeQv4wy+emtwq/HjqTK5lyQPqF3ffiQoeqWS8AzEr4qW9Xiwmarlr3GURL1dhgAlX31lkFHLzuzQk0v1tmRqNZPuZVO6Nde1tfBJfvWPKfcax/Nf37O+2ZjMECgmYEuGKJGpz8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712797445; c=relaxed/simple; bh=Eb0PJ1vYwrl0NMtQT60fNBI5AJMQSh9o4iVlR3khSMw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=PcVsNZv8llAJAGtgT9yqxgM40tL/3qTGyJgBA6/z/sKGKOn37FnJqieUcYqGpMRJztYwX2PTMSp0Q1J08h87vdO7l0ff55iUVVMl0r/misJB6Aj9ukYjMKZVJHK0GKacHiEOSAJYyBCv8u0LOamVCqBE8Rr+IyVoQyWl9ftIc5k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=f1Ki49ck; 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="f1Ki49ck" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 538BFC433C7; Thu, 11 Apr 2024 01:03:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712797445; bh=Eb0PJ1vYwrl0NMtQT60fNBI5AJMQSh9o4iVlR3khSMw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=f1Ki49ckuhHVHkIvDsQy/YFcmG18xuICkkRr5jzffuQRuaZkr4HLIBGf0e5uPgK9u MDPYjhKUYPnhrUkhA1LSEtp0UHpvMV4BQ/88ORr2+4fW/s4Wvb8QjE08vLz2K/tVdh mrh14O3l5s1uwOG5cfUfNu1p9jGgUCW/RvWBNirGJkBS+BX/zouwg7Q/0zOIy9xyik JDN3eCZTkbQcHVui1HqdkfXkAz8O+/SbnII0wvplkrCLONxc0jSCOmM1UpfzeYjv4u r0PUl1yZI0nWK6Jxha2s8ooMBnZ7l80+PiycpZmSAGXH5Zkr/+tKsIqw9+UAOxQYmJ 7Ig0Hzji3Uy1g== 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 v2 05/14] selftests/bpf: Use connect_to_addr in sk_assign Date: Thu, 11 Apr 2024 09:03:13 +0800 Message-Id: <55a16644cf8b53e2bbf305fbd9ae21c6f8ad3cbf.1712796967.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Geliang Tang This patch uses public helper connect_to_addr() exported in network_helpers.h instead of the local defined function connect_to_server() in prog_tests/sk_assign.c. This can avoid duplicate code. The code that sets SO_SNDTIMEO timeout as timeo_sec (3s) can be dropped, since connect_to_addr() sets default timeout as 3s. Signed-off-by: Geliang Tang --- .../selftests/bpf/prog_tests/sk_assign.c | 26 +------------------ 1 file changed, 1 insertion(+), 25 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/sk_assign.c b/tools/testing/selftests/bpf/prog_tests/sk_assign.c index 130aafe8cff6..b574e162ce6e 100644 --- a/tools/testing/selftests/bpf/prog_tests/sk_assign.c +++ b/tools/testing/selftests/bpf/prog_tests/sk_assign.c @@ -23,8 +23,6 @@ #define NS_SELF "/proc/self/ns/net" #define SERVER_MAP_PATH "/sys/fs/bpf/tc/globals/server_map" -static const struct timeval timeo_sec = { .tv_sec = 3 }; -static const size_t timeo_optlen = sizeof(timeo_sec); static int stop, duration; static bool @@ -74,28 +72,6 @@ configure_stack(void) return true; } -static int -connect_to_server(const struct sockaddr *addr, socklen_t len, int type) -{ - int fd = -1; - - fd = socket(addr->sa_family, type, 0); - if (CHECK_FAIL(fd == -1)) - goto out; - if (CHECK_FAIL(setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, &timeo_sec, - timeo_optlen))) - goto close_out; - if (CHECK_FAIL(connect(fd, addr, len))) - goto close_out; - - goto out; -close_out: - close(fd); - fd = -1; -out: - return fd; -} - static in_port_t get_port(int fd) { @@ -138,7 +114,7 @@ run_test(int server_fd, const struct sockaddr *addr, socklen_t len, int type) in_port_t port; int ret = 1; - client = connect_to_server(addr, len, type); + client = connect_to_addr((struct sockaddr_storage *)addr, len, type); if (client == -1) { perror("Cannot connect to server"); goto out; From patchwork Thu Apr 11 01:03:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13625261 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 E84D4604B3; Thu, 11 Apr 2024 01:04:11 +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=1712797452; cv=none; b=fL8/Msw90jY8c/KPlXyLkuB7DTC7LRAzlch8KiOOxTehVIuVdQyurdujLk8kOqWzmzFEUrnmX1+ecEYH4w6QPCM1OZHBzvoHhbKnjodvNObvmvhxk6ixTHQoSdeeNmRcgsPj7maCD5a4tcj6IqcCBTvT+gxBbCjIZsn7XgBsJhk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712797452; c=relaxed/simple; bh=DHoqFzvR8h5e0Ka81U5pi4ylSFr7lfzO4yBmabLLGH0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=CIj49r1cnTL9PTvWKSYFADsIysxQhUG4MevAFxN49aliKMEtEQGo23ZlwKTwmshLVD/C7jHBfKILcR1GpWwoMfI1MrJSN5F6yOrtuEu8GgCYx/ZiobWeHT9vfcEPOchwexfl8J4VgcWfOkAvhyKI4QCgFkRYpSsejN8WPByH+I4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=F2tLgnTO; 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="F2tLgnTO" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C463EC433C7; Thu, 11 Apr 2024 01:04:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712797451; bh=DHoqFzvR8h5e0Ka81U5pi4ylSFr7lfzO4yBmabLLGH0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=F2tLgnTOhrXYzLea29+C8wWkjfueJJKh4q00kJJ3aVNXrJsCy3R1r7AFRy7OlFiCE ckjRsvqIyzkk/4Nrw7Pm5BRyeir4BOFvEi3tuLWLmt+K4AhCpf7Gu9rPFbwnplfYqU o2daSFPd5BiIZRRChhEadDOJKHJwPhb/o34n/Y5xxAF41XLo3XkhUv+f4H65Sun6hG 7W6yp1r2nh80cwzyXA9c8f5MhruRcOkhCnbZ5mm5uiG9ViL4VBEyV78irhGBWBwyBB IjFUxlAAdCEBVCYu/mFhxkZ9ta6oL5P5b8CraruH//qwTB8x4qDBk7D8+ZaycXb8y3 njVqgV+Xm8mcQ== 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 v2 06/14] selftests/bpf: Use log_err in network_helpers Date: Thu, 11 Apr 2024 09:03:14 +0800 Message-Id: X-Mailer: git-send-email 2.40.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Geliang Tang The helpers ASSERT_OK/GE/OK_PTR should avoid using in public functions. This patch uses log_err() to replace them in network_helpers.c. Signed-off-by: Geliang Tang --- tools/testing/selftests/bpf/network_helpers.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c index 7ddeb6698ec7..91b014784dd9 100644 --- a/tools/testing/selftests/bpf/network_helpers.c +++ b/tools/testing/selftests/bpf/network_helpers.c @@ -447,22 +447,30 @@ struct nstoken *open_netns(const char *name) struct nstoken *token; token = calloc(1, sizeof(struct nstoken)); - if (!ASSERT_OK_PTR(token, "malloc token")) + if (!token) { + log_err("malloc token"); return NULL; + } token->orig_netns_fd = open("/proc/self/ns/net", O_RDONLY); - if (!ASSERT_GE(token->orig_netns_fd, 0, "open /proc/self/ns/net")) + if (token->orig_netns_fd <= 0) { + log_err("open /proc/self/ns/net"); goto fail; + } snprintf(nspath, sizeof(nspath), "%s/%s", "/var/run/netns", name); nsfd = open(nspath, O_RDONLY | O_CLOEXEC); - if (!ASSERT_GE(nsfd, 0, "open netns fd")) + if (nsfd <= 0) { + log_err("open netns fd"); goto fail; + } err = setns(nsfd, CLONE_NEWNET); close(nsfd); - if (!ASSERT_OK(err, "setns")) + if (err) { + log_err("setns"); goto fail; + } return token; fail: @@ -475,7 +483,8 @@ void close_netns(struct nstoken *token) if (!token) return; - ASSERT_OK(setns(token->orig_netns_fd, CLONE_NEWNET), "setns"); + if (setns(token->orig_netns_fd, CLONE_NEWNET)) + log_err("setns"); close(token->orig_netns_fd); free(token); } From patchwork Thu Apr 11 01:03:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13625262 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 BE297EEDA; Thu, 11 Apr 2024 01:04:18 +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=1712797458; cv=none; b=AM/5OybxnJTsUuSHO1DnF+dY2Wml1s6MaPBtsVv5Md/WVBt/0P+Xo2B2cX96AkXvxf/zNZVuqQbg3jsNFk9uV6u7ZBWKXaDvil5/ndT73kMYMsVXUlXHMBsqrq9VDTfKiDdoRWN71ZYEAmP8tnV70STRvle7hcNLj4+nc3ttsm4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712797458; c=relaxed/simple; bh=zi+o6uclkjcrk8md1bNQnPKb1sjr2NUYeI4Bz4JNeeE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=bhdGlQgL5spOFAnIcBoOG2s4lNM38yjAABAlhy93TuWJkX7rRNR+jJnYGkKPmjT0gkB3WamwLox1yJot1G/yC1QBe68PzUNq4AXvowF9O04ejePIDnDtuTEwnuKeGqhaMFPUQOyiOt8DiBHh/nPZDVds0GMmkKEL5VNYNGAxY0c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XRGAQqU9; 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="XRGAQqU9" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 437C3C433C7; Thu, 11 Apr 2024 01:04:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712797458; bh=zi+o6uclkjcrk8md1bNQnPKb1sjr2NUYeI4Bz4JNeeE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XRGAQqU9UJ/PARgnXGwvWsNhpUiVJNl5DZtTE9OdjxiqqG1VB4H88E8oNDzGRhEQI 5X7nAsKeG0Ri5GKGjhdPxfrgKyp/wUKhdjIAPjb8ObccSu7K1CkvXPT6lio81pRYwS ChjIVXvW+k7o0GdikONdm5alfs/cUPc7xS2Jg/ogxMinQ9gepBC+bssd/tcd9MMa7D R/Go4P7zWAUOT+XuKUMVlLk0P+yFA7g/6/0oM8XVfTQVqm3sZpanI9P+Et8h944KvC HmMcb72RT+YB5QAcJmVZMugIbTkB7j9Au8gGgjf5C8km+mvnyy1RC0/UDiudEeetgu VHWRYCBmSVvLg== 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 v2 07/14] selftests/bpf: Use start_server_addr in test_sock_addr Date: Thu, 11 Apr 2024 09:03:15 +0800 Message-Id: X-Mailer: git-send-email 2.40.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Geliang Tang Include network_helpers.h in test_sock_addr.c, use the newly added public helper start_server_addr() instead of the local defined function start_server(). This can avoid duplicate code. In order to use functions defined in network_helpers.c, Makefile needs to be updated and needs to be included in network_helpers.h to avoid compilation errors. Signed-off-by: Geliang Tang --- tools/testing/selftests/bpf/Makefile | 3 +- tools/testing/selftests/bpf/network_helpers.h | 1 + tools/testing/selftests/bpf/test_sock_addr.c | 38 ++----------------- 3 files changed, 7 insertions(+), 35 deletions(-) diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile index 3b9eb40d6343..c8049d1d13b5 100644 --- a/tools/testing/selftests/bpf/Makefile +++ b/tools/testing/selftests/bpf/Makefile @@ -290,11 +290,12 @@ UNPRIV_HELPERS := $(OUTPUT)/unpriv_helpers.o TRACE_HELPERS := $(OUTPUT)/trace_helpers.o JSON_WRITER := $(OUTPUT)/json_writer.o CAP_HELPERS := $(OUTPUT)/cap_helpers.o +NETWORK_HELPERS := $(OUTPUT)/network_helpers.o $(OUTPUT)/test_dev_cgroup: $(CGROUP_HELPERS) $(TESTING_HELPERS) $(OUTPUT)/test_skb_cgroup_id_user: $(CGROUP_HELPERS) $(TESTING_HELPERS) $(OUTPUT)/test_sock: $(CGROUP_HELPERS) $(TESTING_HELPERS) -$(OUTPUT)/test_sock_addr: $(CGROUP_HELPERS) $(TESTING_HELPERS) +$(OUTPUT)/test_sock_addr: $(CGROUP_HELPERS) $(TESTING_HELPERS) $(NETWORK_HELPERS) $(OUTPUT)/test_sockmap: $(CGROUP_HELPERS) $(TESTING_HELPERS) $(OUTPUT)/test_tcpnotify_user: $(CGROUP_HELPERS) $(TESTING_HELPERS) $(TRACE_HELPERS) $(OUTPUT)/get_cgroup_id_user: $(CGROUP_HELPERS) $(TESTING_HELPERS) diff --git a/tools/testing/selftests/bpf/network_helpers.h b/tools/testing/selftests/bpf/network_helpers.h index 89f59b65ce76..738b1764f562 100644 --- a/tools/testing/selftests/bpf/network_helpers.h +++ b/tools/testing/selftests/bpf/network_helpers.h @@ -11,6 +11,7 @@ typedef __u16 __sum16; #include #include #include +#include #include #include #include diff --git a/tools/testing/selftests/bpf/test_sock_addr.c b/tools/testing/selftests/bpf/test_sock_addr.c index 80c42583f597..8fa6bec8f7a5 100644 --- a/tools/testing/selftests/bpf/test_sock_addr.c +++ b/tools/testing/selftests/bpf/test_sock_addr.c @@ -19,6 +19,7 @@ #include #include "cgroup_helpers.h" +#include "network_helpers.h" #include "testing_helpers.h" #include "bpf_util.h" @@ -939,37 +940,6 @@ static int cmp_peer_addr(int sock1, const struct sockaddr_storage *addr2) return cmp_sock_addr(getpeername, sock1, addr2, /*cmp_port*/ 1); } -static int start_server(int type, const struct sockaddr_storage *addr, - socklen_t addr_len) -{ - int fd; - - fd = socket(addr->ss_family, type, 0); - if (fd == -1) { - log_err("Failed to create server socket"); - goto out; - } - - if (bind(fd, (const struct sockaddr *)addr, addr_len) == -1) { - log_err("Failed to bind server socket"); - goto close_out; - } - - if (type == SOCK_STREAM) { - if (listen(fd, 128) == -1) { - log_err("Failed to listen on server socket"); - goto close_out; - } - } - - goto out; -close_out: - close(fd); - fd = -1; -out: - return fd; -} - static int connect_to_server(int type, const struct sockaddr_storage *addr, socklen_t addr_len) { @@ -1178,7 +1148,7 @@ static int run_bind_test_case(const struct sock_addr_test *test) if (init_addrs(test, &requested_addr, &expected_addr, NULL)) goto err; - servfd = start_server(test->type, &requested_addr, addr_len); + servfd = start_server_addr((struct sockaddr *)&requested_addr, addr_len, test->type); if (servfd == -1) goto err; @@ -1214,7 +1184,7 @@ static int run_connect_test_case(const struct sock_addr_test *test) goto err; /* Prepare server to connect to */ - servfd = start_server(test->type, &expected_addr, addr_len); + servfd = start_server_addr((struct sockaddr *)&expected_addr, addr_len, test->type); if (servfd == -1) goto err; @@ -1271,7 +1241,7 @@ static int run_xmsg_test_case(const struct sock_addr_test *test, int max_cmsg) goto err; /* Prepare server to sendmsg to */ - servfd = start_server(test->type, &server_addr, addr_len); + servfd = start_server_addr((struct sockaddr *)&server_addr, addr_len, test->type); if (servfd == -1) goto err; From patchwork Thu Apr 11 01:03:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13625263 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 CE1C15FDD1; Thu, 11 Apr 2024 01:04:25 +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=1712797465; cv=none; b=s0rC+Cz+0CpMgqBrJbQbNO2boj9npKghxWjp1XHxGBPmQ+0jKqkWTbDfRJW/wWf7/VYKwbxp9EhblGGfaRzA/aD8JP0ldcNNGbx8dGosiSMtwqgBYSY6cSEeNO/ODbphEnuAQ3K7e8h8LCry/UPbi+GzuxSmI1gMqV9oTle7vjI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712797465; c=relaxed/simple; bh=zgJeV6DRmGVjHX4hBjMfwVzhEFdDeZ/nyzCdaQvCHS4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=BdUe+sMss8ZOmgULtPEnS8uZAp49uU2C/p3ap1Qu9KC6KVNPZo7qNGQ7F/tR4rK0VADuGUDwLUNDhqhcfmXeAFrqfs+ozBshNrAQ5koKepoycb60l9fXBIAPIgZBZP2FRyE+BhNV003hsM0RSP1O0QuL0c32YQjvD3MSAuu4OfU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=oBfUu4ve; 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="oBfUu4ve" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0A6C9C433F1; Thu, 11 Apr 2024 01:04:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712797465; bh=zgJeV6DRmGVjHX4hBjMfwVzhEFdDeZ/nyzCdaQvCHS4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oBfUu4veL3LNkzDIgc2ezyU1JGsupM1VcrzvWC5LwQSnCTRcreJTwZG8u01ECYb8T eKalrWr1qF+h32rktWowcujcwR/SCb/spY+YxYB0Ah60ow/g6jru1a6yXyAZ7hhE+W hwHjFZ4eZlTCbj0EBKdrSCeXQyPVtJalgJceLETtmN/SCwYomo33BPPX1NZD6R1nPt GdWxO7mb4mTT1cvrs3/vxei1nflBocGgqjC9lZLZ1GzVi5K5k7INbfxa2+PlHToLUA HFMCyszvGpeMu3m/DAbF/e9un50+LRw+JIhun9q0o8ShWmrLMX6urVcYggMS66iTQp M0l23p3gfwXTA== 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 v2 08/14] selftests/bpf: Use connect_to_addr in test_sock_addr Date: Thu, 11 Apr 2024 09:03:16 +0800 Message-Id: <7d5d626203c07fbc092df66cc2efea56f9bd3c25.1712796967.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Geliang Tang This patch uses public helper connect_to_addr() exported in network_helpers.h instead of the local defined function connect_to_server() in test_sock_addr.c. This can avoid duplicate code. Signed-off-by: Geliang Tang --- tools/testing/selftests/bpf/test_sock_addr.c | 36 ++------------------ 1 file changed, 2 insertions(+), 34 deletions(-) diff --git a/tools/testing/selftests/bpf/test_sock_addr.c b/tools/testing/selftests/bpf/test_sock_addr.c index 8fa6bec8f7a5..743ff05e7755 100644 --- a/tools/testing/selftests/bpf/test_sock_addr.c +++ b/tools/testing/selftests/bpf/test_sock_addr.c @@ -940,38 +940,6 @@ static int cmp_peer_addr(int sock1, const struct sockaddr_storage *addr2) return cmp_sock_addr(getpeername, sock1, addr2, /*cmp_port*/ 1); } -static int connect_to_server(int type, const struct sockaddr_storage *addr, - socklen_t addr_len) -{ - int domain; - int fd = -1; - - domain = addr->ss_family; - - if (domain != AF_INET && domain != AF_INET6) { - log_err("Unsupported address family"); - goto err; - } - - fd = socket(domain, type, 0); - if (fd == -1) { - log_err("Failed to create client socket"); - goto err; - } - - if (connect(fd, (const struct sockaddr *)addr, addr_len) == -1) { - log_err("Fail to connect to server"); - goto err; - } - - goto out; -err: - close(fd); - fd = -1; -out: - return fd; -} - int init_pktinfo(int domain, struct cmsghdr *cmsg) { struct in6_pktinfo *pktinfo6; @@ -1156,7 +1124,7 @@ static int run_bind_test_case(const struct sock_addr_test *test) goto err; /* Try to connect to server just in case */ - clientfd = connect_to_server(test->type, &expected_addr, addr_len); + clientfd = connect_to_addr(&expected_addr, addr_len, test->type); if (clientfd == -1) goto err; @@ -1188,7 +1156,7 @@ static int run_connect_test_case(const struct sock_addr_test *test) if (servfd == -1) goto err; - clientfd = connect_to_server(test->type, &requested_addr, addr_len); + clientfd = connect_to_addr(&requested_addr, addr_len, test->type); if (clientfd == -1) goto err; From patchwork Thu Apr 11 01:03:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13625264 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 24E66EEB5; Thu, 11 Apr 2024 01:04:31 +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=1712797472; cv=none; b=Wkz3Y/3TdrWeqjWwgieHyS2Q0tZT3mO+H6CZRCHEVwLGp8l5c+zW2e3GFL76c7NmbxSg2MFU7zDzYgsNtGzmtbCNUYca7gTGk0nuEJxg2JtEQyWjqe4gFEu5kOVpUnPlpUy15jYQ8YHDXIoejXySaegrBtPOdzcFUbYbPUXa0z8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712797472; c=relaxed/simple; bh=OeODH0klwt+6i/ftihxA/lIrmuSswUPkNOdx9aZwfUc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=QF0izMf5WwR1Rc2GsjxmZIMH/daj3SFgHOFM2CSRNWWYuAgZF7gr4U+iHGfkI2iCsQoBSjW+JVZE3ReDLAsLAQoYZXr5uon9qAua+8u3gQXJmvcJs5WzBQ263CFCquruI/bwaDCd7R0ZOSV6HvylAASfAItZHeKaBw4AatJaXk8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=iMSYUceg; 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="iMSYUceg" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1588FC433C7; Thu, 11 Apr 2024 01:04:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712797471; bh=OeODH0klwt+6i/ftihxA/lIrmuSswUPkNOdx9aZwfUc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iMSYUcegY5kgEHrb8bQs3BbZI9+G88/ru6J5KlSk8dsQr/8vcggrGznGw8E0bYD25 7aHFFvhPPogco86DpG2LGtvFpaIiji3g9QUNPflAlPzsW4N2N5I/k3CVGeGpPy9n7n X00LPGTx/bkFqGSzcG3CPtHoavLBIR1aB4oukaebsQpkTBvT8hTr6k4sseV8tAT/cl g4cUazW0JkNM2UA4zFurmw+DWfF80L8OuiTziS4YxbqTc0DGceQI3DqSaOh8DsFvpn xzX56Jn9SjNxqP5zN4i6qUl/RPicbH06PtDSjRHXCWPnKXyZmYU+ZnTnUQqQwvxniI WrhKt3KwvUzvg== 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 v2 09/14] selftests/bpf: Add function pointer for __start_server Date: Thu, 11 Apr 2024 09:03:17 +0800 Message-Id: X-Mailer: git-send-email 2.40.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Geliang Tang __start_server() sets SO_REUSPORT through setsockopt() when the parameter 'reuseport' is set. This patch makes it more flexible by accepting a function pointer named setsockopt. Then the original start_reuseport_server() can be implemented by passing in a newly defined setsockopt_reuse() function pointer to __start_server(). Signed-off-by: Geliang Tang --- tools/testing/selftests/bpf/network_helpers.c | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c index 91b014784dd9..2a389e8c2503 100644 --- a/tools/testing/selftests/bpf/network_helpers.c +++ b/tools/testing/selftests/bpf/network_helpers.c @@ -79,9 +79,9 @@ 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, int protocol, const struct sockaddr *addr, - socklen_t addrlen, int timeout_ms, bool reuseport) + socklen_t addrlen, int timeout_ms, + int *(*setsockopt)(int fd, int val), int val) { - int on = 1; int fd; fd = socket(addr->sa_family, type, protocol); @@ -93,9 +93,8 @@ static int __start_server(int type, int protocol, const struct sockaddr *addr, if (settimeo(fd, timeout_ms)) goto error_close; - if (reuseport && - setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &on, sizeof(on))) { - log_err("Failed to set SO_REUSEPORT"); + if (setsockopt && setsockopt(fd, val)) { + log_err("Failed to set sockopt"); goto error_close; } @@ -128,7 +127,7 @@ static int start_server_proto(int family, int type, int protocol, return -1; return __start_server(type, protocol, (struct sockaddr *)&addr, - addrlen, timeout_ms, false); + addrlen, timeout_ms, NULL, 0); } int start_server(int family, int type, const char *addr_str, __u16 port, @@ -144,6 +143,11 @@ int start_mptcp_server(int family, const char *addr_str, __u16 port, port, timeout_ms); } +static int setsockopt_reuse(int fd, int on) +{ + return setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &on, sizeof(on)); +} + int *start_reuseport_server(int family, int type, const char *addr_str, __u16 port, int timeout_ms, unsigned int nr_listens) { @@ -163,7 +167,7 @@ int *start_reuseport_server(int family, int type, const char *addr_str, return NULL; fds[0] = __start_server(type, 0, (struct sockaddr *)&addr, addrlen, - timeout_ms, true); + timeout_ms, (void *)setsockopt_reuse, 1); if (fds[0] == -1) goto close_fds; nr_fds = 1; @@ -173,7 +177,7 @@ int *start_reuseport_server(int family, int type, const char *addr_str, for (; nr_fds < nr_listens; nr_fds++) { fds[nr_fds] = __start_server(type, 0, (struct sockaddr *)&addr, - addrlen, timeout_ms, true); + addrlen, timeout_ms, (void *)setsockopt_reuse, 1); if (fds[nr_fds] == -1) goto close_fds; } @@ -187,7 +191,7 @@ int *start_reuseport_server(int family, int type, const char *addr_str, int start_server_addr(const struct sockaddr *addr, socklen_t addrlen, int type) { - return __start_server(type, 0, addr, addrlen, 0, 0); + return __start_server(type, 0, addr, addrlen, 0, NULL, 0); } void free_fds(int *fds, unsigned int nr_close_fds) From patchwork Thu Apr 11 01:03:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13625265 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 51EC3EEB5; Thu, 11 Apr 2024 01:04:37 +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=1712797478; cv=none; b=q6M5n5mtcO9RZIbzdnxl7Jf6oZkZdY08RCvMKlYcxcbZBPkcokyTuXdOuvC1iwLqqePq5kU7iw3a+q+zxSsjR7TC+Ht37Opg+acnlFn8INmesizd4XR1xl0WCeQEFhxazx46DbiF4XbYiii7w6lOQqsYFhRamnfdUcUrnimUds8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712797478; c=relaxed/simple; bh=Pz4ujWmcp2brvLUaNw44/Jpxi7AGSx14STq9+IUuYNg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=KKj3EdwX4pHlYFJDq2rBJcforacG4I/8CzxbQnuEbTFnlNUxpaWfTxXapYFRVsDhYPzojdPFy+gp+wgJXNDWGYJhKSmHwwrC/KeaVWI6g5AkQetLckKmoAMo5QsDiM1eJwg/+u5wLWH+We6p9ozJ9jFjS8kfpA3FAWe4WZUDpWs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ZCGlJ73o; 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="ZCGlJ73o" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 36B2DC43399; Thu, 11 Apr 2024 01:04:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712797477; bh=Pz4ujWmcp2brvLUaNw44/Jpxi7AGSx14STq9+IUuYNg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZCGlJ73oHRuLypSwtlMZoeg2hl9Qrdb1gaEo4gDhAHiGj2KbYC525K655ZPBsx1IR rG9Tcm4tXvhMs8/qT7qs4HbaxYt2DUkbC6DyOKqp7Cj7Kqp5cxH8wt9PdURQyuwVnj oDaH6ig5ZgwT9TKlledWRA/VcyorumRlacm0Tx8ZrBoq/NT5UO7sgqE3tXu4phPg6C upVTta2ru6+JHKvIv5GZELCveV0wVuWNwXyI6dOmX8aSrpy/GhjUff9SxYFJzkTHDc O6EO/sf/aaKvuR3uLUDjEdd28p0i0b7Av5DvvU5BOAu64RHyy7vUIwNb20HbTsIwYp 0Ao8kJf5E5o5A== 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 v2 10/14] selftests/bpf: Add start_server_setsockopt helper Date: Thu, 11 Apr 2024 09:03:18 +0800 Message-Id: <3285ff8422870c291a4d20d2f1e79fe0bc8d9557.1712796967.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Geliang Tang This patch adds a new helper start_server_setsockopt(), which is a wrapper of __start_server(), and accepts a function pointer setsockopt as a parameter. Signed-off-by: Geliang Tang --- tools/testing/selftests/bpf/network_helpers.c | 6 ++++++ tools/testing/selftests/bpf/network_helpers.h | 2 ++ 2 files changed, 8 insertions(+) diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c index 2a389e8c2503..227ed132b84a 100644 --- a/tools/testing/selftests/bpf/network_helpers.c +++ b/tools/testing/selftests/bpf/network_helpers.c @@ -194,6 +194,12 @@ int start_server_addr(const struct sockaddr *addr, socklen_t addrlen, int type) return __start_server(type, 0, addr, addrlen, 0, NULL, 0); } +int start_server_setsockopt(const struct sockaddr *addr, socklen_t addrlen, int type, + int *(*setsockopt)(int fd, int val), int val) +{ + return __start_server(type, 0, addr, addrlen, 0, setsockopt, val); +} + void free_fds(int *fds, unsigned int nr_close_fds) { if (fds) { diff --git a/tools/testing/selftests/bpf/network_helpers.h b/tools/testing/selftests/bpf/network_helpers.h index 738b1764f562..543295230062 100644 --- a/tools/testing/selftests/bpf/network_helpers.h +++ b/tools/testing/selftests/bpf/network_helpers.h @@ -55,6 +55,8 @@ 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(const struct sockaddr *addr, socklen_t addrlen, int type); +int start_server_setsockopt(const struct sockaddr *addr, socklen_t addrlen, int type, + int *(*setsockopt)(int fd, int val), int val); void free_fds(int *fds, unsigned int nr_close_fds); int connect_to_addr(const struct sockaddr_storage *addr, socklen_t len, int type); int connect_to_fd(int server_fd, int timeout_ms); From patchwork Thu Apr 11 01:03:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13625266 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 97DABEEB5; Thu, 11 Apr 2024 01:04:44 +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=1712797484; cv=none; b=LA+fpz5TDnXintuFOu4mUwVkGNy+2hUIfjgO2FyBRcMxtgr6zyNCn+p1p2HoTtabSj7WF/F2u1va5mk/t5OpM5JPLy83Z8oNTRFstmh46T9PFs1Y46u9GvjElinKoDvO4TeXEBMOr1Wme6BffsRmvqDRfwpBtf7aLb1Gii6L1yw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712797484; c=relaxed/simple; bh=zZcnBQfKixrMVLzDiYNjVUUGOzJiKw5LGXwrJ09Y7ys=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=RX4i7IcAt89n16XdsWBDaGhLbZgJ6iRUXVF9GKolbzUwu60TY9YmwIIDhz+7Q5agnlQ8vgNB83OupQeqHyx735SJQkHRPwjYz8jnzVRXKpd0JdUWOUc41lN6qnLqxR1iv4RwnzMnrtdE/CYaTQXTYNGJ8uleWNdh/0E0/Pi2iSs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ZxxRRgTL; 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="ZxxRRgTL" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 70652C433F1; Thu, 11 Apr 2024 01:04:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712797484; bh=zZcnBQfKixrMVLzDiYNjVUUGOzJiKw5LGXwrJ09Y7ys=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZxxRRgTLi0/B0F9vkiU05YLDSvddaK+UDOFKwcnDcBLldgA2T3miVzVDrjJjVtDyE VpXvLsT32J1bEzs/IgP3CSGTwgYbGCn19QK8d8ZxJrC/v4SzSDnasJhbOsbtB0CLxE uYhuPbaGSuQIuoc/M5qRz5ZZOvXzfW+B9mAr2OuPaTPJp/QGensvOq8CGo529+vrfp B6GdP4Bq3Y7+xopwxhnnmGqUcrEdoaQeIWYaRneTUdvmtocfp/m5tHxrDwJ/as1VyF Oe8ehEIhwIPT4hPt2xgBPHPej8Ak0vMB9NLRzQ0j9zVwIT4UAaeXHxGgI4GQ7Bm/3O G3gdn8S1wVjjw== 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 v2 11/14] selftests/bpf: Use start_server_setsockopt in sockopt_inherit Date: Thu, 11 Apr 2024 09:03:19 +0800 Message-Id: X-Mailer: git-send-email 2.40.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Geliang Tang Include network_helpers.h in prog_tests/sockopt_inherit.c, use public helpers make_sockaddr() and start_server_setsockopt() instead of the local defined function start_server(). This can avoid duplicate code. Add a helper setsockopt_loop() to set SOL_CUSTOM sockopt looply, and pass it to start_server_setsockopt(). Signed-off-by: Geliang Tang --- .../bpf/prog_tests/sockopt_inherit.c | 33 ++++++++----------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/sockopt_inherit.c b/tools/testing/selftests/bpf/prog_tests/sockopt_inherit.c index 917f486db826..f000d9229765 100644 --- a/tools/testing/selftests/bpf/prog_tests/sockopt_inherit.c +++ b/tools/testing/selftests/bpf/prog_tests/sockopt_inherit.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 #include #include "cgroup_helpers.h" +#include "network_helpers.h" #include "sockopt_inherit.skel.h" @@ -98,23 +99,12 @@ static void *server_thread(void *arg) return (void *)(long)err; } -static int start_server(void) +static int setsockopt_loop(int fd, int val) { - struct sockaddr_in addr = { - .sin_family = AF_INET, - .sin_addr.s_addr = htonl(INADDR_LOOPBACK), - }; char buf; int err; - int fd; int i; - fd = socket(AF_INET, SOCK_STREAM, 0); - if (fd < 0) { - log_err("Failed to create server socket"); - return -1; - } - for (i = CUSTOM_INHERIT1; i <= CUSTOM_LISTENER; i++) { buf = 0x01; err = setsockopt(fd, SOL_CUSTOM, i, &buf, 1); @@ -125,13 +115,18 @@ static int start_server(void) } } - if (bind(fd, (const struct sockaddr *)&addr, sizeof(addr)) < 0) { - log_err("Failed to bind socket"); - close(fd); - return -1; - } + return 0; +} - return fd; +static int start_server_lo(void) +{ + struct sockaddr_storage addr; + socklen_t addrlen; + + if (make_sockaddr(AF_INET, "127.0.0.1", 0, &addr, &addrlen)) + return -1; + return start_server_setsockopt((struct sockaddr *)&addr, addrlen, + SOCK_STREAM, (void *)setsockopt_loop, 0); } static void run_test(int cgroup_fd) @@ -160,7 +155,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(); + server_fd = start_server_lo(); if (!ASSERT_GE(server_fd, 0, "start_server")) goto close_bpf_object; From patchwork Thu Apr 11 01:03:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13625267 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 A209F3201; Thu, 11 Apr 2024 01:04:51 +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=1712797491; cv=none; b=LBjoNtPaIaR7zI9G2SY4UsOg2uahAg4K5vlzxNhcNknJyh55u1aVpkLdU5CTAakqt2aTaOIF/BtVR/nkkQK3+gs09ToRpbQS+9mG++pnVhhxLCmrmyZNCQIz5uvm41u4w6NT11nYke4d3oYC4pBqE+CJwHtDyQzGy1Oa0W64X2s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712797491; c=relaxed/simple; bh=yZjR/xeezxILen9lY9+6wkHKExavQ/iubE/fh5VTeiw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=JRyrMQgfxH304s8po/Gy3EhUMR5G64qvRyjzrQWlcrcLGUu0F0b5ocwBfKMnZdaIVyEZeIFsyviZU3dHqa7qRVloirzopXi69rmeTMif9zJBiOuMlQDo8qsYJ7lZ8tdy3cAmxJmAClcDadJsS1EHvbt/+8S/ue5/Yw8QwS98oO8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jj2O03XG; 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="jj2O03XG" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D3831C43390; Thu, 11 Apr 2024 01:04:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712797491; bh=yZjR/xeezxILen9lY9+6wkHKExavQ/iubE/fh5VTeiw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jj2O03XGQpv2o+hE6boqz64HokWnzTXXKyD4Ooks7rPvQXu9zuCPd3qDnGi5tIw09 mnnt5wPUjIF4HZ3jRxlqrCR3aWrXzNJi004P3ztvataey6Jqo2t8Bww+vLY95CfKAD UD4dr+Yt3jOBFC4mISZEus/p8sa8F93oGo1/PdXdAbD11Nz8u6b7eDYHENIwp5gJ4b X/8zuXChZPqS5I/jP0N3/LHVv8RKy5yHFLdr2mKIKJpeuBPyrAeMt0CFBMnHA7QdCy Fv2Mj391p1TzGKj/iS2L1ipdiDBWeJNrcxtFzVOjIsexZqzxlYwTPvVFwbf9OMprIJ PNEQ0+z6BSsXA== 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 v2 12/14] selftests/bpf: Use connect_to_fd in sockopt_inherit Date: Thu, 11 Apr 2024 09:03:20 +0800 Message-Id: X-Mailer: git-send-email 2.40.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Geliang Tang This patch uses public helper connect_to_fd() exported in network_helpers.h instead of the local defined function connect_to_server() in prog_tests/sockopt_inherit.c. This can avoid duplicate code. Signed-off-by: Geliang Tang --- .../bpf/prog_tests/sockopt_inherit.c | 31 +------------------ 1 file changed, 1 insertion(+), 30 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/sockopt_inherit.c b/tools/testing/selftests/bpf/prog_tests/sockopt_inherit.c index f000d9229765..4fee4b343255 100644 --- a/tools/testing/selftests/bpf/prog_tests/sockopt_inherit.c +++ b/tools/testing/selftests/bpf/prog_tests/sockopt_inherit.c @@ -10,35 +10,6 @@ #define CUSTOM_INHERIT2 1 #define CUSTOM_LISTENER 2 -static int connect_to_server(int server_fd) -{ - struct sockaddr_storage addr; - socklen_t len = sizeof(addr); - int fd; - - fd = socket(AF_INET, SOCK_STREAM, 0); - if (fd < 0) { - log_err("Failed to create client socket"); - return -1; - } - - if (getsockname(server_fd, (struct sockaddr *)&addr, &len)) { - log_err("Failed to get server addr"); - goto out; - } - - if (connect(fd, (const struct sockaddr *)&addr, len) < 0) { - log_err("Fail to connect to server"); - goto out; - } - - return fd; - -out: - close(fd); - return -1; -} - static int verify_sockopt(int fd, int optname, const char *msg, char expected) { socklen_t optlen = 1; @@ -168,7 +139,7 @@ static void run_test(int cgroup_fd) pthread_cond_wait(&server_started, &server_started_mtx); pthread_mutex_unlock(&server_started_mtx); - client_fd = connect_to_server(server_fd); + client_fd = connect_to_fd(server_fd, 0); if (!ASSERT_GE(client_fd, 0, "connect_to_server")) goto close_server_fd; From patchwork Thu Apr 11 01:03:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13625268 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 32E23605BA; Thu, 11 Apr 2024 01:04:57 +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=1712797498; cv=none; b=TakL0edhcDTtqkzRo1U10oqmxPupwvWPxB2XSmvX/vWCDIpoXvLg5YfdgZq8hxhHth2t6k5406y8s/FGAgejSwFRmF/IWLpVn+YwJNstsP698xgO7kest5+mLKI7Il2PmRXmvVKK2Ib559avncJ+I+HzHziwLefMsi1ZLvrlBAY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712797498; c=relaxed/simple; bh=D681493RS9/j/Z5FXYsW/FjB6GnXH9LyJ4AKTGsA0ZM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=JI5GQGATtCHsQpeatvgIPWYGjJdKpzPQiDPasylb0kfrxzmPpLtTu+xQkMMw3CkI3UAF+0pEfCNNFhbjE5u+lG6T/u+wKqiFMrQ3jlEo24QaKTGjTVQGHsKp9OZfU7SY2qTB1z+9dccoQiL/KvpKmGXXtMk8CHMzRsBo3wdfGgI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=PeGS4oNa; 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="PeGS4oNa" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D7099C433C7; Thu, 11 Apr 2024 01:04:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712797497; bh=D681493RS9/j/Z5FXYsW/FjB6GnXH9LyJ4AKTGsA0ZM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PeGS4oNaosuVP/4FNzLSY3NtHKoLltvKG3pjH6k5mpvRSkK7orrIlugC3XB2uu4Xj E3Yh6RHx5LdMvr8Xa93IXIcK39VkR0Xve8CyPuB1+2ZiokLMVGaDqbRr2zcZDmUWZ1 youxt5dHbqLwnffu1dCt2xyoB6Xu4KFAKxTI7RTZsBc8obCSlnvjLiJXI384XnzndA TXNzlkqU20RVSYqpdDo7LAwD90YJO5OMYes/SAUJOIx9JySIy+LoXMate4dM5s+yno WeQfmRox5W3WeEmD2S4GUVqlxQmhIgrlFn/ObO3V+bQ9TfOo6h1U7cVlm5IN13Y6mM LU1odBPh3qOEA== 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 v2 13/14] selftests/bpf: Use start_server_* in test_tcp_check_syncookie Date: Thu, 11 Apr 2024 09:03:21 +0800 Message-Id: <9abfa7cda06cc5bf5a706bf546877c765e762112.1712796967.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Geliang Tang Include network_helpers.h in test_tcp_check_syncookie_user.c, use public helpers start_server_addr() and start_server_setsockopt() in it instead of the local defined function start_server(). This can avoid duplicate code. Add a helper setsockopt_mode() to set IPV6_V6ONLY sockopt, and pass it to start_server_setsockopt(). In order to use functions defined in network_helpers.c, Makefile needs to be updated to avoid compilation errors. Signed-off-by: Geliang Tang --- tools/testing/selftests/bpf/Makefile | 1 + .../bpf/test_tcp_check_syncookie_user.c | 50 ++++--------------- 2 files changed, 12 insertions(+), 39 deletions(-) diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile index c8049d1d13b5..1199a02a5ae4 100644 --- a/tools/testing/selftests/bpf/Makefile +++ b/tools/testing/selftests/bpf/Makefile @@ -309,6 +309,7 @@ $(OUTPUT)/flow_dissector_load: $(TESTING_HELPERS) $(OUTPUT)/test_maps: $(TESTING_HELPERS) $(OUTPUT)/test_verifier: $(TESTING_HELPERS) $(CAP_HELPERS) $(UNPRIV_HELPERS) $(OUTPUT)/xsk.o: $(BPFOBJ) +$(OUTPUT)/test_tcp_check_syncookie_user: $(NETWORK_HELPERS) BPFTOOL ?= $(DEFAULT_BPFTOOL) $(DEFAULT_BPFTOOL): $(wildcard $(BPFTOOLDIR)/*.[ch] $(BPFTOOLDIR)/Makefile) \ 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 32df93747095..e6ad4895d2b3 100644 --- a/tools/testing/selftests/bpf/test_tcp_check_syncookie_user.c +++ b/tools/testing/selftests/bpf/test_tcp_check_syncookie_user.c @@ -16,43 +16,13 @@ #include #include "cgroup_helpers.h" +#include "network_helpers.h" -static int start_server(const struct sockaddr *addr, socklen_t len, bool dual) +static int setsockopt_mode(int fd, int dual) { int mode = !dual; - int fd; - fd = socket(addr->sa_family, SOCK_STREAM, 0); - if (fd == -1) { - log_err("Failed to create server socket"); - goto out; - } - - if (addr->sa_family == AF_INET6) { - if (setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, (char *)&mode, - sizeof(mode)) == -1) { - log_err("Failed to set the dual-stack mode"); - goto close_out; - } - } - - if (bind(fd, addr, len) == -1) { - log_err("Failed to bind server socket"); - goto close_out; - } - - if (listen(fd, 128) == -1) { - log_err("Failed to listen on server socket"); - goto close_out; - } - - goto out; - -close_out: - close(fd); - fd = -1; -out: - return fd; + return setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, (char *)&mode, sizeof(mode)); } static int connect_to_server(const struct sockaddr *addr, socklen_t len) @@ -259,18 +229,20 @@ int main(int argc, char **argv) addr6dual.sin6_addr = in6addr_any; addr6dual.sin6_port = 0; - server = start_server((const struct sockaddr *)&addr4, sizeof(addr4), - false); + server = start_server_addr((const struct sockaddr *)&addr4, + sizeof(addr4), SOCK_STREAM); if (server == -1 || !get_port(server, &addr4.sin_port)) goto err; - server_v6 = start_server((const struct sockaddr *)&addr6, - sizeof(addr6), false); + server_v6 = start_server_setsockopt((const struct sockaddr *)&addr6, + sizeof(addr6), SOCK_STREAM, + (void *)setsockopt_mode, false); if (server_v6 == -1 || !get_port(server_v6, &addr6.sin6_port)) goto err; - server_dual = start_server((const struct sockaddr *)&addr6dual, - sizeof(addr6dual), true); + server_dual = start_server_setsockopt((const struct sockaddr *)&addr6dual, + sizeof(addr6dual), SOCK_STREAM, + (void *)setsockopt_mode, true); if (server_dual == -1 || !get_port(server_dual, &addr4dual.sin_port)) goto err; From patchwork Thu Apr 11 01:03:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13625269 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 D3D01604DD; Thu, 11 Apr 2024 01:05:04 +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=1712797504; cv=none; b=uVv7FDUXUYE0S390iTv65HJcv+dIzew5PYFQd3zqI9c11LQRzNUyxb5gRB+HU5FXLmVb+3aRMcZKwrbINrO71KPLoqY9hJddBhPHaeRX/2Rj3+D0ZjjzdA9N7sJQNEenWOH87OA/xXK+XpHNiUDzDyXR4tLALR8YSatnE5b69E4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712797504; c=relaxed/simple; bh=UMsJz02F0Aq81sLV0Yh1Banv8hIJKOdtNjKb5msmB68=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=rKsqKvfnRsDYaQP8i8OEULV8vVeYbthT2aqA9PQn64mv5pIur9xtLLghn2KlvibBn13ypfbUm0EWI6OHTCTnwpvcockg/tgOmTr5xWAHBV8LDCwUhQvQJ+ZtRJoUW4Nv7yMgdV9YiS4EBWL8Tj0+xciPz9TgpEFVdzXCt5C/Xfc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=oMKX3Rji; 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="oMKX3Rji" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6B88EC433F1; Thu, 11 Apr 2024 01:04:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712797504; bh=UMsJz02F0Aq81sLV0Yh1Banv8hIJKOdtNjKb5msmB68=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oMKX3RjiFi4+cQn01BrDMW7yFXz7N01+aT5CGFBx1dLnW57PQ7q4ZsiAUIfPW+Fvy 7bY5wecrKQ/Cwc2naMDb+x7RP1eNnTyxmHYrjao6sn3X2hhuPlW+QjjqiLPDyvm3Y3 LDRNvYa9bfbZyhpGgm1HMSReCDi1nQOIDnsVePHba+6KeCt7cUQ4i1XeEhuUp2R893 U2ov8jAmVYzjpZ6BumUbEjuq6L2xc5388krnYI8JYlnCDrTnPjX/b2tl4bgr8ZOe4E fprYQE3mhoqdGfK5mqOjLjhabjDZAZCsVlZpNy7udUa7xTELK5CX7oG/7fGEthUAvQ hXVjX2CxWEB1A== 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 v2 14/14] selftests/bpf: Use connect_to_addr in test_tcp_check_syncookie Date: Thu, 11 Apr 2024 09:03:22 +0800 Message-Id: <993fe5771221a5307d566ff88fcbf3f41ecad48f.1712796967.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Geliang Tang This patch uses public helper connect_to_addr() exported in network_helpers.h instead of the local defined function connect_to_server() in test_tcp_check_syncookie_user.c. This can avoid duplicate code. Signed-off-by: Geliang Tang --- .../bpf/test_tcp_check_syncookie_user.c | 26 +------------------ 1 file changed, 1 insertion(+), 25 deletions(-) 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 e6ad4895d2b3..e678228b915f 100644 --- a/tools/testing/selftests/bpf/test_tcp_check_syncookie_user.c +++ b/tools/testing/selftests/bpf/test_tcp_check_syncookie_user.c @@ -25,30 +25,6 @@ static int setsockopt_mode(int fd, int dual) return setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, (char *)&mode, sizeof(mode)); } -static int connect_to_server(const struct sockaddr *addr, socklen_t len) -{ - int fd = -1; - - fd = socket(addr->sa_family, SOCK_STREAM, 0); - if (fd == -1) { - log_err("Failed to create client socket"); - goto out; - } - - if (connect(fd, (const struct sockaddr *)addr, len) == -1) { - log_err("Fail to connect to server"); - goto close_out; - } - - goto out; - -close_out: - close(fd); - fd = -1; -out: - return fd; -} - static int get_map_fd_by_prog_id(int prog_id, bool *xdp) { struct bpf_prog_info info = {}; @@ -114,7 +90,7 @@ static int run_test(int server_fd, int results_fd, bool xdp, goto err; } - client = connect_to_server(addr, len); + client = connect_to_addr((struct sockaddr_storage *)addr, len, SOCK_STREAM); if (client == -1) goto err;