1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
3 Copyright © 2014 Intel Corporation. All rights reserved.
6 #include <netinet/in.h>
8 #include <linux/if_arp.h>
10 #include "sd-dhcp6-client.h"
14 #include "hostname-setup.h"
15 #include "hostname-util.h"
16 #include "missing_network.h"
17 #include "networkd-address.h"
18 #include "networkd-dhcp6.h"
19 #include "networkd-link.h"
20 #include "networkd-manager.h"
21 #include "networkd-radv.h"
22 #include "siphash24.h"
23 #include "string-table.h"
24 #include "string-util.h"
25 #include "radv-internal.h"
28 bool link_dhcp6_with_address_enabled(Link
*link
) {
29 if (!link_dhcp6_enabled(link
))
32 return link
->network
->dhcp6_use_address
;
35 bool link_dhcp6_pd_is_enabled(Link
*link
) {
41 return link
->network
->dhcp6_pd
;
44 static bool dhcp6_lease_has_pd_prefix(sd_dhcp6_lease
*lease
) {
45 uint32_t lifetime_preferred
, lifetime_valid
;
46 union in_addr_union pd_prefix
;
47 uint8_t pd_prefix_len
;
52 sd_dhcp6_lease_reset_pd_prefix_iter(lease
);
54 return sd_dhcp6_lease_get_pd(lease
, &pd_prefix
.in6
, &pd_prefix_len
, &lifetime_preferred
, &lifetime_valid
) >= 0;
57 DHCP6DelegatedPrefix
*dhcp6_pd_free(DHCP6DelegatedPrefix
*p
) {
61 if (p
->link
&& p
->link
->manager
) {
62 hashmap_remove(p
->link
->manager
->dhcp6_prefixes
, &p
->prefix
);
63 set_remove(p
->link
->manager
->dhcp6_pd_prefixes
, p
);
70 static void dhcp6_pd_hash_func(const DHCP6DelegatedPrefix
*p
, struct siphash
*state
) {
73 siphash24_compress(&p
->pd_prefix
, sizeof(p
->pd_prefix
), state
);
74 siphash24_compress(&p
->link
, sizeof(p
->link
), state
);
77 static int dhcp6_pd_compare_func(const DHCP6DelegatedPrefix
*a
, const DHCP6DelegatedPrefix
*b
) {
80 r
= memcmp(&a
->pd_prefix
, &b
->pd_prefix
, sizeof(a
->pd_prefix
));
84 return CMP(a
->link
, b
->link
);
87 DEFINE_HASH_OPS(dhcp6_pd_hash_ops
, DHCP6DelegatedPrefix
, dhcp6_pd_hash_func
, dhcp6_pd_compare_func
);
89 static Link
*dhcp6_pd_get_link_by_prefix(Link
*link
, const union in_addr_union
*prefix
) {
90 DHCP6DelegatedPrefix
*pd
;
93 assert(link
->manager
);
96 pd
= hashmap_get(link
->manager
->dhcp6_prefixes
, &prefix
->in6
);
103 static int dhcp6_pd_get_assigned_prefix(Link
*link
, const union in_addr_union
*pd_prefix
, union in_addr_union
*ret_prefix
) {
104 DHCP6DelegatedPrefix
*pd
, in
;
107 assert(link
->manager
);
111 in
= (DHCP6DelegatedPrefix
) {
112 .pd_prefix
= pd_prefix
->in6
,
116 pd
= set_get(link
->manager
->dhcp6_pd_prefixes
, &in
);
120 ret_prefix
->in6
= pd
->prefix
;
124 static int dhcp6_pd_remove_old(Link
*link
, bool force
);
126 static int dhcp6_pd_address_callback(Address
*address
) {
130 assert(address
->link
);
132 /* Make this called only once */
133 SET_FOREACH(a
, address
->link
->dhcp6_pd_addresses
)
136 return dhcp6_pd_remove_old(address
->link
, true);
139 static int dhcp6_pd_remove_old(Link
*link
, bool force
) {
145 assert(link
->manager
);
147 if (!force
&& (link
->dhcp6_pd_address_messages
!= 0 || link
->dhcp6_pd_route_messages
!= 0))
150 if (set_isempty(link
->dhcp6_pd_addresses_old
) && set_isempty(link
->dhcp6_pd_routes_old
))
154 bool set_callback
= !set_isempty(link
->dhcp6_pd_addresses
);
156 SET_FOREACH(address
, link
->dhcp6_pd_addresses
)
157 if (address_is_ready(address
)) {
158 set_callback
= false;
163 SET_FOREACH(address
, link
->dhcp6_pd_addresses
)
164 address
->callback
= dhcp6_pd_address_callback
;
169 log_link_debug(link
, "Removing old DHCPv6 Prefix Delegation addresses and routes.");
171 SET_FOREACH(route
, link
->dhcp6_pd_routes_old
) {
172 k
= route_remove(route
, NULL
, link
, NULL
);
177 (void) sd_radv_remove_prefix(link
->radv
, &route
->dst
.in6
, 64);
178 dhcp6_pd_free(hashmap_get(link
->manager
->dhcp6_prefixes
, &route
->dst
.in6
));
181 SET_FOREACH(address
, link
->dhcp6_pd_addresses_old
) {
182 k
= address_remove(address
, link
, NULL
);
190 int dhcp6_pd_remove(Link
*link
) {
196 assert(link
->manager
);
198 if (!link_dhcp6_pd_is_enabled(link
))
201 link
->dhcp6_pd_address_configured
= false;
202 link
->dhcp6_pd_route_configured
= false;
204 k
= dhcp6_pd_remove_old(link
, true);
208 if (set_isempty(link
->dhcp6_pd_addresses
) && set_isempty(link
->dhcp6_pd_routes
))
211 log_link_debug(link
, "Removing DHCPv6 Prefix Delegation addresses and routes.");
213 SET_FOREACH(route
, link
->dhcp6_pd_routes
) {
214 k
= route_remove(route
, NULL
, link
, NULL
);
219 (void) sd_radv_remove_prefix(link
->radv
, &route
->dst
.in6
, 64);
220 dhcp6_pd_free(hashmap_get(link
->manager
->dhcp6_prefixes
, &route
->dst
.in6
));
223 SET_FOREACH(address
, link
->dhcp6_pd_addresses
) {
224 k
= address_remove(address
, link
, NULL
);
232 static int dhcp6_pd_route_handler(sd_netlink
*nl
, sd_netlink_message
*m
, Link
*link
) {
236 assert(link
->dhcp6_pd_route_messages
> 0);
238 link
->dhcp6_pd_route_messages
--;
240 if (IN_SET(link
->state
, LINK_STATE_FAILED
, LINK_STATE_LINGER
))
243 r
= sd_netlink_message_get_errno(m
);
244 if (r
< 0 && r
!= -EEXIST
) {
245 log_link_message_warning_errno(link
, m
, r
, "Failed to add DHCPv6 Prefix Delegation route");
246 link_enter_failed(link
);
250 if (link
->dhcp6_pd_route_messages
== 0) {
251 log_link_debug(link
, "DHCPv6 prefix delegation routes set");
252 if (link
->dhcp6_pd_prefixes_assigned
)
253 link
->dhcp6_pd_route_configured
= true;
255 r
= dhcp6_pd_remove_old(link
, false);
257 link_enter_failed(link
);
261 link_check_ready(link
);
267 static int dhcp6_set_pd_route(Link
*link
, const union in_addr_union
*prefix
, const union in_addr_union
*pd_prefix
) {
268 _cleanup_(dhcp6_pd_freep
) DHCP6DelegatedPrefix
*pd
= NULL
;
269 _cleanup_(route_freep
) Route
*route
= NULL
;
275 assert(link
->manager
);
279 r
= route_new(&route
);
283 route
->family
= AF_INET6
;
284 route
->dst
= *prefix
;
285 route
->dst_prefixlen
= 64;
286 route
->protocol
= RTPROT_DHCP
;
287 route
->priority
= link
->network
->dhcp6_pd_route_metric
;
289 r
= route_configure(route
, link
, dhcp6_pd_route_handler
, &ret
);
291 return log_link_error_errno(link
, r
, "Failed to set DHCPv6 prefix route: %m");
293 link
->dhcp6_pd_route_configured
= false;
295 link
->dhcp6_pd_route_messages
++;
297 r
= set_ensure_put(&link
->dhcp6_pd_routes
, &route_hash_ops
, ret
);
299 return log_link_error_errno(link
, r
, "Failed to store DHCPv6 prefix route: %m");
301 (void) set_remove(link
->dhcp6_pd_routes_old
, ret
);
303 assigned_link
= dhcp6_pd_get_link_by_prefix(link
, prefix
);
305 assert(assigned_link
== link
);
309 pd
= new(DHCP6DelegatedPrefix
, 1);
313 *pd
= (DHCP6DelegatedPrefix
) {
314 .prefix
= prefix
->in6
,
315 .pd_prefix
= pd_prefix
->in6
,
316 .link
= link_ref(link
),
319 r
= hashmap_ensure_put(&link
->manager
->dhcp6_prefixes
, &in6_addr_hash_ops
, &pd
->prefix
, pd
);
323 return log_link_error_errno(link
, r
, "Failed to store DHCPv6 prefix route at manager: %m");
325 r
= set_ensure_put(&link
->manager
->dhcp6_pd_prefixes
, &dhcp6_pd_hash_ops
, pd
);
327 return log_link_error_errno(link
, r
, "Failed to store DHCPv6 prefix route at manager: %m");
333 static int dhcp6_pd_address_handler(sd_netlink
*rtnl
, sd_netlink_message
*m
, Link
*link
) {
337 assert(link
->dhcp6_pd_address_messages
> 0);
339 link
->dhcp6_pd_address_messages
--;
341 if (IN_SET(link
->state
, LINK_STATE_FAILED
, LINK_STATE_LINGER
))
344 r
= sd_netlink_message_get_errno(m
);
345 if (r
< 0 && r
!= -EEXIST
) {
346 log_link_message_warning_errno(link
, m
, r
, "Could not set DHCPv6 delegated prefix address");
347 link_enter_failed(link
);
350 (void) manager_rtnl_process_address(rtnl
, m
, link
->manager
);
352 if (link
->dhcp6_pd_address_messages
== 0) {
353 log_link_debug(link
, "DHCPv6 delegated prefix addresses set");
354 if (link
->dhcp6_pd_prefixes_assigned
)
355 link
->dhcp6_pd_address_configured
= true;
357 r
= dhcp6_pd_remove_old(link
, false);
359 link_enter_failed(link
);
367 static int dhcp6_set_pd_address(
369 const union in_addr_union
*prefix
,
370 uint32_t lifetime_preferred
,
371 uint32_t lifetime_valid
) {
373 _cleanup_(address_freep
) Address
*address
= NULL
;
378 assert(link
->network
);
381 if (!link
->network
->dhcp6_pd_assign
)
384 r
= address_new(&address
);
386 return log_link_error_errno(link
, r
, "Failed to allocate address for DHCPv6 delegated prefix: %m");
388 address
->in_addr
= *prefix
;
390 if (in_addr_is_set(AF_INET6
, &link
->network
->dhcp6_pd_token
))
391 memcpy(address
->in_addr
.in6
.s6_addr
+ 8, link
->network
->dhcp6_pd_token
.in6
.s6_addr
+ 8, 8);
393 r
= generate_ipv6_eui_64_address(link
, &address
->in_addr
.in6
);
395 return log_link_warning_errno(link
, r
, "Failed to generate EUI64 address for acquired DHCPv6 delegated prefix: %m");
398 address
->prefixlen
= 64;
399 address
->family
= AF_INET6
;
400 address
->cinfo
.ifa_prefered
= lifetime_preferred
;
401 address
->cinfo
.ifa_valid
= lifetime_valid
;
402 SET_FLAG(address
->flags
, IFA_F_MANAGETEMPADDR
, link
->network
->dhcp6_pd_manage_temporary_address
);
403 address
->route_metric
= link
->network
->dhcp6_pd_route_metric
;
405 r
= address_configure(address
, link
, dhcp6_pd_address_handler
, &ret
);
407 return log_link_error_errno(link
, r
, "Failed to set DHCPv6 delegated prefix address: %m");
409 link
->dhcp6_pd_address_configured
= false;
411 link
->dhcp6_pd_address_messages
++;
413 r
= set_ensure_put(&link
->dhcp6_pd_addresses
, &address_hash_ops
, ret
);
415 return log_link_error_errno(link
, r
, "Failed to store DHCPv6 delegated prefix address: %m");
417 (void) set_remove(link
->dhcp6_pd_addresses_old
, ret
);
422 static int dhcp6_pd_assign_prefix(
424 const union in_addr_union
*prefix
,
425 const union in_addr_union
*pd_prefix
,
426 uint32_t lifetime_preferred
,
427 uint32_t lifetime_valid
) {
432 assert(link
->network
);
435 if (link
->network
->dhcp6_pd_announce
) {
436 r
= radv_add_prefix(link
, &prefix
->in6
, 64, lifetime_preferred
, lifetime_valid
);
441 r
= dhcp6_set_pd_route(link
, prefix
, pd_prefix
);
445 r
= dhcp6_set_pd_address(link
, prefix
, lifetime_preferred
, lifetime_valid
);
452 static bool link_has_preferred_subnet_id(Link
*link
) {
456 return link
->network
->dhcp6_pd_subnet_id
>= 0;
459 static int dhcp6_get_preferred_delegated_prefix(
461 const union in_addr_union
*masked_pd_prefix
,
462 uint8_t pd_prefix_len
,
463 union in_addr_union
*ret
) {
465 /* We start off with the original PD prefix we have been assigned and iterate from there */
466 union in_addr_union prefix
;
472 assert(link
->manager
);
473 assert(masked_pd_prefix
);
474 assert(pd_prefix_len
<= 64);
476 n_prefixes
= UINT64_C(1) << (64 - pd_prefix_len
);
477 prefix
= *masked_pd_prefix
;
479 if (link_has_preferred_subnet_id(link
)) {
480 uint64_t subnet_id
= link
->network
->dhcp6_pd_subnet_id
;
482 /* If the link has a preference for a particular subnet id try to allocate that */
483 if (subnet_id
>= n_prefixes
)
484 return log_link_warning_errno(link
, SYNTHETIC_ERRNO(ERANGE
),
485 "subnet id %" PRIu64
" is out of range. Only have %" PRIu64
" subnets.",
486 subnet_id
, n_prefixes
);
488 r
= in_addr_prefix_nth(AF_INET6
, &prefix
, 64, subnet_id
);
490 return log_link_warning_errno(link
, r
,
491 "subnet id %" PRIu64
" is out of range. Only have %" PRIu64
" subnets.",
492 subnet_id
, n_prefixes
);
494 /* Verify that the prefix we did calculate fits in the pd prefix.
495 * This should not fail as we checked the prefix size beforehand */
496 assert_se(in_addr_prefix_covers(AF_INET6
, masked_pd_prefix
, pd_prefix_len
, &prefix
) > 0);
498 assigned_link
= dhcp6_pd_get_link_by_prefix(link
, &prefix
);
499 if (assigned_link
&& assigned_link
!= link
) {
500 _cleanup_free_
char *assigned_buf
= NULL
;
502 (void) in_addr_to_string(AF_INET6
, &prefix
, &assigned_buf
);
503 return log_link_warning_errno(link
, SYNTHETIC_ERRNO(EAGAIN
),
504 "The requested prefix %s is already assigned to another link.",
505 strna(assigned_buf
));
512 for (uint64_t n
= 0; n
< n_prefixes
; n
++) {
513 /* If we do not have an allocation preference just iterate
514 * through the address space and return the first free prefix. */
515 assigned_link
= dhcp6_pd_get_link_by_prefix(link
, &prefix
);
516 if (!assigned_link
|| assigned_link
== link
) {
521 r
= in_addr_prefix_next(AF_INET6
, &prefix
, 64);
523 return log_link_warning_errno(link
, r
, "Can't allocate another prefix. Out of address space?: %m");
526 return log_link_warning_errno(link
, SYNTHETIC_ERRNO(ERANGE
), "Couldn't find a suitable prefix. Ran out of address space.");
529 static void dhcp6_pd_prefix_distribute(Link
*dhcp6_link
,
530 const union in_addr_union
*masked_pd_prefix
,
531 uint8_t pd_prefix_len
,
532 uint32_t lifetime_preferred
,
533 uint32_t lifetime_valid
,
534 bool assign_preferred_subnet_id
) {
540 assert(dhcp6_link
->manager
);
541 assert(masked_pd_prefix
);
542 assert(pd_prefix_len
<= 64);
544 HASHMAP_FOREACH(link
, dhcp6_link
->manager
->links
) {
545 _cleanup_free_
char *assigned_buf
= NULL
;
546 union in_addr_union assigned_prefix
;
548 if (link
== dhcp6_link
)
551 if (!link_dhcp6_pd_is_enabled(link
))
554 if (IN_SET(link
->state
, LINK_STATE_FAILED
, LINK_STATE_LINGER
))
557 if (assign_preferred_subnet_id
!= link_has_preferred_subnet_id(link
))
560 r
= dhcp6_pd_get_assigned_prefix(link
, masked_pd_prefix
, &assigned_prefix
);
562 r
= dhcp6_get_preferred_delegated_prefix(link
, masked_pd_prefix
, pd_prefix_len
, &assigned_prefix
);
564 link
->dhcp6_pd_prefixes_assigned
= false;
569 (void) in_addr_to_string(AF_INET6
, &assigned_prefix
, &assigned_buf
);
570 r
= dhcp6_pd_assign_prefix(link
, &assigned_prefix
, masked_pd_prefix
,
571 lifetime_preferred
, lifetime_valid
);
573 log_link_error_errno(link
, r
, "Unable to assign/update prefix %s/64: %m",
574 strna(assigned_buf
));
575 link_enter_failed(link
);
577 log_link_debug(link
, "Assigned prefix %s/64", strna(assigned_buf
));
581 static int dhcp6_pd_prepare(Link
*link
) {
586 if (IN_SET(link
->state
, LINK_STATE_FAILED
, LINK_STATE_LINGER
))
589 if (!link_dhcp6_pd_is_enabled(link
))
592 link
->dhcp6_pd_prefixes_assigned
= true;
594 while ((address
= set_steal_first(link
->dhcp6_pd_addresses
))) {
595 r
= set_ensure_put(&link
->dhcp6_pd_addresses_old
, &address_hash_ops
, address
);
597 return log_link_error_errno(link
, r
, "Failed to store old DHCPv6 Prefix Delegation address: %m");
600 while ((route
= set_steal_first(link
->dhcp6_pd_routes
))) {
601 r
= set_ensure_put(&link
->dhcp6_pd_routes_old
, &route_hash_ops
, route
);
603 return log_link_error_errno(link
, r
, "Failed to store old DHCPv6 Prefix Delegation route: %m");
609 static int dhcp6_pd_finalize(Link
*link
) {
612 if (IN_SET(link
->state
, LINK_STATE_FAILED
, LINK_STATE_LINGER
))
615 if (!link_dhcp6_pd_is_enabled(link
))
618 if (link
->dhcp6_pd_address_messages
== 0) {
619 if (link
->dhcp6_pd_prefixes_assigned
)
620 link
->dhcp6_pd_address_configured
= true;
622 log_link_debug(link
, "Setting DHCPv6 PD addresses");
624 if (link
->dhcp6_pd_route_messages
== 0) {
625 if (link
->dhcp6_pd_prefixes_assigned
)
626 link
->dhcp6_pd_route_configured
= true;
628 log_link_debug(link
, "Setting DHCPv6 PD routes");
630 r
= dhcp6_pd_remove_old(link
, false);
634 if (link
->dhcp6_pd_address_configured
&& link
->dhcp6_pd_route_configured
)
635 link_check_ready(link
);
637 link_set_state(link
, LINK_STATE_CONFIGURING
);
642 static void dhcp6_pd_prefix_lost(Link
*dhcp6_link
) {
647 assert(dhcp6_link
->manager
);
649 HASHMAP_FOREACH(link
, dhcp6_link
->manager
->links
) {
650 if (link
== dhcp6_link
)
653 r
= dhcp6_pd_remove(link
);
655 link_enter_failed(link
);
659 static int dhcp6_remove_old(Link
*link
, bool force
);
661 static int dhcp6_address_callback(Address
*address
) {
665 assert(address
->link
);
667 /* Make this called only once */
668 SET_FOREACH(a
, address
->link
->dhcp6_addresses
)
671 return dhcp6_remove_old(address
->link
, true);
674 static int dhcp6_remove_old(Link
*link
, bool force
) {
681 if (!force
&& (!link
->dhcp6_address_configured
|| !link
->dhcp6_route_configured
))
684 if (set_isempty(link
->dhcp6_addresses_old
) && set_isempty(link
->dhcp6_routes_old
))
688 bool set_callback
= !set_isempty(link
->dhcp6_addresses
);
690 SET_FOREACH(address
, link
->dhcp6_addresses
)
691 if (address_is_ready(address
)) {
692 set_callback
= false;
697 SET_FOREACH(address
, link
->dhcp6_addresses
)
698 address
->callback
= dhcp6_address_callback
;
703 log_link_debug(link
, "Removing old DHCPv6 addresses and routes.");
705 SET_FOREACH(route
, link
->dhcp6_routes_old
) {
706 k
= route_remove(route
, NULL
, link
, NULL
);
711 SET_FOREACH(address
, link
->dhcp6_addresses_old
) {
712 k
= address_remove(address
, link
, NULL
);
720 static int dhcp6_remove(Link
*link
) {
727 link
->dhcp6_address_configured
= false;
728 link
->dhcp6_route_configured
= false;
730 k
= dhcp6_remove_old(link
, true);
734 if (set_isempty(link
->dhcp6_addresses
) && set_isempty(link
->dhcp6_routes
))
737 log_link_debug(link
, "Removing DHCPv6 addresses and routes.");
739 SET_FOREACH(route
, link
->dhcp6_routes
) {
740 k
= route_remove(route
, NULL
, link
, NULL
);
745 SET_FOREACH(address
, link
->dhcp6_addresses
) {
746 k
= address_remove(address
, link
, NULL
);
754 static int dhcp6_route_handler(sd_netlink
*nl
, sd_netlink_message
*m
, Link
*link
) {
758 assert(link
->dhcp6_route_messages
> 0);
760 link
->dhcp6_route_messages
--;
762 if (IN_SET(link
->state
, LINK_STATE_FAILED
, LINK_STATE_LINGER
))
765 r
= sd_netlink_message_get_errno(m
);
766 if (r
< 0 && r
!= -EEXIST
) {
767 log_link_message_warning_errno(link
, m
, r
, "Failed to add unreachable route for DHCPv6 delegated subnet");
768 link_enter_failed(link
);
772 if (link
->dhcp6_route_messages
== 0) {
773 log_link_debug(link
, "Unreachable routes for DHCPv6 delegated subnets set");
774 link
->dhcp6_route_configured
= true;
776 r
= dhcp6_remove_old(link
, false);
778 link_enter_failed(link
);
782 link_check_ready(link
);
788 static int dhcp6_set_unreachable_route(Link
*link
, const union in_addr_union
*addr
, uint8_t prefixlen
) {
789 _cleanup_(route_freep
) Route
*route
= NULL
;
790 _cleanup_free_
char *buf
= NULL
;
797 (void) in_addr_prefix_to_string(AF_INET6
, addr
, prefixlen
, &buf
);
799 if (prefixlen
> 64) {
800 log_link_debug(link
, "PD Prefix length > 64, ignoring prefix %s", strna(buf
));
804 if (prefixlen
== 64) {
805 log_link_debug(link
, "Not adding a blocking route for DHCPv6 delegated subnet %s since distributed prefix is 64",
811 log_link_warning(link
, "PD Prefix length < 48, looks unusual: %s", strna(buf
));
813 r
= route_new(&route
);
817 route
->family
= AF_INET6
;
819 route
->dst_prefixlen
= prefixlen
;
820 route
->table
= link_get_dhcp_route_table(link
);
821 route
->type
= RTN_UNREACHABLE
;
822 route
->protocol
= RTPROT_DHCP
;
824 r
= route_configure(route
, link
, dhcp6_route_handler
, &ret
);
826 return log_link_error_errno(link
, r
, "Failed to set unreachable route for DHCPv6 delegated subnet %s: %m",
829 link
->dhcp6_route_configured
= false;
831 link
->dhcp6_route_messages
++;
833 r
= set_ensure_put(&link
->dhcp6_routes
, &route_hash_ops
, ret
);
835 return log_link_error_errno(link
, r
, "Failed to store unreachable route for DHCPv6 delegated subnet %s: %m",
838 (void) set_remove(link
->dhcp6_routes_old
, ret
);
843 static int dhcp6_pd_prefix_acquired(Link
*dhcp6_link
) {
848 assert(dhcp6_link
->dhcp6_lease
);
850 HASHMAP_FOREACH(link
, dhcp6_link
->manager
->links
) {
851 if (link
== dhcp6_link
)
854 r
= dhcp6_pd_prepare(link
);
856 link_enter_failed(link
);
859 for (sd_dhcp6_lease_reset_pd_prefix_iter(dhcp6_link
->dhcp6_lease
);;) {
860 uint32_t lifetime_preferred
, lifetime_valid
;
861 union in_addr_union pd_prefix
, prefix
;
862 uint8_t pd_prefix_len
;
864 r
= sd_dhcp6_lease_get_pd(dhcp6_link
->dhcp6_lease
, &pd_prefix
.in6
, &pd_prefix_len
,
865 &lifetime_preferred
, &lifetime_valid
);
869 r
= dhcp6_set_unreachable_route(dhcp6_link
, &pd_prefix
, pd_prefix_len
);
875 /* We are doing prefix allocation in two steps:
876 * 1. all those links that have a preferred subnet id will be assigned their subnet
877 * 2. all those links that remain will receive prefixes in sequential order. Prefixes
878 * that were previously already allocated to another link will be skipped.
879 * The assignment has to be split in two phases since subnet id
880 * preferences should be honored. Meaning that any subnet id should be
881 * handed out to the requesting link and not to some link that didn't
882 * specify any preference. */
884 assert(pd_prefix_len
<= 64);
887 r
= in_addr_mask(AF_INET6
, &prefix
, pd_prefix_len
);
889 return log_link_error_errno(dhcp6_link
, r
, "Failed to mask DHCPv6 PD prefix: %m");
892 uint64_t n_prefixes
= UINT64_C(1) << (64 - pd_prefix_len
);
893 _cleanup_free_
char *buf
= NULL
;
895 (void) in_addr_prefix_to_string(AF_INET6
, &prefix
, pd_prefix_len
, &buf
);
896 log_link_debug(dhcp6_link
, "Assigning up to %" PRIu64
" prefixes from %s",
897 n_prefixes
, strna(buf
));
900 dhcp6_pd_prefix_distribute(dhcp6_link
,
907 dhcp6_pd_prefix_distribute(dhcp6_link
,
915 HASHMAP_FOREACH(link
, dhcp6_link
->manager
->links
) {
916 if (link
== dhcp6_link
)
919 r
= dhcp6_pd_finalize(link
);
921 link_enter_failed(link
);
927 static int dhcp6_address_handler(sd_netlink
*rtnl
, sd_netlink_message
*m
, Link
*link
) {
931 assert(link
->dhcp6_address_messages
> 0);
933 link
->dhcp6_address_messages
--;
935 if (IN_SET(link
->state
, LINK_STATE_FAILED
, LINK_STATE_LINGER
))
938 r
= sd_netlink_message_get_errno(m
);
939 if (r
< 0 && r
!= -EEXIST
) {
940 log_link_message_warning_errno(link
, m
, r
, "Could not set DHCPv6 address");
941 link_enter_failed(link
);
944 (void) manager_rtnl_process_address(rtnl
, m
, link
->manager
);
946 if (link
->dhcp6_address_messages
== 0) {
947 log_link_debug(link
, "DHCPv6 addresses set");
948 link
->dhcp6_address_configured
= true;
950 r
= dhcp6_remove_old(link
, false);
952 link_enter_failed(link
);
960 static void log_dhcp6_address(Link
*link
, const Address
*address
, char **ret
) {
961 char valid_buf
[FORMAT_TIMESPAN_MAX
], preferred_buf
[FORMAT_TIMESPAN_MAX
];
962 const char *valid_str
= NULL
, *preferred_str
= NULL
;
963 _cleanup_free_
char *buffer
= NULL
;
964 bool by_ndisc
= false;
972 (void) in_addr_prefix_to_string(address
->family
, &address
->in_addr
, address
->prefixlen
, &buffer
);
973 if (address
->cinfo
.ifa_valid
!= CACHE_INFO_INFINITY_LIFE_TIME
)
974 valid_str
= format_timespan(valid_buf
, FORMAT_TIMESPAN_MAX
,
975 address
->cinfo
.ifa_valid
* USEC_PER_SEC
,
977 if (address
->cinfo
.ifa_prefered
!= CACHE_INFO_INFINITY_LIFE_TIME
)
978 preferred_str
= format_timespan(preferred_buf
, FORMAT_TIMESPAN_MAX
,
979 address
->cinfo
.ifa_prefered
* USEC_PER_SEC
,
982 r
= address_get(link
, address
, &existing
);
985 log_level
= LOG_INFO
;
988 log_level
= LOG_DEBUG
;
990 if (set_contains(link
->dhcp6_addresses
, address
))
991 /* Already warned. */
994 if (address
->prefixlen
== existing
->prefixlen
)
995 /* Currently, only conflict in prefix length is reported. */
998 SET_FOREACH(na
, link
->ndisc_addresses
)
999 if (address_compare_func(na
->address
, existing
)) {
1004 log_link_warning(link
, "DHCPv6 address %s (valid %s%s, preferred %s%s) conflicts the existing address %s %s.",
1006 valid_str
? "for " : "forever", strempty(valid_str
),
1007 preferred_str
? "for " : "forever", strempty(preferred_str
),
1009 by_ndisc
? "assigned by NDISC. Please try to use or update IPv6Token= setting "
1010 "to change the address generated by NDISC, or disable UseAutonomousPrefix=" : "");
1014 log_link_full(link
, log_level
, "DHCPv6 address %s (valid %s%s, preferred %s%s)",
1016 valid_str
? "for " : "forever", strempty(valid_str
),
1017 preferred_str
? "for " : "forever", strempty(preferred_str
));
1021 *ret
= TAKE_PTR(buffer
);
1024 static int dhcp6_update_address(
1026 const struct in6_addr
*ip6_addr
,
1027 uint32_t lifetime_preferred
,
1028 uint32_t lifetime_valid
) {
1030 _cleanup_(address_freep
) Address
*addr
= NULL
;
1031 _cleanup_free_
char *buffer
= NULL
;
1035 r
= address_new(&addr
);
1039 addr
->family
= AF_INET6
;
1040 addr
->in_addr
.in6
= *ip6_addr
;
1041 addr
->flags
= IFA_F_NOPREFIXROUTE
;
1042 addr
->prefixlen
= 128;
1043 addr
->cinfo
.ifa_prefered
= lifetime_preferred
;
1044 addr
->cinfo
.ifa_valid
= lifetime_valid
;
1046 log_dhcp6_address(link
, addr
, &buffer
);
1048 r
= address_configure(addr
, link
, dhcp6_address_handler
, &ret
);
1050 return log_link_error_errno(link
, r
, "Failed to set DHCPv6 address %s: %m", strna(buffer
));
1052 link
->dhcp6_address_configured
= false;
1054 link
->dhcp6_address_messages
++;
1056 r
= set_ensure_put(&link
->dhcp6_addresses
, &address_hash_ops
, ret
);
1058 return log_link_error_errno(link
, r
, "Failed to store DHCPv6 address %s: %m", strna(buffer
));
1060 (void) set_remove(link
->dhcp6_addresses_old
, ret
);
1065 static int dhcp6_address_acquired(Link
*link
) {
1069 assert(link
->network
);
1070 assert(link
->dhcp6_lease
);
1072 if (!link
->network
->dhcp6_use_address
)
1075 for (sd_dhcp6_lease_reset_address_iter(link
->dhcp6_lease
);;) {
1076 uint32_t lifetime_preferred
, lifetime_valid
;
1077 struct in6_addr ip6_addr
;
1079 r
= sd_dhcp6_lease_get_address(link
->dhcp6_lease
, &ip6_addr
, &lifetime_preferred
, &lifetime_valid
);
1083 r
= dhcp6_update_address(link
, &ip6_addr
, lifetime_preferred
, lifetime_valid
);
1088 if (link
->network
->dhcp6_use_hostname
) {
1089 const char *dhcpname
= NULL
;
1090 _cleanup_free_
char *hostname
= NULL
;
1092 (void) sd_dhcp6_lease_get_fqdn(link
->dhcp6_lease
, &dhcpname
);
1095 r
= shorten_overlong(dhcpname
, &hostname
);
1097 log_link_warning_errno(link
, r
, "Unable to shorten overlong DHCP hostname '%s', ignoring: %m", dhcpname
);
1099 log_link_notice(link
, "Overlong DHCP hostname received, shortened from '%s' to '%s'", dhcpname
, hostname
);
1102 r
= manager_set_hostname(link
->manager
, hostname
);
1104 log_link_error_errno(link
, r
, "Failed to set transient hostname to '%s': %m", hostname
);
1111 static int dhcp6_lease_ip_acquired(sd_dhcp6_client
*client
, Link
*link
) {
1112 _cleanup_(sd_dhcp6_lease_unrefp
) sd_dhcp6_lease
*lease_old
= NULL
;
1113 sd_dhcp6_lease
*lease
;
1118 while ((a
= set_steal_first(link
->dhcp6_addresses
))) {
1119 r
= set_ensure_put(&link
->dhcp6_addresses_old
, &address_hash_ops
, a
);
1121 return log_link_error_errno(link
, r
, "Failed to store old DHCPv6 address: %m");
1124 while ((rt
= set_steal_first(link
->dhcp6_routes
))) {
1125 r
= set_ensure_put(&link
->dhcp6_routes_old
, &route_hash_ops
, rt
);
1127 return log_link_error_errno(link
, r
, "Failed to store old DHCPv6 route: %m");
1130 r
= sd_dhcp6_client_get_lease(client
, &lease
);
1132 return log_link_error_errno(link
, r
, "Failed to get DHCPv6 lease: %m");
1134 lease_old
= TAKE_PTR(link
->dhcp6_lease
);
1135 link
->dhcp6_lease
= sd_dhcp6_lease_ref(lease
);
1137 r
= dhcp6_address_acquired(link
);
1141 if (dhcp6_lease_has_pd_prefix(lease
)) {
1142 r
= dhcp6_pd_prefix_acquired(link
);
1145 } else if (dhcp6_lease_has_pd_prefix(lease_old
))
1146 /* When we had PD prefixes but not now, we need to remove them. */
1147 dhcp6_pd_prefix_lost(link
);
1149 if (link
->dhcp6_address_messages
== 0)
1150 link
->dhcp6_address_configured
= true;
1152 log_link_debug(link
, "Setting DHCPv6 addresses");
1154 if (link
->dhcp6_route_messages
== 0)
1155 link
->dhcp6_route_configured
= true;
1157 log_link_debug(link
, "Setting unreachable routes for DHCPv6 delegated subnets");
1159 r
= dhcp6_remove_old(link
, false);
1163 if (link
->dhcp6_address_configured
&& link
->dhcp6_route_configured
)
1164 link_check_ready(link
);
1166 link_set_state(link
, LINK_STATE_CONFIGURING
);
1171 static int dhcp6_lease_information_acquired(sd_dhcp6_client
*client
, Link
*link
) {
1175 static int dhcp6_lease_lost(Link
*link
) {
1179 assert(link
->manager
);
1181 log_link_info(link
, "DHCPv6 lease lost");
1183 if (dhcp6_lease_has_pd_prefix(link
->dhcp6_lease
))
1184 dhcp6_pd_prefix_lost(link
);
1186 link
->dhcp6_lease
= sd_dhcp6_lease_unref(link
->dhcp6_lease
);
1188 r
= dhcp6_remove(link
);
1195 static void dhcp6_handler(sd_dhcp6_client
*client
, int event
, void *userdata
) {
1196 Link
*link
= userdata
;
1200 assert(link
->network
);
1202 if (IN_SET(link
->state
, LINK_STATE_FAILED
, LINK_STATE_LINGER
))
1206 case SD_DHCP6_CLIENT_EVENT_STOP
:
1207 case SD_DHCP6_CLIENT_EVENT_RESEND_EXPIRE
:
1208 case SD_DHCP6_CLIENT_EVENT_RETRANS_MAX
:
1209 r
= dhcp6_lease_lost(link
);
1211 link_enter_failed(link
);
1214 case SD_DHCP6_CLIENT_EVENT_IP_ACQUIRE
:
1215 r
= dhcp6_lease_ip_acquired(client
, link
);
1217 link_enter_failed(link
);
1222 case SD_DHCP6_CLIENT_EVENT_INFORMATION_REQUEST
:
1223 r
= dhcp6_lease_information_acquired(client
, link
);
1225 link_enter_failed(link
);
1230 log_link_warning_errno(link
, event
, "DHCPv6 error: %m");
1232 log_link_warning(link
, "DHCPv6 unknown event: %d", event
);
1237 int dhcp6_request_address(Link
*link
, int ir
) {
1242 assert(link
->dhcp6_client
);
1243 assert(link
->network
);
1244 assert(in6_addr_is_link_local(&link
->ipv6ll_address
));
1246 r
= sd_dhcp6_client_is_running(link
->dhcp6_client
);
1251 r
= sd_dhcp6_client_get_prefix_delegation(link
->dhcp6_client
, &pd
);
1255 if (pd
&& ir
&& link
->network
->dhcp6_force_pd_other_information
) {
1256 log_link_debug(link
, "Enabling managed mode to request DHCPv6 PD with 'Other Information' set");
1258 r
= sd_dhcp6_client_set_address_request(link
->dhcp6_client
, false);
1266 r
= sd_dhcp6_client_get_information_request(link
->dhcp6_client
, &inf_req
);
1273 r
= sd_dhcp6_client_stop(link
->dhcp6_client
);
1277 r
= sd_dhcp6_client_set_local_address(link
->dhcp6_client
, &link
->ipv6ll_address
);
1282 r
= sd_dhcp6_client_set_information_request(link
->dhcp6_client
, ir
);
1286 r
= sd_dhcp6_client_start(link
->dhcp6_client
);
1293 int dhcp6_request_prefix_delegation(Link
*link
) {
1297 assert(link
->manager
);
1299 if (!link_dhcp6_pd_is_enabled(link
))
1302 log_link_debug(link
, "Requesting DHCPv6 prefixes to be delegated for new link");
1304 HASHMAP_FOREACH(l
, link
->manager
->links
) {
1310 if (!l
->dhcp6_client
)
1313 r
= sd_dhcp6_client_get_prefix_delegation(l
->dhcp6_client
, &enabled
);
1315 log_link_warning_errno(l
, r
, "Cannot get prefix delegation when adding new link: %m");
1316 link_enter_failed(l
);
1321 r
= sd_dhcp6_client_set_prefix_delegation(l
->dhcp6_client
, 1);
1323 log_link_warning_errno(l
, r
, "Cannot enable prefix delegation when adding new link: %m");
1324 link_enter_failed(l
);
1329 r
= sd_dhcp6_client_is_running(l
->dhcp6_client
);
1334 if (dhcp6_lease_has_pd_prefix(l
->dhcp6_lease
)) {
1335 log_link_debug(l
, "Requesting re-assignment of delegated prefixes after adding new link");
1336 r
= dhcp6_pd_prefix_acquired(l
);
1338 link_enter_failed(l
);
1343 r
= sd_dhcp6_client_stop(l
->dhcp6_client
);
1345 log_link_warning_errno(l
, r
, "Cannot stop DHCPv6 prefix delegation client after adding new link: %m");
1346 link_enter_failed(l
);
1350 r
= sd_dhcp6_client_start(l
->dhcp6_client
);
1352 log_link_warning_errno(l
, r
, "Cannot restart DHCPv6 prefix delegation client after adding new link: %m");
1353 link_enter_failed(l
);
1357 log_link_debug(l
, "Restarted DHCPv6 client to acquire prefix delegations after adding new link");
1360 /* dhcp6_pd_prefix_acquired() may make the link in failed state. */
1361 if (link
->state
== LINK_STATE_FAILED
)
1367 static int dhcp6_set_hostname(sd_dhcp6_client
*client
, Link
*link
) {
1368 _cleanup_free_
char *hostname
= NULL
;
1374 if (!link
->network
->dhcp_send_hostname
)
1376 else if (link
->network
->dhcp_hostname
)
1377 hn
= link
->network
->dhcp_hostname
;
1379 r
= gethostname_strict(&hostname
);
1380 if (r
< 0 && r
!= -ENXIO
) /* ENXIO: no hostname set or hostname is "localhost" */
1386 r
= sd_dhcp6_client_set_fqdn(client
, hn
);
1387 if (r
== -EINVAL
&& hostname
)
1388 /* Ignore error when the machine's hostname is not suitable to send in DHCP packet. */
1389 log_link_warning_errno(link
, r
, "DHCP6 CLIENT: Failed to set hostname from kernel hostname, ignoring: %m");
1391 return log_link_error_errno(link
, r
, "DHCP6 CLIENT: Failed to set hostname: %m");
1396 static bool dhcp6_enable_prefix_delegation(Link
*dhcp6_link
) {
1400 assert(dhcp6_link
->manager
);
1402 HASHMAP_FOREACH(link
, dhcp6_link
->manager
->links
) {
1403 if (link
== dhcp6_link
)
1406 if (!link_dhcp6_pd_is_enabled(link
))
1415 static int dhcp6_set_identifier(Link
*link
, sd_dhcp6_client
*client
) {
1420 assert(link
->network
);
1423 r
= sd_dhcp6_client_set_mac(client
, link
->hw_addr
.addr
.bytes
, link
->hw_addr
.length
, link
->iftype
);
1427 if (link
->network
->dhcp6_iaid_set
) {
1428 r
= sd_dhcp6_client_set_iaid(client
, link
->network
->dhcp6_iaid
);
1433 duid
= link_get_dhcp6_duid(link
);
1434 if (duid
->type
== DUID_TYPE_LLT
&& duid
->raw_data_len
== 0)
1435 r
= sd_dhcp6_client_set_duid_llt(client
, duid
->llt_time
);
1437 r
= sd_dhcp6_client_set_duid(client
,
1439 duid
->raw_data_len
> 0 ? duid
->raw_data
: NULL
,
1440 duid
->raw_data_len
);
1447 int dhcp6_configure(Link
*link
) {
1448 _cleanup_(sd_dhcp6_client_unrefp
) sd_dhcp6_client
*client
= NULL
;
1449 sd_dhcp6_option
*vendor_option
;
1450 sd_dhcp6_option
*send_option
;
1451 void *request_options
;
1455 assert(link
->network
);
1457 if (!link_dhcp6_enabled(link
) && !link_ipv6_accept_ra_enabled(link
))
1460 if (link
->dhcp6_client
)
1463 r
= sd_dhcp6_client_new(&client
);
1467 return log_link_error_errno(link
, r
, "DHCP6 CLIENT: Failed to create DHCP6 client: %m");
1469 r
= sd_dhcp6_client_attach_event(client
, link
->manager
->event
, 0);
1471 return log_link_error_errno(link
, r
, "DHCP6 CLIENT: Failed to attach event: %m");
1473 r
= dhcp6_set_identifier(link
, client
);
1475 return log_link_error_errno(link
, r
, "DHCP6 CLIENT: Failed to set identifier: %m");
1477 ORDERED_HASHMAP_FOREACH(send_option
, link
->network
->dhcp6_client_send_options
) {
1478 r
= sd_dhcp6_client_add_option(client
, send_option
);
1482 return log_link_error_errno(link
, r
, "DHCP6 CLIENT: Failed to set option: %m");
1485 r
= dhcp6_set_hostname(client
, link
);
1489 r
= sd_dhcp6_client_set_ifindex(client
, link
->ifindex
);
1491 return log_link_error_errno(link
, r
, "DHCP6 CLIENT: Failed to set ifindex: %m");
1493 if (link
->network
->dhcp6_rapid_commit
) {
1494 r
= sd_dhcp6_client_set_request_option(client
, SD_DHCP6_OPTION_RAPID_COMMIT
);
1496 return log_link_error_errno(link
, r
, "DHCP6 CLIENT: Failed to set request flag for rapid commit: %m");
1499 if (link
->network
->dhcp6_mudurl
) {
1500 r
= sd_dhcp6_client_set_request_mud_url(client
, link
->network
->dhcp6_mudurl
);
1502 return log_link_error_errno(link
, r
, "DHCP6 CLIENT: Failed to set MUD URL: %m");
1505 SET_FOREACH(request_options
, link
->network
->dhcp6_request_options
) {
1506 uint32_t option
= PTR_TO_UINT32(request_options
);
1508 r
= sd_dhcp6_client_set_request_option(client
, option
);
1510 log_link_debug(link
, "DHCP6 CLIENT: Failed to set request flag for '%u' already exists, ignoring.", option
);
1514 return log_link_error_errno(link
, r
, "DHCP6 CLIENT: Failed to set request flag for '%u': %m", option
);
1517 if (link
->network
->dhcp6_user_class
) {
1518 r
= sd_dhcp6_client_set_request_user_class(client
, link
->network
->dhcp6_user_class
);
1520 return log_link_error_errno(link
, r
, "DHCP6 CLIENT: Failed to set user class: %m");
1523 if (link
->network
->dhcp6_vendor_class
) {
1524 r
= sd_dhcp6_client_set_request_vendor_class(client
, link
->network
->dhcp6_vendor_class
);
1526 return log_link_error_errno(link
, r
, "DHCP6 CLIENT: Failed to set vendor class: %m");
1529 ORDERED_HASHMAP_FOREACH(vendor_option
, link
->network
->dhcp6_client_send_vendor_options
) {
1530 r
= sd_dhcp6_client_add_vendor_option(client
, vendor_option
);
1534 return log_link_error_errno(link
, r
, "DHCP6 CLIENT: Failed to set vendor option: %m");
1537 r
= sd_dhcp6_client_set_callback(client
, dhcp6_handler
, link
);
1539 return log_link_error_errno(link
, r
, "DHCP6 CLIENT: Failed to set callback: %m");
1541 if (dhcp6_enable_prefix_delegation(link
)) {
1542 r
= sd_dhcp6_client_set_prefix_delegation(client
, true);
1544 return log_link_error_errno(link
, r
, "DHCP6 CLIENT: Failed to set prefix delegation: %m");
1547 if (link
->network
->dhcp6_pd_length
> 0) {
1548 r
= sd_dhcp6_client_set_prefix_delegation_hint(client
, link
->network
->dhcp6_pd_length
, &link
->network
->dhcp6_pd_address
);
1550 return log_link_error_errno(link
, r
, "DHCP6 CLIENT: Failed to set prefix hint: %m");
1553 link
->dhcp6_client
= TAKE_PTR(client
);
1558 int dhcp6_update_mac(Link
*link
) {
1564 if (!link
->dhcp6_client
)
1567 restart
= sd_dhcp6_client_is_running(link
->dhcp6_client
) > 0;
1570 r
= sd_dhcp6_client_stop(link
->dhcp6_client
);
1575 r
= dhcp6_set_identifier(link
, link
->dhcp6_client
);
1580 r
= sd_dhcp6_client_start(link
->dhcp6_client
);
1582 return log_link_warning_errno(link
, r
, "Could not restart DHCPv6 client: %m");
1588 int link_serialize_dhcp6_client(Link
*link
, FILE *f
) {
1589 _cleanup_free_
char *duid
= NULL
;
1595 if (!link
->dhcp6_client
)
1598 r
= sd_dhcp6_client_get_iaid(link
->dhcp6_client
, &iaid
);
1600 fprintf(f
, "DHCP6_CLIENT_IAID=0x%x\n", iaid
);
1602 r
= sd_dhcp6_client_duid_as_string(link
->dhcp6_client
, &duid
);
1604 fprintf(f
, "DHCP6_CLIENT_DUID=%s\n", duid
);
1609 int config_parse_dhcp6_pd_hint(
1611 const char *filename
,
1613 const char *section
,
1614 unsigned section_line
,
1621 Network
*network
= data
;
1622 union in_addr_union u
;
1623 unsigned char prefixlen
;
1631 r
= in_addr_prefix_from_string(rvalue
, AF_INET6
, &u
, &prefixlen
);
1633 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1634 "Failed to parse %s=%s, ignoring assignment.", lvalue
, rvalue
);
1638 if (prefixlen
< 1 || prefixlen
> 128) {
1639 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
1640 "Invalid prefix length in %s=%s, ignoring assignment.", lvalue
, rvalue
);
1644 network
->dhcp6_pd_address
= u
.in6
;
1645 network
->dhcp6_pd_length
= prefixlen
;
1650 int config_parse_dhcp6_mud_url(
1652 const char *filename
,
1654 const char *section
,
1655 unsigned section_line
,
1662 _cleanup_free_
char *unescaped
= NULL
;
1663 Network
*network
= data
;
1670 if (isempty(rvalue
)) {
1671 network
->dhcp6_mudurl
= mfree(network
->dhcp6_mudurl
);
1675 r
= cunescape(rvalue
, 0, &unescaped
);
1677 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1678 "Failed to Failed to unescape MUD URL, ignoring: %s", rvalue
);
1682 if (!http_url_is_valid(unescaped
) || strlen(unescaped
) > UINT8_MAX
) {
1683 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
1684 "Failed to parse MUD URL '%s', ignoring: %m", rvalue
);
1688 return free_and_replace(network
->dhcp6_mudurl
, unescaped
);
1691 DEFINE_CONFIG_PARSE_ENUM(config_parse_dhcp6_client_start_mode
, dhcp6_client_start_mode
, DHCP6ClientStartMode
,
1692 "Failed to parse WithoutRA= setting");
1694 static const char* const dhcp6_client_start_mode_table
[_DHCP6_CLIENT_START_MODE_MAX
] = {
1695 [DHCP6_CLIENT_START_MODE_NO
] = "no",
1696 [DHCP6_CLIENT_START_MODE_INFORMATION_REQUEST
] = "information-request",
1697 [DHCP6_CLIENT_START_MODE_SOLICIT
] = "solicit",
1700 DEFINE_STRING_TABLE_LOOKUP(dhcp6_client_start_mode
, DHCP6ClientStartMode
);
1702 int config_parse_dhcp6_pd_subnet_id(
1704 const char *filename
,
1706 const char *section
,
1707 unsigned section_line
,
1723 if (isempty(rvalue
) || streq(rvalue
, "auto")) {
1728 r
= safe_atoux64(rvalue
, &t
);
1730 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1731 "Failed to parse %s=, ignoring assignment: %s",
1735 if (t
> INT64_MAX
) {
1736 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
1737 "Invalid subnet id '%s', ignoring assignment.",
1747 int config_parse_dhcp6_pd_token(
1749 const char *filename
,
1751 const char *section
,
1752 unsigned section_line
,
1759 union in_addr_union
*addr
= data
, tmp
;
1767 if (isempty(rvalue
)) {
1768 *addr
= IN_ADDR_NULL
;
1772 r
= in_addr_from_string(AF_INET6
, rvalue
, &tmp
);
1774 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1775 "Failed to parse DHCPv6 Prefix Delegation token, ignoring: %s", rvalue
);
1779 if (in_addr_is_null(AF_INET6
, &tmp
)) {
1780 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
1781 "DHCPv6 Prefix Delegation token cannot be the ANY address, ignoring: %s", rvalue
);