From a2532c9db871e9d64ed47ad53a7fbd06fc2df530 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sun, 9 Jul 2023 07:10:57 +0900 Subject: [PATCH] network/address: split-out address_match_null() No functional change, preparation for later commits. --- src/network/networkd-address.c | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/src/network/networkd-address.c b/src/network/networkd-address.c index 7ddc58337ba..3345f83506b 100644 --- a/src/network/networkd-address.c +++ b/src/network/networkd-address.c @@ -587,6 +587,27 @@ static int address_drop(Address *address) { return 0; } +static bool address_match_null(const Address *a, const Address *null_address) { + assert(a); + assert(null_address); + + if (!a->requested_as_null) + return false; + + /* Currently, null address is supported only by static addresses. Note that static + * address may be set as foreign during reconfiguring the interface. */ + if (!IN_SET(a->source, NETWORK_CONFIG_SOURCE_FOREIGN, NETWORK_CONFIG_SOURCE_STATIC)) + return false; + + if (a->family != null_address->family) + return false; + + if (a->prefixlen != null_address->prefixlen) + return false; + + return true; +} + int address_get(Link *link, const Address *in, Address **ret) { Address *a; @@ -603,17 +624,7 @@ int address_get(Link *link, const Address *in, Address **ret) { /* Find matching address that originally requested as null address. */ if (address_is_static_null(in)) SET_FOREACH(a, link->addresses) { - if (!a->requested_as_null) - continue; - - /* Currently, null address is supported only by static addresses. Note that static - * address may be set as foreign during reconfiguring the interface. */ - if (!IN_SET(a->source, NETWORK_CONFIG_SOURCE_FOREIGN, NETWORK_CONFIG_SOURCE_STATIC)) - continue; - - if (a->family != in->family) - continue; - if (a->prefixlen != in->prefixlen) + if (!address_match_null(a, in)) continue; if (ret) -- 2.47.3