summaryrefslogtreecommitdiffstats
path: root/net/mptcp/protocol.c
diff options
context:
space:
mode:
authorFlorian Westphal <fw@strlen.de>2020-11-16 10:48:13 +0100
committerJakub Kicinski <kuba@kernel.org>2020-11-16 10:46:07 -0800
commit6f8a612a33e426d473f7161d1950dc00a613494b (patch)
tree38d484799e333eea7da33f483219f3d9a3a41760 /net/mptcp/protocol.c
parent8edf08649eede6e5a3e39a3d38c63f30039a0c1e (diff)
downloadlinux-6f8a612a33e426d473f7161d1950dc00a613494b.tar.gz
linux-6f8a612a33e426d473f7161d1950dc00a613494b.tar.bz2
linux-6f8a612a33e426d473f7161d1950dc00a613494b.zip
mptcp: keep track of advertised windows right edge
Before sending 'x' new bytes also check that the new snd_una would be within the permitted receive window. For every ACK that also contains a DSS ack, check whether its tcp-level receive window would advance the current mptcp window right edge and update it if so. Signed-off-by: Florian Westphal <fw@strlen.de> Co-developed-by: Paolo Abeni <pabeni@redhat.com> Signed-off-by: Paolo Abeni <pabeni@redhat.com> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Diffstat (limited to 'net/mptcp/protocol.c')
-rw-r--r--net/mptcp/protocol.c49
1 files changed, 48 insertions, 1 deletions
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index 7fcd26011a3d..5a92b9239909 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -57,6 +57,12 @@ static struct socket *__mptcp_nmpc_socket(const struct mptcp_sock *msk)
return msk->subflow;
}
+/* Returns end sequence number of the receiver's advertised window */
+static u64 mptcp_wnd_end(const struct mptcp_sock *msk)
+{
+ return atomic64_read(&msk->wnd_end);
+}
+
static bool mptcp_is_tcpsk(struct sock *sk)
{
struct socket *sock = sk->sk_socket;
@@ -174,6 +180,7 @@ static void mptcp_data_queue_ofo(struct mptcp_sock *msk, struct sk_buff *skb)
if (after64(seq, max_seq)) {
/* out of window */
mptcp_drop(sk, skb);
+ pr_debug("oow by %ld", (unsigned long)seq - (unsigned long)max_seq);
MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_NODSSWINDOW);
return;
}
@@ -847,6 +854,7 @@ static void mptcp_clean_una(struct sock *sk)
*/
if (__mptcp_check_fallback(msk))
atomic64_set(&msk->snd_una, msk->snd_nxt);
+
snd_una = atomic64_read(&msk->snd_una);
list_for_each_entry_safe(dfrag, dtmp, &msk->rtx_queue, list) {
@@ -944,12 +952,30 @@ struct mptcp_sendmsg_info {
unsigned int flags;
};
+static int mptcp_check_allowed_size(struct mptcp_sock *msk, u64 data_seq,
+ int avail_size)
+{
+ u64 window_end = mptcp_wnd_end(msk);
+
+ if (__mptcp_check_fallback(msk))
+ return avail_size;
+
+ if (!before64(data_seq + avail_size, window_end)) {
+ u64 allowed_size = window_end - data_seq;
+
+ return min_t(unsigned int, allowed_size, avail_size);
+ }
+
+ return avail_size;
+}
+
static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk,
struct mptcp_data_frag *dfrag,
struct mptcp_sendmsg_info *info)
{
u64 data_seq = dfrag->data_seq + info->sent;
struct mptcp_sock *msk = mptcp_sk(sk);
+ bool zero_window_probe = false;
struct mptcp_ext *mpext = NULL;
struct sk_buff *skb, *tail;
bool can_collapse = false;
@@ -979,6 +1005,16 @@ static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk,
avail_size = info->size_goal - skb->len;
}
+ /* Zero window and all data acked? Probe. */
+ avail_size = mptcp_check_allowed_size(msk, data_seq, avail_size);
+ if (avail_size == 0) {
+ if (skb || atomic64_read(&msk->snd_una) != msk->snd_nxt)
+ return 0;
+ zero_window_probe = true;
+ data_seq = atomic64_read(&msk->snd_una) - 1;
+ avail_size = 1;
+ }
+
if (WARN_ON_ONCE(info->sent > info->limit ||
info->limit > dfrag->data_len))
return 0;
@@ -996,6 +1032,7 @@ static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk,
if (skb == tail) {
WARN_ON_ONCE(!can_collapse);
mpext->data_len += ret;
+ WARN_ON_ONCE(zero_window_probe);
goto out;
}
@@ -1013,6 +1050,12 @@ static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk,
mpext->data_seq, mpext->subflow_seq, mpext->data_len,
mpext->dsn64);
+ if (zero_window_probe) {
+ mptcp_subflow_ctx(ssk)->rel_write_seq += ret;
+ mpext->frozen = 1;
+ ret = 0;
+ tcp_push_pending_frames(ssk);
+ }
out:
mptcp_subflow_ctx(ssk)->rel_write_seq += ret;
return ret;
@@ -1866,7 +1909,7 @@ static void mptcp_worker(struct work_struct *work)
info.limit = dfrag->already_sent;
while (info.sent < dfrag->already_sent) {
ret = mptcp_sendmsg_frag(sk, ssk, dfrag, &info);
- if (ret < 0)
+ if (ret <= 0)
break;
MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_RETRANSSEGS);
@@ -2226,6 +2269,8 @@ struct sock *mptcp_sk_clone(const struct sock *sk,
msk->write_seq = subflow_req->idsn + 1;
msk->snd_nxt = msk->write_seq;
atomic64_set(&msk->snd_una, msk->write_seq);
+ atomic64_set(&msk->wnd_end, msk->snd_nxt + req->rsk_rcv_wnd);
+
if (mp_opt->mp_capable) {
msk->can_ack = true;
msk->remote_key = mp_opt->sndr_key;
@@ -2258,6 +2303,8 @@ void mptcp_rcv_space_init(struct mptcp_sock *msk, const struct sock *ssk)
TCP_INIT_CWND * tp->advmss);
if (msk->rcvq_space.space == 0)
msk->rcvq_space.space = TCP_INIT_CWND * TCP_MSS_DEFAULT;
+
+ atomic64_set(&msk->wnd_end, msk->snd_nxt + tcp_sk(ssk)->snd_wnd);
}
static struct sock *mptcp_accept(struct sock *sk, int flags, int *err,