Peter Krystad | 1b1c7a0 | 2020-03-27 14:48:38 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* Multipath TCP |
| 3 | * |
| 4 | * Copyright (c) 2019, Intel Corporation. |
| 5 | */ |
Geliang Tang | c85adce | 2020-04-03 17:14:08 +0800 | [diff] [blame] | 6 | #define pr_fmt(fmt) "MPTCP: " fmt |
| 7 | |
Peter Krystad | 1b1c7a0 | 2020-03-27 14:48:38 -0700 | [diff] [blame] | 8 | #include <linux/kernel.h> |
| 9 | #include <net/tcp.h> |
| 10 | #include <net/mptcp.h> |
| 11 | #include "protocol.h" |
| 12 | |
Peter Krystad | 1b1c7a0 | 2020-03-27 14:48:38 -0700 | [diff] [blame] | 13 | /* path manager command handlers */ |
| 14 | |
| 15 | int mptcp_pm_announce_addr(struct mptcp_sock *msk, |
Geliang Tang | 6a6c05a | 2020-09-24 08:29:50 +0800 | [diff] [blame] | 16 | const struct mptcp_addr_info *addr, |
Geliang Tang | 0f5c9e3 | 2020-12-09 15:51:24 -0800 | [diff] [blame] | 17 | bool echo, bool port) |
Peter Krystad | 1b1c7a0 | 2020-03-27 14:48:38 -0700 | [diff] [blame] | 18 | { |
Geliang Tang | 13ad9f0 | 2020-12-09 15:51:27 -0800 | [diff] [blame] | 19 | u8 add_addr = READ_ONCE(msk->pm.addr_signal); |
Geliang Tang | d91d322 | 2020-11-19 11:45:59 -0800 | [diff] [blame] | 20 | |
Peter Krystad | 926bdea | 2020-03-27 14:48:41 -0700 | [diff] [blame] | 21 | pr_debug("msk=%p, local_id=%d", msk, addr->id); |
| 22 | |
Florian Westphal | 3abc05d | 2021-02-04 15:23:30 -0800 | [diff] [blame] | 23 | lockdep_assert_held(&msk->pm.lock); |
| 24 | |
Geliang Tang | 42842a4 | 2020-12-09 15:51:26 -0800 | [diff] [blame] | 25 | if (add_addr) { |
| 26 | pr_warn("addr_signal error, add_addr=%d", add_addr); |
| 27 | return -EINVAL; |
| 28 | } |
| 29 | |
Peter Krystad | 926bdea | 2020-03-27 14:48:41 -0700 | [diff] [blame] | 30 | msk->pm.local = *addr; |
Geliang Tang | d91d322 | 2020-11-19 11:45:59 -0800 | [diff] [blame] | 31 | add_addr |= BIT(MPTCP_ADD_ADDR_SIGNAL); |
| 32 | if (echo) |
| 33 | add_addr |= BIT(MPTCP_ADD_ADDR_ECHO); |
Geliang Tang | 84dfe36 | 2020-11-19 11:46:00 -0800 | [diff] [blame] | 34 | if (addr->family == AF_INET6) |
| 35 | add_addr |= BIT(MPTCP_ADD_ADDR_IPV6); |
Geliang Tang | 0f5c9e3 | 2020-12-09 15:51:24 -0800 | [diff] [blame] | 36 | if (port) |
| 37 | add_addr |= BIT(MPTCP_ADD_ADDR_PORT); |
Geliang Tang | 13ad9f0 | 2020-12-09 15:51:27 -0800 | [diff] [blame] | 38 | WRITE_ONCE(msk->pm.addr_signal, add_addr); |
Peter Krystad | 926bdea | 2020-03-27 14:48:41 -0700 | [diff] [blame] | 39 | return 0; |
Peter Krystad | 1b1c7a0 | 2020-03-27 14:48:38 -0700 | [diff] [blame] | 40 | } |
| 41 | |
Geliang Tang | cbde278 | 2021-03-12 17:16:12 -0800 | [diff] [blame] | 42 | int mptcp_pm_remove_addr(struct mptcp_sock *msk, const struct mptcp_rm_list *rm_list) |
Peter Krystad | 1b1c7a0 | 2020-03-27 14:48:38 -0700 | [diff] [blame] | 43 | { |
Geliang Tang | 13ad9f0 | 2020-12-09 15:51:27 -0800 | [diff] [blame] | 44 | u8 rm_addr = READ_ONCE(msk->pm.addr_signal); |
Geliang Tang | 42842a4 | 2020-12-09 15:51:26 -0800 | [diff] [blame] | 45 | |
Geliang Tang | cbde278 | 2021-03-12 17:16:12 -0800 | [diff] [blame] | 46 | pr_debug("msk=%p, rm_list_nr=%d", msk, rm_list->nr); |
Geliang Tang | b6c0838 | 2020-09-24 08:29:54 +0800 | [diff] [blame] | 47 | |
Geliang Tang | 42842a4 | 2020-12-09 15:51:26 -0800 | [diff] [blame] | 48 | if (rm_addr) { |
| 49 | pr_warn("addr_signal error, rm_addr=%d", rm_addr); |
| 50 | return -EINVAL; |
| 51 | } |
| 52 | |
Geliang Tang | cbde278 | 2021-03-12 17:16:12 -0800 | [diff] [blame] | 53 | msk->pm.rm_list_tx = *rm_list; |
Geliang Tang | 42842a4 | 2020-12-09 15:51:26 -0800 | [diff] [blame] | 54 | rm_addr |= BIT(MPTCP_RM_ADDR_SIGNAL); |
Geliang Tang | 13ad9f0 | 2020-12-09 15:51:27 -0800 | [diff] [blame] | 55 | WRITE_ONCE(msk->pm.addr_signal, rm_addr); |
Geliang Tang | b6c0838 | 2020-09-24 08:29:54 +0800 | [diff] [blame] | 56 | return 0; |
Peter Krystad | 1b1c7a0 | 2020-03-27 14:48:38 -0700 | [diff] [blame] | 57 | } |
| 58 | |
Geliang Tang | 0ee4261 | 2020-09-24 08:29:55 +0800 | [diff] [blame] | 59 | int mptcp_pm_remove_subflow(struct mptcp_sock *msk, u8 local_id) |
Peter Krystad | 1b1c7a0 | 2020-03-27 14:48:38 -0700 | [diff] [blame] | 60 | { |
Geliang Tang | 0ee4261 | 2020-09-24 08:29:55 +0800 | [diff] [blame] | 61 | pr_debug("msk=%p, local_id=%d", msk, local_id); |
| 62 | |
| 63 | spin_lock_bh(&msk->pm.lock); |
| 64 | mptcp_pm_nl_rm_subflow_received(msk, local_id); |
| 65 | spin_unlock_bh(&msk->pm.lock); |
| 66 | return 0; |
Peter Krystad | 1b1c7a0 | 2020-03-27 14:48:38 -0700 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | /* path manager event handlers */ |
| 70 | |
Florian Westphal | 6c714f1 | 2021-02-12 15:59:58 -0800 | [diff] [blame] | 71 | void mptcp_pm_new_connection(struct mptcp_sock *msk, const struct sock *ssk, int server_side) |
Peter Krystad | 1b1c7a0 | 2020-03-27 14:48:38 -0700 | [diff] [blame] | 72 | { |
| 73 | struct mptcp_pm_data *pm = &msk->pm; |
| 74 | |
| 75 | pr_debug("msk=%p, token=%u side=%d", msk, msk->token, server_side); |
| 76 | |
| 77 | WRITE_ONCE(pm->server_side, server_side); |
Florian Westphal | b911c97 | 2021-02-12 16:00:01 -0800 | [diff] [blame] | 78 | mptcp_event(MPTCP_EVENT_CREATED, msk, ssk, GFP_ATOMIC); |
Peter Krystad | 1b1c7a0 | 2020-03-27 14:48:38 -0700 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | bool mptcp_pm_allow_new_subflow(struct mptcp_sock *msk) |
| 82 | { |
Peter Krystad | 926bdea | 2020-03-27 14:48:41 -0700 | [diff] [blame] | 83 | struct mptcp_pm_data *pm = &msk->pm; |
Geliang Tang | a914e58 | 2021-02-01 15:09:07 -0800 | [diff] [blame] | 84 | unsigned int subflows_max; |
Geliang Tang | f58f065 | 2020-09-24 08:29:53 +0800 | [diff] [blame] | 85 | int ret = 0; |
Peter Krystad | 926bdea | 2020-03-27 14:48:41 -0700 | [diff] [blame] | 86 | |
Geliang Tang | a914e58 | 2021-02-01 15:09:07 -0800 | [diff] [blame] | 87 | subflows_max = mptcp_pm_get_subflows_max(msk); |
| 88 | |
Peter Krystad | 926bdea | 2020-03-27 14:48:41 -0700 | [diff] [blame] | 89 | pr_debug("msk=%p subflows=%d max=%d allow=%d", msk, pm->subflows, |
Geliang Tang | a914e58 | 2021-02-01 15:09:07 -0800 | [diff] [blame] | 90 | subflows_max, READ_ONCE(pm->accept_subflow)); |
Peter Krystad | 926bdea | 2020-03-27 14:48:41 -0700 | [diff] [blame] | 91 | |
| 92 | /* try to avoid acquiring the lock below */ |
| 93 | if (!READ_ONCE(pm->accept_subflow)) |
| 94 | return false; |
| 95 | |
| 96 | spin_lock_bh(&pm->lock); |
Geliang Tang | f58f065 | 2020-09-24 08:29:53 +0800 | [diff] [blame] | 97 | if (READ_ONCE(pm->accept_subflow)) { |
Geliang Tang | a914e58 | 2021-02-01 15:09:07 -0800 | [diff] [blame] | 98 | ret = pm->subflows < subflows_max; |
| 99 | if (ret && ++pm->subflows == subflows_max) |
Geliang Tang | f58f065 | 2020-09-24 08:29:53 +0800 | [diff] [blame] | 100 | WRITE_ONCE(pm->accept_subflow, false); |
| 101 | } |
Peter Krystad | 926bdea | 2020-03-27 14:48:41 -0700 | [diff] [blame] | 102 | spin_unlock_bh(&pm->lock); |
| 103 | |
| 104 | return ret; |
| 105 | } |
| 106 | |
| 107 | /* return true if the new status bit is currently cleared, that is, this event |
| 108 | * can be server, eventually by an already scheduled work |
| 109 | */ |
| 110 | static bool mptcp_pm_schedule_work(struct mptcp_sock *msk, |
| 111 | enum mptcp_pm_status new_status) |
| 112 | { |
| 113 | pr_debug("msk=%p status=%x new=%lx", msk, msk->pm.status, |
| 114 | BIT(new_status)); |
| 115 | if (msk->pm.status & BIT(new_status)) |
| 116 | return false; |
| 117 | |
| 118 | msk->pm.status |= BIT(new_status); |
Paolo Abeni | ba8f48f | 2020-11-16 10:48:05 +0100 | [diff] [blame] | 119 | mptcp_schedule_work((struct sock *)msk); |
Peter Krystad | 926bdea | 2020-03-27 14:48:41 -0700 | [diff] [blame] | 120 | return true; |
Peter Krystad | 1b1c7a0 | 2020-03-27 14:48:38 -0700 | [diff] [blame] | 121 | } |
| 122 | |
Florian Westphal | 6c714f1 | 2021-02-12 15:59:58 -0800 | [diff] [blame] | 123 | void mptcp_pm_fully_established(struct mptcp_sock *msk, const struct sock *ssk, gfp_t gfp) |
Peter Krystad | 1b1c7a0 | 2020-03-27 14:48:38 -0700 | [diff] [blame] | 124 | { |
Peter Krystad | 926bdea | 2020-03-27 14:48:41 -0700 | [diff] [blame] | 125 | struct mptcp_pm_data *pm = &msk->pm; |
Florian Westphal | b911c97 | 2021-02-12 16:00:01 -0800 | [diff] [blame] | 126 | bool announce = false; |
Peter Krystad | 926bdea | 2020-03-27 14:48:41 -0700 | [diff] [blame] | 127 | |
Peter Krystad | 1b1c7a0 | 2020-03-27 14:48:38 -0700 | [diff] [blame] | 128 | pr_debug("msk=%p", msk); |
Peter Krystad | 926bdea | 2020-03-27 14:48:41 -0700 | [diff] [blame] | 129 | |
Peter Krystad | 926bdea | 2020-03-27 14:48:41 -0700 | [diff] [blame] | 130 | spin_lock_bh(&pm->lock); |
| 131 | |
Paolo Abeni | 5b950ff | 2020-12-09 12:03:29 +0100 | [diff] [blame] | 132 | /* mptcp_pm_fully_established() can be invoked by multiple |
| 133 | * racing paths - accept() and check_fully_established() |
| 134 | * be sure to serve this event only once. |
| 135 | */ |
| 136 | if (READ_ONCE(pm->work_pending) && |
| 137 | !(msk->pm.status & BIT(MPTCP_PM_ALREADY_ESTABLISHED))) |
Peter Krystad | 926bdea | 2020-03-27 14:48:41 -0700 | [diff] [blame] | 138 | mptcp_pm_schedule_work(msk, MPTCP_PM_ESTABLISHED); |
| 139 | |
Florian Westphal | b911c97 | 2021-02-12 16:00:01 -0800 | [diff] [blame] | 140 | if ((msk->pm.status & BIT(MPTCP_PM_ALREADY_ESTABLISHED)) == 0) |
| 141 | announce = true; |
| 142 | |
| 143 | msk->pm.status |= BIT(MPTCP_PM_ALREADY_ESTABLISHED); |
Peter Krystad | 926bdea | 2020-03-27 14:48:41 -0700 | [diff] [blame] | 144 | spin_unlock_bh(&pm->lock); |
Florian Westphal | b911c97 | 2021-02-12 16:00:01 -0800 | [diff] [blame] | 145 | |
| 146 | if (announce) |
| 147 | mptcp_event(MPTCP_EVENT_ESTABLISHED, msk, ssk, gfp); |
Peter Krystad | 1b1c7a0 | 2020-03-27 14:48:38 -0700 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | void mptcp_pm_connection_closed(struct mptcp_sock *msk) |
| 151 | { |
| 152 | pr_debug("msk=%p", msk); |
| 153 | } |
| 154 | |
| 155 | void mptcp_pm_subflow_established(struct mptcp_sock *msk, |
| 156 | struct mptcp_subflow_context *subflow) |
| 157 | { |
Peter Krystad | 926bdea | 2020-03-27 14:48:41 -0700 | [diff] [blame] | 158 | struct mptcp_pm_data *pm = &msk->pm; |
| 159 | |
Peter Krystad | 1b1c7a0 | 2020-03-27 14:48:38 -0700 | [diff] [blame] | 160 | pr_debug("msk=%p", msk); |
Peter Krystad | 926bdea | 2020-03-27 14:48:41 -0700 | [diff] [blame] | 161 | |
| 162 | if (!READ_ONCE(pm->work_pending)) |
| 163 | return; |
| 164 | |
| 165 | spin_lock_bh(&pm->lock); |
| 166 | |
| 167 | if (READ_ONCE(pm->work_pending)) |
| 168 | mptcp_pm_schedule_work(msk, MPTCP_PM_SUBFLOW_ESTABLISHED); |
| 169 | |
| 170 | spin_unlock_bh(&pm->lock); |
Peter Krystad | 1b1c7a0 | 2020-03-27 14:48:38 -0700 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | void mptcp_pm_subflow_closed(struct mptcp_sock *msk, u8 id) |
| 174 | { |
| 175 | pr_debug("msk=%p", msk); |
| 176 | } |
| 177 | |
| 178 | void mptcp_pm_add_addr_received(struct mptcp_sock *msk, |
| 179 | const struct mptcp_addr_info *addr) |
| 180 | { |
Peter Krystad | 926bdea | 2020-03-27 14:48:41 -0700 | [diff] [blame] | 181 | struct mptcp_pm_data *pm = &msk->pm; |
| 182 | |
| 183 | pr_debug("msk=%p remote_id=%d accept=%d", msk, addr->id, |
| 184 | READ_ONCE(pm->accept_addr)); |
| 185 | |
Florian Westphal | b911c97 | 2021-02-12 16:00:01 -0800 | [diff] [blame] | 186 | mptcp_event_addr_announced(msk, addr); |
| 187 | |
Peter Krystad | 926bdea | 2020-03-27 14:48:41 -0700 | [diff] [blame] | 188 | spin_lock_bh(&pm->lock); |
| 189 | |
Geliang Tang | 84dfe36 | 2020-11-19 11:46:00 -0800 | [diff] [blame] | 190 | if (!READ_ONCE(pm->accept_addr)) { |
Geliang Tang | 0f5c9e3 | 2020-12-09 15:51:24 -0800 | [diff] [blame] | 191 | mptcp_pm_announce_addr(msk, addr, true, addr->port); |
Geliang Tang | 84dfe36 | 2020-11-19 11:46:00 -0800 | [diff] [blame] | 192 | mptcp_pm_add_addr_send_ack(msk); |
| 193 | } else if (mptcp_pm_schedule_work(msk, MPTCP_PM_ADD_ADDR_RECEIVED)) { |
Peter Krystad | 926bdea | 2020-03-27 14:48:41 -0700 | [diff] [blame] | 194 | pm->remote = *addr; |
Geliang Tang | 84dfe36 | 2020-11-19 11:46:00 -0800 | [diff] [blame] | 195 | } |
Peter Krystad | 926bdea | 2020-03-27 14:48:41 -0700 | [diff] [blame] | 196 | |
| 197 | spin_unlock_bh(&pm->lock); |
Peter Krystad | 1b1c7a0 | 2020-03-27 14:48:38 -0700 | [diff] [blame] | 198 | } |
| 199 | |
Geliang Tang | 84dfe36 | 2020-11-19 11:46:00 -0800 | [diff] [blame] | 200 | void mptcp_pm_add_addr_send_ack(struct mptcp_sock *msk) |
| 201 | { |
Geliang Tang | b5a7acd | 2021-02-01 15:09:09 -0800 | [diff] [blame] | 202 | if (!mptcp_pm_should_add_signal(msk)) |
Geliang Tang | 84dfe36 | 2020-11-19 11:46:00 -0800 | [diff] [blame] | 203 | return; |
| 204 | |
| 205 | mptcp_pm_schedule_work(msk, MPTCP_PM_ADD_ADDR_SEND_ACK); |
| 206 | } |
| 207 | |
Geliang Tang | 5c4a824 | 2021-03-12 17:16:13 -0800 | [diff] [blame] | 208 | void mptcp_pm_rm_addr_received(struct mptcp_sock *msk, |
| 209 | const struct mptcp_rm_list *rm_list) |
Geliang Tang | d0876b2 | 2020-09-24 08:29:49 +0800 | [diff] [blame] | 210 | { |
| 211 | struct mptcp_pm_data *pm = &msk->pm; |
Geliang Tang | 5c4a824 | 2021-03-12 17:16:13 -0800 | [diff] [blame] | 212 | u8 i; |
Geliang Tang | d0876b2 | 2020-09-24 08:29:49 +0800 | [diff] [blame] | 213 | |
Geliang Tang | 5c4a824 | 2021-03-12 17:16:13 -0800 | [diff] [blame] | 214 | pr_debug("msk=%p remote_ids_nr=%d", msk, rm_list->nr); |
Geliang Tang | d0876b2 | 2020-09-24 08:29:49 +0800 | [diff] [blame] | 215 | |
Geliang Tang | 5c4a824 | 2021-03-12 17:16:13 -0800 | [diff] [blame] | 216 | for (i = 0; i < rm_list->nr; i++) |
| 217 | mptcp_event_addr_removed(msk, rm_list->ids[i]); |
Florian Westphal | b911c97 | 2021-02-12 16:00:01 -0800 | [diff] [blame] | 218 | |
Geliang Tang | d0876b2 | 2020-09-24 08:29:49 +0800 | [diff] [blame] | 219 | spin_lock_bh(&pm->lock); |
| 220 | mptcp_pm_schedule_work(msk, MPTCP_PM_RM_ADDR_RECEIVED); |
Geliang Tang | b5c55f3 | 2021-03-12 17:16:14 -0800 | [diff] [blame] | 221 | pm->rm_list_rx = *rm_list; |
Geliang Tang | d0876b2 | 2020-09-24 08:29:49 +0800 | [diff] [blame] | 222 | spin_unlock_bh(&pm->lock); |
| 223 | } |
| 224 | |
Geliang Tang | 40453a5 | 2021-01-08 16:47:58 -0800 | [diff] [blame] | 225 | void mptcp_pm_mp_prio_received(struct sock *sk, u8 bkup) |
| 226 | { |
| 227 | struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk); |
| 228 | |
| 229 | pr_debug("subflow->backup=%d, bkup=%d\n", subflow->backup, bkup); |
| 230 | subflow->backup = bkup; |
Florian Westphal | b911c97 | 2021-02-12 16:00:01 -0800 | [diff] [blame] | 231 | |
| 232 | mptcp_event(MPTCP_EVENT_SUB_PRIORITY, mptcp_sk(subflow->conn), sk, GFP_ATOMIC); |
Geliang Tang | 40453a5 | 2021-01-08 16:47:58 -0800 | [diff] [blame] | 233 | } |
| 234 | |
Peter Krystad | 1b1c7a0 | 2020-03-27 14:48:38 -0700 | [diff] [blame] | 235 | /* path manager helpers */ |
| 236 | |
Geliang Tang | f643b80 | 2020-09-24 08:29:47 +0800 | [diff] [blame] | 237 | bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, unsigned int remaining, |
Geliang Tang | 4a2777a8 | 2020-12-09 15:51:22 -0800 | [diff] [blame] | 238 | struct mptcp_addr_info *saddr, bool *echo, bool *port) |
Peter Krystad | 1b1c7a0 | 2020-03-27 14:48:38 -0700 | [diff] [blame] | 239 | { |
Peter Krystad | 926bdea | 2020-03-27 14:48:41 -0700 | [diff] [blame] | 240 | int ret = false; |
| 241 | |
| 242 | spin_lock_bh(&msk->pm.lock); |
| 243 | |
| 244 | /* double check after the lock is acquired */ |
Geliang Tang | f643b80 | 2020-09-24 08:29:47 +0800 | [diff] [blame] | 245 | if (!mptcp_pm_should_add_signal(msk)) |
Peter Krystad | 926bdea | 2020-03-27 14:48:41 -0700 | [diff] [blame] | 246 | goto out_unlock; |
| 247 | |
Geliang Tang | d91d322 | 2020-11-19 11:45:59 -0800 | [diff] [blame] | 248 | *echo = mptcp_pm_should_add_signal_echo(msk); |
Geliang Tang | 4a2777a8 | 2020-12-09 15:51:22 -0800 | [diff] [blame] | 249 | *port = mptcp_pm_should_add_signal_port(msk); |
Matthieu Baerts | 456afe0 | 2020-10-03 17:36:56 +0200 | [diff] [blame] | 250 | |
Geliang Tang | 4a2777a8 | 2020-12-09 15:51:22 -0800 | [diff] [blame] | 251 | if (remaining < mptcp_add_addr_len(msk->pm.local.family, *echo, *port)) |
Peter Krystad | 926bdea | 2020-03-27 14:48:41 -0700 | [diff] [blame] | 252 | goto out_unlock; |
| 253 | |
| 254 | *saddr = msk->pm.local; |
Geliang Tang | 13ad9f0 | 2020-12-09 15:51:27 -0800 | [diff] [blame] | 255 | WRITE_ONCE(msk->pm.addr_signal, 0); |
Peter Krystad | 926bdea | 2020-03-27 14:48:41 -0700 | [diff] [blame] | 256 | ret = true; |
| 257 | |
| 258 | out_unlock: |
| 259 | spin_unlock_bh(&msk->pm.lock); |
| 260 | return ret; |
Peter Krystad | 1b1c7a0 | 2020-03-27 14:48:38 -0700 | [diff] [blame] | 261 | } |
| 262 | |
Geliang Tang | 5cb104a | 2020-09-24 08:29:48 +0800 | [diff] [blame] | 263 | bool mptcp_pm_rm_addr_signal(struct mptcp_sock *msk, unsigned int remaining, |
Geliang Tang | 6445e17 | 2021-03-12 17:16:11 -0800 | [diff] [blame] | 264 | struct mptcp_rm_list *rm_list) |
Geliang Tang | 5cb104a | 2020-09-24 08:29:48 +0800 | [diff] [blame] | 265 | { |
Geliang Tang | cbde278 | 2021-03-12 17:16:12 -0800 | [diff] [blame] | 266 | int ret = false, len; |
Geliang Tang | 5cb104a | 2020-09-24 08:29:48 +0800 | [diff] [blame] | 267 | |
| 268 | spin_lock_bh(&msk->pm.lock); |
| 269 | |
| 270 | /* double check after the lock is acquired */ |
| 271 | if (!mptcp_pm_should_rm_signal(msk)) |
| 272 | goto out_unlock; |
| 273 | |
Geliang Tang | cbde278 | 2021-03-12 17:16:12 -0800 | [diff] [blame] | 274 | len = mptcp_rm_addr_len(&msk->pm.rm_list_tx); |
| 275 | if (len < 0) { |
| 276 | WRITE_ONCE(msk->pm.addr_signal, 0); |
| 277 | goto out_unlock; |
| 278 | } |
| 279 | if (remaining < len) |
Geliang Tang | 5cb104a | 2020-09-24 08:29:48 +0800 | [diff] [blame] | 280 | goto out_unlock; |
| 281 | |
Geliang Tang | cbde278 | 2021-03-12 17:16:12 -0800 | [diff] [blame] | 282 | *rm_list = msk->pm.rm_list_tx; |
Geliang Tang | 13ad9f0 | 2020-12-09 15:51:27 -0800 | [diff] [blame] | 283 | WRITE_ONCE(msk->pm.addr_signal, 0); |
Geliang Tang | 5cb104a | 2020-09-24 08:29:48 +0800 | [diff] [blame] | 284 | ret = true; |
| 285 | |
| 286 | out_unlock: |
| 287 | spin_unlock_bh(&msk->pm.lock); |
| 288 | return ret; |
| 289 | } |
| 290 | |
Peter Krystad | 1b1c7a0 | 2020-03-27 14:48:38 -0700 | [diff] [blame] | 291 | int mptcp_pm_get_local_id(struct mptcp_sock *msk, struct sock_common *skc) |
| 292 | { |
Paolo Abeni | 01cacb0 | 2020-03-27 14:48:51 -0700 | [diff] [blame] | 293 | return mptcp_pm_nl_get_local_id(msk, skc); |
Peter Krystad | 1b1c7a0 | 2020-03-27 14:48:38 -0700 | [diff] [blame] | 294 | } |
| 295 | |
Peter Krystad | 1b1c7a0 | 2020-03-27 14:48:38 -0700 | [diff] [blame] | 296 | void mptcp_pm_data_init(struct mptcp_sock *msk) |
| 297 | { |
| 298 | msk->pm.add_addr_signaled = 0; |
| 299 | msk->pm.add_addr_accepted = 0; |
| 300 | msk->pm.local_addr_used = 0; |
| 301 | msk->pm.subflows = 0; |
Geliang Tang | cbde278 | 2021-03-12 17:16:12 -0800 | [diff] [blame] | 302 | msk->pm.rm_list_tx.nr = 0; |
Geliang Tang | b5c55f3 | 2021-03-12 17:16:14 -0800 | [diff] [blame] | 303 | msk->pm.rm_list_rx.nr = 0; |
Peter Krystad | 1b1c7a0 | 2020-03-27 14:48:38 -0700 | [diff] [blame] | 304 | WRITE_ONCE(msk->pm.work_pending, false); |
Geliang Tang | 13ad9f0 | 2020-12-09 15:51:27 -0800 | [diff] [blame] | 305 | WRITE_ONCE(msk->pm.addr_signal, 0); |
Peter Krystad | 1b1c7a0 | 2020-03-27 14:48:38 -0700 | [diff] [blame] | 306 | WRITE_ONCE(msk->pm.accept_addr, false); |
| 307 | WRITE_ONCE(msk->pm.accept_subflow, false); |
| 308 | msk->pm.status = 0; |
| 309 | |
| 310 | spin_lock_init(&msk->pm.lock); |
Geliang Tang | b6c0838 | 2020-09-24 08:29:54 +0800 | [diff] [blame] | 311 | INIT_LIST_HEAD(&msk->pm.anno_list); |
Paolo Abeni | 01cacb0 | 2020-03-27 14:48:51 -0700 | [diff] [blame] | 312 | |
| 313 | mptcp_pm_nl_data_init(msk); |
Peter Krystad | 1b1c7a0 | 2020-03-27 14:48:38 -0700 | [diff] [blame] | 314 | } |
| 315 | |
Paolo Abeni | d39dcec | 2020-06-26 19:29:59 +0200 | [diff] [blame] | 316 | void __init mptcp_pm_init(void) |
Peter Krystad | 1b1c7a0 | 2020-03-27 14:48:38 -0700 | [diff] [blame] | 317 | { |
Paolo Abeni | 01cacb0 | 2020-03-27 14:48:51 -0700 | [diff] [blame] | 318 | mptcp_pm_nl_init(); |
Peter Krystad | 1b1c7a0 | 2020-03-27 14:48:38 -0700 | [diff] [blame] | 319 | } |