#include "hashmap.h"
#include "hostname-util.h"
+#include "missing_network.h"
#include "network-internal.h"
#include "networkd-link.h"
#include "networkd-manager.h"
if (!link->network)
return false;
- if (!IN_SET(link->network->router_prefix_delegation,
- RADV_PREFIX_DELEGATION_DHCP6,
- RADV_PREFIX_DELEGATION_BOTH)) {
- return false;
- }
-
- return true;
+ return IN_SET(link->network->router_prefix_delegation,
+ RADV_PREFIX_DELEGATION_DHCP6,
+ RADV_PREFIX_DELEGATION_BOTH);
}
static bool dhcp6_enable_prefix_delegation(Link *dhcp6_link) {
return sd_radv_start(radv);
}
-static int dhcp6_route_remove_cb(sd_netlink *nl, sd_netlink_message *m,
- void *userdata) {
- Link *l = userdata;
+static int dhcp6_route_remove_handler(sd_netlink *nl, sd_netlink_message *m, Link *link) {
int r;
+ assert(link);
+
r = sd_netlink_message_get_errno(m);
if (r < 0)
- log_link_debug_errno(l, r, "Received error on unreachable route removal for DHCPv6 delegated subnetl: %m");
-
- l = link_unref(l);
+ log_link_debug_errno(link, r, "Received error on unreachable route removal for DHCPv6 delegated subnetl: %m");
- return 0;
+ return 1;
}
int dhcp6_lease_pd_prefix_lost(sd_dhcp6_client *client, Link* link) {
continue;
}
- route_add(link, AF_INET6, &pd_prefix, pd_prefix_len,
- 0, 0, 0, &route);
- route_update(route, NULL, 0, NULL, NULL, 0, 0,
- RTN_UNREACHABLE);
+ r = route_add(link, AF_INET6, &pd_prefix, pd_prefix_len, 0, 0, 0, &route);
+ if (r < 0) {
+ log_link_warning_errno(link, r, "Failed to add unreachable route to delete for DHCPv6 delegated subnet %s/%u: %m",
+ strnull(buf),
+ pd_prefix_len);
+ continue;
+ }
+
+ route_update(route, NULL, 0, NULL, NULL, 0, 0, RTN_UNREACHABLE);
- r = route_remove(route, link, dhcp6_route_remove_cb);
+ r = route_remove(route, link, dhcp6_route_remove_handler);
if (r < 0) {
(void) in_addr_to_string(AF_INET6,
&pd_prefix, &buf);
continue;
}
- link = link_ref(link);
log_link_debug(link, "Removing unreachable route %s/%u",
strnull(buf), pd_prefix_len);
return 0;
}
-static int dhcp6_route_add_cb(sd_netlink *nl, sd_netlink_message *m,
- void *userdata) {
- Link *l = userdata;
+static int dhcp6_route_handler(sd_netlink *nl, sd_netlink_message *m, Link *link) {
int r;
+ assert(link);
+
r = sd_netlink_message_get_errno(m);
if (r < 0 && r != -EEXIST)
- log_link_debug_errno(l, r, "Received error when adding unreachable route for DHCPv6 delegated subnet: %m");
+ log_link_debug_errno(link, r, "Received error when adding unreachable route for DHCPv6 delegated subnet: %m");
- l = link_unref(l);
-
- return 0;
+ return 1;
}
-
static int dhcp6_lease_pd_prefix_acquired(sd_dhcp6_client *client, Link *link) {
int r;
sd_dhcp6_lease *lease;
}
if (pd_prefix_len < 64) {
- Route *route = NULL;
+ _cleanup_(route_freep) Route *route = NULL;
+ uint32_t table;
(void) in_addr_to_string(AF_INET6, &pd_prefix, &buf);
continue;
}
- route_add(link, AF_INET6, &pd_prefix, pd_prefix_len,
- 0, 0, 0, &route);
- route_update(route, NULL, 0, NULL, NULL, 0, 0,
- RTN_UNREACHABLE);
+ table = link_get_dhcp_route_table(link);
- r = route_configure(route, link, dhcp6_route_add_cb);
+ r = route_add(link, AF_INET6, &pd_prefix, pd_prefix_len, 0, 0, table, &route);
if (r < 0) {
- log_link_warning_errno(link, r, "Cannot configure unreachable route for delegated subnet %s/%u: %m",
+ log_link_warning_errno(link, r, "Failed to add unreachable route for DHCPv6 delegated subnet %s/%u: %m",
strnull(buf),
pd_prefix_len);
- route_free(route);
continue;
}
- link = link_ref(link);
- route_free(route);
+ route_update(route, NULL, 0, NULL, NULL, 0, 0, RTN_UNREACHABLE);
+
+ r = route_configure(route, link, dhcp6_route_handler);
+ if (r < 0) {
+ log_link_warning_errno(link, r, "Cannot configure unreachable route for delegated subnet %s/%u: %m",
+ strnull(buf),
+ pd_prefix_len);
+ continue;
+ }
log_link_debug(link, "Configuring unreachable route for %s/%u",
strnull(buf), pd_prefix_len);
return 0;
}
-static int dhcp6_address_handler(sd_netlink *rtnl, sd_netlink_message *m,
- void *userdata) {
- _cleanup_(link_unrefp) Link *link = userdata;
+static int dhcp6_address_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
int r;
assert(link);
if (r < 0)
return log_link_error_errno(link, r, "DHCP6 CLIENT: Failed to set MAC address: %m");
- r = sd_dhcp6_client_set_iaid(client, link->network->iaid);
- if (r < 0)
- return log_link_error_errno(link, r, "DHCP6 CLIENT: Failed to set IAID: %m");
+ if (link->network->iaid_set) {
+ r = sd_dhcp6_client_set_iaid(client, link->network->iaid);
+ if (r < 0)
+ return log_link_error_errno(link, r, "DHCP6 CLIENT: Failed to set IAID: %m");
+ }
duid = link_get_duid(link);
if (duid->type == DUID_TYPE_LLT && duid->raw_data_len == 0)