Lines Matching refs:link
71 bool link_ipv4ll_enabled(Link *link) { in link_ipv4ll_enabled() argument
72 assert(link); in link_ipv4ll_enabled()
74 if (link->flags & IFF_LOOPBACK) in link_ipv4ll_enabled()
77 if (!link->network) in link_ipv4ll_enabled()
80 if (link->iftype == ARPHRD_CAN) in link_ipv4ll_enabled()
83 if (link->hw_addr.length != ETH_ALEN) in link_ipv4ll_enabled()
86 if (ether_addr_is_null(&link->hw_addr.ether)) in link_ipv4ll_enabled()
91 if (link->iftype != ARPHRD_ETHER) in link_ipv4ll_enabled()
94 if (streq_ptr(link->kind, "vrf")) in link_ipv4ll_enabled()
98 if (IN_SET(link_get_ipvlan_mode(link), NETDEV_IPVLAN_MODE_L3, NETDEV_IPVLAN_MODE_L3S)) in link_ipv4ll_enabled()
101 if (link->network->bond) in link_ipv4ll_enabled()
104 return link->network->link_local & ADDRESS_FAMILY_IPV4; in link_ipv4ll_enabled()
107 bool link_ipv6_enabled(Link *link) { in link_ipv6_enabled() argument
108 assert(link); in link_ipv6_enabled()
113 if (link->network->bond) in link_ipv6_enabled()
116 if (link->iftype == ARPHRD_CAN) in link_ipv6_enabled()
120 if (link_ipv6ll_enabled(link)) in link_ipv6_enabled()
123 if (network_has_static_ipv6_configurations(link->network)) in link_ipv6_enabled()
129 bool link_is_ready_to_configure(Link *link, bool allow_unmanaged) { in link_is_ready_to_configure() argument
130 assert(link); in link_is_ready_to_configure()
132 if (!link->network) { in link_is_ready_to_configure()
136 return link_has_carrier(link); in link_is_ready_to_configure()
139 if (!IN_SET(link->state, LINK_STATE_CONFIGURING, LINK_STATE_CONFIGURED)) in link_is_ready_to_configure()
142 if (!link->network->configure_without_carrier) { in link_is_ready_to_configure()
143 if (link->set_flags_messages > 0) in link_is_ready_to_configure()
146 if (!link_has_carrier(link)) in link_is_ready_to_configure()
150 if (link->set_link_messages > 0) in link_is_ready_to_configure()
153 if (!link->activated) in link_is_ready_to_configure()
159 void link_ntp_settings_clear(Link *link) { in link_ntp_settings_clear() argument
160 link->ntp = strv_free(link->ntp); in link_ntp_settings_clear()
163 void link_dns_settings_clear(Link *link) { in link_dns_settings_clear() argument
164 if (link->n_dns != UINT_MAX) in link_dns_settings_clear()
165 for (unsigned i = 0; i < link->n_dns; i++) in link_dns_settings_clear()
166 in_addr_full_free(link->dns[i]); in link_dns_settings_clear()
167 link->dns = mfree(link->dns); in link_dns_settings_clear()
168 link->n_dns = UINT_MAX; in link_dns_settings_clear()
170 link->search_domains = ordered_set_free(link->search_domains); in link_dns_settings_clear()
171 link->route_domains = ordered_set_free(link->route_domains); in link_dns_settings_clear()
173 link->dns_default_route = -1; in link_dns_settings_clear()
174 link->llmnr = _RESOLVE_SUPPORT_INVALID; in link_dns_settings_clear()
175 link->mdns = _RESOLVE_SUPPORT_INVALID; in link_dns_settings_clear()
176 link->dnssec_mode = _DNSSEC_MODE_INVALID; in link_dns_settings_clear()
177 link->dns_over_tls_mode = _DNS_OVER_TLS_MODE_INVALID; in link_dns_settings_clear()
179 link->dnssec_negative_trust_anchors = set_free_free(link->dnssec_negative_trust_anchors); in link_dns_settings_clear()
182 static void link_free_engines(Link *link) { in link_free_engines() argument
183 if (!link) in link_free_engines()
186 link->dhcp_server = sd_dhcp_server_unref(link->dhcp_server); in link_free_engines()
187 link->dhcp_client = sd_dhcp_client_unref(link->dhcp_client); in link_free_engines()
188 link->dhcp_lease = sd_dhcp_lease_unref(link->dhcp_lease); in link_free_engines()
189 link->dhcp4_6rd_tunnel_name = mfree(link->dhcp4_6rd_tunnel_name); in link_free_engines()
191 link->lldp_rx = sd_lldp_rx_unref(link->lldp_rx); in link_free_engines()
192 link->lldp_tx = sd_lldp_tx_unref(link->lldp_tx); in link_free_engines()
194 ndisc_flush(link); in link_free_engines()
196 link->ipv4ll = sd_ipv4ll_unref(link->ipv4ll); in link_free_engines()
197 link->dhcp6_client = sd_dhcp6_client_unref(link->dhcp6_client); in link_free_engines()
198 link->dhcp6_lease = sd_dhcp6_lease_unref(link->dhcp6_lease); in link_free_engines()
199 link->ndisc = sd_ndisc_unref(link->ndisc); in link_free_engines()
200 link->radv = sd_radv_unref(link->radv); in link_free_engines()
203 static Link *link_free(Link *link) { in link_free() argument
204 assert(link); in link_free()
206 link_ntp_settings_clear(link); in link_free()
207 link_dns_settings_clear(link); in link_free()
209 link->routes = set_free(link->routes); in link_free()
210 link->nexthops = set_free(link->nexthops); in link_free()
211 link->neighbors = set_free(link->neighbors); in link_free()
212 link->addresses = set_free(link->addresses); in link_free()
213 link->qdiscs = set_free(link->qdiscs); in link_free()
214 link->tclasses = set_free(link->tclasses); in link_free()
216 link->dhcp_pd_prefixes = set_free(link->dhcp_pd_prefixes); in link_free()
218 link_free_engines(link); in link_free()
220 free(link->ifname); in link_free()
221 strv_free(link->alternative_names); in link_free()
222 free(link->kind); in link_free()
223 free(link->ssid); in link_free()
224 free(link->previous_ssid); in link_free()
225 free(link->driver); in link_free()
227 unlink_and_free(link->lease_file); in link_free()
228 unlink_and_free(link->lldp_file); in link_free()
229 unlink_and_free(link->state_file); in link_free()
231 sd_device_unref(link->sd_device); in link_free()
232 netdev_unref(link->netdev); in link_free()
234 hashmap_free(link->bound_to_links); in link_free()
235 hashmap_free(link->bound_by_links); in link_free()
237 set_free_with_destructor(link->slaves, link_unref); in link_free()
239 network_unref(link->network); in link_free()
241 sd_event_source_disable_unref(link->carrier_lost_timer); in link_free()
243 return mfree(link); in link_free()
246 DEFINE_TRIVIAL_REF_UNREF_FUNC(Link, link, link_free);
249 Link *link; in link_get_by_index() local
254 link = hashmap_get(m->links_by_index, INT_TO_PTR(ifindex)); in link_get_by_index()
255 if (!link) in link_get_by_index()
259 *ret = link; in link_get_by_index()
264 Link *link; in link_get_by_name() local
269 link = hashmap_get(m->links_by_name, ifname); in link_get_by_name()
270 if (!link) in link_get_by_name()
274 *ret = link; in link_get_by_name()
279 Link *link; in link_get_by_hw_addr() local
284 link = hashmap_get(m->links_by_hw_addr, hw_addr); in link_get_by_hw_addr()
285 if (!link) in link_get_by_hw_addr()
289 *ret = link; in link_get_by_hw_addr()
293 int link_get_master(Link *link, Link **ret) { in link_get_master() argument
294 assert(link); in link_get_master()
295 assert(link->manager); in link_get_master()
298 if (link->master_ifindex <= 0 || link->master_ifindex == link->ifindex) in link_get_master()
301 return link_get_by_index(link->manager, link->master_ifindex, ret); in link_get_master()
304 void link_set_state(Link *link, LinkState state) { in link_set_state() argument
305 assert(link); in link_set_state()
307 if (link->state == state) in link_set_state()
310 log_link_debug(link, "State changed: %s -> %s", in link_set_state()
311 link_state_to_string(link->state), in link_set_state()
314 link->state = state; in link_set_state()
316 link_send_changed(link, "AdministrativeState", NULL); in link_set_state()
317 link_dirty(link); in link_set_state()
320 int link_stop_engines(Link *link, bool may_keep_dhcp) { in link_stop_engines() argument
323 assert(link); in link_stop_engines()
324 assert(link->manager); in link_stop_engines()
325 assert(link->manager->event); in link_stop_engines()
328 link->network && in link_stop_engines()
329 … !link->network->dhcp_send_decline && /* IPv4 ACD for the DHCPv4 address is running. */ in link_stop_engines()
330 (link->manager->restarting || in link_stop_engines()
331 … FLAGS_SET(link->network->keep_configuration, KEEP_CONFIGURATION_DHCP_ON_STOP)); in link_stop_engines()
334 k = sd_dhcp_client_stop(link->dhcp_client); in link_stop_engines()
336 r = log_link_warning_errno(link, k, "Could not stop DHCPv4 client: %m"); in link_stop_engines()
339 k = sd_dhcp_server_stop(link->dhcp_server); in link_stop_engines()
341 r = log_link_warning_errno(link, k, "Could not stop DHCPv4 server: %m"); in link_stop_engines()
343 k = sd_lldp_rx_stop(link->lldp_rx); in link_stop_engines()
345 r = log_link_warning_errno(link, k, "Could not stop LLDP Rx: %m"); in link_stop_engines()
347 k = sd_lldp_tx_stop(link->lldp_tx); in link_stop_engines()
349 r = log_link_warning_errno(link, k, "Could not stop LLDP Tx: %m"); in link_stop_engines()
351 k = sd_ipv4ll_stop(link->ipv4ll); in link_stop_engines()
353 r = log_link_warning_errno(link, k, "Could not stop IPv4 link-local: %m"); in link_stop_engines()
355 k = ipv4acd_stop(link); in link_stop_engines()
357 r = log_link_warning_errno(link, k, "Could not stop IPv4 ACD client: %m"); in link_stop_engines()
359 k = sd_dhcp6_client_stop(link->dhcp6_client); in link_stop_engines()
361 r = log_link_warning_errno(link, k, "Could not stop DHCPv6 client: %m"); in link_stop_engines()
363 k = dhcp_pd_remove(link, /* only_marked = */ false); in link_stop_engines()
365 … r = log_link_warning_errno(link, k, "Could not remove DHCPv6 PD addresses and routes: %m"); in link_stop_engines()
367 k = sd_ndisc_stop(link->ndisc); in link_stop_engines()
369 r = log_link_warning_errno(link, k, "Could not stop IPv6 Router Discovery: %m"); in link_stop_engines()
371 ndisc_flush(link); in link_stop_engines()
373 k = sd_radv_stop(link->radv); in link_stop_engines()
375 r = log_link_warning_errno(link, k, "Could not stop IPv6 Router Advertisement: %m"); in link_stop_engines()
380 void link_enter_failed(Link *link) { in link_enter_failed() argument
381 assert(link); in link_enter_failed()
383 if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER)) in link_enter_failed()
386 log_link_warning(link, "Failed"); in link_enter_failed()
388 link_set_state(link, LINK_STATE_FAILED); in link_enter_failed()
390 (void) link_stop_engines(link, false); in link_enter_failed()
393 void link_check_ready(Link *link) { in link_check_ready() argument
396 assert(link); in link_check_ready()
398 if (link->state == LINK_STATE_CONFIGURED) in link_check_ready()
401 if (link->state != LINK_STATE_CONFIGURING) in link_check_ready()
402 …return (void) log_link_debug(link, "%s(): link is in %s state.", __func__, link_state_to_string(li… in link_check_ready()
404 if (!link->network) in link_check_ready()
405 return (void) log_link_debug(link, "%s(): link is unmanaged.", __func__); in link_check_ready()
407 if (!link->tc_configured) in link_check_ready()
408 … return (void) log_link_debug(link, "%s(): traffic controls are not configured.", __func__); in link_check_ready()
410 if (link->set_link_messages > 0) in link_check_ready()
411 return (void) log_link_debug(link, "%s(): link layer is configuring.", __func__); in link_check_ready()
413 if (!link->activated) in link_check_ready()
414 return (void) log_link_debug(link, "%s(): link is not activated.", __func__); in link_check_ready()
416 if (link->iftype == ARPHRD_CAN) { in link_check_ready()
418 link_set_state(link, LINK_STATE_CONFIGURED); in link_check_ready()
422 if (!link->stacked_netdevs_created) in link_check_ready()
423 … return (void) log_link_debug(link, "%s(): stacked netdevs are not created.", __func__); in link_check_ready()
425 if (!link->static_addresses_configured) in link_check_ready()
426 … return (void) log_link_debug(link, "%s(): static addresses are not configured.", __func__); in link_check_ready()
428 SET_FOREACH(a, link->addresses) in link_check_ready()
433 … return (void) log_link_debug(link, "%s(): address %s is not ready.", __func__, strna(str)); in link_check_ready()
436 if (!link->static_address_labels_configured) in link_check_ready()
437 … return (void) log_link_debug(link, "%s(): static address labels are not configured.", __func__); in link_check_ready()
439 if (!link->static_bridge_fdb_configured) in link_check_ready()
440 …return (void) log_link_debug(link, "%s(): static bridge MDB entries are not configured.", __func__… in link_check_ready()
442 if (!link->static_bridge_mdb_configured) in link_check_ready()
443 …return (void) log_link_debug(link, "%s(): static bridge MDB entries are not configured.", __func__… in link_check_ready()
445 if (!link->static_ipv6_proxy_ndp_configured) in link_check_ready()
446 …return (void) log_link_debug(link, "%s(): static IPv6 proxy NDP addresses are not configured.", __… in link_check_ready()
448 if (!link->static_neighbors_configured) in link_check_ready()
449 … return (void) log_link_debug(link, "%s(): static neighbors are not configured.", __func__); in link_check_ready()
451 if (!link->static_nexthops_configured) in link_check_ready()
452 … return (void) log_link_debug(link, "%s(): static nexthops are not configured.", __func__); in link_check_ready()
454 if (!link->static_routes_configured) in link_check_ready()
455 … return (void) log_link_debug(link, "%s(): static routes are not configured.", __func__); in link_check_ready()
457 if (!link->static_routing_policy_rules_configured) in link_check_ready()
458 …return (void) log_link_debug(link, "%s(): static routing policy rules are not configured.", __func… in link_check_ready()
460 if (!link->sr_iov_configured) in link_check_ready()
461 return (void) log_link_debug(link, "%s(): SR-IOV is not configured.", __func__); in link_check_ready()
464 if (!link->network->configure_without_carrier && in link_check_ready()
465 link_ipv6ll_enabled(link) && in link_check_ready()
466 !in6_addr_is_set(&link->ipv6ll_address)) in link_check_ready()
467 return (void) log_link_debug(link, "%s(): IPv6LL is not configured yet.", __func__); in link_check_ready()
470 SET_FOREACH(a, link->addresses) { in link_check_ready()
486 …if ((link_ipv4ll_enabled(link) || link_dhcp4_enabled(link) || link_dhcp6_with_address_enabled(link… in link_check_ready()
487 … (link_dhcp_pd_is_enabled(link) && link->network->dhcp_pd_assign)) && !has_dynamic_address) in link_check_ready()
489 …return (void) log_link_debug(link, "%s(): DHCPv4, DHCPv6, DHCP-PD or IPv4LL is enabled but no dyna… in link_check_ready()
492 if (link_ipv4ll_enabled(link) || link_dhcp4_enabled(link) || in link_check_ready()
493 link_dhcp6_enabled(link) || link_dhcp_pd_is_enabled(link) || in link_check_ready()
494 (!link->network->configure_without_carrier && link_ipv6_accept_ra_enabled(link))) { in link_check_ready()
496 if (!link->ipv4ll_address_configured && !link->dhcp4_configured && in link_check_ready()
497 !link->dhcp6_configured && !link->dhcp_pd_configured && !link->ndisc_configured) in link_check_ready()
499 …return (void) log_link_debug(link, "%s(): dynamic addresses or routes are not configured.", __func… in link_check_ready()
501 log_link_debug(link, "%s(): IPv4LL:%s DHCPv4:%s DHCPv6:%s DHCP-PD:%s NDisc:%s", in link_check_ready()
503 yes_no(link->ipv4ll_address_configured), in link_check_ready()
504 yes_no(link->dhcp4_configured), in link_check_ready()
505 yes_no(link->dhcp6_configured), in link_check_ready()
506 yes_no(link->dhcp_pd_configured), in link_check_ready()
507 yes_no(link->ndisc_configured)); in link_check_ready()
510 link_set_state(link, LINK_STATE_CONFIGURED); in link_check_ready()
513 static int link_request_static_configs(Link *link) { in link_request_static_configs() argument
516 assert(link); in link_request_static_configs()
517 assert(link->network); in link_request_static_configs()
518 assert(link->state != _LINK_STATE_INVALID); in link_request_static_configs()
520 r = link_request_static_addresses(link); in link_request_static_configs()
524 r = link_request_static_address_labels(link); in link_request_static_configs()
528 r = link_request_static_bridge_fdb(link); in link_request_static_configs()
532 r = link_request_static_bridge_mdb(link); in link_request_static_configs()
536 r = link_request_static_ipv6_proxy_ndp_addresses(link); in link_request_static_configs()
540 r = link_request_static_neighbors(link); in link_request_static_configs()
544 r = link_request_static_nexthops(link, false); in link_request_static_configs()
548 r = link_request_static_routes(link, false); in link_request_static_configs()
552 r = link_request_static_routing_policy_rules(link); in link_request_static_configs()
559 static int link_request_stacked_netdevs(Link *link) { in link_request_stacked_netdevs() argument
563 assert(link); in link_request_stacked_netdevs()
565 link->stacked_netdevs_created = false; in link_request_stacked_netdevs()
567 HASHMAP_FOREACH(netdev, link->network->stacked_netdevs) { in link_request_stacked_netdevs()
568 r = link_request_stacked_netdev(link, netdev); in link_request_stacked_netdevs()
573 if (link->create_stacked_netdev_messages == 0) { in link_request_stacked_netdevs()
574 link->stacked_netdevs_created = true; in link_request_stacked_netdevs()
575 link_check_ready(link); in link_request_stacked_netdevs()
581 static int link_acquire_dynamic_ipv6_conf(Link *link) { in link_acquire_dynamic_ipv6_conf() argument
584 assert(link); in link_acquire_dynamic_ipv6_conf()
586 r = radv_start(link); in link_acquire_dynamic_ipv6_conf()
588 … return log_link_warning_errno(link, r, "Failed to start IPv6 Router Advertisement engine: %m"); in link_acquire_dynamic_ipv6_conf()
590 r = ndisc_start(link); in link_acquire_dynamic_ipv6_conf()
592 return log_link_warning_errno(link, r, "Failed to start IPv6 Router Discovery: %m"); in link_acquire_dynamic_ipv6_conf()
594 r = dhcp6_start(link); in link_acquire_dynamic_ipv6_conf()
596 return log_link_warning_errno(link, r, "Failed to start DHCPv6 client: %m"); in link_acquire_dynamic_ipv6_conf()
601 static int link_acquire_dynamic_ipv4_conf(Link *link) { in link_acquire_dynamic_ipv4_conf() argument
604 assert(link); in link_acquire_dynamic_ipv4_conf()
605 assert(link->manager); in link_acquire_dynamic_ipv4_conf()
606 assert(link->manager->event); in link_acquire_dynamic_ipv4_conf()
608 if (link->dhcp_client) { in link_acquire_dynamic_ipv4_conf()
609 r = dhcp4_start(link); in link_acquire_dynamic_ipv4_conf()
611 return log_link_warning_errno(link, r, "Failed to start DHCPv4 client: %m"); in link_acquire_dynamic_ipv4_conf()
613 log_link_debug(link, "Acquiring DHCPv4 lease."); in link_acquire_dynamic_ipv4_conf()
615 } else if (link->ipv4ll) { in link_acquire_dynamic_ipv4_conf()
616 r = sd_ipv4ll_start(link->ipv4ll); in link_acquire_dynamic_ipv4_conf()
618 … return log_link_warning_errno(link, r, "Could not acquire IPv4 link-local address: %m"); in link_acquire_dynamic_ipv4_conf()
620 log_link_debug(link, "Acquiring IPv4 link-local address."); in link_acquire_dynamic_ipv4_conf()
623 if (link->dhcp_server) { in link_acquire_dynamic_ipv4_conf()
624 r = sd_dhcp_server_start(link->dhcp_server); in link_acquire_dynamic_ipv4_conf()
626 return log_link_warning_errno(link, r, "Could not start DHCP server: %m"); in link_acquire_dynamic_ipv4_conf()
629 r = ipv4acd_start(link); in link_acquire_dynamic_ipv4_conf()
631 return log_link_warning_errno(link, r, "Could not start IPv4 ACD client: %m"); in link_acquire_dynamic_ipv4_conf()
636 static int link_acquire_dynamic_conf(Link *link) { in link_acquire_dynamic_conf() argument
639 assert(link); in link_acquire_dynamic_conf()
640 assert(link->network); in link_acquire_dynamic_conf()
642 r = link_acquire_dynamic_ipv4_conf(link); in link_acquire_dynamic_conf()
646 if (in6_addr_is_set(&link->ipv6ll_address)) { in link_acquire_dynamic_conf()
647 r = link_acquire_dynamic_ipv6_conf(link); in link_acquire_dynamic_conf()
652 if (!link_radv_enabled(link) || !link->network->dhcp_pd_announce) { in link_acquire_dynamic_conf()
657 r = dhcp_request_prefix_delegation(link); in link_acquire_dynamic_conf()
659 … return log_link_warning_errno(link, r, "Failed to request DHCP delegated subnet prefix: %m"); in link_acquire_dynamic_conf()
662 if (link->lldp_tx) { in link_acquire_dynamic_conf()
663 r = sd_lldp_tx_start(link->lldp_tx); in link_acquire_dynamic_conf()
665 … return log_link_warning_errno(link, r, "Failed to start LLDP transmission: %m"); in link_acquire_dynamic_conf()
668 if (link->lldp_rx) { in link_acquire_dynamic_conf()
669 r = sd_lldp_rx_start(link->lldp_rx); in link_acquire_dynamic_conf()
671 return log_link_warning_errno(link, r, "Failed to start LLDP client: %m"); in link_acquire_dynamic_conf()
677 int link_ipv6ll_gained(Link *link) { in link_ipv6ll_gained() argument
680 assert(link); in link_ipv6ll_gained()
682 log_link_info(link, "Gained IPv6LL"); in link_ipv6ll_gained()
684 if (!IN_SET(link->state, LINK_STATE_CONFIGURING, LINK_STATE_CONFIGURED)) in link_ipv6ll_gained()
687 r = link_acquire_dynamic_ipv6_conf(link); in link_ipv6ll_gained()
691 link_check_ready(link); in link_ipv6ll_gained()
695 int link_handle_bound_to_list(Link *link) { in link_handle_bound_to_list() argument
700 assert(link); in link_handle_bound_to_list()
705 if (hashmap_isempty(link->bound_to_links)) in link_handle_bound_to_list()
708 if (link->flags & IFF_UP) in link_handle_bound_to_list()
711 HASHMAP_FOREACH(l, link->bound_to_links) in link_handle_bound_to_list()
718 return link_request_to_bring_up_or_down(link, /* up = */ false); in link_handle_bound_to_list()
720 return link_request_to_bring_up_or_down(link, /* up = */ true); in link_handle_bound_to_list()
725 static int link_handle_bound_by_list(Link *link) { in link_handle_bound_by_list() argument
729 assert(link); in link_handle_bound_by_list()
733 if (hashmap_isempty(link->bound_by_links)) in link_handle_bound_by_list()
736 HASHMAP_FOREACH(l, link->bound_by_links) { in link_handle_bound_by_list()
745 static int link_put_carrier(Link *link, Link *carrier, Hashmap **h) { in link_put_carrier() argument
748 assert(link); in link_put_carrier()
751 if (link == carrier) in link_put_carrier()
761 link_dirty(link); in link_put_carrier()
766 static int link_new_bound_by_list(Link *link) { in link_new_bound_by_list() argument
771 assert(link); in link_new_bound_by_list()
772 assert(link->manager); in link_new_bound_by_list()
774 m = link->manager; in link_new_bound_by_list()
783 if (strv_fnmatch(carrier->network->bind_carrier, link->ifname)) { in link_new_bound_by_list()
784 r = link_put_carrier(link, carrier, &link->bound_by_links); in link_new_bound_by_list()
790 HASHMAP_FOREACH(carrier, link->bound_by_links) { in link_new_bound_by_list()
791 r = link_put_carrier(carrier, link, &carrier->bound_to_links); in link_new_bound_by_list()
799 static int link_new_bound_to_list(Link *link) { in link_new_bound_to_list() argument
804 assert(link); in link_new_bound_to_list()
805 assert(link->manager); in link_new_bound_to_list()
807 if (!link->network) in link_new_bound_to_list()
810 if (strv_isempty(link->network->bind_carrier)) in link_new_bound_to_list()
813 m = link->manager; in link_new_bound_to_list()
816 if (strv_fnmatch(link->network->bind_carrier, carrier->ifname)) { in link_new_bound_to_list()
817 r = link_put_carrier(link, carrier, &link->bound_to_links); in link_new_bound_to_list()
823 HASHMAP_FOREACH(carrier, link->bound_to_links) { in link_new_bound_to_list()
824 r = link_put_carrier(carrier, link, &carrier->bound_by_links); in link_new_bound_to_list()
832 static void link_free_bound_to_list(Link *link) { in link_free_bound_to_list() argument
836 assert(link); in link_free_bound_to_list()
838 while ((bound_to = hashmap_steal_first(link->bound_to_links))) { in link_free_bound_to_list()
841 if (hashmap_remove(bound_to->bound_by_links, INT_TO_PTR(link->ifindex))) in link_free_bound_to_list()
846 link_dirty(link); in link_free_bound_to_list()
849 static void link_free_bound_by_list(Link *link) { in link_free_bound_by_list() argument
853 assert(link); in link_free_bound_by_list()
855 while ((bound_by = hashmap_steal_first(link->bound_by_links))) { in link_free_bound_by_list()
858 if (hashmap_remove(bound_by->bound_to_links, INT_TO_PTR(link->ifindex))) { in link_free_bound_by_list()
865 link_dirty(link); in link_free_bound_by_list()
868 static int link_append_to_master(Link *link) { in link_append_to_master() argument
872 assert(link); in link_append_to_master()
876 if (link_get_master(link, &master) < 0) in link_append_to_master()
879 r = set_ensure_put(&master->slaves, NULL, link); in link_append_to_master()
883 link_ref(link); in link_append_to_master()
887 static void link_drop_from_master(Link *link) { in link_drop_from_master() argument
890 assert(link); in link_drop_from_master()
892 if (!link->manager) in link_drop_from_master()
895 if (link_get_master(link, &master) < 0) in link_drop_from_master()
898 link_unref(set_remove(master->slaves, link)); in link_drop_from_master()
901 static void link_drop_requests(Link *link) { in link_drop_requests() argument
904 assert(link); in link_drop_requests()
905 assert(link->manager); in link_drop_requests()
907 ORDERED_SET_FOREACH(req, link->manager->request_queue) in link_drop_requests()
908 if (req->link == link) in link_drop_requests()
909 request_detach(link->manager, req); in link_drop_requests()
912 static Link *link_drop(Link *link) { in link_drop() argument
913 if (!link) in link_drop()
916 assert(link->manager); in link_drop()
918 link_set_state(link, LINK_STATE_LINGER); in link_drop()
923 link_drop_requests(link); in link_drop()
925 link_free_bound_to_list(link); in link_drop()
926 link_free_bound_by_list(link); in link_drop()
928 link_drop_from_master(link); in link_drop()
930 if (link->state_file) in link_drop()
931 (void) unlink(link->state_file); in link_drop()
933 link_clean(link); in link_drop()
935 STRV_FOREACH(n, link->alternative_names) in link_drop()
936 hashmap_remove(link->manager->links_by_name, *n); in link_drop()
937 hashmap_remove(link->manager->links_by_name, link->ifname); in link_drop()
940 hashmap_remove_value(link->manager->links_by_hw_addr, &link->hw_addr, link); in link_drop()
943 assert_se(hashmap_remove(link->manager->links_by_index, INT_TO_PTR(link->ifindex)) == link); in link_drop()
944 return link_unref(link); in link_drop()
947 static int link_drop_foreign_config(Link *link) { in link_drop_foreign_config() argument
950 assert(link); in link_drop_foreign_config()
951 assert(link->manager); in link_drop_foreign_config()
956 if (IN_SET(link->state, LINK_STATE_UNMANAGED, LINK_STATE_PENDING, LINK_STATE_INITIALIZED)) in link_drop_foreign_config()
958 if (FLAGS_SET(link->flags, IFF_LOOPBACK)) in link_drop_foreign_config()
960 if (link->network->keep_configuration == KEEP_CONFIGURATION_YES) in link_drop_foreign_config()
963 r = link_drop_foreign_routes(link); in link_drop_foreign_config()
965 k = link_drop_foreign_nexthops(link); in link_drop_foreign_config()
969 k = link_drop_foreign_addresses(link); in link_drop_foreign_config()
973 k = link_drop_foreign_neighbors(link); in link_drop_foreign_config()
977 k = manager_drop_foreign_routing_policy_rules(link->manager); in link_drop_foreign_config()
984 static int link_drop_managed_config(Link *link) { in link_drop_managed_config() argument
987 assert(link); in link_drop_managed_config()
988 assert(link->manager); in link_drop_managed_config()
990 r = link_drop_managed_routes(link); in link_drop_managed_config()
992 k = link_drop_managed_nexthops(link); in link_drop_managed_config()
996 k = link_drop_managed_addresses(link); in link_drop_managed_config()
1000 k = link_drop_managed_neighbors(link); in link_drop_managed_config()
1004 k = link_drop_managed_routing_policy_rules(link); in link_drop_managed_config()
1011 static void link_foreignize_config(Link *link) { in link_foreignize_config() argument
1012 assert(link); in link_foreignize_config()
1013 assert(link->manager); in link_foreignize_config()
1015 link_foreignize_routes(link); in link_foreignize_config()
1016 link_foreignize_nexthops(link); in link_foreignize_config()
1017 link_foreignize_addresses(link); in link_foreignize_config()
1018 link_foreignize_neighbors(link); in link_foreignize_config()
1019 link_foreignize_routing_policy_rules(link); in link_foreignize_config()
1022 static int link_configure(Link *link) { in link_configure() argument
1025 assert(link); in link_configure()
1026 assert(link->network); in link_configure()
1027 assert(link->state == LINK_STATE_INITIALIZED); in link_configure()
1029 link_set_state(link, LINK_STATE_CONFIGURING); in link_configure()
1031 r = link_new_bound_to_list(link); in link_configure()
1035 r = link_request_traffic_control(link); in link_configure()
1039 if (link->iftype == ARPHRD_CAN) { in link_configure()
1041 r = link_request_to_set_can(link); in link_configure()
1045 return link_request_to_activate(link); in link_configure()
1048 r = link_request_sr_iov_vfs(link); in link_configure()
1052 r = link_set_sysctl(link); in link_configure()
1056 r = link_request_to_set_mac(link, /* allow_retry = */ true); in link_configure()
1060 r = link_request_to_set_ipoib(link); in link_configure()
1064 r = link_request_to_set_flags(link); in link_configure()
1068 r = link_request_to_set_group(link); in link_configure()
1072 r = link_configure_mtu(link); in link_configure()
1076 r = link_request_to_set_addrgen_mode(link); in link_configure()
1080 r = link_request_to_set_master(link); in link_configure()
1084 r = link_request_stacked_netdevs(link); in link_configure()
1088 r = link_request_to_set_bond(link); in link_configure()
1092 r = link_request_to_set_bridge(link); in link_configure()
1096 r = link_request_to_set_bridge_vlan(link); in link_configure()
1100 r = link_request_to_activate(link); in link_configure()
1104 r = ipv4ll_configure(link); in link_configure()
1108 r = link_request_dhcp4_client(link); in link_configure()
1112 r = link_request_dhcp6_client(link); in link_configure()
1116 r = link_request_ndisc(link); in link_configure()
1120 r = link_request_dhcp_server(link); in link_configure()
1124 r = link_request_radv(link); in link_configure()
1128 r = link_lldp_rx_configure(link); in link_configure()
1132 r = link_lldp_tx_configure(link); in link_configure()
1136 r = link_drop_foreign_config(link); in link_configure()
1140 r = link_request_static_configs(link); in link_configure()
1144 if (!link_has_carrier(link)) in link_configure()
1147 return link_acquire_dynamic_conf(link); in link_configure()
1150 static int link_get_network(Link *link, Network **ret) { in link_get_network() argument
1154 assert(link); in link_get_network()
1155 assert(link->manager); in link_get_network()
1158 ORDERED_HASHMAP_FOREACH(network, link->manager->networks) { in link_get_network()
1163 link->sd_device, in link_get_network()
1164 &link->hw_addr, in link_get_network()
1165 &link->permanent_hw_addr, in link_get_network()
1166 link->driver, in link_get_network()
1167 link->iftype, in link_get_network()
1168 link->kind, in link_get_network()
1169 link->ifname, in link_get_network()
1170 link->alternative_names, in link_get_network()
1171 link->wlan_iftype, in link_get_network()
1172 link->ssid, in link_get_network()
1173 &link->bssid); in link_get_network()
1179 if (network->match.ifname && link->sd_device) { in link_get_network()
1183 … if (sd_device_get_sysattr_value(link->sd_device, "name_assign_type", &attr) >= 0) in link_get_network()
1189 log_link_full(link, warn ? LOG_WARNING : LOG_DEBUG, in link_get_network()
1204 static int link_reconfigure_impl(Link *link, bool force) { in link_reconfigure_impl() argument
1209 assert(link); in link_reconfigure_impl()
1211 …if (!IN_SET(link->state, LINK_STATE_INITIALIZED, LINK_STATE_CONFIGURING, LINK_STATE_CONFIGURED, LI… in link_reconfigure_impl()
1214 r = netdev_get(link->manager, link->ifname, &netdev); in link_reconfigure_impl()
1218 r = link_get_network(link, &network); in link_reconfigure_impl()
1222 if (link->state != LINK_STATE_UNMANAGED && !network) in link_reconfigure_impl()
1226 if (link->network == network && !force) in link_reconfigure_impl()
1230 if (link->state == LINK_STATE_INITIALIZED) in link_reconfigure_impl()
1231 log_link_info(link, "Configuring with %s.", network->filename); in link_reconfigure_impl()
1233 log_link_info(link, "Reconfiguring with %s.", network->filename); in link_reconfigure_impl()
1235 log_link_full(link, link->state == LINK_STATE_INITIALIZED ? LOG_DEBUG : LOG_INFO, in link_reconfigure_impl()
1239 r = link_stop_engines(link, false); in link_reconfigure_impl()
1243 link_drop_requests(link); in link_reconfigure_impl()
1252 link_foreignize_config(link); in link_reconfigure_impl()
1256 r = link_drop_managed_config(link); in link_reconfigure_impl()
1265 link_free_bound_to_list(link); in link_reconfigure_impl()
1267 link_free_engines(link); in link_reconfigure_impl()
1268 link->network = network_unref(link->network); in link_reconfigure_impl()
1270 netdev_unref(link->netdev); in link_reconfigure_impl()
1271 link->netdev = netdev_ref(netdev); in link_reconfigure_impl()
1274 link_set_state(link, LINK_STATE_UNMANAGED); in link_reconfigure_impl()
1279 link->network = network_ref(network); in link_reconfigure_impl()
1280 link_update_operstate(link, true); in link_reconfigure_impl()
1281 link_dirty(link); in link_reconfigure_impl()
1283 link_set_state(link, LINK_STATE_INITIALIZED); in link_reconfigure_impl()
1284 link->activated = false; in link_reconfigure_impl()
1286 r = link_configure(link); in link_reconfigure_impl()
1293 static int link_reconfigure_handler_internal(sd_netlink *rtnl, sd_netlink_message *m, Link *link, b… in link_reconfigure_handler_internal() argument
1296 assert(link); in link_reconfigure_handler_internal()
1298 r = link_getlink_handler_internal(rtnl, m, link, "Failed to update link state"); in link_reconfigure_handler_internal()
1302 r = link_reconfigure_impl(link, force); in link_reconfigure_handler_internal()
1304 link_enter_failed(link); in link_reconfigure_handler_internal()
1311 static int link_reconfigure_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) { in link_reconfigure_handler() argument
1312 return link_reconfigure_handler_internal(rtnl, m, link, /* force = */ false); in link_reconfigure_handler()
1315 static int link_force_reconfigure_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) { in link_force_reconfigure_handler() argument
1316 return link_reconfigure_handler_internal(rtnl, m, link, /* force = */ true); in link_force_reconfigure_handler()
1319 static int link_reconfigure_after_sleep_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link… in link_reconfigure_after_sleep_handler() argument
1322 assert(link); in link_reconfigure_after_sleep_handler()
1324 r = link_reconfigure_handler_internal(rtnl, m, link, /* force = */ false); in link_reconfigure_after_sleep_handler()
1329 if (!IN_SET(link->state, LINK_STATE_CONFIGURING, LINK_STATE_CONFIGURED)) in link_reconfigure_after_sleep_handler()
1333 r = link_stop_engines(link, false); in link_reconfigure_after_sleep_handler()
1335 link_enter_failed(link); in link_reconfigure_after_sleep_handler()
1339 r = link_acquire_dynamic_conf(link); in link_reconfigure_after_sleep_handler()
1341 link_enter_failed(link); in link_reconfigure_after_sleep_handler()
1345 r = link_request_static_configs(link); in link_reconfigure_after_sleep_handler()
1347 link_enter_failed(link); in link_reconfigure_after_sleep_handler()
1354 static int link_reconfigure_internal(Link *link, link_netlink_message_handler_t callback) { in link_reconfigure_internal() argument
1357 assert(link); in link_reconfigure_internal()
1363 if (IN_SET(link->state, LINK_STATE_PENDING, LINK_STATE_INITIALIZED, LINK_STATE_LINGER)) in link_reconfigure_internal()
1366 r = link_call_getlink(link, callback); in link_reconfigure_internal()
1373 int link_reconfigure(Link *link, bool force) { in link_reconfigure() argument
1374 …return link_reconfigure_internal(link, force ? link_force_reconfigure_handler : link_reconfigure_h… in link_reconfigure()
1377 int link_reconfigure_after_sleep(Link *link) { in link_reconfigure_after_sleep() argument
1378 return link_reconfigure_internal(link, link_reconfigure_after_sleep_handler); in link_reconfigure_after_sleep()
1381 static int link_initialized_and_synced(Link *link) { in link_initialized_and_synced() argument
1384 assert(link); in link_initialized_and_synced()
1385 assert(link->manager); in link_initialized_and_synced()
1387 if (link->manager->test_mode) { in link_initialized_and_synced()
1388 log_link_debug(link, "Running in test mode, refusing to enter initialized state."); in link_initialized_and_synced()
1389 link_set_state(link, LINK_STATE_UNMANAGED); in link_initialized_and_synced()
1395 if (!IN_SET(link->state, LINK_STATE_PENDING, LINK_STATE_INITIALIZED)) in link_initialized_and_synced()
1398 log_link_debug(link, "Link state is up-to-date"); in link_initialized_and_synced()
1399 link_set_state(link, LINK_STATE_INITIALIZED); in link_initialized_and_synced()
1401 r = link_new_bound_by_list(link); in link_initialized_and_synced()
1405 r = link_handle_bound_by_list(link); in link_initialized_and_synced()
1409 return link_reconfigure_impl(link, /* force = */ false); in link_initialized_and_synced()
1412 static int link_initialized_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) { in link_initialized_handler() argument
1415 …r = link_getlink_handler_internal(rtnl, m, link, "Failed to wait for the interface to be initializ… in link_initialized_handler()
1419 r = link_initialized_and_synced(link); in link_initialized_handler()
1421 link_enter_failed(link); in link_initialized_handler()
1426 static int link_initialized(Link *link, sd_device *device) { in link_initialized() argument
1427 assert(link); in link_initialized()
1433 sd_device_unref(link->sd_device); in link_initialized()
1434 link->sd_device = device; in link_initialized()
1439 if (!IN_SET(link->state, LINK_STATE_PENDING, LINK_STATE_UNMANAGED)) in link_initialized()
1442 log_link_debug(link, "udev initialized link"); in link_initialized()
1443 link_set_state(link, LINK_STATE_INITIALIZED); in link_initialized()
1450 return link_call_getlink(link, link_initialized_handler); in link_initialized()
1453 static int link_check_initialized(Link *link) { in link_check_initialized() argument
1457 assert(link); in link_check_initialized()
1460 return link_initialized_and_synced(link); in link_check_initialized()
1463 r = sd_device_new_from_ifindex(&device, link->ifindex); in link_check_initialized()
1465 … log_link_debug_errno(link, r, "Could not find device, waiting for device initialization: %m"); in link_check_initialized()
1471 …return log_link_warning_errno(link, r, "Could not determine whether the device is initialized: %m"… in link_check_initialized()
1474 log_link_debug(link, "link pending udev initialization..."); in link_check_initialized()
1480 … return log_link_warning_errno(link, r, "Failed to determine the device is being renamed: %m"); in link_check_initialized()
1482 log_link_debug(link, "Interface is being renamed, pending initialization."); in link_check_initialized()
1486 return link_initialized(link, device); in link_check_initialized()
1492 Link *link = NULL; in manager_udev_process_link() local
1528 r = link_get_by_index(m, ifindex, &link); in manager_udev_process_link()
1534 r = link_initialized(link, device); in manager_udev_process_link()
1536 link_enter_failed(link); in manager_udev_process_link()
1541 static int link_carrier_gained(Link *link) { in link_carrier_gained() argument
1545 assert(link); in link_carrier_gained()
1547 r = event_source_disable(link->carrier_lost_timer); in link_carrier_gained()
1549 … log_link_warning_errno(link, r, "Failed to disable carrier lost timer, ignoring: %m"); in link_carrier_gained()
1565 force_reconfigure = link->previous_ssid && !streq_ptr(link->previous_ssid, link->ssid); in link_carrier_gained()
1566 link->previous_ssid = mfree(link->previous_ssid); in link_carrier_gained()
1568 if (!IN_SET(link->state, LINK_STATE_PENDING, LINK_STATE_FAILED, LINK_STATE_LINGER)) { in link_carrier_gained()
1573 r = link_reconfigure_impl(link, force_reconfigure); in link_carrier_gained()
1578 r = link_handle_bound_by_list(link); in link_carrier_gained()
1582 if (link->iftype == ARPHRD_CAN) in link_carrier_gained()
1586 if (IN_SET(link->state, LINK_STATE_CONFIGURING, LINK_STATE_CONFIGURED)) { in link_carrier_gained()
1587 r = link_acquire_dynamic_conf(link); in link_carrier_gained()
1591 r = link_request_static_configs(link); in link_carrier_gained()
1599 static int link_carrier_lost_impl(Link *link) { in link_carrier_lost_impl() argument
1602 assert(link); in link_carrier_lost_impl()
1604 link->previous_ssid = mfree(link->previous_ssid); in link_carrier_lost_impl()
1606 if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER)) in link_carrier_lost_impl()
1609 if (!link->network) in link_carrier_lost_impl()
1612 r = link_stop_engines(link, false); in link_carrier_lost_impl()
1616 r = link_drop_managed_config(link); in link_carrier_lost_impl()
1624 Link *link = userdata; in link_carrier_lost_handler() local
1627 assert(link); in link_carrier_lost_handler()
1629 r = link_carrier_lost_impl(link); in link_carrier_lost_handler()
1631 log_link_warning_errno(link, r, "Failed to process carrier lost event: %m"); in link_carrier_lost_handler()
1632 link_enter_failed(link); in link_carrier_lost_handler()
1638 static int link_carrier_lost(Link *link) { in link_carrier_lost() argument
1643 assert(link); in link_carrier_lost()
1645 r = link_handle_bound_by_list(link); in link_carrier_lost()
1649 if (link->iftype == ARPHRD_CAN) in link_carrier_lost()
1653 if (!link->network) in link_carrier_lost()
1656 if (link->network->ignore_carrier_loss_set) in link_carrier_lost()
1658 usec = link->network->ignore_carrier_loss_usec; in link_carrier_lost()
1660 else if (link->network->bond && link->wlan_iftype > 0) in link_carrier_lost()
1665 else if (link->network->dhcp_use_mtu && in link_carrier_lost()
1666 link->dhcp_lease && in link_carrier_lost()
1667 sd_dhcp_lease_get_mtu(link->dhcp_lease, &dhcp_mtu) >= 0 && in link_carrier_lost()
1668 dhcp_mtu != link->original_mtu) in link_carrier_lost()
1676 usec = link->network->ignore_carrier_loss_usec; in link_carrier_lost()
1682 return link_carrier_lost_impl(link); in link_carrier_lost()
1684 return event_reset_time_relative(link->manager->event, in link_carrier_lost()
1685 &link->carrier_lost_timer, in link_carrier_lost()
1690 link, in link_carrier_lost()
1696 static int link_admin_state_up(Link *link) { in link_admin_state_up() argument
1699 assert(link); in link_admin_state_up()
1704 if (!link->network) in link_admin_state_up()
1707 if (link->activated && link->network->activation_policy == ACTIVATION_POLICY_ALWAYS_DOWN) { in link_admin_state_up()
1708 log_link_info(link, "Activation policy is \"always-down\", forcing link down."); in link_admin_state_up()
1709 return link_request_to_bring_up_or_down(link, /* up = */ false); in link_admin_state_up()
1714 r = link_set_ipv6_mtu(link); in link_admin_state_up()
1716 log_link_warning_errno(link, r, "Cannot set IPv6 MTU, ignoring: %m"); in link_admin_state_up()
1721 static int link_admin_state_down(Link *link) { in link_admin_state_down() argument
1722 assert(link); in link_admin_state_down()
1724 if (!link->network) in link_admin_state_down()
1727 if (link->activated && link->network->activation_policy == ACTIVATION_POLICY_ALWAYS_UP) { in link_admin_state_down()
1728 log_link_info(link, "Activation policy is \"always-up\", forcing link up."); in link_admin_state_down()
1729 return link_request_to_bring_up_or_down(link, /* up = */ true); in link_admin_state_down()
1735 static bool link_is_enslaved(Link *link) { in link_is_enslaved() argument
1736 if (link->flags & IFF_SLAVE) in link_is_enslaved()
1739 if (link->master_ifindex > 0) in link_is_enslaved()
1758 void link_update_operstate(Link *link, bool also_update_master) { in link_update_operstate() argument
1768 assert(link); in link_update_operstate()
1770 if (link->kernel_operstate == IF_OPER_DORMANT) in link_update_operstate()
1772 else if (link_has_carrier(link)) { in link_update_operstate()
1773 if (link_is_enslaved(link)) in link_update_operstate()
1777 } else if (link->flags & IFF_UP) in link_update_operstate()
1785 SET_FOREACH(slave, link->slaves) { in link_update_operstate()
1793 SET_FOREACH(address, link->addresses) { in link_update_operstate()
1827 if (!link->network || !link->network->required_for_online) in link_update_operstate()
1829 else if (operstate < link->network->required_operstate_for_online.min || in link_update_operstate()
1830 operstate > link->network->required_operstate_for_online.max) in link_update_operstate()
1833 AddressFamily required_family = link->network->required_family_for_online; in link_update_operstate()
1842 if (link->network->required_operstate_for_online.min >= LINK_OPERSTATE_DEGRADED) { in link_update_operstate()
1849 if (link->network->required_operstate_for_online.min >= LINK_OPERSTATE_ROUTABLE) { in link_update_operstate()
1857 if (link->carrier_state != carrier_state) { in link_update_operstate()
1858 link->carrier_state = carrier_state; in link_update_operstate()
1864 if (link->address_state != address_state) { in link_update_operstate()
1865 link->address_state = address_state; in link_update_operstate()
1871 if (link->ipv4_address_state != ipv4_address_state) { in link_update_operstate()
1872 link->ipv4_address_state = ipv4_address_state; in link_update_operstate()
1878 if (link->ipv6_address_state != ipv6_address_state) { in link_update_operstate()
1879 link->ipv6_address_state = ipv6_address_state; in link_update_operstate()
1885 if (link->operstate != operstate) { in link_update_operstate()
1886 link->operstate = operstate; in link_update_operstate()
1892 if (link->online_state != online_state) { in link_update_operstate()
1893 link->online_state = online_state; in link_update_operstate()
1900 link_send_changed_strv(link, p); in link_update_operstate()
1902 link_dirty(link); in link_update_operstate()
1907 if (link_get_master(link, &master) >= 0) in link_update_operstate()
1917 static int link_update_flags(Link *link, sd_netlink_message *message) { in link_update_flags() argument
1923 assert(link); in link_update_flags()
1928 return log_link_debug_errno(link, r, "rtnl: failed to read link flags: %m"); in link_update_flags()
1933 operstate = link->kernel_operstate; in link_update_flags()
1935 return log_link_debug_errno(link, r, "rtnl: failed to read operational state: %m"); in link_update_flags()
1937 if (link->flags == flags && link->kernel_operstate == operstate) in link_update_flags()
1940 if (link->flags != flags) { in link_update_flags()
1943 log_link_debug(link, "Flags change:%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s", in link_update_flags()
1944 FLAG_STRING("LOOPBACK", IFF_LOOPBACK, link->flags, flags), in link_update_flags()
1945 FLAG_STRING("MASTER", IFF_MASTER, link->flags, flags), in link_update_flags()
1946 FLAG_STRING("SLAVE", IFF_SLAVE, link->flags, flags), in link_update_flags()
1947 FLAG_STRING("UP", IFF_UP, link->flags, flags), in link_update_flags()
1948 FLAG_STRING("DORMANT", IFF_DORMANT, link->flags, flags), in link_update_flags()
1949 FLAG_STRING("LOWER_UP", IFF_LOWER_UP, link->flags, flags), in link_update_flags()
1950 FLAG_STRING("RUNNING", IFF_RUNNING, link->flags, flags), in link_update_flags()
1951 FLAG_STRING("MULTICAST", IFF_MULTICAST, link->flags, flags), in link_update_flags()
1952 FLAG_STRING("BROADCAST", IFF_BROADCAST, link->flags, flags), in link_update_flags()
1953 FLAG_STRING("POINTOPOINT", IFF_POINTOPOINT, link->flags, flags), in link_update_flags()
1954 FLAG_STRING("PROMISC", IFF_PROMISC, link->flags, flags), in link_update_flags()
1955 FLAG_STRING("ALLMULTI", IFF_ALLMULTI, link->flags, flags), in link_update_flags()
1956 FLAG_STRING("PORTSEL", IFF_PORTSEL, link->flags, flags), in link_update_flags()
1957 FLAG_STRING("AUTOMEDIA", IFF_AUTOMEDIA, link->flags, flags), in link_update_flags()
1958 FLAG_STRING("DYNAMIC", IFF_DYNAMIC, link->flags, flags), in link_update_flags()
1959 FLAG_STRING("NOARP", IFF_NOARP, link->flags, flags), in link_update_flags()
1960 FLAG_STRING("NOTRAILERS", IFF_NOTRAILERS, link->flags, flags), in link_update_flags()
1961 FLAG_STRING("DEBUG", IFF_DEBUG, link->flags, flags), in link_update_flags()
1962 FLAG_STRING("ECHO", IFF_ECHO, link->flags, flags)); in link_update_flags()
1970 unknown_flags_added = ((link->flags ^ flags) & flags & unknown_flags); in link_update_flags()
1971 unknown_flags_removed = ((link->flags ^ flags) & link->flags & unknown_flags); in link_update_flags()
1974 … log_link_debug(link, "Unknown link flags gained, ignoring: %#.5x", unknown_flags_added); in link_update_flags()
1977 … log_link_debug(link, "Unknown link flags lost, ignoring: %#.5x", unknown_flags_removed); in link_update_flags()
1980 link_was_admin_up = link->flags & IFF_UP; in link_update_flags()
1981 had_carrier = link_has_carrier(link); in link_update_flags()
1983 link->flags = flags; in link_update_flags()
1984 link->kernel_operstate = operstate; in link_update_flags()
1986 link_update_operstate(link, true); in link_update_flags()
1988 if (!link_was_admin_up && (link->flags & IFF_UP)) { in link_update_flags()
1989 log_link_info(link, "Link UP"); in link_update_flags()
1991 r = link_admin_state_up(link); in link_update_flags()
1994 } else if (link_was_admin_up && !(link->flags & IFF_UP)) { in link_update_flags()
1995 log_link_info(link, "Link DOWN"); in link_update_flags()
1997 r = link_admin_state_down(link); in link_update_flags()
2002 if (!had_carrier && link_has_carrier(link)) { in link_update_flags()
2003 log_link_info(link, "Gained carrier"); in link_update_flags()
2005 r = link_carrier_gained(link); in link_update_flags()
2008 } else if (had_carrier && !link_has_carrier(link)) { in link_update_flags()
2009 log_link_info(link, "Lost carrier"); in link_update_flags()
2011 r = link_carrier_lost(link); in link_update_flags()
2019 static int link_update_master(Link *link, sd_netlink_message *message) { in link_update_master() argument
2022 assert(link); in link_update_master()
2029 return log_link_debug_errno(link, r, "rtnl: failed to read master ifindex: %m"); in link_update_master()
2031 if (master_ifindex == link->ifindex) in link_update_master()
2034 if (master_ifindex == link->master_ifindex) in link_update_master()
2037 if (link->master_ifindex == 0) in link_update_master()
2038 log_link_debug(link, "Attached to master interface: %i", master_ifindex); in link_update_master()
2040 log_link_debug(link, "Detached from master interface: %i", link->master_ifindex); in link_update_master()
2042 … log_link_debug(link, "Master interface changed: %i → %i", link->master_ifindex, master_ifindex); in link_update_master()
2044 link_drop_from_master(link); in link_update_master()
2046 link->master_ifindex = master_ifindex; in link_update_master()
2048 r = link_append_to_master(link); in link_update_master()
2050 return log_link_debug_errno(link, r, "Failed to append link to master: %m"); in link_update_master()
2055 static int link_update_driver(Link *link, sd_netlink_message *message) { in link_update_driver() argument
2058 assert(link); in link_update_driver()
2059 assert(link->manager); in link_update_driver()
2063 if (link->driver) in link_update_driver()
2069 if (link->state != (udev_available() ? LINK_STATE_INITIALIZED : LINK_STATE_PENDING)) in link_update_driver()
2072 r = ethtool_get_driver(&link->manager->ethtool_fd, link->ifname, &link->driver); in link_update_driver()
2074 log_link_debug_errno(link, r, "Failed to get driver, continuing without: %m"); in link_update_driver()
2078 log_link_debug(link, "Found driver: %s", strna(link->driver)); in link_update_driver()
2080 if (streq_ptr(link->driver, "dsa")) { in link_update_driver()
2085 …return log_link_debug_errno(link, r, "rtnl: failed to read ifindex of the DSA master interface: %m… in link_update_driver()
2088 …log_link_debug(link, "rtnl: received too large DSA master ifindex (%"PRIu32" > INT_MAX), ignoring.… in link_update_driver()
2093 link->dsa_master_ifindex = (int) dsa_master_ifindex; in link_update_driver()
2099 static int link_update_permanent_hardware_address(Link *link, sd_netlink_message *message) { in link_update_permanent_hardware_address() argument
2102 assert(link); in link_update_permanent_hardware_address()
2103 assert(link->manager); in link_update_permanent_hardware_address()
2106 if (link->permanent_hw_addr.length > 0) in link_update_permanent_hardware_address()
2112 if (link->state != (udev_available() ? LINK_STATE_INITIALIZED : LINK_STATE_PENDING)) in link_update_permanent_hardware_address()
2115 r = netlink_message_read_hw_addr(message, IFLA_PERM_ADDRESS, &link->permanent_hw_addr); in link_update_permanent_hardware_address()
2118 … return log_link_debug_errno(link, r, "Failed to read IFLA_PERM_ADDRESS attribute: %m"); in link_update_permanent_hardware_address()
2122 …r = ethtool_get_permanent_hw_addr(&link->manager->ethtool_fd, link->ifname, &link->permanent_hw_ad… in link_update_permanent_hardware_address()
2124 … log_link_debug_errno(link, r, "Permanent hardware address not found, continuing without: %m"); in link_update_permanent_hardware_address()
2128 if (link->permanent_hw_addr.length > 0) in link_update_permanent_hardware_address()
2129 …log_link_debug(link, "Saved permanent hardware address: %s", HW_ADDR_TO_STR(&link->permanent_hw_ad… in link_update_permanent_hardware_address()
2134 static int link_update_hardware_address(Link *link, sd_netlink_message *message) { in link_update_hardware_address() argument
2138 assert(link); in link_update_hardware_address()
2141 r = netlink_message_read_hw_addr(message, IFLA_BROADCAST, &link->bcast_addr); in link_update_hardware_address()
2143 return log_link_debug_errno(link, r, "rtnl: failed to read broadcast address: %m"); in link_update_hardware_address()
2149 return log_link_debug_errno(link, r, "rtnl: failed to read hardware address: %m"); in link_update_hardware_address()
2151 if (hw_addr_equal(&link->hw_addr, &addr)) in link_update_hardware_address()
2154 if (link->hw_addr.length == 0) in link_update_hardware_address()
2155 log_link_debug(link, "Saved hardware address: %s", HW_ADDR_TO_STR(&addr)); in link_update_hardware_address()
2157 log_link_debug(link, "Hardware address is changed: %s → %s", in link_update_hardware_address()
2158 HW_ADDR_TO_STR(&link->hw_addr), HW_ADDR_TO_STR(&addr)); in link_update_hardware_address()
2160 hashmap_remove_value(link->manager->links_by_hw_addr, &link->hw_addr, link); in link_update_hardware_address()
2163 link->hw_addr = addr; in link_update_hardware_address()
2165 if (!hw_addr_is_null(&link->hw_addr)) { in link_update_hardware_address()
2166 … r = hashmap_ensure_put(&link->manager->links_by_hw_addr, &hw_addr_hash_ops, &link->hw_addr, link); in link_update_hardware_address()
2167 if (r == -EEXIST && streq_ptr(link->kind, "bond")) in link_update_hardware_address()
2169 r = hashmap_replace(link->manager->links_by_hw_addr, &link->hw_addr, link); in link_update_hardware_address()
2171 … log_link_debug_errno(link, r, "Failed to manage link by its new hardware address, ignoring: %m"); in link_update_hardware_address()
2174 r = ipv4ll_update_mac(link); in link_update_hardware_address()
2176 … return log_link_debug_errno(link, r, "Could not update MAC address in IPv4 ACD client: %m"); in link_update_hardware_address()
2178 r = ipv4ll_update_mac(link); in link_update_hardware_address()
2180 … return log_link_debug_errno(link, r, "Could not update MAC address in IPv4LL client: %m"); in link_update_hardware_address()
2182 r = dhcp4_update_mac(link); in link_update_hardware_address()
2184 … return log_link_debug_errno(link, r, "Could not update MAC address in DHCP client: %m"); in link_update_hardware_address()
2186 r = dhcp6_update_mac(link); in link_update_hardware_address()
2188 … return log_link_debug_errno(link, r, "Could not update MAC address in DHCPv6 client: %m"); in link_update_hardware_address()
2190 r = radv_update_mac(link); in link_update_hardware_address()
2192 … return log_link_debug_errno(link, r, "Could not update MAC address for Router Advertisement: %m"); in link_update_hardware_address()
2194 if (link->ndisc) { in link_update_hardware_address()
2195 r = sd_ndisc_set_mac(link->ndisc, &link->hw_addr.ether); in link_update_hardware_address()
2197 return log_link_debug_errno(link, r, "Could not update MAC for NDisc: %m"); in link_update_hardware_address()
2200 if (link->lldp_rx) { in link_update_hardware_address()
2201 r = sd_lldp_rx_set_filter_address(link->lldp_rx, &link->hw_addr.ether); in link_update_hardware_address()
2203 … return log_link_debug_errno(link, r, "Could not update MAC address for LLDP Rx: %m"); in link_update_hardware_address()
2206 if (link->lldp_tx) { in link_update_hardware_address()
2207 r = sd_lldp_tx_set_hwaddr(link->lldp_tx, &link->hw_addr.ether); in link_update_hardware_address()
2209 … return log_link_debug_errno(link, r, "Could not update MAC address for LLDP Tx: %m"); in link_update_hardware_address()
2215 static int link_update_mtu(Link *link, sd_netlink_message *message) { in link_update_mtu() argument
2219 assert(link); in link_update_mtu()
2226 … return log_link_debug_errno(link, r, "rtnl: failed to read MTU in RTM_NEWLINK message: %m"); in link_update_mtu()
2232 …return log_link_debug_errno(link, r, "rtnl: failed to read minimum MTU in RTM_NEWLINK message: %m"… in link_update_mtu()
2236 …return log_link_debug_errno(link, r, "rtnl: failed to read maximum MTU in RTM_NEWLINK message: %m"… in link_update_mtu()
2241 link->min_mtu = min_mtu; in link_update_mtu()
2242 link->max_mtu = max_mtu; in link_update_mtu()
2244 if (link->original_mtu == 0) { in link_update_mtu()
2245 link->original_mtu = mtu; in link_update_mtu()
2246 … log_link_debug(link, "Saved original MTU %" PRIu32" (min: %"PRIu32", max: %"PRIu32")", in link_update_mtu()
2247 link->original_mtu, link->min_mtu, link->max_mtu); in link_update_mtu()
2250 if (link->mtu == mtu) in link_update_mtu()
2253 if (link->mtu != 0) in link_update_mtu()
2254 … log_link_debug(link, "MTU is changed: %"PRIu32" → %"PRIu32" (min: %"PRIu32", max: %"PRIu32")", in link_update_mtu()
2255 link->mtu, mtu, link->min_mtu, link->max_mtu); in link_update_mtu()
2257 link->mtu = mtu; in link_update_mtu()
2259 if (link->dhcp_client) { in link_update_mtu()
2260 r = sd_dhcp_client_set_mtu(link->dhcp_client, link->mtu); in link_update_mtu()
2262 … return log_link_debug_errno(link, r, "Could not update MTU in DHCP client: %m"); in link_update_mtu()
2265 if (link->radv) { in link_update_mtu()
2266 r = sd_radv_set_mtu(link->radv, link->mtu); in link_update_mtu()
2268 … return log_link_debug_errno(link, r, "Could not set MTU for Router Advertisement: %m"); in link_update_mtu()
2274 static int link_update_alternative_names(Link *link, sd_netlink_message *message) { in link_update_alternative_names() argument
2278 assert(link); in link_update_alternative_names()
2287 return log_link_debug_errno(link, r, "rtnl: failed to read alternative names: %m"); in link_update_alternative_names()
2289 if (strv_equal(altnames, link->alternative_names)) in link_update_alternative_names()
2292 STRV_FOREACH(n, link->alternative_names) in link_update_alternative_names()
2293 hashmap_remove(link->manager->links_by_name, *n); in link_update_alternative_names()
2295 strv_free_and_replace(link->alternative_names, altnames); in link_update_alternative_names()
2297 STRV_FOREACH(n, link->alternative_names) { in link_update_alternative_names()
2298 r = hashmap_ensure_put(&link->manager->links_by_name, &string_hash_ops, *n, link); in link_update_alternative_names()
2300 … return log_link_debug_errno(link, r, "Failed to manage link by its new alternative names: %m"); in link_update_alternative_names()
2306 static int link_update_name(Link *link, sd_netlink_message *message) { in link_update_name() argument
2311 assert(link); in link_update_name()
2319 … return log_link_debug_errno(link, r, "Failed to read interface name in RTM_NEWLINK message: %m"); in link_update_name()
2321 if (streq(ifname, link->ifname)) in link_update_name()
2324 r = format_ifname(link->ifindex, ifname_from_index); in link_update_name()
2326 … return log_link_debug_errno(link, r, "Could not get interface name for index %i.", link->ifindex); in link_update_name()
2329 … log_link_debug(link, "New interface name '%s' received from the kernel does not correspond " in link_update_name()
2335 log_link_info(link, "Interface name change detected, renamed to %s.", ifname); in link_update_name()
2337 hashmap_remove(link->manager->links_by_name, link->ifname); in link_update_name()
2339 r = free_and_strdup(&link->ifname, ifname); in link_update_name()
2343 r = hashmap_ensure_put(&link->manager->links_by_name, &string_hash_ops, link->ifname, link); in link_update_name()
2345 return log_link_debug_errno(link, r, "Failed to manage link by its new name: %m"); in link_update_name()
2347 if (link->dhcp_client) { in link_update_name()
2348 r = sd_dhcp_client_set_ifname(link->dhcp_client, link->ifname); in link_update_name()
2350 … return log_link_debug_errno(link, r, "Failed to update interface name in DHCP client: %m"); in link_update_name()
2353 if (link->dhcp6_client) { in link_update_name()
2354 r = sd_dhcp6_client_set_ifname(link->dhcp6_client, link->ifname); in link_update_name()
2356 … return log_link_debug_errno(link, r, "Failed to update interface name in DHCP6 client: %m"); in link_update_name()
2359 if (link->ndisc) { in link_update_name()
2360 r = sd_ndisc_set_ifname(link->ndisc, link->ifname); in link_update_name()
2362 … return log_link_debug_errno(link, r, "Failed to update interface name in NDisc: %m"); in link_update_name()
2365 if (link->dhcp_server) { in link_update_name()
2366 r = sd_dhcp_server_set_ifname(link->dhcp_server, link->ifname); in link_update_name()
2368 … return log_link_debug_errno(link, r, "Failed to update interface name in DHCP server: %m"); in link_update_name()
2371 if (link->radv) { in link_update_name()
2372 r = sd_radv_set_ifname(link->radv, link->ifname); in link_update_name()
2374 …return log_link_debug_errno(link, r, "Failed to update interface name in Router Advertisement: %m"… in link_update_name()
2377 if (link->lldp_rx) { in link_update_name()
2378 r = sd_lldp_rx_set_ifname(link->lldp_rx, link->ifname); in link_update_name()
2380 … return log_link_debug_errno(link, r, "Failed to update interface name in LLDP Rx: %m"); in link_update_name()
2383 if (link->lldp_tx) { in link_update_name()
2384 r = sd_lldp_tx_set_ifname(link->lldp_tx, link->ifname); in link_update_name()
2386 … return log_link_debug_errno(link, r, "Failed to update interface name in LLDP Tx: %m"); in link_update_name()
2389 if (link->ipv4ll) { in link_update_name()
2390 r = sd_ipv4ll_set_ifname(link->ipv4ll, link->ifname); in link_update_name()
2392 … return log_link_debug_errno(link, r, "Failed to update interface name in IPv4LL client: %m"); in link_update_name()
2395 r = ipv4acd_set_ifname(link); in link_update_name()
2397 … return log_link_debug_errno(link, r, "Failed to update interface name in IPv4ACD client: %m"); in link_update_name()
2402 static int link_update(Link *link, sd_netlink_message *message) { in link_update() argument
2405 assert(link); in link_update()
2408 r = link_update_name(link, message); in link_update()
2412 r = link_update_alternative_names(link, message); in link_update()
2416 r = link_update_mtu(link, message); in link_update()
2420 r = link_update_driver(link, message); in link_update()
2424 r = link_update_permanent_hardware_address(link, message); in link_update()
2428 r = link_update_hardware_address(link, message); in link_update()
2432 r = link_update_master(link, message); in link_update()
2436 r = link_update_ipv6ll_addrgen_mode(link, message); in link_update()
2440 return link_update_flags(link, message); in link_update()
2443 static Link *link_drop_or_unref(Link *link) { in link_drop_or_unref() argument
2444 if (!link) in link_drop_or_unref()
2446 if (!link->manager) in link_drop_or_unref()
2447 return link_unref(link); in link_drop_or_unref()
2448 return link_drop(link); in link_drop_or_unref()
2455 _cleanup_(link_drop_or_unrefp) Link *link = NULL; in link_new()
2500 link = new(Link, 1); in link_new()
2501 if (!link) in link_new()
2504 *link = (Link) { in link_new()
2527 r = hashmap_ensure_put(&manager->links_by_index, NULL, INT_TO_PTR(link->ifindex), link); in link_new()
2529 return log_link_debug_errno(link, r, "Failed to store link into manager: %m"); in link_new()
2531 link->manager = manager; in link_new()
2533 r = hashmap_ensure_put(&manager->links_by_name, &string_hash_ops, link->ifname, link); in link_new()
2535 … return log_link_debug_errno(link, r, "Failed to manage link by its interface name: %m"); in link_new()
2537 log_link_debug(link, "Saved new link: ifindex=%i, iftype=%s(%u), kind=%s", in link_new()
2538 … link->ifindex, strna(arphrd_to_name(link->iftype)), link->iftype, strna(link->kind)); in link_new()
2540 *ret = TAKE_PTR(link); in link_new()
2545 Link *link = NULL; in manager_rtnl_process_link() local
2587 (void) link_get_by_index(manager, ifindex, &link); in manager_rtnl_process_link()
2601 if (!link) { in manager_rtnl_process_link()
2603 r = link_new(manager, message, &link); in manager_rtnl_process_link()
2609 r = link_update(link, message); in manager_rtnl_process_link()
2611 … log_link_warning_errno(link, r, "Could not process link message: %m"); in manager_rtnl_process_link()
2612 link_enter_failed(link); in manager_rtnl_process_link()
2616 r = link_check_initialized(link); in manager_rtnl_process_link()
2618 … log_link_warning_errno(link, r, "Failed to check link is initialized: %m"); in manager_rtnl_process_link()
2619 link_enter_failed(link); in manager_rtnl_process_link()
2623 r = link_update(link, message); in manager_rtnl_process_link()
2625 … log_link_warning_errno(link, r, "Could not process link message: %m"); in manager_rtnl_process_link()
2626 link_enter_failed(link); in manager_rtnl_process_link()
2633 link_drop(link); in manager_rtnl_process_link()
2644 int link_getlink_handler_internal(sd_netlink *rtnl, sd_netlink_message *m, Link *link, const char *… in link_getlink_handler_internal() argument
2649 assert(link); in link_getlink_handler_internal()
2652 if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER)) in link_getlink_handler_internal()
2657 log_link_message_warning_errno(link, m, r, error_msg); in link_getlink_handler_internal()
2658 link_enter_failed(link); in link_getlink_handler_internal()
2664 … log_link_debug_errno(link, r, "rtnl: failed to read link message type, ignoring: %m"); in link_getlink_handler_internal()
2668 log_link_debug(link, "rtnl: received invalid link message type, ignoring."); in link_getlink_handler_internal()
2672 r = link_update(link, m); in link_getlink_handler_internal()
2674 link_enter_failed(link); in link_getlink_handler_internal()
2681 int link_call_getlink(Link *link, link_netlink_message_handler_t callback) { in link_call_getlink() argument
2685 assert(link); in link_call_getlink()
2686 assert(link->manager); in link_call_getlink()
2687 assert(link->manager->rtnl); in link_call_getlink()
2690 r = sd_rtnl_message_new_link(link->manager->rtnl, &req, RTM_GETLINK, link->ifindex); in link_call_getlink()
2694 r = netlink_call_async(link->manager->rtnl, NULL, req, callback, in link_call_getlink()
2695 link_netlink_destroy_callback, link); in link_call_getlink()
2699 link_ref(link); in link_call_getlink()