diff mbox series

[RFC,iproute2] include: replace htobe64

Message ID 20240813165925.12345-1-stephen@networkplumber.org (mailing list archive)
State RFC
Delegated to: David Ahern
Headers show
Series [RFC,iproute2] include: replace htobe64 | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch

Commit Message

Stephen Hemminger Aug. 13, 2024, 4:58 p.m. UTC
The PDCP code introduced rte_getattr_be64 and that introduced
a dependency on htobe64. But iproute2 already hadn htonll macro.

Move the macro into an inline function in libnetlink.h

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 include/libnetlink.h | 23 ++++++++++++++++++++++-
 include/utils.h      |  3 ---
 2 files changed, 22 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/include/libnetlink.h b/include/libnetlink.h
index 30f0c2d2..b0e3be3a 100644
--- a/include/libnetlink.h
+++ b/include/libnetlink.h
@@ -13,6 +13,27 @@ 
 #include <linux/netconf.h>
 #include <arpa/inet.h>
 
+static inline uint64_t
+htonll(uint64_t x)
+{
+	if (1 == htonl(1)) /* is this a big endian cpu? */
+		return x;
+	else
+		return ((uint64_t)htonl(x & 0xFFFFFFFF) << 32) |
+			(htonl(x >> 32));
+}
+
+static inline uint64_t
+ntohll(uint64_t x)
+{
+	if (1 == ntohl(1)) /* is this a big endian cpu? */
+		return x;
+	else
+		return ((uint64_t)ntohl(x & 0xFFFFFFFF) << 32) |
+			(ntohl(x >> 32));
+}
+
+
 struct rtnl_handle {
 	int			fd;
 	struct sockaddr_nl	local;
@@ -277,7 +298,7 @@  static inline __u64 rta_getattr_uint(const struct rtattr *rta)
 
 static inline __be64 rta_getattr_be64(const struct rtattr *rta)
 {
-	return htobe64(rta_getattr_u64(rta));
+	return htonll(rta_getattr_u64(rta));
 }
 
 static inline __s32 rta_getattr_s32(const struct rtattr *rta)
diff --git a/include/utils.h b/include/utils.h
index a2a98b9b..59bfd294 100644
--- a/include/utils.h
+++ b/include/utils.h
@@ -303,9 +303,6 @@  unsigned int print_name_and_link(const char *fmt,
 #define _textify(x)	#x
 #define textify(x)	_textify(x)
 
-#define htonll(x) ((1==htonl(1)) ? (x) : ((uint64_t)htonl((x) & 0xFFFFFFFF) << 32) | htonl((x) >> 32))
-#define ntohll(x) ((1==ntohl(1)) ? (x) : ((uint64_t)ntohl((x) & 0xFFFFFFFF) << 32) | ntohl((x) >> 32))
-
 extern int cmdlineno;
 
 char *int_to_str(int val, char *buf);