summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2023-03-09 11:07:05 +0100
committerThomas Haller <thaller@redhat.com>2023-03-21 15:58:36 +0100
commit9b48c7f3735a034a93b1734242ebd58b622766bb (patch)
treeef9d8e0f9ebe814e76ffee4e0c92b47db3757d5a
parent953055331117bf5cc0edca464d3038ba38b7fe28 (diff)
glib-aux: optimize nm_ip_addr_is_null()
The nm_ip_addr_*() APIs are supposed to work with unaligned input, so we could use them while parsing binary data (where the field may not be properly aligned). For that reason, it used to first copy the argument to a local (properly aligned) variable. Rework that a bit, and use unaligned_read_ne32() for IPv4.
-rw-r--r--src/libnm-glib-aux/nm-inet-utils.h11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/libnm-glib-aux/nm-inet-utils.h b/src/libnm-glib-aux/nm-inet-utils.h
index 572a80c2b1..087a8af179 100644
--- a/src/libnm-glib-aux/nm-inet-utils.h
+++ b/src/libnm-glib-aux/nm-inet-utils.h
@@ -3,6 +3,8 @@
#ifndef __NM_INET_UTILS_H__
#define __NM_INET_UTILS_H__
+#include "libnm-std-aux/unaligned-fundamental.h"
+
typedef union _NMIPAddr {
guint8 addr_ptr[sizeof(struct in6_addr)];
in_addr_t addr4;
@@ -90,14 +92,15 @@ nm_ip_addr_set(int addr_family, gpointer dst, gconstpointer src)
static inline gboolean
nm_ip_addr_is_null(int addr_family, gconstpointer addr)
{
- NMIPAddr a;
+ struct in6_addr a6;
- nm_ip_addr_set(addr_family, &a, addr);
+ nm_assert(addr);
if (NM_IS_IPv4(addr_family))
- return a.addr4 == 0;
+ return unaligned_read_ne32(addr) == 0;
- return IN6_IS_ADDR_UNSPECIFIED(&a.addr6);
+ memcpy(&a6, addr, sizeof(struct in6_addr));
+ return IN6_IS_ADDR_UNSPECIFIED(&a6);
}
static inline NMIPAddr