From: Martin KaFai Lau <martin.lau@linux.dev>
To: Geliang Tang <geliang@kernel.org>
Cc: Andrii Nakryiko <andrii@kernel.org>,
Eduard Zingerman <eddyz87@gmail.com>,
Mykola Lysenko <mykolal@fb.com>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Song Liu <song@kernel.org>,
Yonghong Song <yonghong.song@linux.dev>,
John Fastabend <john.fastabend@gmail.com>,
KP Singh <kpsingh@kernel.org>,
Stanislav Fomichev <sdf@google.com>, Hao Luo <haoluo@google.com>,
Jiri Olsa <jolsa@kernel.org>, Shuah Khan <shuah@kernel.org>,
Geliang Tang <tanggeliang@kylinos.cn>,
bpf@vger.kernel.org, mptcp@lists.linux.dev,
linux-kselftest@vger.kernel.org
Subject: Re: [PATCH bpf-next v2 1/8] selftests/bpf: Add unshare_netns helper
Date: Wed, 29 May 2024 16:31:41 -0700 [thread overview]
Message-ID: <1808b186-27d3-4bb8-854e-5ce19920a0c9@linux.dev> (raw)
In-Reply-To: <cf3c81f6014cfd1339622b1230e8dc9cca7a4440.1715821541.git.tanggeliang@kylinos.cn>
On 5/15/24 6:13 PM, Geliang Tang wrote:
> From: Geliang Tang <tanggeliang@kylinos.cn>
>
> Many BPF selftests create new test network namespaces by using CLONE_NEWNET
> flag to unshare the network namespace, so that the calling process is moved
> into a new network namespace which is not shared with any previously
> existing process. So this patch adds a new helper in network_helpers.c
> named unshare_netns(), which create a new network namespace and set the
> net device lo up.
>
> Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
> ---
> tools/testing/selftests/bpf/network_helpers.c | 19 +++++++++++++++++++
> tools/testing/selftests/bpf/network_helpers.h | 1 +
> 2 files changed, 20 insertions(+)
>
> diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c
> index 35250e6cde7f..919bb2a0c6a6 100644
> --- a/tools/testing/selftests/bpf/network_helpers.c
> +++ b/tools/testing/selftests/bpf/network_helpers.c
> @@ -670,3 +670,22 @@ int send_recv_data(int lfd, int fd, uint32_t total_bytes)
>
> return err;
> }
> +
> +int unshare_netns(void)
> +{
> + int err;
> +
> + err = unshare(CLONE_NEWNET);
> + if (err) {
> + log_err("unshare netns failed");
> + return err;
> + }
> +
> + err = SYS_NOFAIL("ip link set dev lo up");
Losing useful error output is not good. Please find a way to keep them available
such that it is easier to debug. The same goes for similar cases in this patch
set. I think the only exception could be the "ip netns del" during cleanup.
Also, bpf CI reports a crash (should be the test #18 bpf_ip_check_defrag). Not
sure how this set indirectly triggered it more easily:
https://github.com/kernel-patches/bpf/actions/runs/9290828674/job/25569002645
pw-bot: cr
> + if (err) {
> + log_err("set dev lo up failed");
> + return err;
> + }
> +
> + return 0;
> +}
> diff --git a/tools/testing/selftests/bpf/network_helpers.h b/tools/testing/selftests/bpf/network_helpers.h
> index 883c7ea9d8d5..b087330f2861 100644
> --- a/tools/testing/selftests/bpf/network_helpers.h
> +++ b/tools/testing/selftests/bpf/network_helpers.h
> @@ -82,6 +82,7 @@ struct nstoken;
> struct nstoken *open_netns(const char *name);
> void close_netns(struct nstoken *token);
> int send_recv_data(int lfd, int fd, uint32_t total_bytes);
> +int unshare_netns(void);
>
> static __u16 csum_fold(__u32 csum)
> {
next prev parent reply other threads:[~2024-05-29 23:31 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-16 1:13 [PATCH bpf-next v2 0/8] add netns helpers Geliang Tang
2024-05-16 1:13 ` [PATCH bpf-next v2 1/8] selftests/bpf: Add unshare_netns helper Geliang Tang
2024-05-29 23:31 ` Martin KaFai Lau [this message]
2024-05-16 1:13 ` [PATCH bpf-next v2 2/8] selftests/bpf: Use " Geliang Tang
2024-05-16 1:13 ` [PATCH bpf-next v2 3/8] selftests/bpf: Drop duplicate create_netns Geliang Tang
2024-05-16 1:13 ` [PATCH bpf-next v2 4/8] selftests/bpf: Export create_netns helper Geliang Tang
2024-05-16 1:13 ` [PATCH bpf-next v2 5/8] selftests/bpf: Use " Geliang Tang
2024-05-16 1:13 ` [PATCH bpf-next v2 6/8] selftests/bpf: Export cleanup_netns helper Geliang Tang
2024-05-16 1:13 ` [PATCH bpf-next v2 7/8] selftests/bpf: Use " Geliang Tang
2024-05-16 1:13 ` [PATCH bpf-next v2 8/8] selftests/bpf: Use netns helpers in lwt tests Geliang Tang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1808b186-27d3-4bb8-854e-5ce19920a0c9@linux.dev \
--to=martin.lau@linux.dev \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=geliang@kernel.org \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=mptcp@lists.linux.dev \
--cc=mykolal@fb.com \
--cc=sdf@google.com \
--cc=shuah@kernel.org \
--cc=song@kernel.org \
--cc=tanggeliang@kylinos.cn \
--cc=yonghong.song@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox