diff options
author | Thomas Haller <thaller@redhat.com> | 2022-03-29 17:23:52 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2022-05-03 12:18:10 +0200 |
commit | 429540a6b7f3c704af77d8605b5e2b58aaaf9c78 (patch) | |
tree | 63439af40bc2e6ef5d557a86cdfb8269cd299282 | |
parent | aa764f5fccb5366dca91dd4204f77937fc9acbb3 (diff) | |
download | NetworkManager-429540a6b7f3c704af77d8605b5e2b58aaaf9c78.tar.gz |
platform: avoid unnecessary configuration of IP address in nm_platform_ip_address_sync()
We call sync many times. Often there is nothing to update. Check the
cache first, before (re) adding it.
Note that many addresses have a limited lifetime, that is, a lifetime
that keeps counting down with seconds granularity. For those (common)
cases we will only avoid the call to kernel if there are two syncs
within less than a second.
(cherry picked from commit 528a63d9cc4da678482e05de3c41dfdfe649dcfe)
-rw-r--r-- | src/libnm-platform/nm-platform.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/libnm-platform/nm-platform.c b/src/libnm-platform/nm-platform.c index e14c81afa0..ec50bdb60a 100644 --- a/src/libnm-platform/nm-platform.c +++ b/src/libnm-platform/nm-platform.c @@ -4348,6 +4348,7 @@ next_plat:; * priority. */ for (i_know = 0; i_know < known_addresses->len; i_know++) { + const NMPObject *plat_obj; const NMPObject *known_obj; const NMPlatformIPXAddress *known_address; guint32 lifetime; @@ -4368,6 +4369,23 @@ next_plat:; &preferred); nm_assert(lifetime > 0); + plat_obj = nm_platform_ip_address_get(self, addr_family, ifindex, known_address); + if (plat_obj + && nm_platform_vtable_address.vx[IS_IPv4].address_cmp( + known_address, + NMP_OBJECT_CAST_IPX_ADDRESS(plat_obj), + NM_PLATFORM_IP_ADDRESS_CMP_TYPE_SEMANTICALLY) + == 0) { + char sbuf[sizeof(_nm_utils_to_string_buffer)]; + + /* The object is already added. Skip update. */ + _LOG3t( + "address: skip updating IPv%c address: %s", + nm_utils_addr_family_to_char(addr_family), + nmp_object_to_string(known_obj, NMP_OBJECT_TO_STRING_PUBLIC, sbuf, sizeof(sbuf))); + continue; + } + if (IS_IPv4) { if (!nm_platform_ip4_address_add( self, |