fixes for "new MPTCP subflow subtest v4"
Subsystems (4)
Geliang Tang
reviewerv4 cover fixes for "new MPTCP subflow subtest v4"
From: Geliang Tang <[email protected]>
v4:
- address Matt's comments in v3.
v3:
- drop "ss_search" from subflow subtest
- fix mptcp_for_each_subflow_safe
- add cond_break in list_for_each_entry/_safe
Two fixes address Martin's comments in "new MPTCP subflow subtest" v4. Patch 2 will conflict with "selftests/bpf: Add bpf_first scheduler & test".
Geliang Tang (3):
Squash to "selftests/bpf: Add mptcp subflow example" selftests/bpf: Add getsockopt to inspect mptcp subflow Squash to "selftests/bpf: Add mptcp subflow subtest"
.../testing/selftests/bpf/prog_tests/mptcp.c | 57 +++++++++------- tools/testing/selftests/bpf/progs/mptcp_bpf.h | 35 ++++++++++ .../selftests/bpf/progs/mptcp_subflow.c | 66 ++++++++++++++++++- 3 files changed, 135 insertions(+), 23 deletions(-)
Signature · 1 line
2.43.0
Geliang Tang
reviewerPATCH v4 1/3 Squash to "selftests/bpf: Add mptcp subflow example"
From: Geliang Tang <[email protected]>
For easier verification of cc, set cc of the second subflow as "reno", instead of the first one.
--- tools/testing/selftests/bpf/progs/mptcp_subflow.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/bpf/progs/mptcp_subflow.c +1 -1
@@ -52,7 +52,7 @@ int mptcp_subflow(struct bpf_sock_ops *skops) err =bpf_setsockopt (skops,SOL_SOCKET ,SO_MARK , &mark,sizeof (mark));if (err <0 )return 1 ; -if (mark ==1 ) +if (mark ==2 ) err =bpf_setsockopt (skops,SOL_TCP ,TCP_CONGESTION , cc,TCP_CA_NAME_MAX );return 1 ;
Signature · 1 line
2.43.0
Geliang Tang
reviewerPATCH v4 2/3 selftests/bpf: Add getsockopt to inspect mptcp subflow
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
This patch adds a "cgroup/getsockopt" way to inspect the subflows of a mptcp socket.
mptcp_for_each_stubflow() and other helpers related to list_dentry are added into progs/mptcp_bpf.h.
Add an extra "cgroup/getsockopt" prog to walk the msk->conn_list and use bpf_core_cast to cast a pointer to tcp_sock for readonly. It will allow to inspect all the fields in a tcp_sock.
--- tools/testing/selftests/bpf/progs/mptcp_bpf.h | 35 ++++++++++ .../selftests/bpf/progs/mptcp_subflow.c | 64 +++++++++++++++++++ 2 files changed, 99 insertions(+)
tools/testing/selftests/bpf/progs/mptcp_bpf.h +35 -0
@@ -4,9 +4,44 @@#include <vmlinux.h> #include <bpf/bpf_core_read.h> +#include "bpf_experimental.h" #define MPTCP_SUBFLOWS_MAX 8 +static inline int list_is_head (const struct list_head *list, +const struct list_head *head) +{ +return list == head; +} + +#define list_entry (ptr, type, member) \ + container_of(ptr, type, member) + +#define list_first_entry (ptr, type, member) \ + list_entry((ptr)->next, type, member) + +#define list_next_entry (pos, member) \ + list_entry((pos)->member.next, typeof(*(pos)), member) + +#define list_entry_is_head (pos, head, member) \ + list_is_head(&pos->member, (head)) + +#define list_for_each_entry (pos, head, member) \ + for (pos = list_first_entry(head, typeof(*pos), member); \ + cond_break, !list_entry_is_head(pos, head, member); \ + pos = list_next_entry(pos, member)) + +#define list_for_each_entry_safe (pos, n, head, member) \ + for (pos = list_first_entry(head, typeof(*pos), member), \ + n = list_next_entry(pos, member); \ + cond_break, !list_entry_is_head(pos, head, member); \ + pos = n, n = list_next_entry(n, member)) + +#define mptcp_for_each_subflow (__msk, __subflow) \ + list_for_each_entry(__subflow, &((__msk)->conn_list), node) +#define mptcp_for_each_subflow_safe (__msk, __subflow, __tmp) \ + list_for_each_entry_safe(__subflow, __tmp, &((__msk)->conn_list), node) + extern void mptcp_subflow_set_scheduled(struct mptcp_subflow_context *subflow, bool scheduled) __ksym;
tools/testing/selftests/bpf/progs/mptcp_subflow.c +64 -0
73 lines not on this page · raw message
Signature · 1 line
2.43.0
Geliang Tang
reviewerRe: [PATCH mptcp-next v4 2/3] selftests/bpf: Add getsockopt to inspect mptcp subflow
Hi Matt,
Quoted 106 lines · Geliang Tang
From: Geliang Tang <[email protected]>
This patch adds a "cgroup/getsockopt" way to inspect the subflows of a
mptcp socket.
mptcp_for_each_stubflow()and other helpers related tolist_dentryare
added intoprogs/mptcp_bpf.h.Add an extra "cgroup/getsockopt" prog to walk the
msk->conn_listand usebpf_core_castto cast a pointer totcp_sockfor readonly. It will allow
to inspect all the fields in atcp_sock.Suggested-by Martin KaFai Lau <[email protected]>Signed-off-by Geliang Tang <[email protected]>---
tools/testing/selftests/bpf/progs/mptcp_bpf.h | 35 ++++++++++ .../selftests/bpf/progs/mptcp_subflow.c | 64
+++++++++++++++++++2 files changed, 99 insertions(+)tools/testing/selftests/bpf/progs/mptcp_bpf.h +0
-0@@ -4,9 +4,44 @@
#include <vmlinux.h>
#include <bpf/bpf_core_read.h>
+#include "bpf_experimental.h"
#defineMPTCP_SUBFLOWS_MAX8tools/testing/selftests/bpf/progs/mptcp_bpf.h +7
-0+static inline int list_is_head (const struct list_head *list, + const struct list_head *head) +{ +return list == head; +} + +#define list_entry(ptr, type,member) \
tools/testing/selftests/bpf/progs/mptcp_bpf.h +3
-0+ container_of(ptr, type, member) + +#define list_first_entry(ptr, type,member) \
tools/testing/selftests/bpf/progs/mptcp_bpf.h +3
-0+ list_entry((ptr)->next, type, member) + +#define list_next_entry(pos,member) \
tools/testing/selftests/bpf/progs/mptcp_bpf.h +3
-0+ list_entry((pos)->member.next, typeof(*(pos)), member) + +#define list_entry_is_head(pos, head,member) \
tools/testing/selftests/bpf/progs/mptcp_bpf.h +3
-0+ list_is_head(&pos->member, (head)) + +#define list_for_each_entry(pos, head,member) \
tools/testing/selftests/bpf/progs/mptcp_bpf.h +1
-0+ for (pos = list_first_entry(head, typeof(*pos),member); \
tools/testing/selftests/bpf/progs/mptcp_bpf.h +1
-0+ cond_break, !list_entry_is_head(pos, head,member); \
tools/testing/selftests/bpf/progs/mptcp_bpf.h +3
-0+ pos = list_next_entry(pos, member)) + +#define list_for_each_entry_safe(pos, n, head,member) \
tools/testing/selftests/bpf/progs/mptcp_bpf.h +1
-0+ for (pos = list_first_entry(head, typeof(*pos),member), \
tools/testing/selftests/bpf/progs/mptcp_bpf.h +1
-0+ n = list_next_entry(pos,member); \
tools/testing/selftests/bpf/progs/mptcp_bpf.h +1
-0+ cond_break, !list_entry_is_head(pos, head,member); \
tools/testing/selftests/bpf/progs/mptcp_bpf.h +3
-0+ pos = n, n = list_next_entry(n, member)) + +#define mptcp_for_each_subflow(__msk,
__subflow) \tools/testing/selftests/bpf/progs/mptcp_bpf.h +2
-0+list_for_each_entry (__subflow, &((__msk)->conn_list), node) +#define mptcp_for_each_subflow_safe(__msk, __subflow,
__tmp) \tools/testing/selftests/bpf/progs/mptcp_bpf.h +1
-0+ list_for_each_entry_safe(__subflow, __tmp, &((__msk)-Quoted 1 line
conn_list), node)+
extern void mptcp_subflow_set_scheduled(structmptcp_subflow_context*subflow,
bool scheduled)__ksym;tools/testing/selftests/bpf/progs/mptcp_subflow.c +0
-0@@ -4,6 +4,7 @@
/*vmlinux.h,bpf_helpers.hand other 'define' */ #include "bpf_tracing_net.h"
+#include "mptcp_bpf.h"
char _license[]SEC("license")= "GPL";tools/testing/selftests/bpf/progs/mptcp_subflow.c +0
-0@@ -57,3 +58,66 @@ int mptcp_subflow(struct bpf_sock_ops *skops)
return 1;
}
tools/testing/selftests/bpf/progs/mptcp_subflow.c
Quoted 2 lines
tools/testing/selftests/bpf/progs/mptcp_subflow.c +2
-0+ +static int _check_getsockopt_subflows_mark(struct mptcp_sock *msk,
I prefer to rename this function as _check_getsockopt_subflow_mark. If there's no next iteration version, please help me update this when merging this patch.
Thanks,
-Geliang
Quoted 68 lines
struct
bpf_sockopt*ctx)tools/testing/selftests/bpf/progs/mptcp_subflow.c +9
-0+{ +struct mptcp_subflow_context *subflow; +int *optval = ctx->optval; + +mptcp_for_each_subflow (msk, subflow) { +struct sock *ssk; + + ssk = mptcp_subflow_tcp_sock(bpf_core_cast(subflow, + struct
mptcp_subflow_context));tools/testing/selftests/bpf/progs/mptcp_subflow.c +11
-0+ +if (ctx->optval +sizeof (int ) <= ctx->optval_end) { + *optval = ssk->sk_mark; + ctx->retval =0 ; + } + } + +return 1 ; +} + +static int _check_getsockopt_subflow_cc(struct mptcp_sock *msk,struct
bpf_sockopt*ctx)tools/testing/selftests/bpf/progs/mptcp_subflow.c +10
-0+{ +struct mptcp_subflow_context *subflow, *tmp; +char *optval = ctx->optval; + +mptcp_for_each_subflow_safe (msk, subflow, tmp) { +struct inet_connection_sock *icsk; +struct sock *ssk; + + ssk = mptcp_subflow_tcp_sock(bpf_core_cast(subflow, + struct
mptcp_subflow_context));tools/testing/selftests/bpf/progs/mptcp_subflow.c +1
-0+ icsk = bpf_core_cast(ssk, struct
inet_connection_sock);tools/testing/selftests/bpf/progs/mptcp_subflow.c +2
-0+ + if (ctx->optval + TCP_CA_NAME_MAX <= ctx-Quoted 1 line
optval_end) {tools/testing/selftests/bpf/progs/mptcp_subflow.c +1
-0+ __builtin_memcpy(optval, icsk->icsk_ca_ops-Quoted 1 line
name,
TCP_CA_NAME_MAX);tools/testing/selftests/bpf/progs/mptcp_subflow.c +27
-0+ ctx->retval =0 ; + } + } + +return 1 ; +} + +SEC("cgroup/getsockopt") +int _getsockopt_subflow (struct bpf_sockopt *ctx) +{ +struct bpf_sock *sk = ctx->sk; +struct mptcp_sock *msk; + +if (!sk || sk->protocol !=IPPROTO_MPTCP ) +return 1 ; + + msk = bpf_core_cast(sk, struct mptcp_sock); +if (msk->pm.subflows !=1 ) +return 1 ; + +if (ctx->level ==SOL_SOCKET && ctx->optname ==SO_MARK ) +return _check_getsockopt_subflows_mark (msk, ctx); +if (ctx->level ==SOL_TCP && ctx->optname ==TCP_CONGESTION ) +return _check_getsockopt_subflow_cc (msk, ctx); + +return 1 ; +}
Geliang Tang
reviewerPATCH v4 3/3 Squash to "selftests/bpf: Add mptcp subflow subtest"
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
Drop ss_search() from run_subflow().
Now ss_search() are only used by bpf_sched tests. It will be dropped in next step.
Use the "cgroup/getsockopt" way to inspect the subflows.
--- .../testing/selftests/bpf/prog_tests/mptcp.c | 57 ++++++++++++------- 1 file changed, 35 insertions(+), 22 deletions(-)
tools/testing/selftests/bpf/prog_tests/mptcp.c +35 -22
@@ -368,22 +368,13 @@ static int endpoint_init(char *flags)return -1 ; } -static int _ss_search (char *src,char *dst,char *port,char *keyword) -{ -return SYS_NOFAIL ("ip netns exec %s ss -enita src %s dst %s %s %d | grep -q '%s'" , -NS_TEST , src, dst, port,PORT_1 , keyword); -} - -static int ss_search (char *src,char *keyword) -{ -return _ss_search (src,ADDR_1 ,"dport" , keyword); -} -static void run_subflow (char *new) { -int server_fd, client_fd, err; +int server_fd, client_fd, err, i;char cc[TCP_CA_NAME_MAX ]; +unsigned int mark;socklen_t len; +u8 subflows; server_fd =start_mptcp_server (AF_INET ,ADDR_1 ,PORT_1 ,0 );if (!ASSERT_GE (server_fd,0 ,"start_mptcp_server" ))
@@ -393,17 +384,26 @@ static void run_subflow(char *new)if (!ASSERT_GE (client_fd,0 ,"connect to fd" )) goto close_server; - len =sizeof (cc); - err =getsockopt (server_fd,SOL_TCP ,TCP_CONGESTION , cc, &len); -if (!ASSERT_OK (err,"getsockopt(server_fd, TCP_CONGESTION)" )) - goto close_client; -send_byte (client_fd); -ASSERT_OK (ss_search (ADDR_1 ,"fwmark:0x1" ),"ss_search fwmark:0x1" ); -ASSERT_OK (ss_search (ADDR_2 ,"fwmark:0x2" ),"ss_search fwmark:0x2" ); -ASSERT_OK (ss_search (ADDR_1 , new),"ss_search new cc" ); -ASSERT_OK (ss_search (ADDR_2 , cc),"ss_search default cc" ); + len =sizeof (subflows); +/* Wait max 1 sec for new subflows to be created */ +for (i =0 ; i <10 ; i++) { + err =getsockopt (client_fd,SOL_MPTCP ,MPTCP_INFO , &subflows, &len); +if (!err && subflows >0 ) +break ; + +sleep (0.1 ); + } + + len =sizeof (mark); + err =getsockopt (client_fd,SOL_SOCKET ,SO_MARK , &mark, &len); +if (!ASSERT_OK (err || mark !=2 ,"getsockopt(client_fd, SO_MARK)" )) + goto close_client; + + len =sizeof (cc); + err =getsockopt (client_fd,SOL_TCP ,TCP_CONGESTION , cc, &len); +ASSERT_OK (err ||strcmp (cc, new),"getsockopt(client_fd, TCP_CONGESTION)" ); close_client:close (client_fd);
@@ -416,6 +416,7 @@ static void test_subflow(void)int cgroup_fd, prog_fd, err;struct mptcp_subflow *skel;struct nstoken *nstoken; +struct bpf_link *link; cgroup_fd =test__join_cgroup ("/mptcp_subflow" );if (!ASSERT_GE (cgroup_fd,0 ,"join_cgroup: mptcp_subflow" ))
@@ -441,6 +442,11 @@ static void test_subflow(void)if (endpoint_init ("subflow" ) <0 ) goto close_netns; + link =bpf_program__attach_cgroup (skel->progs._getsockopt_subflow, + cgroup_fd); +if (!ASSERT_OK_PTR (link,"getsockopt prog" )) + goto close_netns; +run_subflow (skel->data->cc); close_netns:
@@ -449,6 +455,7 @@ static void test_subflow(void)mptcp_subflow__destroy (skel); close_cgroup:close (cgroup_fd); +bpf_link__destroy (link); }static struct nstoken *sched_init (char *flags,char *sched)
@@ -470,9 +477,15 @@ static struct nstoken *sched_init(char *flags, char *sched)return NULL ; } +static int ss_search (char *src,char *dst,char *port,char *keyword) +{ +return SYS_NOFAIL ("ip netns exec %s ss -enita src %s dst %s %s %d | grep -q '%s'" , +NS_TEST , src, dst, port,PORT_1 , keyword); +} +static int has_bytes_sent (char *dst) { -return _ss_search (ADDR_1 , dst,"sport" ,"bytes_sent:" ); +return ss_search (ADDR_1 , dst,"sport" ,"bytes_sent:" ); }static void send_data_and_verify (char *sched,bool addr1,bool addr2)
Signature · 1 line
2.43.0
Matthieu Baerts
maintainerRe: [PATCH mptcp-next v4 3/3] Squash to "selftests/bpf: Add mptcp subflow subtest"
Hi Geliang,
Quoted 62 lines · Geliang Tang
From: Geliang Tang <[email protected]>
Drop
ss_search()fromrun_subflow().Now
ss_search()are only used bybpf_schedtests. It will be dropped in next step.Use the "cgroup/getsockopt" way to inspect the subflows.
Signed-off-by Geliang Tang <[email protected]>--- .../testing/selftests/bpf/prog_tests/mptcp.c | 57 ++++++++++++------- 1 file changed, 35 insertions(+), 22 deletions(-)tools/testing/selftests/bpf/prog_tests/mptcp.c +6
-21@@ -368,22 +368,13 @@ static int endpoint_init(char *flags)return -1 ; } -static int _ss_search (char *src,char *dst,char *port,char *keyword) -{ -return SYS_NOFAIL ("ip netns exec %s ss -enita src %s dst %s %s %d | grep -q '%s'" , -NS_TEST , src, dst, port,PORT_1 , keyword); -} - -static int ss_search (char *src,char *keyword) -{ -return _ss_search (src,ADDR_1 ,"dport" , keyword); -} -static void run_subflow (char *new) { -int server_fd, client_fd, err; +int server_fd, client_fd, err, i;char cc[TCP_CA_NAME_MAX ]; +unsigned int mark;socklen_t len; +u8 subflows; server_fd =start_mptcp_server (AF_INET ,ADDR_1 ,PORT_1 ,0 );if (!ASSERT_GE (server_fd,0 ,"start_mptcp_server" ))@@ -393,17 +384,26 @@ static void run_subflow(char *new)if (!ASSERT_GE (client_fd,0 ,"connect to fd" )) goto close_server; - len =sizeof (cc); - err =getsockopt (server_fd,SOL_TCP ,TCP_CONGESTION , cc, &len); -if (!ASSERT_OK (err,"getsockopt(server_fd, TCP_CONGESTION)" )) - goto close_client; -send_byte (client_fd); -ASSERT_OK (ss_search (ADDR_1 ,"fwmark:0x1" ),"ss_search fwmark:0x1" ); -ASSERT_OK (ss_search (ADDR_2 ,"fwmark:0x2" ),"ss_search fwmark:0x2" ); -ASSERT_OK (ss_search (ADDR_1 , new),"ss_search new cc" ); -ASSERT_OK (ss_search (ADDR_2 , cc),"ss_search default cc" ); + len =sizeof (subflows); +/* Wait max 1 sec for new subflows to be created */ +for (i =0 ; i <10 ; i++) {
tools/testing/selftests/bpf/prog_tests/mptcp.c static void run_subflow(char *new) · line 401
Quoted 10 lines
tools/testing/selftests/bpf/prog_tests/mptcp.c +10
-0+ err =getsockopt (client_fd,SOL_MPTCP ,MPTCP_INFO , &subflows, &len); +if (!err && subflows >0 ) +break ; + +sleep (0.1 ); + } + + len =sizeof (mark); + err =getsockopt (client_fd,SOL_SOCKET ,SO_MARK , &mark, &len); +if (!ASSERT_OK (err || mark !=2 ,"getsockopt(client_fd, SO_MARK)" ))
The mark should be 0 on the MPTCP socket, no?
Also, I don't think you can do this check:
err || mark != 2
That will be converted to:
(err || mark != 2) == 0
We need to check there was no error and the mark is 0.
You could use ASSERT_TRUE/ASSERT_FALSE instead, but I think it is better to use two different assert: check 'err' is OK, then check the mark is 0, no?
tools/testing/selftests/bpf/prog_tests/mptcp.c static void run_subflow(char *new) · line 402
Quoted 1 line
tools/testing/selftests/bpf/prog_tests/mptcp.c +1
-0+ goto close_client;
Please see my previous comment on the v3:
It is not needed to stop earlier here, we should check everything we can to give more info about the issue:
err = getsockopt(client_fd, SOL_SOCKET, SO_MARK, &mark, &len); ASSERT_OK(err, "getsockopt(client_fd, SO_MARK)"); ASSERT_EQ(mark, 0, "mark"); err = getsockopt(client_fd, SOL_TCP, TCP_CONGESTION, cc, &len); ASSERT_OK(err, "getsockopt(client_fd, TCP_CONGESTION)"); ASSERT_STREQ(new, cc, "cc");
tools/testing/selftests/bpf/prog_tests/mptcp.c static void run_subflow(char *new) · line 406
Quoted 4 lines
tools/testing/selftests/bpf/prog_tests/mptcp.c +4
-0+ + len =sizeof (cc); + err =getsockopt (client_fd,SOL_TCP ,TCP_CONGESTION , cc, &len); +ASSERT_OK (err ||strcmp (cc, new),"getsockopt(client_fd, TCP_CONGESTION)" );
(See above)
But after your modification in patch 1/3, 'cc' should be equal to '/proc/sys/net/ipv4/tcp_congestion_control' (not 'new'). So you need to get the value of the default CC first, then compare it to 'cc'. It should be different from 'new' (except if 'new' == default cc from /proc, so maybe enough to compare that 'cc' is the same as the default one).
Quoted 24 lines
tools/testing/selftests/bpf/prog_tests/mptcp.c +6
-0close_client:close (client_fd);@@ -416,6 +416,7 @@ static void test_subflow(void)int cgroup_fd, prog_fd, err;struct mptcp_subflow *skel;struct nstoken *nstoken; +struct bpf_link *link; cgroup_fd =test__join_cgroup ("/mptcp_subflow" );if (!ASSERT_GE (cgroup_fd,0 ,"join_cgroup: mptcp_subflow" ))@@ -441,6 +442,11 @@ static void test_subflow(void)if (endpoint_init ("subflow" ) <0 ) goto close_netns; + link =bpf_program__attach_cgroup (skel->progs._getsockopt_subflow, + cgroup_fd); +if (!ASSERT_OK_PTR (link,"getsockopt prog" )) + goto close_netns; +run_subflow (skel->data->cc); close_netns:
tools/testing/selftests/bpf/prog_tests/mptcp.c static void test_subflow(void) · line 458
Quoted 4 lines
tools/testing/selftests/bpf/prog_tests/mptcp.c +1
-0@@ -449,6 +455,7 @@ static void test_subflow(void)mptcp_subflow__destroy (skel); close_cgroup:close (cgroup_fd); +bpf_link__destroy (link);
That should be done just before 'close_netns' label, otherwise this will be called with 'link' that has not been defined.
tools/testing/selftests/bpf/prog_tests/mptcp.c static struct nstoken *sched_init(char *flags, char *sched) · line 480
Quoted 8 lines
tools/testing/selftests/bpf/prog_tests/mptcp.c +1
-0}static struct nstoken *sched_init (char *flags,char *sched)@@ -470,9 +477,15 @@ static struct nstoken *sched_init(char *flags, char *sched)return NULL ; } +static int ss_search (char *src,char *dst,char *port,char *keyword)
I guess this part should not be squashed in "selftests/bpf: Add mptcp subflow subtest", but in a different patch ("selftests/bpf: Add bpf scheduler test"), no?
If yes, and if you need to send a new version, please split that in a separated patch, otherwise I might forget and apply this in "selftests/bpf: Add mptcp subflow subtest" instead.
tools/testing/selftests/bpf/prog_tests/mptcp.c static struct nstoken *sched_init(char *flags, char *sched) · line 491
Quoted 12 lines
tools/testing/selftests/bpf/prog_tests/mptcp.c +6
-1+{ +return SYS_NOFAIL ("ip netns exec %s ss -enita src %s dst %s %s %d | grep -q '%s'" , +NS_TEST , src, dst, port,PORT_1 , keyword); +} +static int has_bytes_sent (char *dst) { -return _ss_search (ADDR_1 , dst,"sport" ,"bytes_sent:" ); +return ss_search (ADDR_1 , dst,"sport" ,"bytes_sent:" ); }static void send_data_and_verify (char *sched,bool addr1,bool addr2)
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Geliang Tang
reviewerRe: [PATCH mptcp-next v4 3/3] Squash to "selftests/bpf: Add mptcp subflow subtest"
Hi Matt,
Thanks for the review.
Quoted 78 lines · Matthieu Baerts
Hi Geliang,
Quoted 75 lines · Geliang Tang
From: Geliang Tang <[email protected]>
Drop
ss_search()fromrun_subflow().Now
ss_search()are only used bybpf_schedtests. It will be dropped
in next step.Use the "cgroup/getsockopt" way to inspect the subflows.
Signed-off-by Geliang Tang <[email protected]>---
.../testing/selftests/bpf/prog_tests/mptcp.c | 57 ++++++++++++---
----1 file changed, 35 insertions(+), 22 deletions(-)tools/testing/selftests/bpf/prog_tests/mptcp.c +0
-0@@ -368,22 +368,13 @@ static int endpoint_init(char *flags) return -1; }
-static int_ss_search(char *src, char *dst, char *port, char *keyword)
-{
- return SYS_NOFAIL("ip netns exec %s ss -enita src %s dst %s %s %d | grep -q '%s'",
-NS_TEST, src, dst, port,PORT_1, keyword);tools/testing/selftests/bpf/prog_tests/mptcp.c +0
-7-} - -static int ss_search (char *src,char *keyword) -{ -return _ss_search (src,ADDR_1 ,"dport" , keyword); -} -static void
run_subflow(char *new)
{
- intserver_fd,client_fd, err;
+ intserver_fd,client_fd, err, i;
char cc[TCP_CA_NAME_MAX];
+ unsigned int mark;
socklen_tlen;
+ u8 subflows;
server_fd=start_mptcp_server(AF_INET, ADDR_1, PORT_1, 0); if (!ASSERT_GE(server_fd, 0, "start_mptcp_server"))tools/testing/selftests/bpf/prog_tests/mptcp.c +0
-0@@ -393,17 +384,26 @@ static void run_subflow(char *new) if (!ASSERT_GE(client_fd, 0, "connect to fd")) goto close_server;
- len = sizeof(cc);
- err =getsockopt(server_fd, SOL_TCP, TCP_CONGESTION, cc, &len);
- if (!ASSERT_OK(err, "getsockopt(server_fd, TCP_CONGESTION)"))
- gotoclose_client;
-
send_byte(client_fd);
-ASSERT_OK(ss_search(ADDR_1, "fwmark:0x1"), "ss_search fwmark:0x1");
-ASSERT_OK(ss_search(ADDR_2, "fwmark:0x2"), "ss_search fwmark:0x2");
-ASSERT_OK(ss_search(ADDR_1, new), "ss_search new cc");
-ASSERT_OK(ss_search(ADDR_2, cc), "ss_search default cc");
+ len = sizeof(subflows);
+ /* Wait max 1 sec for new subflows to be created */
+ for (i = 0; i < 10; i++) {
+ err =getsockopt(client_fd, SOL_MPTCP, MPTCP_INFO, &subflows, &len);
+ if (!err && subflows > 0)
+ break;
+
+ sleep(0.1);
Quoted 8 lines
Quoted 6 lines
+ }
+
+ len = sizeof(mark);
+ err =getsockopt(client_fd, SOL_SOCKET, SO_MARK, &mark, &len);
+ if (!ASSERT_OK(err || mark != 2, "getsockopt(client_fd, SO_MARK)"))The mark should be 0 on the MPTCP socket, no?
optval is modified in _check_getsockopt_subflows_mark(), so the mark is 2 now.
Quoted 9 lines
Also, I don't think you can do this check:
err || mark != 2
That will be converted to:
(err || mark != 2) == 0
Quoted 7 lines
We need to check there was no error and the mark is 0.
You could use ASSERT_TRUE/ASSERT_FALSE instead, but I think it is better
to use two different assert: check 'err' is OK, then check the mark is
0, no?
Will update in v5.
Quoted 26 lines
Quoted 3 lines
+ goto
close_client;Please see my previous comment on the v3:
It is not needed to stop earlier here, we should check everything we can
to give more info about the issue:err =
getsockopt(client_fd, SOL_SOCKET, SO_MARK, &mark, &len);ASSERT_OK(err, "getsockopt(client_fd, SO_MARK)");ASSERT_EQ(mark, 0, "mark");err =
getsockopt(client_fd, SOL_TCP, TCP_CONGESTION, cc, &len);ASSERT_OK(err, "getsockopt(client_fd, TCP_CONGESTION)");ASSERT_STREQ(new, cc, "cc");Quoted 5 lines
+
+ len = sizeof(cc);
+ err =getsockopt(client_fd, SOL_TCP, TCP_CONGESTION, cc, &len);
+ASSERT_OK(err || strcmp(cc, new), "getsockopt(client_fd, TCP_CONGESTION)");(See above)
Quoted 7 lines
But after your modification in patch 1/3, 'cc' should be equal to '
/proc/sys/net/ipv4/tcp_congestion_control' (not 'new'). So you need to
get the value of the default CC first, then compare it to 'cc'. It should be different from 'new' (except if 'new' == default cc from /proc, so maybe enough to compare that 'cc' is the same as the default one).
optval is modified in _check_getsockopt_subflow_cc(), so 'cc' is equal to 'new' now.
Quoted 18 lines
Quoted 18 lines
close_client:
close(client_fd);tools/testing/selftests/bpf/prog_tests/mptcp.c +1
-0@@ -416,6 +416,7 @@ static void test_subflow(void) int cgroup_fd, prog_fd, err; struct mptcp_subflow *skel; struct nstoken *nstoken; +struct bpf_link *link;
cgroup_fd=test__join_cgroup("/mptcp_subflow"); if (!ASSERT_GE(cgroup_fd, 0, "join_cgroup:mptcp_subflow"))tools/testing/selftests/bpf/prog_tests/mptcp.c +0
-0@@ -441,6 +442,11 @@ static void test_subflow(void) if (endpoint_init("subflow") < 0) goto close_netns;
+ link = bpf_program__attach_cgroup(skel-Quoted 1 line
progs._getsockopt_subflow,
Quoted 16 lines
Quoted 9 lines
+
cgroup_fd);
+ if (!ASSERT_OK_PTR(link, "getsockopt prog"))
+ gotoclose_netns;
+
run_subflow(skel->data->cc);
close_netns:tools/testing/selftests/bpf/prog_tests/mptcp.c +0
-0@@ -449,6 +455,7 @@ static void test_subflow(void) mptcp_subflow__destroy(skel);Quoted 3 lines
close_cgroup:
close(cgroup_fd);
+bpf_link__destroy(link);That should be done just before '
close_netns' label, otherwise this will
be called with 'link' that has not been defined.
Good catch, will update in v5.
Quoted 15 lines
Quoted 11 lines
}
static struct nstoken *sched_init(char *flags, char *sched)tools/testing/selftests/bpf/prog_tests/mptcp.c +0
-0@@ -470,9 +477,15 @@ static struct nstoken *sched_init(char *flags, char *sched) return NULL; }
+static intss_search(char *src, char *dst, char *port, char *keyword)I guess this part should not be squashed in "selftests/bpf: Add mptcp subflow subtest", but in a different patch ("selftests/bpf: Add bpf scheduler test"), no?
Yes, it's for a different patch.
Quoted 4 lines
If yes, and if you need to send a new version, please split that in a separated patch, otherwise I might forget and apply this in "selftests/bpf: Add mptcp subflow subtest" instead.
Sure, will update in v5.
Thanks,
-Geliang
Quoted 18 lines
Quoted 7 lines
+{
+ return SYS_NOFAIL("ip netns exec %s ss -enita src %s dst %s %s %d | grep -q '%s'",
+NS_TEST, src, dst, port,PORT_1, keyword);tools/testing/selftests/bpf/prog_tests/mptcp.c +2
-0+} +Quoted 8 lines
static int
has_bytes_sent(char *dst)
{
- return_ss_search(ADDR_1, dst, "sport", "bytes_sent:");
+ returnss_search(ADDR_1, dst, "sport", "bytes_sent:"); }
static voidsend_data_and_verify(char *sched, bool addr1, bool addr2)Cheers,
Matt
Matthieu Baerts
maintainerRe: [PATCH mptcp-next v4 3/3] Squash to "selftests/bpf: Add mptcp subflow subtest"
Hi Geliang,
Thank you for your reply.
Quoted 30 lines · Geliang Tang
Hi Matt,
Thanks for the review.
Quoted 25 lines · Matthieu Baerts
Hi Geliang,
Quoted 22 lines · Geliang Tang
From: Geliang Tang <[email protected]>
Drop
ss_search()fromrun_subflow().Now
ss_search()are only used bybpf_schedtests. It will be dropped
in next step.Use the "cgroup/getsockopt" way to inspect the subflows.
Signed-off-by Geliang Tang <[email protected]>---
.../testing/selftests/bpf/prog_tests/mptcp.c | 57 ++++++++++++---
----1 file changed, 35 insertions(+), 22 deletions(-)tools/testing/selftests/bpf/prog_tests/mptcp.c +0
-0@@ -368,22 +368,13 @@ static int endpoint_init(char *flags)
(...)
Quoted 9 lines
Quoted 6 lines
Quoted 4 lines
+ len = sizeof(mark);
+ err =getsockopt(client_fd, SOL_SOCKET, SO_MARK, &mark, &len);
+ if (!ASSERT_OK(err || mark != 2, "getsockopt(client_fd, SO_MARK)"))The mark should be 0 on the MPTCP socket, no?
optval is modified in
_check_getsockopt_subflows_mark(), so the mark is 2 now.
Mmh, I missed that. I don't think a helper called 'check_xxx()' should modify anything.
Would it not be better to have ...
_check_getsockopt_subflows_mark()
... making sure the first subflow has the mark 1, and the other one, the mark 2? (if we add items at the end of the list)
(...)
Quoted 15 lines
Quoted 7 lines
Quoted 4 lines
+ len = sizeof(cc);
+ err =getsockopt(client_fd, SOL_TCP, TCP_CONGESTION, cc, &len);
+ASSERT_OK(err || strcmp(cc, new), "getsockopt(client_fd, TCP_CONGESTION)");(See above)
Quoted 7 lines
But after your modification in patch 1/3, 'cc' should be equal to '
/proc/sys/net/ipv4/tcp_congestion_control' (not 'new'). So you need to
get the value of the default CC first, then compare it to 'cc'. It should be different from 'new' (except if 'new' == default cc from /proc, so maybe enough to compare that 'cc' is the same as the default one).
Quoted 2 lines
optval is modified in
_check_getsockopt_subflow_cc(), so 'cc' is equal to 'new' now.
Same here:
_check_getsockopt_subflow_cc()
... can check that the subflow with the mark 2 has the congestion control algorithm is set to 'cc' (reno).
By doing that, you would have the BPF program setting the different socket options when the subflows are created, and later checking that they have been set properly when a 'getsockopt()' is called. The userspace here will check that the values for the MPTCP sockets have the default values as expected: the BPF program has only modified the subflow options, not the ones from the MPTCP socket.
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Geliang Tang
reviewerRe: [PATCH mptcp-next v4 3/3] Squash to "selftests/bpf: Add mptcp subflow subtest"
Hi Matt,
Quoted 47 lines · Matthieu Baerts
Hi Geliang,
Thank you for your reply.
Quoted 31 lines · Geliang Tang
Hi Matt,
Thanks for the review.
Quoted 26 lines · Matthieu Baerts
Hi Geliang,
Quoted 23 lines · Geliang Tang
From: Geliang Tang <[email protected]>
Drop
ss_search()fromrun_subflow().Now
ss_search()are only used bybpf_schedtests. It will be dropped
in next step.Use the "cgroup/getsockopt" way to inspect the subflows.
Signed-off-by Geliang Tang <[email protected]>---
.../testing/selftests/bpf/prog_tests/mptcp.c | 57
++++++++++++---
----1 file changed, 35 insertions(+), 22 deletions(-)tools/testing/selftests/bpf/prog_tests/mptcp.c +0
-0@@ -368,22 +368,13 @@ static int endpoint_init(char *flags)(...)
Quoted 8 lines
Quoted 7 lines
Quoted 5 lines
+ len = sizeof(mark);
+ err =getsockopt(client_fd, SOL_SOCKET, SO_MARK, &mark, &len);
+ if (!ASSERT_OK(err || mark != 2, "getsockopt(client_fd, SO_MARK)"))The mark should be 0 on the MPTCP socket, no?
Quoted 7 lines
Quoted 3 lines
optval is modified in
_check_getsockopt_subflows_mark(), so the mark is
2 now.Mmh, I missed that. I don't think a helper called '
check_xxx()' should
modify anything.
We can rename _check_getsockopt_subflow_mark/_cc to _getsockopt_subflow_mark/_cc to make their names match.
Quoted 8 lines
Would it not be better to have ...
_check_getsockopt_subflows_mark()... making sure the first subflow has the mark 1, and the other one, the
mark 2? (if we add items at the end of the list)
No, this is what v3 do. I think this v4 is much better than v3.
I didn't find a way to return a string type optval to getsockopt() in v3, so I had to do the mark/cc checks in _check_getsockopt_subflow_mark/_cc. I finally found a way to do this, so I used it in v4.
It's strange that v3 sets mark/cc in the BPF program and checks mark/cc in the BPF program too.
v4 is much better, it sets mark/cc in the BPF program, use getsockopt() to get mark/cc in user space in prog_tests/mptcp.c and do the checks in user space too.
Thanks,
-Geliang
Quoted 43 lines
(...)
Quoted 19 lines
Quoted 8 lines
Quoted 5 lines
+ len = sizeof(cc);
+ err =getsockopt(client_fd, SOL_TCP, TCP_CONGESTION, cc, &len);
+ASSERT_OK(err || strcmp(cc, new), "getsockopt(client_fd, TCP_CONGESTION)");(See above)
Quoted 10 lines
But after your modification in patch 1/3, 'cc' should be equal to '
/proc/sys/net/ipv4/tcp_congestion_control' (not 'new'). So you need
to
get the value of the default CC first, then compare it to 'cc'. It
should be different from 'new' (except if 'new' == default cc from
/proc, so maybe enough to compare that 'cc' is the same as the default one).Quoted 3 lines
optval is modified in
_check_getsockopt_subflow_cc(), so 'cc' is equal
to 'new' now.Same here:
_check_getsockopt_subflow_cc()... can check that the subflow with the mark 2 has the congestion control algorithm is set to 'cc' (reno).
By doing that, you would have the BPF program setting the different socket options when the subflows are created, and later checking that they have been set properly when a '
getsockopt()' is called. The userspace here will check that the values for the MPTCP sockets have
the default values as expected: the BPF program has only modified the subflow options, not the ones from the MPTCP socket.Cheers,
Matt
Matthieu Baerts
maintainerRe: [PATCH mptcp-next v4 3/3] Squash to "selftests/bpf: Add mptcp subflow subtest"
Hi Geliang,
Quoted 54 lines · Geliang Tang
Hi Matt,
Quoted 51 lines · Matthieu Baerts
Hi Geliang,
Thank you for your reply.
Quoted 31 lines · Geliang Tang
Hi Matt,
Thanks for the review.
Quoted 26 lines · Matthieu Baerts
Hi Geliang,
Quoted 23 lines · Geliang Tang
From: Geliang Tang <[email protected]>
Drop
ss_search()fromrun_subflow().Now
ss_search()are only used bybpf_schedtests. It will be dropped
in next step.Use the "cgroup/getsockopt" way to inspect the subflows.
Signed-off-by Geliang Tang <[email protected]>---
.../testing/selftests/bpf/prog_tests/mptcp.c | 57
++++++++++++---
----1 file changed, 35 insertions(+), 22 deletions(-)tools/testing/selftests/bpf/prog_tests/mptcp.c +0
-0@@ -368,22 +368,13 @@ static int endpoint_init(char *flags)(...)
Quoted 11 lines
Quoted 7 lines
Quoted 5 lines
+ len = sizeof(mark);
+ err =getsockopt(client_fd, SOL_SOCKET, SO_MARK, &mark, &len);
+ if (!ASSERT_OK(err || mark != 2, "getsockopt(client_fd, SO_MARK)"))The mark should be 0 on the MPTCP socket, no?
optval is modified in
_check_getsockopt_subflows_mark(), so the mark is
2 now.
Quoted 6 lines
Quoted 3 lines
Mmh, I missed that. I don't think a helper called '
check_xxx()' should
modify anything.We can rename _check_getsockopt_subflow_mark/_cc to _getsockopt_subflow_mark/_cc to make their names match.
I don't know: to me, it is still strange to have the validation part modifying output. It could then hide thing.
Quoted 16 lines
Quoted 8 lines
Would it not be better to have ...
_check_getsockopt_subflows_mark()... making sure the first subflow has the mark 1, and the other one, the
mark 2? (if we add items at the end of the list)No, this is what v3 do. I think this v4 is much better than v3.
I didn't find a way to return a string type optval to
getsockopt()in v3, so I had to do the mark/cc checks in _check_getsockopt_subflow_mark/_cc. I finally found a way to do this, so I used it in v4.
Quoted 6 lines
It's strange that v3 sets mark/cc in the BPF program and checks mark/cc in the BPF program too.
v4 is much better, it sets mark/cc in the BPF program, use
getsockopt()to get mark/cc in user space inprog_tests/mptcp.cand do the checks in user space too.
I don't know as well: I understand that the v4 is doing more operations in BPF, but it still does not check the MPTCP socket option, only the ones of the subflows. Also, the userspace, and the BPF programs are now validating the same thing: the options have been changed on the subflows, but is it really needed to do the same validation twice?
The idea being Nicolas' BPF program is to show that it is possible to set socket options per subflow with BPF. So it likes it is important to validate that:
- the subflows TCP socket options have been modified: different marks and CC, validated by the new BPF program
- and the MPTCP socket options are still referencing the default ones
I don't think it is important to check that BPF can change the values returned by getsockopt(). I mean: doing this is not specific to MPTCP I think. That's why I think the BPF program should not modify the value returned by getsockopt(), but only checking everything is OK on the subflow side. No?
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Hi Geliang,
Thank you for your modifications, that's great!
Our CI did some validations and here is its report:
- KVM Validation: normal: Success! ✅
- KVM Validation: debug: Success! ✅
- KVM Validation: btf (only bpftest_all): Success! ✅
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/10525835229
Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/8be9a8f01421
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=882630
If there are some issues, you can reproduce them using the same environment as the one used by the CI thanks to a docker image, e.g.:
$ cd [kernel source code]
$ docker run -v "${PWD}:${PWD}:rw" -w "${PWD}" --privileged --rm -it \
--pull always mptcp/mptcp-upstream-virtme-docker:latest \
auto-normalFor more details:
https://github.com/multipath-tcp/mptcp-upstream-virtme-docker
Please note that despite all the efforts that have been already done to have a stable tests suite when executed on a public CI like here, it is possible some reported issues are not due to your modifications. Still, do not hesitate to help us improve that ;-)
Cheers,
MPTCP GH Action bot
Bot operated by Matthieu Baerts (NGI0 Core)