From d361bfc945a4a7db3d4f2c845660e9f1e5c5d828 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 25 Mar 2022 20:33:24 +0100 Subject: [PATCH] platform: add logging statements to nm_platform_ip_address_sync() for printf() debugging The code is disabled at compile time. It's only useful for printf debugging to modify the source to get more logging. (cherry picked from commit fcb4033a81a12c53d5f31ad1a435bc791c03a603) --- src/libnm-platform/nm-platform.c | 53 ++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/src/libnm-platform/nm-platform.c b/src/libnm-platform/nm-platform.c index 575cdc801e..785a5e2370 100644 --- a/src/libnm-platform/nm-platform.c +++ b/src/libnm-platform/nm-platform.c @@ -3988,6 +3988,7 @@ nm_platform_ip_address_sync(NMPlatform *self, gint32 now = 0; const int IS_IPv4 = NM_IS_IPv4(addr_family); NMPLookup lookup; + const gboolean EXTRA_LOGGING = FALSE; gs_unref_hashtable GHashTable *known_addresses_idx = NULL; gs_unref_ptrarray GPtrArray *plat_addresses = NULL; gboolean success; @@ -3998,6 +3999,39 @@ nm_platform_ip_address_sync(NMPlatform *self, _CHECK_SELF(self, klass, FALSE); + /* Disabled. Enable this for printf debugging. */ + if (EXTRA_LOGGING) { + char sbuf[sizeof(_nm_utils_to_string_buffer)]; + char sbuf1[50]; + + _LOG3T("IPv%c address sync on %d (%u addresses, %u to prune)", + nm_utils_addr_family_to_char(addr_family), + ifindex, + nm_g_ptr_array_len(known_addresses), + nm_g_ptr_array_len(addresses_prune)); + for (i = 0; known_addresses && i < known_addresses->len; i++) { + _LOG3T(" address#%u: %s%s", + i, + nmp_object_to_string(known_addresses->pdata[i], + NMP_OBJECT_TO_STRING_ALL, + sbuf, + sizeof(sbuf)), + IS_IPv4 ? "" + : nm_sprintf_buf(sbuf1, + " (scope %d)", + (int) ip6_address_scope(NMP_OBJECT_CAST_IP6_ADDRESS( + known_addresses->pdata[i])))); + } + for (i = 0; addresses_prune && i < addresses_prune->len; i++) { + _LOG3T(" prune #%u: %s", + i, + nmp_object_to_string(addresses_prune->pdata[i], + NMP_OBJECT_TO_STRING_ALL, + sbuf, + sizeof(sbuf))); + } + } + /* @known_addresses (IPv4) are in decreasing priority order (highest priority addresses first). * @known_addresses (IPv6) are in increasing priority order (highest priority addresses last) (we will sort them by scope next). */ @@ -4048,6 +4082,25 @@ nm_platform_ip_address_sync(NMPlatform *self, NULL, NULL); + if (EXTRA_LOGGING && plat_addresses) { + for (i = 0; i < plat_addresses->len; i++) { + char sbuf[sizeof(_nm_utils_to_string_buffer)]; + char sbuf1[50]; + + _LOG3T(" platform#%u: %s%s", + i, + nmp_object_to_string(plat_addresses->pdata[i], + NMP_OBJECT_TO_STRING_ALL, + sbuf, + sizeof(sbuf)), + IS_IPv4 ? "" + : nm_sprintf_buf(sbuf1, + " (scope %d)", + (int) ip6_address_scope(NMP_OBJECT_CAST_IP6_ADDRESS( + plat_addresses->pdata[i])))); + } + } + if (nm_g_ptr_array_len(plat_addresses) > 0) { /* Delete addresses that interfere with our intended order. */ if (IS_IPv4) {