From: Yu Watanabe Date: Sat, 11 Dec 2021 17:30:27 +0000 (+0900) Subject: network: address: minor optimization for link_drop_foreign_addresses() X-Git-Tag: v250-rc3~33^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a71c5c44f73553e1af6c10645fa3b5ca0a12f87a;p=thirdparty%2Fsystemd.git network: address: minor optimization for link_drop_foreign_addresses() link_address_is_dynamic() is costful in general. Call it only when KeepConfiguration= is set. Note, it is not necessary to check link->network in the loop, as we have the assertion for that in the beginning of the function. --- diff --git a/src/network/networkd-address.c b/src/network/networkd-address.c index c4a666a908c..603882bd454 100644 --- a/src/network/networkd-address.c +++ b/src/network/networkd-address.c @@ -840,6 +840,10 @@ int link_drop_foreign_addresses(Link *link) { assert(link); assert(link->network); + /* Keep all addresses when KeepConfiguration=yes. */ + if (link->network->keep_configuration == KEEP_CONFIGURATION_YES) + return 0; + /* First, mark all addresses. */ SET_FOREACH(address, link->addresses) { /* We consider IPv6LL addresses to be managed by the kernel, or dropped in link_drop_ipv6ll_addresses() */ @@ -854,10 +858,9 @@ int link_drop_foreign_addresses(Link *link) { if (!address_exists(address)) continue; - if (link_address_is_dynamic(link, address)) { - if (link->network && FLAGS_SET(link->network->keep_configuration, KEEP_CONFIGURATION_DHCP)) - continue; - } else if (link->network && FLAGS_SET(link->network->keep_configuration, KEEP_CONFIGURATION_STATIC)) + /* link_address_is_dynamic() is slightly heavy. Let's call the function only when KeepConfiguration= is set. */ + if (IN_SET(link->network->keep_configuration, KEEP_CONFIGURATION_DHCP, KEEP_CONFIGURATION_STATIC) && + link_address_is_dynamic(link, address) == (link->network->keep_configuration == KEEP_CONFIGURATION_DHCP)) continue; address_mark(address);