1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
3 Copyright © 2014 Intel Corporation. All rights reserved.
6 #include <linux/if_arp.h>
7 #include <linux/rtnetlink.h>
8 #include <netinet/icmp6.h>
12 #include "conf-parser.h"
13 #include "errno-util.h"
14 #include "event-util.h"
15 #include "missing_network.h"
16 #include "ndisc-router-internal.h"
17 #include "networkd-address.h"
18 #include "networkd-address-generation.h"
19 #include "networkd-dhcp6.h"
20 #include "networkd-link.h"
21 #include "networkd-manager.h"
22 #include "networkd-ndisc.h"
23 #include "networkd-nexthop.h"
24 #include "networkd-queue.h"
25 #include "networkd-route.h"
26 #include "networkd-state-file.h"
27 #include "networkd-sysctl.h"
28 #include "ordered-set.h"
30 #include "siphash24.h"
31 #include "socket-util.h"
32 #include "string-table.h"
33 #include "string-util.h"
35 #include "sysctl-util.h"
37 #define NDISC_DNSSL_MAX 64U
38 #define NDISC_RDNSS_MAX 64U
39 #define NDISC_ENCRYPTED_DNS_MAX 64U
40 /* Not defined in the RFC, but let's set an upper limit to make not consume much memory.
41 * This should be safe as typically there should be at most 1 portal per network. */
42 #define NDISC_CAPTIVE_PORTAL_MAX 64U
43 /* Neither defined in the RFC. Just for safety. Otherwise, malformed messages can make clients trigger OOM.
44 * Not sure if the threshold is high enough. Let's adjust later if not. */
45 #define NDISC_PREF64_MAX 64U
47 static int ndisc_drop_outdated(Link
*link
, const struct in6_addr
*router
, usec_t timestamp_usec
);
49 char* ndisc_dnssl_domain(const NDiscDNSSL
*n
) {
50 return ((char*) n
) + ALIGN(sizeof(NDiscDNSSL
));
53 bool link_ndisc_enabled(Link
*link
) {
56 if (!socket_ipv6_is_supported())
59 if (link
->flags
& IFF_LOOPBACK
)
62 if (link
->iftype
== ARPHRD_CAN
)
68 if (!link_may_have_ipv6ll(link
, /* check_multicast = */ true))
71 /* Honor explicitly specified value. */
72 if (link
->network
->ndisc
>= 0)
73 return link
->network
->ndisc
;
75 /* Disable if RADV is enabled. */
76 if (link_radv_enabled(link
))
79 /* Accept RAs if IPv6 forwarding is disabled, and ignore RAs if IPv6 forwarding is enabled. */
80 int t
= link_get_ip_forwarding(link
, AF_INET6
);
84 /* Otherwise, defaults to true. */
88 void network_adjust_ndisc(Network
*network
) {
91 if (!FLAGS_SET(network
->link_local
, ADDRESS_FAMILY_IPV6
)) {
92 if (network
->ndisc
> 0)
93 log_warning("%s: IPv6AcceptRA= is enabled but IPv6 link-local addressing is disabled or not supported. "
94 "Disabling IPv6AcceptRA=.", network
->filename
);
95 network
->ndisc
= false;
98 /* When RouterAllowList=, PrefixAllowList= or RouteAllowList= are specified, then
99 * RouterDenyList=, PrefixDenyList= or RouteDenyList= are ignored, respectively. */
100 if (!set_isempty(network
->ndisc_allow_listed_router
))
101 network
->ndisc_deny_listed_router
= set_free(network
->ndisc_deny_listed_router
);
102 if (!set_isempty(network
->ndisc_allow_listed_prefix
))
103 network
->ndisc_deny_listed_prefix
= set_free(network
->ndisc_deny_listed_prefix
);
104 if (!set_isempty(network
->ndisc_allow_listed_route_prefix
))
105 network
->ndisc_deny_listed_route_prefix
= set_free(network
->ndisc_deny_listed_route_prefix
);
108 static int ndisc_check_ready(Link
*link
);
110 static int ndisc_address_ready_callback(Address
*address
) {
114 assert(address
->link
);
116 SET_FOREACH(a
, address
->link
->addresses
)
117 if (a
->source
== NETWORK_CONFIG_SOURCE_NDISC
)
120 return ndisc_check_ready(address
->link
);
123 static int ndisc_check_ready(Link
*link
) {
124 bool found
= false, ready
= false;
129 if (link
->ndisc_messages
> 0) {
130 log_link_debug(link
, "%s(): SLAAC addresses and routes are not set.", __func__
);
134 SET_FOREACH(address
, link
->addresses
) {
135 if (address
->source
!= NETWORK_CONFIG_SOURCE_NDISC
)
140 if (address_is_ready(address
)) {
146 if (found
&& !ready
) {
147 SET_FOREACH(address
, link
->addresses
)
148 if (address
->source
== NETWORK_CONFIG_SOURCE_NDISC
)
149 address
->callback
= ndisc_address_ready_callback
;
151 log_link_debug(link
, "%s(): no SLAAC address is ready.", __func__
);
155 link
->ndisc_configured
= true;
156 log_link_debug(link
, "SLAAC addresses and routes set.");
158 link_check_ready(link
);
162 static int ndisc_remove_unused_nexthop(Link
*link
, NextHop
*nexthop
) {
166 assert(link
->manager
);
167 assert(link
->ifindex
> 0);
170 if (nexthop
->source
!= NETWORK_CONFIG_SOURCE_NDISC
)
173 if (nexthop
->ifindex
!= link
->ifindex
)
177 SET_FOREACH(route
, nexthop
->routes
)
178 if (route_exists(route
) || route_is_requesting(route
))
182 ORDERED_SET_FOREACH(req
, link
->manager
->request_queue
) {
183 if (req
->type
!= REQUEST_TYPE_ROUTE
)
186 route
= ASSERT_PTR(req
->userdata
);
187 if (route
->nexthop_id
== nexthop
->id
)
191 r
= nexthop_remove_and_cancel(nexthop
, link
->manager
);
193 return log_link_debug_errno(link
, r
, "Failed to remove unused nexthop: %m");
198 static int ndisc_remove_unused_nexthop_by_id(Link
*link
, uint32_t id
) {
200 assert(link
->manager
);
206 if (nexthop_get_by_id(link
->manager
, id
, &nexthop
) < 0)
209 return ndisc_remove_unused_nexthop(link
, nexthop
);
212 static int ndisc_remove_unused_nexthops(Link
*link
) {
216 assert(link
->manager
);
219 HASHMAP_FOREACH(nexthop
, link
->manager
->nexthops_by_id
)
220 RET_GATHER(ret
, ndisc_remove_unused_nexthop(link
, nexthop
));
225 #define NDISC_NEXTHOP_APP_ID SD_ID128_MAKE(76,d2,0f,1f,76,1e,44,d1,97,3a,52,5c,05,68,b5,0d)
227 static uint32_t ndisc_generate_nexthop_id(const NextHop
*nexthop
, Link
*link
, sd_id128_t app_id
, uint64_t trial
) {
231 struct siphash state
;
232 siphash24_init(&state
, app_id
.bytes
);
233 siphash24_compress_typesafe(nexthop
->protocol
, &state
);
234 siphash24_compress_string(link
->ifname
, &state
);
235 siphash24_compress_typesafe(nexthop
->gw
.address
.in6
, &state
);
236 siphash24_compress_typesafe(nexthop
->provider
.in6
, &state
);
237 uint64_t n
= htole64(trial
);
238 siphash24_compress_typesafe(n
, &state
);
240 uint64_t result
= htole64(siphash24_finalize(&state
));
241 return (uint32_t) ((result
& 0xffffffff) ^ (result
>> 32));
244 static bool ndisc_nexthop_equal(const NextHop
*a
, const NextHop
*b
) {
248 if (a
->source
!= b
->source
)
250 if (a
->protocol
!= b
->protocol
)
252 if (a
->ifindex
!= b
->ifindex
)
254 if (!in6_addr_equal(&a
->provider
.in6
, &b
->provider
.in6
))
256 if (!in6_addr_equal(&a
->gw
.address
.in6
, &b
->gw
.address
.in6
))
262 static bool ndisc_take_nexthop_id(NextHop
*nexthop
, const NextHop
*existing
, Manager
*manager
) {
264 assert(nexthop
->id
== 0);
266 assert(existing
->id
> 0);
269 if (!ndisc_nexthop_equal(nexthop
, existing
))
272 log_nexthop_debug(existing
, "Found matching", manager
);
273 nexthop
->id
= existing
->id
;
277 static int ndisc_nexthop_find_id(NextHop
*nexthop
, Link
*link
) {
284 assert(link
->manager
);
287 r
= sd_id128_get_machine_app_specific(NDISC_NEXTHOP_APP_ID
, &app_id
);
291 uint32_t id
= ndisc_generate_nexthop_id(nexthop
, link
, app_id
, 0);
292 if (nexthop_get_by_id(link
->manager
, id
, &n
) >= 0 &&
293 ndisc_take_nexthop_id(nexthop
, n
, link
->manager
))
295 if (nexthop_get_request_by_id(link
->manager
, id
, &req
) >= 0 &&
296 ndisc_take_nexthop_id(nexthop
, req
->userdata
, link
->manager
))
299 HASHMAP_FOREACH(n
, link
->manager
->nexthops_by_id
)
300 if (ndisc_take_nexthop_id(nexthop
, n
, link
->manager
))
303 ORDERED_SET_FOREACH(req
, link
->manager
->request_queue
) {
304 if (req
->type
!= REQUEST_TYPE_NEXTHOP
)
307 if (ndisc_take_nexthop_id(nexthop
, req
->userdata
, link
->manager
))
314 static int ndisc_nexthop_new(const Route
*route
, Link
*link
, NextHop
**ret
) {
315 _cleanup_(nexthop_unrefp
) NextHop
*nexthop
= NULL
;
322 r
= nexthop_new(&nexthop
);
326 nexthop
->source
= NETWORK_CONFIG_SOURCE_NDISC
;
327 nexthop
->provider
= route
->provider
;
328 nexthop
->protocol
= route
->protocol
== RTPROT_REDIRECT
? RTPROT_REDIRECT
: RTPROT_RA
;
329 nexthop
->family
= AF_INET6
;
330 nexthop
->gw
.address
= route
->nexthop
.gw
;
331 nexthop
->ifindex
= link
->ifindex
;
333 r
= ndisc_nexthop_find_id(nexthop
, link
);
337 *ret
= TAKE_PTR(nexthop
);
341 static int ndisc_nexthop_acquire_id(NextHop
*nexthop
, Link
*link
) {
345 assert(nexthop
->id
== 0);
347 assert(link
->manager
);
350 r
= sd_id128_get_machine_app_specific(NDISC_NEXTHOP_APP_ID
, &app_id
);
354 for (uint64_t trial
= 0; trial
< 100; trial
++) {
355 uint32_t id
= ndisc_generate_nexthop_id(nexthop
, link
, app_id
, trial
);
359 if (set_contains(link
->manager
->nexthop_ids
, UINT32_TO_PTR(id
)))
360 continue; /* The ID is already used in a .network file. */
362 if (nexthop_get_by_id(link
->manager
, id
, NULL
) >= 0)
363 continue; /* The ID is already used by an existing nexthop. */
365 if (nexthop_get_request_by_id(link
->manager
, id
, NULL
) >= 0)
366 continue; /* The ID is already used by a nexthop being requested. */
368 log_link_debug(link
, "Generated new ndisc nexthop ID for %s with trial %"PRIu64
": %"PRIu32
,
369 IN6_ADDR_TO_STRING(&nexthop
->gw
.address
.in6
), trial
, id
);
374 return log_link_debug_errno(link
, SYNTHETIC_ERRNO(EBUSY
), "Cannot find free nexthop ID for %s.",
375 IN6_ADDR_TO_STRING(&nexthop
->gw
.address
.in6
));
378 static int ndisc_nexthop_handler(sd_netlink
*rtnl
, sd_netlink_message
*m
, Request
*req
, Link
*link
, NextHop
*nexthop
) {
384 r
= nexthop_configure_handler_internal(m
, link
, nexthop
);
388 r
= ndisc_check_ready(link
);
390 link_enter_failed(link
);
395 static int ndisc_request_nexthop(NextHop
*nexthop
, Link
*link
) {
404 r
= ndisc_nexthop_acquire_id(nexthop
, link
);
408 r
= link_request_nexthop(link
, nexthop
, &link
->ndisc_messages
, ndisc_nexthop_handler
);
412 link
->ndisc_configured
= false;
417 static int ndisc_set_route_nexthop(Route
*route
, Link
*link
, bool request
) {
418 _cleanup_(nexthop_unrefp
) NextHop
*nexthop
= NULL
;
423 assert(link
->manager
);
425 if (!link
->manager
->manage_foreign_nexthops
)
428 if (route
->nexthop
.family
!= AF_INET6
|| in6_addr_is_null(&route
->nexthop
.gw
.in6
))
431 r
= ndisc_nexthop_new(route
, link
, &nexthop
);
435 if (nexthop
->id
== 0 && !request
)
438 r
= ndisc_request_nexthop(nexthop
, link
);
442 route
->nexthop
= (RouteNextHop
) {};
443 route
->nexthop_id
= nexthop
->id
;
446 return route_adjust_nexthops(route
, link
);
449 static int ndisc_route_handler(sd_netlink
*rtnl
, sd_netlink_message
*m
, Request
*req
, Link
*link
, Route
*route
) {
456 r
= route_configure_handler_internal(m
, req
, route
);
460 r
= ndisc_check_ready(link
);
462 link_enter_failed(link
);
467 static void ndisc_set_route_priority(Link
*link
, Route
*route
) {
471 if (route
->priority_set
)
472 return; /* explicitly configured. */
474 switch (route
->pref
) {
475 case SD_NDISC_PREFERENCE_LOW
:
476 route
->priority
= link
->network
->ndisc_route_metric_low
;
478 case SD_NDISC_PREFERENCE_MEDIUM
:
479 route
->priority
= link
->network
->ndisc_route_metric_medium
;
481 case SD_NDISC_PREFERENCE_HIGH
:
482 route
->priority
= link
->network
->ndisc_route_metric_high
;
485 assert_not_reached();
489 static int ndisc_request_route(Route
*route
, Link
*link
) {
494 assert(link
->manager
);
495 assert(link
->network
);
497 r
= route_metric_set(&route
->metric
, RTAX_QUICKACK
, link
->network
->ndisc_quickack
);
501 r
= ndisc_set_route_nexthop(route
, link
, /* request = */ true);
505 uint8_t pref
, pref_original
= route
->pref
;
506 FOREACH_ARGUMENT(pref
, SD_NDISC_PREFERENCE_LOW
, SD_NDISC_PREFERENCE_MEDIUM
, SD_NDISC_PREFERENCE_HIGH
) {
510 /* If the preference is specified by the user config (that is, for semi-static routes),
511 * rather than RA, then only search conflicting routes that have the same preference. */
512 if (route
->pref_set
&& pref
!= pref_original
)
516 ndisc_set_route_priority(link
, route
);
518 /* Note, here do not call route_remove_and_cancel() with 'route' directly, otherwise
519 * existing route(s) may be removed needlessly. */
521 /* First, check if a conflicting route is already requested. If there is an existing route,
522 * and also an existing pending request, then the source may be updated by the request. So,
523 * we first need to check the source of the requested route. */
524 if (route_get_request(link
->manager
, route
, &req
) >= 0) {
525 route
->pref
= pref_original
;
526 ndisc_set_route_priority(link
, route
);
528 existing
= ASSERT_PTR(req
->userdata
);
529 if (!route_can_update(link
->manager
, existing
, route
)) {
530 if (existing
->source
== NETWORK_CONFIG_SOURCE_STATIC
) {
531 log_link_debug(link
, "Found a pending route request that conflicts with new request based on a received RA, ignoring request.");
535 log_link_debug(link
, "Found a pending route request that conflicts with new request based on a received RA, cancelling.");
536 r
= route_remove_and_cancel(existing
, link
->manager
);
543 ndisc_set_route_priority(link
, route
);
545 /* Then, check if a conflicting route exists. */
546 if (route_get(link
->manager
, route
, &existing
) >= 0) {
547 route
->pref
= pref_original
;
548 ndisc_set_route_priority(link
, route
);
550 if (!route_can_update(link
->manager
, existing
, route
)) {
551 if (existing
->source
== NETWORK_CONFIG_SOURCE_STATIC
) {
552 log_link_debug(link
, "Found an existing route that conflicts with new route based on a received RA, ignoring request.");
556 log_link_debug(link
, "Found an existing route that conflicts with new route based on a received RA, removing.");
557 r
= route_remove_and_cancel(existing
, link
->manager
);
564 /* The preference (and priority) may be changed in the above loop. Restore it. */
565 route
->pref
= pref_original
;
566 ndisc_set_route_priority(link
, route
);
568 bool is_new
= route_get(link
->manager
, route
, NULL
) < 0;
570 r
= link_request_route(link
, route
, &link
->ndisc_messages
, ndisc_route_handler
);
574 link
->ndisc_configured
= false;
579 static void ndisc_route_prepare(Route
*route
, Link
*link
) {
583 route
->source
= NETWORK_CONFIG_SOURCE_NDISC
;
585 if (!route
->table_set
)
586 route
->table
= link_get_ndisc_route_table(link
);
589 static int ndisc_router_route_prepare(Route
*route
, Link
*link
, sd_ndisc_router
*rt
) {
594 ndisc_route_prepare(route
, link
);
596 if (!route
->protocol_set
)
597 route
->protocol
= RTPROT_RA
;
599 return sd_ndisc_router_get_sender_address(rt
, &route
->provider
.in6
);
602 static int ndisc_request_router_route(Route
*route
, Link
*link
, sd_ndisc_router
*rt
) {
609 r
= ndisc_router_route_prepare(route
, link
, rt
);
613 return ndisc_request_route(route
, link
);
616 static int ndisc_remove_route(Route
*route
, Link
*link
) {
621 assert(link
->manager
);
623 r
= ndisc_set_route_nexthop(route
, link
, /* request = */ false);
627 uint8_t pref
, pref_original
= route
->pref
;
628 FOREACH_ARGUMENT(pref
, SD_NDISC_PREFERENCE_LOW
, SD_NDISC_PREFERENCE_MEDIUM
, SD_NDISC_PREFERENCE_HIGH
) {
632 /* If the preference is specified by the user config (that is, for semi-static routes),
633 * rather than RA, then only search conflicting routes that have the same preference. */
634 if (route
->pref_set
&& pref
!= pref_original
)
638 ndisc_set_route_priority(link
, route
);
640 /* Unfortunately, we cannot directly pass 'route' to route_remove_and_cancel() here, as the
641 * same or similar route may be configured or requested statically. */
643 /* First, check if the route is already requested. If there is an existing route, and also an
644 * existing pending request, then the source may be updated by the request. So, we first need
645 * to check the source of the requested route. */
646 if (route_get_request(link
->manager
, route
, &req
) >= 0) {
647 existing
= ASSERT_PTR(req
->userdata
);
648 if (existing
->source
== NETWORK_CONFIG_SOURCE_STATIC
)
651 RET_GATHER(ret
, route_remove_and_cancel(existing
, link
->manager
));
654 /* Then, check if the route exists. */
655 if (route_get(link
->manager
, route
, &existing
) >= 0) {
656 if (existing
->source
== NETWORK_CONFIG_SOURCE_STATIC
)
659 RET_GATHER(ret
, route_remove_and_cancel(existing
, link
->manager
));
663 return RET_GATHER(ret
, ndisc_remove_unused_nexthop_by_id(link
, route
->nexthop_id
));
666 static int ndisc_remove_router_route(Route
*route
, Link
*link
, sd_ndisc_router
*rt
) {
673 r
= ndisc_router_route_prepare(route
, link
, rt
);
677 return ndisc_remove_route(route
, link
);
680 static int ndisc_address_handler(sd_netlink
*rtnl
, sd_netlink_message
*m
, Request
*req
, Link
*link
, Address
*address
) {
686 r
= address_configure_handler_internal(m
, link
, address
);
690 r
= ndisc_check_ready(link
);
692 link_enter_failed(link
);
697 static int ndisc_request_address(Address
*address
, Link
*link
) {
704 address
->source
= NETWORK_CONFIG_SOURCE_NDISC
;
706 r
= free_and_strdup_warn(&address
->netlabel
, link
->network
->ndisc_netlabel
);
711 if (address_get_harder(link
, address
, &existing
) < 0)
713 else if (address_can_update(existing
, address
))
715 else if (existing
->source
== NETWORK_CONFIG_SOURCE_DHCP6
) {
716 /* SLAAC address is preferred over DHCPv6 address. */
717 log_link_debug(link
, "Conflicting DHCPv6 address %s exists, removing.",
718 IN_ADDR_PREFIX_TO_STRING(existing
->family
, &existing
->in_addr
, existing
->prefixlen
));
719 r
= address_remove(existing
, link
);
725 /* Conflicting static address is configured?? */
726 log_link_debug(link
, "Conflicting address %s exists, ignoring request.",
727 IN_ADDR_PREFIX_TO_STRING(existing
->family
, &existing
->in_addr
, existing
->prefixlen
));
731 r
= link_request_address(link
, address
, &link
->ndisc_messages
,
732 ndisc_address_handler
, NULL
);
736 link
->ndisc_configured
= false;
741 int ndisc_reconfigure_address(Address
*address
, Link
*link
) {
745 assert(address
->source
== NETWORK_CONFIG_SOURCE_NDISC
);
748 r
= regenerate_address(address
, link
);
752 r
= ndisc_request_address(address
, link
);
756 if (!link
->ndisc_configured
)
757 link_set_state(link
, LINK_STATE_CONFIGURING
);
759 link_check_ready(link
);
763 static int ndisc_redirect_route_new(sd_ndisc_redirect
*rd
, Route
**ret
) {
764 _cleanup_(route_unrefp
) Route
*route
= NULL
;
765 struct in6_addr gateway
, destination
;
771 r
= sd_ndisc_redirect_get_target_address(rd
, &gateway
);
775 r
= sd_ndisc_redirect_get_destination_address(rd
, &destination
);
779 r
= route_new(&route
);
783 route
->family
= AF_INET6
;
784 if (!in6_addr_equal(&gateway
, &destination
)) {
785 route
->nexthop
.gw
.in6
= gateway
;
786 route
->nexthop
.family
= AF_INET6
;
788 route
->dst
.in6
= destination
;
789 route
->dst_prefixlen
= 128;
790 route
->protocol
= RTPROT_REDIRECT
;
792 r
= sd_ndisc_redirect_get_sender_address(rd
, &route
->provider
.in6
);
796 *ret
= TAKE_PTR(route
);
800 static int ndisc_remove_redirect_route(Link
*link
, sd_ndisc_redirect
*rd
) {
801 _cleanup_(route_unrefp
) Route
*route
= NULL
;
807 r
= ndisc_redirect_route_new(rd
, &route
);
811 ndisc_route_prepare(route
, link
);
813 return ndisc_remove_route(route
, link
);
816 static void ndisc_redirect_hash_func(const sd_ndisc_redirect
*x
, struct siphash
*state
) {
817 struct in6_addr dest
= {};
822 (void) sd_ndisc_redirect_get_destination_address((sd_ndisc_redirect
*) x
, &dest
);
824 siphash24_compress_typesafe(dest
, state
);
827 static int ndisc_redirect_compare_func(const sd_ndisc_redirect
*x
, const sd_ndisc_redirect
*y
) {
828 struct in6_addr dest_x
= {}, dest_y
= {};
833 (void) sd_ndisc_redirect_get_destination_address((sd_ndisc_redirect
*) x
, &dest_x
);
834 (void) sd_ndisc_redirect_get_destination_address((sd_ndisc_redirect
*) y
, &dest_y
);
836 return memcmp(&dest_x
, &dest_y
, sizeof(dest_x
));
839 DEFINE_PRIVATE_HASH_OPS_WITH_KEY_DESTRUCTOR(
840 ndisc_redirect_hash_ops
,
842 ndisc_redirect_hash_func
,
843 ndisc_redirect_compare_func
,
844 sd_ndisc_redirect_unref
);
846 static int ndisc_redirect_equal(sd_ndisc_redirect
*x
, sd_ndisc_redirect
*y
) {
847 struct in6_addr a
, b
;
853 r
= sd_ndisc_redirect_get_destination_address(x
, &a
);
857 r
= sd_ndisc_redirect_get_destination_address(y
, &b
);
861 if (!in6_addr_equal(&a
, &b
))
864 r
= sd_ndisc_redirect_get_target_address(x
, &a
);
868 r
= sd_ndisc_redirect_get_target_address(y
, &b
);
872 return in6_addr_equal(&a
, &b
);
875 static int ndisc_redirect_drop_conflict(Link
*link
, sd_ndisc_redirect
*rd
) {
876 _cleanup_(sd_ndisc_redirect_unrefp
) sd_ndisc_redirect
*existing
= NULL
;
882 existing
= set_remove(link
->ndisc_redirects
, rd
);
886 r
= ndisc_redirect_equal(rd
, existing
);
890 return ndisc_remove_redirect_route(link
, existing
);
893 static int ndisc_redirect_verify_sender(Link
*link
, sd_ndisc_redirect
*rd
) {
899 /* RFC 4861 section 8.1
900 * The IP source address of the Redirect is the same as the current first-hop router for the specified
901 * ICMP Destination Address. */
903 struct in6_addr sender
;
904 r
= sd_ndisc_redirect_get_sender_address(rd
, &sender
);
908 /* We will reuse the sender's router lifetime as the lifetime of the redirect route. Hence, if we
909 * have not remembered an RA from the sender, refuse the Redirect message. */
910 sd_ndisc_router
*router
= hashmap_get(link
->ndisc_routers_by_sender
, &sender
);
914 sd_ndisc_redirect
*existing
= set_get(link
->ndisc_redirects
, rd
);
916 struct in6_addr target
, dest
;
918 /* If we have received Redirect message for the host, the sender must be the previous target. */
920 r
= sd_ndisc_redirect_get_target_address(existing
, &target
);
924 if (in6_addr_equal(&sender
, &target
))
927 /* If the existing redirect route is on-link, that is, the destination and target address are
928 * equivalent, then also accept Redirect message from the current default router. This is not
929 * mentioned by the RFC, but without this, we cannot update on-link redirect route. */
930 r
= sd_ndisc_redirect_get_destination_address(existing
, &dest
);
934 if (!in6_addr_equal(&dest
, &target
))
938 /* Check if the sender is one of the known router with highest priority. */
940 r
= sd_ndisc_router_get_preference(router
, &preference
);
944 if (preference
== SD_NDISC_PREFERENCE_HIGH
)
948 HASHMAP_FOREACH(rt
, link
->ndisc_routers_by_sender
) {
953 if (sd_ndisc_router_get_preference(rt
, &pref
) < 0)
956 if (pref
== SD_NDISC_PREFERENCE_HIGH
||
957 (pref
== SD_NDISC_PREFERENCE_MEDIUM
&& preference
== SD_NDISC_PREFERENCE_LOW
))
964 static int ndisc_redirect_handler(Link
*link
, sd_ndisc_redirect
*rd
) {
968 assert(link
->network
);
971 if (!link
->network
->ndisc_use_redirect
)
975 r
= sd_event_now(link
->manager
->event
, CLOCK_BOOTTIME
, &now_usec
);
979 r
= ndisc_drop_outdated(link
, /* router = */ NULL
, now_usec
);
983 r
= ndisc_redirect_verify_sender(link
, rd
);
987 /* First, drop conflicting redirect route, if exists. */
988 r
= ndisc_redirect_drop_conflict(link
, rd
);
992 /* Then, remember the received message. */
993 r
= set_ensure_put(&link
->ndisc_redirects
, &ndisc_redirect_hash_ops
, rd
);
997 sd_ndisc_redirect_ref(rd
);
999 /* Finally, request the corresponding route. */
1000 _cleanup_(route_unrefp
) Route
*route
= NULL
;
1001 r
= ndisc_redirect_route_new(rd
, &route
);
1005 sd_ndisc_router
*rt
= hashmap_get(link
->ndisc_routers_by_sender
, &route
->provider
.in6
);
1007 return -EADDRNOTAVAIL
;
1009 r
= sd_ndisc_router_get_lifetime_timestamp(rt
, CLOCK_BOOTTIME
, &route
->lifetime_usec
);
1013 ndisc_route_prepare(route
, link
);
1015 return ndisc_request_route(route
, link
);
1018 static int ndisc_drop_redirect(Link
*link
, const struct in6_addr
*router
) {
1023 sd_ndisc_redirect
*rd
;
1024 SET_FOREACH(rd
, link
->ndisc_redirects
) {
1028 if (!(sd_ndisc_redirect_get_sender_address(rd
, &a
) >= 0 && in6_addr_equal(&a
, router
)) &&
1029 !(sd_ndisc_redirect_get_target_address(rd
, &a
) >= 0 && in6_addr_equal(&a
, router
)))
1033 r
= ndisc_remove_redirect_route(link
, rd
);
1035 RET_GATHER(ret
, log_link_warning_errno(link
, r
, "Failed to remove redirect route, ignoring: %m"));
1037 sd_ndisc_redirect_unref(set_remove(link
->ndisc_redirects
, rd
));
1043 static int ndisc_update_redirect_sender(Link
*link
, const struct in6_addr
*original_address
, const struct in6_addr
*current_address
) {
1047 assert(original_address
);
1048 assert(current_address
);
1050 sd_ndisc_redirect
*rd
;
1051 SET_FOREACH(rd
, link
->ndisc_redirects
) {
1052 struct in6_addr sender
;
1054 r
= sd_ndisc_redirect_get_sender_address(rd
, &sender
);
1058 if (!in6_addr_equal(&sender
, original_address
))
1061 r
= sd_ndisc_redirect_set_sender_address(rd
, current_address
);
1069 static int ndisc_router_drop_default(Link
*link
, sd_ndisc_router
*rt
) {
1070 _cleanup_(route_unrefp
) Route
*route
= NULL
;
1071 struct in6_addr gateway
;
1075 assert(link
->network
);
1078 r
= sd_ndisc_router_get_sender_address(rt
, &gateway
);
1080 return log_link_warning_errno(link
, r
, "Failed to get router address from RA: %m");
1082 r
= route_new(&route
);
1086 route
->family
= AF_INET6
;
1087 route
->nexthop
.family
= AF_INET6
;
1088 route
->nexthop
.gw
.in6
= gateway
;
1090 r
= ndisc_remove_router_route(route
, link
, rt
);
1092 return log_link_warning_errno(link
, r
, "Failed to remove the default gateway configured by RA: %m");
1095 HASHMAP_FOREACH(route_gw
, link
->network
->routes_by_section
) {
1096 _cleanup_(route_unrefp
) Route
*tmp
= NULL
;
1098 if (route_gw
->source
!= NETWORK_CONFIG_SOURCE_NDISC
)
1101 assert(route_gw
->nexthop
.family
== AF_INET6
);
1103 r
= route_dup(route_gw
, NULL
, &tmp
);
1107 tmp
->nexthop
.gw
.in6
= gateway
;
1109 r
= ndisc_remove_router_route(tmp
, link
, rt
);
1111 return log_link_warning_errno(link
, r
, "Could not remove semi-static gateway: %m");
1117 static int ndisc_router_process_default(Link
*link
, sd_ndisc_router
*rt
) {
1118 usec_t lifetime_usec
;
1119 struct in6_addr gateway
;
1124 assert(link
->network
);
1127 /* If the router lifetime is zero, the router should not be used as the default gateway. */
1128 r
= sd_ndisc_router_get_lifetime(rt
, NULL
);
1132 return ndisc_router_drop_default(link
, rt
);
1134 if (!link
->network
->ndisc_use_gateway
&&
1135 hashmap_isempty(link
->network
->routes_by_section
))
1138 r
= sd_ndisc_router_get_lifetime_timestamp(rt
, CLOCK_BOOTTIME
, &lifetime_usec
);
1140 return log_link_warning_errno(link
, r
, "Failed to get gateway lifetime from RA: %m");
1142 r
= sd_ndisc_router_get_sender_address(rt
, &gateway
);
1144 return log_link_warning_errno(link
, r
, "Failed to get gateway address from RA: %m");
1146 r
= sd_ndisc_router_get_preference(rt
, &preference
);
1148 return log_link_warning_errno(link
, r
, "Failed to get router preference from RA: %m");
1150 if (link
->network
->ndisc_use_gateway
) {
1151 _cleanup_(route_unrefp
) Route
*route
= NULL
;
1153 r
= route_new(&route
);
1157 route
->family
= AF_INET6
;
1158 route
->pref
= preference
;
1159 route
->nexthop
.family
= AF_INET6
;
1160 route
->nexthop
.gw
.in6
= gateway
;
1161 route
->lifetime_usec
= lifetime_usec
;
1163 r
= ndisc_request_router_route(route
, link
, rt
);
1165 return log_link_warning_errno(link
, r
, "Could not request default route: %m");
1169 HASHMAP_FOREACH(route_gw
, link
->network
->routes_by_section
) {
1170 _cleanup_(route_unrefp
) Route
*route
= NULL
;
1172 if (route_gw
->source
!= NETWORK_CONFIG_SOURCE_NDISC
)
1175 assert(route_gw
->nexthop
.family
== AF_INET6
);
1177 r
= route_dup(route_gw
, NULL
, &route
);
1181 route
->nexthop
.gw
.in6
= gateway
;
1182 if (!route
->pref_set
)
1183 route
->pref
= preference
;
1184 route
->lifetime_usec
= lifetime_usec
;
1186 r
= ndisc_request_router_route(route
, link
, rt
);
1188 return log_link_warning_errno(link
, r
, "Could not request gateway: %m");
1194 DEFINE_PRIVATE_HASH_OPS_WITH_VALUE_DESTRUCTOR(
1195 ndisc_router_hash_ops
,
1198 in6_addr_compare_func
,
1200 sd_ndisc_router_unref
);
1202 static int ndisc_update_router_address(Link
*link
, const struct in6_addr
*original_address
, const struct in6_addr
*current_address
) {
1203 _cleanup_(sd_ndisc_router_unrefp
) sd_ndisc_router
*rt
= NULL
;
1207 assert(original_address
);
1208 assert(current_address
);
1210 rt
= hashmap_remove(link
->ndisc_routers_by_sender
, original_address
);
1214 /* If we already received an RA from the new address, then forget the RA from the old address. */
1215 if (hashmap_contains(link
->ndisc_routers_by_sender
, current_address
))
1218 /* Otherwise, update the sender address of the previously received RA. */
1219 r
= sd_ndisc_router_set_sender_address(rt
, current_address
);
1223 r
= hashmap_put(link
->ndisc_routers_by_sender
, &rt
->packet
->sender_address
, rt
);
1231 static int ndisc_drop_router_one(Link
*link
, sd_ndisc_router
*rt
, usec_t timestamp_usec
) {
1232 usec_t lifetime_usec
;
1239 r
= sd_ndisc_router_get_lifetime_timestamp(rt
, CLOCK_BOOTTIME
, &lifetime_usec
);
1243 if (lifetime_usec
> timestamp_usec
)
1246 r
= ndisc_drop_redirect(link
, &rt
->packet
->sender_address
);
1248 sd_ndisc_router_unref(hashmap_remove(link
->ndisc_routers_by_sender
, &rt
->packet
->sender_address
));
1253 static int ndisc_drop_routers(Link
*link
, const struct in6_addr
*router
, usec_t timestamp_usec
) {
1254 sd_ndisc_router
*rt
;
1260 rt
= hashmap_get(link
->ndisc_routers_by_sender
, router
);
1264 return ndisc_drop_router_one(link
, rt
, timestamp_usec
);
1267 HASHMAP_FOREACH_KEY(rt
, router
, link
->ndisc_routers_by_sender
)
1268 RET_GATHER(ret
, ndisc_drop_router_one(link
, rt
, timestamp_usec
));
1273 static int ndisc_remember_router(Link
*link
, sd_ndisc_router
*rt
) {
1280 sd_ndisc_router_unref(hashmap_remove(link
->ndisc_routers_by_sender
, &rt
->packet
->sender_address
));
1282 /* Remember RAs with non-zero lifetime. */
1283 r
= sd_ndisc_router_get_lifetime(rt
, NULL
);
1287 r
= hashmap_ensure_put(&link
->ndisc_routers_by_sender
, &ndisc_router_hash_ops
, &rt
->packet
->sender_address
, rt
);
1291 sd_ndisc_router_ref(rt
);
1295 static int ndisc_router_process_reachable_time(Link
*link
, sd_ndisc_router
*rt
) {
1296 usec_t reachable_time
, msec
;
1300 assert(link
->manager
);
1301 assert(link
->network
);
1304 if (!link
->network
->ndisc_use_reachable_time
)
1307 r
= sd_ndisc_router_get_reachable_time(rt
, &reachable_time
);
1309 return log_link_warning_errno(link
, r
, "Failed to get reachable time from RA: %m");
1311 /* 0 is the unspecified value and must not be set (see RFC4861, 6.3.4) */
1312 if (!timestamp_is_set(reachable_time
))
1315 msec
= DIV_ROUND_UP(reachable_time
, USEC_PER_MSEC
);
1316 if (msec
<= 0 || msec
> UINT32_MAX
) {
1317 log_link_debug(link
, "Failed to get reachable time from RA - out of range (%"PRIu64
"), ignoring", msec
);
1321 /* Set the reachable time for Neighbor Solicitations. */
1322 r
= sysctl_write_ip_neighbor_property_uint32(AF_INET6
, link
->ifname
, "base_reachable_time_ms", (uint32_t) msec
, manager_get_sysctl_shadow(link
->manager
));
1324 log_link_warning_errno(link
, r
, "Failed to apply neighbor reachable time (%"PRIu64
"), ignoring: %m", msec
);
1329 static int ndisc_router_process_retransmission_time(Link
*link
, sd_ndisc_router
*rt
) {
1330 usec_t retrans_time
, msec
;
1334 assert(link
->manager
);
1335 assert(link
->network
);
1338 if (!link
->network
->ndisc_use_retransmission_time
)
1341 r
= sd_ndisc_router_get_retransmission_time(rt
, &retrans_time
);
1343 return log_link_warning_errno(link
, r
, "Failed to get retransmission time from RA: %m");
1345 /* 0 is the unspecified value and must not be set (see RFC4861, 6.3.4) */
1346 if (!timestamp_is_set(retrans_time
))
1349 msec
= DIV_ROUND_UP(retrans_time
, USEC_PER_MSEC
);
1350 if (msec
<= 0 || msec
> UINT32_MAX
) {
1351 log_link_debug(link
, "Failed to get retransmission time from RA - out of range (%"PRIu64
"), ignoring", msec
);
1355 /* Set the retransmission time for Neighbor Solicitations. */
1356 r
= sysctl_write_ip_neighbor_property_uint32(AF_INET6
, link
->ifname
, "retrans_time_ms", (uint32_t) msec
, manager_get_sysctl_shadow(link
->manager
));
1358 log_link_warning_errno(link
, r
, "Failed to apply neighbor retransmission time (%"PRIu64
"), ignoring: %m", msec
);
1363 static int ndisc_router_process_hop_limit(Link
*link
, sd_ndisc_router
*rt
) {
1368 assert(link
->manager
);
1369 assert(link
->network
);
1372 if (!link
->network
->ndisc_use_hop_limit
)
1375 r
= sd_ndisc_router_get_hop_limit(rt
, &hop_limit
);
1377 return log_link_warning_errno(link
, r
, "Failed to get hop limit from RA: %m");
1379 /* 0 is the unspecified value and must not be set (see RFC4861, 6.3.4):
1381 * A Router Advertisement field (e.g., Cur Hop Limit, Reachable Time, and Retrans Timer) may contain
1382 * a value denoting that it is unspecified. In such cases, the parameter should be ignored and the
1383 * host should continue using whatever value it is already using. In particular, a host MUST NOT
1384 * interpret the unspecified value as meaning change back to the default value that was in use before
1385 * the first Router Advertisement was received.
1387 * If the received Cur Hop Limit value is non-zero, the host SHOULD set
1388 * its CurHopLimit variable to the received value. */
1392 r
= sysctl_write_ip_property_uint32(AF_INET6
, link
->ifname
, "hop_limit", (uint32_t) hop_limit
, manager_get_sysctl_shadow(link
->manager
));
1394 log_link_warning_errno(link
, r
, "Failed to apply hop_limit (%u), ignoring: %m", hop_limit
);
1399 static int ndisc_router_process_mtu(Link
*link
, sd_ndisc_router
*rt
) {
1404 assert(link
->network
);
1407 if (!link
->network
->ndisc_use_mtu
)
1410 r
= sd_ndisc_router_get_mtu(rt
, &mtu
);
1414 return log_link_warning_errno(link
, r
, "Failed to get MTU from RA: %m");
1416 link
->ndisc_mtu
= mtu
;
1418 (void) link_set_ipv6_mtu(link
, LOG_DEBUG
);
1423 static int ndisc_address_set_lifetime(Address
*address
, Link
*link
, sd_ndisc_router
*rt
) {
1432 /* This is mostly based on RFC 4862 section 5.5.3 (e). However, the definition of 'RemainingLifetime'
1433 * is ambiguous, and there is no clear explanation when the address is not assigned yet. If we assume
1434 * that 'RemainingLifetime' is zero in that case, then IPv6 Core Conformance test [v6LC.3.2.5 Part C]
1435 * fails. So, in such case, we skip the conditions about 'RemainingLifetime'. */
1437 r
= sd_ndisc_router_prefix_get_valid_lifetime_timestamp(rt
, CLOCK_BOOTTIME
, &address
->lifetime_valid_usec
);
1441 r
= sd_ndisc_router_prefix_get_preferred_lifetime_timestamp(rt
, CLOCK_BOOTTIME
, &address
->lifetime_preferred_usec
);
1445 /* RFC 4862 section 5.5.3 (e)
1446 * 1. If the received Valid Lifetime is greater than 2 hours or greater than RemainingLifetime,
1447 * set the valid lifetime of the corresponding address to the advertised Valid Lifetime. */
1448 r
= sd_ndisc_router_prefix_get_valid_lifetime(rt
, &t
);
1452 if (t
> 2 * USEC_PER_HOUR
)
1455 if (address_get(link
, address
, &existing
) < 0 || existing
->source
!= NETWORK_CONFIG_SOURCE_NDISC
)
1458 if (address
->lifetime_valid_usec
> existing
->lifetime_valid_usec
)
1461 /* 2. If RemainingLifetime is less than or equal to 2 hours, ignore the Prefix Information option
1462 * with regards to the valid lifetime, unless the Router Advertisement from which this option was
1463 * obtained has been authenticated (e.g., via Secure Neighbor Discovery [RFC3971]). If the Router
1464 * Advertisement was authenticated, the valid lifetime of the corresponding address should be set
1465 * to the Valid Lifetime in the received option.
1467 * Currently, authentication is not supported. So check the lifetime of the existing address. */
1468 r
= sd_ndisc_router_get_timestamp(rt
, CLOCK_BOOTTIME
, &t
);
1472 if (existing
->lifetime_valid_usec
<= usec_add(t
, 2 * USEC_PER_HOUR
)) {
1473 address
->lifetime_valid_usec
= existing
->lifetime_valid_usec
;
1477 /* 3. Otherwise, reset the valid lifetime of the corresponding address to 2 hours. */
1478 address
->lifetime_valid_usec
= usec_add(t
, 2 * USEC_PER_HOUR
);
1482 static int ndisc_router_process_autonomous_prefix(Link
*link
, sd_ndisc_router
*rt
) {
1483 usec_t lifetime_valid_usec
, lifetime_preferred_usec
;
1484 struct in6_addr prefix
, router
;
1489 assert(link
->network
);
1492 if (!link
->network
->ndisc_use_autonomous_prefix
)
1495 r
= sd_ndisc_router_get_sender_address(rt
, &router
);
1497 return log_link_warning_errno(link
, r
, "Failed to get router address: %m");
1499 r
= sd_ndisc_router_prefix_get_address(rt
, &prefix
);
1501 return log_link_warning_errno(link
, r
, "Failed to get prefix address: %m");
1503 r
= sd_ndisc_router_prefix_get_prefixlen(rt
, &prefixlen
);
1505 return log_link_warning_errno(link
, r
, "Failed to get prefix length: %m");
1507 /* ndisc_generate_addresses() below requires the prefix length <= 64. */
1508 if (prefixlen
> 64) {
1509 log_link_debug(link
, "Prefix is longer than 64, ignoring autonomous prefix %s.",
1510 IN6_ADDR_PREFIX_TO_STRING(&prefix
, prefixlen
));
1514 r
= sd_ndisc_router_prefix_get_valid_lifetime(rt
, &lifetime_valid_usec
);
1516 return log_link_warning_errno(link
, r
, "Failed to get prefix valid lifetime: %m");
1518 r
= sd_ndisc_router_prefix_get_preferred_lifetime(rt
, &lifetime_preferred_usec
);
1520 return log_link_warning_errno(link
, r
, "Failed to get prefix preferred lifetime: %m");
1522 /* RFC 4862 section 5.5.3 (c)
1523 * If the preferred lifetime is greater than the valid lifetime, silently ignore the Prefix
1524 * Information option. */
1525 if (lifetime_preferred_usec
> lifetime_valid_usec
)
1528 _cleanup_hashmap_free_ Hashmap
*tokens_by_address
= NULL
;
1529 r
= ndisc_generate_addresses(link
, &prefix
, prefixlen
, &tokens_by_address
);
1531 return log_link_warning_errno(link
, r
, "Failed to generate SLAAC addresses: %m");
1535 HASHMAP_FOREACH_KEY(token
, a
, tokens_by_address
) {
1536 _cleanup_(address_unrefp
) Address
*address
= NULL
;
1538 r
= address_new(&address
);
1542 address
->provider
.in6
= router
;
1543 address
->family
= AF_INET6
;
1544 address
->in_addr
.in6
= *a
;
1545 address
->prefixlen
= prefixlen
;
1546 address
->flags
= IFA_F_NOPREFIXROUTE
|IFA_F_MANAGETEMPADDR
;
1547 address
->token
= ipv6_token_ref(token
);
1549 r
= ndisc_address_set_lifetime(address
, link
, rt
);
1551 return log_link_warning_errno(link
, r
, "Failed to set lifetime of SLAAC address: %m");
1553 assert(address
->lifetime_preferred_usec
<= address
->lifetime_valid_usec
);
1555 r
= ndisc_request_address(address
, link
);
1557 return log_link_warning_errno(link
, r
, "Could not request SLAAC address: %m");
1563 static int ndisc_router_process_onlink_prefix(Link
*link
, sd_ndisc_router
*rt
) {
1564 _cleanup_(route_unrefp
) Route
*route
= NULL
;
1565 uint8_t prefixlen
, preference
;
1566 usec_t lifetime_usec
;
1567 struct in6_addr prefix
;
1571 assert(link
->network
);
1574 if (!link
->network
->ndisc_use_onlink_prefix
)
1577 r
= sd_ndisc_router_prefix_get_valid_lifetime_timestamp(rt
, CLOCK_BOOTTIME
, &lifetime_usec
);
1579 return log_link_warning_errno(link
, r
, "Failed to get prefix lifetime: %m");
1581 r
= sd_ndisc_router_prefix_get_address(rt
, &prefix
);
1583 return log_link_warning_errno(link
, r
, "Failed to get prefix address: %m");
1585 r
= sd_ndisc_router_prefix_get_prefixlen(rt
, &prefixlen
);
1587 return log_link_warning_errno(link
, r
, "Failed to get prefix length: %m");
1589 /* Prefix Information option does not have preference, hence we use the 'main' preference here */
1590 r
= sd_ndisc_router_get_preference(rt
, &preference
);
1592 return log_link_warning_errno(link
, r
, "Failed to get router preference from RA: %m");
1594 r
= route_new(&route
);
1598 route
->family
= AF_INET6
;
1599 route
->dst
.in6
= prefix
;
1600 route
->dst_prefixlen
= prefixlen
;
1601 route
->pref
= preference
;
1602 route
->lifetime_usec
= lifetime_usec
;
1604 /* RFC 4861 section 6.3.4:
1605 * - If the prefix is not already present in the Prefix List, and the Prefix Information option's
1606 * Valid Lifetime field is non-zero, create a new entry for the prefix and initialize its
1607 * invalidation timer to the Valid Lifetime value in the Prefix Information option.
1609 * - If the prefix is already present in the host's Prefix List as the result of a previously
1610 * received advertisement, reset its invalidation timer to the Valid Lifetime value in the Prefix
1611 * Information option. If the new Lifetime value is zero, timeout the prefix immediately. */
1612 if (lifetime_usec
== 0) {
1613 r
= ndisc_remove_router_route(route
, link
, rt
);
1615 return log_link_warning_errno(link
, r
, "Failed to remove prefix route: %m");
1617 r
= ndisc_request_router_route(route
, link
, rt
);
1619 return log_link_warning_errno(link
, r
, "Failed to request prefix route: %m");
1625 static int ndisc_router_process_prefix(Link
*link
, sd_ndisc_router
*rt
, bool zero_lifetime
) {
1626 uint8_t flags
, prefixlen
;
1631 assert(link
->network
);
1634 usec_t lifetime_usec
;
1635 r
= sd_ndisc_router_prefix_get_valid_lifetime(rt
, &lifetime_usec
);
1637 return log_link_warning_errno(link
, r
, "Failed to get prefix lifetime: %m");
1639 if ((lifetime_usec
== 0) != zero_lifetime
)
1642 r
= sd_ndisc_router_prefix_get_address(rt
, &a
);
1644 return log_link_warning_errno(link
, r
, "Failed to get prefix address: %m");
1646 /* RFC 4861 Section 4.6.2:
1647 * A router SHOULD NOT send a prefix option for the link-local prefix and a host SHOULD ignore such
1648 * a prefix option. */
1649 if (in6_addr_is_link_local(&a
)) {
1650 log_link_debug(link
, "Received link-local prefix, ignoring prefix.");
1654 r
= sd_ndisc_router_prefix_get_prefixlen(rt
, &prefixlen
);
1656 return log_link_warning_errno(link
, r
, "Failed to get prefix length: %m");
1658 if (in6_prefix_is_filtered(&a
, prefixlen
, link
->network
->ndisc_allow_listed_prefix
, link
->network
->ndisc_deny_listed_prefix
)) {
1659 if (set_isempty(link
->network
->ndisc_allow_listed_prefix
))
1660 log_link_debug(link
, "Prefix '%s' is in deny list, ignoring.",
1661 IN6_ADDR_PREFIX_TO_STRING(&a
, prefixlen
));
1663 log_link_debug(link
, "Prefix '%s' is not in allow list, ignoring.",
1664 IN6_ADDR_PREFIX_TO_STRING(&a
, prefixlen
));
1668 r
= sd_ndisc_router_prefix_get_flags(rt
, &flags
);
1670 return log_link_warning_errno(link
, r
, "Failed to get RA prefix flags: %m");
1672 if (FLAGS_SET(flags
, ND_OPT_PI_FLAG_ONLINK
)) {
1673 r
= ndisc_router_process_onlink_prefix(link
, rt
);
1678 if (FLAGS_SET(flags
, ND_OPT_PI_FLAG_AUTO
)) {
1679 r
= ndisc_router_process_autonomous_prefix(link
, rt
);
1687 static int ndisc_router_process_route(Link
*link
, sd_ndisc_router
*rt
, bool zero_lifetime
) {
1688 _cleanup_(route_unrefp
) Route
*route
= NULL
;
1689 uint8_t preference
, prefixlen
;
1690 struct in6_addr gateway
, dst
;
1691 usec_t lifetime_usec
;
1696 if (!link
->network
->ndisc_use_route_prefix
)
1699 r
= sd_ndisc_router_route_get_lifetime_timestamp(rt
, CLOCK_BOOTTIME
, &lifetime_usec
);
1701 return log_link_warning_errno(link
, r
, "Failed to get route lifetime from RA: %m");
1703 if ((lifetime_usec
== 0) != zero_lifetime
)
1706 r
= sd_ndisc_router_route_get_address(rt
, &dst
);
1708 return log_link_warning_errno(link
, r
, "Failed to get route destination address: %m");
1710 r
= sd_ndisc_router_route_get_prefixlen(rt
, &prefixlen
);
1712 return log_link_warning_errno(link
, r
, "Failed to get route prefix length: %m");
1714 if (in6_prefix_is_filtered(&dst
, prefixlen
,
1715 link
->network
->ndisc_allow_listed_route_prefix
,
1716 link
->network
->ndisc_deny_listed_route_prefix
)) {
1717 if (set_isempty(link
->network
->ndisc_allow_listed_route_prefix
))
1718 log_link_debug(link
, "Route prefix '%s' is in deny list, ignoring.",
1719 IN6_ADDR_PREFIX_TO_STRING(&dst
, prefixlen
));
1721 log_link_debug(link
, "Route prefix '%s' is not in allow list, ignoring.",
1722 IN6_ADDR_PREFIX_TO_STRING(&dst
, prefixlen
));
1726 r
= sd_ndisc_router_get_sender_address(rt
, &gateway
);
1728 return log_link_warning_errno(link
, r
, "Failed to get gateway address from RA: %m");
1730 if (link_get_ipv6_address(link
, &gateway
, NULL
) >= 0) {
1732 log_link_debug(link
, "Advertised route gateway %s is local to the link, ignoring route",
1733 IN6_ADDR_TO_STRING(&gateway
));
1737 r
= sd_ndisc_router_route_get_preference(rt
, &preference
);
1739 return log_link_warning_errno(link
, r
, "Failed to get router preference from RA: %m");
1741 r
= route_new(&route
);
1745 route
->family
= AF_INET6
;
1746 route
->pref
= preference
;
1747 route
->nexthop
.gw
.in6
= gateway
;
1748 route
->nexthop
.family
= AF_INET6
;
1749 route
->dst
.in6
= dst
;
1750 route
->dst_prefixlen
= prefixlen
;
1751 route
->lifetime_usec
= lifetime_usec
;
1753 if (lifetime_usec
!= 0) {
1754 r
= ndisc_request_router_route(route
, link
, rt
);
1756 return log_link_warning_errno(link
, r
, "Could not request additional route: %m");
1758 r
= ndisc_remove_router_route(route
, link
, rt
);
1760 return log_link_warning_errno(link
, r
, "Could not remove additional route with zero lifetime: %m");
1766 static void ndisc_rdnss_hash_func(const NDiscRDNSS
*x
, struct siphash
*state
) {
1767 siphash24_compress_typesafe(x
->address
, state
);
1770 static int ndisc_rdnss_compare_func(const NDiscRDNSS
*a
, const NDiscRDNSS
*b
) {
1771 return memcmp(&a
->address
, &b
->address
, sizeof(a
->address
));
1774 DEFINE_PRIVATE_HASH_OPS_WITH_KEY_DESTRUCTOR(
1775 ndisc_rdnss_hash_ops
,
1777 ndisc_rdnss_hash_func
,
1778 ndisc_rdnss_compare_func
,
1781 static int ndisc_router_process_rdnss(Link
*link
, sd_ndisc_router
*rt
, bool zero_lifetime
) {
1782 usec_t lifetime_usec
;
1783 const struct in6_addr
*a
;
1784 struct in6_addr router
;
1785 bool updated
= false, logged_about_too_many
= false;
1789 assert(link
->network
);
1792 if (!link_get_use_dns(link
, NETWORK_CONFIG_SOURCE_NDISC
))
1795 r
= sd_ndisc_router_get_sender_address(rt
, &router
);
1797 return log_link_warning_errno(link
, r
, "Failed to get router address from RA: %m");
1799 r
= sd_ndisc_router_rdnss_get_lifetime_timestamp(rt
, CLOCK_BOOTTIME
, &lifetime_usec
);
1801 return log_link_warning_errno(link
, r
, "Failed to get RDNSS lifetime: %m");
1803 if ((lifetime_usec
== 0) != zero_lifetime
)
1806 n
= sd_ndisc_router_rdnss_get_addresses(rt
, &a
);
1808 return log_link_warning_errno(link
, n
, "Failed to get RDNSS addresses: %m");
1810 for (int j
= 0; j
< n
; j
++) {
1811 _cleanup_free_ NDiscRDNSS
*x
= NULL
;
1812 NDiscRDNSS
*rdnss
, d
= {
1816 if (lifetime_usec
== 0) {
1817 /* The entry is outdated. */
1818 free(set_remove(link
->ndisc_rdnss
, &d
));
1823 rdnss
= set_get(link
->ndisc_rdnss
, &d
);
1825 rdnss
->router
= router
;
1826 rdnss
->lifetime_usec
= lifetime_usec
;
1830 if (set_size(link
->ndisc_rdnss
) >= NDISC_RDNSS_MAX
) {
1831 if (!logged_about_too_many
)
1832 log_link_warning(link
, "Too many RDNSS records per link. Only first %u records will be used.", NDISC_RDNSS_MAX
);
1833 logged_about_too_many
= true;
1837 x
= new(NDiscRDNSS
, 1);
1844 .lifetime_usec
= lifetime_usec
,
1847 r
= set_ensure_consume(&link
->ndisc_rdnss
, &ndisc_rdnss_hash_ops
, TAKE_PTR(x
));
1861 static void ndisc_dnssl_hash_func(const NDiscDNSSL
*x
, struct siphash
*state
) {
1862 siphash24_compress_string(ndisc_dnssl_domain(x
), state
);
1865 static int ndisc_dnssl_compare_func(const NDiscDNSSL
*a
, const NDiscDNSSL
*b
) {
1866 return strcmp(ndisc_dnssl_domain(a
), ndisc_dnssl_domain(b
));
1869 DEFINE_PRIVATE_HASH_OPS_WITH_KEY_DESTRUCTOR(
1870 ndisc_dnssl_hash_ops
,
1872 ndisc_dnssl_hash_func
,
1873 ndisc_dnssl_compare_func
,
1876 static int ndisc_router_process_dnssl(Link
*link
, sd_ndisc_router
*rt
, bool zero_lifetime
) {
1878 usec_t lifetime_usec
;
1879 struct in6_addr router
;
1880 bool updated
= false, logged_about_too_many
= false;
1884 assert(link
->network
);
1887 if (link_get_use_domains(link
, NETWORK_CONFIG_SOURCE_NDISC
) <= 0)
1890 r
= sd_ndisc_router_get_sender_address(rt
, &router
);
1892 return log_link_warning_errno(link
, r
, "Failed to get router address from RA: %m");
1894 r
= sd_ndisc_router_dnssl_get_lifetime_timestamp(rt
, CLOCK_BOOTTIME
, &lifetime_usec
);
1896 return log_link_warning_errno(link
, r
, "Failed to get DNSSL lifetime: %m");
1898 if ((lifetime_usec
== 0) != zero_lifetime
)
1901 r
= sd_ndisc_router_dnssl_get_domains(rt
, &l
);
1903 return log_link_warning_errno(link
, r
, "Failed to get DNSSL addresses: %m");
1905 STRV_FOREACH(j
, l
) {
1906 _cleanup_free_ NDiscDNSSL
*s
= NULL
;
1909 s
= malloc0(ALIGN(sizeof(NDiscDNSSL
)) + strlen(*j
) + 1);
1913 strcpy(ndisc_dnssl_domain(s
), *j
);
1915 if (lifetime_usec
== 0) {
1916 /* The entry is outdated. */
1917 free(set_remove(link
->ndisc_dnssl
, s
));
1922 dnssl
= set_get(link
->ndisc_dnssl
, s
);
1924 dnssl
->router
= router
;
1925 dnssl
->lifetime_usec
= lifetime_usec
;
1929 if (set_size(link
->ndisc_dnssl
) >= NDISC_DNSSL_MAX
) {
1930 if (!logged_about_too_many
)
1931 log_link_warning(link
, "Too many DNSSL records per link. Only first %u records will be used.", NDISC_DNSSL_MAX
);
1932 logged_about_too_many
= true;
1937 s
->lifetime_usec
= lifetime_usec
;
1939 r
= set_ensure_consume(&link
->ndisc_dnssl
, &ndisc_dnssl_hash_ops
, TAKE_PTR(s
));
1953 static NDiscCaptivePortal
* ndisc_captive_portal_free(NDiscCaptivePortal
*x
) {
1957 free(x
->captive_portal
);
1961 DEFINE_TRIVIAL_CLEANUP_FUNC(NDiscCaptivePortal
*, ndisc_captive_portal_free
);
1963 static void ndisc_captive_portal_hash_func(const NDiscCaptivePortal
*x
, struct siphash
*state
) {
1965 siphash24_compress_string(x
->captive_portal
, state
);
1968 static int ndisc_captive_portal_compare_func(const NDiscCaptivePortal
*a
, const NDiscCaptivePortal
*b
) {
1971 return strcmp_ptr(a
->captive_portal
, b
->captive_portal
);
1974 DEFINE_PRIVATE_HASH_OPS_WITH_KEY_DESTRUCTOR(
1975 ndisc_captive_portal_hash_ops
,
1977 ndisc_captive_portal_hash_func
,
1978 ndisc_captive_portal_compare_func
,
1979 ndisc_captive_portal_free
);
1981 static int ndisc_router_process_captive_portal(Link
*link
, sd_ndisc_router
*rt
, bool zero_lifetime
) {
1982 _cleanup_(ndisc_captive_portal_freep
) NDiscCaptivePortal
*new_entry
= NULL
;
1983 _cleanup_free_
char *captive_portal
= NULL
;
1985 usec_t lifetime_usec
;
1986 NDiscCaptivePortal
*exist
;
1987 struct in6_addr router
;
1991 assert(link
->network
);
1994 if (!link
->network
->ndisc_use_captive_portal
)
1997 r
= sd_ndisc_router_get_sender_address(rt
, &router
);
1999 return log_link_warning_errno(link
, r
, "Failed to get router address from RA: %m");
2001 /* RFC 4861 section 4.2. states that the lifetime in the message header should be used only for the
2002 * default gateway, but the captive portal option does not have a lifetime field, hence, we use the
2003 * main lifetime for the portal. */
2004 r
= sd_ndisc_router_get_lifetime_timestamp(rt
, CLOCK_BOOTTIME
, &lifetime_usec
);
2006 return log_link_warning_errno(link
, r
, "Failed to get lifetime of RA message: %m");
2008 if ((lifetime_usec
== 0) != zero_lifetime
)
2011 r
= sd_ndisc_router_get_captive_portal(rt
, &uri
);
2013 return log_link_warning_errno(link
, r
, "Failed to get captive portal from RA: %m");
2015 captive_portal
= strdup(uri
);
2016 if (!captive_portal
)
2019 if (lifetime_usec
== 0) {
2020 /* Drop the portal with zero lifetime. */
2021 ndisc_captive_portal_free(set_remove(link
->ndisc_captive_portals
,
2022 &(const NDiscCaptivePortal
) {
2023 .captive_portal
= captive_portal
,
2028 exist
= set_get(link
->ndisc_captive_portals
,
2029 &(const NDiscCaptivePortal
) {
2030 .captive_portal
= captive_portal
,
2033 /* update existing entry */
2034 exist
->router
= router
;
2035 exist
->lifetime_usec
= lifetime_usec
;
2039 if (set_size(link
->ndisc_captive_portals
) >= NDISC_CAPTIVE_PORTAL_MAX
) {
2040 NDiscCaptivePortal
*c
, *target
= NULL
;
2042 /* Find the portal who has the minimal lifetime and drop it to store new one. */
2043 SET_FOREACH(c
, link
->ndisc_captive_portals
)
2044 if (!target
|| c
->lifetime_usec
< target
->lifetime_usec
)
2048 assert(set_remove(link
->ndisc_captive_portals
, target
) == target
);
2049 ndisc_captive_portal_free(target
);
2052 new_entry
= new(NDiscCaptivePortal
, 1);
2056 *new_entry
= (NDiscCaptivePortal
) {
2058 .lifetime_usec
= lifetime_usec
,
2059 .captive_portal
= TAKE_PTR(captive_portal
),
2062 r
= set_ensure_put(&link
->ndisc_captive_portals
, &ndisc_captive_portal_hash_ops
, new_entry
);
2066 TAKE_PTR(new_entry
);
2072 static void ndisc_pref64_hash_func(const NDiscPREF64
*x
, struct siphash
*state
) {
2075 siphash24_compress_typesafe(x
->prefix_len
, state
);
2076 siphash24_compress_typesafe(x
->prefix
, state
);
2079 static int ndisc_pref64_compare_func(const NDiscPREF64
*a
, const NDiscPREF64
*b
) {
2085 r
= CMP(a
->prefix_len
, b
->prefix_len
);
2089 return memcmp(&a
->prefix
, &b
->prefix
, sizeof(a
->prefix
));
2092 DEFINE_PRIVATE_HASH_OPS_WITH_KEY_DESTRUCTOR(
2093 ndisc_pref64_hash_ops
,
2095 ndisc_pref64_hash_func
,
2096 ndisc_pref64_compare_func
,
2099 static int ndisc_router_process_pref64(Link
*link
, sd_ndisc_router
*rt
, bool zero_lifetime
) {
2100 _cleanup_free_ NDiscPREF64
*new_entry
= NULL
;
2101 usec_t lifetime_usec
;
2102 struct in6_addr a
, router
;
2108 assert(link
->network
);
2111 if (!link
->network
->ndisc_use_pref64
)
2114 r
= sd_ndisc_router_get_sender_address(rt
, &router
);
2116 return log_link_warning_errno(link
, r
, "Failed to get router address from RA: %m");
2118 r
= sd_ndisc_router_prefix64_get_prefix(rt
, &a
);
2120 return log_link_warning_errno(link
, r
, "Failed to get pref64 prefix: %m");
2122 r
= sd_ndisc_router_prefix64_get_prefixlen(rt
, &prefix_len
);
2124 return log_link_warning_errno(link
, r
, "Failed to get pref64 prefix length: %m");
2126 r
= sd_ndisc_router_prefix64_get_lifetime_timestamp(rt
, CLOCK_BOOTTIME
, &lifetime_usec
);
2128 return log_link_warning_errno(link
, r
, "Failed to get pref64 prefix lifetime: %m");
2130 if ((lifetime_usec
== 0) != zero_lifetime
)
2133 if (lifetime_usec
== 0) {
2134 free(set_remove(link
->ndisc_pref64
,
2137 .prefix_len
= prefix_len
2142 exist
= set_get(link
->ndisc_pref64
,
2145 .prefix_len
= prefix_len
2148 /* update existing entry */
2149 exist
->router
= router
;
2150 exist
->lifetime_usec
= lifetime_usec
;
2154 if (set_size(link
->ndisc_pref64
) >= NDISC_PREF64_MAX
) {
2155 log_link_debug(link
, "Too many PREF64 records received. Only first %u records will be used.", NDISC_PREF64_MAX
);
2159 new_entry
= new(NDiscPREF64
, 1);
2163 *new_entry
= (NDiscPREF64
) {
2165 .lifetime_usec
= lifetime_usec
,
2167 .prefix_len
= prefix_len
,
2170 r
= set_ensure_put(&link
->ndisc_pref64
, &ndisc_pref64_hash_ops
, new_entry
);
2175 TAKE_PTR(new_entry
);
2180 static NDiscDNR
* ndisc_dnr_free(NDiscDNR
*x
) {
2184 sd_dns_resolver_done(&x
->resolver
);
2188 DEFINE_TRIVIAL_CLEANUP_FUNC(NDiscDNR
*, ndisc_dnr_free
);
2190 static int ndisc_dnr_compare_func(const NDiscDNR
*a
, const NDiscDNR
*b
) {
2191 return CMP(a
->resolver
.priority
, b
->resolver
.priority
) ||
2192 strcmp_ptr(a
->resolver
.auth_name
, b
->resolver
.auth_name
) ||
2193 CMP(a
->resolver
.transports
, b
->resolver
.transports
) ||
2194 CMP(a
->resolver
.port
, b
->resolver
.port
) ||
2195 strcmp_ptr(a
->resolver
.dohpath
, b
->resolver
.dohpath
) ||
2196 CMP(a
->resolver
.family
, b
->resolver
.family
) ||
2197 CMP(a
->resolver
.n_addrs
, b
->resolver
.n_addrs
) ||
2198 memcmp(a
->resolver
.addrs
, b
->resolver
.addrs
, sizeof(a
->resolver
.addrs
[0]) * a
->resolver
.n_addrs
);
2201 static void ndisc_dnr_hash_func(const NDiscDNR
*x
, struct siphash
*state
) {
2204 siphash24_compress_resolver(&x
->resolver
, state
);
2207 DEFINE_PRIVATE_HASH_OPS_WITH_KEY_DESTRUCTOR(
2210 ndisc_dnr_hash_func
,
2211 ndisc_dnr_compare_func
,
2214 static int sd_dns_resolver_copy(const sd_dns_resolver
*a
, sd_dns_resolver
*b
) {
2220 _cleanup_(sd_dns_resolver_done
) sd_dns_resolver c
= {
2221 .priority
= a
->priority
,
2222 .transports
= a
->transports
,
2225 .family
= a
->family
,
2232 r
= strdup_to(&c
.auth_name
, a
->auth_name
);
2236 /* addrs, n_addrs */
2237 c
.addrs
= newdup(union in_addr_union
, a
->addrs
, a
->n_addrs
);
2240 c
.n_addrs
= a
->n_addrs
;
2243 r
= strdup_to(&c
.dohpath
, a
->dohpath
);
2247 *b
= TAKE_STRUCT(c
);
2251 static int ndisc_router_process_encrypted_dns(Link
*link
, sd_ndisc_router
*rt
, bool zero_lifetime
) {
2255 assert(link
->network
);
2258 struct in6_addr router
;
2259 usec_t lifetime_usec
;
2260 sd_dns_resolver
*res
;
2261 _cleanup_(ndisc_dnr_freep
) NDiscDNR
*new_entry
= NULL
;
2263 if (!link_get_use_dnr(link
, NETWORK_CONFIG_SOURCE_NDISC
))
2266 r
= sd_ndisc_router_get_sender_address(rt
, &router
);
2268 return log_link_warning_errno(link
, r
, "Failed to get gateway address from RA: %m");
2270 r
= sd_ndisc_router_encrypted_dns_get_lifetime_timestamp(rt
, CLOCK_BOOTTIME
, &lifetime_usec
);
2272 return log_link_warning_errno(link
, r
, "Failed to get lifetime of RA message: %m");
2274 if ((lifetime_usec
== 0) != zero_lifetime
)
2277 r
= sd_ndisc_router_encrypted_dns_get_resolver(rt
, &res
);
2279 return log_link_warning_errno(link
, r
, "Failed to get encrypted dns resolvers: %m");
2281 NDiscDNR
*dnr
, d
= { .resolver
= *res
};
2282 if (lifetime_usec
== 0) {
2283 dnr
= set_remove(link
->ndisc_dnr
, &d
);
2285 ndisc_dnr_free(dnr
);
2291 dnr
= set_get(link
->ndisc_dnr
, &d
);
2293 dnr
->router
= router
;
2294 dnr
->lifetime_usec
= lifetime_usec
;
2298 if (set_size(link
->ndisc_dnr
) >= NDISC_ENCRYPTED_DNS_MAX
) {
2299 log_link_warning(link
, "Too many Encrypted DNS records received. Only first %u records will be used.", NDISC_ENCRYPTED_DNS_MAX
);
2303 new_entry
= new(NDiscDNR
, 1);
2307 *new_entry
= (NDiscDNR
) {
2310 .lifetime_usec
= lifetime_usec
,
2312 r
= sd_dns_resolver_copy(res
, &new_entry
->resolver
);
2316 /* Not sorted by priority */
2317 r
= set_ensure_put(&link
->ndisc_dnr
, &ndisc_dnr_hash_ops
, new_entry
);
2322 TAKE_PTR(new_entry
);
2329 static int ndisc_router_process_options(Link
*link
, sd_ndisc_router
*rt
, bool zero_lifetime
) {
2330 size_t n_captive_portal
= 0;
2334 assert(link
->network
);
2337 for (r
= sd_ndisc_router_option_rewind(rt
); ; r
= sd_ndisc_router_option_next(rt
)) {
2341 return log_link_warning_errno(link
, r
, "Failed to iterate through options: %m");
2342 if (r
== 0) /* EOF */
2345 r
= sd_ndisc_router_option_get_type(rt
, &type
);
2347 return log_link_warning_errno(link
, r
, "Failed to get RA option type: %m");
2350 case SD_NDISC_OPTION_PREFIX_INFORMATION
:
2351 r
= ndisc_router_process_prefix(link
, rt
, zero_lifetime
);
2354 case SD_NDISC_OPTION_ROUTE_INFORMATION
:
2355 r
= ndisc_router_process_route(link
, rt
, zero_lifetime
);
2358 case SD_NDISC_OPTION_RDNSS
:
2359 r
= ndisc_router_process_rdnss(link
, rt
, zero_lifetime
);
2362 case SD_NDISC_OPTION_DNSSL
:
2363 r
= ndisc_router_process_dnssl(link
, rt
, zero_lifetime
);
2365 case SD_NDISC_OPTION_CAPTIVE_PORTAL
:
2366 if (n_captive_portal
> 0) {
2367 if (n_captive_portal
== 1)
2368 log_link_notice(link
, "Received RA with multiple captive portals, only using the first one.");
2373 r
= ndisc_router_process_captive_portal(link
, rt
, zero_lifetime
);
2377 case SD_NDISC_OPTION_PREF64
:
2378 r
= ndisc_router_process_pref64(link
, rt
, zero_lifetime
);
2380 case SD_NDISC_OPTION_ENCRYPTED_DNS
:
2381 r
= ndisc_router_process_encrypted_dns(link
, rt
, zero_lifetime
);
2384 if (r
< 0 && r
!= -EBADMSG
)
2389 static int ndisc_drop_outdated(Link
*link
, const struct in6_addr
*router
, usec_t timestamp_usec
) {
2390 bool updated
= false;
2393 NDiscCaptivePortal
*cp
;
2401 assert(link
->manager
);
2403 /* If an address or friends is already assigned, but not valid anymore, then refuse to update it,
2404 * and let's immediately remove it.
2405 * See RFC4862, section 5.5.3.e. But the following logic is deviated from RFC4862 by honoring all
2406 * valid lifetimes to improve the reaction of SLAAC to renumbering events.
2407 * See draft-ietf-6man-slaac-renum-02, section 4.2. */
2409 r
= ndisc_drop_routers(link
, router
, timestamp_usec
);
2411 RET_GATHER(ret
, log_link_warning_errno(link
, r
, "Failed to drop outdated default router, ignoring: %m"));
2413 SET_FOREACH(route
, link
->manager
->routes
) {
2414 if (route
->source
!= NETWORK_CONFIG_SOURCE_NDISC
)
2417 if (!route_is_bound_to_link(route
, link
))
2420 if (route
->protocol
== RTPROT_REDIRECT
)
2421 continue; /* redirect route will be dropped by ndisc_drop_redirect(). */
2423 if (route
->lifetime_usec
> timestamp_usec
)
2424 continue; /* the route is still valid */
2426 if (router
&& !in6_addr_equal(&route
->provider
.in6
, router
))
2429 r
= route_remove_and_cancel(route
, link
->manager
);
2431 RET_GATHER(ret
, log_link_warning_errno(link
, r
, "Failed to remove outdated SLAAC route, ignoring: %m"));
2434 RET_GATHER(ret
, ndisc_remove_unused_nexthops(link
));
2436 SET_FOREACH(address
, link
->addresses
) {
2437 if (address
->source
!= NETWORK_CONFIG_SOURCE_NDISC
)
2440 if (address
->lifetime_valid_usec
> timestamp_usec
)
2441 continue; /* the address is still valid */
2443 if (router
&& !in6_addr_equal(&address
->provider
.in6
, router
))
2446 r
= address_remove_and_cancel(address
, link
);
2448 RET_GATHER(ret
, log_link_warning_errno(link
, r
, "Failed to remove outdated SLAAC address, ignoring: %m"));
2451 SET_FOREACH(rdnss
, link
->ndisc_rdnss
) {
2452 if (rdnss
->lifetime_usec
> timestamp_usec
)
2453 continue; /* the DNS server is still valid */
2455 if (router
&& !in6_addr_equal(&rdnss
->router
, router
))
2458 free(set_remove(link
->ndisc_rdnss
, rdnss
));
2462 SET_FOREACH(dnssl
, link
->ndisc_dnssl
) {
2463 if (dnssl
->lifetime_usec
> timestamp_usec
)
2464 continue; /* the DNS domain is still valid */
2466 if (router
&& !in6_addr_equal(&dnssl
->router
, router
))
2469 free(set_remove(link
->ndisc_dnssl
, dnssl
));
2473 SET_FOREACH(cp
, link
->ndisc_captive_portals
) {
2474 if (cp
->lifetime_usec
> timestamp_usec
)
2475 continue; /* the captive portal is still valid */
2477 if (router
&& !in6_addr_equal(&cp
->router
, router
))
2480 ndisc_captive_portal_free(set_remove(link
->ndisc_captive_portals
, cp
));
2484 SET_FOREACH(p64
, link
->ndisc_pref64
) {
2485 if (p64
->lifetime_usec
> timestamp_usec
)
2486 continue; /* the pref64 prefix is still valid */
2488 if (router
&& !in6_addr_equal(&p64
->router
, router
))
2491 free(set_remove(link
->ndisc_pref64
, p64
));
2492 /* The pref64 prefix is not exported through the state file, hence it is not necessary to set
2493 * the 'updated' flag. */
2496 SET_FOREACH(dnr
, link
->ndisc_dnr
) {
2497 if (dnr
->lifetime_usec
> timestamp_usec
)
2498 continue; /* The resolver is still valid */
2500 ndisc_dnr_free(set_remove(link
->ndisc_dnr
, dnr
));
2504 RET_GATHER(ret
, link_request_stacked_netdevs(link
, NETDEV_LOCAL_ADDRESS_SLAAC
));
2512 static int ndisc_setup_expire(Link
*link
);
2514 static int ndisc_expire_handler(sd_event_source
*s
, uint64_t usec
, void *userdata
) {
2515 Link
*link
= ASSERT_PTR(userdata
);
2518 assert(link
->manager
);
2520 assert_se(sd_event_now(link
->manager
->event
, CLOCK_BOOTTIME
, &now_usec
) >= 0);
2522 (void) ndisc_drop_outdated(link
, /* router = */ NULL
, now_usec
);
2523 (void) ndisc_setup_expire(link
);
2527 static int ndisc_setup_expire(Link
*link
) {
2528 usec_t lifetime_usec
= USEC_INFINITY
;
2529 NDiscCaptivePortal
*cp
;
2539 assert(link
->manager
);
2541 sd_ndisc_router
*rt
;
2542 HASHMAP_FOREACH(rt
, link
->ndisc_routers_by_sender
) {
2545 if (sd_ndisc_router_get_lifetime_timestamp(rt
, CLOCK_BOOTTIME
, &t
) < 0)
2548 lifetime_usec
= MIN(lifetime_usec
, t
);
2551 SET_FOREACH(route
, link
->manager
->routes
) {
2552 if (route
->source
!= NETWORK_CONFIG_SOURCE_NDISC
)
2555 if (!route_is_bound_to_link(route
, link
))
2558 if (!route_exists(route
))
2561 lifetime_usec
= MIN(lifetime_usec
, route
->lifetime_usec
);
2564 SET_FOREACH(address
, link
->addresses
) {
2565 if (address
->source
!= NETWORK_CONFIG_SOURCE_NDISC
)
2568 if (!address_exists(address
))
2571 lifetime_usec
= MIN(lifetime_usec
, address
->lifetime_valid_usec
);
2574 SET_FOREACH(rdnss
, link
->ndisc_rdnss
)
2575 lifetime_usec
= MIN(lifetime_usec
, rdnss
->lifetime_usec
);
2577 SET_FOREACH(dnssl
, link
->ndisc_dnssl
)
2578 lifetime_usec
= MIN(lifetime_usec
, dnssl
->lifetime_usec
);
2580 SET_FOREACH(cp
, link
->ndisc_captive_portals
)
2581 lifetime_usec
= MIN(lifetime_usec
, cp
->lifetime_usec
);
2583 SET_FOREACH(p64
, link
->ndisc_pref64
)
2584 lifetime_usec
= MIN(lifetime_usec
, p64
->lifetime_usec
);
2586 SET_FOREACH(dnr
, link
->ndisc_dnr
)
2587 lifetime_usec
= MIN(lifetime_usec
, dnr
->lifetime_usec
);
2589 if (lifetime_usec
== USEC_INFINITY
)
2592 r
= event_reset_time(link
->manager
->event
, &link
->ndisc_expire
, CLOCK_BOOTTIME
,
2593 lifetime_usec
, 0, ndisc_expire_handler
, link
, 0, "ndisc-expiration", true);
2595 return log_link_warning_errno(link
, r
, "Failed to update expiration timer for ndisc: %m");
2600 static int ndisc_start_dhcp6_client(Link
*link
, sd_ndisc_router
*rt
) {
2604 assert(link
->network
);
2606 switch (link
->network
->ndisc_start_dhcp6_client
) {
2607 case IPV6_ACCEPT_RA_START_DHCP6_CLIENT_NO
:
2610 case IPV6_ACCEPT_RA_START_DHCP6_CLIENT_YES
: {
2613 r
= sd_ndisc_router_get_flags(rt
, &flags
);
2615 return log_link_warning_errno(link
, r
, "Failed to get RA flags: %m");
2617 if ((flags
& (ND_RA_FLAG_MANAGED
| ND_RA_FLAG_OTHER
)) == 0)
2620 /* (re)start DHCPv6 client in stateful or stateless mode according to RA flags.
2621 * Note, if both "managed" and "other configuration" bits are set, then ignore
2622 * "other configuration" bit. See RFC 4861. */
2623 r
= dhcp6_start_on_ra(link
, !(flags
& ND_RA_FLAG_MANAGED
));
2626 case IPV6_ACCEPT_RA_START_DHCP6_CLIENT_ALWAYS
:
2627 /* When IPv6AcceptRA.DHCPv6Client=always, start dhcp6 client in solicit mode
2628 * even if the router flags have neither M nor O flags. */
2629 r
= dhcp6_start_on_ra(link
, /* information_request = */ false);
2633 assert_not_reached();
2637 return log_link_warning_errno(link
, r
, "Could not acquire DHCPv6 lease on NDisc request: %m");
2639 log_link_debug(link
, "Acquiring DHCPv6 lease on NDisc request");
2643 static int ndisc_router_handler(Link
*link
, sd_ndisc_router
*rt
) {
2644 struct in6_addr router
;
2645 usec_t timestamp_usec
;
2649 assert(link
->network
);
2650 assert(link
->manager
);
2653 r
= sd_ndisc_router_get_sender_address(rt
, &router
);
2654 if (r
== -ENODATA
) {
2655 log_link_debug(link
, "Received RA without router address, ignoring.");
2659 return log_link_warning_errno(link
, r
, "Failed to get router address from RA: %m");
2661 if (in6_prefix_is_filtered(&router
, 128, link
->network
->ndisc_allow_listed_router
, link
->network
->ndisc_deny_listed_router
)) {
2662 if (!set_isempty(link
->network
->ndisc_allow_listed_router
))
2663 log_link_debug(link
, "Router %s is not in allow list, ignoring.", IN6_ADDR_TO_STRING(&router
));
2665 log_link_debug(link
, "Router %s is in deny list, ignoring.", IN6_ADDR_TO_STRING(&router
));
2669 r
= sd_ndisc_router_get_timestamp(rt
, CLOCK_BOOTTIME
, ×tamp_usec
);
2670 if (r
== -ENODATA
) {
2671 log_link_debug(link
, "Received RA without timestamp, ignoring.");
2677 r
= ndisc_drop_outdated(link
, /* router = */ NULL
, timestamp_usec
);
2681 r
= ndisc_remember_router(link
, rt
);
2685 r
= ndisc_start_dhcp6_client(link
, rt
);
2689 r
= ndisc_router_process_reachable_time(link
, rt
);
2693 r
= ndisc_router_process_retransmission_time(link
, rt
);
2697 r
= ndisc_router_process_hop_limit(link
, rt
);
2701 r
= ndisc_router_process_mtu(link
, rt
);
2705 r
= ndisc_router_process_options(link
, rt
, /* zero_lifetime = */ true);
2709 r
= ndisc_router_process_default(link
, rt
);
2713 r
= ndisc_router_process_options(link
, rt
, /* zero_lifetime = */ false);
2717 r
= ndisc_setup_expire(link
);
2721 if (sd_ndisc_router_get_lifetime(rt
, NULL
) <= 0)
2722 (void) ndisc_drop_redirect(link
, &router
);
2724 if (link
->ndisc_messages
== 0)
2725 link
->ndisc_configured
= true;
2727 log_link_debug(link
, "Setting SLAAC addresses and router.");
2729 if (!link
->ndisc_configured
)
2730 link_set_state(link
, LINK_STATE_CONFIGURING
);
2732 link_check_ready(link
);
2736 static int ndisc_neighbor_handle_non_router_message(Link
*link
, sd_ndisc_neighbor
*na
) {
2737 struct in6_addr address
;
2743 /* Received Neighbor Advertisement message without Router flag. The node might have been a router,
2744 * and now it is not. Let's drop all configurations based on RAs sent from the node. */
2746 r
= sd_ndisc_neighbor_get_target_address(na
, &address
);
2752 /* Remove the routes configured by Redirect messages. */
2753 r
= ndisc_drop_redirect(link
, &address
);
2755 /* Also remove the default gateway via the host, but keep the configurations based on the RA options. */
2756 _cleanup_(sd_ndisc_router_unrefp
) sd_ndisc_router
*rt
= hashmap_remove(link
->ndisc_routers_by_sender
, &address
);
2758 RET_GATHER(r
, ndisc_router_drop_default(link
, rt
));
2763 static int ndisc_neighbor_handle_router_message(Link
*link
, sd_ndisc_neighbor
*na
) {
2764 struct in6_addr current_address
, original_address
;
2768 assert(link
->manager
);
2771 /* Received Neighbor Advertisement message with Router flag. If the router address is changed, update
2772 * the provider field of configurations. */
2774 r
= sd_ndisc_neighbor_get_sender_address(na
, ¤t_address
);
2780 r
= sd_ndisc_neighbor_get_target_address(na
, &original_address
);
2786 if (in6_addr_equal(¤t_address
, &original_address
))
2787 return 0; /* the router address is not changed */
2789 r
= ndisc_update_router_address(link
, &original_address
, ¤t_address
);
2793 r
= ndisc_update_redirect_sender(link
, &original_address
, ¤t_address
);
2798 SET_FOREACH(route
, link
->manager
->routes
) {
2799 if (route
->source
!= NETWORK_CONFIG_SOURCE_NDISC
)
2802 if (!route_is_bound_to_link(route
, link
))
2805 if (!in6_addr_equal(&route
->provider
.in6
, &original_address
))
2808 route
->provider
.in6
= current_address
;
2812 SET_FOREACH(address
, link
->addresses
) {
2813 if (address
->source
!= NETWORK_CONFIG_SOURCE_NDISC
)
2816 if (!in6_addr_equal(&address
->provider
.in6
, &original_address
))
2819 address
->provider
.in6
= current_address
;
2823 SET_FOREACH(rdnss
, link
->ndisc_rdnss
) {
2824 if (!in6_addr_equal(&rdnss
->router
, &original_address
))
2827 rdnss
->router
= current_address
;
2831 SET_FOREACH(dnssl
, link
->ndisc_dnssl
) {
2832 if (!in6_addr_equal(&dnssl
->router
, &original_address
))
2835 dnssl
->router
= current_address
;
2838 NDiscCaptivePortal
*cp
;
2839 SET_FOREACH(cp
, link
->ndisc_captive_portals
) {
2840 if (!in6_addr_equal(&cp
->router
, &original_address
))
2843 cp
->router
= current_address
;
2847 SET_FOREACH(p64
, link
->ndisc_pref64
) {
2848 if (!in6_addr_equal(&p64
->router
, &original_address
))
2851 p64
->router
= current_address
;
2855 SET_FOREACH(dnr
, link
->ndisc_dnr
) {
2856 if (!in6_addr_equal(&dnr
->router
, &original_address
))
2859 dnr
->router
= current_address
;
2865 static int ndisc_neighbor_handler(Link
*link
, sd_ndisc_neighbor
*na
) {
2871 r
= sd_ndisc_neighbor_is_router(na
);
2875 r
= ndisc_neighbor_handle_non_router_message(link
, na
);
2877 r
= ndisc_neighbor_handle_router_message(link
, na
);
2884 static void ndisc_handler(sd_ndisc
*nd
, sd_ndisc_event_t event
, void *message
, void *userdata
) {
2885 Link
*link
= ASSERT_PTR(userdata
);
2888 if (IN_SET(link
->state
, LINK_STATE_FAILED
, LINK_STATE_LINGER
))
2893 case SD_NDISC_EVENT_ROUTER
:
2894 r
= ndisc_router_handler(link
, ASSERT_PTR(message
));
2895 if (r
< 0 && r
!= -EBADMSG
) {
2896 link_enter_failed(link
);
2901 case SD_NDISC_EVENT_NEIGHBOR
:
2902 r
= ndisc_neighbor_handler(link
, ASSERT_PTR(message
));
2903 if (r
< 0 && r
!= -EBADMSG
) {
2904 link_enter_failed(link
);
2909 case SD_NDISC_EVENT_REDIRECT
:
2910 r
= ndisc_redirect_handler(link
, ASSERT_PTR(message
));
2911 if (r
< 0 && r
!= -EBADMSG
) {
2912 log_link_warning_errno(link
, r
, "Failed to process Redirect message: %m");
2913 link_enter_failed(link
);
2918 case SD_NDISC_EVENT_TIMEOUT
:
2919 log_link_debug(link
, "NDisc handler get timeout event");
2920 if (link
->ndisc_messages
== 0) {
2921 link
->ndisc_configured
= true;
2922 link_check_ready(link
);
2927 log_link_debug(link
, "Received unsupported NDisc event, ignoring.");
2931 static int ndisc_configure(Link
*link
) {
2936 if (!link_ndisc_enabled(link
))
2940 return -EBUSY
; /* Already configured. */
2942 r
= sd_ndisc_new(&link
->ndisc
);
2946 r
= sd_ndisc_attach_event(link
->ndisc
, link
->manager
->event
, 0);
2950 if (link
->hw_addr
.length
== ETH_ALEN
) {
2951 r
= sd_ndisc_set_mac(link
->ndisc
, &link
->hw_addr
.ether
);
2956 r
= sd_ndisc_set_ifindex(link
->ndisc
, link
->ifindex
);
2960 r
= sd_ndisc_set_callback(link
->ndisc
, ndisc_handler
, link
);
2967 int ndisc_start(Link
*link
) {
2972 if (!link
->ndisc
|| !link
->dhcp6_client
)
2975 if (!link_has_carrier(link
))
2978 if (in6_addr_is_null(&link
->ipv6ll_address
))
2981 r
= sd_ndisc_set_link_local_address(link
->ndisc
, &link
->ipv6ll_address
);
2985 log_link_debug(link
, "Discovering IPv6 routers");
2987 r
= sd_ndisc_start(link
->ndisc
);
2994 static int ndisc_process_request(Request
*req
, Link
*link
, void *userdata
) {
2999 if (!link_is_ready_to_configure(link
, /* allow_unmanaged = */ false))
3002 r
= ndisc_configure(link
);
3004 return log_link_warning_errno(link
, r
, "Failed to configure IPv6 Router Discovery: %m");
3006 r
= ndisc_start(link
);
3008 return log_link_warning_errno(link
, r
, "Failed to start IPv6 Router Discovery: %m");
3010 log_link_debug(link
, "IPv6 Router Discovery is configured%s.",
3011 r
> 0 ? " and started" : "");
3015 int link_request_ndisc(Link
*link
) {
3020 if (!link_ndisc_enabled(link
))
3026 r
= link_queue_request(link
, REQUEST_TYPE_NDISC
, ndisc_process_request
, NULL
);
3028 return log_link_warning_errno(link
, r
, "Failed to request configuring of the IPv6 Router Discovery: %m");
3030 log_link_debug(link
, "Requested configuring of the IPv6 Router Discovery.");
3034 int link_drop_ndisc_config(Link
*link
, Network
*network
) {
3038 assert(link
->network
);
3040 if (link
->network
== network
)
3041 return 0; /* .network file is unchanged. It is not necessary to reconfigure the client. */
3043 if (!link_ndisc_enabled(link
)) {
3044 /* NDisc is disabled. Stop the client if it is running and flush configs. */
3045 ret
= ndisc_stop(link
);
3047 link
->ndisc
= sd_ndisc_unref(link
->ndisc
);
3051 /* Even if the client was previously enabled and also enabled in the new .network file, detailed
3052 * settings for the client may be different. Let's unref() the client. */
3053 link
->ndisc
= sd_ndisc_unref(link
->ndisc
);
3055 /* Get if NDisc was enabled or not. */
3056 Network
*current
= link
->network
;
3057 link
->network
= network
;
3058 bool enabled
= link_ndisc_enabled(link
);
3059 link
->network
= current
;
3061 /* If previously explicitly disabled, there should be nothing to drop.
3062 * If we do not know the previous setting of the client, e.g. when networkd is restarted, in that
3063 * case we do not have the previous .network file assigned to the interface, then let's assume no
3064 * detailed configuration is changed. Hopefully, unmatching configurations will be dropped after
3065 * their lifetime. */
3071 /* Redirect messages will be ignored. Drop configurations based on the previously received redirect
3073 if (!network
->ndisc_use_redirect
)
3074 (void) ndisc_drop_redirect(link
, /* router = */ NULL
);
3076 /* If one of the route setting is changed, drop all routes. */
3077 if (link
->network
->ndisc_use_gateway
!= network
->ndisc_use_gateway
||
3078 link
->network
->ndisc_use_route_prefix
!= network
->ndisc_use_route_prefix
||
3079 link
->network
->ndisc_use_onlink_prefix
!= network
->ndisc_use_onlink_prefix
||
3080 link
->network
->ndisc_quickack
!= network
->ndisc_quickack
||
3081 link
->network
->ndisc_route_metric_high
!= network
->ndisc_route_metric_high
||
3082 link
->network
->ndisc_route_metric_medium
!= network
->ndisc_route_metric_medium
||
3083 link
->network
->ndisc_route_metric_low
!= network
->ndisc_route_metric_low
||
3084 !set_equal(link
->network
->ndisc_deny_listed_router
, network
->ndisc_deny_listed_router
) ||
3085 !set_equal(link
->network
->ndisc_allow_listed_router
, network
->ndisc_allow_listed_router
) ||
3086 !set_equal(link
->network
->ndisc_deny_listed_prefix
, network
->ndisc_deny_listed_prefix
) ||
3087 !set_equal(link
->network
->ndisc_allow_listed_prefix
, network
->ndisc_allow_listed_prefix
) ||
3088 !set_equal(link
->network
->ndisc_deny_listed_route_prefix
, network
->ndisc_deny_listed_route_prefix
) ||
3089 !set_equal(link
->network
->ndisc_allow_listed_route_prefix
, network
->ndisc_allow_listed_route_prefix
)) {
3091 SET_FOREACH(route
, link
->manager
->routes
) {
3092 if (route
->source
!= NETWORK_CONFIG_SOURCE_NDISC
)
3095 if (!route_is_bound_to_link(route
, link
))
3098 if (route
->protocol
== RTPROT_REDIRECT
)
3099 continue; /* redirect route is handled by ndisc_drop_redirect(). */
3101 r
= route_remove_and_cancel(route
, link
->manager
);
3103 RET_GATHER(ret
, log_link_warning_errno(link
, r
, "Failed to remove SLAAC route, ignoring: %m"));
3106 RET_GATHER(ret
, ndisc_remove_unused_nexthops(link
));
3109 /* If SLAAC address is disabled, drop all addresses. */
3110 if (!network
->ndisc_use_autonomous_prefix
||
3111 !set_equal(link
->network
->ndisc_tokens
, network
->ndisc_tokens
) ||
3112 !set_equal(link
->network
->ndisc_deny_listed_prefix
, network
->ndisc_deny_listed_prefix
) ||
3113 !set_equal(link
->network
->ndisc_allow_listed_prefix
, network
->ndisc_allow_listed_prefix
)) {
3115 SET_FOREACH(address
, link
->addresses
) {
3116 if (address
->source
!= NETWORK_CONFIG_SOURCE_NDISC
)
3119 r
= address_remove_and_cancel(address
, link
);
3121 RET_GATHER(ret
, log_link_warning_errno(link
, r
, "Failed to remove SLAAC address, ignoring: %m"));
3125 if (!network
->ndisc_use_mtu
)
3126 link
->ndisc_mtu
= 0;
3131 int ndisc_stop(Link
*link
) {
3134 link
->ndisc_expire
= sd_event_source_disable_unref(link
->ndisc_expire
);
3136 return sd_ndisc_stop(link
->ndisc
);
3139 void ndisc_flush(Link
*link
) {
3142 /* Remove all addresses, routes, RDNSS, DNSSL, DNR, and Captive Portal entries, without exception. */
3143 (void) ndisc_drop_outdated(link
, /* router = */ NULL
, /* timestamp_usec = */ USEC_INFINITY
);
3144 (void) ndisc_drop_redirect(link
, /* router = */ NULL
);
3146 link
->ndisc_routers_by_sender
= hashmap_free(link
->ndisc_routers_by_sender
);
3147 link
->ndisc_rdnss
= set_free(link
->ndisc_rdnss
);
3148 link
->ndisc_dnssl
= set_free(link
->ndisc_dnssl
);
3149 link
->ndisc_captive_portals
= set_free(link
->ndisc_captive_portals
);
3150 link
->ndisc_pref64
= set_free(link
->ndisc_pref64
);
3151 link
->ndisc_redirects
= set_free(link
->ndisc_redirects
);
3152 link
->ndisc_dnr
= set_free(link
->ndisc_dnr
);
3153 link
->ndisc_mtu
= 0;
3156 static const char* const ndisc_start_dhcp6_client_table
[_IPV6_ACCEPT_RA_START_DHCP6_CLIENT_MAX
] = {
3157 [IPV6_ACCEPT_RA_START_DHCP6_CLIENT_NO
] = "no",
3158 [IPV6_ACCEPT_RA_START_DHCP6_CLIENT_ALWAYS
] = "always",
3159 [IPV6_ACCEPT_RA_START_DHCP6_CLIENT_YES
] = "yes",
3162 DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING_WITH_BOOLEAN(ndisc_start_dhcp6_client
, IPv6AcceptRAStartDHCP6Client
, IPV6_ACCEPT_RA_START_DHCP6_CLIENT_YES
);
3164 DEFINE_CONFIG_PARSE_ENUM(config_parse_ndisc_start_dhcp6_client
, ndisc_start_dhcp6_client
, IPv6AcceptRAStartDHCP6Client
);