Skip to content

Commit

Permalink
mptcp: send out checksum for MP_CAPABLE with data
Browse files Browse the repository at this point in the history
If the checksum is enabled, send out the data checksum with the
MP_CAPABLE suboption with data.

In mptcp_established_options_mp, save the data checksum in
opts->ext_copy.csum. In mptcp_write_options, adjust the option length and
send it out with the MP_CAPABLE suboption.

Co-developed-by: Paolo Abeni <[email protected]>
Signed-off-by: Paolo Abeni <[email protected]>
Reviewed-by: Mat Martineau <[email protected]>
Signed-off-by: Geliang Tang <[email protected]>
  • Loading branch information
geliangtang authored and matttbe committed May 6, 2021
1 parent 70f1bc1 commit fa7ac4a
Showing 1 changed file with 43 additions and 9 deletions.
52 changes: 43 additions & 9 deletions net/mptcp/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ 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;
u8 len;

/* When skb is not available, we better over-estimate the emitted
* options len. A full DSS option (28 bytes) is longer than
Expand Down Expand Up @@ -475,10 +476,16 @@ static bool mptcp_established_options_mp(struct sock *sk, struct sk_buff *skb,
* packets that start the first subflow of an MPTCP connection,
* as well as the first packet that carries data
*/
if (data_len > 0)
*size = ALIGN(TCPOLEN_MPTCP_MPC_ACK_DATA, 4);
else
if (data_len > 0) {
len = TCPOLEN_MPTCP_MPC_ACK_DATA;
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;
}

pr_debug("subflow=%p, local_key=%llu, remote_key=%llu map_len=%d",
subflow, subflow->local_key, subflow->remote_key,
Expand Down Expand Up @@ -1126,21 +1133,43 @@ 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)
{
if ((OPTION_MPTCP_MPC_SYN | OPTION_MPTCP_MPC_SYNACK |
OPTION_MPTCP_MPC_ACK) & opts->suboptions) {
u8 len, flag = MPTCP_CAP_HMAC_SHA256;

if (OPTION_MPTCP_MPC_SYN & opts->suboptions)
if (OPTION_MPTCP_MPC_SYN & opts->suboptions) {
len = TCPOLEN_MPTCP_MPC_SYN;
else if (OPTION_MPTCP_MPC_SYNACK & opts->suboptions)
} else if (OPTION_MPTCP_MPC_SYNACK & opts->suboptions) {
len = TCPOLEN_MPTCP_MPC_SYNACK;
else if (opts->ext_copy.data_len)
} else if (opts->ext_copy.data_len) {
len = TCPOLEN_MPTCP_MPC_ACK_DATA;
else
if (opts->csum_reqd)
len += TCPOLEN_MPTCP_DSS_CHECKSUM;
} else {
len = TCPOLEN_MPTCP_MPC_ACK;
}

if (opts->csum_reqd)
flag |= MPTCP_CAP_CHECKSUM_REQD;
Expand All @@ -1163,8 +1192,13 @@ void mptcp_write_options(__be32 *ptr, const struct tcp_sock *tp,
if (!opts->ext_copy.data_len)
goto mp_capable_done;

put_unaligned_be32(opts->ext_copy.data_len << 16 |
TCPOPT_NOP << 8 | TCPOPT_NOP, ptr);
if (opts->csum_reqd) {
put_unaligned_be32(opts->ext_copy.data_len << 16 |
mptcp_make_csum(&opts->ext_copy), ptr);
} else {
put_unaligned_be32(opts->ext_copy.data_len << 16 |
TCPOPT_NOP << 8 | TCPOPT_NOP, ptr);
}
ptr += 1;
}

Expand Down

0 comments on commit fa7ac4a

Please sign in to comment.