Skip to contentSkip to conversation

DATA_FIN fixes proposed for net tree

PATCH In review Mat Martineau 2 participants 6 messages Feb 28, 2020

Subsystems (2)
lore
Share & tools
lore

Mat Martineau

author
#0 lore raw

cover DATA_FIN fixes proposed for net tree

More changes are needed for multi-subflow DATA_FIN support, but these fixes may be worth applying to the 5.6 tree for single subflow. Self tests pass, and I checked the headers with DATA_FIN for both the DATA_FIN-only DSS option and packet with a full mapping and DATA_FIN.

I'll send to netdev following review on this list.

RFC -> v1: Rebased on current net tree

Mat Martineau (3):
mptcp: Check connection state before attempting send
mptcp: Use per-subflow storage for DATA_FIN sequence number
mptcp: Only send DATA_FIN with final mapping

 net/mptcp/options.c  | 16 ++++++++--------
 net/mptcp/protocol.c | 32 +++++++++++++++++++++++++++-----
 net/mptcp/protocol.h |  2 ++
 3 files changed, 37 insertions(+), 13 deletions(-)

base-commit: 3ee339eb28959629db33aaa2b8cde4c63c6289eb

Signature · 1 line
2.25.1
author
#1 lore raw

PATCH 1/3 mptcp: Check connection state before attempting send

MPTCP should wait for an active connection or skip sending depending on the connection state, as TCP does. This happens before the possible passthrough to a regular TCP sendmsg because the subflow's socket type (MPTCP or TCP fallback) is not known until the connection is complete.

Signed-off-by Mat Martineau <mathew.j.martineau(a)linux.intel.com>
---
 net/mptcp/protocol.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
net/mptcp/protocol.c +10 -2
index 3c19a8efdcea..42a3160fae51 100644
@@ -278,6 +278,15 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
 		return -EOPNOTSUPP;
 
 	lock_sock(sk);
+
+	timeo = sock_sndtimeo(sk, msg->msg_flags & MSG_DONTWAIT);
+
+	if ((1 << sk->sk_state) & ~(TCPF_ESTABLISHED | TCPF_CLOSE_WAIT)) {
+		ret = sk_stream_wait_connect(sk, &timeo);
+		if (ret)
+			goto out;
+	}
+
 	ssock = __mptcp_tcp_fallback(msk);
 	if (unlikely(ssock)) {
 fallback:
@@ -286,8 +295,6 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
 		return ret >= 0 ? ret + copied : (copied ? copied : ret);
 	}
 
-	timeo = sock_sndtimeo(sk, msg->msg_flags & MSG_DONTWAIT);
-
 	ssk = mptcp_subflow_get(msk);
 	if (!ssk) {
 		release_sock(sk);
@@ -319,6 +326,7 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
 
 	ssk_check_wmem(msk, ssk);
 	release_sock(ssk);
+out:
 	release_sock(sk);
 	return ret;
 }
Signature · 1 line
2.25.1
author
#2 lore raw

PATCH 2/3 mptcp: Use per-subflow storage for DATA_FIN sequence number

In reply to Mat Martineau

Instead of reading the MPTCP-level sequence number when sending DATA_FIN, store the data in the subflow so it can be safely accessed when the subflow TCP headers are written to the packet without the MPTCP-level lock held. This also allows the MPTCP-level socket to close individual subflows without closing the MPTCP connection.

Signed-off-by Mat Martineau <mathew.j.martineau(a)linux.intel.com>
---
 net/mptcp/options.c  |  5 ++---
 net/mptcp/protocol.c | 20 +++++++++++++++++---
 net/mptcp/protocol.h |  2 ++
 3 files changed, 21 insertions(+), 6 deletions(-)
net/mptcp/options.c +2 -3
index 45acd877bef3..90c81953ec2c 100644
@@ -312,7 +312,7 @@ static void mptcp_write_data_fin(struct mptcp_subflow_context *subflow,
 		 */
 		ext->use_map = 1;
 		ext->dsn64 = 1;
-		ext->data_seq = mptcp_sk(subflow->conn)->write_seq;
+		ext->data_seq = subflow->data_fin_tx_seq;
 		ext->subflow_seq = 0;
 		ext->data_len = 1;
 	} else {
@@ -354,8 +354,7 @@ static bool mptcp_established_options_dss(struct sock *sk, struct sk_buff *skb,
 		if (mpext)
 			opts->ext_copy = *mpext;
 
-		if (skb && tcp_fin &&
-		    subflow->conn->sk_state != TCP_ESTABLISHED)
+		if (skb && tcp_fin && subflow->data_fin_tx_enable)
 			mptcp_write_data_fin(subflow, &opts->ext_copy);
 		ret = true;
 	}
net/mptcp/protocol.c +17 -3
index 42a3160fae51..c319da349a20 100644
@@ -577,7 +577,8 @@ static int mptcp_init_sock(struct sock *sk)
 	return __mptcp_init_sock(sk);
 }
 
-static void mptcp_subflow_shutdown(struct sock *ssk, int how)
+static void mptcp_subflow_shutdown(struct sock *ssk, int how,
+				   bool data_fin_tx_enable, u64 data_fin_tx_seq)
 {
 	lock_sock(ssk);
 
@@ -590,6 +591,14 @@ static void mptcp_subflow_shutdown(struct sock *ssk, int how)
 		tcp_disconnect(ssk, O_NONBLOCK);
 		break;
 	default:
+		if (data_fin_tx_enable) {
+			struct mptcp_subflow_context *subflow;
+
+			subflow = mptcp_subflow_ctx(ssk);
+			subflow->data_fin_tx_seq = data_fin_tx_seq;
+			subflow->data_fin_tx_enable = 1;
+		}
+
 		ssk->sk_shutdown |= how;
 		tcp_shutdown(ssk, how);
 		break;
@@ -606,6 +615,7 @@ static void mptcp_close(struct sock *sk, long timeout)
 	struct mptcp_subflow_context *subflow, *tmp;
 	struct mptcp_sock *msk = mptcp_sk(sk);
 	LIST_HEAD(conn_list);
+	u64 data_fin_tx_seq;
 
 	lock_sock(sk);
 
@@ -614,11 +624,15 @@ static void mptcp_close(struct sock *sk, long timeout)
 
 	list_splice_init(&msk->conn_list, &conn_list);
 
+	data_fin_tx_seq = msk->write_seq;
+
 	release_sock(sk);
 
 	list_for_each_entry_safe(subflow, tmp, &conn_list, node) {
 		struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
 
+		subflow->data_fin_tx_seq = data_fin_tx_seq;
+		subflow->data_fin_tx_enable = 1;
 		__mptcp_close_ssk(sk, ssk, subflow, timeout);
 	}
 
@@ -707,7 +721,7 @@ static struct sock *mptcp_accept(struct sock *sk, int flags, int *err,
 			*err = -ENOBUFS;
 			local_bh_enable();
 			release_sock(sk);
-			mptcp_subflow_shutdown(newsk, SHUT_RDWR + 1);
+			mptcp_subflow_shutdown(newsk, SHUT_RDWR + 1, 0, 0);
 			tcp_close(newsk, 0);
 			return NULL;
 		}
@@ -1135,7 +1149,7 @@ static int mptcp_shutdown(struct socket *sock, int how)
 	mptcp_for_each_subflow(msk, subflow) {
 		struct sock *tcp_sk = mptcp_subflow_tcp_sock(subflow);
 
-		mptcp_subflow_shutdown(tcp_sk, how);
+		mptcp_subflow_shutdown(tcp_sk, how, 1, msk->write_seq);
 	}
 
 out_unlock:
net/mptcp/protocol.h +2 -0
index 9f8663b30456..82e3dfb191fe 100644
@@ -124,7 +124,9 @@ struct mptcp_subflow_context {
 		mpc_map : 1,
 		data_avail : 1,
 		rx_eof : 1,
+		data_fin_tx_enable : 1,
 		can_ack : 1;	    /* only after processing the remote a key */
+	u64	data_fin_tx_seq;
 
 	struct	sock *tcp_sock;	    /* tcp sk backpointer */
 	struct	sock *conn;	    /* parent mptcp_sock */
Signature · 1 line
2.25.1
author
#3 lore raw

PATCH 3/3 mptcp: Only send DATA_FIN with final mapping

In reply to Mat Martineau

When a DATA_FIN is sent in a MPTCP DSS option that contains a data mapping, the DATA_FIN consumes one byte of space in the mapping. In this case, the DATA_FIN should only be included in the DSS option if its sequence number aligns with the end of the mapped data. Otherwise the subflow can send an incorrect implicit sequence number for the DATA_FIN, and the DATA_ACK for that sequence number would not close the MPTCP-level connection correctly.

Signed-off-by Mat Martineau <mathew.j.martineau(a)linux.intel.com>
---
 net/mptcp/options.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
net/mptcp/options.c +6 -5
index 90c81953ec2c..b9a8305bd934 100644
@@ -304,21 +304,22 @@ static bool mptcp_established_options_mp(struct sock *sk, struct sk_buff *skb,
 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->data_fin = 1;
 		ext->use_map = 1;
 		ext->dsn64 = 1;
 		ext->data_seq = subflow->data_fin_tx_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.
+	} else if (ext->data_seq + ext->data_len == subflow->data_fin_tx_seq) {
+		/* If there's an existing DSS mapping and it is the
+		 * final mapping, DATA_FIN consumes 1 additional byte of
+		 * mapping space.
 		 */
+		ext->data_fin = 1;
 		ext->data_len++;
 	}
 }
Signature · 1 line
2.25.1
#4 lore raw
In reply to Mat Martineau
Quoted 14 lines · Mat Martineau

More changes are needed for multi-subflow DATA_FIN support, but these fixes may be worth applying to the 5.6 tree for single subflow. Self tests pass, and I checked the headers with DATA_FIN for both the DATA_FIN-only DSS option and packet with a full mapping and DATA_FIN.

I'll send to netdev following review on this list.

RFC -> v1: Rebased on current net tree

Mat Martineau (3):
mptcp: Check connection state before attempting send
mptcp: Use per-subflow storage for DATA_FIN sequence number
mptcp: Only send DATA_FIN with final mapping

Quoted 7 lines
 net/mptcp/options.c  | 16 ++++++++--------
 net/mptcp/protocol.c | 32 +++++++++++++++++++++++++++-----
 net/mptcp/protocol.h |  2 ++
 3 files changed, 37 insertions(+), 13 deletions(-)

base-commit: 3ee339eb28959629db33aaa2b8cde4c63c6289eb

The patches look good ot me.

On patch 2/3 we likely want to replace:

	mptcp_subflow_shutdown(newsk, SHUT_RDWR + 1, 0, 0);

with a FAST_CLOSE, but first we have to support/implement that:)

My understanding is that there a pending quesiton on the git tree these patches should target. I think net-next is more suitable than -net, as this is somewhat relevant change of data_fin handling.

Cheers,

Paolo

author
#5 lore raw
Quoted 27 lines · Paolo Abeni
Quoted 14 lines · Mat Martineau

More changes are needed for multi-subflow DATA_FIN support, but these fixes may be worth applying to the 5.6 tree for single subflow. Self tests pass, and I checked the headers with DATA_FIN for both the DATA_FIN-only DSS option and packet with a full mapping and DATA_FIN.

I'll send to netdev following review on this list.

RFC -> v1: Rebased on current net tree

Mat Martineau (3):
mptcp: Check connection state before attempting send
mptcp: Use per-subflow storage for DATA_FIN sequence number
mptcp: Only send DATA_FIN with final mapping

Quoted 7 lines
 net/mptcp/options.c  | 16 ++++++++--------
 net/mptcp/protocol.c | 32 +++++++++++++++++++++++++++-----
 net/mptcp/protocol.h |  2 ++
 3 files changed, 37 insertions(+), 13 deletions(-)

base-commit: 3ee339eb28959629db33aaa2b8cde4c63c6289eb

The patches look good ot me.

On patch 2/3 we likely want to replace:

Quoted 7 lines
	mptcp_subflow_shutdown(newsk, SHUT_RDWR + 1, 0, 0);

with a FAST_CLOSE, but first we have to support/implement that:)

My understanding is that there a pending quesiton on the git tree these patches should target. I think net-next is more suitable than -net, as this is somewhat relevant change of data_fin handling.

I can bring these patches back to the development branch if that's what works better. I do think of these as bug fixes, but for single subflow they are corner cases for sure - and there's also some chance of creating some merge conflicts with net-next or our branch if merged to -net, so net-next/mptcp_net-next is fine.

I'll rebase on the updated export branch and post again.

Thanks,

--
Mat Martineau
Intel