lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20240813165925.12345-1-stephen@networkplumber.org>
Date: Tue, 13 Aug 2024 09:58:50 -0700
From: Stephen Hemminger <stephen@...workplumber.org>
To: netdev@...r.kernel.org
Cc: Stephen Hemminger <stephen@...workplumber.org>
Subject: [RFC iproute2] include: replace htobe64

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@...workplumber.org>
---
 include/libnetlink.h | 23 ++++++++++++++++++++++-
 include/utils.h      |  3 ---
 2 files changed, 22 insertions(+), 4 deletions(-)

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);
-- 
2.43.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ