Skip to content

Commit

Permalink
mptcp: drop addr_match and id_match
Browse files Browse the repository at this point in the history
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@linux.dev>
  • Loading branch information
Geliang Tang authored and Geliang Tang committed Dec 12, 2024
1 parent a1cd91c commit 1b2efbb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 32 deletions.
54 changes: 22 additions & 32 deletions net/mptcp/pm_userspace.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,48 +56,38 @@ static int mptcp_userspace_pm_append_new_local_addr(struct mptcp_sock *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;

bitmap_zero(id_bitmap, MPTCP_PM_MAX_ADDR_ID + 1);

spin_lock_bh(&msk->pm.lock);
mptcp_for_each_userspace_pm_addr(msk, e) {
addr_match = mptcp_addresses_equal(&e->addr, &entry->addr, true);
if (addr_match && entry->addr.id == 0 && needs_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;
if (mptcp_addresses_equal_check_id(&e->addr, &entry->addr, true, entry->addr.id)) {
if (entry->addr.id == 0 && needs_id)
entry->addr.id = e->addr.id;
ret = entry->addr.id;
goto append_err;
}
__set_bit(e->addr.id, id_bitmap);
}

if (!match && !addr_match && !id_match) {
/* Memory for the entry is allocated from the
* sock option buffer.
*/
e = sock_kmalloc(sk, sizeof(*e), GFP_ATOMIC);
if (!e) {
ret = -ENOMEM;
goto append_err;
}

*e = *entry;
if (!e->addr.id && needs_id)
e->addr.id = find_next_zero_bit(id_bitmap,
MPTCP_PM_MAX_ADDR_ID + 1,
1);
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;
}
/* Memory for the entry is allocated from the
* sock option buffer.
*/
e = sock_kmalloc(sk, sizeof(*e), GFP_ATOMIC);
if (!e) {
ret = -ENOMEM;
goto append_err;
}

*e = *entry;
if (!e->addr.id && needs_id)
e->addr.id = find_next_zero_bit(id_bitmap,
MPTCP_PM_MAX_ADDR_ID + 1,
1);
list_add_tail_rcu(&e->list, &msk->pm.userspace_pm_local_addr_list);
msk->pm.local_addr_used++;
ret = e->addr.id;

append_err:
spin_unlock_bh(&msk->pm.lock);
Expand Down
7 changes: 7 additions & 0 deletions net/mptcp/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,13 @@ bool mptcp_addresses_equal(const struct mptcp_addr_info *a,
const struct mptcp_addr_info *b, bool use_port);
void mptcp_local_address(const struct sock_common *skc, struct mptcp_addr_info *addr);

static inline bool mptcp_addresses_equal_check_id(const struct mptcp_addr_info *a,
const struct mptcp_addr_info *b,
bool use_port, bool check_id)
{
return mptcp_addresses_equal(a, b, use_port) ? a->id == b->id : false;
}

/* called with sk socket lock held */
int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_pm_local *local,
const struct mptcp_addr_info *remote);
Expand Down

0 comments on commit 1b2efbb

Please sign in to comment.