From patchwork Sat Jul 20 11:40:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13737800 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 2A38D5CDE9; Sat, 20 Jul 2024 11:40: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=1721475645; cv=none; b=IN43IaEC2SttDU74EHTc57drBMW+qOVszGQ8+7EtqGOMAxzn4mR0bHTm9q3H7Y4uLyGsUIYrsh8+diFiFGJw13Taq46Wjxe0BkZ2jR8VIYrKi30kaPnbPeo7BVFIJrezqc4S5Tl/n7AIJv1fn8XzYSVACPTqLeqhYsDa6dlA1CI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721475645; c=relaxed/simple; bh=qtkq8RbpDkRkY4VVcTna6668JvN2OQ1kXkufYfP8GgA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BJ1V/Agi7F0tZBRK3NWH6urf9XRJNKL9m73goeOWENw4O3fT5cuPg5GYg1leZ6sNAbDfFYX6ZLXkuyNk7UrHv5hIsHh2gpsXfQ1MdEaZn7oI4YOfOogdL+wr2kp7hSnyCDnOdJtfN+ZsmCLK2w8gZ5YscSgky/7luwKsXONU6N8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TuDDiTXK; 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="TuDDiTXK" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4935FC4AF0E; Sat, 20 Jul 2024 11:40:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721475645; bh=qtkq8RbpDkRkY4VVcTna6668JvN2OQ1kXkufYfP8GgA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TuDDiTXKfG89pUiC11GSfJIo9NA+dIJg/+vxp4fJmU0Az3j0Jsn/xUuk5iWTiBX6I uilcoudhYBgEAfRysoymA460H0xJdAI7qKEGre66N+6WkuvBC7sdhqNq1gVAqqRdU1 vjyAT2ZjOu3gEEoeKshPUEGIObXnPvqLMdgxtzHFICnEd3qyWFi3CT/xZRzY+lFLlO 57rRirl3tlvn5fb4dnyBeIRDhgR5rkHtfNDA6cC46svLJd6RXEQ8RQchjzIXnzbKZu zW1nFgOAP7k4q5okyBhK9O8z5qvj4aPUkudH8VyOOmtgoS8nYM/juNB0e20lpovBuy KpTGv1Osns8aA== 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 , Hao Luo , Jiri Olsa , Shuah Khan Cc: Geliang Tang , bpf@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH bpf-next 1/4] selftests/bpf: Drop make_client in sk_lookup Date: Sat, 20 Jul 2024 19:40:03 +0800 Message-ID: <058199d7ab46802249dae066ca22c98f6be508ee.1721475357.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 the new helper connect_to_addr_str() in sk_lookup.c to create the client socket and connect to the server, instead of using local defined function make_client(). This local function can be dropped then. Signed-off-by: Geliang Tang --- .../selftests/bpf/prog_tests/sk_lookup.c | 34 ++++--------------- 1 file changed, 7 insertions(+), 27 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/sk_lookup.c b/tools/testing/selftests/bpf/prog_tests/sk_lookup.c index ae87c00867ba..9510a3f83787 100644 --- a/tools/testing/selftests/bpf/prog_tests/sk_lookup.c +++ b/tools/testing/selftests/bpf/prog_tests/sk_lookup.c @@ -229,27 +229,6 @@ static int make_server(int sotype, const char *ip, int port, return -1; } -static int make_client(int sotype, const char *ip, int port) -{ - struct sockaddr_storage addr = {0}; - int err, fd; - - fd = make_socket(sotype, ip, port, &addr); - if (fd < 0) - 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; -} - static __u64 socket_cookie(int fd) { __u64 cookie; @@ -646,8 +625,9 @@ static void run_lookup_prog(const struct test *t) goto close; } - client_fd = make_client(t->sotype, t->connect_to.ip, t->connect_to.port); - if (client_fd < 0) + client_fd = connect_to_addr_str(is_ipv6(t->connect_to.ip) ? AF_INET6 : AF_INET, + t->sotype, t->connect_to.ip, t->connect_to.port, NULL); + if (!ASSERT_OK_FD(client_fd, "connect_to_addr_str")) goto close; if (t->sotype == SOCK_STREAM) @@ -1152,8 +1132,8 @@ 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); - if (connected_fd < 0) + connected_fd = connect_to_addr_str(AF_INET, sotype, EXT_IP4, EXT_PORT, NULL); + if (!ASSERT_OK_FD(connected_fd, "connect_to_addr_str")) goto out_close_server; /* Put a connected socket in redirect map */ @@ -1166,8 +1146,8 @@ 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); - if (client_fd < 0) + client_fd = connect_to_addr_str(AF_INET, sotype, EXT_IP4, EXT_PORT, NULL); + if (!ASSERT_OK_FD(client_fd, "connect_to_addr_str")) goto out_unlink_prog; if (sotype == SOCK_DGRAM) { send_byte(client_fd); From patchwork Sat Jul 20 11:40:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13737801 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 7BB5C5CDE9; Sat, 20 Jul 2024 11:40:49 +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=1721475649; cv=none; b=hUvKUyo77sRWtFT1XBBp+ucrQsZY6NhILCyVP4/B6YVHnDAWObndfo87JqqM6juwG5aqqd7qQwiV76w9TRdntIVpKwPKYf5amZhPntPRxZ36BPu+z99b3/5iuvI8V8vbqnSzjbtnYgnEMTkw2oDuQ1LR1L3KKpTPJVAdQY7HALQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721475649; c=relaxed/simple; bh=ymOxyTJNDeP01Xw3MU6AS7hSYqG64TrobZgfiA/a/CM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UwnCB2LU7p3RRMgIpW1MNi0TOgh0Gwimzn3+WaPDn2D3rrsOZoV2fLykYws6IvrGp/I8kgSytZ8AvFhonMn3WspMdh9+Vr8cx/9GqUKEdKb6cx+3Fvf4W0+dYDM6apdiZZrpoOdQY4x8jDq58CmV8EIUA27Zkm4LAbegihnkjXM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=HTTmx3sj; 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="HTTmx3sj" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AB154C4AF0C; Sat, 20 Jul 2024 11:40:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721475649; bh=ymOxyTJNDeP01Xw3MU6AS7hSYqG64TrobZgfiA/a/CM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HTTmx3sjCuYdBkDXlNUp2CDoNQZwqn+ii1YzhbEucgw53axHbSRpLGROipTOHpklK +4KU+wRRD6xkOcT4nJ3gsY3EVKM4dUmrJhWd5WHzwbChPKvj4Qfmt6MwgjCSbJMHuR MJ3xhvzpAnEu2RvccPe+7/fpddRtvY+bpH/VUCbt+jGu1KVlLWbDpvYACA66EkJfRD iD/GWGgWgHCtO5MPhpGcC7RbRFlm0fcb/vqZQbA3Sj5aJQUpjjzXtZJwzL3FNjDPTK JkKb+ymkcFdWFuOAE7CDsRum+133XEOhXVFhL2kMibCKv0DPU1Rn8o+tBF5UZhAmix 5upncMZub/1Tw== 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 , Hao Luo , Jiri Olsa , Shuah Khan Cc: Geliang Tang , bpf@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH bpf-next 2/4] selftests/bpf: Drop make_socket in sk_lookup Date: Sat, 20 Jul 2024 19:40:04 +0800 Message-ID: <588771977ac48c27f73526d8421a84b91d7cf218.1721475357.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 the public network helers client_socket() + make_sockaddr() in sk_lookup.c to create the client socket, set the timeout sockopts, and make the connecting address. The local defined function make_socket() can be dropped then. Signed-off-by: Geliang Tang --- .../selftests/bpf/prog_tests/sk_lookup.c | 61 ++++++------------- 1 file changed, 17 insertions(+), 44 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/sk_lookup.c b/tools/testing/selftests/bpf/prog_tests/sk_lookup.c index 9510a3f83787..88f2f9efeea5 100644 --- a/tools/testing/selftests/bpf/prog_tests/sk_lookup.c +++ b/tools/testing/selftests/bpf/prog_tests/sk_lookup.c @@ -47,8 +47,6 @@ #define INT_IP6 "fd00::2" #define INT_PORT 8008 -#define IO_TIMEOUT_SEC 3 - enum server { SERVER_A = 0, SERVER_B = 1, @@ -114,40 +112,6 @@ static socklen_t inetaddr_len(const struct sockaddr_storage *addr) 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 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); - 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; @@ -842,6 +806,7 @@ static void test_redirect_lookup(struct test_sk_lookup *skel) static void drop_on_lookup(const struct test *t) { + int family = is_ipv6(t->connect_to.ip) ? AF_INET6 : AF_INET; struct sockaddr_storage dst = {}; int client_fd, server_fd, err; struct bpf_link *lookup_link; @@ -856,11 +821,13 @@ 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); - if (client_fd < 0) + client_fd = client_socket(family, t->sotype, NULL); + if (!ASSERT_OK_FD(client_fd, "client_socket")) goto close_srv; + err = make_sockaddr(family, t->connect_to.ip, t->connect_to.port, &dst, NULL); + if (!ASSERT_OK(err, "make_sockaddr")) + goto close_all; err = connect(client_fd, (void *)&dst, inetaddr_len(&dst)); if (t->sotype == SOCK_DGRAM) { err = send_byte(client_fd); @@ -956,6 +923,7 @@ static void test_drop_on_lookup(struct test_sk_lookup *skel) static void drop_on_reuseport(const struct test *t) { + int family = is_ipv6(t->connect_to.ip) ? AF_INET6 : AF_INET; struct sockaddr_storage dst = { 0 }; int client, server1, server2, err; struct bpf_link *lookup_link; @@ -980,11 +948,13 @@ 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); - if (client < 0) + client = client_socket(family, t->sotype, NULL); + if (!ASSERT_OK_FD(client, "client_socket")) goto close_srv2; + err = make_sockaddr(family, t->connect_to.ip, t->connect_to.port, &dst, NULL); + if (!ASSERT_OK(err, "make_sockaddr")) + goto close_all; err = connect(client, (void *)&dst, inetaddr_len(&dst)); if (t->sotype == SOCK_DGRAM) { err = send_byte(client); @@ -1228,10 +1198,13 @@ 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); - if (client_fd < 0) + client_fd = client_socket(AF_INET, SOCK_STREAM, NULL); + if (!ASSERT_OK_FD(client_fd, "client_socket")) goto out_close_server; + err = make_sockaddr(AF_INET, EXT_IP4, EXT_PORT, &dst, NULL); + if (!ASSERT_OK(err, "make_sockaddr")) + goto out_close_client; err = connect(client_fd, (void *)&dst, inetaddr_len(&dst)); if (CHECK(err && !t->expect_errno, "connect", "unexpected error %d\n", errno)) From patchwork Sat Jul 20 11:40:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13737802 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 F2C6629AB; Sat, 20 Jul 2024 11:40:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721475654; cv=none; b=BwmkVjexdIteN4sjxZLhxLAVeCeaaD2Od23zDD5TGqHUfN7Cpp1A4/AhbhBGtl58t9aHwe+yzMvYi+u9vzmddIfQEElaK4F2sl3mc7nBbKcAFA5rcaJLux9f2HnCpmYMMldXeiX2kyrZZZUvwtLSiDgPlHpY7qioLr2P3PzFYHE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721475654; c=relaxed/simple; bh=wkqdp7kya0n3h+GrMwSd66zEgaaks7rxfiWYlU/VT0w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KyCrwUxliPDGDakh3JK7wXbuarjvKYa5lQcyp6aJOhQlAGvpTP3ze6IxuTP7yCPrU8r8Clng7qKOGdWUoNNpxKMNK0nO2qzA3cLKZb/A5bYcJIWRJ4HlbheuJg90Jfm68+bQOlrw2x6rzauS65ncIN3Wwx4qcSSwWhMo8kEByz8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=tZVrpwD2; 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="tZVrpwD2" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DB49DC4AF0E; Sat, 20 Jul 2024 11:40:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721475653; bh=wkqdp7kya0n3h+GrMwSd66zEgaaks7rxfiWYlU/VT0w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tZVrpwD2gTvLOmFUvec0eswhzdhyEAxg2Qx3WZABdwwuTThr0dvfJRqQ6V3/dBYz6 36isBwIv6oepzS+IWfy4y2sdcEYOeGTLBpFK1oRfH5YKo3ZEZQZhKCalodrR2+UKqB 79NxHrhoK4AeIBuvx9uOg5oQtWYD1HNVCt3bmmmgNPTFIdq+jcKdwUDMeJ1ZQuX3Jm +F1LvyTQ0ahNhRt599gmiT6U1lAMKNa0Qt9FFbEhY0ObfnJ3Jc4Qpfc0Z5UgcAvg5z k6xO3aMON3B0PAx1EqjLg6DiVAuQu6ZFWeZviAsTX3xKFm+ukptCF2lJXxBcAYFPto RVdTp450VL2IA== 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 , Hao Luo , Jiri Olsa , Shuah Khan Cc: Geliang Tang , bpf@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH bpf-next 3/4] selftests/bpf: Drop inetaddr_len in sk_lookup Date: Sat, 20 Jul 2024 19:40:05 +0800 Message-ID: <32e2a4122921051da38a6e4fbb2ebee5f0af5a4e.1721475357.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 No need to use a dedicated helper inetaddr_len() to get the length of the IPv4 or IPv6 address, it can be got by make_sockaddr(), this patch drops it. Signed-off-by: Geliang Tang --- .../selftests/bpf/prog_tests/sk_lookup.c | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/sk_lookup.c b/tools/testing/selftests/bpf/prog_tests/sk_lookup.c index 88f2f9efeea5..96f3863da8bc 100644 --- a/tools/testing/selftests/bpf/prog_tests/sk_lookup.c +++ b/tools/testing/selftests/bpf/prog_tests/sk_lookup.c @@ -106,12 +106,6 @@ 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 setsockopts(int fd, void *opts) { struct cb_opts *co = (struct cb_opts *)opts; @@ -810,6 +804,7 @@ static void drop_on_lookup(const struct test *t) struct sockaddr_storage dst = {}; int client_fd, server_fd, err; struct bpf_link *lookup_link; + socklen_t len; ssize_t n; lookup_link = attach_lookup_prog(t->lookup_prog); @@ -825,10 +820,10 @@ static void drop_on_lookup(const struct test *t) if (!ASSERT_OK_FD(client_fd, "client_socket")) goto close_srv; - err = make_sockaddr(family, t->connect_to.ip, t->connect_to.port, &dst, NULL); + err = make_sockaddr(family, t->connect_to.ip, t->connect_to.port, &dst, &len); if (!ASSERT_OK(err, "make_sockaddr")) goto close_all; - err = connect(client_fd, (void *)&dst, inetaddr_len(&dst)); + err = connect(client_fd, (void *)&dst, len); if (t->sotype == SOCK_DGRAM) { err = send_byte(client_fd); if (err) @@ -927,6 +922,7 @@ static void drop_on_reuseport(const struct test *t) struct sockaddr_storage dst = { 0 }; int client, server1, server2, err; struct bpf_link *lookup_link; + socklen_t len; ssize_t n; lookup_link = attach_lookup_prog(t->lookup_prog); @@ -952,10 +948,10 @@ static void drop_on_reuseport(const struct test *t) if (!ASSERT_OK_FD(client, "client_socket")) goto close_srv2; - err = make_sockaddr(family, t->connect_to.ip, t->connect_to.port, &dst, NULL); + err = make_sockaddr(family, t->connect_to.ip, t->connect_to.port, &dst, &len); if (!ASSERT_OK(err, "make_sockaddr")) goto close_all; - err = connect(client, (void *)&dst, inetaddr_len(&dst)); + err = connect(client, (void *)&dst, len); if (t->sotype == SOCK_DGRAM) { err = send_byte(client); if (err) @@ -1169,6 +1165,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); @@ -1202,10 +1199,10 @@ static void run_multi_prog_lookup(const struct test_multi_prog *t) if (!ASSERT_OK_FD(client_fd, "client_socket")) goto out_close_server; - err = make_sockaddr(AF_INET, EXT_IP4, EXT_PORT, &dst, NULL); + err = make_sockaddr(AF_INET, EXT_IP4, EXT_PORT, &dst, &len); if (!ASSERT_OK(err, "make_sockaddr")) goto out_close_client; - 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 Jul 20 11:40:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13737803 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 D3340127E3A; Sat, 20 Jul 2024 11:40: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=1721475657; cv=none; b=O7SGNdMzXaQQ7+qB4g4zBhSXV0C2ZooPy+S9VVq5RcEAAphGg6JoptWkim/jcSpaRGD+Mos8BS0Zcj48Pb0SDD2oRLin4lfjxiyM6QdQWOmYW9A94SU0YqXx+AYJ61ZHGYDQ38++TgRwa3sLRLX8YCwJek8tkb1fLr+pR9sUfDA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721475657; c=relaxed/simple; bh=bgfaanFUHt1fg5aKtQXT1YN7plxOQcDy48h6Pqa0jEU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fCDMwYNG+Y9BX9Lng/1Jt+zfi8ZnfpbTgbDmZRgAfnzFEAQylSSehwPLWNyS8QbCNM8CWioLx8Rc23UoN2Sex7u1ZslWbK5RVzbMus1PWhiMFUo/X07lN6IvropTUTwekSZYzXqVw4h/yb6el1RBl6Fnul3QWKqXB9I1wFKo4I8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Cu3DYg3J; 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="Cu3DYg3J" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 17E02C4AF09; Sat, 20 Jul 2024 11:40:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721475657; bh=bgfaanFUHt1fg5aKtQXT1YN7plxOQcDy48h6Pqa0jEU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Cu3DYg3J89FuBmIpUb+8sFpVUUb0V2EvA1QVQDUAdfvTGhjG+PQ8IC1lttdHWrUn8 eKp6D095FIZQ3tYUTY0L19ZEAkTaO/U7jfwLPPF2uYnJkkN/naKWrWDNl+T+dLN+PT NBVna/1NY8RBKid494PgAnDrb2drIy1ppiZl+y5D9EiM5T+gzjh7zNglSRNJx9qUwE 3sWsoKftDd9aXh6LvpshOLXSfEGIZChD8M8BuAVqqhVKGep5Xvc4cnmVzNFoxRvgAs RmBcrBqSeLwMQDxV318PAzEfTXFDFjbS7paUQ8zNYOv/qIfRIynbzq9cPTb7BLjPi7 6O3NELUe32Zrw== 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 , Hao Luo , Jiri Olsa , Shuah Khan Cc: Geliang Tang , bpf@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH bpf-next 4/4] selftests/bpf: Drop __start_server in network_helpers Date: Sat, 20 Jul 2024 19:40:06 +0800 Message-ID: <31399df7cb957b7c233e79963b0aa0dc4278d273.1721475357.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 The helper start_server_addr() is a wrapper of __start_server(), the only difference between them is __start_server() accepts a sockaddr type address parameter, but start_server_addr() accepts a sockaddr_storage one. This patch drops __start_server(), and updates the callers to invoke start_server_addr() instead. Signed-off-by: Geliang Tang --- tools/testing/selftests/bpf/network_helpers.c | 26 +++++++------------ 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c index 9c98a60cf1e2..a3f0a49fb26f 100644 --- a/tools/testing/selftests/bpf/network_helpers.c +++ b/tools/testing/selftests/bpf/network_helpers.c @@ -80,12 +80,15 @@ int settimeo(int fd, int timeout_ms) #define save_errno_close(fd) ({ int __save = errno; close(fd); errno = __save; }) -static int __start_server(int type, const struct sockaddr *addr, socklen_t addrlen, - const struct network_helper_opts *opts) +int start_server_addr(int type, const struct sockaddr_storage *addr, socklen_t addrlen, + const struct network_helper_opts *opts) { int fd; - fd = socket(addr->sa_family, type, opts->proto); + if (!opts) + opts = &default_opts; + + fd = socket(addr->ss_family, type, opts->proto); if (fd < 0) { log_err("Failed to create server socket"); return -1; @@ -100,7 +103,7 @@ static int __start_server(int type, const struct sockaddr *addr, socklen_t addrl goto error_close; } - if (bind(fd, addr, addrlen) < 0) { + if (bind(fd, (struct sockaddr *)addr, addrlen) < 0) { log_err("Failed to bind socket"); goto error_close; } @@ -131,7 +134,7 @@ int start_server_str(int family, int type, const char *addr_str, __u16 port, if (make_sockaddr(family, addr_str, port, &addr, &addrlen)) return -1; - return __start_server(type, (struct sockaddr *)&addr, addrlen, opts); + return start_server_addr(type, &addr, addrlen, opts); } int start_server(int family, int type, const char *addr_str, __u16 port, @@ -173,7 +176,7 @@ int *start_reuseport_server(int family, int type, const char *addr_str, if (!fds) return NULL; - fds[0] = __start_server(type, (struct sockaddr *)&addr, addrlen, &opts); + fds[0] = start_server_addr(type, &addr, addrlen, &opts); if (fds[0] == -1) goto close_fds; nr_fds = 1; @@ -182,7 +185,7 @@ int *start_reuseport_server(int family, int type, const char *addr_str, goto close_fds; for (; nr_fds < nr_listens; nr_fds++) { - fds[nr_fds] = __start_server(type, (struct sockaddr *)&addr, addrlen, &opts); + fds[nr_fds] = start_server_addr(type, &addr, addrlen, &opts); if (fds[nr_fds] == -1) goto close_fds; } @@ -194,15 +197,6 @@ int *start_reuseport_server(int family, int type, const char *addr_str, return NULL; } -int start_server_addr(int type, const struct sockaddr_storage *addr, socklen_t len, - const struct network_helper_opts *opts) -{ - if (!opts) - opts = &default_opts; - - return __start_server(type, (struct sockaddr *)addr, len, opts); -} - void free_fds(int *fds, unsigned int nr_close_fds) { if (fds) {