Skip to contentSkip to conversation

mptcp: Basic single-subflow DATA_FIN

PATCH Superseded Mat Martineau 2 participants 3 messages Nov 19, 2019

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Mat Martineau

author
#0 lore raw

PATCH v2 1/1 mptcp: Basic single-subflow DATA_FIN

Send a DATA_FIN along with any subflow TCP FIN flag when the MPTCP socket is closing or shutting down writes.

Signed-off-by Mat Martineau <mathew.j.martineau(a)linux.intel.com>

---

Changes from v1:

* Fixed problem with the receive side truncating data. The issue happened when a DSS mapping for DATA_FIN was found on a data segment, where the data in the packet was already covered by an earlier mapping.

* Only send DATA_FIN when the subflow is sending a FIN and the MPTCP socket is no longer in the TCP_ESTABLISHED state. This prevents sending DATA_FIN when an individual subflow is removed but the MPTCP-level connection is kept alive.

* Changes to warnings and comments suggested in code review.

net/mptcp/options.c | 40 +++++++++++++++++++++++++++++++++++++---

 net/mptcp/protocol.c |  4 ++++
 net/mptcp/subflow.c  | 42 ++++++++++++++++++++++++++++--------------
 3 files changed, 69 insertions(+), 17 deletions(-)
net/mptcp/options.c +37 -3
index 9a18a3670cdf..f8dd8b2a4785 100644
@@ -384,18 +384,48 @@ static bool mptcp_established_options_mp(struct sock *sk, unsigned int *size,
 	return false;
 }
 
+static void mptcp_write_data_fin(struct mptcp_subflow_context *subflow,
+				 struct mptcp_ext *ext)
+{
+	ext->data_fin = 1;
+
+	if (!ext->use_map) {
+		/* RFC6824 requires a DSS mapping with specific values
+		 * if DATA_FIN is set but no data payload is mapped
+		 */
+		ext->use_map = 1;
+		ext->dsn64 = 1;
+		ext->data_seq = mptcp_sk(subflow->conn)->write_seq;
+		ext->subflow_seq = 0;
+		ext->data_len = 1;
+	} else {
+		/* If there's an existing DSS mapping, DATA_FIN consumes
+		 * 1 additional byte of mapping space.
+		 */
+		ext->data_len++;
+	}
+}
+
 static bool mptcp_established_options_dss(struct sock *sk, struct sk_buff *skb,
 					  unsigned int *size,
 					  unsigned int remaining,
 					  struct mptcp_out_options *opts)
 {
+	struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
 	unsigned int dss_size = 0;
 	struct mptcp_ext *mpext;
 	unsigned int ack_size;
+	u8 tcp_fin;
 
-	mpext = skb ? mptcp_get_ext(skb) : NULL;
+	if (skb) {
+		mpext = mptcp_get_ext(skb);
+		tcp_fin = TCP_SKB_CB(skb)->tcp_flags & TCPHDR_FIN;
+	} else {
+		mpext = NULL;
+		tcp_fin = 0;
+	}
 
-	if (!skb || (mpext && mpext->use_map)) {
+	if (!skb || (mpext && mpext->use_map) || tcp_fin) {
 		unsigned int map_size;
 
 		map_size = TCPOLEN_MPTCP_DSS_BASE + TCPOLEN_MPTCP_DSS_MAP64;
@@ -405,6 +435,10 @@ static bool mptcp_established_options_dss(struct sock *sk, struct sk_buff *skb,
 			dss_size = map_size;
 			if (mpext)
 				opts->ext_copy = *mpext;
+
+			if (skb && tcp_fin &&
+			    subflow->conn->sk_state != TCP_ESTABLISHED)
+				mptcp_write_data_fin(subflow, &opts->ext_copy);
 		} else {
 			opts->ext_copy.use_map = 0;
 			WARN_ONCE(1, "MPTCP: Map dropped");
@@ -422,7 +456,7 @@ static bool mptcp_established_options_dss(struct sock *sk, struct sk_buff *skb,
 
 		dss_size += ack_size;
 
-		msk = mptcp_sk(mptcp_subflow_ctx(sk)->conn);
+		msk = mptcp_sk(subflow->conn);
 		if (msk) {
 			opts->ext_copy.data_ack = msk->ack_seq;
 		} else {
net/mptcp/protocol.c +4 -0
index 1a432abfb176..910cf26037b7 100644
@@ -1284,6 +1284,10 @@ static int mptcp_shutdown(struct socket *sock, int how)
 	pr_debug("sk=%p, how=%d", msk, how);
 
 	lock_sock(sock->sk);
+
+	if (how == SHUT_WR || how == SHUT_RDWR)
+		inet_sk_state_store(sock->sk, TCP_FIN_WAIT1);
+
 	ssock = __mptcp_fallback_get_ref(msk);
 	if (ssock) {
 		release_sock(sock->sk);
net/mptcp/subflow.c +28 -14

74 lines not on this page · raw message

Signature · 1 line
2.24.0
#1 lore raw

Hi,

I'm sorry for lagging behind with the reviews...

net/mptcp/options.c static bool mptcp_established_options_dss(struct sock *sk, struct sk_buff *skb, · line 444

Quoted 11 lines · Mat Martineau
net/mptcp/options.c +4 -0
@@ -405,6 +435,10 @@ static bool mptcp_established_options_dss(struct sock *sk, struct sk_buff *skb,
 			dss_size = map_size;
 			if (mpext)
 				opts->ext_copy = *mpext;
+
+			if (skb && tcp_fin &&
+			    subflow->conn->sk_state != TCP_ESTABLISHED)
+				mptcp_write_data_fin(subflow, &opts->ext_copy);
 		} else {
 			opts->ext_copy.use_map = 0;
 			WARN_ONCE(1, "MPTCP: Map dropped");

Don't we need some additional check to avoid sending multiple DATA_FIN on all subflows ?!? e.g. fiddling with some bit status bit on msk.

Quoted 62 lines
net/mptcp/protocol.c +4 -0
index 1a432abfb176..910cf26037b7 100644
@@ -1284,6 +1284,10 @@ static int mptcp_shutdown(struct socket *sock, int how)
 	pr_debug("sk=%p, how=%d", msk, how);
 
 	lock_sock(sock->sk);
+
+	if (how == SHUT_WR || how == SHUT_RDWR)
+		inet_sk_state_store(sock->sk, TCP_FIN_WAIT1);
+
 	ssock = __mptcp_fallback_get_ref(msk);
 	if (ssock) {
 		release_sock(sock->sk);
net/mptcp/subflow.c +12 -12
index ff38d54392cd..89e6533c97b6 100644
@@ -422,6 +422,7 @@ static enum mapping_status get_mapping_status(struct sock *ssk)
 	struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk);
 	struct mptcp_ext *mpext;
 	struct sk_buff *skb;
+	u16 data_len;
 	u64 map_seq;
 
 	skb = skb_peek(&ssk->sk_receive_queue);
@@ -446,26 +447,39 @@ static enum mapping_status get_mapping_status(struct sock *ssk)
 
 		if (!subflow->map_valid)
 			return MAPPING_INVALID;
+
 		goto validate_seq;
 	}
 
-	pr_debug("seq=%llu is64=%d ssn=%u data_len=%u", mpext->data_seq,
-		 mpext->dsn64, mpext->subflow_seq, mpext->data_len);
+	pr_debug("seq=%llu is64=%d ssn=%u data_len=%u data_fin=%d",
+		 mpext->data_seq, mpext->dsn64, mpext->subflow_seq,
+		 mpext->data_len, mpext->data_fin);
 
-	if (mpext->data_len == 0) {
+	data_len = mpext->data_len;
+	if (data_len == 0) {
 		pr_err("Infinite mapping not handled");
 		MPTCP_INC_STATS(sock_net(ssk), MPTCP_MIB_INFINITEMAPRX);
 		return MAPPING_INVALID;
-	} else if (mpext->subflow_seq == 0 &&
-		   mpext->data_fin == 1) {
-		if (WARN_ON_ONCE(mpext->data_len != 1))
-			return false;
+	}
 
-		/* do not try hard to handle this any better, till we have
-		 * real data_fin support
-		 */
-		pr_debug("DATA_FIN with no payload");
-		return MAPPING_DATA_FIN;
+	if (mpext->data_fin == 1) {
+		if (data_len == 1) {
+			pr_debug("DATA_FIN with no payload");
+			if (subflow->map_valid) {

net/mptcp/subflow.c static enum mapping_status get_mapping_status(struct sock *ssk) · line 478

Quoted 10 lines
net/mptcp/subflow.c +10 -0
+				/* A DATA_FIN might arrive in a DSS
+				 * option before the previous mapping
+				 * has been fully consumed. Continue
+				 * handling the existing mapping.
+				 */
+				skb_ext_del(skb, SKB_EXT_MPTCP);
+				return MAPPING_OK;
+			} else {
+				return MAPPING_DATA_FIN;
+			}

Can we instead:

	data_len--;
	WRITE_ONCE(msk->data_fin_set, 1);
	WRITE_ONCE(msk->data_fin_seq, mpext->data_seq + data_len);

and than in mptcp_recvmsg():

	if (READ_ONCE(msk->data_fin_seq) &&
	    msk->ack_seq == msk->data_fin_seq)
		msk->ack_seq++;

(or something along these lines)

?

Thanks,

Paolo

author
#2 lore raw
Quoted 5 lines · Paolo Abeni

Hi,

I'm sorry for lagging behind with the reviews...

On Mon, 2019-11-18 at 16:31 -0800, Mat Martineau wrote:

Quoted 14 lines

net/mptcp/options.c static bool mptcp_established_options_dss(struct sock *sk, struct sk_buff *skb, · line 444

Quoted 11 lines
net/mptcp/options.c +4 -0
@@ -405,6 +435,10 @@ static bool mptcp_established_options_dss(struct sock *sk, struct sk_buff *skb,
 			dss_size = map_size;
 			if (mpext)
 				opts->ext_copy = *mpext;
+
+			if (skb && tcp_fin &&
+			    subflow->conn->sk_state != TCP_ESTABLISHED)
+				mptcp_write_data_fin(subflow, &opts->ext_copy);
 		} else {
 			opts->ext_copy.use_map = 0;
 			WARN_ONCE(1, "MPTCP: Map dropped");

Don't we need some additional check to avoid sending multiple DATA_FIN on all subflows ?!? e.g. fiddling with some bit status bit on msk.

Sending DATA_FIN on multiple subflows is deliberate - what if one of them is not behaving well?

I ran a test between two multipath-tcp.org v0.95 kernels (VM A: 2 interfaces, VM B: 1 interface, "fullmesh" path manager on both), and it sent DATA_FIN only on one subflow. Sending on multiple subflows should be fine, right? The first DATA_FIN received will modify the MPTCP connection state (when that's implemented) so duplicate DATA_FINs can be ignored.

Quoted 81 lines
Quoted 63 lines
net/mptcp/protocol.c +4 -0
index 1a432abfb176..910cf26037b7 100644
@@ -1284,6 +1284,10 @@ static int mptcp_shutdown(struct socket *sock, int how)
 	pr_debug("sk=%p, how=%d", msk, how);
 
 	lock_sock(sock->sk);
+
+	if (how == SHUT_WR || how == SHUT_RDWR)
+		inet_sk_state_store(sock->sk, TCP_FIN_WAIT1);
+
 	ssock = __mptcp_fallback_get_ref(msk);
 	if (ssock) {
 		release_sock(sock->sk);
net/mptcp/subflow.c +12 -12
index ff38d54392cd..89e6533c97b6 100644
@@ -422,6 +422,7 @@ static enum mapping_status get_mapping_status(struct sock *ssk)
 	struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk);
 	struct mptcp_ext *mpext;
 	struct sk_buff *skb;
+	u16 data_len;
 	u64 map_seq;
 
 	skb = skb_peek(&ssk->sk_receive_queue);
@@ -446,26 +447,39 @@ static enum mapping_status get_mapping_status(struct sock *ssk)
 
 		if (!subflow->map_valid)
 			return MAPPING_INVALID;
+
 		goto validate_seq;
 	}
 
-	pr_debug("seq=%llu is64=%d ssn=%u data_len=%u", mpext->data_seq,
-		 mpext->dsn64, mpext->subflow_seq, mpext->data_len);
+	pr_debug("seq=%llu is64=%d ssn=%u data_len=%u data_fin=%d",
+		 mpext->data_seq, mpext->dsn64, mpext->subflow_seq,
+		 mpext->data_len, mpext->data_fin);
 
-	if (mpext->data_len == 0) {
+	data_len = mpext->data_len;
+	if (data_len == 0) {
 		pr_err("Infinite mapping not handled");
 		MPTCP_INC_STATS(sock_net(ssk), MPTCP_MIB_INFINITEMAPRX);
 		return MAPPING_INVALID;
-	} else if (mpext->subflow_seq == 0 &&
-		   mpext->data_fin == 1) {
-		if (WARN_ON_ONCE(mpext->data_len != 1))
-			return false;
+	}
 
-		/* do not try hard to handle this any better, till we have
-		 * real data_fin support
-		 */
-		pr_debug("DATA_FIN with no payload");
-		return MAPPING_DATA_FIN;
+	if (mpext->data_fin == 1) {
+		if (data_len == 1) {
+			pr_debug("DATA_FIN with no payload");
+			if (subflow->map_valid) {

net/mptcp/subflow.c static enum mapping_status get_mapping_status(struct sock *ssk) · line 478

Quoted 10 lines
net/mptcp/subflow.c +10 -0
+				/* A DATA_FIN might arrive in a DSS
+				 * option before the previous mapping
+				 * has been fully consumed. Continue
+				 * handling the existing mapping.
+				 */
+				skb_ext_del(skb, SKB_EXT_MPTCP);
+				return MAPPING_OK;
+			} else {
+				return MAPPING_DATA_FIN;
+			}

Can we instead:

	data_len--;
	WRITE_ONCE(msk->data_fin_set, 1);
	WRITE_ONCE(msk->data_fin_seq, mpext->data_seq + data_len);

and than in mptcp_recvmsg():

Quoted 8 lines
	if (READ_ONCE(msk->data_fin_seq) &&
	    msk->ack_seq == msk->data_fin_seq)
		msk->ack_seq++;

(or something along these lines)

?

In an earlier thread I mentioned I would get the DATA_FIN sending part finished first, then approach the ack as a second step. As you point out, it may be a small step!

--
Mat Martineau
Intel