From: Matthieu Baerts <matthieu.baerts@tessares.net>
To: mptcp@lists.linux.dev
Cc: Florian Westphal <fw@strlen.de>
Subject: [RESEND] [MPTCP] [PATCH MPTCP 5/5] mptcp: send fastclose if userspace closes socket with unread data
Date: Wed, 26 May 2021 18:08:10 +0200 [thread overview]
Message-ID: <20201105170126.5627-6-fw@strlen.de> (raw)
Message-ID: <20210526160810.AQGZaK36PMDV5E686aHcYoQ1voldKfI3QvSTKQR_3rw@z> (raw)
In-Reply-To: <20210526160813.4160315-1-matthieu.baerts@tessares.net>
From: Florian Westphal <fw@strlen.de>
Add building & sending of FASTCLOSE option.
RFC 8684 describes two methods:
A): Host sends an ACK containing the MP_FASTCLOSE
option on one subflow [..] On all the other subflows,
Host A sends a regular TCP RST to close these subflows and tears
them down. [..]
R): Host A sends a RST containing the MP_FASTCLOSE option on all
subflows [..]. Host A can tear down the subflows and the
connection immediately.
This implements option R) only: All subflows are re-set with FASTCLOSE.
Signed-off-by: Florian Westphal <fw@strlen.de>
---
net/mptcp/options.c | 35 +++++++++++++++++++++++++++++++++++
net/mptcp/protocol.c | 32 +++++++++++++++++++++++++++++++-
net/mptcp/protocol.h | 1 +
3 files changed, 67 insertions(+), 1 deletion(-)
diff --git a/net/mptcp/options.c b/net/mptcp/options.c
index 0a940687f738..08b60d527de0 100644
--- a/net/mptcp/options.c
+++ b/net/mptcp/options.c
@@ -681,6 +681,31 @@ static bool mptcp_established_options_rm_addr(struct sock *sk,
return true;
}
+static bool mptcp_fastclose(const struct mptcp_sock *msk)
+{
+ return READ_ONCE(msk->snd_fastclose);
+}
+
+static bool mptcp_established_options_fastclose(struct sock *sk,
+ unsigned int *size,
+ unsigned int remaining,
+ struct mptcp_out_options *opts)
+{
+ const struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
+
+ if (likely(!mptcp_fastclose(mptcp_sk(subflow->conn))))
+ return false;
+
+ if (remaining < TCPOLEN_MPTCP_FASTCLOSE)
+ return false;
+
+ *size = TCPOLEN_MPTCP_FASTCLOSE;
+ opts->suboptions |= OPTION_MPTCP_FASTCLOSE;
+ opts->rcvr_key = subflow->remote_key;
+
+ return true;
+}
+
static noinline void mptcp_established_options_rst(struct sock *sk, struct sk_buff *skb,
unsigned int *size,
unsigned int remaining,
@@ -691,6 +716,9 @@ static noinline void mptcp_established_options_rst(struct sock *sk, struct sk_bu
if (remaining < TCPOLEN_MPTCP_RST)
return;
+ if (mptcp_established_options_fastclose(sk, size, remaining, opts))
+ return;
+
*size = TCPOLEN_MPTCP_RST;
opts->suboptions |= OPTION_MPTCP_RST;
opts->reset_transient = subflow->reset_transient;
@@ -1179,6 +1207,13 @@ void mptcp_write_options(__be32 *ptr, const struct tcp_sock *tp,
ptr += 5;
}
+ if (OPTION_MPTCP_FASTCLOSE & opts->suboptions) {
+ *ptr++ = mptcp_option(MPTCPOPT_MP_FASTCLOSE,
+ TCPOLEN_MPTCP_FASTCLOSE, 0, 0);
+ put_unaligned_be64(opts->rcvr_key, ptr);
+ ptr += 2;
+ }
+
if (OPTION_MPTCP_RST & opts->suboptions)
*ptr++ = mptcp_option(MPTCPOPT_RST,
TCPOLEN_MPTCP_RST,
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index 7e9705943813..6b6efa00cad5 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -2133,6 +2133,29 @@ static void __mptcp_check_send_data_fin(struct sock *sk)
}
}
+static void __mptcp_send_fastclose(struct sock *sk)
+{
+ struct mptcp_subflow_context *subflow, *tmp;
+ struct mptcp_sock *msk = mptcp_sk(sk);
+
+ WRITE_ONCE(msk->snd_fastclose, true);
+
+ __mptcp_flush_join_list(msk);
+ __mptcp_clear_xmit(sk);
+
+ WRITE_ONCE(msk->snd_nxt, msk->write_seq);
+
+ list_for_each_entry_safe(subflow, tmp, &msk->conn_list, node) {
+ struct sock *tcp_sk = mptcp_subflow_tcp_sock(subflow);
+
+ lock_sock(tcp_sk);
+ subflow->reset_transient = 0;
+ subflow->reset_reason = MPTCP_RST_EMPTCP;
+ mptcp_subflow_reset(tcp_sk);
+ release_sock(tcp_sk);
+ }
+}
+
static void __mptcp_wr_shutdown(struct sock *sk)
{
struct mptcp_sock *msk = mptcp_sk(sk);
@@ -2185,6 +2208,7 @@ static void mptcp_close(struct sock *sk, long timeout)
{
struct mptcp_subflow_context *subflow;
bool do_cancel_work = false;
+ bool send_fin = false;
lock_sock(sk);
sk->sk_shutdown = SHUTDOWN_MASK;
@@ -2197,7 +2221,13 @@ static void mptcp_close(struct sock *sk, long timeout)
goto cleanup;
}
- if (mptcp_close_state(sk))
+ send_fin = mptcp_close_state(sk);
+ if (!skb_queue_empty(&sk->sk_receive_queue)) {
+ __mptcp_send_fastclose(sk);
+ send_fin = false;
+ }
+
+ if (send_fin)
__mptcp_wr_shutdown(sk);
sk_stream_wait_close(sk, timeout);
diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
index d4c99e091cb9..93352044bff9 100644
--- a/net/mptcp/protocol.h
+++ b/net/mptcp/protocol.h
@@ -243,6 +243,7 @@ struct mptcp_sock {
bool fully_established;
bool rcv_data_fin;
bool snd_data_fin_enable;
+ bool snd_fastclose;
bool rcv_fastclose;
bool use_64bit_ack; /* Set when we received a 64-bit DSN */
spinlock_t join_list_lock;
next prev parent reply other threads:[~2021-05-26 16:08 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-26 16:08 [RESEND] [PATCH 0/8] Please ignore: resending some patches for patchwork.kernel.org Matthieu Baerts
2020-09-24 14:35 ` [MPTCP] [RFC PATCH 2/4] tcp: move selected mptcp helpers to tcp.h/mptcp.h Florian Westphal
2021-05-26 16:08 ` [RESEND] " Matthieu Baerts
2020-09-24 14:35 ` [MPTCP] [RFC PATCH 4/4] tcp: parse tcp options contained in reset packets Florian Westphal
2021-05-26 16:08 ` [RESEND] " Matthieu Baerts
2020-10-02 15:45 ` [MPTCP] [RFC mptpcp-next] mptcp: add ooo prune support Florian Westphal
2021-05-26 16:08 ` [RESEND] " Matthieu Baerts
2020-11-05 17:01 ` [MPTCP] [PATCH MPTCP 1/5] tcp: make two mptcp helpers available to tcp stack Florian Westphal
2021-05-26 16:08 ` [RESEND] " Matthieu Baerts
2020-11-05 17:01 ` Florian Westphal [this message]
2021-05-26 16:08 ` [RESEND] [MPTCP] [PATCH MPTCP 5/5] mptcp: send fastclose if userspace closes socket with unread data Matthieu Baerts
-- strict thread matches above, loose matches on Subject: below --
2021-05-06 6:39 [MPTCP][PATCH mptcp-next 0/3] MP_FAIL support Geliang Tang
2021-05-06 6:39 ` [MPTCP][PATCH mptcp-next 1/3] mptcp: MP_FAIL suboption sending Geliang Tang
2021-05-06 6:39 ` [MPTCP][PATCH mptcp-next 2/3] mptcp: MP_FAIL suboption receiving Geliang Tang
2021-05-06 6:39 ` [MPTCP][PATCH mptcp-next 3/3] mptcp: send out MP_FAIL when data checksum fail Geliang Tang
2021-05-08 0:54 ` Mat Martineau
2021-05-26 16:08 ` [RESEND] " Matthieu Baerts
2021-05-08 0:44 ` [MPTCP][PATCH mptcp-next 2/3] mptcp: MP_FAIL suboption receiving Mat Martineau
2021-05-26 16:08 ` [RESEND] " Matthieu Baerts
2021-05-26 16:08 ` [RESEND] [MPTCP][PATCH mptcp-next 1/3] mptcp: MP_FAIL suboption sending Matthieu Baerts
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201105170126.5627-6-fw@strlen.de \
--to=matthieu.baerts@tessares.net \
--cc=fw@strlen.de \
--cc=mptcp@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).