for bpf-next
Subsystems (11)
cover for bpf-next
- The first 10 patches is for bpf-next v5.
- Rebased the "BPF packet scheduler" series on export branch.
- base-commit: df896c77f02a ("DO-NOT-MERGE: git markup: features net-next-next"), export/20220517T155019
Geliang Tang (16):
mptcp: move MPTCPOPT_HMAC_LEN to net/mptcp.h
mptcp: move mptcp_subflow_context in net/mptcp.h
bpf: add bpf_mptcp_sock_from_subflow helper
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 (1):
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 | 131 +++++++- include/uapi/linux/bpf.h | 7 + kernel/bpf/bpf_struct_ops_types.h | 4 + kernel/bpf/verifier.c | 1 + kernel/trace/bpf_trace.c | 2 + net/core/filter.c | 18 ++ net/mptcp/Makefile | 6 +- net/mptcp/bpf.c | 162 ++++++++++ net/mptcp/ctrl.c | 14 + net/mptcp/protocol.c | 32 +- net/mptcp/protocol.h | 106 +------ net/mptcp/sched.c | 141 +++++++++ scripts/bpf_doc.py | 2 + tools/include/uapi/linux/bpf.h | 7 + tools/testing/selftests/bpf/bpf_tcp_helpers.h | 32 ++ tools/testing/selftests/bpf/config | 3 + tools/testing/selftests/bpf/network_helpers.c | 40 ++- tools/testing/selftests/bpf/network_helpers.h | 2 + .../testing/selftests/bpf/prog_tests/mptcp.c | 288 ++++++++++++++++++ .../selftests/bpf/progs/mptcp_bpf_first.c | 32 ++ .../testing/selftests/bpf/progs/mptcp_sock.c | 89 ++++++ 25 files changed, 1007 insertions(+), 125 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/17 mptcp: move MPTCPOPT_HMAC_LEN to net/mptcp.h
Move macro MPTCPOPT_HMAC_LEN definition from net/mptcp/protocol.h to include/net/mptcp.h.
--- include/net/mptcp.h | 3 ++- net/mptcp/protocol.h | 1 - 2 files changed, 2 insertions(+), 2 deletions(-)
include/net/mptcp.h +2 -1
@@ -39,6 +39,7 @@ struct mptcp_ext { infinite_map:1 ; }; +#define MPTCPOPT_HMAC_LEN 20#define MPTCP_RM_IDS_MAX 8struct mptcp_rm_list {
@@ -89,7 +90,7 @@ struct mptcp_out_options {u32 nonce;u32 token;u64 thmac; - u8 hmac[20]; + u8 hmac[MPTCPOPT_HMAC_LEN]; }; };#endif
net/mptcp/protocol.h +0 -1
@@ -83,7 +83,6 @@/* MPTCP MP_JOIN flags */ #define MPTCPOPT_BACKUP BIT(0) -#define MPTCPOPT_HMAC_LEN 20#define MPTCPOPT_THMAC_LEN 8/* MPTCP MP_CAPABLE flags */
Signature · 1 line
2.34.1
PATCH 2/17 mptcp: move mptcp_subflow_context in net/mptcp.h
In reply to Geliang TangMove struct mptcp_subflow_context definition from net/mptcp/protocol.h to include/net/mptcp.h. And move the related struct mptcp_data_avail and function mptcp_subflow_ctx() too.
--- include/net/mptcp.h | 91 ++++++++++++++++++++++++++++++++++++++++++++ net/mptcp/protocol.h | 88 ------------------------------------------ 2 files changed, 91 insertions(+), 88 deletions(-)
include/net/mptcp.h +91 -0
@@ -40,6 +40,86 @@ struct mptcp_ext { };#define MPTCPOPT_HMAC_LEN 20 + +enum mptcp_data_avail { +MPTCP_SUBFLOW_NODATA , +MPTCP_SUBFLOW_DATA_AVAIL , +}; + +/* MPTCP subflow context */ +struct mptcp_subflow_context { +struct list_head node;/* conn_list of subflows */ + + struct_group(reset, + + unsigned long avg_pacing_rate; /* protected by msk socket lock */ +u64 local_key; +u64 remote_key; +u64 idsn; +u64 map_seq; +u32 snd_isn; +u32 token; +u32 rel_write_seq; +u32 map_subflow_seq; +u32 ssn_offset; +u32 map_data_len; +__wsum map_data_csum; +u32 map_csum_len; +u32 request_mptcp :1 ,/* send MP_CAPABLE */ + request_join :1 ,/* send MP_JOIN */ + request_bkup :1 , + mp_capable :1 ,/* remote is MPTCP capable */ + mp_join :1 ,/* remote is JOINing */ + fully_established :1 ,/* path validated */ + pm_notified :1 ,/* PM hook called for established status */ + conn_finished :1 , + map_valid :1 , + map_csum_reqd :1 , + map_data_fin :1 , + mpc_map :1 , + backup :1 , + send_mp_prio :1 , + send_mp_fail :1 , + send_fastclose :1 , + send_infinite_map :1 , + rx_eof :1 , + can_ack :1 ,/* only after processing the remote a key */ + disposable :1 ,/* ctx can be free at ulp release time */ + stale :1 ,/* unable to snd/rcv data, do not use for xmit */ + local_id_valid :1 ,/* local_id is correctly initialized */ + valid_csum_seen :1 ;/* at least one csum validated */ +enum mptcp_data_avail data_avail; +bool mp_fail_response_expect; +u32 remote_nonce; +u64 thmac; +u32 local_nonce; +u32 remote_token; +u8 hmac[MPTCPOPT_HMAC_LEN ]; +u8 local_id; +u8 remote_id; +u8 reset_seen:1 ; +u8 reset_transient:1 ; +u8 reset_reason:4 ; +u8 stale_count; + +long delegated_status; + + ); + +struct list_head delegated_node;/* link into delegated_action, protected by local BH */ + +u32 setsockopt_seq; +u32 stale_rcv_tstamp; + +struct sock *tcp_sock;/* tcp sk backpointer */ +struct sock *conn;/* parent mptcp_sock */ +const struct inet_connection_sock_af_ops *icsk_af_ops; +void (*tcp_state_change)(struct sock *sk); +void (*tcp_error_report)(struct sock *sk); + +struct rcu_head rcu; +}; +#define MPTCP_RM_IDS_MAX 8struct mptcp_rm_list {
@@ -198,6 +278,15 @@ static inline __be32 mptcp_reset_option(const struct sk_buff *skb) return htonl(0u); } + +static inline struct mptcp_subflow_context * +mptcp_subflow_ctx (const struct sock *sk) +{ +struct inet_connection_sock *icsk =inet_csk (sk); + +/* Use RCU on icsk_ulp_data only for sock diag code */ +return (__force struct mptcp_subflow_context *)icsk->icsk_ulp_data; +}#else static inline void mptcp_init (void )
@@ -275,6 +364,8 @@ static inline int mptcp_subflow_init_cookie_req(struct request_sock *req, }static inline __be32 mptcp_reset_option (const struct sk_buff *skb) {return htonl (0u ); } +static inline struct mptcp_subflow_context * +mptcp_subflow_ctx (const struct sock *sk) {return NULL ; }#endif /* CONFIG_MPTCP */ #if IS_ENABLED (CONFIG_MPTCP_IPV6 )
net/mptcp/protocol.h +0 -88
100 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH 3/17 bpf: add bpf_mptcp_sock_from_subflow helper
In reply to Geliang TangThis patch implements the helper bpf_mptcp_sock_from_subflow(), to get the MPTCP socket from a given TCP subflow socket.
Move the inline function mptcp_sk() from net/mptcp/protocol.h to include/net/mptcp.h.
--- include/net/mptcp.h | 18 ++++++++++++++++++ net/mptcp/protocol.h | 5 ----- 2 files changed, 18 insertions(+), 5 deletions(-)
include/net/mptcp.h +18 -0
@@ -287,6 +287,11 @@ mptcp_subflow_ctx(const struct sock *sk)/* Use RCU on icsk_ulp_data only for sock diag code */ return (__force struct mptcp_subflow_context *)icsk->icsk_ulp_data; } + +static inline struct mptcp_sock *mptcp_sk (const struct sock *sk) +{ +return (struct mptcp_sock *)sk; +}#else static inline void mptcp_init (void )
@@ -366,6 +371,7 @@ static inline int mptcp_subflow_init_cookie_req(struct request_sock *req,static inline __be32 mptcp_reset_option (const struct sk_buff *skb) {return htonl (0u ); }static inline struct mptcp_subflow_context *mptcp_subflow_ctx (const struct sock *sk) {return NULL ; } +static inline struct mptcp_sock *mptcp_sk (const struct sock *sk) {return NULL ; }#endif /* CONFIG_MPTCP */ #if IS_ENABLED (CONFIG_MPTCP_IPV6 )
@@ -376,4 +382,16 @@ 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 ) +static inline 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 ; +} +#else +static inline struct mptcp_sock *bpf_mptcp_sock_from_subflow (struct sock *sk) {return NULL ; } +#endif +#endif /* __NET_MPTCP_H */
net/mptcp/protocol.h +0 -5
@@ -318,11 +318,6 @@ static inline void msk_owned_by_me(const struct mptcp_sock *msk)sock_owned_by_me ((const struct sock *)msk); } -static inline struct mptcp_sock *mptcp_sk (const struct sock *sk) -{ -return (struct mptcp_sock *)sk; -} -/* the msk socket don't use the backlog, also account for the bulk * free memory */
Signature · 1 line
2.34.1
PATCH 4/17 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
v3: Drop bpf.c, define bpf_mptcp_sock_from_subflow() in mptcp.h (Martin)
--- include/linux/bpf.h | 1 + include/linux/btf_ids.h | 3 ++- include/uapi/linux/bpf.h | 7 +++++++ kernel/bpf/verifier.c | 1 + kernel/trace/bpf_trace.c | 2 ++ net/core/filter.c | 18 ++++++++++++++++++ scripts/bpf_doc.py | 2 ++ tools/include/uapi/linux/bpf.h | 7 +++++++ 8 files changed, 40 insertions(+), 1 deletion(-)
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/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);
@@ -11272,6 +11273,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);
@@ -11314,6 +11329,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 :
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 5/17 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 6/17 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)
- use is_mptcp in tcp_sock, instead of bpf_tcp_sock (Martin & Andrii)
v5:
- Drop connect_to_mptcp_fd (Martin)
- Use BPF test skeleton (Andrii)
- Use ASSERT_EQ (Andrii)
--- MAINTAINERS | 1 + tools/testing/selftests/bpf/bpf_tcp_helpers.h | 1 + tools/testing/selftests/bpf/config | 1 + tools/testing/selftests/bpf/network_helpers.c | 40 +++++-- tools/testing/selftests/bpf/network_helpers.h | 2 + .../testing/selftests/bpf/prog_tests/mptcp.c | 112 ++++++++++++++++++ .../testing/selftests/bpf/progs/mptcp_sock.c | 53 +++++++++ 7 files changed, 201 insertions(+), 9 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
@@ -13799,6 +13799,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/bpf_tcp_helpers.h +1 -0
@@ -81,6 +81,7 @@ struct tcp_sock {__u32 lsndtime;__u32 prior_cwnd;__u64 tcp_mstamp;/* most recent packet received/sent */ +bool is_mptcp; } __attribute__((preserve_access_index)); static __always_inline struct inet_connection_sock *inet_csk(const struct sock *sk)
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 +31 -9
@@ -21,6 +21,10 @@#include "network_helpers.h" #include "test_progs.h" +#ifndef IPPROTO_MPTCP +#define IPPROTO_MPTCP 262 +#endif +#define clean_errno () (errno == 0 ? "None" : strerror(errno))#define log_err (MSG , ...) ({ \ int __save = errno; \
@@ -73,13 +77,13 @@ int settimeo(int fd, int timeout_ms)#define save_errno_close (fd) ({ int __save = errno; close(fd); errno = __save; }) -static int __start_server (int type,const struct sockaddr *addr, +static int __start_server (int type,int protocol,const struct sockaddr *addr,socklen_t addrlen,int timeout_ms,bool reuseport) {int on =1 ;int fd; - fd =socket (addr->sa_family, type,0 ); + fd =socket (addr->sa_family, type, protocol);if (fd <0 ) {log_err ("Failed to create server socket" );return -1 ;
@@ -113,8 +117,8 @@ static int __start_server(int type, const struct sockaddr *addr,return -1 ; } -int start_server (int family,int type,const char *addr_str,__u16 port, -int timeout_ms) +static int start_server_proto (int family,int type,int protocol, +const char *addr_str,__u16 port,int timeout_ms) {struct sockaddr_storage addr;socklen_t addrlen;
@@ -122,10 +126,23 @@ int start_server(int family, int type, const char *addr_str, __u16 port,if (make_sockaddr (family, addr_str, port, &addr, &addrlen))return -1 ; -return __start_server (type, (struct sockaddr *)&addr, +return __start_server (type, protocol, (struct sockaddr *)&addr, addrlen, timeout_ms, false); } +int start_server (int family,int type,const char *addr_str,__u16 port, +int timeout_ms) +{ +return start_server_proto (family, type,0 , addr_str, port, timeout_ms); +} + +int start_mptcp_server (int family,const char *addr_str,__u16 port, +int timeout_ms) +{ +return start_server_proto (family,SOCK_STREAM ,IPPROTO_MPTCP , addr_str, + port, timeout_ms); +} +int *start_reuseport_server (int family,int type,const char *addr_str,__u16 port,int timeout_ms,unsigned int nr_listens) {
@@ -144,7 +161,7 @@ int *start_reuseport_server(int family, int type, const char *addr_str,if (!fds)return NULL ; - fds[0 ] =__start_server (type, (struct sockaddr *)&addr, addrlen, + fds[0 ] =__start_server (type,0 , (struct sockaddr *)&addr, addrlen, timeout_ms, true);if (fds[0 ] ==-1 ) goto close_fds;
@@ -154,7 +171,7 @@ int *start_reuseport_server(int family, int type, const char *addr_str, goto close_fds;for (; nr_fds < nr_listens; nr_fds++) { - fds[nr_fds] =__start_server (type, (struct sockaddr *)&addr, + fds[nr_fds] =__start_server (type,0 , (struct sockaddr *)&addr, addrlen, timeout_ms, true);if (fds[nr_fds] ==-1 ) goto close_fds;
@@ -247,7 +264,7 @@ int connect_to_fd_opts(int server_fd, const struct network_helper_opts *opts)struct sockaddr_storage addr;struct sockaddr_in *addr_in;socklen_t addrlen, optlen; -int fd, type; +int fd, type, protocol;if (!opts) opts = &default_opts;
@@ -258,6 +275,11 @@ int connect_to_fd_opts(int server_fd, const struct network_helper_opts *opts)return -1 ; } +if (getsockopt (server_fd,SOL_SOCKET ,SO_PROTOCOL , &protocol, &optlen)) { +log_err ("getsockopt(SOL_PROTOCOL)" ); +return -1 ; + } + addrlen =sizeof (addr);if (getsockname (server_fd, (struct sockaddr *)&addr, &addrlen)) {log_err ("Failed to get server addr" );
@@ -265,7 +287,7 @@ int connect_to_fd_opts(int server_fd, const struct network_helper_opts *opts) } addr_in = (struct sockaddr_in *)&addr; - fd =socket (addr_in->sin_family, type,0 ); + fd =socket (addr_in->sin_family, type, protocol);if (fd <0 ) {log_err ("Failed to create client socket" );return -1 ;
tools/testing/selftests/bpf/network_helpers.h +2 -0
@@ -42,6 +42,8 @@ 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);
tools/testing/selftests/bpf/prog_tests/mptcp.c new file +112 -0
112 lines not on this page · raw message
tools/testing/selftests/bpf/progs/mptcp_sock.c new file +53 -0
53 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH 7/17 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)
v5:
- some 'ASSERT_*' were replaced in the next commit by mistake.
- Drop CONFIG_MPTCP (Martin)
- Use ASSERT_EQ (Andrii)
--- tools/testing/selftests/bpf/bpf_tcp_helpers.h | 5 ++++ .../testing/selftests/bpf/prog_tests/mptcp.c | 27 ++++++++++++++----- .../testing/selftests/bpf/progs/mptcp_sock.c | 19 ++++++++++--- 3 files changed, 41 insertions(+), 10 deletions(-)
tools/testing/selftests/bpf/bpf_tcp_helpers.h +5 -0
@@ -226,4 +226,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 +21 -6
@@ -12,14 +12,11 @@ struct mptcp_storage {__u32 is_mptcp; }; -static int verify_sk (int map_fd,int client_fd,const char *msg,__u32 is_mptcp) +static int verify_tsk (int map_fd,int client_fd) {int err, cfd = client_fd;struct mptcp_storage val; -if (is_mptcp ==1 ) -return 0 ; - err =bpf_map_lookup_elem (map_fd, &cfd, &val);if (!ASSERT_OK (err,"bpf_map_lookup_elem" ))return err;
@@ -33,6 +30,24 @@ static int verify_sk(int map_fd, int client_fd, const char *msg, __u32 is_mptcp)return err; } +static int verify_msk (int map_fd,int client_fd) +{ +int err, cfd = client_fd; +struct mptcp_storage val; + + err =bpf_map_lookup_elem (map_fd, &cfd, &val); +if (!ASSERT_OK (err,"bpf_map_lookup_elem" )) +return err; + +if (!ASSERT_EQ (val.invoked,1 ,"unexpected invoked count" )) + err++; + +if (!ASSERT_EQ (val.is_mptcp,1 ,"unexpected is_mptcp" )) + err++; + +return err; +} +static int run_test (int cgroup_fd,int server_fd,bool is_mptcp) {int client_fd, prog_fd, map_fd, err;
@@ -64,8 +79,8 @@ static int run_test(int cgroup_fd, int server_fd, bool is_mptcp) goto out; } - err += is_mptcp ?verify_sk (map_fd, client_fd,"MPTCP subflow socket" ,1 ) : -verify_sk (map_fd, client_fd,"plain TCP socket" ,0 ); + err += is_mptcp ?verify_msk (map_fd, client_fd) : +verify_tsk (map_fd, client_fd);close (client_fd);
tools/testing/selftests/bpf/progs/mptcp_sock.c +15 -4
@@ -24,6 +24,7 @@ SEC("sockops")int _sockops (struct bpf_sock_ops *ctx) {struct mptcp_storage *storage; +struct mptcp_sock *msk;int op = (int )ctx->op;struct tcp_sock *tsk;struct bpf_sock *sk;
@@ -41,11 +42,21 @@ int _sockops(struct bpf_sock_ops *ctx)return 1 ; is_mptcp =bpf_core_field_exists (tsk->is_mptcp) ? tsk->is_mptcp :0 ; - storage =bpf_sk_storage_get (&socket_storage_map, sk,0 , -BPF_SK_STORAGE_GET_F_CREATE ); -if (!storage) -return 1 ; +if (!is_mptcp) { + storage =bpf_sk_storage_get (&socket_storage_map, sk,0 , +BPF_SK_STORAGE_GET_F_CREATE ); +if (!storage) +return 1 ; + }else { + 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 = is_mptcp;
Signature · 1 line
2.34.1
PATCH 8/17 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)
v5:
- Drop 'ip mptcp monitor', trace mptcp_pm_new_connection instead(Martin)
- Use ASSERT_EQ (Andrii)
--- tools/testing/selftests/bpf/bpf_tcp_helpers.h | 1 + tools/testing/selftests/bpf/prog_tests/mptcp.c | 15 +++++++++++++-- tools/testing/selftests/bpf/progs/mptcp_sock.c | 16 ++++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-)
tools/testing/selftests/bpf/bpf_tcp_helpers.h +1 -0
@@ -229,6 +229,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 +13 -2
@@ -10,6 +10,7 @@struct mptcp_storage {__u32 invoked;__u32 is_mptcp; +__u32 token; };static int verify_tsk (int map_fd,int client_fd)
@@ -30,11 +31,14 @@ static int verify_tsk(int map_fd, int client_fd)return err; } -static int verify_msk (int map_fd,int client_fd) +static int verify_msk (int map_fd,int client_fd,__u32 token) {int err, cfd = client_fd;struct mptcp_storage val; +if (!ASSERT_GT (token,0 ,"invalid token" )) +return -1 ; + err =bpf_map_lookup_elem (map_fd, &cfd, &val);if (!ASSERT_OK (err,"bpf_map_lookup_elem" ))return err;
@@ -45,6 +49,9 @@ static int verify_msk(int map_fd, int client_fd)if (!ASSERT_EQ (val.is_mptcp,1 ,"unexpected is_mptcp" )) err++; +if (!ASSERT_EQ (val.token, token,"unexpected token" )) + err++; +return err; }
@@ -57,6 +64,10 @@ static int run_test(int cgroup_fd, int server_fd, bool is_mptcp)if (!ASSERT_OK_PTR (sock_skel,"skel_open_load" ))return -EIO ; + err =mptcp_sock__attach (sock_skel); +if (!ASSERT_OK (err,"skel_attach" )) + goto out; + prog_fd =bpf_program__fd (sock_skel->progs._sockops);if (!ASSERT_GE (prog_fd,0 ,"bpf_program__fd" )) { err = -EIO ;
@@ -79,7 +90,7 @@ static int run_test(int cgroup_fd, int server_fd, bool is_mptcp) goto out; } - err += is_mptcp ?verify_msk (map_fd, client_fd) : + err += is_mptcp ?verify_msk (map_fd, client_fd, sock_skel->bss->token) :verify_tsk (map_fd, client_fd);close (client_fd);
tools/testing/selftests/bpf/progs/mptcp_sock.c +16 -0
@@ -7,10 +7,12 @@#include "bpf_tcp_helpers.h" char _license[] SEC("license") = "GPL"; +__u32 token =0 ;struct mptcp_storage {__u32 invoked;__u32 is_mptcp; +__u32 token; };struct {
@@ -47,6 +49,8 @@ int _sockops(struct bpf_sock_ops *ctx) BPF_SK_STORAGE_GET_F_CREATE);if (!storage)return 1 ; + + storage->token =0 ; }else { msk =bpf_skc_to_mptcp_sock (sk);if (!msk)
@@ -56,9 +60,21 @@ 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 = is_mptcp;return 1 ; } + +SEC("fentry/mptcp_pm_new_connection") +int BPF_PROG (trace_mptcp_pm_new_connection ,struct mptcp_sock *msk, +const struct sock *ssk,int server_side) +{ +if (!server_side) + token = msk->token; + +return 0 ; +}
Signature · 1 line
2.34.1
PATCH 9/17 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 | 31 +++++++++++++++++++ .../testing/selftests/bpf/progs/mptcp_sock.c | 4 +++ 3 files changed, 40 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 {
@@ -230,6 +234,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 +31 -0
@@ -7,10 +7,15 @@#include "network_helpers.h" #include "mptcp_sock.skel.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 int verify_tsk (int map_fd,int client_fd)
@@ -31,14 +36,37 @@ static int verify_tsk(int map_fd, int client_fd)return err; } +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,__u32 token) { +char ca_name[TCP_CA_NAME_MAX ];int err, cfd = client_fd;struct mptcp_storage val;if (!ASSERT_GT (token,0 ,"invalid 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;
@@ -52,6 +80,9 @@ static int verify_msk(int map_fd, int client_fd, __u32 token)if (!ASSERT_EQ (val.token, token,"unexpected token" )) err++; +if (!ASSERT_STRNEQ (val.ca_name, ca_name,TCP_CA_NAME_MAX ,"unexpected 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 {
@@ -51,6 +53,7 @@ int _sockops(struct bpf_sock_ops *ctx)return 1 ; storage->token =0 ; +bzero (storage->ca_name,TCP_CA_NAME_MAX ); }else { msk =bpf_skc_to_mptcp_sock (sk);if (!msk)
@@ -62,6 +65,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 = is_mptcp;
Signature · 1 line
2.34.1
PATCH 10/17 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().
v5:
- Use ASSERT_EQ.
--- tools/testing/selftests/bpf/bpf_tcp_helpers.h | 1 + tools/testing/selftests/bpf/prog_tests/mptcp.c | 5 +++++ tools/testing/selftests/bpf/progs/mptcp_sock.c | 5 +++++ 3 files changed, 11 insertions(+)
tools/testing/selftests/bpf/bpf_tcp_helpers.h +1 -0
@@ -234,6 +234,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 +5 -0
@@ -14,7 +14,9 @@struct mptcp_storage {__u32 invoked;__u32 is_mptcp; +struct sock *sk;__u32 token; +struct sock *first;char ca_name[TCP_CA_NAME_MAX ]; };
@@ -80,6 +82,9 @@ static int verify_msk(int map_fd, int client_fd, __u32 token)if (!ASSERT_EQ (val.token, token,"unexpected token" )) err++; +if (!ASSERT_EQ (val.first, val.sk,"unexpected first" )) + err++; +if (!ASSERT_STRNEQ (val.ca_name, ca_name,TCP_CA_NAME_MAX ,"unexpected ca_name" )) err++;
tools/testing/selftests/bpf/progs/mptcp_sock.c +5 -0
@@ -13,7 +13,9 @@ __u32 token = 0;struct mptcp_storage {__u32 invoked;__u32 is_mptcp; +struct sock *sk;__u32 token; +struct sock *first;char ca_name[TCP_CA_NAME_MAX ]; };
@@ -54,6 +56,7 @@ int _sockops(struct bpf_sock_ops *ctx) storage->token =0 ;bzero (storage->ca_name,TCP_CA_NAME_MAX ); + storage->first =NULL ; }else { msk =bpf_skc_to_mptcp_sock (sk);if (!msk)
@@ -66,9 +69,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 = is_mptcp; + storage->sk = (struct sock *)sk;return 1 ; }
Signature · 1 line
2.34.1
PATCH 11/17 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
@@ -176,6 +176,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
@@ -527,6 +527,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
@@ -230,6 +230,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 12/17 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
@@ -502,6 +502,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 13/17 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
@@ -2643,6 +2643,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 */
@@ -2798,6 +2803,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
@@ -2971,6 +2977,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
@@ -296,6 +296,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 */
@@ -531,6 +532,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
@@ -253,6 +253,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 14/17 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) {
@@ -2203,17 +2195,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);
@@ -2466,7 +2453,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)) {
@@ -3114,7 +3101,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
@@ -535,6 +535,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 15/17 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/Makefile | 4 + net/mptcp/bpf.c | 162 ++++++++++++++++++++++++++++++ 3 files changed, 170 insertions(+) create mode 100644 net/mptcp/bpf.c
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/Makefile +4 -0
@@ -10,3 +10,7 @@ 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 + +ifeq ($(CONFIG_BPF_JIT),y) +obj-$(CONFIG_BPF_SYSCALL) += bpf.o +endif
net/mptcp/bpf.c new file +162 -0
162 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH 16/17 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 17/17 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 | 114 ++++++++++++++++++ 1 file changed, 114 insertions(+)
tools/testing/selftests/bpf/prog_tests/mptcp.c +114 -0
@@ -6,6 +6,7 @@#include "cgroup_helpers.h" #include "network_helpers.h" #include "mptcp_sock.skel.h" +#include "mptcp_bpf_first.skel.h" #ifndef TCP_CA_NAME_MAX #define TCP_CA_NAME_MAX 16
@@ -20,6 +21,9 @@ struct mptcp_storage {char ca_name[TCP_CA_NAME_MAX ]; }; +static const unsigned int total_bytes =10 *1024 *1024 ; +static int stop, duration; +static int verify_tsk (int map_fd,int client_fd) {int err, cfd = client_fd;
@@ -167,8 +171,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_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
Re: [PATCH mptcp-next 08/17] selftests/bpf: verify token of struct mptcp_sock
In reply to Geliang TangQuoted 3 lines
This patch verifies the struct member token of struct
mptcp_sock. Add a new functionget_msk_token()to parse the msk token from the output of the command 'ip mptcp monitor', and verify it inverify_msk().
Please update the commit log:
'''
This patch verifies the struct member token of struct mptcp_sock. Add a new member token in struct mptcp_storage to store the token value of the msk socket got by bpf_skc_to_mptcp_sock(). Trace the kernel function mptcp_pm_new_connection() by using bpf fentry prog to obtain the msk token and save it in a global bpf variable. Pass the variable to verify_msk() to verify it with the token saved in socket_storage_map.
'''
Re: [PATCH mptcp-next 02/17] mptcp: move mptcp_subflow_context in net/mptcp.h
In reply to Geliang TangPlease update the subject:
'''
mptcp: move mptcp_subflow_context to net/mptcp.h
'''
Hi Geliang,
Thank you for this series.
Quoted 4 lines · Geliang Tang
- The first 10 patches is for bpf-next v5.
- Rebased the "BPF packet scheduler" series on export branch.
- base-commit:df896c77f02a("DO-NOT-MERGE: git markup: features net-next-next"), export/20220517T155019
Does this correspond to what I should get if I apply all the Squash-to patch you sent yesterday?
Or are there differences on top of that?
On my side, it is easier to apply squash-to patch and re-apply an updated series which is already in our tree.
Of course if the conflicts are complex, you can send your version on a public Git repo for me to compare.
Cheers,
Matt
Signature · 2 lines
Tessares | Belgium | Hybrid Access Solutions www.tessares.net
Hi Matt,
Quoted 6 lines · Matthieu Baerts <[email protected]> 于2022年5月18日周三 18:59写道:
Hi Geliang,
Thank you for this series.
On 18/05/2022 08:10, Geliang Tang wrote:
Quoted 8 lines
Quoted 4 lines
- The first 10 patches is for bpf-next v5.
- Rebased the "BPF packet scheduler" series on export branch.
- base-commit:df896c77f02a("DO-NOT-MERGE: git markup: features net-next-next"), export/20220517T155019Does this correspond to what I should get if I apply all the Squash-to patch you sent yesterday?
Or are there differences on top of that?
This series addresses all BPF maintainers‘ comments for v4. It makes the squash-to patches I sent yesterday superseded. I found it's hard to send them as squash-to patches because there are too many differences. So I sent this new series. I think it's much easier for Mat to review and upstream.
Quoted 5 lines
On my side, it is easier to apply squash-to patch and re-apply an updated series which is already in our tree.
Of course if the conflicts are complex, you can send your version on a public Git repo for me to compare.
I suggest we skip merging this version into our export branch. I guess BPF maintainers will give some comments for this v5 too. When this series is accepted at last, then I'll split them as squash-to patches, and send to you for merging into our export branch.
Thanks,
-Geliang
Quoted 7 lines
Cheers,
Matt
--
Tessares | Belgium | Hybrid Access Solutions
www.tessares.net
Re: [PATCH mptcp-next 02/17] mptcp: move mptcp_subflow_context in net/mptcp.h
In reply to Geliang TangQuoted 5 lines · Geliang Tang
Move struct
mptcp_subflow_contextdefinition fromnet/mptcp/protocol.htoinclude/net/mptcp.h. And move the related structmptcp_data_availand functionmptcp_subflow_ctx()too.Signed-off-by Geliang Tang <[email protected]>
I'm not sure I agree with moving all of this just because Martin asked about an inline function. I'll follow up on the netdev email thread.
- Mat
Quoted 224 lines
---
include/net/mptcp.h| 91 ++++++++++++++++++++++++++++++++++++++++++++net/mptcp/protocol.h| 88 ------------------------------------------2 files changed, 91 insertions(+), 88 deletions(-)include/net/mptcp.h +91
-0@@ -40,6 +40,86 @@ struct mptcp_ext { };#define MPTCPOPT_HMAC_LEN 20 + +enum mptcp_data_avail { +MPTCP_SUBFLOW_NODATA , +MPTCP_SUBFLOW_DATA_AVAIL , +}; + +/* MPTCP subflow context */ +struct mptcp_subflow_context { +struct list_head node;/* conn_list of subflows */ + + struct_group(reset, + + unsigned long avg_pacing_rate; /* protected by msk socket lock */ +u64 local_key; +u64 remote_key; +u64 idsn; +u64 map_seq; +u32 snd_isn; +u32 token; +u32 rel_write_seq; +u32 map_subflow_seq; +u32 ssn_offset; +u32 map_data_len; +__wsum map_data_csum; +u32 map_csum_len; +u32 request_mptcp :1 ,/* send MP_CAPABLE */ + request_join :1 ,/* send MP_JOIN */ + request_bkup :1 , + mp_capable :1 ,/* remote is MPTCP capable */ + mp_join :1 ,/* remote is JOINing */ + fully_established :1 ,/* path validated */ + pm_notified :1 ,/* PM hook called for established status */ + conn_finished :1 , + map_valid :1 , + map_csum_reqd :1 , + map_data_fin :1 , + mpc_map :1 , + backup :1 , + send_mp_prio :1 , + send_mp_fail :1 , + send_fastclose :1 , + send_infinite_map :1 , + rx_eof :1 , + can_ack :1 ,/* only after processing the remote a key */ + disposable :1 ,/* ctx can be free at ulp release time */ + stale :1 ,/* unable to snd/rcv data, do not use for xmit */ + local_id_valid :1 ,/* local_id is correctly initialized */ + valid_csum_seen :1 ;/* at least one csum validated */ +enum mptcp_data_avail data_avail; +bool mp_fail_response_expect; +u32 remote_nonce; +u64 thmac; +u32 local_nonce; +u32 remote_token; +u8 hmac[MPTCPOPT_HMAC_LEN ]; +u8 local_id; +u8 remote_id; +u8 reset_seen:1 ; +u8 reset_transient:1 ; +u8 reset_reason:4 ; +u8 stale_count; + +long delegated_status; + + ); + +struct list_head delegated_node;/* link into delegated_action, protected by local BH */ + +u32 setsockopt_seq; +u32 stale_rcv_tstamp; + +struct sock *tcp_sock;/* tcp sk backpointer */ +struct sock *conn;/* parent mptcp_sock */ +const struct inet_connection_sock_af_ops *icsk_af_ops; +void (*tcp_state_change)(struct sock *sk); +void (*tcp_error_report)(struct sock *sk); + +struct rcu_head rcu; +}; +#define MPTCP_RM_IDS_MAX 8struct mptcp_rm_list {@@ -198,6 +278,15 @@ static inline __be32 mptcp_reset_option(const struct sk_buff *skb) return htonl(0u); } + +static inline struct mptcp_subflow_context * +mptcp_subflow_ctx (const struct sock *sk) +{ +struct inet_connection_sock *icsk =inet_csk (sk); + +/* Use RCU on icsk_ulp_data only for sock diag code */ +return (__force struct mptcp_subflow_context *)icsk->icsk_ulp_data; +}#else static inline void mptcp_init (void )@@ -275,6 +364,8 @@ static inline int mptcp_subflow_init_cookie_req(struct request_sock *req, }static inline __be32 mptcp_reset_option (const struct sk_buff *skb) {return htonl (0u ); } +static inline struct mptcp_subflow_context * +mptcp_subflow_ctx (const struct sock *sk) {return NULL ; }#endif /* CONFIG_MPTCP */ #if IS_ENABLED (CONFIG_MPTCP_IPV6 )net/mptcp/protocol.h +0
-88@@ -409,11 +409,6 @@ mptcp_subflow_rsk(const struct request_sock *rsk)return (struct mptcp_subflow_request_sock *)rsk; } -enum mptcp_data_avail { -MPTCP_SUBFLOW_NODATA , -MPTCP_SUBFLOW_DATA_AVAIL , -}; -struct mptcp_delegated_action {struct napi_struct napi;struct list_head head;@@ -424,89 +419,6 @@ DECLARE_PER_CPU(struct mptcp_delegated_action, mptcp_delegated_actions);#define MPTCP_DELEGATE_SEND 0#define MPTCP_DELEGATE_ACK 1 -/* MPTCP subflow context */ -struct mptcp_subflow_context { -struct list_head node;/* conn_list of subflows */ - - struct_group(reset, - - unsigned long avg_pacing_rate; /* protected by msk socket lock */ -u64 local_key; -u64 remote_key; -u64 idsn; -u64 map_seq; -u32 snd_isn; -u32 token; -u32 rel_write_seq; -u32 map_subflow_seq; -u32 ssn_offset; -u32 map_data_len; -__wsum map_data_csum; -u32 map_csum_len; -u32 request_mptcp :1 ,/* send MP_CAPABLE */ - request_join :1 ,/* send MP_JOIN */ - request_bkup :1 , - mp_capable :1 ,/* remote is MPTCP capable */ - mp_join :1 ,/* remote is JOINing */ - fully_established :1 ,/* path validated */ - pm_notified :1 ,/* PM hook called for established status */ - conn_finished :1 , - map_valid :1 , - map_csum_reqd :1 , - map_data_fin :1 , - mpc_map :1 , - backup :1 , - send_mp_prio :1 , - send_mp_fail :1 , - send_fastclose :1 , - send_infinite_map :1 , - rx_eof :1 , - can_ack :1 ,/* only after processing the remote a key */ - disposable :1 ,/* ctx can be free at ulp release time */ - stale :1 ,/* unable to snd/rcv data, do not use for xmit */ - local_id_valid :1 ,/* local_id is correctly initialized */ - valid_csum_seen :1 ;/* at least one csum validated */ -enum mptcp_data_avail data_avail; -bool mp_fail_response_expect; -u32 remote_nonce; -u64 thmac; -u32 local_nonce; -u32 remote_token; -u8 hmac[MPTCPOPT_HMAC_LEN ]; -u8 local_id; -u8 remote_id; -u8 reset_seen:1 ; -u8 reset_transient:1 ; -u8 reset_reason:4 ; -u8 stale_count; - -long delegated_status; - - ); - -struct list_head delegated_node;/* link into delegated_action, protected by local BH */ - -u32 setsockopt_seq; -u32 stale_rcv_tstamp; - -struct sock *tcp_sock;/* tcp sk backpointer */ -struct sock *conn;/* parent mptcp_sock */ -const struct inet_connection_sock_af_ops *icsk_af_ops; -void (*tcp_state_change)(struct sock *sk); -void (*tcp_error_report)(struct sock *sk); - -struct rcu_head rcu; -}; - -static inline struct mptcp_subflow_context * -mptcp_subflow_ctx (const struct sock *sk) -{ -struct inet_connection_sock *icsk =inet_csk (sk); - -/* Use RCU on icsk_ulp_data only for sock diag code */ -return (__force struct mptcp_subflow_context *)icsk->icsk_ulp_data; -} -
Quoted 8 lines
static inline struct sock *
mptcp_subflow_tcp_sock(const struct mptcp_subflow_context *subflow){Signature · 1 line
2.34.1
--
Mat Martineau
Intel
Re: [PATCH mptcp-next 02/17] mptcp: move mptcp_subflow_context in net/mptcp.h
Quoted 8 lines
Quoted 5 lines
Move struct
mptcp_subflow_contextdefinition fromnet/mptcp/protocol.htoinclude/net/mptcp.h. And move the related structmptcp_data_availand functionmptcp_subflow_ctx()too.Signed-off-by Geliang Tang <[email protected]>I'm not sure I agree with moving all of this just because Martin asked about an inline function. I'll follow up on the netdev email thread.
Mat, I removed the first three patches in v2. Could patch 1 still be used as an effective cleanup?
Thanks,
-Geliang
Quoted 240 lines
- Mat
Quoted 224 lines
---
include/net/mptcp.h| 91 ++++++++++++++++++++++++++++++++++++++++++++net/mptcp/protocol.h| 88 ------------------------------------------2 files changed, 91 insertions(+), 88 deletions(-)include/net/mptcp.h +91
-0@@ -40,6 +40,86 @@ struct mptcp_ext { };#define MPTCPOPT_HMAC_LEN 20 + +enum mptcp_data_avail { +MPTCP_SUBFLOW_NODATA , +MPTCP_SUBFLOW_DATA_AVAIL , +}; + +/* MPTCP subflow context */ +struct mptcp_subflow_context { +struct list_head node;/* conn_list of subflows */ + + struct_group(reset, + + unsigned long avg_pacing_rate; /* protected by msk socket lock */ +u64 local_key; +u64 remote_key; +u64 idsn; +u64 map_seq; +u32 snd_isn; +u32 token; +u32 rel_write_seq; +u32 map_subflow_seq; +u32 ssn_offset; +u32 map_data_len; +__wsum map_data_csum; +u32 map_csum_len; +u32 request_mptcp :1 ,/* send MP_CAPABLE */ + request_join :1 ,/* send MP_JOIN */ + request_bkup :1 , + mp_capable :1 ,/* remote is MPTCP capable */ + mp_join :1 ,/* remote is JOINing */ + fully_established :1 ,/* path validated */ + pm_notified :1 ,/* PM hook called for established status */ + conn_finished :1 , + map_valid :1 , + map_csum_reqd :1 , + map_data_fin :1 , + mpc_map :1 , + backup :1 , + send_mp_prio :1 , + send_mp_fail :1 , + send_fastclose :1 , + send_infinite_map :1 , + rx_eof :1 , + can_ack :1 ,/* only after processing the remote a key */ + disposable :1 ,/* ctx can be free at ulp release time */ + stale :1 ,/* unable to snd/rcv data, do not use for xmit */ + local_id_valid :1 ,/* local_id is correctly initialized */ + valid_csum_seen :1 ;/* at least one csum validated */ +enum mptcp_data_avail data_avail; +bool mp_fail_response_expect; +u32 remote_nonce; +u64 thmac; +u32 local_nonce; +u32 remote_token; +u8 hmac[MPTCPOPT_HMAC_LEN ]; +u8 local_id; +u8 remote_id; +u8 reset_seen:1 ; +u8 reset_transient:1 ; +u8 reset_reason:4 ; +u8 stale_count; + +long delegated_status; + + ); + +struct list_head delegated_node;/* link into delegated_action, protected by local BH */ + +u32 setsockopt_seq; +u32 stale_rcv_tstamp; + +struct sock *tcp_sock;/* tcp sk backpointer */ +struct sock *conn;/* parent mptcp_sock */ +const struct inet_connection_sock_af_ops *icsk_af_ops; +void (*tcp_state_change)(struct sock *sk); +void (*tcp_error_report)(struct sock *sk); + +struct rcu_head rcu; +}; +#define MPTCP_RM_IDS_MAX 8struct mptcp_rm_list {@@ -198,6 +278,15 @@ static inline __be32 mptcp_reset_option(const struct sk_buff *skb) return htonl(0u); } + +static inline struct mptcp_subflow_context * +mptcp_subflow_ctx (const struct sock *sk) +{ +struct inet_connection_sock *icsk =inet_csk (sk); + +/* Use RCU on icsk_ulp_data only for sock diag code */ +return (__force struct mptcp_subflow_context *)icsk->icsk_ulp_data; +}#else static inline void mptcp_init (void )@@ -275,6 +364,8 @@ static inline int mptcp_subflow_init_cookie_req(struct request_sock *req, }static inline __be32 mptcp_reset_option (const struct sk_buff *skb) {return htonl (0u ); } +static inline struct mptcp_subflow_context * +mptcp_subflow_ctx (const struct sock *sk) {return NULL ; }#endif /* CONFIG_MPTCP */ #if IS_ENABLED (CONFIG_MPTCP_IPV6 )net/mptcp/protocol.h +0
-88@@ -409,11 +409,6 @@ mptcp_subflow_rsk(const struct request_sock *rsk)return (struct mptcp_subflow_request_sock *)rsk; } -enum mptcp_data_avail { -MPTCP_SUBFLOW_NODATA , -MPTCP_SUBFLOW_DATA_AVAIL , -}; -struct mptcp_delegated_action {struct napi_struct napi;struct list_head head;@@ -424,89 +419,6 @@ DECLARE_PER_CPU(struct mptcp_delegated_action, mptcp_delegated_actions);#define MPTCP_DELEGATE_SEND 0#define MPTCP_DELEGATE_ACK 1 -/* MPTCP subflow context */ -struct mptcp_subflow_context { -struct list_head node;/* conn_list of subflows */ - - struct_group(reset, - - unsigned long avg_pacing_rate; /* protected by msk socket lock */ -u64 local_key; -u64 remote_key; -u64 idsn; -u64 map_seq; -u32 snd_isn; -u32 token; -u32 rel_write_seq; -u32 map_subflow_seq; -u32 ssn_offset; -u32 map_data_len; -__wsum map_data_csum; -u32 map_csum_len; -u32 request_mptcp :1 ,/* send MP_CAPABLE */ - request_join :1 ,/* send MP_JOIN */ - request_bkup :1 , - mp_capable :1 ,/* remote is MPTCP capable */ - mp_join :1 ,/* remote is JOINing */ - fully_established :1 ,/* path validated */ - pm_notified :1 ,/* PM hook called for established status */ - conn_finished :1 , - map_valid :1 , - map_csum_reqd :1 , - map_data_fin :1 , - mpc_map :1 , - backup :1 , - send_mp_prio :1 , - send_mp_fail :1 , - send_fastclose :1 , - send_infinite_map :1 , - rx_eof :1 , - can_ack :1 ,/* only after processing the remote a key */ - disposable :1 ,/* ctx can be free at ulp release time */ - stale :1 ,/* unable to snd/rcv data, do not use for xmit */ - local_id_valid :1 ,/* local_id is correctly initialized */ - valid_csum_seen :1 ;/* at least one csum validated */ -enum mptcp_data_avail data_avail; -bool mp_fail_response_expect; -u32 remote_nonce; -u64 thmac; -u32 local_nonce; -u32 remote_token; -u8 hmac[MPTCPOPT_HMAC_LEN ]; -u8 local_id; -u8 remote_id; -u8 reset_seen:1 ; -u8 reset_transient:1 ; -u8 reset_reason:4 ; -u8 stale_count; - -long delegated_status; - - ); - -struct list_head delegated_node;/* link into delegated_action, protected by local BH */ - -u32 setsockopt_seq; -u32 stale_rcv_tstamp; - -struct sock *tcp_sock;/* tcp sk backpointer */ -struct sock *conn;/* parent mptcp_sock */ -const struct inet_connection_sock_af_ops *icsk_af_ops; -void (*tcp_state_change)(struct sock *sk); -void (*tcp_error_report)(struct sock *sk); - -struct rcu_head rcu; -}; - -static inline struct mptcp_subflow_context * -mptcp_subflow_ctx (const struct sock *sk) -{ -struct inet_connection_sock *icsk =inet_csk (sk); - -/* Use RCU on icsk_ulp_data only for sock diag code */ -return (__force struct mptcp_subflow_context *)icsk->icsk_ulp_data; -} -Quoted 8 lines
static inline struct sock *
mptcp_subflow_tcp_sock(const struct mptcp_subflow_context *subflow){
--
2.34.1--
Mat Martineau
Intel
Re: [PATCH mptcp-next 02/17] mptcp: move mptcp_subflow_context in net/mptcp.h
Quoted 11 lines · Geliang Tang
Quoted 8 lines
Quoted 5 lines
Move struct
mptcp_subflow_contextdefinition fromnet/mptcp/protocol.htoinclude/net/mptcp.h. And move the related structmptcp_data_availand functionmptcp_subflow_ctx()too.Signed-off-by Geliang Tang <[email protected]>I'm not sure I agree with moving all of this just because Martin asked about an inline function. I'll follow up on the netdev email thread.
Mat, I removed the first three patches in v2. Could patch 1 still be used as an effective cleanup?
Sure, I'll update that in patchwork.
--
Mat Martineau
Intel
Re: [PATCH mptcp-next 01/17] mptcp: move MPTCPOPT_HMAC_LEN to net/mptcp.h
In reply to Geliang TangQuoted 4 lines · Geliang Tang
Move macro
MPTCPOPT_HMAC_LENdefinition fromnet/mptcp/protocol.htoinclude/net/mptcp.h.Signed-off-by Geliang Tang <[email protected]>
This one's fine for the mptcp tree (will upstream to net-next):
Quoted 43 lines
---
include/net/mptcp.h| 3 ++-net/mptcp/protocol.h| 1 -2 files changed, 2 insertions(+), 2 deletions(-)include/net/mptcp.h +2
-1@@ -39,6 +39,7 @@ struct mptcp_ext { infinite_map:1 ; }; +#define MPTCPOPT_HMAC_LEN 20#define MPTCP_RM_IDS_MAX 8struct mptcp_rm_list {@@ -89,7 +90,7 @@ struct mptcp_out_options {u32 nonce;u32 token;u64 thmac; - u8 hmac[20]; + u8 hmac[MPTCPOPT_HMAC_LEN]; }; };#endif net/mptcp/protocol.h +0
-1@@ -83,7 +83,6 @@/* MPTCP MP_JOIN flags */ #define MPTCPOPT_BACKUP BIT(0) -#define MPTCPOPT_HMAC_LEN 20#define MPTCPOPT_THMAC_LEN 8/* MPTCP MP_CAPABLE flags */ Signature · 1 line
2.34.1
--
Mat Martineau
Intel
Re: [PATCH mptcp-next 01/17] mptcp: move MPTCPOPT_HMAC_LEN to net/mptcp.h
Hi Geliang, Mat,
Quoted 10 lines · Mat Martineau
Quoted 4 lines · Geliang Tang
Move macro
MPTCPOPT_HMAC_LENdefinition fromnet/mptcp/protocol.htoinclude/net/mptcp.h.Signed-off-by Geliang Tang <[email protected]>This one's fine for the mptcp tree (will upstream to net-next):
Reviewed-by Mat Martineau <[email protected]>
Thank you for the patch and the review!
Now in our tree (feat. for net-next) with Mat's RvB tag:
New patches for t/upstream:
- e4afdbb036ca: mptcp: move MPTCPOPT_HMAC_LEN to net/mptcp.h
- Results: 086d4a4a0f34..52d9427a77d9 (export)
Builds and tests are now in progress:
https://cirrus-ci.com/github/multipath-tcp/mptcp_net-next/export/20220519T160645
Cheers,
Matt
Signature · 2 lines
Tessares | Belgium | Hybrid Access Solutions www.tessares.net