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_pd_is_enabled(Link
*link
) {
34 return link
->network
->dhcp6_pd
;
37 static bool dhcp6_lease_has_pd_prefix(sd_dhcp6_lease
*lease
) {
38 uint32_t lifetime_preferred
, lifetime_valid
;
39 union in_addr_union pd_prefix
;
40 uint8_t pd_prefix_len
;
45 sd_dhcp6_lease_reset_pd_prefix_iter(lease
);
47 return sd_dhcp6_lease_get_pd(lease
, &pd_prefix
.in6
, &pd_prefix_len
, &lifetime_preferred
, &lifetime_valid
) >= 0;
50 DHCP6DelegatedPrefix
*dhcp6_pd_free(DHCP6DelegatedPrefix
*p
) {
54 if (p
->link
&& p
->link
->manager
) {
55 hashmap_remove(p
->link
->manager
->dhcp6_prefixes
, &p
->prefix
);
56 set_remove(p
->link
->manager
->dhcp6_pd_prefixes
, p
);
63 static void dhcp6_pd_hash_func(const DHCP6DelegatedPrefix
*p
, struct siphash
*state
) {
66 siphash24_compress(&p
->pd_prefix
, sizeof(p
->pd_prefix
), state
);
67 siphash24_compress(&p
->link
, sizeof(p
->link
), state
);
70 static int dhcp6_pd_compare_func(const DHCP6DelegatedPrefix
*a
, const DHCP6DelegatedPrefix
*b
) {
73 r
= memcmp(&a
->pd_prefix
, &b
->pd_prefix
, sizeof(a
->pd_prefix
));
77 return CMP(a
->link
, b
->link
);
80 DEFINE_HASH_OPS(dhcp6_pd_hash_ops
, DHCP6DelegatedPrefix
, dhcp6_pd_hash_func
, dhcp6_pd_compare_func
);
82 static Link
*dhcp6_pd_get_link_by_prefix(Link
*link
, const union in_addr_union
*prefix
) {
83 DHCP6DelegatedPrefix
*pd
;
86 assert(link
->manager
);
89 pd
= hashmap_get(link
->manager
->dhcp6_prefixes
, &prefix
->in6
);
96 static int dhcp6_pd_get_assigned_prefix(Link
*link
, const union in_addr_union
*pd_prefix
, union in_addr_union
*ret_prefix
) {
97 DHCP6DelegatedPrefix
*pd
, in
;
100 assert(link
->manager
);
104 in
= (DHCP6DelegatedPrefix
) {
105 .pd_prefix
= pd_prefix
->in6
,
109 pd
= set_get(link
->manager
->dhcp6_pd_prefixes
, &in
);
113 ret_prefix
->in6
= pd
->prefix
;
117 static int dhcp6_pd_remove_old(Link
*link
, bool force
);
119 static int dhcp6_pd_address_callback(Address
*address
) {
123 assert(address
->link
);
125 /* Make this called only once */
126 SET_FOREACH(a
, address
->link
->dhcp6_pd_addresses
)
129 return dhcp6_pd_remove_old(address
->link
, true);
132 static int dhcp6_pd_remove_old(Link
*link
, bool force
) {
138 assert(link
->manager
);
140 if (!force
&& (link
->dhcp6_pd_address_messages
!= 0 || link
->dhcp6_pd_route_messages
!= 0))
143 if (set_isempty(link
->dhcp6_pd_addresses_old
) && set_isempty(link
->dhcp6_pd_routes_old
))
147 bool set_callback
= !set_isempty(link
->dhcp6_pd_addresses
);
149 SET_FOREACH(address
, link
->dhcp6_pd_addresses
)
150 if (address_is_ready(address
)) {
151 set_callback
= false;
156 SET_FOREACH(address
, link
->dhcp6_pd_addresses
)
157 address
->callback
= dhcp6_pd_address_callback
;
162 log_link_debug(link
, "Removing old DHCPv6 Prefix Delegation addresses and routes.");
164 SET_FOREACH(route
, link
->dhcp6_pd_routes_old
) {
165 k
= route_remove(route
, NULL
, link
, NULL
);
170 (void) sd_radv_remove_prefix(link
->radv
, &route
->dst
.in6
, 64);
171 dhcp6_pd_free(hashmap_get(link
->manager
->dhcp6_prefixes
, &route
->dst
.in6
));
174 SET_FOREACH(address
, link
->dhcp6_pd_addresses_old
) {
175 k
= address_remove(address
, link
, NULL
);
183 int dhcp6_pd_remove(Link
*link
) {
189 assert(link
->manager
);
191 if (!link_dhcp6_pd_is_enabled(link
))
194 link
->dhcp6_pd_address_configured
= false;
195 link
->dhcp6_pd_route_configured
= false;
197 k
= dhcp6_pd_remove_old(link
, true);
201 if (set_isempty(link
->dhcp6_pd_addresses
) && set_isempty(link
->dhcp6_pd_routes
))
204 log_link_debug(link
, "Removing DHCPv6 Prefix Delegation addresses and routes.");
206 SET_FOREACH(route
, link
->dhcp6_pd_routes
) {
207 k
= route_remove(route
, NULL
, link
, NULL
);
212 (void) sd_radv_remove_prefix(link
->radv
, &route
->dst
.in6
, 64);
213 dhcp6_pd_free(hashmap_get(link
->manager
->dhcp6_prefixes
, &route
->dst
.in6
));
216 SET_FOREACH(address
, link
->dhcp6_pd_addresses
) {
217 k
= address_remove(address
, link
, NULL
);
225 static int dhcp6_pd_route_handler(sd_netlink
*nl
, sd_netlink_message
*m
, Link
*link
) {
229 assert(link
->dhcp6_pd_route_messages
> 0);
231 link
->dhcp6_pd_route_messages
--;
233 if (IN_SET(link
->state
, LINK_STATE_FAILED
, LINK_STATE_LINGER
))
236 r
= sd_netlink_message_get_errno(m
);
237 if (r
< 0 && r
!= -EEXIST
) {
238 log_link_message_warning_errno(link
, m
, r
, "Failed to add DHCPv6 Prefix Delegation route");
239 link_enter_failed(link
);
243 if (link
->dhcp6_pd_route_messages
== 0) {
244 log_link_debug(link
, "DHCPv6 prefix delegation routes set");
245 if (link
->dhcp6_pd_prefixes_assigned
)
246 link
->dhcp6_pd_route_configured
= true;
248 r
= dhcp6_pd_remove_old(link
, false);
250 link_enter_failed(link
);
254 link_check_ready(link
);
260 static int dhcp6_set_pd_route(Link
*link
, const union in_addr_union
*prefix
, const union in_addr_union
*pd_prefix
) {
261 _cleanup_(dhcp6_pd_freep
) DHCP6DelegatedPrefix
*pd
= NULL
;
262 _cleanup_(route_freep
) Route
*route
= NULL
;
268 assert(link
->manager
);
272 r
= route_new(&route
);
276 route
->family
= AF_INET6
;
277 route
->dst
= *prefix
;
278 route
->dst_prefixlen
= 64;
279 route
->protocol
= RTPROT_DHCP
;
281 r
= route_configure(route
, link
, dhcp6_pd_route_handler
, &ret
);
283 return log_link_error_errno(link
, r
, "Failed to set DHCPv6 prefix route: %m");
285 link
->dhcp6_pd_route_configured
= false;
287 link
->dhcp6_pd_route_messages
++;
289 r
= set_ensure_put(&link
->dhcp6_pd_routes
, &route_hash_ops
, ret
);
291 return log_link_error_errno(link
, r
, "Failed to store DHCPv6 prefix route: %m");
293 (void) set_remove(link
->dhcp6_pd_routes_old
, ret
);
295 assigned_link
= dhcp6_pd_get_link_by_prefix(link
, prefix
);
297 assert(assigned_link
== link
);
301 pd
= new(DHCP6DelegatedPrefix
, 1);
305 *pd
= (DHCP6DelegatedPrefix
) {
306 .prefix
= prefix
->in6
,
307 .pd_prefix
= pd_prefix
->in6
,
308 .link
= link_ref(link
),
311 r
= hashmap_ensure_put(&link
->manager
->dhcp6_prefixes
, &in6_addr_hash_ops
, &pd
->prefix
, pd
);
315 return log_link_error_errno(link
, r
, "Failed to store DHCPv6 prefix route at manager: %m");
317 r
= set_ensure_put(&link
->manager
->dhcp6_pd_prefixes
, &dhcp6_pd_hash_ops
, pd
);
319 return log_link_error_errno(link
, r
, "Failed to store DHCPv6 prefix route at manager: %m");
325 static int dhcp6_pd_address_handler(sd_netlink
*rtnl
, sd_netlink_message
*m
, Link
*link
) {
329 assert(link
->dhcp6_pd_address_messages
> 0);
331 link
->dhcp6_pd_address_messages
--;
333 if (IN_SET(link
->state
, LINK_STATE_FAILED
, LINK_STATE_LINGER
))
336 r
= sd_netlink_message_get_errno(m
);
337 if (r
< 0 && r
!= -EEXIST
) {
338 log_link_message_warning_errno(link
, m
, r
, "Could not set DHCPv6 delegated prefix address");
339 link_enter_failed(link
);
342 (void) manager_rtnl_process_address(rtnl
, m
, link
->manager
);
344 if (link
->dhcp6_pd_address_messages
== 0) {
345 log_link_debug(link
, "DHCPv6 delegated prefix addresses set");
346 if (link
->dhcp6_pd_prefixes_assigned
)
347 link
->dhcp6_pd_address_configured
= true;
349 r
= dhcp6_pd_remove_old(link
, false);
351 link_enter_failed(link
);
359 static int dhcp6_set_pd_address(
361 const union in_addr_union
*prefix
,
362 uint32_t lifetime_preferred
,
363 uint32_t lifetime_valid
) {
365 _cleanup_(address_freep
) Address
*address
= NULL
;
370 assert(link
->network
);
373 if (!link
->network
->dhcp6_pd_assign
)
376 r
= address_new(&address
);
378 return log_link_error_errno(link
, r
, "Failed to allocate address for DHCPv6 delegated prefix: %m");
380 address
->in_addr
= *prefix
;
382 if (!in_addr_is_null(AF_INET6
, &link
->network
->dhcp6_pd_token
))
383 memcpy(address
->in_addr
.in6
.s6_addr
+ 8, link
->network
->dhcp6_pd_token
.in6
.s6_addr
+ 8, 8);
385 r
= generate_ipv6_eui_64_address(link
, &address
->in_addr
.in6
);
387 return log_link_warning_errno(link
, r
, "Failed to generate EUI64 address for acquired DHCPv6 delegated prefix: %m");
390 address
->prefixlen
= 64;
391 address
->family
= AF_INET6
;
392 address
->cinfo
.ifa_prefered
= lifetime_preferred
;
393 address
->cinfo
.ifa_valid
= lifetime_valid
;
394 SET_FLAG(address
->flags
, IFA_F_MANAGETEMPADDR
, link
->network
->dhcp6_pd_manage_temporary_address
);
396 r
= address_configure(address
, link
, dhcp6_pd_address_handler
, &ret
);
398 return log_link_error_errno(link
, r
, "Failed to set DHCPv6 delegated prefix address: %m");
400 link
->dhcp6_pd_address_configured
= false;
402 link
->dhcp6_pd_address_messages
++;
404 r
= set_ensure_put(&link
->dhcp6_pd_addresses
, &address_hash_ops
, ret
);
406 return log_link_error_errno(link
, r
, "Failed to store DHCPv6 delegated prefix address: %m");
408 (void) set_remove(link
->dhcp6_pd_addresses_old
, ret
);
413 static int dhcp6_pd_assign_prefix(
415 const union in_addr_union
*prefix
,
416 const union in_addr_union
*pd_prefix
,
417 uint32_t lifetime_preferred
,
418 uint32_t lifetime_valid
) {
423 assert(link
->network
);
426 if (link
->network
->dhcp6_pd_announce
) {
427 r
= radv_add_prefix(link
, &prefix
->in6
, 64, lifetime_preferred
, lifetime_valid
);
432 r
= dhcp6_set_pd_route(link
, prefix
, pd_prefix
);
436 r
= dhcp6_set_pd_address(link
, prefix
, lifetime_preferred
, lifetime_valid
);
443 static bool link_has_preferred_subnet_id(Link
*link
) {
447 return link
->network
->dhcp6_pd_subnet_id
>= 0;
450 static int dhcp6_get_preferred_delegated_prefix(
452 const union in_addr_union
*masked_pd_prefix
,
453 uint8_t pd_prefix_len
,
454 union in_addr_union
*ret
) {
456 /* We start off with the original PD prefix we have been assigned and iterate from there */
457 union in_addr_union prefix
;
463 assert(link
->manager
);
464 assert(masked_pd_prefix
);
465 assert(pd_prefix_len
<= 64);
467 n_prefixes
= UINT64_C(1) << (64 - pd_prefix_len
);
468 prefix
= *masked_pd_prefix
;
470 if (link_has_preferred_subnet_id(link
)) {
471 uint64_t subnet_id
= link
->network
->dhcp6_pd_subnet_id
;
473 /* If the link has a preference for a particular subnet id try to allocate that */
474 if (subnet_id
>= n_prefixes
)
475 return log_link_warning_errno(link
, SYNTHETIC_ERRNO(ERANGE
),
476 "subnet id %" PRIu64
" is out of range. Only have %" PRIu64
" subnets.",
477 subnet_id
, n_prefixes
);
479 r
= in_addr_prefix_nth(AF_INET6
, &prefix
, 64, subnet_id
);
481 return log_link_warning_errno(link
, r
,
482 "subnet id %" PRIu64
" is out of range. Only have %" PRIu64
" subnets.",
483 subnet_id
, n_prefixes
);
485 /* Verify that the prefix we did calculate fits in the pd prefix.
486 * This should not fail as we checked the prefix size beforehand */
487 assert_se(in_addr_prefix_covers(AF_INET6
, masked_pd_prefix
, pd_prefix_len
, &prefix
) > 0);
489 assigned_link
= dhcp6_pd_get_link_by_prefix(link
, &prefix
);
490 if (assigned_link
&& assigned_link
!= link
) {
491 _cleanup_free_
char *assigned_buf
= NULL
;
493 (void) in_addr_to_string(AF_INET6
, &prefix
, &assigned_buf
);
494 return log_link_warning_errno(link
, SYNTHETIC_ERRNO(EAGAIN
),
495 "The requested prefix %s is already assigned to another link.",
496 strna(assigned_buf
));
503 for (uint64_t n
= 0; n
< n_prefixes
; n
++) {
504 /* If we do not have an allocation preference just iterate
505 * through the address space and return the first free prefix. */
506 assigned_link
= dhcp6_pd_get_link_by_prefix(link
, &prefix
);
507 if (!assigned_link
|| assigned_link
== link
) {
512 r
= in_addr_prefix_next(AF_INET6
, &prefix
, 64);
514 return log_link_warning_errno(link
, r
, "Can't allocate another prefix. Out of address space?: %m");
517 return log_link_warning_errno(link
, SYNTHETIC_ERRNO(ERANGE
), "Couldn't find a suitable prefix. Ran out of address space.");
520 static void dhcp6_pd_prefix_distribute(Link
*dhcp6_link
,
521 const union in_addr_union
*masked_pd_prefix
,
522 uint8_t pd_prefix_len
,
523 uint32_t lifetime_preferred
,
524 uint32_t lifetime_valid
,
525 bool assign_preferred_subnet_id
) {
531 assert(dhcp6_link
->manager
);
532 assert(masked_pd_prefix
);
533 assert(pd_prefix_len
<= 64);
535 HASHMAP_FOREACH(link
, dhcp6_link
->manager
->links
) {
536 _cleanup_free_
char *assigned_buf
= NULL
;
537 union in_addr_union assigned_prefix
;
539 if (link
== dhcp6_link
)
542 if (!link_dhcp6_pd_is_enabled(link
))
545 if (IN_SET(link
->state
, LINK_STATE_FAILED
, LINK_STATE_LINGER
))
548 if (assign_preferred_subnet_id
!= link_has_preferred_subnet_id(link
))
551 r
= dhcp6_pd_get_assigned_prefix(link
, masked_pd_prefix
, &assigned_prefix
);
553 r
= dhcp6_get_preferred_delegated_prefix(link
, masked_pd_prefix
, pd_prefix_len
, &assigned_prefix
);
555 link
->dhcp6_pd_prefixes_assigned
= false;
560 (void) in_addr_to_string(AF_INET6
, &assigned_prefix
, &assigned_buf
);
561 r
= dhcp6_pd_assign_prefix(link
, &assigned_prefix
, masked_pd_prefix
,
562 lifetime_preferred
, lifetime_valid
);
564 log_link_error_errno(link
, r
, "Unable to assign/update prefix %s/64: %m",
565 strna(assigned_buf
));
566 link_enter_failed(link
);
568 log_link_debug(link
, "Assigned prefix %s/64", strna(assigned_buf
));
572 static int dhcp6_pd_prepare(Link
*link
) {
577 if (IN_SET(link
->state
, LINK_STATE_FAILED
, LINK_STATE_LINGER
))
580 if (!link_dhcp6_pd_is_enabled(link
))
583 link
->dhcp6_pd_prefixes_assigned
= true;
585 while ((address
= set_steal_first(link
->dhcp6_pd_addresses
))) {
586 r
= set_ensure_put(&link
->dhcp6_pd_addresses_old
, &address_hash_ops
, address
);
588 return log_link_error_errno(link
, r
, "Failed to store old DHCPv6 Prefix Delegation address: %m");
591 while ((route
= set_steal_first(link
->dhcp6_pd_routes
))) {
592 r
= set_ensure_put(&link
->dhcp6_pd_routes_old
, &route_hash_ops
, route
);
594 return log_link_error_errno(link
, r
, "Failed to store old DHCPv6 Prefix Delegation route: %m");
600 static int dhcp6_pd_finalize(Link
*link
) {
603 if (IN_SET(link
->state
, LINK_STATE_FAILED
, LINK_STATE_LINGER
))
606 if (!link_dhcp6_pd_is_enabled(link
))
609 if (link
->dhcp6_pd_address_messages
== 0) {
610 if (link
->dhcp6_pd_prefixes_assigned
)
611 link
->dhcp6_pd_address_configured
= true;
613 log_link_debug(link
, "Setting DHCPv6 PD addresses");
615 if (link
->dhcp6_pd_route_messages
== 0) {
616 if (link
->dhcp6_pd_prefixes_assigned
)
617 link
->dhcp6_pd_route_configured
= true;
619 log_link_debug(link
, "Setting DHCPv6 PD routes");
621 r
= dhcp6_pd_remove_old(link
, false);
625 if (link
->dhcp6_pd_address_configured
&& link
->dhcp6_pd_route_configured
)
626 link_check_ready(link
);
628 link_set_state(link
, LINK_STATE_CONFIGURING
);
633 static void dhcp6_pd_prefix_lost(Link
*dhcp6_link
) {
638 assert(dhcp6_link
->manager
);
640 HASHMAP_FOREACH(link
, dhcp6_link
->manager
->links
) {
641 if (link
== dhcp6_link
)
644 r
= dhcp6_pd_remove(link
);
646 link_enter_failed(link
);
650 static int dhcp6_remove_old(Link
*link
, bool force
);
652 static int dhcp6_address_callback(Address
*address
) {
656 assert(address
->link
);
658 /* Make this called only once */
659 SET_FOREACH(a
, address
->link
->dhcp6_addresses
)
662 return dhcp6_remove_old(address
->link
, true);
665 static int dhcp6_remove_old(Link
*link
, bool force
) {
672 if (!force
&& (!link
->dhcp6_address_configured
|| !link
->dhcp6_route_configured
))
675 if (set_isempty(link
->dhcp6_addresses_old
) && set_isempty(link
->dhcp6_routes_old
))
679 bool set_callback
= !set_isempty(link
->dhcp6_addresses
);
681 SET_FOREACH(address
, link
->dhcp6_addresses
)
682 if (address_is_ready(address
)) {
683 set_callback
= false;
688 SET_FOREACH(address
, link
->dhcp6_addresses
)
689 address
->callback
= dhcp6_address_callback
;
694 log_link_debug(link
, "Removing old DHCPv6 addresses and routes.");
696 SET_FOREACH(route
, link
->dhcp6_routes_old
) {
697 k
= route_remove(route
, NULL
, link
, NULL
);
702 SET_FOREACH(address
, link
->dhcp6_addresses_old
) {
703 k
= address_remove(address
, link
, NULL
);
711 static int dhcp6_remove(Link
*link
) {
718 link
->dhcp6_address_configured
= false;
719 link
->dhcp6_route_configured
= false;
721 k
= dhcp6_remove_old(link
, true);
725 if (set_isempty(link
->dhcp6_addresses
) && set_isempty(link
->dhcp6_routes
))
728 log_link_debug(link
, "Removing DHCPv6 addresses and routes.");
730 SET_FOREACH(route
, link
->dhcp6_routes
) {
731 k
= route_remove(route
, NULL
, link
, NULL
);
736 SET_FOREACH(address
, link
->dhcp6_addresses
) {
737 k
= address_remove(address
, link
, NULL
);
745 static int dhcp6_route_handler(sd_netlink
*nl
, sd_netlink_message
*m
, Link
*link
) {
749 assert(link
->dhcp6_route_messages
> 0);
751 link
->dhcp6_route_messages
--;
753 if (IN_SET(link
->state
, LINK_STATE_FAILED
, LINK_STATE_LINGER
))
756 r
= sd_netlink_message_get_errno(m
);
757 if (r
< 0 && r
!= -EEXIST
) {
758 log_link_message_warning_errno(link
, m
, r
, "Failed to add unreachable route for DHCPv6 delegated subnet");
759 link_enter_failed(link
);
763 if (link
->dhcp6_route_messages
== 0) {
764 log_link_debug(link
, "Unreachable routes for DHCPv6 delegated subnets set");
765 link
->dhcp6_route_configured
= true;
767 r
= dhcp6_remove_old(link
, false);
769 link_enter_failed(link
);
773 link_check_ready(link
);
779 static int dhcp6_set_unreachable_route(Link
*link
, const union in_addr_union
*addr
, uint8_t prefixlen
) {
780 _cleanup_(route_freep
) Route
*route
= NULL
;
781 _cleanup_free_
char *buf
= NULL
;
788 (void) in_addr_to_string(AF_INET6
, addr
, &buf
);
790 if (prefixlen
> 64) {
791 log_link_debug(link
, "PD Prefix length > 64, ignoring prefix %s/%u",
792 strna(buf
), prefixlen
);
796 if (prefixlen
== 64) {
797 log_link_debug(link
, "Not adding a blocking route for DHCPv6 delegated subnet %s/64 since distributed prefix is 64",
803 log_link_warning(link
, "PD Prefix length < 48, looks unusual %s/%u",
804 strna(buf
), prefixlen
);
806 r
= route_new(&route
);
810 route
->family
= AF_INET6
;
812 route
->dst_prefixlen
= prefixlen
;
813 route
->table
= link_get_dhcp_route_table(link
);
814 route
->type
= RTN_UNREACHABLE
;
815 route
->protocol
= RTPROT_DHCP
;
817 r
= route_configure(route
, link
, dhcp6_route_handler
, &ret
);
819 return log_link_error_errno(link
, r
, "Failed to set unreachable route for DHCPv6 delegated subnet %s/%u: %m",
820 strna(buf
), prefixlen
);
822 link
->dhcp6_route_configured
= false;
824 link
->dhcp6_route_messages
++;
826 r
= set_ensure_put(&link
->dhcp6_routes
, &route_hash_ops
, ret
);
828 return log_link_error_errno(link
, r
, "Failed to store unreachable route for DHCPv6 delegated subnet %s/%u: %m",
829 strna(buf
), prefixlen
);
831 (void) set_remove(link
->dhcp6_routes_old
, ret
);
836 static int dhcp6_pd_prefix_acquired(Link
*dhcp6_link
) {
841 assert(dhcp6_link
->dhcp6_lease
);
843 HASHMAP_FOREACH(link
, dhcp6_link
->manager
->links
) {
844 if (link
== dhcp6_link
)
847 r
= dhcp6_pd_prepare(link
);
849 link_enter_failed(link
);
852 for (sd_dhcp6_lease_reset_pd_prefix_iter(dhcp6_link
->dhcp6_lease
);;) {
853 uint32_t lifetime_preferred
, lifetime_valid
;
854 union in_addr_union pd_prefix
, prefix
;
855 uint8_t pd_prefix_len
;
857 r
= sd_dhcp6_lease_get_pd(dhcp6_link
->dhcp6_lease
, &pd_prefix
.in6
, &pd_prefix_len
,
858 &lifetime_preferred
, &lifetime_valid
);
862 r
= dhcp6_set_unreachable_route(dhcp6_link
, &pd_prefix
, pd_prefix_len
);
868 /* We are doing prefix allocation in two steps:
869 * 1. all those links that have a preferred subnet id will be assigned their subnet
870 * 2. all those links that remain will receive prefixes in sequential order. Prefixes
871 * that were previously already allocated to another link will be skipped.
872 * The assignment has to be split in two phases since subnet id
873 * preferences should be honored. Meaning that any subnet id should be
874 * handed out to the requesting link and not to some link that didn't
875 * specify any preference. */
877 assert(pd_prefix_len
<= 64);
880 r
= in_addr_mask(AF_INET6
, &prefix
, pd_prefix_len
);
882 return log_link_error_errno(dhcp6_link
, r
, "Failed to mask DHCPv6 PD prefix: %m");
885 uint64_t n_prefixes
= UINT64_C(1) << (64 - pd_prefix_len
);
886 _cleanup_free_
char *buf
= NULL
;
888 (void) in_addr_to_string(AF_INET6
, &prefix
, &buf
);
889 log_link_debug(dhcp6_link
, "Assigning up to %" PRIu64
" prefixes from %s/%u",
890 n_prefixes
, strna(buf
), pd_prefix_len
);
893 dhcp6_pd_prefix_distribute(dhcp6_link
,
900 dhcp6_pd_prefix_distribute(dhcp6_link
,
908 HASHMAP_FOREACH(link
, dhcp6_link
->manager
->links
) {
909 if (link
== dhcp6_link
)
912 r
= dhcp6_pd_finalize(link
);
914 link_enter_failed(link
);
920 static int dhcp6_address_handler(sd_netlink
*rtnl
, sd_netlink_message
*m
, Link
*link
) {
924 assert(link
->dhcp6_address_messages
> 0);
926 link
->dhcp6_address_messages
--;
928 if (IN_SET(link
->state
, LINK_STATE_FAILED
, LINK_STATE_LINGER
))
931 r
= sd_netlink_message_get_errno(m
);
932 if (r
< 0 && r
!= -EEXIST
) {
933 log_link_message_warning_errno(link
, m
, r
, "Could not set DHCPv6 address");
934 link_enter_failed(link
);
937 (void) manager_rtnl_process_address(rtnl
, m
, link
->manager
);
939 if (link
->dhcp6_address_messages
== 0) {
940 log_link_debug(link
, "DHCPv6 addresses set");
941 link
->dhcp6_address_configured
= true;
943 r
= dhcp6_remove_old(link
, false);
945 link_enter_failed(link
);
953 static void log_dhcp6_address(Link
*link
, const Address
*address
, char **ret
) {
954 char valid_buf
[FORMAT_TIMESPAN_MAX
], preferred_buf
[FORMAT_TIMESPAN_MAX
];
955 const char *valid_str
= NULL
, *preferred_str
= NULL
;
956 _cleanup_free_
char *buffer
= NULL
;
957 bool by_ndisc
= false;
965 (void) in_addr_to_string(address
->family
, &address
->in_addr
, &buffer
);
966 if (address
->cinfo
.ifa_valid
!= CACHE_INFO_INFINITY_LIFE_TIME
)
967 valid_str
= format_timespan(valid_buf
, FORMAT_TIMESPAN_MAX
,
968 address
->cinfo
.ifa_valid
* USEC_PER_SEC
,
970 if (address
->cinfo
.ifa_prefered
!= CACHE_INFO_INFINITY_LIFE_TIME
)
971 preferred_str
= format_timespan(preferred_buf
, FORMAT_TIMESPAN_MAX
,
972 address
->cinfo
.ifa_prefered
* USEC_PER_SEC
,
975 r
= address_get(link
, address
, &existing
);
978 log_level
= LOG_INFO
;
981 log_level
= LOG_DEBUG
;
983 if (set_contains(link
->dhcp6_addresses
, address
))
984 /* Already warned. */
987 if (address
->prefixlen
== existing
->prefixlen
)
988 /* Currently, only conflict in prefix length is reported. */
991 SET_FOREACH(na
, link
->ndisc_addresses
)
992 if (address_compare_func(na
->address
, existing
)) {
997 log_link_warning(link
, "DHCPv6 address %s/%u (valid %s%s, preferred %s%s) conflicts the existing address %s/%u%s.",
998 strnull(buffer
), address
->prefixlen
,
999 valid_str
? "for " : "forever", strempty(valid_str
),
1000 preferred_str
? "for " : "forever", strempty(preferred_str
),
1001 strnull(buffer
), existing
->prefixlen
,
1002 by_ndisc
? "assigned by NDISC. Please try to use or update IPv6Token= setting "
1003 "to change the address generated by NDISC, or disable UseAutonomousPrefix=" : "");
1007 log_link_full(link
, log_level
, "DHCPv6 address %s/%u (valid %s%s, preferred %s%s)",
1008 strnull(buffer
), address
->prefixlen
,
1009 valid_str
? "for " : "forever", strempty(valid_str
),
1010 preferred_str
? "for " : "forever", strempty(preferred_str
));
1014 *ret
= TAKE_PTR(buffer
);
1017 static int dhcp6_update_address(
1019 const struct in6_addr
*ip6_addr
,
1020 uint32_t lifetime_preferred
,
1021 uint32_t lifetime_valid
) {
1023 _cleanup_(address_freep
) Address
*addr
= NULL
;
1024 _cleanup_free_
char *buffer
= NULL
;
1028 r
= address_new(&addr
);
1032 addr
->family
= AF_INET6
;
1033 addr
->in_addr
.in6
= *ip6_addr
;
1034 addr
->flags
= IFA_F_NOPREFIXROUTE
;
1035 addr
->prefixlen
= 128;
1036 addr
->cinfo
.ifa_prefered
= lifetime_preferred
;
1037 addr
->cinfo
.ifa_valid
= lifetime_valid
;
1039 log_dhcp6_address(link
, addr
, &buffer
);
1041 r
= address_configure(addr
, link
, dhcp6_address_handler
, &ret
);
1043 return log_link_error_errno(link
, r
, "Failed to set DHCPv6 address %s/%u: %m",
1044 strnull(buffer
), addr
->prefixlen
);
1046 link
->dhcp6_address_configured
= false;
1048 link
->dhcp6_address_messages
++;
1050 r
= set_ensure_put(&link
->dhcp6_addresses
, &address_hash_ops
, ret
);
1052 return log_link_error_errno(link
, r
, "Failed to store DHCPv6 address %s/%u: %m",
1053 strnull(buffer
), addr
->prefixlen
);
1055 (void) set_remove(link
->dhcp6_addresses_old
, ret
);
1060 static int dhcp6_address_acquired(Link
*link
) {
1064 assert(link
->network
);
1065 assert(link
->dhcp6_lease
);
1067 if (!link
->network
->dhcp6_use_address
)
1070 for (sd_dhcp6_lease_reset_address_iter(link
->dhcp6_lease
);;) {
1071 uint32_t lifetime_preferred
, lifetime_valid
;
1072 struct in6_addr ip6_addr
;
1074 r
= sd_dhcp6_lease_get_address(link
->dhcp6_lease
, &ip6_addr
, &lifetime_preferred
, &lifetime_valid
);
1078 r
= dhcp6_update_address(link
, &ip6_addr
, lifetime_preferred
, lifetime_valid
);
1083 if (link
->network
->dhcp6_use_fqdn
) {
1084 const char *dhcpname
= NULL
;
1085 _cleanup_free_
char *hostname
= NULL
;
1086 (void) sd_dhcp6_lease_get_fqdn(link
->dhcp6_lease
, &dhcpname
);
1089 r
= shorten_overlong(dhcpname
, &hostname
);
1091 log_link_warning_errno(link
, r
, "Unable to shorten overlong DHCP hostname '%s', ignoring: %m", dhcpname
);
1093 log_link_notice(link
, "Overlong DHCP hostname received, shortened from '%s' to '%s'", dhcpname
, hostname
);
1096 r
= manager_set_hostname(link
->manager
, hostname
);
1098 log_link_error_errno(link
, r
, "Failed to set transient hostname to '%s': %m", hostname
);
1105 static int dhcp6_lease_ip_acquired(sd_dhcp6_client
*client
, Link
*link
) {
1106 _cleanup_(sd_dhcp6_lease_unrefp
) sd_dhcp6_lease
*lease_old
= NULL
;
1107 sd_dhcp6_lease
*lease
;
1112 while ((a
= set_steal_first(link
->dhcp6_addresses
))) {
1113 r
= set_ensure_put(&link
->dhcp6_addresses_old
, &address_hash_ops
, a
);
1115 return log_link_error_errno(link
, r
, "Failed to store old DHCPv6 address: %m");
1118 while ((rt
= set_steal_first(link
->dhcp6_routes
))) {
1119 r
= set_ensure_put(&link
->dhcp6_routes_old
, &route_hash_ops
, rt
);
1121 return log_link_error_errno(link
, r
, "Failed to store old DHCPv6 route: %m");
1124 r
= sd_dhcp6_client_get_lease(client
, &lease
);
1126 return log_link_error_errno(link
, r
, "Failed to get DHCPv6 lease: %m");
1128 lease_old
= TAKE_PTR(link
->dhcp6_lease
);
1129 link
->dhcp6_lease
= sd_dhcp6_lease_ref(lease
);
1131 r
= dhcp6_address_acquired(link
);
1135 if (dhcp6_lease_has_pd_prefix(lease
)) {
1136 r
= dhcp6_pd_prefix_acquired(link
);
1139 } else if (dhcp6_lease_has_pd_prefix(lease_old
))
1140 /* When we had PD prefixes but not now, we need to remove them. */
1141 dhcp6_pd_prefix_lost(link
);
1143 if (link
->dhcp6_address_messages
== 0)
1144 link
->dhcp6_address_configured
= true;
1146 log_link_debug(link
, "Setting DHCPv6 addresses");
1148 if (link
->dhcp6_route_messages
== 0)
1149 link
->dhcp6_route_configured
= true;
1151 log_link_debug(link
, "Setting unreachable routes for DHCPv6 delegated subnets");
1153 r
= dhcp6_remove_old(link
, false);
1157 if (link
->dhcp6_address_configured
&& link
->dhcp6_route_configured
)
1158 link_check_ready(link
);
1160 link_set_state(link
, LINK_STATE_CONFIGURING
);
1165 static int dhcp6_lease_information_acquired(sd_dhcp6_client
*client
, Link
*link
) {
1169 static int dhcp6_lease_lost(Link
*link
) {
1173 assert(link
->manager
);
1175 log_link_info(link
, "DHCPv6 lease lost");
1177 if (dhcp6_lease_has_pd_prefix(link
->dhcp6_lease
))
1178 dhcp6_pd_prefix_lost(link
);
1180 link
->dhcp6_lease
= sd_dhcp6_lease_unref(link
->dhcp6_lease
);
1182 r
= dhcp6_remove(link
);
1189 static void dhcp6_handler(sd_dhcp6_client
*client
, int event
, void *userdata
) {
1190 Link
*link
= userdata
;
1194 assert(link
->network
);
1196 if (IN_SET(link
->state
, LINK_STATE_FAILED
, LINK_STATE_LINGER
))
1200 case SD_DHCP6_CLIENT_EVENT_STOP
:
1201 case SD_DHCP6_CLIENT_EVENT_RESEND_EXPIRE
:
1202 case SD_DHCP6_CLIENT_EVENT_RETRANS_MAX
:
1203 r
= dhcp6_lease_lost(link
);
1205 link_enter_failed(link
);
1208 case SD_DHCP6_CLIENT_EVENT_IP_ACQUIRE
:
1209 r
= dhcp6_lease_ip_acquired(client
, link
);
1211 link_enter_failed(link
);
1216 case SD_DHCP6_CLIENT_EVENT_INFORMATION_REQUEST
:
1217 r
= dhcp6_lease_information_acquired(client
, link
);
1219 link_enter_failed(link
);
1224 log_link_warning_errno(link
, event
, "DHCPv6 error: %m");
1226 log_link_warning(link
, "DHCPv6 unknown event: %d", event
);
1231 int dhcp6_request_address(Link
*link
, int ir
) {
1236 assert(link
->dhcp6_client
);
1237 assert(link
->network
);
1238 assert(in_addr_is_link_local(AF_INET6
, (const union in_addr_union
*) &link
->ipv6ll_address
) > 0);
1240 r
= sd_dhcp6_client_is_running(link
->dhcp6_client
);
1245 r
= sd_dhcp6_client_get_prefix_delegation(link
->dhcp6_client
, &pd
);
1249 if (pd
&& ir
&& link
->network
->dhcp6_force_pd_other_information
) {
1250 log_link_debug(link
, "Enabling managed mode to request DHCPv6 PD with 'Other Information' set");
1252 r
= sd_dhcp6_client_set_address_request(link
->dhcp6_client
, false);
1260 r
= sd_dhcp6_client_get_information_request(link
->dhcp6_client
, &inf_req
);
1267 r
= sd_dhcp6_client_stop(link
->dhcp6_client
);
1271 r
= sd_dhcp6_client_set_local_address(link
->dhcp6_client
, &link
->ipv6ll_address
);
1276 r
= sd_dhcp6_client_set_information_request(link
->dhcp6_client
, ir
);
1280 r
= sd_dhcp6_client_start(link
->dhcp6_client
);
1287 int dhcp6_request_prefix_delegation(Link
*link
) {
1291 assert(link
->manager
);
1293 if (!link_dhcp6_pd_is_enabled(link
))
1296 log_link_debug(link
, "Requesting DHCPv6 prefixes to be delegated for new link");
1298 HASHMAP_FOREACH(l
, link
->manager
->links
) {
1304 if (!l
->dhcp6_client
)
1307 r
= sd_dhcp6_client_get_prefix_delegation(l
->dhcp6_client
, &enabled
);
1309 log_link_warning_errno(l
, r
, "Cannot get prefix delegation when adding new link: %m");
1310 link_enter_failed(l
);
1315 r
= sd_dhcp6_client_set_prefix_delegation(l
->dhcp6_client
, 1);
1317 log_link_warning_errno(l
, r
, "Cannot enable prefix delegation when adding new link: %m");
1318 link_enter_failed(l
);
1323 r
= sd_dhcp6_client_is_running(l
->dhcp6_client
);
1328 if (dhcp6_lease_has_pd_prefix(l
->dhcp6_lease
)) {
1329 log_link_debug(l
, "Requesting re-assignment of delegated prefixes after adding new link");
1330 r
= dhcp6_pd_prefix_acquired(l
);
1332 link_enter_failed(l
);
1337 r
= sd_dhcp6_client_stop(l
->dhcp6_client
);
1339 log_link_warning_errno(l
, r
, "Cannot stop DHCPv6 prefix delegation client after adding new link: %m");
1340 link_enter_failed(l
);
1344 r
= sd_dhcp6_client_start(l
->dhcp6_client
);
1346 log_link_warning_errno(l
, r
, "Cannot restart DHCPv6 prefix delegation client after adding new link: %m");
1347 link_enter_failed(l
);
1351 log_link_debug(l
, "Restarted DHCPv6 client to acquire prefix delegations after adding new link");
1354 /* dhcp6_pd_prefix_acquired() may make the link in failed state. */
1355 if (link
->state
== LINK_STATE_FAILED
)
1361 static int dhcp6_set_hostname(sd_dhcp6_client
*client
, Link
*link
) {
1362 _cleanup_free_
char *hostname
= NULL
;
1368 if (!link
->network
->dhcp_send_hostname
)
1370 else if (link
->network
->dhcp_hostname
)
1371 hn
= link
->network
->dhcp_hostname
;
1373 r
= gethostname_strict(&hostname
);
1374 if (r
< 0 && r
!= -ENXIO
) /* ENXIO: no hostname set or hostname is "localhost" */
1380 r
= sd_dhcp6_client_set_fqdn(client
, hn
);
1381 if (r
== -EINVAL
&& hostname
)
1382 /* Ignore error when the machine's hostname is not suitable to send in DHCP packet. */
1383 log_link_warning_errno(link
, r
, "DHCP6 CLIENT: Failed to set hostname from kernel hostname, ignoring: %m");
1385 return log_link_error_errno(link
, r
, "DHCP6 CLIENT: Failed to set hostname: %m");
1390 static bool dhcp6_enable_prefix_delegation(Link
*dhcp6_link
) {
1394 assert(dhcp6_link
->manager
);
1396 HASHMAP_FOREACH(link
, dhcp6_link
->manager
->links
) {
1397 if (link
== dhcp6_link
)
1400 if (!link_dhcp6_pd_is_enabled(link
))
1409 static int dhcp6_set_identifier(Link
*link
, sd_dhcp6_client
*client
) {
1414 assert(link
->network
);
1417 r
= sd_dhcp6_client_set_mac(client
, link
->hw_addr
.addr
.bytes
, link
->hw_addr
.length
, link
->iftype
);
1421 if (link
->network
->iaid_set
) {
1422 r
= sd_dhcp6_client_set_iaid(client
, link
->network
->iaid
);
1427 duid
= link_get_duid(link
);
1428 if (duid
->type
== DUID_TYPE_LLT
&& duid
->raw_data_len
== 0)
1429 r
= sd_dhcp6_client_set_duid_llt(client
, duid
->llt_time
);
1431 r
= sd_dhcp6_client_set_duid(client
,
1433 duid
->raw_data_len
> 0 ? duid
->raw_data
: NULL
,
1434 duid
->raw_data_len
);
1441 int dhcp6_configure(Link
*link
) {
1442 _cleanup_(sd_dhcp6_client_unrefp
) sd_dhcp6_client
*client
= NULL
;
1443 sd_dhcp6_option
*vendor_option
;
1444 sd_dhcp6_option
*send_option
;
1445 void *request_options
;
1449 assert(link
->network
);
1451 if (!link_dhcp6_enabled(link
) && !link_ipv6_accept_ra_enabled(link
))
1454 if (link
->dhcp6_client
)
1457 r
= sd_dhcp6_client_new(&client
);
1461 return log_link_error_errno(link
, r
, "DHCP6 CLIENT: Failed to create DHCP6 client: %m");
1463 r
= sd_dhcp6_client_attach_event(client
, link
->manager
->event
, 0);
1465 return log_link_error_errno(link
, r
, "DHCP6 CLIENT: Failed to attach event: %m");
1467 r
= dhcp6_set_identifier(link
, client
);
1469 return log_link_error_errno(link
, r
, "DHCP6 CLIENT: Failed to set identifier: %m");
1471 ORDERED_HASHMAP_FOREACH(send_option
, link
->network
->dhcp6_client_send_options
) {
1472 r
= sd_dhcp6_client_add_option(client
, send_option
);
1476 return log_link_error_errno(link
, r
, "DHCP6 CLIENT: Failed to set option: %m");
1479 r
= dhcp6_set_hostname(client
, link
);
1483 r
= sd_dhcp6_client_set_ifindex(client
, link
->ifindex
);
1485 return log_link_error_errno(link
, r
, "DHCP6 CLIENT: Failed to set ifindex: %m");
1487 if (link
->network
->dhcp6_rapid_commit
) {
1488 r
= sd_dhcp6_client_set_request_option(client
, SD_DHCP6_OPTION_RAPID_COMMIT
);
1490 return log_link_error_errno(link
, r
, "DHCP6 CLIENT: Failed to set request flag for rapid commit: %m");
1493 if (link
->network
->dhcp6_mudurl
) {
1494 r
= sd_dhcp6_client_set_request_mud_url(client
, link
->network
->dhcp6_mudurl
);
1496 return log_link_error_errno(link
, r
, "DHCP6 CLIENT: Failed to set MUD URL: %m");
1499 SET_FOREACH(request_options
, link
->network
->dhcp6_request_options
) {
1500 uint32_t option
= PTR_TO_UINT32(request_options
);
1502 r
= sd_dhcp6_client_set_request_option(client
, option
);
1504 log_link_debug(link
, "DHCP6 CLIENT: Failed to set request flag for '%u' already exists, ignoring.", option
);
1508 return log_link_error_errno(link
, r
, "DHCP6 CLIENT: Failed to set request flag for '%u': %m", option
);
1511 if (link
->network
->dhcp6_user_class
) {
1512 r
= sd_dhcp6_client_set_request_user_class(client
, link
->network
->dhcp6_user_class
);
1514 return log_link_error_errno(link
, r
, "DHCP6 CLIENT: Failed to set user class: %m");
1517 if (link
->network
->dhcp6_vendor_class
) {
1518 r
= sd_dhcp6_client_set_request_vendor_class(client
, link
->network
->dhcp6_vendor_class
);
1520 return log_link_error_errno(link
, r
, "DHCP6 CLIENT: Failed to set vendor class: %m");
1523 ORDERED_HASHMAP_FOREACH(vendor_option
, link
->network
->dhcp6_client_send_vendor_options
) {
1524 r
= sd_dhcp6_client_add_vendor_option(client
, vendor_option
);
1528 return log_link_error_errno(link
, r
, "DHCP6 CLIENT: Failed to set vendor option: %m");
1531 r
= sd_dhcp6_client_set_callback(client
, dhcp6_handler
, link
);
1533 return log_link_error_errno(link
, r
, "DHCP6 CLIENT: Failed to set callback: %m");
1535 if (dhcp6_enable_prefix_delegation(link
)) {
1536 r
= sd_dhcp6_client_set_prefix_delegation(client
, true);
1538 return log_link_error_errno(link
, r
, "DHCP6 CLIENT: Failed to set prefix delegation: %m");
1541 if (link
->network
->dhcp6_pd_length
> 0) {
1542 r
= sd_dhcp6_client_set_prefix_delegation_hint(client
, link
->network
->dhcp6_pd_length
, &link
->network
->dhcp6_pd_address
);
1544 return log_link_error_errno(link
, r
, "DHCP6 CLIENT: Failed to set prefix hint: %m");
1547 link
->dhcp6_client
= TAKE_PTR(client
);
1552 int dhcp6_update_mac(Link
*link
) {
1558 if (!link
->dhcp6_client
)
1561 restart
= sd_dhcp6_client_is_running(link
->dhcp6_client
) > 0;
1564 r
= sd_dhcp6_client_stop(link
->dhcp6_client
);
1569 r
= dhcp6_set_identifier(link
, link
->dhcp6_client
);
1574 r
= sd_dhcp6_client_start(link
->dhcp6_client
);
1576 return log_link_warning_errno(link
, r
, "Could not restart DHCPv6 client: %m");
1582 int link_serialize_dhcp6_client(Link
*link
, FILE *f
) {
1583 _cleanup_free_
char *duid
= NULL
;
1589 if (!link
->dhcp6_client
)
1592 r
= sd_dhcp6_client_get_iaid(link
->dhcp6_client
, &iaid
);
1594 fprintf(f
, "DHCP6_CLIENT_IAID=0x%x\n", iaid
);
1596 r
= sd_dhcp6_client_duid_as_string(link
->dhcp6_client
, &duid
);
1598 fprintf(f
, "DHCP6_CLIENT_DUID=%s\n", duid
);
1603 int config_parse_dhcp6_pd_hint(
1605 const char *filename
,
1607 const char *section
,
1608 unsigned section_line
,
1615 Network
*network
= data
;
1623 r
= in_addr_prefix_from_string(rvalue
, AF_INET6
, (union in_addr_union
*) &network
->dhcp6_pd_address
, &network
->dhcp6_pd_length
);
1625 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse PrefixDelegationHint=%s, ignoring assignment", rvalue
);
1629 if (network
->dhcp6_pd_length
< 1 || network
->dhcp6_pd_length
> 128) {
1630 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid prefix length='%d', ignoring assignment", network
->dhcp6_pd_length
);
1631 network
->dhcp6_pd_length
= 0;
1638 int config_parse_dhcp6_mud_url(
1640 const char *filename
,
1642 const char *section
,
1643 unsigned section_line
,
1650 _cleanup_free_
char *unescaped
= NULL
;
1651 Network
*network
= data
;
1658 if (isempty(rvalue
)) {
1659 network
->dhcp6_mudurl
= mfree(network
->dhcp6_mudurl
);
1663 r
= cunescape(rvalue
, 0, &unescaped
);
1665 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1666 "Failed to Failed to unescape MUD URL, ignoring: %s", rvalue
);
1670 if (!http_url_is_valid(unescaped
) || strlen(unescaped
) > UINT8_MAX
) {
1671 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
1672 "Failed to parse MUD URL '%s', ignoring: %m", rvalue
);
1676 return free_and_replace(network
->dhcp6_mudurl
, unescaped
);
1679 DEFINE_CONFIG_PARSE_ENUM(config_parse_dhcp6_client_start_mode
, dhcp6_client_start_mode
, DHCP6ClientStartMode
,
1680 "Failed to parse WithoutRA= setting");
1682 static const char* const dhcp6_client_start_mode_table
[_DHCP6_CLIENT_START_MODE_MAX
] = {
1683 [DHCP6_CLIENT_START_MODE_NO
] = "no",
1684 [DHCP6_CLIENT_START_MODE_INFORMATION_REQUEST
] = "information-request",
1685 [DHCP6_CLIENT_START_MODE_SOLICIT
] = "solicit",
1688 DEFINE_STRING_TABLE_LOOKUP(dhcp6_client_start_mode
, DHCP6ClientStartMode
);
1690 int config_parse_dhcp6_pd_subnet_id(
1692 const char *filename
,
1694 const char *section
,
1695 unsigned section_line
,
1711 if (isempty(rvalue
) || streq(rvalue
, "auto")) {
1716 r
= safe_atoux64(rvalue
, &t
);
1718 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1719 "Failed to parse %s=, ignoring assignment: %s",
1723 if (t
> INT64_MAX
) {
1724 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
1725 "Invalid subnet id '%s', ignoring assignment.",
1735 int config_parse_dhcp6_pd_token(
1737 const char *filename
,
1739 const char *section
,
1740 unsigned section_line
,
1747 union in_addr_union
*addr
= data
, tmp
;
1755 if (isempty(rvalue
)) {
1756 *addr
= IN_ADDR_NULL
;
1760 r
= in_addr_from_string(AF_INET6
, rvalue
, &tmp
);
1762 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1763 "Failed to parse DHCPv6 Prefix Delegation token, ignoring: %s", rvalue
);
1767 if (in_addr_is_null(AF_INET6
, &tmp
)) {
1768 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
1769 "DHCPv6 Prefix Delegation token cannot be the ANY address, ignoring: %s", rvalue
);