Lines Matching refs:link

21 bool link_dhcp6_with_address_enabled(Link *link) {  in link_dhcp6_with_address_enabled()  argument
22 if (!link_dhcp6_enabled(link)) in link_dhcp6_with_address_enabled()
25 return link->network->dhcp6_use_address; in link_dhcp6_with_address_enabled()
28 static DHCP6ClientStartMode link_get_dhcp6_client_start_mode(Link *link) { in link_get_dhcp6_client_start_mode() argument
29 assert(link); in link_get_dhcp6_client_start_mode()
31 if (!link->network) in link_get_dhcp6_client_start_mode()
35 if (link->network->dhcp6_client_start_mode >= 0) in link_get_dhcp6_client_start_mode()
36 return link->network->dhcp6_client_start_mode; in link_get_dhcp6_client_start_mode()
39 if (dhcp_pd_is_uplink(link, link, /* accept_auto = */ false)) in link_get_dhcp6_client_start_mode()
46 static int dhcp6_remove(Link *link, bool only_marked) { in dhcp6_remove() argument
51 assert(link); in dhcp6_remove()
54 link->dhcp6_configured = false; in dhcp6_remove()
56 SET_FOREACH(route, link->routes) { in dhcp6_remove()
66 route_cancel_request(route, link); in dhcp6_remove()
69 SET_FOREACH(address, link->addresses) { in dhcp6_remove()
89 assert(address->link); in dhcp6_address_ready_callback()
91 SET_FOREACH(a, address->link->addresses) in dhcp6_address_ready_callback()
95 return dhcp6_check_ready(address->link); in dhcp6_address_ready_callback()
98 int dhcp6_check_ready(Link *link) { in dhcp6_check_ready() argument
103 assert(link); in dhcp6_check_ready()
105 if (link->dhcp6_messages > 0) { in dhcp6_check_ready()
106 log_link_debug(link, "%s(): DHCPv6 addresses and routes are not set.", __func__); in dhcp6_check_ready()
110 SET_FOREACH(address, link->addresses) { in dhcp6_check_ready()
120 SET_FOREACH(address, link->addresses) in dhcp6_check_ready()
124 log_link_debug(link, "%s(): no DHCPv6 address is ready.", __func__); in dhcp6_check_ready()
128 link->dhcp6_configured = true; in dhcp6_check_ready()
129 log_link_debug(link, "DHCPv6 addresses and routes set."); in dhcp6_check_ready()
131 r = dhcp6_remove(link, /* only_marked = */ true); in dhcp6_check_ready()
135 link_check_ready(link); in dhcp6_check_ready()
139 static int dhcp6_address_handler(sd_netlink *rtnl, sd_netlink_message *m, Request *req, Link *link,… in dhcp6_address_handler() argument
142 assert(link); in dhcp6_address_handler()
144 r = address_configure_handler_internal(rtnl, m, link, "Could not set DHCPv6 address"); in dhcp6_address_handler()
148 r = dhcp6_check_ready(link); in dhcp6_address_handler()
150 link_enter_failed(link); in dhcp6_address_handler()
155 static int verify_dhcp6_address(Link *link, const Address *address) { in verify_dhcp6_address() argument
161 assert(link); in verify_dhcp6_address()
167 if (address_get(link, address, &existing) < 0 && in verify_dhcp6_address()
168 link_get_address(link, AF_INET6, &address->in_addr, 0, &existing) < 0) { in verify_dhcp6_address()
182 …log_link_warning(link, "Ignoring DHCPv6 address %s/%u (valid %s, preferred %s) which conflicts wit… in verify_dhcp6_address()
189 …log_link_warning(link, "Hint: use IPv6Token= setting to change the address generated by NDisc or s… in verify_dhcp6_address()
194 log_link_full(link, log_level, "DHCPv6 address %s/%u (valid %s, preferred %s)", in verify_dhcp6_address()
202 Link *link, in dhcp6_request_address() argument
225 if (verify_dhcp6_address(link, addr) < 0) in dhcp6_request_address()
228 if (address_get(link, addr, &existing) < 0) in dhcp6_request_address()
229 link->dhcp6_configured = false; in dhcp6_request_address()
233 r = link_request_address(link, TAKE_PTR(addr), true, &link->dhcp6_messages, in dhcp6_request_address()
239 …return log_link_error_errno(link, r, "Failed to request DHCPv6 address %s/128: %m", strna(buffer)); in dhcp6_request_address()
245 static int dhcp6_address_acquired(Link *link) { in dhcp6_address_acquired() argument
250 assert(link); in dhcp6_address_acquired()
251 assert(link->network); in dhcp6_address_acquired()
252 assert(link->dhcp6_lease); in dhcp6_address_acquired()
254 if (!link->network->dhcp6_use_address) in dhcp6_address_acquired()
257 r = sd_dhcp6_lease_get_server_address(link->dhcp6_lease, &server_address); in dhcp6_address_acquired()
259 … return log_link_warning_errno(link, r, "Failed to get server address of DHCPv6 lease: %m"); in dhcp6_address_acquired()
261 r = sd_dhcp6_lease_get_timestamp(link->dhcp6_lease, CLOCK_BOOTTIME, &timestamp_usec); in dhcp6_address_acquired()
263 … return log_link_warning_errno(link, r, "Failed to get timestamp of DHCPv6 lease: %m"); in dhcp6_address_acquired()
265 for (sd_dhcp6_lease_reset_address_iter(link->dhcp6_lease);;) { in dhcp6_address_acquired()
269 …r = sd_dhcp6_lease_get_address(link->dhcp6_lease, &ip6_addr, &lifetime_preferred_sec, &lifetime_va… in dhcp6_address_acquired()
273 r = dhcp6_request_address(link, &server_address, &ip6_addr, in dhcp6_address_acquired()
280 if (link->network->dhcp6_use_hostname) { in dhcp6_address_acquired()
284 (void) sd_dhcp6_lease_get_fqdn(link->dhcp6_lease, &dhcpname); in dhcp6_address_acquired()
289 …log_link_warning_errno(link, r, "Unable to shorten overlong DHCP hostname '%s', ignoring: %m", dhc… in dhcp6_address_acquired()
291 …log_link_notice(link, "Overlong DHCP hostname received, shortened from '%s' to '%s'", dhcpname, ho… in dhcp6_address_acquired()
294 r = manager_set_hostname(link->manager, hostname); in dhcp6_address_acquired()
296 … log_link_error_errno(link, r, "Failed to set transient hostname to '%s': %m", hostname); in dhcp6_address_acquired()
303 static int dhcp6_lease_ip_acquired(sd_dhcp6_client *client, Link *link) { in dhcp6_lease_ip_acquired() argument
308 link_mark_addresses(link, NETWORK_CONFIG_SOURCE_DHCP6, NULL); in dhcp6_lease_ip_acquired()
309 link_mark_routes(link, NETWORK_CONFIG_SOURCE_DHCP6, NULL); in dhcp6_lease_ip_acquired()
313 return log_link_error_errno(link, r, "Failed to get DHCPv6 lease: %m"); in dhcp6_lease_ip_acquired()
315 lease_old = TAKE_PTR(link->dhcp6_lease); in dhcp6_lease_ip_acquired()
316 link->dhcp6_lease = sd_dhcp6_lease_ref(lease); in dhcp6_lease_ip_acquired()
318 r = dhcp6_address_acquired(link); in dhcp6_lease_ip_acquired()
323 r = dhcp6_pd_prefix_acquired(link); in dhcp6_lease_ip_acquired()
328 dhcp_pd_prefix_lost(link); in dhcp6_lease_ip_acquired()
330 if (link->dhcp6_messages == 0) { in dhcp6_lease_ip_acquired()
331 link->dhcp6_configured = true; in dhcp6_lease_ip_acquired()
333 r = dhcp6_remove(link, /* only_marked = */ true); in dhcp6_lease_ip_acquired()
337 log_link_debug(link, "Setting DHCPv6 addresses and routes"); in dhcp6_lease_ip_acquired()
339 if (!link->dhcp6_configured) in dhcp6_lease_ip_acquired()
340 link_set_state(link, LINK_STATE_CONFIGURING); in dhcp6_lease_ip_acquired()
342 link_check_ready(link); in dhcp6_lease_ip_acquired()
346 static int dhcp6_lease_information_acquired(sd_dhcp6_client *client, Link *link) { in dhcp6_lease_information_acquired() argument
350 static int dhcp6_lease_lost(Link *link) { in dhcp6_lease_lost() argument
353 assert(link); in dhcp6_lease_lost()
354 assert(link->manager); in dhcp6_lease_lost()
356 log_link_info(link, "DHCPv6 lease lost"); in dhcp6_lease_lost()
358 if (dhcp6_lease_has_pd_prefix(link->dhcp6_lease)) in dhcp6_lease_lost()
359 dhcp_pd_prefix_lost(link); in dhcp6_lease_lost()
361 link->dhcp6_lease = sd_dhcp6_lease_unref(link->dhcp6_lease); in dhcp6_lease_lost()
363 r = dhcp6_remove(link, /* only_marked = */ false); in dhcp6_lease_lost()
371 Link *link = userdata; in dhcp6_handler() local
374 assert(link); in dhcp6_handler()
375 assert(link->network); in dhcp6_handler()
377 if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER)) in dhcp6_handler()
384 r = dhcp6_lease_lost(link); in dhcp6_handler()
386 link_enter_failed(link); in dhcp6_handler()
390 r = dhcp6_lease_ip_acquired(client, link); in dhcp6_handler()
392 link_enter_failed(link); in dhcp6_handler()
398 r = dhcp6_lease_information_acquired(client, link); in dhcp6_handler()
400 link_enter_failed(link); in dhcp6_handler()
405 log_link_warning_errno(link, event, "DHCPv6 error: %m"); in dhcp6_handler()
407 log_link_warning(link, "DHCPv6 unknown event: %d", event); in dhcp6_handler()
412 int dhcp6_start_on_ra(Link *link, bool information_request) { in dhcp6_start_on_ra() argument
415 assert(link); in dhcp6_start_on_ra()
416 assert(link->dhcp6_client); in dhcp6_start_on_ra()
417 assert(link->network); in dhcp6_start_on_ra()
418 assert(in6_addr_is_link_local(&link->ipv6ll_address)); in dhcp6_start_on_ra()
420 if (link_get_dhcp6_client_start_mode(link) != DHCP6_CLIENT_START_MODE_NO) in dhcp6_start_on_ra()
425 r = sd_dhcp6_client_is_running(link->dhcp6_client); in dhcp6_start_on_ra()
432 r = sd_dhcp6_client_get_information_request(link->dhcp6_client, &inf_req); in dhcp6_start_on_ra()
441 log_link_debug(link, in dhcp6_start_on_ra()
447 log_link_debug(link, in dhcp6_start_on_ra()
451 r = sd_dhcp6_client_stop(link->dhcp6_client); in dhcp6_start_on_ra()
455 r = sd_dhcp6_client_set_local_address(link->dhcp6_client, &link->ipv6ll_address); in dhcp6_start_on_ra()
460 r = sd_dhcp6_client_set_information_request(link->dhcp6_client, information_request); in dhcp6_start_on_ra()
464 r = sd_dhcp6_client_start(link->dhcp6_client); in dhcp6_start_on_ra()
471 int dhcp6_start(Link *link) { in dhcp6_start() argument
475 assert(link); in dhcp6_start()
476 assert(link->network); in dhcp6_start()
478 if (!link->dhcp6_client) in dhcp6_start()
481 if (!link_dhcp6_enabled(link)) in dhcp6_start()
484 if (!link_has_carrier(link)) in dhcp6_start()
487 if (sd_dhcp6_client_is_running(link->dhcp6_client) > 0) in dhcp6_start()
490 if (!in6_addr_is_link_local(&link->ipv6ll_address)) { in dhcp6_start()
491 … log_link_debug(link, "IPv6 link-local address is not set, delaying to start DHCPv6 client."); in dhcp6_start()
495 r = sd_dhcp6_client_set_local_address(link->dhcp6_client, &link->ipv6ll_address); in dhcp6_start()
499 start_mode = link_get_dhcp6_client_start_mode(link); in dhcp6_start()
503 r = sd_dhcp6_client_set_information_request(link->dhcp6_client, in dhcp6_start()
508 r = sd_dhcp6_client_start(link->dhcp6_client); in dhcp6_start()
515 static int dhcp6_set_hostname(sd_dhcp6_client *client, Link *link) { in dhcp6_set_hostname() argument
520 assert(link); in dhcp6_set_hostname()
522 if (!link->network->dhcp_send_hostname) in dhcp6_set_hostname()
524 else if (link->network->dhcp_hostname) in dhcp6_set_hostname()
525 hn = link->network->dhcp_hostname; in dhcp6_set_hostname()
529 … return log_link_debug_errno(link, r, "DHCPv6 CLIENT: Failed to get hostname: %m"); in dhcp6_set_hostname()
537 …log_link_debug_errno(link, r, "DHCPv6 CLIENT: Failed to set hostname from kernel hostname, ignorin… in dhcp6_set_hostname()
539 return log_link_debug_errno(link, r, "DHCPv6 CLIENT: Failed to set hostname: %m"); in dhcp6_set_hostname()
544 static int dhcp6_set_identifier(Link *link, sd_dhcp6_client *client) { in dhcp6_set_identifier() argument
548 assert(link); in dhcp6_set_identifier()
549 assert(link->network); in dhcp6_set_identifier()
552 … r = sd_dhcp6_client_set_mac(client, link->hw_addr.bytes, link->hw_addr.length, link->iftype); in dhcp6_set_identifier()
556 if (link->network->dhcp6_iaid_set) { in dhcp6_set_identifier()
557 r = sd_dhcp6_client_set_iaid(client, link->network->dhcp6_iaid); in dhcp6_set_identifier()
562 duid = link_get_dhcp6_duid(link); in dhcp6_set_identifier()
576 static int dhcp6_configure(Link *link) { in dhcp6_configure() argument
583 assert(link); in dhcp6_configure()
584 assert(link->network); in dhcp6_configure()
586 if (link->dhcp6_client) in dhcp6_configure()
587 … return log_link_debug_errno(link, SYNTHETIC_ERRNO(EBUSY), "DHCPv6 client is already configured."); in dhcp6_configure()
593 … return log_link_debug_errno(link, r, "DHCPv6 CLIENT: Failed to create DHCPv6 client: %m"); in dhcp6_configure()
595 r = sd_dhcp6_client_attach_event(client, link->manager->event, 0); in dhcp6_configure()
597 return log_link_debug_errno(link, r, "DHCPv6 CLIENT: Failed to attach event: %m"); in dhcp6_configure()
599 r = dhcp6_set_identifier(link, client); in dhcp6_configure()
601 return log_link_debug_errno(link, r, "DHCPv6 CLIENT: Failed to set identifier: %m"); in dhcp6_configure()
603 ORDERED_HASHMAP_FOREACH(send_option, link->network->dhcp6_client_send_options) { in dhcp6_configure()
608 … return log_link_debug_errno(link, r, "DHCPv6 CLIENT: Failed to set option: %m"); in dhcp6_configure()
611 r = dhcp6_set_hostname(client, link); in dhcp6_configure()
615 r = sd_dhcp6_client_set_ifindex(client, link->ifindex); in dhcp6_configure()
617 return log_link_debug_errno(link, r, "DHCPv6 CLIENT: Failed to set ifindex: %m"); in dhcp6_configure()
619 if (link->network->dhcp6_mudurl) { in dhcp6_configure()
620 r = sd_dhcp6_client_set_request_mud_url(client, link->network->dhcp6_mudurl); in dhcp6_configure()
622 … return log_link_debug_errno(link, r, "DHCPv6 CLIENT: Failed to set MUD URL: %m"); in dhcp6_configure()
625 if (link->network->dhcp6_use_dns) { in dhcp6_configure()
628 … return log_link_debug_errno(link, r, "DHCPv6 CLIENT: Failed to request DNS servers: %m"); in dhcp6_configure()
631 if (link->network->dhcp6_use_domains > 0) { in dhcp6_configure()
634 … return log_link_debug_errno(link, r, "DHCPv6 CLIENT: Failed to request domains: %m"); in dhcp6_configure()
637 if (link->network->dhcp6_use_ntp) { in dhcp6_configure()
640 … return log_link_debug_errno(link, r, "DHCPv6 CLIENT: Failed to request NTP servers: %m"); in dhcp6_configure()
645 … return log_link_debug_errno(link, r, "DHCPv6 CLIENT: Failed to request SNTP servers: %m"); in dhcp6_configure()
648 SET_FOREACH(request_options, link->network->dhcp6_request_options) { in dhcp6_configure()
653 …log_link_debug(link, "DHCPv6 CLIENT: Failed to set request flag for '%u' already exists, ignoring.… in dhcp6_configure()
657 …return log_link_debug_errno(link, r, "DHCPv6 CLIENT: Failed to set request flag for '%u': %m", opt… in dhcp6_configure()
660 if (link->network->dhcp6_user_class) { in dhcp6_configure()
661 r = sd_dhcp6_client_set_request_user_class(client, link->network->dhcp6_user_class); in dhcp6_configure()
663 … return log_link_debug_errno(link, r, "DHCPv6 CLIENT: Failed to set user class: %m"); in dhcp6_configure()
666 if (link->network->dhcp6_vendor_class) { in dhcp6_configure()
667 … r = sd_dhcp6_client_set_request_vendor_class(client, link->network->dhcp6_vendor_class); in dhcp6_configure()
669 … return log_link_debug_errno(link, r, "DHCPv6 CLIENT: Failed to set vendor class: %m"); in dhcp6_configure()
672 ORDERED_HASHMAP_FOREACH(vendor_option, link->network->dhcp6_client_send_vendor_options) { in dhcp6_configure()
677 … return log_link_debug_errno(link, r, "DHCPv6 CLIENT: Failed to set vendor option: %m"); in dhcp6_configure()
680 r = sd_dhcp6_client_set_callback(client, dhcp6_handler, link); in dhcp6_configure()
682 return log_link_debug_errno(link, r, "DHCPv6 CLIENT: Failed to set callback: %m"); in dhcp6_configure()
684 r = sd_dhcp6_client_set_prefix_delegation(client, link->network->dhcp6_use_pd_prefix); in dhcp6_configure()
686 …return log_link_debug_errno(link, r, "DHCPv6 CLIENT: Failed to %s requesting prefixes to be delega… in dhcp6_configure()
687 enable_disable(link->network->dhcp6_use_pd_prefix)); in dhcp6_configure()
690 …r = sd_dhcp6_client_set_address_request(client, link->network->dhcp6_use_pd_prefix ? link->network… in dhcp6_configure()
692 … return log_link_debug_errno(link, r, "DHCPv6 CLIENT: Failed to %s requesting address: %m", in dhcp6_configure()
693 enable_disable(link->network->dhcp6_use_address)); in dhcp6_configure()
695 if (link->network->dhcp6_pd_prefix_length > 0) { in dhcp6_configure()
697link->network->dhcp6_pd_prefix_length, in dhcp6_configure()
698 … &link->network->dhcp6_pd_prefix_hint); in dhcp6_configure()
700 … return log_link_debug_errno(link, r, "DHCPv6 CLIENT: Failed to set prefix delegation hint: %m"); in dhcp6_configure()
703 link->dhcp6_client = TAKE_PTR(client); in dhcp6_configure()
708 int dhcp6_update_mac(Link *link) { in dhcp6_update_mac() argument
712 assert(link); in dhcp6_update_mac()
714 if (!link->dhcp6_client) in dhcp6_update_mac()
717 restart = sd_dhcp6_client_is_running(link->dhcp6_client) > 0; in dhcp6_update_mac()
720 r = sd_dhcp6_client_stop(link->dhcp6_client); in dhcp6_update_mac()
725 r = dhcp6_set_identifier(link, link->dhcp6_client); in dhcp6_update_mac()
730 r = sd_dhcp6_client_start(link->dhcp6_client); in dhcp6_update_mac()
732 … return log_link_warning_errno(link, r, "Could not restart DHCPv6 client: %m"); in dhcp6_update_mac()
738 static int dhcp6_process_request(Request *req, Link *link, void *userdata) { in dhcp6_process_request() argument
741 assert(link); in dhcp6_process_request()
743 if (!IN_SET(link->state, LINK_STATE_CONFIGURING, LINK_STATE_CONFIGURED)) in dhcp6_process_request()
746 if (!IN_SET(link->hw_addr.length, ETH_ALEN, INFINIBAND_ALEN) || in dhcp6_process_request()
747 hw_addr_is_null(&link->hw_addr)) in dhcp6_process_request()
751 r = dhcp_configure_duid(link, link_get_dhcp6_duid(link)); in dhcp6_process_request()
755 r = dhcp6_configure(link); in dhcp6_process_request()
757 return log_link_warning_errno(link, r, "Failed to configure DHCPv6 client: %m"); in dhcp6_process_request()
759 r = ndisc_start(link); in dhcp6_process_request()
761 return log_link_warning_errno(link, r, "Failed to start IPv6 Router Discovery: %m"); in dhcp6_process_request()
763 r = dhcp6_start(link); in dhcp6_process_request()
765 return log_link_warning_errno(link, r, "Failed to start DHCPv6 client: %m"); in dhcp6_process_request()
767 log_link_debug(link, "DHCPv6 client is configured%s.", in dhcp6_process_request()
772 int link_request_dhcp6_client(Link *link) { in link_request_dhcp6_client() argument
775 assert(link); in link_request_dhcp6_client()
777 if (!link_dhcp6_enabled(link) && !link_ipv6_accept_ra_enabled(link)) in link_request_dhcp6_client()
780 if (link->dhcp6_client) in link_request_dhcp6_client()
783 r = link_queue_request(link, REQUEST_TYPE_DHCP6_CLIENT, dhcp6_process_request, NULL); in link_request_dhcp6_client()
785 … return log_link_warning_errno(link, r, "Failed to request configuring of the DHCPv6 client: %m"); in link_request_dhcp6_client()
787 log_link_debug(link, "Requested configuring of the DHCPv6 client."); in link_request_dhcp6_client()
791 int link_serialize_dhcp6_client(Link *link, FILE *f) { in link_serialize_dhcp6_client() argument
796 assert(link); in link_serialize_dhcp6_client()
798 if (!link->dhcp6_client) in link_serialize_dhcp6_client()
801 r = sd_dhcp6_client_get_iaid(link->dhcp6_client, &iaid); in link_serialize_dhcp6_client()
805 r = sd_dhcp6_client_duid_as_string(link->dhcp6_client, &duid); in link_serialize_dhcp6_client()