blob: 2469e06a3a9d6019973d5dd83c497f9e5ebf97c5 [file] [log] [blame]
Paolo Abeni01cacb02020-03-27 14:48:51 -07001// SPDX-License-Identifier: GPL-2.0
2/* Multipath TCP
3 *
4 * Copyright (c) 2020, Red Hat, Inc.
5 */
6
Geliang Tangc85adce2020-04-03 17:14:08 +08007#define pr_fmt(fmt) "MPTCP: " fmt
8
Paolo Abeni01cacb02020-03-27 14:48:51 -07009#include <linux/inet.h>
10#include <linux/kernel.h>
11#include <net/tcp.h>
12#include <net/netns/generic.h>
13#include <net/mptcp.h>
14#include <net/genetlink.h>
15#include <uapi/linux/mptcp.h>
16
17#include "protocol.h"
Geliang Tang7a7e52e2020-09-24 08:29:56 +080018#include "mib.h"
Paolo Abeni01cacb02020-03-27 14:48:51 -070019
20/* forward declaration */
21static struct genl_family mptcp_genl_family;
22
23static int pm_nl_pernet_id;
24
25struct mptcp_pm_addr_entry {
26 struct list_head list;
Paolo Abeni01cacb02020-03-27 14:48:51 -070027 struct mptcp_addr_info addr;
Geliang Tangdaa83ab2021-04-06 17:15:57 -070028 u8 flags;
29 int ifindex;
Paolo Abeni01cacb02020-03-27 14:48:51 -070030 struct rcu_head rcu;
Geliang Tang1729cf12021-02-01 15:09:12 -080031 struct socket *lsk;
Paolo Abeni01cacb02020-03-27 14:48:51 -070032};
33
Geliang Tang0abd40f2020-09-24 08:30:00 +080034struct mptcp_pm_add_entry {
35 struct list_head list;
36 struct mptcp_addr_info addr;
Geliang Tang00cfd772020-09-24 08:30:02 +080037 struct timer_list add_timer;
38 struct mptcp_sock *sock;
39 u8 retrans_times;
Geliang Tang0abd40f2020-09-24 08:30:00 +080040};
41
Geliang Tangefd5a4c2021-01-08 16:47:55 -080042#define MAX_ADDR_ID 255
43#define BITMAP_SZ DIV_ROUND_UP(MAX_ADDR_ID + 1, BITS_PER_LONG)
44
Paolo Abeni01cacb02020-03-27 14:48:51 -070045struct pm_nl_pernet {
46 /* protects pernet updates */
47 spinlock_t lock;
48 struct list_head local_addr_list;
49 unsigned int addrs;
50 unsigned int add_addr_signal_max;
51 unsigned int add_addr_accept_max;
52 unsigned int local_addr_max;
53 unsigned int subflows_max;
54 unsigned int next_id;
Geliang Tangefd5a4c2021-01-08 16:47:55 -080055 unsigned long id_bitmap[BITMAP_SZ];
Paolo Abeni01cacb02020-03-27 14:48:51 -070056};
57
58#define MPTCP_PM_ADDR_MAX 8
Geliang Tang00cfd772020-09-24 08:30:02 +080059#define ADD_ADDR_RETRANS_MAX 3
Paolo Abeni01cacb02020-03-27 14:48:51 -070060
61static bool addresses_equal(const struct mptcp_addr_info *a,
62 struct mptcp_addr_info *b, bool use_port)
63{
64 bool addr_equals = false;
65
Matthieu Baerts7b9b0f72021-01-25 10:59:01 -080066 if (a->family == b->family) {
67 if (a->family == AF_INET)
68 addr_equals = a->addr.s_addr == b->addr.s_addr;
Paolo Abeni01cacb02020-03-27 14:48:51 -070069#if IS_ENABLED(CONFIG_MPTCP_IPV6)
Matthieu Baerts7b9b0f72021-01-25 10:59:01 -080070 else
71 addr_equals = !ipv6_addr_cmp(&a->addr6, &b->addr6);
72 } else if (a->family == AF_INET) {
73 if (ipv6_addr_v4mapped(&b->addr6))
74 addr_equals = a->addr.s_addr == b->addr6.s6_addr32[3];
75 } else if (b->family == AF_INET) {
76 if (ipv6_addr_v4mapped(&a->addr6))
77 addr_equals = a->addr6.s6_addr32[3] == b->addr.s_addr;
Paolo Abeni01cacb02020-03-27 14:48:51 -070078#endif
Matthieu Baerts7b9b0f72021-01-25 10:59:01 -080079 }
Paolo Abeni01cacb02020-03-27 14:48:51 -070080
81 if (!addr_equals)
82 return false;
83 if (!use_port)
84 return true;
85
86 return a->port == b->port;
87}
88
Geliang Tang57025812020-09-08 10:49:38 +080089static bool address_zero(const struct mptcp_addr_info *addr)
90{
91 struct mptcp_addr_info zero;
92
93 memset(&zero, 0, sizeof(zero));
94 zero.family = addr->family;
95
Geliang Tang60b57bf2021-02-01 15:09:16 -080096 return addresses_equal(addr, &zero, true);
Geliang Tang57025812020-09-08 10:49:38 +080097}
98
Paolo Abeni01cacb02020-03-27 14:48:51 -070099static void local_address(const struct sock_common *skc,
100 struct mptcp_addr_info *addr)
101{
Paolo Abeni01cacb02020-03-27 14:48:51 -0700102 addr->family = skc->skc_family;
Geliang Tang5bc56382021-02-01 15:09:15 -0800103 addr->port = htons(skc->skc_num);
Paolo Abeni01cacb02020-03-27 14:48:51 -0700104 if (addr->family == AF_INET)
105 addr->addr.s_addr = skc->skc_rcv_saddr;
106#if IS_ENABLED(CONFIG_MPTCP_IPV6)
107 else if (addr->family == AF_INET6)
108 addr->addr6 = skc->skc_v6_rcv_saddr;
109#endif
110}
111
112static void remote_address(const struct sock_common *skc,
113 struct mptcp_addr_info *addr)
114{
115 addr->family = skc->skc_family;
116 addr->port = skc->skc_dport;
117 if (addr->family == AF_INET)
118 addr->addr.s_addr = skc->skc_daddr;
119#if IS_ENABLED(CONFIG_MPTCP_IPV6)
120 else if (addr->family == AF_INET6)
121 addr->addr6 = skc->skc_v6_daddr;
122#endif
123}
124
125static bool lookup_subflow_by_saddr(const struct list_head *list,
126 struct mptcp_addr_info *saddr)
127{
128 struct mptcp_subflow_context *subflow;
129 struct mptcp_addr_info cur;
130 struct sock_common *skc;
131
132 list_for_each_entry(subflow, list, node) {
133 skc = (struct sock_common *)mptcp_subflow_tcp_sock(subflow);
134
135 local_address(skc, &cur);
Geliang Tang60b57bf2021-02-01 15:09:16 -0800136 if (addresses_equal(&cur, saddr, saddr->port))
Paolo Abeni01cacb02020-03-27 14:48:51 -0700137 return true;
138 }
139
140 return false;
141}
142
Geliang Tangd84ad042021-03-26 11:26:32 -0700143static bool lookup_subflow_by_daddr(const struct list_head *list,
144 struct mptcp_addr_info *daddr)
145{
146 struct mptcp_subflow_context *subflow;
147 struct mptcp_addr_info cur;
148 struct sock_common *skc;
149
150 list_for_each_entry(subflow, list, node) {
151 skc = (struct sock_common *)mptcp_subflow_tcp_sock(subflow);
152
153 remote_address(skc, &cur);
154 if (addresses_equal(&cur, daddr, daddr->port))
155 return true;
156 }
157
158 return false;
159}
160
Paolo Abeni01cacb02020-03-27 14:48:51 -0700161static struct mptcp_pm_addr_entry *
162select_local_address(const struct pm_nl_pernet *pernet,
163 struct mptcp_sock *msk)
164{
165 struct mptcp_pm_addr_entry *entry, *ret = NULL;
Matthieu Baerts7b9b0f72021-01-25 10:59:01 -0800166 struct sock *sk = (struct sock *)msk;
Paolo Abeni01cacb02020-03-27 14:48:51 -0700167
Florian Westphal3abc05d2021-02-04 15:23:30 -0800168 msk_owned_by_me(msk);
169
Paolo Abeni01cacb02020-03-27 14:48:51 -0700170 rcu_read_lock();
Paolo Abeni1bc73272020-12-10 14:25:05 -0800171 __mptcp_flush_join_list(msk);
Paolo Abeni01cacb02020-03-27 14:48:51 -0700172 list_for_each_entry_rcu(entry, &pernet->local_addr_list, list) {
Geliang Tangdaa83ab2021-04-06 17:15:57 -0700173 if (!(entry->flags & MPTCP_PM_ADDR_FLAG_SUBFLOW))
Paolo Abeni01cacb02020-03-27 14:48:51 -0700174 continue;
175
Matthieu Baerts7b9b0f72021-01-25 10:59:01 -0800176 if (entry->addr.family != sk->sk_family) {
177#if IS_ENABLED(CONFIG_MPTCP_IPV6)
178 if ((entry->addr.family == AF_INET &&
179 !ipv6_addr_v4mapped(&sk->sk_v6_daddr)) ||
180 (sk->sk_family == AF_INET &&
181 !ipv6_addr_v4mapped(&entry->addr.addr6)))
182#endif
183 continue;
184 }
185
Paolo Abeni01cacb02020-03-27 14:48:51 -0700186 /* avoid any address already in use by subflows and
187 * pending join
188 */
Matthieu Baerts7b9b0f72021-01-25 10:59:01 -0800189 if (!lookup_subflow_by_saddr(&msk->conn_list, &entry->addr)) {
Paolo Abeni01cacb02020-03-27 14:48:51 -0700190 ret = entry;
191 break;
192 }
193 }
Paolo Abeni01cacb02020-03-27 14:48:51 -0700194 rcu_read_unlock();
195 return ret;
196}
197
198static struct mptcp_pm_addr_entry *
199select_signal_address(struct pm_nl_pernet *pernet, unsigned int pos)
200{
201 struct mptcp_pm_addr_entry *entry, *ret = NULL;
202 int i = 0;
203
204 rcu_read_lock();
205 /* do not keep any additional per socket state, just signal
206 * the address list in order.
207 * Note: removal from the local address list during the msk life-cycle
208 * can lead to additional addresses not being announced.
209 */
210 list_for_each_entry_rcu(entry, &pernet->local_addr_list, list) {
Geliang Tangdaa83ab2021-04-06 17:15:57 -0700211 if (!(entry->flags & MPTCP_PM_ADDR_FLAG_SIGNAL))
Paolo Abeni01cacb02020-03-27 14:48:51 -0700212 continue;
213 if (i++ == pos) {
214 ret = entry;
215 break;
216 }
217 }
218 rcu_read_unlock();
219 return ret;
220}
221
Geliang Tanga914e582021-02-01 15:09:07 -0800222unsigned int mptcp_pm_get_add_addr_signal_max(struct mptcp_sock *msk)
223{
224 struct pm_nl_pernet *pernet;
225
226 pernet = net_generic(sock_net((struct sock *)msk), pm_nl_pernet_id);
227 return READ_ONCE(pernet->add_addr_signal_max);
228}
229EXPORT_SYMBOL_GPL(mptcp_pm_get_add_addr_signal_max);
230
231unsigned int mptcp_pm_get_add_addr_accept_max(struct mptcp_sock *msk)
232{
233 struct pm_nl_pernet *pernet;
234
235 pernet = net_generic(sock_net((struct sock *)msk), pm_nl_pernet_id);
236 return READ_ONCE(pernet->add_addr_accept_max);
237}
238EXPORT_SYMBOL_GPL(mptcp_pm_get_add_addr_accept_max);
239
240unsigned int mptcp_pm_get_subflows_max(struct mptcp_sock *msk)
241{
242 struct pm_nl_pernet *pernet;
243
244 pernet = net_generic(sock_net((struct sock *)msk), pm_nl_pernet_id);
245 return READ_ONCE(pernet->subflows_max);
246}
247EXPORT_SYMBOL_GPL(mptcp_pm_get_subflows_max);
248
Geliang Tang0caf3ad2021-02-12 16:52:02 -0800249unsigned int mptcp_pm_get_local_addr_max(struct mptcp_sock *msk)
Geliang Tanga914e582021-02-01 15:09:07 -0800250{
251 struct pm_nl_pernet *pernet;
252
253 pernet = net_generic(sock_net((struct sock *)msk), pm_nl_pernet_id);
254 return READ_ONCE(pernet->local_addr_max);
255}
Geliang Tang0caf3ad2021-02-12 16:52:02 -0800256EXPORT_SYMBOL_GPL(mptcp_pm_get_local_addr_max);
Geliang Tanga914e582021-02-01 15:09:07 -0800257
Paolo Abeni01cacb02020-03-27 14:48:51 -0700258static void check_work_pending(struct mptcp_sock *msk)
259{
Geliang Tanga914e582021-02-01 15:09:07 -0800260 if (msk->pm.add_addr_signaled == mptcp_pm_get_add_addr_signal_max(msk) &&
261 (msk->pm.local_addr_used == mptcp_pm_get_local_addr_max(msk) ||
262 msk->pm.subflows == mptcp_pm_get_subflows_max(msk)))
Paolo Abeni01cacb02020-03-27 14:48:51 -0700263 WRITE_ONCE(msk->pm.work_pending, false);
264}
265
Geliang Tangd88c4762021-03-26 11:26:37 -0700266struct mptcp_pm_add_entry *
267mptcp_lookup_anno_list_by_saddr(struct mptcp_sock *msk,
268 struct mptcp_addr_info *addr)
Geliang Tangb6c08382020-09-24 08:29:54 +0800269{
Geliang Tang0abd40f2020-09-24 08:30:00 +0800270 struct mptcp_pm_add_entry *entry;
Geliang Tangb6c08382020-09-24 08:29:54 +0800271
Florian Westphal3abc05d2021-02-04 15:23:30 -0800272 lockdep_assert_held(&msk->pm.lock);
273
Geliang Tangb6c08382020-09-24 08:29:54 +0800274 list_for_each_entry(entry, &msk->pm.anno_list, list) {
Geliang Tang60b57bf2021-02-01 15:09:16 -0800275 if (addresses_equal(&entry->addr, addr, true))
Geliang Tang00cfd772020-09-24 08:30:02 +0800276 return entry;
Geliang Tangb6c08382020-09-24 08:29:54 +0800277 }
278
Geliang Tang00cfd772020-09-24 08:30:02 +0800279 return NULL;
280}
281
Geliang Tang5bc56382021-02-01 15:09:15 -0800282bool mptcp_pm_sport_in_anno_list(struct mptcp_sock *msk, const struct sock *sk)
283{
284 struct mptcp_pm_add_entry *entry;
285 struct mptcp_addr_info saddr;
286 bool ret = false;
287
288 local_address((struct sock_common *)sk, &saddr);
289
290 spin_lock_bh(&msk->pm.lock);
291 list_for_each_entry(entry, &msk->pm.anno_list, list) {
292 if (addresses_equal(&entry->addr, &saddr, true)) {
293 ret = true;
294 goto out;
295 }
296 }
297
298out:
299 spin_unlock_bh(&msk->pm.lock);
300 return ret;
301}
302
Geliang Tang00cfd772020-09-24 08:30:02 +0800303static void mptcp_pm_add_timer(struct timer_list *timer)
304{
305 struct mptcp_pm_add_entry *entry = from_timer(entry, timer, add_timer);
306 struct mptcp_sock *msk = entry->sock;
307 struct sock *sk = (struct sock *)msk;
308
309 pr_debug("msk=%p", msk);
310
311 if (!msk)
312 return;
313
314 if (inet_sk_state_load(sk) == TCP_CLOSE)
315 return;
316
317 if (!entry->addr.id)
318 return;
319
320 if (mptcp_pm_should_add_signal(msk)) {
321 sk_reset_timer(sk, timer, jiffies + TCP_RTO_MAX / 8);
322 goto out;
323 }
324
325 spin_lock_bh(&msk->pm.lock);
326
327 if (!mptcp_pm_should_add_signal(msk)) {
328 pr_debug("retransmit ADD_ADDR id=%d", entry->addr.id);
Geliang Tangf7efc772021-03-26 11:26:31 -0700329 mptcp_pm_announce_addr(msk, &entry->addr, false);
Geliang Tang84dfe362020-11-19 11:46:00 -0800330 mptcp_pm_add_addr_send_ack(msk);
Geliang Tang00cfd772020-09-24 08:30:02 +0800331 entry->retrans_times++;
332 }
333
334 if (entry->retrans_times < ADD_ADDR_RETRANS_MAX)
Geliang Tang93f323b2020-11-03 11:05:07 -0800335 sk_reset_timer(sk, timer,
Geliang Tang724d06b2020-11-10 11:01:43 +0800336 jiffies + mptcp_get_add_addr_timeout(sock_net(sk)));
Geliang Tang00cfd772020-09-24 08:30:02 +0800337
338 spin_unlock_bh(&msk->pm.lock);
339
Geliang Tang348d5c12021-03-26 11:26:34 -0700340 if (entry->retrans_times == ADD_ADDR_RETRANS_MAX)
341 mptcp_pm_subflow_established(msk);
342
Geliang Tang00cfd772020-09-24 08:30:02 +0800343out:
344 __sock_put(sk);
345}
346
347struct mptcp_pm_add_entry *
348mptcp_pm_del_add_timer(struct mptcp_sock *msk,
Davide Carattid58300c2021-05-25 14:23:13 -0700349 struct mptcp_addr_info *addr, bool check_id)
Geliang Tang00cfd772020-09-24 08:30:02 +0800350{
351 struct mptcp_pm_add_entry *entry;
352 struct sock *sk = (struct sock *)msk;
353
354 spin_lock_bh(&msk->pm.lock);
Geliang Tangd88c4762021-03-26 11:26:37 -0700355 entry = mptcp_lookup_anno_list_by_saddr(msk, addr);
Davide Carattid58300c2021-05-25 14:23:13 -0700356 if (entry && (!check_id || entry->addr.id == addr->id))
Geliang Tang00cfd772020-09-24 08:30:02 +0800357 entry->retrans_times = ADD_ADDR_RETRANS_MAX;
358 spin_unlock_bh(&msk->pm.lock);
359
Davide Carattid58300c2021-05-25 14:23:13 -0700360 if (entry && (!check_id || entry->addr.id == addr->id))
Geliang Tang00cfd772020-09-24 08:30:02 +0800361 sk_stop_timer_sync(sk, &entry->add_timer);
362
363 return entry;
Geliang Tangb6c08382020-09-24 08:29:54 +0800364}
365
366static bool mptcp_pm_alloc_anno_list(struct mptcp_sock *msk,
367 struct mptcp_pm_addr_entry *entry)
368{
Geliang Tang0abd40f2020-09-24 08:30:00 +0800369 struct mptcp_pm_add_entry *add_entry = NULL;
Geliang Tang00cfd772020-09-24 08:30:02 +0800370 struct sock *sk = (struct sock *)msk;
Geliang Tang93f323b2020-11-03 11:05:07 -0800371 struct net *net = sock_net(sk);
Geliang Tangb6c08382020-09-24 08:29:54 +0800372
Florian Westphal3abc05d2021-02-04 15:23:30 -0800373 lockdep_assert_held(&msk->pm.lock);
374
Geliang Tangd88c4762021-03-26 11:26:37 -0700375 if (mptcp_lookup_anno_list_by_saddr(msk, &entry->addr))
Geliang Tangb6c08382020-09-24 08:29:54 +0800376 return false;
377
Geliang Tang0abd40f2020-09-24 08:30:00 +0800378 add_entry = kmalloc(sizeof(*add_entry), GFP_ATOMIC);
379 if (!add_entry)
Geliang Tangb6c08382020-09-24 08:29:54 +0800380 return false;
381
Geliang Tang0abd40f2020-09-24 08:30:00 +0800382 list_add(&add_entry->list, &msk->pm.anno_list);
Geliang Tangb6c08382020-09-24 08:29:54 +0800383
Geliang Tang00cfd772020-09-24 08:30:02 +0800384 add_entry->addr = entry->addr;
385 add_entry->sock = msk;
386 add_entry->retrans_times = 0;
387
388 timer_setup(&add_entry->add_timer, mptcp_pm_add_timer, 0);
Geliang Tang93f323b2020-11-03 11:05:07 -0800389 sk_reset_timer(sk, &add_entry->add_timer,
390 jiffies + mptcp_get_add_addr_timeout(net));
Geliang Tang00cfd772020-09-24 08:30:02 +0800391
Geliang Tangb6c08382020-09-24 08:29:54 +0800392 return true;
393}
394
395void mptcp_pm_free_anno_list(struct mptcp_sock *msk)
396{
Geliang Tang0abd40f2020-09-24 08:30:00 +0800397 struct mptcp_pm_add_entry *entry, *tmp;
Geliang Tang00cfd772020-09-24 08:30:02 +0800398 struct sock *sk = (struct sock *)msk;
399 LIST_HEAD(free_list);
Geliang Tangb6c08382020-09-24 08:29:54 +0800400
401 pr_debug("msk=%p", msk);
402
403 spin_lock_bh(&msk->pm.lock);
Geliang Tang00cfd772020-09-24 08:30:02 +0800404 list_splice_init(&msk->pm.anno_list, &free_list);
405 spin_unlock_bh(&msk->pm.lock);
406
407 list_for_each_entry_safe(entry, tmp, &free_list, list) {
408 sk_stop_timer_sync(sk, &entry->add_timer);
Geliang Tangb6c08382020-09-24 08:29:54 +0800409 kfree(entry);
410 }
Geliang Tangb6c08382020-09-24 08:29:54 +0800411}
412
Paolo Abeni01cacb02020-03-27 14:48:51 -0700413static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk)
414{
415 struct sock *sk = (struct sock *)msk;
416 struct mptcp_pm_addr_entry *local;
Geliang Tanga914e582021-02-01 15:09:07 -0800417 unsigned int add_addr_signal_max;
418 unsigned int local_addr_max;
Paolo Abeni01cacb02020-03-27 14:48:51 -0700419 struct pm_nl_pernet *pernet;
Geliang Tanga914e582021-02-01 15:09:07 -0800420 unsigned int subflows_max;
Paolo Abeni01cacb02020-03-27 14:48:51 -0700421
Geliang Tang432d9e72020-12-09 15:51:28 -0800422 pernet = net_generic(sock_net(sk), pm_nl_pernet_id);
Paolo Abeni01cacb02020-03-27 14:48:51 -0700423
Geliang Tanga914e582021-02-01 15:09:07 -0800424 add_addr_signal_max = mptcp_pm_get_add_addr_signal_max(msk);
425 local_addr_max = mptcp_pm_get_local_addr_max(msk);
426 subflows_max = mptcp_pm_get_subflows_max(msk);
427
Paolo Abeni01cacb02020-03-27 14:48:51 -0700428 pr_debug("local %d:%d signal %d:%d subflows %d:%d\n",
Geliang Tanga914e582021-02-01 15:09:07 -0800429 msk->pm.local_addr_used, local_addr_max,
430 msk->pm.add_addr_signaled, add_addr_signal_max,
431 msk->pm.subflows, subflows_max);
Paolo Abeni01cacb02020-03-27 14:48:51 -0700432
433 /* check first for announce */
Geliang Tanga914e582021-02-01 15:09:07 -0800434 if (msk->pm.add_addr_signaled < add_addr_signal_max) {
Paolo Abeni01cacb02020-03-27 14:48:51 -0700435 local = select_signal_address(pernet,
436 msk->pm.add_addr_signaled);
437
438 if (local) {
Geliang Tangb6c08382020-09-24 08:29:54 +0800439 if (mptcp_pm_alloc_anno_list(msk, local)) {
440 msk->pm.add_addr_signaled++;
Geliang Tangf7efc772021-03-26 11:26:31 -0700441 mptcp_pm_announce_addr(msk, &local->addr, false);
Geliang Tangb46a0232021-03-26 11:26:41 -0700442 mptcp_pm_nl_addr_send_ack(msk);
Geliang Tangb6c08382020-09-24 08:29:54 +0800443 }
Paolo Abeni01cacb02020-03-27 14:48:51 -0700444 } else {
445 /* pick failed, avoid fourther attempts later */
Geliang Tanga914e582021-02-01 15:09:07 -0800446 msk->pm.local_addr_used = add_addr_signal_max;
Paolo Abeni01cacb02020-03-27 14:48:51 -0700447 }
448
449 check_work_pending(msk);
450 }
451
452 /* check if should create a new subflow */
Geliang Tanga914e582021-02-01 15:09:07 -0800453 if (msk->pm.local_addr_used < local_addr_max &&
454 msk->pm.subflows < subflows_max) {
Paolo Abeni01cacb02020-03-27 14:48:51 -0700455 local = select_local_address(pernet, msk);
456 if (local) {
Matthieu Baerts1f2f1932021-01-25 10:59:02 -0800457 struct mptcp_addr_info remote = { 0 };
458
Paolo Abeni01cacb02020-03-27 14:48:51 -0700459 msk->pm.local_addr_used++;
460 msk->pm.subflows++;
461 check_work_pending(msk);
Matthieu Baerts1f2f1932021-01-25 10:59:02 -0800462 remote_address((struct sock_common *)sk, &remote);
Paolo Abeni01cacb02020-03-27 14:48:51 -0700463 spin_unlock_bh(&msk->pm.lock);
Geliang Tangdaa83ab2021-04-06 17:15:57 -0700464 __mptcp_subflow_connect(sk, &local->addr, &remote,
465 local->flags, local->ifindex);
Paolo Abeni01cacb02020-03-27 14:48:51 -0700466 spin_lock_bh(&msk->pm.lock);
467 return;
468 }
469
470 /* lookup failed, avoid fourther attempts later */
Geliang Tanga914e582021-02-01 15:09:07 -0800471 msk->pm.local_addr_used = local_addr_max;
Paolo Abeni01cacb02020-03-27 14:48:51 -0700472 check_work_pending(msk);
473 }
474}
475
Florian Westphale9801432021-02-12 15:59:54 -0800476static void mptcp_pm_nl_fully_established(struct mptcp_sock *msk)
Paolo Abeni01cacb02020-03-27 14:48:51 -0700477{
478 mptcp_pm_create_subflow_or_signal_addr(msk);
479}
480
Florian Westphale9801432021-02-12 15:59:54 -0800481static void mptcp_pm_nl_subflow_established(struct mptcp_sock *msk)
Paolo Abeni01cacb02020-03-27 14:48:51 -0700482{
483 mptcp_pm_create_subflow_or_signal_addr(msk);
484}
485
Florian Westphale9801432021-02-12 15:59:54 -0800486static void mptcp_pm_nl_add_addr_received(struct mptcp_sock *msk)
Paolo Abeni01cacb02020-03-27 14:48:51 -0700487{
488 struct sock *sk = (struct sock *)msk;
Geliang Tanga914e582021-02-01 15:09:07 -0800489 unsigned int add_addr_accept_max;
Paolo Abeni01cacb02020-03-27 14:48:51 -0700490 struct mptcp_addr_info remote;
491 struct mptcp_addr_info local;
Geliang Tanga914e582021-02-01 15:09:07 -0800492 unsigned int subflows_max;
Paolo Abeni01cacb02020-03-27 14:48:51 -0700493
Geliang Tanga914e582021-02-01 15:09:07 -0800494 add_addr_accept_max = mptcp_pm_get_add_addr_accept_max(msk);
495 subflows_max = mptcp_pm_get_subflows_max(msk);
496
Paolo Abeni01cacb02020-03-27 14:48:51 -0700497 pr_debug("accepted %d:%d remote family %d",
Geliang Tanga914e582021-02-01 15:09:07 -0800498 msk->pm.add_addr_accepted, add_addr_accept_max,
Paolo Abeni01cacb02020-03-27 14:48:51 -0700499 msk->pm.remote.family);
Geliang Tangd84ad042021-03-26 11:26:32 -0700500
501 if (lookup_subflow_by_daddr(&msk->conn_list, &msk->pm.remote))
502 goto add_addr_echo;
503
Paolo Abeni01cacb02020-03-27 14:48:51 -0700504 msk->pm.add_addr_accepted++;
505 msk->pm.subflows++;
Geliang Tanga914e582021-02-01 15:09:07 -0800506 if (msk->pm.add_addr_accepted >= add_addr_accept_max ||
507 msk->pm.subflows >= subflows_max)
Paolo Abeni01cacb02020-03-27 14:48:51 -0700508 WRITE_ONCE(msk->pm.accept_addr, false);
509
510 /* connect to the specified remote address, using whatever
511 * local address the routing configuration will pick.
512 */
513 remote = msk->pm.remote;
514 if (!remote.port)
515 remote.port = sk->sk_dport;
516 memset(&local, 0, sizeof(local));
517 local.family = remote.family;
518
519 spin_unlock_bh(&msk->pm.lock);
Geliang Tangdaa83ab2021-04-06 17:15:57 -0700520 __mptcp_subflow_connect(sk, &local, &remote, 0, 0);
Paolo Abeni01cacb02020-03-27 14:48:51 -0700521 spin_lock_bh(&msk->pm.lock);
Geliang Tang6a6c05a2020-09-24 08:29:50 +0800522
Geliang Tangd84ad042021-03-26 11:26:32 -0700523add_addr_echo:
Geliang Tangf7efc772021-03-26 11:26:31 -0700524 mptcp_pm_announce_addr(msk, &msk->pm.remote, true);
Geliang Tangb46a0232021-03-26 11:26:41 -0700525 mptcp_pm_nl_addr_send_ack(msk);
Geliang Tang84dfe362020-11-19 11:46:00 -0800526}
527
Geliang Tangb46a0232021-03-26 11:26:41 -0700528void mptcp_pm_nl_addr_send_ack(struct mptcp_sock *msk)
Geliang Tang84dfe362020-11-19 11:46:00 -0800529{
530 struct mptcp_subflow_context *subflow;
531
Florian Westphal3abc05d2021-02-04 15:23:30 -0800532 msk_owned_by_me(msk);
533 lockdep_assert_held(&msk->pm.lock);
534
Geliang Tang8dd5efb2021-03-26 11:26:40 -0700535 if (!mptcp_pm_should_add_signal(msk) &&
536 !mptcp_pm_should_rm_signal(msk))
Geliang Tang84dfe362020-11-19 11:46:00 -0800537 return;
538
539 __mptcp_flush_join_list(msk);
540 subflow = list_first_entry_or_null(&msk->conn_list, typeof(*subflow), node);
541 if (subflow) {
542 struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
Geliang Tang84dfe362020-11-19 11:46:00 -0800543
544 spin_unlock_bh(&msk->pm.lock);
Geliang Tang8dd5efb2021-03-26 11:26:40 -0700545 pr_debug("send ack for %s%s%s",
546 mptcp_pm_should_add_signal(msk) ? "add_addr" : "rm_addr",
Geliang Tangb5a7acd2021-02-01 15:09:09 -0800547 mptcp_pm_should_add_signal_ipv6(msk) ? " [ipv6]" : "",
548 mptcp_pm_should_add_signal_port(msk) ? " [port]" : "");
Geliang Tangfbe0f872020-12-09 15:51:23 -0800549
Geliang Tang84dfe362020-11-19 11:46:00 -0800550 lock_sock(ssk);
551 tcp_send_ack(ssk);
552 release_sock(ssk);
553 spin_lock_bh(&msk->pm.lock);
Geliang Tang84dfe362020-11-19 11:46:00 -0800554 }
Paolo Abeni01cacb02020-03-27 14:48:51 -0700555}
556
Geliang Tang06706542021-01-08 16:47:57 -0800557int mptcp_pm_nl_mp_prio_send_ack(struct mptcp_sock *msk,
558 struct mptcp_addr_info *addr,
559 u8 bkup)
560{
561 struct mptcp_subflow_context *subflow;
562
563 pr_debug("bkup=%d", bkup);
564
565 mptcp_for_each_subflow(msk, subflow) {
566 struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
Geliang Tang0be2ac22021-01-08 16:48:01 -0800567 struct sock *sk = (struct sock *)msk;
Geliang Tang06706542021-01-08 16:47:57 -0800568 struct mptcp_addr_info local;
569
570 local_address((struct sock_common *)ssk, &local);
571 if (!addresses_equal(&local, addr, addr->port))
572 continue;
573
574 subflow->backup = bkup;
575 subflow->send_mp_prio = 1;
576 subflow->request_bkup = bkup;
Geliang Tang0be2ac22021-01-08 16:48:01 -0800577 __MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_MPPRIOTX);
Geliang Tang06706542021-01-08 16:47:57 -0800578
579 spin_unlock_bh(&msk->pm.lock);
580 pr_debug("send ack for mp_prio");
581 lock_sock(ssk);
582 tcp_send_ack(ssk);
583 release_sock(ssk);
584 spin_lock_bh(&msk->pm.lock);
585
586 return 0;
587 }
588
589 return -EINVAL;
590}
591
Geliang Tang9f12e972021-03-30 17:08:52 -0700592static void mptcp_pm_nl_rm_addr_or_subflow(struct mptcp_sock *msk,
593 const struct mptcp_rm_list *rm_list,
594 enum linux_mptcp_mib_field rm_type)
Geliang Tangd0876b22020-09-24 08:29:49 +0800595{
596 struct mptcp_subflow_context *subflow, *tmp;
597 struct sock *sk = (struct sock *)msk;
Geliang Tangd0b698c2021-03-12 17:16:15 -0800598 u8 i;
Geliang Tangd0876b22020-09-24 08:29:49 +0800599
Geliang Tang9f12e972021-03-30 17:08:52 -0700600 pr_debug("%s rm_list_nr %d",
601 rm_type == MPTCP_MIB_RMADDR ? "address" : "subflow", rm_list->nr);
Geliang Tangd0876b22020-09-24 08:29:49 +0800602
Florian Westphal3abc05d2021-02-04 15:23:30 -0800603 msk_owned_by_me(msk);
604
Geliang Tang9f12e972021-03-30 17:08:52 -0700605 if (!rm_list->nr)
Geliang Tangd0876b22020-09-24 08:29:49 +0800606 return;
607
608 if (list_empty(&msk->conn_list))
609 return;
610
Geliang Tang9f12e972021-03-30 17:08:52 -0700611 for (i = 0; i < rm_list->nr; i++) {
Geliang Tangd0b698c2021-03-12 17:16:15 -0800612 list_for_each_entry_safe(subflow, tmp, &msk->conn_list, node) {
613 struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
614 int how = RCV_SHUTDOWN | SEND_SHUTDOWN;
Geliang Tang9f12e972021-03-30 17:08:52 -0700615 u8 id = subflow->local_id;
Geliang Tangd0876b22020-09-24 08:29:49 +0800616
Geliang Tang9f12e972021-03-30 17:08:52 -0700617 if (rm_type == MPTCP_MIB_RMADDR)
618 id = subflow->remote_id;
619
620 if (rm_list->ids[i] != id)
Geliang Tangd0b698c2021-03-12 17:16:15 -0800621 continue;
Geliang Tangd0876b22020-09-24 08:29:49 +0800622
Geliang Tang9f12e972021-03-30 17:08:52 -0700623 pr_debug(" -> %s rm_list_ids[%d]=%u local_id=%u remote_id=%u",
624 rm_type == MPTCP_MIB_RMADDR ? "address" : "subflow",
625 i, rm_list->ids[i], subflow->local_id, subflow->remote_id);
Geliang Tangd0b698c2021-03-12 17:16:15 -0800626 spin_unlock_bh(&msk->pm.lock);
627 mptcp_subflow_shutdown(sk, ssk, how);
628 mptcp_close_ssk(sk, ssk, subflow);
629 spin_lock_bh(&msk->pm.lock);
Geliang Tangd0876b22020-09-24 08:29:49 +0800630
Geliang Tang9f12e972021-03-30 17:08:52 -0700631 if (rm_type == MPTCP_MIB_RMADDR) {
632 msk->pm.add_addr_accepted--;
633 WRITE_ONCE(msk->pm.accept_addr, true);
634 } else if (rm_type == MPTCP_MIB_RMSUBFLOW) {
635 msk->pm.local_addr_used--;
636 }
Geliang Tangd0b698c2021-03-12 17:16:15 -0800637 msk->pm.subflows--;
Geliang Tang9f12e972021-03-30 17:08:52 -0700638 __MPTCP_INC_STATS(sock_net(sk), rm_type);
Geliang Tangd0b698c2021-03-12 17:16:15 -0800639 }
Geliang Tangd0876b22020-09-24 08:29:49 +0800640 }
641}
642
Geliang Tang9f12e972021-03-30 17:08:52 -0700643static void mptcp_pm_nl_rm_addr_received(struct mptcp_sock *msk)
644{
645 mptcp_pm_nl_rm_addr_or_subflow(msk, &msk->pm.rm_list_rx, MPTCP_MIB_RMADDR);
646}
647
648void mptcp_pm_nl_rm_subflow_received(struct mptcp_sock *msk,
649 const struct mptcp_rm_list *rm_list)
650{
651 mptcp_pm_nl_rm_addr_or_subflow(msk, rm_list, MPTCP_MIB_RMSUBFLOW);
652}
653
Florian Westphale9801432021-02-12 15:59:54 -0800654void mptcp_pm_nl_work(struct mptcp_sock *msk)
655{
656 struct mptcp_pm_data *pm = &msk->pm;
657
658 msk_owned_by_me(msk);
659
660 spin_lock_bh(&msk->pm.lock);
661
662 pr_debug("msk=%p status=%x", msk, pm->status);
663 if (pm->status & BIT(MPTCP_PM_ADD_ADDR_RECEIVED)) {
664 pm->status &= ~BIT(MPTCP_PM_ADD_ADDR_RECEIVED);
665 mptcp_pm_nl_add_addr_received(msk);
666 }
667 if (pm->status & BIT(MPTCP_PM_ADD_ADDR_SEND_ACK)) {
668 pm->status &= ~BIT(MPTCP_PM_ADD_ADDR_SEND_ACK);
Geliang Tangb46a0232021-03-26 11:26:41 -0700669 mptcp_pm_nl_addr_send_ack(msk);
Florian Westphale9801432021-02-12 15:59:54 -0800670 }
671 if (pm->status & BIT(MPTCP_PM_RM_ADDR_RECEIVED)) {
672 pm->status &= ~BIT(MPTCP_PM_RM_ADDR_RECEIVED);
673 mptcp_pm_nl_rm_addr_received(msk);
674 }
675 if (pm->status & BIT(MPTCP_PM_ESTABLISHED)) {
676 pm->status &= ~BIT(MPTCP_PM_ESTABLISHED);
677 mptcp_pm_nl_fully_established(msk);
678 }
679 if (pm->status & BIT(MPTCP_PM_SUBFLOW_ESTABLISHED)) {
680 pm->status &= ~BIT(MPTCP_PM_SUBFLOW_ESTABLISHED);
681 mptcp_pm_nl_subflow_established(msk);
682 }
683
684 spin_unlock_bh(&msk->pm.lock);
685}
686
Paolo Abeni01cacb02020-03-27 14:48:51 -0700687static bool address_use_port(struct mptcp_pm_addr_entry *entry)
688{
Geliang Tangdaa83ab2021-04-06 17:15:57 -0700689 return (entry->flags &
Paolo Abeni01cacb02020-03-27 14:48:51 -0700690 (MPTCP_PM_ADDR_FLAG_SIGNAL | MPTCP_PM_ADDR_FLAG_SUBFLOW)) ==
691 MPTCP_PM_ADDR_FLAG_SIGNAL;
692}
693
694static int mptcp_pm_nl_append_new_local_addr(struct pm_nl_pernet *pernet,
695 struct mptcp_pm_addr_entry *entry)
696{
697 struct mptcp_pm_addr_entry *cur;
Geliang Tang72603d22021-02-01 15:09:06 -0800698 unsigned int addr_max;
Paolo Abeni01cacb02020-03-27 14:48:51 -0700699 int ret = -EINVAL;
700
701 spin_lock_bh(&pernet->lock);
702 /* to keep the code simple, don't do IDR-like allocation for address ID,
703 * just bail when we exceed limits
704 */
Geliang Tangefd5a4c2021-01-08 16:47:55 -0800705 if (pernet->next_id == MAX_ADDR_ID)
706 pernet->next_id = 1;
Paolo Abeni01cacb02020-03-27 14:48:51 -0700707 if (pernet->addrs >= MPTCP_PM_ADDR_MAX)
708 goto out;
Geliang Tangefd5a4c2021-01-08 16:47:55 -0800709 if (test_bit(entry->addr.id, pernet->id_bitmap))
710 goto out;
Paolo Abeni01cacb02020-03-27 14:48:51 -0700711
712 /* do not insert duplicate address, differentiate on port only
713 * singled addresses
714 */
715 list_for_each_entry(cur, &pernet->local_addr_list, list) {
716 if (addresses_equal(&cur->addr, &entry->addr,
717 address_use_port(entry) &&
718 address_use_port(cur)))
719 goto out;
720 }
721
Geliang Tangefd5a4c2021-01-08 16:47:55 -0800722 if (!entry->addr.id) {
723find_next:
724 entry->addr.id = find_next_zero_bit(pernet->id_bitmap,
725 MAX_ADDR_ID + 1,
726 pernet->next_id);
727 if ((!entry->addr.id || entry->addr.id > MAX_ADDR_ID) &&
728 pernet->next_id != 1) {
729 pernet->next_id = 1;
730 goto find_next;
731 }
732 }
733
734 if (!entry->addr.id || entry->addr.id > MAX_ADDR_ID)
735 goto out;
736
737 __set_bit(entry->addr.id, pernet->id_bitmap);
738 if (entry->addr.id > pernet->next_id)
739 pernet->next_id = entry->addr.id;
740
Geliang Tangdaa83ab2021-04-06 17:15:57 -0700741 if (entry->flags & MPTCP_PM_ADDR_FLAG_SIGNAL) {
Geliang Tang72603d22021-02-01 15:09:06 -0800742 addr_max = pernet->add_addr_signal_max;
743 WRITE_ONCE(pernet->add_addr_signal_max, addr_max + 1);
744 }
Geliang Tangdaa83ab2021-04-06 17:15:57 -0700745 if (entry->flags & MPTCP_PM_ADDR_FLAG_SUBFLOW) {
Geliang Tang72603d22021-02-01 15:09:06 -0800746 addr_max = pernet->local_addr_max;
747 WRITE_ONCE(pernet->local_addr_max, addr_max + 1);
748 }
Paolo Abeni01cacb02020-03-27 14:48:51 -0700749
Paolo Abeni01cacb02020-03-27 14:48:51 -0700750 pernet->addrs++;
751 list_add_tail_rcu(&entry->list, &pernet->local_addr_list);
752 ret = entry->addr.id;
753
754out:
755 spin_unlock_bh(&pernet->lock);
756 return ret;
757}
758
Geliang Tang1729cf12021-02-01 15:09:12 -0800759static int mptcp_pm_nl_create_listen_socket(struct sock *sk,
760 struct mptcp_pm_addr_entry *entry)
761{
762 struct sockaddr_storage addr;
763 struct mptcp_sock *msk;
764 struct socket *ssock;
765 int backlog = 1024;
766 int err;
767
768 err = sock_create_kern(sock_net(sk), entry->addr.family,
769 SOCK_STREAM, IPPROTO_MPTCP, &entry->lsk);
770 if (err)
771 return err;
772
773 msk = mptcp_sk(entry->lsk->sk);
774 if (!msk) {
775 err = -EINVAL;
776 goto out;
777 }
778
779 ssock = __mptcp_nmpc_socket(msk);
780 if (!ssock) {
781 err = -EINVAL;
782 goto out;
783 }
784
785 mptcp_info2sockaddr(&entry->addr, &addr, entry->addr.family);
786 err = kernel_bind(ssock, (struct sockaddr *)&addr,
787 sizeof(struct sockaddr_in));
788 if (err) {
789 pr_warn("kernel_bind error, err=%d", err);
790 goto out;
791 }
792
793 err = kernel_listen(ssock, backlog);
794 if (err) {
795 pr_warn("kernel_listen error, err=%d", err);
796 goto out;
797 }
798
799 return 0;
800
801out:
802 sock_release(entry->lsk);
803 return err;
804}
805
Paolo Abeni01cacb02020-03-27 14:48:51 -0700806int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct sock_common *skc)
807{
808 struct mptcp_pm_addr_entry *entry;
809 struct mptcp_addr_info skc_local;
810 struct mptcp_addr_info msk_local;
811 struct pm_nl_pernet *pernet;
812 int ret = -1;
813
814 if (WARN_ON_ONCE(!msk))
815 return -1;
816
817 /* The 0 ID mapping is defined by the first subflow, copied into the msk
818 * addr
819 */
820 local_address((struct sock_common *)msk, &msk_local);
Geliang Tang57025812020-09-08 10:49:38 +0800821 local_address((struct sock_common *)skc, &skc_local);
Paolo Abeni01cacb02020-03-27 14:48:51 -0700822 if (addresses_equal(&msk_local, &skc_local, false))
823 return 0;
824
Geliang Tang57025812020-09-08 10:49:38 +0800825 if (address_zero(&skc_local))
826 return 0;
827
Paolo Abeni01cacb02020-03-27 14:48:51 -0700828 pernet = net_generic(sock_net((struct sock *)msk), pm_nl_pernet_id);
829
830 rcu_read_lock();
831 list_for_each_entry_rcu(entry, &pernet->local_addr_list, list) {
Geliang Tang60b57bf2021-02-01 15:09:16 -0800832 if (addresses_equal(&entry->addr, &skc_local, entry->addr.port)) {
Paolo Abeni01cacb02020-03-27 14:48:51 -0700833 ret = entry->addr.id;
834 break;
835 }
836 }
837 rcu_read_unlock();
838 if (ret >= 0)
839 return ret;
840
841 /* address not found, add to local list */
Geliang Tangf612eb72020-09-09 11:01:24 +0800842 entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
Paolo Abeni01cacb02020-03-27 14:48:51 -0700843 if (!entry)
844 return -ENOMEM;
845
Paolo Abeni01cacb02020-03-27 14:48:51 -0700846 entry->addr = skc_local;
Geliang Tangefd5a4c2021-01-08 16:47:55 -0800847 entry->addr.id = 0;
Geliang Tang1729cf12021-02-01 15:09:12 -0800848 entry->addr.port = 0;
Geliang Tangdaa83ab2021-04-06 17:15:57 -0700849 entry->ifindex = 0;
850 entry->flags = 0;
Geliang Tang1729cf12021-02-01 15:09:12 -0800851 entry->lsk = NULL;
Paolo Abeni01cacb02020-03-27 14:48:51 -0700852 ret = mptcp_pm_nl_append_new_local_addr(pernet, entry);
853 if (ret < 0)
854 kfree(entry);
855
856 return ret;
857}
858
859void mptcp_pm_nl_data_init(struct mptcp_sock *msk)
860{
861 struct mptcp_pm_data *pm = &msk->pm;
Paolo Abeni01cacb02020-03-27 14:48:51 -0700862 bool subflows;
863
Geliang Tanga914e582021-02-01 15:09:07 -0800864 subflows = !!mptcp_pm_get_subflows_max(msk);
865 WRITE_ONCE(pm->work_pending, (!!mptcp_pm_get_local_addr_max(msk) && subflows) ||
866 !!mptcp_pm_get_add_addr_signal_max(msk));
867 WRITE_ONCE(pm->accept_addr, !!mptcp_pm_get_add_addr_accept_max(msk) && subflows);
Paolo Abeni01cacb02020-03-27 14:48:51 -0700868 WRITE_ONCE(pm->accept_subflow, subflows);
869}
870
Florian Westphalb911c972021-02-12 16:00:01 -0800871#define MPTCP_PM_CMD_GRP_OFFSET 0
872#define MPTCP_PM_EV_GRP_OFFSET 1
Paolo Abeni01cacb02020-03-27 14:48:51 -0700873
874static const struct genl_multicast_group mptcp_pm_mcgrps[] = {
875 [MPTCP_PM_CMD_GRP_OFFSET] = { .name = MPTCP_PM_CMD_GRP_NAME, },
Florian Westphalb911c972021-02-12 16:00:01 -0800876 [MPTCP_PM_EV_GRP_OFFSET] = { .name = MPTCP_PM_EV_GRP_NAME,
877 .flags = GENL_UNS_ADMIN_PERM,
878 },
Paolo Abeni01cacb02020-03-27 14:48:51 -0700879};
880
881static const struct nla_policy
882mptcp_pm_addr_policy[MPTCP_PM_ADDR_ATTR_MAX + 1] = {
883 [MPTCP_PM_ADDR_ATTR_FAMILY] = { .type = NLA_U16, },
884 [MPTCP_PM_ADDR_ATTR_ID] = { .type = NLA_U8, },
885 [MPTCP_PM_ADDR_ATTR_ADDR4] = { .type = NLA_U32, },
Johannes Berg81408602020-08-18 10:17:31 +0200886 [MPTCP_PM_ADDR_ATTR_ADDR6] =
887 NLA_POLICY_EXACT_LEN(sizeof(struct in6_addr)),
Paolo Abeni01cacb02020-03-27 14:48:51 -0700888 [MPTCP_PM_ADDR_ATTR_PORT] = { .type = NLA_U16 },
889 [MPTCP_PM_ADDR_ATTR_FLAGS] = { .type = NLA_U32 },
890 [MPTCP_PM_ADDR_ATTR_IF_IDX] = { .type = NLA_S32 },
891};
892
893static const struct nla_policy mptcp_pm_policy[MPTCP_PM_ATTR_MAX + 1] = {
894 [MPTCP_PM_ATTR_ADDR] =
895 NLA_POLICY_NESTED(mptcp_pm_addr_policy),
896 [MPTCP_PM_ATTR_RCV_ADD_ADDRS] = { .type = NLA_U32, },
897 [MPTCP_PM_ATTR_SUBFLOWS] = { .type = NLA_U32, },
898};
899
900static int mptcp_pm_family_to_addr(int family)
901{
902#if IS_ENABLED(CONFIG_MPTCP_IPV6)
903 if (family == AF_INET6)
904 return MPTCP_PM_ADDR_ATTR_ADDR6;
905#endif
906 return MPTCP_PM_ADDR_ATTR_ADDR4;
907}
908
909static int mptcp_pm_parse_addr(struct nlattr *attr, struct genl_info *info,
910 bool require_family,
911 struct mptcp_pm_addr_entry *entry)
912{
913 struct nlattr *tb[MPTCP_PM_ADDR_ATTR_MAX + 1];
914 int err, addr_addr;
915
916 if (!attr) {
917 GENL_SET_ERR_MSG(info, "missing address info");
918 return -EINVAL;
919 }
920
921 /* no validation needed - was already done via nested policy */
922 err = nla_parse_nested_deprecated(tb, MPTCP_PM_ADDR_ATTR_MAX, attr,
923 mptcp_pm_addr_policy, info->extack);
924 if (err)
925 return err;
926
927 memset(entry, 0, sizeof(*entry));
928 if (!tb[MPTCP_PM_ADDR_ATTR_FAMILY]) {
929 if (!require_family)
930 goto skip_family;
931
932 NL_SET_ERR_MSG_ATTR(info->extack, attr,
933 "missing family");
934 return -EINVAL;
935 }
936
937 entry->addr.family = nla_get_u16(tb[MPTCP_PM_ADDR_ATTR_FAMILY]);
938 if (entry->addr.family != AF_INET
939#if IS_ENABLED(CONFIG_MPTCP_IPV6)
940 && entry->addr.family != AF_INET6
941#endif
942 ) {
943 NL_SET_ERR_MSG_ATTR(info->extack, attr,
944 "unknown address family");
945 return -EINVAL;
946 }
947 addr_addr = mptcp_pm_family_to_addr(entry->addr.family);
948 if (!tb[addr_addr]) {
949 NL_SET_ERR_MSG_ATTR(info->extack, attr,
950 "missing address data");
951 return -EINVAL;
952 }
953
954#if IS_ENABLED(CONFIG_MPTCP_IPV6)
955 if (entry->addr.family == AF_INET6)
956 entry->addr.addr6 = nla_get_in6_addr(tb[addr_addr]);
957 else
958#endif
959 entry->addr.addr.s_addr = nla_get_in_addr(tb[addr_addr]);
960
961skip_family:
Paolo Abenief0da3b2020-09-14 10:01:15 +0200962 if (tb[MPTCP_PM_ADDR_ATTR_IF_IDX]) {
963 u32 val = nla_get_s32(tb[MPTCP_PM_ADDR_ATTR_IF_IDX]);
964
Geliang Tangdaa83ab2021-04-06 17:15:57 -0700965 entry->ifindex = val;
Paolo Abenief0da3b2020-09-14 10:01:15 +0200966 }
Paolo Abeni01cacb02020-03-27 14:48:51 -0700967
968 if (tb[MPTCP_PM_ADDR_ATTR_ID])
969 entry->addr.id = nla_get_u8(tb[MPTCP_PM_ADDR_ATTR_ID]);
970
971 if (tb[MPTCP_PM_ADDR_ATTR_FLAGS])
Geliang Tangdaa83ab2021-04-06 17:15:57 -0700972 entry->flags = nla_get_u32(tb[MPTCP_PM_ADDR_ATTR_FLAGS]);
Paolo Abeni01cacb02020-03-27 14:48:51 -0700973
Geliang Tanga77e9172021-02-01 15:09:17 -0800974 if (tb[MPTCP_PM_ADDR_ATTR_PORT])
975 entry->addr.port = htons(nla_get_u16(tb[MPTCP_PM_ADDR_ATTR_PORT]));
976
Paolo Abeni01cacb02020-03-27 14:48:51 -0700977 return 0;
978}
979
980static struct pm_nl_pernet *genl_info_pm_nl(struct genl_info *info)
981{
982 return net_generic(genl_info_net(info), pm_nl_pernet_id);
983}
984
Geliang Tang875b76712021-02-01 15:09:08 -0800985static int mptcp_nl_add_subflow_or_signal_addr(struct net *net)
986{
987 struct mptcp_sock *msk;
988 long s_slot = 0, s_num = 0;
989
990 while ((msk = mptcp_token_iter_next(net, &s_slot, &s_num)) != NULL) {
991 struct sock *sk = (struct sock *)msk;
992
993 if (!READ_ONCE(msk->fully_established))
994 goto next;
995
996 lock_sock(sk);
997 spin_lock_bh(&msk->pm.lock);
998 mptcp_pm_create_subflow_or_signal_addr(msk);
999 spin_unlock_bh(&msk->pm.lock);
1000 release_sock(sk);
1001
1002next:
1003 sock_put(sk);
1004 cond_resched();
1005 }
1006
1007 return 0;
1008}
1009
Paolo Abeni01cacb02020-03-27 14:48:51 -07001010static int mptcp_nl_cmd_add_addr(struct sk_buff *skb, struct genl_info *info)
1011{
1012 struct nlattr *attr = info->attrs[MPTCP_PM_ATTR_ADDR];
1013 struct pm_nl_pernet *pernet = genl_info_pm_nl(info);
1014 struct mptcp_pm_addr_entry addr, *entry;
1015 int ret;
1016
1017 ret = mptcp_pm_parse_addr(attr, info, true, &addr);
1018 if (ret < 0)
1019 return ret;
1020
1021 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
1022 if (!entry) {
1023 GENL_SET_ERR_MSG(info, "can't allocate addr");
1024 return -ENOMEM;
1025 }
1026
1027 *entry = addr;
Geliang Tang1729cf12021-02-01 15:09:12 -08001028 if (entry->addr.port) {
1029 ret = mptcp_pm_nl_create_listen_socket(skb->sk, entry);
1030 if (ret) {
1031 GENL_SET_ERR_MSG(info, "create listen socket error");
1032 kfree(entry);
1033 return ret;
1034 }
1035 }
Paolo Abeni01cacb02020-03-27 14:48:51 -07001036 ret = mptcp_pm_nl_append_new_local_addr(pernet, entry);
1037 if (ret < 0) {
1038 GENL_SET_ERR_MSG(info, "too many addresses or duplicate one");
Geliang Tang1729cf12021-02-01 15:09:12 -08001039 if (entry->lsk)
1040 sock_release(entry->lsk);
Paolo Abeni01cacb02020-03-27 14:48:51 -07001041 kfree(entry);
1042 return ret;
1043 }
1044
Geliang Tang875b76712021-02-01 15:09:08 -08001045 mptcp_nl_add_subflow_or_signal_addr(sock_net(skb->sk));
1046
Paolo Abeni01cacb02020-03-27 14:48:51 -07001047 return 0;
1048}
1049
1050static struct mptcp_pm_addr_entry *
1051__lookup_addr_by_id(struct pm_nl_pernet *pernet, unsigned int id)
1052{
1053 struct mptcp_pm_addr_entry *entry;
1054
1055 list_for_each_entry(entry, &pernet->local_addr_list, list) {
1056 if (entry->addr.id == id)
1057 return entry;
1058 }
1059 return NULL;
1060}
1061
Geliang Tangb6c08382020-09-24 08:29:54 +08001062static bool remove_anno_list_by_saddr(struct mptcp_sock *msk,
1063 struct mptcp_addr_info *addr)
1064{
Geliang Tang00cfd772020-09-24 08:30:02 +08001065 struct mptcp_pm_add_entry *entry;
Geliang Tangb6c08382020-09-24 08:29:54 +08001066
Davide Carattid58300c2021-05-25 14:23:13 -07001067 entry = mptcp_pm_del_add_timer(msk, addr, false);
Geliang Tang00cfd772020-09-24 08:30:02 +08001068 if (entry) {
1069 list_del(&entry->list);
1070 kfree(entry);
1071 return true;
Geliang Tangb6c08382020-09-24 08:29:54 +08001072 }
1073
1074 return false;
1075}
1076
1077static bool mptcp_pm_remove_anno_addr(struct mptcp_sock *msk,
1078 struct mptcp_addr_info *addr,
1079 bool force)
1080{
Geliang Tangcbde2782021-03-12 17:16:12 -08001081 struct mptcp_rm_list list = { .nr = 0 };
Geliang Tangb6c08382020-09-24 08:29:54 +08001082 bool ret;
1083
Geliang Tangcbde2782021-03-12 17:16:12 -08001084 list.ids[list.nr++] = addr->id;
1085
Geliang Tangb6c08382020-09-24 08:29:54 +08001086 ret = remove_anno_list_by_saddr(msk, addr);
Geliang Tang00cfd772020-09-24 08:30:02 +08001087 if (ret || force) {
1088 spin_lock_bh(&msk->pm.lock);
Geliang Tangcbde2782021-03-12 17:16:12 -08001089 mptcp_pm_remove_addr(msk, &list);
Geliang Tang00cfd772020-09-24 08:30:02 +08001090 spin_unlock_bh(&msk->pm.lock);
1091 }
Geliang Tangb6c08382020-09-24 08:29:54 +08001092 return ret;
1093}
1094
1095static int mptcp_nl_remove_subflow_and_signal_addr(struct net *net,
1096 struct mptcp_addr_info *addr)
1097{
1098 struct mptcp_sock *msk;
1099 long s_slot = 0, s_num = 0;
Geliang Tangddd14bb2021-03-12 17:16:16 -08001100 struct mptcp_rm_list list = { .nr = 0 };
Geliang Tangb6c08382020-09-24 08:29:54 +08001101
1102 pr_debug("remove_id=%d", addr->id);
1103
Geliang Tangddd14bb2021-03-12 17:16:16 -08001104 list.ids[list.nr++] = addr->id;
1105
Geliang Tangb6c08382020-09-24 08:29:54 +08001106 while ((msk = mptcp_token_iter_next(net, &s_slot, &s_num)) != NULL) {
1107 struct sock *sk = (struct sock *)msk;
1108 bool remove_subflow;
1109
1110 if (list_empty(&msk->conn_list)) {
1111 mptcp_pm_remove_anno_addr(msk, addr, false);
1112 goto next;
1113 }
1114
1115 lock_sock(sk);
1116 remove_subflow = lookup_subflow_by_saddr(&msk->conn_list, addr);
1117 mptcp_pm_remove_anno_addr(msk, addr, remove_subflow);
1118 if (remove_subflow)
Geliang Tangddd14bb2021-03-12 17:16:16 -08001119 mptcp_pm_remove_subflow(msk, &list);
Geliang Tangb6c08382020-09-24 08:29:54 +08001120 release_sock(sk);
1121
1122next:
1123 sock_put(sk);
1124 cond_resched();
1125 }
1126
1127 return 0;
1128}
1129
Geliang Tang1729cf12021-02-01 15:09:12 -08001130struct addr_entry_release_work {
1131 struct rcu_work rwork;
1132 struct mptcp_pm_addr_entry *entry;
1133};
1134
1135static void mptcp_pm_release_addr_entry(struct work_struct *work)
1136{
1137 struct addr_entry_release_work *w;
1138 struct mptcp_pm_addr_entry *entry;
1139
1140 w = container_of(to_rcu_work(work), struct addr_entry_release_work, rwork);
1141 entry = w->entry;
1142 if (entry) {
1143 if (entry->lsk)
1144 sock_release(entry->lsk);
1145 kfree(entry);
1146 }
1147 kfree(w);
1148}
1149
1150static void mptcp_pm_free_addr_entry(struct mptcp_pm_addr_entry *entry)
1151{
1152 struct addr_entry_release_work *w;
1153
1154 w = kmalloc(sizeof(*w), GFP_ATOMIC);
1155 if (w) {
1156 INIT_RCU_WORK(&w->rwork, mptcp_pm_release_addr_entry);
1157 w->entry = entry;
1158 queue_rcu_work(system_wq, &w->rwork);
1159 }
1160}
1161
Geliang Tang740d7982021-03-30 17:08:53 -07001162static int mptcp_nl_remove_id_zero_address(struct net *net,
1163 struct mptcp_addr_info *addr)
1164{
1165 struct mptcp_rm_list list = { .nr = 0 };
1166 long s_slot = 0, s_num = 0;
1167 struct mptcp_sock *msk;
1168
1169 list.ids[list.nr++] = 0;
1170
1171 while ((msk = mptcp_token_iter_next(net, &s_slot, &s_num)) != NULL) {
1172 struct sock *sk = (struct sock *)msk;
1173 struct mptcp_addr_info msk_local;
1174
1175 if (list_empty(&msk->conn_list))
1176 goto next;
1177
1178 local_address((struct sock_common *)msk, &msk_local);
1179 if (!addresses_equal(&msk_local, addr, addr->port))
1180 goto next;
1181
1182 lock_sock(sk);
1183 spin_lock_bh(&msk->pm.lock);
1184 mptcp_pm_remove_addr(msk, &list);
1185 mptcp_pm_nl_rm_subflow_received(msk, &list);
1186 spin_unlock_bh(&msk->pm.lock);
1187 release_sock(sk);
1188
1189next:
1190 sock_put(sk);
1191 cond_resched();
1192 }
1193
1194 return 0;
1195}
1196
Paolo Abeni01cacb02020-03-27 14:48:51 -07001197static int mptcp_nl_cmd_del_addr(struct sk_buff *skb, struct genl_info *info)
1198{
1199 struct nlattr *attr = info->attrs[MPTCP_PM_ATTR_ADDR];
1200 struct pm_nl_pernet *pernet = genl_info_pm_nl(info);
1201 struct mptcp_pm_addr_entry addr, *entry;
Geliang Tang72603d22021-02-01 15:09:06 -08001202 unsigned int addr_max;
Paolo Abeni01cacb02020-03-27 14:48:51 -07001203 int ret;
1204
1205 ret = mptcp_pm_parse_addr(attr, info, false, &addr);
1206 if (ret < 0)
1207 return ret;
1208
Geliang Tang740d7982021-03-30 17:08:53 -07001209 /* the zero id address is special: the first address used by the msk
1210 * always gets such an id, so different subflows can have different zero
1211 * id addresses. Additionally zero id is not accounted for in id_bitmap.
1212 * Let's use an 'mptcp_rm_list' instead of the common remove code.
1213 */
1214 if (addr.addr.id == 0)
1215 return mptcp_nl_remove_id_zero_address(sock_net(skb->sk), &addr.addr);
1216
Paolo Abeni01cacb02020-03-27 14:48:51 -07001217 spin_lock_bh(&pernet->lock);
1218 entry = __lookup_addr_by_id(pernet, addr.addr.id);
1219 if (!entry) {
1220 GENL_SET_ERR_MSG(info, "address not found");
Geliang Tangb6c08382020-09-24 08:29:54 +08001221 spin_unlock_bh(&pernet->lock);
1222 return -EINVAL;
Paolo Abeni01cacb02020-03-27 14:48:51 -07001223 }
Geliang Tangdaa83ab2021-04-06 17:15:57 -07001224 if (entry->flags & MPTCP_PM_ADDR_FLAG_SIGNAL) {
Geliang Tang72603d22021-02-01 15:09:06 -08001225 addr_max = pernet->add_addr_signal_max;
1226 WRITE_ONCE(pernet->add_addr_signal_max, addr_max - 1);
1227 }
Geliang Tangdaa83ab2021-04-06 17:15:57 -07001228 if (entry->flags & MPTCP_PM_ADDR_FLAG_SUBFLOW) {
Geliang Tang72603d22021-02-01 15:09:06 -08001229 addr_max = pernet->local_addr_max;
1230 WRITE_ONCE(pernet->local_addr_max, addr_max - 1);
1231 }
Paolo Abeni01cacb02020-03-27 14:48:51 -07001232
1233 pernet->addrs--;
1234 list_del_rcu(&entry->list);
Geliang Tangefd5a4c2021-01-08 16:47:55 -08001235 __clear_bit(entry->addr.id, pernet->id_bitmap);
Paolo Abeni01cacb02020-03-27 14:48:51 -07001236 spin_unlock_bh(&pernet->lock);
Geliang Tangb6c08382020-09-24 08:29:54 +08001237
1238 mptcp_nl_remove_subflow_and_signal_addr(sock_net(skb->sk), &entry->addr);
Geliang Tang1729cf12021-02-01 15:09:12 -08001239 mptcp_pm_free_addr_entry(entry);
Geliang Tangb6c08382020-09-24 08:29:54 +08001240
Paolo Abeni01cacb02020-03-27 14:48:51 -07001241 return ret;
1242}
1243
Geliang Tang06faa222021-03-12 17:16:17 -08001244static void mptcp_pm_remove_addrs_and_subflows(struct mptcp_sock *msk,
1245 struct list_head *rm_list)
1246{
1247 struct mptcp_rm_list alist = { .nr = 0 }, slist = { .nr = 0 };
1248 struct mptcp_pm_addr_entry *entry;
1249
1250 list_for_each_entry(entry, rm_list, list) {
1251 if (lookup_subflow_by_saddr(&msk->conn_list, &entry->addr) &&
1252 alist.nr < MPTCP_RM_IDS_MAX &&
1253 slist.nr < MPTCP_RM_IDS_MAX) {
1254 alist.ids[alist.nr++] = entry->addr.id;
1255 slist.ids[slist.nr++] = entry->addr.id;
1256 } else if (remove_anno_list_by_saddr(msk, &entry->addr) &&
1257 alist.nr < MPTCP_RM_IDS_MAX) {
1258 alist.ids[alist.nr++] = entry->addr.id;
1259 }
1260 }
1261
1262 if (alist.nr) {
1263 spin_lock_bh(&msk->pm.lock);
1264 mptcp_pm_remove_addr(msk, &alist);
1265 spin_unlock_bh(&msk->pm.lock);
1266 }
1267 if (slist.nr)
1268 mptcp_pm_remove_subflow(msk, &slist);
1269}
1270
1271static void mptcp_nl_remove_addrs_list(struct net *net,
1272 struct list_head *rm_list)
1273{
1274 long s_slot = 0, s_num = 0;
1275 struct mptcp_sock *msk;
1276
1277 if (list_empty(rm_list))
1278 return;
1279
1280 while ((msk = mptcp_token_iter_next(net, &s_slot, &s_num)) != NULL) {
1281 struct sock *sk = (struct sock *)msk;
1282
1283 lock_sock(sk);
1284 mptcp_pm_remove_addrs_and_subflows(msk, rm_list);
1285 release_sock(sk);
1286
1287 sock_put(sk);
1288 cond_resched();
1289 }
1290}
1291
Geliang Tang0e4a3e62021-03-12 17:16:18 -08001292static void __flush_addrs(struct list_head *list)
Paolo Abeni01cacb02020-03-27 14:48:51 -07001293{
Geliang Tang141694d2020-12-10 14:24:59 -08001294 while (!list_empty(list)) {
Paolo Abeni01cacb02020-03-27 14:48:51 -07001295 struct mptcp_pm_addr_entry *cur;
1296
Geliang Tang141694d2020-12-10 14:24:59 -08001297 cur = list_entry(list->next,
Paolo Abeni01cacb02020-03-27 14:48:51 -07001298 struct mptcp_pm_addr_entry, list);
1299 list_del_rcu(&cur->list);
Geliang Tang1729cf12021-02-01 15:09:12 -08001300 mptcp_pm_free_addr_entry(cur);
Paolo Abeni01cacb02020-03-27 14:48:51 -07001301 }
1302}
1303
1304static void __reset_counters(struct pm_nl_pernet *pernet)
1305{
Geliang Tang72603d22021-02-01 15:09:06 -08001306 WRITE_ONCE(pernet->add_addr_signal_max, 0);
1307 WRITE_ONCE(pernet->add_addr_accept_max, 0);
1308 WRITE_ONCE(pernet->local_addr_max, 0);
Paolo Abeni01cacb02020-03-27 14:48:51 -07001309 pernet->addrs = 0;
1310}
1311
1312static int mptcp_nl_cmd_flush_addrs(struct sk_buff *skb, struct genl_info *info)
1313{
1314 struct pm_nl_pernet *pernet = genl_info_pm_nl(info);
Geliang Tang141694d2020-12-10 14:24:59 -08001315 LIST_HEAD(free_list);
Paolo Abeni01cacb02020-03-27 14:48:51 -07001316
1317 spin_lock_bh(&pernet->lock);
Geliang Tang141694d2020-12-10 14:24:59 -08001318 list_splice_init(&pernet->local_addr_list, &free_list);
Paolo Abeni01cacb02020-03-27 14:48:51 -07001319 __reset_counters(pernet);
Geliang Tangefd5a4c2021-01-08 16:47:55 -08001320 pernet->next_id = 1;
1321 bitmap_zero(pernet->id_bitmap, MAX_ADDR_ID + 1);
Paolo Abeni01cacb02020-03-27 14:48:51 -07001322 spin_unlock_bh(&pernet->lock);
Geliang Tang0e4a3e62021-03-12 17:16:18 -08001323 mptcp_nl_remove_addrs_list(sock_net(skb->sk), &free_list);
1324 __flush_addrs(&free_list);
Paolo Abeni01cacb02020-03-27 14:48:51 -07001325 return 0;
1326}
1327
1328static int mptcp_nl_fill_addr(struct sk_buff *skb,
1329 struct mptcp_pm_addr_entry *entry)
1330{
1331 struct mptcp_addr_info *addr = &entry->addr;
1332 struct nlattr *attr;
1333
1334 attr = nla_nest_start(skb, MPTCP_PM_ATTR_ADDR);
1335 if (!attr)
1336 return -EMSGSIZE;
1337
1338 if (nla_put_u16(skb, MPTCP_PM_ADDR_ATTR_FAMILY, addr->family))
1339 goto nla_put_failure;
Geliang Tanga77e9172021-02-01 15:09:17 -08001340 if (nla_put_u16(skb, MPTCP_PM_ADDR_ATTR_PORT, ntohs(addr->port)))
1341 goto nla_put_failure;
Paolo Abeni01cacb02020-03-27 14:48:51 -07001342 if (nla_put_u8(skb, MPTCP_PM_ADDR_ATTR_ID, addr->id))
1343 goto nla_put_failure;
Geliang Tangdaa83ab2021-04-06 17:15:57 -07001344 if (nla_put_u32(skb, MPTCP_PM_ADDR_ATTR_FLAGS, entry->flags))
Paolo Abeni01cacb02020-03-27 14:48:51 -07001345 goto nla_put_failure;
Geliang Tangdaa83ab2021-04-06 17:15:57 -07001346 if (entry->ifindex &&
1347 nla_put_s32(skb, MPTCP_PM_ADDR_ATTR_IF_IDX, entry->ifindex))
Paolo Abeni01cacb02020-03-27 14:48:51 -07001348 goto nla_put_failure;
1349
Bo YUb4e0f9a2020-04-23 10:10:03 +08001350 if (addr->family == AF_INET &&
1351 nla_put_in_addr(skb, MPTCP_PM_ADDR_ATTR_ADDR4,
1352 addr->addr.s_addr))
1353 goto nla_put_failure;
Paolo Abeni01cacb02020-03-27 14:48:51 -07001354#if IS_ENABLED(CONFIG_MPTCP_IPV6)
Bo YUb4e0f9a2020-04-23 10:10:03 +08001355 else if (addr->family == AF_INET6 &&
1356 nla_put_in6_addr(skb, MPTCP_PM_ADDR_ATTR_ADDR6, &addr->addr6))
1357 goto nla_put_failure;
Paolo Abeni01cacb02020-03-27 14:48:51 -07001358#endif
1359 nla_nest_end(skb, attr);
1360 return 0;
1361
1362nla_put_failure:
1363 nla_nest_cancel(skb, attr);
1364 return -EMSGSIZE;
1365}
1366
1367static int mptcp_nl_cmd_get_addr(struct sk_buff *skb, struct genl_info *info)
1368{
1369 struct nlattr *attr = info->attrs[MPTCP_PM_ATTR_ADDR];
1370 struct pm_nl_pernet *pernet = genl_info_pm_nl(info);
1371 struct mptcp_pm_addr_entry addr, *entry;
1372 struct sk_buff *msg;
1373 void *reply;
1374 int ret;
1375
1376 ret = mptcp_pm_parse_addr(attr, info, false, &addr);
1377 if (ret < 0)
1378 return ret;
1379
1380 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
1381 if (!msg)
1382 return -ENOMEM;
1383
1384 reply = genlmsg_put_reply(msg, info, &mptcp_genl_family, 0,
1385 info->genlhdr->cmd);
1386 if (!reply) {
1387 GENL_SET_ERR_MSG(info, "not enough space in Netlink message");
1388 ret = -EMSGSIZE;
1389 goto fail;
1390 }
1391
1392 spin_lock_bh(&pernet->lock);
1393 entry = __lookup_addr_by_id(pernet, addr.addr.id);
1394 if (!entry) {
1395 GENL_SET_ERR_MSG(info, "address not found");
1396 ret = -EINVAL;
1397 goto unlock_fail;
1398 }
1399
1400 ret = mptcp_nl_fill_addr(msg, entry);
1401 if (ret)
1402 goto unlock_fail;
1403
1404 genlmsg_end(msg, reply);
1405 ret = genlmsg_reply(msg, info);
1406 spin_unlock_bh(&pernet->lock);
1407 return ret;
1408
1409unlock_fail:
1410 spin_unlock_bh(&pernet->lock);
1411
1412fail:
1413 nlmsg_free(msg);
1414 return ret;
1415}
1416
1417static int mptcp_nl_cmd_dump_addrs(struct sk_buff *msg,
1418 struct netlink_callback *cb)
1419{
1420 struct net *net = sock_net(msg->sk);
1421 struct mptcp_pm_addr_entry *entry;
1422 struct pm_nl_pernet *pernet;
1423 int id = cb->args[0];
1424 void *hdr;
Geliang Tangefd5a4c2021-01-08 16:47:55 -08001425 int i;
Paolo Abeni01cacb02020-03-27 14:48:51 -07001426
1427 pernet = net_generic(net, pm_nl_pernet_id);
1428
1429 spin_lock_bh(&pernet->lock);
Geliang Tangefd5a4c2021-01-08 16:47:55 -08001430 for (i = id; i < MAX_ADDR_ID + 1; i++) {
1431 if (test_bit(i, pernet->id_bitmap)) {
1432 entry = __lookup_addr_by_id(pernet, i);
1433 if (!entry)
1434 break;
Paolo Abeni01cacb02020-03-27 14:48:51 -07001435
Geliang Tangefd5a4c2021-01-08 16:47:55 -08001436 if (entry->addr.id <= id)
1437 continue;
Paolo Abeni01cacb02020-03-27 14:48:51 -07001438
Geliang Tangefd5a4c2021-01-08 16:47:55 -08001439 hdr = genlmsg_put(msg, NETLINK_CB(cb->skb).portid,
1440 cb->nlh->nlmsg_seq, &mptcp_genl_family,
1441 NLM_F_MULTI, MPTCP_PM_CMD_GET_ADDR);
1442 if (!hdr)
1443 break;
1444
1445 if (mptcp_nl_fill_addr(msg, entry) < 0) {
1446 genlmsg_cancel(msg, hdr);
1447 break;
1448 }
1449
1450 id = entry->addr.id;
1451 genlmsg_end(msg, hdr);
Paolo Abeni01cacb02020-03-27 14:48:51 -07001452 }
Paolo Abeni01cacb02020-03-27 14:48:51 -07001453 }
1454 spin_unlock_bh(&pernet->lock);
1455
1456 cb->args[0] = id;
1457 return msg->len;
1458}
1459
1460static int parse_limit(struct genl_info *info, int id, unsigned int *limit)
1461{
1462 struct nlattr *attr = info->attrs[id];
1463
1464 if (!attr)
1465 return 0;
1466
1467 *limit = nla_get_u32(attr);
1468 if (*limit > MPTCP_PM_ADDR_MAX) {
1469 GENL_SET_ERR_MSG(info, "limit greater than maximum");
1470 return -EINVAL;
1471 }
1472 return 0;
1473}
1474
1475static int
1476mptcp_nl_cmd_set_limits(struct sk_buff *skb, struct genl_info *info)
1477{
1478 struct pm_nl_pernet *pernet = genl_info_pm_nl(info);
1479 unsigned int rcv_addrs, subflows;
1480 int ret;
1481
1482 spin_lock_bh(&pernet->lock);
1483 rcv_addrs = pernet->add_addr_accept_max;
1484 ret = parse_limit(info, MPTCP_PM_ATTR_RCV_ADD_ADDRS, &rcv_addrs);
1485 if (ret)
1486 goto unlock;
1487
1488 subflows = pernet->subflows_max;
1489 ret = parse_limit(info, MPTCP_PM_ATTR_SUBFLOWS, &subflows);
1490 if (ret)
1491 goto unlock;
1492
1493 WRITE_ONCE(pernet->add_addr_accept_max, rcv_addrs);
1494 WRITE_ONCE(pernet->subflows_max, subflows);
1495
1496unlock:
1497 spin_unlock_bh(&pernet->lock);
1498 return ret;
1499}
1500
1501static int
1502mptcp_nl_cmd_get_limits(struct sk_buff *skb, struct genl_info *info)
1503{
1504 struct pm_nl_pernet *pernet = genl_info_pm_nl(info);
1505 struct sk_buff *msg;
1506 void *reply;
1507
1508 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
1509 if (!msg)
1510 return -ENOMEM;
1511
1512 reply = genlmsg_put_reply(msg, info, &mptcp_genl_family, 0,
1513 MPTCP_PM_CMD_GET_LIMITS);
1514 if (!reply)
1515 goto fail;
1516
1517 if (nla_put_u32(msg, MPTCP_PM_ATTR_RCV_ADD_ADDRS,
1518 READ_ONCE(pernet->add_addr_accept_max)))
1519 goto fail;
1520
1521 if (nla_put_u32(msg, MPTCP_PM_ATTR_SUBFLOWS,
1522 READ_ONCE(pernet->subflows_max)))
1523 goto fail;
1524
1525 genlmsg_end(msg, reply);
1526 return genlmsg_reply(msg, info);
1527
1528fail:
1529 GENL_SET_ERR_MSG(info, "not enough space in Netlink message");
1530 nlmsg_free(msg);
1531 return -EMSGSIZE;
1532}
1533
Geliang Tang0f9f6962021-01-08 16:47:59 -08001534static int mptcp_nl_addr_backup(struct net *net,
1535 struct mptcp_addr_info *addr,
1536 u8 bkup)
1537{
1538 long s_slot = 0, s_num = 0;
1539 struct mptcp_sock *msk;
1540 int ret = -EINVAL;
1541
1542 while ((msk = mptcp_token_iter_next(net, &s_slot, &s_num)) != NULL) {
1543 struct sock *sk = (struct sock *)msk;
1544
1545 if (list_empty(&msk->conn_list))
1546 goto next;
1547
1548 lock_sock(sk);
1549 spin_lock_bh(&msk->pm.lock);
1550 ret = mptcp_pm_nl_mp_prio_send_ack(msk, addr, bkup);
1551 spin_unlock_bh(&msk->pm.lock);
1552 release_sock(sk);
1553
1554next:
1555 sock_put(sk);
1556 cond_resched();
1557 }
1558
1559 return ret;
1560}
1561
1562static int mptcp_nl_cmd_set_flags(struct sk_buff *skb, struct genl_info *info)
1563{
1564 struct nlattr *attr = info->attrs[MPTCP_PM_ATTR_ADDR];
1565 struct pm_nl_pernet *pernet = genl_info_pm_nl(info);
1566 struct mptcp_pm_addr_entry addr, *entry;
1567 struct net *net = sock_net(skb->sk);
1568 u8 bkup = 0;
1569 int ret;
1570
1571 ret = mptcp_pm_parse_addr(attr, info, true, &addr);
1572 if (ret < 0)
1573 return ret;
1574
Geliang Tangdaa83ab2021-04-06 17:15:57 -07001575 if (addr.flags & MPTCP_PM_ADDR_FLAG_BACKUP)
Geliang Tang0f9f6962021-01-08 16:47:59 -08001576 bkup = 1;
1577
1578 list_for_each_entry(entry, &pernet->local_addr_list, list) {
1579 if (addresses_equal(&entry->addr, &addr.addr, true)) {
1580 ret = mptcp_nl_addr_backup(net, &entry->addr, bkup);
1581 if (ret)
1582 return ret;
1583
1584 if (bkup)
Geliang Tangdaa83ab2021-04-06 17:15:57 -07001585 entry->flags |= MPTCP_PM_ADDR_FLAG_BACKUP;
Geliang Tang0f9f6962021-01-08 16:47:59 -08001586 else
Geliang Tangdaa83ab2021-04-06 17:15:57 -07001587 entry->flags &= ~MPTCP_PM_ADDR_FLAG_BACKUP;
Geliang Tang0f9f6962021-01-08 16:47:59 -08001588 }
1589 }
1590
1591 return 0;
1592}
1593
Florian Westphalb911c972021-02-12 16:00:01 -08001594static void mptcp_nl_mcast_send(struct net *net, struct sk_buff *nlskb, gfp_t gfp)
1595{
1596 genlmsg_multicast_netns(&mptcp_genl_family, net,
1597 nlskb, 0, MPTCP_PM_EV_GRP_OFFSET, gfp);
1598}
1599
1600static int mptcp_event_add_subflow(struct sk_buff *skb, const struct sock *ssk)
1601{
1602 const struct inet_sock *issk = inet_sk(ssk);
1603 const struct mptcp_subflow_context *sf;
1604
1605 if (nla_put_u16(skb, MPTCP_ATTR_FAMILY, ssk->sk_family))
1606 return -EMSGSIZE;
1607
1608 switch (ssk->sk_family) {
1609 case AF_INET:
1610 if (nla_put_in_addr(skb, MPTCP_ATTR_SADDR4, issk->inet_saddr))
1611 return -EMSGSIZE;
1612 if (nla_put_in_addr(skb, MPTCP_ATTR_DADDR4, issk->inet_daddr))
1613 return -EMSGSIZE;
1614 break;
1615#if IS_ENABLED(CONFIG_MPTCP_IPV6)
1616 case AF_INET6: {
1617 const struct ipv6_pinfo *np = inet6_sk(ssk);
1618
1619 if (nla_put_in6_addr(skb, MPTCP_ATTR_SADDR6, &np->saddr))
1620 return -EMSGSIZE;
1621 if (nla_put_in6_addr(skb, MPTCP_ATTR_DADDR6, &ssk->sk_v6_daddr))
1622 return -EMSGSIZE;
1623 break;
1624 }
1625#endif
1626 default:
1627 WARN_ON_ONCE(1);
1628 return -EMSGSIZE;
1629 }
1630
1631 if (nla_put_be16(skb, MPTCP_ATTR_SPORT, issk->inet_sport))
1632 return -EMSGSIZE;
1633 if (nla_put_be16(skb, MPTCP_ATTR_DPORT, issk->inet_dport))
1634 return -EMSGSIZE;
1635
1636 sf = mptcp_subflow_ctx(ssk);
1637 if (WARN_ON_ONCE(!sf))
1638 return -EINVAL;
1639
1640 if (nla_put_u8(skb, MPTCP_ATTR_LOC_ID, sf->local_id))
1641 return -EMSGSIZE;
1642
1643 if (nla_put_u8(skb, MPTCP_ATTR_REM_ID, sf->remote_id))
1644 return -EMSGSIZE;
1645
1646 return 0;
1647}
1648
1649static int mptcp_event_put_token_and_ssk(struct sk_buff *skb,
1650 const struct mptcp_sock *msk,
1651 const struct sock *ssk)
1652{
1653 const struct sock *sk = (const struct sock *)msk;
1654 const struct mptcp_subflow_context *sf;
1655 u8 sk_err;
1656
1657 if (nla_put_u32(skb, MPTCP_ATTR_TOKEN, msk->token))
1658 return -EMSGSIZE;
1659
1660 if (mptcp_event_add_subflow(skb, ssk))
1661 return -EMSGSIZE;
1662
1663 sf = mptcp_subflow_ctx(ssk);
1664 if (WARN_ON_ONCE(!sf))
1665 return -EINVAL;
1666
1667 if (nla_put_u8(skb, MPTCP_ATTR_BACKUP, sf->backup))
1668 return -EMSGSIZE;
1669
1670 if (ssk->sk_bound_dev_if &&
1671 nla_put_s32(skb, MPTCP_ATTR_IF_IDX, ssk->sk_bound_dev_if))
1672 return -EMSGSIZE;
1673
1674 sk_err = ssk->sk_err;
1675 if (sk_err && sk->sk_state == TCP_ESTABLISHED &&
1676 nla_put_u8(skb, MPTCP_ATTR_ERROR, sk_err))
1677 return -EMSGSIZE;
1678
1679 return 0;
1680}
1681
1682static int mptcp_event_sub_established(struct sk_buff *skb,
1683 const struct mptcp_sock *msk,
1684 const struct sock *ssk)
1685{
1686 return mptcp_event_put_token_and_ssk(skb, msk, ssk);
1687}
1688
1689static int mptcp_event_sub_closed(struct sk_buff *skb,
1690 const struct mptcp_sock *msk,
1691 const struct sock *ssk)
1692{
Florian Westphaldc87efd2021-04-01 16:19:44 -07001693 const struct mptcp_subflow_context *sf;
1694
Florian Westphalb911c972021-02-12 16:00:01 -08001695 if (mptcp_event_put_token_and_ssk(skb, msk, ssk))
1696 return -EMSGSIZE;
1697
Florian Westphaldc87efd2021-04-01 16:19:44 -07001698 sf = mptcp_subflow_ctx(ssk);
1699 if (!sf->reset_seen)
1700 return 0;
1701
1702 if (nla_put_u32(skb, MPTCP_ATTR_RESET_REASON, sf->reset_reason))
1703 return -EMSGSIZE;
1704
1705 if (nla_put_u32(skb, MPTCP_ATTR_RESET_FLAGS, sf->reset_transient))
1706 return -EMSGSIZE;
1707
Florian Westphalb911c972021-02-12 16:00:01 -08001708 return 0;
1709}
1710
1711static int mptcp_event_created(struct sk_buff *skb,
1712 const struct mptcp_sock *msk,
1713 const struct sock *ssk)
1714{
1715 int err = nla_put_u32(skb, MPTCP_ATTR_TOKEN, msk->token);
1716
1717 if (err)
1718 return err;
1719
1720 return mptcp_event_add_subflow(skb, ssk);
1721}
1722
1723void mptcp_event_addr_removed(const struct mptcp_sock *msk, uint8_t id)
1724{
1725 struct net *net = sock_net((const struct sock *)msk);
1726 struct nlmsghdr *nlh;
1727 struct sk_buff *skb;
1728
1729 if (!genl_has_listeners(&mptcp_genl_family, net, MPTCP_PM_EV_GRP_OFFSET))
1730 return;
1731
1732 skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
1733 if (!skb)
1734 return;
1735
1736 nlh = genlmsg_put(skb, 0, 0, &mptcp_genl_family, 0, MPTCP_EVENT_REMOVED);
1737 if (!nlh)
1738 goto nla_put_failure;
1739
1740 if (nla_put_u32(skb, MPTCP_ATTR_TOKEN, msk->token))
1741 goto nla_put_failure;
1742
1743 if (nla_put_u8(skb, MPTCP_ATTR_REM_ID, id))
1744 goto nla_put_failure;
1745
1746 genlmsg_end(skb, nlh);
1747 mptcp_nl_mcast_send(net, skb, GFP_ATOMIC);
1748 return;
1749
1750nla_put_failure:
1751 kfree_skb(skb);
1752}
1753
1754void mptcp_event_addr_announced(const struct mptcp_sock *msk,
1755 const struct mptcp_addr_info *info)
1756{
1757 struct net *net = sock_net((const struct sock *)msk);
1758 struct nlmsghdr *nlh;
1759 struct sk_buff *skb;
1760
1761 if (!genl_has_listeners(&mptcp_genl_family, net, MPTCP_PM_EV_GRP_OFFSET))
1762 return;
1763
1764 skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
1765 if (!skb)
1766 return;
1767
1768 nlh = genlmsg_put(skb, 0, 0, &mptcp_genl_family, 0,
1769 MPTCP_EVENT_ANNOUNCED);
1770 if (!nlh)
1771 goto nla_put_failure;
1772
1773 if (nla_put_u32(skb, MPTCP_ATTR_TOKEN, msk->token))
1774 goto nla_put_failure;
1775
1776 if (nla_put_u8(skb, MPTCP_ATTR_REM_ID, info->id))
1777 goto nla_put_failure;
1778
1779 if (nla_put_be16(skb, MPTCP_ATTR_DPORT, info->port))
1780 goto nla_put_failure;
1781
1782 switch (info->family) {
1783 case AF_INET:
1784 if (nla_put_in_addr(skb, MPTCP_ATTR_DADDR4, info->addr.s_addr))
1785 goto nla_put_failure;
1786 break;
1787#if IS_ENABLED(CONFIG_MPTCP_IPV6)
1788 case AF_INET6:
1789 if (nla_put_in6_addr(skb, MPTCP_ATTR_DADDR6, &info->addr6))
1790 goto nla_put_failure;
1791 break;
1792#endif
1793 default:
1794 WARN_ON_ONCE(1);
1795 goto nla_put_failure;
1796 }
1797
1798 genlmsg_end(skb, nlh);
1799 mptcp_nl_mcast_send(net, skb, GFP_ATOMIC);
1800 return;
1801
1802nla_put_failure:
1803 kfree_skb(skb);
1804}
1805
1806void mptcp_event(enum mptcp_event_type type, const struct mptcp_sock *msk,
1807 const struct sock *ssk, gfp_t gfp)
1808{
1809 struct net *net = sock_net((const struct sock *)msk);
1810 struct nlmsghdr *nlh;
1811 struct sk_buff *skb;
1812
1813 if (!genl_has_listeners(&mptcp_genl_family, net, MPTCP_PM_EV_GRP_OFFSET))
1814 return;
1815
1816 skb = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
1817 if (!skb)
1818 return;
1819
1820 nlh = genlmsg_put(skb, 0, 0, &mptcp_genl_family, 0, type);
1821 if (!nlh)
1822 goto nla_put_failure;
1823
1824 switch (type) {
1825 case MPTCP_EVENT_UNSPEC:
1826 WARN_ON_ONCE(1);
1827 break;
1828 case MPTCP_EVENT_CREATED:
1829 case MPTCP_EVENT_ESTABLISHED:
1830 if (mptcp_event_created(skb, msk, ssk) < 0)
1831 goto nla_put_failure;
1832 break;
1833 case MPTCP_EVENT_CLOSED:
1834 if (nla_put_u32(skb, MPTCP_ATTR_TOKEN, msk->token) < 0)
1835 goto nla_put_failure;
1836 break;
1837 case MPTCP_EVENT_ANNOUNCED:
1838 case MPTCP_EVENT_REMOVED:
1839 /* call mptcp_event_addr_announced()/removed instead */
1840 WARN_ON_ONCE(1);
1841 break;
1842 case MPTCP_EVENT_SUB_ESTABLISHED:
1843 case MPTCP_EVENT_SUB_PRIORITY:
1844 if (mptcp_event_sub_established(skb, msk, ssk) < 0)
1845 goto nla_put_failure;
1846 break;
1847 case MPTCP_EVENT_SUB_CLOSED:
1848 if (mptcp_event_sub_closed(skb, msk, ssk) < 0)
1849 goto nla_put_failure;
1850 break;
1851 }
1852
1853 genlmsg_end(skb, nlh);
1854 mptcp_nl_mcast_send(net, skb, gfp);
1855 return;
1856
1857nla_put_failure:
1858 kfree_skb(skb);
1859}
1860
Rikard Falkeborn674d3ab2020-10-05 01:44:16 +02001861static const struct genl_small_ops mptcp_pm_ops[] = {
Paolo Abeni01cacb02020-03-27 14:48:51 -07001862 {
1863 .cmd = MPTCP_PM_CMD_ADD_ADDR,
1864 .doit = mptcp_nl_cmd_add_addr,
1865 .flags = GENL_ADMIN_PERM,
1866 },
1867 {
1868 .cmd = MPTCP_PM_CMD_DEL_ADDR,
1869 .doit = mptcp_nl_cmd_del_addr,
1870 .flags = GENL_ADMIN_PERM,
1871 },
1872 {
1873 .cmd = MPTCP_PM_CMD_FLUSH_ADDRS,
1874 .doit = mptcp_nl_cmd_flush_addrs,
1875 .flags = GENL_ADMIN_PERM,
1876 },
1877 {
1878 .cmd = MPTCP_PM_CMD_GET_ADDR,
1879 .doit = mptcp_nl_cmd_get_addr,
1880 .dumpit = mptcp_nl_cmd_dump_addrs,
1881 },
1882 {
1883 .cmd = MPTCP_PM_CMD_SET_LIMITS,
1884 .doit = mptcp_nl_cmd_set_limits,
1885 .flags = GENL_ADMIN_PERM,
1886 },
1887 {
1888 .cmd = MPTCP_PM_CMD_GET_LIMITS,
1889 .doit = mptcp_nl_cmd_get_limits,
1890 },
Geliang Tang0f9f6962021-01-08 16:47:59 -08001891 {
1892 .cmd = MPTCP_PM_CMD_SET_FLAGS,
1893 .doit = mptcp_nl_cmd_set_flags,
1894 .flags = GENL_ADMIN_PERM,
1895 },
Paolo Abeni01cacb02020-03-27 14:48:51 -07001896};
1897
1898static struct genl_family mptcp_genl_family __ro_after_init = {
1899 .name = MPTCP_PM_NAME,
1900 .version = MPTCP_PM_VER,
1901 .maxattr = MPTCP_PM_ATTR_MAX,
1902 .policy = mptcp_pm_policy,
1903 .netnsok = true,
1904 .module = THIS_MODULE,
Jakub Kicinski66a9b922020-10-02 14:49:54 -07001905 .small_ops = mptcp_pm_ops,
1906 .n_small_ops = ARRAY_SIZE(mptcp_pm_ops),
Paolo Abeni01cacb02020-03-27 14:48:51 -07001907 .mcgrps = mptcp_pm_mcgrps,
1908 .n_mcgrps = ARRAY_SIZE(mptcp_pm_mcgrps),
1909};
1910
1911static int __net_init pm_nl_init_net(struct net *net)
1912{
1913 struct pm_nl_pernet *pernet = net_generic(net, pm_nl_pernet_id);
1914
1915 INIT_LIST_HEAD_RCU(&pernet->local_addr_list);
1916 __reset_counters(pernet);
1917 pernet->next_id = 1;
Geliang Tangefd5a4c2021-01-08 16:47:55 -08001918 bitmap_zero(pernet->id_bitmap, MAX_ADDR_ID + 1);
Paolo Abeni01cacb02020-03-27 14:48:51 -07001919 spin_lock_init(&pernet->lock);
1920 return 0;
1921}
1922
1923static void __net_exit pm_nl_exit_net(struct list_head *net_list)
1924{
1925 struct net *net;
1926
1927 list_for_each_entry(net, net_list, exit_list) {
Geliang Tang141694d2020-12-10 14:24:59 -08001928 struct pm_nl_pernet *pernet = net_generic(net, pm_nl_pernet_id);
1929
Paolo Abeni01cacb02020-03-27 14:48:51 -07001930 /* net is removed from namespace list, can't race with
1931 * other modifiers
1932 */
Geliang Tang0e4a3e62021-03-12 17:16:18 -08001933 __flush_addrs(&pernet->local_addr_list);
Paolo Abeni01cacb02020-03-27 14:48:51 -07001934 }
1935}
1936
1937static struct pernet_operations mptcp_pm_pernet_ops = {
1938 .init = pm_nl_init_net,
1939 .exit_batch = pm_nl_exit_net,
1940 .id = &pm_nl_pernet_id,
1941 .size = sizeof(struct pm_nl_pernet),
1942};
1943
Paolo Abenid39dcec2020-06-26 19:29:59 +02001944void __init mptcp_pm_nl_init(void)
Paolo Abeni01cacb02020-03-27 14:48:51 -07001945{
1946 if (register_pernet_subsys(&mptcp_pm_pernet_ops) < 0)
1947 panic("Failed to register MPTCP PM pernet subsystem.\n");
1948
1949 if (genl_register_family(&mptcp_genl_family))
1950 panic("Failed to register MPTCP PM netlink family\n");
1951}