MP_JOIN handling WIP
Subsystems (3)
Peter Krystad
v3 cover MP_JOIN handling WIP
Current state of MP_JOIN handling. As I mentioned this is not functional yet but am sharing for visibility. The intent of this patchset is to complete the handshake for a second subflow in the incoming direction. Sending an outgoing SYN with MP_JOIN and the data path is not addressed.
v2 - pr_debug() cleanup and single mptcp_established() hook were
address in other already-merged patchsets
- split path manager skeleton into its own commit
- cleaned up logic in subflow_syn_recv_sock
- rebase onto Florian's locking change
- namespace for token table NOT addressed
v3 - revise IPv6 handling for ADD_ADDR
- macro for option word
- fix indentation
- mp_join vs mp_capable else statement cleanup
Peter Krystad (3):
mptcp: Add path manager interface
mptcp: Add ADD_ADDR handling
mptcp: Add handling of incoming MP_JOIN requests
include/linux/tcp.h | 17 +++++ include/net/mptcp.h | 30 +++++++- net/ipv4/tcp_minisocks.c | 6 ++ net/mptcp/Makefile | 2 +- net/mptcp/options.c | 156 +++++++++++++++++++++++++++++++++++---- net/mptcp/pm.c | 66 +++++++++++++++++ net/mptcp/protocol.c | 25 +++++++ net/mptcp/protocol.h | 69 ++++++++++++++++- net/mptcp/subflow.c | 61 ++++++++++++--- net/mptcp/token.c | 124 +++++++++++++++++++++++++++++++ 10 files changed, 526 insertions(+), 30 deletions(-) create mode 100644 net/mptcp/pm.c
Signature · 1 line
2.17.2
Peter Krystad
RFC v3 1/3 mptcp: Add path manager interface
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.
This is a skeleton interface definition for events generated by MPTCP.
--- net/mptcp/Makefile | 2 +- net/mptcp/pm.c | 57 ++++++++++++++++++++++++++++++++++++++++++++ net/mptcp/protocol.c | 4 ++++ net/mptcp/protocol.h | 25 ++++++++++++++++++- 4 files changed, 86 insertions(+), 2 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 +mptcp-y := protocol.o subflow.o options.o token.o crypto.o pm.o
net/mptcp/pm.c new file +57 -0
57 lines not on this page · raw message
net/mptcp/protocol.c +4 -0
@@ -632,6 +632,8 @@ static struct sock *mptcp_accept(struct sock *sk, int flags, int *err,token_update_accept (new_sock->sk, new_mptcp_sock); msk->subflow =NULL ; +pm_new_connection (msk); +crypto_key_sha1 (msk->remote_key,NULL , &ack_seq); msk->write_seq = subflow->idsn +1 ; ack_seq++;
@@ -757,6 +759,8 @@ void mptcp_finish_connect(struct sock *sk, int mp_capable) msk->token = subflow->token;pr_debug ("msk=%p, token=%u" , msk, msk->token); +pm_new_connection (msk); +crypto_key_sha1 (msk->remote_key,NULL , &ack_seq); msk->write_seq = subflow->idsn +1 ; ack_seq++;
net/mptcp/protocol.h +24 -1
@@ -15,7 +15,7 @@#define MPTCPOPT_MP_JOIN 1#define MPTCPOPT_DSS 2#define MPTCPOPT_ADD_ADDR 3 -#define MPTCPOPT_REMOVE_ADDR 4 +#define MPTCPOPT_RM_ADDR 4#define MPTCPOPT_MP_PRIO 5#define MPTCPOPT_MP_FAIL 6#define MPTCPOPT_MP_FASTCLOSE 7
@@ -36,6 +36,17 @@#define MPTCP_DSS_HAS_ACK BIT(0)#define MPTCP_DSS_FLAG_MASK (0x1F) +struct pm_data { +u8 addr_id; +sa_family_t family; +union { +struct in_addr addr; +#if IS_ENABLED (CONFIG_IPV6 ) +struct in6_addr addr6; +#endif + }; +}; +/* MPTCP connection sock */ struct mptcp_sock {/* inet_connection_sock must be the first member */
@@ -47,6 +58,7 @@ struct mptcp_sock {u32 token;struct list_head conn_list;struct socket *subflow;/* outgoing connect/listener/!mp_capable */ +struct pm_data pm; };#define mptcp_for_each_subflow (__msk, __subflow) \
@@ -146,6 +158,17 @@ void crypto_key_sha1(u64 key, u32 *token, u64 *idsn);void crypto_hmac_sha1 (u64 key1,u64 key2,u32 *hash_out,int arg_num, ...); +void pm_new_connection (struct mptcp_sock *msk); +void pm_fully_established (struct mptcp_sock *msk); +void pm_connection_closed (struct mptcp_sock *msk); +void pm_subflow_established (struct mptcp_sock *msk,u8 id); +void pm_subflow_closed (struct mptcp_sock *msk,u8 id); +void pm_add_addr (struct mptcp_sock *msk,const struct in_addr *addr,u8 id); +void pm_add_addr6 (struct mptcp_sock *msk,const struct in6_addr *addr,u8 id); +void pm_rm_addr (struct mptcp_sock *msk,u8 id); +bool pm_addr_signal (struct mptcp_sock *msk,unsigned *size, +unsigned int remaining,struct mptcp_out_options *opts); +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.17.2
Peter Krystad
RFC v3 2/3 mptcp: Add ADD_ADDR handling
In reply to Peter KrystadAdd handling for sending and receiving the ADD_ADDR, ADD_ADDR6, and RM_ADDR suboptions.
--- include/linux/tcp.h | 11 +++++ include/net/mptcp.h | 16 ++++++-- net/mptcp/options.c | 98 +++++++++++++++++++++++++++++++++++++++----- net/mptcp/pm.c | 11 ++++- net/mptcp/protocol.h | 16 ++++++++ 5 files changed, 138 insertions(+), 14 deletions(-)
include/linux/tcp.h +11 -0
@@ -122,6 +122,16 @@ struct tcp_options_received { use_ack:1, ack64:1, __unused:2; + u8 add_addr : 1, + rm_addr : 1, + family : 4; +u8 addr_id; +union { +struct in_addr addr; +#if IS_ENABLED (CONFIG_IPV6 ) +struct in6_addr addr6; +#endif + }; } mptcp;#endif };
@@ -135,6 +145,7 @@ static inline void tcp_clear_options(struct tcp_options_received *rx_opt)#endif #if IS_ENABLED (CONFIG_MPTCP ) rx_opt->mptcp.mp_capable = rx_opt->mptcp.mp_join =0 ; + rx_opt->mptcp.add_addr = rx_opt->mptcp.rm_addr =0 ; rx_opt->mptcp.dss =0 ;#endif }
include/net/mptcp.h +13 -3
@@ -25,15 +25,25 @@ struct mptcp_ext { };/* MPTCP option subtypes */ -#define OPTION_MPTCP_MPC_SYN BIT(0) -#define OPTION_MPTCP_MPC_SYNACK BIT(1) -#define OPTION_MPTCP_MPC_ACK BIT(2) +#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)struct mptcp_out_options {#if IS_ENABLED (CONFIG_MPTCP )u16 suboptions;u64 sndr_key;u64 rcvr_key; +union { +struct in_addr addr; +#if IS_ENABLED (CONFIG_IPV6 ) +struct in6_addr addr6; +#endif + }; +u8 addr_id;struct mptcp_ext ext_copy;#endif };
net/mptcp/options.c +88 -10
143 lines not on this page · raw message
net/mptcp/pm.c +10 -1
@@ -51,7 +51,16 @@ void pm_rm_addr(struct mptcp_sock *msk, u8 id)bool pm_addr_signal (struct mptcp_sock *msk,unsigned *size,unsigned int remaining,struct mptcp_out_options *opts) { +if (!msk || !msk->addr_signal) +return false; + +if (msk->pm.family ==AF_INET && remaining <TCPOLEN_MPTCP_ADD_ADDR ) +return false; +pr_debug ("msk=%p" , msk); + opts->suboptions |=OPTION_MPTCP_ADD_ADDR ; + opts->addr_id = msk->pm.addr_id; + opts->addr.s_addr = msk->pm.addr.s_addr; -return false; +return true; }
net/mptcp/protocol.h +16 -0
@@ -9,6 +9,7 @@#define __MPTCP_PROTOCOL_H#include <linux/spinlock.h> +#include <net/tcp.h> /* MPTCP option subtypes */ #define MPTCPOPT_MP_CAPABLE 0
@@ -20,8 +21,16 @@#define MPTCPOPT_MP_FAIL 6#define MPTCPOPT_MP_FASTCLOSE 7 +#define TCPOLEN_MPTCP_ADD_ADDR 8 +#define TCPOLEN_MPTCP_ADD_ADDR6 20 +#define TCPOLEN_MPTCP_RM_ADDR 4 +#define MPTCPOPT_VERSION_MASK 0x0F +#define MPTCP_ADDR_FAMILY_MASK 0x0F +#define MPTCP_ADDR_IPVERSION_4 4 +#define MPTCP_ADDR_IPVERSION_6 6 +/* MPTCP handshake flags */ #define MPTCP_CAP_CHECKSUM_REQD BIT(7)#define MPTCP_CAP_EXTENSIBILITY BIT(6)
@@ -36,6 +45,12 @@#define MPTCP_DSS_HAS_ACK BIT(0)#define MPTCP_DSS_FLAG_MASK (0x1F) +static inline u32 mptcp_option (u8 subopt,u8 len,u8 nib,u8 field) +{ +return htonl ((TCPOPT_MPTCP <<24 ) | (len <<16 ) | (subopt <<12 ) | + ((nib &0xF ) <<8 ) | field); +} +struct pm_data {u8 addr_id;sa_family_t family;
@@ -59,6 +74,7 @@ struct mptcp_sock {struct list_head conn_list;struct socket *subflow;/* outgoing connect/listener/!mp_capable */ struct pm_data pm; +u8 addr_signal; };#define mptcp_for_each_subflow (__msk, __subflow) \
Signature · 1 line
2.17.2
Peter Krystad
RFC v3 3/3 mptcp: Add handling of incoming MP_JOIN requests
In reply to Peter KrystadProcess 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 | 6 ++ include/net/mptcp.h | 14 +++++ net/ipv4/tcp_minisocks.c | 6 ++ net/mptcp/options.c | 58 ++++++++++++++++-- net/mptcp/protocol.c | 21 +++++++ net/mptcp/protocol.h | 28 ++++++++- net/mptcp/subflow.c | 61 ++++++++++++++++--- net/mptcp/token.c | 124 +++++++++++++++++++++++++++++++++++++++ 8 files changed, 303 insertions(+), 15 deletions(-)
include/linux/tcp.h +6 -0
@@ -112,8 +112,14 @@ struct tcp_options_received { u8 mp_capable : 1, mp_join : 1, dss : 1, + backup : 1, version : 4;u8 flags; +u8 join_id; +u32 token; +u32 nonce; +u64 thmac; +u8 hmac[20 ];u8 dss_flags; u8 use_map:1, dsn64:1,
include/net/mptcp.h +14 -0
@@ -28,6 +28,9 @@ struct mptcp_ext {#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)
@@ -44,6 +47,10 @@ struct mptcp_out_options { #endif };u8 addr_id; +u8 join_id; +u8 backup; +u32 nonce; +u64 thmac;struct mptcp_ext ext_copy;#endif };
@@ -83,6 +90,8 @@ static inline bool mptcp_skb_ext_exist(const struct sk_buff *skb)void mptcp_write_options (__be32 *ptr,struct mptcp_out_options *opts); +bool mptcp_sk_is_subflow (const struct sock *sk); +#else static inline void mptcp_init (void )
@@ -140,5 +149,10 @@ static inline bool mptcp_skb_ext_exist(const struct sk_buff *skb)return false; } +static inline book mptcp_sk_is_subflow (const struct sock *sk) +{ +return false; +} +#endif /* CONFIG_MPTCP */ #endif /* __NET_MPTCP_H */
net/ipv4/tcp_minisocks.c +6 -0
@@ -766,6 +766,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)) { +inet_csk_reqsk_queue_drop (sk, req); +reqsk_queue_removed (&inet_csk (sk)->icsk_accept_queue, req); +return child; + } +sock_rps_save_rxhash (child, skb);tcp_synack_rtt_meas (child, req); *req_stolen = !own_req;
net/mptcp/options.c +54 -4
94 lines not on this page · raw message
net/mptcp/protocol.c +21 -0
@@ -777,6 +777,27 @@ void mptcp_finish_connect(struct sock *sk, int mp_capable)inet_sk_state_store (sk,TCP_ESTABLISHED ); } +void mptcp_finish_join (struct sock *conn,struct sock *sk) +{ +struct subflow_context *subflow =subflow_ctx (sk); +struct mptcp_sock *msk =mptcp_sk (conn); + +pr_debug ("msk=%p, subflow=%p" , msk, subflow); + +local_bh_disable (); +bh_lock_sock_nested (sk); +list_add_tail (&subflow->node, &msk->conn_list); +bh_unlock_sock (sk); +local_bh_enable (); +} + +bool mptcp_sk_is_subflow (const struct sock *sk) +{ +struct subflow_context *subflow =subflow_ctx (sk); + +return subflow->mp_join ==1 ; +} +static struct proto mptcp_prot = { .name ="MPTCP" , .owner =THIS_MODULE ,
net/mptcp/protocol.h +26 -2
@@ -21,11 +21,16 @@#define MPTCPOPT_MP_FAIL 6#define MPTCPOPT_MP_FASTCLOSE 7 +#define TCPOLEN_MPTCP_MPJ_SYN 12 +#define TCPOLEN_MPTCP_MPJ_SYNACK 16 +#define TCPOLEN_MPTCP_MPJ_ACK 24#define TCPOLEN_MPTCP_ADD_ADDR 8#define TCPOLEN_MPTCP_ADD_ADDR6 20#define TCPOLEN_MPTCP_RM_ADDR 4#define MPTCPOPT_VERSION_MASK 0x0F +#define MPTCPOPT_BACKUP (1 << 0) +#define MPTCPOPT_HMAC_LEN 20#define MPTCP_ADDR_FAMILY_MASK 0x0F#define MPTCP_ADDR_IPVERSION_4 4
@@ -92,11 +97,16 @@ struct subflow_request_sock { checksum : 1, backup : 1, version : 4; +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
@@ -119,15 +129,23 @@ struct subflow_context {u16 map_data_len; u16 request_mptcp : 1, /* send MP_CAPABLE */ request_cksum : 1, - mp_capable : 1, /* remote is MPTCP capable */ + mp_capable : 1, /* remote is MPTCP capable */ + mp_join : 1, /* remote is JOINing */ fourth_ack : 1, /* send initial DSS */ version : 4, conn_finished : 1, use_checksum : 1, - map_valid : 1; + map_valid : 1, + backup : 1; +u32 remote_nonce; +u64 thmac; +u32 local_nonce; +u8 local_id; +u8 remote_id;struct socket *tcp_sock;/* underlying tcp_sock */ struct sock *conn;/* parent mptcp_sock */ +void (*tcp_sk_data_ready)(struct sock *sk); };
@@ -150,13 +168,19 @@ void mptcp_get_options(const struct sk_buff *skb, struct tcp_options_received *opt_rx);void mptcp_finish_connect (struct sock *sk,int mp_capable); +void mptcp_finish_join (struct sock *conn,struct sock *sk);void token_init (void );void token_new_request (struct request_sock *req,const struct sk_buff *skb); +int token_join_request (struct request_sock *req,const struct sk_buff *skb); +int token_join_valid (struct request_sock *req, +struct tcp_options_received *rx_opt);void token_destroy_request (u32 token);void token_new_connect (struct sock *sk);void token_new_accept (struct sock *sk); +int token_new_join (struct sock *sk);void token_update_accept (struct sock *sk,struct sock *conn); +void token_release (u32 token);void token_destroy (u32 token);void crypto_init (void );
net/mptcp/subflow.c +52 -9
102 lines not on this page · raw message
net/mptcp/token.c +124 -0
154 lines not on this page · raw message
Signature · 1 line
2.17.2