2017-11-18 17:09:20 +01:00
|
|
|
/* SPDX-License-Identifier: LGPL-2.1+ */
|
2014-12-10 15:17:34 +01:00
|
|
|
/***
|
2018-06-12 17:15:23 +02:00
|
|
|
Copyright © 2014 Intel Corporation. All rights reserved.
|
2014-12-10 15:17:34 +01:00
|
|
|
***/
|
|
|
|
|
2019-05-09 02:33:45 +02:00
|
|
|
#include <netinet/in.h>
|
2014-12-10 15:17:34 +01:00
|
|
|
#include <linux/if.h>
|
2019-07-24 11:22:43 +02:00
|
|
|
#include <linux/if_arp.h>
|
2014-12-10 15:17:34 +01:00
|
|
|
|
|
|
|
#include "sd-dhcp6-client.h"
|
|
|
|
|
2020-06-01 06:18:22 +02:00
|
|
|
#include "escape.h"
|
2018-01-04 14:11:59 +01:00
|
|
|
#include "hashmap.h"
|
2017-11-16 10:07:07 +01:00
|
|
|
#include "hostname-util.h"
|
2019-02-03 18:38:10 +01:00
|
|
|
#include "missing_network.h"
|
2015-10-24 22:58:24 +02:00
|
|
|
#include "network-internal.h"
|
2019-06-29 20:57:47 +02:00
|
|
|
#include "networkd-dhcp6.h"
|
2016-11-13 04:59:06 +01:00
|
|
|
#include "networkd-link.h"
|
|
|
|
#include "networkd-manager.h"
|
2020-07-07 04:19:49 +02:00
|
|
|
#include "networkd-radv.h"
|
2018-01-04 14:11:59 +01:00
|
|
|
#include "siphash24.h"
|
2020-07-02 01:03:17 +02:00
|
|
|
#include "string-table.h"
|
2018-01-04 14:11:59 +01:00
|
|
|
#include "string-util.h"
|
|
|
|
#include "radv-internal.h"
|
2020-06-01 06:18:22 +02:00
|
|
|
#include "web-util.h"
|
2015-10-24 22:58:24 +02:00
|
|
|
|
2019-06-29 21:09:51 +02:00
|
|
|
static Link *dhcp6_prefix_get(Manager *m, struct in6_addr *addr);
|
|
|
|
static int dhcp6_prefix_add(Manager *m, struct in6_addr *addr, Link *link);
|
|
|
|
static int dhcp6_prefix_remove_all(Manager *m, Link *link);
|
2020-04-04 20:07:18 +02:00
|
|
|
static int dhcp6_assign_delegated_prefix(Link *link, const struct in6_addr *prefix,
|
|
|
|
uint8_t prefix_len,
|
|
|
|
uint32_t lifetime_preferred,
|
|
|
|
uint32_t lifetime_valid);
|
2015-04-10 13:03:18 +02:00
|
|
|
|
2020-07-08 04:19:13 +02:00
|
|
|
bool dhcp6_get_prefix_delegation(Link *link) {
|
2018-10-02 20:29:06 +02:00
|
|
|
if (!link->network)
|
2018-01-04 14:11:51 +01:00
|
|
|
return false;
|
|
|
|
|
2018-11-28 20:48:34 +01:00
|
|
|
return IN_SET(link->network->router_prefix_delegation,
|
|
|
|
RADV_PREFIX_DELEGATION_DHCP6,
|
|
|
|
RADV_PREFIX_DELEGATION_BOTH);
|
2018-01-04 14:11:51 +01:00
|
|
|
}
|
|
|
|
|
2020-05-14 00:54:37 +02:00
|
|
|
static bool dhcp6_has_preferred_subnet_id(Link *link) {
|
|
|
|
if (!link->network)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return link->network->router_prefix_subnet_id >= 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int dhcp6_get_preferred_delegated_prefix(
|
|
|
|
Manager* manager,
|
|
|
|
Link *link,
|
|
|
|
const struct in6_addr *pd_prefix,
|
|
|
|
uint8_t pd_prefix_len,
|
|
|
|
struct in6_addr *ret_addr) {
|
|
|
|
|
2020-06-10 04:57:35 +02:00
|
|
|
int64_t subnet_id = link->network->router_prefix_subnet_id;
|
2020-05-14 00:54:37 +02:00
|
|
|
uint8_t prefix_bits = 64 - pd_prefix_len;
|
|
|
|
uint64_t n_prefixes = UINT64_C(1) << prefix_bits;
|
|
|
|
_cleanup_free_ char *assigned_buf = NULL;
|
2020-06-10 04:57:35 +02:00
|
|
|
union in_addr_union pd_prefix_union = {
|
|
|
|
.in6 = *pd_prefix,
|
|
|
|
};
|
2020-05-14 00:54:37 +02:00
|
|
|
/* We start off with the original PD prefix we have been assigned and
|
|
|
|
* iterate from there */
|
|
|
|
union in_addr_union prefix = {
|
|
|
|
.in6 = *pd_prefix,
|
|
|
|
};
|
2020-06-10 04:57:35 +02:00
|
|
|
int r;
|
|
|
|
|
|
|
|
assert(pd_prefix_len <= 64);
|
|
|
|
assert(manager);
|
|
|
|
assert(link);
|
|
|
|
assert(link->network);
|
2020-05-14 00:54:37 +02:00
|
|
|
|
|
|
|
if (subnet_id >= 0) {
|
|
|
|
/* If the link has a preference for a particular subnet id try to allocate that */
|
2020-07-07 02:14:21 +02:00
|
|
|
if ((uint64_t) subnet_id >= n_prefixes)
|
2020-05-14 00:54:37 +02:00
|
|
|
return log_link_debug_errno(link,
|
|
|
|
SYNTHETIC_ERRNO(ERANGE),
|
|
|
|
"subnet id %" PRIi64 " is out of range. Only have %" PRIu64 " subnets.",
|
|
|
|
subnet_id,
|
|
|
|
n_prefixes);
|
|
|
|
|
|
|
|
r = in_addr_prefix_nth(AF_INET6, &prefix, 64, subnet_id);
|
|
|
|
if (r < 0)
|
|
|
|
return log_link_debug_errno(link,
|
|
|
|
r,
|
|
|
|
"subnet id %" PRIi64 " is out of range. Only have %" PRIu64 " subnets.",
|
|
|
|
subnet_id,
|
|
|
|
n_prefixes);
|
|
|
|
|
|
|
|
/* Verify that the prefix we did calculate fits in the pd prefix.
|
|
|
|
* This should not fail as we checked the prefix size beforehand */
|
|
|
|
assert_se(in_addr_prefix_covers(AF_INET6, &pd_prefix_union, pd_prefix_len, &prefix) > 0);
|
|
|
|
|
|
|
|
Link* assigned_link = dhcp6_prefix_get(manager, &prefix.in6);
|
|
|
|
|
|
|
|
(void) in_addr_to_string(AF_INET6, &prefix, &assigned_buf);
|
|
|
|
|
|
|
|
if (assigned_link && assigned_link != link)
|
|
|
|
return log_link_error_errno(link, SYNTHETIC_ERRNO(EAGAIN),
|
|
|
|
"The requested prefix %s is already assigned to another link: %s",
|
|
|
|
strnull(assigned_buf),
|
|
|
|
strnull(assigned_link->ifname));
|
|
|
|
|
|
|
|
*ret_addr = prefix.in6;
|
|
|
|
|
|
|
|
log_link_debug(link, "The requested prefix %s is available. Using it.",
|
|
|
|
strnull(assigned_buf));
|
|
|
|
return 0;
|
2020-07-07 02:14:21 +02:00
|
|
|
}
|
2020-05-14 00:54:37 +02:00
|
|
|
|
2020-07-07 02:14:21 +02:00
|
|
|
for (uint64_t n = 0; n < n_prefixes; n++) {
|
|
|
|
/* if we do not have an allocation preference just iterate
|
|
|
|
* through the address space and return the first free prefix. */
|
|
|
|
Link* assigned_link = dhcp6_prefix_get(manager, &prefix.in6);
|
|
|
|
|
|
|
|
if (!assigned_link || assigned_link == link) {
|
|
|
|
*ret_addr = prefix.in6;
|
|
|
|
return 0;
|
2020-05-14 00:54:37 +02:00
|
|
|
}
|
|
|
|
|
2020-07-07 02:14:21 +02:00
|
|
|
r = in_addr_prefix_next(AF_INET6, &prefix, 64);
|
|
|
|
if (r < 0)
|
2020-07-11 22:13:43 +02:00
|
|
|
return log_link_error_errno(link, r, "Can't allocate another prefix. Out of address space?: %m");
|
2020-05-14 00:54:37 +02:00
|
|
|
}
|
|
|
|
|
2020-07-07 02:14:21 +02:00
|
|
|
return log_link_warning_errno(link, SYNTHETIC_ERRNO(ERANGE), "Couldn't find a suitable prefix. Ran out of address space.");
|
2020-05-14 00:54:37 +02:00
|
|
|
}
|
|
|
|
|
2018-01-04 14:11:51 +01:00
|
|
|
static bool dhcp6_enable_prefix_delegation(Link *dhcp6_link) {
|
|
|
|
Manager *manager;
|
|
|
|
Link *l;
|
|
|
|
Iterator i;
|
|
|
|
|
|
|
|
assert(dhcp6_link);
|
|
|
|
|
|
|
|
manager = dhcp6_link->manager;
|
|
|
|
assert(manager);
|
|
|
|
|
|
|
|
HASHMAP_FOREACH(l, manager->links, i) {
|
|
|
|
if (l == dhcp6_link)
|
|
|
|
continue;
|
|
|
|
|
2018-10-02 20:29:06 +02:00
|
|
|
if (!dhcp6_get_prefix_delegation(l))
|
2018-01-04 14:11:51 +01:00
|
|
|
continue;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-07-07 04:18:28 +02:00
|
|
|
static int dhcp6_lease_information_acquired(sd_dhcp6_client *client, Link *link) {
|
2015-01-20 18:36:04 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-01-04 14:11:59 +01:00
|
|
|
static int dhcp6_pd_prefix_assign(Link *link, struct in6_addr *prefix,
|
|
|
|
uint8_t prefix_len,
|
|
|
|
uint32_t lifetime_preferred,
|
|
|
|
uint32_t lifetime_valid) {
|
|
|
|
int r;
|
|
|
|
|
2020-07-07 04:19:49 +02:00
|
|
|
r = radv_add_prefix(link, prefix, prefix_len, lifetime_preferred, lifetime_valid);
|
2018-01-04 14:11:59 +01:00
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
2019-06-29 21:09:51 +02:00
|
|
|
r = dhcp6_prefix_add(link->manager, prefix, link);
|
2018-01-04 14:11:59 +01:00
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
2020-07-08 04:19:13 +02:00
|
|
|
r = dhcp6_assign_delegated_prefix(link, prefix, prefix_len, lifetime_preferred, lifetime_valid);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
2020-04-04 20:07:18 +02:00
|
|
|
|
2020-07-07 04:19:49 +02:00
|
|
|
return 0;
|
2018-01-04 14:11:59 +01:00
|
|
|
}
|
|
|
|
|
2018-11-28 21:06:52 +01:00
|
|
|
static int dhcp6_route_remove_handler(sd_netlink *nl, sd_netlink_message *m, Link *link) {
|
2018-09-19 02:32:19 +02:00
|
|
|
int r;
|
|
|
|
|
2018-10-06 06:55:19 +02:00
|
|
|
assert(link);
|
|
|
|
|
2019-07-14 17:35:49 +02:00
|
|
|
if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER))
|
|
|
|
return 1;
|
|
|
|
|
2018-09-19 02:32:19 +02:00
|
|
|
r = sd_netlink_message_get_errno(m);
|
|
|
|
if (r < 0)
|
2019-11-30 07:54:07 +01:00
|
|
|
log_link_message_warning_errno(link, m, r, "Received error on unreachable route removal for DHCPv6 delegated subnet");
|
2018-09-19 02:32:19 +02:00
|
|
|
|
2018-10-10 07:39:35 +02:00
|
|
|
return 1;
|
2018-09-19 02:32:19 +02:00
|
|
|
}
|
|
|
|
|
2018-09-19 02:32:30 +02:00
|
|
|
int dhcp6_lease_pd_prefix_lost(sd_dhcp6_client *client, Link* link) {
|
2020-06-10 04:57:35 +02:00
|
|
|
uint32_t lifetime_preferred, lifetime_valid;
|
2018-09-19 02:32:19 +02:00
|
|
|
union in_addr_union pd_prefix;
|
|
|
|
uint8_t pd_prefix_len;
|
2020-06-10 04:57:35 +02:00
|
|
|
sd_dhcp6_lease *lease;
|
|
|
|
int r;
|
2018-09-19 02:32:19 +02:00
|
|
|
|
|
|
|
r = sd_dhcp6_client_get_lease(client, &lease);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
sd_dhcp6_lease_reset_pd_prefix_iter(lease);
|
|
|
|
|
|
|
|
while (sd_dhcp6_lease_get_pd(lease, &pd_prefix.in6, &pd_prefix_len,
|
|
|
|
&lifetime_preferred,
|
|
|
|
&lifetime_valid) >= 0) {
|
|
|
|
_cleanup_free_ char *buf = NULL;
|
2019-09-09 17:16:41 +02:00
|
|
|
_cleanup_(route_freep) Route *route = NULL;
|
2018-09-19 02:32:19 +02:00
|
|
|
|
2019-05-04 15:59:36 +02:00
|
|
|
if (pd_prefix_len >= 64)
|
2018-09-19 02:32:19 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
(void) in_addr_to_string(AF_INET6, &pd_prefix, &buf);
|
|
|
|
|
2019-09-09 17:16:41 +02:00
|
|
|
r = route_new(&route);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
2018-09-26 02:09:17 +02:00
|
|
|
|
2019-09-09 17:16:41 +02:00
|
|
|
route->family = AF_INET6;
|
|
|
|
route->dst = pd_prefix;
|
|
|
|
route->dst_prefixlen = pd_prefix_len;
|
|
|
|
route->type = RTN_UNREACHABLE;
|
2018-09-19 02:32:19 +02:00
|
|
|
|
2019-05-04 15:59:36 +02:00
|
|
|
r = route_remove(route, link, dhcp6_route_remove_handler);
|
|
|
|
if (r < 0) {
|
|
|
|
log_link_warning_errno(link, r, "Cannot delete unreachable route for DHCPv6 delegated subnet %s/%u: %m",
|
|
|
|
strnull(buf),
|
|
|
|
pd_prefix_len);
|
|
|
|
continue;
|
2018-09-19 02:32:19 +02:00
|
|
|
}
|
2019-05-04 15:59:36 +02:00
|
|
|
|
|
|
|
log_link_debug(link, "Removing unreachable route %s/%u",
|
|
|
|
strnull(buf), pd_prefix_len);
|
2018-09-19 02:32:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-05-14 00:54:37 +02:00
|
|
|
static int dhcp6_pd_prefix_distribute(Link *dhcp6_link,
|
2018-01-04 14:11:59 +01:00
|
|
|
struct in6_addr *pd_prefix,
|
|
|
|
uint8_t pd_prefix_len,
|
|
|
|
uint32_t lifetime_preferred,
|
2020-05-14 00:54:37 +02:00
|
|
|
uint32_t lifetime_valid,
|
|
|
|
bool assign_preferred_subnet_id) {
|
2020-06-10 04:57:35 +02:00
|
|
|
|
|
|
|
_cleanup_free_ char *assigned_buf = NULL, *buf = NULL;
|
2018-01-04 14:11:59 +01:00
|
|
|
Manager *manager = dhcp6_link->manager;
|
2020-05-14 00:54:37 +02:00
|
|
|
union in_addr_union prefix = {
|
|
|
|
.in6 = *pd_prefix,
|
|
|
|
};
|
2020-06-10 04:57:35 +02:00
|
|
|
bool pool_depleted = false;
|
2020-05-14 00:54:37 +02:00
|
|
|
uint64_t n_prefixes;
|
2020-06-10 04:57:35 +02:00
|
|
|
Iterator i;
|
|
|
|
Link *link;
|
2018-01-04 14:11:59 +01:00
|
|
|
int r;
|
|
|
|
|
|
|
|
assert(manager);
|
|
|
|
assert(pd_prefix_len <= 64);
|
|
|
|
|
|
|
|
r = in_addr_mask(AF_INET6, &prefix, pd_prefix_len);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
2018-07-16 12:31:50 +02:00
|
|
|
n_prefixes = UINT64_C(1) << (64 - pd_prefix_len);
|
2018-01-04 14:11:59 +01:00
|
|
|
|
|
|
|
(void) in_addr_to_string(AF_INET6, &prefix, &buf);
|
2018-07-16 12:31:50 +02:00
|
|
|
log_link_debug(dhcp6_link, "Assigning up to %" PRIu64 " prefixes from %s/%u",
|
2018-01-04 14:11:59 +01:00
|
|
|
n_prefixes, strnull(buf), pd_prefix_len);
|
|
|
|
|
2020-05-14 00:54:37 +02:00
|
|
|
HASHMAP_FOREACH(link, manager->links, i) {
|
|
|
|
union in_addr_union assigned_prefix;
|
2018-01-04 14:11:59 +01:00
|
|
|
|
|
|
|
if (link == dhcp6_link)
|
|
|
|
continue;
|
|
|
|
|
2018-10-02 20:29:06 +02:00
|
|
|
if (!dhcp6_get_prefix_delegation(link))
|
2018-01-04 14:11:59 +01:00
|
|
|
continue;
|
|
|
|
|
2020-05-14 00:54:37 +02:00
|
|
|
if (assign_preferred_subnet_id != dhcp6_has_preferred_subnet_id(link))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
r = dhcp6_get_preferred_delegated_prefix(manager, link, &prefix.in6, pd_prefix_len,
|
2020-07-07 01:47:38 +02:00
|
|
|
&assigned_prefix.in6);
|
2020-05-14 00:54:37 +02:00
|
|
|
|
|
|
|
if (assign_preferred_subnet_id && r == -EAGAIN) {
|
|
|
|
/* A link has a preferred subnet_id but that one is
|
|
|
|
* already taken by another link. Now all the remaining
|
|
|
|
* links will also not obtain a prefix. */
|
|
|
|
pool_depleted = true;
|
|
|
|
continue;
|
|
|
|
} else if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
(void) in_addr_to_string(AF_INET6, &assigned_prefix, &assigned_buf);
|
|
|
|
r = dhcp6_pd_prefix_assign(link, &assigned_prefix.in6, 64,
|
2018-01-04 14:11:59 +01:00
|
|
|
lifetime_preferred, lifetime_valid);
|
|
|
|
if (r < 0) {
|
2020-05-14 00:54:37 +02:00
|
|
|
log_link_error_errno(link, r, "Unable to assign/update prefix %s/64 from %s/%u for link: %m",
|
2018-08-24 17:49:22 +02:00
|
|
|
strnull(assigned_buf),
|
2018-01-04 14:11:59 +01:00
|
|
|
strnull(buf), pd_prefix_len);
|
|
|
|
} else
|
2020-05-14 00:54:37 +02:00
|
|
|
log_link_debug(link, "Assigned prefix %s/64 from %s/%u to link",
|
2018-08-24 17:49:22 +02:00
|
|
|
strnull(assigned_buf),
|
|
|
|
strnull(buf), pd_prefix_len);
|
2018-01-04 14:11:59 +01:00
|
|
|
}
|
|
|
|
|
2020-05-14 00:54:37 +02:00
|
|
|
/* If one of the link requests couldn't be fulfilled, signal that we
|
|
|
|
should try again with another prefix. */
|
|
|
|
if (pool_depleted)
|
|
|
|
return -EAGAIN;
|
|
|
|
|
2018-09-19 02:32:19 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2018-05-11 08:43:04 +02:00
|
|
|
|
2018-11-28 21:06:52 +01:00
|
|
|
static int dhcp6_route_handler(sd_netlink *nl, sd_netlink_message *m, Link *link) {
|
2018-09-19 02:32:19 +02:00
|
|
|
int r;
|
2018-01-04 14:12:01 +01:00
|
|
|
|
2018-10-06 06:55:19 +02:00
|
|
|
assert(link);
|
2020-07-08 04:19:13 +02:00
|
|
|
assert(link->dhcp6_route_messages > 0);
|
|
|
|
|
|
|
|
link->dhcp6_route_messages--;
|
2018-10-06 06:55:19 +02:00
|
|
|
|
2019-07-14 17:35:49 +02:00
|
|
|
if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER))
|
|
|
|
return 1;
|
|
|
|
|
2018-09-19 02:32:19 +02:00
|
|
|
r = sd_netlink_message_get_errno(m);
|
2020-07-08 04:19:13 +02:00
|
|
|
if (r < 0 && r != -EEXIST) {
|
|
|
|
log_link_message_warning_errno(link, m, r, "Failed to add unreachable route for DHCPv6 delegated subnet");
|
|
|
|
link_enter_failed(link);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (link->dhcp6_route_messages == 0) {
|
|
|
|
log_link_debug(link, "Unreachable routes for DHCPv6 delegated subnets set");
|
|
|
|
link->dhcp6_route_configured = true;
|
|
|
|
link_check_ready(link);
|
|
|
|
}
|
2018-01-04 14:12:01 +01:00
|
|
|
|
2018-10-10 07:39:35 +02:00
|
|
|
return 1;
|
2018-01-04 14:11:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static int dhcp6_lease_pd_prefix_acquired(sd_dhcp6_client *client, Link *link) {
|
2020-06-10 04:57:35 +02:00
|
|
|
uint32_t lifetime_preferred, lifetime_valid;
|
2018-09-19 02:32:19 +02:00
|
|
|
union in_addr_union pd_prefix;
|
2020-06-10 04:57:35 +02:00
|
|
|
sd_dhcp6_lease *lease;
|
2018-01-04 14:11:59 +01:00
|
|
|
uint8_t pd_prefix_len;
|
2020-06-10 04:57:35 +02:00
|
|
|
int r;
|
2018-01-04 14:11:59 +01:00
|
|
|
|
2020-07-08 04:19:13 +02:00
|
|
|
link->dhcp6_route_configured = false;
|
|
|
|
|
2018-01-04 14:11:59 +01:00
|
|
|
r = sd_dhcp6_client_get_lease(client, &lease);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
sd_dhcp6_lease_reset_pd_prefix_iter(lease);
|
|
|
|
|
2018-09-19 02:32:19 +02:00
|
|
|
while (sd_dhcp6_lease_get_pd(lease, &pd_prefix.in6, &pd_prefix_len,
|
2018-01-04 14:11:59 +01:00
|
|
|
&lifetime_preferred,
|
|
|
|
&lifetime_valid) >= 0) {
|
|
|
|
|
2019-05-04 15:59:36 +02:00
|
|
|
_cleanup_free_ char *buf = NULL;
|
|
|
|
|
|
|
|
(void) in_addr_to_string(AF_INET6, &pd_prefix, &buf);
|
|
|
|
|
2018-01-04 14:11:59 +01:00
|
|
|
if (pd_prefix_len > 64) {
|
|
|
|
log_link_debug(link, "PD Prefix length > 64, ignoring prefix %s/%u",
|
|
|
|
strnull(buf), pd_prefix_len);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-05-04 15:59:36 +02:00
|
|
|
if (pd_prefix_len < 48)
|
2018-08-24 17:49:14 +02:00
|
|
|
log_link_warning(link, "PD Prefix length < 48, looks unusual %s/%u",
|
|
|
|
strnull(buf), pd_prefix_len);
|
|
|
|
|
2018-09-19 02:32:19 +02:00
|
|
|
if (pd_prefix_len < 64) {
|
2019-09-09 17:16:41 +02:00
|
|
|
_cleanup_(route_freep) Route *route = NULL;
|
2019-02-12 04:49:45 +01:00
|
|
|
|
2019-09-09 17:16:41 +02:00
|
|
|
r = route_new(&route);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
2019-02-12 05:03:57 +01:00
|
|
|
|
2019-09-09 17:16:41 +02:00
|
|
|
route->family = AF_INET6;
|
|
|
|
route->dst = pd_prefix;
|
|
|
|
route->dst_prefixlen = pd_prefix_len;
|
|
|
|
route->table = link_get_dhcp_route_table(link);
|
|
|
|
route->type = RTN_UNREACHABLE;
|
2018-09-19 02:32:19 +02:00
|
|
|
|
2018-10-10 07:38:57 +02:00
|
|
|
r = route_configure(route, link, dhcp6_route_handler);
|
2018-09-19 02:32:19 +02:00
|
|
|
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;
|
|
|
|
}
|
2020-07-08 04:19:13 +02:00
|
|
|
if (r > 0)
|
|
|
|
link->dhcp6_route_messages++;
|
2018-09-19 02:32:19 +02:00
|
|
|
|
|
|
|
log_link_debug(link, "Configuring unreachable route for %s/%u",
|
|
|
|
strnull(buf), pd_prefix_len);
|
|
|
|
} else
|
|
|
|
log_link_debug(link, "Not adding a blocking route since distributed prefix is /64");
|
|
|
|
|
2020-05-14 00:54:37 +02:00
|
|
|
/* We are doing prefix allocation in two steps:
|
|
|
|
* 1. all those links that have a preferred subnet id will be assigned their subnet
|
|
|
|
* 2. all those links that remain will receive prefixes in sequential
|
|
|
|
* order. Prefixes that were previously already allocated to another
|
|
|
|
* link will be skipped.
|
|
|
|
|
2020-05-29 13:35:11 +02:00
|
|
|
* If a subnet id request couldn't be fulfilled the failure will be logged (as error)
|
2020-05-14 00:54:37 +02:00
|
|
|
* and no further attempts at obtaining a prefix will be made.
|
|
|
|
|
|
|
|
* The assignment has to be split in two phases since subnet id
|
|
|
|
* preferences should be honored. Meaning that any subnet id should be
|
|
|
|
* handed out to the requesting link and not to some link that didn't
|
|
|
|
* specify any preference. */
|
|
|
|
|
|
|
|
r = dhcp6_pd_prefix_distribute(link, &pd_prefix.in6,
|
2018-01-04 14:11:59 +01:00
|
|
|
pd_prefix_len,
|
|
|
|
lifetime_preferred,
|
2020-05-14 00:54:37 +02:00
|
|
|
lifetime_valid,
|
|
|
|
true);
|
2018-01-04 14:11:59 +01:00
|
|
|
if (r < 0 && r != -EAGAIN)
|
|
|
|
return r;
|
|
|
|
|
2020-05-14 00:54:37 +02:00
|
|
|
/* if r == -EAGAIN then the allocation failed because we ran
|
|
|
|
* out of addresses for the preferred subnet id's. This doesn't
|
2020-05-29 13:35:11 +02:00
|
|
|
* mean we can't fulfill other prefix requests.
|
2020-05-14 00:54:37 +02:00
|
|
|
*
|
|
|
|
* Since we do not have dedicated lists of links that request
|
|
|
|
* specific subnet id's and those that accept any prefix we
|
|
|
|
* *must* reset the iterator to the start as otherwise some
|
|
|
|
* links might not get their requested prefix. */
|
|
|
|
|
|
|
|
r = dhcp6_pd_prefix_distribute(link, &pd_prefix.in6,
|
|
|
|
pd_prefix_len,
|
|
|
|
lifetime_preferred,
|
|
|
|
lifetime_valid,
|
|
|
|
false);
|
|
|
|
if (r < 0 && r != -EAGAIN)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
/* If the prefix distribution did return -EAGAIN we will try to
|
2020-05-29 13:35:11 +02:00
|
|
|
* fulfill those with the next available pd delegated prefix. */
|
2018-01-04 14:11:59 +01:00
|
|
|
}
|
|
|
|
|
2020-07-08 04:19:13 +02:00
|
|
|
if (link->dhcp6_route_messages == 0) {
|
|
|
|
link->dhcp6_route_configured = true;
|
|
|
|
link_check_ready(link);
|
|
|
|
} else {
|
|
|
|
log_link_debug(link, "Setting unreachable routes for DHCPv6 delegated subnets");
|
|
|
|
link_set_state(link, LINK_STATE_CONFIGURING);
|
|
|
|
}
|
|
|
|
|
2018-01-04 14:11:59 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-10-02 20:29:09 +02:00
|
|
|
int dhcp6_request_prefix_delegation(Link *link) {
|
|
|
|
Link *l;
|
|
|
|
Iterator i;
|
|
|
|
|
|
|
|
assert_return(link, -EINVAL);
|
|
|
|
assert_return(link->manager, -EOPNOTSUPP);
|
|
|
|
|
|
|
|
if (dhcp6_get_prefix_delegation(link) <= 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
log_link_debug(link, "Requesting DHCPv6 prefixes to be delegated for new link");
|
|
|
|
|
|
|
|
HASHMAP_FOREACH(l, link->manager->links, i) {
|
|
|
|
int r, enabled;
|
|
|
|
|
|
|
|
if (l == link)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!l->dhcp6_client)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
r = sd_dhcp6_client_get_prefix_delegation(l->dhcp6_client, &enabled);
|
|
|
|
if (r < 0) {
|
2020-07-11 22:13:43 +02:00
|
|
|
log_link_warning_errno(l, r, "Cannot get prefix delegation when adding new link: %m");
|
2018-10-02 20:29:09 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (enabled == 0) {
|
|
|
|
r = sd_dhcp6_client_set_prefix_delegation(l->dhcp6_client, 1);
|
|
|
|
if (r < 0) {
|
2020-07-11 22:13:43 +02:00
|
|
|
log_link_warning_errno(l, r, "Cannot enable prefix delegation when adding new link: 5m");
|
2018-10-02 20:29:09 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
r = sd_dhcp6_client_is_running(l->dhcp6_client);
|
|
|
|
if (r <= 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (enabled != 0) {
|
|
|
|
log_link_debug(l, "Requesting re-assignment of delegated prefixes after adding new link");
|
|
|
|
(void) dhcp6_lease_pd_prefix_acquired(l->dhcp6_client, l);
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = sd_dhcp6_client_stop(l->dhcp6_client);
|
|
|
|
if (r < 0) {
|
2020-07-11 22:13:43 +02:00
|
|
|
log_link_warning_errno(l, r, "Cannot stop DHCPv6 prefix delegation client after adding new link: %m");
|
2018-10-02 20:29:09 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = sd_dhcp6_client_start(l->dhcp6_client);
|
|
|
|
if (r < 0) {
|
2020-07-11 22:13:43 +02:00
|
|
|
log_link_warning_errno(l, r, "Cannot restart DHCPv6 prefix delegation client after adding new link: %m");
|
2018-10-02 20:29:09 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
log_link_debug(l, "Restarted DHCPv6 client to acquire prefix delegations after adding new link");
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-11-28 21:06:52 +01:00
|
|
|
static int dhcp6_address_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
|
2015-01-20 18:36:04 +01:00
|
|
|
int r;
|
|
|
|
|
|
|
|
assert(link);
|
2020-07-08 04:19:13 +02:00
|
|
|
assert(link->dhcp6_address_messages > 0);
|
|
|
|
|
|
|
|
link->dhcp6_address_messages--;
|
2015-01-20 18:36:04 +01:00
|
|
|
|
2019-07-14 17:35:49 +02:00
|
|
|
if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER))
|
|
|
|
return 1;
|
|
|
|
|
2015-06-12 16:31:33 +02:00
|
|
|
r = sd_netlink_message_get_errno(m);
|
2015-01-20 18:36:04 +01:00
|
|
|
if (r < 0 && r != -EEXIST) {
|
2019-11-30 07:54:07 +01:00
|
|
|
log_link_message_warning_errno(link, m, r, "Could not set DHCPv6 address");
|
2015-01-20 18:36:04 +01:00
|
|
|
link_enter_failed(link);
|
2019-07-06 02:03:02 +02:00
|
|
|
return 1;
|
2019-07-17 02:40:06 +02:00
|
|
|
} else if (r >= 0)
|
2019-07-14 17:35:49 +02:00
|
|
|
(void) manager_rtnl_process_address(rtnl, m, link->manager);
|
2015-01-20 18:36:04 +01:00
|
|
|
|
2020-07-08 04:19:13 +02:00
|
|
|
if (link->dhcp6_address_messages == 0) {
|
|
|
|
log_link_debug(link, "DHCPv6 addresses set");
|
|
|
|
link->dhcp6_address_configured = true;
|
|
|
|
r = link_request_set_routes(link);
|
|
|
|
if (r < 0) {
|
|
|
|
link_enter_failed(link);
|
|
|
|
return 1;
|
|
|
|
}
|
2019-07-14 17:35:49 +02:00
|
|
|
}
|
2019-07-06 02:04:10 +02:00
|
|
|
|
2015-01-20 18:36:04 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
network: beef up ipv6 RA support considerably
This reworks sd-ndisc and networkd substantially to support IPv6 RA much more
comprehensively. Since the API is extended quite a bit networkd has been ported
over too, and the patch is not as straight-forward as one could wish. The
rework includes:
- Support for DNSSL, RDNSS and RA routing options in sd-ndisc and networkd. Two
new configuration options have been added to networkd to make this
configurable.
- sd-ndisc now exposes an sd_ndisc_router object that encapsulates a full RA
message, and has direct, friendly acessor functions for the singleton RA
properties, as well as an iterative interface to iterate through known and
unsupported options. The router object may either be retrieved from the wire,
or generated from raw data. In many ways the sd-ndisc API now matches the
sd-lldp API, except that no implicit database of seen data is kept. (Note
that sd-ndisc actually had a half-written, but unused implementaiton of such
a store, which is removed now.)
- sd-ndisc will now collect the reception timestamps of RA, which is useful to
make sd_ndisc_router fully descriptive of what it covers.
Fixes: #1079
2016-06-02 20:38:12 +02:00
|
|
|
static int dhcp6_address_change(
|
|
|
|
Link *link,
|
|
|
|
struct in6_addr *ip6_addr,
|
|
|
|
uint32_t lifetime_preferred,
|
|
|
|
uint32_t lifetime_valid) {
|
|
|
|
|
tree-wide: drop redundant _cleanup_ macros (#8810)
This drops a good number of type-specific _cleanup_ macros, and patches
all users to just use the generic ones.
In most recent code we abstained from defining type-specific macros, and
this basically removes all those added already, with the exception of
the really low-level ones.
Having explicit macros for this is not too useful, as the expression
without the extra macro is generally just 2ch wider. We should generally
emphesize generic code, unless there are really good reasons for
specific code, hence let's follow this in this case too.
Note that _cleanup_free_ and similar really low-level, libc'ish, Linux
API'ish macros continue to be defined, only the really high-level OO
ones are dropped. From now on this should really be the rule: for really
low-level stuff, such as memory allocation, fd handling and so one, go
ahead and define explicit per-type macros, but for high-level, specific
program code, just use the generic _cleanup_() macro directly, in order
to keep things simple and as readable as possible for the uninitiated.
Note that before this patch some of the APIs (notable libudev ones) were
already used with the high-level macros at some places and with the
generic _cleanup_ macro at others. With this patch we hence unify on the
latter.
2018-04-25 12:31:45 +02:00
|
|
|
_cleanup_(address_freep) Address *addr = NULL;
|
2019-05-09 00:03:54 +02:00
|
|
|
_cleanup_free_ char *buffer = NULL;
|
network: beef up ipv6 RA support considerably
This reworks sd-ndisc and networkd substantially to support IPv6 RA much more
comprehensively. Since the API is extended quite a bit networkd has been ported
over too, and the patch is not as straight-forward as one could wish. The
rework includes:
- Support for DNSSL, RDNSS and RA routing options in sd-ndisc and networkd. Two
new configuration options have been added to networkd to make this
configurable.
- sd-ndisc now exposes an sd_ndisc_router object that encapsulates a full RA
message, and has direct, friendly acessor functions for the singleton RA
properties, as well as an iterative interface to iterate through known and
unsupported options. The router object may either be retrieved from the wire,
or generated from raw data. In many ways the sd-ndisc API now matches the
sd-lldp API, except that no implicit database of seen data is kept. (Note
that sd-ndisc actually had a half-written, but unused implementaiton of such
a store, which is removed now.)
- sd-ndisc will now collect the reception timestamps of RA, which is useful to
make sd_ndisc_router fully descriptive of what it covers.
Fixes: #1079
2016-06-02 20:38:12 +02:00
|
|
|
int r;
|
2015-01-20 18:36:04 +01:00
|
|
|
|
2015-09-21 15:53:40 +02:00
|
|
|
r = address_new(&addr);
|
2015-01-20 18:36:04 +01:00
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
addr->family = AF_INET6;
|
2019-05-09 00:03:54 +02:00
|
|
|
addr->in_addr.in6 = *ip6_addr;
|
2015-02-02 12:13:17 +01:00
|
|
|
addr->flags = IFA_F_NOPREFIXROUTE;
|
2015-10-18 16:59:21 +02:00
|
|
|
addr->prefixlen = 128;
|
2015-01-20 18:36:04 +01:00
|
|
|
addr->cinfo.ifa_prefered = lifetime_preferred;
|
|
|
|
addr->cinfo.ifa_valid = lifetime_valid;
|
|
|
|
|
2019-05-09 00:03:54 +02:00
|
|
|
(void) in_addr_to_string(addr->family, &addr->in_addr, &buffer);
|
core,network: major per-object logging rework
This changes log_unit_info() (and friends) to take a real Unit* object
insted of just a unit name as parameter. The call will now prefix all
logged messages with the unit name, thus allowing the unit name to be
dropped from the various passed romat strings, simplifying invocations
drastically, and unifying log output across messages. Also, UNIT= vs.
USER_UNIT= is now derived from the Manager object attached to the Unit
object, instead of getpid(). This has the benefit of correcting the
field for --test runs.
Also contains a couple of other logging improvements:
- Drops a couple of strerror() invocations in favour of using %m.
- Not only .mount units now warn if a symlinks exist for the mount
point already, .automount units do that too, now.
- A few invocations of log_struct() that didn't actually pass any
additional structured data have been replaced by simpler invocations
of log_unit_info() and friends.
- For structured data a new LOG_UNIT_MESSAGE() macro has been added,
that works like LOG_MESSAGE() but prefixes the message with the unit
name. Similar, there's now LOG_LINK_MESSAGE() and
LOG_NETDEV_MESSAGE().
- For structured data new LOG_UNIT_ID(), LOG_LINK_INTERFACE(),
LOG_NETDEV_INTERFACE() macros have been added that generate the
necessary per object fields. The old log_unit_struct() call has been
removed in favour of these new macros used in raw log_struct()
invocations. In addition to removing one more function call this
allows generated structured log messages that contain two object
fields, as necessary for example for network interfaces that are
joined into another network interface, and whose messages shall be
indexed by both.
- The LOG_ERRNO() macro has been removed, in favour of
log_struct_errno(). The latter has the benefit of ensuring that %m in
format strings is properly resolved to the specified error number.
- A number of logging messages have been converted to use
log_unit_info() instead of log_info()
- The client code in sysv-generator no longer #includes core code from
src/core/.
- log_unit_full_errno() has been removed, log_unit_full() instead takes
an errno now, too.
- log_unit_info(), log_link_info(), log_netdev_info() and friends, now
avoid double evaluation of their parameters
2015-05-11 20:38:21 +02:00
|
|
|
log_link_info(link,
|
network: beef up ipv6 RA support considerably
This reworks sd-ndisc and networkd substantially to support IPv6 RA much more
comprehensively. Since the API is extended quite a bit networkd has been ported
over too, and the patch is not as straight-forward as one could wish. The
rework includes:
- Support for DNSSL, RDNSS and RA routing options in sd-ndisc and networkd. Two
new configuration options have been added to networkd to make this
configurable.
- sd-ndisc now exposes an sd_ndisc_router object that encapsulates a full RA
message, and has direct, friendly acessor functions for the singleton RA
properties, as well as an iterative interface to iterate through known and
unsupported options. The router object may either be retrieved from the wire,
or generated from raw data. In many ways the sd-ndisc API now matches the
sd-lldp API, except that no implicit database of seen data is kept. (Note
that sd-ndisc actually had a half-written, but unused implementaiton of such
a store, which is removed now.)
- sd-ndisc will now collect the reception timestamps of RA, which is useful to
make sd_ndisc_router fully descriptive of what it covers.
Fixes: #1079
2016-06-02 20:38:12 +02:00
|
|
|
"DHCPv6 address %s/%d timeout preferred %d valid %d",
|
2019-05-09 00:03:54 +02:00
|
|
|
strnull(buffer), addr->prefixlen, lifetime_preferred, lifetime_valid);
|
2015-01-20 18:36:04 +01:00
|
|
|
|
2015-10-01 17:31:14 +02:00
|
|
|
r = address_configure(addr, link, dhcp6_address_handler, true);
|
2015-01-20 18:36:04 +01:00
|
|
|
if (r < 0)
|
2019-07-14 17:35:49 +02:00
|
|
|
return log_link_warning_errno(link, r, "Could not assign DHCPv6 address: %m");
|
2020-07-08 04:19:13 +02:00
|
|
|
if (r > 0)
|
|
|
|
link->dhcp6_address_messages++;
|
2015-01-20 18:36:04 +01:00
|
|
|
|
2019-07-14 17:35:49 +02:00
|
|
|
return 0;
|
2015-01-20 18:36:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static int dhcp6_lease_address_acquired(sd_dhcp6_client *client, Link *link) {
|
|
|
|
int r;
|
|
|
|
sd_dhcp6_lease *lease;
|
|
|
|
struct in6_addr ip6_addr;
|
|
|
|
uint32_t lifetime_preferred, lifetime_valid;
|
|
|
|
|
2020-07-08 04:19:13 +02:00
|
|
|
link->dhcp6_address_configured = false;
|
|
|
|
|
2015-01-20 18:36:04 +01:00
|
|
|
r = sd_dhcp6_client_get_lease(client, &lease);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
sd_dhcp6_lease_reset_address_iter(lease);
|
|
|
|
while (sd_dhcp6_lease_get_address(lease, &ip6_addr,
|
2016-05-15 16:22:40 +02:00
|
|
|
&lifetime_preferred,
|
|
|
|
&lifetime_valid) >= 0) {
|
2015-01-20 18:36:04 +01:00
|
|
|
|
2015-10-18 16:59:21 +02:00
|
|
|
r = dhcp6_address_change(link, &ip6_addr, lifetime_preferred, lifetime_valid);
|
2015-01-20 18:36:04 +01:00
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2020-07-08 04:19:13 +02:00
|
|
|
if (link->dhcp6_address_messages == 0) {
|
|
|
|
link->dhcp6_address_configured = true;
|
|
|
|
return link_request_set_routes(link);
|
|
|
|
} else {
|
|
|
|
log_link_debug(link, "Setting DHCPv6 addresses");
|
2020-07-12 20:12:11 +02:00
|
|
|
/* address_handler calls link_request_set_routes() and link_request_set_nexthop().
|
|
|
|
* Before they are called, the related flags must be cleared. Otherwise, the link
|
|
|
|
* becomes configured state before routes are configured. */
|
|
|
|
link->static_routes_configured = false;
|
|
|
|
link->static_nexthops_configured = false;
|
2020-07-08 04:19:13 +02:00
|
|
|
link_set_state(link, LINK_STATE_CONFIGURING);
|
|
|
|
}
|
|
|
|
|
2015-01-20 18:36:04 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-12-10 15:17:34 +01:00
|
|
|
static void dhcp6_handler(sd_dhcp6_client *client, int event, void *userdata) {
|
2015-01-20 18:36:04 +01:00
|
|
|
int r;
|
2014-12-10 15:17:34 +01:00
|
|
|
Link *link = userdata;
|
|
|
|
|
|
|
|
assert(link);
|
|
|
|
assert(link->network);
|
|
|
|
|
|
|
|
if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER))
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch(event) {
|
2015-09-22 14:52:23 +02:00
|
|
|
case SD_DHCP6_CLIENT_EVENT_STOP:
|
|
|
|
case SD_DHCP6_CLIENT_EVENT_RESEND_EXPIRE:
|
|
|
|
case SD_DHCP6_CLIENT_EVENT_RETRANS_MAX:
|
2015-11-13 14:35:39 +01:00
|
|
|
if (sd_dhcp6_client_get_lease(client, NULL) >= 0)
|
|
|
|
log_link_warning(link, "DHCPv6 lease lost");
|
2015-09-23 13:52:03 +02:00
|
|
|
|
2018-09-19 02:32:19 +02:00
|
|
|
(void) dhcp6_lease_pd_prefix_lost(client, link);
|
2019-06-29 21:09:51 +02:00
|
|
|
(void) dhcp6_prefix_remove_all(link->manager, link);
|
2018-01-04 14:11:59 +01:00
|
|
|
|
2019-07-17 16:12:07 +02:00
|
|
|
link_dirty(link);
|
2015-01-20 18:36:04 +01:00
|
|
|
break;
|
|
|
|
|
2015-09-22 14:52:23 +02:00
|
|
|
case SD_DHCP6_CLIENT_EVENT_IP_ACQUIRE:
|
2015-01-20 18:36:04 +01:00
|
|
|
r = dhcp6_lease_address_acquired(client, link);
|
|
|
|
if (r < 0) {
|
|
|
|
link_enter_failed(link);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-01-04 14:11:59 +01:00
|
|
|
r = dhcp6_lease_pd_prefix_acquired(client, link);
|
|
|
|
if (r < 0)
|
2020-07-11 22:13:43 +02:00
|
|
|
log_link_debug_errno(link, r, "DHCPv6 did not receive prefixes to delegate: %m");
|
2018-01-04 14:11:59 +01:00
|
|
|
|
2017-11-19 19:06:10 +01:00
|
|
|
_fallthrough_;
|
2015-09-22 14:52:23 +02:00
|
|
|
case SD_DHCP6_CLIENT_EVENT_INFORMATION_REQUEST:
|
2015-01-20 18:36:04 +01:00
|
|
|
r = dhcp6_lease_information_acquired(client, link);
|
|
|
|
if (r < 0) {
|
|
|
|
link_enter_failed(link);
|
|
|
|
return;
|
|
|
|
}
|
2014-12-10 15:17:34 +01:00
|
|
|
|
2019-07-17 16:12:07 +02:00
|
|
|
link_dirty(link);
|
2014-12-10 15:17:34 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
if (event < 0)
|
2015-09-30 22:16:17 +02:00
|
|
|
log_link_warning_errno(link, event, "DHCPv6 error: %m");
|
2014-12-10 15:17:34 +01:00
|
|
|
else
|
2015-09-30 22:16:17 +02:00
|
|
|
log_link_warning(link, "DHCPv6 unknown event: %d", event);
|
2014-12-10 15:17:34 +01:00
|
|
|
return;
|
|
|
|
}
|
2015-09-23 13:52:03 +02:00
|
|
|
|
2015-09-28 13:38:43 +02:00
|
|
|
link_check_ready(link);
|
2014-12-10 15:17:34 +01:00
|
|
|
}
|
|
|
|
|
2016-06-01 08:54:46 +02:00
|
|
|
int dhcp6_request_address(Link *link, int ir) {
|
2018-09-07 22:15:55 +02:00
|
|
|
int r, inf_req, pd;
|
2015-11-10 15:43:52 +01:00
|
|
|
bool running;
|
2014-12-10 15:17:34 +01:00
|
|
|
|
2015-11-10 15:43:52 +01:00
|
|
|
assert(link);
|
|
|
|
assert(link->dhcp6_client);
|
2018-09-07 22:15:55 +02:00
|
|
|
assert(link->network);
|
2016-06-01 08:54:46 +02:00
|
|
|
assert(in_addr_is_link_local(AF_INET6, (const union in_addr_union*)&link->ipv6ll_address) > 0);
|
2014-12-10 15:17:35 +01:00
|
|
|
|
2015-11-10 15:43:52 +01:00
|
|
|
r = sd_dhcp6_client_is_running(link->dhcp6_client);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
2019-08-26 08:40:30 +02:00
|
|
|
running = r;
|
2015-09-23 13:10:26 +02:00
|
|
|
|
2018-09-07 22:15:55 +02:00
|
|
|
r = sd_dhcp6_client_get_prefix_delegation(link->dhcp6_client, &pd);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
if (pd && ir && link->network->dhcp6_force_pd_other_information) {
|
|
|
|
log_link_debug(link, "Enabling managed mode to request DHCPv6 PD with 'Other Information' set");
|
|
|
|
|
|
|
|
r = sd_dhcp6_client_set_address_request(link->dhcp6_client,
|
|
|
|
false);
|
2020-07-08 04:19:13 +02:00
|
|
|
if (r < 0)
|
2018-09-07 22:15:55 +02:00
|
|
|
return r;
|
|
|
|
|
|
|
|
ir = false;
|
|
|
|
}
|
|
|
|
|
2015-11-10 15:43:52 +01:00
|
|
|
if (running) {
|
2016-06-01 08:54:46 +02:00
|
|
|
r = sd_dhcp6_client_get_information_request(link->dhcp6_client, &inf_req);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
if (inf_req == ir)
|
|
|
|
return 0;
|
|
|
|
|
2015-11-10 15:43:52 +01:00
|
|
|
r = sd_dhcp6_client_stop(link->dhcp6_client);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
2016-06-01 08:54:46 +02:00
|
|
|
} else {
|
|
|
|
r = sd_dhcp6_client_set_local_address(link->dhcp6_client, &link->ipv6ll_address);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
2015-11-10 15:43:52 +01:00
|
|
|
}
|
2014-12-10 15:17:35 +01:00
|
|
|
|
2016-06-01 08:54:46 +02:00
|
|
|
r = sd_dhcp6_client_set_information_request(link->dhcp6_client, ir);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
r = sd_dhcp6_client_start(link->dhcp6_client);
|
2015-11-10 15:43:52 +01:00
|
|
|
if (r < 0)
|
|
|
|
return r;
|
2014-12-10 15:17:35 +01:00
|
|
|
|
2015-11-10 15:43:52 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2015-09-23 13:52:03 +02:00
|
|
|
|
2017-11-16 10:07:07 +01:00
|
|
|
static int dhcp6_set_hostname(sd_dhcp6_client *client, Link *link) {
|
|
|
|
_cleanup_free_ char *hostname = NULL;
|
|
|
|
const char *hn;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
assert(link);
|
|
|
|
|
|
|
|
if (!link->network->dhcp_send_hostname)
|
|
|
|
hn = NULL;
|
|
|
|
else if (link->network->dhcp_hostname)
|
|
|
|
hn = link->network->dhcp_hostname;
|
|
|
|
else {
|
|
|
|
r = gethostname_strict(&hostname);
|
|
|
|
if (r < 0 && r != -ENXIO) /* ENXIO: no hostname set or hostname is "localhost" */
|
|
|
|
return r;
|
|
|
|
|
|
|
|
hn = hostname;
|
|
|
|
}
|
|
|
|
|
2018-08-02 09:31:10 +02:00
|
|
|
r = sd_dhcp6_client_set_fqdn(client, hn);
|
|
|
|
if (r == -EINVAL && hostname)
|
|
|
|
/* Ignore error when the machine's hostname is not suitable to send in DHCP packet. */
|
|
|
|
log_link_warning_errno(link, r, "DHCP6 CLIENT: Failed to set hostname from kernel hostname, ignoring: %m");
|
|
|
|
else if (r < 0)
|
|
|
|
return log_link_error_errno(link, r, "DHCP6 CLIENT: Failed to set hostname: %m");
|
|
|
|
|
|
|
|
return 0;
|
2017-11-16 10:07:07 +01:00
|
|
|
}
|
|
|
|
|
2015-11-10 15:43:52 +01:00
|
|
|
int dhcp6_configure(Link *link) {
|
2018-08-01 03:42:49 +02:00
|
|
|
_cleanup_(sd_dhcp6_client_unrefp) sd_dhcp6_client *client = NULL;
|
2020-05-26 10:46:54 +02:00
|
|
|
sd_dhcp6_option *vendor_option;
|
2020-05-01 16:30:31 +02:00
|
|
|
sd_dhcp6_option *send_option;
|
2020-04-23 14:31:47 +02:00
|
|
|
void *request_options;
|
networkd: rework duid_{type,duid_type,duid,duid_len} setting
Separate fields are replaced with a struct.
Second second duid type field is removed. The first field was used to carry
the result of DUIDType= configuration, and the second was either a copy of
this, or contained the type extracted from DuidRawData. The semantics are changed
so that the type specified in DUIDType is always used. DUIDRawData= no longer
overrides the type setting.
The networkd code is now more constrained than the sd-dhcp code:
DUIDRawData cannot have 0 length, length 0 is treated the same as unsetting.
Likewise, it is not possible to set a DUIDType=0. If it ever becomes necessary
to set type=0 or a zero-length duid, the code can be changed to support that.
Nevertheless, I think that's unlikely.
This addresses #3127 § 1 and 3.
v2:
- rename DUID.duid, DUID.duid_len to DUID.raw_data, DUID.raw_data_len
2016-04-29 05:23:45 +02:00
|
|
|
const DUID *duid;
|
2020-05-01 16:30:31 +02:00
|
|
|
Iterator i;
|
2018-01-22 09:09:18 +01:00
|
|
|
int r;
|
2015-11-10 15:43:52 +01:00
|
|
|
|
|
|
|
assert(link);
|
2018-01-22 09:09:18 +01:00
|
|
|
assert(link->network);
|
2015-11-10 15:43:52 +01:00
|
|
|
|
2015-11-16 16:47:18 +01:00
|
|
|
if (link->dhcp6_client)
|
|
|
|
return 0;
|
|
|
|
|
2015-11-10 15:43:52 +01:00
|
|
|
r = sd_dhcp6_client_new(&client);
|
2018-08-01 03:42:49 +02:00
|
|
|
if (r == -ENOMEM)
|
|
|
|
return log_oom();
|
2015-11-10 15:43:52 +01:00
|
|
|
if (r < 0)
|
2018-08-01 03:42:49 +02:00
|
|
|
return log_link_error_errno(link, r, "DHCP6 CLIENT: Failed to create DHCP6 client: %m");
|
2014-12-10 15:17:34 +01:00
|
|
|
|
2015-11-10 15:43:52 +01:00
|
|
|
r = sd_dhcp6_client_attach_event(client, NULL, 0);
|
2014-12-10 15:17:34 +01:00
|
|
|
if (r < 0)
|
2018-08-01 03:42:49 +02:00
|
|
|
return log_link_error_errno(link, r, "DHCP6 CLIENT: Failed to attach event: %m");
|
2014-12-10 15:17:34 +01:00
|
|
|
|
2015-11-10 15:43:52 +01:00
|
|
|
r = sd_dhcp6_client_set_mac(client,
|
2014-12-10 15:17:34 +01:00
|
|
|
(const uint8_t *) &link->mac,
|
|
|
|
sizeof (link->mac), ARPHRD_ETHER);
|
2015-09-23 13:10:26 +02:00
|
|
|
if (r < 0)
|
2018-08-01 03:42:49 +02:00
|
|
|
return log_link_error_errno(link, r, "DHCP6 CLIENT: Failed to set MAC address: %m");
|
2014-12-10 15:17:34 +01:00
|
|
|
|
2018-11-23 22:19:26 +01:00
|
|
|
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");
|
|
|
|
}
|
2016-03-31 01:33:55 +02:00
|
|
|
|
2018-08-06 10:28:27 +02:00
|
|
|
duid = link_get_duid(link);
|
2018-08-07 06:57:48 +02:00
|
|
|
if (duid->type == DUID_TYPE_LLT && duid->raw_data_len == 0)
|
|
|
|
r = sd_dhcp6_client_set_duid_llt(client, duid->llt_time);
|
|
|
|
else
|
|
|
|
r = sd_dhcp6_client_set_duid(client,
|
|
|
|
duid->type,
|
|
|
|
duid->raw_data_len > 0 ? duid->raw_data : NULL,
|
|
|
|
duid->raw_data_len);
|
2016-03-31 01:33:55 +02:00
|
|
|
if (r < 0)
|
2018-08-01 03:42:49 +02:00
|
|
|
return log_link_error_errno(link, r, "DHCP6 CLIENT: Failed to set DUID: %m");
|
2016-03-31 01:33:55 +02:00
|
|
|
|
2020-05-01 16:30:31 +02:00
|
|
|
ORDERED_HASHMAP_FOREACH(send_option, link->network->dhcp6_client_send_options, i) {
|
|
|
|
r = sd_dhcp6_client_add_option(client, send_option);
|
|
|
|
if (r == -EEXIST)
|
|
|
|
continue;
|
|
|
|
if (r < 0)
|
|
|
|
return log_link_error_errno(link, r, "DHCP6 CLIENT: Failed to set option: %m");
|
|
|
|
}
|
|
|
|
|
2017-11-16 10:07:07 +01:00
|
|
|
r = dhcp6_set_hostname(client, link);
|
|
|
|
if (r < 0)
|
2018-08-02 09:31:10 +02:00
|
|
|
return r;
|
2017-11-16 10:07:07 +01:00
|
|
|
|
2016-05-23 16:13:18 +02:00
|
|
|
r = sd_dhcp6_client_set_ifindex(client, link->ifindex);
|
2015-09-23 13:10:26 +02:00
|
|
|
if (r < 0)
|
2018-08-01 03:42:49 +02:00
|
|
|
return log_link_error_errno(link, r, "DHCP6 CLIENT: Failed to set ifindex: %m");
|
2014-12-10 15:17:34 +01:00
|
|
|
|
2018-01-22 09:09:18 +01:00
|
|
|
if (link->network->rapid_commit) {
|
|
|
|
r = sd_dhcp6_client_set_request_option(client, SD_DHCP6_OPTION_RAPID_COMMIT);
|
|
|
|
if (r < 0)
|
2018-08-01 03:42:49 +02:00
|
|
|
return log_link_error_errno(link, r, "DHCP6 CLIENT: Failed to set request flag for rapid commit: %m");
|
2018-01-22 09:09:18 +01:00
|
|
|
}
|
|
|
|
|
2020-03-30 16:31:10 +02:00
|
|
|
if (link->network->dhcp6_mudurl) {
|
|
|
|
r = sd_dhcp6_client_set_request_mud_url(client, link->network->dhcp6_mudurl);
|
|
|
|
if (r < 0)
|
|
|
|
return log_link_error_errno(link, r, "DHCP6 CLIENT: Failed to set MUD URL: %m");
|
|
|
|
}
|
|
|
|
|
2020-04-23 14:31:47 +02:00
|
|
|
SET_FOREACH(request_options, link->network->dhcp6_request_options, i) {
|
|
|
|
uint32_t option = PTR_TO_UINT32(request_options);
|
|
|
|
|
|
|
|
r = sd_dhcp6_client_set_request_option(client, option);
|
|
|
|
if (r == -EEXIST) {
|
|
|
|
log_link_debug(link, "DHCP6 CLIENT: Failed to set request flag for '%u' already exists, ignoring.", option);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (r < 0)
|
|
|
|
return log_link_error_errno(link, r, "DHCP6 CLIENT: Failed to set request flag for '%u': %m", option);
|
|
|
|
}
|
|
|
|
|
2020-05-18 14:49:47 +02:00
|
|
|
if (link->network->dhcp6_user_class) {
|
|
|
|
r = sd_dhcp6_client_set_request_user_class(client, link->network->dhcp6_user_class);
|
|
|
|
if (r < 0)
|
|
|
|
return log_link_error_errno(link, r, "DHCP6 CLIENT: Failed to set user class: %m");
|
|
|
|
}
|
|
|
|
|
2020-05-17 17:14:47 +02:00
|
|
|
if (link->network->dhcp6_vendor_class) {
|
|
|
|
r = sd_dhcp6_client_set_request_vendor_class(client, link->network->dhcp6_vendor_class);
|
|
|
|
if (r < 0)
|
|
|
|
return log_link_error_errno(link, r, "DHCP6 CLIENT: Failed to set vendor class: %m");
|
|
|
|
}
|
|
|
|
|
2020-05-26 10:46:54 +02:00
|
|
|
ORDERED_HASHMAP_FOREACH(vendor_option, link->network->dhcp6_client_send_vendor_options, i) {
|
|
|
|
r = sd_dhcp6_client_add_vendor_option(client, vendor_option);
|
|
|
|
if (r == -EEXIST)
|
|
|
|
continue;
|
|
|
|
if (r < 0)
|
|
|
|
return log_link_error_errno(link, r, "DHCP6 CLIENT: Failed to set vendor option: %m");
|
|
|
|
}
|
|
|
|
|
2015-11-10 15:43:52 +01:00
|
|
|
r = sd_dhcp6_client_set_callback(client, dhcp6_handler, link);
|
2015-09-23 13:10:26 +02:00
|
|
|
if (r < 0)
|
2018-08-01 03:42:49 +02:00
|
|
|
return log_link_error_errno(link, r, "DHCP6 CLIENT: Failed to set callback: %m");
|
2014-12-10 15:17:34 +01:00
|
|
|
|
2018-01-04 14:11:51 +01:00
|
|
|
if (dhcp6_enable_prefix_delegation(link)) {
|
|
|
|
r = sd_dhcp6_client_set_prefix_delegation(client, true);
|
|
|
|
if (r < 0)
|
2018-08-01 03:42:49 +02:00
|
|
|
return log_link_error_errno(link, r, "DHCP6 CLIENT: Failed to set prefix delegation: %m");
|
2018-01-04 14:11:51 +01:00
|
|
|
}
|
|
|
|
|
2019-09-25 05:14:12 +02:00
|
|
|
if (link->network->dhcp6_pd_length > 0) {
|
|
|
|
r = sd_dhcp6_client_set_prefix_delegation_hint(client, link->network->dhcp6_pd_length, &link->network->dhcp6_pd_address);
|
|
|
|
if (r < 0)
|
|
|
|
return log_link_error_errno(link, r, "DHCP6 CLIENT: Failed to set prefix hint: %m");
|
|
|
|
}
|
|
|
|
|
2018-08-01 03:42:49 +02:00
|
|
|
link->dhcp6_client = TAKE_PTR(client);
|
2015-09-23 13:10:26 +02:00
|
|
|
|
2015-11-10 15:43:52 +01:00
|
|
|
return 0;
|
2014-12-10 15:17:34 +01:00
|
|
|
}
|
2019-06-29 21:09:51 +02:00
|
|
|
|
|
|
|
static Link *dhcp6_prefix_get(Manager *m, struct in6_addr *addr) {
|
|
|
|
assert_return(m, NULL);
|
|
|
|
assert_return(addr, NULL);
|
|
|
|
|
|
|
|
return hashmap_get(m->dhcp6_prefixes, addr);
|
|
|
|
}
|
|
|
|
|
2020-07-08 04:19:13 +02:00
|
|
|
static int dhcp6_pd_route_handler(sd_netlink *nl, sd_netlink_message *m, Link *link) {
|
2019-06-29 21:09:51 +02:00
|
|
|
int r;
|
|
|
|
|
|
|
|
assert(link);
|
2020-07-08 04:19:13 +02:00
|
|
|
assert(link->dhcp6_pd_route_messages > 0);
|
|
|
|
|
|
|
|
link->dhcp6_pd_route_messages--;
|
2019-06-29 21:09:51 +02:00
|
|
|
|
2019-07-14 17:35:49 +02:00
|
|
|
if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER))
|
|
|
|
return 1;
|
|
|
|
|
2019-06-29 21:09:51 +02:00
|
|
|
r = sd_netlink_message_get_errno(m);
|
2019-07-14 17:35:49 +02:00
|
|
|
if (r < 0 && r != -EEXIST) {
|
2020-07-08 04:19:13 +02:00
|
|
|
log_link_message_warning_errno(link, m, r, "Failed to add DHCPv6 Prefix Delegation route");
|
2019-07-14 17:35:49 +02:00
|
|
|
link_enter_failed(link);
|
|
|
|
return 1;
|
|
|
|
}
|
2019-06-29 21:09:51 +02:00
|
|
|
|
2020-07-08 04:19:13 +02:00
|
|
|
if (link->dhcp6_pd_route_messages == 0) {
|
|
|
|
log_link_debug(link, "DHCPv6 prefix delegation routes set");
|
|
|
|
link->dhcp6_pd_route_configured = true;
|
|
|
|
link_check_ready(link);
|
|
|
|
}
|
|
|
|
|
2019-07-14 17:35:49 +02:00
|
|
|
return 1;
|
2019-06-29 21:09:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static int dhcp6_prefix_add(Manager *m, struct in6_addr *addr, Link *link) {
|
2019-09-09 17:16:41 +02:00
|
|
|
_cleanup_(route_freep) Route *route = NULL;
|
2019-06-29 21:09:51 +02:00
|
|
|
_cleanup_free_ struct in6_addr *a = NULL;
|
|
|
|
_cleanup_free_ char *buf = NULL;
|
|
|
|
Link *assigned_link;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
assert_return(m, -EINVAL);
|
|
|
|
assert_return(addr, -EINVAL);
|
|
|
|
|
2019-09-09 17:16:41 +02:00
|
|
|
r = route_new(&route);
|
2019-06-29 21:09:51 +02:00
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
2019-09-09 17:16:41 +02:00
|
|
|
route->family = AF_INET6;
|
|
|
|
route->dst.in6 = *addr;
|
|
|
|
route->dst_prefixlen = 64;
|
|
|
|
|
2020-07-08 04:19:13 +02:00
|
|
|
link->dhcp6_pd_route_configured = false;
|
|
|
|
link_set_state(link, LINK_STATE_CONFIGURING);
|
|
|
|
|
|
|
|
r = route_configure(route, link, dhcp6_pd_route_handler);
|
2019-06-29 21:09:51 +02:00
|
|
|
if (r < 0)
|
|
|
|
return r;
|
2020-07-08 04:19:13 +02:00
|
|
|
if (r > 0)
|
|
|
|
link->dhcp6_pd_route_messages++;
|
2019-06-29 21:09:51 +02:00
|
|
|
|
|
|
|
(void) in_addr_to_string(AF_INET6, (union in_addr_union *) addr, &buf);
|
|
|
|
log_link_debug(link, "Adding prefix route %s/64", strnull(buf));
|
|
|
|
|
|
|
|
assigned_link = hashmap_get(m->dhcp6_prefixes, addr);
|
|
|
|
if (assigned_link) {
|
|
|
|
assert(assigned_link == link);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
a = newdup(struct in6_addr, addr, 1);
|
|
|
|
if (!a)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
r = hashmap_ensure_allocated(&m->dhcp6_prefixes, &in6_addr_hash_ops);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
r = hashmap_put(m->dhcp6_prefixes, a, link);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
TAKE_PTR(a);
|
|
|
|
link_ref(link);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int dhcp6_prefix_remove_handler(sd_netlink *nl, sd_netlink_message *m, Link *link) {
|
|
|
|
int r;
|
|
|
|
|
|
|
|
assert(link);
|
|
|
|
|
2019-07-14 17:35:49 +02:00
|
|
|
if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER))
|
|
|
|
return 1;
|
|
|
|
|
2019-06-29 21:09:51 +02:00
|
|
|
r = sd_netlink_message_get_errno(m);
|
2019-07-14 17:35:49 +02:00
|
|
|
if (r < 0) {
|
2019-11-30 07:54:07 +01:00
|
|
|
log_link_message_warning_errno(link, m, r, "Received error on DHCPv6 Prefix Delegation route removal");
|
2019-07-14 17:35:49 +02:00
|
|
|
link_enter_failed(link);
|
|
|
|
return 1;
|
|
|
|
}
|
2019-06-29 21:09:51 +02:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int dhcp6_prefix_remove(Manager *m, struct in6_addr *addr) {
|
|
|
|
_cleanup_free_ struct in6_addr *a = NULL;
|
|
|
|
_cleanup_(link_unrefp) Link *l = NULL;
|
2019-09-09 17:16:41 +02:00
|
|
|
_cleanup_(route_freep) Route *route = NULL;
|
2019-06-29 21:09:51 +02:00
|
|
|
_cleanup_free_ char *buf = NULL;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
assert_return(m, -EINVAL);
|
|
|
|
assert_return(addr, -EINVAL);
|
|
|
|
|
|
|
|
l = hashmap_remove2(m->dhcp6_prefixes, addr, (void **) &a);
|
|
|
|
if (!l)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
(void) sd_radv_remove_prefix(l->radv, addr, 64);
|
2019-09-09 17:16:41 +02:00
|
|
|
|
|
|
|
r = route_new(&route);
|
2019-06-29 21:09:51 +02:00
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
2019-09-09 17:16:41 +02:00
|
|
|
route->family = AF_INET6;
|
|
|
|
route->dst.in6 = *addr;
|
|
|
|
route->dst_prefixlen = 64;
|
|
|
|
|
2019-06-29 21:09:51 +02:00
|
|
|
r = route_remove(route, l, dhcp6_prefix_remove_handler);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
(void) in_addr_to_string(AF_INET6, (union in_addr_union *) addr, &buf);
|
|
|
|
log_link_debug(l, "Removing prefix route %s/64", strnull(buf));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int dhcp6_prefix_remove_all(Manager *m, Link *link) {
|
|
|
|
struct in6_addr *addr;
|
|
|
|
Iterator i;
|
|
|
|
Link *l;
|
|
|
|
|
|
|
|
assert_return(m, -EINVAL);
|
|
|
|
assert_return(link, -EINVAL);
|
|
|
|
|
|
|
|
HASHMAP_FOREACH_KEY(l, addr, m->dhcp6_prefixes, i)
|
|
|
|
if (l == link)
|
|
|
|
(void) dhcp6_prefix_remove(m, addr);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2020-05-14 00:54:37 +02:00
|
|
|
|
2020-07-08 04:19:13 +02:00
|
|
|
static int dhcp6_pd_address_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
|
2020-07-07 01:38:37 +02:00
|
|
|
int r;
|
|
|
|
|
|
|
|
assert(link);
|
2020-07-08 04:19:13 +02:00
|
|
|
assert(link->dhcp6_pd_address_messages > 0);
|
|
|
|
|
|
|
|
link->dhcp6_pd_address_messages--;
|
2020-07-07 01:38:37 +02:00
|
|
|
|
|
|
|
if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
r = sd_netlink_message_get_errno(m);
|
|
|
|
if (r < 0 && r != -EEXIST) {
|
2020-07-08 04:19:13 +02:00
|
|
|
log_link_message_warning_errno(link, m, r, "Could not set DHCPv6 delegated prefix address");
|
2020-07-07 01:38:37 +02:00
|
|
|
link_enter_failed(link);
|
|
|
|
return 1;
|
|
|
|
} else if (r >= 0)
|
|
|
|
(void) manager_rtnl_process_address(rtnl, m, link->manager);
|
|
|
|
|
2020-07-08 04:19:13 +02:00
|
|
|
if (link->dhcp6_pd_address_messages == 0) {
|
|
|
|
log_link_debug(link, "DHCPv6 delegated prefix addresses set");
|
|
|
|
link->dhcp6_pd_address_configured = true;
|
|
|
|
r = link_request_set_routes(link);
|
|
|
|
if (r < 0) {
|
|
|
|
link_enter_failed(link);
|
|
|
|
return 1;
|
|
|
|
}
|
2020-07-07 01:38:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2020-04-04 20:07:18 +02:00
|
|
|
static int dhcp6_assign_delegated_prefix(Link *link,
|
|
|
|
const struct in6_addr *prefix,
|
|
|
|
uint8_t prefix_len,
|
|
|
|
uint32_t lifetime_preferred,
|
|
|
|
uint32_t lifetime_valid) {
|
2020-06-10 04:57:35 +02:00
|
|
|
|
2020-04-04 20:07:18 +02:00
|
|
|
_cleanup_(address_freep) Address *address = NULL;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
assert(link);
|
|
|
|
assert(link->network);
|
|
|
|
assert(prefix);
|
|
|
|
|
2020-07-08 04:19:13 +02:00
|
|
|
if (!link->network->dhcp6_pd_assign_prefix) {
|
|
|
|
link->dhcp6_pd_address_configured = true;
|
2020-04-04 20:07:18 +02:00
|
|
|
return 0;
|
2020-07-08 04:19:13 +02:00
|
|
|
}
|
2020-04-04 20:07:18 +02:00
|
|
|
|
|
|
|
r = address_new(&address);
|
|
|
|
if (r < 0)
|
2020-06-10 04:57:35 +02:00
|
|
|
return log_link_error_errno(link, r, "Failed to allocate address for DHCPv6 delegated prefix: %m");
|
2020-04-04 20:07:18 +02:00
|
|
|
|
|
|
|
address->in_addr.in6 = *prefix;
|
2020-06-10 04:57:35 +02:00
|
|
|
|
|
|
|
if (!in_addr_is_null(AF_INET6, &link->network->dhcp6_delegation_prefix_token))
|
2020-06-22 05:13:20 +02:00
|
|
|
memcpy(address->in_addr.in6.s6_addr + 8, link->network->dhcp6_delegation_prefix_token.in6.s6_addr + 8, 8);
|
2020-06-10 04:57:35 +02:00
|
|
|
else {
|
|
|
|
r = generate_ipv6_eui_64_address(link, &address->in_addr.in6);
|
|
|
|
if (r < 0)
|
|
|
|
return log_link_warning_errno(link, r, "Failed to generate EUI64 address for acquired DHCPv6 delegated prefix: %m");
|
|
|
|
}
|
2020-04-04 20:07:18 +02:00
|
|
|
|
|
|
|
address->prefixlen = prefix_len;
|
|
|
|
address->family = AF_INET6;
|
|
|
|
address->cinfo.ifa_prefered = lifetime_preferred;
|
|
|
|
address->cinfo.ifa_valid = lifetime_valid;
|
|
|
|
|
2020-07-12 20:12:11 +02:00
|
|
|
/* address_handler calls link_request_set_routes() and link_request_set_nexthop(). Before they
|
|
|
|
* are called, the related flags must be cleared. Otherwise, the link becomes configured state
|
|
|
|
* before routes are configured. */
|
|
|
|
link->static_routes_configured = false;
|
|
|
|
link->static_nexthops_configured = false;
|
2020-07-08 04:19:13 +02:00
|
|
|
link->dhcp6_pd_address_configured = false;
|
2020-04-04 20:07:18 +02:00
|
|
|
link_set_state(link, LINK_STATE_CONFIGURING);
|
|
|
|
|
2020-07-08 04:19:13 +02:00
|
|
|
r = address_configure(address, link, dhcp6_pd_address_handler, true);
|
2020-04-04 20:07:18 +02:00
|
|
|
if (r < 0)
|
2020-06-10 04:57:35 +02:00
|
|
|
return log_link_warning_errno(link, r, "Failed to set acquired DHCPv6 delegated prefix address: %m");
|
2020-07-08 04:19:13 +02:00
|
|
|
if (r > 0)
|
|
|
|
link->dhcp6_pd_address_messages++;
|
2020-04-04 20:07:18 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2020-06-01 06:18:22 +02:00
|
|
|
|
|
|
|
int config_parse_dhcp6_pd_hint(
|
|
|
|
const char* unit,
|
|
|
|
const char *filename,
|
|
|
|
unsigned line,
|
|
|
|
const char *section,
|
|
|
|
unsigned section_line,
|
|
|
|
const char *lvalue,
|
|
|
|
int ltype,
|
|
|
|
const char *rvalue,
|
|
|
|
void *data,
|
|
|
|
void *userdata) {
|
|
|
|
|
|
|
|
Network *network = data;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
assert(filename);
|
|
|
|
assert(lvalue);
|
|
|
|
assert(rvalue);
|
|
|
|
assert(data);
|
|
|
|
|
|
|
|
r = in_addr_prefix_from_string(rvalue, AF_INET6, (union in_addr_union *) &network->dhcp6_pd_address, &network->dhcp6_pd_length);
|
|
|
|
if (r < 0) {
|
|
|
|
log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse PrefixDelegationHint=%s, ignoring assignment", rvalue);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (network->dhcp6_pd_length < 1 || network->dhcp6_pd_length > 128) {
|
|
|
|
log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid prefix length='%d', ignoring assignment", network->dhcp6_pd_length);
|
|
|
|
network->dhcp6_pd_length = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int config_parse_dhcp6_mud_url(
|
|
|
|
const char *unit,
|
|
|
|
const char *filename,
|
|
|
|
unsigned line,
|
|
|
|
const char *section,
|
|
|
|
unsigned section_line,
|
|
|
|
const char *lvalue,
|
|
|
|
int ltype,
|
|
|
|
const char *rvalue,
|
|
|
|
void *data,
|
|
|
|
void *userdata) {
|
2020-06-10 04:57:35 +02:00
|
|
|
|
2020-06-01 06:18:22 +02:00
|
|
|
_cleanup_free_ char *unescaped = NULL;
|
|
|
|
Network *network = data;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
assert(filename);
|
|
|
|
assert(lvalue);
|
|
|
|
assert(rvalue);
|
|
|
|
|
|
|
|
if (isempty(rvalue)) {
|
|
|
|
network->dhcp6_mudurl = mfree(network->dhcp6_mudurl);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = cunescape(rvalue, 0, &unescaped);
|
|
|
|
if (r < 0) {
|
|
|
|
log_syntax(unit, LOG_ERR, filename, line, r,
|
|
|
|
"Failed to Failed to unescape MUD URL, ignoring: %s", rvalue);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!http_url_is_valid(unescaped) || strlen(unescaped) > UINT8_MAX) {
|
|
|
|
log_syntax(unit, LOG_ERR, filename, line, 0,
|
|
|
|
"Failed to parse MUD URL '%s', ignoring: %m", rvalue);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return free_and_replace(network->dhcp6_mudurl, unescaped);
|
|
|
|
}
|
2020-06-10 04:57:35 +02:00
|
|
|
|
|
|
|
int config_parse_dhcp6_delegated_prefix_token(
|
|
|
|
const char *unit,
|
|
|
|
const char *filename,
|
|
|
|
unsigned line,
|
|
|
|
const char *section,
|
|
|
|
unsigned section_line,
|
|
|
|
const char *lvalue,
|
|
|
|
int ltype,
|
|
|
|
const char *rvalue,
|
|
|
|
void *data,
|
|
|
|
void *userdata) {
|
|
|
|
|
|
|
|
Network *network = data;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
assert(filename);
|
|
|
|
assert(lvalue);
|
|
|
|
assert(rvalue);
|
|
|
|
assert(data);
|
|
|
|
|
|
|
|
if (isempty(rvalue)) {
|
|
|
|
network->dhcp6_delegation_prefix_token = IN_ADDR_NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = in_addr_from_string(AF_INET6, rvalue, &network->dhcp6_delegation_prefix_token);
|
|
|
|
if (r < 0) {
|
|
|
|
log_syntax(unit, LOG_ERR, filename, line, r,
|
|
|
|
"Failed to parse DHCPv6 %s, ignoring: %s", lvalue, rvalue);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (in_addr_is_null(AF_INET6, &network->dhcp6_delegation_prefix_token)) {
|
|
|
|
log_syntax(unit, LOG_ERR, filename, line, 0,
|
|
|
|
"DHCPv6 %s cannot be the ANY address, ignoring: %s", lvalue, rvalue);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2020-07-02 01:03:17 +02:00
|
|
|
|
|
|
|
DEFINE_CONFIG_PARSE_ENUM(config_parse_dhcp6_client_start_mode, dhcp6_client_start_mode, DHCP6ClientStartMode,
|
|
|
|
"Failed to parse WithoutRA= setting");
|
|
|
|
|
|
|
|
static const char* const dhcp6_client_start_mode_table[_DHCP6_CLIENT_START_MODE_MAX] = {
|
|
|
|
[DHCP6_CLIENT_START_MODE_NO] = "no",
|
|
|
|
[DHCP6_CLIENT_START_MODE_INFORMATION_REQUEST] = "information-request",
|
|
|
|
[DHCP6_CLIENT_START_MODE_SOLICIT] = "solicit",
|
|
|
|
};
|
|
|
|
|
|
|
|
DEFINE_STRING_TABLE_LOOKUP(dhcp6_client_start_mode, DHCP6ClientStartMode);
|