Skip to content

Commit 1a0d613

Browse files
Geliang Tangdavem330
authored andcommitted
mptcp: local addresses fullmesh
In mptcp_pm_nl_add_addr_received(), fill a temporary allocate array of all local address corresponding to the fullmesh endpoint. If such array is empty, keep the current behavior. Elsewhere loop on such array and create a subflow for each local address towards the given remote address Suggested-by: Paolo Abeni <[email protected]> Signed-off-by: Geliang Tang <[email protected]> Signed-off-by: Mat Martineau <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 2843ff6 commit 1a0d613

File tree

1 file changed

+63
-10
lines changed

1 file changed

+63
-10
lines changed

net/mptcp/pm_netlink.c

Lines changed: 63 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -534,13 +534,67 @@ static void mptcp_pm_nl_subflow_established(struct mptcp_sock *msk)
534534
mptcp_pm_create_subflow_or_signal_addr(msk);
535535
}
536536

537+
/* Fill all the local addresses into the array addrs[],
538+
* and return the array size.
539+
*/
540+
static unsigned int fill_local_addresses_vec(struct mptcp_sock *msk,
541+
struct mptcp_addr_info *addrs)
542+
{
543+
struct sock *sk = (struct sock *)msk;
544+
struct mptcp_pm_addr_entry *entry;
545+
struct mptcp_addr_info local;
546+
struct pm_nl_pernet *pernet;
547+
unsigned int subflows_max;
548+
int i = 0;
549+
550+
pernet = net_generic(sock_net(sk), pm_nl_pernet_id);
551+
subflows_max = mptcp_pm_get_subflows_max(msk);
552+
553+
rcu_read_lock();
554+
__mptcp_flush_join_list(msk);
555+
list_for_each_entry_rcu(entry, &pernet->local_addr_list, list) {
556+
if (!(entry->flags & MPTCP_PM_ADDR_FLAG_FULLMESH))
557+
continue;
558+
559+
if (entry->addr.family != sk->sk_family) {
560+
#if IS_ENABLED(CONFIG_MPTCP_IPV6)
561+
if ((entry->addr.family == AF_INET &&
562+
!ipv6_addr_v4mapped(&sk->sk_v6_daddr)) ||
563+
(sk->sk_family == AF_INET &&
564+
!ipv6_addr_v4mapped(&entry->addr.addr6)))
565+
#endif
566+
continue;
567+
}
568+
569+
if (msk->pm.subflows < subflows_max) {
570+
msk->pm.subflows++;
571+
addrs[i++] = entry->addr;
572+
}
573+
}
574+
rcu_read_unlock();
575+
576+
/* If the array is empty, fill in the single
577+
* 'IPADDRANY' local address
578+
*/
579+
if (!i) {
580+
memset(&local, 0, sizeof(local));
581+
local.family = msk->pm.remote.family;
582+
583+
msk->pm.subflows++;
584+
addrs[i++] = local;
585+
}
586+
587+
return i;
588+
}
589+
537590
static void mptcp_pm_nl_add_addr_received(struct mptcp_sock *msk)
538591
{
592+
struct mptcp_addr_info addrs[MPTCP_PM_ADDR_MAX];
539593
struct sock *sk = (struct sock *)msk;
540594
unsigned int add_addr_accept_max;
541595
struct mptcp_addr_info remote;
542-
struct mptcp_addr_info local;
543596
unsigned int subflows_max;
597+
int i, nr;
544598

545599
add_addr_accept_max = mptcp_pm_get_add_addr_accept_max(msk);
546600
subflows_max = mptcp_pm_get_subflows_max(msk);
@@ -552,23 +606,22 @@ static void mptcp_pm_nl_add_addr_received(struct mptcp_sock *msk)
552606
if (lookup_subflow_by_daddr(&msk->conn_list, &msk->pm.remote))
553607
goto add_addr_echo;
554608

555-
msk->pm.add_addr_accepted++;
556-
msk->pm.subflows++;
557-
if (msk->pm.add_addr_accepted >= add_addr_accept_max ||
558-
msk->pm.subflows >= subflows_max)
559-
WRITE_ONCE(msk->pm.accept_addr, false);
560-
561609
/* connect to the specified remote address, using whatever
562610
* local address the routing configuration will pick.
563611
*/
564612
remote = msk->pm.remote;
565613
if (!remote.port)
566614
remote.port = sk->sk_dport;
567-
memset(&local, 0, sizeof(local));
568-
local.family = remote.family;
615+
nr = fill_local_addresses_vec(msk, addrs);
616+
617+
msk->pm.add_addr_accepted++;
618+
if (msk->pm.add_addr_accepted >= add_addr_accept_max ||
619+
msk->pm.subflows >= subflows_max)
620+
WRITE_ONCE(msk->pm.accept_addr, false);
569621

570622
spin_unlock_bh(&msk->pm.lock);
571-
__mptcp_subflow_connect(sk, &local, &remote);
623+
for (i = 0; i < nr; i++)
624+
__mptcp_subflow_connect(sk, &addrs[i], &remote);
572625
spin_lock_bh(&msk->pm.lock);
573626

574627
add_addr_echo:

0 commit comments

Comments
 (0)