BPF 'force to MPTCP'
Subsystems (8)
v4 cover BPF 'force to MPTCP'
v4:
- add hooks in __sock_create().
v3:
- add a wrapper socket_create(), the bpf hooks will added in this wrapper.
v2:
- Address issue #79 "allow 'force to MPTCP' mode: BPF".
- Define the prog in patch 3 in SEC "cgroup/sock_create" instead of "sockops".
- Update other patches correspondingly.
v1:
This series depends on the two netns patches, should be inserted before the BPF scheduler series:
selftests/bpf: use random netns name for mptcp selftests/bpf: add two mptcp netns helpers
bpf: Add bpf_mptcpify helper
selftests/bpf: Test bpf_mptcpify helper
selftests/bpf: Add mptcpify selftest
mptcp: refactor push_pending logic
Geliang Tang (7):
bpf: Add new prog type sockinit
bpf: Run a sockinit program
net: socket: run sockinit hooks
libbpf: Support sockinit hook
selftests/bpf: Add mptcpify program
Squash to "selftests/bpf: add two mptcp netns helpers" selftests/bpf: Add mptcpify selftest
include/linux/bpf-cgroup-defs.h | 1 + include/linux/bpf-cgroup.h | 14 ++ include/linux/bpf_types.h | 2 + include/uapi/linux/bpf.h | 8 ++ kernel/bpf/cgroup.c | 90 +++++++++++++ kernel/bpf/syscall.c | 7 + kernel/bpf/verifier.c | 1 + net/socket.c | 6 + tools/include/uapi/linux/bpf.h | 8 ++ tools/lib/bpf/libbpf.c | 3 + tools/lib/bpf/libbpf_probes.c | 1 + .../bpf/cgroup_getset_retval_hooks.h | 1 + .../testing/selftests/bpf/prog_tests/mptcp.c | 124 +++++++++++++++--- .../selftests/bpf/prog_tests/section_names.c | 5 + tools/testing/selftests/bpf/progs/mptcpify.c | 26 ++++ 15 files changed, 277 insertions(+), 20 deletions(-) create mode 100644 tools/testing/selftests/bpf/progs/mptcpify.c
Signature · 1 line
2.35.3
PATCH v4 1/7 bpf: Add new prog type sockinit
The patch introduces new program type BPF_PROG_TYPE_CGROUP_SOCKINIT and attach type BPF_CGROUP_SOCKINIT on cgroup basis.
Define this program by BPF_PROG_TYPE(), and implement two operations:cg_sockinit_prog_ops and cg_sockinit_verifier_ops.
--- include/linux/bpf_types.h | 2 ++ include/uapi/linux/bpf.h | 8 +++++ kernel/bpf/cgroup.c | 66 +++++++++++++++++++++++++++++++++++++++ kernel/bpf/syscall.c | 7 +++++ kernel/bpf/verifier.c | 1 + 5 files changed, 84 insertions(+)
include/linux/bpf_types.h +2 -0
@@ -52,6 +52,8 @@ BPF_PROG_TYPE(BPF_PROG_TYPE_TRACING, tracing,#ifdef CONFIG_CGROUP_BPF BPF_PROG_TYPE (BPF_PROG_TYPE_CGROUP_DEVICE , cg_dev, struct bpf_cgroup_dev_ctx, struct bpf_cgroup_dev_ctx) +BPF_PROG_TYPE (BPF_PROG_TYPE_CGROUP_SOCKINIT , cg_sockinit, + struct bpf_sockinit_ctx, struct bpf_sockinit_ctx)BPF_PROG_TYPE (BPF_PROG_TYPE_CGROUP_SYSCTL , cg_sysctl, struct bpf_sysctl, struct bpf_sysctl_kern) BPF_PROG_TYPE(BPF_PROG_TYPE_CGROUP_SOCKOPT, cg_sockopt,
include/uapi/linux/bpf.h +8 -0
@@ -980,6 +980,7 @@ enum bpf_prog_type {BPF_PROG_TYPE_CGROUP_SYSCTL ,BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE ,BPF_PROG_TYPE_CGROUP_SOCKOPT , +BPF_PROG_TYPE_CGROUP_SOCKINIT ,BPF_PROG_TYPE_TRACING ,BPF_PROG_TYPE_STRUCT_OPS , BPF_PROG_TYPE_EXT,
@@ -1013,6 +1014,7 @@ enum bpf_attach_type {BPF_CGROUP_UDP6_RECVMSG ,BPF_CGROUP_GETSOCKOPT ,BPF_CGROUP_SETSOCKOPT , +BPF_CGROUP_SOCKINIT ,BPF_TRACE_RAW_TP ,BPF_TRACE_FENTRY , BPF_TRACE_FEXIT,
@@ -6829,6 +6831,12 @@ struct bpf_raw_tracepoint_args {__u64 args[0 ]; }; +struct bpf_sockinit_ctx { +__u32 family; +__u32 type; +__u32 protocol; +}; +/* DIRECT: Skip the FIB rules and go to FIB table associated with device * OUTPUT: Do lookup from egress perspective; default is ingress */
kernel/bpf/cgroup.c +66 -0
72 lines not on this page · raw message
kernel/bpf/syscall.c +7 -0
@@ -2513,6 +2513,7 @@ static bool is_net_admin_prog_type(enum bpf_prog_type prog_type)case BPF_PROG_TYPE_CGROUP_SOCK_ADDR :case BPF_PROG_TYPE_CGROUP_SOCKOPT :case BPF_PROG_TYPE_CGROUP_SYSCTL : +case BPF_PROG_TYPE_CGROUP_SOCKINIT :case BPF_PROG_TYPE_SOCK_OPS :case BPF_PROG_TYPE_EXT :/* extends any prog */ case BPF_PROG_TYPE_NETFILTER :
@@ -3574,6 +3575,8 @@ attach_type_to_prog_type(enum bpf_attach_type attach_type)case BPF_CGROUP_GETSOCKOPT :case BPF_CGROUP_SETSOCKOPT :return BPF_PROG_TYPE_CGROUP_SOCKOPT ; +case BPF_CGROUP_SOCKINIT : +return BPF_PROG_TYPE_CGROUP_SOCKINIT ;case BPF_TRACE_ITER :case BPF_TRACE_RAW_TP :case BPF_TRACE_FENTRY :
@@ -3640,6 +3643,7 @@ static int bpf_prog_attach(const union bpf_attr *attr)case BPF_PROG_TYPE_CGROUP_SOCK_ADDR :case BPF_PROG_TYPE_CGROUP_SOCKOPT :case BPF_PROG_TYPE_CGROUP_SYSCTL : +case BPF_PROG_TYPE_CGROUP_SOCKINIT :case BPF_PROG_TYPE_SOCK_OPS :case BPF_PROG_TYPE_LSM : if (ptype == BPF_PROG_TYPE_LSM &&
@@ -3682,6 +3686,7 @@ static int bpf_prog_detach(const union bpf_attr *attr)case BPF_PROG_TYPE_CGROUP_SOCK_ADDR :case BPF_PROG_TYPE_CGROUP_SOCKOPT :case BPF_PROG_TYPE_CGROUP_SYSCTL : +case BPF_PROG_TYPE_CGROUP_SOCKINIT :case BPF_PROG_TYPE_SOCK_OPS :case BPF_PROG_TYPE_LSM :return cgroup_bpf_prog_detach (attr, ptype);
@@ -3726,6 +3731,7 @@ static int bpf_prog_query(const union bpf_attr *attr,case BPF_CGROUP_SYSCTL :case BPF_CGROUP_GETSOCKOPT :case BPF_CGROUP_SETSOCKOPT : +case BPF_CGROUP_SOCKINIT :case BPF_LSM_CGROUP :return cgroup_bpf_prog_query (attr, uattr);case BPF_LIRC_MODE2 :
@@ -4717,6 +4723,7 @@ static int link_create(union bpf_attr *attr, bpfptr_t uattr)case BPF_PROG_TYPE_CGROUP_DEVICE :case BPF_PROG_TYPE_CGROUP_SYSCTL :case BPF_PROG_TYPE_CGROUP_SOCKOPT : +case BPF_PROG_TYPE_CGROUP_SOCKINIT : ret =cgroup_bpf_link_attach (attr, prog);break ;case BPF_PROG_TYPE_EXT :
kernel/bpf/verifier.c +1 -0
@@ -14316,6 +14316,7 @@ static int check_return_code(struct bpf_verifier_env *env)case BPF_PROG_TYPE_CGROUP_DEVICE :case BPF_PROG_TYPE_CGROUP_SYSCTL :case BPF_PROG_TYPE_CGROUP_SOCKOPT : +case BPF_PROG_TYPE_CGROUP_SOCKINIT :break ;case BPF_PROG_TYPE_RAW_TRACEPOINT :if (!env->prog->aux->attach_btf_id)
Signature · 1 line
2.35.3
PATCH v4 2/7 bpf: Run a sockinit program
In reply to Geliang TangThis patch defines BPF_CGROUP_RUN_PROG_SOCKINIT() helper, and implements __cgroup_bpf_run_sockinit() helper to run a sockinit program.
--- include/linux/bpf-cgroup-defs.h | 1 + include/linux/bpf-cgroup.h | 14 ++++++++++++++ kernel/bpf/cgroup.c | 24 ++++++++++++++++++++++++ 3 files changed, 39 insertions(+)
include/linux/bpf-cgroup-defs.h +1 -0
@@ -37,6 +37,7 @@ enum cgroup_bpf_attach_type {CGROUP_UDP6_RECVMSG ,CGROUP_GETSOCKOPT ,CGROUP_SETSOCKOPT , +CGROUP_SOCKINIT ,CGROUP_INET4_GETPEERNAME ,CGROUP_INET6_GETPEERNAME , CGROUP_INET4_GETSOCKNAME,
include/linux/bpf-cgroup.h +14 -0
@@ -57,6 +57,7 @@ to_cgroup_bpf_attach_type(enum bpf_attach_type attach_type)CGROUP_ATYPE (CGROUP_UDP6_RECVMSG );CGROUP_ATYPE (CGROUP_GETSOCKOPT );CGROUP_ATYPE (CGROUP_SETSOCKOPT ); +CGROUP_ATYPE (CGROUP_SOCKINIT );CGROUP_ATYPE (CGROUP_INET4_GETPEERNAME );CGROUP_ATYPE (CGROUP_INET6_GETPEERNAME );CGROUP_ATYPE (CGROUP_INET4_GETSOCKNAME );
@@ -148,6 +149,9 @@ int __cgroup_bpf_run_filter_getsockopt_kern(struct sock *sk, int level, int optname, void *optval, int *optlen, int retval); +int __cgroup_bpf_run_sockinit (int *family,int *type,int *protocol, +enum cgroup_bpf_attach_type atype); +static inline enum bpf_cgroup_storage_type cgroup_storage_type (struct bpf_map *map) {
@@ -407,6 +411,15 @@ static inline bool cgroup_bpf_sock_enabled(struct sock *sk, __ret; \ }) +#define BPF_CGROUP_RUN_PROG_SOCKINIT (family, type, protocol) \ +({ \ + int __ret = 0; \ + if (cgroup_bpf_enabled(CGROUP_SOCKINIT)) \ + __ret = __cgroup_bpf_run_sockinit(family, type, protocol, \ + CGROUP_SOCKINIT); \ + __ret; \ +}) +int cgroup_bpf_prog_attach (const union bpf_attr *attr,enum bpf_prog_type ptype,struct bpf_prog *prog); int cgroup_bpf_prog_detach(const union bpf_attr *attr,
@@ -505,6 +518,7 @@ static inline int bpf_percpu_cgroup_storage_update(struct bpf_map *map, optlen, retval) ({ retval; })#define BPF_CGROUP_RUN_PROG_SETSOCKOPT (sock, level, optname, optval, optlen, \ kernel_optval) ({ 0; }) +#define BPF_CGROUP_RUN_PROG_SOCKINIT (family, type, protocol) ({ 0; })#define for_each_cgroup_storage_type (stype) for (; false; )
kernel/bpf/cgroup.c +24 -0
@@ -1996,6 +1996,30 @@ int __cgroup_bpf_run_filter_getsockopt_kern(struct sock *sk, int level,return ret; } + +int __cgroup_bpf_run_sockinit (int *family,int *type,int *protocol, +enum cgroup_bpf_attach_type atype) +{ +struct bpf_sockinit_ctx ctx = { + .family = *family, + .type = *type, + .protocol = *protocol, + }; +struct cgroup *cgrp; +int ret; + +rcu_read_lock (); + cgrp =task_dfl_cgroup (current); + ret =bpf_prog_run_array_cg (&cgrp->bpf, atype, &ctx, bpf_prog_run,0 , +NULL ); +rcu_read_unlock (); + + *family = ctx.family; + *type = ctx.type; + *protocol = ctx.protocol; + +return ret; +}#endif static ssize_t sysctl_cpy_dir(const struct ctl_dir *dir, char **bufp,
Signature · 1 line
2.35.3
PATCH v4 3/7 net: socket: run sockinit hooks
In reply to Geliang TangThe arguments of socket() need to be changed sometimes like the MPTCP case in the next commits.
It's too late to add the BPF hooks in BPF_CGROUP_RUN_PROG_INET_SOCK() in inet_create(). So this patch invokes BPF_CGROUP_RUN_PROG_SOCKINIT() in __socket_create() to change the arguments.
--- net/socket.c | 6 ++++++ 1 file changed, 6 insertions(+)
net/socket.c +6 -0
@@ -1469,6 +1469,12 @@ int __sock_create(struct net *net, int family, int type, int protocol,struct socket *sock;const struct net_proto_family *pf; +if (!kern) { + err =BPF_CGROUP_RUN_PROG_SOCKINIT (&family, &type, &protocol); +if (err) +return err; + } +/* * Check protocol is in range */
Signature · 1 line
2.35.3
PATCH v4 4/7 libbpf: Support sockinit hook
In reply to Geliang TangSync BPF_PROG_TYPE_CGROUP_SOCKINIT related bpf UAPI changes to tools/. Support BPF_PROG_TYPE_CGROUP_SOCKINIT program in libbpf: identifying program and attach types by section name, probe.
--- tools/include/uapi/linux/bpf.h | 8 ++++++++ tools/lib/bpf/libbpf.c | 3 +++ tools/lib/bpf/libbpf_probes.c | 1 + 3 files changed, 12 insertions(+)
tools/include/uapi/linux/bpf.h +8 -0
@@ -980,6 +980,7 @@ enum bpf_prog_type {BPF_PROG_TYPE_CGROUP_SYSCTL ,BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE ,BPF_PROG_TYPE_CGROUP_SOCKOPT , +BPF_PROG_TYPE_CGROUP_SOCKINIT ,BPF_PROG_TYPE_TRACING ,BPF_PROG_TYPE_STRUCT_OPS , BPF_PROG_TYPE_EXT,
@@ -1013,6 +1014,7 @@ enum bpf_attach_type {BPF_CGROUP_UDP6_RECVMSG ,BPF_CGROUP_GETSOCKOPT ,BPF_CGROUP_SETSOCKOPT , +BPF_CGROUP_SOCKINIT ,BPF_TRACE_RAW_TP ,BPF_TRACE_FENTRY , BPF_TRACE_FEXIT,
@@ -6829,6 +6831,12 @@ struct bpf_raw_tracepoint_args {__u64 args[0 ]; }; +struct bpf_sockinit_ctx { +__u32 family; +__u32 type; +__u32 protocol; +}; +/* DIRECT: Skip the FIB rules and go to FIB table associated with device * OUTPUT: Do lookup from egress perspective; default is ingress */
tools/lib/bpf/libbpf.c +3 -0
@@ -95,6 +95,7 @@ static const char * const attach_type_name[] = { [BPF_CGROUP_UDP6_RECVMSG] = "cgroup_udp6_recvmsg", [BPF_CGROUP_GETSOCKOPT] = "cgroup_getsockopt", [BPF_CGROUP_SETSOCKOPT] = "cgroup_setsockopt", + [BPF_CGROUP_SOCKINIT] = "cgroup_sockinit", [BPF_SK_SKB_STREAM_PARSER] = "sk_skb_stream_parser", [BPF_SK_SKB_STREAM_VERDICT] = "sk_skb_stream_verdict", [BPF_SK_SKB_VERDICT] = "sk_skb_verdict",
@@ -197,6 +198,7 @@ static const char * const prog_type_name[] = { [BPF_PROG_TYPE_CGROUP_SYSCTL] = "cgroup_sysctl", [BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE] = "raw_tracepoint_writable", [BPF_PROG_TYPE_CGROUP_SOCKOPT] = "cgroup_sockopt", + [BPF_PROG_TYPE_CGROUP_SOCKINIT] = "cgroup_sockinit", [BPF_PROG_TYPE_TRACING] = "tracing", [BPF_PROG_TYPE_STRUCT_OPS] = "struct_ops", [BPF_PROG_TYPE_EXT] = "ext",
@@ -8734,6 +8736,7 @@ static const struct bpf_sec_def section_defs[] = {SEC_DEF ("cgroup/getsockopt" ,CGROUP_SOCKOPT ,BPF_CGROUP_GETSOCKOPT ,SEC_ATTACHABLE ),SEC_DEF ("cgroup/setsockopt" ,CGROUP_SOCKOPT ,BPF_CGROUP_SETSOCKOPT ,SEC_ATTACHABLE ),SEC_DEF ("cgroup/dev" ,CGROUP_DEVICE ,BPF_CGROUP_DEVICE ,SEC_ATTACHABLE_OPT ), +SEC_DEF ("cgroup/sockinit" ,CGROUP_SOCKINIT ,BPF_CGROUP_SOCKINIT ,SEC_ATTACHABLE ),SEC_DEF ("struct_ops+" ,STRUCT_OPS ,0 ,SEC_NONE ),SEC_DEF ("struct_ops.s+" ,STRUCT_OPS ,0 ,SEC_SLEEPABLE ), SEC_DEF("sk_lookup", SK_LOOKUP, BPF_SK_LOOKUP, SEC_ATTACHABLE),
tools/lib/bpf/libbpf_probes.c +1 -0
@@ -180,6 +180,7 @@ static int probe_prog_load(enum bpf_prog_type prog_type,case BPF_PROG_TYPE_SK_REUSEPORT :case BPF_PROG_TYPE_FLOW_DISSECTOR :case BPF_PROG_TYPE_CGROUP_SYSCTL : +case BPF_PROG_TYPE_CGROUP_SOCKINIT :break ;case BPF_PROG_TYPE_NETFILTER : opts.expected_attach_type =BPF_NETFILTER ;
Signature · 1 line
2.35.3
PATCH v4 5/7 selftests/bpf: Add mptcpify program
In reply to Geliang TangThis patch implements a new test program mptcpify: if the family is AF_INET or AF_INET6, the type is SOCK_STREAM, and the protocol ID is 0 or IPPROTO_TCP, set it to IPPROTO_MPTCP.
This is defined in a newly added 'sockinit' SEC, so it will be hooked in BPF_CGROUP_RUN_PROG_SOCKINIT() in __socket_create().
--- .../bpf/cgroup_getset_retval_hooks.h | 1 + .../selftests/bpf/prog_tests/section_names.c | 5 ++++ tools/testing/selftests/bpf/progs/mptcpify.c | 26 +++++++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 tools/testing/selftests/bpf/progs/mptcpify.c
tools/testing/selftests/bpf/cgroup_getset_retval_hooks.h +1 -0
@@ -14,6 +14,7 @@ BPF_RETVAL_HOOK(post_bind6, "cgroup/post_bind6", bpf_sock_addr, 0) BPF_RETVAL_HOOK(sendmsg4, "cgroup/sendmsg4", bpf_sock_addr, 0) BPF_RETVAL_HOOK(sendmsg6, "cgroup/sendmsg6", bpf_sock_addr, 0) BPF_RETVAL_HOOK(sysctl, "cgroup/sysctl", bpf_sysctl, 0) +BPF_RETVAL_HOOK(sockinit, "cgroup/sockinit", bpf_sockinit_ctx, 0) BPF_RETVAL_HOOK(recvmsg4, "cgroup/recvmsg4", bpf_sock_addr, -EINVAL) BPF_RETVAL_HOOK(recvmsg6, "cgroup/recvmsg6", bpf_sock_addr, -EINVAL)BPF_RETVAL_HOOK (getsockopt,"cgroup/getsockopt" , bpf_sockopt,0 )
tools/testing/selftests/bpf/prog_tests/section_names.c +5 -0
@@ -158,6 +158,11 @@ static struct sec_name_test tests[] = { {0, BPF_PROG_TYPE_CGROUP_SOCKOPT, BPF_CGROUP_SETSOCKOPT}, {0, BPF_CGROUP_SETSOCKOPT}, }, + { +"cgroup/sockinit" , + {0, BPF_PROG_TYPE_CGROUP_SOCKINIT, BPF_CGROUP_SOCKINIT}, + {0, BPF_CGROUP_SOCKINIT}, + }, };static void test_prog_type_by_name (const struct sec_name_test *test)
tools/testing/selftests/bpf/progs/mptcpify.c new file +26 -0
@@ -0,0 +1,26 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) 2023, SUSE. */ + +#include <linux/bpf.h> +#include <bpf/bpf_helpers.h> +#include "bpf_tcp_helpers.h" + +char _license[] SEC("license") = "GPL"; + +#define AF_INET 2 +#define AF_INET6 10 +#define SOCK_STREAM 1 +#define IPPROTO_TCP 6 +#define IPPROTO_MPTCP 262 + +SEC("cgroup/sockinit") +int mptcpify (struct bpf_sockinit_ctx *ctx) +{ +if ((ctx->family ==AF_INET || ctx->family ==AF_INET6 ) && + ctx->type ==SOCK_STREAM && + (!ctx->protocol || ctx->protocol ==IPPROTO_TCP )) { + ctx->protocol =IPPROTO_MPTCP ; + } + +return 1 ; +}
Signature · 1 line
2.35.3
PATCH v4 6/7 Squash to "selftests/bpf: add two mptcp netns helpers"
In reply to Geliang TangMove the helpers to the beginning.
--- .../testing/selftests/bpf/prog_tests/mptcp.c | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-)
tools/testing/selftests/bpf/prog_tests/mptcp.c +20 -20
@@ -26,6 +26,26 @@ struct mptcp_storage {char ca_name[TCP_CA_NAME_MAX ]; }; +static struct nstoken *create_netns (void ) +{ +srand (time (NULL )); +snprintf (NS_TEST ,sizeof (NS_TEST ),"mptcp_ns_%d" ,rand ()); +SYS (fail,"ip netns add %s" ,NS_TEST ); +SYS (fail,"ip -net %s link set dev lo up" ,NS_TEST ); + +return open_netns (NS_TEST ); +fail: +return NULL ; +} + +static void cleanup_netns (struct nstoken *nstoken) +{ +if (nstoken) +close_netns (nstoken); + +SYS_NOFAIL ("ip netns del %s &> /dev/null" ,NS_TEST ); +} +static int verify_tsk (int map_fd,int client_fd) {int err, cfd = client_fd;
@@ -142,26 +162,6 @@ static int run_test(int cgroup_fd, int server_fd, bool is_mptcp)return err; } -static struct nstoken *create_netns (void ) -{ -srand (time (NULL )); -snprintf (NS_TEST ,sizeof (NS_TEST ),"mptcp_ns_%d" ,rand ()); -SYS (fail,"ip netns add %s" ,NS_TEST ); -SYS (fail,"ip -net %s link set dev lo up" ,NS_TEST ); - -return open_netns (NS_TEST ); -fail: -return NULL ; -} - -static void cleanup_netns (struct nstoken *nstoken) -{ -if (nstoken) -close_netns (nstoken); - -SYS_NOFAIL ("ip netns del %s &> /dev/null" ,NS_TEST ); -} -static void test_base (void ) {struct nstoken *nstoken =NULL ;
Signature · 1 line
2.35.3
Re: [PATCH mptcp-next v4 6/7] Squash to "selftests/bpf: add two mptcp netns helpers"
Hi Geliang,
Quoted 1 line · Geliang Tang
Move the helpers to the beginning.
I can already apply this patch, it will be easier for you later I guess.
Cheers,
Matt
Signature · 2 lines
Tessares | Belgium | Hybrid Access Solutions www.tessares.net
PATCH v4 7/7 selftests/bpf: Add mptcpify selftest
In reply to Geliang TangThis patch extends the MPTCP test base, add a selftest test_mptcpify() for the mptcpify case.
Open and load the mptcpify test prog to mptcpify the TCP sockets dynamically, then use start_server() and connect_to_fd() to create a TCP socket, but actually what's created is an MPTCP socket, which can be verified through the output of 'ss' command.
--- .../testing/selftests/bpf/prog_tests/mptcp.c | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+)
tools/testing/selftests/bpf/prog_tests/mptcp.c +84 -0
@@ -6,6 +6,7 @@#include "cgroup_helpers.h" #include "network_helpers.h" #include "mptcp_sock.skel.h" +#include "mptcpify.skel.h" #include "mptcp_bpf_first.skel.h" #include "mptcp_bpf_bkup.skel.h" #include "mptcp_bpf_rr.skel.h"
@@ -200,6 +201,87 @@ static void test_base(void)close (cgroup_fd); } +static void send_byte (int fd) +{ +char b =0x55 ; + +ASSERT_EQ (write (fd, &b,sizeof (b)),1 ,"send single byte" ); +} + +static int verify_mptcpify (void ) +{ +char cmd[128 ]; +int err =0 ; + +snprintf (cmd,sizeof (cmd), +"ip netns exec %s ss -tOni | grep -q tcp-ulp-mptcp" , +NS_TEST ); +if (!ASSERT_OK (system (cmd),"No tcp-ulp-mptcp found!" )) + err++; + +return err; +} + +static int run_mptcpify (int cgroup_fd) +{ +int server_fd, client_fd, err =0 ; +struct mptcpify *mptcpify_skel; + + mptcpify_skel =mptcpify__open_and_load (); +if (!ASSERT_OK_PTR (mptcpify_skel,"mptcpify__open_and_load" )) +return -EIO ; + + mptcpify_skel->links.mptcpify = +bpf_program__attach_cgroup (mptcpify_skel->progs.mptcpify, cgroup_fd); +if (!ASSERT_OK_PTR (mptcpify_skel->links.mptcpify,"bpf_program__attach_cgroup" )) { + err = -EIO ; + goto out; + } + +/* without MPTCP */ + server_fd =start_server (AF_INET ,SOCK_STREAM ,NULL ,0 ,0 ); +if (!ASSERT_GE (server_fd,0 ,"start_server" )) { + err = -EIO ; + goto out; + } + + client_fd =connect_to_fd (server_fd,0 ); +if (!ASSERT_GE (client_fd,0 ,"connect to fd" )) { + err = -EIO ; + goto close_server; + } + +send_byte (client_fd); + err +=verify_mptcpify (); + +close (client_fd); +close_server: +close (server_fd); +out: +mptcpify__destroy (mptcpify_skel); +return err; +} + +static void test_mptcpify (void ) +{ +struct nstoken *nstoken =NULL ; +int cgroup_fd; + + cgroup_fd =test__join_cgroup ("/mptcpify" ); +if (!ASSERT_GE (cgroup_fd,0 ,"test__join_cgroup" )) +return ; + + nstoken =create_netns (); +if (!ASSERT_OK_PTR (nstoken,"create_netns" )) + goto fail; + +ASSERT_OK (run_mptcpify (cgroup_fd),"run_mptcpify" ); + +fail: +cleanup_netns (nstoken); +close (cgroup_fd); +} +static const unsigned int total_bytes =10 *1024 *1024 ;static int stop, duration;
@@ -459,6 +541,8 @@ void test_mptcp(void) {if (test__start_subtest ("base" ))test_base (); +if (test__start_subtest ("mptcpify" )) +test_mptcpify ();if (test__start_subtest ("first" ))test_first ();if (test__start_subtest ("bkup" ))
Signature · 1 line
2.35.3
Re: selftests/bpf: Add mptcpify selftest: Tests Results
Hi Geliang,
Thank you for your modifications, that's great!
Our CI did some validations and here is its report:
- KVM Validation: normal (except selftest_mptcp_join):
- Success! ✅:
- Task: https://cirrus-ci.com/task/5087982516961280
- Summary: https://api.cirrus-ci.com/v1/artifact/task/5087982516961280/summary/summary.txt
- KVM Validation: debug (only selftest_mptcp_join):
- Success! ✅:
- Task: https://cirrus-ci.com/task/5932407447093248
- Summary: https://api.cirrus-ci.com/v1/artifact/task/5932407447093248/summary/summary.txt
- KVM Validation: normal (only selftest_mptcp_join):
- Success! ✅:
- Task: https://cirrus-ci.com/task/6213882423803904
- Summary: https://api.cirrus-ci.com/v1/artifact/task/6213882423803904/summary/summary.txt
- KVM Validation: debug (except selftest_mptcp_join):
- Success! ✅:
- Task: https://cirrus-ci.com/task/4806507540250624
- Summary: https://api.cirrus-ci.com/v1/artifact/task/4806507540250624/summary/summary.txt
Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/ba6544f98bca
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-debugFor 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 (Tessares)
Hi Geliang,
Quoted 2 lines · Geliang Tang
v4:
- add hooks in__sock_create().
Thank you for this new version!
I had a very quick look: it seems nice!
Personally, I don't know the BPF environment well enough to give a good review and judge if the direction you took is the good one. Then, I wonder if it would not be better to rebase this series on top of bpf-next and send a first (RFC?) version to BPF maintainers to get some feedbacks (with MPTCP list in CC of course). WDYT?
In this case, it will be important to mention in the cover-letter what is the goal (e.g. create a different socket and the main use-case is MPTCP) and why it is interesting to do that with BPF (see my previous email [1] -- I also updated the ticket [2]). Don't hesitate to add a link to the v3 explaining what was the limitations.
I can help reviewing the new cover-letter if needed.
[1]
https://lore.kernel.org/mptcp/[email protected]/
[2] https://github.com/multipath-tcp/mptcp_net-next/issues/79
Cheers,
Matt
Signature · 2 lines
Tessares | Belgium | Hybrid Access Solutions www.tessares.net