All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net] mptcp: always include dack if possible.
@ 2020-03-03 17:22 Paolo Abeni
  2020-03-03 18:58 ` Mat Martineau
  0 siblings, 1 reply; 3+ messages in thread
From: Paolo Abeni @ 2020-03-03 17:22 UTC (permalink / raw
  To: netdev; +Cc: Mat Martineau, Matthieu Baerts, David S. Miller, Christoph Paasch

Currently passive MPTCP socket can skip including the DACK
option - if the peer sends data before accept() completes.

The above happens because the msk 'can_ack' flag is set
only after the accept() call.

Such missing DACK option may cause - as per RFC spec -
unwanted fallback to TCP.

This change addresses the issue using the key material
available in the current subflow, if any, to create a suitable
dack option when msk ack seq is not yet available.

Fixes: d22f4988ffec ("mptcp: process MP_CAPABLE data option")
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
---
 net/mptcp/options.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/net/mptcp/options.c b/net/mptcp/options.c
index 45acd877bef3..9eb84115dc35 100644
--- a/net/mptcp/options.c
+++ b/net/mptcp/options.c
@@ -334,6 +334,8 @@ static bool mptcp_established_options_dss(struct sock *sk, struct sk_buff *skb,
 	struct mptcp_sock *msk;
 	unsigned int ack_size;
 	bool ret = false;
+	bool can_ack;
+	u64 ack_seq;
 	u8 tcp_fin;
 
 	if (skb) {
@@ -360,9 +362,20 @@ static bool mptcp_established_options_dss(struct sock *sk, struct sk_buff *skb,
 		ret = true;
 	}
 
+	/* passive sockets msk will set the 'can_ack' after accept(), even
+	 * if the first subflow may have the already the remote key handy
+	 */
+	can_ack = true;
 	opts->ext_copy.use_ack = 0;
 	msk = mptcp_sk(subflow->conn);
-	if (!msk || !READ_ONCE(msk->can_ack)) {
+	if (likely(msk && READ_ONCE(msk->can_ack)))
+		ack_seq = msk->ack_seq;
+	else if (subflow->can_ack)
+		mptcp_crypto_key_sha(subflow->remote_key, NULL, &ack_seq);
+	else
+		can_ack = false;
+
+	if (unlikely(!can_ack)) {
 		*size = ALIGN(dss_size, 4);
 		return ret;
 	}
@@ -375,7 +388,7 @@ static bool mptcp_established_options_dss(struct sock *sk, struct sk_buff *skb,
 
 	dss_size += ack_size;
 
-	opts->ext_copy.data_ack = msk->ack_seq;
+	opts->ext_copy.data_ack = ack_seq;
 	opts->ext_copy.ack64 = 1;
 	opts->ext_copy.use_ack = 1;
 
-- 
2.21.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH net] mptcp: always include dack if possible.
  2020-03-03 17:22 [PATCH net] mptcp: always include dack if possible Paolo Abeni
@ 2020-03-03 18:58 ` Mat Martineau
  2020-03-03 21:14   ` Paolo Abeni
  0 siblings, 1 reply; 3+ messages in thread
From: Mat Martineau @ 2020-03-03 18:58 UTC (permalink / raw
  To: Paolo Abeni; +Cc: netdev, Matthieu Baerts, David S. Miller, Christoph Paasch


Paolo -

On Tue, 3 Mar 2020, Paolo Abeni wrote:

> Currently passive MPTCP socket can skip including the DACK
> option - if the peer sends data before accept() completes.
>
> The above happens because the msk 'can_ack' flag is set
> only after the accept() call.
>
> Such missing DACK option may cause - as per RFC spec -
> unwanted fallback to TCP.
>
> This change addresses the issue using the key material
> available in the current subflow, if any, to create a suitable
> dack option when msk ack seq is not yet available.
>
> Fixes: d22f4988ffec ("mptcp: process MP_CAPABLE data option")
> Signed-off-by: Paolo Abeni <pabeni@redhat.com>
> ---
> net/mptcp/options.c | 17 +++++++++++++++--
> 1 file changed, 15 insertions(+), 2 deletions(-)
>
> diff --git a/net/mptcp/options.c b/net/mptcp/options.c
> index 45acd877bef3..9eb84115dc35 100644
> --- a/net/mptcp/options.c
> +++ b/net/mptcp/options.c
> @@ -334,6 +334,8 @@ static bool mptcp_established_options_dss(struct sock *sk, struct sk_buff *skb,
> 	struct mptcp_sock *msk;
> 	unsigned int ack_size;
> 	bool ret = false;
> +	bool can_ack;
> +	u64 ack_seq;
> 	u8 tcp_fin;
>
> 	if (skb) {
> @@ -360,9 +362,20 @@ static bool mptcp_established_options_dss(struct sock *sk, struct sk_buff *skb,
> 		ret = true;
> 	}
>
> +	/* passive sockets msk will set the 'can_ack' after accept(), even
> +	 * if the first subflow may have the already the remote key handy
> +	 */
> +	can_ack = true;
> 	opts->ext_copy.use_ack = 0;
> 	msk = mptcp_sk(subflow->conn);
> -	if (!msk || !READ_ONCE(msk->can_ack)) {
> +	if (likely(msk && READ_ONCE(msk->can_ack)))
> +		ack_seq = msk->ack_seq;
> +	else if (subflow->can_ack)
> +		mptcp_crypto_key_sha(subflow->remote_key, NULL, &ack_seq);

The other code paths that set the initial sequence number all increment it 
before sending (to ack SYN+MP_CAPABLE). It looks like the spec allows the 
value calculated here, but we might as well be consistent about the 
initial value we send over the wire.

> +	else
> +		can_ack = false;
> +
> +	if (unlikely(!can_ack)) {
> 		*size = ALIGN(dss_size, 4);
> 		return ret;
> 	}
> @@ -375,7 +388,7 @@ static bool mptcp_established_options_dss(struct sock *sk, struct sk_buff *skb,
>
> 	dss_size += ack_size;
>
> -	opts->ext_copy.data_ack = msk->ack_seq;
> +	opts->ext_copy.data_ack = ack_seq;
> 	opts->ext_copy.ack64 = 1;
> 	opts->ext_copy.use_ack = 1;
>
> -- 
> 2.21.1
>
>

--
Mat Martineau
Intel

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH net] mptcp: always include dack if possible.
  2020-03-03 18:58 ` Mat Martineau
@ 2020-03-03 21:14   ` Paolo Abeni
  0 siblings, 0 replies; 3+ messages in thread
From: Paolo Abeni @ 2020-03-03 21:14 UTC (permalink / raw
  To: Mat Martineau; +Cc: netdev, Matthieu Baerts, David S. Miller, Christoph Paasch

On Tue, 2020-03-03 at 10:58 -0800, Mat Martineau wrote:
> On Tue, 3 Mar 2020, Paolo Abeni wrote:
> 
> > Currently passive MPTCP socket can skip including the DACK
> > option - if the peer sends data before accept() completes.
> > 
> > The above happens because the msk 'can_ack' flag is set
> > only after the accept() call.
> > 
> > Such missing DACK option may cause - as per RFC spec -
> > unwanted fallback to TCP.
> > 
> > This change addresses the issue using the key material
> > available in the current subflow, if any, to create a suitable
> > dack option when msk ack seq is not yet available.
> > 
> > Fixes: d22f4988ffec ("mptcp: process MP_CAPABLE data option")
> > Signed-off-by: Paolo Abeni <pabeni@redhat.com>
> > ---
> > net/mptcp/options.c | 17 +++++++++++++++--
> > 1 file changed, 15 insertions(+), 2 deletions(-)
> > 
> > diff --git a/net/mptcp/options.c b/net/mptcp/options.c
> > index 45acd877bef3..9eb84115dc35 100644
> > --- a/net/mptcp/options.c
> > +++ b/net/mptcp/options.c
> > @@ -334,6 +334,8 @@ static bool mptcp_established_options_dss(struct sock *sk, struct sk_buff *skb,
> > 	struct mptcp_sock *msk;
> > 	unsigned int ack_size;
> > 	bool ret = false;
> > +	bool can_ack;
> > +	u64 ack_seq;
> > 	u8 tcp_fin;
> > 
> > 	if (skb) {
> > @@ -360,9 +362,20 @@ static bool mptcp_established_options_dss(struct sock *sk, struct sk_buff *skb,
> > 		ret = true;
> > 	}
> > 
> > +	/* passive sockets msk will set the 'can_ack' after accept(), even
> > +	 * if the first subflow may have the already the remote key handy
> > +	 */
> > +	can_ack = true;
> > 	opts->ext_copy.use_ack = 0;
> > 	msk = mptcp_sk(subflow->conn);
> > -	if (!msk || !READ_ONCE(msk->can_ack)) {
> > +	if (likely(msk && READ_ONCE(msk->can_ack)))
> > +		ack_seq = msk->ack_seq;
> > +	else if (subflow->can_ack)
> > +		mptcp_crypto_key_sha(subflow->remote_key, NULL, &ack_seq);
> 
> The other code paths that set the initial sequence number all increment it 
> before sending (to ack SYN+MP_CAPABLE). It looks like the spec allows the 
> value calculated here, but we might as well be consistent about the 
> initial value we send over the wire.

Thanks for the feedback! Agreed. I'll send a v2 tomorrow.

Cheers,

Paolo


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-03-03 21:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-03-03 17:22 [PATCH net] mptcp: always include dack if possible Paolo Abeni
2020-03-03 18:58 ` Mat Martineau
2020-03-03 21:14   ` Paolo Abeni

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.