Skip to content

Commit 9e8ac63

Browse files
committed
Merge branch 'mptcp-more-miscellaneous-mptcp-fixes'
Mat Martineau says: ==================== mptcp: More miscellaneous MPTCP fixes Here's another batch of fixup and enhancement patches that we have collected in the MPTCP tree. Patch 1 removes an unnecessary flag and related code. Patch 2 fixes a bug encountered when closing fallback sockets. Patches 3 and 4 choose a better transmit subflow, with a self test. Patch 5 adjusts tracking of unaccepted subflows Patches 6-8 improve handling of long ADD_ADDR options, with a test. Patch 9 more reliably tracks the MPTCP-level window shared with peers. Patch 10 sends MPTCP-level acknowledgements more aggressively, so the peer can send more data without extra delay. ==================== Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents 3cd336c + ea4ca58 commit 9e8ac63

File tree

9 files changed

+391
-141
lines changed

9 files changed

+391
-141
lines changed

include/net/mptcp.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ bool mptcp_established_options(struct sock *sk, struct sk_buff *skb,
8888
struct mptcp_out_options *opts);
8989
void mptcp_incoming_options(struct sock *sk, struct sk_buff *skb);
9090

91-
void mptcp_write_options(__be32 *ptr, struct mptcp_out_options *opts);
91+
void mptcp_write_options(__be32 *ptr, const struct tcp_sock *tp,
92+
struct mptcp_out_options *opts);
9293

9394
/* move the skb extension owership, with the assumption that 'to' is
9495
* newly allocated

net/ipv4/tcp_output.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -445,11 +445,12 @@ struct tcp_out_options {
445445
struct mptcp_out_options mptcp;
446446
};
447447

448-
static void mptcp_options_write(__be32 *ptr, struct tcp_out_options *opts)
448+
static void mptcp_options_write(__be32 *ptr, const struct tcp_sock *tp,
449+
struct tcp_out_options *opts)
449450
{
450451
#if IS_ENABLED(CONFIG_MPTCP)
451452
if (unlikely(OPTION_MPTCP & opts->options))
452-
mptcp_write_options(ptr, &opts->mptcp);
453+
mptcp_write_options(ptr, tp, &opts->mptcp);
453454
#endif
454455
}
455456

@@ -701,7 +702,7 @@ static void tcp_options_write(__be32 *ptr, struct tcp_sock *tp,
701702

702703
smc_options_write(ptr, &options);
703704

704-
mptcp_options_write(ptr, opts);
705+
mptcp_options_write(ptr, tp, opts);
705706
}
706707

707708
static void smc_set_option(const struct tcp_sock *tp,
@@ -1346,7 +1347,6 @@ static int __tcp_transmit_skb(struct sock *sk, struct sk_buff *skb,
13461347
}
13471348
}
13481349

1349-
tcp_options_write((__be32 *)(th + 1), tp, &opts);
13501350
skb_shinfo(skb)->gso_type = sk->sk_gso_type;
13511351
if (likely(!(tcb->tcp_flags & TCPHDR_SYN))) {
13521352
th->window = htons(tcp_select_window(sk));
@@ -1357,6 +1357,9 @@ static int __tcp_transmit_skb(struct sock *sk, struct sk_buff *skb,
13571357
*/
13581358
th->window = htons(min(tp->rcv_wnd, 65535U));
13591359
}
1360+
1361+
tcp_options_write((__be32 *)(th + 1), tp, &opts);
1362+
13601363
#ifdef CONFIG_TCP_MD5SIG
13611364
/* Calculate the MD5 hash, as we have all we need now */
13621365
if (md5) {

net/mptcp/options.c

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,9 @@ static void mptcp_parse_option(const struct sk_buff *skb,
242242

243243
mp_opt->add_addr = 1;
244244
mp_opt->addr_id = *ptr++;
245-
pr_debug("ADD_ADDR: id=%d, echo=%d", mp_opt->addr_id, mp_opt->echo);
245+
pr_debug("ADD_ADDR%s: id=%d, echo=%d",
246+
(mp_opt->family == MPTCP_ADDR_IPVERSION_6) ? "6" : "",
247+
mp_opt->addr_id, mp_opt->echo);
246248
if (mp_opt->family == MPTCP_ADDR_IPVERSION_4) {
247249
memcpy((u8 *)&mp_opt->addr.s_addr, (u8 *)ptr, 4);
248250
ptr += 4;
@@ -528,6 +530,7 @@ static bool mptcp_established_options_dss(struct sock *sk, struct sk_buff *skb,
528530
opts->ext_copy.ack64 = 0;
529531
}
530532
opts->ext_copy.use_ack = 1;
533+
WRITE_ONCE(msk->old_wspace, __mptcp_space((struct sock *)msk));
531534

532535
/* Add kind/length/subtype/flag overhead if mapping is not populated */
533536
if (dss_size == 0)
@@ -573,17 +576,27 @@ static u64 add_addr6_generate_hmac(u64 key1, u64 key2, u8 addr_id,
573576
}
574577
#endif
575578

576-
static bool mptcp_established_options_add_addr(struct sock *sk,
579+
static bool mptcp_established_options_add_addr(struct sock *sk, struct sk_buff *skb,
577580
unsigned int *size,
578581
unsigned int remaining,
579582
struct mptcp_out_options *opts)
580583
{
581584
struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
582585
struct mptcp_sock *msk = mptcp_sk(subflow->conn);
586+
bool drop_other_suboptions = false;
587+
unsigned int opt_size = *size;
583588
struct mptcp_addr_info saddr;
584589
bool echo;
585590
int len;
586591

592+
if (mptcp_pm_should_add_signal_ipv6(msk) &&
593+
skb && skb_is_tcp_pure_ack(skb)) {
594+
pr_debug("drop other suboptions");
595+
opts->suboptions = 0;
596+
remaining += opt_size;
597+
drop_other_suboptions = true;
598+
}
599+
587600
if (!mptcp_pm_should_add_signal(msk) ||
588601
!(mptcp_pm_add_addr_signal(msk, remaining, &saddr, &echo)))
589602
return false;
@@ -593,6 +606,8 @@ static bool mptcp_established_options_add_addr(struct sock *sk,
593606
return false;
594607

595608
*size = len;
609+
if (drop_other_suboptions)
610+
*size -= opt_size;
596611
opts->addr_id = saddr.id;
597612
if (saddr.family == AF_INET) {
598613
opts->suboptions |= OPTION_MPTCP_ADD_ADDR;
@@ -678,7 +693,7 @@ bool mptcp_established_options(struct sock *sk, struct sk_buff *skb,
678693

679694
*size += opt_size;
680695
remaining -= opt_size;
681-
if (mptcp_established_options_add_addr(sk, &opt_size, remaining, opts)) {
696+
if (mptcp_established_options_add_addr(sk, skb, &opt_size, remaining, opts)) {
682697
*size += opt_size;
683698
remaining -= opt_size;
684699
ret = true;
@@ -759,6 +774,11 @@ static bool check_fully_established(struct mptcp_sock *msk, struct sock *ssk,
759774
goto fully_established;
760775
}
761776

777+
if (mp_opt->add_addr) {
778+
WRITE_ONCE(msk->fully_established, true);
779+
return true;
780+
}
781+
762782
/* If the first established packet does not contain MP_CAPABLE + data
763783
* then fallback to TCP. Fallback scenarios requires a reset for
764784
* MP_JOIN subflows.
@@ -991,7 +1011,24 @@ void mptcp_incoming_options(struct sock *sk, struct sk_buff *skb)
9911011
}
9921012
}
9931013

994-
void mptcp_write_options(__be32 *ptr, struct mptcp_out_options *opts)
1014+
static void mptcp_set_rwin(const struct tcp_sock *tp)
1015+
{
1016+
const struct sock *ssk = (const struct sock *)tp;
1017+
const struct mptcp_subflow_context *subflow;
1018+
struct mptcp_sock *msk;
1019+
u64 ack_seq;
1020+
1021+
subflow = mptcp_subflow_ctx(ssk);
1022+
msk = mptcp_sk(subflow->conn);
1023+
1024+
ack_seq = READ_ONCE(msk->ack_seq) + tp->rcv_wnd;
1025+
1026+
if (after64(ack_seq, READ_ONCE(msk->rcv_wnd_sent)))
1027+
WRITE_ONCE(msk->rcv_wnd_sent, ack_seq);
1028+
}
1029+
1030+
void mptcp_write_options(__be32 *ptr, const struct tcp_sock *tp,
1031+
struct mptcp_out_options *opts)
9951032
{
9961033
if ((OPTION_MPTCP_MPC_SYN | OPTION_MPTCP_MPC_SYNACK |
9971034
OPTION_MPTCP_MPC_ACK) & opts->suboptions) {
@@ -1148,4 +1185,7 @@ void mptcp_write_options(__be32 *ptr, struct mptcp_out_options *opts)
11481185
TCPOPT_NOP << 8 | TCPOPT_NOP, ptr);
11491186
}
11501187
}
1188+
1189+
if (tp)
1190+
mptcp_set_rwin(tp);
11511191
}

net/mptcp/pm.c

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,17 @@ int mptcp_pm_announce_addr(struct mptcp_sock *msk,
1616
const struct mptcp_addr_info *addr,
1717
bool echo)
1818
{
19+
u8 add_addr = READ_ONCE(msk->pm.add_addr_signal);
20+
1921
pr_debug("msk=%p, local_id=%d", msk, addr->id);
2022

2123
msk->pm.local = *addr;
22-
WRITE_ONCE(msk->pm.add_addr_echo, echo);
23-
WRITE_ONCE(msk->pm.add_addr_signal, true);
24+
add_addr |= BIT(MPTCP_ADD_ADDR_SIGNAL);
25+
if (echo)
26+
add_addr |= BIT(MPTCP_ADD_ADDR_ECHO);
27+
if (addr->family == AF_INET6)
28+
add_addr |= BIT(MPTCP_ADD_ADDR_IPV6);
29+
WRITE_ONCE(msk->pm.add_addr_signal, add_addr);
2430
return 0;
2531
}
2632

@@ -149,14 +155,24 @@ void mptcp_pm_add_addr_received(struct mptcp_sock *msk,
149155

150156
spin_lock_bh(&pm->lock);
151157

152-
if (!READ_ONCE(pm->accept_addr))
158+
if (!READ_ONCE(pm->accept_addr)) {
153159
mptcp_pm_announce_addr(msk, addr, true);
154-
else if (mptcp_pm_schedule_work(msk, MPTCP_PM_ADD_ADDR_RECEIVED))
160+
mptcp_pm_add_addr_send_ack(msk);
161+
} else if (mptcp_pm_schedule_work(msk, MPTCP_PM_ADD_ADDR_RECEIVED)) {
155162
pm->remote = *addr;
163+
}
156164

157165
spin_unlock_bh(&pm->lock);
158166
}
159167

168+
void mptcp_pm_add_addr_send_ack(struct mptcp_sock *msk)
169+
{
170+
if (!mptcp_pm_should_add_signal_ipv6(msk))
171+
return;
172+
173+
mptcp_pm_schedule_work(msk, MPTCP_PM_ADD_ADDR_SEND_ACK);
174+
}
175+
160176
void mptcp_pm_rm_addr_received(struct mptcp_sock *msk, u8 rm_id)
161177
{
162178
struct mptcp_pm_data *pm = &msk->pm;
@@ -182,13 +198,13 @@ bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
182198
if (!mptcp_pm_should_add_signal(msk))
183199
goto out_unlock;
184200

185-
*echo = READ_ONCE(msk->pm.add_addr_echo);
201+
*echo = mptcp_pm_should_add_signal_echo(msk);
186202

187203
if (remaining < mptcp_add_addr_len(msk->pm.local.family, *echo))
188204
goto out_unlock;
189205

190206
*saddr = msk->pm.local;
191-
WRITE_ONCE(msk->pm.add_addr_signal, false);
207+
WRITE_ONCE(msk->pm.add_addr_signal, 0);
192208
ret = true;
193209

194210
out_unlock:
@@ -232,11 +248,10 @@ void mptcp_pm_data_init(struct mptcp_sock *msk)
232248
msk->pm.subflows = 0;
233249
msk->pm.rm_id = 0;
234250
WRITE_ONCE(msk->pm.work_pending, false);
235-
WRITE_ONCE(msk->pm.add_addr_signal, false);
251+
WRITE_ONCE(msk->pm.add_addr_signal, 0);
236252
WRITE_ONCE(msk->pm.rm_addr_signal, false);
237253
WRITE_ONCE(msk->pm.accept_addr, false);
238254
WRITE_ONCE(msk->pm.accept_subflow, false);
239-
WRITE_ONCE(msk->pm.add_addr_echo, false);
240255
msk->pm.status = 0;
241256

242257
spin_lock_init(&msk->pm.lock);

net/mptcp/pm_netlink.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ static void mptcp_pm_add_timer(struct timer_list *timer)
228228
if (!mptcp_pm_should_add_signal(msk)) {
229229
pr_debug("retransmit ADD_ADDR id=%d", entry->addr.id);
230230
mptcp_pm_announce_addr(msk, &entry->addr, false);
231+
mptcp_pm_add_addr_send_ack(msk);
231232
entry->retrans_times++;
232233
}
233234

@@ -328,6 +329,7 @@ static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk)
328329
if (mptcp_pm_alloc_anno_list(msk, local)) {
329330
msk->pm.add_addr_signaled++;
330331
mptcp_pm_announce_addr(msk, &local->addr, false);
332+
mptcp_pm_nl_add_addr_send_ack(msk);
331333
}
332334
} else {
333335
/* pick failed, avoid fourther attempts later */
@@ -398,6 +400,33 @@ void mptcp_pm_nl_add_addr_received(struct mptcp_sock *msk)
398400
spin_lock_bh(&msk->pm.lock);
399401

400402
mptcp_pm_announce_addr(msk, &remote, true);
403+
mptcp_pm_nl_add_addr_send_ack(msk);
404+
}
405+
406+
void mptcp_pm_nl_add_addr_send_ack(struct mptcp_sock *msk)
407+
{
408+
struct mptcp_subflow_context *subflow;
409+
410+
if (!mptcp_pm_should_add_signal_ipv6(msk))
411+
return;
412+
413+
__mptcp_flush_join_list(msk);
414+
subflow = list_first_entry_or_null(&msk->conn_list, typeof(*subflow), node);
415+
if (subflow) {
416+
struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
417+
u8 add_addr;
418+
419+
spin_unlock_bh(&msk->pm.lock);
420+
pr_debug("send ack for add_addr6");
421+
lock_sock(ssk);
422+
tcp_send_ack(ssk);
423+
release_sock(ssk);
424+
spin_lock_bh(&msk->pm.lock);
425+
426+
add_addr = READ_ONCE(msk->pm.add_addr_signal);
427+
add_addr &= ~BIT(MPTCP_ADD_ADDR_IPV6);
428+
WRITE_ONCE(msk->pm.add_addr_signal, add_addr);
429+
}
401430
}
402431

403432
void mptcp_pm_nl_rm_addr_received(struct mptcp_sock *msk)

0 commit comments

Comments
 (0)