All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paolo Abeni <pabeni@redhat.com>
To: mptcp@lists.linux.dev
Subject: [PATCH v6 mptcp-next 06/22] Squash-to: "mptcp: send out checksum for MP_CAPABLE with data"
Date: Tue,  4 May 2021 23:41:54 +0200	[thread overview]
Message-ID: <8850fb3700c38e61a548c65424c678df38ce380d.1620163861.git.pabeni@redhat.com> (raw)
In-Reply-To: <cover.1620163861.git.pabeni@redhat.com>

Finalize the csum value including the pseudo header and copy the
checksum into the opts only after computing it.

This is necessary after:
Squash-to: "mptcp: generate the data checksum"

Signed-off-by: Paolo Abeni <pabeni@redhat.com>
---
v4 -> v5:$
 - finalize csum in mptcp_write_options() this is necessary due to$
   the incremental csum update in v5 revision$
---
 net/mptcp/options.c | 29 +++++++++++++++++++++++------
 1 file changed, 23 insertions(+), 6 deletions(-)

diff --git a/net/mptcp/options.c b/net/mptcp/options.c
index 175635214ce6..d18a686aab7d 100644
--- a/net/mptcp/options.c
+++ b/net/mptcp/options.c
@@ -440,7 +440,6 @@ static bool mptcp_established_options_mp(struct sock *sk, struct sk_buff *skb,
 	struct mptcp_sock *msk = mptcp_sk(subflow->conn);
 	struct mptcp_ext *mpext;
 	unsigned int data_len;
-	__sum16 csum;
 	u8 len;
 
 	/* When skb is not available, we better over-estimate the emitted
@@ -461,7 +460,6 @@ static bool mptcp_established_options_mp(struct sock *sk, struct sk_buff *skb,
 	if (subflow->mp_capable) {
 		mpext = mptcp_get_ext(skb);
 		data_len = mpext ? mpext->data_len : 0;
-		csum = mpext ? mpext->csum : 0;
 
 		/* we will check ext_copy.data_len in mptcp_write_options() to
 		 * discriminate between TCPOLEN_MPTCP_MPC_ACK_DATA and
@@ -472,8 +470,6 @@ static bool mptcp_established_options_mp(struct sock *sk, struct sk_buff *skb,
 		opts->sndr_key = subflow->local_key;
 		opts->rcvr_key = subflow->remote_key;
 		opts->csum_reqd = READ_ONCE(msk->csum_enabled);
-		if (opts->csum_reqd)
-			opts->ext_copy.csum = csum;
 
 		/* Section 3.1.
 		 * The MP_CAPABLE option is carried on the SYN, SYN/ACK, and ACK
@@ -482,8 +478,10 @@ static bool mptcp_established_options_mp(struct sock *sk, struct sk_buff *skb,
 		 */
 		if (data_len > 0) {
 			len = TCPOLEN_MPTCP_MPC_ACK_DATA;
-			if (opts->csum_reqd)
+			if (opts->csum_reqd) {
+				opts->ext_copy.csum = mpext->csum;
 				len += TCPOLEN_MPTCP_DSS_CHECKSUM;
+			}
 			*size = ALIGN(len, 4);
 		} else {
 			*size = TCPOLEN_MPTCP_MPC_ACK;
@@ -1135,6 +1133,25 @@ static void mptcp_set_rwin(const struct tcp_sock *tp)
 		WRITE_ONCE(msk->rcv_wnd_sent, ack_seq);
 }
 
+static u16 mptcp_make_csum(const struct mptcp_ext *mpext)
+{
+	struct csum_pseudo_header header;
+	__wsum csum;
+
+	/* cfr RFC 8684 3.3.1.:
+	 * the data sequence number used in the pseudo-header is
+	 * always the 64-bit value, irrespective of what length is used in the
+	 * DSS option itself.
+	 */
+	header.data_seq = cpu_to_be64(mpext->data_seq);
+	header.subflow_seq = htonl(mpext->subflow_seq);
+	header.data_len = htons(mpext->data_len);
+	header.csum = 0;
+
+	csum = csum_partial(&header, sizeof(header), ~csum_unfold(mpext->csum));
+	return (__force u16)csum_fold(csum);
+}
+
 void mptcp_write_options(__be32 *ptr, const struct tcp_sock *tp,
 			 struct mptcp_out_options *opts)
 {
@@ -1177,7 +1194,7 @@ void mptcp_write_options(__be32 *ptr, const struct tcp_sock *tp,
 
 		if (opts->csum_reqd) {
 			put_unaligned_be32(opts->ext_copy.data_len << 16 |
-					   (__force u16)opts->ext_copy.csum, ptr);
+					   mptcp_make_csum(&opts->ext_copy), ptr);
 		} else {
 			put_unaligned_be32(opts->ext_copy.data_len << 16 |
 					   TCPOPT_NOP << 8 | TCPOPT_NOP, ptr);
-- 
2.26.2


  parent reply	other threads:[~2021-05-04 21:42 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-04 21:41 [PATCH v6 mptcp-next 00/22] mptcp: data checksum support Paolo Abeni
2021-05-04 21:41 ` [PATCH v6 mptcp-next 01/22] mptcp: add csum_enabled in mptcp_sock Paolo Abeni
2021-05-04 21:41 ` [PATCH v6 mptcp-next 02/22] mptcp: generate the data checksum Paolo Abeni
2021-05-04 21:41 ` [PATCH v6 mptcp-next 03/22] Squash-to: "mptcp: generate the data checksum" Paolo Abeni
2021-05-04 21:41 ` [PATCH v6 mptcp-next 04/22] mptcp: add csum_reqd in mptcp_out_options Paolo Abeni
2021-05-04 21:41 ` [PATCH v6 mptcp-next 05/22] mptcp: send out checksum for MP_CAPABLE with data Paolo Abeni
2021-05-04 21:41 ` Paolo Abeni [this message]
2021-05-04 21:41 ` [PATCH v6 mptcp-next 07/22] mptcp: send out checksum for DSS Paolo Abeni
2021-05-04 21:41 ` [PATCH v6 mptcp-next 08/22] Squash-to "mptcp: send out checksum for DSS" Paolo Abeni
2021-05-04 21:41 ` [PATCH v6 mptcp-next 09/22] mptcp: add sk parameter for mptcp_parse_option Paolo Abeni
2021-05-04 21:41 ` [PATCH v6 mptcp-next 10/22] mptcp: add csum_reqd in mptcp_options_received Paolo Abeni
2021-05-04 21:41 ` [PATCH v6 mptcp-next 11/22] mptcp: receive checksum for MP_CAPABLE with data Paolo Abeni
2021-05-04 21:42 ` [PATCH v6 mptcp-next 12/22] Squash-to: "mptcp: receive checksum for MP_CAPABLE with data" Paolo Abeni
2021-05-04 21:42 ` [PATCH v6 mptcp-next 13/22] mptcp: receive checksum for DSS Paolo Abeni
2021-05-04 21:42 ` [PATCH v6 mptcp-next 14/22] Squash-to: "mptcp: receive checksum for DSS" Paolo Abeni
2021-05-04 21:42 ` [PATCH v6 mptcp-next 15/22] mptcp: validate the data checksum Paolo Abeni
2021-05-04 21:42 ` [PATCH v6 mptcp-next 16/22] Squash-to: " Paolo Abeni
2021-05-04 21:42 ` [PATCH v6 mptcp-next 17/22] mptcp: cleanup error path in subflow_check_data_avail() Paolo Abeni
2021-05-04 21:42 ` [PATCH v6 mptcp-next 18/22] mptcp: tune re-injections for csum enabled mode Paolo Abeni
2021-05-04 21:42 ` [PATCH v6 mptcp-next 19/22] mptcp: add the mib for data checksum Paolo Abeni
2021-05-04 21:42 ` [PATCH v6 mptcp-next 20/22] mptcp: add a new sysctl checksum_enabled Paolo Abeni
2021-05-04 21:42 ` [PATCH v6 mptcp-next 21/22] selftests: mptcp: enable checksum in mptcp_connect.sh Paolo Abeni
2021-05-04 21:42 ` [PATCH v6 mptcp-next 22/22] selftests: mptcp: enable checksum in mptcp_join.sh Paolo Abeni
2021-05-05 10:12 ` [PATCH v6 mptcp-next 00/22] mptcp: data checksum support Paolo Abeni
2021-05-05 18:03   ` Mat Martineau
2021-05-05 23:56 ` Mat Martineau
2021-05-06  8:31 ` 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=8850fb3700c38e61a548c65424c678df38ce380d.1620163861.git.pabeni@redhat.com \
    --to=pabeni@redhat.com \
    --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 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.