Multipath TCP part 3: Multiple subflows and path management
Subsystems (5)
v2 cover Multipath TCP part 3: Multiple subflows and path management
v1 -> v2: Rebase on current net-next, fix for netlink limit setting, and update .gitignore for selftest.
This patch set allows more than one TCP subflow to be established and used for a multipath TCP connection. Subflows are added to an existing connection using the MP_JOIN option during the 3-way handshake. With multiple TCP subflows available, sent data is now stored in the MPTCP socket so it may be retransmitted on any TCP subflow if there is no DATA_ACK before a timeout. If an MPTCP-level timeout occurs, data is retransmitted using an available subflow. Storing this sent data requires the addition of memory accounting at the MPTCP level, which was previously delegated to the single subflow. Incoming DATA_ACKs now free data from the MPTCP-level retransmit buffer.
IP addresses available for new subflow connections can now be advertised and received with the ADD_ADDR option, and the corresponding REMOVE_ADDR option likewise advertises that an address is no longer available.
The MPTCP path manager netlink interface has commands to set in-kernel limits for the number of concurrent subflows and control the advertisement of IP addresses between peers.
To track and debug MPTCP connections there are new MPTCP MIB counters, and subflow context can be requested using inet_diag. The MPTCP self-tests now validate multiple-subflow operation and the netlink path manager interface.
Clone/fetch:
https://github.com/multipath-tcp/mptcp_net-next.git (tag: netdev-for-5.7-part3-v2)
Browse:
https://github.com/multipath-tcp/mptcp_net-next/tree/netdev-for-5.7-part3-v2
Thank you for your review. You can find us at [email protected] and
https://is.gd/mptcp_upstream
Davide Caratti (1):
mptcp: allow dumping subflow context to userspace
Florian Westphal (2):
mptcp: allow partial cleaning of rtx head dfrag
mptcp: add and use MIB counter infrastructure
Paolo Abeni (9):
mptcp: update per unacked sequence on pkt reception
mptcp: queue data for mptcp level retransmission
mptcp: introduce MPTCP retransmission timer
mptcp: implement memory accounting for mptcp rtx queue
mptcp: rework mptcp_sendmsg_frag to accept optional dfrag
mptcp: implement and use MPTCP-level retransmission
mptcp: add netlink-based PM
selftests: add PM netlink functional tests
selftests: add test-cases for MPTCP MP_JOIN
Peter Krystad (5):
mptcp: Add ADD_ADDR handling
mptcp: Add path manager interface
mptcp: Add handling of incoming MP_JOIN requests
mptcp: Add handling of outgoing MP_JOIN requests
mptcp: Implement path manager interface commands
MAINTAINERS | 1 + include/linux/tcp.h | 26 +- include/net/mptcp.h | 26 + include/net/netns/mib.h | 3 + include/uapi/linux/inet_diag.h | 1 + include/uapi/linux/mptcp.h | 88 ++ net/ipv4/af_inet.c | 4 + net/ipv4/proc.c | 2 + net/ipv4/tcp_minisocks.c | 6 + net/mptcp/Makefile | 3 +- net/mptcp/crypto.c | 17 +- net/mptcp/diag.c | 104 +++ net/mptcp/mib.c | 69 ++ net/mptcp/mib.h | 40 + net/mptcp/options.c | 515 ++++++++++- net/mptcp/pm.c | 242 +++++ net/mptcp/pm_netlink.c | 857 ++++++++++++++++++ net/mptcp/protocol.c | 584 +++++++++++- net/mptcp/protocol.h | 187 +++- net/mptcp/subflow.c | 337 ++++++- net/mptcp/token.c | 27 + tools/testing/selftests/net/mptcp/.gitignore | 1 + tools/testing/selftests/net/mptcp/Makefile | 7 +- .../selftests/net/mptcp/mptcp_connect.c | 28 +- .../testing/selftests/net/mptcp/mptcp_join.sh | 357 ++++++++ .../testing/selftests/net/mptcp/pm_netlink.sh | 130 +++ tools/testing/selftests/net/mptcp/pm_nl_ctl.c | 616 +++++++++++++ 27 files changed, 4155 insertions(+), 123 deletions(-) create mode 100644 include/uapi/linux/mptcp.h create mode 100644 net/mptcp/diag.c create mode 100644 net/mptcp/mib.c create mode 100644 net/mptcp/mib.h create mode 100644 net/mptcp/pm.c create mode 100644 net/mptcp/pm_netlink.c create mode 100755 tools/testing/selftests/net/mptcp/mptcp_join.sh create mode 100755 tools/testing/selftests/net/mptcp/pm_netlink.sh create mode 100644 tools/testing/selftests/net/mptcp/pm_nl_ctl.c
base-commit: 14340219b89c98d96170721d38378252db206e69
Signature · 1 line
2.26.0
PATCH v2 1/17 mptcp: Add ADD_ADDR handling
From: Peter Krystad <[email protected]>
Add handling for sending and receiving the ADD_ADDR, ADD_ADDR6, and RM_ADDR suboptions.
--- include/linux/tcp.h | 20 ++++- include/net/mptcp.h | 9 ++ net/mptcp/crypto.c | 17 ++-- net/mptcp/options.c | 206 +++++++++++++++++++++++++++++++++++++++++-- net/mptcp/protocol.h | 28 +++++- 5 files changed, 262 insertions(+), 18 deletions(-)
include/linux/tcp.h +18 -2
@@ -86,9 +86,13 @@ struct mptcp_options_received {u64 data_seq;u32 subflow_seq;u16 data_len; - u8 mp_capable : 1, + u16 mp_capable : 1, mp_join : 1, - dss : 1; + dss : 1, + add_addr : 1, + rm_addr : 1, + family : 4, + echo : 1; u8 use_map:1, dsn64:1, data_fin:1,
@@ -96,6 +100,16 @@ struct mptcp_options_received { ack64:1, mpc_map:1, __unused:2; +u8 addr_id; +u8 rm_id; +union { +struct in_addr addr; +#if IS_ENABLED (CONFIG_MPTCP_IPV6 ) +struct in6_addr addr6; +#endif + }; +u64 ahmac; + u16 port; };#endif
@@ -131,6 +145,8 @@ static inline void tcp_clear_options(struct tcp_options_received *rx_opt)#if IS_ENABLED (CONFIG_MPTCP ) rx_opt->mptcp.mp_capable =0 ; rx_opt->mptcp.mp_join =0 ; + rx_opt->mptcp.add_addr =0 ; + rx_opt->mptcp.rm_addr =0 ; rx_opt->mptcp.dss =0 ;#endif }
include/net/mptcp.h +9 -0
@@ -33,6 +33,15 @@ struct mptcp_out_options {u16 suboptions;u64 sndr_key;u64 rcvr_key; +union { +struct in_addr addr; +#if IS_ENABLED (CONFIG_MPTCP_IPV6 ) +struct in6_addr addr6; +#endif + }; +u8 addr_id; +u64 ahmac; +u8 rm_id;struct mptcp_ext ext_copy;#endif };
net/mptcp/crypto.c +11 -6
@@ -44,8 +44,7 @@ void mptcp_crypto_key_sha(u64 key, u32 *token, u64 *idsn) *idsn =be64_to_cpu (*((__be64 *)&mptcp_hashed_key[6 ])); } -void mptcp_crypto_hmac_sha (u64 key1,u64 key2,u32 nonce1,u32 nonce2, -void *hmac) +void mptcp_crypto_hmac_sha (u64 key1,u64 key2,u8 *msg,int len,void *hmac) {u8 input[SHA256_BLOCK_SIZE +SHA256_DIGEST_SIZE ];__be32 mptcp_hashed_key[SHA256_DIGEST_WORDS ];
@@ -55,6 +54,9 @@ void mptcp_crypto_hmac_sha(u64 key1, u64 key2, u32 nonce1, u32 nonce2,u8 key2be[8 ];int i; +if (WARN_ON_ONCE (len >SHA256_DIGEST_SIZE )) + len =SHA256_DIGEST_SIZE ; +put_unaligned_be64 (key1, key1be);put_unaligned_be64 (key2, key2be);
@@ -65,11 +67,10 @@ void mptcp_crypto_hmac_sha(u64 key1, u64 key2, u32 nonce1, u32 nonce2,for (i =0 ; i <8 ; i++) input[i +8 ] ^= key2be[i]; -put_unaligned_be32 (nonce1, &input[SHA256_BLOCK_SIZE ]); -put_unaligned_be32 (nonce2, &input[SHA256_BLOCK_SIZE +4 ]); +memcpy (&input[SHA256_BLOCK_SIZE ], msg, len);sha256_init (&state); -sha256_update (&state, input,SHA256_BLOCK_SIZE +8 ); +sha256_update (&state, input,SHA256_BLOCK_SIZE + len);/* emit sha256(K1 || msg) on the second input block, so we can * reuse 'input' for the last hashing
@@ -125,6 +126,7 @@ static int __init test_mptcp_crypto(void)char hmac[20 ], hmac_hex[41 ];u32 nonce1, nonce2;u64 key1, key2; +u8 msg[8 ];int i, j;for (i =0 ; i <ARRAY_SIZE (tests); ++i) {
@@ -134,7 +136,10 @@ static int __init test_mptcp_crypto(void) nonce1 =be32_to_cpu (*((__be32 *)&tests[i].msg[0 ])); nonce2 =be32_to_cpu (*((__be32 *)&tests[i].msg[4 ])); -mptcp_crypto_hmac_sha (key1, key2, nonce1, nonce2, hmac); +put_unaligned_be32 (nonce1, &msg[0 ]); +put_unaligned_be32 (nonce2, &msg[4 ]); + +mptcp_crypto_hmac_sha (key1, key2, msg,8 , hmac);for (j =0 ; j <20 ; ++j)sprintf (&hmac_hex[j <<1 ],"%02x" , hmac[j] &0xff ); hmac_hex[40 ] =0 ;
net/mptcp/options.c +198 -8
248 lines not on this page · raw message
net/mptcp/protocol.h +26 -2
@@ -17,6 +17,9 @@#define OPTION_MPTCP_MPC_SYN BIT(0)#define OPTION_MPTCP_MPC_SYNACK BIT(1)#define OPTION_MPTCP_MPC_ACK BIT(2) +#define OPTION_MPTCP_ADD_ADDR BIT(6) +#define OPTION_MPTCP_ADD_ADDR6 BIT(7) +#define OPTION_MPTCP_RM_ADDR BIT(8)/* MPTCP option subtypes */ #define MPTCPOPT_MP_CAPABLE 0
@@ -39,6 +42,16 @@#define TCPOLEN_MPTCP_DSS_MAP32 10#define TCPOLEN_MPTCP_DSS_MAP64 14#define TCPOLEN_MPTCP_DSS_CHECKSUM 2 +#define TCPOLEN_MPTCP_ADD_ADDR 16 +#define TCPOLEN_MPTCP_ADD_ADDR_PORT 18 +#define TCPOLEN_MPTCP_ADD_ADDR_BASE 8 +#define TCPOLEN_MPTCP_ADD_ADDR_BASE_PORT 10 +#define TCPOLEN_MPTCP_ADD_ADDR6 28 +#define TCPOLEN_MPTCP_ADD_ADDR6_PORT 30 +#define TCPOLEN_MPTCP_ADD_ADDR6_BASE 20 +#define TCPOLEN_MPTCP_ADD_ADDR6_BASE_PORT 22 +#define TCPOLEN_MPTCP_PORT_LEN 2 +#define TCPOLEN_MPTCP_RM_ADDR_BASE 4/* MPTCP MP_CAPABLE flags */ #define MPTCP_VERSION_MASK (0x0F)
@@ -55,10 +68,22 @@#define MPTCP_DSS_HAS_ACK BIT(0)#define MPTCP_DSS_FLAG_MASK (0x1F) +/* MPTCP ADD_ADDR flags */ +#define MPTCP_ADDR_ECHO BIT(0) +#define MPTCP_ADDR_HMAC_LEN 20 +#define MPTCP_ADDR_IPVERSION_4 4 +#define MPTCP_ADDR_IPVERSION_6 6 +/* MPTCP socket flags */ #define MPTCP_DATA_READY 0#define MPTCP_SEND_SPACE 1 +static inline __be32 mptcp_option (u8 subopt,u8 len,u8 nib,u8 field) +{ +return htonl ((TCPOPT_MPTCP <<24 ) | (len <<16 ) | (subopt <<12 ) | + ((nib &0xF ) <<8 ) | field); +} +/* MPTCP connection sock */ struct mptcp_sock {/* inet_connection_sock must be the first member */
@@ -219,8 +244,7 @@ static inline void mptcp_crypto_key_gen_sha(u64 *key, u32 *token, u64 *idsn)mptcp_crypto_key_sha (*key, token, idsn); } -void mptcp_crypto_hmac_sha (u64 key1,u64 key2,u32 nonce1,u32 nonce2, -void *hash_out); +void mptcp_crypto_hmac_sha (u64 key1,u64 key2,u8 *msg,int len,void *hmac);static inline struct mptcp_ext *mptcp_get_ext (struct sk_buff *skb) {
Signature · 1 line
2.26.0
PATCH v2 2/17 mptcp: Add path manager interface
In reply to Mat MartineauFrom: Peter Krystad <[email protected]>
Add enough of a path manager interface to allow sending of ADD_ADDR when an incoming MPTCP connection is created. Capable of sending only a single IPv4 ADD_ADDR option. The 'pm_data' element of the connection sock will need to be expanded to handle multiple interfaces and IPv6. Partial processing of the incoming ADD_ADDR is included so the path manager notification of that event happens at the proper time, which involves validating the incoming address information.
This is a skeleton interface definition for events generated by MPTCP.
--- net/mptcp/Makefile | 2 +- net/mptcp/options.c | 80 ++++++++++++++++++++++++------ net/mptcp/pm.c | 113 +++++++++++++++++++++++++++++++++++++++++++ net/mptcp/protocol.c | 5 ++ net/mptcp/protocol.h | 79 ++++++++++++++++++++++++++++++ net/mptcp/subflow.c | 4 +- 6 files changed, 264 insertions(+), 19 deletions(-) create mode 100644 net/mptcp/pm.c
net/mptcp/Makefile +1 -1
@@ -1,4 +1,4 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_MPTCP) += mptcp.o -mptcp-y := protocol.o subflow.o options.o token.o crypto.o ctrl.o +mptcp-y := protocol.o subflow.o options.o token.o crypto.o ctrl.o pm.o
net/mptcp/options.c +64 -16
122 lines not on this page · raw message
net/mptcp/pm.c new file +113 -0
113 lines not on this page · raw message
net/mptcp/protocol.c +5 -0
@@ -703,6 +703,8 @@ static int __mptcp_init_sock(struct sock *sk) msk->first =NULL ;inet_csk (sk)->icsk_sync_mss = mptcp_sync_mss; +mptcp_pm_data_init (msk); +return 0 ; }
@@ -1055,6 +1057,8 @@ void mptcp_finish_connect(struct sock *ssk)WRITE_ONCE (msk->write_seq, subflow->idsn +1 );WRITE_ONCE (msk->ack_seq, ack_seq);WRITE_ONCE (msk->can_ack,1 ); + +mptcp_pm_new_connection (msk,0 ); }static void mptcp_sock_graft (struct sock *sk,struct socket *parent)
@@ -1377,6 +1381,7 @@ void mptcp_proto_init(void) mptcp_prot.h.hashinfo = tcp_prot.h.hashinfo;mptcp_subflow_init (); +mptcp_pm_init ();if (proto_register (&mptcp_prot,1 ) !=0 )panic ("Failed to register MPTCP proto.\n" );
net/mptcp/protocol.h +79 -0
103 lines not on this page · raw message
net/mptcp/subflow.c +2 -2
@@ -240,8 +240,8 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk,/* new mpc subflow takes ownership of the newly * created mptcp socket */ -inet_sk_state_store ((struct sock *)new_msk, -TCP_ESTABLISHED ); +inet_sk_state_store (new_msk,TCP_ESTABLISHED ); +mptcp_pm_new_connection (mptcp_sk (new_msk),1 ); ctx->conn = new_msk; new_msk =NULL ; }
Signature · 1 line
2.26.0
PATCH v2 3/17 mptcp: Add handling of incoming MP_JOIN requests
In reply to Mat MartineauFrom: Peter Krystad <[email protected]>
Process the MP_JOIN option in a SYN packet with the same flow as MP_CAPABLE but when the third ACK is received add the subflow to the MPTCP socket subflow list instead of adding it to the TCP socket accept queue.
The subflow is added at the end of the subflow list so it will not interfere with the existing subflows operation and no data is expected to be transmitted on it.
--- include/linux/tcp.h | 8 +- include/net/mptcp.h | 11 +++ net/ipv4/tcp_minisocks.c | 6 ++ net/mptcp/options.c | 107 +++++++++++++++++++++++--- net/mptcp/protocol.c | 96 +++++++++++++++++++----- net/mptcp/protocol.h | 23 ++++++ net/mptcp/subflow.c | 158 +++++++++++++++++++++++++++++++++++---- net/mptcp/token.c | 27 +++++++ 8 files changed, 390 insertions(+), 46 deletions(-)
include/linux/tcp.h +7 -1
@@ -92,7 +92,13 @@ struct mptcp_options_received { add_addr : 1, rm_addr : 1, family : 4, - echo : 1; + echo : 1, + backup : 1; +u32 token; +u32 nonce; +u64 thmac; +u8 hmac[20 ]; +u8 join_id; u8 use_map:1, dsn64:1, data_fin:1,
include/net/mptcp.h +11 -0
@@ -42,6 +42,10 @@ struct mptcp_out_options {u8 addr_id;u64 ahmac;u8 rm_id; +u8 join_id; +u8 backup; +u32 nonce; +u64 thmac;struct mptcp_ext ext_copy;#endif };
@@ -115,6 +119,8 @@ static inline bool mptcp_skb_can_collapse(const struct sk_buff *to, skb_ext_find(from, SKB_EXT_MPTCP)); } +bool mptcp_sk_is_subflow (const struct sock *sk); +#else static inline void mptcp_init (void )
@@ -181,6 +187,11 @@ static inline bool mptcp_skb_can_collapse(const struct sk_buff *to, return true; } +static inline bool mptcp_sk_is_subflow (const struct sock *sk) +{ +return false; +} +#endif /* CONFIG_MPTCP */ #if IS_ENABLED (CONFIG_MPTCP_IPV6 )
net/ipv4/tcp_minisocks.c +6 -0
@@ -774,6 +774,12 @@ struct sock *tcp_check_req(struct sock *sk, struct sk_buff *skb,if (!child) goto listen_overflow; +if (own_req &&sk_is_mptcp (child) &&mptcp_sk_is_subflow (child)) { +reqsk_queue_removed (&inet_csk (sk)->icsk_accept_queue, req); +inet_csk_reqsk_queue_drop_and_put (sk, req); +return child; + } +sock_rps_save_rxhash (child, skb);tcp_synack_rtt_meas (child, req); *req_stolen = !own_req;
net/mptcp/options.c +95 -12
159 lines not on this page · raw message
net/mptcp/protocol.c +79 -17
120 lines not on this page · raw message
net/mptcp/protocol.h +23 -0
@@ -17,6 +17,9 @@#define OPTION_MPTCP_MPC_SYN BIT(0)#define OPTION_MPTCP_MPC_SYNACK BIT(1)#define OPTION_MPTCP_MPC_ACK BIT(2) +#define OPTION_MPTCP_MPJ_SYN BIT(3) +#define OPTION_MPTCP_MPJ_SYNACK BIT(4) +#define OPTION_MPTCP_MPJ_ACK BIT(5)#define OPTION_MPTCP_ADD_ADDR BIT(6)#define OPTION_MPTCP_ADD_ADDR6 BIT(7)#define OPTION_MPTCP_RM_ADDR BIT(8)
@@ -36,6 +39,9 @@#define TCPOLEN_MPTCP_MPC_SYNACK 12#define TCPOLEN_MPTCP_MPC_ACK 20#define TCPOLEN_MPTCP_MPC_ACK_DATA 22 +#define TCPOLEN_MPTCP_MPJ_SYN 12 +#define TCPOLEN_MPTCP_MPJ_SYNACK 16 +#define TCPOLEN_MPTCP_MPJ_ACK 24#define TCPOLEN_MPTCP_DSS_BASE 4#define TCPOLEN_MPTCP_DSS_ACK32 4#define TCPOLEN_MPTCP_DSS_ACK64 8
@@ -53,6 +59,9 @@#define TCPOLEN_MPTCP_PORT_LEN 2#define TCPOLEN_MPTCP_RM_ADDR_BASE 4 +#define MPTCPOPT_BACKUP BIT(0) +#define MPTCPOPT_HMAC_LEN 20 +/* MPTCP MP_CAPABLE flags */ #define MPTCP_VERSION_MASK (0x0F)#define MPTCP_CAP_CHECKSUM_REQD BIT(7)
@@ -162,11 +171,15 @@ struct mptcp_subflow_request_sock { backup :1 , remote_key_valid : 1;u8 local_id; +u8 remote_id;u64 local_key;u64 remote_key;u64 idsn;u32 token;u32 ssn_offset; +u64 thmac; +u32 local_nonce; +u32 remote_nonce; }; static inline struct mptcp_subflow_request_sock *
@@ -190,15 +203,23 @@ struct mptcp_subflow_context {u32 map_data_len; u32 request_mptcp : 1, /* send MP_CAPABLE */ 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, mpc_map : 1, + backup : 1, data_avail : 1, rx_eof : 1, data_fin_tx_enable : 1, can_ack : 1; /* only after processing the remote a key */u64 data_fin_tx_seq; +u32 remote_nonce; +u64 thmac; +u32 local_nonce; +u8 local_id; +u8 remote_id;struct sock *tcp_sock;/* tcp sk backpointer */ struct sock *conn;/* parent mptcp_sock */
@@ -270,11 +291,13 @@ void mptcp_get_options(const struct sk_buff *skb,void mptcp_finish_connect (struct sock *sk);void mptcp_data_ready (struct sock *sk,struct sock *ssk); +bool mptcp_finish_join (struct sock *sk);int mptcp_token_new_request (struct request_sock *req);void mptcp_token_destroy_request (u32 token);int mptcp_token_new_connect (struct sock *sk);int mptcp_token_new_accept (u32 token,struct sock *conn); +struct mptcp_sock *mptcp_token_get_sock (u32 token);void mptcp_token_destroy (u32 token);void mptcp_crypto_key_sha (u64 key,u32 *token,u64 *idsn);
net/mptcp/subflow.c +142 -16
250 lines not on this page · raw message
net/mptcp/token.c +27 -0
@@ -140,6 +140,33 @@ int mptcp_token_new_accept(u32 token, struct sock *conn)return err; } +/** +* mptcp_token_get_sock - retrieve mptcp connection sock using its token +* @token: token of the mptcp connection to retrieve +* +* This function returns the mptcp connection structure with the given token. +* A reference count on the mptcp socket returned is taken. +* +* returns NULL if no connection with the given token value exists. +*/ +struct mptcp_sock *mptcp_token_get_sock (u32 token) +{ +struct sock *conn; + +spin_lock_bh (&token_tree_lock); + conn =radix_tree_lookup (&token_tree, token); +if (conn) { +/* token still reserved? */ +if (conn == (struct sock *)&token_used) + conn =NULL ; +else +sock_hold (conn); + } +spin_unlock_bh (&token_tree_lock); + +return mptcp_sk (conn); +} +/** * mptcp_token_destroy_request - remove mptcp connection/token * @token - token of mptcp connection to remove
Signature · 1 line
2.26.0
PATCH v2 4/17 mptcp: Add handling of outgoing MP_JOIN requests
In reply to Mat MartineauFrom: Peter Krystad <[email protected]>
Subflow creation may be initiated by the path manager when the primary connection is fully established and a remote address has been received via ADD_ADDR.
Create an in-kernel sock and use kernel_connect() to initiate connection.
Passive sockets can't acquire the mptcp socket lock at subflow creation time, so an additional list protected by a new spinlock is used to track the MPJ subflows.
Such list is spliced into conn_list tail every time the msk socket lock is acquired, so that it will not interfere with data flow on the original connection.
Data flow and connection failover not addressed by this commit.
--- include/net/mptcp.h | 2 + net/mptcp/options.c | 108 +++++++++++++++++++++++++++---- net/mptcp/protocol.c | 31 ++++++++- net/mptcp/protocol.h | 13 ++++ net/mptcp/subflow.c | 150 ++++++++++++++++++++++++++++++++++++++++++- 5 files changed, 287 insertions(+), 17 deletions(-)
include/net/mptcp.h +2 -0
@@ -46,6 +46,8 @@ struct mptcp_out_options {u8 backup;u32 nonce;u64 thmac; +u32 token; +u8 hmac[20 ];struct mptcp_ext ext_copy;#endif };
net/mptcp/options.c +94 -14
161 lines not on this page · raw message
net/mptcp/protocol.c +30 -1
@@ -241,6 +241,16 @@ void mptcp_data_ready(struct sock *sk, struct sock *ssk) sk->sk_data_ready (sk); } +static void __mptcp_flush_join_list (struct mptcp_sock *msk) +{ +if (likely (list_empty (&msk->join_list))) +return ; + +spin_lock_bh (&msk->join_list_lock); +list_splice_tail_init (&msk->join_list, &msk->conn_list); +spin_unlock_bh (&msk->join_list_lock); +} +static bool mptcp_ext_cache_refill (struct mptcp_sock *msk) {if (!msk->cached_ext)
@@ -462,6 +472,7 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)return ret >=0 ? ret + copied : (copied ? copied : ret); } +__mptcp_flush_join_list (msk); ssk =mptcp_subflow_get_send (msk);while (!sk_stream_memory_free (sk) || !ssk) { ret =sk_stream_wait_memory (sk, &timeo);
@@ -603,6 +614,7 @@ static int mptcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, len =min_t (size_t, len,INT_MAX ); target =sock_rcvlowat (sk, flags &MSG_WAITALL , len); +__mptcp_flush_join_list (msk);while (len > (size_t )copied) {int bytes_read;
@@ -718,6 +730,7 @@ static void mptcp_worker(struct work_struct *work)struct sock *sk = &msk->sk.icsk_inet.sk;lock_sock (sk); +__mptcp_flush_join_list (msk);__mptcp_move_skbs (msk);release_sock (sk);sock_put (sk);
@@ -727,7 +740,10 @@ static int __mptcp_init_sock(struct sock *sk) {struct mptcp_sock *msk =mptcp_sk (sk); +spin_lock_init (&msk->join_list_lock); +INIT_LIST_HEAD (&msk->conn_list); +INIT_LIST_HEAD (&msk->join_list);__set_bit (MPTCP_SEND_SPACE , &msk->flags);INIT_WORK (&msk->work, mptcp_worker);
@@ -800,6 +816,8 @@ static void mptcp_close(struct sock *sk, long timeout)mptcp_token_destroy (msk->token);inet_sk_state_store (sk,TCP_CLOSE ); +__mptcp_flush_join_list (msk); +list_splice_init (&msk->conn_list, &conn_list); data_fin_tx_seq = msk->write_seq;
@@ -1107,6 +1125,7 @@ bool mptcp_finish_join(struct sock *sk)struct mptcp_sock *msk =mptcp_sk (subflow->conn);struct sock *parent = (void *)msk;struct socket *parent_sock; +bool ret;pr_debug ("msk=%p, subflow=%p" , msk, subflow);
@@ -1122,7 +1141,15 @@ bool mptcp_finish_join(struct sock *sk)if (parent_sock && !sk->sk_socket)mptcp_sock_graft (sk, parent_sock); -return mptcp_pm_allow_new_subflow (msk); + ret =mptcp_pm_allow_new_subflow (msk); +if (ret) { +/* active connections are already on conn_list */ +spin_lock_bh (&msk->join_list_lock); +if (!WARN_ON_ONCE (!list_empty (&subflow->node))) +list_add_tail (&subflow->node, &msk->join_list); +spin_unlock_bh (&msk->join_list_lock); + } +return ret; }bool mptcp_sk_is_subflow (const struct sock *sk)
@@ -1311,6 +1338,7 @@ static int mptcp_stream_accept(struct socket *sock, struct socket *newsock,/* set ssk->sk_socket of accept()ed flows to mptcp socket. * This is needed so NOSPACE flag can be set from tcp stack. */ +__mptcp_flush_join_list (msk);list_for_each_entry (subflow, &msk->conn_list, node) {struct sock *ssk =mptcp_subflow_tcp_sock (subflow);
@@ -1392,6 +1420,7 @@ static int mptcp_shutdown(struct socket *sock, int how) sock->state =SS_CONNECTED ; } +__mptcp_flush_join_list (msk);mptcp_for_each_subflow (msk, subflow) {struct sock *tcp_sk =mptcp_subflow_tcp_sock (subflow);
net/mptcp/protocol.h +13 -0
@@ -59,8 +59,10 @@#define TCPOLEN_MPTCP_PORT_LEN 2#define TCPOLEN_MPTCP_RM_ADDR_BASE 4 +/* MPTCP MP_JOIN flags */ #define MPTCPOPT_BACKUP BIT(0)#define MPTCPOPT_HMAC_LEN 20 +#define MPTCPOPT_THMAC_LEN 8/* MPTCP MP_CAPABLE flags */ #define MPTCP_VERSION_MASK (0x0F)
@@ -148,8 +150,10 @@ struct mptcp_sock {u32 token;unsigned long flags;bool can_ack; +spinlock_t join_list_lock;struct work_struct work;struct list_head conn_list; +struct list_head join_list;struct skb_ext *cached_ext;/* for the next sendmsg */ struct socket *subflow;/* outgoing connect/listener/!mp_capable */ struct sock *first;
@@ -202,6 +206,8 @@ struct mptcp_subflow_context {u32 ssn_offset;u32 map_data_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 */
@@ -218,6 +224,8 @@ struct mptcp_subflow_context {u32 remote_nonce;u64 thmac;u32 local_nonce; +u32 remote_token; +u8 hmac[MPTCPOPT_HMAC_LEN ];u8 local_id;u8 remote_id;
@@ -263,6 +271,11 @@ mptcp_subflow_get_mapped_dsn(const struct mptcp_subflow_context *subflow)int mptcp_is_enabled (struct net *net);bool mptcp_subflow_data_available (struct sock *sk);void mptcp_subflow_init (void ); + +/* called with sk socket lock held */ +int __mptcp_subflow_connect (struct sock *sk,int ifindex, +const struct mptcp_addr_info *loc, +const struct mptcp_addr_info *remote);int mptcp_subflow_create_socket (struct sock *sk,struct socket **new_sock); static inline void mptcp_subflow_tcp_fallback(struct sock *sk,
net/mptcp/subflow.c +148 -2
198 lines not on this page · raw message
Signature · 1 line
2.26.0
PATCH v2 5/17 mptcp: Implement path manager interface commands
In reply to Mat MartineauFrom: Peter Krystad <[email protected]>
Fill in more path manager functionality by adding a worker function and modifying the related stub functions to schedule the worker.
--- net/mptcp/pm.c | 132 +++++++++++++++++++++++++++++++++++++++++-- net/mptcp/protocol.c | 1 + net/mptcp/protocol.h | 1 + 3 files changed, 129 insertions(+), 5 deletions(-)
net/mptcp/pm.c +127 -5
@@ -15,7 +15,11 @@ static struct workqueue_struct *pm_wq;int mptcp_pm_announce_addr (struct mptcp_sock *msk,const struct mptcp_addr_info *addr) { -return -ENOTSUPP ; +pr_debug ("msk=%p, local_id=%d" , msk, addr->id); + + msk->pm.local = *addr; +WRITE_ONCE (msk->pm.addr_signal, true); +return 0 ; }int mptcp_pm_remove_addr (struct mptcp_sock *msk,u8 local_id)
@@ -41,13 +45,58 @@ void mptcp_pm_new_connection(struct mptcp_sock *msk, int server_side)bool mptcp_pm_allow_new_subflow (struct mptcp_sock *msk) { -pr_debug ("msk=%p" , msk); -return false; +struct mptcp_pm_data *pm = &msk->pm; +int ret; + +pr_debug ("msk=%p subflows=%d max=%d allow=%d" , msk, pm->subflows, + pm->subflows_max,READ_ONCE (pm->accept_subflow)); + +/* try to avoid acquiring the lock below */ +if (!READ_ONCE (pm->accept_subflow)) +return false; + +spin_lock_bh (&pm->lock); + ret = pm->subflows < pm->subflows_max; +if (ret && ++pm->subflows == pm->subflows_max) +WRITE_ONCE (pm->accept_subflow, false); +spin_unlock_bh (&pm->lock); + +return ret; +} + +/* return true if the new status bit is currently cleared, that is, this event +* can be server, eventually by an already scheduled work +*/ +static bool mptcp_pm_schedule_work (struct mptcp_sock *msk, +enum mptcp_pm_status new_status) +{ +pr_debug ("msk=%p status=%x new=%lx" , msk, msk->pm.status, +BIT (new_status)); +if (msk->pm.status &BIT (new_status)) +return false; + + msk->pm.status |=BIT (new_status); +if (queue_work (pm_wq, &msk->pm.work)) +sock_hold ((struct sock *)msk); +return true; }void mptcp_pm_fully_established (struct mptcp_sock *msk) { +struct mptcp_pm_data *pm = &msk->pm; +pr_debug ("msk=%p" , msk); + +/* try to avoid acquiring the lock below */ +if (!READ_ONCE (pm->work_pending)) +return ; + +spin_lock_bh (&pm->lock); + +if (READ_ONCE (pm->work_pending)) +mptcp_pm_schedule_work (msk,MPTCP_PM_ESTABLISHED ); + +spin_unlock_bh (&pm->lock); }void mptcp_pm_connection_closed (struct mptcp_sock *msk)
@@ -58,7 +107,19 @@ void mptcp_pm_connection_closed(struct mptcp_sock *msk)void mptcp_pm_subflow_established (struct mptcp_sock *msk,struct mptcp_subflow_context *subflow) { +struct mptcp_pm_data *pm = &msk->pm; +pr_debug ("msk=%p" , msk); + +if (!READ_ONCE (pm->work_pending)) +return ; + +spin_lock_bh (&pm->lock); + +if (READ_ONCE (pm->work_pending)) +mptcp_pm_schedule_work (msk,MPTCP_PM_SUBFLOW_ESTABLISHED ); + +spin_unlock_bh (&pm->lock); }void mptcp_pm_subflow_closed (struct mptcp_sock *msk,u8 id)
@@ -69,7 +130,23 @@ void mptcp_pm_subflow_closed(struct mptcp_sock *msk, u8 id)void mptcp_pm_add_addr_received (struct mptcp_sock *msk,const struct mptcp_addr_info *addr) { -pr_debug ("msk=%p, remote_id=%d" , msk, addr->id); +struct mptcp_pm_data *pm = &msk->pm; + +pr_debug ("msk=%p remote_id=%d accept=%d" , msk, addr->id, +READ_ONCE (pm->accept_addr)); + +/* avoid acquiring the lock if there is no room for fouther addresses */ +if (!READ_ONCE (pm->accept_addr)) +return ; + +spin_lock_bh (&pm->lock); + +/* be sure there is something to signal re-checking under PM lock */ +if (READ_ONCE (pm->accept_addr) && +mptcp_pm_schedule_work (msk,MPTCP_PM_ADD_ADDR_RECEIVED )) + pm->remote = *addr; + +spin_unlock_bh (&pm->lock); }/* path manager helpers */
@@ -77,7 +154,24 @@ void mptcp_pm_add_addr_received(struct mptcp_sock *msk,bool mptcp_pm_addr_signal (struct mptcp_sock *msk,unsigned int remaining,struct mptcp_addr_info *saddr) { -return false; +int ret = false; + +spin_lock_bh (&msk->pm.lock); + +/* double check after the lock is acquired */ +if (!mptcp_pm_should_signal (msk)) + goto out_unlock; + +if (remaining <mptcp_add_addr_len (msk->pm.local.family)) + goto out_unlock; + + *saddr = msk->pm.local; +WRITE_ONCE (msk->pm.addr_signal, false); + ret = true; + +out_unlock: +spin_unlock_bh (&msk->pm.lock); +return ret; }int mptcp_pm_get_local_id (struct mptcp_sock *msk,struct sock_common *skc)
@@ -87,6 +181,28 @@ int mptcp_pm_get_local_id(struct mptcp_sock *msk, struct sock_common *skc)static void pm_worker (struct work_struct *work) { + struct mptcp_pm_data *pm = container_of(work, struct mptcp_pm_data, + work); + struct mptcp_sock *msk = container_of(pm, struct mptcp_sock, pm); +struct sock *sk = (struct sock *)msk; + +lock_sock (sk); +spin_lock_bh (&msk->pm.lock); + +pr_debug ("msk=%p status=%x" , msk, pm->status); +if (pm->status &BIT (MPTCP_PM_ADD_ADDR_RECEIVED )) { + pm->status &= ~BIT (MPTCP_PM_ADD_ADDR_RECEIVED ); + } +if (pm->status &BIT (MPTCP_PM_ESTABLISHED )) { + pm->status &= ~BIT (MPTCP_PM_ESTABLISHED ); + } +if (pm->status &BIT (MPTCP_PM_SUBFLOW_ESTABLISHED )) { + pm->status &= ~BIT (MPTCP_PM_SUBFLOW_ESTABLISHED ); + } + +spin_unlock_bh (&msk->pm.lock); +release_sock (sk); +sock_put (sk); }void mptcp_pm_data_init (struct mptcp_sock *msk)
@@ -105,6 +221,12 @@ void mptcp_pm_data_init(struct mptcp_sock *msk)INIT_WORK (&msk->pm.work, pm_worker); } +void mptcp_pm_close (struct mptcp_sock *msk) +{ +if (cancel_work_sync (&msk->pm.work)) +sock_put ((struct sock *)msk); +} +void mptcp_pm_init (void ) { pm_wq =alloc_workqueue ("pm_wq" ,WQ_UNBOUND |WQ_MEM_RECLAIM ,8 );
net/mptcp/protocol.c +1 -0
@@ -833,6 +833,7 @@ static void mptcp_close(struct sock *sk, long timeout) }mptcp_cancel_work (sk); +mptcp_pm_close (msk);__skb_queue_purge (&sk->sk_receive_queue);
net/mptcp/protocol.h +1 -0
@@ -330,6 +330,7 @@ void mptcp_crypto_hmac_sha(u64 key1, u64 key2, u8 *msg, int len, void *hmac);void mptcp_pm_init (void );void mptcp_pm_data_init (struct mptcp_sock *msk); +void mptcp_pm_close (struct mptcp_sock *msk);void mptcp_pm_new_connection (struct mptcp_sock *msk,int server_side);void mptcp_pm_fully_established (struct mptcp_sock *msk);bool mptcp_pm_allow_new_subflow (struct mptcp_sock *msk);
Signature · 1 line
2.26.0
PATCH v2 6/17 mptcp: update per unacked sequence on pkt reception
In reply to Mat MartineauFrom: Paolo Abeni <[email protected]>
So that we keep per unacked sequence number consistent; since we update per msk data, use an atomic64 cmpxchg() to protect against concurrent updates from multiple subflows.
Initialize the snd_una at connect()/accept() time.
--- net/mptcp/options.c | 52 +++++++++++++++++++++++++++++++++++++++----- net/mptcp/protocol.c | 2 ++ net/mptcp/protocol.h | 1 + 3 files changed, 49 insertions(+), 6 deletions(-)
net/mptcp/options.c +46 -6
@@ -744,6 +744,46 @@ static bool check_fully_established(struct mptcp_sock *msk, struct sock *sk,return true; } +static u64 expand_ack (u64 old_ack,u64 cur_ack,bool use_64bit) +{ +u32 old_ack32, cur_ack32; + +if (use_64bit) +return cur_ack; + + old_ack32 = (u32 )old_ack; + cur_ack32 = (u32 )cur_ack; + cur_ack = (old_ack &GENMASK_ULL (63 ,32 )) + cur_ack32; +if (unlikely (before (cur_ack32, old_ack32))) +return cur_ack + (1LL <<32 ); +return cur_ack; +} + +static void update_una (struct mptcp_sock *msk, +struct mptcp_options_received *mp_opt) +{ +u64 new_snd_una, snd_una, old_snd_una =atomic64_read (&msk->snd_una); +u64 write_seq =READ_ONCE (msk->write_seq); + +/* avoid ack expansion on update conflict, to reduce the risk of +* wrongly expanding to a future ack sequence number, which is way +* more dangerous than missing an ack +*/ + new_snd_una =expand_ack (old_snd_una, mp_opt->data_ack, mp_opt->ack64); + +/* ACK for data not even sent yet? Ignore. */ +if (after64 (new_snd_una, write_seq)) + new_snd_una = old_snd_una; + +while (after64 (new_snd_una, old_snd_una)) { + snd_una = old_snd_una; + old_snd_una =atomic64_cmpxchg (&msk->snd_una, snd_una, + new_snd_una); +if (old_snd_una == snd_una) +break ; + } +} +static bool add_addr_hmac_valid (struct mptcp_sock *msk,struct mptcp_options_received *mp_opt) {
@@ -805,6 +845,12 @@ void mptcp_incoming_options(struct sock *sk, struct sk_buff *skb,if (!mp_opt->dss)return ; +/* we can't wait for recvmsg() to update the ack_seq, otherwise +* monodirectional flows will stuck +*/ +if (mp_opt->use_ack) +update_una (msk, mp_opt); + mpext =skb_ext_add (skb,SKB_EXT_MPTCP );if (!mpext)return ;
@@ -831,12 +877,6 @@ void mptcp_incoming_options(struct sock *sk, struct sk_buff *skb, mpext->use_map =1 ; } -if (mp_opt->use_ack) { - mpext->data_ack = mp_opt->data_ack; - mpext->use_ack =1 ; - mpext->ack64 = mp_opt->ack64; - } - mpext->data_fin = mp_opt->data_fin; }
net/mptcp/protocol.c +2 -0
@@ -906,6 +906,7 @@ struct sock *mptcp_sk_clone(const struct sock *sk, struct request_sock *req) } msk->write_seq = subflow_req->idsn +1 ; +atomic64_set (&msk->snd_una, msk->write_seq);if (subflow_req->remote_key_valid) { msk->can_ack = true; msk->remote_key = subflow_req->remote_key;
@@ -1107,6 +1108,7 @@ void mptcp_finish_connect(struct sock *ssk)WRITE_ONCE (msk->write_seq, subflow->idsn +1 );WRITE_ONCE (msk->ack_seq, ack_seq);WRITE_ONCE (msk->can_ack,1 ); +atomic64_set (&msk->snd_una, msk->write_seq);mptcp_pm_new_connection (msk,0 ); }
net/mptcp/protocol.h +1 -0
@@ -147,6 +147,7 @@ struct mptcp_sock {u64 remote_key;u64 write_seq;u64 ack_seq; +atomic64_t snd_una;u32 token;unsigned long flags;bool can_ack;
Signature · 1 line
2.26.0
PATCH v2 7/17 mptcp: queue data for mptcp level retransmission
In reply to Mat MartineauFrom: Paolo Abeni <[email protected]>
keep the send page fragment on an MPTCP level retransmission queue. the queue entries are allocated inside the page frag allocator, acquiring an additional reference to the page for each list entry.
Also switch to a custom page frag refill function, to ensure that the current page fragment can always host an MPTCP rtx queue entry.
The MPTCP rtx queue is flushed at disconnect() and close() time
Note that now we need to call __mptcp_init_sock() regardless of mptcp enable status, as the destructor will try to walk the rtx_queue.
--- net/mptcp/protocol.c | 135 ++++++++++++++++++++++++++++++++++++++++--- net/mptcp/protocol.h | 20 +++++++ 2 files changed, 147 insertions(+), 8 deletions(-)
net/mptcp/protocol.c +127 -8
@@ -285,15 +285,75 @@ static inline bool mptcp_skb_can_collapse_to(const struct mptcp_sock *msk,return mpext && mpext->data_seq + mpext->data_len == msk->write_seq; } +static inline bool mptcp_frag_can_collapse_to (const struct mptcp_sock *msk, +const struct page_frag *pfrag, +const struct mptcp_data_frag *df) +{ +return df && pfrag->page == df->page && + df->data_seq + df->data_len == msk->write_seq; +} + +static void dfrag_clear (struct mptcp_data_frag *dfrag) +{ +list_del (&dfrag->list); +put_page (dfrag->page); +} + +static void mptcp_clean_una (struct sock *sk) +{ +struct mptcp_sock *msk =mptcp_sk (sk); +struct mptcp_data_frag *dtmp, *dfrag; +u64 snd_una =atomic64_read (&msk->snd_una); + +list_for_each_entry_safe (dfrag, dtmp, &msk->rtx_queue, list) { +if (after64 (dfrag->data_seq + dfrag->data_len, snd_una)) +break ; + +dfrag_clear (dfrag); + } +} + +/* ensure we get enough memory for the frag hdr, beyond some minimal amount of +* data +*/ +static bool mptcp_page_frag_refill (struct sock *sk,struct page_frag *pfrag) +{ +if (likely (skb_page_frag_refill (32U +sizeof (struct mptcp_data_frag ), + pfrag, sk->sk_allocation))) +return true; + + sk->sk_prot->enter_memory_pressure (sk); +sk_stream_moderate_sndbuf (sk); +return false; +} + +static inline struct mptcp_data_frag * +mptcp_carve_data_frag (const struct mptcp_sock *msk,struct page_frag *pfrag, +int orig_offset) +{ +int offset =ALIGN (orig_offset,sizeof (long )); +struct mptcp_data_frag *dfrag; + + dfrag = (struct mptcp_data_frag *)(page_to_virt (pfrag->page) + offset); + dfrag->data_len =0 ; + dfrag->data_seq = msk->write_seq; + dfrag->overhead = offset - orig_offset +sizeof (struct mptcp_data_frag ); + dfrag->offset = offset +sizeof (struct mptcp_data_frag ); + dfrag->page = pfrag->page; + +return dfrag; +} +static int mptcp_sendmsg_frag (struct sock *sk,struct sock *ssk,struct msghdr *msg,long *timeo,int *pmss_now,int *ps_goal) { -int mss_now, avail_size, size_goal, ret; +int mss_now, avail_size, size_goal, offset, ret, frag_truesize =0 ; +bool dfrag_collapsed, can_collapse = false;struct mptcp_sock *msk =mptcp_sk (sk);struct mptcp_ext *mpext =NULL ; +struct mptcp_data_frag *dfrag;struct sk_buff *skb, *tail; -bool can_collapse = false;struct page_frag *pfrag;size_t psize;
@@ -301,11 +361,17 @@ static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk,* from one substream to another, but do per subflow memory accounting */ pfrag =sk_page_frag (sk); -while (!sk_page_frag_refill (ssk, pfrag) || +while (!mptcp_page_frag_refill (ssk, pfrag) || !mptcp_ext_cache_refill (msk)) { ret =sk_stream_wait_memory (ssk, timeo);if (ret)return ret; + +/* if sk_stream_wait_memory() sleeps snd_una can change +* significantly, refresh the rtx queue +*/ +mptcp_clean_una (sk); +if (unlikely (__mptcp_needs_tcp_fallback (msk)))return 0 ; }
@@ -332,11 +398,23 @@ static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk,else avail_size = size_goal - skb->len; } - psize =min_t (size_t, pfrag->size - pfrag->offset, avail_size); + +/* reuse tail pfrag, if possible, or carve a new one from the page +* allocator +*/ + dfrag =mptcp_rtx_tail (sk); + offset = pfrag->offset; + dfrag_collapsed =mptcp_frag_can_collapse_to (msk, pfrag, dfrag); +if (!dfrag_collapsed) { + dfrag =mptcp_carve_data_frag (msk, pfrag, offset); + offset = dfrag->offset; + frag_truesize = dfrag->overhead; + } + psize =min_t (size_t, pfrag->size - offset, avail_size);/* Copy to page */ pr_debug ("left=%zu" ,msg_data_left (msg)); - psize =copy_page_from_iter (pfrag->page, pfrag->offset, + psize =copy_page_from_iter (pfrag->page, offset,min_t (size_t,msg_data_left (msg), psize), &msg->msg_iter);pr_debug ("left=%zu" ,msg_data_left (msg));
@@ -346,13 +424,24 @@ static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk,/* tell the TCP stack to delay the push so that we can safely * access the skb after the sendpages call */ - ret =do_tcp_sendpages (ssk, pfrag->page, pfrag->offset, psize, + ret =do_tcp_sendpages (ssk, pfrag->page, offset, psize, msg->msg_flags |MSG_SENDPAGE_NOTLAST );if (ret <=0 )return ret; + + frag_truesize += ret;if (unlikely (ret < psize))iov_iter_revert (&msg->msg_iter, psize - ret); +/* send successful, keep track of sent data for mptcp-level +* retransmission +*/ + dfrag->data_len += ret; +if (!dfrag_collapsed) { +get_page (dfrag->page); +list_add_tail (&dfrag->list, &msk->rtx_queue); + } +/* if the tail skb extension is still the cached one, collapsing * really happened. Note: we can't check for 'same skb' as the sk_buff * hdr on tail can be transmitted, freed and re-allocated by the
@@ -381,7 +470,7 @@ static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk, mpext->dsn64); out: - pfrag->offset += ret; + pfrag->offset += frag_truesize; msk->write_seq += ret;mptcp_subflow_ctx (ssk)->rel_write_seq += ret;
@@ -472,6 +561,8 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)return ret >=0 ? ret + copied : (copied ? copied : ret); } +mptcp_clean_una (sk); +__mptcp_flush_join_list (msk); ssk =mptcp_subflow_get_send (msk);while (!sk_stream_memory_free (sk) || !ssk) {
@@ -479,6 +570,8 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)if (ret) goto out; +mptcp_clean_una (sk); + ssk =mptcp_subflow_get_send (msk);if (list_empty (&msk->conn_list)) { ret = -ENOTCONN ;
@@ -744,6 +837,7 @@ static int __mptcp_init_sock(struct sock *sk)INIT_LIST_HEAD (&msk->conn_list);INIT_LIST_HEAD (&msk->join_list); +INIT_LIST_HEAD (&msk->rtx_queue);__set_bit (MPTCP_SEND_SPACE , &msk->flags);INIT_WORK (&msk->work, mptcp_worker);
@@ -757,10 +851,24 @@ static int __mptcp_init_sock(struct sock *sk)static int mptcp_init_sock (struct sock *sk) { +int ret =__mptcp_init_sock (sk); + +if (ret) +return ret; +if (!mptcp_is_enabled (sock_net (sk)))return -ENOPROTOOPT ; -return __mptcp_init_sock (sk); +return 0 ; +} + +static void __mptcp_clear_xmit (struct sock *sk) +{ +struct mptcp_sock *msk =mptcp_sk (sk); +struct mptcp_data_frag *dtmp, *dfrag; + +list_for_each_entry_safe (dfrag, dtmp, &msk->rtx_queue, list) +dfrag_clear (dfrag); }static void mptcp_cancel_work (struct sock *sk)
@@ -822,6 +930,8 @@ static void mptcp_close(struct sock *sk, long timeout) data_fin_tx_seq = msk->write_seq; +__mptcp_clear_xmit (sk); +release_sock (sk);list_for_each_entry_safe (subflow, tmp, &conn_list, node) {
@@ -863,6 +973,14 @@ static void mptcp_copy_inaddrs(struct sock *msk, const struct sock *ssk)inet_sk (msk)->inet_rcv_saddr =inet_sk (ssk)->inet_rcv_saddr; } +static int mptcp_disconnect (struct sock *sk,int flags) +{ +lock_sock (sk); +__mptcp_clear_xmit (sk); +release_sock (sk); +return tcp_disconnect (sk, flags); +} +#if IS_ENABLED (CONFIG_MPTCP_IPV6 )static struct ipv6_pinfo *mptcp_inet6_sk (const struct sock *sk) {
@@ -1173,6 +1291,7 @@ static struct proto mptcp_prot = { .name = "MPTCP", .owner = THIS_MODULE, .init = mptcp_init_sock, + .disconnect = mptcp_disconnect, .close = mptcp_close, .accept = mptcp_accept, .setsockopt = mptcp_setsockopt,
net/mptcp/protocol.h +20 -0
@@ -139,6 +139,15 @@ struct mptcp_pm_data {struct work_struct work; }; +struct mptcp_data_frag { +struct list_head list; +u64 data_seq; +int data_len; +int offset; +int overhead; +struct page *page; +}; +/* MPTCP connection sock */ struct mptcp_sock {/* inet_connection_sock must be the first member */
@@ -154,6 +163,7 @@ struct mptcp_sock {spinlock_t join_list_lock;struct work_struct work;struct list_head conn_list; +struct list_head rtx_queue;struct list_head join_list;struct skb_ext *cached_ext;/* for the next sendmsg */ struct socket *subflow;/* outgoing connect/listener/!mp_capable */
@@ -169,6 +179,16 @@ static inline struct mptcp_sock *mptcp_sk(const struct sock *sk)return (struct mptcp_sock *)sk; } +static inline struct mptcp_data_frag *mptcp_rtx_tail (const struct sock *sk) +{ +struct mptcp_sock *msk =mptcp_sk (sk); + +if (list_empty (&msk->rtx_queue)) +return NULL ; + + return list_last_entry(&msk->rtx_queue, struct mptcp_data_frag, list); +} +struct mptcp_subflow_request_sock {struct tcp_request_sock sk; u16 mp_capable : 1,
Signature · 1 line
2.26.0
David Miller
maintainerRe: [PATCH net-next v2 07/17] mptcp: queue data for mptcp level retransmission
From: Mat Martineau <[email protected]>
Date: Thu, 26 Mar 2020 13:46:30 -0700
net/mptcp/protocol.c static inline bool mptcp_skb_can_collapse_to(const struct mptcp_sock *msk, · line 290
Quoted 7 lines
net/mptcp/protocol.c +3
-0@@ -285,15 +285,75 @@ static inline bool mptcp_skb_can_collapse_to(const struct mptcp_sock *msk,return mpext && mpext->data_seq + mpext->data_len == msk->write_seq; } +static inline bool mptcp_frag_can_collapse_to (const struct mptcp_sock *msk, +const struct page_frag *pfrag, +const struct mptcp_data_frag *df)
Please don't use inline in foo.c files, let the compiler decide.
PATCH v2 8/17 mptcp: introduce MPTCP retransmission timer
In reply to Mat MartineauFrom: Paolo Abeni <[email protected]>
The timer will be used to schedule retransmission. It's frequency is based on the current subflow RTO estimation and is reset on every una_seq update
The timer is clearer for good by __mptcp_clear_xmit()
Also clean MPTCP rtx queue before each transmission.
--- net/mptcp/options.c | 4 +- net/mptcp/protocol.c | 89 +++++++++++++++++++++++++++++++++++++++++++- net/mptcp/protocol.h | 2 + 3 files changed, 93 insertions(+), 2 deletions(-)
net/mptcp/options.c +3 -1
@@ -779,8 +779,10 @@ static void update_una(struct mptcp_sock *msk, snd_una = old_snd_una; old_snd_una =atomic64_cmpxchg (&msk->snd_una, snd_una, new_snd_una); -if (old_snd_una == snd_una) +if (old_snd_una == snd_una) { +mptcp_data_acked ((struct sock *)msk);break ; + } } }
net/mptcp/protocol.c +88 -1
141 lines not on this page · raw message
net/mptcp/protocol.h +2 -0
@@ -157,6 +157,7 @@ struct mptcp_sock {u64 write_seq;u64 ack_seq;atomic64_t snd_una; +unsigned long timer_ival;u32 token;unsigned long flags;bool can_ack;
@@ -326,6 +327,7 @@ void mptcp_get_options(const struct sk_buff *skb,void mptcp_finish_connect (struct sock *sk);void mptcp_data_ready (struct sock *sk,struct sock *ssk);bool mptcp_finish_join (struct sock *sk); +void mptcp_data_acked (struct sock *sk);int mptcp_token_new_request (struct request_sock *req);void mptcp_token_destroy_request (u32 token);
Signature · 1 line
2.26.0
PATCH v2 9/17 mptcp: implement memory accounting for mptcp rtx queue
In reply to Mat MartineauFrom: Paolo Abeni <[email protected]>
Charge the data on the rtx queue to the master MPTCP socket, too. Such memory in uncharged when the data is acked/dequeued.
Also account mptcp sockets inuse via a protocol specific pcpu counter.
--- net/mptcp/protocol.c | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-)
net/mptcp/protocol.c +39 -3
@@ -37,6 +37,8 @@ struct mptcp_skb_cb {#define MPTCP_SKB_CB (__skb) ((struct mptcp_skb_cb *)&((__skb)->cb[0])) +static struct percpu_counter mptcp_sockets_allocated; +/* If msk has an initial subflow socket, and the MP_CAPABLE handshake has not * completed yet or has failed, return the subflow socket. * Otherwise return NULL.
@@ -333,9 +335,17 @@ static inline bool mptcp_frag_can_collapse_to(const struct mptcp_sock *msk, df->data_seq + df->data_len == msk->write_seq; } -static void dfrag_clear (struct mptcp_data_frag *dfrag) +static void dfrag_uncharge (struct sock *sk,int len) +{ +sk_mem_uncharge (sk, len); +} + +static void dfrag_clear (struct sock *sk,struct mptcp_data_frag *dfrag) { +int len = dfrag->data_len + dfrag->overhead; +list_del (&dfrag->list); +dfrag_uncharge (sk, len);put_page (dfrag->page); }
@@ -344,12 +354,18 @@ static void mptcp_clean_una(struct sock *sk)struct mptcp_sock *msk =mptcp_sk (sk);struct mptcp_data_frag *dtmp, *dfrag;u64 snd_una =atomic64_read (&msk->snd_una); +bool cleaned = false;list_for_each_entry_safe (dfrag, dtmp, &msk->rtx_queue, list) {if (after64 (dfrag->data_seq + dfrag->data_len, snd_una))break ; -dfrag_clear (dfrag); +dfrag_clear (sk, dfrag); + cleaned = true; + } + +if (cleaned) { +sk_mem_reclaim_partial (sk); } }
@@ -461,6 +477,9 @@ static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk,if (!psize)return -EINVAL ; +if (!sk_wmem_schedule (sk, psize + dfrag->overhead)) +return -ENOMEM ; +/* tell the TCP stack to delay the push so that we can safely * access the skb after the sendpages call */
@@ -482,6 +501,11 @@ static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk,list_add_tail (&dfrag->list, &msk->rtx_queue); } +/* charge data on mptcp rtx queue to the master socket +* Note: we charge such data both to sk and ssk +*/ + sk->sk_forward_alloc -= frag_truesize; +/* if the tail skb extension is still the cached one, collapsing * really happened. Note: we can't check for 'same skb' as the sk_buff * hdr on tail can be transmitted, freed and re-allocated by the
@@ -933,6 +957,8 @@ static int mptcp_init_sock(struct sock *sk)if (ret)return ret; +sk_sockets_allocated_inc (sk); +if (!mptcp_is_enabled (sock_net (sk)))return -ENOPROTOOPT ;
@@ -947,7 +973,7 @@ static void __mptcp_clear_xmit(struct sock *sk)sk_stop_timer (sk, &msk->sk.icsk_retransmit_timer);list_for_each_entry_safe (dfrag, dtmp, &msk->rtx_queue, list) -dfrag_clear (dfrag); +dfrag_clear (sk, dfrag); }static void mptcp_cancel_work (struct sock *sk)
@@ -1182,6 +1208,8 @@ static void mptcp_destroy(struct sock *sk)if (msk->cached_ext)__skb_ext_put (msk->cached_ext); + +sk_sockets_allocated_dec (sk); } static int mptcp_setsockopt(struct sock *sk, int level, int optname,
@@ -1391,7 +1419,12 @@ static struct proto mptcp_prot = { .hash = inet_hash, .unhash = inet_unhash, .get_port = mptcp_get_port, + .sockets_allocated = &mptcp_sockets_allocated, + .memory_allocated = &tcp_memory_allocated, + .memory_pressure = &tcp_memory_pressure, .stream_memory_free = mptcp_memory_free, + .sysctl_wmem_offset = offsetof(struct net, ipv4.sysctl_tcp_wmem), + .sysctl_mem = sysctl_tcp_mem, .obj_size = sizeof(struct mptcp_sock), .no_autobind = true, };
@@ -1680,6 +1713,9 @@ void mptcp_proto_init(void) { mptcp_prot.h.hashinfo = tcp_prot.h.hashinfo; +if (percpu_counter_init (&mptcp_sockets_allocated,0 ,GFP_KERNEL )) +panic ("Failed to allocate MPTCP pcpu counter\n" ); +mptcp_subflow_init ();mptcp_pm_init ();
Signature · 1 line
2.26.0
PATCH v2 10/17 mptcp: allow partial cleaning of rtx head dfrag
In reply to Mat MartineauFrom: Florian Westphal <[email protected]>
After adding wmem accounting for the mptcp socket we could get into a situation where the mptcp socket can't transmit more data, and mptcp_clean_una doesn't reduce wmem even if snd_una has advanced because it currently will only remove entire dfrags.
Allow advancing the dfrag head sequence and reduce wmem, even though this isn't correct (as we can't release the page).
Because we will soon block on mptcp sk in case wmem is too large, call sk_stream_write_space() in case we reduced the backlog so userspace task blocked in sendmsg or poll will be woken up.
This isn't an issue if the send buffer is large, but it is when SO_SNDBUF is used to reduce it to a lower value.
Note we can still get a deadlock for low SO_SNDBUF values in case both sides of the connection write to the socket: both could be blocked due to wmem being too small -- and current mptcp stack will only increment mptcp ack_seq on recv.
This doesn't happen with the selftest as it uses poll() and will always call recv if there is data to read.
--- net/mptcp/protocol.c | 16 ++++++++++++++++ net/mptcp/protocol.h | 10 ++++++++++ 2 files changed, 26 insertions(+)
net/mptcp/protocol.c +16 -0
@@ -338,6 +338,7 @@ static inline bool mptcp_frag_can_collapse_to(const struct mptcp_sock *msk,static void dfrag_uncharge (struct sock *sk,int len) {sk_mem_uncharge (sk, len); +sk_wmem_queued_add (sk, -len); }static void dfrag_clear (struct sock *sk,struct mptcp_data_frag *dfrag)
@@ -364,8 +365,23 @@ static void mptcp_clean_una(struct sock *sk) cleaned = true; } + dfrag =mptcp_rtx_head (sk); +if (dfrag &&after64 (snd_una, dfrag->data_seq)) { +u64 delta = dfrag->data_seq + dfrag->data_len - snd_una; + + dfrag->data_seq += delta; + dfrag->data_len -= delta; + +dfrag_uncharge (sk, delta); + cleaned = true; + } +if (cleaned) {sk_mem_reclaim_partial (sk); + +/* Only wake up writers if a subflow is ready */ +if (test_bit (MPTCP_SEND_SPACE , &msk->flags)) +sk_stream_write_space (sk); } }
net/mptcp/protocol.h +10 -0
@@ -190,6 +190,16 @@ static inline struct mptcp_data_frag *mptcp_rtx_tail(const struct sock *sk) return list_last_entry(&msk->rtx_queue, struct mptcp_data_frag, list); } +static inline struct mptcp_data_frag *mptcp_rtx_head (const struct sock *sk) +{ +struct mptcp_sock *msk =mptcp_sk (sk); + +if (list_empty (&msk->rtx_queue)) +return NULL ; + + return list_first_entry(&msk->rtx_queue, struct mptcp_data_frag, list); +} +struct mptcp_subflow_request_sock {struct tcp_request_sock sk; u16 mp_capable : 1,
Signature · 1 line
2.26.0
PATCH v2 11/17 mptcp: rework mptcp_sendmsg_frag to accept optional dfrag
In reply to Mat MartineauFrom: Paolo Abeni <[email protected]>
This will simplify mptcp-level retransmission implementation in the next patch. If dfrag is provided by the caller, skip kernel space memory allocation and use data and metadata provided by the dfrag itself.
Because a peer could ack data at TCP level but refrain from sending mptcp-level ACKs, we could grow the mptcp socket backlog indefinitely.
We should thus block mptcp_sendmsg until the peer has acked some of the sent data.
In order to be able to do so, increment the mptcp socket wmem_queued counter on memory allocation and decrement it when releasing the memory on mptcp-level ack reception.
Because TCP performns sndbuf auto-tuning up to tcp_wmem_max[2], make this the mptcp sk_sndbuf limit.
In the future we could add experiment with autotuning as TCP does in tcp_sndbuf_expand().
--- net/mptcp/protocol.c | 119 ++++++++++++++++++++++++++----------------- 1 file changed, 72 insertions(+), 47 deletions(-)
net/mptcp/protocol.c +72 -47
@@ -316,7 +316,7 @@ static struct sock *mptcp_subflow_recv_lookup(const struct mptcp_sock *msk)return NULL ; } -static inline bool mptcp_skb_can_collapse_to (const struct mptcp_sock *msk, +static inline bool mptcp_skb_can_collapse_to (u64 write_seq,const struct sk_buff *skb,const struct mptcp_ext *mpext) {
@@ -324,7 +324,7 @@ static inline bool mptcp_skb_can_collapse_to(const struct mptcp_sock *msk,return false;/* can collapse only if MPTCP level sequence is in order */ -return mpext && mpext->data_seq + mpext->data_len == msk->write_seq; +return mpext && mpext->data_seq + mpext->data_len == write_seq; } static inline bool mptcp_frag_can_collapse_to(const struct mptcp_sock *msk,
@@ -417,23 +417,28 @@ mptcp_carve_data_frag(const struct mptcp_sock *msk, struct page_frag *pfrag, }static int mptcp_sendmsg_frag (struct sock *sk,struct sock *ssk, -struct msghdr *msg,long *timeo,int *pmss_now, +struct msghdr *msg,struct mptcp_data_frag *dfrag, +long *timeo,int *pmss_now,int *ps_goal) {int mss_now, avail_size, size_goal, offset, ret, frag_truesize =0 ;bool dfrag_collapsed, can_collapse = false;struct mptcp_sock *msk =mptcp_sk (sk);struct mptcp_ext *mpext =NULL ; -struct mptcp_data_frag *dfrag; +bool retransmission = !!dfrag;struct sk_buff *skb, *tail;struct page_frag *pfrag; +struct page *page; +u64 *write_seq;size_t psize;/* use the mptcp page cache so that we can easily move the data * from one substream to another, but do per subflow memory accounting +* Note: pfrag is used only !retransmission, but the compiler if +* fooled into a warning if we don't init here */ pfrag =sk_page_frag (sk); -while (!mptcp_page_frag_refill (ssk, pfrag) || +while ((!retransmission && !mptcp_page_frag_refill (ssk, pfrag)) || !mptcp_ext_cache_refill (msk)) { ret =sk_stream_wait_memory (ssk, timeo);if (ret)
@@ -447,6 +452,13 @@ static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk,if (unlikely (__mptcp_needs_tcp_fallback (msk)))return 0 ; } +if (!retransmission) { + write_seq = &msk->write_seq; + page = pfrag->page; + }else { + write_seq = &dfrag->data_seq; + page = dfrag->page; + }/* compute copy limit */ mss_now =tcp_send_mss (ssk, &size_goal, msg->msg_flags);
@@ -464,63 +476,74 @@ static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk,* SSN association set here */ can_collapse = (size_goal - skb->len >0 ) && -mptcp_skb_can_collapse_to (msk, skb, mpext); +mptcp_skb_can_collapse_to (*write_seq, skb, mpext);if (!can_collapse)TCP_SKB_CB (skb)->eor =1 ;else avail_size = size_goal - skb->len; } -/* reuse tail pfrag, if possible, or carve a new one from the page -* allocator -*/ - dfrag =mptcp_rtx_tail (sk); - offset = pfrag->offset; - dfrag_collapsed =mptcp_frag_can_collapse_to (msk, pfrag, dfrag); -if (!dfrag_collapsed) { - dfrag =mptcp_carve_data_frag (msk, pfrag, offset); +if (!retransmission) { +/* reuse tail pfrag, if possible, or carve a new one from the +* page allocator +*/ + dfrag =mptcp_rtx_tail (sk); + offset = pfrag->offset; + dfrag_collapsed =mptcp_frag_can_collapse_to (msk, pfrag, dfrag); +if (!dfrag_collapsed) { + dfrag =mptcp_carve_data_frag (msk, pfrag, offset); + offset = dfrag->offset; + frag_truesize = dfrag->overhead; + } + psize =min_t (size_t, pfrag->size - offset, avail_size); + +/* Copy to page */ +pr_debug ("left=%zu" ,msg_data_left (msg)); + psize =copy_page_from_iter (pfrag->page, offset, +min_t (size_t,msg_data_left (msg), + psize), + &msg->msg_iter); +pr_debug ("left=%zu" ,msg_data_left (msg)); +if (!psize) +return -EINVAL ; + +if (!sk_wmem_schedule (sk, psize + dfrag->overhead)) +return -ENOMEM ; + }else { offset = dfrag->offset; - frag_truesize = dfrag->overhead; + psize =min_t (size_t, dfrag->data_len, avail_size); } - psize =min_t (size_t, pfrag->size - offset, avail_size); - -/* Copy to page */ -pr_debug ("left=%zu" ,msg_data_left (msg)); - psize =copy_page_from_iter (pfrag->page, offset, -min_t (size_t,msg_data_left (msg), psize), - &msg->msg_iter); -pr_debug ("left=%zu" ,msg_data_left (msg)); -if (!psize) -return -EINVAL ; - -if (!sk_wmem_schedule (sk, psize + dfrag->overhead)) -return -ENOMEM ;/* tell the TCP stack to delay the push so that we can safely * access the skb after the sendpages call */ - ret =do_tcp_sendpages (ssk, pfrag->page, offset, psize, + ret =do_tcp_sendpages (ssk, page, offset, psize, msg->msg_flags |MSG_SENDPAGE_NOTLAST );if (ret <=0 )return ret; frag_truesize += ret; -if (unlikely (ret < psize)) -iov_iter_revert (&msg->msg_iter, psize - ret); +if (!retransmission) { +if (unlikely (ret < psize)) +iov_iter_revert (&msg->msg_iter, psize - ret); -/* send successful, keep track of sent data for mptcp-level -* retransmission -*/ - dfrag->data_len += ret; -if (!dfrag_collapsed) { -get_page (dfrag->page); -list_add_tail (&dfrag->list, &msk->rtx_queue); - } +/* send successful, keep track of sent data for mptcp-level +* retransmission +*/ + dfrag->data_len += ret; +if (!dfrag_collapsed) { +get_page (dfrag->page); +list_add_tail (&dfrag->list, &msk->rtx_queue); +sk_wmem_queued_add (sk, frag_truesize); + }else { +sk_wmem_queued_add (sk, ret); + } -/* charge data on mptcp rtx queue to the master socket -* Note: we charge such data both to sk and ssk -*/ - sk->sk_forward_alloc -= frag_truesize; +/* charge data on mptcp rtx queue to the master socket +* Note: we charge such data both to sk and ssk +*/ + sk->sk_forward_alloc -= frag_truesize; + }/* if the tail skb extension is still the cached one, collapsing * really happened. Note: we can't check for 'same skb' as the sk_buff
@@ -539,7 +562,7 @@ static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk, msk->cached_ext =NULL ;memset (mpext,0 ,sizeof (*mpext)); - mpext->data_seq = msk->write_seq; + mpext->data_seq = *write_seq; mpext->subflow_seq =mptcp_subflow_ctx (ssk)->rel_write_seq; mpext->data_len = ret; mpext->use_map =1 ;
@@ -550,8 +573,9 @@ static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk, mpext->dsn64); out: - pfrag->offset += frag_truesize; - msk->write_seq += ret; +if (!retransmission) + pfrag->offset += frag_truesize; + *write_seq += ret;mptcp_subflow_ctx (ssk)->rel_write_seq += ret;return ret;
@@ -663,7 +687,7 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)lock_sock (ssk);while (msg_data_left (msg)) { - ret =mptcp_sendmsg_frag (sk, ssk, msg, &timeo, &mss_now, + ret =mptcp_sendmsg_frag (sk, ssk, msg,NULL , &timeo, &mss_now, &size_goal);if (ret <0 )break ;
@@ -974,6 +998,7 @@ static int mptcp_init_sock(struct sock *sk)return ret;sk_sockets_allocated_inc (sk); + sk->sk_sndbuf =sock_net (sk)->ipv4.sysctl_tcp_wmem[2 ];if (!mptcp_is_enabled (sock_net (sk)))return -ENOPROTOOPT ;
Signature · 1 line
2.26.0
PATCH v2 12/17 mptcp: implement and use MPTCP-level retransmission
In reply to Mat MartineauFrom: Paolo Abeni <[email protected]>
On timeout event, schedule a work queue to do the retransmission. Retransmission code closely resembles the sendmsg() implementation and re-uses mptcp_sendmsg_frag, providing a dummy msghdr - for flags' sake - and peeking the relevant dfrag from the rtx head.
--- net/mptcp/protocol.c | 98 ++++++++++++++++++++++++++++++++++++++++++-- net/mptcp/protocol.h | 1 + 2 files changed, 95 insertions(+), 4 deletions(-)
net/mptcp/protocol.c +94 -4
@@ -283,6 +283,10 @@ static void mptcp_reset_timer(struct sock *sk)void mptcp_data_acked (struct sock *sk) {mptcp_reset_timer (sk); + +if (!sk_stream_is_writeable (sk) && +schedule_work (&mptcp_sk (sk)->work)) +sock_hold (sk); }static void mptcp_stop_timer (struct sock *sk)
@@ -900,10 +904,13 @@ static void mptcp_retransmit_handler(struct sock *sk) {struct mptcp_sock *msk =mptcp_sk (sk); -if (atomic64_read (&msk->snd_una) == msk->write_seq) +if (atomic64_read (&msk->snd_una) == msk->write_seq) {mptcp_stop_timer (sk); -else -mptcp_reset_timer (sk); + }else { +set_bit (MPTCP_WORK_RTX , &msk->flags); +if (schedule_work (&msk->work)) +sock_hold (sk); + } }static void mptcp_retransmit_timer (struct timer_list *t)
@@ -925,6 +932,37 @@ static void mptcp_retransmit_timer(struct timer_list *t)sock_put (sk); } +/* Find an idle subflow. Return NULL if there is unacked data at tcp +* level. +* +* A backup subflow is returned only if that is the only kind available. +*/ +static struct sock *mptcp_subflow_get_retrans (const struct mptcp_sock *msk) +{ +struct mptcp_subflow_context *subflow; +struct sock *backup =NULL ; + +sock_owned_by_me ((const struct sock *)msk); + +mptcp_for_each_subflow (msk, subflow) { +struct sock *ssk =mptcp_subflow_tcp_sock (subflow); + +/* still data outstanding at TCP level? Don't retransmit. */ +if (!tcp_write_queue_empty (ssk)) +return NULL ; + +if (subflow->backup) { +if (!backup) + backup = ssk; +continue ; + } + +return ssk; + } + +return backup; +} +/* subflow sockets can be either outgoing (connect) or incoming * (accept). *
@@ -958,11 +996,62 @@ static unsigned int mptcp_sync_mss(struct sock *sk, u32 pmtu)static void mptcp_worker (struct work_struct *work) { struct mptcp_sock *msk = container_of(work, struct mptcp_sock, work); -struct sock *sk = &msk->sk.icsk_inet.sk; +struct sock *ssk, *sk = &msk->sk.icsk_inet.sk; +int orig_len, orig_offset, ret, mss_now =0 , size_goal =0 ; +struct mptcp_data_frag *dfrag; +u64 orig_write_seq; +size_t copied =0 ; +struct msghdr msg; +long timeo =0 ;lock_sock (sk); +mptcp_clean_una (sk);__mptcp_flush_join_list (msk);__mptcp_move_skbs (msk); + +if (!test_and_clear_bit (MPTCP_WORK_RTX , &msk->flags)) + goto unlock; + + dfrag =mptcp_rtx_head (sk); +if (!dfrag) + goto unlock; + + ssk =mptcp_subflow_get_retrans (msk); +if (!ssk) + goto reset_unlock; + +lock_sock (ssk); + + msg.msg_flags =MSG_DONTWAIT ; + orig_len = dfrag->data_len; + orig_offset = dfrag->offset; + orig_write_seq = dfrag->data_seq; +while (dfrag->data_len >0 ) { + ret =mptcp_sendmsg_frag (sk, ssk, &msg, dfrag, &timeo, &mss_now, + &size_goal); +if (ret <0 ) +break ; + + copied += ret; + dfrag->data_len -= ret; + dfrag->offset += ret; + } +if (copied) +tcp_push (ssk, msg.msg_flags, mss_now,tcp_sk (ssk)->nonagle, + size_goal); + + dfrag->data_seq = orig_write_seq; + dfrag->offset = orig_offset; + dfrag->data_len = orig_len; + +mptcp_set_timeout (sk, ssk); +release_sock (ssk); + +reset_unlock: +if (!mptcp_timer_pending (sk)) +mptcp_reset_timer (sk); + +unlock:release_sock (sk);sock_put (sk); }
@@ -1124,6 +1213,7 @@ static int mptcp_disconnect(struct sock *sk, int flags)lock_sock (sk);__mptcp_clear_xmit (sk);release_sock (sk); +mptcp_cancel_work (sk);return tcp_disconnect (sk, flags); }
net/mptcp/protocol.h +1 -0
@@ -88,6 +88,7 @@/* MPTCP socket flags */ #define MPTCP_DATA_READY 0#define MPTCP_SEND_SPACE 1 +#define MPTCP_WORK_RTX 2static inline __be32 mptcp_option (u8 subopt,u8 len,u8 nib,u8 field) {
Signature · 1 line
2.26.0
PATCH v2 13/17 mptcp: allow dumping subflow context to userspace
In reply to Mat MartineauFrom: Davide Caratti <[email protected]>
add ulp-specific diagnostic functions, so that subflow information can be dumped to userspace programs like 'ss'.
--- MAINTAINERS | 1 + include/uapi/linux/inet_diag.h | 1 + include/uapi/linux/mptcp.h | 34 +++++++++++ net/mptcp/Makefile | 2 +- net/mptcp/diag.c | 104 +++++++++++++++++++++++++++++++++ net/mptcp/protocol.h | 2 + net/mptcp/subflow.c | 2 + 7 files changed, 145 insertions(+), 1 deletion(-) create mode 100644 include/uapi/linux/mptcp.h create mode 100644 net/mptcp/diag.c
MAINTAINERS +1 -0
@@ -11719,6 +11719,7 @@ W: https://github.com/multipath-tcp/mptcp_net-next/wiki B: https://github.com/multipath-tcp/mptcp_net-next/issues S: Maintained F: include/net/mptcp.h +F: include/uapi/linux/mptcp.h F: net/mptcp/ F: tools/testing/selftests/net/mptcp/
include/uapi/linux/inet_diag.h +1 -0
@@ -166,6 +166,7 @@ enum {INET_ULP_INFO_UNSPEC ,INET_ULP_INFO_NAME ,INET_ULP_INFO_TLS , +INET_ULP_INFO_MPTCP , __INET_ULP_INFO_MAX, };#define INET_ULP_INFO_MAX (__INET_ULP_INFO_MAX - 1)
include/uapi/linux/mptcp.h new file +34 -0
@@ -0,0 +1,34 @@ +/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */ +#ifndef _UAPI_MPTCP_H +#define _UAPI_MPTCP_H + +#include <linux/types.h> + +#define MPTCP_SUBFLOW_FLAG_MCAP_REM BIT(0) +#define MPTCP_SUBFLOW_FLAG_MCAP_LOC BIT(1) +#define MPTCP_SUBFLOW_FLAG_JOIN_REM BIT(2) +#define MPTCP_SUBFLOW_FLAG_JOIN_LOC BIT(3) +#define MPTCP_SUBFLOW_FLAG_BKUP_REM BIT(4) +#define MPTCP_SUBFLOW_FLAG_BKUP_LOC BIT(5) +#define MPTCP_SUBFLOW_FLAG_FULLY_ESTABLISHED BIT(6) +#define MPTCP_SUBFLOW_FLAG_CONNECTED BIT(7) +#define MPTCP_SUBFLOW_FLAG_MAPVALID BIT(8) + +enum { +MPTCP_SUBFLOW_ATTR_UNSPEC , +MPTCP_SUBFLOW_ATTR_TOKEN_REM , +MPTCP_SUBFLOW_ATTR_TOKEN_LOC , +MPTCP_SUBFLOW_ATTR_RELWRITE_SEQ , +MPTCP_SUBFLOW_ATTR_MAP_SEQ , +MPTCP_SUBFLOW_ATTR_MAP_SFSEQ , +MPTCP_SUBFLOW_ATTR_SSN_OFFSET , +MPTCP_SUBFLOW_ATTR_MAP_DATALEN , +MPTCP_SUBFLOW_ATTR_FLAGS , +MPTCP_SUBFLOW_ATTR_ID_REM , +MPTCP_SUBFLOW_ATTR_ID_LOC , +MPTCP_SUBFLOW_ATTR_PAD , + __MPTCP_SUBFLOW_ATTR_MAX +}; + +#define MPTCP_SUBFLOW_ATTR_MAX (__MPTCP_SUBFLOW_ATTR_MAX - 1) +#endif /* _UAPI_MPTCP_H */
net/mptcp/Makefile +1 -1
@@ -1,4 +1,4 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_MPTCP) += mptcp.o -mptcp-y := protocol.o subflow.o options.o token.o crypto.o ctrl.o pm.o +mptcp-y := protocol.o subflow.o options.o token.o crypto.o ctrl.o pm.o diag.o
net/mptcp/diag.c new file +104 -0
104 lines not on this page · raw message
net/mptcp/protocol.h +2 -0
@@ -408,4 +408,6 @@ static inline bool before64(__u64 seq1, __u64 seq2)#define after64 (seq2, seq1) before64(seq1, seq2) +void mptcp_diag_subflow_init (struct tcp_ulp_ops *ops); +#endif /* __MPTCP_PROTOCOL_H */
net/mptcp/subflow.c +2 -0
@@ -1148,6 +1148,8 @@ void mptcp_subflow_init(void) subflow_v6m_specific.net_frag_header_len =0 ;#endif +mptcp_diag_subflow_init (&subflow_ulp_ops); +if (tcp_register_ulp (&subflow_ulp_ops) !=0 )panic ("MPTCP: failed to register subflows to ULP\n" ); }
Signature · 1 line
2.26.0
PATCH v2 14/17 mptcp: add and use MIB counter infrastructure
In reply to Mat MartineauFrom: Florian Westphal <[email protected]>
Exported via same /proc file as the Linux TCP MIB counters, so "netstat -s" or "nstat" will show them automatically.
The MPTCP MIB counters are allocated in a distinct pcpu area in order to avoid bloating/wasting TCP pcpu memory.
Counters are allocated once the first MPTCP socket is created in a network namespace and free'd on exit.
If no sockets have been allocated, all-zero mptcp counters are shown.
The MIB counter list is taken from the multipath-tcp.org kernel, but only a few counters have been picked up so far. The counter list can be increased at any time later on.
--- include/net/mptcp.h | 4 +++ include/net/netns/mib.h | 3 ++ net/ipv4/af_inet.c | 4 +++ net/ipv4/proc.c | 2 ++ net/mptcp/Makefile | 2 +- net/mptcp/mib.c | 69 +++++++++++++++++++++++++++++++++++++++++ net/mptcp/mib.h | 40 ++++++++++++++++++++++++ net/mptcp/protocol.c | 30 +++++++++++++----- net/mptcp/subflow.c | 33 ++++++++++++++++---- 9 files changed, 172 insertions(+), 15 deletions(-) create mode 100644 net/mptcp/mib.c create mode 100644 net/mptcp/mib.h
include/net/mptcp.h +4 -0
@@ -12,6 +12,8 @@#include <linux/tcp.h> #include <linux/types.h> +struct seq_file ; +/* MPTCP sk_buff extension data */ struct mptcp_ext {u64 data_ack;
@@ -123,6 +125,7 @@ static inline bool mptcp_skb_can_collapse(const struct sk_buff *to,bool mptcp_sk_is_subflow (const struct sock *sk); +void mptcp_seq_show (struct seq_file *seq);#else static inline void mptcp_init (void )
@@ -194,6 +197,7 @@ static inline bool mptcp_sk_is_subflow(const struct sock *sk) return false; } +static inline void mptcp_seq_show (struct seq_file *seq) { }#endif /* CONFIG_MPTCP */ #if IS_ENABLED (CONFIG_MPTCP_IPV6 )
include/net/netns/mib.h +3 -0
@@ -27,6 +27,9 @@ struct netns_mib {#if IS_ENABLED (CONFIG_TLS ) DEFINE_SNMP_STAT(struct linux_tls_mib, tls_statistics);#endif +#ifdef CONFIG_MPTCP + DEFINE_SNMP_STAT(struct mptcp_mib, mptcp_statistics); +#endif };#endif
net/ipv4/af_inet.c +4 -0
@@ -1793,6 +1793,10 @@ static __net_exit void ipv4_mib_exit_net(struct net *net)free_percpu (net->mib.net_statistics);free_percpu (net->mib.ip_statistics);free_percpu (net->mib.tcp_statistics); +#ifdef CONFIG_MPTCP +/* allocated on demand, see mptcp_init_sock() */ +free_percpu (net->mib.mptcp_statistics); +#endif }static __net_initdata struct pernet_operations ipv4_mib_ops = {
net/ipv4/proc.c +2 -0
@@ -32,6 +32,7 @@#include <net/icmp.h> #include <net/protocol.h> #include <net/tcp.h> +#include <net/mptcp.h> #include <net/udp.h> #include <net/udplite.h> #include <linux/bottom_half.h>
@@ -485,6 +486,7 @@ static int netstat_seq_show(struct seq_file *seq, void *v) offsetof(struct ipstats_mib, syncp)));seq_putc (seq,'\n' ); +mptcp_seq_show (seq);return 0 ; }
net/mptcp/Makefile +1 -1
@@ -1,4 +1,4 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_MPTCP) += mptcp.o -mptcp-y := protocol.o subflow.o options.o token.o crypto.o ctrl.o pm.o diag.o +mptcp-y := protocol.o subflow.o options.o token.o crypto.o ctrl.o pm.o diag.o mib.o
net/mptcp/mib.c new file +69 -0
69 lines not on this page · raw message
net/mptcp/mib.h new file +40 -0
@@ -0,0 +1,40 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +enum linux_mptcp_mib_field { +MPTCP_MIB_NUM =0 , +MPTCP_MIB_MPCAPABLEPASSIVE ,/* Received SYN with MP_CAPABLE */ +MPTCP_MIB_MPCAPABLEPASSIVEACK ,/* Received third ACK with MP_CAPABLE */ +MPTCP_MIB_MPCAPABLEPASSIVEFALLBACK ,/* Server-side fallback during 3-way handshake */ +MPTCP_MIB_MPCAPABLEACTIVEFALLBACK ,/* Client-side fallback during 3-way handshake */ +MPTCP_MIB_RETRANSSEGS ,/* Segments retransmitted at the MPTCP-level */ +MPTCP_MIB_JOINNOTOKEN ,/* Received MP_JOIN but the token was not found */ +MPTCP_MIB_JOINSYNRX ,/* Received a SYN + MP_JOIN */ +MPTCP_MIB_JOINSYNACKRX ,/* Received a SYN/ACK + MP_JOIN */ +MPTCP_MIB_JOINSYNACKMAC ,/* HMAC was wrong on SYN/ACK + MP_JOIN */ +MPTCP_MIB_JOINACKRX ,/* Received an ACK + MP_JOIN */ +MPTCP_MIB_JOINACKMAC ,/* HMAC was wrong on ACK + MP_JOIN */ +MPTCP_MIB_DSSNOMATCH ,/* Received a new mapping that did not match the previous one */ +MPTCP_MIB_INFINITEMAPRX ,/* Received an infinite mapping */ + __MPTCP_MIB_MAX +}; + +#define LINUX_MIB_MPTCP_MAX __MPTCP_MIB_MAX +struct mptcp_mib { +unsigned long mibs[LINUX_MIB_MPTCP_MAX ]; +}; + +static inline void MPTCP_INC_STATS (struct net *net, +enum linux_mptcp_mib_field field) +{ +if (likely (net->mib.mptcp_statistics)) +SNMP_INC_STATS (net->mib.mptcp_statistics, field); +} + +static inline void __MPTCP_INC_STATS (struct net *net, +enum linux_mptcp_mib_field field) +{ +if (likely (net->mib.mptcp_statistics)) +__SNMP_INC_STATS (net->mib.mptcp_statistics, field); +} + +bool mptcp_mib_alloc (struct net *net);
net/mptcp/protocol.c +22 -8
@@ -21,6 +21,7 @@#endif #include <net/mptcp.h> #include "protocol.h" +#include "mib.h" #define MPTCP_SAME_STATE TCP_MAX_STATES
@@ -1032,6 +1033,7 @@ static void mptcp_worker(struct work_struct *work)if (ret <0 )break ; +MPTCP_INC_STATS (sock_net (sk),MPTCP_MIB_RETRANSSEGS ); copied += ret; dfrag->data_len -= ret; dfrag->offset += ret;
@@ -1081,17 +1083,22 @@ static int __mptcp_init_sock(struct sock *sk)static int mptcp_init_sock (struct sock *sk) { -int ret =__mptcp_init_sock (sk); +struct net *net =sock_net (sk); +int ret; +if (!mptcp_is_enabled (net)) +return -ENOPROTOOPT ; + +if (unlikely (!net->mib.mptcp_statistics) && !mptcp_mib_alloc (net)) +return -ENOMEM ; + + ret =__mptcp_init_sock (sk);if (ret)return ret;sk_sockets_allocated_inc (sk); sk->sk_sndbuf =sock_net (sk)->ipv4.sysctl_tcp_wmem[2 ]; -if (!mptcp_is_enabled (sock_net (sk))) -return -ENOPROTOOPT ; -return 0 ; }
@@ -1327,7 +1334,12 @@ static struct sock *mptcp_accept(struct sock *sk, int flags, int *err,list_add (&subflow->node, &msk->conn_list);bh_unlock_sock (new_mptcp_sock); + +__MPTCP_INC_STATS (sock_net (sk),MPTCP_MIB_MPCAPABLEPASSIVEACK );local_bh_enable (); + }else { +MPTCP_INC_STATS (sock_net (sk), +MPTCP_MIB_MPCAPABLEPASSIVEFALLBACK ); }return newsk;
@@ -1448,13 +1460,15 @@ void mptcp_finish_connect(struct sock *ssk)u64 ack_seq; subflow =mptcp_subflow_ctx (ssk); - -if (!subflow->mp_capable) -return ; - sk = subflow->conn; msk =mptcp_sk (sk); +if (!subflow->mp_capable) { +MPTCP_INC_STATS (sock_net (sk), +MPTCP_MIB_MPCAPABLEACTIVEFALLBACK ); +return ; + } +pr_debug ("msk=%p, token=%u" , sk, subflow->token);mptcp_crypto_key_sha (subflow->remote_key,NULL , &ack_seq);
net/mptcp/subflow.c +27 -6
@@ -20,6 +20,13 @@#endif #include <net/mptcp.h> #include "protocol.h" +#include "mib.h" + +static inline void SUBFLOW_REQ_INC_STATS (struct request_sock *req, +enum linux_mptcp_mib_field field) +{ +MPTCP_INC_STATS (sock_net (req_to_sk (req)), field); +}static int subflow_rebuild_header (struct sock *sk) {
@@ -88,8 +95,7 @@ static bool subflow_token_join_request(struct request_sock *req, msk =mptcp_token_get_sock (subflow_req->token);if (!msk) { -pr_debug ("subflow_req=%p, token=%u - not found\n" , - subflow_req, subflow_req->token); +SUBFLOW_REQ_INC_STATS (req,MPTCP_MIB_JOINNOTOKEN );return false; }
@@ -137,8 +143,14 @@ static void subflow_init_req(struct request_sock *req,return ;#endif -if (rx_opt.mptcp.mp_capable && rx_opt.mptcp.mp_join) -return ; +if (rx_opt.mptcp.mp_capable) { +SUBFLOW_REQ_INC_STATS (req,MPTCP_MIB_MPCAPABLEPASSIVE ); + +if (rx_opt.mptcp.mp_join) +return ; + }else if (rx_opt.mptcp.mp_join) { +SUBFLOW_REQ_INC_STATS (req,MPTCP_MIB_JOINSYNRX ); + }if (rx_opt.mptcp.mp_capable && listener->request_mptcp) {int err;
@@ -237,6 +249,7 @@ static void subflow_finish_connect(struct sock *sk, const struct sk_buff *skb) subflow, subflow->thmac, subflow->remote_nonce);if (!subflow_thmac_valid (subflow)) { +MPTCP_INC_STATS (sock_net (sk),MPTCP_MIB_JOINACKMAC ); subflow->mp_join =0 ; goto do_reset; }
@@ -253,6 +266,7 @@ static void subflow_finish_connect(struct sock *sk, const struct sk_buff *skb) goto do_reset; subflow->conn_finished =1 ; +MPTCP_INC_STATS (sock_net (sk),MPTCP_MIB_JOINSYNACKRX ); }else { do_reset:tcp_send_active_reset (sk,GFP_ATOMIC );
@@ -382,8 +396,10 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk, opt_rx.mptcp.mp_join =0 ;mptcp_get_options (skb, &opt_rx);if (!opt_rx.mptcp.mp_join || - !subflow_hmac_valid (req, &opt_rx)) + !subflow_hmac_valid (req, &opt_rx)) { +SUBFLOW_REQ_INC_STATS (req,MPTCP_MIB_JOINACKMAC );return NULL ; + } } create_child:
@@ -420,6 +436,8 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk, ctx->conn = (struct sock *)owner;if (!mptcp_finish_join (child)) goto close_child; + +SUBFLOW_REQ_INC_STATS (req,MPTCP_MIB_JOINACKRX ); } }
@@ -535,6 +553,7 @@ static enum mapping_status get_mapping_status(struct sock *ssk) data_len = mpext->data_len;if (data_len ==0 ) {pr_err ("Infinite mapping not handled" ); +MPTCP_INC_STATS (sock_net (ssk),MPTCP_MIB_INFINITEMAPRX );return MAPPING_INVALID ; }
@@ -578,8 +597,10 @@ static enum mapping_status get_mapping_status(struct sock *ssk)/* If this skb data are fully covered by the current mapping, * the new map would need caching, which is not supported */ -if (skb_is_fully_mapped (ssk, skb)) +if (skb_is_fully_mapped (ssk, skb)) { +MPTCP_INC_STATS (sock_net (ssk),MPTCP_MIB_DSSNOMATCH );return MAPPING_INVALID ; + }/* will validate the next map after consuming the current one */ return MAPPING_OK ;
Signature · 1 line
2.26.0
PATCH v2 15/17 mptcp: add netlink-based PM
In reply to Mat MartineauFrom: Paolo Abeni <[email protected]>
Expose a new netlink family to userspace to control the PM, setting:
- list of local addresses to be signalled.
- list of local addresses used to created subflows.
- maximum number of add_addr option to react
When the msk is fully established, the PM netlink attempts to announce the 'signal' list via the ADD_ADDR option. Since we currently lack the ADD_ADDR echo (and related event) only the first addr is sent.
After exhausting the 'announce' list, the PM tries to create subflow for each addr in 'local' list, waiting for each connection to be completed before attempting the next one.
Idea is to add an additional PM hook for ADD_ADDR echo, to allow the PM netlink announcing multiple addresses, in sequence.
--- include/uapi/linux/mptcp.h | 54 +++ net/mptcp/Makefile | 3 +- net/mptcp/pm.c | 9 +- net/mptcp/pm_netlink.c | 857 +++++++++++++++++++++++++++++++++++++ net/mptcp/protocol.h | 7 + 5 files changed, 928 insertions(+), 2 deletions(-) create mode 100644 net/mptcp/pm_netlink.c
include/uapi/linux/mptcp.h +54 -0
@@ -31,4 +31,58 @@ enum { };#define MPTCP_SUBFLOW_ATTR_MAX (__MPTCP_SUBFLOW_ATTR_MAX - 1) + +/* netlink interface */ +#define MPTCP_PM_NAME "mptcp_pm" +#define MPTCP_PM_CMD_GRP_NAME "mptcp_pm_cmds" +#define MPTCP_PM_VER 0x1 + +/* +* ATTR types defined for MPTCP +*/ +enum { +MPTCP_PM_ATTR_UNSPEC , + +MPTCP_PM_ATTR_ADDR ,/* nested address */ +MPTCP_PM_ATTR_RCV_ADD_ADDRS ,/* u32 */ +MPTCP_PM_ATTR_SUBFLOWS ,/* u32 */ + + __MPTCP_PM_ATTR_MAX +}; + +#define MPTCP_PM_ATTR_MAX (__MPTCP_PM_ATTR_MAX - 1) + +enum { +MPTCP_PM_ADDR_ATTR_UNSPEC , + +MPTCP_PM_ADDR_ATTR_FAMILY ,/* u16 */ +MPTCP_PM_ADDR_ATTR_ID ,/* u8 */ +MPTCP_PM_ADDR_ATTR_ADDR4 ,/* struct in_addr */ +MPTCP_PM_ADDR_ATTR_ADDR6 ,/* struct in6_addr */ +MPTCP_PM_ADDR_ATTR_PORT ,/* u16 */ +MPTCP_PM_ADDR_ATTR_FLAGS ,/* u32 */ +MPTCP_PM_ADDR_ATTR_IF_IDX ,/* s32 */ + + __MPTCP_PM_ADDR_ATTR_MAX +}; + +#define MPTCP_PM_ADDR_ATTR_MAX (__MPTCP_PM_ADDR_ATTR_MAX - 1) + +#define MPTCP_PM_ADDR_FLAG_SIGNAL (1 << 0) +#define MPTCP_PM_ADDR_FLAG_SUBFLOW (1 << 1) +#define MPTCP_PM_ADDR_FLAG_BACKUP (1 << 2) + +enum { +MPTCP_PM_CMD_UNSPEC , + +MPTCP_PM_CMD_ADD_ADDR , +MPTCP_PM_CMD_DEL_ADDR , +MPTCP_PM_CMD_GET_ADDR , +MPTCP_PM_CMD_FLUSH_ADDRS , +MPTCP_PM_CMD_SET_LIMITS , +MPTCP_PM_CMD_GET_LIMITS , + + __MPTCP_PM_CMD_AFTER_LAST +}; +#endif /* _UAPI_MPTCP_H */
net/mptcp/Makefile +2 -1
@@ -1,4 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 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 +mptcp-y := protocol.o subflow.o options.o token.o crypto.o ctrl.o pm.o diag.o \ + mib.o pm_netlink.o
net/mptcp/pm.c +8 -1
@@ -176,7 +176,7 @@ bool mptcp_pm_addr_signal(struct mptcp_sock *msk, unsigned int remaining,int mptcp_pm_get_local_id (struct mptcp_sock *msk,struct sock_common *skc) { -return 0 ; +return mptcp_pm_nl_get_local_id (msk, skc); }static void pm_worker (struct work_struct *work)
@@ -192,12 +192,15 @@ static void pm_worker(struct work_struct *work)pr_debug ("msk=%p status=%x" , msk, pm->status);if (pm->status &BIT (MPTCP_PM_ADD_ADDR_RECEIVED )) { pm->status &= ~BIT (MPTCP_PM_ADD_ADDR_RECEIVED ); +mptcp_pm_nl_add_addr_received (msk); }if (pm->status &BIT (MPTCP_PM_ESTABLISHED )) { pm->status &= ~BIT (MPTCP_PM_ESTABLISHED ); +mptcp_pm_nl_fully_established (msk); }if (pm->status &BIT (MPTCP_PM_SUBFLOW_ESTABLISHED )) { pm->status &= ~BIT (MPTCP_PM_SUBFLOW_ESTABLISHED ); +mptcp_pm_nl_subflow_established (msk); }spin_unlock_bh (&msk->pm.lock);
@@ -219,6 +222,8 @@ void mptcp_pm_data_init(struct mptcp_sock *msk)spin_lock_init (&msk->pm.lock);INIT_WORK (&msk->pm.work, pm_worker); + +mptcp_pm_nl_data_init (msk); }void mptcp_pm_close (struct mptcp_sock *msk)
@@ -232,4 +237,6 @@ void mptcp_pm_init(void) pm_wq =alloc_workqueue ("pm_wq" ,WQ_UNBOUND |WQ_MEM_RECLAIM ,8 );if (!pm_wq)panic ("Failed to allocate workqueue" ); + +mptcp_pm_nl_init (); }
net/mptcp/pm_netlink.c new file +857 -0
857 lines not on this page · raw message
net/mptcp/protocol.h +7 -0
@@ -396,6 +396,13 @@ bool mptcp_pm_addr_signal(struct mptcp_sock *msk, unsigned int remaining, struct mptcp_addr_info *saddr);int mptcp_pm_get_local_id (struct mptcp_sock *msk,struct sock_common *skc); +void mptcp_pm_nl_init (void ); +void mptcp_pm_nl_data_init (struct mptcp_sock *msk); +void mptcp_pm_nl_fully_established (struct mptcp_sock *msk); +void mptcp_pm_nl_subflow_established (struct mptcp_sock *msk); +void mptcp_pm_nl_add_addr_received (struct mptcp_sock *msk); +int mptcp_pm_nl_get_local_id (struct mptcp_sock *msk,struct sock_common *skc); +static inline struct mptcp_ext *mptcp_get_ext (struct sk_buff *skb) {return (struct mptcp_ext *)skb_ext_find (skb,SKB_EXT_MPTCP );
Signature · 1 line
2.26.0
PATCH v2 16/17 selftests: add PM netlink functional tests
In reply to Mat MartineauFrom: Paolo Abeni <[email protected]>
This introduces basic self-tests for the PM netlink, checking the basic APIs and possible exceptional values.
--- tools/testing/selftests/net/mptcp/.gitignore | 1 + tools/testing/selftests/net/mptcp/Makefile | 7 +- .../testing/selftests/net/mptcp/pm_netlink.sh | 130 ++++ tools/testing/selftests/net/mptcp/pm_nl_ctl.c | 616 ++++++++++++++++++ 4 files changed, 751 insertions(+), 3 deletions(-) create mode 100755 tools/testing/selftests/net/mptcp/pm_netlink.sh create mode 100644 tools/testing/selftests/net/mptcp/pm_nl_ctl.c
tools/testing/selftests/net/mptcp/.gitignore +1 -0
@@ -1,2 +1,3 @@ mptcp_connect +pm_nl_ctl *.pcap
tools/testing/selftests/net/mptcp/Makefile +4 -3
@@ -1,12 +1,13 @@ # SPDX-License-Identifier: GPL-2.0 top_srcdir = ../../../../.. +KSFT_KHDR_INSTALL := 1 -CFLAGS = -Wall -Wl,--no-as-needed -O2 -g +CFLAGS = -Wall -Wl,--no-as-needed -O2 -g -I$(top_srcdir)/usr/include -TEST_PROGS := mptcp_connect.sh +TEST_PROGS := mptcp_connect.sh pm_netlink.sh -TEST_GEN_FILES = mptcp_connect +TEST_GEN_FILES = mptcp_connect pm_nl_ctl TEST_FILES := settings
tools/testing/selftests/net/mptcp/pm_netlink.sh new file +130 -0
130 lines not on this page · raw message
tools/testing/selftests/net/mptcp/pm_nl_ctl.c new file +616 -0
616 lines not on this page · raw message
Signature · 1 line
2.26.0
PATCH v2 17/17 selftests: add test-cases for MPTCP MP_JOIN
In reply to Mat MartineauFrom: Paolo Abeni <[email protected]>
Use the pm netlink to configure the creation of several subflows, and verify that via MIB counters.
Update the mptcp_connect program to allow reliable MP_JOIN handshake even on small data file
--- tools/testing/selftests/net/mptcp/Makefile | 2 +- .../selftests/net/mptcp/mptcp_connect.c | 28 +- .../testing/selftests/net/mptcp/mptcp_join.sh | 357 ++++++++++++++++++ 3 files changed, 383 insertions(+), 4 deletions(-) create mode 100755 tools/testing/selftests/net/mptcp/mptcp_join.sh
tools/testing/selftests/net/mptcp/Makefile +1 -1
@@ -5,7 +5,7 @@ KSFT_KHDR_INSTALL := 1 CFLAGS = -Wall -Wl,--no-as-needed -O2 -g -I$(top_srcdir)/usr/include -TEST_PROGS := mptcp_connect.sh pm_netlink.sh +TEST_PROGS := mptcp_connect.sh pm_netlink.sh mptcp_join.sh TEST_GEN_FILES = mptcp_connect pm_nl_ctl
tools/testing/selftests/net/mptcp/mptcp_connect.c +25 -3
@@ -51,6 +51,7 @@ static bool tcpulp_audit;static int pf =AF_INET ;static int cfg_sndbuf;static int cfg_rcvbuf; +static bool cfg_join;static void die_usage (void ) {
@@ -250,6 +251,7 @@ static int sock_connect_mptcp(const char * const remoteaddr,static size_t do_rnd_write (const int fd,char *buf,const size_t len) { +static bool first = true;unsigned int do_w;ssize_t bw;
@@ -257,10 +259,19 @@ static size_t do_rnd_write(const int fd, char *buf, const size_t len)if (do_w ==0 || do_w > len) do_w = len; +if (cfg_join && first && do_w >100 ) + do_w =100 ; + bw =write (fd, buf, do_w);if (bw <0 )perror ("write" ); +/* let the join handshake complete, before going on */ +if (cfg_join && first) { +usleep (200000 ); + first = false; + } +return bw; }
@@ -385,8 +396,11 @@ static int copyfd_io_poll(int infd, int peerfd, int outfd)break ;/* ... but we still receive. -* Close our write side. +* Close our write side, ev. give some time +* for address notification */ +if (cfg_join) +usleep (400000 );shutdown (peerfd,SHUT_WR ); }else {if (errno ==EINTR )
@@ -403,6 +417,10 @@ static int copyfd_io_poll(int infd, int peerfd, int outfd) } } +/* leave some time for late join/announce */ +if (cfg_join) +usleep (400000 ); +close (peerfd);return 0 ; }
@@ -658,7 +676,7 @@ static void maybe_close(int fd) {unsigned int r =rand (); -if (r &1 ) +if (!cfg_join && (r &1 ))close (fd); }
@@ -794,8 +812,12 @@ static void parse_opts(int argc, char **argv) {int c; -while ((c =getopt (argc, argv,"6lp:s:hut:m:S:R:" )) !=-1 ) { +while ((c =getopt (argc, argv,"6jlp:s:hut:m:S:R:" )) !=-1 ) {switch (c) { +case 'j' : + cfg_join = true; + cfg_mode =CFG_MODE_POLL ; +break ;case 'l' : listen_mode = true;break ;
tools/testing/selftests/net/mptcp/mptcp_join.sh new file +357 -0
357 lines not on this page · raw message
Signature · 1 line
2.26.0