networkd-manager: Fix route removals on shutdown
In order to shut down networkd properly, the delegated routes added need to be removed properly, and as error reporting is wanted, the network link is needed in the debug output. Solve this by calling manager_dhcp6_prefix_remove_all(), which will remove each prefix stored in the Manager structure, and while doing that reference each link so that it isn't freed before the route removal callback is called. This in turn causes the network link to be referenced once more, and an explicit hashmap_remove() must be called to remove the network link from the m->links hashmap. Also, since the registered callback is not called when the DHCPv6 client is stopped with sd_dhcp6_client_stop(), an explicit call to dhcp6_lease_pd_prefix_lost() needs to be made to clean up any unreachable routes set up for the delegated prefixes.
This commit is contained in:
parent
e1d737ef9d
commit
65dd5e3105
|
@ -117,7 +117,7 @@ static int dhcp6_route_remove_cb(sd_netlink *nl, sd_netlink_message *m,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int dhcp6_lease_pd_prefix_lost(sd_dhcp6_client *client, Link* link) {
|
||||
int dhcp6_lease_pd_prefix_lost(sd_dhcp6_client *client, Link* link) {
|
||||
int r;
|
||||
sd_dhcp6_lease *lease;
|
||||
union in_addr_union pd_prefix;
|
||||
|
|
|
@ -165,6 +165,7 @@ int dhcp4_set_client_identifier(Link *link);
|
|||
int dhcp4_set_promote_secondaries(Link *link);
|
||||
int dhcp6_configure(Link *link);
|
||||
int dhcp6_request_address(Link *link, int ir);
|
||||
int dhcp6_lease_pd_prefix_lost(sd_dhcp6_client *client, Link* link);
|
||||
|
||||
const char* link_state_to_string(LinkState s) _const_;
|
||||
LinkState link_state_from_string(const char *s) _pure_;
|
||||
|
|
|
@ -1248,6 +1248,7 @@ static int dhcp6_route_add_callback(sd_netlink *nl, sd_netlink_message *m,
|
|||
if (r < 0 && r != -EEXIST)
|
||||
log_link_debug_errno(l, r, "Received error adding DHCPv6 Prefix Delegation route: %m");
|
||||
|
||||
l = link_unref(l);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1273,6 +1274,8 @@ int manager_dhcp6_prefix_add(Manager *m, struct in6_addr *addr, Link *link) {
|
|||
(void) in_addr_to_string(AF_INET6, (union in_addr_union *) addr, &buf);
|
||||
log_link_debug(link, "Adding prefix route %s/64", strnull(buf));
|
||||
|
||||
link = link_ref(link);
|
||||
|
||||
return hashmap_put(m->dhcp6_prefixes, addr, link);
|
||||
}
|
||||
|
||||
|
@ -1285,6 +1288,7 @@ static int dhcp6_route_remove_callback(sd_netlink *nl, sd_netlink_message *m,
|
|||
if (r < 0)
|
||||
log_link_debug_errno(l, r, "Received error on DHCPv6 Prefix Delegation route removal: %m");
|
||||
|
||||
l = link_unref(l);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1316,6 +1320,8 @@ int manager_dhcp6_prefix_remove(Manager *m, struct in6_addr *addr) {
|
|||
(void) in_addr_to_string(AF_INET6, (union in_addr_union *) addr, &buf);
|
||||
log_link_debug(l, "Removing prefix route %s/64", strnull(buf));
|
||||
|
||||
l = link_ref(l);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1438,11 +1444,18 @@ void manager_free(Manager *m) {
|
|||
network_free(network);
|
||||
|
||||
while ((link = hashmap_first(m->dhcp6_prefixes)))
|
||||
link_unref(link);
|
||||
manager_dhcp6_prefix_remove_all(m, link);
|
||||
hashmap_free(m->dhcp6_prefixes);
|
||||
|
||||
while ((link = hashmap_first(m->links)))
|
||||
while ((link = hashmap_first(m->links))) {
|
||||
if (link->dhcp6_client)
|
||||
(void) dhcp6_lease_pd_prefix_lost(link->dhcp6_client,
|
||||
link);
|
||||
|
||||
hashmap_remove(m->links, INT_TO_PTR(link->ifindex));
|
||||
|
||||
link_unref(link);
|
||||
}
|
||||
hashmap_free(m->links);
|
||||
|
||||
set_free(m->links_requesting_uuid);
|
||||
|
|
Loading…
Reference in a new issue