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 fcb4033a81)
This commit is contained in:
Thomas Haller 2022-03-25 20:33:24 +01:00
parent 032757a02d
commit d361bfc945
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728

View file

@ -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) {