Skip to contentSkip to conversation

Implement outgoing MP_JOIN

PATCH Superseded Peter Krystad 3 participants 26 messages Jul 26, 2019 – Aug 7, 2019

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Peter Krystad

author
#0 lore raw

v2 cover Implement outgoing MP_JOIN

This is several accumulated fixes that are required for MP_JOIN (secondary subflows) plus the outgoing code.

Both outgoing and incoming MP_JOIN now inter-operate with the multipath.org implementation although there is still a deadlock when incoming is fully established. Since the incoming direction did not work at all before this is an improvement. I have not yet tested running our implmentation against itself.

The final patch in the set is an "interim path manager", this is throw-away code that I include for testing purposes. For an incoming connection it is necessary for the server to advertise a secondary address and for my testing I have been hard-coding the IP address of my secondary interface when I build the kernel. Obviously not the final solution but we need to discuss what approach to use for the self tests. I also think we may not want to publish this patch on our net-next branch.

v2:
- move mptcp_options_received formatting to options.c
- resolve conflicts with Davide's crypto commit
- make helper for setting request fields
- fix locking in token_lookup()
- move token_lookup() to "Implement path manager interface commands:
(where it belongs)
- split interim path manager out of final commit, will submit seperately
- remove use of local_id in pm_create_subflow
- restrict announcing addresses to server side only
- add one more commit with get_local_id fix for incoming MP_JOIN

Peter Krystad (10):
Extend path manager interface
Fix locking in mptcp_finish_join.
Fix parsing MP_JOIN third ACK.
Re-factor and fixes for crypto_hmac_sha1()
Rename mptcp_attach_dss()
Fix return value if no DSS option is created.
Move setting request_ fields of subflow to MPTCP layer helper
mptcp: Add handling of outgoing MP_JOIN requests Use pm_get_local_id() to get the real local address id.
mptcp: Implement path manager interface commands

 include/net/mptcp.h  |  12 ++--
 net/ipv4/tcp_input.c |   4 +-
 net/mptcp/crypto.c   |  23 +++----
 net/mptcp/options.c  |  95 ++++++++++++++++++++++++++---
 net/mptcp/pm.c       | 141 +++++++++++++++++++++++++++++++++++++++----
 net/mptcp/protocol.c |  22 +++++--
 net/mptcp/protocol.h |  58 ++++++++++++++----
 net/mptcp/subflow.c  |  72 +++++++++++++++++++---
 net/mptcp/token.c    |  89 +++++++++++++++++++++------
 9 files changed, 429 insertions(+), 87 deletions(-)
Signature · 1 line
2.17.2
author
#1 lore raw

PATCH v2 1/10 Extend path manager interface

A little more functionality and some comments clarifying which routines are for a path manager to call and which are callbacks.

squashto: Add path manager interface

Signed-off-by Peter Krystad <peter.krystad(a)linux.intel.com>
---
 net/mptcp/options.c  | 37 +++++++++++++++++--
 net/mptcp/pm.c       | 85 +++++++++++++++++++++++++++++++++++++-------
 net/mptcp/protocol.c |  5 +--
 net/mptcp/protocol.h | 39 +++++++++++++++-----
 4 files changed, 139 insertions(+), 27 deletions(-)
net/mptcp/options.c +34 -3
index 58215f19829a..62a46b75ba62 100644
@@ -411,11 +411,29 @@ static bool mptcp_established_options_addr(struct sock *sk,
 {
 	struct subflow_context *subflow = subflow_ctx(sk);
 	struct mptcp_sock *msk = mptcp_sk(subflow->conn);
+	struct sockaddr_storage saddr;
+	u8 id;
 
-	if (subflow->fourth_ack)
-		return pm_addr_signal(msk, size, remaining, opts);
+	if (!msk)
+		return false;
 
-	return false;
+	if (!msk->pm.fully_established || !msk->addr_signal)
+		return false;
+
+	if (pm_addr_signal(msk, &id, &saddr))
+		return false;
+
+	if (saddr.ss_family == AF_INET && remaining < TCPOLEN_MPTCP_ADD_ADDR)
+		return false;
+
+	opts->suboptions |= OPTION_MPTCP_ADD_ADDR;
+	opts->addr_id = id;
+	opts->addr.s_addr = ((struct sockaddr_in *)&saddr)->sin_addr.s_addr;
+	*size = TCPOLEN_MPTCP_ADD_ADDR;
+
+	msk->addr_signal = 0;
+
+	return true;
 }
 
 bool mptcp_established_options(struct sock *sk, struct sk_buff *skb,
@@ -479,11 +497,20 @@ bool mptcp_synack_options(const struct request_sock *req, unsigned int *size,
 void mptcp_attach_dss(struct sock *sk, struct sk_buff *skb,
 		      struct tcp_options_received *opt_rx)
 {
+	struct subflow_context *subflow = subflow_ctx(sk);
+	struct mptcp_sock *msk = mptcp_sk(subflow->conn);
 	struct mptcp_options_received *mp_opt;
 	struct mptcp_ext *mpext;
 
 	mp_opt = &opt_rx->mptcp;
 
+	if (mp_opt->add_addr && mp_opt->family == MPTCP_ADDR_IPVERSION_4) {
+		if (msk) {
+			pm_add_addr(msk, &mp_opt->addr, mp_opt->addr_id);
+			mp_opt->add_addr = 0;
+		}
+	}
+
 	if (!mp_opt->dss)
 		return;
 
@@ -510,6 +537,10 @@ void mptcp_attach_dss(struct sock *sk, struct sk_buff *skb,
 	}
 
 	mpext->data_fin = mp_opt->data_fin;
+
+	if (msk)
+		pm_fully_established(msk);
+
 }
 
 void mptcp_write_options(__be32 *ptr, struct mptcp_out_options *opts)
net/mptcp/pm.c +72 -13

112 lines not on this page · raw message

net/mptcp/protocol.c +3 -2
index 4d2844bff36f..5501c405c6e0 100644
@@ -663,7 +663,7 @@ 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);
+		pm_new_connection(msk, 1);
 
 		crypto_key_sha1(msk->remote_key, NULL, &ack_seq);
 		msk->write_seq = subflow->idsn + 1;
@@ -798,7 +798,7 @@ 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);
+		pm_new_connection(msk, 0);
 
 		crypto_key_sha1(msk->remote_key, NULL, &ack_seq);
 		msk->write_seq = subflow->idsn + 1;
@@ -1090,6 +1090,7 @@ void __init mptcp_init(void)
 
 	token_init();
 	subflow_init();
+	pm_init();
 
 	if (proto_register(&mptcp_prot, 1) != 0)
 		panic("Failed to register MPTCP proto.\n");
net/mptcp/protocol.h +30 -9
index 4c098acf4170..6e6cf37799ef 100644
@@ -78,15 +78,33 @@ static inline u32 mptcp_option(u8 subopt, u8 len, u8 nib, u8 field)
 		     ((nib & 0xF) << 8) | field);
 }
 
-struct pm_data {
-	u8 addr_id;
-	sa_family_t family;
+struct mptcp_pm_data {
+	u8	local_valid;
+	u8	local_id;
+	sa_family_t local_family;
+	union {
+		struct in_addr local_addr;
+#if IS_ENABLED(CONFIG_IPV6)
+		struct in6_addr local_addr6;
+#endif
+	};
+	u8	remote_valid;
+	u8	remote_id;
+	sa_family_t remote_family;
 	union {
-		struct in_addr addr;
+		struct in_addr remote_addr;
 #if IS_ENABLED(CONFIG_IPV6)
-		struct in6_addr addr6;
+		struct in6_addr remote_addr6;
 #endif
 	};
+	u32	remote_token;
+	u8	server_side : 1,
+		fully_established : 1;
+
+	/* for interim path manager */
+	struct	work_struct addr_work;
+	struct	work_struct subflow_work;
+	u32	token;
 };
 
 /* MPTCP connection sock */
@@ -100,7 +118,7 @@ struct mptcp_sock {
 	u32		token;
 	struct list_head conn_list;
 	struct socket	*subflow; /* outgoing connect/listener/!mp_capable */
-	struct pm_data	pm;
+	struct mptcp_pm_data	pm;
 	u8		addr_signal;
 };
 
@@ -223,7 +241,8 @@ static inline void crypto_key_gen_sha1(u64 *key, u32 *token, u64 *idsn)
 	crypto_key_sha1(*key, token, idsn);
 }
 
-void pm_new_connection(struct mptcp_sock *msk);
+void pm_init(void);
+void pm_new_connection(struct mptcp_sock *msk, int server_side);
 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);
@@ -231,8 +250,10 @@ 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 int *size,
-		    unsigned int remaining, struct mptcp_out_options *opts);
+int pm_addr_signal(struct mptcp_sock *msk, u8 *id,
+		   struct sockaddr_storage *saddr);
+int pm_get_local_id(struct request_sock *req, struct sock *sk,
+		    const struct sk_buff *skb);
 
 static inline struct mptcp_ext *mptcp_get_ext(struct sk_buff *skb)
 {
Signature · 1 line
2.17.2
#2 lore raw

Re: [MPTCP] [PATCH v2 01/10] Extend path manager interface

Quoted 54 lines · Peter Krystad

A little more functionality and some comments clarifying which routines are for a path manager to call and which are callbacks.

squashto: Add path manager interface

Signed-off-by Peter Krystad <peter.krystad(a)linux.intel.com>

---

net/mptcp/options.c  | 37 +++++++++++++++++--
net/mptcp/pm.c       | 85 +++++++++++++++++++++++++++++++++++++-------
net/mptcp/protocol.c |  5 +--
net/mptcp/protocol.h | 39 +++++++++++++++-----
4 files changed, 139 insertions(+), 27 deletions(-)
net/mptcp/options.c +21 -3
index 58215f19829a..62a46b75ba62 100644
@@ -411,11 +411,29 @@ static bool mptcp_established_options_addr(struct sock *sk,
 {
 	struct subflow_context *subflow = subflow_ctx(sk);
 	struct mptcp_sock *msk = mptcp_sk(subflow->conn);
+	struct sockaddr_storage saddr;
+	u8 id;
 
-	if (subflow->fourth_ack)
-		return pm_addr_signal(msk, size, remaining, opts);
+	if (!msk)
+		return false;
 
-	return false;
+	if (!msk->pm.fully_established || !msk->addr_signal)
+		return false;
+
+	if (pm_addr_signal(msk, &id, &saddr))
+		return false;
+
+	if (saddr.ss_family == AF_INET && remaining < TCPOLEN_MPTCP_ADD_ADDR)
+		return false;
+
+	opts->suboptions |= OPTION_MPTCP_ADD_ADDR;
+	opts->addr_id = id;
+	opts->addr.s_addr = ((struct sockaddr_in *)&saddr)->sin_addr.s_addr;
+	*size = TCPOLEN_MPTCP_ADD_ADDR;
+
+	msk->addr_signal = 0;
+
+	return true;
 }
 
 bool mptcp_established_options(struct sock *sk, struct sk_buff *skb,
@@ -479,11 +497,20 @@ bool mptcp_synack_options(const struct request_sock *req, unsigned int *size,
 void mptcp_attach_dss(struct sock *sk, struct sk_buff *skb,
 		      struct tcp_options_received *opt_rx)

net/mptcp/options.c bool mptcp_synack_options(const struct request_sock *req, unsigned int *size, · line 508

Quoted 10 lines
net/mptcp/options.c +4 -0
 {
+	struct subflow_context *subflow = subflow_ctx(sk);
+	struct mptcp_sock *msk = mptcp_sk(subflow->conn);
 	struct mptcp_options_received *mp_opt;
 	struct mptcp_ext *mpext;
 
 	mp_opt = &opt_rx->mptcp;
 
+	if (mp_opt->add_addr && mp_opt->family == MPTCP_ADDR_IPVERSION_4) {
+		if (msk) {

Minor: could add '&& msk' to the previous line instead of nesting this if statement.

Mat

Quoted 251 lines
net/mptcp/options.c +9 -0
+			pm_add_addr(msk, &mp_opt->addr, mp_opt->addr_id);
+			mp_opt->add_addr = 0;
+		}
+	}
+
 	if (!mp_opt->dss)
 		return;
 
@@ -510,6 +537,10 @@ void mptcp_attach_dss(struct sock *sk, struct sk_buff *skb,
 	}
 
 	mpext->data_fin = mp_opt->data_fin;
+
+	if (msk)
+		pm_fully_established(msk);
+
 }
 
 void mptcp_write_options(__be32 *ptr, struct mptcp_out_options *opts)
net/mptcp/pm.c +72 -13
index 9e9c681a4544..b51cab3809c9 100644
@@ -8,14 +8,43 @@
 #include <net/mptcp.h>
 #include "protocol.h"
 
-void pm_new_connection(struct mptcp_sock *msk)
+/* path manager command handlers */
+
+int pm_announce_addr(u32 token, sa_family_t family, u8 local_id,
+		     struct in_addr *addr)
+{
+	return -ENOTSUPP;
+}
+
+int pm_remove_addr(u32 token, u8 local_id)
+{
+	return -ENOTSUPP;
+}
+
+int pm_create_subflow(u32 token, u8 remote_id)
+{
+	return -ENOTSUPP;
+}
+
+int pm_remove_subflow(u32 token, u8 remote_id)
+{
+	return -ENOTSUPP;
+}
+
+/* path manager event handlers */
+
+void pm_new_connection(struct mptcp_sock *msk, int server_side)
 {
 	pr_debug("msk=%p", msk);
+
+	msk->pm.server_side = server_side;
 }
 
 void pm_fully_established(struct mptcp_sock *msk)
 {
 	pr_debug("msk=%p", msk);
+
+	msk->pm.fully_established = 1;
 }
 
 void pm_connection_closed(struct mptcp_sock *msk)
@@ -35,7 +64,13 @@ 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)
 {
-	pr_debug("msk=%p", msk);
+	pr_debug("msk=%p, addr=%x, remote_id=%d", msk, addr->s_addr, id);
+
+	msk->pm.remote_valid = 1;
+	msk->pm.remote_token = msk->token;
+	msk->pm.remote_addr.s_addr = addr->s_addr;
+	msk->pm.remote_id = id;
+	msk->pm.remote_family = AF_INET;
 }
 
 void pm_add_addr6(struct mptcp_sock *msk, const struct in6_addr *addr, u8 id)
@@ -48,19 +83,43 @@ void pm_rm_addr(struct mptcp_sock *msk, u8 id)
 	pr_debug("msk=%p", msk);
 }
 
-bool pm_addr_signal(struct mptcp_sock *msk, unsigned int *size,
-		    unsigned int remaining, struct mptcp_out_options *opts)
+/* path manager helpers */
+
+int pm_addr_signal(struct mptcp_sock *msk, u8 *id,
+		   struct sockaddr_storage *saddr)
 {
-	if (!msk || !msk->addr_signal)
-		return false;
+	struct sockaddr_in *addr = (struct sockaddr_in *)saddr;
 
-	if (msk->pm.family == AF_INET && remaining < TCPOLEN_MPTCP_ADD_ADDR)
-		return false;
+	if (!msk->pm.local_valid)
+		return -1;
 
-	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;
+	if (msk->pm.local_family != AF_INET)
+		return -1;
 
-	return true;
+	*id = msk->pm.local_id;
+	addr->sin_family = msk->pm.local_family;
+	addr->sin_addr.s_addr = msk->pm.local_addr.s_addr;
+
+	return 0;
+}
+
+int pm_get_local_id(struct request_sock *req, struct sock *sk,
+		    const struct sk_buff *skb)
+{
+	struct subflow_request_sock *subflow_req = subflow_rsk(req);
+	struct mptcp_sock *msk = mptcp_sk(sk);
+
+	if (!msk->pm.local_valid)
+		return -1;
+
+	/* @@ check if address actually matches... */
+
+	pr_debug("msk=%p, addr_id=%d", msk, msk->pm.local_id);
+	subflow_req->local_id = msk->pm.local_id;
+
+	return 0;
+}
+
+void pm_init(void)
+{
 }
net/mptcp/protocol.c +3 -2
index 4d2844bff36f..5501c405c6e0 100644
@@ -663,7 +663,7 @@ 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);
+		pm_new_connection(msk, 1);
 
 		crypto_key_sha1(msk->remote_key, NULL, &ack_seq);
 		msk->write_seq = subflow->idsn + 1;
@@ -798,7 +798,7 @@ 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);
+		pm_new_connection(msk, 0);
 
 		crypto_key_sha1(msk->remote_key, NULL, &ack_seq);
 		msk->write_seq = subflow->idsn + 1;
@@ -1090,6 +1090,7 @@ void __init mptcp_init(void)
 
 	token_init();
 	subflow_init();
+	pm_init();
 
 	if (proto_register(&mptcp_prot, 1) != 0)
 		panic("Failed to register MPTCP proto.\n");
net/mptcp/protocol.h +30 -9
index 4c098acf4170..6e6cf37799ef 100644
@@ -78,15 +78,33 @@ static inline u32 mptcp_option(u8 subopt, u8 len, u8 nib, u8 field)
 		     ((nib & 0xF) << 8) | field);
 }
 
-struct pm_data {
-	u8 addr_id;
-	sa_family_t family;
+struct mptcp_pm_data {
+	u8	local_valid;
+	u8	local_id;
+	sa_family_t local_family;
+	union {
+		struct in_addr local_addr;
+#if IS_ENABLED(CONFIG_IPV6)
+		struct in6_addr local_addr6;
+#endif
+	};
+	u8	remote_valid;
+	u8	remote_id;
+	sa_family_t remote_family;
 	union {
-		struct in_addr addr;
+		struct in_addr remote_addr;
 #if IS_ENABLED(CONFIG_IPV6)
-		struct in6_addr addr6;
+		struct in6_addr remote_addr6;
 #endif
 	};
+	u32	remote_token;
+	u8	server_side : 1,
+		fully_established : 1;
+
+	/* for interim path manager */
+	struct	work_struct addr_work;
+	struct	work_struct subflow_work;
+	u32	token;
 };
 
 /* MPTCP connection sock */
@@ -100,7 +118,7 @@ struct mptcp_sock {
 	u32		token;
 	struct list_head conn_list;
 	struct socket	*subflow; /* outgoing connect/listener/!mp_capable */
-	struct pm_data	pm;
+	struct mptcp_pm_data	pm;
 	u8		addr_signal;
 };
 
@@ -223,7 +241,8 @@ static inline void crypto_key_gen_sha1(u64 *key, u32 *token, u64 *idsn)
 	crypto_key_sha1(*key, token, idsn);
 }
 
-void pm_new_connection(struct mptcp_sock *msk);
+void pm_init(void);
+void pm_new_connection(struct mptcp_sock *msk, int server_side);
 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);
@@ -231,8 +250,10 @@ 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 int *size,
-		    unsigned int remaining, struct mptcp_out_options *opts);
+int pm_addr_signal(struct mptcp_sock *msk, u8 *id,
+		   struct sockaddr_storage *saddr);
+int pm_get_local_id(struct request_sock *req, struct sock *sk,
+		    const struct sk_buff *skb);
 
 static inline struct mptcp_ext *mptcp_get_ext(struct sk_buff *skb)
 {
Signature · 6 lines
2.17.2

_______________________________________________
mptcp mailing list
mptcp(a)lists.01.org
https://lists.01.org/mailman/listinfo/mptcp

--
Mat Martineau
Intel

author
#3 lore raw

Re: [MPTCP] [PATCH v2 01/10] Extend path manager interface

Quoted 62 lines · Mat Martineau
Quoted 60 lines · Peter Krystad

A little more functionality and some comments clarifying which routines are for a path manager to call and which are callbacks.

squashto: Add path manager interface

Signed-off-by Peter Krystad <peter.krystad(a)linux.intel.com>

---

net/mptcp/options.c  | 37 +++++++++++++++++--
net/mptcp/pm.c       | 85 +++++++++++++++++++++++++++++++++++++-------
net/mptcp/protocol.c |  5 +--
net/mptcp/protocol.h | 39 +++++++++++++++-----
4 files changed, 139 insertions(+), 27 deletions(-)
net/mptcp/options.c +23 -3
index 58215f19829a..62a46b75ba62 100644
@@ -411,11 +411,29 @@ static bool mptcp_established_options_addr(struct sock *sk,
 {
 	struct subflow_context *subflow = subflow_ctx(sk);
 	struct mptcp_sock *msk = mptcp_sk(subflow->conn);
+	struct sockaddr_storage saddr;
+	u8 id;
 
-	if (subflow->fourth_ack)
-		return pm_addr_signal(msk, size, remaining, opts);
+	if (!msk)
+		return false;
 
-	return false;
+	if (!msk->pm.fully_established || !msk->addr_signal)
+		return false;
+
+	if (pm_addr_signal(msk, &id, &saddr))
+		return false;
+
+	if (saddr.ss_family == AF_INET && remaining < TCPOLEN_MPTCP_ADD_ADDR)
+		return false;
+
+	opts->suboptions |= OPTION_MPTCP_ADD_ADDR;
+	opts->addr_id = id;
+	opts->addr.s_addr = ((struct sockaddr_in *)&saddr)->sin_addr.s_addr;
+	*size = TCPOLEN_MPTCP_ADD_ADDR;
+
+	msk->addr_signal = 0;
+
+	return true;
 }
 
 bool mptcp_established_options(struct sock *sk, struct sk_buff *skb,
@@ -479,11 +497,20 @@ bool mptcp_synack_options(const struct request_sock *req, unsigned int *size,
 void mptcp_attach_dss(struct sock *sk, struct sk_buff *skb,
 		      struct tcp_options_received *opt_rx)
 {
+	struct subflow_context *subflow = subflow_ctx(sk);
+	struct mptcp_sock *msk = mptcp_sk(subflow->conn);
 	struct mptcp_options_received *mp_opt;
 	struct mptcp_ext *mpext;
 
Quoted 7 lines

net/mptcp/options.c bool mptcp_synack_options(const struct request_sock *req, unsigned int *size, · line 508

Quoted 4 lines
net/mptcp/options.c +2 -0
 	mp_opt = &opt_rx->mptcp;
 
+	if (mp_opt->add_addr && mp_opt->family == MPTCP_ADDR_IPVERSION_4) {
+		if (msk) {

Minor: could add '&& msk' to the previous line instead of nesting this if statement.

Sure. In the interest of fill disclosure this line marks a condition when running against the multipath.org implementation, which includes the ADD_ADDR option in a duplicate ACK after the 3whs. On the server side this ACK may be processed before 'subflow->conn' is set in mptcp_accept(), and the ADD_ADDR option is dropped. Since we are not expecting to initiate new subflows from the server side it seems OK.

Peter.

Quoted 260 lines

Mat

Quoted 251 lines
net/mptcp/options.c +9 -0
+			pm_add_addr(msk, &mp_opt->addr, mp_opt->addr_id);
+			mp_opt->add_addr = 0;
+		}
+	}
+
 	if (!mp_opt->dss)
 		return;
 
@@ -510,6 +537,10 @@ void mptcp_attach_dss(struct sock *sk, struct sk_buff *skb,
 	}
 
 	mpext->data_fin = mp_opt->data_fin;
+
+	if (msk)
+		pm_fully_established(msk);
+
 }
 
 void mptcp_write_options(__be32 *ptr, struct mptcp_out_options *opts)
net/mptcp/pm.c +72 -13
index 9e9c681a4544..b51cab3809c9 100644
@@ -8,14 +8,43 @@
 #include <net/mptcp.h>
 #include "protocol.h"
 
-void pm_new_connection(struct mptcp_sock *msk)
+/* path manager command handlers */
+
+int pm_announce_addr(u32 token, sa_family_t family, u8 local_id,
+		     struct in_addr *addr)
+{
+	return -ENOTSUPP;
+}
+
+int pm_remove_addr(u32 token, u8 local_id)
+{
+	return -ENOTSUPP;
+}
+
+int pm_create_subflow(u32 token, u8 remote_id)
+{
+	return -ENOTSUPP;
+}
+
+int pm_remove_subflow(u32 token, u8 remote_id)
+{
+	return -ENOTSUPP;
+}
+
+/* path manager event handlers */
+
+void pm_new_connection(struct mptcp_sock *msk, int server_side)
 {
 	pr_debug("msk=%p", msk);
+
+	msk->pm.server_side = server_side;
 }
 
 void pm_fully_established(struct mptcp_sock *msk)
 {
 	pr_debug("msk=%p", msk);
+
+	msk->pm.fully_established = 1;
 }
 
 void pm_connection_closed(struct mptcp_sock *msk)
@@ -35,7 +64,13 @@ 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)
 {
-	pr_debug("msk=%p", msk);
+	pr_debug("msk=%p, addr=%x, remote_id=%d", msk, addr->s_addr, id);
+
+	msk->pm.remote_valid = 1;
+	msk->pm.remote_token = msk->token;
+	msk->pm.remote_addr.s_addr = addr->s_addr;
+	msk->pm.remote_id = id;
+	msk->pm.remote_family = AF_INET;
 }
 
 void pm_add_addr6(struct mptcp_sock *msk, const struct in6_addr *addr, u8 id)
@@ -48,19 +83,43 @@ void pm_rm_addr(struct mptcp_sock *msk, u8 id)
 	pr_debug("msk=%p", msk);
 }
 
-bool pm_addr_signal(struct mptcp_sock *msk, unsigned int *size,
-		    unsigned int remaining, struct mptcp_out_options *opts)
+/* path manager helpers */
+
+int pm_addr_signal(struct mptcp_sock *msk, u8 *id,
+		   struct sockaddr_storage *saddr)
 {
-	if (!msk || !msk->addr_signal)
-		return false;
+	struct sockaddr_in *addr = (struct sockaddr_in *)saddr;
 
-	if (msk->pm.family == AF_INET && remaining < TCPOLEN_MPTCP_ADD_ADDR)
-		return false;
+	if (!msk->pm.local_valid)
+		return -1;
 
-	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;
+	if (msk->pm.local_family != AF_INET)
+		return -1;
 
-	return true;
+	*id = msk->pm.local_id;
+	addr->sin_family = msk->pm.local_family;
+	addr->sin_addr.s_addr = msk->pm.local_addr.s_addr;
+
+	return 0;
+}
+
+int pm_get_local_id(struct request_sock *req, struct sock *sk,
+		    const struct sk_buff *skb)
+{
+	struct subflow_request_sock *subflow_req = subflow_rsk(req);
+	struct mptcp_sock *msk = mptcp_sk(sk);
+
+	if (!msk->pm.local_valid)
+		return -1;
+
+	/* @@ check if address actually matches... */
+
+	pr_debug("msk=%p, addr_id=%d", msk, msk->pm.local_id);
+	subflow_req->local_id = msk->pm.local_id;
+
+	return 0;
+}
+
+void pm_init(void)
+{
 }
net/mptcp/protocol.c +3 -2
index 4d2844bff36f..5501c405c6e0 100644
@@ -663,7 +663,7 @@ 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);
+		pm_new_connection(msk, 1);
 
 		crypto_key_sha1(msk->remote_key, NULL, &ack_seq);
 		msk->write_seq = subflow->idsn + 1;
@@ -798,7 +798,7 @@ 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);
+		pm_new_connection(msk, 0);
 
 		crypto_key_sha1(msk->remote_key, NULL, &ack_seq);
 		msk->write_seq = subflow->idsn + 1;
@@ -1090,6 +1090,7 @@ void __init mptcp_init(void)
 
 	token_init();
 	subflow_init();
+	pm_init();
 
 	if (proto_register(&mptcp_prot, 1) != 0)
 		panic("Failed to register MPTCP proto.\n");
net/mptcp/protocol.h +30 -9
index 4c098acf4170..6e6cf37799ef 100644
@@ -78,15 +78,33 @@ static inline u32 mptcp_option(u8 subopt, u8 len, u8 nib, u8 field)
 		     ((nib & 0xF) << 8) | field);
 }
 
-struct pm_data {
-	u8 addr_id;
-	sa_family_t family;
+struct mptcp_pm_data {
+	u8	local_valid;
+	u8	local_id;
+	sa_family_t local_family;
+	union {
+		struct in_addr local_addr;
+#if IS_ENABLED(CONFIG_IPV6)
+		struct in6_addr local_addr6;
+#endif
+	};
+	u8	remote_valid;
+	u8	remote_id;
+	sa_family_t remote_family;
 	union {
-		struct in_addr addr;
+		struct in_addr remote_addr;
 #if IS_ENABLED(CONFIG_IPV6)
-		struct in6_addr addr6;
+		struct in6_addr remote_addr6;
 #endif
 	};
+	u32	remote_token;
+	u8	server_side : 1,
+		fully_established : 1;
+
+	/* for interim path manager */
+	struct	work_struct addr_work;
+	struct	work_struct subflow_work;
+	u32	token;
 };
 
 /* MPTCP connection sock */
@@ -100,7 +118,7 @@ struct mptcp_sock {
 	u32		token;
 	struct list_head conn_list;
 	struct socket	*subflow; /* outgoing connect/listener/!mp_capable */
-	struct pm_data	pm;
+	struct mptcp_pm_data	pm;
 	u8		addr_signal;
 };
 
@@ -223,7 +241,8 @@ static inline void crypto_key_gen_sha1(u64 *key, u32 *token, u64 *idsn)
 	crypto_key_sha1(*key, token, idsn);
 }
 
-void pm_new_connection(struct mptcp_sock *msk);
+void pm_init(void);
+void pm_new_connection(struct mptcp_sock *msk, int server_side);
 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);
@@ -231,8 +250,10 @@ 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 int *size,
-		    unsigned int remaining, struct mptcp_out_options *opts);
+int pm_addr_signal(struct mptcp_sock *msk, u8 *id,
+		   struct sockaddr_storage *saddr);
+int pm_get_local_id(struct request_sock *req, struct sock *sk,
+		    const struct sk_buff *skb);
 
 static inline struct mptcp_ext *mptcp_get_ext(struct sk_buff *skb)
 {
Signature · 6 lines
2.17.2

_______________________________________________
mptcp mailing list
mptcp(a)lists.01.org
https://lists.01.org/mailman/listinfo/mptcp

--
Mat Martineau
Intel

author
#4 lore raw

PATCH v2 2/10 Fix locking in mptcp_finish_join.

In reply to Peter Krystad

Lock was being taken on the subflow sock, not mptcp_sock.

squashto: Add handling of incoming MP_JOIN requests

Signed-off-by Peter Krystad <peter.krystad(a)linux.intel.com>
---
 net/mptcp/protocol.c | 9 +++++----
 net/mptcp/protocol.h | 2 +-
 net/mptcp/subflow.c  | 2 +-
 3 files changed, 7 insertions(+), 6 deletions(-)
net/mptcp/protocol.c +5 -4
index 5501c405c6e0..8a841d489b52 100644
@@ -816,18 +816,19 @@ 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)
+void mptcp_finish_join(struct sock *sk)
 {
 	struct subflow_context *subflow = subflow_ctx(sk);
-	struct mptcp_sock *msk = mptcp_sk(conn);
+	struct mptcp_sock *msk = mptcp_sk(subflow->conn);
 
 	pr_debug("msk=%p, subflow=%p", msk, subflow);
 
 	local_bh_disable();
-	bh_lock_sock_nested(sk);
+	bh_lock_sock_nested(subflow->conn);
 	list_add_tail(&subflow->node, &msk->conn_list);
-	bh_unlock_sock(sk);
+	bh_unlock_sock(subflow->conn);
 	local_bh_enable();
+	inet_sk_state_store(sk, TCP_ESTABLISHED);
 }
 
 bool mptcp_sk_is_subflow(const struct sock *sk)
net/mptcp/protocol.h +1 -1
index 6e6cf37799ef..90e11d28fad8 100644
@@ -211,7 +211,7 @@ 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 mptcp_finish_join(struct sock *sk);
 
 void token_init(void);
 void token_new_request(struct request_sock *req, const struct sk_buff *skb);
net/mptcp/subflow.c +1 -1
index d91d817b8779..9d91014c0d1b 100644
@@ -165,7 +165,7 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk,
 			if (token_new_join(child))
 				goto close_child;
 			else
-				mptcp_finish_join(ctx->conn, child);
+				mptcp_finish_join(child);
 		}
 	}
 
Signature · 1 line
2.17.2
#5 lore raw

Re: [MPTCP] [PATCH v2 02/10] Fix locking in mptcp_finish_join.

Quoted 24 lines · Peter Krystad

Lock was being taken on the subflow sock, not mptcp_sock.

squashto: Add handling of incoming MP_JOIN requests

Signed-off-by Peter Krystad <peter.krystad(a)linux.intel.com>

---

net/mptcp/protocol.c | 9 +++++----
net/mptcp/protocol.h | 2 +-
net/mptcp/subflow.c  | 2 +-
3 files changed, 7 insertions(+), 6 deletions(-)
net/mptcp/protocol.c +1 -2
index 5501c405c6e0..8a841d489b52 100644
@@ -816,18 +816,19 @@ 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)
+void mptcp_finish_join(struct sock *sk)
 {
 	struct subflow_context *subflow = subflow_ctx(sk);
-	struct mptcp_sock *msk = mptcp_sk(conn);

net/mptcp/protocol.c void mptcp_finish_connect(struct sock *sk, int mp_capable) · line 829

Quoted 10 lines
net/mptcp/protocol.c +3 -2
+	struct mptcp_sock *msk = mptcp_sk(subflow->conn);
 
 	pr_debug("msk=%p, subflow=%p", msk, subflow);
 
 	local_bh_disable();
-	bh_lock_sock_nested(sk);
+	bh_lock_sock_nested(subflow->conn);
 	list_add_tail(&subflow->node, &msk->conn_list);
-	bh_unlock_sock(sk);
+	bh_unlock_sock(subflow->conn);

This is the sort of locking I'm getting deadlock warnings for in my mptcp-level data_ready function (patch that tries to fix the MPTCP socket wakeup problem). The selftest didn't trigger the lock warning for me, but it doesn't do any joins yet! I didn't get a chance to test against the multipath-tcp.org kernel yet.

This function reverses the order of lock acquisition (locks the mptcp socket second), so it could deadlock. How we solve this is part of our larger locking discussion so I don't have a solution to give here :)

Mat

Quoted 39 lines
net/mptcp/protocol.c +1 -0
 	local_bh_enable();
+	inet_sk_state_store(sk, TCP_ESTABLISHED);
 }
 
 bool mptcp_sk_is_subflow(const struct sock *sk)
net/mptcp/protocol.h +1 -1
index 6e6cf37799ef..90e11d28fad8 100644
@@ -211,7 +211,7 @@ 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 mptcp_finish_join(struct sock *sk);
 
 void token_init(void);
 void token_new_request(struct request_sock *req, const struct sk_buff *skb);
net/mptcp/subflow.c +1 -1
index d91d817b8779..9d91014c0d1b 100644
@@ -165,7 +165,7 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk,
 			if (token_new_join(child))
 				goto close_child;
 			else
-				mptcp_finish_join(ctx->conn, child);
+				mptcp_finish_join(child);
 		}
 	}
 
Signature · 6 lines
2.17.2

_______________________________________________
mptcp mailing list
mptcp(a)lists.01.org
https://lists.01.org/mailman/listinfo/mptcp

--
Mat Martineau
Intel

#6 lore raw

Re: [MPTCP] [PATCH v2 02/10] Fix locking in mptcp_finish_join.

Quoted 30 lines · Mat Martineau
Quoted 28 lines · Peter Krystad

Lock was being taken on the subflow sock, not mptcp_sock.

squashto: Add handling of incoming MP_JOIN requests

Signed-off-by Peter Krystad <peter.krystad(a)linux.intel.com>

---

net/mptcp/protocol.c | 9 +++++----
net/mptcp/protocol.h | 2 +-
net/mptcp/subflow.c  | 2 +-
3 files changed, 7 insertions(+), 6 deletions(-)
net/mptcp/protocol.c +2 -2
index 5501c405c6e0..8a841d489b52 100644
@@ -816,18 +816,19 @@ 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)
+void mptcp_finish_join(struct sock *sk)
 {
 	struct subflow_context *subflow = subflow_ctx(sk);
-	struct mptcp_sock *msk = mptcp_sk(conn);
+	struct mptcp_sock *msk = mptcp_sk(subflow->conn);
 
 	pr_debug("msk=%p, subflow=%p", msk, subflow);
 
Quoted 12 lines

net/mptcp/protocol.c void mptcp_finish_connect(struct sock *sk, int mp_capable) · line 829

Quoted 6 lines
net/mptcp/protocol.c +2 -2
 	local_bh_disable();
-	bh_lock_sock_nested(sk);
+	bh_lock_sock_nested(subflow->conn);
 	list_add_tail(&subflow->node, &msk->conn_list);
-	bh_unlock_sock(sk);
+	bh_unlock_sock(subflow->conn);

This is the sort of locking I'm getting deadlock warnings for in my mptcp-level data_ready function (patch that tries to fix the MPTCP socket wakeup problem). The selftest didn't trigger the lock warning for me, but it doesn't do any joins yet! I didn't get a chance to test against the multipath-tcp.org kernel yet.

I *think* this specific inversion in lock acquisition order should be safe, for the same reason the one mptcp_finish_connect().

Generally speaking each inversion in lock acquisition order done to just insert the subflow socket into the connected socket list should be safe.

Quoted 3 lines

This function reverses the order of lock acquisition (locks the mptcp socket second), so it could deadlock. How we solve this is part of our larger locking discussion so I don't have a solution to give here :)

Lately I'm thinking that using a new, third spinlock to protect connection level shared datas - among them the connection list - could simplify the code a bit.

But that would be for later work, I think this patch is good as is.

/P

author
#7 lore raw

PATCH v2 3/10 Fix parsing MP_JOIN third ACK.

In reply to Peter Krystad

There is a reserved byte of zero's in there.

squashto: Add handling of incoming MP_JOIN requests

Signed-off-by Peter Krystad <peter.krystad(a)linux.intel.com>
---
 net/mptcp/options.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/mptcp/options.c +1 -1
index 62a46b75ba62..cafc51dcbfb2 100644
@@ -92,7 +92,7 @@ void mptcp_parse_option(const unsigned char *ptr, int opsize,
 				 mp_opt->backup, mp_opt->join_id,
 				 mp_opt->thmac, mp_opt->nonce);
 		} else if (opsize == TCPOLEN_MPTCP_MPJ_ACK) {
-			ptr++;
+			ptr += 2;
 			memcpy(mp_opt->hmac, ptr, MPTCPOPT_HMAC_LEN);
 			pr_debug("MP_JOIN hmac");
 		} else {
Signature · 1 line
2.17.2
author
#8 lore raw

PATCH v2 4/10 Re-factor and fixes for crypto_hmac_sha1()

In reply to Peter Krystad

Re-factor to use parameters specific to MPTCP use case similar to crypto_key_sha1() and get rid of var args. Also fix endianness issues.

squash to: Add key generation and token tree
and: Add handling of incoming MP_JOIN requests

Signed-off-by Peter Krystad <peter.krystad(a)linux.intel.com>
---
 net/mptcp/crypto.c   | 23 +++++++++--------------
 net/mptcp/protocol.h |  4 ++--
 net/mptcp/token.c    | 19 ++++++++-----------
 3 files changed, 19 insertions(+), 27 deletions(-)
net/mptcp/crypto.c +9 -14
index 5b764798c536..8b67b11e626c 100644
@@ -51,23 +51,23 @@ void crypto_key_sha1(u64 key, u32 *token, u64 *idsn)
 		*idsn = ((u64)mptcp_hashed_key[3] << 32) + mptcp_hashed_key[4];
 }
 
-void crypto_hmac_sha1(u64 key1, u64 key2, u32 *hash_out,
-		      int arg_num, ...)
+void crypto_hmac_sha1(u64 key1, u64 key2, u32 nonce1, u32 nonce2, u32 *hash_out)
 {
 	u32 workspace[SHA_WORKSPACE_WORDS];
 	u8 input[128]; /* 2 512-bit blocks */
 	int i;
 	int index;
-	int length;
-	u8 *msg;
-	va_list list;
 	u8 key_1[8];
 	u8 key_2[8];
+	u8 nonce_1[4];
+	u8 nonce_2[4];
 
 	memset(workspace, 0, sizeof(workspace));
 
 	put_unaligned_be64(key1, key_1);
 	put_unaligned_be64(key2, key_2);
+	put_unaligned_be32(nonce1, nonce_1);
+	put_unaligned_be32(nonce2, nonce_2);
 
 	/* Generate key xored with ipad */
 	memset(input, 0x36, 64);
@@ -76,16 +76,11 @@ void crypto_hmac_sha1(u64 key1, u64 key2, u32 *hash_out,
 	for (i = 0; i < 8; i++)
 		input[i + 8] ^= key_2[i];
 
-	va_start(list, arg_num);
 	index = 64;
-	for (i = 0; i < arg_num; i++) {
-		length = va_arg(list, int);
-		msg = va_arg(list, u8 *);
-		WARN_ON(index + length > 125); /* Message is too long */
-		memcpy(&input[index], msg, length);
-		index += length;
-	}
-	va_end(list);
+	memcpy(&input[index], nonce_1, 4);
+	index = 68;
+	memcpy(&input[index], nonce_2, 4);
+	index = 72;
 
 	input[index] = 0x80; /* Padding: First bit after message = 1 */
 	memset(&input[index + 1], 0, (126 - index));
net/mptcp/protocol.h +2 -2
index 90e11d28fad8..591cebcf1bfa 100644
@@ -227,8 +227,6 @@ void token_release(u32 token);
 void token_destroy(u32 token);
 
 void crypto_key_sha1(u64 key, u32 *token, u64 *idsn);
-void crypto_hmac_sha1(u64 key1, u64 key2, u32 *hash_out, int arg_num, ...);
-
 static inline void crypto_key_gen_sha1(u64 *key, u32 *token, u64 *idsn)
 {
 	/* we might consider a faster version that computes the key as a
@@ -240,6 +238,8 @@ static inline void crypto_key_gen_sha1(u64 *key, u32 *token, u64 *idsn)
 	get_random_bytes(key, sizeof(u64));
 	crypto_key_sha1(*key, token, idsn);
 }
+void crypto_hmac_sha1(u64 key1, u64 key2, u32 nonce1, u32 nonce2,
+		      u32 *hash_out);
 
 void pm_init(void);
 void pm_new_connection(struct mptcp_sock *msk, int server_side);
net/mptcp/token.c +8 -11
index e5e0c9689e3a..ef03ef19af98 100644
@@ -84,12 +84,11 @@ static void new_req_join(struct request_sock *req, struct sock *sk,
 	u8 hmac[MPTCPOPT_HMAC_LEN];
 
 	get_random_bytes(&subflow_req->local_nonce, sizeof(u32));
-	crypto_hmac_sha1(msk->local_key,
-			 msk->remote_key,
-			 (u32 *)hmac, 2,
-			 4, (u8 *)&subflow_req->local_nonce,
-			 4, (u8 *)&subflow_req->remote_nonce);
-	subflow_req->thmac = *(u64 *)hmac;
+	crypto_hmac_sha1(msk->local_key, msk->remote_key,
+			 subflow_req->local_nonce, subflow_req->remote_nonce,
+			 (u32 *)hmac);
+
+	subflow_req->thmac = get_unaligned_be64(hmac);
 	pr_debug("local_nonce=%u, thmac=%llu", subflow_req->local_nonce,
 		 subflow_req->thmac);
 }
@@ -101,11 +100,9 @@ static int new_join_valid(struct request_sock *req, struct sock *sk,
 	struct mptcp_sock *msk = mptcp_sk(sk);
 	u8 hmac[MPTCPOPT_HMAC_LEN];
 
-	crypto_hmac_sha1(msk->remote_key,
-			 msk->local_key,
-			 (u32 *)hmac, 2,
-			 4, (u8 *)&subflow_req->remote_nonce,
-			 4, (u8 *)&subflow_req->local_nonce);
+	crypto_hmac_sha1(msk->remote_key, msk->local_key,
+			 subflow_req->remote_nonce, subflow_req->local_nonce,
+			 (u32 *)hmac);
 
 	return memcmp(hmac, (char *)rx_opt->mptcp.hmac, MPTCPOPT_HMAC_LEN);
 }
Signature · 1 line
2.17.2
author
#9 lore raw

PATCH v2 5/10 Rename mptcp_attach_dss()

In reply to Peter Krystad

Other incoming MPTCP options will be handled in this routine.

squashto: Implement MPTCP receive path

Signed-off-by Peter Krystad <peter.krystad(a)linux.intel.com>
---
 include/net/mptcp.h  | 10 +++++-----
 net/ipv4/tcp_input.c |  4 ++--
 net/mptcp/options.c  |  4 ++--
 3 files changed, 9 insertions(+), 9 deletions(-)
include/net/mptcp.h +5 -5
index 6cd650838ddf..bb2dd193c0c5 100644
@@ -68,9 +68,8 @@ bool mptcp_synack_options(const struct request_sock *req, unsigned int *size,
 bool mptcp_established_options(struct sock *sk, struct sk_buff *skb,
 			       unsigned int *size, unsigned int remaining,
 			       struct mptcp_out_options *opts);
-
-void mptcp_attach_dss(struct sock *sk, struct sk_buff *skb,
-		      struct tcp_options_received *opt_rx);
+void mptcp_incoming_options(struct sock *sk, struct sk_buff *skb,
+			    struct tcp_options_received *opt_rx);
 
 static inline bool mptcp_skb_ext_exist(const struct sk_buff *skb)
 {
@@ -128,8 +127,9 @@ static inline bool mptcp_established_options(struct sock *sk,
 	return false;
 }
 
-static inline void mptcp_attach_dss(struct sock *sk, struct sk_buff *skb,
-				    struct tcp_options_received *opt_rx)
+static inline void mptcp_incoming_options(struct sock *sk,
+					  struct sk_buff *skb,
+					  struct tcp_options_received *opt_rx)
 {
 }
 
net/ipv4/tcp_input.c +2 -2
index b92985b4762c..ca2fea882281 100644
@@ -5668,9 +5668,9 @@ void tcp_rcv_established(struct sock *sk, struct sk_buff *skb)
 	/* Process urgent data. */
 	tcp_urg(sk, skb, th);
 
-	/* Prepare MPTCP sequence data */
+	/* Process MPTCP options */
 	if (sk_is_mptcp(sk))
-		mptcp_attach_dss(sk, skb, &tp->rx_opt);
+		mptcp_incoming_options(sk, skb, &tp->rx_opt);
 
 	/* step 7: process the segment text */
 	tcp_data_queue(sk, skb);
net/mptcp/options.c +2 -2
index cafc51dcbfb2..fbd53b9fa28f 100644
@@ -494,8 +494,8 @@ bool mptcp_synack_options(const struct request_sock *req, unsigned int *size,
 	return false;
 }
 
-void mptcp_attach_dss(struct sock *sk, struct sk_buff *skb,
-		      struct tcp_options_received *opt_rx)
+void mptcp_incoming_options(struct sock *sk, struct sk_buff *skb,
+			    struct tcp_options_received *opt_rx)
 {
 	struct subflow_context *subflow = subflow_ctx(sk);
 	struct mptcp_sock *msk = mptcp_sk(subflow->conn);
Signature · 1 line
2.17.2
author
#10 lore raw

PATCH v2 6/10 Fix return value if no DSS option is created.

In reply to Peter Krystad

Strictly speaking mptcp_established_options_dss() should return false if no DSS option is created.

squashto: Write MPTCP DSS headers to outgoing data packets

Signed-off-by Peter Krystad <peter.krystad(a)linux.intel.com>
---
 net/mptcp/options.c | 3 +++
 1 file changed, 3 insertions(+)
net/mptcp/options.c +3 -0
index fbd53b9fa28f..848d761b2ac7 100644
@@ -400,6 +400,9 @@ static bool mptcp_established_options_dss(struct sock *sk, struct sk_buff *skb,
 		WARN(1, "MPTCP: Ack dropped");
 	}
 
+	if (!dss_size)
+		return false;
+
 	*size = ALIGN(dss_size, 4);
 	return true;
 }
Signature · 1 line
2.17.2
author
#11 lore raw

PATCH v2 7/10 Move setting request_ fields of subflow to MPTCP layer helper

In reply to Peter Krystad

For secondary subflows different request_ fields will be added that will be set differently based on subflow type (initial vs secondary).

squashto: Associate MPTCP context with TCP socket

Signed-off-by Peter Krystad <peter.krystad(a)linux.intel.com>
---
 net/mptcp/protocol.c | 6 ++++++
 net/mptcp/protocol.h | 2 +-
 net/mptcp/subflow.c  | 7 ++-----
 3 files changed, 9 insertions(+), 6 deletions(-)
net/mptcp/protocol.c +6 -0
index 8a841d489b52..4d4a9c3d25c4 100644
@@ -860,6 +860,7 @@ static struct proto mptcp_prot = {
 static struct socket *mptcp_socket_create_get(struct mptcp_sock *msk)
 {
 	struct sock *sk = (struct sock *)msk;
+	struct subflow_context *subflow;
 	struct socket *ssock;
 	int err;
 
@@ -875,6 +876,11 @@ static struct socket *mptcp_socket_create_get(struct mptcp_sock *msk)
 	}
 
 	msk->subflow = ssock;
+	subflow = subflow_ctx(msk->subflow->sk);
+	subflow->request_mptcp = 1; /* @@ if MPTCP enabled */
+	subflow->request_cksum = 1; /* @@ if checksum enabled */
+	subflow->request_version = 0; /* only v0 supported */
+
 	sock_hold(ssock->sk);
 
 release:
net/mptcp/protocol.h +1 -1
index 591cebcf1bfa..2891715a82f0 100644
@@ -169,10 +169,10 @@ struct subflow_context {
 	u16	map_data_len;
 	u16	request_mptcp : 1,  /* send MP_CAPABLE */
 		request_cksum : 1,
+		request_version : 4,
 		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,
net/mptcp/subflow.c +2 -5
index 9d91014c0d1b..678fca99c23a 100644
@@ -62,8 +62,8 @@ static void subflow_v4_init_req(struct request_sock *req,
 
 	if (rx_opt.mptcp.mp_capable && listener->request_mptcp) {
 		subflow_req->mp_capable = 1;
-		if (rx_opt.mptcp.version >= listener->version)
-			subflow_req->version = listener->version;
+		if (rx_opt.mptcp.version >= listener->request_version)
+			subflow_req->version = listener->request_version;
 		else
 			subflow_req->version = rx_opt.mptcp.version;
 		if ((rx_opt.mptcp.flags & MPTCP_CAP_CHECKSUM_REQD) ||
@@ -218,9 +218,6 @@ int subflow_create_socket(struct sock *sk, struct socket **new_sock)
 
 	*new_sock = sf;
 	subflow->conn = sk;
-	subflow->request_mptcp = 1; // @@ if MPTCP enabled
-	subflow->request_cksum = 1; // @@ if checksum enabled
-	subflow->version = 0;
 
 	return 0;
 }
Signature · 1 line
2.17.2
#12 lore raw

Re: [MPTCP] [PATCH v2 07/10] Move setting request_ fields of subflow to MPTCP layer helper

Quoted 26 lines · Peter Krystad

For secondary subflows different request_ fields will be added that will be set differently based on subflow type (initial vs secondary).

squashto: Associate MPTCP context with TCP socket

Signed-off-by Peter Krystad <peter.krystad(a)linux.intel.com>

---

net/mptcp/protocol.c | 6 ++++++
net/mptcp/protocol.h | 2 +-
net/mptcp/subflow.c  | 7 ++-----
3 files changed, 9 insertions(+), 6 deletions(-)
net/mptcp/protocol.c +1 -0
index 8a841d489b52..4d4a9c3d25c4 100644
@@ -860,6 +860,7 @@ static struct proto mptcp_prot = {
 static struct socket *mptcp_socket_create_get(struct mptcp_sock *msk)
 {
 	struct sock *sk = (struct sock *)msk;
+	struct subflow_context *subflow;
 	struct socket *ssock;
 	int err;
 

net/mptcp/protocol.c static struct socket *mptcp_socket_create_get(struct mptcp_sock *msk) · line 881

Quoted 6 lines
net/mptcp/protocol.c +3 -0
@@ -875,6 +876,11 @@ static struct socket *mptcp_socket_create_get(struct mptcp_sock *msk)
 	}
 
 	msk->subflow = ssock;
+	subflow = subflow_ctx(msk->subflow->sk);
+	subflow->request_mptcp = 1; /* @@ if MPTCP enabled */
+	subflow->request_cksum = 1; /* @@ if checksum enabled */

request_cksum should be 0 since we don't support it.

Mat

Quoted 54 lines
net/mptcp/protocol.c +2 -0
+	subflow->request_version = 0; /* only v0 supported */
+
 	sock_hold(ssock->sk);
 

release:

net/mptcp/protocol.h +1 -1
index 591cebcf1bfa..2891715a82f0 100644
@@ -169,10 +169,10 @@ struct subflow_context {
 	u16	map_data_len;
 	u16	request_mptcp : 1,  /* send MP_CAPABLE */
 		request_cksum : 1,
+		request_version : 4,
 		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,
net/mptcp/subflow.c +2 -5
index 9d91014c0d1b..678fca99c23a 100644
@@ -62,8 +62,8 @@ static void subflow_v4_init_req(struct request_sock *req,
 
 	if (rx_opt.mptcp.mp_capable && listener->request_mptcp) {
 		subflow_req->mp_capable = 1;
-		if (rx_opt.mptcp.version >= listener->version)
-			subflow_req->version = listener->version;
+		if (rx_opt.mptcp.version >= listener->request_version)
+			subflow_req->version = listener->request_version;
 		else
 			subflow_req->version = rx_opt.mptcp.version;
 		if ((rx_opt.mptcp.flags & MPTCP_CAP_CHECKSUM_REQD) ||
@@ -218,9 +218,6 @@ int subflow_create_socket(struct sock *sk, struct socket **new_sock)
 
 	*new_sock = sf;
 	subflow->conn = sk;
-	subflow->request_mptcp = 1; // @@ if MPTCP enabled
-	subflow->request_cksum = 1; // @@ if checksum enabled
-	subflow->version = 0;
 
 	return 0;
 }
Signature · 6 lines
2.17.2

_______________________________________________
mptcp mailing list
mptcp(a)lists.01.org
https://lists.01.org/mailman/listinfo/mptcp

--
Mat Martineau
Intel

author
#13 lore raw

Re: [MPTCP] [PATCH v2 07/10] Move setting request_ fields of subflow to MPTCP layer helper

Quoted 30 lines · Mat Martineau
Quoted 28 lines · Peter Krystad

For secondary subflows different request_ fields will be added that will be set differently based on subflow type (initial vs secondary).

squashto: Associate MPTCP context with TCP socket

Signed-off-by Peter Krystad <peter.krystad(a)linux.intel.com>

---

net/mptcp/protocol.c | 6 ++++++
net/mptcp/protocol.h | 2 +-
net/mptcp/subflow.c  | 7 ++-----
3 files changed, 9 insertions(+), 6 deletions(-)
net/mptcp/protocol.c +1 -0
index 8a841d489b52..4d4a9c3d25c4 100644
@@ -860,6 +860,7 @@ static struct proto mptcp_prot = {
 static struct socket *mptcp_socket_create_get(struct mptcp_sock *msk)
 {
 	struct sock *sk = (struct sock *)msk;
+	struct subflow_context *subflow;
 	struct socket *ssock;
 	int err;
 
@@ -875,6 +876,11 @@ static struct socket *mptcp_socket_create_get(struct mptcp_sock *msk)
 	}
 
Quoted 7 lines

net/mptcp/protocol.c static struct socket *mptcp_socket_create_get(struct mptcp_sock *msk) · line 881

Quoted 4 lines
net/mptcp/protocol.c +3 -0
 	msk->subflow = ssock;
+	subflow = subflow_ctx(msk->subflow->sk);
+	subflow->request_mptcp = 1; /* @@ if MPTCP enabled */
+	subflow->request_cksum = 1; /* @@ if checksum enabled */

request_cksum should be 0 since we don't support it.

Nor do we bother looking at this field when we send the option, so I'll clean this up.

Peter.

Quoted 62 lines

Mat

Quoted 54 lines
net/mptcp/protocol.c +2 -0
+	subflow->request_version = 0; /* only v0 supported */
+
 	sock_hold(ssock->sk);
 

release:

net/mptcp/protocol.h +1 -1
index 591cebcf1bfa..2891715a82f0 100644
@@ -169,10 +169,10 @@ struct subflow_context {
 	u16	map_data_len;
 	u16	request_mptcp : 1,  /* send MP_CAPABLE */
 		request_cksum : 1,
+		request_version : 4,
 		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,
net/mptcp/subflow.c +2 -5
index 9d91014c0d1b..678fca99c23a 100644
@@ -62,8 +62,8 @@ static void subflow_v4_init_req(struct request_sock *req,
 
 	if (rx_opt.mptcp.mp_capable && listener->request_mptcp) {
 		subflow_req->mp_capable = 1;
-		if (rx_opt.mptcp.version >= listener->version)
-			subflow_req->version = listener->version;
+		if (rx_opt.mptcp.version >= listener->request_version)
+			subflow_req->version = listener->request_version;
 		else
 			subflow_req->version = rx_opt.mptcp.version;
 		if ((rx_opt.mptcp.flags & MPTCP_CAP_CHECKSUM_REQD) ||
@@ -218,9 +218,6 @@ int subflow_create_socket(struct sock *sk, struct socket **new_sock)
 
 	*new_sock = sf;
 	subflow->conn = sk;
-	subflow->request_mptcp = 1; // @@ if MPTCP enabled
-	subflow->request_cksum = 1; // @@ if checksum enabled
-	subflow->version = 0;
 
 	return 0;
 }
Signature · 6 lines
2.17.2

_______________________________________________
mptcp mailing list
mptcp(a)lists.01.org
https://lists.01.org/mailman/listinfo/mptcp

--
Mat Martineau
Intel

author
#14 lore raw

PATCH v2 8/10 mptcp: Add handling of outgoing MP_JOIN requests

In reply to Peter Krystad

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. When a valid SYN-ACK is received the new sock is added to the tail of the mptcp sock conn_list where it will not interfere with data flow on the original connection.

Data flow and connection failover not addressed by this commit.

Signed-off-by Peter Krystad <peter.krystad(a)linux.intel.com>
---
 include/net/mptcp.h  |  2 ++
 net/mptcp/options.c  | 51 ++++++++++++++++++++++++++++++++---
 net/mptcp/protocol.c |  2 ++
 net/mptcp/protocol.h | 10 +++++++
 net/mptcp/subflow.c  | 63 +++++++++++++++++++++++++++++++++++++++++++-
 net/mptcp/token.c    | 41 ++++++++++++++++++++++++++++
 6 files changed, 164 insertions(+), 5 deletions(-)
include/net/mptcp.h +2 -0
index bb2dd193c0c5..50cd1b31ebdd 100644
@@ -40,6 +40,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 +47 -4

105 lines not on this page · raw message

net/mptcp/protocol.c +2 -0
index 4d4a9c3d25c4..67a93ab709f1 100644
@@ -797,6 +797,8 @@ void mptcp_finish_connect(struct sock *sk, int mp_capable)
 		msk->local_key = subflow->local_key;
 		msk->token = subflow->token;
 		pr_debug("msk=%p, token=%u", msk, msk->token);
+		msk->dport = ntohs(inet_sk(msk->subflow->sk)->inet_dport);
+		pr_debug("dport=%d", msk->dport);
 
 		pm_new_connection(msk, 0);
 
net/mptcp/protocol.h +10 -0
index 2891715a82f0..b40e99ebca52 100644
@@ -49,8 +49,10 @@
 #define TCPOLEN_MPTCP_ADD_ADDR6		20
 #define TCPOLEN_MPTCP_RM_ADDR		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)
@@ -116,6 +118,7 @@ struct mptcp_sock {
 	u64		write_seq;
 	u64		ack_seq;
 	u32		token;
+	u16		dport;
 	struct list_head conn_list;
 	struct socket	*subflow; /* outgoing connect/listener/!mp_capable */
 	struct mptcp_pm_data	pm;
@@ -168,7 +171,9 @@ struct subflow_context {
 	u32	ssn_offset;
 	u16	map_data_len;
 	u16	request_mptcp : 1,  /* send MP_CAPABLE */
+		request_join : 1,   /* send MP_JOIN */
 		request_cksum : 1,
+		request_bkup : 1,
 		request_version : 4,
 		mp_capable : 1,     /* remote is MPTCP capable */
 		mp_join : 1,        /* remote is JOINing */
@@ -180,6 +185,7 @@ struct subflow_context {
 	u32	remote_nonce;
 	u64	thmac;
 	u32	local_nonce;
+	u8	hmac[MPTCPOPT_HMAC_LEN];
 	u8	local_id;
 	u8	remote_id;
 
@@ -203,6 +209,8 @@ mptcp_subflow_tcp_socket(const struct subflow_context *subflow)
 }
 
 void subflow_init(void);
+int subflow_connect(struct sock *sk, struct sockaddr_in *local,
+		    struct sockaddr_in *remote, u8 remote_id);
 int subflow_create_socket(struct sock *sk, struct socket **new_sock);
 
 extern const struct inet_connection_sock_af_ops ipv4_specific;
@@ -216,10 +224,12 @@ void mptcp_finish_join(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_response(struct sock *sk);
 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_subflow(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);
net/mptcp/subflow.c +62 -1

87 lines not on this page · raw message

net/mptcp/token.c +41 -0

59 lines not on this page · raw message

Signature · 1 line
2.17.2
#15 lore raw

Re: [MPTCP] [PATCH v2 08/10] mptcp: Add handling of outgoing MP_JOIN requests

Quoted 27 lines · Peter Krystad

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. When a valid SYN-ACK is received the new sock is added to the tail of the mptcp sock conn_list where it will not interfere with data flow on the original connection.

Data flow and connection failover not addressed by this commit.

Signed-off-by Peter Krystad <peter.krystad(a)linux.intel.com>

---

include/net/mptcp.h  |  2 ++
net/mptcp/options.c  | 51 ++++++++++++++++++++++++++++++++---
net/mptcp/protocol.c |  2 ++
net/mptcp/protocol.h | 10 +++++++
net/mptcp/subflow.c  | 63 +++++++++++++++++++++++++++++++++++++++++++-
net/mptcp/token.c    | 41 ++++++++++++++++++++++++++++
6 files changed, 164 insertions(+), 5 deletions(-)
include/net/mptcp.h +0 -0
index bb2dd193c0c5..50cd1b31ebdd 100644

include/net/mptcp.h struct mptcp_out_options { · line 44

Quoted 5 lines
include/net/mptcp.h +2 -0
@@ -40,6 +40,8 @@ struct mptcp_out_options {
 	u8 backup;
 	u32 nonce;
 	u64 thmac;
+	u32 token;
+	u8 hmac[20];

'20' needs to match MPTCPOPT_HMAC_LEN, but that definition is in protocol.h. Would be better to define the value in mptcp.h so it can be used everywhere that it's needed.

Quoted 244 lines
include/net/mptcp.h +0 -0
 	struct mptcp_ext ext_copy;
 #endif
 };
net/mptcp/options.c +47 -4
index 848d761b2ac7..d6f1c832c209 100644
@@ -300,6 +300,16 @@ bool mptcp_syn_options(struct sock *sk, unsigned int *size,
 		opts->sndr_key = subflow->local_key;
 		*size = TCPOLEN_MPTCP_MPC_SYN;
 		return true;
+	} else if (subflow->request_join) {
+		pr_debug("token=%u, nonce=%u", subflow->token,
+			 subflow->local_nonce);
+		opts->suboptions = OPTION_MPTCP_MPJ_SYN;
+		opts->join_id = subflow->remote_id;
+		opts->token = subflow->token;
+		opts->nonce = subflow->local_nonce;
+		opts->backup = subflow->request_bkup;
+		*size = TCPOLEN_MPTCP_MPJ_SYN;
+		return true;
 	}
 	return false;
 }
@@ -309,10 +319,17 @@ void mptcp_rcv_synsent(struct sock *sk)
 	struct tcp_sock *tp = tcp_sk(sk);
 	struct subflow_context *subflow = subflow_ctx(sk);
 
-	pr_debug("subflow=%p", subflow);
 	if (subflow->request_mptcp && tp->rx_opt.mptcp.mp_capable) {
 		subflow->mp_capable = 1;
 		subflow->remote_key = tp->rx_opt.mptcp.sndr_key;
+		pr_debug("subflow=%p, remote_key=%llu", subflow,
+			 subflow->remote_key);
+	} else if (subflow->request_join && tp->rx_opt.mptcp.mp_join) {
+		subflow->mp_join = 1;
+		subflow->thmac = tp->rx_opt.mptcp.thmac;
+		subflow->remote_nonce = tp->rx_opt.mptcp.nonce;
+		pr_debug("subflow=%p, thmac=%llu, remote_nonce=%u", subflow,
+			 subflow->thmac, subflow->remote_nonce);
 	}
 }
 
@@ -322,7 +339,8 @@ static bool mptcp_established_options_mp(struct sock *sk, unsigned int *size,
 {
 	struct subflow_context *subflow = subflow_ctx(sk);
 
-	if (!subflow->fourth_ack && remaining >= TCPOLEN_MPTCP_MPC_ACK) {
+	if (subflow->mp_capable && !subflow->fourth_ack &&
+	    remaining >= TCPOLEN_MPTCP_MPC_ACK) {
 		opts->suboptions = OPTION_MPTCP_MPC_ACK;
 		opts->sndr_key = subflow->local_key;
 		opts->rcvr_key = subflow->remote_key;
@@ -331,6 +349,14 @@ static bool mptcp_established_options_mp(struct sock *sk, unsigned int *size,
 		pr_debug("subflow=%p, local_key=%llu, remote_key=%llu",
 			 subflow, subflow->local_key, subflow->remote_key);
 		return true;
+	} else if (subflow->mp_join && !subflow->fourth_ack &&
+		   remaining >= TCPOLEN_MPTCP_MPJ_ACK) {
+		opts->suboptions = OPTION_MPTCP_MPJ_ACK;
+		memcpy(opts->hmac, subflow->hmac, MPTCPOPT_HMAC_LEN);
+		*size = TCPOLEN_MPTCP_MPJ_ACK;
+		subflow->fourth_ack = 1;
+		pr_debug("subflow=%p", subflow);
+		return true;
 	}
 	return false;
 }
@@ -443,10 +469,11 @@ bool mptcp_established_options(struct sock *sk, struct sk_buff *skb,
 			       unsigned int *size, unsigned int remaining,
 			       struct mptcp_out_options *opts)
 {
+	struct subflow_context *subflow = subflow_ctx(sk);
 	unsigned int opt_size = 0;
 	bool ret = false;
 
-	if (!subflow_ctx(sk)->mp_capable)
+	if (!subflow->mp_capable && !subflow->mp_join)
 		return false;
 
 	opts->suboptions = 0;
@@ -543,7 +570,6 @@ void mptcp_incoming_options(struct sock *sk, struct sk_buff *skb,
 
 	if (msk)
 		pm_fully_established(msk);
-
 }
 
 void mptcp_write_options(__be32 *ptr, struct mptcp_out_options *opts)
@@ -592,6 +618,16 @@ void mptcp_write_options(__be32 *ptr, struct mptcp_out_options *opts)
 				      0, opts->addr_id);
 	}
 
+	if (OPTION_MPTCP_MPJ_SYN & opts->suboptions) {
+		*ptr++ = mptcp_option(MPTCPOPT_MP_JOIN,
+				      TCPOLEN_MPTCP_MPJ_SYN,
+				      opts->backup, opts->join_id);
+		put_unaligned_be32(opts->token, ptr);
+		ptr += 1;
+		put_unaligned_be32(opts->nonce, ptr);
+		ptr += 1;
+	}
+
 	if (OPTION_MPTCP_MPJ_SYNACK & opts->suboptions) {
 		*ptr++ = mptcp_option(MPTCPOPT_MP_JOIN,
 				      TCPOLEN_MPTCP_MPJ_SYNACK,
@@ -602,6 +638,13 @@ void mptcp_write_options(__be32 *ptr, struct mptcp_out_options *opts)
 		ptr += 1;
 	}
 
+	if (OPTION_MPTCP_MPJ_ACK & opts->suboptions) {
+		*ptr++ = mptcp_option(MPTCPOPT_MP_JOIN,
+				      TCPOLEN_MPTCP_MPJ_ACK, 0, 0);
+		memcpy(ptr, opts->hmac, MPTCPOPT_HMAC_LEN);
+		ptr += 5;
+	}
+
 	if (opts->ext_copy.use_ack || opts->ext_copy.use_map) {
 		struct mptcp_ext *mpext = &opts->ext_copy;
 		u8 len = TCPOLEN_MPTCP_DSS_BASE;
net/mptcp/protocol.c +2 -0
index 4d4a9c3d25c4..67a93ab709f1 100644
@@ -797,6 +797,8 @@ void mptcp_finish_connect(struct sock *sk, int mp_capable)
 		msk->local_key = subflow->local_key;
 		msk->token = subflow->token;
 		pr_debug("msk=%p, token=%u", msk, msk->token);
+		msk->dport = ntohs(inet_sk(msk->subflow->sk)->inet_dport);
+		pr_debug("dport=%d", msk->dport);
 
 		pm_new_connection(msk, 0);
 
net/mptcp/protocol.h +10 -0
index 2891715a82f0..b40e99ebca52 100644
@@ -49,8 +49,10 @@
 #define TCPOLEN_MPTCP_ADD_ADDR6		20
 #define TCPOLEN_MPTCP_RM_ADDR		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)
@@ -116,6 +118,7 @@ struct mptcp_sock {
 	u64		write_seq;
 	u64		ack_seq;
 	u32		token;
+	u16		dport;
 	struct list_head conn_list;
 	struct socket	*subflow; /* outgoing connect/listener/!mp_capable */
 	struct mptcp_pm_data	pm;
@@ -168,7 +171,9 @@ struct subflow_context {
 	u32	ssn_offset;
 	u16	map_data_len;
 	u16	request_mptcp : 1,  /* send MP_CAPABLE */
+		request_join : 1,   /* send MP_JOIN */
 		request_cksum : 1,
+		request_bkup : 1,
 		request_version : 4,
 		mp_capable : 1,     /* remote is MPTCP capable */
 		mp_join : 1,        /* remote is JOINing */
@@ -180,6 +185,7 @@ struct subflow_context {
 	u32	remote_nonce;
 	u64	thmac;
 	u32	local_nonce;
+	u8	hmac[MPTCPOPT_HMAC_LEN];
 	u8	local_id;
 	u8	remote_id;
 
@@ -203,6 +209,8 @@ mptcp_subflow_tcp_socket(const struct subflow_context *subflow)
 }
 
 void subflow_init(void);
+int subflow_connect(struct sock *sk, struct sockaddr_in *local,
+		    struct sockaddr_in *remote, u8 remote_id);
 int subflow_create_socket(struct sock *sk, struct socket **new_sock);
 
 extern const struct inet_connection_sock_af_ops ipv4_specific;
@@ -216,10 +224,12 @@ void mptcp_finish_join(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_response(struct sock *sk);
 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_subflow(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);
net/mptcp/subflow.c +18 -1
index 678fca99c23a..a871dbb21a1d 100644
@@ -22,6 +22,9 @@ static int subflow_rebuild_header(struct sock *sk)
 	if (subflow->request_mptcp && !subflow->token) {
 		pr_debug("subflow=%p", sk);
 		token_new_connect(sk);
+	} else if (subflow->request_join && !subflow->local_nonce) {
+		pr_debug("subflow=%p", sk);
+		token_new_subflow(sk);
 	}
 
 	return inet_sk_rebuild_header(sk);
@@ -95,7 +98,10 @@ static void subflow_finish_connect(struct sock *sk, const struct sk_buff *skb)
 
 	inet_sk_rx_dst_set(sk, skb);
 
-	if (subflow->conn && !subflow->conn_finished) {
+	if (!subflow->conn)
+		return;
+
+	if (subflow->mp_capable && !subflow->conn_finished) {
 		pr_debug("subflow=%p, remote_key=%llu", subflow_ctx(sk),
 			 subflow->remote_key);
 		mptcp_finish_connect(subflow->conn, subflow->mp_capable);
@@ -105,6 +111,17 @@ static void subflow_finish_connect(struct sock *sk, const struct sk_buff *skb)
 			pr_debug("synack seq=%u", TCP_SKB_CB(skb)->seq);
 			subflow->ssn_offset = TCP_SKB_CB(skb)->seq;
 		}
+	} else if (subflow->mp_join && !subflow->conn_finished) {
+		pr_debug("subflow=%p, thmac=%llu, remote_nonce=%u",
+			 subflow_ctx(sk), subflow->thmac,
+			 subflow->remote_nonce);
+		if (token_join_response(sk)) {
+			subflow->mp_join = 0;
+			// @@ need to trigger RST
+		} else {
+			mptcp_finish_join(sk);
+			subflow->conn_finished = 1;
+		}
 	}
 }
 
@@ -195,6 +212,50 @@ static void subflow_data_ready(struct sock *sk)
 	}
 }
 

net/mptcp/subflow.c static void subflow_data_ready(struct sock *sk) · line 224

Quoted 10 lines
net/mptcp/subflow.c +10 -0
+int subflow_connect(struct sock *sk, struct sockaddr_in *local,
+		    struct sockaddr_in *remote, u8 remote_id)
+{
+	struct mptcp_sock *msk = mptcp_sk(sk);
+	struct subflow_context *subflow;
+	struct socket *sf;
+	u32 token;
+	int err;
+
+	err = subflow_create_socket(sk, &sf);

Is the caller supposed to lock the MPTCP socket? pm_create_subflow() in patch 10 doesn't appear to lock it.

Mat

Quoted 111 lines
net/mptcp/subflow.c +34 -0
+	if (err)
+		return err;
+
+	err = kernel_bind(sf, (struct sockaddr *)local,
+			  sizeof(struct sockaddr_in));
+	if (err) {
+		pr_debug("bind err=%d", err);
+		goto failed;
+	}
+
+	subflow = subflow_ctx(sf->sk);
+	subflow->remote_key = msk->remote_key;
+	subflow->local_key = msk->local_key;
+	crypto_key_sha1(msk->remote_key, &token, NULL);
+	pr_debug("msk=%p token=%u", msk, token);
+	subflow->token = token;
+	subflow->remote_id = remote_id;
+	subflow->request_join = 1;
+	subflow->request_bkup = 1;
+
+	err = kernel_connect(sf, (struct sockaddr *)remote,
+			     sizeof(struct sockaddr_in), O_NONBLOCK);
+	if (err && err != -EINPROGRESS) {
+		pr_debug("connect err=%d", err);
+		goto failed;
+	}
+
+	return 0;
+
+failed:
+	/* @@ cleanup the socket */
+	return err;
+}
+
 int subflow_create_socket(struct sock *sk, struct socket **new_sock)
 {
 	struct subflow_context *subflow;
net/mptcp/token.c +41 -0
index ef03ef19af98..b31d98ba5c0d 100644
@@ -93,6 +93,28 @@ static void new_req_join(struct request_sock *req, struct sock *sk,
 		 subflow_req->thmac);
 }
 
+static int new_rsp_join(struct sock *sk)
+{
+	struct subflow_context *subflow = subflow_ctx(sk);
+	u8 hmac[MPTCPOPT_HMAC_LEN];
+	u64 thmac;
+
+	crypto_hmac_sha1(subflow->remote_key, subflow->local_key,
+			 subflow->remote_nonce, subflow->local_nonce,
+			 (u32 *)hmac);
+
+	thmac = get_unaligned_be64(hmac);
+	pr_debug("thmac=%llu", thmac);
+	if (thmac != subflow->thmac)
+		return -1;
+
+	crypto_hmac_sha1(subflow->local_key, subflow->remote_key,
+			 subflow->local_nonce, subflow->remote_nonce,
+			 (u32 *)subflow->hmac);
+
+	return 0;
+}
+
 static int new_join_valid(struct request_sock *req, struct sock *sk,
 			  struct tcp_options_received *rx_opt)
 {
@@ -210,6 +232,15 @@ int token_join_request(struct request_sock *req, const struct sk_buff *skb)
 	return -1;
 }
 
+/* validate received truncated hmac and create hmac for third ACK */
+int token_join_response(struct sock *sk)
+{
+	struct subflow_context *subflow = subflow_ctx(sk);
+
+	pr_debug("subflow=%p, token=%u", subflow, subflow->token);
+	return new_rsp_join(sk);
+}
+
 /* validate hmac received in third ACK */
 int token_join_valid(struct request_sock *req,
 		     struct tcp_options_received *rx_opt)
@@ -247,6 +278,16 @@ void token_new_connect(struct sock *sk)
 	spin_unlock_bh(&token_tree_lock);
 }
 
+/* create nonce for secondary subflow */
+void token_new_subflow(struct sock *sk)
+{
+	struct subflow_context *subflow = subflow_ctx(sk);
+
+	pr_debug("subflow=%p", subflow);
+
+	get_random_bytes(&subflow->local_nonce, sizeof(u32));
+}
+
 void token_new_accept(struct sock *sk)
 {
 	struct subflow_context *subflow = subflow_ctx(sk);
Signature · 6 lines
2.17.2

_______________________________________________
mptcp mailing list
mptcp(a)lists.01.org
https://lists.01.org/mailman/listinfo/mptcp

--
Mat Martineau
Intel

author
#16 lore raw

Re: [MPTCP] [PATCH v2 08/10] mptcp: Add handling of outgoing MP_JOIN requests

Quoted 24 lines · Mat Martineau
Quoted 22 lines · Peter Krystad

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. When a valid SYN-ACK is received the new sock is added to the tail of the mptcp sock conn_list where it will not interfere with data flow on the original connection.

Data flow and connection failover not addressed by this commit.

Signed-off-by Peter Krystad <peter.krystad(a)linux.intel.com>

---

include/net/mptcp.h  |  2 ++
net/mptcp/options.c  | 51 ++++++++++++++++++++++++++++++++---
net/mptcp/protocol.c |  2 ++
net/mptcp/protocol.h | 10 +++++++
net/mptcp/subflow.c  | 63 +++++++++++++++++++++++++++++++++++++++++++-
net/mptcp/token.c    | 41 ++++++++++++++++++++++++++++
6 files changed, 164 insertions(+), 5 deletions(-)
Quoted 14 lines

include/net/mptcp.h struct mptcp_out_options { · line 44

Quoted 10 lines
include/net/mptcp.h +2 -0
index bb2dd193c0c5..50cd1b31ebdd 100644
@@ -40,6 +40,8 @@ struct mptcp_out_options {
 	u8 backup;
 	u32 nonce;
 	u64 thmac;
+	u32 token;
+	u8 hmac[20];

'20' needs to match MPTCPOPT_HMAC_LEN, but that definition is in protocol.h. Would be better to define the value in mptcp.h so it can be used everywhere that it's needed.

Every other MPTCP option definition is in protocol.h so I'd like to try to let this slide. That this field is size 20 is defined by the protocol spec, not the implementation, so it isn't going to change.

Quoted 244 lines
Quoted 244 lines
include/net/mptcp.h +0 -0
 	struct mptcp_ext ext_copy;
 #endif
 };
net/mptcp/options.c +47 -4
index 848d761b2ac7..d6f1c832c209 100644
@@ -300,6 +300,16 @@ bool mptcp_syn_options(struct sock *sk, unsigned int *size,
 		opts->sndr_key = subflow->local_key;
 		*size = TCPOLEN_MPTCP_MPC_SYN;
 		return true;
+	} else if (subflow->request_join) {
+		pr_debug("token=%u, nonce=%u", subflow->token,
+			 subflow->local_nonce);
+		opts->suboptions = OPTION_MPTCP_MPJ_SYN;
+		opts->join_id = subflow->remote_id;
+		opts->token = subflow->token;
+		opts->nonce = subflow->local_nonce;
+		opts->backup = subflow->request_bkup;
+		*size = TCPOLEN_MPTCP_MPJ_SYN;
+		return true;
 	}
 	return false;
 }
@@ -309,10 +319,17 @@ void mptcp_rcv_synsent(struct sock *sk)
 	struct tcp_sock *tp = tcp_sk(sk);
 	struct subflow_context *subflow = subflow_ctx(sk);
 
-	pr_debug("subflow=%p", subflow);
 	if (subflow->request_mptcp && tp->rx_opt.mptcp.mp_capable) {
 		subflow->mp_capable = 1;
 		subflow->remote_key = tp->rx_opt.mptcp.sndr_key;
+		pr_debug("subflow=%p, remote_key=%llu", subflow,
+			 subflow->remote_key);
+	} else if (subflow->request_join && tp->rx_opt.mptcp.mp_join) {
+		subflow->mp_join = 1;
+		subflow->thmac = tp->rx_opt.mptcp.thmac;
+		subflow->remote_nonce = tp->rx_opt.mptcp.nonce;
+		pr_debug("subflow=%p, thmac=%llu, remote_nonce=%u", subflow,
+			 subflow->thmac, subflow->remote_nonce);
 	}
 }
 
@@ -322,7 +339,8 @@ static bool mptcp_established_options_mp(struct sock *sk, unsigned int *size,
 {
 	struct subflow_context *subflow = subflow_ctx(sk);
 
-	if (!subflow->fourth_ack && remaining >= TCPOLEN_MPTCP_MPC_ACK) {
+	if (subflow->mp_capable && !subflow->fourth_ack &&
+	    remaining >= TCPOLEN_MPTCP_MPC_ACK) {
 		opts->suboptions = OPTION_MPTCP_MPC_ACK;
 		opts->sndr_key = subflow->local_key;
 		opts->rcvr_key = subflow->remote_key;
@@ -331,6 +349,14 @@ static bool mptcp_established_options_mp(struct sock *sk, unsigned int *size,
 		pr_debug("subflow=%p, local_key=%llu, remote_key=%llu",
 			 subflow, subflow->local_key, subflow->remote_key);
 		return true;
+	} else if (subflow->mp_join && !subflow->fourth_ack &&
+		   remaining >= TCPOLEN_MPTCP_MPJ_ACK) {
+		opts->suboptions = OPTION_MPTCP_MPJ_ACK;
+		memcpy(opts->hmac, subflow->hmac, MPTCPOPT_HMAC_LEN);
+		*size = TCPOLEN_MPTCP_MPJ_ACK;
+		subflow->fourth_ack = 1;
+		pr_debug("subflow=%p", subflow);
+		return true;
 	}
 	return false;
 }
@@ -443,10 +469,11 @@ bool mptcp_established_options(struct sock *sk, struct sk_buff *skb,
 			       unsigned int *size, unsigned int remaining,
 			       struct mptcp_out_options *opts)
 {
+	struct subflow_context *subflow = subflow_ctx(sk);
 	unsigned int opt_size = 0;
 	bool ret = false;
 
-	if (!subflow_ctx(sk)->mp_capable)
+	if (!subflow->mp_capable && !subflow->mp_join)
 		return false;
 
 	opts->suboptions = 0;
@@ -543,7 +570,6 @@ void mptcp_incoming_options(struct sock *sk, struct sk_buff *skb,
 
 	if (msk)
 		pm_fully_established(msk);
-
 }
 
 void mptcp_write_options(__be32 *ptr, struct mptcp_out_options *opts)
@@ -592,6 +618,16 @@ void mptcp_write_options(__be32 *ptr, struct mptcp_out_options *opts)
 				      0, opts->addr_id);
 	}
 
+	if (OPTION_MPTCP_MPJ_SYN & opts->suboptions) {
+		*ptr++ = mptcp_option(MPTCPOPT_MP_JOIN,
+				      TCPOLEN_MPTCP_MPJ_SYN,
+				      opts->backup, opts->join_id);
+		put_unaligned_be32(opts->token, ptr);
+		ptr += 1;
+		put_unaligned_be32(opts->nonce, ptr);
+		ptr += 1;
+	}
+
 	if (OPTION_MPTCP_MPJ_SYNACK & opts->suboptions) {
 		*ptr++ = mptcp_option(MPTCPOPT_MP_JOIN,
 				      TCPOLEN_MPTCP_MPJ_SYNACK,
@@ -602,6 +638,13 @@ void mptcp_write_options(__be32 *ptr, struct mptcp_out_options *opts)
 		ptr += 1;
 	}
 
+	if (OPTION_MPTCP_MPJ_ACK & opts->suboptions) {
+		*ptr++ = mptcp_option(MPTCPOPT_MP_JOIN,
+				      TCPOLEN_MPTCP_MPJ_ACK, 0, 0);
+		memcpy(ptr, opts->hmac, MPTCPOPT_HMAC_LEN);
+		ptr += 5;
+	}
+
 	if (opts->ext_copy.use_ack || opts->ext_copy.use_map) {
 		struct mptcp_ext *mpext = &opts->ext_copy;
 		u8 len = TCPOLEN_MPTCP_DSS_BASE;
net/mptcp/protocol.c +2 -0
index 4d4a9c3d25c4..67a93ab709f1 100644
@@ -797,6 +797,8 @@ void mptcp_finish_connect(struct sock *sk, int mp_capable)
 		msk->local_key = subflow->local_key;
 		msk->token = subflow->token;
 		pr_debug("msk=%p, token=%u", msk, msk->token);
+		msk->dport = ntohs(inet_sk(msk->subflow->sk)->inet_dport);
+		pr_debug("dport=%d", msk->dport);
 
 		pm_new_connection(msk, 0);
 
net/mptcp/protocol.h +10 -0
index 2891715a82f0..b40e99ebca52 100644
@@ -49,8 +49,10 @@
 #define TCPOLEN_MPTCP_ADD_ADDR6		20
 #define TCPOLEN_MPTCP_RM_ADDR		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)
@@ -116,6 +118,7 @@ struct mptcp_sock {
 	u64		write_seq;
 	u64		ack_seq;
 	u32		token;
+	u16		dport;
 	struct list_head conn_list;
 	struct socket	*subflow; /* outgoing connect/listener/!mp_capable */
 	struct mptcp_pm_data	pm;
@@ -168,7 +171,9 @@ struct subflow_context {
 	u32	ssn_offset;
 	u16	map_data_len;
 	u16	request_mptcp : 1,  /* send MP_CAPABLE */
+		request_join : 1,   /* send MP_JOIN */
 		request_cksum : 1,
+		request_bkup : 1,
 		request_version : 4,
 		mp_capable : 1,     /* remote is MPTCP capable */
 		mp_join : 1,        /* remote is JOINing */
@@ -180,6 +185,7 @@ struct subflow_context {
 	u32	remote_nonce;
 	u64	thmac;
 	u32	local_nonce;
+	u8	hmac[MPTCPOPT_HMAC_LEN];
 	u8	local_id;
 	u8	remote_id;
 
@@ -203,6 +209,8 @@ mptcp_subflow_tcp_socket(const struct subflow_context *subflow)
 }
 
 void subflow_init(void);
+int subflow_connect(struct sock *sk, struct sockaddr_in *local,
+		    struct sockaddr_in *remote, u8 remote_id);
 int subflow_create_socket(struct sock *sk, struct socket **new_sock);
 
 extern const struct inet_connection_sock_af_ops ipv4_specific;
@@ -216,10 +224,12 @@ void mptcp_finish_join(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_response(struct sock *sk);
 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_subflow(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);
net/mptcp/subflow.c +18 -1
index 678fca99c23a..a871dbb21a1d 100644
@@ -22,6 +22,9 @@ static int subflow_rebuild_header(struct sock *sk)
 	if (subflow->request_mptcp && !subflow->token) {
 		pr_debug("subflow=%p", sk);
 		token_new_connect(sk);
+	} else if (subflow->request_join && !subflow->local_nonce) {
+		pr_debug("subflow=%p", sk);
+		token_new_subflow(sk);
 	}
 
 	return inet_sk_rebuild_header(sk);
@@ -95,7 +98,10 @@ static void subflow_finish_connect(struct sock *sk, const struct sk_buff *skb)
 
 	inet_sk_rx_dst_set(sk, skb);
 
-	if (subflow->conn && !subflow->conn_finished) {
+	if (!subflow->conn)
+		return;
+
+	if (subflow->mp_capable && !subflow->conn_finished) {
 		pr_debug("subflow=%p, remote_key=%llu", subflow_ctx(sk),
 			 subflow->remote_key);
 		mptcp_finish_connect(subflow->conn, subflow->mp_capable);
@@ -105,6 +111,17 @@ static void subflow_finish_connect(struct sock *sk, const struct sk_buff *skb)
 			pr_debug("synack seq=%u", TCP_SKB_CB(skb)->seq);
 			subflow->ssn_offset = TCP_SKB_CB(skb)->seq;
 		}
+	} else if (subflow->mp_join && !subflow->conn_finished) {
+		pr_debug("subflow=%p, thmac=%llu, remote_nonce=%u",
+			 subflow_ctx(sk), subflow->thmac,
+			 subflow->remote_nonce);
+		if (token_join_response(sk)) {
+			subflow->mp_join = 0;
+			// @@ need to trigger RST
+		} else {
+			mptcp_finish_join(sk);
+			subflow->conn_finished = 1;
+		}
 	}
 }
 
@@ -195,6 +212,50 @@ static void subflow_data_ready(struct sock *sk)
 	}
 }
 
Quoted 13 lines

net/mptcp/subflow.c static void subflow_data_ready(struct sock *sk) · line 224

Quoted 10 lines
net/mptcp/subflow.c +10 -0
+int subflow_connect(struct sock *sk, struct sockaddr_in *local,
+		    struct sockaddr_in *remote, u8 remote_id)
+{
+	struct mptcp_sock *msk = mptcp_sk(sk);
+	struct subflow_context *subflow;
+	struct socket *sf;
+	u32 token;
+	int err;
+
+	err = subflow_create_socket(sk, &sf);

Is the caller supposed to lock the MPTCP socket? pm_create_subflow() in patch 10 doesn't appear to lock it.

I think it needs to be locked when the token (and key) information is copied out from it, and a reference taken, then unlocked. Then the reference released when creation fails or succeeds. I'll try this out and put in a separate patch.

Peter.

Quoted 120 lines

Mat

Quoted 111 lines
net/mptcp/subflow.c +34 -0
+	if (err)
+		return err;
+
+	err = kernel_bind(sf, (struct sockaddr *)local,
+			  sizeof(struct sockaddr_in));
+	if (err) {
+		pr_debug("bind err=%d", err);
+		goto failed;
+	}
+
+	subflow = subflow_ctx(sf->sk);
+	subflow->remote_key = msk->remote_key;
+	subflow->local_key = msk->local_key;
+	crypto_key_sha1(msk->remote_key, &token, NULL);
+	pr_debug("msk=%p token=%u", msk, token);
+	subflow->token = token;
+	subflow->remote_id = remote_id;
+	subflow->request_join = 1;
+	subflow->request_bkup = 1;
+
+	err = kernel_connect(sf, (struct sockaddr *)remote,
+			     sizeof(struct sockaddr_in), O_NONBLOCK);
+	if (err && err != -EINPROGRESS) {
+		pr_debug("connect err=%d", err);
+		goto failed;
+	}
+
+	return 0;
+
+failed:
+	/* @@ cleanup the socket */
+	return err;
+}
+
 int subflow_create_socket(struct sock *sk, struct socket **new_sock)
 {
 	struct subflow_context *subflow;
net/mptcp/token.c +41 -0
index ef03ef19af98..b31d98ba5c0d 100644
@@ -93,6 +93,28 @@ static void new_req_join(struct request_sock *req, struct sock *sk,
 		 subflow_req->thmac);
 }
 
+static int new_rsp_join(struct sock *sk)
+{
+	struct subflow_context *subflow = subflow_ctx(sk);
+	u8 hmac[MPTCPOPT_HMAC_LEN];
+	u64 thmac;
+
+	crypto_hmac_sha1(subflow->remote_key, subflow->local_key,
+			 subflow->remote_nonce, subflow->local_nonce,
+			 (u32 *)hmac);
+
+	thmac = get_unaligned_be64(hmac);
+	pr_debug("thmac=%llu", thmac);
+	if (thmac != subflow->thmac)
+		return -1;
+
+	crypto_hmac_sha1(subflow->local_key, subflow->remote_key,
+			 subflow->local_nonce, subflow->remote_nonce,
+			 (u32 *)subflow->hmac);
+
+	return 0;
+}
+
 static int new_join_valid(struct request_sock *req, struct sock *sk,
 			  struct tcp_options_received *rx_opt)
 {
@@ -210,6 +232,15 @@ int token_join_request(struct request_sock *req, const struct sk_buff *skb)
 	return -1;
 }
 
+/* validate received truncated hmac and create hmac for third ACK */
+int token_join_response(struct sock *sk)
+{
+	struct subflow_context *subflow = subflow_ctx(sk);
+
+	pr_debug("subflow=%p, token=%u", subflow, subflow->token);
+	return new_rsp_join(sk);
+}
+
 /* validate hmac received in third ACK */
 int token_join_valid(struct request_sock *req,
 		     struct tcp_options_received *rx_opt)
@@ -247,6 +278,16 @@ void token_new_connect(struct sock *sk)
 	spin_unlock_bh(&token_tree_lock);
 }
 
+/* create nonce for secondary subflow */
+void token_new_subflow(struct sock *sk)
+{
+	struct subflow_context *subflow = subflow_ctx(sk);
+
+	pr_debug("subflow=%p", subflow);
+
+	get_random_bytes(&subflow->local_nonce, sizeof(u32));
+}
+
 void token_new_accept(struct sock *sk)
 {
 	struct subflow_context *subflow = subflow_ctx(sk);
Signature · 6 lines
2.17.2

_______________________________________________
mptcp mailing list
mptcp(a)lists.01.org
https://lists.01.org/mailman/listinfo/mptcp

--
Mat Martineau
Intel

#17 lore raw

Re: [MPTCP] [PATCH v2 08/10] mptcp: Add handling of outgoing MP_JOIN requests

In reply to Peter Krystad

Hi,

I have a couple of minor comments below.

net/mptcp/protocol.c void mptcp_finish_connect(struct sock *sk, int mp_capable) · line 801

Quoted 10 lines · Peter Krystad
net/mptcp/protocol.c +2 -0
index 4d4a9c3d25c4..67a93ab709f1 100644
@@ -797,6 +797,8 @@ void mptcp_finish_connect(struct sock *sk, int mp_capable)
 		msk->local_key = subflow->local_key;
 		msk->token = subflow->token;
 		pr_debug("msk=%p, token=%u", msk, msk->token);
+		msk->dport = ntohs(inet_sk(msk->subflow->sk)->inet_dport);
+		pr_debug("dport=%d", msk->dport);

Very minor nit, I think that the previous debug message can be merged into this one.

Quoted 27 lines
net/mptcp/protocol.c +23 -0
@@ -195,6 +212,50 @@ static void subflow_data_ready(struct sock *sk)
 	}
 }
 
+int subflow_connect(struct sock *sk, struct sockaddr_in *local,
+		    struct sockaddr_in *remote, u8 remote_id)
+{
+	struct mptcp_sock *msk = mptcp_sk(sk);
+	struct subflow_context *subflow;
+	struct socket *sf;
+	u32 token;
+	int err;
+
+	err = subflow_create_socket(sk, &sf);
+	if (err)
+		return err;
+
+	err = kernel_bind(sf, (struct sockaddr *)local,
+			  sizeof(struct sockaddr_in));
+	if (err) {
+		pr_debug("bind err=%d", err);
+		goto failed;
+	}
+
+	subflow = subflow_ctx(sf->sk);
+	subflow->remote_key = msk->remote_key;
+	subflow->local_key = msk->local_key;

net/mptcp/protocol.c static void subflow_data_ready(struct sock *sk) · line 247

Quoted 10 lines
net/mptcp/protocol.c +10 -0
+	crypto_key_sha1(msk->remote_key, &token, NULL);
+	pr_debug("msk=%p token=%u", msk, token);
+	subflow->token = token;
+	subflow->remote_id = remote_id;
+	subflow->request_join = 1;
+	subflow->request_bkup = 1;
+
+	err = kernel_connect(sf, (struct sockaddr *)remote,
+			     sizeof(struct sockaddr_in), O_NONBLOCK);
+	if (err && err != -EINPROGRESS) {

AFAICS, the 'sf' should not have the nonblocking flag set, to we should not ever hit the EINPROGRESS condition. I think we should avoid this check.

If we are going to support non blocking connect, should we return the INPROGRESS code instead ?

net/mptcp/protocol.c static void subflow_data_ready(struct sock *sk) · line 255

Quoted 8 lines
net/mptcp/protocol.c +8 -0
+		pr_debug("connect err=%d", err);
+		goto failed;
+	}
+
+	return 0;
+
+failed:
+	/* @@ cleanup the socket */

Yep ;)

/P

author
#18 lore raw

Re: [MPTCP] [PATCH v2 08/10] mptcp: Add handling of outgoing MP_JOIN requests

Quoted 5 lines · Paolo Abeni

Hi,

I have a couple of minor comments below.

On Thu, 2019-07-25 at 18:58 -0700, Peter Krystad wrote:

Quoted 13 lines

net/mptcp/protocol.c void mptcp_finish_connect(struct sock *sk, int mp_capable) · line 801

Quoted 10 lines
net/mptcp/protocol.c +2 -0
index 4d4a9c3d25c4..67a93ab709f1 100644
@@ -797,6 +797,8 @@ void mptcp_finish_connect(struct sock *sk, int mp_capable)
 		msk->local_key = subflow->local_key;
 		msk->token = subflow->token;
 		pr_debug("msk=%p, token=%u", msk, msk->token);
+		msk->dport = ntohs(inet_sk(msk->subflow->sk)->inet_dport);
+		pr_debug("dport=%d", msk->dport);

Very minor nit, I think that the previous debug message can be merged into this one.

I'll just remove it.

Quoted 34 lines
Quoted 34 lines
net/mptcp/protocol.c +29 -0
@@ -195,6 +212,50 @@ static void subflow_data_ready(struct sock *sk)
 	}
 }
 
+int subflow_connect(struct sock *sk, struct sockaddr_in *local,
+		    struct sockaddr_in *remote, u8 remote_id)
+{
+	struct mptcp_sock *msk = mptcp_sk(sk);
+	struct subflow_context *subflow;
+	struct socket *sf;
+	u32 token;
+	int err;
+
+	err = subflow_create_socket(sk, &sf);
+	if (err)
+		return err;
+
+	err = kernel_bind(sf, (struct sockaddr *)local,
+			  sizeof(struct sockaddr_in));
+	if (err) {
+		pr_debug("bind err=%d", err);
+		goto failed;
+	}
+
+	subflow = subflow_ctx(sf->sk);
+	subflow->remote_key = msk->remote_key;
+	subflow->local_key = msk->local_key;
+	crypto_key_sha1(msk->remote_key, &token, NULL);
+	pr_debug("msk=%p token=%u", msk, token);
+	subflow->token = token;
+	subflow->remote_id = remote_id;
+	subflow->request_join = 1;
+	subflow->request_bkup = 1;
Quoted 8 lines

net/mptcp/protocol.c static void subflow_data_ready(struct sock *sk) · line 247

Quoted 4 lines
net/mptcp/protocol.c +4 -0
+
+	err = kernel_connect(sf, (struct sockaddr *)remote,
+			     sizeof(struct sockaddr_in), O_NONBLOCK);
+	if (err && err != -EINPROGRESS) {

AFAICS, the 'sf' should not have the nonblocking flag set, to we should not ever hit the EINPROGRESS condition. I think we should avoid this check.

We're passing the NONBLOCK flag right here in the call to kernel_connect(). Maybe there is something I don't understand, what is the reason not to use non-blocking?

Quoted 3 lines

If we are going to support non blocking connect, should we return the INPROGRESS code instead ?

That makes sense, will do, pending discussion of support non-blocking.

Quoted 11 lines

net/mptcp/protocol.c static void subflow_data_ready(struct sock *sk) · line 255

Quoted 8 lines
net/mptcp/protocol.c +8 -0
+		pr_debug("connect err=%d", err);
+		goto failed;
+	}
+
+	return 0;
+
+failed:
+	/* @@ cleanup the socket */

Yep ;)

Ok, Ok.

Peter.

Quoted 2 lines

/P

#19 lore raw

Re: [MPTCP] [PATCH v2 08/10] mptcp: Add handling of outgoing MP_JOIN requests

Quoted 43 lines · Peter Krystad
Quoted 33 lines · Paolo Abeni
(quoted diff) +0 -0
@@ -195,6 +212,50 @@ static void subflow_data_ready(struct sock *sk)
 >  	}
 >  }
Quoted 30 lines
net/mptcp/subflow.c +29 -0
+int subflow_connect(struct sock *sk, struct sockaddr_in *local,
+		    struct sockaddr_in *remote, u8 remote_id)
+{
+	struct mptcp_sock *msk = mptcp_sk(sk);
+	struct subflow_context *subflow;
+	struct socket *sf;
+	u32 token;
+	int err;
+
+	err = subflow_create_socket(sk, &sf);
+	if (err)
+		return err;
+
+	err = kernel_bind(sf, (struct sockaddr *)local,
+			  sizeof(struct sockaddr_in));
+	if (err) {
+		pr_debug("bind err=%d", err);
+		goto failed;
+	}
+
+	subflow = subflow_ctx(sf->sk);
+	subflow->remote_key = msk->remote_key;
+	subflow->local_key = msk->local_key;
+	crypto_key_sha1(msk->remote_key, &token, NULL);
+	pr_debug("msk=%p token=%u", msk, token);
+	subflow->token = token;
+	subflow->remote_id = remote_id;
+	subflow->request_join = 1;
+	subflow->request_bkup = 1;
Quoted 8 lines

net/mptcp/subflow.c static void subflow_data_ready(struct sock *sk) · line 247

Quoted 4 lines
net/mptcp/subflow.c +4 -0
+
+	err = kernel_connect(sf, (struct sockaddr *)remote,
+			     sizeof(struct sockaddr_in), O_NONBLOCK);
+	if (err && err != -EINPROGRESS) {

AFAICS, the 'sf' should not have the nonblocking flag set, to we should not ever hit the EINPROGRESS condition. I think we should avoid this check.

Quoted 3 lines

We're passing the NONBLOCK flag right here in the call to kernel_connect(). Maybe there is something I don't understand, what is the reason not to use non-blocking?

Nope, sorry, just serious lack of coffee on my side. Please disregard the above comment.

Sorry for the noise,

Paolo

author
#20 lore raw

PATCH v2 9/10 Use pm_get_local_id() to get the real local address id.

In reply to Peter Krystad

squashto: Add handling of incoming MP_JOIN requests

Signed-off-by Peter Krystad <peter.krystad(a)linux.intel.com>
---
 net/mptcp/token.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
net/mptcp/token.c +9 -7
index b31d98ba5c0d..8e4da2d05f45 100644
@@ -223,13 +223,15 @@ int token_join_request(struct request_sock *req, const struct sk_buff *skb)
 	spin_lock_bh(&token_tree_lock);
 	conn = lookup_token(subflow_req->token);
 	spin_unlock_bh(&token_tree_lock);
-	if (conn) {
-		// @@ get real local address id for this skb->saddr
-		subflow_req->local_id = 0;
-		new_req_join(req, conn, skb);
-		return 0;
-	}
-	return -1;
+	if (!conn)
+		return -1;
+
+	if (pm_get_local_id(req, conn, skb))
+		return -1;
+
+	new_req_join(req, conn, skb);
+
+	return 0;
 }
 
 /* validate received truncated hmac and create hmac for third ACK */
Signature · 1 line
2.17.2
#21 lore raw

Re: [MPTCP] [PATCH v2 09/10] Use pm_get_local_id() to get the real local address id.

Quoted 15 lines · Peter Krystad
net/mptcp/token.c +0 -7
index b31d98ba5c0d..8e4da2d05f45 100644
@@ -223,13 +223,15 @@ int token_join_request(struct request_sock *req, const struct sk_buff *skb)
 	spin_lock_bh(&token_tree_lock);
 	conn = lookup_token(subflow_req->token);
 	spin_unlock_bh(&token_tree_lock);
-	if (conn) {
-		// @@ get real local address id for this skb->saddr
-		subflow_req->local_id = 0;
-		new_req_join(req, conn, skb);
-		return 0;
-	}
-	return -1;

net/mptcp/token.c int token_join_request(struct request_sock *req, const struct sk_buff *skb) · line 235

Quoted 10 lines
net/mptcp/token.c +9 -0
+	if (!conn)
+		return -1;
+
+	if (pm_get_local_id(req, conn, skb))
+		return -1;
+
+	new_req_join(req, conn, skb);
+
+	return 0;
 }

I'm sorry for the late doubt, but I think we should acquire a refcnt to conn while holding the token_tree_lock to protect vs cuncurrent shutdown of the 'conn' socket after the lookup.

Perhaps adding a new helper, alike 'token_lookup_get()' would help.

token_join_valid() has possibly the same issue.

/P

#22 lore raw

Re: [MPTCP] [PATCH v2 09/10] Use pm_get_local_id() to get the real local address id.

Quoted 1 line · Paolo Abeni

Perhaps adding a new helper, alike 'token_lookup_get()' would help.

I should have looked first at the last patch in the series.

The function 'token_lookup()' implemented in 10/10 would do.

My personal taste - notoriously not good, still - is that functions name is a little confusing. How about:

s/lookup_token/__token_lookup/

because requires leave to the caller acquiring the needed locking

s/token_lookup/token_lookup_get/

because also get a reference to the returned sock

?

author
#23 lore raw

Re: [MPTCP] [PATCH v2 09/10] Use pm_get_local_id() to get the real local address id.

Quoted 12 lines · Paolo Abeni
Quoted 1 line · Paolo Abeni

Perhaps adding a new helper, alike 'token_lookup_get()' would help.

I should have looked first at the last patch in the series.

The function 'token_lookup()' implemented in 10/10 would do.

My personal taste - notoriously not good, still - is that functions name is a little confusing. How about:

s/lookup_token/__token_lookup/

Quoted 7 lines

because requires leave to the caller acquiring the needed locking

s/token_lookup/token_lookup_get/

because also get a reference to the returned sock

?

I will rename token_lookup() from patch 10 to token_lookup_get() to reflect that it takes a reference.

I will rename the static helper 'lookup_token' to '__token_lookup' (swapping words really was a horrible bit of naming). However since this change will need to be several commits that can be squashed to different places I will submit it as a separate patchset.

Peter.

Quoted 2 lines
author
#24 lore raw

Re: [MPTCP] [PATCH v2 09/10] Use pm_get_local_id() to get the real local address id.

In reply to Paolo Abeni
Quoted 31 lines · Paolo Abeni
Quoted 15 lines · Peter Krystad
net/mptcp/token.c +0 -7
index b31d98ba5c0d..8e4da2d05f45 100644
@@ -223,13 +223,15 @@ int token_join_request(struct request_sock *req, const struct sk_buff *skb)
 	spin_lock_bh(&token_tree_lock);
 	conn = lookup_token(subflow_req->token);
 	spin_unlock_bh(&token_tree_lock);
-	if (conn) {
-		// @@ get real local address id for this skb->saddr
-		subflow_req->local_id = 0;
-		new_req_join(req, conn, skb);
-		return 0;
-	}
-	return -1;

net/mptcp/token.c int token_join_request(struct request_sock *req, const struct sk_buff *skb) · line 235

Quoted 10 lines
net/mptcp/token.c +9 -0
+	if (!conn)
+		return -1;
+
+	if (pm_get_local_id(req, conn, skb))
+		return -1;
+
+	new_req_join(req, conn, skb);
+
+	return 0;
 }

I'm sorry for the late doubt, but I think we should acquire a refcnt to conn while holding the token_tree_lock to protect vs cuncurrent shutdown of the 'conn' socket after the lookup.

Quoted 1 line

Perhaps adding a new helper, alike 'token_lookup_get()' would help.

Agreed will add taking this reference.

Quoted 1 line

token_join_valid() has possibly the same issue.

Agreed will do it here too.

Peter.

Quoted 3 lines

/P

author
#25 lore raw

PATCH v2 10/10 mptcp: Implement path manager interface commands

In reply to Peter Krystad

Use the addr_signal flag to indicate to the subflow layer that a local address may be announced, and call subflow_connect() to initiate a secondary subflow.

Signed-off-by Peter Krystad <peter.krystad(a)linux.intel.com>
---
 net/mptcp/pm.c       | 62 +++++++++++++++++++++++++++++++++++++++++---
 net/mptcp/protocol.h |  1 +
 net/mptcp/token.c    | 13 ++++++++++
 3 files changed, 73 insertions(+), 3 deletions(-)
net/mptcp/pm.c +59 -3
index b51cab3809c9..ccfc72d02b2f 100644
@@ -13,17 +13,73 @@
 int pm_announce_addr(u32 token, sa_family_t family, u8 local_id,
 		     struct in_addr *addr)
 {
-	return -ENOTSUPP;
+	struct mptcp_sock *msk = mptcp_sk(token_lookup(token));
+	int err = 0;
+
+	if (!msk)
+		return -EINVAL;
+
+	if (msk->pm.local_valid) {
+		err = -EBADR;
+		goto announce_put;
+	}
+
+	pr_debug("msk=%p, local_id=%d, addr=%x", msk, local_id, addr->s_addr);
+	msk->pm.local_valid = 1;
+	msk->pm.local_id = local_id;
+	msk->pm.local_family = family;
+	msk->pm.local_addr.s_addr = addr->s_addr;
+	msk->addr_signal = 1;
+
+announce_put:
+	sock_put((struct sock *)msk);
+	return err;
 }
 
 int pm_remove_addr(u32 token, u8 local_id)
 {
-	return -ENOTSUPP;
+	struct mptcp_sock *msk = mptcp_sk(token_lookup(token));
+
+	if (!msk)
+		return -EINVAL;
+
+	pr_debug("msk=%p", msk);
+	msk->pm.local_valid = 0;
+
+	sock_put((struct sock *)msk);
+	return 0;
 }
 
 int pm_create_subflow(u32 token, u8 remote_id)
 {
-	return -ENOTSUPP;
+	struct mptcp_sock *msk = mptcp_sk(token_lookup(token));
+	struct sockaddr_in remote;
+	struct sockaddr_in local;
+	int err;
+
+	if (!msk)
+		return -EINVAL;
+
+	pr_debug("msk=%p", msk);
+
+	if (!msk->pm.remote_valid || remote_id != msk->pm.remote_id) {
+		err = -EBADR;
+		goto create_put;
+	}
+
+	local.sin_family = AF_INET;
+	local.sin_port = 0;
+	local.sin_addr.s_addr = INADDR_ANY;
+
+	remote.sin_family = msk->pm.remote_family;
+	remote.sin_port = htons(msk->dport);
+	remote.sin_addr.s_addr = htonl(msk->pm.remote_addr.s_addr);
+
+	err = subflow_connect((struct sock *)msk, &local, &remote, remote_id);
+
+create_put:
+	sock_put((struct sock *)msk);
+	return err;
 }
 
 int pm_remove_subflow(u32 token, u8 remote_id)
net/mptcp/protocol.h +1 -0
index b40e99ebca52..d4233d4edb9b 100644
@@ -233,6 +233,7 @@ void token_new_subflow(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);
+struct sock *token_lookup(u32 token);
 void token_release(u32 token);
 void token_destroy(u32 token);
 
net/mptcp/token.c +13 -0
index 8e4da2d05f45..d7d81bb2e1c2 100644
@@ -330,6 +330,19 @@ int token_new_join(struct sock *sk)
 	return -1;
 }
 
+struct sock *token_lookup(u32 token)
+{
+	struct sock *conn;
+
+	spin_lock_bh(&token_tree_lock);
+	conn = lookup_token(token);
+	if (conn)
+		sock_hold(conn);
+
+	spin_unlock_bh(&token_tree_lock);
+	return conn;
+}
+
 void token_destroy_request(u32 token)
 {
 	pr_debug("token=%u", token);
Signature · 1 line
2.17.2