From patchwork Tue Jul 23 22:22:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13740396 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 C86391DDD6; Tue, 23 Jul 2024 22:22:41 +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=1721773361; cv=none; b=gyLufQm+HQ0IJzneuznKB2boX4Ahhntrvt8NTmq9Wthbzos+zu0lo6J6v+gXNAJF9HgExxJY2KfqnN8aOXBspiFE9zKctfbvQdEn25yHcEinGDzO7hcACXQGMK6ilVttUijcxFcsttFVW9wtE3/Nmc6bYwW4nCPH+2GmwlgIxt0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721773361; c=relaxed/simple; bh=ElpE2SCASgLAzFZeIC5RV+POqvIJfTF2T+hNolb6Xgw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KkCT31E2R9RihEWYAyNsJooiWJp5Ttg4rAkfVpeokHQkFKyulQSDouY6egGvhgYm3oZKQHByBIgfRlyy6uafg35Ag+VPbOc6Hbk2HdwqfT0c0gLmeA0C7iDgH0YwSUPgRMT/zs+ad/NjMAViMqmwkANdqLDmfm1NYgkGr0PvXyM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=d8w3Zo4i; 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="d8w3Zo4i" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BBADFC4AF0F; Tue, 23 Jul 2024 22:22:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721773361; bh=ElpE2SCASgLAzFZeIC5RV+POqvIJfTF2T+hNolb6Xgw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=d8w3Zo4ix6WFStCKHCkvG3BDjigxNuemxP31xEgB+sI/2AxoqlME8Ayrij4YV2d3X nwfF4BhSfg+/+77MCdlxf5tZqBAaSS5JlmgFf9i7l6x71x0lwduRGrXz8HT9Tv5tF3 79HAj7ZTZcG1YVa5PoDD4JSnmNh26a3wuUp3s1v3F//hex1JnMIcZDUUBejF77OO/W rF+dHLQV4nP6cMrJFH9HvVEMKGZrR4+6Kq8nsQ/+9ziYjEGuYEVjB18jRr3qEKBt9m hXTnUn1HohDECViTDhFw5KS9kHhyqaL6BcGQW9AVR9GUV+ZHoXu4omMZ++ijEq58ac bXRAcHE/yFKBg== 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 01/15] selftests/bpf: Use start_server_str in skc_to_unix_sock Date: Wed, 24 Jul 2024 06:22:07 +0800 Message-ID: X-Mailer: git-send-email 2.43.0 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 network helper start_server_str() in skc_to_unix_sock test in skc_to_unix_sock.c to simplify the code. This is the first time to use start_server_str() for a AF_UNIX socket. The first "@" of "sun_path" needs to be skipped by make_sockaddr(), so path string "sock_path + 1" ("skc_to_unix_sock") is passed to the helper, not "sock_path" ("@skc_to_unix_sock"). Signed-off-by: Geliang Tang --- .../bpf/prog_tests/skc_to_unix_sock.c | 22 +++++-------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/skc_to_unix_sock.c b/tools/testing/selftests/bpf/prog_tests/skc_to_unix_sock.c index 3eefdfed1db9..4c23409a3072 100644 --- a/tools/testing/selftests/bpf/prog_tests/skc_to_unix_sock.c +++ b/tools/testing/selftests/bpf/prog_tests/skc_to_unix_sock.c @@ -4,13 +4,16 @@ #include #include #include "test_skc_to_unix_sock.skel.h" +#include "network_helpers.h" static const char *sock_path = "@skc_to_unix_sock"; void test_skc_to_unix_sock(void) { + struct network_helper_opts opts = { + .backlog = 1, + }; struct test_skc_to_unix_sock *skel; - struct sockaddr_un sockaddr; int err, sockfd = 0; skel = test_skc_to_unix_sock__open(); @@ -28,21 +31,8 @@ void test_skc_to_unix_sock(void) goto cleanup; /* trigger unix_listen */ - sockfd = socket(AF_UNIX, SOCK_STREAM, 0); - if (!ASSERT_GT(sockfd, 0, "socket failed")) - goto cleanup; - - memset(&sockaddr, 0, sizeof(sockaddr)); - sockaddr.sun_family = AF_UNIX; - strncpy(sockaddr.sun_path, sock_path, strlen(sock_path)); - sockaddr.sun_path[0] = '\0'; - - err = bind(sockfd, (struct sockaddr *)&sockaddr, sizeof(sockaddr)); - if (!ASSERT_OK(err, "bind failed")) - goto cleanup; - - err = listen(sockfd, 1); - if (!ASSERT_OK(err, "listen failed")) + sockfd = start_server_str(AF_UNIX, SOCK_STREAM, sock_path + 1, 0, &opts); + if (!ASSERT_OK_FD(sockfd, "start_server_str")) goto cleanup; ASSERT_EQ(strcmp(skel->bss->path, sock_path), 0, "bpf_skc_to_unix_sock failed"); From patchwork Tue Jul 23 22:22:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13740397 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 B86FB1487E9; Tue, 23 Jul 2024 22:22: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=1721773365; cv=none; b=bH1VgPfmihd9u0L8q/gQIROiUM9WJKKBvPWef0fIK63l6+mblJcRlz8sjhk6eM5POXr5WcLuCrEkLR8A8vxH8Ekhp8cycRT9AfbJyWI7rvdUt1dHizcfqAul6rsuPRZBSRI2mKwC2YJlldeWHooLivoBuTxt76RnKPvlJIuYqQo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721773365; c=relaxed/simple; bh=12aAaZMootg+cvj+0ayt/8qu159GnEbnVlWc6KZT748=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mu6J/Uu5w9Lxj5N2y2ZnvQtVo4jZwDIVeKTJTAOlF1QmOeBw8kMUITpMX1ByTTn5fAZJwb1OhiBq5e0mSUpRGIWXh3LCNugODnwzYmZN6jpAAMhAbQVrROAm9BKY0TGe0iPRDrldnQJ2ASVLjAtM1aJd7JkXWUOZ6b3ie5x012o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GcNgF9j8; 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="GcNgF9j8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EC283C4AF0F; Tue, 23 Jul 2024 22:22:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721773365; bh=12aAaZMootg+cvj+0ayt/8qu159GnEbnVlWc6KZT748=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GcNgF9j8fYFu0O8jZo1teuViXEcwm5ET1nCR4ZdoTXhkpDmsEd2gWimUte/Ge/0pY d2eMuUQPGqeRME6Mw0gs/MkIyE5dGVq3WijwFBrJR4g1Cc169OH+Bh6pH/PQm7tW5O uFw05Qm8gX+M7b7hSsZcqLU/jmvfnSi4kXB83DxscXADZkNC27Gcx07liHm+DhVFk0 pf0PTouQzG2QjnktC6hFId6ZRCOovNTbgVNiLvMvM8XLeuV7vOTZGTQvsEZ1fN9OTJ Ix1Z+VmviIDUvD0BUg9J7+4tjNYo3xF/X9x+Yz4JuMRkcTBN4PHsrpJrt4cv3dMNHu 4i7MjDv3Wq3Yg== 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 02/15] selftests/bpf: AF_PACKET support for make_sockaddr Date: Wed, 24 Jul 2024 06:22:08 +0800 Message-ID: X-Mailer: git-send-email 2.43.0 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 AF_PACKET support for make_sockaddr(), uses sscanf() to parse the given addr_str string into sll_ifindex, sll_halen and sll_addr of sockaddr_ll. Other fields of struct sockaddr_ll are not used in BPF selftests right now. Signed-off-by: Geliang Tang --- tools/testing/selftests/bpf/network_helpers.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c index a3f0a49fb26f..2a142d713861 100644 --- a/tools/testing/selftests/bpf/network_helpers.c +++ b/tools/testing/selftests/bpf/network_helpers.c @@ -416,6 +416,21 @@ int make_sockaddr(int family, const char *addr_str, __u16 port, if (len) *len = offsetof(struct sockaddr_un, sun_path) + 1 + strlen(addr_str); return 0; + } else if (family == AF_PACKET) { + struct sockaddr_ll *sll = (void *)addr; + + memset(addr, 0, sizeof(*sll)); + sll->sll_family = family; + sll->sll_protocol = htons(ETH_P_ALL); + if (addr_str && + sscanf(addr_str, "%d %c %s", &sll->sll_ifindex, + &sll->sll_halen, sll->sll_addr) == -1) { + log_err("AF_PACKET sscanf(%s)", addr_str); + return -1; + } + if (len) + *len = sizeof(*sll); + return 0; } return -1; } From patchwork Tue Jul 23 22:22: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: 13740398 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 131EF148827; Tue, 23 Jul 2024 22:22:50 +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=1721773370; cv=none; b=CKEqqIL2AsO7JTgiC4nGX6OIhnS5QtDAAZ3ROZ1nQyERHntk6jLKP4MGJbf9Q2d1CXdARmn9z/U344+Ry9c5beMFQkJ8oqcA6xlcSZkU81Y/1AUTvBPrP4jL4Vj25YFio0uXHcKcTe1lmC+bOclldR7D4xvCsjFSZC5pZV8EFf8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721773370; c=relaxed/simple; bh=KqMjTfdH3u15gtevijB3kg0N1GugqZKCG34zP8wwTAc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JDOGbUQlVwsUwYTkTYiCi+kjp8MVaAOnYCgr7iobfYZdV2RZzvd+mProkICoShHzjsX24HVdf7+kW85xaBqsO/wSrm9xOBdaxRI/rgKbD/tC8u8eCpFFHavP5dtYYQJ9eJARynHIX6BZW6mOq0hnC9kqX+xecVtLEgPIFUmuuHI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=aA2k9J+R; 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="aA2k9J+R" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 424FFC4AF11; Tue, 23 Jul 2024 22:22:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721773369; bh=KqMjTfdH3u15gtevijB3kg0N1GugqZKCG34zP8wwTAc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aA2k9J+RBpPquH6t/tiNY7iEvKjFI6LrEHxmUwtCF8WKySK0DzMhGyjnut9kJllWX buO5qJcPgG5DGs8ejkgNrrAfol47Z4oIqk1RRK5EBsjk0GQwFIp2IQnyP39EP8x+Fw peVHpfoCDikqoxQcs75jdPlhDXBVj18UHoH9BvxWdy55op/do6fOxwtT5pFE8sSPVP zzJZIAK+GfuXM9DLqjCM25BdUiQcfqHhjjF4QFFN6aDnIYp8x24ESmWrBkLHIi+NR1 2/rOyHesbqLuBkmjzcPi7Ns8NYEx95VvlbHUr6xzhz6Af2CUyer8mfWnfHatPY8Gu3 Q2324fnWJbKnw== 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 03/15] selftests/bpf: Use start_server_str in lwt_redirect Date: Wed, 24 Jul 2024 06:22:09 +0800 Message-ID: <44231acb3ed09db3bca33a4b5f959f0ec476efe3.1721771340.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.43.0 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 AF_PACKET can be passed to start_server_str() now. Use it to simplify the code in lwt_redirect. In this test, use sprintf() to save the "ifindex" value into addr_str string, then pass it to the helper. Signed-off-by: Geliang Tang --- .../selftests/bpf/prog_tests/lwt_redirect.c | 21 +++++-------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/lwt_redirect.c b/tools/testing/selftests/bpf/prog_tests/lwt_redirect.c index 835a1d756c16..f4c54bb7e416 100644 --- a/tools/testing/selftests/bpf/prog_tests/lwt_redirect.c +++ b/tools/testing/selftests/bpf/prog_tests/lwt_redirect.c @@ -94,30 +94,19 @@ static int new_packet_sock(const char *ifname) { int err = 0; int ignore_outgoing = 1; + char addr_str[32]; int ifindex = -1; int s = -1; - s = socket(AF_PACKET, SOCK_RAW, 0); - if (!ASSERT_GE(s, 0, "socket(AF_PACKET)")) - return -1; - ifindex = if_nametoindex(ifname); - if (!ASSERT_GE(ifindex, 0, "if_nametoindex")) { - close(s); + if (!ASSERT_GE(ifindex, 0, "if_nametoindex")) return -1; - } - struct sockaddr_ll addr = { - .sll_family = AF_PACKET, - .sll_protocol = htons(ETH_P_IP), - .sll_ifindex = ifindex, - }; + sprintf(addr_str, "%d", ifindex); - err = bind(s, (struct sockaddr *)&addr, sizeof(addr)); - if (!ASSERT_OK(err, "bind(AF_PACKET)")) { - close(s); + s = start_server_str(AF_PACKET, SOCK_RAW, addr_str, 0, NULL); + if (!ASSERT_OK_FD(s, "start_server_str")) return -1; - } /* Use packet socket to capture only the ingress, so we can distinguish * the case where a regression that actually redirects the packet to From patchwork Tue Jul 23 22:22: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: 13740399 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 67EC7148833; Tue, 23 Jul 2024 22:22:54 +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=1721773374; cv=none; b=db7RrmXu+GtXjBmLJFu/qOFu+O1xZBmgW3WfSlWSAvL+Va7VEuvBjD9WFnJ5uZLBew36MgoGtdjPKg8NI6UpAUVdT6YqlW6T4tySJ5J854UL+xqZldaznd1NPEyIwTQEX5o4MN0gj7NctjTvgM5Jn68gk8vMAymgmBbNKr6TJAk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721773374; c=relaxed/simple; bh=l5jLQwh0GHxuTfhViQjcXfLWAJLnjuwX6xKYGvb2no0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kuSdUhffFqYfIi5AH9YoE9vOjs5m05V0wDvV/hSHNq1Qs2NmnwSc01UT+YD97gR2cNP9YjSL1MleerpVrkyu3IE2xy+atNNMn5mNPx5tQuetaVjhnZZoC5o9gueTid9hrcTeqpOyHPI40v+l3rsttms+/RPFuNnhKKFqp8D6o/I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ii/A0ner; 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="ii/A0ner" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 71F32C4AF0F; Tue, 23 Jul 2024 22:22:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721773374; bh=l5jLQwh0GHxuTfhViQjcXfLWAJLnjuwX6xKYGvb2no0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ii/A0nerdcE+HP2ErzIzzVxdY61AjJ26VNm7QnkMYhVwr8XjAp+aTSzvlfdsWfyTW AOrLVnAsLj1jus/V3bhAqLKpQiCHDYLP4rtFW8u6/rPnKk+6YjRb0oMT8RFZOetbce x01tOS5T8lXPJmPH5Hiw+HQV0brYmpH+B3xb61efp944Jx/xtyIqPfx39OcEzf4//h PkNCmrAEp+uad1uCK9fVnM3gdAqHaHhZWnQMsZ9oVaXz8/QBVc4aa7DOfVdurFfiyx otbW/Zl1dSzazoo8suAKclj8nPChesWQy+olsr04ddcb0OBlOxL8QXTuanVUOkYC7K hFgx7yBytFp7g== 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 04/15] selftests/bpf: Add send_to_fd_opts helper Date: Wed, 24 Jul 2024 06:22:10 +0800 Message-ID: X-Mailer: git-send-email 2.43.0 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 Similar to network helpers connect_to_addr() and connect_to_fd_opts(), this patch adds two helpers send_to_addr() send_to_fd_opts() to use sendto() to send data. They accepts three more parameters "const void *data", "size_t datalen" and "int flags" for the sending data. send_to_addr() is a static function at this moment, only send_to_fd_opts() is exported. The first user of send_to_fd_opts() is fastopen_connect() in network_helpers.c. Signed-off-by: Geliang Tang --- tools/testing/selftests/bpf/network_helpers.c | 65 ++++++++++++------- tools/testing/selftests/bpf/network_helpers.h | 2 + 2 files changed, 45 insertions(+), 22 deletions(-) diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c index 2a142d713861..311c3a559414 100644 --- a/tools/testing/selftests/bpf/network_helpers.c +++ b/tools/testing/selftests/bpf/network_helpers.c @@ -206,41 +206,62 @@ void free_fds(int *fds, unsigned int nr_close_fds) } } -int fastopen_connect(int server_fd, const char *data, unsigned int data_len, - int timeout_ms) +static int send_to_addr(int type, const void *data, size_t datalen, int flags, + const struct sockaddr_storage *addr, socklen_t addrlen, + const struct network_helper_opts *opts) { - struct sockaddr_storage addr; - socklen_t addrlen = sizeof(addr); - struct sockaddr_in *addr_in; int fd, ret; - if (getsockname(server_fd, (struct sockaddr *)&addr, &addrlen)) { - log_err("Failed to get server addr"); + fd = client_socket(addr->ss_family, type, opts); + if (fd < 0) { + log_err("Failed to create client socket"); return -1; } - addr_in = (struct sockaddr_in *)&addr; - fd = socket(addr_in->sin_family, SOCK_STREAM, 0); - if (fd < 0) { - log_err("Failed to create client socket"); + ret = sendto(fd, data, datalen, flags, + (const struct sockaddr *)addr, addrlen); + if (ret != datalen) { + log_err("Failed to send to server"); + save_errno_close(fd); return -1; } - if (settimeo(fd, timeout_ms)) - goto error_close; + return fd; +} - ret = sendto(fd, data, data_len, MSG_FASTOPEN, (struct sockaddr *)&addr, - addrlen); - if (ret != data_len) { - log_err("sendto(data, %u) != %d\n", data_len, ret); - goto error_close; +int send_to_fd_opts(int server_fd, const void *data, size_t datalen, int flags, + const struct network_helper_opts *opts) +{ + struct sockaddr_storage addr; + socklen_t addrlen, optlen; + int type; + + if (!opts) + opts = &default_opts; + + optlen = sizeof(type); + if (getsockopt(server_fd, SOL_SOCKET, SO_TYPE, &type, &optlen)) { + log_err("getsockopt(SOL_TYPE)"); + return -1; } - return fd; + addrlen = sizeof(addr); + if (getsockname(server_fd, (struct sockaddr *)&addr, &addrlen)) { + log_err("Failed to get server addr"); + return -1; + } -error_close: - save_errno_close(fd); - return -1; + return send_to_addr(type, data, datalen, flags, &addr, addrlen, opts); +} + +int fastopen_connect(int server_fd, const char *data, unsigned int data_len, + int timeout_ms) +{ + struct network_helper_opts opts = { + .timeout_ms = timeout_ms, + }; + + return send_to_fd_opts(server_fd, data, data_len, MSG_FASTOPEN, &opts); } int client_socket(int family, int type, diff --git a/tools/testing/selftests/bpf/network_helpers.h b/tools/testing/selftests/bpf/network_helpers.h index cce56955371f..19210a234bc1 100644 --- a/tools/testing/selftests/bpf/network_helpers.h +++ b/tools/testing/selftests/bpf/network_helpers.h @@ -74,6 +74,8 @@ int connect_to_addr_str(int family, int type, const char *addr_str, __u16 port, int connect_to_fd(int server_fd, int timeout_ms); int connect_to_fd_opts(int server_fd, const struct network_helper_opts *opts); int connect_fd_to_fd(int client_fd, int server_fd, int timeout_ms); +int send_to_fd_opts(int server_fd, const void *data, size_t datalen, int flags, + const struct network_helper_opts *opts); int fastopen_connect(int server_fd, const char *data, unsigned int data_len, int timeout_ms); int make_sockaddr(int family, const char *addr_str, __u16 port, From patchwork Tue Jul 23 22:22: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: 13740400 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 BF29F14884F; Tue, 23 Jul 2024 22:22: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=1721773378; cv=none; b=QRzKjpOkydrNmO/JAGFVa2lOud+XzvG7Jp8viC1kHyWEN0mLd5AEZ3m55a3x/xkDgPGEe2yuLQl7jpAn8rzJdko0nraVb1MUGGN/0MaZB30QKzN+iaRdtw7JJ+7R8Ry8RajS+TmBESy4T+A9cvI7VWKzy2u13aS2DMcRLiRySc8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721773378; c=relaxed/simple; bh=vMawzUa6obfX+VBE9Ykam0WOLhjlYMSTbs5HX0CvXPs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Y9+2HgOceyn59qX+8KF+oOJ7/uR2YsuzVY4nllrtxy4FJ0iBPiF4nWjFMRuPtbu9NqLQIGgmCjRC5t3dWKRCaIPVTTZUpK3nxTvjPz6bm8q8TwG/aFiGxMvl5grlX0cDw0PUcorxfTIHvsTOs0QPeEdDq2vklOkp9hjDZZdewOY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=WPSnLxjP; 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="WPSnLxjP" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BB26EC4AF09; Tue, 23 Jul 2024 22:22:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721773378; bh=vMawzUa6obfX+VBE9Ykam0WOLhjlYMSTbs5HX0CvXPs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WPSnLxjPk5JyEmeMZwyF5/WZBbvqpLZmR6awUviXvVX02VnRG7QwIF2h0k1vV8tLW sRU4RPgLd4ik3vQ7YNruKqbmnvaN08C+a8JGe3QxLfNDW28fRiOdGMK4+Dn11PFlhd 1Gh5AeW+jCe6G2DVPvCBy+5+RIxz/y7uz5sGGU3bPTDb74gY34oRqSKYrPkyq0uYKd 1cTcsYPiyRX2KfQDrsXh9pIcWUD9pm4sJCgNqE5b53vDTC6SowYHenU+htjzrn0pBD BddBQVVaE25oqIGiF1p6XAQrGHxdJRIMGHQ3Le2T2811jtgd0iUlfRHj1tyEHMKz6Z Anda4sQ7ixQtA== 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 05/15] selftests/bpf: Add send_to_addr_str helper Date: Wed, 24 Jul 2024 06:22:11 +0800 Message-ID: <7a909bf0164987f1b92f505a9dfb85509c57bf9d.1721771340.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.43.0 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 Similar to network helper connect_to_addr_str(), this patch adds a new helper send_to_addr_str(). It uses make_sockaddr() to make a sockaddr_storage type address from the "family", "addr_str" and "port" parameters and passes it to send_to_addr(). Signed-off-by: Geliang Tang --- tools/testing/selftests/bpf/network_helpers.c | 16 ++++++++++++++++ tools/testing/selftests/bpf/network_helpers.h | 3 +++ 2 files changed, 19 insertions(+) diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c index 311c3a559414..a6c158718267 100644 --- a/tools/testing/selftests/bpf/network_helpers.c +++ b/tools/testing/selftests/bpf/network_helpers.c @@ -229,6 +229,22 @@ static int send_to_addr(int type, const void *data, size_t datalen, int flags, return fd; } +int send_to_addr_str(int family, int type, const char *addr_str, __u16 port, + const void *data, size_t datalen, int flags, + const struct network_helper_opts *opts) +{ + struct sockaddr_storage addr; + socklen_t addrlen; + + if (!opts) + opts = &default_opts; + + if (make_sockaddr(family, addr_str, port, &addr, &addrlen)) + return -1; + + return send_to_addr(type, data, datalen, flags, &addr, addrlen, opts); +} + int send_to_fd_opts(int server_fd, const void *data, size_t datalen, int flags, const struct network_helper_opts *opts) { diff --git a/tools/testing/selftests/bpf/network_helpers.h b/tools/testing/selftests/bpf/network_helpers.h index 19210a234bc1..ebed1fb1bd49 100644 --- a/tools/testing/selftests/bpf/network_helpers.h +++ b/tools/testing/selftests/bpf/network_helpers.h @@ -76,6 +76,9 @@ int connect_to_fd_opts(int server_fd, const struct network_helper_opts *opts); int connect_fd_to_fd(int client_fd, int server_fd, int timeout_ms); int send_to_fd_opts(int server_fd, const void *data, size_t datalen, int flags, const struct network_helper_opts *opts); +int send_to_addr_str(int family, int type, const char *addr_str, __u16 port, + const void *data, size_t datalen, int flags, + const struct network_helper_opts *opts); int fastopen_connect(int server_fd, const char *data, unsigned int data_len, int timeout_ms); int make_sockaddr(int family, const char *addr_str, __u16 port, From patchwork Tue Jul 23 22:22: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: 13740401 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 B28A0148827; Tue, 23 Jul 2024 22:23:02 +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=1721773382; cv=none; b=mdVE2FhWgh2FwlqUb8zy24IZW3RuI/XtY5/TIqcIiP0b4GgYFIerxqJKNpBtHm6X2U+NpSxz0KeP0cpxMuBVVCtJT4wfese9oRVPNfO44Hk/ovoBxkWeY8ZGuD7xhWAe+ummG+LYcy4OUGSkAGS2sY0K9WIbibhl4GLhbCMoXmU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721773382; c=relaxed/simple; bh=bv3iZilP69LsdBfqj6UWFYuqdyB7jfED8iPUSdIaI7I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SCwm5HS/HO3b5R5uB1dEQRAhJHyUdB/aRe30j8ElDDuaVVrRxCqOIHqw/JUQo7NE4EUuyZc8jrmHpK67DoV13nx6yk9RVMN8njCPp/YmB5sHSLdzteZ+aY1nbVJI/kwZpIVLIzscsI1oAz7aetyF3tIHlaO+6jkvYVfORkQLVbU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=JAmq3tY1; 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="JAmq3tY1" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EC396C4AF09; Tue, 23 Jul 2024 22:22:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721773382; bh=bv3iZilP69LsdBfqj6UWFYuqdyB7jfED8iPUSdIaI7I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JAmq3tY1hzIeEAN6SHNybfemqmOBqutimROjEDHazhhcog2AfwWqdM9okvFmWK6uS DZSnRL3IsUL2WoVamHUHfoGw/eROOye0CelGgXz+u4E6HZzi7XDwZt6CePhVglrVUP p391zQQ3abuKOvFQGfhwgGTwBf3/soM9xqqrCPPJ3ubV2nID1pxPDUOif3pMzZ1mif zagkonys8AskaIsUHmr24AMSGNDKZVihHnb8rTJLtIo1taoHb+pjdT/AqtlEHY/CVk pXObTZqnj+Y9MXXbVb2+JqzJWJ+3sO4Edjh8obDYmGYn0qCKlcyb3APTe0hZr7ztVo HchSUnYnGtS1A== 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 06/15] selftests/bpf: Use send_to_addr_str in xdp_bonding Date: Wed, 24 Jul 2024 06:22:12 +0800 Message-ID: X-Mailer: git-send-email 2.43.0 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 first user of send_to_addr_str() is send_udp_packets() in xdp_bonding. Use sprintf() to generate "addr_str" string from ifindex, sll_halen and sll_addr, and pass it to send_to_addr_str(). Since IPPROTO_ICMP is used, set it as opts.proto and pass opts to the helper too. Use ASSERT_OK_FD() to check the return fd of send_to_addr_str(). Signed-off-by: Geliang Tang --- .../selftests/bpf/prog_tests/xdp_bonding.c | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_bonding.c b/tools/testing/selftests/bpf/prog_tests/xdp_bonding.c index 6d8b54124cb3..5c60268b805c 100644 --- a/tools/testing/selftests/bpf/prog_tests/xdp_bonding.c +++ b/tools/testing/selftests/bpf/prog_tests/xdp_bonding.c @@ -206,6 +206,9 @@ static void bonding_cleanup(struct skeletons *skeletons) static int send_udp_packets(int vary_dst_ip) { + struct network_helper_opts opts = { + .proto = IPPROTO_RAW, + }; struct ethhdr eh = { .h_source = BOND1_MAC, .h_dest = BOND2_MAC, @@ -213,17 +216,15 @@ static int send_udp_packets(int vary_dst_ip) }; struct iphdr iph = {}; struct udphdr uh = {}; + char addr_str[32]; uint8_t buf[128]; int i, s = -1; int ifindex; - s = socket(AF_PACKET, SOCK_RAW, IPPROTO_RAW); - if (!ASSERT_GE(s, 0, "socket")) - goto err; - ifindex = if_nametoindex("bond1"); if (!ASSERT_GT(ifindex, 0, "get bond1 ifindex")) goto err; + sprintf(addr_str, "%d %c %s", ifindex, ETH_ALEN, BOND2_MAC_STR); iph.ihl = 5; iph.version = 4; @@ -237,13 +238,6 @@ static int send_udp_packets(int vary_dst_ip) iph.check = 0; for (i = 1; i <= NPACKETS; i++) { - int n; - struct sockaddr_ll saddr_ll = { - .sll_ifindex = ifindex, - .sll_halen = ETH_ALEN, - .sll_addr = BOND2_MAC, - }; - /* vary the UDP destination port for even distribution with roundrobin/xor modes */ uh.dest++; @@ -255,8 +249,8 @@ static int send_udp_packets(int vary_dst_ip) memcpy(buf + sizeof(eh), &iph, sizeof(iph)); memcpy(buf + sizeof(eh) + sizeof(iph), &uh, sizeof(uh)); - n = sendto(s, buf, sizeof(buf), 0, (struct sockaddr *)&saddr_ll, sizeof(saddr_ll)); - if (!ASSERT_EQ(n, sizeof(buf), "sendto")) + s = send_to_addr_str(AF_PACKET, SOCK_RAW, addr_str, 0, buf, sizeof(buf), 0, &opts); + if (!ASSERT_OK_FD(s, "send_to_addr_str")) goto err; } From patchwork Tue Jul 23 22:22: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: 13740402 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 0B9431482E2; Tue, 23 Jul 2024 22:23:07 +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=1721773387; cv=none; b=GRkzfcMVH6B23VaPtWumkgKkBR3qxB1MsUa0uvvFdzZgRVlFj+CD4jc10g6u7F626sPaEdQosCEliYJ9t+bIPVG6tQ/zdLUWgvSltd1JJHy4Pbyaedd1d1XPZeOoxNzxaN5YG70QOR2qpzNCvAOIn+ERfkB/lKHlYsOO+npiALU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721773387; c=relaxed/simple; bh=YBqZd6bqszPv1L2BqgxtBBlG+WaL56Es26tyx6TtL3s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TgKtJ+1YQJzAuK5uE99DBW6KiFAEfP++juwMkRCdFR626yeQciwqDb0GQrMSXg94hU/Lf2sRU+gr1EfkFmecSnRr+X3PcqajwHnAaigXiyyn1P7dY34D/fpmcQuyrmWWtelvbIUUK1/494fQirbO+0J7G6z422W3KjoDrlwHJe4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=eQk+CzTM; 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="eQk+CzTM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4113DC4AF15; Tue, 23 Jul 2024 22:23:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721773386; bh=YBqZd6bqszPv1L2BqgxtBBlG+WaL56Es26tyx6TtL3s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eQk+CzTM7Qr522xqMY9N7CAb4PyK2usQye6nLJMGuB4oq/koKJ4h9cQiirCeuw9O4 bYksXqn74TjF5oGYYYD92Ts8hKttp7/i87VP+/uOM4HDxq2RV380atq1xUmyGKHTNk tJZlPWngT97gYfOD7JaInXDB4dx5m7oQVRWqMF7xxUM8iNXD0JpVtZM++34Y77OpbS CrNKOcoLAOImAA423GvFi1X4pQ5DMu/VmoAD26ZZoTgDxBk3W+X71hqKF8oC7642yt txL0scyPEWcc5c88jU5qCe/m69WX49OfORb8m8GDMTT/y47vtebDZu2o4OQeOpzV+U CzPmAmgB019wg== 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 07/15] selftests/bpf: AF_ALG support for make_sockaddr Date: Wed, 24 Jul 2024 06:22:13 +0800 Message-ID: <50e333e776a5b33393bdf51d24053bf091784402.1721771340.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.43.0 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 AF_ALG support for make_sockaddr(), uses sscanf() to parse the given addr_str string to "salg_type" and "salg_name" of struct sockaddr_alg. Signed-off-by: Geliang Tang --- tools/testing/selftests/bpf/network_helpers.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c index a6c158718267..8f39adbc2c16 100644 --- a/tools/testing/selftests/bpf/network_helpers.c +++ b/tools/testing/selftests/bpf/network_helpers.c @@ -17,6 +17,7 @@ #include #include #include +#include #include "bpf_util.h" #include "network_helpers.h" @@ -468,6 +469,20 @@ int make_sockaddr(int family, const char *addr_str, __u16 port, if (len) *len = sizeof(*sll); return 0; + } else if (family == AF_ALG) { + struct sockaddr_alg *salg = (void *)addr; + + memset(addr, 0, sizeof(*salg)); + salg->salg_family = family; + if (addr_str && + sscanf(addr_str, "%s %s", + salg->salg_type, salg->salg_name) == -1) { + log_err("AF_ALG sscanf(%s)", addr_str); + return -1; + } + if (len) + *len = sizeof(*salg); + return 0; } return -1; } From patchwork Tue Jul 23 22:22: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: 13740403 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 5A21414831C; Tue, 23 Jul 2024 22:23: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=1721773391; cv=none; b=aZq4Aj2VSr3xKBEblmw0PianGkkUmVWhSZJ9qZJb6kFaWdlPCyYRndbJZMbiBkpQx5z/HLm2faYn6Hg4kbSoYBMjybTQIFgEaxQIZXNnkKB3LzbilDjMt8lsW9WTZBMvIYjuSMgIANBhw6s1kRFK7VWc8LLMnMmss1Cq4sb7asg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721773391; c=relaxed/simple; bh=5om8By3O7JAi0xe/XZSca4IIUIS1286qoC70zrmf0Dk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hk34AMLIBJmOoEGNOFtwBccB93r5vKANm3JDUCUXCSA+S9KD4t7atG0VJlTi28STp+2Yg1kFh1jJ7p8yMOhL3JEoa2BSgn45yM4AoLxggqldin17n1TmFjcH+L7qqvjLkFcpOQyAynBF4puMJpM3Empw37JuhiBV7Vgoms5ryM8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=acr3xK2P; 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="acr3xK2P" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8A7A9C4AF15; Tue, 23 Jul 2024 22:23:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721773391; bh=5om8By3O7JAi0xe/XZSca4IIUIS1286qoC70zrmf0Dk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=acr3xK2PzD3aIS+fw4f3hDCeUsa8MyFu4WJqeMIQT5/E3EPx+Km0SZvRFEn9ZIlmF ihKTGUcXH06mdmK3m54kPrnMNL2gEVEy7N9lvrAGjWQo35LDDNIuC5SSg3eN+6lICW /adU40IYjWtz9svqGYCk44f0W557TBNJkhjQHMrIE9ns2SXt/25zWffmGumxKfPE/b sZOTJ5EirkBMw9Rp0EcaEsTMBGRoTLAmnAv8jLAbufaXG9WtKNGWI9fynXUZAveLew Sdmq2i3niJ/Tt3NrQBSFZ0zNeVXHdkVTllq4GqyESWtyF4p25Gbti7dm7bXuRFVMvb BSUL/0l9GiQdg== 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 08/15] selftests/bpf: Add nolisten for network_helper_opts Date: Wed, 24 Jul 2024 06:22:14 +0800 Message-ID: X-Mailer: git-send-email 2.43.0 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 struct member "nolisten" for network_helper_opts, which is used to control whether to invoke listen() or not in start_server_addr(). Also print out a warning if backlog is set for a type not support listen for connections. Signed-off-by: Geliang Tang --- tools/testing/selftests/bpf/network_helpers.c | 5 ++++- tools/testing/selftests/bpf/network_helpers.h | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c index 8f39adbc2c16..f140a76d3d7f 100644 --- a/tools/testing/selftests/bpf/network_helpers.c +++ b/tools/testing/selftests/bpf/network_helpers.c @@ -109,11 +109,14 @@ int start_server_addr(int type, const struct sockaddr_storage *addr, socklen_t a goto error_close; } - if (type == SOCK_STREAM) { + if (!opts->nolisten && type == SOCK_STREAM) { if (listen(fd, opts->backlog ? MAX(opts->backlog, 0) : 1) < 0) { log_err("Failed to listed on socket"); goto error_close; } + } else if (opts->backlog) { + log_err("Useless network helper opts: backlog %d", + opts->backlog); } return fd; diff --git a/tools/testing/selftests/bpf/network_helpers.h b/tools/testing/selftests/bpf/network_helpers.h index ebed1fb1bd49..16f266c53b61 100644 --- a/tools/testing/selftests/bpf/network_helpers.h +++ b/tools/testing/selftests/bpf/network_helpers.h @@ -34,6 +34,7 @@ struct network_helper_opts { * changing the "tcp_syncookies" sysctl from 1 to 2. */ int backlog; + bool nolisten; int (*post_socket_cb)(int fd, void *opts); void *cb_opts; }; From patchwork Tue Jul 23 22:22: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: 13740404 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 8322D1DDD6; Tue, 23 Jul 2024 22:23:15 +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=1721773395; cv=none; b=uDeiW6/75mlwShht3AqnVkzqkAeyyikHdiLT5SJ4UQVLYj+Za/4vOA7Xc66bP7xT/qiAu+NznyFFBcdP3Ook6g7h9U5gaerWFjgqvsfbOCw1fthn8y2ubh18TfHFkTT7iyFYAKpW+z6W/NUvjqpQRASC3EXpndi1X7MiqbKNgiw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721773395; c=relaxed/simple; bh=xQr7aSrfooBfu5skylei+sIq3p9y31kRyAxMfGrXLWQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=goahHxboEDdwxfEBkj5bzKHjec2oAEZTr8GWsMy2evmrFSma8KtQjoQoQfa/i4rk4K0Y/8ywuTsdDQqOcuIAEkiDl6i5sAWy3JEhHG0sJbjx2+u7Hu7f74SYXAMdG/UrK6fqEe6qkBOhgiyFhtW9T5Pkci7qXuXZendoHMHlhK0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=L6DAk+Yj; 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="L6DAk+Yj" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BAFE3C4AF10; Tue, 23 Jul 2024 22:23:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721773395; bh=xQr7aSrfooBfu5skylei+sIq3p9y31kRyAxMfGrXLWQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=L6DAk+YjXuhKF2RBaZQVesMJSg2HZw5XYB9KnqU2DUZUqdjUW3U6G/40NYJ/St8Lv T7exNt7zD5fE7THzdu23M5tMgifA4vJmiwoybFgNeeinYRfp7Z6YSUyAIYCc8sfbZ9 u2qC2HR1pUnVpGi8Hsi8qjjjnPT8XD1u20tUHFx9UXKtR5gpZzyVjduSJmEqVYtxiJ RqUOCpIdDOdTDgkgEOZufOW01F/xrbzE6KAmhKKsAd4yaybmQI+1Bl06XF3/7H+n+b mgk/d9zUOmqogS2WUv9hibRtjL83rkb2KiJ1FZHN/N3aMU1rscipVbVsaghFT801ra o2IbNybxlW4ww== 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 09/15] selftests/bpf: Use start_server_str in crypto_sanity Date: Wed, 24 Jul 2024 06:22:15 +0800 Message-ID: <11d7a17f7245e17d29c1001461af6260b62ea610.1721771340.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.43.0 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 start_server_str() to start a AF_ALG server in test crypto_sanity, since no listen is needed in this test, nolisten flag of network_helper_opts is set. Signed-off-by: Geliang Tang --- .../testing/selftests/bpf/prog_tests/crypto_sanity.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/crypto_sanity.c b/tools/testing/selftests/bpf/prog_tests/crypto_sanity.c index b1a3a49a822a..9b7a26c79123 100644 --- a/tools/testing/selftests/bpf/prog_tests/crypto_sanity.c +++ b/tools/testing/selftests/bpf/prog_tests/crypto_sanity.c @@ -20,16 +20,12 @@ static int opfd = -1, tfmfd = -1; static const char algo[] = "ecb(aes)"; static int init_afalg(void) { - struct sockaddr_alg sa = { - .salg_family = AF_ALG, - .salg_type = "skcipher", - .salg_name = "ecb(aes)" + struct network_helper_opts opts = { + .nolisten = true, }; - tfmfd = socket(AF_ALG, SOCK_SEQPACKET, 0); - if (tfmfd == -1) - return errno; - if (bind(tfmfd, (struct sockaddr *)&sa, sizeof(sa)) == -1) + tfmfd = start_server_str(AF_ALG, SOCK_SEQPACKET, "skcipher ecb(aes)", 0, &opts); + if (!ASSERT_OK_FD(tfmfd, "start_server_addr")) return errno; if (setsockopt(tfmfd, SOL_ALG, ALG_SET_KEY, crypto_key, 16) == -1) return errno; From patchwork Tue Jul 23 22:22: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: 13740405 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 D5CA91DDD6; Tue, 23 Jul 2024 22:23:19 +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=1721773399; cv=none; b=MRpmFndEQn/xaDhfJhUXUSmECPPPOv+1z1RpDgEqfC6TROpDBqMHYzsqCGSQNt7Y4/CvnfdzdNLI6EkA5m1APN0PjiuZihSCgAkPZpg22t4mIIyY5EVS8oXzoN8WrL5RFo/Peimlt7L+JSgLweGVQ+/0oDtRJLfOY7P7ZSCxjOI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721773399; c=relaxed/simple; bh=4RgzlUO1ELpjhyL1Q4t07Sw3sMou1DtPvptQrfqDGKg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YNlFwWM720gi2PYRIdhBK4PXvgWo7biLZ6Ts/PgR97tp8lQucu07TVVYBSS2Cyz2Dspgdo3BJz+LjYarTjFbj1BsFLkh2jn1eeLSgV1kyNHkG2RGLp5cssbBiCYAt6UKXmye/40zuBAhtonXAmzBahY0YwgAqJ/Ln90MKuTtIAc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=fNduFsIm; 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="fNduFsIm" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1041CC4AF14; Tue, 23 Jul 2024 22:23:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721773399; bh=4RgzlUO1ELpjhyL1Q4t07Sw3sMou1DtPvptQrfqDGKg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fNduFsImGJp2OKknBzpaaEwfdYy2iTK1tt2thM9HPAGTp93XKDDNYo9RmbdMZr+aC dZiZ0WcRM1DIhG0c6E3MRlVue4K3racvkNn6VpKuIZZTs5F/qfZgwlDYMKJ0tAg0G4 PlaczmwZpOdU7QDVUJLLkwcgwRsr34BRAcV+MnmOggqCfEzMeOaju+1imLxIHvh4xY dZKxkOwMIHKC2ZV5TYfV6LVfaxbj2EdaKBXQO/AsranHW9nEjIwAvZVLvTcozBji76 dOODZXbuVsyWE8BPJAt0XTNYhNT1D6S3A0+ysIe7FeoI4ND5vGtYmXrbLju8G75/2W rdGNC/w0fcQrg== 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 10/15] selftests/bpf: AF_VSOCK support for make_sockaddr Date: Wed, 24 Jul 2024 06:22:16 +0800 Message-ID: X-Mailer: git-send-email 2.43.0 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 AF_VSOCK support for make_sockaddr(), uses atoi() to convert the given addr_str string to an integer id and sets it to "svm_cid". Set "svm_port" as VMADDR_PORT_ANY if the value of port is zero. Signed-off-by: Geliang Tang --- tools/testing/selftests/bpf/network_helpers.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c index f140a76d3d7f..8b06b0bf66ae 100644 --- a/tools/testing/selftests/bpf/network_helpers.c +++ b/tools/testing/selftests/bpf/network_helpers.c @@ -18,6 +18,7 @@ #include #include #include +#include #include "bpf_util.h" #include "network_helpers.h" @@ -486,6 +487,16 @@ int make_sockaddr(int family, const char *addr_str, __u16 port, if (len) *len = sizeof(*salg); return 0; + } else if (family == AF_VSOCK) { + struct sockaddr_vm *svm = (void *)addr; + + memset(addr, 0, sizeof(*svm)); + svm->svm_family = family; + svm->svm_port = port ?: VMADDR_PORT_ANY; + svm->svm_cid = addr_str ? atoi(addr_str) : 0; + if (len) + *len = sizeof(*svm); + return 0; } return -1; } From patchwork Tue Jul 23 22:22: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: 13740406 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 248A31487EA; Tue, 23 Jul 2024 22:23:24 +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=1721773404; cv=none; b=QLVu6dMXXtGKrTmQL5kQwlcOAjkw4o8LnUxEzZq07loNmA6APCxrCHbid/mInZNvXz1g1ovwZjFbw1kc/myG2tj28Iufm5gghrppiHtqT9NAFvxIZQ4XWi/LyN9RKul0GgC2pvGbigO+biNmEICToqWKEQ4hgzhGvk95jfyxyoY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721773404; c=relaxed/simple; bh=ME+tSI8PBgw6F7c3OiWB1NRmntbKUJH1Ek+eeeScfqI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=b8JFndErtPbUyWIuEVBDjIPGiBHaANKDTSh6okyCytihSv73SUd4COVPfxhfGWswxRW7m2mdkckYGnHGYUoTzExY5vKeSVp8ynhHfEXTbFVElQllDYMz8rKnMNwF1om2qymWWXDHOJ8mBmAXmamYHcY95Tz17TArKfwcZPc0oKQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=WdPm2klD; 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="WdPm2klD" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 59A5FC4AF09; Tue, 23 Jul 2024 22:23:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721773404; bh=ME+tSI8PBgw6F7c3OiWB1NRmntbKUJH1Ek+eeeScfqI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WdPm2klDvcfsdO0G5UKGuhYAkHxrRaapwMfpAlhKxfl0Uy3Htgav78ANecohHQvDY oJdTNAIsY0tgbt3b2NxYEdLhyycCZ+rtXlFSXqbucZMJiQAZ8Nmlksa6S0cIuJjPZh fEqPNPlcJ4q5AjDVeEEEt3mzClRMLlxXksSn9VbNS5ltI9f+7H3yDcyfoYxuONR7C6 iINXm9lHwTRNBe4Nlsl5qM19KzhwkwYzE6TnqiRsFSeLFALSd9v/4RZy/PBQ5Nstva zvfK/PGqZe8pPAw5Yf01FAzUQvp4IoYDjdf1ernmv/xuGyQ8FmiNvpFrwPpLWGkClw M+kiEkEDecm5w== 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 11/15] selftests/bpf: Add loopback_addr_str helper Date: Wed, 24 Jul 2024 06:22:17 +0800 Message-ID: <92d84e92e60304b26e7bae9dfc65bb3548d4f3a2.1721771340.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.43.0 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 loopback_addr_str() to get the loopback address string according to the given different protocol family. Also use this new helper in start_servers() in migrate_reuseport.c. Signed-off-by: Geliang Tang --- tools/testing/selftests/bpf/network_helpers.h | 15 +++++++++++++++ .../selftests/bpf/prog_tests/migrate_reuseport.c | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/bpf/network_helpers.h b/tools/testing/selftests/bpf/network_helpers.h index 16f266c53b61..893f07c677da 100644 --- a/tools/testing/selftests/bpf/network_helpers.h +++ b/tools/testing/selftests/bpf/network_helpers.h @@ -55,6 +55,21 @@ struct ipv6_packet { } __packed; extern struct ipv6_packet pkt_v6; +static inline char *loopback_addr_str(int family) +{ + switch (family) { + case AF_INET: + return "127.0.0.1"; + case AF_INET6: + return "::1"; + case AF_VSOCK: + return "1"; /* VMADDR_CID_LOCAL */ + default: + fprintf(stderr, "unsupported address family %d", family); + return NULL; + } +} + int settimeo(int fd, int timeout_ms); int start_server_str(int family, int type, const char *addr_str, __u16 port, const struct network_helper_opts *opts); diff --git a/tools/testing/selftests/bpf/prog_tests/migrate_reuseport.c b/tools/testing/selftests/bpf/prog_tests/migrate_reuseport.c index 653b0a20fab9..7c31c7fdaecb 100644 --- a/tools/testing/selftests/bpf/prog_tests/migrate_reuseport.c +++ b/tools/testing/selftests/bpf/prog_tests/migrate_reuseport.c @@ -221,7 +221,7 @@ static int start_servers(struct migrate_reuseport_test_case *test_case, prog_fd = bpf_program__fd(skel->progs.migrate_reuseport); make_sockaddr(test_case->family, - test_case->family == AF_INET ? "127.0.0.1" : "::1", 0, + loopback_addr_str(test_case->family), 0, &test_case->addr, &test_case->addrlen); for (i = 0; i < NR_SERVERS; i++) { From patchwork Tue Jul 23 22:22: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: 13740407 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 546D214831C; Tue, 23 Jul 2024 22:23:28 +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=1721773408; cv=none; b=SVcLLAQbwZxJIUPPxv5nd7PlpmwMGP6Eg474pXQoR1gzf7yIzn0Ti/lrcJ1ru4H9O48q+iu9uYKCXgI9rxcELj0bDbE3jLfYbkJhy7yc8Zdru40a60HuawYH6B/mdSMrHEE7PJfhu6f5IhnxoWZqFuXIpKT5mpmw81FwDwtjchE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721773408; c=relaxed/simple; bh=bK0shGl2RZDG63euPAWvwcmVDmknniOqfLk8yYBn9AM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SBibm8tY7oRYgrOq1VudfJyLBpgsFrjqeqkZTSPP6RFRZp18c/+QeMpf0TzU+a7d5sh12iPZ7HLthpWO+3oTbjXNqe366zBnLs6y28k7tuBGVeI/najMS1hnpsTqopSJS2a+fxMLVW3IlJu9dSlAYuazrOJymAdX6qZGTMRr/rM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=M0v9veyj; 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="M0v9veyj" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8A4B8C4AF0A; Tue, 23 Jul 2024 22:23:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721773408; bh=bK0shGl2RZDG63euPAWvwcmVDmknniOqfLk8yYBn9AM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=M0v9veyjRExJZzVzmTao0Qv8qqkk8tkXCe1aezbXz8PFJJ1o6xXAtlaKWts/UTjuL VR2eedLK+ptffihsxZJDLtql+wvFN72noUwm1WuoU7bj7XpXaWxWqk7e08cz9KaGqh w6OK0ssdOseJcDt4J00+QWcOKRRJO8+EY5M7lMbCcFBEpLKOHuEdiVput3GqQczBbQ /R0SGfLtJWkHJ6ooQtb1T64RwnkwtJS0SNHjCYzZzjKECIUxY2l91nRlMspr1e8nVP +QJ87SRGibKK9FxDBnTvIVCOAMPrWg8QzPu2eGEf0HRrhRyMR3hVF7Nl8EzfMb34dr KmNQvQhl+bAzA== 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 12/15] selftests/bpf: Use make_sockaddr in sockmap_helpers Date: Wed, 24 Jul 2024 06:22:18 +0800 Message-ID: <951ea44c8df0f6d8904317be8bec33db85e9a5de.1721771340.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.43.0 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 AF_VSOCK is supported in make_sockaddr() now, use it to implement init_addr_loopback() in sockmap_helpers.h. Then three local functions init_addr_loopback4(), init_addr_loopback6() and init_addr_loopback_vsock() can be dropped. Signed-off-by: Geliang Tang --- .../bpf/prog_tests/sockmap_helpers.h | 54 +------------------ 1 file changed, 2 insertions(+), 52 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/sockmap_helpers.h b/tools/testing/selftests/bpf/prog_tests/sockmap_helpers.h index e880f97bc44d..0fe095497f34 100644 --- a/tools/testing/selftests/bpf/prog_tests/sockmap_helpers.h +++ b/tools/testing/selftests/bpf/prog_tests/sockmap_helpers.h @@ -1,17 +1,12 @@ #ifndef __SOCKMAP_HELPERS__ #define __SOCKMAP_HELPERS__ -#include +#include "network_helpers.h" #define IO_TIMEOUT_SEC 30 #define MAX_STRERR_LEN 256 #define MAX_TEST_NAME 80 -/* workaround for older vm_sockets.h */ -#ifndef VMADDR_CID_LOCAL -#define VMADDR_CID_LOCAL 1 -#endif - #define __always_unused __attribute__((__unused__)) #define _FAIL(errnum, fmt...) \ @@ -239,55 +234,10 @@ static inline int recv_timeout(int fd, void *buf, size_t len, int flags, return recv(fd, buf, len, flags); } -static inline void init_addr_loopback4(struct sockaddr_storage *ss, - socklen_t *len) -{ - struct sockaddr_in *addr4 = memset(ss, 0, sizeof(*ss)); - - addr4->sin_family = AF_INET; - addr4->sin_port = 0; - addr4->sin_addr.s_addr = htonl(INADDR_LOOPBACK); - *len = sizeof(*addr4); -} - -static inline void init_addr_loopback6(struct sockaddr_storage *ss, - socklen_t *len) -{ - struct sockaddr_in6 *addr6 = memset(ss, 0, sizeof(*ss)); - - addr6->sin6_family = AF_INET6; - addr6->sin6_port = 0; - addr6->sin6_addr = in6addr_loopback; - *len = sizeof(*addr6); -} - -static inline void init_addr_loopback_vsock(struct sockaddr_storage *ss, - socklen_t *len) -{ - struct sockaddr_vm *addr = memset(ss, 0, sizeof(*ss)); - - addr->svm_family = AF_VSOCK; - addr->svm_port = VMADDR_PORT_ANY; - addr->svm_cid = VMADDR_CID_LOCAL; - *len = sizeof(*addr); -} - static inline void init_addr_loopback(int family, struct sockaddr_storage *ss, socklen_t *len) { - switch (family) { - case AF_INET: - init_addr_loopback4(ss, len); - return; - case AF_INET6: - init_addr_loopback6(ss, len); - return; - case AF_VSOCK: - init_addr_loopback_vsock(ss, len); - return; - default: - FAIL("unsupported address family %d", family); - } + make_sockaddr(family, loopback_addr_str(family), 0, ss, len); } static inline struct sockaddr *sockaddr(struct sockaddr_storage *ss) From patchwork Tue Jul 23 22:22: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: 13740408 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 C515D1422AB; Tue, 23 Jul 2024 22:23: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=1721773412; cv=none; b=lwYpaSC5Wu+WitBD4eDPhIUwMQ0SFJA95hQ/2yHhpNxoxLjom9pjuQ2cG+snHLvcOtxGQwIe3KHnn9iYTkT5ONWwjJVEV6P70HSxYaHzrHDjq6wH5WXvw2mDAFGljw//KOYJ3hZfaVNYftmuW1QajGltr5QyoMGHuxCHmVQWlgg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721773412; c=relaxed/simple; bh=SDq3d/iEx9vI0ULJ3CqdeMcebgGgRTUsqukdR9Cpzt0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Gkvjj482ayvwGMJJat4P/8be87AM0JAyRSoliDppt6yL3VqxLSpynIKR1TE03kGH0uJQhl3zLwOX4F4kbO4V67B78APqg8C+UUg/C2HHTDdw8BhdJhzF0ZliMoeeeRBE4mA43w9VJ3yGasgkyl6+RXDOnVgZnjYLbyS/JLljWiY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=beyXCFmY; 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="beyXCFmY" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D36F3C4AF11; Tue, 23 Jul 2024 22:23:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721773412; bh=SDq3d/iEx9vI0ULJ3CqdeMcebgGgRTUsqukdR9Cpzt0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=beyXCFmYzzEJqASQWEOUEMS7X2fzUJfTjHTs865sGKFa3TAegi8BdhGYhQfZkW2c1 10osi/NmWRPS0Q1V0nJvHyGax8TKsNMh8EkzOwg5uWxQMW6j3JBKFD7ProQF0b/lm/ btpiEX64j+PVa3FgxNYBXW2zp1F9/FzVSQw62DozXZuWO7rbFmeQXunhJUvrndslDL XL2ejo/uWhnnDz4qj+6cBs/lEPyC4jAFybR7Kl+XK7P5YI+RTtFMR4F/k5UPhLEQHU 6HMiRFpIbw2GlH+yh0Mi2qUUTyaBdGJQos8Y3WhMAk96Br2QH1F9tX1HWtyyr576ml WYJi4FUbXRY3g== 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 13/15] selftests/bpf: Check listen support for start_server_addr Date: Wed, 24 Jul 2024 06:22:19 +0800 Message-ID: X-Mailer: git-send-email 2.43.0 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 No only SOCK_STREAM type supports listen for connections on a socket, SOCK_SEQPACKET used in sockmap_listen.c supports it too. This patch adds a new helper listen_support() to check whether a given "type" supports listen for connections on a socket or not. Signed-off-by: Geliang Tang --- tools/testing/selftests/bpf/network_helpers.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c index 8b06b0bf66ae..6b6734b893e4 100644 --- a/tools/testing/selftests/bpf/network_helpers.c +++ b/tools/testing/selftests/bpf/network_helpers.c @@ -82,6 +82,17 @@ int settimeo(int fd, int timeout_ms) #define save_errno_close(fd) ({ int __save = errno; close(fd); errno = __save; }) +static bool listen_support(int type) +{ + switch (type) { + case SOCK_STREAM: + case SOCK_SEQPACKET: + return true; + default: + return false; + } +} + int start_server_addr(int type, const struct sockaddr_storage *addr, socklen_t addrlen, const struct network_helper_opts *opts) { @@ -110,7 +121,7 @@ int start_server_addr(int type, const struct sockaddr_storage *addr, socklen_t a goto error_close; } - if (!opts->nolisten && type == SOCK_STREAM) { + if (!opts->nolisten && listen_support(type)) { if (listen(fd, opts->backlog ? MAX(opts->backlog, 0) : 1) < 0) { log_err("Failed to listed on socket"); goto error_close; From patchwork Tue Jul 23 22:22: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: 13740409 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 2BA2314882E; Tue, 23 Jul 2024 22:23:36 +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=1721773417; cv=none; b=PkrIdVBQaJriToeBhY5IwEsziLw561g0Ukxtjfylom/PKgnX8p8k+9NJrW4WCUcVIj7X/k0MeqEkYB7PuWn1ZKLGIIeotDXIXvH47SpwVF/fFWdA4yTsrLVcfHdga1Ef/IsmiLjfVXz3a63bgM8F9hmi8XZzDF/z0DnO7bbtBbU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721773417; c=relaxed/simple; bh=2LU2vjg3f906UWyhDzXWAXiRIxOItrklwjsTG1UwTzg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Tj6e+difzErR9AGCYdaswD5E+x3ikGi/JgwITSl/QlXHJb+VOw+sUbKnsdRF2at7NoXQ+IKsRIVfxQTF+56s2yPHZlDARaFEfQ56qKiiVaPRRYkU/AcFcFTd1VPAAhSNRPwG94pmTisLkfYGKTNe/nX8p9sHqfD5lvZ9m/RVYdg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=N8SJcWOc; 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="N8SJcWOc" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0FE91C4AF0A; Tue, 23 Jul 2024 22:23:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721773416; bh=2LU2vjg3f906UWyhDzXWAXiRIxOItrklwjsTG1UwTzg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=N8SJcWOcfw58BTkjnpuO9e88EIkrHRbhQYDvakVuO9wjJUpl05HoggBxvEo/AHBMD Lg/PYxevuKR8H79Ec3+G3UFaPxfb+FSyjUczU4ZKorr9kITUU7JPwph3cxPttMR5jk wHZSFhlZL5VTq/wp4bAqBOzV1C1X/1QlD0s5QgjeK8qY6I3/eTbYBnDTERCjJpwqkG nz7wKRbrgdkdJbUzseBGLgmkmgzd8jFjhz6rqqNGC/8s66gADq7Vpvv8uG3tKNLwzj yHAiPQIsr/NCjE1aLdxe1eh6PhzUYlQLD9AaCsnb/cnBmTgITjJESJ+AeSIsWHNQQM LDPz4Qr/7KYmA== 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 14/15] selftests/bpf: Clear type bits for start_server_addr Date: Wed, 24 Jul 2024 06:22:20 +0800 Message-ID: <2bdf858ce89445fa66ef15b0159425649cfe1ffa.1721771340.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.43.0 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 types "sotype | SOCK_NONBLOCK" are passed to socket_loopback_reuseport by some tests in sockmap_listen.c, so they must be handled in helper start_server_addr() too. This patch uses SOCK_TYPE_MASK to clear useless bits of "type" before check whether it supports listen for connections. Signed-off-by: Geliang Tang --- tools/testing/selftests/bpf/network_helpers.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c index 6b6734b893e4..919b691c2699 100644 --- a/tools/testing/selftests/bpf/network_helpers.c +++ b/tools/testing/selftests/bpf/network_helpers.c @@ -28,6 +28,9 @@ #define IPPROTO_MPTCP 262 #endif +#define SOCK_MAX (SOCK_PACKET + 1) +#define SOCK_TYPE_MASK 0xf + #define clean_errno() (errno == 0 ? "None" : strerror(errno)) #define log_err(MSG, ...) ({ \ int __save = errno; \ @@ -121,6 +124,9 @@ int start_server_addr(int type, const struct sockaddr_storage *addr, socklen_t a goto error_close; } + if (type > SOCK_MAX) + type &= SOCK_TYPE_MASK; + if (!opts->nolisten && listen_support(type)) { if (listen(fd, opts->backlog ? MAX(opts->backlog, 0) : 1) < 0) { log_err("Failed to listed on socket"); From patchwork Tue Jul 23 22:22: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: 13740410 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 73BF9143C6B; Tue, 23 Jul 2024 22:23:41 +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=1721773421; cv=none; b=ZEXTmchjE0yBoW8TDr9TheeDYjovurGKPKXf72E592IXrQGTIqQGgPRiZs3s426b26OqlVKOFZ7xZSWRvBUPGQdCPdQrN0jYtubVGPQaGgPjabTEuoPM+TmSg8AqnPY6nYTrLruOtOnjmIaJ1H17dXlVoLP1lwdhIBiff5QZGYI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721773421; c=relaxed/simple; bh=SHYjF4mo17ALM2nROj6zICCd1uAMwHnpyC0sTX26ffQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RPZiQl+d1n2uJ8v3ERsA4YPkM+XvxCV/yt66WC6ci0v7e260qFJwsCZ6nO0qJNt/OOZYlH3wwJLDxcABoQ/NwJui/ebV7g1upHUeZXzJNaUEkcapd9f/m+dcgCDYZFoZj03gVD1uXHbuAU/n7XKKhScRf/ne8LksMOdcvyIPbi4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=c+/CRT+w; 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="c+/CRT+w" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5956BC4AF0A; Tue, 23 Jul 2024 22:23:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721773421; bh=SHYjF4mo17ALM2nROj6zICCd1uAMwHnpyC0sTX26ffQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=c+/CRT+wOpVLTY3i81U+anoR/qpAysQBi9B6bWo+oaVKpRO6+ogl/+VPzLWsFTV3+ NlqcM7Jra4HTpWU+epoYQqD67LwvdDYAI4STtxisstomYnbRyBACa+0Qkju+4QGoA/ yGPmcIEOTe1ta7QffPVmfKZlb5NVQw+gm2WUa3pb3XuI/wgKnqPfMOEdvzPXDpwY0g Fbk2WzExYE0l5+960XzR9fmf4MiNW7ZPo3aoQdxbwHu8JwHweb807P6KOUfktMX4Rb rgHf3k/EKvxeYIU6+TMEPTty4nfJx7ys2k39gWyb/yDvOq98WkQx3uLGuQhAnKtT0Y fY6+ySy1Zrc2w== 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 15/15] selftests/bpf: Use start_server_str in sockmap_helpers Date: Wed, 24 Jul 2024 06:22:21 +0800 Message-ID: <2de2cd7a23bcd02d4711ec66d3b3a77c5632d1e7.1721771340.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.43.0 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 Now both SOCK_SEQPACKET and SOCK_NONBLOCK can be passed as "type" parameter into start_server_str(), use this helper in socket_loopback_reuseport() in sockmap_helpers.h to simplify the code. Signed-off-by: Geliang Tang --- .../bpf/prog_tests/sockmap_helpers.h | 47 ++++++++----------- 1 file changed, 19 insertions(+), 28 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/sockmap_helpers.h b/tools/testing/selftests/bpf/prog_tests/sockmap_helpers.h index 0fe095497f34..1e681e71e9ad 100644 --- a/tools/testing/selftests/bpf/prog_tests/sockmap_helpers.h +++ b/tools/testing/selftests/bpf/prog_tests/sockmap_helpers.h @@ -310,8 +310,14 @@ static inline int create_socket_pairs(int s, int family, int sotype, return err; } -static inline int enable_reuseport(int s, int progfd) +struct cb_opts { + int progfd; +}; + +static int enable_reuseport(int s, void *opts) { + struct cb_opts *co = (struct cb_opts *)opts; + int progfd = co->progfd; int err, one = 1; err = xsetsockopt(s, SOL_SOCKET, SO_REUSEPORT, &one, sizeof(one)); @@ -327,34 +333,19 @@ static inline int enable_reuseport(int s, int progfd) static inline int socket_loopback_reuseport(int family, int sotype, int progfd) { - struct sockaddr_storage addr; - socklen_t len = 0; - int err, s; - - init_addr_loopback(family, &addr, &len); - - s = xsocket(family, sotype, 0); - if (s == -1) - return -1; - - if (progfd >= 0) - enable_reuseport(s, progfd); - - err = xbind(s, sockaddr(&addr), len); - if (err) - goto close; - - if (sotype & SOCK_DGRAM) - return s; - - err = xlisten(s, SOMAXCONN); - if (err) - goto close; + struct cb_opts cb_opts = { + .progfd = progfd, + }; + struct network_helper_opts opts = { + .backlog = SOMAXCONN, + }; + + if (progfd >= 0) { + opts.post_socket_cb = enable_reuseport; + opts.cb_opts = &cb_opts; + } - return s; -close: - xclose(s); - return -1; + return start_server_str(family, sotype, loopback_addr_str(family), 0, &opts); } static inline int socket_loopback(int family, int sotype)