Skip to content

Commit

Permalink
mptcp: add addresses_identically_equal helper
Browse files Browse the repository at this point in the history
Similar to addresses_equal() helper, this patch adds a new helper
addresses_identically_equal() to test if the two given addresses
have both the same address and the same address id.

Add a new parameter check_id for mptcp_lookup_anno_list_by_saddr(),
and use the newly added helper instead of mptcp_addresses_equal()
in it.

Signed-off-by: Geliang Tang <[email protected]>
  • Loading branch information
geliangtang authored and intel-lab-lkp committed Nov 4, 2023
1 parent f7e5ef8 commit 891bd5e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
2 changes: 1 addition & 1 deletion net/mptcp/pm.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ void mptcp_pm_add_addr_echoed(struct mptcp_sock *msk,

spin_lock_bh(&pm->lock);

if (mptcp_lookup_anno_list_by_saddr(msk, addr) && READ_ONCE(pm->work_pending))
if (mptcp_lookup_anno_list_by_saddr(msk, addr, false) && READ_ONCE(pm->work_pending))
mptcp_pm_schedule_work(msk, MPTCP_PM_SUBFLOW_ESTABLISHED);

spin_unlock_bh(&pm->lock);
Expand Down
25 changes: 19 additions & 6 deletions net/mptcp/pm_netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,18 @@ bool mptcp_addresses_equal(const struct mptcp_addr_info *a,
return a->port == b->port;
}

static bool addresses_identically_equal(const struct mptcp_addr_info *a,
const struct mptcp_addr_info *b,
bool use_port, bool check_id)
{
if (!mptcp_addresses_equal(a, b, use_port))
return false;
if (!check_id)
return true;

return a->id == b->id;
}

void mptcp_local_address(const struct sock_common *skc, struct mptcp_addr_info *addr)
{
addr->family = skc->skc_family;
Expand Down Expand Up @@ -267,14 +279,15 @@ bool mptcp_pm_nl_check_work_pending(struct mptcp_sock *msk)

struct mptcp_pm_add_entry *
mptcp_lookup_anno_list_by_saddr(const struct mptcp_sock *msk,
const struct mptcp_addr_info *addr)
const struct mptcp_addr_info *addr,
bool check_id)
{
struct mptcp_pm_add_entry *entry;

lockdep_assert_held(&msk->pm.lock);

list_for_each_entry(entry, &msk->pm.anno_list, list) {
if (mptcp_addresses_equal(&entry->addr, addr, true))
if (addresses_identically_equal(&entry->addr, addr, true, check_id))
return entry;
}

Expand Down Expand Up @@ -354,12 +367,12 @@ mptcp_pm_del_add_timer(struct mptcp_sock *msk,
struct sock *sk = (struct sock *)msk;

spin_lock_bh(&msk->pm.lock);
entry = mptcp_lookup_anno_list_by_saddr(msk, addr);
if (entry && (!check_id || entry->addr.id == addr->id))
entry = mptcp_lookup_anno_list_by_saddr(msk, addr, check_id);
if (entry)
entry->retrans_times = ADD_ADDR_RETRANS_MAX;
spin_unlock_bh(&msk->pm.lock);

if (entry && (!check_id || entry->addr.id == addr->id))
if (entry)
sk_stop_timer_sync(sk, &entry->add_timer);

return entry;
Expand All @@ -374,7 +387,7 @@ bool mptcp_pm_alloc_anno_list(struct mptcp_sock *msk,

lockdep_assert_held(&msk->pm.lock);

add_entry = mptcp_lookup_anno_list_by_saddr(msk, addr);
add_entry = mptcp_lookup_anno_list_by_saddr(msk, addr, false);

if (add_entry) {
if (mptcp_pm_is_kernel(msk))
Expand Down
3 changes: 2 additions & 1 deletion net/mptcp/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,8 @@ mptcp_pm_del_add_timer(struct mptcp_sock *msk,
const struct mptcp_addr_info *addr, bool check_id);
struct mptcp_pm_add_entry *
mptcp_lookup_anno_list_by_saddr(const struct mptcp_sock *msk,
const struct mptcp_addr_info *addr);
const struct mptcp_addr_info *addr,
bool check_id);
int mptcp_pm_get_flags_and_ifindex_by_id(struct mptcp_sock *msk,
unsigned int id,
u8 *flags, int *ifindex);
Expand Down

0 comments on commit 891bd5e

Please sign in to comment.