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 <geliang.tang@suse.com>
---
net/mptcp/pm_netlink.c | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c
index 1a66de9127e2..a482faad567d 100644
--- a/net/mptcp/pm_netlink.c
+++ b/net/mptcp/pm_netlink.c
@@ -637,8 +637,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);
@@ -678,7 +680,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;
}
@@ -929,9 +932,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,
@@ -1121,6 +1126,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);
@@ -1348,6 +1354,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) {
--
2.35.3