diff mbox series

[for-6.11,07/29] sunrpc: add and export rpc_ntop6_addr_noscopeid

Message ID 20240607142646.20924-8-snitzer@kernel.org (mailing list archive)
State New
Headers show
Series nfs/nfsd: add support for localio bypass | expand

Commit Message

Mike Snitzer June 7, 2024, 2:26 p.m. UTC
From: Peng Tao <tao.peng@primarydata.com>

Signed-off-by: Peng Tao <tao.peng@primarydata.com>
Signed-off-by: Lance Shelton <lance.shelton@hammerspace.com>
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
Signed-off-by: Mike Snitzer <snitzer@kernel.org>
---
 include/linux/sunrpc/addr.h |  9 +++++++++
 net/sunrpc/addr.c           | 19 +++++++++++++------
 2 files changed, 22 insertions(+), 6 deletions(-)

Comments

Jeff Layton June 9, 2024, 12:36 p.m. UTC | #1
On Fri, 2024-06-07 at 10:26 -0400, Mike Snitzer wrote:
> From: Peng Tao <tao.peng@primarydata.com>
> 

Still looking over the set, but this could use some justification.

> Signed-off-by: Peng Tao <tao.peng@primarydata.com>
> Signed-off-by: Lance Shelton <lance.shelton@hammerspace.com>
> Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
> Signed-off-by: Mike Snitzer <snitzer@kernel.org>
> ---
>  include/linux/sunrpc/addr.h |  9 +++++++++
>  net/sunrpc/addr.c           | 19 +++++++++++++------
>  2 files changed, 22 insertions(+), 6 deletions(-)
> 
> diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
> index 07d454873b6d..e1007bddc3c4 100644
> --- a/include/linux/sunrpc/addr.h
> +++ b/include/linux/sunrpc/addr.h
> @@ -68,6 +68,9 @@ static inline bool __rpc_copy_addr4(struct sockaddr *dst,
>  }
>  
>  #if IS_ENABLED(CONFIG_IPV6)
> +extern size_t rpc_ntop6_addr_noscopeid(const struct in6_addr *addr,
> +				       char *buf, const int buflen);
> +
>  static inline bool rpc_cmp_addr6(const struct sockaddr *sap1,
>  				 const struct sockaddr *sap2)
>  {
> @@ -94,6 +97,12 @@ static inline bool __rpc_copy_addr6(struct sockaddr *dst,
>  	return true;
>  }
>  #else	/* !(IS_ENABLED(CONFIG_IPV6) */
> +static size_t rpc_ntop6_addr_noscopeid(const struct in6_addr *addr,
> +				       char *buf, const int buflen)
> +{
> +	return 0;
> +}
> +
>  static inline bool rpc_cmp_addr6(const struct sockaddr *sap1,
>  				   const struct sockaddr *sap2)
>  {
> diff --git a/net/sunrpc/addr.c b/net/sunrpc/addr.c
> index 97ff11973c49..78a123a7c39b 100644
> --- a/net/sunrpc/addr.c
> +++ b/net/sunrpc/addr.c
> @@ -25,12 +25,9 @@
>  
>  #if IS_ENABLED(CONFIG_IPV6)
>  
> -static size_t rpc_ntop6_noscopeid(const struct sockaddr *sap,
> -				  char *buf, const int buflen)
> +size_t rpc_ntop6_addr_noscopeid(const struct in6_addr *addr,
> +				char *buf, const int buflen)
>  {
> -	const struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
> -	const struct in6_addr *addr = &sin6->sin6_addr;
> -
>  	/*
>  	 * RFC 4291, Section 2.2.2
>  	 *
> @@ -55,13 +52,23 @@ static size_t rpc_ntop6_noscopeid(const struct sockaddr *sap,
>  	 */
>  	if (ipv6_addr_v4mapped(addr))
>  		return snprintf(buf, buflen, "::ffff:%pI4",
> -					&addr->s6_addr32[3]);
> +				&addr->s6_addr32[3]);
>  
>  	/*
>  	 * RFC 4291, Section 2.2.1
>  	 */
>  	return snprintf(buf, buflen, "%pI6c", addr);
>  }
> +EXPORT_SYMBOL_GPL(rpc_ntop6_addr_noscopeid);
> +
> +static size_t rpc_ntop6_noscopeid(const struct sockaddr *sap,
> +				  char *buf, const int buflen)
> +{
> +	const struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
> +	const struct in6_addr *addr = &sin6->sin6_addr;
> +
> +	return rpc_ntop6_addr_noscopeid(addr, buf, buflen);
> +}
>  
>  static size_t rpc_ntop6(const struct sockaddr *sap,
>  			char *buf, const size_t buflen)
Mike Snitzer June 10, 2024, 4:33 p.m. UTC | #2
On Sun, Jun 09, 2024 at 08:36:40AM -0400, Jeff Layton wrote:
> On Fri, 2024-06-07 at 10:26 -0400, Mike Snitzer wrote:
> > From: Peng Tao <tao.peng@primarydata.com>
> > 
> 
> Still looking over the set, but this could use some justification.

OK, note that it gets reverted by patch 20.  It was introduced for the
benefit of sockadd based matching of "local" network interfaces.
diff mbox series

Patch

diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
index 07d454873b6d..e1007bddc3c4 100644
--- a/include/linux/sunrpc/addr.h
+++ b/include/linux/sunrpc/addr.h
@@ -68,6 +68,9 @@  static inline bool __rpc_copy_addr4(struct sockaddr *dst,
 }
 
 #if IS_ENABLED(CONFIG_IPV6)
+extern size_t rpc_ntop6_addr_noscopeid(const struct in6_addr *addr,
+				       char *buf, const int buflen);
+
 static inline bool rpc_cmp_addr6(const struct sockaddr *sap1,
 				 const struct sockaddr *sap2)
 {
@@ -94,6 +97,12 @@  static inline bool __rpc_copy_addr6(struct sockaddr *dst,
 	return true;
 }
 #else	/* !(IS_ENABLED(CONFIG_IPV6) */
+static size_t rpc_ntop6_addr_noscopeid(const struct in6_addr *addr,
+				       char *buf, const int buflen)
+{
+	return 0;
+}
+
 static inline bool rpc_cmp_addr6(const struct sockaddr *sap1,
 				   const struct sockaddr *sap2)
 {
diff --git a/net/sunrpc/addr.c b/net/sunrpc/addr.c
index 97ff11973c49..78a123a7c39b 100644
--- a/net/sunrpc/addr.c
+++ b/net/sunrpc/addr.c
@@ -25,12 +25,9 @@ 
 
 #if IS_ENABLED(CONFIG_IPV6)
 
-static size_t rpc_ntop6_noscopeid(const struct sockaddr *sap,
-				  char *buf, const int buflen)
+size_t rpc_ntop6_addr_noscopeid(const struct in6_addr *addr,
+				char *buf, const int buflen)
 {
-	const struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
-	const struct in6_addr *addr = &sin6->sin6_addr;
-
 	/*
 	 * RFC 4291, Section 2.2.2
 	 *
@@ -55,13 +52,23 @@  static size_t rpc_ntop6_noscopeid(const struct sockaddr *sap,
 	 */
 	if (ipv6_addr_v4mapped(addr))
 		return snprintf(buf, buflen, "::ffff:%pI4",
-					&addr->s6_addr32[3]);
+				&addr->s6_addr32[3]);
 
 	/*
 	 * RFC 4291, Section 2.2.1
 	 */
 	return snprintf(buf, buflen, "%pI6c", addr);
 }
+EXPORT_SYMBOL_GPL(rpc_ntop6_addr_noscopeid);
+
+static size_t rpc_ntop6_noscopeid(const struct sockaddr *sap,
+				  char *buf, const int buflen)
+{
+	const struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
+	const struct in6_addr *addr = &sin6->sin6_addr;
+
+	return rpc_ntop6_addr_noscopeid(addr, buf, buflen);
+}
 
 static size_t rpc_ntop6(const struct sockaddr *sap,
 			char *buf, const size_t buflen)