update bpf patches on export branch
Subsystems (11)
cover update bpf patches on export branch
- drop bpf_mptcp_helpers.h (Andrii)
- patch 6, skip the test if 'ip mptcp monitor' is not supported (Mat)
base-commit: bcf89bc9c28e ("DO-NOT-MERGE: git markup: features net-next-next") on export/20220510T054929
Geliang Tang (13):
bpf: add bpf_skc_to_mptcp_sock_proto selftests/bpf: Enable CONFIG_IKCONFIG_PROC in config selftests/bpf: test bpf_skc_to_mptcp_sock selftests/bpf: verify token of struct mptcp_sock selftests/bpf: verify ca_name of struct mptcp_sock selftests/bpf: verify first of struct mptcp_sock
mptcp: add struct mptcp_sched_ops
mptcp: add a new sysctl scheduler
mptcp: add sched in mptcp_sock
mptcp: add get_subflow wrappers
mptcp: add bpf_mptcp_sched_ops selftests/bpf: add bpf_first scheduler selftests/bpf: add bpf_first test
Nicolas Rybowski (2):
bpf: expose is_mptcp flag to bpf_tcp_sock
selftests/bpf: add MPTCP test base
Documentation/networking/mptcp-sysctl.rst | 8 + MAINTAINERS | 1 + include/linux/bpf.h | 1 + include/linux/btf_ids.h | 3 +- include/net/mptcp.h | 25 ++ include/uapi/linux/bpf.h | 8 + kernel/bpf/bpf_struct_ops_types.h | 4 + kernel/bpf/verifier.c | 1 + kernel/trace/bpf_trace.c | 2 + net/core/filter.c | 27 +- net/mptcp/Makefile | 4 +- net/mptcp/bpf.c | 175 ++++++++ net/mptcp/ctrl.c | 14 + net/mptcp/protocol.c | 32 +- net/mptcp/protocol.h | 12 + net/mptcp/sched.c | 141 +++++++ scripts/bpf_doc.py | 2 + tools/include/uapi/linux/bpf.h | 8 + tools/testing/selftests/bpf/bpf_tcp_helpers.h | 31 ++ tools/testing/selftests/bpf/config | 3 + tools/testing/selftests/bpf/network_helpers.c | 43 +- tools/testing/selftests/bpf/network_helpers.h | 4 + .../testing/selftests/bpf/prog_tests/mptcp.c | 378 ++++++++++++++++++ .../selftests/bpf/progs/mptcp_bpf_first.c | 32 ++ .../testing/selftests/bpf/progs/mptcp_sock.c | 80 ++++ 25 files changed, 1009 insertions(+), 30 deletions(-) create mode 100644 net/mptcp/bpf.c create mode 100644 net/mptcp/sched.c create mode 100644 tools/testing/selftests/bpf/prog_tests/mptcp.c create mode 100644 tools/testing/selftests/bpf/progs/mptcp_bpf_first.c create mode 100644 tools/testing/selftests/bpf/progs/mptcp_sock.c
Signature · 1 line
2.34.1
PATCH 1/15 bpf: expose is_mptcp flag to bpf_tcp_sock
From: Nicolas Rybowski <[email protected]>
is_mptcp is a field from struct tcp_sock used to indicate that the current tcp_sock is part of the MPTCP protocol.
In this protocol, a first socket (mptcp_sock) is created with sk_protocol set to IPPROTO_MPTCP (=262) for control purpose but it isn't directly on the wire. This is the role of the subflow (kernel) sockets which are classical tcp_sock with sk_protocol set to IPPROTO_TCP. The only way to differentiate such sockets from plain TCP sockets is the is_mptcp field from tcp_sock.
Such an exposure in BPF is thus required to be able to differentiate plain TCP sockets from MPTCP subflow sockets in BPF_PROG_TYPE_SOCK_OPS programs.
The choice has been made to silently pass the case when CONFIG_MPTCP is unset by defaulting is_mptcp to 0 in order to make BPF independent of the MPTCP configuration. Another solution is to make the verifier fail in 'bpf_tcp_sock_is_valid_ctx_access' but this will add an additional '#ifdef CONFIG_MPTCP' in the BPF code and a same injected BPF program will not run if MPTCP is not set.
An example use-case is provided in
https://github.com/multipath-tcp/mptcp_net-next/tree/scripts/bpf/examples
--- include/uapi/linux/bpf.h | 1 + net/core/filter.c | 9 ++++++++- tools/include/uapi/linux/bpf.h | 1 + 3 files changed, 10 insertions(+), 1 deletion(-)
include/uapi/linux/bpf.h +1 -0
@@ -5706,6 +5706,7 @@ struct bpf_tcp_sock {__u32 delivered;/* Total data packets delivered incl. rexmits */ __u32 delivered_ce;/* Like the above but only ECE marked packets */ __u32 icsk_retransmits;/* Number of unrecovered [RTO] timeouts */ +__u32 is_mptcp;/* Is MPTCP subflow? */ };struct bpf_sock_tuple {
net/core/filter.c +8 -1
@@ -6754,7 +6754,7 @@ bool bpf_tcp_sock_is_valid_access(int off, int size, enum bpf_access_type type, struct bpf_insn_access_aux *info) { if (off < 0 || off >= offsetofend(struct bpf_tcp_sock, - icsk_retransmits)) + is_mptcp))return false;if (off % size !=0 )
@@ -6888,6 +6888,13 @@ u32 bpf_tcp_sock_convert_ctx_access(enum bpf_access_type type,case offsetof(struct bpf_tcp_sock , icsk_retransmits):BPF_INET_SOCK_GET_COMMON (icsk_retransmits);break ; +case offsetof(struct bpf_tcp_sock , is_mptcp): +#ifdef CONFIG_MPTCP +BPF_TCP_SOCK_GET_COMMON (is_mptcp); +#else + *insn++ =BPF_MOV32_IMM (si->dst_reg,0 ); +#endif +break ; }return insn - insn_buf;
tools/include/uapi/linux/bpf.h +1 -0
@@ -5706,6 +5706,7 @@ struct bpf_tcp_sock {__u32 delivered;/* Total data packets delivered incl. rexmits */ __u32 delivered_ce;/* Like the above but only ECE marked packets */ __u32 icsk_retransmits;/* Number of unrecovered [RTO] timeouts */ +__u32 is_mptcp;/* Is MPTCP subflow? */ };struct bpf_sock_tuple {
Signature · 1 line
2.34.1
PATCH 2/15 bpf: add bpf_skc_to_mptcp_sock_proto
In reply to Geliang TangThis patch implements a new struct bpf_func_proto, named bpf_skc_to_mptcp_sock_proto. Define a new bpf_id BTF_SOCK_TYPE_MPTCP, and a new helper bpf_skc_to_mptcp_sock(), which invokes another new helper bpf_mptcp_sock_from_subflow() in net/mptcp/bpf.c to get struct mptcp_sock from a given subflow socket.
v2: Emit BTF type, add func_id checks in verifier.c and bpf_trace.c, remove build check for CONFIG_BPF_JIT
--- include/linux/bpf.h | 1 + include/linux/btf_ids.h | 3 ++- include/net/mptcp.h | 6 ++++++ include/uapi/linux/bpf.h | 7 +++++++ kernel/bpf/verifier.c | 1 + kernel/trace/bpf_trace.c | 2 ++ net/core/filter.c | 18 ++++++++++++++++++ net/mptcp/Makefile | 2 ++ net/mptcp/bpf.c | 22 ++++++++++++++++++++++ scripts/bpf_doc.py | 2 ++ tools/include/uapi/linux/bpf.h | 7 +++++++ 11 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 net/mptcp/bpf.c
include/linux/bpf.h +1 -0
@@ -2204,6 +2204,7 @@ extern const struct bpf_func_proto bpf_skc_to_tcp_timewait_sock_proto;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_copy_from_user_proto;extern const struct bpf_func_proto bpf_snprintf_btf_proto;extern const struct bpf_func_proto bpf_snprintf_proto;
include/linux/btf_ids.h +2 -1
@@ -178,7 +178,8 @@ extern struct btf_id_set name; BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP6, tcp6_sock) \ BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP, udp_sock) \ BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP6, udp6_sock) \ - BTF_SOCK_TYPE(BTF_SOCK_TYPE_UNIX, unix_sock) + BTF_SOCK_TYPE(BTF_SOCK_TYPE_UNIX, unix_sock) \ + BTF_SOCK_TYPE(BTF_SOCK_TYPE_MPTCP, mptcp_sock) enum {#define BTF_SOCK_TYPE (name, str) name,
include/net/mptcp.h +6 -0
@@ -284,4 +284,10 @@ static inline int mptcpv6_init(void) { return 0; }static inline void mptcpv6_handle_mapped (struct sock *sk,bool mapped) { }#endif +#if defined(CONFIG_MPTCP ) && defined(CONFIG_BPF_SYSCALL ) +struct mptcp_sock *bpf_mptcp_sock_from_subflow (struct sock *sk); +#else +static inline struct mptcp_sock *bpf_mptcp_sock_from_subflow (struct sock *sk) {return NULL ; } +#endif +#endif /* __NET_MPTCP_H */
include/uapi/linux/bpf.h +7 -0
@@ -5154,6 +5154,12 @@ union bpf_attr {* if not NULL, is a reference which must be released using its * corresponding release function, or moved into a BPF map before * program exit. +* +* struct mptcp_sock *bpf_skc_to_mptcp_sock(void *sk) +* Description +* Dynamically cast a *sk* pointer to a *mptcp_sock* pointer. +* Return +* *sk* if casting is valid, or **NULL** otherwise. */ #define __BPF_FUNC_MAPPER (FN ) \ FN(unspec), \
@@ -5351,6 +5357,7 @@ union bpf_attr {FN (skb_set_tstamp), \FN (ima_file_hash), \FN (kptr_xchg), \ +FN (skc_to_mptcp_sock), \/* */ /* integer value in 'imm' field of BPF_CALL instruction selects which helper
kernel/bpf/verifier.c +1 -0
@@ -509,6 +509,7 @@ static bool is_ptr_cast_function(enum bpf_func_id func_id) func_id == BPF_FUNC_skc_to_tcp_sock || func_id == BPF_FUNC_skc_to_tcp6_sock || func_id == BPF_FUNC_skc_to_udp6_sock || + func_id == BPF_FUNC_skc_to_mptcp_sock || func_id == BPF_FUNC_skc_to_tcp_timewait_sock || func_id == BPF_FUNC_skc_to_tcp_request_sock; }
kernel/trace/bpf_trace.c +2 -0
@@ -1688,6 +1688,8 @@ tracing_prog_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)return &bpf_skc_to_udp6_sock_proto;case BPF_FUNC_skc_to_unix_sock:return &bpf_skc_to_unix_sock_proto; +case BPF_FUNC_skc_to_mptcp_sock: +return &bpf_skc_to_mptcp_sock_proto;case BPF_FUNC_sk_storage_get:return &bpf_sk_storage_get_tracing_proto;case BPF_FUNC_sk_storage_delete:
net/core/filter.c +18 -0
@@ -78,6 +78,7 @@#include <linux/btf_ids.h> #include <net/tls.h> #include <net/xdp.h> +#include <net/mptcp.h> static const struct bpf_func_proto *bpf_sk_base_func_proto (enum bpf_func_id func_id);
@@ -11279,6 +11280,20 @@ const struct bpf_func_proto bpf_skc_to_unix_sock_proto = { .ret_btf_id = &btf_sock_ids[BTF_SOCK_TYPE_UNIX], }; +BPF_CALL_1(bpf_skc_to_mptcp_sock, struct sock *, sk) +{ +BTF_TYPE_EMIT (struct mptcp_sock ); +return (unsigned long )bpf_mptcp_sock_from_subflow (sk); +} + +const struct bpf_func_proto bpf_skc_to_mptcp_sock_proto = { + .func = bpf_skc_to_mptcp_sock, + .gpl_only = false, + .ret_type =RET_PTR_TO_BTF_ID_OR_NULL , + .arg1_type =ARG_PTR_TO_SOCK_COMMON , + .ret_btf_id = &btf_sock_ids[BTF_SOCK_TYPE_MPTCP ], +}; + BPF_CALL_1(bpf_sock_from_file, struct file *, file) {return (unsigned long )sock_from_file (file);
@@ -11321,6 +11336,9 @@ bpf_sk_base_func_proto(enum bpf_func_id func_id)case BPF_FUNC_skc_to_unix_sock: func = &bpf_skc_to_unix_sock_proto;break ; +case BPF_FUNC_skc_to_mptcp_sock: + func = &bpf_skc_to_mptcp_sock_proto; +break ;case BPF_FUNC_ktime_get_coarse_ns:return &bpf_ktime_get_coarse_ns_proto;default :
net/mptcp/Makefile +2 -0
@@ -10,3 +10,5 @@ obj-$(CONFIG_INET_MPTCP_DIAG) += mptcp_diag.o mptcp_crypto_test-objs := crypto_test.o mptcp_token_test-objs := token_test.o obj-$(CONFIG_MPTCP_KUNIT_TEST) += mptcp_crypto_test.o mptcp_token_test.o + +obj-$(CONFIG_BPF_SYSCALL) += bpf.o
net/mptcp/bpf.c new file +22 -0
@@ -0,0 +1,22 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Multipath TCP +* +* Copyright (c) 2020, Tessares SA. +* Copyright (c) 2022, SUSE. +* +* Author: Nicolas Rybowski <[email protected]> +*/ + +#define pr_fmt (fmt) "MPTCP: " fmt + +#include <linux/bpf.h> +#include "protocol.h" + +struct mptcp_sock *bpf_mptcp_sock_from_subflow (struct sock *sk) +{ +if (sk &&sk_fullsock (sk) && sk->sk_protocol ==IPPROTO_TCP &&sk_is_mptcp (sk)) +return mptcp_sk (mptcp_subflow_ctx (sk)->conn); + +return NULL ; +} +EXPORT_SYMBOL (bpf_mptcp_sock_from_subflow);
scripts/bpf_doc.py +2 -0
@@ -633,6 +633,7 @@ class PrinterHelpers(Printer): 'struct socket', 'struct file', 'struct bpf_timer', + 'struct mptcp_sock', ] known_types = { '...',
@@ -682,6 +683,7 @@ class PrinterHelpers(Printer): 'struct socket', 'struct file', 'struct bpf_timer', + 'struct mptcp_sock', } mapped_types = { 'u8': '__u8',
tools/include/uapi/linux/bpf.h +7 -0
@@ -5154,6 +5154,12 @@ union bpf_attr {* if not NULL, is a reference which must be released using its * corresponding release function, or moved into a BPF map before * program exit. +* +* struct mptcp_sock *bpf_skc_to_mptcp_sock(void *sk) +* Description +* Dynamically cast a *sk* pointer to a *mptcp_sock* pointer. +* Return +* *sk* if casting is valid, or **NULL** otherwise. */ #define __BPF_FUNC_MAPPER (FN ) \ FN(unspec), \
@@ -5351,6 +5357,7 @@ union bpf_attr {FN (skb_set_tstamp), \FN (ima_file_hash), \FN (kptr_xchg), \ +FN (skc_to_mptcp_sock), \/* */ /* integer value in 'imm' field of BPF_CALL instruction selects which helper
Signature · 1 line
2.34.1
PATCH 3/15 selftests/bpf: Enable CONFIG_IKCONFIG_PROC in config
In reply to Geliang TangCONFIG_IKCONFIG_PROC is required by BPF selftests, otherwise we get errors like this:
libbpf: failed to open system Kconfig
libbpf: failed to load object 'kprobe_multi'
libbpf: failed to load BPF skeleton 'kprobe_multi': -22
It's because /proc/config.gz is opened in bpf_object__read_kconfig_file() in tools/lib/bpf/libbpf.c:
file = gzopen("/proc/config.gz", "r");So this patch enables CONFIG_IKCONFIG and CONFIG_IKCONFIG_PROC in tools/testing/selftests/bpf/config.
--- tools/testing/selftests/bpf/config | 2 ++ 1 file changed, 2 insertions(+)
tools/testing/selftests/bpf/config +2 -0
@@ -53,3 +53,5 @@ CONFIG_NF_DEFRAG_IPV4=y CONFIG_NF_DEFRAG_IPV6=y CONFIG_NF_CONNTRACK=y CONFIG_USERFAULTFD=y +CONFIG_IKCONFIG=y +CONFIG_IKCONFIG_PROC=y
Signature · 1 line
2.34.1
PATCH 4/15 selftests/bpf: add MPTCP test base
In reply to Geliang TangFrom: Nicolas Rybowski <[email protected]>
This patch adds a base for MPTCP specific tests.
It is currently limited to the is_mptcp field in case of plain TCP connection because there is no easy way to get the subflow sk from a msk in userspace. This implies that we cannot lookup the sk_storage attached to the subflow sk in the sockops program.
v4:
- add copyright 2022 (Andrii)
- use ASSERT_* instead of CHECK_FAIL (Andrii)
- drop SEC("version") (Andrii)
--- MAINTAINERS | 1 + tools/testing/selftests/bpf/config | 1 + tools/testing/selftests/bpf/network_helpers.c | 43 ++++-- tools/testing/selftests/bpf/network_helpers.h | 4 + .../testing/selftests/bpf/prog_tests/mptcp.c | 136 ++++++++++++++++++ .../testing/selftests/bpf/progs/mptcp_sock.c | 50 +++++++ 6 files changed, 227 insertions(+), 8 deletions(-) create mode 100644 tools/testing/selftests/bpf/prog_tests/mptcp.c create mode 100644 tools/testing/selftests/bpf/progs/mptcp_sock.c
MAINTAINERS +1 -0
@@ -13798,6 +13798,7 @@ F: include/net/mptcp.h F: include/trace/events/mptcp.h F: include/uapi/linux/mptcp.h F: net/mptcp/ +F: tools/testing/selftests/bpf/*/*mptcp*.c F: tools/testing/selftests/net/mptcp/ NETWORKING [TCP]
tools/testing/selftests/bpf/config +1 -0
@@ -55,3 +55,4 @@ CONFIG_NF_CONNTRACK=y CONFIG_USERFAULTFD=y CONFIG_IKCONFIG=y CONFIG_IKCONFIG_PROC=y +CONFIG_MPTCP=y
tools/testing/selftests/bpf/network_helpers.c +35 -8
99 lines not on this page · raw message
tools/testing/selftests/bpf/network_helpers.h +4 -0
@@ -21,6 +21,7 @@ struct network_helper_opts {const char *cc;int timeout_ms;bool must_fail; +int protocol; };/* ipv4 test vector */
@@ -42,11 +43,14 @@ extern struct ipv6_packet pkt_v6;int settimeo (int fd,int timeout_ms);int start_server (int family,int type,const char *addr,__u16 port,int timeout_ms); +int start_mptcp_server (int family,const char *addr,__u16 port, +int timeout_ms);int *start_reuseport_server (int family,int type,const char *addr_str,__u16 port,int timeout_ms,unsigned int nr_listens);void free_fds (int *fds,unsigned int nr_close_fds);int connect_to_fd (int server_fd,int timeout_ms); +int connect_to_mptcp_fd (int server_fd,int timeout_ms);int connect_to_fd_opts (int server_fd,const struct network_helper_opts *opts);int connect_fd_to_fd (int client_fd,int server_fd,int timeout_ms); int fastopen_connect(int server_fd, const char *data, unsigned int data_len,
tools/testing/selftests/bpf/prog_tests/mptcp.c new file +136 -0
136 lines not on this page · raw message
tools/testing/selftests/bpf/progs/mptcp_sock.c new file +50 -0
50 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH 5/15 selftests/bpf: test bpf_skc_to_mptcp_sock
In reply to Geliang TangThis patch extends the MPTCP test base, to test the new helper bpf_skc_to_mptcp_sock().
Define struct mptcp_sock in bpf_tcp_helpers.h, use bpf_skc_to_mptcp_sock to get the msk socket in progs/mptcp_sock.c and store the infos in socket_storage_map.
Get the infos from socket_storage_map in prog_tests/mptcp.c. Add a new function verify_msk() to verify the infos of MPTCP socket, and rename verify_sk() to verify_tsk() to verify TCP socket only.
v2: Add CONFIG_MPTCP check for clearer error messages v4:
- use ASSERT_* instead of CHECK_FAIL (Andrii)
- drop bpf_mptcp_helpers.h (Andrii)
--- tools/testing/selftests/bpf/bpf_tcp_helpers.h | 5 +++ .../testing/selftests/bpf/prog_tests/mptcp.c | 45 ++++++++++++++----- .../testing/selftests/bpf/progs/mptcp_sock.c | 24 ++++++++-- 3 files changed, 59 insertions(+), 15 deletions(-)
tools/testing/selftests/bpf/bpf_tcp_helpers.h +5 -0
@@ -225,4 +225,9 @@ static __always_inline bool tcp_cc_eq(const char *a, const char *b) extern __u32 tcp_slow_start(struct tcp_sock *tp, __u32 acked) __ksym; extern void tcp_cong_avoid_ai(struct tcp_sock *tp, __u32 w, __u32 acked) __ksym; +struct mptcp_sock { +struct inet_connection_sock sk; + +} __attribute__((preserve_access_index)); +#endif
tools/testing/selftests/bpf/prog_tests/mptcp.c +34 -11
87 lines not on this page · raw message
tools/testing/selftests/bpf/progs/mptcp_sock.c +20 -4
@@ -4,8 +4,10 @@#include <linux/bpf.h> #include <bpf/bpf_helpers.h> +#include "bpf_tcp_helpers.h" char _license[] SEC("license") = "GPL"; +extern bool CONFIG_MPTCP __kconfig;struct mptcp_storage {__u32 invoked;
@@ -24,6 +26,7 @@ int _sockops(struct bpf_sock_ops *ctx) {struct mptcp_storage *storage;struct bpf_tcp_sock *tcp_sk; +struct mptcp_sock *msk;int op = (int )ctx->op;struct bpf_sock *sk;
@@ -38,11 +41,24 @@ int _sockops(struct bpf_sock_ops *ctx)if (!tcp_sk)return 1 ; - storage =bpf_sk_storage_get (&socket_storage_map, sk,0 , -BPF_SK_STORAGE_GET_F_CREATE ); -if (!storage) -return 1 ; +if (!tcp_sk->is_mptcp) { + storage =bpf_sk_storage_get (&socket_storage_map, sk,0 , +BPF_SK_STORAGE_GET_F_CREATE ); +if (!storage) +return 1 ; + }else { +if (!CONFIG_MPTCP ) +return 1 ; + + msk =bpf_skc_to_mptcp_sock (sk); +if (!msk) +return 1 ; + storage =bpf_sk_storage_get (&socket_storage_map, msk,0 , +BPF_SK_STORAGE_GET_F_CREATE ); +if (!storage) +return 1 ; + } storage->invoked++; storage->is_mptcp = tcp_sk->is_mptcp;
Signature · 1 line
2.34.1
PATCH 6/15 selftests/bpf: verify token of struct mptcp_sock
In reply to Geliang TangThis patch verifies the struct member token of struct mptcp_sock. Add a new function get_msk_token() to parse the msk token from the output of the command 'ip mptcp monitor', and verify it in verify_msk().
v4:
- use ASSERT_* instead of CHECK_FAIL (Andrii)
- skip the test if 'ip mptcp monitor' is not supported (Mat)
--- tools/testing/selftests/bpf/bpf_tcp_helpers.h | 1 + .../testing/selftests/bpf/prog_tests/mptcp.c | 64 +++++++++++++++++++ .../testing/selftests/bpf/progs/mptcp_sock.c | 5 ++ 3 files changed, 70 insertions(+)
tools/testing/selftests/bpf/bpf_tcp_helpers.h +1 -0
@@ -228,6 +228,7 @@ extern void tcp_cong_avoid_ai(struct tcp_sock *tp, __u32 w, __u32 acked) __ksym;struct mptcp_sock {struct inet_connection_sock sk; +__u32 token; } __attribute__((preserve_access_index));#endif
tools/testing/selftests/bpf/prog_tests/mptcp.c +64 -0
107 lines not on this page · raw message
tools/testing/selftests/bpf/progs/mptcp_sock.c +5 -0
@@ -12,6 +12,7 @@ extern bool CONFIG_MPTCP __kconfig;struct mptcp_storage {__u32 invoked;__u32 is_mptcp; +__u32 token; };struct {
@@ -46,6 +47,8 @@ int _sockops(struct bpf_sock_ops *ctx) BPF_SK_STORAGE_GET_F_CREATE);if (!storage)return 1 ; + + storage->token =0 ; }else {if (!CONFIG_MPTCP )return 1 ;
@@ -58,6 +61,8 @@ int _sockops(struct bpf_sock_ops *ctx) BPF_SK_STORAGE_GET_F_CREATE);if (!storage)return 1 ; + + storage->token = msk->token; } storage->invoked++; storage->is_mptcp = tcp_sk->is_mptcp;
Signature · 1 line
2.34.1
PATCH 7/15 selftests/bpf: verify ca_name of struct mptcp_sock
In reply to Geliang TangThis patch verifies another member of struct mptcp_sock, ca_name. Add a new function get_msk_ca_name() to read the sysctl tcp_congestion_control and verify it in verify_msk().
v3: Access the sysctl through the filesystem to avoid compatibility
issues with the busybox sysctl command.
v4: use ASSERT_* instead of CHECK_FAIL (Andrii)
--- tools/testing/selftests/bpf/bpf_tcp_helpers.h | 5 +++ .../testing/selftests/bpf/prog_tests/mptcp.c | 34 +++++++++++++++++++ .../testing/selftests/bpf/progs/mptcp_sock.c | 4 +++ 3 files changed, 43 insertions(+)
tools/testing/selftests/bpf/bpf_tcp_helpers.h +5 -0
@@ -16,6 +16,10 @@ BPF_PROG(name, args)#define SOL_TCP 6#endif +#ifndef TCP_CA_NAME_MAX +#define TCP_CA_NAME_MAX 16 +#endif +#define tcp_jiffies32 ((__u32)bpf_jiffies64())struct sock_common {
@@ -229,6 +233,7 @@ struct mptcp_sock {struct inet_connection_sock sk;__u32 token; +char ca_name[TCP_CA_NAME_MAX ]; } __attribute__((preserve_access_index));#endif
tools/testing/selftests/bpf/prog_tests/mptcp.c +34 -0
@@ -6,10 +6,15 @@#include "cgroup_helpers.h" #include "network_helpers.h" +#ifndef TCP_CA_NAME_MAX +#define TCP_CA_NAME_MAX 16 +#endif +struct mptcp_storage {__u32 invoked;__u32 is_mptcp;__u32 token; +char ca_name[TCP_CA_NAME_MAX ]; };static char monitor_log_path[64 ];
@@ -75,17 +80,40 @@ static __u32 get_msk_token(void)return token; } +void get_msk_ca_name (char ca_name[]) +{ +size_t len; +int fd; + + fd =open ("/proc/sys/net/ipv4/tcp_congestion_control" ,O_RDONLY ); +if (!ASSERT_GE (fd,0 ,"Failed to open tcp_congestion_control" )) +return ; + + len =read (fd, ca_name,TCP_CA_NAME_MAX ); +if (!ASSERT_GT (len,0 ,"Failed to read ca_name" )) + goto err; + +if (len >0 && ca_name[len -1 ] =='\n' ) + ca_name[len -1 ] ='\0' ; + +err: +close (fd); +} +static int verify_msk (int map_fd,int client_fd) {char *msg ="MPTCP subflow socket" ;int err, cfd = client_fd;struct mptcp_storage val; +char ca_name[TCP_CA_NAME_MAX ];__u32 token; token =get_msk_token ();if (!ASSERT_GT (token,0 ,"Unexpected token" ))return -1 ; +get_msk_ca_name (ca_name); + err =bpf_map_lookup_elem (map_fd, &cfd, &val);if (!ASSERT_OK (err,"bpf_map_lookup_elem" ))return err;
@@ -108,6 +136,12 @@ static int verify_msk(int map_fd, int client_fd) err++; } +if (strncmp (val.ca_name, ca_name,TCP_CA_NAME_MAX )) { +log_err ("Unexpected mptcp_sock.ca_name %s != %s" , + val.ca_name, ca_name); + err++; + } +return err; }
tools/testing/selftests/bpf/progs/mptcp_sock.c +4 -0
@@ -2,6 +2,7 @@/* Copyright (c) 2020, Tessares SA. */ /* Copyright (c) 2022, SUSE. */ +#include <string.h> #include <linux/bpf.h> #include <bpf/bpf_helpers.h> #include "bpf_tcp_helpers.h"
@@ -13,6 +14,7 @@ struct mptcp_storage {__u32 invoked;__u32 is_mptcp;__u32 token; +char ca_name[TCP_CA_NAME_MAX ]; };struct {
@@ -49,6 +51,7 @@ int _sockops(struct bpf_sock_ops *ctx)return 1 ; storage->token =0 ; +bzero (storage->ca_name,TCP_CA_NAME_MAX ); }else {if (!CONFIG_MPTCP )return 1 ;
@@ -63,6 +66,7 @@ int _sockops(struct bpf_sock_ops *ctx)return 1 ; storage->token = msk->token; +memcpy (storage->ca_name, msk->ca_name,TCP_CA_NAME_MAX ); } storage->invoked++; storage->is_mptcp = tcp_sk->is_mptcp;
Signature · 1 line
2.34.1
PATCH 8/15 selftests/bpf: verify first of struct mptcp_sock
In reply to Geliang TangThis patch verifies the 'first' struct member of struct mptcp_sock, which points to the first subflow of msk. Save 'sk' in mptcp_storage, and verify it with 'first' in verify_msk().
--- tools/testing/selftests/bpf/bpf_tcp_helpers.h | 1 + tools/testing/selftests/bpf/prog_tests/mptcp.c | 8 ++++++++ tools/testing/selftests/bpf/progs/mptcp_sock.c | 5 +++++ 3 files changed, 14 insertions(+)
tools/testing/selftests/bpf/bpf_tcp_helpers.h +1 -0
@@ -233,6 +233,7 @@ struct mptcp_sock {struct inet_connection_sock sk;__u32 token; +struct sock *first;char ca_name[TCP_CA_NAME_MAX ]; } __attribute__((preserve_access_index));
tools/testing/selftests/bpf/prog_tests/mptcp.c +8 -0
@@ -13,7 +13,9 @@struct mptcp_storage {__u32 invoked;__u32 is_mptcp; +struct sock *sk;__u32 token; +struct sock *first;char ca_name[TCP_CA_NAME_MAX ]; };
@@ -136,6 +138,12 @@ static int verify_msk(int map_fd, int client_fd) err++; } +if (val.first != val.sk) { +log_err ("Unexpected mptcp_sock.first %p != %p" , + val.first, val.sk); + err++; + } +if (strncmp (val.ca_name, ca_name,TCP_CA_NAME_MAX )) {log_err ("Unexpected mptcp_sock.ca_name %s != %s" , val.ca_name, ca_name);
tools/testing/selftests/bpf/progs/mptcp_sock.c +5 -0
@@ -13,7 +13,9 @@ extern bool CONFIG_MPTCP __kconfig;struct mptcp_storage {__u32 invoked;__u32 is_mptcp; +struct sock *sk;__u32 token; +struct sock *first;char ca_name[TCP_CA_NAME_MAX ]; };
@@ -52,6 +54,7 @@ int _sockops(struct bpf_sock_ops *ctx) storage->token =0 ;bzero (storage->ca_name,TCP_CA_NAME_MAX ); + storage->first =NULL ; }else {if (!CONFIG_MPTCP )return 1 ;
@@ -67,9 +70,11 @@ int _sockops(struct bpf_sock_ops *ctx) storage->token = msk->token;memcpy (storage->ca_name, msk->ca_name,TCP_CA_NAME_MAX ); + storage->first = msk->first; } storage->invoked++; storage->is_mptcp = tcp_sk->is_mptcp; + storage->sk = (struct sock *)sk;return 1 ; }
Signature · 1 line
2.34.1
PATCH 9/15 mptcp: add struct mptcp_sched_ops
In reply to Geliang TangThis patch defines struct mptcp_sched_ops, which has three struct members, name, owner and list, and three function pointers, init, release and get_subflow.
Add the scheduler registering, unregistering and finding functions to add, delete and find a packet scheduler on the global list mptcp_sched_list.
For supporting a "redundant" packet scheduler in the future, this patch adds a flag in struct mptcp_sched_data named call_again to indicate that get_subflow() function needs to be called again.
--- include/net/mptcp.h | 19 +++++++ net/mptcp/Makefile | 2 +- net/mptcp/protocol.h | 3 + net/mptcp/sched.c | 56 +++++++++++++++++++ tools/testing/selftests/bpf/bpf_tcp_helpers.h | 18 ++++++ 5 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 net/mptcp/sched.c
include/net/mptcp.h +19 -0
@@ -95,6 +95,25 @@ struct mptcp_out_options {#endif }; +#define MPTCP_SCHED_NAME_MAX 16 + +struct mptcp_sched_data { +struct sock *sock; +bool call_again; +}; + +struct mptcp_sched_ops { +void (*get_subflow)(const struct mptcp_sock *msk,bool reinject, +struct mptcp_sched_data *data); + +char name[MPTCP_SCHED_NAME_MAX ]; +struct module *owner; +struct list_head list; + +void (*init)(const struct mptcp_sock *msk); +void (*release)(const struct mptcp_sock *msk); +}____cacheline_aligned_in_smp ; +#ifdef CONFIG_MPTCP extern struct request_sock_ops mptcp_subflow_request_sock_ops;
net/mptcp/Makefile +1 -1
@@ -2,7 +2,7 @@ obj-$(CONFIG_MPTCP) += mptcp.o mptcp-y := protocol.o subflow.o options.o token.o crypto.o ctrl.o pm.o diag.o \ - mib.o pm_netlink.o sockopt.o pm_userspace.o + mib.o pm_netlink.o sockopt.o pm_userspace.o sched.o obj-$(CONFIG_SYN_COOKIES) += syncookies.o obj-$(CONFIG_INET_MPTCP_DIAG) += mptcp_diag.o
net/mptcp/protocol.h +3 -0
@@ -621,6 +621,9 @@ int mptcp_subflow_create_socket(struct sock *sk, struct socket **new_sock);void mptcp_info2sockaddr (const struct mptcp_addr_info *info,struct sockaddr_storage *addr,unsigned short family); +struct mptcp_sched_ops *mptcp_sched_find (const char *name); +int mptcp_register_scheduler (struct mptcp_sched_ops *sched); +void mptcp_unregister_scheduler (struct mptcp_sched_ops *sched);static inline bool __mptcp_subflow_active (struct mptcp_subflow_context *subflow) {
net/mptcp/sched.c new file +56 -0
56 lines not on this page · raw message
tools/testing/selftests/bpf/bpf_tcp_helpers.h +18 -0
@@ -229,6 +229,24 @@ static __always_inline bool tcp_cc_eq(const char *a, const char *b) extern __u32 tcp_slow_start(struct tcp_sock *tp, __u32 acked) __ksym; extern void tcp_cong_avoid_ai(struct tcp_sock *tp, __u32 w, __u32 acked) __ksym; +#define MPTCP_SCHED_NAME_MAX 16 + +struct mptcp_sched_data { +struct sock *sock; +bool call_again; +}; + +struct mptcp_sched_ops { +char name[MPTCP_SCHED_NAME_MAX ]; + +void (*init)(const struct mptcp_sock *msk); +void (*release)(const struct mptcp_sock *msk); + +void (*get_subflow)(const struct mptcp_sock *msk,bool reinject, +struct mptcp_sched_data *data); +void *owner; +}; +struct mptcp_sock {struct inet_connection_sock sk;
Signature · 1 line
2.34.1
PATCH 10/15 mptcp: add a new sysctl scheduler
In reply to Geliang TangThis patch adds a new sysctl, named scheduler, to support for selection of different schedulers. Export mptcp_get_scheduler helper to get this sysctl.
--- Documentation/networking/mptcp-sysctl.rst | 8 ++++++++ net/mptcp/ctrl.c | 14 ++++++++++++++ net/mptcp/protocol.h | 1 + 3 files changed, 23 insertions(+)
Documentation/networking/mptcp-sysctl.rst +8 -0
@@ -75,3 +75,11 @@ stale_loss_cnt - INTEGER This is a per-namespace sysctl. Default: 4 + +scheduler - STRING + Select the scheduler of your choice. + + Support for selection of different schedulers. This is a per-namespace + sysctl. + + Default: "default"
net/mptcp/ctrl.c +14 -0
@@ -32,6 +32,7 @@ struct mptcp_pernet {u8 checksum_enabled;u8 allow_join_initial_addr_port;u8 pm_type; +char scheduler[MPTCP_SCHED_NAME_MAX ]; };static struct mptcp_pernet *mptcp_get_pernet (const struct net *net)
@@ -69,6 +70,11 @@ int mptcp_get_pm_type(const struct net *net)return mptcp_get_pernet (net)->pm_type; } +const char *mptcp_get_scheduler (const struct net *net) +{ +return mptcp_get_pernet (net)->scheduler; +} +static void mptcp_pernet_set_defaults (struct mptcp_pernet *pernet) { pernet->mptcp_enabled =1 ;
@@ -77,6 +83,7 @@ static void mptcp_pernet_set_defaults(struct mptcp_pernet *pernet) pernet->allow_join_initial_addr_port =1 ; pernet->stale_loss_cnt =4 ; pernet->pm_type =MPTCP_PM_TYPE_KERNEL ; +strcpy (pernet->scheduler,"default" ); }#ifdef CONFIG_SYSCTL
@@ -128,6 +135,12 @@ static struct ctl_table mptcp_sysctl_table[] = { .extra1 = SYSCTL_ZERO, .extra2 = &mptcp_pm_type_max }, + { + .procname = "scheduler", + .maxlen = MPTCP_SCHED_NAME_MAX, + .mode = 0644, + .proc_handler = proc_dostring, + }, {} };
@@ -149,6 +162,7 @@ static int mptcp_pernet_new_table(struct net *net, struct mptcp_pernet *pernet) table[3 ].data = &pernet->allow_join_initial_addr_port; table[4 ].data = &pernet->stale_loss_cnt; table[5 ].data = &pernet->pm_type; + table[6 ].data = &pernet->scheduler; hdr =register_net_sysctl (net,MPTCP_SYSCTL_PATH , table);if (!hdr)
net/mptcp/protocol.h +1 -0
@@ -596,6 +596,7 @@ int mptcp_is_checksum_enabled(const struct net *net);int mptcp_allow_join_id0 (const struct net *net);unsigned int mptcp_stale_loss_cnt (const struct net *net);int mptcp_get_pm_type (const struct net *net); +const char *mptcp_get_scheduler (const struct net *net);void mptcp_subflow_fully_established (struct mptcp_subflow_context *subflow,struct mptcp_options_received *mp_opt);bool __mptcp_retransmit_pending_data (struct sock *sk);
Signature · 1 line
2.34.1
PATCH 11/15 mptcp: add sched in mptcp_sock
In reply to Geliang TangThis patch adds a new struct member sched in struct mptcp_sock. And two helpers mptcp_init_sched() and mptcp_release_sched() to init and release it.
Init it with the sysctl scheduler in mptcp_init_sock(), copy the scheduler from the parent in mptcp_sk_clone(), and release it in __mptcp_destroy_sock().
--- net/mptcp/protocol.c | 7 ++++ net/mptcp/protocol.h | 4 +++ net/mptcp/sched.c | 33 +++++++++++++++++++ tools/testing/selftests/bpf/bpf_tcp_helpers.h | 1 + 4 files changed, 45 insertions(+)
net/mptcp/protocol.c +7 -0
@@ -2657,6 +2657,11 @@ static int mptcp_init_sock(struct sock *sk)if (ret)return ret; + ret =mptcp_init_sched (mptcp_sk (sk), +mptcp_sched_find (mptcp_get_scheduler (net))); +if (ret) +return ret; +/* fetch the ca name; do it outside __mptcp_init_sock(), so that clone will * propagate the correct value */
@@ -2812,6 +2817,7 @@ static void __mptcp_destroy_sock(struct sock *sk)mptcp_stop_timer (sk);sk_stop_timer (sk, &sk->sk_timer); msk->pm.status =0 ; +mptcp_release_sched (msk);/* clears msk->subflow, allowing the following loop to close * even the initial subflow
@@ -2985,6 +2991,7 @@ struct sock *mptcp_sk_clone(const struct sock *sk, msk->snd_una = msk->write_seq; msk->wnd_end = msk->snd_nxt + req->rsk_rcv_wnd; msk->setsockopt_seq =mptcp_sk (sk)->setsockopt_seq; +mptcp_init_sched (msk,mptcp_sk (sk)->sched);if (mp_opt->suboptions &OPTIONS_MPTCP_MPC ) { msk->can_ack = true;
net/mptcp/protocol.h +4 -0
@@ -298,6 +298,7 @@ struct mptcp_sock {struct socket *subflow;/* outgoing connect/listener/!mp_capable */ struct sock *first;struct mptcp_pm_data pm; +struct mptcp_sched_ops *sched;struct {u32 space;/* bytes copied in last measurement window */ u32 copied;/* bytes copied in this measurement window */
@@ -625,6 +626,9 @@ void mptcp_info2sockaddr(const struct mptcp_addr_info *info,struct mptcp_sched_ops *mptcp_sched_find (const char *name);int mptcp_register_scheduler (struct mptcp_sched_ops *sched);void mptcp_unregister_scheduler (struct mptcp_sched_ops *sched); +int mptcp_init_sched (struct mptcp_sock *msk, +struct mptcp_sched_ops *sched); +void mptcp_release_sched (struct mptcp_sock *msk);static inline bool __mptcp_subflow_active (struct mptcp_subflow_context *subflow) {
net/mptcp/sched.c +33 -0
@@ -54,3 +54,36 @@ void mptcp_unregister_scheduler(struct mptcp_sched_ops *sched)list_del_rcu (&sched->list);spin_unlock (&mptcp_sched_list_lock); } + +int mptcp_init_sched (struct mptcp_sock *msk, +struct mptcp_sched_ops *sched) +{ +if (!sched) + goto out; + +if (!bpf_try_module_get (sched, sched->owner)) +return -EBUSY ; + + msk->sched = sched; +if (msk->sched->init) + msk->sched->init (msk); + +pr_debug ("sched=%s" , msk->sched->name); + +out: +return 0 ; +} + +void mptcp_release_sched (struct mptcp_sock *msk) +{ +struct mptcp_sched_ops *sched = msk->sched; + +if (!sched) +return ; + + msk->sched =NULL ; +if (sched->release) + sched->release (msk); + +bpf_module_put (sched, sched->owner); +}
tools/testing/selftests/bpf/bpf_tcp_helpers.h +1 -0
@@ -252,6 +252,7 @@ struct mptcp_sock {__u32 token;struct sock *first; +struct mptcp_sched_ops *sched;char ca_name[TCP_CA_NAME_MAX ]; } __attribute__((preserve_access_index));
Signature · 1 line
2.34.1
PATCH 12/15 mptcp: add get_subflow wrappers
In reply to Geliang TangThis patch defines two new wrappers mptcp_sched_get_send() and mptcp_sched_get_retrans(), invoke get_subflow() of msk->sched in them. Use them instead of using mptcp_subflow_get_send() or mptcp_subflow_get_retrans() directly.
--- net/mptcp/protocol.c | 25 +++++---------------- net/mptcp/protocol.h | 4 ++++ net/mptcp/sched.c | 52 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 19 deletions(-)
net/mptcp/protocol.c +6 -19
@@ -1427,7 +1427,7 @@ bool mptcp_subflow_active(struct mptcp_subflow_context *subflow)* returns the subflow that will transmit the next DSS * additionally updates the rtx timeout */ -static struct sock *mptcp_subflow_get_send (struct mptcp_sock *msk) +struct sock *mptcp_subflow_get_send (struct mptcp_sock *msk) {struct subflow_send_info send_info[SSK_MODE_MAX ];struct mptcp_subflow_context *subflow;
@@ -1438,14 +1438,6 @@ static struct sock *mptcp_subflow_get_send(struct mptcp_sock *msk)u64 linger_time;long tout =0 ; -sock_owned_by_me (sk); - -if (__mptcp_check_fallback (msk)) { -if (!msk->first) -return NULL ; -return sk_stream_memory_free (msk->first) ? msk->first :NULL ; - } -/* re-use last subflow, if the burst allow that */ if (msk->last_snd && msk->snd_burst > 0 && sk_stream_memory_free(msk->last_snd) &&
@@ -1575,7 +1567,7 @@ void __mptcp_push_pending(struct sock *sk, unsigned int flags)int ret =0 ; prev_ssk = ssk; - ssk =mptcp_subflow_get_send (msk); + ssk =mptcp_sched_get_send (msk);/* First check. If the ssk has changed since * the last round, release prev_ssk
@@ -1642,7 +1634,7 @@ static void __mptcp_subflow_push_pending(struct sock *sk, struct sock *ssk)* check for a different subflow usage only after * spooling the first chunk of data */ - xmit_ssk = first ? ssk :mptcp_subflow_get_send (mptcp_sk (sk)); + xmit_ssk = first ? ssk :mptcp_sched_get_send (mptcp_sk (sk));if (!xmit_ssk) goto out;if (xmit_ssk != ssk) {
@@ -2216,17 +2208,12 @@ static void mptcp_timeout_timer(struct timer_list *t)* * A backup subflow is returned only if that is the only kind available. */ -static struct sock *mptcp_subflow_get_retrans (struct mptcp_sock *msk) +struct sock *mptcp_subflow_get_retrans (struct mptcp_sock *msk) {struct sock *backup =NULL , *pick =NULL ;struct mptcp_subflow_context *subflow;int min_stale_count =INT_MAX ; -sock_owned_by_me ((const struct sock *)msk); - -if (__mptcp_check_fallback (msk)) -return NULL ; -mptcp_for_each_subflow (msk, subflow) {struct sock *ssk =mptcp_subflow_tcp_sock (subflow);
@@ -2479,7 +2466,7 @@ static void __mptcp_retrans(struct sock *sk)mptcp_clean_una_wakeup (sk);/* first check ssk: need to kick "stale" logic */ - ssk =mptcp_subflow_get_retrans (msk); + ssk =mptcp_sched_get_retrans (msk); dfrag =mptcp_rtx_head (sk);if (!dfrag) {if (mptcp_data_fin_enabled (msk)) {
@@ -3128,7 +3115,7 @@ void __mptcp_check_push(struct sock *sk, struct sock *ssk)return ;if (!sock_owned_by_user (sk)) { -struct sock *xmit_ssk =mptcp_subflow_get_send (mptcp_sk (sk)); +struct sock *xmit_ssk =mptcp_sched_get_send (mptcp_sk (sk));if (xmit_ssk == ssk)__mptcp_subflow_push_pending (sk, ssk);
net/mptcp/protocol.h +4 -0
@@ -629,6 +629,10 @@ void mptcp_unregister_scheduler(struct mptcp_sched_ops *sched);int mptcp_init_sched (struct mptcp_sock *msk,struct mptcp_sched_ops *sched);void mptcp_release_sched (struct mptcp_sock *msk); +struct sock *mptcp_subflow_get_send (struct mptcp_sock *msk); +struct sock *mptcp_subflow_get_retrans (struct mptcp_sock *msk); +struct sock *mptcp_sched_get_send (struct mptcp_sock *msk); +struct sock *mptcp_sched_get_retrans (struct mptcp_sock *msk);static inline bool __mptcp_subflow_active (struct mptcp_subflow_context *subflow) {
net/mptcp/sched.c +52 -0
55 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH 13/15 mptcp: add bpf_mptcp_sched_ops
In reply to Geliang TangThis patch implements a new struct bpf_struct_ops, bpf_mptcp_sched_ops. Register and unregister the bpf scheduler in .reg and .unreg.
This MPTCP BPF scheduler implementation is similar to BPF TCP CC. And net/ipv4/bpf_tcp_ca.c is a frame of reference for this patch.
--- kernel/bpf/bpf_struct_ops_types.h | 4 + net/mptcp/bpf.c | 153 ++++++++++++++++++++++++++++++ 2 files changed, 157 insertions(+)
kernel/bpf/bpf_struct_ops_types.h +4 -0
@@ -8,5 +8,9 @@ BPF_STRUCT_OPS_TYPE(bpf_dummy_ops)#ifdef CONFIG_INET #include <net/tcp.h> BPF_STRUCT_OPS_TYPE(tcp_congestion_ops) +#ifdef CONFIG_MPTCP +#include <net/mptcp.h> +BPF_STRUCT_OPS_TYPE(mptcp_sched_ops) +#endif #endif #endif
net/mptcp/bpf.c +153 -0
161 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH 14/15 selftests/bpf: add bpf_first scheduler
In reply to Geliang TangThis patch implements the simplest MPTCP scheduler, named bpf_first, which always picks the first subflow to send data. It's a sample of MPTCP BPF scheduler implementations.
--- .../selftests/bpf/progs/mptcp_bpf_first.c | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 tools/testing/selftests/bpf/progs/mptcp_bpf_first.c
tools/testing/selftests/bpf/progs/mptcp_bpf_first.c new file +32 -0
@@ -0,0 +1,32 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) 2022, SUSE. */ + +#include <linux/bpf.h> +#include "bpf_tcp_helpers.h" + +char _license[] SEC("license") = "GPL"; + +SEC("struct_ops/mptcp_sched_first_init") +void BPF_PROG (mptcp_sched_first_init ,const struct mptcp_sock *msk) +{ +} + +SEC("struct_ops/mptcp_sched_first_release") +void BPF_PROG (mptcp_sched_first_release ,const struct mptcp_sock *msk) +{ +} + +void BPF_STRUCT_OPS (bpf_first_get_subflow ,const struct mptcp_sock *msk, +bool reinject,struct mptcp_sched_data *data) +{ + data->sock = msk->first; + data->call_again =0 ; +} + +SEC(".struct_ops") +struct mptcp_sched_ops first = { + .init = (void *)mptcp_sched_first_init, + .release = (void *)mptcp_sched_first_release, + .get_subflow = (void *)bpf_first_get_subflow, + .name ="bpf_first" , +};
Signature · 1 line
2.34.1
PATCH 15/15 selftests/bpf: add bpf_first test
In reply to Geliang TangThis patch expends the MPTCP test base to support MPTCP packet scheduler tests. Add the bpf_first scheduler test in it. Use sysctl to set net.mptcp.scheduler to use this sched.
Some code in send_data() is from prog_tests/bpf_tcp_ca.c.
--- .../testing/selftests/bpf/prog_tests/mptcp.c | 113 ++++++++++++++++++ 1 file changed, 113 insertions(+)
tools/testing/selftests/bpf/prog_tests/mptcp.c +113 -0
@@ -5,6 +5,7 @@#include <test_progs.h> #include "cgroup_helpers.h" #include "network_helpers.h" +#include "mptcp_bpf_first.skel.h" #ifndef TCP_CA_NAME_MAX #define TCP_CA_NAME_MAX 16
@@ -20,6 +21,8 @@ struct mptcp_storage { };static char monitor_log_path[64 ]; +static const unsigned int total_bytes =10 *1024 *1024 ; +static int stop, duration;static int verify_tsk (int map_fd,int client_fd) {
@@ -258,8 +261,118 @@ void test_base(void)close (cgroup_fd); } +static void *server (void *arg) +{ +int lfd = (int )(long )arg, err =0 , fd; +ssize_t nr_sent =0 , bytes =0 ; +char batch[1500 ]; + + fd =accept (lfd,NULL ,NULL ); +while (fd ==-1 ) { +if (errno ==EINTR ) +continue ; + err = -errno; + goto done; + } + +if (settimeo (fd,0 )) { + err = -errno; + goto done; + } + +while (bytes < total_bytes && !READ_ONCE (stop)) { + nr_sent =send (fd, &batch, +MIN (total_bytes - bytes,sizeof (batch)),0 ); +if (nr_sent ==-1 && errno ==EINTR ) +continue ; +if (nr_sent ==-1 ) { + err = -errno; +break ; + } + bytes += nr_sent; + } + +CHECK (bytes != total_bytes,"send" ,"%zd != %u nr_sent:%zd errno:%d\n" , + bytes, total_bytes, nr_sent, errno); + +done: +if (fd >=0 ) +close (fd); +if (err) { +WRITE_ONCE (stop,1 ); +return ERR_PTR (err); + } +return NULL ; +} + +static void send_data (int lfd,int fd) +{ +ssize_t nr_recv =0 , bytes =0 ; +pthread_t srv_thread; +void *thread_ret; +char batch[1500 ]; +int err; + +WRITE_ONCE (stop,0 ); + + err =pthread_create (&srv_thread,NULL , server, (void *)(long )lfd); +if (CHECK (err !=0 ,"pthread_create" ,"err:%d errno:%d\n" , err, errno)) +return ; + +/* recv total_bytes */ +while (bytes < total_bytes && !READ_ONCE (stop)) { + nr_recv =recv (fd, &batch, +MIN (total_bytes - bytes,sizeof (batch)),0 ); +if (nr_recv ==-1 && errno ==EINTR ) +continue ; +if (nr_recv ==-1 ) +break ; + bytes += nr_recv; + } + +CHECK (bytes != total_bytes,"recv" ,"%zd != %u nr_recv:%zd errno:%d\n" , + bytes, total_bytes, nr_recv, errno); + +WRITE_ONCE (stop,1 ); + +pthread_join (srv_thread, &thread_ret); +CHECK (IS_ERR (thread_ret),"pthread_join" ,"thread_ret:%ld" , +PTR_ERR (thread_ret)); +} + +static void test_first (void ) +{ +struct mptcp_bpf_first *first_skel; +int server_fd, client_fd; +struct bpf_link *link; + + first_skel =mptcp_bpf_first__open_and_load (); +if (!ASSERT_OK_PTR (first_skel,"bpf_first__open_and_load" )) +return ; + + link =bpf_map__attach_struct_ops (first_skel->maps.first); +if (!ASSERT_OK_PTR (link,"bpf_map__attach_struct_ops" )) { +mptcp_bpf_first__destroy (first_skel); +return ; + } + +system ("sysctl -qw net.mptcp.scheduler=bpf_first" ); + server_fd =start_mptcp_server (AF_INET ,NULL ,0 ,0 ); + client_fd =connect_to_mptcp_fd (server_fd,0 ); + +send_data (server_fd, client_fd); + +close (client_fd); +close (server_fd); +system ("sysctl -qw net.mptcp.scheduler=default" ); +bpf_link__destroy (link); +mptcp_bpf_first__destroy (first_skel); +} +void test_mptcp (void ) {if (test__start_subtest ("base" ))test_base (); +if (test__start_subtest ("first" )) +test_first (); }
Signature · 1 line
2.34.1