mptcp: track window announced to peer
Subsystems (3)
Florian Westphal
PATCH v2 1/1 mptcp: track window announced to peer
OoO handling attemtps to detect when packet is out-of-window by testing current ack sequence and remaining space vs. sequence number.
This doesn't work reliably. Store the highest allowed sequence number that we've announced and use it to detect oow packets.
Do this when mptcp options get written to the packet (wire format). For this to work we need to move the write_options call until after stack selected a new tcp window.
---
Changes in v2:
- avoid hooking mptcp_set_rwin in tcp stack, move tcp_options_write a few lines (so tp->rcv_wnd was updated with new chosen tcp window) and call it from mptcp_write_options instead.
include/net/mptcp.h | 2 +- net/ipv4/tcp_output.c | 10 ++++++---- net/mptcp/options.c | 20 +++++++++++++++++++- net/mptcp/protocol.c | 10 +++++----- net/mptcp/protocol.h | 1 + 5 files changed, 32 insertions(+), 11 deletions(-)
include/net/mptcp.h +1 -1
@@ -88,7 +88,7 @@ bool mptcp_established_options(struct sock *sk, struct sk_buff *skb, struct mptcp_out_options *opts);void mptcp_incoming_options (struct sock *sk,struct sk_buff *skb); -void mptcp_write_options (__be32 *ptr,struct mptcp_out_options *opts); +void mptcp_write_options (__be32 *ptr,const struct tcp_sock *tp,struct mptcp_out_options *opts);/* move the skb extension owership, with the assumption that 'to' is * newly allocated
net/ipv4/tcp_output.c +6 -4
@@ -445,11 +445,11 @@ struct tcp_out_options {struct mptcp_out_options mptcp; }; -static void mptcp_options_write (__be32 *ptr,struct tcp_out_options *opts) +static void mptcp_options_write (__be32 *ptr,const struct tcp_sock *tp,struct tcp_out_options *opts) {#if IS_ENABLED (CONFIG_MPTCP )if (unlikely (OPTION_MPTCP & opts->options)) -mptcp_write_options (ptr, &opts->mptcp); +mptcp_write_options (ptr, tp, &opts->mptcp);#endif }
@@ -701,7 +701,7 @@ static void tcp_options_write(__be32 *ptr, struct tcp_sock *tp,smc_options_write (ptr, &options); -mptcp_options_write (ptr, opts); +mptcp_options_write (ptr, tp, opts); } static void smc_set_option(const struct tcp_sock *tp,
@@ -1348,7 +1348,6 @@ static int __tcp_transmit_skb(struct sock *sk, struct sk_buff *skb, } } -tcp_options_write ((__be32 *)(th +1 ), tp, &opts);skb_shinfo (skb)->gso_type = sk->sk_gso_type;if (likely (!(tcb->tcp_flags &TCPHDR_SYN ))) { th->window =htons (tcp_select_window (sk));
@@ -1359,6 +1358,9 @@ static int __tcp_transmit_skb(struct sock *sk, struct sk_buff *skb,*/ th->window =htons (min (tp->rcv_wnd,65535U )); } + +tcp_options_write ((__be32 *)(th +1 ), tp, &opts); +#ifdef CONFIG_TCP_MD5SIG /* Calculate the MD5 hash, as we have all we need now */ if (md5) {
net/mptcp/options.c +19 -1
@@ -991,7 +991,23 @@ void mptcp_incoming_options(struct sock *sk, struct sk_buff *skb) } } -void mptcp_write_options (__be32 *ptr,struct mptcp_out_options *opts) +static void mptcp_set_rwin (const struct tcp_sock *tp) +{ +const struct sock *ssk = (const struct sock *)tp; +const struct mptcp_subflow_context *subflow; +struct mptcp_sock *msk; +u64 ack_seq; + + subflow =mptcp_subflow_ctx (ssk); + msk =mptcp_sk (subflow->conn); + + ack_seq =READ_ONCE (msk->ack_seq) + tp->rcv_wnd; + +if (after64 (ack_seq,READ_ONCE (msk->rcv_wnd_sent))) +WRITE_ONCE (msk->rcv_wnd_sent, ack_seq); +} + +void mptcp_write_options (__be32 *ptr,const struct tcp_sock *tp,struct mptcp_out_options *opts) {if ((OPTION_MPTCP_MPC_SYN |OPTION_MPTCP_MPC_SYNACK |OPTION_MPTCP_MPC_ACK ) & opts->suboptions) {
@@ -1147,5 +1163,7 @@ void mptcp_write_options(__be32 *ptr, struct mptcp_out_options *opts)put_unaligned_be32 (mpext->data_len <<16 |TCPOPT_NOP <<8 |TCPOPT_NOP , ptr); } + +mptcp_set_rwin (tp); } }
net/mptcp/protocol.c +5 -5
@@ -168,19 +168,17 @@ static void mptcp_data_queue_ofo(struct mptcp_sock *msk, struct sk_buff *skb)struct rb_node **p, *parent;u64 seq, end_seq, max_seq;struct sk_buff *skb1; -int space; seq =MPTCP_SKB_CB (skb)->map_seq; end_seq =MPTCP_SKB_CB (skb)->end_seq; - space =tcp_space (sk); - max_seq = space >0 ? space + msk->ack_seq : msk->ack_seq; + max_seq =READ_ONCE (msk->rcv_wnd_sent);pr_debug ("msk=%p seq=%llx limit=%llx empty=%d" , msk, seq, max_seq,RB_EMPTY_ROOT (&msk->out_of_order_queue)); -if (after64 (seq, max_seq)) { +if (after64 (end_seq, max_seq)) {/* out of window */ mptcp_drop (sk, skb); -pr_debug ("oow by %ld" , (unsigned long )seq - (unsigned long )max_seq); +pr_debug ("oow by %ld, rcv_wnd_sent %lu\n" , (unsigned long )end_seq - (unsigned long )max_seq, (long )msk->rcv_wnd_sent);MPTCP_INC_STATS (sock_net (sk),MPTCP_MIB_NODSSWINDOW );return ; }
@@ -2258,6 +2256,7 @@ struct sock *mptcp_sk_clone(const struct sock *sk,mptcp_crypto_key_sha (msk->remote_key,NULL , &ack_seq); ack_seq++;WRITE_ONCE (msk->ack_seq, ack_seq); +WRITE_ONCE (msk->rcv_wnd_sent, ack_seq); }#if !IS_ENABLED (CONFIG_KASAN )
@@ -2567,6 +2566,7 @@ void mptcp_finish_connect(struct sock *ssk)WRITE_ONCE (msk->write_seq, subflow->idsn +1 );WRITE_ONCE (msk->snd_nxt, msk->write_seq);WRITE_ONCE (msk->ack_seq, ack_seq); +WRITE_ONCE (msk->rcv_wnd_sent, ack_seq);WRITE_ONCE (msk->can_ack,1 );atomic64_set (&msk->snd_una, msk->write_seq);
net/mptcp/protocol.h +1 -0
@@ -211,6 +211,7 @@ struct mptcp_sock {u64 write_seq;u64 snd_nxt;u64 ack_seq; +u64 rcv_wnd_sent;u64 rcv_data_fin_seq;struct sock *last_snd;int snd_burst;
Signature · 1 line
2.26.2
Paolo Abeni
Quoted 11 lines · Florian Westphal
OoO handling attemtps to detect when packet is out-of-window by testing current ack sequence and remaining space vs. sequence number.
This doesn't work reliably. Store the highest allowed sequence number that we've announced and use it to detect oow packets.
Do this when mptcp options get written to the packet (wire format). For this to work we need to move the
write_optionscall until after stack selected a new tcp window.Signed-off-by Florian Westphal <fw(a)strlen.de>
I've only a couple of minor comments, see below...
net/ipv4/tcp_output.c struct tcp_out_options { · line 448
Quoted 6 lines
net/ipv4/tcp_output.c +1
-1@@ -445,11 +445,11 @@ struct tcp_out_options {struct mptcp_out_options mptcp; }; -static void mptcp_options_write (__be32 *ptr,struct tcp_out_options *opts) +static void mptcp_options_write (__be32 *ptr,const struct tcp_sock *tp,struct tcp_out_options *opts)
Nit picking: this looks above the 80 char limits ;)
net/mptcp/options.c void mptcp_write_options(__be32 *ptr, struct mptcp_out_options *opts) · line 1167
Quoted 6 lines
net/mptcp/options.c +2
-0@@ -1147,5 +1163,7 @@ void mptcp_write_options(__be32 *ptr, struct mptcp_out_options *opts)put_unaligned_be32 (mpext->data_len <<16 |TCPOPT_NOP <<8 |TCPOPT_NOP , ptr); } + +mptcp_set_rwin (tp);
If I read correctly, we will not update the receive window for pure ack carrying ipv6 add addr option (and nothing else). Likely not particulary relevant, but perhaps we could call the above helper for all egress packet?
Other than that look very good to me, thanks!
/P
Florian Westphal
Quoted 15 lines · Paolo Abeni
Quoted 11 lines · Florian Westphal
OoO handling attemtps to detect when packet is out-of-window by testing current ack sequence and remaining space vs. sequence number.
This doesn't work reliably. Store the highest allowed sequence number that we've announced and use it to detect oow packets.
Do this when mptcp options get written to the packet (wire format). For this to work we need to move the
write_optionscall until after stack selected a new tcp window.Signed-off-by Florian Westphal <fw(a)strlen.de>I've only a couple of minor comments, see below...
Quoted 8 lines
net/ipv4/tcp_output.c struct tcp_out_options { · line 448
Quoted 6 lines
net/ipv4/tcp_output.c +1
-1@@ -445,11 +445,11 @@ struct tcp_out_options {struct mptcp_out_options mptcp; }; -static void mptcp_options_write (__be32 *ptr,struct tcp_out_options *opts) +static void mptcp_options_write (__be32 *ptr,const struct tcp_sock *tp,struct tcp_out_options *opts)Nit picking: this looks above the 80 char limits ;)
Ok, i will break the line.
Quoted 11 lines
net/mptcp/options.c void mptcp_write_options(__be32 *ptr, struct mptcp_out_options *opts) · line 1167
Quoted 6 lines
net/mptcp/options.c +2
-0@@ -1147,5 +1163,7 @@ void mptcp_write_options(__be32 *ptr, struct mptcp_out_options *opts)put_unaligned_be32 (mpext->data_len <<16 |TCPOPT_NOP <<8 |TCPOPT_NOP , ptr); } + +mptcp_set_rwin (tp);If I read correctly, we will not update the receive window for pure ack carrying ipv6 add addr option (and nothing else). Likely not particulary relevant, but perhaps we could call the above helper for all egress packet?
rx side only updates end of window if MPTCP_DSS_HAS_ACK flag is set.
I'll move it outside of the conditional, perhaps its less confusing that way.