diff mbox series

[net-next,3/4] mptcp: unify pm get_flags_and_ifindex_by_id

Message ID 20230608-upstream-net-next-20230608-mptcp-unify-pm-interfaces-v1-3-b301717c9ff5@tessares.net (mailing list archive)
State Accepted
Commit f40be0db0b7680c2e9f0b1289788542813ba0f00
Delegated to: Netdev Maintainers
Headers show
Series mptcp: unify PM interfaces | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 13 this patch: 13
netdev/cc_maintainers success CCed 8 of 8 maintainers
netdev/build_clang success Errors and warnings before: 8 this patch: 8
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 13 this patch: 13
netdev/checkpatch warning WARNING: line length of 81 exceeds 80 columns WARNING: line length of 84 exceeds 80 columns WARNING: line length of 95 exceeds 80 columns
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Matthieu Baerts June 8, 2023, 1:20 p.m. UTC
From: Geliang Tang <geliang.tang@suse.com>

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>
---
 net/mptcp/pm.c           | 14 ++++++++++++++
 net/mptcp/pm_netlink.c   | 27 ++++++++-------------------
 net/mptcp/pm_userspace.c |  3 ---
 net/mptcp/protocol.h     |  2 ++
 4 files changed, 24 insertions(+), 22 deletions(-)

Comments

Larysa Zaremba June 9, 2023, 12:02 p.m. UTC | #1
On Thu, Jun 08, 2023 at 03:20:51PM +0200, Matthieu Baerts wrote:
> From: Geliang Tang <geliang.tang@suse.com>
> 
> 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>

> ---
>  net/mptcp/pm.c           | 14 ++++++++++++++
>  net/mptcp/pm_netlink.c   | 27 ++++++++-------------------
>  net/mptcp/pm_userspace.c |  3 ---
>  net/mptcp/protocol.h     |  2 ++
>  4 files changed, 24 insertions(+), 22 deletions(-)
> 
> diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c
> index 5a027a46196c..2d04598dde05 100644
> --- a/net/mptcp/pm.c
> +++ b/net/mptcp/pm.c
> @@ -419,6 +419,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);
>  }
>  
> +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)
>  {
>  	struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk);
> diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c
> index 315ad669eb3c..e8b32d369f11 100644
> --- a/net/mptcp/pm_netlink.c
> +++ b/net/mptcp/pm_netlink.c
> @@ -1356,31 +1356,20 @@ static int mptcp_nl_cmd_add_addr(struct sk_buff *skb, struct genl_info *info)
>  	return ret;
>  }
>  
> -int mptcp_pm_get_flags_and_ifindex_by_id(struct mptcp_sock *msk, unsigned int id,
> -					 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)
>  {
>  	struct mptcp_pm_addr_entry *entry;
>  	struct sock *sk = (struct sock *)msk;
>  	struct net *net = sock_net(sk);
>  
> -	*flags = 0;
> -	*ifindex = 0;
> -
> -	if (id) {
> -		if (mptcp_pm_is_userspace(msk))
> -			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_lock();
> +	entry = __lookup_addr_by_id(pm_nl_get_pernet(net), id);
> +	if (entry) {
> +		*flags = entry->flags;
> +		*ifindex = entry->ifindex;
>  	}
> +	rcu_read_unlock();
>  
>  	return 0;
>  }
> diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c
> index 27a275805c06..e1df3a4a4f23 100644
> --- a/net/mptcp/pm_userspace.c
> +++ b/net/mptcp/pm_userspace.c
> @@ -85,9 +85,6 @@ int mptcp_userspace_pm_get_flags_and_ifindex_by_id(struct mptcp_sock *msk,
>  {
>  	struct mptcp_pm_addr_entry *entry, *match = NULL;
>  
> -	*flags = 0;
> -	*ifindex = 0;
> -
>  	spin_lock_bh(&msk->pm.lock);
>  	list_for_each_entry(entry, &msk->pm.userspace_pm_local_addr_list, list) {
>  		if (id == entry->addr.id) {
> diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
> index 8a2e01d10582..607cbd2ccb98 100644
> --- a/net/mptcp/protocol.h
> +++ b/net/mptcp/protocol.h
> @@ -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,
>  					 unsigned int id,
>  					 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,
>  						   unsigned int id,
>  						   u8 *flags, int *ifindex);
> 
> -- 
> 2.40.1
> 
>
diff mbox series

Patch

diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c
index 5a027a46196c..2d04598dde05 100644
--- a/net/mptcp/pm.c
+++ b/net/mptcp/pm.c
@@ -419,6 +419,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);
 }
 
+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)
 {
 	struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk);
diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c
index 315ad669eb3c..e8b32d369f11 100644
--- a/net/mptcp/pm_netlink.c
+++ b/net/mptcp/pm_netlink.c
@@ -1356,31 +1356,20 @@  static int mptcp_nl_cmd_add_addr(struct sk_buff *skb, struct genl_info *info)
 	return ret;
 }
 
-int mptcp_pm_get_flags_and_ifindex_by_id(struct mptcp_sock *msk, unsigned int id,
-					 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)
 {
 	struct mptcp_pm_addr_entry *entry;
 	struct sock *sk = (struct sock *)msk;
 	struct net *net = sock_net(sk);
 
-	*flags = 0;
-	*ifindex = 0;
-
-	if (id) {
-		if (mptcp_pm_is_userspace(msk))
-			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_lock();
+	entry = __lookup_addr_by_id(pm_nl_get_pernet(net), id);
+	if (entry) {
+		*flags = entry->flags;
+		*ifindex = entry->ifindex;
 	}
+	rcu_read_unlock();
 
 	return 0;
 }
diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c
index 27a275805c06..e1df3a4a4f23 100644
--- a/net/mptcp/pm_userspace.c
+++ b/net/mptcp/pm_userspace.c
@@ -85,9 +85,6 @@  int mptcp_userspace_pm_get_flags_and_ifindex_by_id(struct mptcp_sock *msk,
 {
 	struct mptcp_pm_addr_entry *entry, *match = NULL;
 
-	*flags = 0;
-	*ifindex = 0;
-
 	spin_lock_bh(&msk->pm.lock);
 	list_for_each_entry(entry, &msk->pm.userspace_pm_local_addr_list, list) {
 		if (id == entry->addr.id) {
diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
index 8a2e01d10582..607cbd2ccb98 100644
--- a/net/mptcp/protocol.h
+++ b/net/mptcp/protocol.h
@@ -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,
 					 unsigned int id,
 					 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,
 						   unsigned int id,
 						   u8 *flags, int *ifindex);