Skip to contentSkip to conversation

mptcp: Basic single-subflow DATA_FIN

PATCH In review Mat Martineau 4 participants 5 messages Nov 22, 2019 – Dec 4, 2019

Subsystems (2)
lore
Share & tools
lore

Mat Martineau

author
#0 lore raw

PATCH v3 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>

---

The DATA_FIN ack patch (would have been a 2nd patch after this) isn't quite working yet, but I wanted to share the sending patch since there was a minor conflict after some recent squashing. I also confirmed that this applies cleanly after the kselftest patch for "part 1", and that the self tests pass.

Changes from v2:
* Rebased and confirmed selftests when cherry-picked to the end of the "part 1" (single-subflow) chunk of the patch series.

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  | 38 ++++++++++++++++++++++++++++++++++++--
 net/mptcp/protocol.c |  4 ++++
 net/mptcp/subflow.c  | 42 ++++++++++++++++++++++++++++--------------
 3 files changed, 68 insertions(+), 16 deletions(-)
net/mptcp/options.c +36 -2
index 644c30d46922..be180c4f71a4 100644
@@ -286,19 +286,49 @@ 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;
 	struct mptcp_sock *msk;
 	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;
@@ -307,6 +337,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);
 	}
 
 	ack_size = TCPOLEN_MPTCP_DSS_ACK64;
net/mptcp/protocol.c +4 -0
index 9b384da910ce..f95a3f824a18 100644
@@ -919,6 +919,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

73 lines not on this page · raw message

Signature · 1 line
2.24.0
#1 lore raw
Quoted 4 lines · Mat Martineau

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>

The patch LGTM, thanks!

Paolo

#2 lore raw

Hi Mat, Paolo,

Quoted 7 lines · Paolo Abeni
Quoted 4 lines · Mat Martineau

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>

The patch LGTM, thanks!

Thank you for the new version and the review!

Where can I apply it? I would like to apply it just before the introduction of the kselftests but please tell me if it is better to squash it / apply it somewhere else.

Cheers,
Matt

Signature · 5 lines
Matthieu Baerts | R&D Engineer
matthieu.baerts(a)tessares.net
Tessares SA | Hybrid Access Solutions
www.tessares.net
1 Avenue Jean Monnet, 1348 Louvain-la-Neuve, Belgium
#3 lore raw

Hi Matt -

Quoted 9 lines · Matthieu Baerts

Hi Mat, Paolo,

Quoted 6 lines · Paolo Abeni
Quoted 4 lines · Mat Martineau

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>
Quoted 7 lines
Quoted 1 line

The patch LGTM, thanks!

Thank you for the new version and the review!

Where can I apply it? I would like to apply it just before the introduction of the kselftests but please tell me if it is better to squash it / apply it somewhere else.

Mat is out this week. I've checked that the changes to options.c and protocol.c can be squashed to 'Write MPTCP DSS headers to outgoing data packets' and the changes to subflow.c squash to 'Implement MPTCP receive path'.

Peter.

Quoted 2 lines

Cheers,
Matt

#4 lore raw

Hi Mat, Paolo, Peter,

Quoted 17 lines · Peter Krystad

Hi Matt -

Quoted 13 lines · Matthieu Baerts

Hi Mat, Paolo,

Quoted 7 lines · Paolo Abeni
Quoted 4 lines · Mat Martineau

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>

The patch LGTM, thanks!

Thank you for the new version and the review!

Quoted 8 lines
Quoted 3 lines

Where can I apply it? I would like to apply it just before the introduction of the kselftests but please tell me if it is better to squash it / apply it somewhere else.

Mat is out this week. I've checked that the changes to options.c and protocol.c can be squashed to 'Write MPTCP DSS headers to outgoing data packets' and the changes to subflow.c squash to 'Implement MPTCP receive path'.

Thank you again for the patch, the reviews and the instructions!

Sorry for the delay. I feel bad because I was suspecting conflicts with other commits of the series but there was no conflict at all!

- 825f10f90667: "squashed" in "mptcp: Write MPTCP DSS headers to outgoing data packets"
- 7a9b711a86ee: "squashed" in "mptcp: Implement MPTCP receive path"
- bcf60b29e527..b887804d061e: result

Each commit still compiles and tests are still passing!

Hopefully tomorrow, I can apply MPTCPv1 patches and all others waiting to be applied :)

Cheers,
Matt

Signature · 5 lines
Matthieu Baerts | R&D Engineer
matthieu.baerts(a)tessares.net
Tessares SA | Hybrid Access Solutions
www.tessares.net
1 Avenue Jean Monnet, 1348 Louvain-la-Neuve, Belgium