From patchwork Sat Jun 22 01:23:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13708169 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 0051D4C6B; Sat, 22 Jun 2024 01:24: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=1719019446; cv=none; b=GT4Pl8j+kCthDZk6BYp+G3CuPcJsH6lGmf71aMopJbAHucZJI1QAFzv6vgplIR4ziKne+SnsclYVwfCbFcUu0uCVm1gjMIRP20BFuQyagSf3EtXgltfo1La1Goirxpw3MB/Brpq8FdtNZAn17Bs6qJyPTHUlh6HbI//1yLneAS4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719019446; c=relaxed/simple; bh=bjmSYjP2RFZmTcSMLnDjwyAItZFAXOlLRE/0dxToen8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QvHcbMgwP94UPCAilLz+WyrUziVSeyQXrCtAdg0zGGWwZJTAZ9cGc00uMk6wzuEKQjzwar6lAuPSLDr51bZQNoWEC6lhodMYaSQsuR85vc0OrpomLiS2JclmHwaUY6Y/Ed137fKu0UHSOlJ+cLJEKPp9SE8H+VE0acUPSgV91ZQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OMnH+dPg; 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="OMnH+dPg" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A94E9C4AF0E; Sat, 22 Jun 2024 01:24:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719019445; bh=bjmSYjP2RFZmTcSMLnDjwyAItZFAXOlLRE/0dxToen8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OMnH+dPgXH3joL+VRQH8cay+r75KJhUjhWW7RlKCkqBeceLpyGvmle9dC3wabYKjW dzeZQ9OOxBtnxCz8KlTJiC8j3Ee2z0TQTb/kjXb4XrKTMbGOAf6t43mV5OUaMvCt8Z CbBQCKBIWzrUaTsNEyHRhf7xehPrpJ+8lagutHRZgKfb+qstxQQNc/LV013wYoBbf2 wwV6WJ2vrnCeNqEAlEkVnMLd3c4M1KCAEbNYNguGmBUQhB+/SJZ8CmvuUFbTvLc6Xn WltndDaB6Gnq2xRHvtD+G6Z1QXSidDOZnbzJukwzIIjbzOCvAwrWm4JDpHUz0exau/ 7cIwPltQQsuuQ== 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 1/7] selftests/bpf: Use start_server in sockmap_ktls Date: Sat, 22 Jun 2024 09:23:41 +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 Include network_helpers.h in prog_tests/sockmap_ktls.c, use public network helper start_server() instead of the local defined function tcp_server(). This can avoid duplicate code. Technically, this is not a one-for-one replacement, as start_server() also does bind() and it's listen backlog is 1, not SOMAXCONN. But the difference does not seem to matter. Acked-by: Eduard Zingerman Signed-off-by: Geliang Tang --- .../selftests/bpf/prog_tests/sockmap_ktls.c | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/sockmap_ktls.c b/tools/testing/selftests/bpf/prog_tests/sockmap_ktls.c index 2d0796314862..9cc881b38669 100644 --- a/tools/testing/selftests/bpf/prog_tests/sockmap_ktls.c +++ b/tools/testing/selftests/bpf/prog_tests/sockmap_ktls.c @@ -6,25 +6,11 @@ #include #include "test_progs.h" +#include "network_helpers.h" #define MAX_TEST_NAME 80 #define TCP_ULP 31 -static int tcp_server(int family) -{ - int err, s; - - s = socket(family, SOCK_STREAM, 0); - if (!ASSERT_GE(s, 0, "socket")) - return -1; - - err = listen(s, SOMAXCONN); - if (!ASSERT_OK(err, "listen")) - return -1; - - return s; -} - static int disconnect(int fd) { struct sockaddr unspec = { AF_UNSPEC }; @@ -39,7 +25,7 @@ static void test_sockmap_ktls_disconnect_after_delete(int family, int map) socklen_t len = sizeof(addr); int err, cli, srv, zero = 0; - srv = tcp_server(family); + srv = start_server(family, SOCK_STREAM, NULL, 0, 0); if (srv == -1) return; From patchwork Sat Jun 22 01:23:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13708170 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 115F64404; Sat, 22 Jun 2024 01:24:10 +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=1719019450; cv=none; b=qQR6eBuHrw6rakjYCq7lKFD+E+DxFj882vPsMKEsj2swkvG6IS0qajIxJOeBKLnnBwEb/z43rAd5Jqj8tb20uD/ytQFkqOFAnVADXX5ZQsQRXNlootzuIsCXeAMJTmxU8KiNMgudDL8+uh2g14w85A8okIxbsMt8ogPhky4Rdbk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719019450; c=relaxed/simple; bh=rZ0OwJbHuOAuxHZEiv3dpoarwqBZUxrIq68bMu+v91Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tNzo81ZRJJtYrgVa4eXes+oQra+Y/dn3hGAXWTU03WfMSqqYZPoBSTwbf5f7fMdS7Dny3slELRIPit4m7t+mewJckkIRPncfbHNJyNMXtk2zxz28Mdita6XoEbCvHCWpcc6hiJu91cisjwtMzq48qN2NDK6S6cz88N9bT5NikyY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=a1PVbRhg; 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="a1PVbRhg" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 13F30C4AF07; Sat, 22 Jun 2024 01:24:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719019449; bh=rZ0OwJbHuOAuxHZEiv3dpoarwqBZUxrIq68bMu+v91Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=a1PVbRhgLRrwtLRXr96acqK/3zoR1SsjSBLeWAm3r+fGEIPscTJoCOiARMA722o86 kr/glWF5LSGctMGS8481DXAt84WGcEMlPF1g+412/PoWxbsZcum1NDqL4Z6irsvwLJ opUvvn3L+LOSQWgRTbbSPicxWEmAe3tCN9w09quFbQrximQ+2VJzvIzXTljcy+U5Zr W12Bwa2T6tgYR4t3ew+Hsz4YEZMFmvGkaAOzir52J3KNLLkxhYqbpWEQUHP2epnad+ 7V7OdN2UuWJkjefUxwNJJE5xv8kGX6unm7NPuiV0LyEOcjIERr03+LSqUXBypbIl55 LgAUfTQ7E4kPg== 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 2/7] selftests/bpf: Use connect_to_fd in sockmap_ktls Date: Sat, 22 Jun 2024 09:23:42 +0800 Message-ID: <1f6a05f89fe56725f42a4e4fba517b61067f2036.1719019125.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 helper connect_to_fd() instead of open-coding it in prog_tests/sockmap_ktls.c. This can avoid duplicate code. Acked-by: Eduard Zingerman Signed-off-by: Geliang Tang --- .../selftests/bpf/prog_tests/sockmap_ktls.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/sockmap_ktls.c b/tools/testing/selftests/bpf/prog_tests/sockmap_ktls.c index 9cc881b38669..68867028c432 100644 --- a/tools/testing/selftests/bpf/prog_tests/sockmap_ktls.c +++ b/tools/testing/selftests/bpf/prog_tests/sockmap_ktls.c @@ -21,26 +21,16 @@ static int disconnect(int fd) /* Disconnect (unhash) a kTLS socket after removing it from sockmap. */ static void test_sockmap_ktls_disconnect_after_delete(int family, int map) { - struct sockaddr_storage addr = {0}; - socklen_t len = sizeof(addr); int err, cli, srv, zero = 0; srv = start_server(family, SOCK_STREAM, NULL, 0, 0); if (srv == -1) return; - err = getsockname(srv, (struct sockaddr *)&addr, &len); - if (!ASSERT_OK(err, "getsockopt")) - goto close_srv; - - cli = socket(family, SOCK_STREAM, 0); - if (!ASSERT_GE(cli, 0, "socket")) + cli = connect_to_fd(srv, 0); + if (!ASSERT_GE(cli, 0, "connect_to_fd")) goto close_srv; - err = connect(cli, (struct sockaddr *)&addr, len); - if (!ASSERT_OK(err, "connect")) - goto close_cli; - err = bpf_map_update_elem(map, &zero, &cli, 0); if (!ASSERT_OK(err, "bpf_map_update_elem")) goto close_cli; From patchwork Sat Jun 22 01:23:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13708171 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 D0EE5441D; Sat, 22 Jun 2024 01:24:14 +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=1719019454; cv=none; b=WU+VNBxUPnMvpi22DD7C4pHDnjCNi1y98sRZsuGbZGqoMcpg6hUrjZ44BHN6NPEdO1Cf1zIRN+C2KSfa5XhB/71K+Ut2+IjBuG3/kQV8GV+D+kkRwstS9zSpooj3A9x9XqY749a55froruNRkp0f3Ye9Kpc1qTnl0GuFWcu0iEA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719019454; c=relaxed/simple; bh=/lxFmWi7jg1WBjAVIvKF5h+VNV6it5HMrFyR1RnRPCs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=l1vLazGWzT88bT2DcFoJ9K7Fdlhe+laFawR2qlW3gJ2VZ8Yp28zRtW/8fPUkbXgezsZvZRGQzWwrZGpNFUDqRXjqC29kRmTZG6YaL3ANdyTEw8s6D7dWiEoHVvD/0uW/sOzlMLh0zAG2X6NO25PieQvA0Fj/dsVAAw/8URjEQ8U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=j64VBEv/; 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="j64VBEv/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 76923C2BBFC; Sat, 22 Jun 2024 01:24:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719019454; bh=/lxFmWi7jg1WBjAVIvKF5h+VNV6it5HMrFyR1RnRPCs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=j64VBEv/jmnT/8YDUccQ+neJMKje6gBz6YEBPRORpxCKH50aL9XQiduDpqmQ00QZe VfPVMXTJFCZj/faSCR5wl8XfQcd+N+rtSWVmfku+wKUftdtrk0Ch1MFYT8PNoCmd/0 Xpe0WFKqh69DdUnG6igjbR0wGEDkKotxlj/nsKJ7UItGbVY59zzu3OaQPSKqZnjve/ nGX3B9daw8zSqjQIxfQZDJ3BjalpVkxYEIvrD/wE1BPqXut4aBYU7fIXN0OTRdnevy IkccEjpUHPAxvAYGDXsDTjZP97rRMauSCI4S6SsmtPSCVu510kcneki9+HfTctKXLG Lzvx/SWPqfAGA== 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 3/7] selftests/bpf: Use start_server_str in sk_lookup Date: Sat, 22 Jun 2024 09:23:43 +0800 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net From: Geliang Tang This patch uses public helper start_server_addr() in make_server() in prog_tests/sk_lookup.c to avoid duplicate code. Add a helper setsockopts() to set SOL_CUSTOM sockopt looply, set it to setsockopt pointer of struct network_helper_opts, and pass it to start_server_addr(). Acked-by: Eduard Zingerman Signed-off-by: Geliang Tang --- .../selftests/bpf/prog_tests/sk_lookup.c | 57 +++++++++++-------- 1 file changed, 33 insertions(+), 24 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/sk_lookup.c b/tools/testing/selftests/bpf/prog_tests/sk_lookup.c index 597d0467a926..ba73b56f4484 100644 --- a/tools/testing/selftests/bpf/prog_tests/sk_lookup.c +++ b/tools/testing/selftests/bpf/prog_tests/sk_lookup.c @@ -77,6 +77,12 @@ struct test { bool reuseport_has_conns; /* Add a connected socket to reuseport group */ }; +struct cb_opts { + int family; + int sotype; + bool reuseport; +}; + static __u32 duration; /* for CHECK macro */ static bool is_ipv6(const char *ip) @@ -142,19 +148,14 @@ static int make_socket(int sotype, const char *ip, int port, return fd; } -static int make_server(int sotype, const char *ip, int port, - struct bpf_program *reuseport_prog) +static int setsockopts(int fd, void *opts) { - struct sockaddr_storage addr = {0}; + struct cb_opts *co = (struct cb_opts *)opts; const int one = 1; - int err, fd = -1; - - fd = make_socket(sotype, ip, port, &addr); - if (fd < 0) - return -1; + int err = 0; /* Enabled for UDPv6 sockets for IPv4-mapped IPv6 to work. */ - if (sotype == SOCK_DGRAM) { + if (co->sotype == SOCK_DGRAM) { err = setsockopt(fd, SOL_IP, IP_RECVORIGDSTADDR, &one, sizeof(one)); if (CHECK(err, "setsockopt(IP_RECVORIGDSTADDR)", "failed\n")) { @@ -163,7 +164,7 @@ static int make_server(int sotype, const char *ip, int port, } } - if (sotype == SOCK_DGRAM && addr.ss_family == AF_INET6) { + if (co->sotype == SOCK_DGRAM && co->family == AF_INET6) { err = setsockopt(fd, SOL_IPV6, IPV6_RECVORIGDSTADDR, &one, sizeof(one)); if (CHECK(err, "setsockopt(IPV6_RECVORIGDSTADDR)", "failed\n")) { @@ -172,7 +173,7 @@ static int make_server(int sotype, const char *ip, int port, } } - if (sotype == SOCK_STREAM) { + if (co->sotype == SOCK_STREAM) { err = setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)); if (CHECK(err, "setsockopt(SO_REUSEADDR)", "failed\n")) { @@ -181,7 +182,7 @@ static int make_server(int sotype, const char *ip, int port, } } - if (reuseport_prog) { + if (co->reuseport) { err = setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &one, sizeof(one)); if (CHECK(err, "setsockopt(SO_REUSEPORT)", "failed\n")) { @@ -190,19 +191,27 @@ static int make_server(int sotype, const char *ip, int port, } } - err = bind(fd, (void *)&addr, inetaddr_len(&addr)); - if (CHECK(err, "bind", "failed\n")) { - log_err("failed to bind listen socket"); - goto fail; - } +fail: + return err; +} - if (sotype == SOCK_STREAM) { - err = listen(fd, SOMAXCONN); - if (CHECK(err, "make_server", "listen")) { - log_err("failed to listen on port %d", port); - goto fail; - } - } +static int make_server(int sotype, const char *ip, int port, + struct bpf_program *reuseport_prog) +{ + struct cb_opts cb_opts = { + .family = is_ipv6(ip) ? AF_INET6 : AF_INET, + .sotype = sotype, + .reuseport = reuseport_prog, + }; + struct network_helper_opts opts = { + .post_socket_cb = setsockopts, + .cb_opts = &cb_opts, + }; + int err, fd = -1; + + fd = start_server_str(cb_opts.family, sotype, ip, port, &opts); + if (CHECK(fd < 0, "start_server_addr", "failed\n")) + return -1; /* Late attach reuseport prog so we can have one init path */ if (reuseport_prog) { From patchwork Sat Jun 22 01:23:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13708172 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 D4319522E; Sat, 22 Jun 2024 01:24: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=1719019458; cv=none; b=eUdssO4sgTKt1RXvRckPqR0/TiBa6g+7XT+cmefbFPvOSEAzvPg6XNnm9Y6AEF+pFIJ8PeWnTWb+IQwzvALVJ2cwHDhet4pVWVIPAOK3kfT5nUEc3DgDB10j7oSVegkHRnheJfv/j310aIFRWiDFyonLd4QqH8KV5mwrUz4mNtY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719019458; c=relaxed/simple; bh=yApkYtcs5+O+7ijpRkT0EqN+HHboLg9uvE4CSPpswQo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iWiAPqWDEUlPbNE7rAQtHTkRz88hMwVlE1ibN21r353eh9QK1SaiVftNCajaI3ZGHJCrdEPpp2dj+IDoWvP/FuLsK49Q4FhpgdzqUc0OmZepy5ApCrTilpc8kdCHwzeCD1VxdEvcUAr96pBUAP1UTPsu1INHhsPfXDlJm2jxGE0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=d8abTtDv; 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="d8abTtDv" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D971CC3277B; Sat, 22 Jun 2024 01:24:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719019458; bh=yApkYtcs5+O+7ijpRkT0EqN+HHboLg9uvE4CSPpswQo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=d8abTtDvmVxEq7VdK6MqDnJGQEd3V+5zpGMGDZpJ1bF2W9kPzhvEDLgX2qeyMEjC0 KHb9W7rzjBj9dLEI61pxKFMsCetKCUBiNrvUhQImeuGVFdIcuKVyrgAvf7VJBMlTsM 77PeYCkt9GGR76veC64Ny0NxYHoXE1qbVIJR0zz83/xqzkjLT5fsM1cZGTLwFvOQJv ZaWgCXTb6mgEnfgqF+eliLbMe9e56ykHKciY9Zws16DVasa5jCR8b2r0OH9QlMRx88 yXpVRCDM1GWLJoJcPIBdXiL4WB6a7aztX2GYpWCMT+ZYN1RuMj91JkDAa52NHppviN /Y6Xwrm1FhKDA== 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 4/7] selftests/bpf: Use connect_to_fd in sk_lookup Date: Sat, 22 Jun 2024 09:23:44 +0800 Message-ID: <49717bed77340bec2678e64b5da66b470f3991bb.1719019125.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 public helper connect_to_fd() exported in network_helpers.h instead of using make_socket() and connect() in prog_tests/sk_lookup.c. This can simplify the code. Signed-off-by: Geliang Tang --- .../testing/selftests/bpf/prog_tests/sk_lookup.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/sk_lookup.c b/tools/testing/selftests/bpf/prog_tests/sk_lookup.c index ba73b56f4484..4a4fc22ed0d2 100644 --- a/tools/testing/selftests/bpf/prog_tests/sk_lookup.c +++ b/tools/testing/selftests/bpf/prog_tests/sk_lookup.c @@ -873,7 +873,6 @@ static void test_redirect_lookup(struct test_sk_lookup *skel) static void drop_on_lookup(const struct test *t) { - struct sockaddr_storage dst = {}; int client_fd, server_fd, err; struct bpf_link *lookup_link; ssize_t n; @@ -887,12 +886,11 @@ static void drop_on_lookup(const struct test *t) if (server_fd < 0) goto detach; - client_fd = make_socket(t->sotype, t->connect_to.ip, - t->connect_to.port, &dst); + client_fd = connect_to_fd(server_fd, IO_TIMEOUT_SEC); if (client_fd < 0) goto close_srv; - err = connect(client_fd, (void *)&dst, inetaddr_len(&dst)); + err = 0; if (t->sotype == SOCK_DGRAM) { err = send_byte(client_fd); if (err) @@ -987,7 +985,6 @@ static void test_drop_on_lookup(struct test_sk_lookup *skel) static void drop_on_reuseport(const struct test *t) { - struct sockaddr_storage dst = { 0 }; int client, server1, server2, err; struct bpf_link *lookup_link; ssize_t n; @@ -1011,12 +1008,11 @@ static void drop_on_reuseport(const struct test *t) if (server2 < 0) goto close_srv1; - client = make_socket(t->sotype, t->connect_to.ip, - t->connect_to.port, &dst); + client = connect_to_fd(server2, IO_TIMEOUT_SEC); if (client < 0) goto close_srv2; - err = connect(client, (void *)&dst, inetaddr_len(&dst)); + err = 0; if (t->sotype == SOCK_DGRAM) { err = send_byte(client); if (err) @@ -1163,7 +1159,7 @@ static void run_sk_assign_connected(struct test_sk_lookup *skel, if (server_fd < 0) return; - connected_fd = make_client(sotype, EXT_IP4, EXT_PORT); + connected_fd = connect_to_fd(server_fd, IO_TIMEOUT_SEC); if (connected_fd < 0) goto out_close_server; @@ -1177,7 +1173,7 @@ static void run_sk_assign_connected(struct test_sk_lookup *skel, goto out_close_connected; /* Try to redirect TCP SYN / UDP packet to a connected socket */ - client_fd = make_client(sotype, EXT_IP4, EXT_PORT); + client_fd = connect_to_fd(server_fd, IO_TIMEOUT_SEC); if (client_fd < 0) goto out_unlink_prog; if (sotype == SOCK_DGRAM) { From patchwork Sat Jun 22 01:23:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13708173 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 3ECDA4404; Sat, 22 Jun 2024 01:24:23 +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=1719019463; cv=none; b=nEo8Oi0DzY7DTynjGi6yNHkWmKbQYLRslKXhJC3smXqr9HIM0/sTf8zUWOfqt/9+AR5y+eACf9wF71iUPK5N5RlPOt5IvBlDWcfXfdDiqU96mweheT1DL5kxZ9BgTJP8LiFLXLGl2YN2qfBVb308y0ThfVD8RqUPvnRMVOGYYhw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719019463; c=relaxed/simple; bh=BjQ5/tmBwgON0M53VKil/t5eyQrCC3L1Lla7CBl+1EE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NlRteGNvz1fxqXhMlgd+bJOtvpJyMDjFkWZ17IjolHkZdOUbd+TMzY2IzRK1PM3zC5RI/iRyp0bR9E7DT0w99R1BGiNInA4ynU7Z5devN+LjsfKllCPbsN2pEK0gkj/SLUqThiDZIHLyiU9+1GpWjf4WI99K6cjCDOV60EWXnwE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=au1encha; 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="au1encha" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 47672C4AF0B; Sat, 22 Jun 2024 01:24:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719019463; bh=BjQ5/tmBwgON0M53VKil/t5eyQrCC3L1Lla7CBl+1EE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=au1enchaWfdwxhxfBZW2kHw/3+SMz/4o+4mVwI8/LkW/CRdbF3kKJRSxqWZAdjZbt Laxj2iIncAj0/E5RBn0uJZiGCYjqXyduag56aKJ7/LtTOu+5o2fze2QWDu5M+s0zQE ibi8M5QS0E6hcUJhfJ/xE4b7a8Yin+1IQ5vLIow6dvMUOZBRVqJHIG3LZEl9tk6HxW hP/hIRgpDs5MbaBSn8waeCUpMcAVS/MyDAR/Cx84Feim/UVJ22yJ3O+rQTONC/cLDa XQYY5+roYMcekquGHRgCe2iPLPKUNr7bRCEWZG5vHPhSR45pNDAYx6mZXZyK17TSNv ftbj6lQ5v5CbQ== 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 5/7] selftests/bpf: Use connect_to_addr in sk_lookup Date: Sat, 22 Jun 2024 09:23:45 +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 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 | 20 +++++++------------ 1 file changed, 7 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 4a4fc22ed0d2..ba386484f785 100644 --- a/tools/testing/selftests/bpf/prog_tests/sk_lookup.c +++ b/tools/testing/selftests/bpf/prog_tests/sk_lookup.c @@ -230,23 +230,17 @@ 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; - fd = make_socket(sotype, ip, port, &addr); - if (fd < 0) + if (make_sockaddr(family, ip, port, &addr, &len)) 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) From patchwork Sat Jun 22 01:23:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13708174 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 3EB7A4404; Sat, 22 Jun 2024 01:24:27 +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=1719019468; cv=none; b=SVZCGgzcyg6cYCGruXAP0W19+094WMZ0h0jFzGqJmME59NqzVlTUMIQMTv5+xPUwdj3zK0+1WlYZnzTGVoslbAiXYX5hY/GyhPj4UlPgvnmCUorXiCMkahe1MnTQUCMhh1IzoW+X9BL8WhgWg9QnLZrbSRFrkiGpXaP5BrNL6dQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719019468; c=relaxed/simple; bh=Uv3Veawq41cRk7HDSAwkwv8rOMzc6SdcshDahoslgfI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=O4s5EVr69/T9cHtj1AZ4474qC3hHH76yXC825u3GnScSkZ14ZSsHXXX3eAUHKamUMCgOmcjNdF6jvvBlO2Is8uanrcxn4PPLHBUjyRU9ShDIYWfc/cuT3CabqeOzj1ZFqg9AmF77Y+wL1TxNzXeacAtM88zAuPnbgWPLS6ygwrY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=u+u+KqqY; 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="u+u+KqqY" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A689FC4AF0E; Sat, 22 Jun 2024 01:24:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719019467; bh=Uv3Veawq41cRk7HDSAwkwv8rOMzc6SdcshDahoslgfI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=u+u+KqqYo2FJiBRP4cxO2af9rnXb3x+/1oBI0i+XJINI0JQe9jfzuA4huODHgxAJa wVQRZ6YR/8Yi8OwfUBYiMKETJM4D9Cj8Z6EQZBtv62R3QBVrRFhwJO26KxDud5aX7a EaCAb/uebhLz0E7qe5MADNsuw8OcU85rvilDJBoPKDrlFK9T+FyrSyAnXylSwIkBg1 PyWTXVrVQ0tEDENuaNJtcEzVP3tSi4r01v9v7FCbYKiJkdlsw5aSm5eBIh0raAh0Nr YLZ75RvIF81zNkjircBzdL+msqssNc9zqbmT42r+XYOlnup3SyNHl8+6Ld5GR9kwIJ mA7467wE4NI5w== 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 6/7] selftests/bpf: Drop inetaddr_len in sk_lookup Date: Sat, 22 Jun 2024 09:23:46 +0800 Message-ID: <1f4b505f4a18308691cc72a9535cc4805f83965a.1719019125.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 adds a new parameter "len" for make_socket() to get the length of the address by make_sockaddr(), then local helper inetaddr_len() can be dropped. Signed-off-by: Geliang Tang --- .../testing/selftests/bpf/prog_tests/sk_lookup.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/sk_lookup.c b/tools/testing/selftests/bpf/prog_tests/sk_lookup.c index ba386484f785..d3821bf350a1 100644 --- a/tools/testing/selftests/bpf/prog_tests/sk_lookup.c +++ b/tools/testing/selftests/bpf/prog_tests/sk_lookup.c @@ -108,20 +108,14 @@ static int attach_reuseport(int sock_fd, struct bpf_program *reuseport_prog) return 0; } -static socklen_t inetaddr_len(const struct sockaddr_storage *addr) -{ - return (addr->ss_family == AF_INET ? sizeof(struct sockaddr_in) : - addr->ss_family == AF_INET6 ? sizeof(struct sockaddr_in6) : 0); -} - static int make_socket(int sotype, const char *ip, int port, - struct sockaddr_storage *addr) + struct sockaddr_storage *addr, socklen_t *len) { struct timeval timeo = { .tv_sec = IO_TIMEOUT_SEC }; int err, family, fd; family = is_ipv6(ip) ? AF_INET6 : AF_INET; - err = make_sockaddr(family, ip, port, addr, NULL); + err = make_sockaddr(family, ip, port, addr, len); if (CHECK(err, "make_address", "failed\n")) return -1; @@ -1220,6 +1214,7 @@ static void run_multi_prog_lookup(const struct test_multi_prog *t) int map_fd, server_fd, client_fd; struct bpf_link *link1, *link2; int prog_idx, done, err; + socklen_t len; map_fd = bpf_map__fd(t->run_map); @@ -1249,11 +1244,11 @@ static void run_multi_prog_lookup(const struct test_multi_prog *t) if (err) goto out_close_server; - client_fd = make_socket(SOCK_STREAM, EXT_IP4, EXT_PORT, &dst); + client_fd = make_socket(SOCK_STREAM, EXT_IP4, EXT_PORT, &dst, &len); if (client_fd < 0) goto out_close_server; - err = connect(client_fd, (void *)&dst, inetaddr_len(&dst)); + err = connect(client_fd, (void *)&dst, len); if (CHECK(err && !t->expect_errno, "connect", "unexpected error %d\n", errno)) goto out_close_client; From patchwork Sat Jun 22 01:23:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13708175 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 ACFDB1C32; Sat, 22 Jun 2024 01:24:32 +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=1719019473; cv=none; b=VqAAWYrXfg/e7NBiO5ee7se0ITGu4O55/ptgD8wOuFje5c0Jg6Om5ihEM/Ivra3rwr9fXdycgH1ISi1zRkZeCKVyBVbIk8IFZi3oP4YRhH111R3Sg+R7kAhuc1sZKylnbtj0vHqZcjQ6gm1vT63RggAzfW/ismlPjHuKPVBTxkM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719019473; c=relaxed/simple; bh=XqLrapib1ix299gEFLaiIbgWz0vz+XnguQVLwlJx2ec=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oPvNp77v/U7MaNqkeGSXZfUvNoy7Px4L02USnJRsEjMed0T0H+YH7+xKAGzMG/v6ifNcnC+HpnuK0sP1Ib4GTV8aVyFRsLXrAwuzrbGMkrqU0J5G3LYyTOy7IT4IAOm9enD5R6sSTcdeSSHXR8AFXCB86LjBq46YYNtIfr1iKl4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=RJPLFI8j; 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="RJPLFI8j" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4C224C2BBFC; Sat, 22 Jun 2024 01:24:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719019472; bh=XqLrapib1ix299gEFLaiIbgWz0vz+XnguQVLwlJx2ec=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RJPLFI8jI8kdn+OUKiK+inJFgfrA3cZ+iTvXTePlrvaVfwVI2xOkejYoNgQZZZiS3 1bI2HxP1lLROgrTdgw2AQlWon4q/ZSC8HA7Yx7qImuS5X0ygIAZaezHTbpg0EHDxLC 8nni3yuUKtV36/jzNT8qLFsGQMqIQoJilnUZMoVUpyQENJsAk7LIdcFXlkoSQE1tfh wAnkzk8UpZw8sLcWdSMOhaecVseqf6QFvPidFs2YACpBSHMv6L3NokxdJ2zFac0lV3 Oi5K2cwHtnr74JagyVXcdWVoCKyKvUX67Ky8GPDqxDvulNbvMPfmT+4uZCTWpnML/c 6HfYbPx3Tj+Qg== 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 7/7] selftests/bpf: Drop make_socket in sk_lookup Date: Sat, 22 Jun 2024 09:23:47 +0800 Message-ID: <28e0e61eb4a14e86ba3463576de4838f83be900e.1719019125.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 local helper make_client() instead of using make_socket() and connect(). Then make_socket() can be dropped now. Signed-off-by: Geliang Tang --- .../selftests/bpf/prog_tests/sk_lookup.c | 40 +------------------ 1 file changed, 2 insertions(+), 38 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/sk_lookup.c b/tools/testing/selftests/bpf/prog_tests/sk_lookup.c index d3821bf350a1..85e927381192 100644 --- a/tools/testing/selftests/bpf/prog_tests/sk_lookup.c +++ b/tools/testing/selftests/bpf/prog_tests/sk_lookup.c @@ -108,40 +108,6 @@ static int attach_reuseport(int sock_fd, struct bpf_program *reuseport_prog) return 0; } -static int make_socket(int sotype, const char *ip, int port, - struct sockaddr_storage *addr, socklen_t *len) -{ - struct timeval timeo = { .tv_sec = IO_TIMEOUT_SEC }; - int err, family, fd; - - family = is_ipv6(ip) ? AF_INET6 : AF_INET; - err = make_sockaddr(family, ip, port, addr, len); - if (CHECK(err, "make_address", "failed\n")) - return -1; - - fd = socket(addr->ss_family, sotype, 0); - if (CHECK(fd < 0, "socket", "failed\n")) { - log_err("failed to make socket"); - return -1; - } - - err = setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, &timeo, sizeof(timeo)); - if (CHECK(err, "setsockopt(SO_SNDTIMEO)", "failed\n")) { - log_err("failed to set SNDTIMEO"); - close(fd); - return -1; - } - - err = setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &timeo, sizeof(timeo)); - if (CHECK(err, "setsockopt(SO_RCVTIMEO)", "failed\n")) { - log_err("failed to set RCVTIMEO"); - close(fd); - return -1; - } - - return fd; -} - static int setsockopts(int fd, void *opts) { struct cb_opts *co = (struct cb_opts *)opts; @@ -1210,11 +1176,9 @@ struct test_multi_prog { static void run_multi_prog_lookup(const struct test_multi_prog *t) { - struct sockaddr_storage dst = {}; int map_fd, server_fd, client_fd; struct bpf_link *link1, *link2; int prog_idx, done, err; - socklen_t len; map_fd = bpf_map__fd(t->run_map); @@ -1244,11 +1208,11 @@ static void run_multi_prog_lookup(const struct test_multi_prog *t) if (err) goto out_close_server; - client_fd = make_socket(SOCK_STREAM, EXT_IP4, EXT_PORT, &dst, &len); + client_fd = make_client(SOCK_STREAM, EXT_IP4, EXT_PORT); if (client_fd < 0) goto out_close_server; - err = connect(client_fd, (void *)&dst, len); + err = 0; if (CHECK(err && !t->expect_errno, "connect", "unexpected error %d\n", errno)) goto out_close_client;