[PATCH net-next 1/3] ipv6: Add ipv6_addr_{cpu_to_be32,be32_to_cpu} helpers

Simon Horman posted 3 patches 1 month, 1 week ago
There is a newer version of this series
[PATCH net-next 1/3] ipv6: Add ipv6_addr_{cpu_to_be32,be32_to_cpu} helpers
Posted by Simon Horman 1 month, 1 week ago
Add helper to convert an ipv6 addr, expressed as an array
of words, from cpy to big-endian byte order.

No functional change intended.
Compile tested only.

Suggested-by: Andrew Lunn <andrew@lunn.ch>
Link: https://lore.kernel.org/netdev/c7684349-535c-45a4-9a74-d47479a50020@lunn.ch/
Signed-off-by: Simon Horman <horms@kernel.org>
---
 include/net/ipv6.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/include/net/ipv6.h b/include/net/ipv6.h
index 88a8e554f7a1..e7113855a10f 100644
--- a/include/net/ipv6.h
+++ b/include/net/ipv6.h
@@ -1365,4 +1365,16 @@ static inline void ip6_sock_set_recvpktinfo(struct sock *sk)
 	release_sock(sk);
 }
 
+#define IPV6_ADDR_WORDS 4
+
+static inline void ipv6_addr_cpu_to_be32(__be32 *dst, const u32 *src)
+{
+	cpu_to_be32_array(dst, src, IPV6_ADDR_WORDS);
+}
+
+static inline void ipv6_addr_be32_to_cpu(u32 *dst, const __be32 *src)
+{
+	be32_to_cpu_array(dst, src, IPV6_ADDR_WORDS);
+}
+
 #endif /* _NET_IPV6_H */

-- 
2.43.0
Re: [PATCH net-next 1/3] ipv6: Add ipv6_addr_{cpu_to_be32,be32_to_cpu} helpers
Posted by Andrew Lunn 1 month, 1 week ago
On Mon, Aug 12, 2024 at 01:11:55PM +0100, Simon Horman wrote:
> Add helper to convert an ipv6 addr, expressed as an array
> of words, from cpy to big-endian byte order.

Hi Simon

Is cpy supposed to be cpu?

Otherwise, please add: Reviewed-by: Andrew Lunn <andrew@lunn.ch>

    Andrew
Re: [PATCH net-next 1/3] ipv6: Add ipv6_addr_{cpu_to_be32,be32_to_cpu} helpers
Posted by Simon Horman 1 month, 1 week ago
On Mon, Aug 12, 2024 at 02:37:36PM +0200, Andrew Lunn wrote:
> On Mon, Aug 12, 2024 at 01:11:55PM +0100, Simon Horman wrote:
> > Add helper to convert an ipv6 addr, expressed as an array
> > of words, from cpy to big-endian byte order.
> 
> Hi Simon
> 
> Is cpy supposed to be cpu?

Yes, sorry about that.

> 
> Otherwise, please add: Reviewed-by: Andrew Lunn <andrew@lunn.ch>
> 
>     Andrew
>