* [PATCH mptcp-next v2 1/4] Squash to "selftests/bpf: add two mptcp netns helpers"
2023-07-01 12:56 [PATCH mptcp-next v2 0/4] BPF 'force to MPTCP' Geliang Tang
@ 2023-07-01 12:56 ` Geliang Tang
2023-07-01 12:56 ` [PATCH mptcp-next v2 2/4] bpf: Add bpf_mptcpify helper Geliang Tang
` (2 subsequent siblings)
3 siblings, 0 replies; 8+ messages in thread
From: Geliang Tang @ 2023-07-01 12:56 UTC (permalink / raw)
To: mptcp; +Cc: Geliang Tang
Move the helpers to the beginning.
Signed-off-by: Geliang Tang <geliang.tang@suse.com>
---
.../testing/selftests/bpf/prog_tests/mptcp.c | 40 +++++++++----------
1 file changed, 20 insertions(+), 20 deletions(-)
diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing/selftests/bpf/prog_tests/mptcp.c
index a968641cc94a..e430bebebcf0 100644
--- a/tools/testing/selftests/bpf/prog_tests/mptcp.c
+++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c
@@ -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;
--
2.35.3
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH mptcp-next v2 2/4] bpf: Add bpf_mptcpify helper
2023-07-01 12:56 [PATCH mptcp-next v2 0/4] BPF 'force to MPTCP' Geliang Tang
2023-07-01 12:56 ` [PATCH mptcp-next v2 1/4] Squash to "selftests/bpf: add two mptcp netns helpers" Geliang Tang
@ 2023-07-01 12:56 ` Geliang Tang
2023-07-01 15:32 ` kernel test robot
2023-07-01 16:55 ` kernel test robot
2023-07-01 12:56 ` [PATCH mptcp-next v2 3/4] selftests/bpf: Test " Geliang Tang
2023-07-01 12:57 ` [PATCH mptcp-next v2 4/4] selftests/bpf: Add mptcpify selftest Geliang Tang
3 siblings, 2 replies; 8+ messages in thread
From: Geliang Tang @ 2023-07-01 12:56 UTC (permalink / raw)
To: mptcp; +Cc: Geliang Tang
This patch implements a new struct bpf_func_proto bpf_mptcpify_proto. And
define a new helper bpf_mptcpify() to mptcpify a TCP socket dynamically as
an MPTCP one.
In bpf_mptcpify(), if the protocol ID of sk is IPPROTO_TCP, set it to
IPPROTO_MPTCP.
Signed-off-by: Geliang Tang <geliang.tang@suse.com>
---
include/linux/bpf.h | 1 +
include/uapi/linux/bpf.h | 7 +++++++
kernel/bpf/cgroup.c | 2 ++
net/core/filter.c | 18 ++++++++++++++++++
scripts/bpf_doc.py | 1 +
tools/include/uapi/linux/bpf.h | 7 +++++++
6 files changed, 36 insertions(+)
diff --git a/include/linux/bpf.h b/include/linux/bpf.h
index f58895830ada..424056fd5335 100644
--- a/include/linux/bpf.h
+++ b/include/linux/bpf.h
@@ -2883,6 +2883,7 @@ extern const struct bpf_func_proto bpf_skc_to_tcp_request_sock_proto;
extern const struct bpf_func_proto bpf_skc_to_udp6_sock_proto;
extern const struct bpf_func_proto bpf_skc_to_unix_sock_proto;
extern const struct bpf_func_proto bpf_skc_to_mptcp_sock_proto;
+extern const struct bpf_func_proto bpf_mptcpify_proto;
extern const struct bpf_func_proto bpf_copy_from_user_proto;
extern const struct bpf_func_proto bpf_snprintf_btf_proto;
extern const struct bpf_func_proto bpf_snprintf_proto;
diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
index 60a9d59beeab..fa8a80024b67 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -5573,6 +5573,12 @@ union bpf_attr {
* 0 on success.
*
* **-ENOENT** if the bpf_local_storage cannot be found.
+ *
+ * struct sock *bpf_mptcpify(void *sk)
+ * Description
+ * Dynamically mptcpify a TCP socket *sk* pointer as an MPTCP one.
+ * Return
+ * *sk* if it's valid, or **NULL** otherwise.
*/
#define ___BPF_FUNC_MAPPER(FN, ctx...) \
FN(unspec, 0, ##ctx) \
@@ -5787,6 +5793,7 @@ union bpf_attr {
FN(user_ringbuf_drain, 209, ##ctx) \
FN(cgrp_storage_get, 210, ##ctx) \
FN(cgrp_storage_delete, 211, ##ctx) \
+ FN(mptcpify, 212, ##ctx) \
/* */
/* backwards-compatibility macros for users of __BPF_FUNC_MAPPER that don't
diff --git a/kernel/bpf/cgroup.c b/kernel/bpf/cgroup.c
index 5b2741aa0d9b..6b56de24e1a2 100644
--- a/kernel/bpf/cgroup.c
+++ b/kernel/bpf/cgroup.c
@@ -2542,6 +2542,8 @@ cgroup_common_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
default:
return &bpf_set_retval_proto;
}
+ case BPF_FUNC_mptcpify:
+ return &bpf_mptcpify_proto;
default:
return NULL;
}
diff --git a/net/core/filter.c b/net/core/filter.c
index 06ba0e56e369..e43b2c42c094 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -11678,6 +11678,24 @@ const struct bpf_func_proto bpf_skc_to_mptcp_sock_proto = {
.ret_btf_id = &btf_sock_ids[BTF_SOCK_TYPE_MPTCP],
};
+BPF_CALL_1(bpf_mptcpify, struct sock *, sk)
+{
+ if (sk && sk_fullsock(sk) && sk->sk_protocol == IPPROTO_TCP) {
+ sk->sk_protocol = IPPROTO_MPTCP;
+ return (unsigned long)sk;
+ }
+
+ return (unsigned long)NULL;
+}
+
+const struct bpf_func_proto bpf_mptcpify_proto = {
+ .func = bpf_mptcpify,
+ .gpl_only = false,
+ .ret_type = RET_PTR_TO_BTF_ID_OR_NULL,
+ .ret_btf_id = &btf_sock_ids[BTF_SOCK_TYPE_SOCK],
+ .arg1_type = ARG_PTR_TO_CTX,
+};
+
BPF_CALL_1(bpf_sock_from_file, struct file *, file)
{
return (unsigned long)sock_from_file(file);
diff --git a/scripts/bpf_doc.py b/scripts/bpf_doc.py
index eaae2ce78381..7a20ab9c6513 100755
--- a/scripts/bpf_doc.py
+++ b/scripts/bpf_doc.py
@@ -751,6 +751,7 @@ class PrinterHelpers(Printer):
'struct file',
'struct bpf_timer',
'struct mptcp_sock',
+ 'struct sock',
'struct bpf_dynptr',
'const struct bpf_dynptr',
'struct iphdr',
diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h
index 60a9d59beeab..fa8a80024b67 100644
--- a/tools/include/uapi/linux/bpf.h
+++ b/tools/include/uapi/linux/bpf.h
@@ -5573,6 +5573,12 @@ union bpf_attr {
* 0 on success.
*
* **-ENOENT** if the bpf_local_storage cannot be found.
+ *
+ * struct sock *bpf_mptcpify(void *sk)
+ * Description
+ * Dynamically mptcpify a TCP socket *sk* pointer as an MPTCP one.
+ * Return
+ * *sk* if it's valid, or **NULL** otherwise.
*/
#define ___BPF_FUNC_MAPPER(FN, ctx...) \
FN(unspec, 0, ##ctx) \
@@ -5787,6 +5793,7 @@ union bpf_attr {
FN(user_ringbuf_drain, 209, ##ctx) \
FN(cgrp_storage_get, 210, ##ctx) \
FN(cgrp_storage_delete, 211, ##ctx) \
+ FN(mptcpify, 212, ##ctx) \
/* */
/* backwards-compatibility macros for users of __BPF_FUNC_MAPPER that don't
--
2.35.3
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH mptcp-next v2 2/4] bpf: Add bpf_mptcpify helper
2023-07-01 12:56 ` [PATCH mptcp-next v2 2/4] bpf: Add bpf_mptcpify helper Geliang Tang
@ 2023-07-01 15:32 ` kernel test robot
2023-07-01 16:55 ` kernel test robot
1 sibling, 0 replies; 8+ messages in thread
From: kernel test robot @ 2023-07-01 15:32 UTC (permalink / raw)
To: Geliang Tang, mptcp; +Cc: oe-kbuild-all, Geliang Tang
Hi Geliang,
kernel test robot noticed the following build errors:
[auto build test ERROR on mptcp/export]
[also build test ERROR on mptcp/export-net linus/master v6.4 next-20230630]
[cannot apply to bpf-next/master bpf/master]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Geliang-Tang/Squash-to-selftests-bpf-add-two-mptcp-netns-helpers/20230701-205922
base: https://github.com/multipath-tcp/mptcp_net-next.git export
patch link: https://lore.kernel.org/r/daf3d1e26f19ee83b427ef9e17183cd09fc26de6.1688215769.git.geliang.tang%40suse.com
patch subject: [PATCH mptcp-next v2 2/4] bpf: Add bpf_mptcpify helper
config: x86_64-buildonly-randconfig-r001-20230701 (https://download.01.org/0day-ci/archive/20230701/202307012313.1sND4cvO-lkp@intel.com/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce: (https://download.01.org/0day-ci/archive/20230701/202307012313.1sND4cvO-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202307012313.1sND4cvO-lkp@intel.com/
All errors (new ones prefixed by >>):
ld: kernel/bpf/cgroup.o: in function `cgroup_common_func_proto':
>> kernel/bpf/cgroup.c:2512: undefined reference to `bpf_mptcpify_proto'
vim +2512 kernel/bpf/cgroup.c
dea6a4e1701338 Stanislav Fomichev 2022-08-23 2507
dea6a4e1701338 Stanislav Fomichev 2022-08-23 2508 /* Common helpers for cgroup hooks. */
dea6a4e1701338 Stanislav Fomichev 2022-08-23 2509 const struct bpf_func_proto *
dea6a4e1701338 Stanislav Fomichev 2022-08-23 2510 cgroup_common_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
dea6a4e1701338 Stanislav Fomichev 2022-08-23 2511 {
dea6a4e1701338 Stanislav Fomichev 2022-08-23 @2512 switch (func_id) {
dea6a4e1701338 Stanislav Fomichev 2022-08-23 2513 case BPF_FUNC_get_local_storage:
dea6a4e1701338 Stanislav Fomichev 2022-08-23 2514 return &bpf_get_local_storage_proto;
dea6a4e1701338 Stanislav Fomichev 2022-08-23 2515 case BPF_FUNC_get_retval:
bed89185af0de0 Stanislav Fomichev 2022-08-23 2516 switch (prog->expected_attach_type) {
bed89185af0de0 Stanislav Fomichev 2022-08-23 2517 case BPF_CGROUP_INET_INGRESS:
bed89185af0de0 Stanislav Fomichev 2022-08-23 2518 case BPF_CGROUP_INET_EGRESS:
bed89185af0de0 Stanislav Fomichev 2022-08-23 2519 case BPF_CGROUP_SOCK_OPS:
bed89185af0de0 Stanislav Fomichev 2022-08-23 2520 case BPF_CGROUP_UDP4_RECVMSG:
bed89185af0de0 Stanislav Fomichev 2022-08-23 2521 case BPF_CGROUP_UDP6_RECVMSG:
bed89185af0de0 Stanislav Fomichev 2022-08-23 2522 case BPF_CGROUP_INET4_GETPEERNAME:
bed89185af0de0 Stanislav Fomichev 2022-08-23 2523 case BPF_CGROUP_INET6_GETPEERNAME:
bed89185af0de0 Stanislav Fomichev 2022-08-23 2524 case BPF_CGROUP_INET4_GETSOCKNAME:
bed89185af0de0 Stanislav Fomichev 2022-08-23 2525 case BPF_CGROUP_INET6_GETSOCKNAME:
bed89185af0de0 Stanislav Fomichev 2022-08-23 2526 return NULL;
bed89185af0de0 Stanislav Fomichev 2022-08-23 2527 default:
dea6a4e1701338 Stanislav Fomichev 2022-08-23 2528 return &bpf_get_retval_proto;
bed89185af0de0 Stanislav Fomichev 2022-08-23 2529 }
dea6a4e1701338 Stanislav Fomichev 2022-08-23 2530 case BPF_FUNC_set_retval:
bed89185af0de0 Stanislav Fomichev 2022-08-23 2531 switch (prog->expected_attach_type) {
bed89185af0de0 Stanislav Fomichev 2022-08-23 2532 case BPF_CGROUP_INET_INGRESS:
bed89185af0de0 Stanislav Fomichev 2022-08-23 2533 case BPF_CGROUP_INET_EGRESS:
bed89185af0de0 Stanislav Fomichev 2022-08-23 2534 case BPF_CGROUP_SOCK_OPS:
bed89185af0de0 Stanislav Fomichev 2022-08-23 2535 case BPF_CGROUP_UDP4_RECVMSG:
bed89185af0de0 Stanislav Fomichev 2022-08-23 2536 case BPF_CGROUP_UDP6_RECVMSG:
bed89185af0de0 Stanislav Fomichev 2022-08-23 2537 case BPF_CGROUP_INET4_GETPEERNAME:
bed89185af0de0 Stanislav Fomichev 2022-08-23 2538 case BPF_CGROUP_INET6_GETPEERNAME:
bed89185af0de0 Stanislav Fomichev 2022-08-23 2539 case BPF_CGROUP_INET4_GETSOCKNAME:
bed89185af0de0 Stanislav Fomichev 2022-08-23 2540 case BPF_CGROUP_INET6_GETSOCKNAME:
bed89185af0de0 Stanislav Fomichev 2022-08-23 2541 return NULL;
bed89185af0de0 Stanislav Fomichev 2022-08-23 2542 default:
dea6a4e1701338 Stanislav Fomichev 2022-08-23 2543 return &bpf_set_retval_proto;
bed89185af0de0 Stanislav Fomichev 2022-08-23 2544 }
96703c9170f3b5 Geliang Tang 2023-07-01 2545 case BPF_FUNC_mptcpify:
96703c9170f3b5 Geliang Tang 2023-07-01 2546 return &bpf_mptcpify_proto;
dea6a4e1701338 Stanislav Fomichev 2022-08-23 2547 default:
dea6a4e1701338 Stanislav Fomichev 2022-08-23 2548 return NULL;
dea6a4e1701338 Stanislav Fomichev 2022-08-23 2549 }
dea6a4e1701338 Stanislav Fomichev 2022-08-23 2550 }
dea6a4e1701338 Stanislav Fomichev 2022-08-23 2551
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH mptcp-next v2 2/4] bpf: Add bpf_mptcpify helper
2023-07-01 12:56 ` [PATCH mptcp-next v2 2/4] bpf: Add bpf_mptcpify helper Geliang Tang
2023-07-01 15:32 ` kernel test robot
@ 2023-07-01 16:55 ` kernel test robot
1 sibling, 0 replies; 8+ messages in thread
From: kernel test robot @ 2023-07-01 16:55 UTC (permalink / raw)
To: Geliang Tang, mptcp; +Cc: oe-kbuild-all, Geliang Tang
Hi Geliang,
kernel test robot noticed the following build errors:
[auto build test ERROR on mptcp/export]
[also build test ERROR on mptcp/export-net linus/master v6.4 next-20230630]
[cannot apply to bpf-next/master bpf/master]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Geliang-Tang/Squash-to-selftests-bpf-add-two-mptcp-netns-helpers/20230701-205922
base: https://github.com/multipath-tcp/mptcp_net-next.git export
patch link: https://lore.kernel.org/r/daf3d1e26f19ee83b427ef9e17183cd09fc26de6.1688215769.git.geliang.tang%40suse.com
patch subject: [PATCH mptcp-next v2 2/4] bpf: Add bpf_mptcpify helper
config: nios2-randconfig-r021-20230701 (https://download.01.org/0day-ci/archive/20230702/202307020056.CI5KNYyK-lkp@intel.com/config)
compiler: nios2-linux-gcc (GCC) 12.3.0
reproduce: (https://download.01.org/0day-ci/archive/20230702/202307020056.CI5KNYyK-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202307020056.CI5KNYyK-lkp@intel.com/
All errors (new ones prefixed by >>):
nios2-linux-ld: kernel/bpf/cgroup.o: in function `cgroup_dev_func_proto':
kernel/bpf/cgroup.c:1607: undefined reference to `bpf_mptcpify_proto'
>> nios2-linux-ld: kernel/bpf/cgroup.c:1607: undefined reference to `bpf_mptcpify_proto'
nios2-linux-ld: kernel/bpf/cgroup.o: in function `cg_sockopt_func_proto':
kernel/bpf/cgroup.c:2297: undefined reference to `bpf_mptcpify_proto'
nios2-linux-ld: kernel/bpf/cgroup.c:2297: undefined reference to `bpf_mptcpify_proto'
nios2-linux-ld: kernel/bpf/cgroup.o: in function `sysctl_func_proto':
kernel/bpf/cgroup.c:2155: undefined reference to `bpf_mptcpify_proto'
nios2-linux-ld: kernel/bpf/cgroup.o:kernel/bpf/cgroup.c:2155: more undefined references to `bpf_mptcpify_proto' follow
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH mptcp-next v2 3/4] selftests/bpf: Test bpf_mptcpify helper
2023-07-01 12:56 [PATCH mptcp-next v2 0/4] BPF 'force to MPTCP' Geliang Tang
2023-07-01 12:56 ` [PATCH mptcp-next v2 1/4] Squash to "selftests/bpf: add two mptcp netns helpers" Geliang Tang
2023-07-01 12:56 ` [PATCH mptcp-next v2 2/4] bpf: Add bpf_mptcpify helper Geliang Tang
@ 2023-07-01 12:56 ` Geliang Tang
2023-07-01 12:57 ` [PATCH mptcp-next v2 4/4] selftests/bpf: Add mptcpify selftest Geliang Tang
3 siblings, 0 replies; 8+ messages in thread
From: Geliang Tang @ 2023-07-01 12:56 UTC (permalink / raw)
To: mptcp; +Cc: Geliang Tang
This patch tests the new helper bpf_mptcpify(). Store the new protocol
value after invoking the helper to a local BSS variable.
This is defined in a 'sock_create' SEC, so it will be invoked in
BPF_CGROUP_RUN_PROG_INET_SOCK() in inet_create().
Signed-off-by: Geliang Tang <geliang.tang@suse.com>
---
tools/testing/selftests/bpf/bpf_tcp_helpers.h | 1 +
tools/testing/selftests/bpf/progs/mptcpify.c | 26 +++++++++++++++++++
2 files changed, 27 insertions(+)
create mode 100644 tools/testing/selftests/bpf/progs/mptcpify.c
diff --git a/tools/testing/selftests/bpf/bpf_tcp_helpers.h b/tools/testing/selftests/bpf/bpf_tcp_helpers.h
index 72c618037386..f846d5d62529 100644
--- a/tools/testing/selftests/bpf/bpf_tcp_helpers.h
+++ b/tools/testing/selftests/bpf/bpf_tcp_helpers.h
@@ -38,6 +38,7 @@ struct sock {
#define sk_state __sk_common.skc_state
unsigned long sk_pacing_rate;
__u32 sk_pacing_status; /* see enum sk_pacing */
+ __u16 sk_protocol;
} __attribute__((preserve_access_index));
struct inet_sock {
diff --git a/tools/testing/selftests/bpf/progs/mptcpify.c b/tools/testing/selftests/bpf/progs/mptcpify.c
new file mode 100644
index 000000000000..f04b186b9c26
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/mptcpify.c
@@ -0,0 +1,26 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (c) 2023, SUSE. */
+
+#include <sys/socket.h>
+#include <linux/bpf.h>
+#include <bpf/bpf_helpers.h>
+#include "bpf_tcp_helpers.h"
+
+char _license[] SEC("license") = "GPL";
+__u16 protocol = 0;
+
+SEC("cgroup/sock_create")
+int sock(struct bpf_sock *ctx)
+{
+ struct sock *sk;
+
+ if (ctx->type != SOCK_STREAM)
+ return 1;
+
+ sk = bpf_mptcpify(ctx);
+ if (!sk)
+ return 1;
+
+ protocol = sk->sk_protocol;
+ return 1;
+}
--
2.35.3
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH mptcp-next v2 4/4] selftests/bpf: Add mptcpify selftest
2023-07-01 12:56 [PATCH mptcp-next v2 0/4] BPF 'force to MPTCP' Geliang Tang
` (2 preceding siblings ...)
2023-07-01 12:56 ` [PATCH mptcp-next v2 3/4] selftests/bpf: Test " Geliang Tang
@ 2023-07-01 12:57 ` Geliang Tang
2023-07-01 14:02 ` selftests/bpf: Add mptcpify selftest: Tests Results MPTCP CI
3 siblings, 1 reply; 8+ messages in thread
From: Geliang Tang @ 2023-07-01 12:57 UTC (permalink / raw)
To: mptcp; +Cc: Geliang Tang
This 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 stored local BSS variable.
Signed-off-by: Geliang Tang <geliang.tang@suse.com>
---
.../testing/selftests/bpf/prog_tests/mptcp.c | 87 +++++++++++++++++++
1 file changed, 87 insertions(+)
diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing/selftests/bpf/prog_tests/mptcp.c
index e430bebebcf0..5f498bf5a677 100644
--- a/tools/testing/selftests/bpf/prog_tests/mptcp.c
+++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c
@@ -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"
@@ -13,6 +14,9 @@
char NS_TEST[32];
+#ifndef IPPROTO_MPTCP
+#define IPPROTO_MPTCP 262
+#endif
#ifndef TCP_CA_NAME_MAX
#define TCP_CA_NAME_MAX 16
#endif
@@ -200,6 +204,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(int protocol)
+{
+ char cmd[128];
+ int err = 0;
+
+ if (!ASSERT_EQ(protocol, IPPROTO_MPTCP, "unexpected protocol"))
+ err++;
+
+ snprintf(cmd, sizeof(cmd),
+ "ip netns exec %s ss -tOni | grep -q tcp-ulp-mptcp",
+ NS_TEST);
+ ASSERT_OK(system(cmd), "No tcp-ulp-mptcp found!");
+
+ 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, "skel_open_load"))
+ return -EIO;
+
+ mptcpify_skel->links.sock =
+ bpf_program__attach_cgroup(mptcpify_skel->progs.sock, cgroup_fd);
+ if (!ASSERT_OK_PTR(mptcpify_skel->links.sock, "cg_attach_sock"))
+ 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(mptcpify_skel->bss->protocol);
+
+ 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 +544,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"))
--
2.35.3
^ permalink raw reply related [flat|nested] 8+ messages in thread