1 // SPDX-License-Identifier: GPL-2.0
4 * Copyright (c) 2020, Red Hat, Inc.
7 #define pr_fmt(fmt) "MPTCP: " fmt
9 #include <linux/inet.h>
10 #include <linux/kernel.h>
12 #include <net/inet_common.h>
13 #include <net/netns/generic.h>
14 #include <net/mptcp.h>
15 #include <net/genetlink.h>
16 #include <uapi/linux/mptcp.h>
21 /* forward declaration */
22 static struct genl_family mptcp_genl_family;
24 static int pm_nl_pernet_id;
26 struct mptcp_pm_add_entry {
27 struct list_head list;
28 struct mptcp_addr_info addr;
30 struct timer_list add_timer;
31 struct mptcp_sock *sock;
35 /* protects pernet updates */
37 struct list_head local_addr_list;
39 unsigned int stale_loss_cnt;
40 unsigned int add_addr_signal_max;
41 unsigned int add_addr_accept_max;
42 unsigned int local_addr_max;
43 unsigned int subflows_max;
45 DECLARE_BITMAP(id_bitmap, MPTCP_PM_MAX_ADDR_ID + 1);
48 #define MPTCP_PM_ADDR_MAX 8
49 #define ADD_ADDR_RETRANS_MAX 3
51 static struct pm_nl_pernet *pm_nl_get_pernet(const struct net *net)
53 return net_generic(net, pm_nl_pernet_id);
56 static struct pm_nl_pernet *
57 pm_nl_get_pernet_from_msk(const struct mptcp_sock *msk)
59 return pm_nl_get_pernet(sock_net((struct sock *)msk));
62 bool mptcp_addresses_equal(const struct mptcp_addr_info *a,
63 const struct mptcp_addr_info *b, bool use_port)
65 bool addr_equals = false;
67 if (a->family == b->family) {
68 if (a->family == AF_INET)
69 addr_equals = a->addr.s_addr == b->addr.s_addr;
70 #if IS_ENABLED(CONFIG_MPTCP_IPV6)
72 addr_equals = !ipv6_addr_cmp(&a->addr6, &b->addr6);
73 } else if (a->family == AF_INET) {
74 if (ipv6_addr_v4mapped(&b->addr6))
75 addr_equals = a->addr.s_addr == b->addr6.s6_addr32[3];
76 } else if (b->family == AF_INET) {
77 if (ipv6_addr_v4mapped(&a->addr6))
78 addr_equals = a->addr6.s6_addr32[3] == b->addr.s_addr;
87 return a->port == b->port;
90 void mptcp_local_address(const struct sock_common *skc, struct mptcp_addr_info *addr)
92 addr->family = skc->skc_family;
93 addr->port = htons(skc->skc_num);
94 if (addr->family == AF_INET)
95 addr->addr.s_addr = skc->skc_rcv_saddr;
96 #if IS_ENABLED(CONFIG_MPTCP_IPV6)
97 else if (addr->family == AF_INET6)
98 addr->addr6 = skc->skc_v6_rcv_saddr;
102 static void remote_address(const struct sock_common *skc,
103 struct mptcp_addr_info *addr)
105 addr->family = skc->skc_family;
106 addr->port = skc->skc_dport;
107 if (addr->family == AF_INET)
108 addr->addr.s_addr = skc->skc_daddr;
109 #if IS_ENABLED(CONFIG_MPTCP_IPV6)
110 else if (addr->family == AF_INET6)
111 addr->addr6 = skc->skc_v6_daddr;
115 static bool lookup_subflow_by_saddr(const struct list_head *list,
116 const struct mptcp_addr_info *saddr)
118 struct mptcp_subflow_context *subflow;
119 struct mptcp_addr_info cur;
120 struct sock_common *skc;
122 list_for_each_entry(subflow, list, node) {
123 skc = (struct sock_common *)mptcp_subflow_tcp_sock(subflow);
125 mptcp_local_address(skc, &cur);
126 if (mptcp_addresses_equal(&cur, saddr, saddr->port))
133 static bool lookup_subflow_by_daddr(const struct list_head *list,
134 const struct mptcp_addr_info *daddr)
136 struct mptcp_subflow_context *subflow;
137 struct mptcp_addr_info cur;
138 struct sock_common *skc;
140 list_for_each_entry(subflow, list, node) {
141 skc = (struct sock_common *)mptcp_subflow_tcp_sock(subflow);
143 remote_address(skc, &cur);
144 if (mptcp_addresses_equal(&cur, daddr, daddr->port))
151 static struct mptcp_pm_addr_entry *
152 select_local_address(const struct pm_nl_pernet *pernet,
153 const struct mptcp_sock *msk)
155 struct mptcp_pm_addr_entry *entry, *ret = NULL;
157 msk_owned_by_me(msk);
160 list_for_each_entry_rcu(entry, &pernet->local_addr_list, list) {
161 if (!(entry->flags & MPTCP_PM_ADDR_FLAG_SUBFLOW))
164 if (!test_bit(entry->addr.id, msk->pm.id_avail_bitmap))
174 static struct mptcp_pm_addr_entry *
175 select_signal_address(struct pm_nl_pernet *pernet, const struct mptcp_sock *msk)
177 struct mptcp_pm_addr_entry *entry, *ret = NULL;
180 /* do not keep any additional per socket state, just signal
181 * the address list in order.
182 * Note: removal from the local address list during the msk life-cycle
183 * can lead to additional addresses not being announced.
185 list_for_each_entry_rcu(entry, &pernet->local_addr_list, list) {
186 if (!test_bit(entry->addr.id, msk->pm.id_avail_bitmap))
189 if (!(entry->flags & MPTCP_PM_ADDR_FLAG_SIGNAL))
199 unsigned int mptcp_pm_get_add_addr_signal_max(const struct mptcp_sock *msk)
201 const struct pm_nl_pernet *pernet = pm_nl_get_pernet_from_msk(msk);
203 return READ_ONCE(pernet->add_addr_signal_max);
205 EXPORT_SYMBOL_GPL(mptcp_pm_get_add_addr_signal_max);
207 unsigned int mptcp_pm_get_add_addr_accept_max(const struct mptcp_sock *msk)
209 struct pm_nl_pernet *pernet = pm_nl_get_pernet_from_msk(msk);
211 return READ_ONCE(pernet->add_addr_accept_max);
213 EXPORT_SYMBOL_GPL(mptcp_pm_get_add_addr_accept_max);
215 unsigned int mptcp_pm_get_subflows_max(const struct mptcp_sock *msk)
217 struct pm_nl_pernet *pernet = pm_nl_get_pernet_from_msk(msk);
219 return READ_ONCE(pernet->subflows_max);
221 EXPORT_SYMBOL_GPL(mptcp_pm_get_subflows_max);
223 unsigned int mptcp_pm_get_local_addr_max(const struct mptcp_sock *msk)
225 struct pm_nl_pernet *pernet = pm_nl_get_pernet_from_msk(msk);
227 return READ_ONCE(pernet->local_addr_max);
229 EXPORT_SYMBOL_GPL(mptcp_pm_get_local_addr_max);
231 bool mptcp_pm_nl_check_work_pending(struct mptcp_sock *msk)
233 struct pm_nl_pernet *pernet = pm_nl_get_pernet_from_msk(msk);
235 if (msk->pm.subflows == mptcp_pm_get_subflows_max(msk) ||
236 (find_next_and_bit(pernet->id_bitmap, msk->pm.id_avail_bitmap,
237 MPTCP_PM_MAX_ADDR_ID + 1, 0) == MPTCP_PM_MAX_ADDR_ID + 1)) {
238 WRITE_ONCE(msk->pm.work_pending, false);
244 struct mptcp_pm_add_entry *
245 mptcp_lookup_anno_list_by_saddr(const struct mptcp_sock *msk,
246 const struct mptcp_addr_info *addr)
248 struct mptcp_pm_add_entry *entry;
250 lockdep_assert_held(&msk->pm.lock);
252 list_for_each_entry(entry, &msk->pm.anno_list, list) {
253 if (mptcp_addresses_equal(&entry->addr, addr, true))
260 bool mptcp_pm_sport_in_anno_list(struct mptcp_sock *msk, const struct sock *sk)
262 struct mptcp_pm_add_entry *entry;
263 struct mptcp_addr_info saddr;
266 mptcp_local_address((struct sock_common *)sk, &saddr);
268 spin_lock_bh(&msk->pm.lock);
269 list_for_each_entry(entry, &msk->pm.anno_list, list) {
270 if (mptcp_addresses_equal(&entry->addr, &saddr, true)) {
277 spin_unlock_bh(&msk->pm.lock);
281 static void mptcp_pm_add_timer(struct timer_list *timer)
283 struct mptcp_pm_add_entry *entry = from_timer(entry, timer, add_timer);
284 struct mptcp_sock *msk = entry->sock;
285 struct sock *sk = (struct sock *)msk;
287 pr_debug("msk=%p", msk);
292 if (inet_sk_state_load(sk) == TCP_CLOSE)
298 if (mptcp_pm_should_add_signal_addr(msk)) {
299 sk_reset_timer(sk, timer, jiffies + TCP_RTO_MAX / 8);
303 spin_lock_bh(&msk->pm.lock);
305 if (!mptcp_pm_should_add_signal_addr(msk)) {
306 pr_debug("retransmit ADD_ADDR id=%d", entry->addr.id);
307 mptcp_pm_announce_addr(msk, &entry->addr, false);
308 mptcp_pm_add_addr_send_ack(msk);
309 entry->retrans_times++;
312 if (entry->retrans_times < ADD_ADDR_RETRANS_MAX)
313 sk_reset_timer(sk, timer,
314 jiffies + mptcp_get_add_addr_timeout(sock_net(sk)));
316 spin_unlock_bh(&msk->pm.lock);
318 if (entry->retrans_times == ADD_ADDR_RETRANS_MAX)
319 mptcp_pm_subflow_established(msk);
325 struct mptcp_pm_add_entry *
326 mptcp_pm_del_add_timer(struct mptcp_sock *msk,
327 const struct mptcp_addr_info *addr, bool check_id)
329 struct mptcp_pm_add_entry *entry;
330 struct sock *sk = (struct sock *)msk;
332 spin_lock_bh(&msk->pm.lock);
333 entry = mptcp_lookup_anno_list_by_saddr(msk, addr);
334 if (entry && (!check_id || entry->addr.id == addr->id))
335 entry->retrans_times = ADD_ADDR_RETRANS_MAX;
336 spin_unlock_bh(&msk->pm.lock);
338 if (entry && (!check_id || entry->addr.id == addr->id))
339 sk_stop_timer_sync(sk, &entry->add_timer);
344 bool mptcp_pm_alloc_anno_list(struct mptcp_sock *msk,
345 const struct mptcp_addr_info *addr)
347 struct mptcp_pm_add_entry *add_entry = NULL;
348 struct sock *sk = (struct sock *)msk;
349 struct net *net = sock_net(sk);
351 lockdep_assert_held(&msk->pm.lock);
353 add_entry = mptcp_lookup_anno_list_by_saddr(msk, addr);
356 if (mptcp_pm_is_kernel(msk))
359 sk_reset_timer(sk, &add_entry->add_timer,
360 jiffies + mptcp_get_add_addr_timeout(net));
364 add_entry = kmalloc(sizeof(*add_entry), GFP_ATOMIC);
368 list_add(&add_entry->list, &msk->pm.anno_list);
370 add_entry->addr = *addr;
371 add_entry->sock = msk;
372 add_entry->retrans_times = 0;
374 timer_setup(&add_entry->add_timer, mptcp_pm_add_timer, 0);
375 sk_reset_timer(sk, &add_entry->add_timer,
376 jiffies + mptcp_get_add_addr_timeout(net));
381 void mptcp_pm_free_anno_list(struct mptcp_sock *msk)
383 struct mptcp_pm_add_entry *entry, *tmp;
384 struct sock *sk = (struct sock *)msk;
385 LIST_HEAD(free_list);
387 pr_debug("msk=%p", msk);
389 spin_lock_bh(&msk->pm.lock);
390 list_splice_init(&msk->pm.anno_list, &free_list);
391 spin_unlock_bh(&msk->pm.lock);
393 list_for_each_entry_safe(entry, tmp, &free_list, list) {
394 sk_stop_timer_sync(sk, &entry->add_timer);
399 static bool lookup_address_in_vec(const struct mptcp_addr_info *addrs, unsigned int nr,
400 const struct mptcp_addr_info *addr)
404 for (i = 0; i < nr; i++) {
405 if (addrs[i].id == addr->id)
412 /* Fill all the remote addresses into the array addrs[],
413 * and return the array size.
415 static unsigned int fill_remote_addresses_vec(struct mptcp_sock *msk,
416 struct mptcp_addr_info *local,
418 struct mptcp_addr_info *addrs)
420 bool deny_id0 = READ_ONCE(msk->pm.remote_deny_join_id0);
421 struct sock *sk = (struct sock *)msk, *ssk;
422 struct mptcp_subflow_context *subflow;
423 struct mptcp_addr_info remote = { 0 };
424 unsigned int subflows_max;
427 subflows_max = mptcp_pm_get_subflows_max(msk);
428 remote_address((struct sock_common *)sk, &remote);
430 /* Non-fullmesh endpoint, fill in the single entry
431 * corresponding to the primary MPC subflow remote address
437 if (!mptcp_pm_addr_families_match(sk, local, &remote))
443 mptcp_for_each_subflow(msk, subflow) {
444 ssk = mptcp_subflow_tcp_sock(subflow);
445 remote_address((struct sock_common *)ssk, &addrs[i]);
446 addrs[i].id = subflow->remote_id;
447 if (deny_id0 && !addrs[i].id)
450 if (!mptcp_pm_addr_families_match(sk, local, &addrs[i]))
453 if (!lookup_address_in_vec(addrs, i, &addrs[i]) &&
454 msk->pm.subflows < subflows_max) {
464 static void __mptcp_pm_send_ack(struct mptcp_sock *msk, struct mptcp_subflow_context *subflow,
465 bool prio, bool backup)
467 struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
470 pr_debug("send ack for %s",
471 prio ? "mp_prio" : (mptcp_pm_should_add_signal(msk) ? "add_addr" : "rm_addr"));
473 slow = lock_sock_fast(ssk);
475 subflow->send_mp_prio = 1;
476 subflow->backup = backup;
477 subflow->request_bkup = backup;
480 __mptcp_subflow_send_ack(ssk);
481 unlock_sock_fast(ssk, slow);
484 static void mptcp_pm_send_ack(struct mptcp_sock *msk, struct mptcp_subflow_context *subflow,
485 bool prio, bool backup)
487 spin_unlock_bh(&msk->pm.lock);
488 __mptcp_pm_send_ack(msk, subflow, prio, backup);
489 spin_lock_bh(&msk->pm.lock);
492 static struct mptcp_pm_addr_entry *
493 __lookup_addr_by_id(struct pm_nl_pernet *pernet, unsigned int id)
495 struct mptcp_pm_addr_entry *entry;
497 list_for_each_entry(entry, &pernet->local_addr_list, list) {
498 if (entry->addr.id == id)
504 static struct mptcp_pm_addr_entry *
505 __lookup_addr(struct pm_nl_pernet *pernet, const struct mptcp_addr_info *info,
508 struct mptcp_pm_addr_entry *entry;
510 list_for_each_entry(entry, &pernet->local_addr_list, list) {
511 if ((!lookup_by_id &&
512 mptcp_addresses_equal(&entry->addr, info, entry->addr.port)) ||
513 (lookup_by_id && entry->addr.id == info->id))
519 static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk)
521 struct sock *sk = (struct sock *)msk;
522 struct mptcp_pm_addr_entry *local;
523 unsigned int add_addr_signal_max;
524 unsigned int local_addr_max;
525 struct pm_nl_pernet *pernet;
526 unsigned int subflows_max;
528 pernet = pm_nl_get_pernet(sock_net(sk));
530 add_addr_signal_max = mptcp_pm_get_add_addr_signal_max(msk);
531 local_addr_max = mptcp_pm_get_local_addr_max(msk);
532 subflows_max = mptcp_pm_get_subflows_max(msk);
534 /* do lazy endpoint usage accounting for the MPC subflows */
535 if (unlikely(!(msk->pm.status & BIT(MPTCP_PM_MPC_ENDPOINT_ACCOUNTED))) && msk->first) {
536 struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(msk->first);
537 struct mptcp_pm_addr_entry *entry;
538 struct mptcp_addr_info mpc_addr;
541 mptcp_local_address((struct sock_common *)msk->first, &mpc_addr);
543 entry = __lookup_addr(pernet, &mpc_addr, false);
545 __clear_bit(entry->addr.id, msk->pm.id_avail_bitmap);
546 msk->mpc_endpoint_id = entry->addr.id;
547 backup = !!(entry->flags & MPTCP_PM_ADDR_FLAG_BACKUP);
552 mptcp_pm_send_ack(msk, subflow, true, backup);
554 msk->pm.status |= BIT(MPTCP_PM_MPC_ENDPOINT_ACCOUNTED);
557 pr_debug("local %d:%d signal %d:%d subflows %d:%d\n",
558 msk->pm.local_addr_used, local_addr_max,
559 msk->pm.add_addr_signaled, add_addr_signal_max,
560 msk->pm.subflows, subflows_max);
562 /* check first for announce */
563 if (msk->pm.add_addr_signaled < add_addr_signal_max) {
564 local = select_signal_address(pernet, msk);
566 /* due to racing events on both ends we can reach here while
567 * previous add address is still running: if we invoke now
568 * mptcp_pm_announce_addr(), that will fail and the
569 * corresponding id will be marked as used.
570 * Instead let the PM machinery reschedule us when the
571 * current address announce will be completed.
573 if (msk->pm.addr_signal & BIT(MPTCP_ADD_ADDR_SIGNAL))
577 if (mptcp_pm_alloc_anno_list(msk, &local->addr)) {
578 __clear_bit(local->addr.id, msk->pm.id_avail_bitmap);
579 msk->pm.add_addr_signaled++;
580 mptcp_pm_announce_addr(msk, &local->addr, false);
581 mptcp_pm_nl_addr_send_ack(msk);
586 /* check if should create a new subflow */
587 while (msk->pm.local_addr_used < local_addr_max &&
588 msk->pm.subflows < subflows_max) {
589 struct mptcp_addr_info addrs[MPTCP_PM_ADDR_MAX];
593 local = select_local_address(pernet, msk);
597 fullmesh = !!(local->flags & MPTCP_PM_ADDR_FLAG_FULLMESH);
599 msk->pm.local_addr_used++;
600 __clear_bit(local->addr.id, msk->pm.id_avail_bitmap);
601 nr = fill_remote_addresses_vec(msk, &local->addr, fullmesh, addrs);
605 spin_unlock_bh(&msk->pm.lock);
606 for (i = 0; i < nr; i++)
607 __mptcp_subflow_connect(sk, &local->addr, &addrs[i]);
608 spin_lock_bh(&msk->pm.lock);
610 mptcp_pm_nl_check_work_pending(msk);
613 static void mptcp_pm_nl_fully_established(struct mptcp_sock *msk)
615 mptcp_pm_create_subflow_or_signal_addr(msk);
618 static void mptcp_pm_nl_subflow_established(struct mptcp_sock *msk)
620 mptcp_pm_create_subflow_or_signal_addr(msk);
623 /* Fill all the local addresses into the array addrs[],
624 * and return the array size.
626 static unsigned int fill_local_addresses_vec(struct mptcp_sock *msk,
627 struct mptcp_addr_info *remote,
628 struct mptcp_addr_info *addrs)
630 struct sock *sk = (struct sock *)msk;
631 struct mptcp_pm_addr_entry *entry;
632 struct pm_nl_pernet *pernet;
633 unsigned int subflows_max;
636 pernet = pm_nl_get_pernet_from_msk(msk);
637 subflows_max = mptcp_pm_get_subflows_max(msk);
640 list_for_each_entry_rcu(entry, &pernet->local_addr_list, list) {
641 if (!(entry->flags & MPTCP_PM_ADDR_FLAG_FULLMESH))
644 if (!mptcp_pm_addr_families_match(sk, &entry->addr, remote))
647 if (msk->pm.subflows < subflows_max) {
649 addrs[i++] = entry->addr;
654 /* If the array is empty, fill in the single
655 * 'IPADDRANY' local address
658 struct mptcp_addr_info local;
660 memset(&local, 0, sizeof(local));
662 #if IS_ENABLED(CONFIG_MPTCP_IPV6)
663 remote->family == AF_INET6 &&
664 ipv6_addr_v4mapped(&remote->addr6) ? AF_INET :
668 if (!mptcp_pm_addr_families_match(sk, &local, remote))
678 static void mptcp_pm_nl_add_addr_received(struct mptcp_sock *msk)
680 struct mptcp_addr_info addrs[MPTCP_PM_ADDR_MAX];
681 struct sock *sk = (struct sock *)msk;
682 unsigned int add_addr_accept_max;
683 struct mptcp_addr_info remote;
684 unsigned int subflows_max;
687 add_addr_accept_max = mptcp_pm_get_add_addr_accept_max(msk);
688 subflows_max = mptcp_pm_get_subflows_max(msk);
690 pr_debug("accepted %d:%d remote family %d",
691 msk->pm.add_addr_accepted, add_addr_accept_max,
692 msk->pm.remote.family);
694 remote = msk->pm.remote;
695 mptcp_pm_announce_addr(msk, &remote, true);
696 mptcp_pm_nl_addr_send_ack(msk);
698 if (lookup_subflow_by_daddr(&msk->conn_list, &remote))
701 /* pick id 0 port, if none is provided the remote address */
703 remote.port = sk->sk_dport;
705 /* connect to the specified remote address, using whatever
706 * local address the routing configuration will pick.
708 nr = fill_local_addresses_vec(msk, &remote, addrs);
712 msk->pm.add_addr_accepted++;
713 if (msk->pm.add_addr_accepted >= add_addr_accept_max ||
714 msk->pm.subflows >= subflows_max)
715 WRITE_ONCE(msk->pm.accept_addr, false);
717 spin_unlock_bh(&msk->pm.lock);
718 for (i = 0; i < nr; i++)
719 __mptcp_subflow_connect(sk, &addrs[i], &remote);
720 spin_lock_bh(&msk->pm.lock);
723 void mptcp_pm_nl_addr_send_ack(struct mptcp_sock *msk)
725 struct mptcp_subflow_context *subflow;
727 msk_owned_by_me(msk);
728 lockdep_assert_held(&msk->pm.lock);
730 if (!mptcp_pm_should_add_signal(msk) &&
731 !mptcp_pm_should_rm_signal(msk))
734 subflow = list_first_entry_or_null(&msk->conn_list, typeof(*subflow), node);
736 mptcp_pm_send_ack(msk, subflow, false, false);
739 int mptcp_pm_nl_mp_prio_send_ack(struct mptcp_sock *msk,
740 struct mptcp_addr_info *addr,
741 struct mptcp_addr_info *rem,
744 struct mptcp_subflow_context *subflow;
746 pr_debug("bkup=%d", bkup);
748 mptcp_for_each_subflow(msk, subflow) {
749 struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
750 struct mptcp_addr_info local, remote;
752 mptcp_local_address((struct sock_common *)ssk, &local);
753 if (!mptcp_addresses_equal(&local, addr, addr->port))
756 if (rem && rem->family != AF_UNSPEC) {
757 remote_address((struct sock_common *)ssk, &remote);
758 if (!mptcp_addresses_equal(&remote, rem, rem->port))
762 __mptcp_pm_send_ack(msk, subflow, true, bkup);
769 static bool mptcp_local_id_match(const struct mptcp_sock *msk, u8 local_id, u8 id)
771 return local_id == id || (!local_id && msk->mpc_endpoint_id == id);
774 static void mptcp_pm_nl_rm_addr_or_subflow(struct mptcp_sock *msk,
775 const struct mptcp_rm_list *rm_list,
776 enum linux_mptcp_mib_field rm_type)
778 struct mptcp_subflow_context *subflow, *tmp;
779 struct sock *sk = (struct sock *)msk;
782 pr_debug("%s rm_list_nr %d",
783 rm_type == MPTCP_MIB_RMADDR ? "address" : "subflow", rm_list->nr);
785 msk_owned_by_me(msk);
787 if (sk->sk_state == TCP_LISTEN)
793 if (list_empty(&msk->conn_list))
796 for (i = 0; i < rm_list->nr; i++) {
797 u8 rm_id = rm_list->ids[i];
798 bool removed = false;
800 mptcp_for_each_subflow_safe(msk, subflow, tmp) {
801 struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
802 int how = RCV_SHUTDOWN | SEND_SHUTDOWN;
803 u8 id = subflow->local_id;
805 if (rm_type == MPTCP_MIB_RMADDR && subflow->remote_id != rm_id)
807 if (rm_type == MPTCP_MIB_RMSUBFLOW && !mptcp_local_id_match(msk, id, rm_id))
810 pr_debug(" -> %s rm_list_ids[%d]=%u local_id=%u remote_id=%u mpc_id=%u",
811 rm_type == MPTCP_MIB_RMADDR ? "address" : "subflow",
812 i, rm_id, subflow->local_id, subflow->remote_id,
813 msk->mpc_endpoint_id);
814 spin_unlock_bh(&msk->pm.lock);
815 mptcp_subflow_shutdown(sk, ssk, how);
817 /* the following takes care of updating the subflows counter */
818 mptcp_close_ssk(sk, ssk, subflow);
819 spin_lock_bh(&msk->pm.lock);
822 __MPTCP_INC_STATS(sock_net(sk), rm_type);
824 if (rm_type == MPTCP_MIB_RMSUBFLOW)
825 __set_bit(rm_id ? rm_id : msk->mpc_endpoint_id, msk->pm.id_avail_bitmap);
829 if (!mptcp_pm_is_kernel(msk))
832 if (rm_type == MPTCP_MIB_RMADDR) {
833 msk->pm.add_addr_accepted--;
834 WRITE_ONCE(msk->pm.accept_addr, true);
835 } else if (rm_type == MPTCP_MIB_RMSUBFLOW) {
836 msk->pm.local_addr_used--;
841 static void mptcp_pm_nl_rm_addr_received(struct mptcp_sock *msk)
843 mptcp_pm_nl_rm_addr_or_subflow(msk, &msk->pm.rm_list_rx, MPTCP_MIB_RMADDR);
846 void mptcp_pm_nl_rm_subflow_received(struct mptcp_sock *msk,
847 const struct mptcp_rm_list *rm_list)
849 mptcp_pm_nl_rm_addr_or_subflow(msk, rm_list, MPTCP_MIB_RMSUBFLOW);
852 void mptcp_pm_nl_work(struct mptcp_sock *msk)
854 struct mptcp_pm_data *pm = &msk->pm;
856 msk_owned_by_me(msk);
858 if (!(pm->status & MPTCP_PM_WORK_MASK))
861 spin_lock_bh(&msk->pm.lock);
863 pr_debug("msk=%p status=%x", msk, pm->status);
864 if (pm->status & BIT(MPTCP_PM_ADD_ADDR_RECEIVED)) {
865 pm->status &= ~BIT(MPTCP_PM_ADD_ADDR_RECEIVED);
866 mptcp_pm_nl_add_addr_received(msk);
868 if (pm->status & BIT(MPTCP_PM_ADD_ADDR_SEND_ACK)) {
869 pm->status &= ~BIT(MPTCP_PM_ADD_ADDR_SEND_ACK);
870 mptcp_pm_nl_addr_send_ack(msk);
872 if (pm->status & BIT(MPTCP_PM_RM_ADDR_RECEIVED)) {
873 pm->status &= ~BIT(MPTCP_PM_RM_ADDR_RECEIVED);
874 mptcp_pm_nl_rm_addr_received(msk);
876 if (pm->status & BIT(MPTCP_PM_ESTABLISHED)) {
877 pm->status &= ~BIT(MPTCP_PM_ESTABLISHED);
878 mptcp_pm_nl_fully_established(msk);
880 if (pm->status & BIT(MPTCP_PM_SUBFLOW_ESTABLISHED)) {
881 pm->status &= ~BIT(MPTCP_PM_SUBFLOW_ESTABLISHED);
882 mptcp_pm_nl_subflow_established(msk);
885 spin_unlock_bh(&msk->pm.lock);
888 static bool address_use_port(struct mptcp_pm_addr_entry *entry)
890 return (entry->flags &
891 (MPTCP_PM_ADDR_FLAG_SIGNAL | MPTCP_PM_ADDR_FLAG_SUBFLOW)) ==
892 MPTCP_PM_ADDR_FLAG_SIGNAL;
895 /* caller must ensure the RCU grace period is already elapsed */
896 static void __mptcp_pm_release_addr_entry(struct mptcp_pm_addr_entry *entry)
899 sock_release(entry->lsk);
903 static int mptcp_pm_nl_append_new_local_addr(struct pm_nl_pernet *pernet,
904 struct mptcp_pm_addr_entry *entry)
906 struct mptcp_pm_addr_entry *cur, *del_entry = NULL;
907 unsigned int addr_max;
910 spin_lock_bh(&pernet->lock);
911 /* to keep the code simple, don't do IDR-like allocation for address ID,
912 * just bail when we exceed limits
914 if (pernet->next_id == MPTCP_PM_MAX_ADDR_ID)
916 if (pernet->addrs >= MPTCP_PM_ADDR_MAX) {
920 if (test_bit(entry->addr.id, pernet->id_bitmap)) {
925 /* do not insert duplicate address, differentiate on port only
928 if (!address_use_port(entry))
929 entry->addr.port = 0;
930 list_for_each_entry(cur, &pernet->local_addr_list, list) {
931 if (mptcp_addresses_equal(&cur->addr, &entry->addr,
932 cur->addr.port || entry->addr.port)) {
933 /* allow replacing the exiting endpoint only if such
934 * endpoint is an implicit one and the user-space
935 * did not provide an endpoint id
937 if (!(cur->flags & MPTCP_PM_ADDR_FLAG_IMPLICIT)) {
945 entry->addr.id = cur->addr.id;
946 list_del_rcu(&cur->list);
952 if (!entry->addr.id) {
954 entry->addr.id = find_next_zero_bit(pernet->id_bitmap,
955 MPTCP_PM_MAX_ADDR_ID + 1,
957 if (!entry->addr.id && pernet->next_id != 1) {
966 __set_bit(entry->addr.id, pernet->id_bitmap);
967 if (entry->addr.id > pernet->next_id)
968 pernet->next_id = entry->addr.id;
970 if (entry->flags & MPTCP_PM_ADDR_FLAG_SIGNAL) {
971 addr_max = pernet->add_addr_signal_max;
972 WRITE_ONCE(pernet->add_addr_signal_max, addr_max + 1);
974 if (entry->flags & MPTCP_PM_ADDR_FLAG_SUBFLOW) {
975 addr_max = pernet->local_addr_max;
976 WRITE_ONCE(pernet->local_addr_max, addr_max + 1);
980 if (!entry->addr.port)
981 list_add_tail_rcu(&entry->list, &pernet->local_addr_list);
983 list_add_rcu(&entry->list, &pernet->local_addr_list);
984 ret = entry->addr.id;
987 spin_unlock_bh(&pernet->lock);
989 /* just replaced an existing entry, free it */
992 __mptcp_pm_release_addr_entry(del_entry);
997 static struct lock_class_key mptcp_slock_keys[2];
998 static struct lock_class_key mptcp_keys[2];
1000 static int mptcp_pm_nl_create_listen_socket(struct sock *sk,
1001 struct mptcp_pm_addr_entry *entry)
1003 bool is_ipv6 = sk->sk_family == AF_INET6;
1004 int addrlen = sizeof(struct sockaddr_in);
1005 struct sockaddr_storage addr;
1006 struct sock *newsk, *ssk;
1010 err = sock_create_kern(sock_net(sk), entry->addr.family,
1011 SOCK_STREAM, IPPROTO_MPTCP, &entry->lsk);
1015 newsk = entry->lsk->sk;
1019 /* The subflow socket lock is acquired in a nested to the msk one
1020 * in several places, even by the TCP stack, and this msk is a kernel
1021 * socket: lockdep complains. Instead of propagating the _nested
1022 * modifiers in several places, re-init the lock class for the msk
1023 * socket to an mptcp specific one.
1025 sock_lock_init_class_and_name(newsk,
1026 is_ipv6 ? "mlock-AF_INET6" : "mlock-AF_INET",
1027 &mptcp_slock_keys[is_ipv6],
1028 is_ipv6 ? "msk_lock-AF_INET6" : "msk_lock-AF_INET",
1029 &mptcp_keys[is_ipv6]);
1032 ssk = __mptcp_nmpc_sk(mptcp_sk(newsk));
1033 release_sock(newsk);
1035 return PTR_ERR(ssk);
1037 mptcp_info2sockaddr(&entry->addr, &addr, entry->addr.family);
1038 #if IS_ENABLED(CONFIG_MPTCP_IPV6)
1039 if (entry->addr.family == AF_INET6)
1040 addrlen = sizeof(struct sockaddr_in6);
1042 if (ssk->sk_family == AF_INET)
1043 err = inet_bind_sk(ssk, (struct sockaddr *)&addr, addrlen);
1044 #if IS_ENABLED(CONFIG_MPTCP_IPV6)
1045 else if (ssk->sk_family == AF_INET6)
1046 err = inet6_bind_sk(ssk, (struct sockaddr *)&addr, addrlen);
1051 inet_sk_state_store(newsk, TCP_LISTEN);
1053 err = __inet_listen_sk(ssk, backlog);
1055 mptcp_event_pm_listener(ssk, MPTCP_EVENT_LISTENER_CREATED);
1060 int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct mptcp_addr_info *skc)
1062 struct mptcp_pm_addr_entry *entry;
1063 struct pm_nl_pernet *pernet;
1066 pernet = pm_nl_get_pernet_from_msk(msk);
1069 list_for_each_entry_rcu(entry, &pernet->local_addr_list, list) {
1070 if (mptcp_addresses_equal(&entry->addr, skc, entry->addr.port)) {
1071 ret = entry->addr.id;
1079 /* address not found, add to local list */
1080 entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
1086 entry->addr.port = 0;
1088 entry->flags = MPTCP_PM_ADDR_FLAG_IMPLICIT;
1090 ret = mptcp_pm_nl_append_new_local_addr(pernet, entry);
1097 #define MPTCP_PM_CMD_GRP_OFFSET 0
1098 #define MPTCP_PM_EV_GRP_OFFSET 1
1100 static const struct genl_multicast_group mptcp_pm_mcgrps[] = {
1101 [MPTCP_PM_CMD_GRP_OFFSET] = { .name = MPTCP_PM_CMD_GRP_NAME, },
1102 [MPTCP_PM_EV_GRP_OFFSET] = { .name = MPTCP_PM_EV_GRP_NAME,
1103 .flags = GENL_UNS_ADMIN_PERM,
1107 void mptcp_pm_nl_subflow_chk_stale(const struct mptcp_sock *msk, struct sock *ssk)
1109 struct mptcp_subflow_context *iter, *subflow = mptcp_subflow_ctx(ssk);
1110 struct sock *sk = (struct sock *)msk;
1111 unsigned int active_max_loss_cnt;
1112 struct net *net = sock_net(sk);
1113 unsigned int stale_loss_cnt;
1116 stale_loss_cnt = mptcp_stale_loss_cnt(net);
1117 if (subflow->stale || !stale_loss_cnt || subflow->stale_count <= stale_loss_cnt)
1120 /* look for another available subflow not in loss state */
1121 active_max_loss_cnt = max_t(int, stale_loss_cnt - 1, 1);
1122 mptcp_for_each_subflow(msk, iter) {
1123 if (iter != subflow && mptcp_subflow_active(iter) &&
1124 iter->stale_count < active_max_loss_cnt) {
1125 /* we have some alternatives, try to mark this subflow as idle ...*/
1126 slow = lock_sock_fast(ssk);
1127 if (!tcp_rtx_and_write_queues_empty(ssk)) {
1129 __mptcp_retransmit_pending_data(sk);
1130 MPTCP_INC_STATS(net, MPTCP_MIB_SUBFLOWSTALE);
1132 unlock_sock_fast(ssk, slow);
1134 /* always try to push the pending data regardless of re-injections:
1135 * we can possibly use backup subflows now, and subflow selection
1136 * is cheap under the msk socket lock
1138 __mptcp_push_pending(sk, 0);
1144 static int mptcp_pm_family_to_addr(int family)
1146 #if IS_ENABLED(CONFIG_MPTCP_IPV6)
1147 if (family == AF_INET6)
1148 return MPTCP_PM_ADDR_ATTR_ADDR6;
1150 return MPTCP_PM_ADDR_ATTR_ADDR4;
1153 static int mptcp_pm_parse_pm_addr_attr(struct nlattr *tb[],
1154 const struct nlattr *attr,
1155 struct genl_info *info,
1156 struct mptcp_addr_info *addr,
1157 bool require_family)
1162 GENL_SET_ERR_MSG(info, "missing address info");
1166 /* no validation needed - was already done via nested policy */
1167 err = nla_parse_nested_deprecated(tb, MPTCP_PM_ADDR_ATTR_MAX, attr,
1168 mptcp_pm_address_nl_policy, info->extack);
1172 if (tb[MPTCP_PM_ADDR_ATTR_ID])
1173 addr->id = nla_get_u8(tb[MPTCP_PM_ADDR_ATTR_ID]);
1175 if (!tb[MPTCP_PM_ADDR_ATTR_FAMILY]) {
1176 if (!require_family)
1179 NL_SET_ERR_MSG_ATTR(info->extack, attr,
1184 addr->family = nla_get_u16(tb[MPTCP_PM_ADDR_ATTR_FAMILY]);
1185 if (addr->family != AF_INET
1186 #if IS_ENABLED(CONFIG_MPTCP_IPV6)
1187 && addr->family != AF_INET6
1190 NL_SET_ERR_MSG_ATTR(info->extack, attr,
1191 "unknown address family");
1194 addr_addr = mptcp_pm_family_to_addr(addr->family);
1195 if (!tb[addr_addr]) {
1196 NL_SET_ERR_MSG_ATTR(info->extack, attr,
1197 "missing address data");
1201 #if IS_ENABLED(CONFIG_MPTCP_IPV6)
1202 if (addr->family == AF_INET6)
1203 addr->addr6 = nla_get_in6_addr(tb[addr_addr]);
1206 addr->addr.s_addr = nla_get_in_addr(tb[addr_addr]);
1208 if (tb[MPTCP_PM_ADDR_ATTR_PORT])
1209 addr->port = htons(nla_get_u16(tb[MPTCP_PM_ADDR_ATTR_PORT]));
1214 int mptcp_pm_parse_addr(struct nlattr *attr, struct genl_info *info,
1215 struct mptcp_addr_info *addr)
1217 struct nlattr *tb[MPTCP_PM_ADDR_ATTR_MAX + 1];
1219 memset(addr, 0, sizeof(*addr));
1221 return mptcp_pm_parse_pm_addr_attr(tb, attr, info, addr, true);
1224 int mptcp_pm_parse_entry(struct nlattr *attr, struct genl_info *info,
1225 bool require_family,
1226 struct mptcp_pm_addr_entry *entry)
1228 struct nlattr *tb[MPTCP_PM_ADDR_ATTR_MAX + 1];
1231 memset(entry, 0, sizeof(*entry));
1233 err = mptcp_pm_parse_pm_addr_attr(tb, attr, info, &entry->addr, require_family);
1237 if (tb[MPTCP_PM_ADDR_ATTR_IF_IDX]) {
1238 u32 val = nla_get_s32(tb[MPTCP_PM_ADDR_ATTR_IF_IDX]);
1240 entry->ifindex = val;
1243 if (tb[MPTCP_PM_ADDR_ATTR_FLAGS])
1244 entry->flags = nla_get_u32(tb[MPTCP_PM_ADDR_ATTR_FLAGS]);
1246 if (tb[MPTCP_PM_ADDR_ATTR_PORT])
1247 entry->addr.port = htons(nla_get_u16(tb[MPTCP_PM_ADDR_ATTR_PORT]));
1252 static struct pm_nl_pernet *genl_info_pm_nl(struct genl_info *info)
1254 return pm_nl_get_pernet(genl_info_net(info));
1257 static int mptcp_nl_add_subflow_or_signal_addr(struct net *net)
1259 struct mptcp_sock *msk;
1260 long s_slot = 0, s_num = 0;
1262 while ((msk = mptcp_token_iter_next(net, &s_slot, &s_num)) != NULL) {
1263 struct sock *sk = (struct sock *)msk;
1265 if (!READ_ONCE(msk->fully_established) ||
1266 mptcp_pm_is_userspace(msk))
1270 spin_lock_bh(&msk->pm.lock);
1271 mptcp_pm_create_subflow_or_signal_addr(msk);
1272 spin_unlock_bh(&msk->pm.lock);
1283 int mptcp_pm_nl_add_addr_doit(struct sk_buff *skb, struct genl_info *info)
1285 struct nlattr *attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR];
1286 struct pm_nl_pernet *pernet = genl_info_pm_nl(info);
1287 struct mptcp_pm_addr_entry addr, *entry;
1290 ret = mptcp_pm_parse_entry(attr, info, true, &addr);
1294 if (addr.addr.port && !(addr.flags & MPTCP_PM_ADDR_FLAG_SIGNAL)) {
1295 GENL_SET_ERR_MSG(info, "flags must have signal when using port");
1299 if (addr.flags & MPTCP_PM_ADDR_FLAG_SIGNAL &&
1300 addr.flags & MPTCP_PM_ADDR_FLAG_FULLMESH) {
1301 GENL_SET_ERR_MSG(info, "flags mustn't have both signal and fullmesh");
1305 if (addr.flags & MPTCP_PM_ADDR_FLAG_IMPLICIT) {
1306 GENL_SET_ERR_MSG(info, "can't create IMPLICIT endpoint");
1310 entry = kzalloc(sizeof(*entry), GFP_KERNEL_ACCOUNT);
1312 GENL_SET_ERR_MSG(info, "can't allocate addr");
1317 if (entry->addr.port) {
1318 ret = mptcp_pm_nl_create_listen_socket(skb->sk, entry);
1320 GENL_SET_ERR_MSG_FMT(info, "create listen socket error: %d", ret);
1324 ret = mptcp_pm_nl_append_new_local_addr(pernet, entry);
1326 GENL_SET_ERR_MSG_FMT(info, "too many addresses or duplicate one: %d", ret);
1330 mptcp_nl_add_subflow_or_signal_addr(sock_net(skb->sk));
1334 __mptcp_pm_release_addr_entry(entry);
1338 int mptcp_pm_nl_get_flags_and_ifindex_by_id(struct mptcp_sock *msk, unsigned int id,
1339 u8 *flags, int *ifindex)
1341 struct mptcp_pm_addr_entry *entry;
1342 struct sock *sk = (struct sock *)msk;
1343 struct net *net = sock_net(sk);
1346 entry = __lookup_addr_by_id(pm_nl_get_pernet(net), id);
1348 *flags = entry->flags;
1349 *ifindex = entry->ifindex;
1356 static bool remove_anno_list_by_saddr(struct mptcp_sock *msk,
1357 const struct mptcp_addr_info *addr)
1359 struct mptcp_pm_add_entry *entry;
1361 entry = mptcp_pm_del_add_timer(msk, addr, false);
1363 list_del(&entry->list);
1371 static bool mptcp_pm_remove_anno_addr(struct mptcp_sock *msk,
1372 const struct mptcp_addr_info *addr,
1375 struct mptcp_rm_list list = { .nr = 0 };
1378 list.ids[list.nr++] = addr->id;
1380 ret = remove_anno_list_by_saddr(msk, addr);
1382 spin_lock_bh(&msk->pm.lock);
1383 mptcp_pm_remove_addr(msk, &list);
1384 spin_unlock_bh(&msk->pm.lock);
1389 static int mptcp_nl_remove_subflow_and_signal_addr(struct net *net,
1390 const struct mptcp_pm_addr_entry *entry)
1392 const struct mptcp_addr_info *addr = &entry->addr;
1393 struct mptcp_rm_list list = { .nr = 0 };
1394 long s_slot = 0, s_num = 0;
1395 struct mptcp_sock *msk;
1397 pr_debug("remove_id=%d", addr->id);
1399 list.ids[list.nr++] = addr->id;
1401 while ((msk = mptcp_token_iter_next(net, &s_slot, &s_num)) != NULL) {
1402 struct sock *sk = (struct sock *)msk;
1403 bool remove_subflow;
1405 if (mptcp_pm_is_userspace(msk))
1408 if (list_empty(&msk->conn_list)) {
1409 mptcp_pm_remove_anno_addr(msk, addr, false);
1414 remove_subflow = lookup_subflow_by_saddr(&msk->conn_list, addr);
1415 mptcp_pm_remove_anno_addr(msk, addr, remove_subflow &&
1416 !(entry->flags & MPTCP_PM_ADDR_FLAG_IMPLICIT));
1418 mptcp_pm_remove_subflow(msk, &list);
1429 static int mptcp_nl_remove_id_zero_address(struct net *net,
1430 struct mptcp_addr_info *addr)
1432 struct mptcp_rm_list list = { .nr = 0 };
1433 long s_slot = 0, s_num = 0;
1434 struct mptcp_sock *msk;
1436 list.ids[list.nr++] = 0;
1438 while ((msk = mptcp_token_iter_next(net, &s_slot, &s_num)) != NULL) {
1439 struct sock *sk = (struct sock *)msk;
1440 struct mptcp_addr_info msk_local;
1442 if (list_empty(&msk->conn_list) || mptcp_pm_is_userspace(msk))
1445 mptcp_local_address((struct sock_common *)msk, &msk_local);
1446 if (!mptcp_addresses_equal(&msk_local, addr, addr->port))
1450 spin_lock_bh(&msk->pm.lock);
1451 mptcp_pm_remove_addr(msk, &list);
1452 mptcp_pm_nl_rm_subflow_received(msk, &list);
1453 spin_unlock_bh(&msk->pm.lock);
1464 int mptcp_pm_nl_del_addr_doit(struct sk_buff *skb, struct genl_info *info)
1466 struct nlattr *attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR];
1467 struct pm_nl_pernet *pernet = genl_info_pm_nl(info);
1468 struct mptcp_pm_addr_entry addr, *entry;
1469 unsigned int addr_max;
1472 ret = mptcp_pm_parse_entry(attr, info, false, &addr);
1476 /* the zero id address is special: the first address used by the msk
1477 * always gets such an id, so different subflows can have different zero
1478 * id addresses. Additionally zero id is not accounted for in id_bitmap.
1479 * Let's use an 'mptcp_rm_list' instead of the common remove code.
1481 if (addr.addr.id == 0)
1482 return mptcp_nl_remove_id_zero_address(sock_net(skb->sk), &addr.addr);
1484 spin_lock_bh(&pernet->lock);
1485 entry = __lookup_addr_by_id(pernet, addr.addr.id);
1487 GENL_SET_ERR_MSG(info, "address not found");
1488 spin_unlock_bh(&pernet->lock);
1491 if (entry->flags & MPTCP_PM_ADDR_FLAG_SIGNAL) {
1492 addr_max = pernet->add_addr_signal_max;
1493 WRITE_ONCE(pernet->add_addr_signal_max, addr_max - 1);
1495 if (entry->flags & MPTCP_PM_ADDR_FLAG_SUBFLOW) {
1496 addr_max = pernet->local_addr_max;
1497 WRITE_ONCE(pernet->local_addr_max, addr_max - 1);
1501 list_del_rcu(&entry->list);
1502 __clear_bit(entry->addr.id, pernet->id_bitmap);
1503 spin_unlock_bh(&pernet->lock);
1505 mptcp_nl_remove_subflow_and_signal_addr(sock_net(skb->sk), entry);
1507 __mptcp_pm_release_addr_entry(entry);
1512 void mptcp_pm_remove_addrs(struct mptcp_sock *msk, struct list_head *rm_list)
1514 struct mptcp_rm_list alist = { .nr = 0 };
1515 struct mptcp_pm_addr_entry *entry;
1517 list_for_each_entry(entry, rm_list, list) {
1518 if ((remove_anno_list_by_saddr(msk, &entry->addr) ||
1519 lookup_subflow_by_saddr(&msk->conn_list, &entry->addr)) &&
1520 alist.nr < MPTCP_RM_IDS_MAX)
1521 alist.ids[alist.nr++] = entry->addr.id;
1525 spin_lock_bh(&msk->pm.lock);
1526 mptcp_pm_remove_addr(msk, &alist);
1527 spin_unlock_bh(&msk->pm.lock);
1531 void mptcp_pm_remove_addrs_and_subflows(struct mptcp_sock *msk,
1532 struct list_head *rm_list)
1534 struct mptcp_rm_list alist = { .nr = 0 }, slist = { .nr = 0 };
1535 struct mptcp_pm_addr_entry *entry;
1537 list_for_each_entry(entry, rm_list, list) {
1538 if (lookup_subflow_by_saddr(&msk->conn_list, &entry->addr) &&
1539 slist.nr < MPTCP_RM_IDS_MAX)
1540 slist.ids[slist.nr++] = entry->addr.id;
1542 if (remove_anno_list_by_saddr(msk, &entry->addr) &&
1543 alist.nr < MPTCP_RM_IDS_MAX)
1544 alist.ids[alist.nr++] = entry->addr.id;
1548 spin_lock_bh(&msk->pm.lock);
1549 mptcp_pm_remove_addr(msk, &alist);
1550 spin_unlock_bh(&msk->pm.lock);
1553 mptcp_pm_remove_subflow(msk, &slist);
1556 static void mptcp_nl_remove_addrs_list(struct net *net,
1557 struct list_head *rm_list)
1559 long s_slot = 0, s_num = 0;
1560 struct mptcp_sock *msk;
1562 if (list_empty(rm_list))
1565 while ((msk = mptcp_token_iter_next(net, &s_slot, &s_num)) != NULL) {
1566 struct sock *sk = (struct sock *)msk;
1568 if (!mptcp_pm_is_userspace(msk)) {
1570 mptcp_pm_remove_addrs_and_subflows(msk, rm_list);
1579 /* caller must ensure the RCU grace period is already elapsed */
1580 static void __flush_addrs(struct list_head *list)
1582 while (!list_empty(list)) {
1583 struct mptcp_pm_addr_entry *cur;
1585 cur = list_entry(list->next,
1586 struct mptcp_pm_addr_entry, list);
1587 list_del_rcu(&cur->list);
1588 __mptcp_pm_release_addr_entry(cur);
1592 static void __reset_counters(struct pm_nl_pernet *pernet)
1594 WRITE_ONCE(pernet->add_addr_signal_max, 0);
1595 WRITE_ONCE(pernet->add_addr_accept_max, 0);
1596 WRITE_ONCE(pernet->local_addr_max, 0);
1600 int mptcp_pm_nl_flush_addrs_doit(struct sk_buff *skb, struct genl_info *info)
1602 struct pm_nl_pernet *pernet = genl_info_pm_nl(info);
1603 LIST_HEAD(free_list);
1605 spin_lock_bh(&pernet->lock);
1606 list_splice_init(&pernet->local_addr_list, &free_list);
1607 __reset_counters(pernet);
1608 pernet->next_id = 1;
1609 bitmap_zero(pernet->id_bitmap, MPTCP_PM_MAX_ADDR_ID + 1);
1610 spin_unlock_bh(&pernet->lock);
1611 mptcp_nl_remove_addrs_list(sock_net(skb->sk), &free_list);
1613 __flush_addrs(&free_list);
1617 static int mptcp_nl_fill_addr(struct sk_buff *skb,
1618 struct mptcp_pm_addr_entry *entry)
1620 struct mptcp_addr_info *addr = &entry->addr;
1621 struct nlattr *attr;
1623 attr = nla_nest_start(skb, MPTCP_PM_ATTR_ADDR);
1627 if (nla_put_u16(skb, MPTCP_PM_ADDR_ATTR_FAMILY, addr->family))
1628 goto nla_put_failure;
1629 if (nla_put_u16(skb, MPTCP_PM_ADDR_ATTR_PORT, ntohs(addr->port)))
1630 goto nla_put_failure;
1631 if (nla_put_u8(skb, MPTCP_PM_ADDR_ATTR_ID, addr->id))
1632 goto nla_put_failure;
1633 if (nla_put_u32(skb, MPTCP_PM_ADDR_ATTR_FLAGS, entry->flags))
1634 goto nla_put_failure;
1635 if (entry->ifindex &&
1636 nla_put_s32(skb, MPTCP_PM_ADDR_ATTR_IF_IDX, entry->ifindex))
1637 goto nla_put_failure;
1639 if (addr->family == AF_INET &&
1640 nla_put_in_addr(skb, MPTCP_PM_ADDR_ATTR_ADDR4,
1642 goto nla_put_failure;
1643 #if IS_ENABLED(CONFIG_MPTCP_IPV6)
1644 else if (addr->family == AF_INET6 &&
1645 nla_put_in6_addr(skb, MPTCP_PM_ADDR_ATTR_ADDR6, &addr->addr6))
1646 goto nla_put_failure;
1648 nla_nest_end(skb, attr);
1652 nla_nest_cancel(skb, attr);
1656 int mptcp_pm_nl_get_addr_doit(struct sk_buff *skb, struct genl_info *info)
1658 struct nlattr *attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR];
1659 struct pm_nl_pernet *pernet = genl_info_pm_nl(info);
1660 struct mptcp_pm_addr_entry addr, *entry;
1661 struct sk_buff *msg;
1665 ret = mptcp_pm_parse_entry(attr, info, false, &addr);
1669 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
1673 reply = genlmsg_put_reply(msg, info, &mptcp_genl_family, 0,
1674 info->genlhdr->cmd);
1676 GENL_SET_ERR_MSG(info, "not enough space in Netlink message");
1681 spin_lock_bh(&pernet->lock);
1682 entry = __lookup_addr_by_id(pernet, addr.addr.id);
1684 GENL_SET_ERR_MSG(info, "address not found");
1689 ret = mptcp_nl_fill_addr(msg, entry);
1693 genlmsg_end(msg, reply);
1694 ret = genlmsg_reply(msg, info);
1695 spin_unlock_bh(&pernet->lock);
1699 spin_unlock_bh(&pernet->lock);
1706 int mptcp_pm_nl_get_addr_dumpit(struct sk_buff *msg,
1707 struct netlink_callback *cb)
1709 struct net *net = sock_net(msg->sk);
1710 struct mptcp_pm_addr_entry *entry;
1711 struct pm_nl_pernet *pernet;
1712 int id = cb->args[0];
1716 pernet = pm_nl_get_pernet(net);
1718 spin_lock_bh(&pernet->lock);
1719 for (i = id; i < MPTCP_PM_MAX_ADDR_ID + 1; i++) {
1720 if (test_bit(i, pernet->id_bitmap)) {
1721 entry = __lookup_addr_by_id(pernet, i);
1725 if (entry->addr.id <= id)
1728 hdr = genlmsg_put(msg, NETLINK_CB(cb->skb).portid,
1729 cb->nlh->nlmsg_seq, &mptcp_genl_family,
1730 NLM_F_MULTI, MPTCP_PM_CMD_GET_ADDR);
1734 if (mptcp_nl_fill_addr(msg, entry) < 0) {
1735 genlmsg_cancel(msg, hdr);
1739 id = entry->addr.id;
1740 genlmsg_end(msg, hdr);
1743 spin_unlock_bh(&pernet->lock);
1749 static int parse_limit(struct genl_info *info, int id, unsigned int *limit)
1751 struct nlattr *attr = info->attrs[id];
1756 *limit = nla_get_u32(attr);
1757 if (*limit > MPTCP_PM_ADDR_MAX) {
1758 GENL_SET_ERR_MSG(info, "limit greater than maximum");
1764 int mptcp_pm_nl_set_limits_doit(struct sk_buff *skb, struct genl_info *info)
1766 struct pm_nl_pernet *pernet = genl_info_pm_nl(info);
1767 unsigned int rcv_addrs, subflows;
1770 spin_lock_bh(&pernet->lock);
1771 rcv_addrs = pernet->add_addr_accept_max;
1772 ret = parse_limit(info, MPTCP_PM_ATTR_RCV_ADD_ADDRS, &rcv_addrs);
1776 subflows = pernet->subflows_max;
1777 ret = parse_limit(info, MPTCP_PM_ATTR_SUBFLOWS, &subflows);
1781 WRITE_ONCE(pernet->add_addr_accept_max, rcv_addrs);
1782 WRITE_ONCE(pernet->subflows_max, subflows);
1785 spin_unlock_bh(&pernet->lock);
1789 int mptcp_pm_nl_get_limits_doit(struct sk_buff *skb, struct genl_info *info)
1791 struct pm_nl_pernet *pernet = genl_info_pm_nl(info);
1792 struct sk_buff *msg;
1795 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
1799 reply = genlmsg_put_reply(msg, info, &mptcp_genl_family, 0,
1800 MPTCP_PM_CMD_GET_LIMITS);
1804 if (nla_put_u32(msg, MPTCP_PM_ATTR_RCV_ADD_ADDRS,
1805 READ_ONCE(pernet->add_addr_accept_max)))
1808 if (nla_put_u32(msg, MPTCP_PM_ATTR_SUBFLOWS,
1809 READ_ONCE(pernet->subflows_max)))
1812 genlmsg_end(msg, reply);
1813 return genlmsg_reply(msg, info);
1816 GENL_SET_ERR_MSG(info, "not enough space in Netlink message");
1821 static void mptcp_pm_nl_fullmesh(struct mptcp_sock *msk,
1822 struct mptcp_addr_info *addr)
1824 struct mptcp_rm_list list = { .nr = 0 };
1826 list.ids[list.nr++] = addr->id;
1828 spin_lock_bh(&msk->pm.lock);
1829 mptcp_pm_nl_rm_subflow_received(msk, &list);
1830 mptcp_pm_create_subflow_or_signal_addr(msk);
1831 spin_unlock_bh(&msk->pm.lock);
1834 static int mptcp_nl_set_flags(struct net *net,
1835 struct mptcp_addr_info *addr,
1836 u8 bkup, u8 changed)
1838 long s_slot = 0, s_num = 0;
1839 struct mptcp_sock *msk;
1842 while ((msk = mptcp_token_iter_next(net, &s_slot, &s_num)) != NULL) {
1843 struct sock *sk = (struct sock *)msk;
1845 if (list_empty(&msk->conn_list) || mptcp_pm_is_userspace(msk))
1849 if (changed & MPTCP_PM_ADDR_FLAG_BACKUP)
1850 ret = mptcp_pm_nl_mp_prio_send_ack(msk, addr, NULL, bkup);
1851 if (changed & MPTCP_PM_ADDR_FLAG_FULLMESH)
1852 mptcp_pm_nl_fullmesh(msk, addr);
1863 int mptcp_pm_nl_set_flags(struct net *net, struct mptcp_pm_addr_entry *addr, u8 bkup)
1865 struct pm_nl_pernet *pernet = pm_nl_get_pernet(net);
1866 u8 changed, mask = MPTCP_PM_ADDR_FLAG_BACKUP |
1867 MPTCP_PM_ADDR_FLAG_FULLMESH;
1868 struct mptcp_pm_addr_entry *entry;
1869 u8 lookup_by_id = 0;
1871 if (addr->addr.family == AF_UNSPEC) {
1877 spin_lock_bh(&pernet->lock);
1878 entry = __lookup_addr(pernet, &addr->addr, lookup_by_id);
1880 spin_unlock_bh(&pernet->lock);
1883 if ((addr->flags & MPTCP_PM_ADDR_FLAG_FULLMESH) &&
1884 (entry->flags & MPTCP_PM_ADDR_FLAG_SIGNAL)) {
1885 spin_unlock_bh(&pernet->lock);
1889 changed = (addr->flags ^ entry->flags) & mask;
1890 entry->flags = (entry->flags & ~mask) | (addr->flags & mask);
1892 spin_unlock_bh(&pernet->lock);
1894 mptcp_nl_set_flags(net, &addr->addr, bkup, changed);
1898 int mptcp_pm_nl_set_flags_doit(struct sk_buff *skb, struct genl_info *info)
1900 struct mptcp_pm_addr_entry remote = { .addr = { .family = AF_UNSPEC }, };
1901 struct mptcp_pm_addr_entry addr = { .addr = { .family = AF_UNSPEC }, };
1902 struct nlattr *attr_rem = info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE];
1903 struct nlattr *token = info->attrs[MPTCP_PM_ATTR_TOKEN];
1904 struct nlattr *attr = info->attrs[MPTCP_PM_ATTR_ADDR];
1905 struct net *net = sock_net(skb->sk);
1909 ret = mptcp_pm_parse_entry(attr, info, false, &addr);
1914 ret = mptcp_pm_parse_entry(attr_rem, info, false, &remote);
1919 if (addr.flags & MPTCP_PM_ADDR_FLAG_BACKUP)
1922 return mptcp_pm_set_flags(net, token, &addr, &remote, bkup);
1925 static void mptcp_nl_mcast_send(struct net *net, struct sk_buff *nlskb, gfp_t gfp)
1927 genlmsg_multicast_netns(&mptcp_genl_family, net,
1928 nlskb, 0, MPTCP_PM_EV_GRP_OFFSET, gfp);
1931 bool mptcp_userspace_pm_active(const struct mptcp_sock *msk)
1933 return genl_has_listeners(&mptcp_genl_family,
1934 sock_net((const struct sock *)msk),
1935 MPTCP_PM_EV_GRP_OFFSET);
1938 static int mptcp_event_add_subflow(struct sk_buff *skb, const struct sock *ssk)
1940 const struct inet_sock *issk = inet_sk(ssk);
1941 const struct mptcp_subflow_context *sf;
1943 if (nla_put_u16(skb, MPTCP_ATTR_FAMILY, ssk->sk_family))
1946 switch (ssk->sk_family) {
1948 if (nla_put_in_addr(skb, MPTCP_ATTR_SADDR4, issk->inet_saddr))
1950 if (nla_put_in_addr(skb, MPTCP_ATTR_DADDR4, issk->inet_daddr))
1953 #if IS_ENABLED(CONFIG_MPTCP_IPV6)
1955 const struct ipv6_pinfo *np = inet6_sk(ssk);
1957 if (nla_put_in6_addr(skb, MPTCP_ATTR_SADDR6, &np->saddr))
1959 if (nla_put_in6_addr(skb, MPTCP_ATTR_DADDR6, &ssk->sk_v6_daddr))
1969 if (nla_put_be16(skb, MPTCP_ATTR_SPORT, issk->inet_sport))
1971 if (nla_put_be16(skb, MPTCP_ATTR_DPORT, issk->inet_dport))
1974 sf = mptcp_subflow_ctx(ssk);
1975 if (WARN_ON_ONCE(!sf))
1978 if (nla_put_u8(skb, MPTCP_ATTR_LOC_ID, sf->local_id))
1981 if (nla_put_u8(skb, MPTCP_ATTR_REM_ID, sf->remote_id))
1987 static int mptcp_event_put_token_and_ssk(struct sk_buff *skb,
1988 const struct mptcp_sock *msk,
1989 const struct sock *ssk)
1991 const struct sock *sk = (const struct sock *)msk;
1992 const struct mptcp_subflow_context *sf;
1995 if (nla_put_u32(skb, MPTCP_ATTR_TOKEN, msk->token))
1998 if (mptcp_event_add_subflow(skb, ssk))
2001 sf = mptcp_subflow_ctx(ssk);
2002 if (WARN_ON_ONCE(!sf))
2005 if (nla_put_u8(skb, MPTCP_ATTR_BACKUP, sf->backup))
2008 if (ssk->sk_bound_dev_if &&
2009 nla_put_s32(skb, MPTCP_ATTR_IF_IDX, ssk->sk_bound_dev_if))
2012 sk_err = READ_ONCE(ssk->sk_err);
2013 if (sk_err && sk->sk_state == TCP_ESTABLISHED &&
2014 nla_put_u8(skb, MPTCP_ATTR_ERROR, sk_err))
2020 static int mptcp_event_sub_established(struct sk_buff *skb,
2021 const struct mptcp_sock *msk,
2022 const struct sock *ssk)
2024 return mptcp_event_put_token_and_ssk(skb, msk, ssk);
2027 static int mptcp_event_sub_closed(struct sk_buff *skb,
2028 const struct mptcp_sock *msk,
2029 const struct sock *ssk)
2031 const struct mptcp_subflow_context *sf;
2033 if (mptcp_event_put_token_and_ssk(skb, msk, ssk))
2036 sf = mptcp_subflow_ctx(ssk);
2037 if (!sf->reset_seen)
2040 if (nla_put_u32(skb, MPTCP_ATTR_RESET_REASON, sf->reset_reason))
2043 if (nla_put_u32(skb, MPTCP_ATTR_RESET_FLAGS, sf->reset_transient))
2049 static int mptcp_event_created(struct sk_buff *skb,
2050 const struct mptcp_sock *msk,
2051 const struct sock *ssk)
2053 int err = nla_put_u32(skb, MPTCP_ATTR_TOKEN, msk->token);
2058 if (nla_put_u8(skb, MPTCP_ATTR_SERVER_SIDE, READ_ONCE(msk->pm.server_side)))
2061 return mptcp_event_add_subflow(skb, ssk);
2064 void mptcp_event_addr_removed(const struct mptcp_sock *msk, uint8_t id)
2066 struct net *net = sock_net((const struct sock *)msk);
2067 struct nlmsghdr *nlh;
2068 struct sk_buff *skb;
2070 if (!genl_has_listeners(&mptcp_genl_family, net, MPTCP_PM_EV_GRP_OFFSET))
2073 skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
2077 nlh = genlmsg_put(skb, 0, 0, &mptcp_genl_family, 0, MPTCP_EVENT_REMOVED);
2079 goto nla_put_failure;
2081 if (nla_put_u32(skb, MPTCP_ATTR_TOKEN, msk->token))
2082 goto nla_put_failure;
2084 if (nla_put_u8(skb, MPTCP_ATTR_REM_ID, id))
2085 goto nla_put_failure;
2087 genlmsg_end(skb, nlh);
2088 mptcp_nl_mcast_send(net, skb, GFP_ATOMIC);
2095 void mptcp_event_addr_announced(const struct sock *ssk,
2096 const struct mptcp_addr_info *info)
2098 struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk);
2099 struct mptcp_sock *msk = mptcp_sk(subflow->conn);
2100 struct net *net = sock_net(ssk);
2101 struct nlmsghdr *nlh;
2102 struct sk_buff *skb;
2104 if (!genl_has_listeners(&mptcp_genl_family, net, MPTCP_PM_EV_GRP_OFFSET))
2107 skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
2111 nlh = genlmsg_put(skb, 0, 0, &mptcp_genl_family, 0,
2112 MPTCP_EVENT_ANNOUNCED);
2114 goto nla_put_failure;
2116 if (nla_put_u32(skb, MPTCP_ATTR_TOKEN, msk->token))
2117 goto nla_put_failure;
2119 if (nla_put_u8(skb, MPTCP_ATTR_REM_ID, info->id))
2120 goto nla_put_failure;
2122 if (nla_put_be16(skb, MPTCP_ATTR_DPORT,
2124 inet_sk(ssk)->inet_dport :
2126 goto nla_put_failure;
2128 switch (info->family) {
2130 if (nla_put_in_addr(skb, MPTCP_ATTR_DADDR4, info->addr.s_addr))
2131 goto nla_put_failure;
2133 #if IS_ENABLED(CONFIG_MPTCP_IPV6)
2135 if (nla_put_in6_addr(skb, MPTCP_ATTR_DADDR6, &info->addr6))
2136 goto nla_put_failure;
2141 goto nla_put_failure;
2144 genlmsg_end(skb, nlh);
2145 mptcp_nl_mcast_send(net, skb, GFP_ATOMIC);
2152 void mptcp_event_pm_listener(const struct sock *ssk,
2153 enum mptcp_event_type event)
2155 const struct inet_sock *issk = inet_sk(ssk);
2156 struct net *net = sock_net(ssk);
2157 struct nlmsghdr *nlh;
2158 struct sk_buff *skb;
2160 if (!genl_has_listeners(&mptcp_genl_family, net, MPTCP_PM_EV_GRP_OFFSET))
2163 skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2167 nlh = genlmsg_put(skb, 0, 0, &mptcp_genl_family, 0, event);
2169 goto nla_put_failure;
2171 if (nla_put_u16(skb, MPTCP_ATTR_FAMILY, ssk->sk_family))
2172 goto nla_put_failure;
2174 if (nla_put_be16(skb, MPTCP_ATTR_SPORT, issk->inet_sport))
2175 goto nla_put_failure;
2177 switch (ssk->sk_family) {
2179 if (nla_put_in_addr(skb, MPTCP_ATTR_SADDR4, issk->inet_saddr))
2180 goto nla_put_failure;
2182 #if IS_ENABLED(CONFIG_MPTCP_IPV6)
2184 const struct ipv6_pinfo *np = inet6_sk(ssk);
2186 if (nla_put_in6_addr(skb, MPTCP_ATTR_SADDR6, &np->saddr))
2187 goto nla_put_failure;
2193 goto nla_put_failure;
2196 genlmsg_end(skb, nlh);
2197 mptcp_nl_mcast_send(net, skb, GFP_KERNEL);
2204 void mptcp_event(enum mptcp_event_type type, const struct mptcp_sock *msk,
2205 const struct sock *ssk, gfp_t gfp)
2207 struct net *net = sock_net((const struct sock *)msk);
2208 struct nlmsghdr *nlh;
2209 struct sk_buff *skb;
2211 if (!genl_has_listeners(&mptcp_genl_family, net, MPTCP_PM_EV_GRP_OFFSET))
2214 skb = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
2218 nlh = genlmsg_put(skb, 0, 0, &mptcp_genl_family, 0, type);
2220 goto nla_put_failure;
2223 case MPTCP_EVENT_UNSPEC:
2226 case MPTCP_EVENT_CREATED:
2227 case MPTCP_EVENT_ESTABLISHED:
2228 if (mptcp_event_created(skb, msk, ssk) < 0)
2229 goto nla_put_failure;
2231 case MPTCP_EVENT_CLOSED:
2232 if (nla_put_u32(skb, MPTCP_ATTR_TOKEN, msk->token) < 0)
2233 goto nla_put_failure;
2235 case MPTCP_EVENT_ANNOUNCED:
2236 case MPTCP_EVENT_REMOVED:
2237 /* call mptcp_event_addr_announced()/removed instead */
2240 case MPTCP_EVENT_SUB_ESTABLISHED:
2241 case MPTCP_EVENT_SUB_PRIORITY:
2242 if (mptcp_event_sub_established(skb, msk, ssk) < 0)
2243 goto nla_put_failure;
2245 case MPTCP_EVENT_SUB_CLOSED:
2246 if (mptcp_event_sub_closed(skb, msk, ssk) < 0)
2247 goto nla_put_failure;
2249 case MPTCP_EVENT_LISTENER_CREATED:
2250 case MPTCP_EVENT_LISTENER_CLOSED:
2254 genlmsg_end(skb, nlh);
2255 mptcp_nl_mcast_send(net, skb, gfp);
2262 static struct genl_family mptcp_genl_family __ro_after_init = {
2263 .name = MPTCP_PM_NAME,
2264 .version = MPTCP_PM_VER,
2266 .module = THIS_MODULE,
2267 .ops = mptcp_pm_nl_ops,
2268 .n_ops = ARRAY_SIZE(mptcp_pm_nl_ops),
2269 .resv_start_op = MPTCP_PM_CMD_SUBFLOW_DESTROY + 1,
2270 .mcgrps = mptcp_pm_mcgrps,
2271 .n_mcgrps = ARRAY_SIZE(mptcp_pm_mcgrps),
2274 static int __net_init pm_nl_init_net(struct net *net)
2276 struct pm_nl_pernet *pernet = pm_nl_get_pernet(net);
2278 INIT_LIST_HEAD_RCU(&pernet->local_addr_list);
2280 /* Cit. 2 subflows ought to be enough for anybody. */
2281 pernet->subflows_max = 2;
2282 pernet->next_id = 1;
2283 pernet->stale_loss_cnt = 4;
2284 spin_lock_init(&pernet->lock);
2286 /* No need to initialize other pernet fields, the struct is zeroed at
2293 static void __net_exit pm_nl_exit_net(struct list_head *net_list)
2297 list_for_each_entry(net, net_list, exit_list) {
2298 struct pm_nl_pernet *pernet = pm_nl_get_pernet(net);
2300 /* net is removed from namespace list, can't race with
2301 * other modifiers, also netns core already waited for a
2304 __flush_addrs(&pernet->local_addr_list);
2308 static struct pernet_operations mptcp_pm_pernet_ops = {
2309 .init = pm_nl_init_net,
2310 .exit_batch = pm_nl_exit_net,
2311 .id = &pm_nl_pernet_id,
2312 .size = sizeof(struct pm_nl_pernet),
2315 void __init mptcp_pm_nl_init(void)
2317 if (register_pernet_subsys(&mptcp_pm_pernet_ops) < 0)
2318 panic("Failed to register MPTCP PM pernet subsystem.\n");
2320 if (genl_register_family(&mptcp_genl_family))
2321 panic("Failed to register MPTCP PM netlink family\n");