From patchwork Fri Jul 5 02:58:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13724392 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 6B1D7225AE; Fri, 5 Jul 2024 02:59: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=1720148362; cv=none; b=G9UZDPvU9/B85xJvnyNiwsDCtd/3kwTkNFHKS8+7i2/aUDoKxeI3IiRHon5OdQ8Vjhsmqmf3zVWoNja/5WnE6J3cyb3rlFlgllsYZneVn78Zu48da/hxnEviQL/kRjAdzXssP7+yQgZlRZb/g5Vfe5IFfAIyadBu8uLCJPw9xS8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720148362; c=relaxed/simple; bh=B7hg/lyFr/T3CIqXns6zB9hcYkz6130EeWwLxus1WNs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=i8RmneGVuXbGXAOB7xAtKBFspjjrfTOGWA6IuDPlpGliltR3kznbVp9/rzAlkFf+4m+hY7e+8hz/WVVGsQ1t1/YtXBpnXVbVAlQa848zYu6gAgMsXSrkvSyD7jDInT/k3kzPPNnKxeQqXTjsY2NP0J7R0T9HCGZCXg/jL+v9YD0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jcnGBD+9; 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="jcnGBD+9" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 45670C3277B; Fri, 5 Jul 2024 02:59:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1720148362; bh=B7hg/lyFr/T3CIqXns6zB9hcYkz6130EeWwLxus1WNs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jcnGBD+9XGnefj7PhzpcE54oyqbkT9fRGwsooMSNI3t0s2NTnUQa4u9V6sQhMXGUK /3DbqMlGuiNq32/pNJmzl/e6SV85nCfOQZSKkDvtI8vJo4x4FntasqHSwhUdM4ag2q 0bfmyoBxydmjHqVmTPqEeXNvQnguu79WbaZ5X1AFjkrP9GBn+a+gZBoIPMiCAvbaYA aRAeaUhnSL/mLDORkUZJv21dZaf2JNStPdnqZSA2PqkKLaDCicxUYzaaL59QqA8r3w LIPTyaYwYbt7fk/Xl0Legavdki2u1Jz5kqLzR9nNuBsisrAnonTf4PT5imRcSWi8KU 6SrjXPr4IKfBg== 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 v8 8/9] selftests/bpf: Use connect_to_addr in sk_lookup Date: Fri, 5 Jul 2024 10:58:30 +0800 Message-ID: <52c22148c66184baf5ba09d60c06d49a8a33d743.1720147953.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 Use public network helpers make_sockaddr() and connect_to_addr() instead of using the local defined function make_socket() and connect(). This make_socket() can be dropped latter. Signed-off-by: Geliang Tang --- .../selftests/bpf/prog_tests/sk_lookup.c | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/sk_lookup.c b/tools/testing/selftests/bpf/prog_tests/sk_lookup.c index ef4a3db34c5f..a436ed8b34e0 100644 --- a/tools/testing/selftests/bpf/prog_tests/sk_lookup.c +++ b/tools/testing/selftests/bpf/prog_tests/sk_lookup.c @@ -231,23 +231,19 @@ static int make_server(int sotype, const char *ip, int port, static int make_client(int sotype, const char *ip, int port) { + int family = is_ipv6(ip) ? AF_INET6 : AF_INET; + struct network_helper_opts opts = { + .timeout_ms = IO_TIMEOUT_SEC, + }; struct sockaddr_storage addr = {0}; - int err, fd; + socklen_t len; + int err; - fd = make_socket(sotype, ip, port, &addr); - if (fd < 0) + err = make_sockaddr(family, ip, port, &addr, &len); + if (!ASSERT_OK(err, "make_sockaddr")) return -1; - err = connect(fd, (void *)&addr, inetaddr_len(&addr)); - if (CHECK(err, "make_client", "connect")) { - log_err("failed to connect client socket"); - goto fail; - } - - return fd; -fail: - close(fd); - return -1; + return connect_to_addr(sotype, &addr, len, &opts); } static __u64 socket_cookie(int fd)