summaryrefslogtreecommitdiffstats
path: root/src/network
diff options
context:
space:
mode:
authorLuca Boccassi <bluca@debian.org>2023-07-30 15:01:53 +0200
committerGitHub <noreply@github.com>2023-07-30 15:01:53 +0200
commit1665bbbddfdfda77a84c23d7f04a4ce9d2c6bdc9 (patch)
treef12d4ea3f3d765ecebfa31fec314863be01f8fd1 /src/network
parentnetwork/neighbor: drop IPv6 settings when the kernel does not support IPv6 (diff)
parentnetwork/address: split-out address_match_null() (diff)
downloadsystemd-1665bbbddfdfda77a84c23d7f04a4ce9d2c6bdc9.tar.xz
systemd-1665bbbddfdfda77a84c23d7f04a4ce9d2c6bdc9.zip
Merge pull request #28571 from yuwata/network-address-next-part1
network: several trivial cleanups
Diffstat (limited to 'src/network')
-rw-r--r--src/network/networkd-address.c50
-rw-r--r--src/network/networkd-address.h5
-rw-r--r--src/network/networkd-dhcp-prefix-delegation.c6
-rw-r--r--src/network/networkd-dhcp-server.c2
-rw-r--r--src/network/networkd-dhcp4.c6
-rw-r--r--src/network/networkd-dhcp6.c6
-rw-r--r--src/network/networkd-ipv4ll.c2
-rw-r--r--src/network/networkd-ndisc.c2
-rw-r--r--src/network/networkd-neighbor.c2
-rw-r--r--src/network/networkd-nexthop.c2
-rw-r--r--src/network/networkd-radv.c2
-rw-r--r--src/network/networkd-route.c2
12 files changed, 43 insertions, 44 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)
diff --git a/src/network/networkd-address.h b/src/network/networkd-address.h
index 766da8ee75..5cb1cc388e 100644
--- a/src/network/networkd-address.h
+++ b/src/network/networkd-address.h
@@ -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);
diff --git a/src/network/networkd-dhcp-prefix-delegation.c b/src/network/networkd-dhcp-prefix-delegation.c
index 66c5e979d9..8d50da042c 100644
--- a/src/network/networkd-dhcp-prefix-delegation.c
+++ b/src/network/networkd-dhcp-prefix-delegation.c
@@ -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");
diff --git a/src/network/networkd-dhcp-server.c b/src/network/networkd-dhcp-server.c
index 620fbbddc7..50d84893c6 100644
--- a/src/network/networkd-dhcp-server.c
+++ b/src/network/networkd-dhcp-server.c
@@ -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) {
diff --git a/src/network/networkd-dhcp4.c b/src/network/networkd-dhcp4.c
index fd8ef402bd..eeb3585f29 100644
--- a/src/network/networkd-dhcp4.c
+++ b/src/network/networkd-dhcp4.c
@@ -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");
diff --git a/src/network/networkd-dhcp6.c b/src/network/networkd-dhcp6.c
index 57272e7bf6..755957f5b1 100644
--- a/src/network/networkd-dhcp6.c
+++ b/src/network/networkd-dhcp6.c
@@ -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",
diff --git a/src/network/networkd-ipv4ll.c b/src/network/networkd-ipv4ll.c
index 8450b346b1..ee78fffdfb 100644
--- a/src/network/networkd-ipv4ll.c
+++ b/src/network/networkd-ipv4ll.c
@@ -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) {
diff --git a/src/network/networkd-ndisc.c b/src/network/networkd-ndisc.c
index 8e6389d202..972ba52b9e 100644
--- a/src/network/networkd-ndisc.c
+++ b/src/network/networkd-ndisc.c
@@ -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;
diff --git a/src/network/networkd-neighbor.c b/src/network/networkd-neighbor.c
index d7d53de376..c1629ae3e9 100644
--- a/src/network/networkd-neighbor.c
+++ b/src/network/networkd-neighbor.c
@@ -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);
diff --git a/src/network/networkd-nexthop.c b/src/network/networkd-nexthop.c
index 42b48198af..2af65ec260 100644
--- a/src/network/networkd-nexthop.c
+++ b/src/network/networkd-nexthop.c
@@ -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;
diff --git a/src/network/networkd-radv.c b/src/network/networkd-radv.c
index db1ecb4c97..0f67ff0973 100644
--- a/src/network/networkd-radv.c
+++ b/src/network/networkd-radv.c
@@ -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;
}
diff --git a/src/network/networkd-route.c b/src/network/networkd-route.c
index 44dc63b642..283d515b81 100644
--- a/src/network/networkd-route.c
+++ b/src/network/networkd-route.c
@@ -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)