All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf] selftests/bpf: enable mptcp before testing
@ 2023-02-10  9:32 Hangbin Liu
  2023-02-10 16:22 ` Matthieu Baerts
  0 siblings, 1 reply; 11+ messages in thread
From: Hangbin Liu @ 2023-02-10  9:32 UTC (permalink / raw)
  To: netdev
  Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko, bpf,
	Jakub Kicinski, David S . Miller, Martin KaFai Lau, Song Liu,
	Yonghong Song, John Fastabend, KP Singh, Stanislav Fomichev,
	Hao Luo, Jiri Olsa, Mykola Lysenko, Felix Maurer,
	Nicolas Rybowski, Hangbin Liu

Some distros may not enable mptcp by default. Enable it before start the
mptcp server. To use the {read/write}_int_sysctl() functions, I moved
them to test_progs.c

Fixes: 8039d353217c ("selftests/bpf: Add MPTCP test base")
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
---
 .../testing/selftests/bpf/prog_tests/mptcp.c  | 15 ++++++-
 .../bpf/prog_tests/select_reuseport.c         | 43 -------------------
 tools/testing/selftests/bpf/test_progs.c      | 36 ++++++++++++++++
 tools/testing/selftests/bpf/test_progs.h      |  9 ++++
 4 files changed, 59 insertions(+), 44 deletions(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing/selftests/bpf/prog_tests/mptcp.c
index 59f08d6d1d53..c0a0ee7abd06 100644
--- a/tools/testing/selftests/bpf/prog_tests/mptcp.c
+++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c
@@ -11,6 +11,8 @@
 #define TCP_CA_NAME_MAX	16
 #endif
 
+#define MPTCP_ENABLED_SYSCTL "/proc/sys/net/mptcp/enabled"
+
 struct mptcp_storage {
 	__u32 invoked;
 	__u32 is_mptcp;
@@ -138,7 +140,7 @@ static int run_test(int cgroup_fd, int server_fd, bool is_mptcp)
 
 static void test_base(void)
 {
-	int server_fd, cgroup_fd;
+	int server_fd, cgroup_fd, saved_mptcp_enabled = -1;
 
 	cgroup_fd = test__join_cgroup("/mptcp");
 	if (!ASSERT_GE(cgroup_fd, 0, "test__join_cgroup"))
@@ -155,6 +157,14 @@ static void test_base(void)
 
 with_mptcp:
 	/* with MPTCP */
+	saved_mptcp_enabled = read_int_sysctl(MPTCP_ENABLED_SYSCTL);
+	if (saved_mptcp_enabled < 0)
+		goto close_cgroup_fd;
+
+	if (saved_mptcp_enabled == 0 &&
+	    write_int_sysctl(MPTCP_ENABLED_SYSCTL, 1))
+		goto close_cgroup_fd;
+
 	server_fd = start_mptcp_server(AF_INET, NULL, 0, 0);
 	if (!ASSERT_GE(server_fd, 0, "start_mptcp_server"))
 		goto close_cgroup_fd;
@@ -164,6 +174,9 @@ static void test_base(void)
 	close(server_fd);
 
 close_cgroup_fd:
+	if (saved_mptcp_enabled == 0)
+		write_int_sysctl(MPTCP_ENABLED_SYSCTL, saved_mptcp_enabled);
+
 	close(cgroup_fd);
 }
 
diff --git a/tools/testing/selftests/bpf/prog_tests/select_reuseport.c b/tools/testing/selftests/bpf/prog_tests/select_reuseport.c
index 64c5f5eb2994..cdf9dd626877 100644
--- a/tools/testing/selftests/bpf/prog_tests/select_reuseport.c
+++ b/tools/testing/selftests/bpf/prog_tests/select_reuseport.c
@@ -56,13 +56,6 @@ static union sa46 {
 	}								\
 })
 
-#define RET_ERR(condition, tag, format...) ({				\
-	if (CHECK_FAIL(condition)) {					\
-		printf(tag " " format);					\
-		return -1;						\
-	}								\
-})
-
 static int create_maps(enum bpf_map_type inner_type)
 {
 	LIBBPF_OPTS(bpf_map_create_opts, opts);
@@ -157,42 +150,6 @@ static void sa46_init_inany(union sa46 *sa, sa_family_t family)
 		sa->v4.sin_addr.s_addr = INADDR_ANY;
 }
 
-static int read_int_sysctl(const char *sysctl)
-{
-	char buf[16];
-	int fd, ret;
-
-	fd = open(sysctl, 0);
-	RET_ERR(fd == -1, "open(sysctl)",
-		"sysctl:%s fd:%d errno:%d\n", sysctl, fd, errno);
-
-	ret = read(fd, buf, sizeof(buf));
-	RET_ERR(ret <= 0, "read(sysctl)",
-		"sysctl:%s ret:%d errno:%d\n", sysctl, ret, errno);
-
-	close(fd);
-	return atoi(buf);
-}
-
-static int write_int_sysctl(const char *sysctl, int v)
-{
-	int fd, ret, size;
-	char buf[16];
-
-	fd = open(sysctl, O_RDWR);
-	RET_ERR(fd == -1, "open(sysctl)",
-		"sysctl:%s fd:%d errno:%d\n", sysctl, fd, errno);
-
-	size = snprintf(buf, sizeof(buf), "%d", v);
-	ret = write(fd, buf, size);
-	RET_ERR(ret != size, "write(sysctl)",
-		"sysctl:%s ret:%d size:%d errno:%d\n",
-		sysctl, ret, size, errno);
-
-	close(fd);
-	return 0;
-}
-
 static void restore_sysctls(void)
 {
 	if (saved_tcp_fo != -1)
diff --git a/tools/testing/selftests/bpf/test_progs.c b/tools/testing/selftests/bpf/test_progs.c
index 4716e38e153a..d50599ccba9a 100644
--- a/tools/testing/selftests/bpf/test_progs.c
+++ b/tools/testing/selftests/bpf/test_progs.c
@@ -967,6 +967,42 @@ int write_sysctl(const char *sysctl, const char *value)
 	return 0;
 }
 
+int read_int_sysctl(const char *sysctl)
+{
+	char buf[16];
+	int fd, ret;
+
+	fd = open(sysctl, 0);
+	RET_ERR(fd == -1, "open(sysctl)",
+		"sysctl:%s fd:%d errno:%d\n", sysctl, fd, errno);
+
+	ret = read(fd, buf, sizeof(buf));
+	RET_ERR(ret <= 0, "read(sysctl)",
+		"sysctl:%s ret:%d errno:%d\n", sysctl, ret, errno);
+
+	close(fd);
+	return atoi(buf);
+}
+
+int write_int_sysctl(const char *sysctl, int v)
+{
+	int fd, ret, size;
+	char buf[16];
+
+	fd = open(sysctl, O_RDWR);
+	RET_ERR(fd == -1, "open(sysctl)",
+		"sysctl:%s fd:%d errno:%d\n", sysctl, fd, errno);
+
+	size = snprintf(buf, sizeof(buf), "%d", v);
+	ret = write(fd, buf, size);
+	RET_ERR(ret != size, "write(sysctl)",
+		"sysctl:%s ret:%d size:%d errno:%d\n",
+		sysctl, ret, size, errno);
+
+	close(fd);
+	return 0;
+}
+
 #define MAX_BACKTRACE_SZ 128
 void crash_handler(int signum)
 {
diff --git a/tools/testing/selftests/bpf/test_progs.h b/tools/testing/selftests/bpf/test_progs.h
index 3f058dfadbaf..1522ea930bf6 100644
--- a/tools/testing/selftests/bpf/test_progs.h
+++ b/tools/testing/selftests/bpf/test_progs.h
@@ -376,6 +376,13 @@ int test__join_cgroup(const char *path);
 	___ok;								\
 })
 
+#define RET_ERR(condition, tag, format...) ({				\
+	if (CHECK_FAIL(condition)) {					\
+		printf(tag " " format);					\
+		return -1;						\
+	}								\
+})
+
 static inline __u64 ptr_to_u64(const void *ptr)
 {
 	return (__u64) (unsigned long) ptr;
@@ -394,6 +401,8 @@ int kern_sync_rcu(void);
 int trigger_module_test_read(int read_sz);
 int trigger_module_test_write(int write_sz);
 int write_sysctl(const char *sysctl, const char *value);
+int read_int_sysctl(const char *sysctl);
+int write_int_sysctl(const char *sysctl, int v);
 
 #ifdef __x86_64__
 #define SYS_NANOSLEEP_KPROBE_NAME "__x64_sys_nanosleep"
-- 
2.38.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH bpf] selftests/bpf: enable mptcp before testing
  2023-02-10  9:32 [PATCH bpf] selftests/bpf: enable mptcp before testing Hangbin Liu
@ 2023-02-10 16:22 ` Matthieu Baerts
  2023-02-13  4:10   ` Hangbin Liu
  0 siblings, 1 reply; 11+ messages in thread
From: Matthieu Baerts @ 2023-02-10 16:22 UTC (permalink / raw)
  To: Hangbin Liu, netdev
  Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko, bpf,
	Jakub Kicinski, David S . Miller, Martin KaFai Lau, Song Liu,
	Yonghong Song, John Fastabend, KP Singh, Stanislav Fomichev,
	Hao Luo, Jiri Olsa, Mykola Lysenko, Felix Maurer,
	Nicolas Rybowski, Davide Caratti

Hi Hangbin Liu,

On 10/02/2023 10:32, Hangbin Liu wrote:
> Some distros may not enable mptcp by default. Enable it before start the
> mptcp server. To use the {read/write}_int_sysctl() functions, I moved
> them to test_progs.c
> 
> Fixes: 8039d353217c ("selftests/bpf: Add MPTCP test base")
> Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
> ---
>  .../testing/selftests/bpf/prog_tests/mptcp.c  | 15 ++++++-

Thank you for the patch!

The modifications linked to MPTCP look good to me.

But I don't think it is needed here: I maybe didn't look properly at
'bpf/test_progs.c' file but I think each program from 'prog_tests'
directory is executed in a dedicated netns, no?

I don't have an environment ready to validate that but if yes, it means
that on a "vanilla" kernel, net.mptcp.enabled sysctl knob should be set
to 1. In this case, this modification would be specific to these distros
patching MPTCP code to disable it by default. It might then be better to
add this patch next to the one disabling MPTCP by default, no? (or
revert it to have MPTCP available by default for the applications asking
for it :) )

Cheers,
Matt
-- 
Tessares | Belgium | Hybrid Access Solutions
www.tessares.net

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH bpf] selftests/bpf: enable mptcp before testing
  2023-02-10 16:22 ` Matthieu Baerts
@ 2023-02-13  4:10   ` Hangbin Liu
  2023-02-13 16:28     ` Matthieu Baerts
  0 siblings, 1 reply; 11+ messages in thread
From: Hangbin Liu @ 2023-02-13  4:10 UTC (permalink / raw)
  To: Matthieu Baerts
  Cc: netdev, Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	bpf, Jakub Kicinski, David S . Miller, Martin KaFai Lau,
	Song Liu, Yonghong Song, John Fastabend, KP Singh,
	Stanislav Fomichev, Hao Luo, Jiri Olsa, Mykola Lysenko,
	Felix Maurer, Nicolas Rybowski, Davide Caratti

On Fri, Feb 10, 2023 at 05:22:24PM +0100, Matthieu Baerts wrote:
> Hi Hangbin Liu,
> 
> On 10/02/2023 10:32, Hangbin Liu wrote:
> > Some distros may not enable mptcp by default. Enable it before start the
> > mptcp server. To use the {read/write}_int_sysctl() functions, I moved
> > them to test_progs.c
> > 
> > Fixes: 8039d353217c ("selftests/bpf: Add MPTCP test base")
> > Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
> > ---
> >  .../testing/selftests/bpf/prog_tests/mptcp.c  | 15 ++++++-
> 
> Thank you for the patch!
> 
> The modifications linked to MPTCP look good to me.
> 
> But I don't think it is needed here: I maybe didn't look properly at
> 'bpf/test_progs.c' file but I think each program from 'prog_tests'
> directory is executed in a dedicated netns, no?
> 
> I don't have an environment ready to validate that but if yes, it means
> that on a "vanilla" kernel, net.mptcp.enabled sysctl knob should be set
> to 1. In this case, this modification would be specific to these distros
> patching MPTCP code to disable it by default. It might then be better to
> add this patch next to the one disabling MPTCP by default, no? (or
> revert it to have MPTCP available by default for the applications asking
> for it :) )

I think this issue looks like the rp_filter setting. The default rp_filter is 0.
But many distros set it to 1 for safety reason. Thus there are some fixes for
the rp_filter setting like this one. e.g.

[Liu@Laptop-X1 net]$ git log --oneline tools/testing/selftests/net | grep rp_filter
f6071e5e3961 selftests/fib_tests: Rework fib_rp_filter_test()
d8e336f77e3b selftests: mptcp: turn rp_filter off on each NIC
e86580235708 selftests: set conf.all.rp_filter=0 in bareudp.sh
1ccd58331f6f selftests: disable rp_filter when testing bareudp
71a0e29e9940 selftests: forwarding: Add missing 'rp_filter' configuration
bcf7ddb0186d selftests: disable rp_filter for icmp_redirect.sh
adb701d6cfa4 selftests: add a test case for rp_filter
42801298386c selftests: forwarding: mirror_gre_nh: Unset rp_filter on host VRF
27a2628b3c24 selftests: forwarding: mirror_gre_vlan_bridge_1q: Unset rp_filter

Thanks
Hangbin

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH bpf] selftests/bpf: enable mptcp before testing
  2023-02-13  4:10   ` Hangbin Liu
@ 2023-02-13 16:28     ` Matthieu Baerts
  2023-02-14  3:11       ` Hangbin Liu
  0 siblings, 1 reply; 11+ messages in thread
From: Matthieu Baerts @ 2023-02-13 16:28 UTC (permalink / raw)
  To: Hangbin Liu
  Cc: netdev, Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	bpf, Jakub Kicinski, David S . Miller, Martin KaFai Lau,
	Song Liu, Yonghong Song, John Fastabend, KP Singh,
	Stanislav Fomichev, Hao Luo, Jiri Olsa, Mykola Lysenko,
	Felix Maurer, Nicolas Rybowski, Davide Caratti

Hi Hangbin Liu,

On 13/02/2023 05:10, Hangbin Liu wrote:
> On Fri, Feb 10, 2023 at 05:22:24PM +0100, Matthieu Baerts wrote:
>> Hi Hangbin Liu,
>>
>> On 10/02/2023 10:32, Hangbin Liu wrote:
>>> Some distros may not enable mptcp by default. Enable it before start the
>>> mptcp server. To use the {read/write}_int_sysctl() functions, I moved
>>> them to test_progs.c
>>>
>>> Fixes: 8039d353217c ("selftests/bpf: Add MPTCP test base")
>>> Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
>>> ---
>>>  .../testing/selftests/bpf/prog_tests/mptcp.c  | 15 ++++++-
>>
>> Thank you for the patch!
>>
>> The modifications linked to MPTCP look good to me.
>>
>> But I don't think it is needed here: I maybe didn't look properly at
>> 'bpf/test_progs.c' file but I think each program from 'prog_tests'
>> directory is executed in a dedicated netns, no?
>>
>> I don't have an environment ready to validate that but if yes, it means
>> that on a "vanilla" kernel, net.mptcp.enabled sysctl knob should be set
>> to 1. In this case, this modification would be specific to these distros
>> patching MPTCP code to disable it by default. It might then be better to
>> add this patch next to the one disabling MPTCP by default, no? (or
>> revert it to have MPTCP available by default for the applications asking
>> for it :) )
> 
> I think this issue looks like the rp_filter setting. The default rp_filter is 0.
> But many distros set it to 1 for safety reason. Thus there are some fixes for
> the rp_filter setting like this one. e.g.

I think we should not compare net.mptcp.enabled with rp_filter because
the latter is a bit particular: the initial value of rp_filter in a
newly created netns is inherited from the "host" (the initial netns). In
this case, it is difficult to predict the value of rp_filter in a new
netns and it makes sense to force it to the expected value.

Here for net.mptcp.enabled, the value should be 1 in a newly created
netns. If not, it means the kernel has been modified. (It was making
sense to disable it when MPTCP was backported to older kernels and
marked as "Tech Preview". Now, I don't think we should recommend distros
to do that and support such modifications in the upstream kernel :) )

But again, I'm not totally against that, I'm just saying that if these
tests are executed in dedicated netns, this modification is not needed
when using a vanilla kernel ;-)

Except if I misunderstood and these tests are not executed in dedicated
netns?

(Note: to reduce the size of the patch, if these tests are correctly
executed in dedicated netns, then you can simply force net.mptcp.enabled
to be set to 1, no need to reset it to the previous value.)

Cheers,
Matt
-- 
Tessares | Belgium | Hybrid Access Solutions
www.tessares.net

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH bpf] selftests/bpf: enable mptcp before testing
  2023-02-13 16:28     ` Matthieu Baerts
@ 2023-02-14  3:11       ` Hangbin Liu
  2023-02-14 19:22         ` Martin KaFai Lau
  0 siblings, 1 reply; 11+ messages in thread
From: Hangbin Liu @ 2023-02-14  3:11 UTC (permalink / raw)
  To: Matthieu Baerts
  Cc: netdev, Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	bpf, Jakub Kicinski, David S . Miller, Martin KaFai Lau,
	Song Liu, Yonghong Song, John Fastabend, KP Singh,
	Stanislav Fomichev, Hao Luo, Jiri Olsa, Mykola Lysenko,
	Felix Maurer, Davide Caratti

On Mon, Feb 13, 2023 at 05:28:19PM +0100, Matthieu Baerts wrote:
> But again, I'm not totally against that, I'm just saying that if these
> tests are executed in dedicated netns, this modification is not needed
> when using a vanilla kernel ;-)
> 
> Except if I misunderstood and these tests are not executed in dedicated
> netns?

I tried on my test machine, it looks the test is executed in init netns.
I modified my patch by setting the net.mptcp.enabled to 1 without setting
it back. You can find the value is changed after testing.

# cat /proc/sys/net/mptcp/enabled
0
# ./test_progs -t mptcp
#127/1   mptcp/base:OK
#127     mptcp:OK
Summary: 1/1 PASSED, 0 SKIPPED, 0 FAILED
# cat /proc/sys/net/mptcp/enabled
1

Thanks
Hangbin

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH bpf] selftests/bpf: enable mptcp before testing
  2023-02-14  3:11       ` Hangbin Liu
@ 2023-02-14 19:22         ` Martin KaFai Lau
  2023-02-15  3:43           ` Hangbin Liu
  0 siblings, 1 reply; 11+ messages in thread
From: Martin KaFai Lau @ 2023-02-14 19:22 UTC (permalink / raw)
  To: Hangbin Liu
  Cc: Matthieu Baerts, netdev, Alexei Starovoitov, Daniel Borkmann,
	Andrii Nakryiko, bpf, Jakub Kicinski, David S . Miller, Song Liu,
	Yonghong Song, John Fastabend, KP Singh, Stanislav Fomichev,
	Hao Luo, Jiri Olsa, Mykola Lysenko, Felix Maurer, Davide Caratti

On 2/13/23 7:11 PM, Hangbin Liu wrote:
> On Mon, Feb 13, 2023 at 05:28:19PM +0100, Matthieu Baerts wrote:
>> But again, I'm not totally against that, I'm just saying that if these
>> tests are executed in dedicated netns, this modification is not needed
>> when using a vanilla kernel ;-)
>>
>> Except if I misunderstood and these tests are not executed in dedicated
>> netns?
> 
> I tried on my test machine, it looks the test is executed in init netns.

The new test is needed to run under its own netns whenever possible. The 
existing mptcp test should be changed to run in its own netns also. Then 
changing any pernet sysctl (eg. mptcp.enabled) is a less concern to other tests. 
You can take a look at how other tests doing it (eg. decap_sanity.c).

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH bpf] selftests/bpf: enable mptcp before testing
  2023-02-14 19:22         ` Martin KaFai Lau
@ 2023-02-15  3:43           ` Hangbin Liu
  2023-02-15  9:58             ` Matthieu Baerts
  0 siblings, 1 reply; 11+ messages in thread
From: Hangbin Liu @ 2023-02-15  3:43 UTC (permalink / raw)
  To: Martin KaFai Lau
  Cc: Matthieu Baerts, netdev, Alexei Starovoitov, Daniel Borkmann,
	Andrii Nakryiko, bpf, Jakub Kicinski, David S . Miller, Song Liu,
	Yonghong Song, John Fastabend, KP Singh, Stanislav Fomichev,
	Hao Luo, Jiri Olsa, Mykola Lysenko, Felix Maurer, Davide Caratti

On Tue, Feb 14, 2023 at 11:22:58AM -0800, Martin KaFai Lau wrote:
> On 2/13/23 7:11 PM, Hangbin Liu wrote:
> > On Mon, Feb 13, 2023 at 05:28:19PM +0100, Matthieu Baerts wrote:
> > > But again, I'm not totally against that, I'm just saying that if these
> > > tests are executed in dedicated netns, this modification is not needed
> > > when using a vanilla kernel ;-)
> > > 
> > > Except if I misunderstood and these tests are not executed in dedicated
> > > netns?
> > 
> > I tried on my test machine, it looks the test is executed in init netns.
> 
> The new test is needed to run under its own netns whenever possible. The
> existing mptcp test should be changed to run in its own netns also. Then
> changing any pernet sysctl (eg. mptcp.enabled) is a less concern to other
> tests. You can take a look at how other tests doing it (eg. decap_sanity.c).

Thanks for the reference. I will update the patch to make mptcp run in it's
own netns.

Hangbin

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH bpf] selftests/bpf: enable mptcp before testing
  2023-02-15  3:43           ` Hangbin Liu
@ 2023-02-15  9:58             ` Matthieu Baerts
  2023-02-16  8:13               ` Hangbin Liu
  0 siblings, 1 reply; 11+ messages in thread
From: Matthieu Baerts @ 2023-02-15  9:58 UTC (permalink / raw)
  To: Hangbin Liu, Martin KaFai Lau
  Cc: netdev, Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	bpf, Jakub Kicinski, David S . Miller, Song Liu, Yonghong Song,
	John Fastabend, KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa,
	Mykola Lysenko, Felix Maurer, Davide Caratti

Hi Hangbin, Martin,

On 15/02/2023 04:43, Hangbin Liu wrote:
> On Tue, Feb 14, 2023 at 11:22:58AM -0800, Martin KaFai Lau wrote:
>> On 2/13/23 7:11 PM, Hangbin Liu wrote:
>>> On Mon, Feb 13, 2023 at 05:28:19PM +0100, Matthieu Baerts wrote:
>>>> But again, I'm not totally against that, I'm just saying that if these
>>>> tests are executed in dedicated netns, this modification is not needed
>>>> when using a vanilla kernel ;-)
>>>>
>>>> Except if I misunderstood and these tests are not executed in dedicated
>>>> netns?
>>>
>>> I tried on my test machine, it looks the test is executed in init netns.
>>
>> The new test is needed to run under its own netns whenever possible. The
>> existing mptcp test should be changed to run in its own netns also. Then
>> changing any pernet sysctl (eg. mptcp.enabled) is a less concern to other
>> tests. You can take a look at how other tests doing it (eg. decap_sanity.c).
> 
> Thanks for the reference. I will update the patch to make mptcp run in it's
> own netns.

Thank you both for your replies!

Yes, that would be good to have this test running in a dedicated NS.

Then mptcp.enabled can be forced using write_sysctl() or SYS("sysctl (...)".

Cheers,
Matt
-- 
Tessares | Belgium | Hybrid Access Solutions
www.tessares.net

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH bpf] selftests/bpf: enable mptcp before testing
  2023-02-15  9:58             ` Matthieu Baerts
@ 2023-02-16  8:13               ` Hangbin Liu
  2023-02-17  7:04                 ` Martin KaFai Lau
  0 siblings, 1 reply; 11+ messages in thread
From: Hangbin Liu @ 2023-02-16  8:13 UTC (permalink / raw)
  To: Matthieu Baerts
  Cc: Martin KaFai Lau, netdev, Alexei Starovoitov, Daniel Borkmann,
	Andrii Nakryiko, bpf, Jakub Kicinski, David S . Miller, Song Liu,
	Yonghong Song, John Fastabend, KP Singh, Stanislav Fomichev,
	Hao Luo, Jiri Olsa, Mykola Lysenko, Felix Maurer, Davide Caratti

On Wed, Feb 15, 2023 at 10:58:20AM +0100, Matthieu Baerts wrote:
> Hi Hangbin, Martin,
>
> Thank you both for your replies!
> 
> Yes, that would be good to have this test running in a dedicated NS.
> 
> Then mptcp.enabled can be forced using write_sysctl() or SYS("sysctl (...)".
> 

Hi Matt, Martin,

I tried to set make mptcp test in netns, like decap_sanity.c does. But I got
error when delete the netns. e.g.

# ./test_progs -t mptcp
Cannot remove namespace file "/var/run/netns/mptcp_ns": Device or resource busy
#127/1   mptcp/base:OK
#127     mptcp:OK
Summary: 1/1 PASSED, 0 SKIPPED, 0 FAILED

Do you have any idea why I can't remove the netns? Here is the draft patch:

diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing/selftests/bpf/prog_tests/mptcp.c
index 59f08d6d1d53..5ad10a860994 100644
--- a/tools/testing/selftests/bpf/prog_tests/mptcp.c
+++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c
@@ -7,6 +7,16 @@
 #include "network_helpers.h"
 #include "mptcp_sock.skel.h"
 
+#define SYS(fmt, ...)						\
+	({							\
+		char cmd[1024];					\
+		snprintf(cmd, sizeof(cmd), fmt, ##__VA_ARGS__);	\
+		if (!ASSERT_OK(system(cmd), cmd))		\
+			goto fail;				\
+	})
+
+#define NS_TEST "mptcp_ns"
+
 #ifndef TCP_CA_NAME_MAX
 #define TCP_CA_NAME_MAX	16
 #endif
@@ -169,6 +179,22 @@ static void test_base(void)
 
 void test_mptcp(void)
 {
+	struct nstoken *nstoken = NULL;
+
+	SYS("ip netns add %s", NS_TEST);
+	SYS("ip -net %s link set dev lo up", NS_TEST);
+
+	nstoken = open_netns(NS_TEST);
+	if (!ASSERT_OK_PTR(nstoken, "open_netns"))
+		goto fail;
+
 	if (test__start_subtest("base"))
 		test_base();
+
+fail:
+	if (nstoken)
+		close_netns(nstoken);
+
+	//system("ip netns del " NS_TEST " >& /dev/null");
+	system("ip netns del " NS_TEST);
 }

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH bpf] selftests/bpf: enable mptcp before testing
  2023-02-16  8:13               ` Hangbin Liu
@ 2023-02-17  7:04                 ` Martin KaFai Lau
  2023-02-17  7:35                   ` Hangbin Liu
  0 siblings, 1 reply; 11+ messages in thread
From: Martin KaFai Lau @ 2023-02-17  7:04 UTC (permalink / raw)
  To: Hangbin Liu
  Cc: netdev, Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	bpf, Jakub Kicinski, David S . Miller, Song Liu, Yonghong Song,
	John Fastabend, KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa,
	Mykola Lysenko, Felix Maurer, Davide Caratti, Matthieu Baerts

On 2/16/23 12:13 AM, Hangbin Liu wrote:
> On Wed, Feb 15, 2023 at 10:58:20AM +0100, Matthieu Baerts wrote:
>> Hi Hangbin, Martin,
>>
>> Thank you both for your replies!
>>
>> Yes, that would be good to have this test running in a dedicated NS.
>>
>> Then mptcp.enabled can be forced using write_sysctl() or SYS("sysctl (...)".
>>
> 
> Hi Matt, Martin,
> 
> I tried to set make mptcp test in netns, like decap_sanity.c does. But I got
> error when delete the netns. e.g.
> 
> # ./test_progs -t mptcp
> Cannot remove namespace file "/var/run/netns/mptcp_ns": Device or resource busy

Could you try to create and delete netns after test__join_cgroup()?


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH bpf] selftests/bpf: enable mptcp before testing
  2023-02-17  7:04                 ` Martin KaFai Lau
@ 2023-02-17  7:35                   ` Hangbin Liu
  0 siblings, 0 replies; 11+ messages in thread
From: Hangbin Liu @ 2023-02-17  7:35 UTC (permalink / raw)
  To: Martin KaFai Lau; +Cc: netdev

On Thu, Feb 16, 2023 at 11:04:33PM -0800, Martin KaFai Lau wrote:
> > Hi Matt, Martin,
> > 
> > I tried to set make mptcp test in netns, like decap_sanity.c does. But I got
> > error when delete the netns. e.g.
> > 
> > # ./test_progs -t mptcp
> > Cannot remove namespace file "/var/run/netns/mptcp_ns": Device or resource busy
> 
> Could you try to create and delete netns after test__join_cgroup()?
> 
Thanks a lot. It works now.

Hangbin

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2023-02-17  7:35 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-10  9:32 [PATCH bpf] selftests/bpf: enable mptcp before testing Hangbin Liu
2023-02-10 16:22 ` Matthieu Baerts
2023-02-13  4:10   ` Hangbin Liu
2023-02-13 16:28     ` Matthieu Baerts
2023-02-14  3:11       ` Hangbin Liu
2023-02-14 19:22         ` Martin KaFai Lau
2023-02-15  3:43           ` Hangbin Liu
2023-02-15  9:58             ` Matthieu Baerts
2023-02-16  8:13               ` Hangbin Liu
2023-02-17  7:04                 ` Martin KaFai Lau
2023-02-17  7:35                   ` Hangbin Liu

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.