diff options
Diffstat (limited to 'src/network/networkd-address.c')
-rw-r--r-- | src/network/networkd-address.c | 50 |
1 files changed, 28 insertions, 22 deletions
diff --git a/src/network/networkd-address.c b/src/network/networkd-address.c index c33ffa9576..3345f83506 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) @@ -1246,13 +1257,11 @@ static int address_process_request(Request *req, Link *link, Address *address) { int link_request_address( Link *link, - Address *address, - bool consume_object, + const Address *address, unsigned *message_counter, address_netlink_handler_t netlink_handler, Request **ret) { - _unused_ _cleanup_(address_freep) Address *address_will_be_freed = NULL; Address *existing; int r; @@ -1260,9 +1269,6 @@ int link_request_address( assert(address); assert(address->source != NETWORK_CONFIG_SOURCE_FOREIGN); - if (consume_object) - address_will_be_freed = address; - if (address_get(link, address, &existing) < 0) { _cleanup_(address_freep) Address *tmp = NULL; @@ -1341,12 +1347,12 @@ static int static_address_handler(sd_netlink *rtnl, sd_netlink_message *m, Reque return 1; } -int link_request_static_address(Link *link, Address *address, bool consume) { +int link_request_static_address(Link *link, const Address *address) { assert(link); assert(address); assert(address->source == NETWORK_CONFIG_SOURCE_STATIC); - return link_request_address(link, address, consume, &link->static_address_messages, + return link_request_address(link, address, &link->static_address_messages, static_address_handler, NULL); } @@ -1360,7 +1366,7 @@ int link_request_static_addresses(Link *link) { link->static_addresses_configured = false; ORDERED_HASHMAP_FOREACH(a, link->network->addresses_by_section) { - r = link_request_static_address(link, a, false); + r = link_request_static_address(link, a); if (r < 0) return r; } @@ -1408,7 +1414,7 @@ void address_cancel_request(Address *address) { int manager_rtnl_process_address(sd_netlink *rtnl, sd_netlink_message *message, Manager *m) { _cleanup_(address_freep) Address *tmp = NULL; struct ifa_cacheinfo cinfo; - Link *link = NULL; + Link *link; uint16_t type; Address *address = NULL; int ifindex, r; @@ -1444,7 +1450,7 @@ int manager_rtnl_process_address(sd_netlink *rtnl, sd_netlink_message *message, } r = link_get_by_index(m, ifindex, &link); - if (r < 0 || !link) { + if (r < 0) { /* when enumerating we might be out of sync, but we will get the address again, so just * ignore it */ if (!m->enumerating) |