summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2021-12-12 02:30:27 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2021-12-16 22:43:18 +0900
commita71c5c44f73553e1af6c10645fa3b5ca0a12f87a (patch)
treeb1cf9d0e43146e69c87c96443d39f666133ee4f5 /src
parent9e86dba94b4e6d13f2bd621f2017c5b0628800f7 (diff)
downloadsystemd-a71c5c44f73553e1af6c10645fa3b5ca0a12f87a.tar.gz
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.
Diffstat (limited to 'src')
-rw-r--r--src/network/networkd-address.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/network/networkd-address.c b/src/network/networkd-address.c
index c4a666a908..603882bd45 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);