@@ -61,26 +61,13 @@ static int mptcp_userspace_pm_append_new_local_addr(struct mptcp_sock *msk,
struct pm_nl_pernet *pernet = pm_nl_get_pernet_from_msk(msk);
struct mptcp_pm_addr_entry *match = NULL;
struct sock *sk = (struct sock *)msk;
- struct mptcp_pm_addr_entry *e;
- bool addr_match = false;
- bool id_match = false;
int ret = -EINVAL;
spin_lock_bh(&msk->pm.lock);
- list_for_each_entry(e, &msk->pm.userspace_pm_local_addr_list, list) {
- addr_match = mptcp_addresses_equal(&e->addr, &entry->addr, true, false);
- if (addr_match && entry->addr.id == 0 && !set_id)
- entry->addr.id = e->addr.id;
- id_match = (e->addr.id == entry->addr.id);
- if (addr_match && id_match) {
- match = e;
- break;
- } else if (addr_match || id_match) {
- break;
- }
- }
+ match = mptcp_userspace_pm_get_entry(msk, &entry->addr, true, entry->addr.id);
+ if (!match) {
+ struct mptcp_pm_addr_entry *e;
- if (!match && !addr_match && !id_match) {
/* Memory for the entry is allocated from the
* sock option buffer.
*/
@@ -99,10 +86,13 @@ static int mptcp_userspace_pm_append_new_local_addr(struct mptcp_sock *msk,
list_add_tail_rcu(&e->list, &msk->pm.userspace_pm_local_addr_list);
msk->pm.local_addr_used++;
ret = e->addr.id;
- } else if (match) {
- ret = entry->addr.id;
+ goto append_err;
}
+ if (entry->addr.id == 0 && !set_id)
+ entry->addr.id = match->addr.id;
+ ret = entry->addr.id;
+
append_err:
spin_unlock_bh(&msk->pm.lock);
return ret;
This patch uses the newly defined helper mptcp_userspace_pm_get_entry() in mptcp_userspace_pm_append_new_local_addr(), and drop local variables addr_match and id_match to simplify the code. Signed-off-by: Geliang Tang <geliang.tang@suse.com> --- net/mptcp/pm_userspace.c | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-)