mptcp: unify pm get_flags_and_ifindex_by_id

This patch unifies the three PM get_flags_and_ifindex_by_id() interfaces:

mptcp_pm_nl_get_flags_and_ifindex_by_id() in mptcp/pm_netlink.c for the
in-kernel PM and mptcp_userspace_pm_get_flags_and_ifindex_by_id() in
mptcp/pm_userspace.c for the userspace PM.

They'll be switched in the common PM infterface
mptcp_pm_get_flags_and_ifindex_by_id() in mptcp/pm.c based on whether
mptcp_pm_is_userspace() or not.

Signed-off-by: Geliang Tang <geliang.tang@suse.com>
Reviewed-by: Matthieu Baerts <matthieu.baerts@tessares.net>
Signed-off-by: Matthieu Baerts <matthieu.baerts@tessares.net>
Reviewed-by: Larysa Zaremba <larysa.zaremba@intel.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
Geliang Tang 2023-06-08 15:20:51 +02:00 committed by Jakub Kicinski
parent 9bbec87ecf
commit f40be0db0b
4 changed files with 24 additions and 22 deletions

View File

@ -434,6 +434,20 @@ int mptcp_pm_get_local_id(struct mptcp_sock *msk, struct sock_common *skc)
return mptcp_pm_nl_get_local_id(msk, &skc_local); return mptcp_pm_nl_get_local_id(msk, &skc_local);
} }
int mptcp_pm_get_flags_and_ifindex_by_id(struct mptcp_sock *msk, unsigned int id,
u8 *flags, int *ifindex)
{
*flags = 0;
*ifindex = 0;
if (!id)
return 0;
if (mptcp_pm_is_userspace(msk))
return mptcp_userspace_pm_get_flags_and_ifindex_by_id(msk, id, flags, ifindex);
return mptcp_pm_nl_get_flags_and_ifindex_by_id(msk, id, flags, ifindex);
}
void mptcp_pm_subflow_chk_stale(const struct mptcp_sock *msk, struct sock *ssk) void mptcp_pm_subflow_chk_stale(const struct mptcp_sock *msk, struct sock *ssk)
{ {
struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk); struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk);

View File

@ -1356,31 +1356,20 @@ out_free:
return ret; return ret;
} }
int mptcp_pm_get_flags_and_ifindex_by_id(struct mptcp_sock *msk, unsigned int id, int mptcp_pm_nl_get_flags_and_ifindex_by_id(struct mptcp_sock *msk, unsigned int id,
u8 *flags, int *ifindex) u8 *flags, int *ifindex)
{ {
struct mptcp_pm_addr_entry *entry; struct mptcp_pm_addr_entry *entry;
struct sock *sk = (struct sock *)msk; struct sock *sk = (struct sock *)msk;
struct net *net = sock_net(sk); struct net *net = sock_net(sk);
*flags = 0; rcu_read_lock();
*ifindex = 0; entry = __lookup_addr_by_id(pm_nl_get_pernet(net), id);
if (entry) {
if (id) { *flags = entry->flags;
if (mptcp_pm_is_userspace(msk)) *ifindex = entry->ifindex;
return mptcp_userspace_pm_get_flags_and_ifindex_by_id(msk,
id,
flags,
ifindex);
rcu_read_lock();
entry = __lookup_addr_by_id(pm_nl_get_pernet(net), id);
if (entry) {
*flags = entry->flags;
*ifindex = entry->ifindex;
}
rcu_read_unlock();
} }
rcu_read_unlock();
return 0; return 0;
} }

View File

@ -111,9 +111,6 @@ int mptcp_userspace_pm_get_flags_and_ifindex_by_id(struct mptcp_sock *msk,
{ {
struct mptcp_pm_addr_entry *entry, *match = NULL; struct mptcp_pm_addr_entry *entry, *match = NULL;
*flags = 0;
*ifindex = 0;
spin_lock_bh(&msk->pm.lock); spin_lock_bh(&msk->pm.lock);
list_for_each_entry(entry, &msk->pm.userspace_pm_local_addr_list, list) { list_for_each_entry(entry, &msk->pm.userspace_pm_local_addr_list, list) {
if (id == entry->addr.id) { if (id == entry->addr.id) {

View File

@ -822,6 +822,8 @@ mptcp_lookup_anno_list_by_saddr(const struct mptcp_sock *msk,
int mptcp_pm_get_flags_and_ifindex_by_id(struct mptcp_sock *msk, int mptcp_pm_get_flags_and_ifindex_by_id(struct mptcp_sock *msk,
unsigned int id, unsigned int id,
u8 *flags, int *ifindex); u8 *flags, int *ifindex);
int mptcp_pm_nl_get_flags_and_ifindex_by_id(struct mptcp_sock *msk, unsigned int id,
u8 *flags, int *ifindex);
int mptcp_userspace_pm_get_flags_and_ifindex_by_id(struct mptcp_sock *msk, int mptcp_userspace_pm_get_flags_and_ifindex_by_id(struct mptcp_sock *msk,
unsigned int id, unsigned int id,
u8 *flags, int *ifindex); u8 *flags, int *ifindex);