Skip to content

Commit

Permalink
mptcp: add netlink pm addr entry refcount
Browse files Browse the repository at this point in the history
This patch adds netlink PM address entry refcount. Init 'refcont' of
every address entry to 1..

Increase this refcount counter when a subflow connecting or an address
signaling in mptcp_pm_create_subflow_or_signal_addr() and
fill_local_addresses_vec().

Decrease it in __mptcp_pm_release_addr_entry(). When the counter reaches
1, then free this entry.

Signed-off-by: Geliang Tang <[email protected]>
  • Loading branch information
geliangtang authored and intel-lab-lkp committed Nov 1, 2023
1 parent 29a577b commit e67a0f6
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions net/mptcp/pm_netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -603,8 +603,10 @@ static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk)
continue;

spin_unlock_bh(&msk->pm.lock);
for (i = 0; i < nr; i++)
__mptcp_subflow_connect(sk, &local->addr, &addrs[i]);
for (i = 0; i < nr; i++) {
if (refcount_inc_not_zero(&local->refcnt))
__mptcp_subflow_connect(sk, &local->addr, &addrs[i]);
}
spin_lock_bh(&msk->pm.lock);
}
mptcp_pm_nl_check_work_pending(msk);
Expand Down Expand Up @@ -644,7 +646,8 @@ static unsigned int fill_local_addresses_vec(struct mptcp_sock *msk,
if (!mptcp_pm_addr_families_match(sk, &entry->addr, remote))
continue;

if (msk->pm.subflows < subflows_max) {
if (msk->pm.subflows < subflows_max &&
refcount_inc_not_zero(&entry->refcnt)) {
msk->pm.subflows++;
addrs[i++] = entry->addr;
}
Expand Down Expand Up @@ -895,9 +898,11 @@ static bool address_use_port(struct mptcp_pm_addr_entry *entry)
/* caller must ensure the RCU grace period is already elapsed */
static void __mptcp_pm_release_addr_entry(struct mptcp_pm_addr_entry *entry)
{
if (entry->lsk)
sock_release(entry->lsk);
kfree(entry);
if (!refcount_dec_not_one(&entry->refcnt)) {
if (entry->lsk)
sock_release(entry->lsk);
kfree(entry);
}
}

static int mptcp_pm_nl_append_new_local_addr(struct pm_nl_pernet *pernet,
Expand Down Expand Up @@ -1087,6 +1092,7 @@ int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct mptcp_addr_info *skc
entry->ifindex = 0;
entry->flags = MPTCP_PM_ADDR_FLAG_IMPLICIT;
entry->lsk = NULL;
refcount_set(&entry->refcnt, 1);
ret = mptcp_pm_nl_append_new_local_addr(pernet, entry);
if (ret < 0)
kfree(entry);
Expand Down Expand Up @@ -1314,6 +1320,7 @@ int mptcp_pm_nl_add_addr_doit(struct sk_buff *skb, struct genl_info *info)
}

*entry = addr;
refcount_set(&entry->refcnt, 1);
if (entry->addr.port) {
ret = mptcp_pm_nl_create_listen_socket(skb->sk, entry);
if (ret) {
Expand Down

0 comments on commit e67a0f6

Please sign in to comment.