blob: 696b2c4613a7c4e2c065a51ed77532dadec6ceeb [file] [log] [blame]
Peter Krystad1b1c7a02020-03-27 14:48:38 -07001// SPDX-License-Identifier: GPL-2.0
2/* Multipath TCP
3 *
4 * Copyright (c) 2019, Intel Corporation.
5 */
Geliang Tangc85adce2020-04-03 17:14:08 +08006#define pr_fmt(fmt) "MPTCP: " fmt
7
Peter Krystad1b1c7a02020-03-27 14:48:38 -07008#include <linux/kernel.h>
9#include <net/tcp.h>
10#include <net/mptcp.h>
11#include "protocol.h"
12
Paolo Abenifc1b4e32021-08-13 15:15:46 -070013#include "mib.h"
14
Peter Krystad1b1c7a02020-03-27 14:48:38 -070015/* path manager command handlers */
16
17int mptcp_pm_announce_addr(struct mptcp_sock *msk,
Geliang Tang6a6c05a2020-09-24 08:29:50 +080018 const struct mptcp_addr_info *addr,
Geliang Tangf7efc772021-03-26 11:26:31 -070019 bool echo)
Peter Krystad1b1c7a02020-03-27 14:48:38 -070020{
Geliang Tang13ad9f02020-12-09 15:51:27 -080021 u8 add_addr = READ_ONCE(msk->pm.addr_signal);
Geliang Tangd91d3222020-11-19 11:45:59 -080022
Yonglong Li18fc1a92021-08-23 18:05:40 -070023 pr_debug("msk=%p, local_id=%d, echo=%d", msk, addr->id, echo);
Peter Krystad926bdea2020-03-27 14:48:41 -070024
Florian Westphal3abc05d2021-02-04 15:23:30 -080025 lockdep_assert_held(&msk->pm.lock);
26
Yonglong Li18fc1a92021-08-23 18:05:40 -070027 if (add_addr &
28 (echo ? BIT(MPTCP_ADD_ADDR_ECHO) : BIT(MPTCP_ADD_ADDR_SIGNAL))) {
29 pr_warn("addr_signal error, add_addr=%d, echo=%d", add_addr, echo);
Geliang Tang42842a42020-12-09 15:51:26 -080030 return -EINVAL;
31 }
32
Yonglong Li18fc1a92021-08-23 18:05:40 -070033 if (echo) {
34 msk->pm.remote = *addr;
Geliang Tangd91d3222020-11-19 11:45:59 -080035 add_addr |= BIT(MPTCP_ADD_ADDR_ECHO);
Yonglong Li18fc1a92021-08-23 18:05:40 -070036 } else {
37 msk->pm.local = *addr;
38 add_addr |= BIT(MPTCP_ADD_ADDR_SIGNAL);
39 }
Geliang Tang13ad9f02020-12-09 15:51:27 -080040 WRITE_ONCE(msk->pm.addr_signal, add_addr);
Peter Krystad926bdea2020-03-27 14:48:41 -070041 return 0;
Peter Krystad1b1c7a02020-03-27 14:48:38 -070042}
43
Geliang Tangcbde2782021-03-12 17:16:12 -080044int mptcp_pm_remove_addr(struct mptcp_sock *msk, const struct mptcp_rm_list *rm_list)
Peter Krystad1b1c7a02020-03-27 14:48:38 -070045{
Geliang Tang13ad9f02020-12-09 15:51:27 -080046 u8 rm_addr = READ_ONCE(msk->pm.addr_signal);
Geliang Tang42842a42020-12-09 15:51:26 -080047
Geliang Tangcbde2782021-03-12 17:16:12 -080048 pr_debug("msk=%p, rm_list_nr=%d", msk, rm_list->nr);
Geliang Tangb6c08382020-09-24 08:29:54 +080049
Geliang Tang42842a42020-12-09 15:51:26 -080050 if (rm_addr) {
51 pr_warn("addr_signal error, rm_addr=%d", rm_addr);
52 return -EINVAL;
53 }
54
Geliang Tangcbde2782021-03-12 17:16:12 -080055 msk->pm.rm_list_tx = *rm_list;
Geliang Tang42842a42020-12-09 15:51:26 -080056 rm_addr |= BIT(MPTCP_RM_ADDR_SIGNAL);
Geliang Tang13ad9f02020-12-09 15:51:27 -080057 WRITE_ONCE(msk->pm.addr_signal, rm_addr);
Geliang Tangb46a0232021-03-26 11:26:41 -070058 mptcp_pm_nl_addr_send_ack(msk);
Geliang Tangb6c08382020-09-24 08:29:54 +080059 return 0;
Peter Krystad1b1c7a02020-03-27 14:48:38 -070060}
61
Geliang Tangddd14bb2021-03-12 17:16:16 -080062int mptcp_pm_remove_subflow(struct mptcp_sock *msk, const struct mptcp_rm_list *rm_list)
Peter Krystad1b1c7a02020-03-27 14:48:38 -070063{
Geliang Tangddd14bb2021-03-12 17:16:16 -080064 pr_debug("msk=%p, rm_list_nr=%d", msk, rm_list->nr);
Geliang Tang0ee42612020-09-24 08:29:55 +080065
66 spin_lock_bh(&msk->pm.lock);
Geliang Tangddd14bb2021-03-12 17:16:16 -080067 mptcp_pm_nl_rm_subflow_received(msk, rm_list);
Geliang Tang0ee42612020-09-24 08:29:55 +080068 spin_unlock_bh(&msk->pm.lock);
69 return 0;
Peter Krystad1b1c7a02020-03-27 14:48:38 -070070}
71
72/* path manager event handlers */
73
Florian Westphal6c714f12021-02-12 15:59:58 -080074void mptcp_pm_new_connection(struct mptcp_sock *msk, const struct sock *ssk, int server_side)
Peter Krystad1b1c7a02020-03-27 14:48:38 -070075{
76 struct mptcp_pm_data *pm = &msk->pm;
77
78 pr_debug("msk=%p, token=%u side=%d", msk, msk->token, server_side);
79
80 WRITE_ONCE(pm->server_side, server_side);
Florian Westphalb911c972021-02-12 16:00:01 -080081 mptcp_event(MPTCP_EVENT_CREATED, msk, ssk, GFP_ATOMIC);
Peter Krystad1b1c7a02020-03-27 14:48:38 -070082}
83
84bool mptcp_pm_allow_new_subflow(struct mptcp_sock *msk)
85{
Peter Krystad926bdea2020-03-27 14:48:41 -070086 struct mptcp_pm_data *pm = &msk->pm;
Geliang Tanga914e582021-02-01 15:09:07 -080087 unsigned int subflows_max;
Geliang Tangf58f0652020-09-24 08:29:53 +080088 int ret = 0;
Peter Krystad926bdea2020-03-27 14:48:41 -070089
Geliang Tanga914e582021-02-01 15:09:07 -080090 subflows_max = mptcp_pm_get_subflows_max(msk);
91
Peter Krystad926bdea2020-03-27 14:48:41 -070092 pr_debug("msk=%p subflows=%d max=%d allow=%d", msk, pm->subflows,
Geliang Tanga914e582021-02-01 15:09:07 -080093 subflows_max, READ_ONCE(pm->accept_subflow));
Peter Krystad926bdea2020-03-27 14:48:41 -070094
95 /* try to avoid acquiring the lock below */
96 if (!READ_ONCE(pm->accept_subflow))
97 return false;
98
99 spin_lock_bh(&pm->lock);
Geliang Tangf58f0652020-09-24 08:29:53 +0800100 if (READ_ONCE(pm->accept_subflow)) {
Geliang Tanga914e582021-02-01 15:09:07 -0800101 ret = pm->subflows < subflows_max;
102 if (ret && ++pm->subflows == subflows_max)
Geliang Tangf58f0652020-09-24 08:29:53 +0800103 WRITE_ONCE(pm->accept_subflow, false);
104 }
Peter Krystad926bdea2020-03-27 14:48:41 -0700105 spin_unlock_bh(&pm->lock);
106
107 return ret;
108}
109
110/* return true if the new status bit is currently cleared, that is, this event
111 * can be server, eventually by an already scheduled work
112 */
113static bool mptcp_pm_schedule_work(struct mptcp_sock *msk,
114 enum mptcp_pm_status new_status)
115{
116 pr_debug("msk=%p status=%x new=%lx", msk, msk->pm.status,
117 BIT(new_status));
118 if (msk->pm.status & BIT(new_status))
119 return false;
120
121 msk->pm.status |= BIT(new_status);
Paolo Abeniba8f48f2020-11-16 10:48:05 +0100122 mptcp_schedule_work((struct sock *)msk);
Peter Krystad926bdea2020-03-27 14:48:41 -0700123 return true;
Peter Krystad1b1c7a02020-03-27 14:48:38 -0700124}
125
Florian Westphal6c714f12021-02-12 15:59:58 -0800126void mptcp_pm_fully_established(struct mptcp_sock *msk, const struct sock *ssk, gfp_t gfp)
Peter Krystad1b1c7a02020-03-27 14:48:38 -0700127{
Peter Krystad926bdea2020-03-27 14:48:41 -0700128 struct mptcp_pm_data *pm = &msk->pm;
Florian Westphalb911c972021-02-12 16:00:01 -0800129 bool announce = false;
Peter Krystad926bdea2020-03-27 14:48:41 -0700130
Peter Krystad1b1c7a02020-03-27 14:48:38 -0700131 pr_debug("msk=%p", msk);
Peter Krystad926bdea2020-03-27 14:48:41 -0700132
Peter Krystad926bdea2020-03-27 14:48:41 -0700133 spin_lock_bh(&pm->lock);
134
Paolo Abeni5b950ff2020-12-09 12:03:29 +0100135 /* mptcp_pm_fully_established() can be invoked by multiple
136 * racing paths - accept() and check_fully_established()
137 * be sure to serve this event only once.
138 */
139 if (READ_ONCE(pm->work_pending) &&
140 !(msk->pm.status & BIT(MPTCP_PM_ALREADY_ESTABLISHED)))
Peter Krystad926bdea2020-03-27 14:48:41 -0700141 mptcp_pm_schedule_work(msk, MPTCP_PM_ESTABLISHED);
142
Florian Westphalb911c972021-02-12 16:00:01 -0800143 if ((msk->pm.status & BIT(MPTCP_PM_ALREADY_ESTABLISHED)) == 0)
144 announce = true;
145
146 msk->pm.status |= BIT(MPTCP_PM_ALREADY_ESTABLISHED);
Peter Krystad926bdea2020-03-27 14:48:41 -0700147 spin_unlock_bh(&pm->lock);
Florian Westphalb911c972021-02-12 16:00:01 -0800148
149 if (announce)
150 mptcp_event(MPTCP_EVENT_ESTABLISHED, msk, ssk, gfp);
Peter Krystad1b1c7a02020-03-27 14:48:38 -0700151}
152
153void mptcp_pm_connection_closed(struct mptcp_sock *msk)
154{
155 pr_debug("msk=%p", msk);
156}
157
Geliang Tang625352002021-03-26 11:26:33 -0700158void mptcp_pm_subflow_established(struct mptcp_sock *msk)
Peter Krystad1b1c7a02020-03-27 14:48:38 -0700159{
Peter Krystad926bdea2020-03-27 14:48:41 -0700160 struct mptcp_pm_data *pm = &msk->pm;
161
Peter Krystad1b1c7a02020-03-27 14:48:38 -0700162 pr_debug("msk=%p", msk);
Peter Krystad926bdea2020-03-27 14:48:41 -0700163
164 if (!READ_ONCE(pm->work_pending))
165 return;
166
167 spin_lock_bh(&pm->lock);
168
169 if (READ_ONCE(pm->work_pending))
170 mptcp_pm_schedule_work(msk, MPTCP_PM_SUBFLOW_ESTABLISHED);
171
172 spin_unlock_bh(&pm->lock);
Peter Krystad1b1c7a02020-03-27 14:48:38 -0700173}
174
Paolo Abenia88c9e42022-01-06 16:20:23 -0800175void mptcp_pm_subflow_check_next(struct mptcp_sock *msk, const struct sock *ssk,
176 const struct mptcp_subflow_context *subflow)
Peter Krystad1b1c7a02020-03-27 14:48:38 -0700177{
Paolo Abenia88c9e42022-01-06 16:20:23 -0800178 struct mptcp_pm_data *pm = &msk->pm;
179 bool update_subflows;
180
181 update_subflows = (ssk->sk_state == TCP_CLOSE) &&
182 (subflow->request_join || subflow->mp_join);
183 if (!READ_ONCE(pm->work_pending) && !update_subflows)
184 return;
185
186 spin_lock_bh(&pm->lock);
187 if (update_subflows)
188 pm->subflows--;
189
190 /* Even if this subflow is not really established, tell the PM to try
191 * to pick the next ones, if possible.
192 */
193 if (mptcp_pm_nl_check_work_pending(msk))
194 mptcp_pm_schedule_work(msk, MPTCP_PM_SUBFLOW_ESTABLISHED);
195
196 spin_unlock_bh(&pm->lock);
Peter Krystad1b1c7a02020-03-27 14:48:38 -0700197}
198
199void mptcp_pm_add_addr_received(struct mptcp_sock *msk,
200 const struct mptcp_addr_info *addr)
201{
Peter Krystad926bdea2020-03-27 14:48:41 -0700202 struct mptcp_pm_data *pm = &msk->pm;
203
204 pr_debug("msk=%p remote_id=%d accept=%d", msk, addr->id,
205 READ_ONCE(pm->accept_addr));
206
Florian Westphalb911c972021-02-12 16:00:01 -0800207 mptcp_event_addr_announced(msk, addr);
208
Peter Krystad926bdea2020-03-27 14:48:41 -0700209 spin_lock_bh(&pm->lock);
210
Geliang Tang84dfe362020-11-19 11:46:00 -0800211 if (!READ_ONCE(pm->accept_addr)) {
Geliang Tangf7efc772021-03-26 11:26:31 -0700212 mptcp_pm_announce_addr(msk, addr, true);
Geliang Tang84dfe362020-11-19 11:46:00 -0800213 mptcp_pm_add_addr_send_ack(msk);
214 } else if (mptcp_pm_schedule_work(msk, MPTCP_PM_ADD_ADDR_RECEIVED)) {
Peter Krystad926bdea2020-03-27 14:48:41 -0700215 pm->remote = *addr;
Geliang Tang84dfe362020-11-19 11:46:00 -0800216 }
Peter Krystad926bdea2020-03-27 14:48:41 -0700217
218 spin_unlock_bh(&pm->lock);
Peter Krystad1b1c7a02020-03-27 14:48:38 -0700219}
220
Geliang Tang557963c2021-03-26 11:26:38 -0700221void mptcp_pm_add_addr_echoed(struct mptcp_sock *msk,
222 struct mptcp_addr_info *addr)
223{
224 struct mptcp_pm_data *pm = &msk->pm;
225
226 pr_debug("msk=%p", msk);
227
228 spin_lock_bh(&pm->lock);
229
230 if (mptcp_lookup_anno_list_by_saddr(msk, addr) && READ_ONCE(pm->work_pending))
231 mptcp_pm_schedule_work(msk, MPTCP_PM_SUBFLOW_ESTABLISHED);
232
233 spin_unlock_bh(&pm->lock);
234}
235
Geliang Tang84dfe362020-11-19 11:46:00 -0800236void mptcp_pm_add_addr_send_ack(struct mptcp_sock *msk)
237{
Geliang Tangb5a7acd2021-02-01 15:09:09 -0800238 if (!mptcp_pm_should_add_signal(msk))
Geliang Tang84dfe362020-11-19 11:46:00 -0800239 return;
240
241 mptcp_pm_schedule_work(msk, MPTCP_PM_ADD_ADDR_SEND_ACK);
242}
243
Geliang Tang5c4a8242021-03-12 17:16:13 -0800244void mptcp_pm_rm_addr_received(struct mptcp_sock *msk,
245 const struct mptcp_rm_list *rm_list)
Geliang Tangd0876b22020-09-24 08:29:49 +0800246{
247 struct mptcp_pm_data *pm = &msk->pm;
Geliang Tang5c4a8242021-03-12 17:16:13 -0800248 u8 i;
Geliang Tangd0876b22020-09-24 08:29:49 +0800249
Geliang Tang5c4a8242021-03-12 17:16:13 -0800250 pr_debug("msk=%p remote_ids_nr=%d", msk, rm_list->nr);
Geliang Tangd0876b22020-09-24 08:29:49 +0800251
Geliang Tang5c4a8242021-03-12 17:16:13 -0800252 for (i = 0; i < rm_list->nr; i++)
253 mptcp_event_addr_removed(msk, rm_list->ids[i]);
Florian Westphalb911c972021-02-12 16:00:01 -0800254
Geliang Tangd0876b22020-09-24 08:29:49 +0800255 spin_lock_bh(&pm->lock);
256 mptcp_pm_schedule_work(msk, MPTCP_PM_RM_ADDR_RECEIVED);
Geliang Tangb5c55f32021-03-12 17:16:14 -0800257 pm->rm_list_rx = *rm_list;
Geliang Tangd0876b22020-09-24 08:29:49 +0800258 spin_unlock_bh(&pm->lock);
259}
260
Geliang Tang40453a52021-01-08 16:47:58 -0800261void mptcp_pm_mp_prio_received(struct sock *sk, u8 bkup)
262{
263 struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
264
265 pr_debug("subflow->backup=%d, bkup=%d\n", subflow->backup, bkup);
266 subflow->backup = bkup;
Florian Westphalb911c972021-02-12 16:00:01 -0800267
268 mptcp_event(MPTCP_EVENT_SUB_PRIORITY, mptcp_sk(subflow->conn), sk, GFP_ATOMIC);
Geliang Tang40453a52021-01-08 16:47:58 -0800269}
270
Geliang Tang5580d412021-08-24 16:26:16 -0700271void mptcp_pm_mp_fail_received(struct sock *sk, u64 fail_seq)
272{
273 pr_debug("fail_seq=%llu", fail_seq);
274}
275
Peter Krystad1b1c7a02020-03-27 14:48:38 -0700276/* path manager helpers */
277
Yonglong Li1f5e9e22021-08-23 18:05:39 -0700278bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, struct sk_buff *skb,
279 unsigned int opt_size, unsigned int remaining,
Yonglong Lif462a442021-08-23 18:05:42 -0700280 struct mptcp_addr_info *addr, bool *echo,
Yonglong Li1f5e9e22021-08-23 18:05:39 -0700281 bool *port, bool *drop_other_suboptions)
Peter Krystad1b1c7a02020-03-27 14:48:38 -0700282{
Peter Krystad926bdea2020-03-27 14:48:41 -0700283 int ret = false;
Yonglong Li119c0222021-08-23 18:05:41 -0700284 u8 add_addr;
Yonglong Lif462a442021-08-23 18:05:42 -0700285 u8 family;
Peter Krystad926bdea2020-03-27 14:48:41 -0700286
287 spin_lock_bh(&msk->pm.lock);
288
289 /* double check after the lock is acquired */
Geliang Tangf643b802020-09-24 08:29:47 +0800290 if (!mptcp_pm_should_add_signal(msk))
Peter Krystad926bdea2020-03-27 14:48:41 -0700291 goto out_unlock;
292
Yonglong Li1f5e9e22021-08-23 18:05:39 -0700293 /* always drop every other options for pure ack ADD_ADDR; this is a
294 * plain dup-ack from TCP perspective. The other MPTCP-relevant info,
295 * if any, will be carried by the 'original' TCP ack
296 */
297 if (skb && skb_is_tcp_pure_ack(skb)) {
298 remaining += opt_size;
299 *drop_other_suboptions = true;
300 }
301
Geliang Tangd91d3222020-11-19 11:45:59 -0800302 *echo = mptcp_pm_should_add_signal_echo(msk);
Yonglong Lic233ef12021-08-23 18:05:43 -0700303 *port = !!(*echo ? msk->pm.remote.port : msk->pm.local.port);
Matthieu Baerts456afe02020-10-03 17:36:56 +0200304
Yonglong Lif462a442021-08-23 18:05:42 -0700305 family = *echo ? msk->pm.remote.family : msk->pm.local.family;
306 if (remaining < mptcp_add_addr_len(family, *echo, *port))
Peter Krystad926bdea2020-03-27 14:48:41 -0700307 goto out_unlock;
308
Yonglong Lif462a442021-08-23 18:05:42 -0700309 if (*echo) {
310 *addr = msk->pm.remote;
Yonglong Li119c0222021-08-23 18:05:41 -0700311 add_addr = msk->pm.addr_signal & ~BIT(MPTCP_ADD_ADDR_ECHO);
Yonglong Lif462a442021-08-23 18:05:42 -0700312 } else {
313 *addr = msk->pm.local;
Yonglong Li119c0222021-08-23 18:05:41 -0700314 add_addr = msk->pm.addr_signal & ~BIT(MPTCP_ADD_ADDR_SIGNAL);
Yonglong Lif462a442021-08-23 18:05:42 -0700315 }
Yonglong Li119c0222021-08-23 18:05:41 -0700316 WRITE_ONCE(msk->pm.addr_signal, add_addr);
Peter Krystad926bdea2020-03-27 14:48:41 -0700317 ret = true;
318
319out_unlock:
320 spin_unlock_bh(&msk->pm.lock);
321 return ret;
Peter Krystad1b1c7a02020-03-27 14:48:38 -0700322}
323
Geliang Tang5cb104a2020-09-24 08:29:48 +0800324bool mptcp_pm_rm_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
Geliang Tang6445e172021-03-12 17:16:11 -0800325 struct mptcp_rm_list *rm_list)
Geliang Tang5cb104a2020-09-24 08:29:48 +0800326{
Geliang Tangcbde2782021-03-12 17:16:12 -0800327 int ret = false, len;
Yonglong Li119c0222021-08-23 18:05:41 -0700328 u8 rm_addr;
Geliang Tang5cb104a2020-09-24 08:29:48 +0800329
330 spin_lock_bh(&msk->pm.lock);
331
332 /* double check after the lock is acquired */
333 if (!mptcp_pm_should_rm_signal(msk))
334 goto out_unlock;
335
Yonglong Li119c0222021-08-23 18:05:41 -0700336 rm_addr = msk->pm.addr_signal & ~BIT(MPTCP_RM_ADDR_SIGNAL);
Geliang Tangcbde2782021-03-12 17:16:12 -0800337 len = mptcp_rm_addr_len(&msk->pm.rm_list_tx);
338 if (len < 0) {
Yonglong Li119c0222021-08-23 18:05:41 -0700339 WRITE_ONCE(msk->pm.addr_signal, rm_addr);
Geliang Tangcbde2782021-03-12 17:16:12 -0800340 goto out_unlock;
341 }
342 if (remaining < len)
Geliang Tang5cb104a2020-09-24 08:29:48 +0800343 goto out_unlock;
344
Geliang Tangcbde2782021-03-12 17:16:12 -0800345 *rm_list = msk->pm.rm_list_tx;
Yonglong Li119c0222021-08-23 18:05:41 -0700346 WRITE_ONCE(msk->pm.addr_signal, rm_addr);
Geliang Tang5cb104a2020-09-24 08:29:48 +0800347 ret = true;
348
349out_unlock:
350 spin_unlock_bh(&msk->pm.lock);
351 return ret;
352}
353
Peter Krystad1b1c7a02020-03-27 14:48:38 -0700354int mptcp_pm_get_local_id(struct mptcp_sock *msk, struct sock_common *skc)
355{
Paolo Abeni01cacb02020-03-27 14:48:51 -0700356 return mptcp_pm_nl_get_local_id(msk, skc);
Peter Krystad1b1c7a02020-03-27 14:48:38 -0700357}
358
Paolo Abeni71b7dec2021-08-13 15:15:42 -0700359void mptcp_pm_subflow_chk_stale(const struct mptcp_sock *msk, struct sock *ssk)
360{
361 struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk);
362 u32 rcv_tstamp = READ_ONCE(tcp_sk(ssk)->rcv_tstamp);
363
364 /* keep track of rtx periods with no progress */
365 if (!subflow->stale_count) {
366 subflow->stale_rcv_tstamp = rcv_tstamp;
367 subflow->stale_count++;
368 } else if (subflow->stale_rcv_tstamp == rcv_tstamp) {
369 if (subflow->stale_count < U8_MAX)
370 subflow->stale_count++;
Paolo Abeniff5a0b42021-08-13 15:15:45 -0700371 mptcp_pm_nl_subflow_chk_stale(msk, ssk);
Paolo Abeni71b7dec2021-08-13 15:15:42 -0700372 } else {
373 subflow->stale_count = 0;
Paolo Abeniff5a0b42021-08-13 15:15:45 -0700374 mptcp_subflow_set_active(subflow);
Paolo Abeni71b7dec2021-08-13 15:15:42 -0700375 }
376}
377
Paolo Abenib29fcfb2022-01-06 16:20:16 -0800378void mptcp_pm_data_reset(struct mptcp_sock *msk)
Peter Krystad1b1c7a02020-03-27 14:48:38 -0700379{
380 msk->pm.add_addr_signaled = 0;
381 msk->pm.add_addr_accepted = 0;
382 msk->pm.local_addr_used = 0;
383 msk->pm.subflows = 0;
Geliang Tangcbde2782021-03-12 17:16:12 -0800384 msk->pm.rm_list_tx.nr = 0;
Geliang Tangb5c55f32021-03-12 17:16:14 -0800385 msk->pm.rm_list_rx.nr = 0;
Peter Krystad1b1c7a02020-03-27 14:48:38 -0700386 WRITE_ONCE(msk->pm.work_pending, false);
Geliang Tang13ad9f02020-12-09 15:51:27 -0800387 WRITE_ONCE(msk->pm.addr_signal, 0);
Peter Krystad1b1c7a02020-03-27 14:48:38 -0700388 WRITE_ONCE(msk->pm.accept_addr, false);
389 WRITE_ONCE(msk->pm.accept_subflow, false);
Geliang Tangdf377be2021-06-22 12:25:20 -0700390 WRITE_ONCE(msk->pm.remote_deny_join_id0, false);
Peter Krystad1b1c7a02020-03-27 14:48:38 -0700391 msk->pm.status = 0;
Paolo Abeni86e39e02022-01-06 16:20:22 -0800392 bitmap_fill(msk->pm.id_avail_bitmap, MPTCP_PM_MAX_ADDR_ID + 1);
Peter Krystad1b1c7a02020-03-27 14:48:38 -0700393
Paolo Abenib29fcfb2022-01-06 16:20:16 -0800394 mptcp_pm_nl_data_init(msk);
395}
396
397void mptcp_pm_data_init(struct mptcp_sock *msk)
398{
Peter Krystad1b1c7a02020-03-27 14:48:38 -0700399 spin_lock_init(&msk->pm.lock);
Geliang Tangb6c08382020-09-24 08:29:54 +0800400 INIT_LIST_HEAD(&msk->pm.anno_list);
Paolo Abenib29fcfb2022-01-06 16:20:16 -0800401 mptcp_pm_data_reset(msk);
Peter Krystad1b1c7a02020-03-27 14:48:38 -0700402}
403
Paolo Abenid39dcec2020-06-26 19:29:59 +0200404void __init mptcp_pm_init(void)
Peter Krystad1b1c7a02020-03-27 14:48:38 -0700405{
Paolo Abeni01cacb02020-03-27 14:48:51 -0700406 mptcp_pm_nl_init();
Peter Krystad1b1c7a02020-03-27 14:48:38 -0700407}