Merge pull request #28571 from yuwata/network-address-next-part1

network: several trivial cleanups
This commit is contained in:
Luca Boccassi
2023-07-30 14:01:53 +01:00
committed by GitHub
12 changed files with 43 additions and 44 deletions
+28 -22
View File
@@ -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)
+2 -3
View File
@@ -107,12 +107,11 @@ bool manager_has_address(Manager *manager, int family, const union in_addr_union
void address_cancel_request(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);
int link_request_static_address(Link *link, Address *address, bool consume);
int link_request_static_address(Link *link, const Address *address);
int link_request_static_addresses(Link *link);
int manager_rtnl_process_address(sd_netlink *nl, sd_netlink_message *message, Manager *m);
@@ -216,11 +216,9 @@ int dhcp_pd_remove(Link *link, bool only_marked) {
link_remove_dhcp_pd_subnet_prefix(link, &prefix);
k = address_remove(address);
k = address_remove_and_drop(address);
if (k < 0)
r = k;
address_cancel_request(address);
}
}
@@ -421,7 +419,7 @@ static int dhcp_pd_request_address(
else
address_unmark(existing);
r = link_request_address(link, TAKE_PTR(address), true, &link->dhcp_pd_messages,
r = link_request_address(link, address, &link->dhcp_pd_messages,
dhcp_pd_address_handler, NULL);
if (r < 0)
return log_link_error_errno(link, r, "Failed to request DHCP delegated prefix address: %m");
+1 -1
View File
@@ -115,7 +115,7 @@ int link_request_dhcp_server_address(Link *link) {
* Configure the DHCP server address only when it is not. */
return 0;
return link_request_static_address(link, TAKE_PTR(address), true);
return link_request_static_address(link, address);
}
static int link_find_dhcp_server_address(Link *link, Address **ret) {
+2 -4
View File
@@ -258,11 +258,9 @@ static int dhcp4_remove_address_and_routes(Link *link, bool only_marked) {
if (only_marked && !address_is_marked(address))
continue;
k = address_remove(address);
k = address_remove_and_drop(address);
if (k < 0)
r = k;
address_cancel_request(address);
}
return r;
@@ -984,7 +982,7 @@ static int dhcp4_request_address(Link *link, bool announce) {
else
address_unmark(existing);
r = link_request_address(link, TAKE_PTR(addr), true, &link->dhcp4_messages,
r = link_request_address(link, addr, &link->dhcp4_messages,
dhcp4_address_handler, NULL);
if (r < 0)
return log_link_error_errno(link, r, "Failed to request DHCPv4 address: %m");
+2 -4
View File
@@ -72,11 +72,9 @@ static int dhcp6_remove(Link *link, bool only_marked) {
if (only_marked && !address_is_marked(address))
continue;
k = address_remove(address);
k = address_remove_and_drop(address);
if (k < 0)
r = k;
address_cancel_request(address);
}
return r;
@@ -232,7 +230,7 @@ static int dhcp6_request_address(
else
address_unmark(existing);
r = link_request_address(link, TAKE_PTR(addr), true, &link->dhcp6_messages,
r = link_request_address(link, addr, &link->dhcp6_messages,
dhcp6_address_handler, NULL);
if (r < 0)
return log_link_error_errno(link, r, "Failed to request DHCPv6 address %s/128: %m",
+1 -1
View File
@@ -120,7 +120,7 @@ static int ipv4ll_address_claimed(sd_ipv4ll *ll, Link *link) {
log_link_debug(link, "IPv4 link-local claim "IPV4_ADDRESS_FMT_STR,
IPV4_ADDRESS_FMT_VAL(address->in_addr.in));
return link_request_address(link, TAKE_PTR(address), true, NULL, ipv4ll_address_handler, NULL);
return link_request_address(link, address, NULL, ipv4ll_address_handler, NULL);
}
static void ipv4ll_handler(sd_ipv4ll *ll, int event, void *userdata) {
+1 -1
View File
@@ -250,7 +250,7 @@ static int ndisc_request_address(Address *in, Link *link, sd_ndisc_router *rt) {
is_new = address_get(link, address, NULL) < 0;
r = link_request_address(link, TAKE_PTR(address), true, &link->ndisc_messages,
r = link_request_address(link, address, &link->ndisc_messages,
ndisc_address_handler, NULL);
if (r < 0)
return r;
+1 -1
View File
@@ -480,7 +480,7 @@ int manager_rtnl_process_neighbor(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 neighbor again. Also,
* kernel sends messages about neighbors after a link is removed. So, just ignore it. */
log_debug("rtnl: received neighbor for link '%d' we don't know about, ignoring.", ifindex);
+1 -1
View File
@@ -835,7 +835,7 @@ int manager_rtnl_process_nexthop(sd_netlink *rtnl, sd_netlink_message *message,
}
r = link_get_by_index(m, ifindex, &link);
if (r < 0 || !link) {
if (r < 0) {
if (!m->enumerating)
log_warning("rtnl: received nexthop message for link (%"PRIu32") we do not know about, ignoring", ifindex);
return 0;
+1 -1
View File
@@ -214,7 +214,7 @@ int link_request_radv_addresses(Link *link) {
address->prefixlen = p->prefixlen;
address->route_metric = p->route_metric;
r = link_request_static_address(link, TAKE_PTR(address), true);
r = link_request_static_address(link, address);
if (r < 0)
return r;
}
+1 -1
View File
@@ -1719,7 +1719,7 @@ int manager_rtnl_process_route(sd_netlink *rtnl, sd_netlink_message *message, Ma
}
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 route again, so just ignore it */
if (!m->enumerating)