Skip to content

Commit f284c0c

Browse files
Paolo Abenidavem330
authored andcommitted
mptcp: implement fastclose xmit path
Allow the MPTCP xmit path to add MP_FASTCLOSE suboption on RST egress packets. Additionally reorder related options writing to reduce the number of conditionals required in the fast path. Co-developed-by: Geliang Tang <[email protected]> Signed-off-by: Geliang Tang <[email protected]> Co-developed-by: Matthieu Baerts <[email protected]> Signed-off-by: Matthieu Baerts <[email protected]> Signed-off-by: Paolo Abeni <[email protected]> Signed-off-by: Mat Martineau <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 58cd405 commit f284c0c

File tree

2 files changed

+46
-12
lines changed

2 files changed

+46
-12
lines changed

net/mptcp/options.c

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,28 @@ static noinline bool mptcp_established_options_rst(struct sock *sk, struct sk_bu
768768
return true;
769769
}
770770

771+
static bool mptcp_established_options_fastclose(struct sock *sk,
772+
unsigned int *size,
773+
unsigned int remaining,
774+
struct mptcp_out_options *opts)
775+
{
776+
struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
777+
struct mptcp_sock *msk = mptcp_sk(subflow->conn);
778+
779+
if (likely(!subflow->send_fastclose))
780+
return false;
781+
782+
if (remaining < TCPOLEN_MPTCP_FASTCLOSE)
783+
return false;
784+
785+
*size = TCPOLEN_MPTCP_FASTCLOSE;
786+
opts->suboptions |= OPTION_MPTCP_FASTCLOSE;
787+
opts->rcvr_key = msk->remote_key;
788+
789+
pr_debug("FASTCLOSE key=%llu", opts->rcvr_key);
790+
return true;
791+
}
792+
771793
static bool mptcp_established_options_mp_fail(struct sock *sk,
772794
unsigned int *size,
773795
unsigned int remaining,
@@ -806,10 +828,12 @@ bool mptcp_established_options(struct sock *sk, struct sk_buff *skb,
806828
return false;
807829

808830
if (unlikely(skb && TCP_SKB_CB(skb)->tcp_flags & TCPHDR_RST)) {
809-
if (mptcp_established_options_mp_fail(sk, &opt_size, remaining, opts)) {
831+
if (mptcp_established_options_fastclose(sk, &opt_size, remaining, opts) ||
832+
mptcp_established_options_mp_fail(sk, &opt_size, remaining, opts)) {
810833
*size += opt_size;
811834
remaining -= opt_size;
812835
}
836+
/* MP_RST can be used with MP_FASTCLOSE and MP_FAIL if there is room */
813837
if (mptcp_established_options_rst(sk, skb, &opt_size, remaining, opts)) {
814838
*size += opt_size;
815839
remaining -= opt_size;
@@ -1251,17 +1275,8 @@ void mptcp_write_options(__be32 *ptr, const struct tcp_sock *tp,
12511275
ptr += 2;
12521276
}
12531277

1254-
/* RST is mutually exclusive with everything else */
1255-
if (unlikely(OPTION_MPTCP_RST & opts->suboptions)) {
1256-
*ptr++ = mptcp_option(MPTCPOPT_RST,
1257-
TCPOLEN_MPTCP_RST,
1258-
opts->reset_transient,
1259-
opts->reset_reason);
1260-
return;
1261-
}
1262-
1263-
/* DSS, MPC, MPJ and ADD_ADDR are mutually exclusive, see
1264-
* mptcp_established_options*()
1278+
/* DSS, MPC, MPJ, ADD_ADDR, FASTCLOSE and RST are mutually exclusive,
1279+
* see mptcp_established_options*()
12651280
*/
12661281
if (likely(OPTION_MPTCP_DSS & opts->suboptions)) {
12671282
struct mptcp_ext *mpext = &opts->ext_copy;
@@ -1447,6 +1462,24 @@ void mptcp_write_options(__be32 *ptr, const struct tcp_sock *tp,
14471462
ptr += 1;
14481463
}
14491464
}
1465+
} else if (unlikely(OPTION_MPTCP_FASTCLOSE & opts->suboptions)) {
1466+
/* FASTCLOSE is mutually exclusive with others except RST */
1467+
*ptr++ = mptcp_option(MPTCPOPT_MP_FASTCLOSE,
1468+
TCPOLEN_MPTCP_FASTCLOSE,
1469+
0, 0);
1470+
put_unaligned_be64(opts->rcvr_key, ptr);
1471+
ptr += 2;
1472+
1473+
if (OPTION_MPTCP_RST & opts->suboptions)
1474+
goto mp_rst;
1475+
return;
1476+
} else if (unlikely(OPTION_MPTCP_RST & opts->suboptions)) {
1477+
mp_rst:
1478+
*ptr++ = mptcp_option(MPTCPOPT_RST,
1479+
TCPOLEN_MPTCP_RST,
1480+
opts->reset_transient,
1481+
opts->reset_reason);
1482+
return;
14501483
}
14511484

14521485
if (OPTION_MPTCP_PRIO & opts->suboptions) {

net/mptcp/protocol.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,7 @@ struct mptcp_subflow_context {
423423
backup : 1,
424424
send_mp_prio : 1,
425425
send_mp_fail : 1,
426+
send_fastclose : 1,
426427
rx_eof : 1,
427428
can_ack : 1, /* only after processing the remote a key */
428429
disposable : 1, /* ctx can be free at ulp release time */

0 commit comments

Comments
 (0)