From f81360bbbf973884b684d8bb9f46aeec128ba5b7 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 6 Aug 2020 17:45:20 +0200 Subject: [PATCH] platform: add nm_platform_ip4_address_addr_to_hash() helper This will only have one particular use, from NNL3Cfg. However, it seems general enough to place it in "nm-platform.h". --- src/platform/nm-platform.c | 36 ++++++++++++++++++++++++++++++++++++ src/platform/nm-platform.h | 3 +++ 2 files changed, 39 insertions(+) diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c index b3371ed96d..b8302fea95 100644 --- a/src/platform/nm-platform.c +++ b/src/platform/nm-platform.c @@ -8149,6 +8149,42 @@ nm_platform_ip_address_cmp_expiry (const NMPlatformIPAddress *a, const NMPlatfor return ta < tb ? -1 : 1; } +/*****************************************************************************/ + +GHashTable * +nm_platform_ip4_address_addr_to_hash (NMPlatform *self, + int ifindex) +{ + const NMDedupMultiHeadEntry *head_entry; + NMDedupMultiIter iter; + const NMPObject *obj; + NMPLookup lookup; + GHashTable *hash; + + g_return_val_if_fail (NM_IS_PLATFORM (self), NULL); + g_return_val_if_fail (ifindex > 0, NULL); + + nmp_lookup_init_object (&lookup, NMP_OBJECT_TYPE_IP4_ADDRESS, ifindex); + + head_entry = nmp_cache_lookup (NM_PLATFORM_GET_PRIVATE (self)->cache, + &lookup); + + if (!head_entry) + return NULL; + + hash = g_hash_table_new (nm_direct_hash, NULL); + + nmp_cache_iter_for_each (&iter, head_entry, &obj) { + const NMPlatformIP4Address *a = NMP_OBJECT_CAST_IP4_ADDRESS (obj); + + g_hash_table_add (hash, GUINT_TO_POINTER (a->address)); + } + + return hash; +} + +/*****************************************************************************/ + const char * nm_platform_signal_change_type_to_string (NMPlatformSignalChangeType change_type) { diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h index e946709abb..cece00dfe9 100644 --- a/src/platform/nm-platform.h +++ b/src/platform/nm-platform.h @@ -2038,6 +2038,9 @@ int nm_platform_ip6_address_pretty_sort_cmp (const NMPlatformIP6Address *a1, const NMPlatformIP6Address *a2, gboolean prefer_temp); +GHashTable *nm_platform_ip4_address_addr_to_hash (NMPlatform *self, + int ifindex); + int nm_platform_ip4_route_cmp (const NMPlatformIP4Route *a, const NMPlatformIP4Route *b, NMPlatformIPRouteCmpType cmp_type); int nm_platform_ip6_route_cmp (const NMPlatformIP6Route *a, const NMPlatformIP6Route *b, NMPlatformIPRouteCmpType cmp_type);