All of lore.kernel.org
 help / color / mirror / Atom feed
From: Martin KaFai Lau <martin.lau@linux.dev>
To: Jordan Rife <jrife@google.com>, bpf@vger.kernel.org
Cc: linux-kselftest@vger.kernel.org, netdev@vger.kernel.org,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>,
	Eduard Zingerman <eddyz87@gmail.com>, 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>, Mykola Lysenko <mykolal@fb.com>,
	Shuah Khan <shuah@kernel.org>,
	Kui-Feng Lee <thinker.li@gmail.com>,
	Artem Savkov <asavkov@redhat.com>,
	Dave Marchevsky <davemarchevsky@fb.com>,
	Menglong Dong <imagedong@tencent.com>, Daniel Xu <dxu@dxuuu.xyz>,
	David Vernet <void@manifault.com>,
	Daan De Meyer <daan.j.demeyer@gmail.com>,
	Willem de Bruijn <willemdebruijn.kernel@gmail.com>
Subject: Re: [PATCH v2 bpf-next 4/6] selftests/bpf: Add IPv4 and IPv6 sockaddr test cases
Date: Mon, 15 Apr 2024 23:07:19 -0700	[thread overview]
Message-ID: <ce275c37-d45e-451a-985e-e60f8a45ca77@linux.dev> (raw)
In-Reply-To: <20240412165230.2009746-5-jrife@google.com>

On 4/12/24 9:52 AM, Jordan Rife wrote:
> This patch lays the groundwork for testing IPv4 and IPv6 sockaddr hooks
> and their interaction with both socket syscalls and kernel functions
> (e.g. kernel_connect, kernel_bind, etc.) and moves the test cases from
> the old-style bpf/test_sock_addr.c self test into the sock_addr
> prog_test.

Thanks for moving the existing sock_addr test to the test_progs.

> +static int ping_once(int ipv, const char *addr)
> +{
> +	const char *ping_cmd_prefix = "ping -";
> +
> +	if (!SYS_NOFAIL("type ping%d >/dev/null 2>&1", ipv))
> +		ping_cmd_prefix = "ping";
> +
> +	return SYS_NOFAIL("%s%d -q -c 1 -W 1 %s >/dev/null 2>&1",
> +			  ping_cmd_prefix, ipv, addr);
> +}
> +
> +static int setup_test_env(void)
> +{
> +	SYS(err, "ip link add dev %s1 type veth peer name %s2", TEST_IF_PREFIX,
> +	    TEST_IF_PREFIX);

I would like to take this chance to simplify the setup.

Does it need a veth pair? The %s2 interface is not used.

Can it be done in lo alone?

Also, all this setup (and test) has to be done in a new netns. Anything blocking 
the kfunc in patch 2 using the current task netns instead of the init_net?


> +	SYS(err, "ip link set %s1 up", TEST_IF_PREFIX);
> +	SYS(err, "ip link set %s2 up", TEST_IF_PREFIX);
> +	SYS(err, "ip -4 addr add %s/8 dev %s1", TEST_IPV4, TEST_IF_PREFIX);
> +	SYS(err, "ip -6 addr add %s/128 dev %s1", TEST_IPV6, TEST_IF_PREFIX);

Add nodad to the "ip -6 addr add...". just in case it may add unnecessary delay.

> +
> +	int i;
> +
> +	for (i = 0; i < 5; i++) {
> +		if (!ping_once(4, TEST_IPV4) && !ping_once(6, TEST_IPV6))

This interface/address ping should not be needed. Other tests under prog_tests/ 
don't need this interface/address ping also.

> +			return 0;
> +	}
> +
> +	ASSERT_FAIL("Timed out waiting for test IP to become available.");
> +err:
> +	return -1;
> +}
> +
> +static void cleanup_test_env(void)
> +{
> +	SYS_NOFAIL("ip link del %s1 2>/dev/null", TEST_IF_PREFIX);
> +	SYS_NOFAIL("ip link del %s2 2>/dev/null", TEST_IF_PREFIX);

Using lo will make this easier. Regardless, the link should go away with the netns.

> +}
> +
>   void test_sock_addr(void)
>   {
>   	int cgroup_fd = -1;
>   	void *skel;
>   
> +	if (!ASSERT_OK(setup_test_env(), "setup_test_env"))

This will probably have to be called after the test__join_cgroup() if it also 
creates a new netns.

pw-bot: cr

> +		goto cleanup;
> +
>   	cgroup_fd = test__join_cgroup("/sock_addr");
>   	if (!ASSERT_GE(cgroup_fd, 0, "join_cgroup"))
>   		goto cleanup;
> @@ -609,4 +755,5 @@ void test_sock_addr(void)
>   cleanup:
>   	if (cgroup_fd >= 0)
>   		close(cgroup_fd);
> +	cleanup_test_env();
>   }


  reply	other threads:[~2024-04-16  6:07 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-12 16:52 [PATCH v2 bpf-next 0/6] selftests/bpf: Add sockaddr tests for kernel networking Jordan Rife
2024-04-12 16:52 ` [PATCH v2 bpf-next 1/6] selftests/bpf: Fix bind program for big endian systems Jordan Rife
2024-04-13  1:01   ` Kui-Feng Lee
2024-04-13  1:19     ` Jordan Rife
     [not found]     ` <CADKFtnR4qtPV4OP_Y04+ON+bKc8uPxxLZF3cTj-0YCupD6y06A@mail.gmail.com>
2024-04-13  1:28       ` Kui-Feng Lee
2024-04-12 16:52 ` [PATCH v2 bpf-next 2/6] selftests/bpf: Implement socket kfuncs for bpf_testmod Jordan Rife
2024-04-13  1:26   ` Kui-Feng Lee
2024-04-15 15:34     ` Jordan Rife
2024-04-16  6:43   ` Martin KaFai Lau
2024-04-17 16:59     ` Jordan Rife
2024-05-01 21:54       ` Kui-Feng Lee
2024-04-12 16:52 ` [PATCH v2 bpf-next 3/6] selftests/bpf: Implement BPF programs for kernel socket operations Jordan Rife
2024-04-12 16:52 ` [PATCH v2 bpf-next 4/6] selftests/bpf: Add IPv4 and IPv6 sockaddr test cases Jordan Rife
2024-04-16  6:07   ` Martin KaFai Lau [this message]
2024-04-16  6:47   ` Martin KaFai Lau
2024-04-17 17:08     ` Jordan Rife
2024-04-18  0:49       ` Martin KaFai Lau
2024-04-18 16:37         ` Jordan Rife
2024-04-22 21:14           ` Martin KaFai Lau
2024-04-28 17:47             ` Jordan Rife
2024-04-29 17:40               ` Martin KaFai Lau
2024-04-29 21:47                 ` Jordan Rife
2024-04-12 16:52 ` [PATCH v2 bpf-next 5/6] selftests/bpf: Make sock configurable for each test case Jordan Rife
2024-04-12 16:52 ` [PATCH v2 bpf-next 6/6] selftests/bpf: Add kernel socket operation tests Jordan Rife

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=ce275c37-d45e-451a-985e-e60f8a45ca77@linux.dev \
    --to=martin.lau@linux.dev \
    --cc=andrii@kernel.org \
    --cc=asavkov@redhat.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daan.j.demeyer@gmail.com \
    --cc=daniel@iogearbox.net \
    --cc=davemarchevsky@fb.com \
    --cc=dxu@dxuuu.xyz \
    --cc=eddyz87@gmail.com \
    --cc=haoluo@google.com \
    --cc=imagedong@tencent.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=jrife@google.com \
    --cc=kpsingh@kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=mykolal@fb.com \
    --cc=netdev@vger.kernel.org \
    --cc=sdf@google.com \
    --cc=shuah@kernel.org \
    --cc=song@kernel.org \
    --cc=thinker.li@gmail.com \
    --cc=void@manifault.com \
    --cc=willemdebruijn.kernel@gmail.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.