1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
4 #include <netinet/in.h>
6 #include <linux/if_arp.h>
7 #include <linux/if_link.h>
8 #include <sys/socket.h>
11 #include "alloc-util.h"
16 #include "device-private.h"
17 #include "device-util.h"
18 #include "dhcp-identifier.h"
19 #include "dhcp-lease-internal.h"
21 #include "ethtool-util.h"
24 #include "format-util.h"
27 #include "missing_network.h"
28 #include "netlink-util.h"
29 #include "network-internal.h"
30 #include "networkd-address-label.h"
31 #include "networkd-address.h"
32 #include "networkd-bridge-fdb.h"
33 #include "networkd-bridge-mdb.h"
34 #include "networkd-can.h"
35 #include "networkd-dhcp-server.h"
36 #include "networkd-dhcp4.h"
37 #include "networkd-dhcp6.h"
38 #include "networkd-ipv4acd.h"
39 #include "networkd-ipv4ll.h"
40 #include "networkd-ipv6-proxy-ndp.h"
41 #include "networkd-link-bus.h"
42 #include "networkd-link.h"
43 #include "networkd-lldp-tx.h"
44 #include "networkd-manager.h"
45 #include "networkd-ndisc.h"
46 #include "networkd-neighbor.h"
47 #include "networkd-nexthop.h"
48 #include "networkd-queue.h"
49 #include "networkd-radv.h"
50 #include "networkd-routing-policy-rule.h"
51 #include "networkd-setlink.h"
52 #include "networkd-sriov.h"
53 #include "networkd-state-file.h"
54 #include "networkd-sysctl.h"
55 #include "networkd-wifi.h"
57 #include "socket-util.h"
58 #include "stat-util.h"
59 #include "stdio-util.h"
60 #include "string-table.h"
63 #include "tmpfile-util.h"
64 #include "udev-util.h"
68 bool link_ipv4ll_enabled(Link
*link
) {
71 if (link
->flags
& IFF_LOOPBACK
)
77 if (link
->iftype
== ARPHRD_CAN
)
80 if (link
->hw_addr
.length
!= ETH_ALEN
)
83 if (ether_addr_is_null(&link
->hw_addr
.ether
))
86 if (STRPTR_IN_SET(link
->kind
,
87 "vrf", "wireguard", "ipip", "gre", "ip6gre","ip6tnl", "sit", "vti",
88 "vti6", "nlmon", "xfrm", "bareudp"))
91 /* L3 or L3S mode do not support ARP. */
92 if (IN_SET(link_get_ipvlan_mode(link
), NETDEV_IPVLAN_MODE_L3
, NETDEV_IPVLAN_MODE_L3S
))
95 if (link
->network
->bond
)
98 return link
->network
->link_local
& ADDRESS_FAMILY_IPV4
;
101 bool link_ipv6ll_enabled(Link
*link
) {
104 if (!socket_ipv6_is_supported())
107 if (link
->flags
& IFF_LOOPBACK
)
113 if (link
->iftype
== ARPHRD_CAN
)
116 if (STRPTR_IN_SET(link
->kind
, "vrf", "wireguard", "ipip", "gre", "sit", "vti", "nlmon"))
119 if (link
->network
->bond
)
122 return link
->network
->link_local
& ADDRESS_FAMILY_IPV6
;
125 bool link_ipv6_enabled(Link
*link
) {
128 if (!socket_ipv6_is_supported())
131 if (link
->network
->bond
)
134 if (link
->iftype
== ARPHRD_CAN
)
137 /* DHCPv6 client will not be started if no IPv6 link-local address is configured. */
138 if (link_ipv6ll_enabled(link
))
141 if (network_has_static_ipv6_configurations(link
->network
))
147 bool link_is_ready_to_configure(Link
*link
, bool allow_unmanaged
) {
150 if (!link
->network
) {
151 if (!allow_unmanaged
)
154 return link_has_carrier(link
);
157 if (!IN_SET(link
->state
, LINK_STATE_CONFIGURING
, LINK_STATE_CONFIGURED
))
160 if (!link
->network
->configure_without_carrier
) {
161 if (link
->set_flags_messages
> 0)
164 if (!link_has_carrier(link
))
168 if (link
->set_link_messages
> 0)
171 if (!link
->stacked_netdevs_created
)
174 if (!link
->activated
)
180 void link_ntp_settings_clear(Link
*link
) {
181 link
->ntp
= strv_free(link
->ntp
);
184 void link_dns_settings_clear(Link
*link
) {
185 if (link
->n_dns
!= UINT_MAX
)
186 for (unsigned i
= 0; i
< link
->n_dns
; i
++)
187 in_addr_full_free(link
->dns
[i
]);
188 link
->dns
= mfree(link
->dns
);
189 link
->n_dns
= UINT_MAX
;
191 link
->search_domains
= ordered_set_free(link
->search_domains
);
192 link
->route_domains
= ordered_set_free(link
->route_domains
);
194 link
->dns_default_route
= -1;
195 link
->llmnr
= _RESOLVE_SUPPORT_INVALID
;
196 link
->mdns
= _RESOLVE_SUPPORT_INVALID
;
197 link
->dnssec_mode
= _DNSSEC_MODE_INVALID
;
198 link
->dns_over_tls_mode
= _DNS_OVER_TLS_MODE_INVALID
;
200 link
->dnssec_negative_trust_anchors
= set_free_free(link
->dnssec_negative_trust_anchors
);
203 static void link_free_engines(Link
*link
) {
207 link
->dhcp_server
= sd_dhcp_server_unref(link
->dhcp_server
);
208 link
->dhcp_client
= sd_dhcp_client_unref(link
->dhcp_client
);
209 link
->dhcp_lease
= sd_dhcp_lease_unref(link
->dhcp_lease
);
211 link
->lldp
= sd_lldp_unref(link
->lldp
);
212 link_lldp_emit_stop(link
);
216 link
->ipv4ll
= sd_ipv4ll_unref(link
->ipv4ll
);
217 link
->dhcp6_client
= sd_dhcp6_client_unref(link
->dhcp6_client
);
218 link
->dhcp6_lease
= sd_dhcp6_lease_unref(link
->dhcp6_lease
);
219 link
->ndisc
= sd_ndisc_unref(link
->ndisc
);
220 link
->radv
= sd_radv_unref(link
->radv
);
223 static Link
*link_free(Link
*link
) {
226 link_ntp_settings_clear(link
);
227 link_dns_settings_clear(link
);
229 link
->routes
= set_free(link
->routes
);
230 link
->routes_foreign
= set_free(link
->routes_foreign
);
231 link
->dhcp_routes
= set_free(link
->dhcp_routes
);
232 link
->dhcp_routes_old
= set_free(link
->dhcp_routes_old
);
233 link
->dhcp6_routes
= set_free(link
->dhcp6_routes
);
234 link
->dhcp6_routes_old
= set_free(link
->dhcp6_routes_old
);
235 link
->dhcp6_pd_routes
= set_free(link
->dhcp6_pd_routes
);
236 link
->dhcp6_pd_routes_old
= set_free(link
->dhcp6_pd_routes_old
);
237 link
->ndisc_routes
= set_free(link
->ndisc_routes
);
239 link
->nexthops
= set_free(link
->nexthops
);
240 link
->nexthops_foreign
= set_free(link
->nexthops_foreign
);
242 link
->neighbors
= set_free(link
->neighbors
);
243 link
->neighbors_foreign
= set_free(link
->neighbors_foreign
);
245 link
->addresses
= set_free(link
->addresses
);
246 link
->addresses_foreign
= set_free(link
->addresses_foreign
);
247 link
->addresses_ipv4acd
= set_free(link
->addresses_ipv4acd
);
248 link
->pool_addresses
= set_free(link
->pool_addresses
);
249 link
->static_addresses
= set_free(link
->static_addresses
);
250 link
->dhcp6_addresses
= set_free(link
->dhcp6_addresses
);
251 link
->dhcp6_addresses_old
= set_free(link
->dhcp6_addresses_old
);
252 link
->dhcp6_pd_addresses
= set_free(link
->dhcp6_pd_addresses
);
253 link
->dhcp6_pd_addresses_old
= set_free(link
->dhcp6_pd_addresses_old
);
254 link
->ndisc_addresses
= set_free(link
->ndisc_addresses
);
256 link
->dhcp6_pd_prefixes
= set_free(link
->dhcp6_pd_prefixes
);
258 link_free_engines(link
);
261 strv_free(link
->alternative_names
);
266 unlink_and_free(link
->lease_file
);
267 unlink_and_free(link
->lldp_file
);
268 unlink_and_free(link
->state_file
);
270 sd_device_unref(link
->sd_device
);
272 hashmap_free(link
->bound_to_links
);
273 hashmap_free(link
->bound_by_links
);
275 set_free_with_destructor(link
->slaves
, link_unref
);
277 network_unref(link
->network
);
282 DEFINE_TRIVIAL_REF_UNREF_FUNC(Link
, link
, link_free
);
284 int link_get_by_index(Manager
*m
, int ifindex
, Link
**ret
) {
290 link
= hashmap_get(m
->links_by_index
, INT_TO_PTR(ifindex
));
299 int link_get_by_name(Manager
*m
, const char *ifname
, Link
**ret
) {
305 link
= hashmap_get(m
->links_by_name
, ifname
);
314 int link_get_by_hw_addr(Manager
*m
, const struct hw_addr_data
*hw_addr
, Link
**ret
) {
320 link
= hashmap_get(m
->links_by_hw_addr
, hw_addr
);
329 int link_get_master(Link
*link
, Link
**ret
) {
331 assert(link
->manager
);
334 if (link
->master_ifindex
<= 0 || link
->master_ifindex
== link
->ifindex
)
337 return link_get_by_index(link
->manager
, link
->master_ifindex
, ret
);
340 void link_set_state(Link
*link
, LinkState state
) {
343 if (link
->state
== state
)
346 log_link_debug(link
, "State changed: %s -> %s",
347 link_state_to_string(link
->state
),
348 link_state_to_string(state
));
352 link_send_changed(link
, "AdministrativeState", NULL
);
356 int link_stop_engines(Link
*link
, bool may_keep_dhcp
) {
360 assert(link
->manager
);
361 assert(link
->manager
->event
);
363 bool keep_dhcp
= may_keep_dhcp
&&
365 !link
->network
->dhcp_send_decline
&& /* IPv4 ACD for the DHCPv4 address is running. */
366 (link
->manager
->restarting
||
367 FLAGS_SET(link
->network
->keep_configuration
, KEEP_CONFIGURATION_DHCP_ON_STOP
));
370 k
= sd_dhcp_client_stop(link
->dhcp_client
);
372 r
= log_link_warning_errno(link
, k
, "Could not stop DHCPv4 client: %m");
375 k
= sd_dhcp_server_stop(link
->dhcp_server
);
377 r
= log_link_warning_errno(link
, k
, "Could not stop DHCPv4 server: %m");
379 k
= sd_lldp_stop(link
->lldp
);
381 r
= log_link_warning_errno(link
, k
, "Could not stop LLDP: %m");
383 k
= sd_ipv4ll_stop(link
->ipv4ll
);
385 r
= log_link_warning_errno(link
, k
, "Could not stop IPv4 link-local: %m");
387 k
= ipv4acd_stop(link
);
389 r
= log_link_warning_errno(link
, k
, "Could not stop IPv4 ACD client: %m");
391 k
= sd_dhcp6_client_stop(link
->dhcp6_client
);
393 r
= log_link_warning_errno(link
, k
, "Could not stop DHCPv6 client: %m");
395 k
= dhcp6_pd_remove(link
);
397 r
= log_link_warning_errno(link
, k
, "Could not remove DHCPv6 PD addresses and routes: %m");
399 k
= sd_ndisc_stop(link
->ndisc
);
401 r
= log_link_warning_errno(link
, k
, "Could not stop IPv6 Router Discovery: %m");
403 k
= sd_radv_stop(link
->radv
);
405 r
= log_link_warning_errno(link
, k
, "Could not stop IPv6 Router Advertisement: %m");
407 link_lldp_emit_stop(link
);
411 void link_enter_failed(Link
*link
) {
414 if (IN_SET(link
->state
, LINK_STATE_FAILED
, LINK_STATE_LINGER
))
417 log_link_warning(link
, "Failed");
419 link_set_state(link
, LINK_STATE_FAILED
);
421 (void) link_stop_engines(link
, false);
424 void link_check_ready(Link
*link
) {
429 if (link
->state
== LINK_STATE_CONFIGURED
)
432 if (link
->state
!= LINK_STATE_CONFIGURING
)
433 return (void) log_link_debug(link
, "%s(): link is in %s state.", __func__
, link_state_to_string(link
->state
));
436 return (void) log_link_debug(link
, "%s(): link is unmanaged.", __func__
);
438 if (!link
->tc_configured
)
439 return (void) log_link_debug(link
, "%s(): traffic controls are not configured.", __func__
);
441 if (link
->set_link_messages
> 0)
442 return (void) log_link_debug(link
, "%s(): link layer is configuring.", __func__
);
444 if (!link
->activated
)
445 return (void) log_link_debug(link
, "%s(): link is not activated.", __func__
);
447 if (link
->iftype
== ARPHRD_CAN
) {
448 /* let's shortcut things for CAN which doesn't need most of checks below. */
449 link_set_state(link
, LINK_STATE_CONFIGURED
);
453 if (!link
->static_addresses_configured
)
454 return (void) log_link_debug(link
, "%s(): static addresses are not configured.", __func__
);
456 SET_FOREACH(a
, link
->addresses
)
457 if (!address_is_ready(a
)) {
458 _cleanup_free_
char *str
= NULL
;
460 (void) in_addr_prefix_to_string(a
->family
, &a
->in_addr
, a
->prefixlen
, &str
);
461 return (void) log_link_debug(link
, "%s(): an address %s is not ready.", __func__
, strna(str
));
464 if (!link
->static_address_labels_configured
)
465 return (void) log_link_debug(link
, "%s(): static address labels are not configured.", __func__
);
467 if (!link
->static_bridge_fdb_configured
)
468 return (void) log_link_debug(link
, "%s(): static bridge MDB entries are not configured.", __func__
);
470 if (!link
->static_bridge_mdb_configured
)
471 return (void) log_link_debug(link
, "%s(): static bridge MDB entries are not configured.", __func__
);
473 if (!link
->static_ipv6_proxy_ndp_configured
)
474 return (void) log_link_debug(link
, "%s(): static IPv6 proxy NDP addresses are not configured.", __func__
);
476 if (!link
->static_neighbors_configured
)
477 return (void) log_link_debug(link
, "%s(): static neighbors are not configured.", __func__
);
479 if (!link
->static_nexthops_configured
)
480 return (void) log_link_debug(link
, "%s(): static nexthops are not configured.", __func__
);
482 if (!link
->static_routes_configured
)
483 return (void) log_link_debug(link
, "%s(): static routes are not configured.", __func__
);
485 if (!link
->static_routing_policy_rules_configured
)
486 return (void) log_link_debug(link
, "%s(): static routing policy rules are not configured.", __func__
);
488 if (!link
->sr_iov_configured
)
489 return (void) log_link_debug(link
, "%s(): SR-IOV is not configured.", __func__
);
491 /* IPv6LL is assigned after the link gains its carrier. */
492 if (!link
->network
->configure_without_carrier
&&
493 link_ipv6ll_enabled(link
) &&
494 !in6_addr_is_set(&link
->ipv6ll_address
))
495 return (void) log_link_debug(link
, "%s(): IPv6LL is not configured yet.", __func__
);
497 bool has_ndisc_address
= false;
499 SET_FOREACH(n
, link
->ndisc_addresses
)
501 has_ndisc_address
= true;
505 if ((link_dhcp4_enabled(link
) || link_dhcp6_with_address_enabled(link
) || link_ipv4ll_enabled(link
)) &&
506 !link
->dhcp_address
&& set_isempty(link
->dhcp6_addresses
) && !has_ndisc_address
&&
507 !link
->ipv4ll_address_configured
)
508 /* When DHCP[46] or IPv4LL is enabled, at least one address is acquired by them. */
509 return (void) log_link_debug(link
, "%s(): DHCP4, DHCP6 or IPv4LL is enabled but no dynamic address is assigned yet.", __func__
);
511 /* Ignore NDisc when ConfigureWithoutCarrier= is enabled, as IPv6AcceptRA= is enabled by default. */
512 if (link_dhcp4_enabled(link
) || link_dhcp6_enabled(link
) || link_dhcp6_pd_is_enabled(link
) ||
513 (!link
->network
->configure_without_carrier
&& link_ipv6_accept_ra_enabled(link
)) ||
514 link_ipv4ll_enabled(link
)) {
516 if (!link
->dhcp4_configured
&&
517 !(link
->dhcp6_address_configured
&& link
->dhcp6_route_configured
) &&
518 !(link
->dhcp6_pd_address_configured
&& link
->dhcp6_pd_route_configured
) &&
519 !(link
->ndisc_addresses_configured
&& link
->ndisc_routes_configured
) &&
520 !link
->ipv4ll_address_configured
)
521 /* When DHCP[46], NDisc, or IPv4LL is enabled, at least one protocol must be finished. */
522 return (void) log_link_debug(link
, "%s(): dynamic addresses or routes are not configured.", __func__
);
524 log_link_debug(link
, "%s(): dhcp4:%s ipv4ll:%s dhcp6_addresses:%s dhcp6_routes:%s "
525 "dhcp6_pd_addresses:%s dhcp6_pd_routes:%s ndisc_addresses:%s ndisc_routes:%s",
527 yes_no(link
->dhcp4_configured
),
528 yes_no(link
->ipv4ll_address_configured
),
529 yes_no(link
->dhcp6_address_configured
),
530 yes_no(link
->dhcp6_route_configured
),
531 yes_no(link
->dhcp6_pd_address_configured
),
532 yes_no(link
->dhcp6_pd_route_configured
),
533 yes_no(link
->ndisc_addresses_configured
),
534 yes_no(link
->ndisc_routes_configured
));
537 link_set_state(link
, LINK_STATE_CONFIGURED
);
540 static int link_request_static_configs(Link
*link
) {
544 assert(link
->network
);
545 assert(link
->state
!= _LINK_STATE_INVALID
);
547 r
= link_request_static_addresses(link
);
551 r
= link_request_static_address_labels(link
);
555 r
= link_request_static_bridge_fdb(link
);
559 r
= link_request_static_bridge_mdb(link
);
563 r
= link_request_static_ipv6_proxy_ndp_addresses(link
);
567 r
= link_request_static_neighbors(link
);
571 r
= link_request_static_nexthops(link
, false);
575 r
= link_request_static_routes(link
, false);
579 r
= link_request_static_routing_policy_rules(link
);
586 static int link_request_stacked_netdevs(Link
*link
) {
592 link
->stacked_netdevs_created
= false;
593 link
->stacked_netdevs_after_configured_created
= false;
595 HASHMAP_FOREACH(netdev
, link
->network
->stacked_netdevs
) {
596 r
= link_request_to_crate_stacked_netdev(link
, netdev
);
601 if (link
->create_stacked_netdev_messages
== 0)
602 link
->stacked_netdevs_created
= true;
603 if (link
->create_stacked_netdev_after_configured_messages
== 0)
604 link
->stacked_netdevs_after_configured_created
= true;
609 static int link_acquire_dynamic_ipv6_conf(Link
*link
) {
616 assert(in6_addr_is_link_local(&link
->ipv6ll_address
));
618 log_link_debug(link
, "Starting IPv6 Router Advertisements");
620 r
= radv_emit_dns(link
);
622 return log_link_warning_errno(link
, r
, "Failed to configure DNS or Domains in IPv6 Router Advertisement: %m");
624 r
= sd_radv_start(link
->radv
);
625 if (r
< 0 && r
!= -EBUSY
)
626 return log_link_warning_errno(link
, r
, "Could not start IPv6 Router Advertisement: %m");
629 r
= ndisc_start(link
);
631 return log_link_warning_errno(link
, r
, "Failed to start IPv6 Router Discovery: %m");
633 r
= dhcp6_start(link
);
635 return log_link_warning_errno(link
, r
, "Failed to start DHCPv6 client: %m");
637 r
= dhcp6_request_prefix_delegation(link
);
639 return log_link_warning_errno(link
, r
, "Failed to request DHCPv6 prefix delegation: %m");
644 static int link_acquire_dynamic_ipv4_conf(Link
*link
) {
648 assert(link
->manager
);
649 assert(link
->manager
->event
);
651 if (link
->dhcp_client
) {
652 r
= dhcp4_start(link
);
654 return log_link_warning_errno(link
, r
, "Failed to start DHCPv4 client: %m");
656 } else if (link
->ipv4ll
) {
657 log_link_debug(link
, "Acquiring IPv4 link-local address");
659 r
= sd_ipv4ll_start(link
->ipv4ll
);
661 return log_link_warning_errno(link
, r
, "Could not acquire IPv4 link-local address: %m");
664 if (link
->dhcp_server
) {
665 r
= sd_dhcp_server_start(link
->dhcp_server
);
667 return log_link_warning_errno(link
, r
, "Could not start DHCP server: %m");
670 r
= ipv4acd_start(link
);
672 return log_link_warning_errno(link
, r
, "Could not start IPv4 ACD client: %m");
677 static int link_acquire_dynamic_conf(Link
*link
) {
682 r
= link_acquire_dynamic_ipv4_conf(link
);
686 if (in6_addr_is_set(&link
->ipv6ll_address
)) {
687 r
= link_acquire_dynamic_ipv6_conf(link
);
692 r
= link_lldp_emit_start(link
);
694 return log_link_warning_errno(link
, r
, "Failed to start LLDP transmission: %m");
699 int link_ipv6ll_gained(Link
*link
, const struct in6_addr
*address
) {
704 log_link_info(link
, "Gained IPv6LL");
706 link
->ipv6ll_address
= *address
;
707 link_check_ready(link
);
709 if (IN_SET(link
->state
, LINK_STATE_CONFIGURING
, LINK_STATE_CONFIGURED
)) {
710 r
= link_acquire_dynamic_ipv6_conf(link
);
712 link_enter_failed(link
);
720 int link_handle_bound_to_list(Link
*link
) {
721 bool required_up
= false;
722 bool link_is_up
= false;
727 /* If at least one interface in bound_to_links has carrier, then make this interface up.
728 * If all interfaces in bound_to_links do not, then make this interface down. */
730 if (hashmap_isempty(link
->bound_to_links
))
733 if (link
->flags
& IFF_UP
)
736 HASHMAP_FOREACH(l
, link
->bound_to_links
)
737 if (link_has_carrier(l
)) {
742 if (!required_up
&& link_is_up
)
743 return link_request_to_bring_up_or_down(link
, /* up = */ false);
744 if (required_up
&& !link_is_up
)
745 return link_request_to_bring_up_or_down(link
, /* up = */ true);
750 static int link_handle_bound_by_list(Link
*link
) {
756 /* Update up or down state of interfaces which depend on this interface's carrier state. */
758 if (hashmap_isempty(link
->bound_by_links
))
761 HASHMAP_FOREACH(l
, link
->bound_by_links
) {
762 r
= link_handle_bound_to_list(l
);
770 static int link_put_carrier(Link
*link
, Link
*carrier
, Hashmap
**h
) {
779 if (hashmap_get(*h
, INT_TO_PTR(carrier
->ifindex
)))
782 r
= hashmap_ensure_put(h
, NULL
, INT_TO_PTR(carrier
->ifindex
), carrier
);
791 static int link_new_bound_by_list(Link
*link
) {
797 assert(link
->manager
);
801 HASHMAP_FOREACH(carrier
, m
->links_by_index
) {
802 if (!carrier
->network
)
805 if (strv_isempty(carrier
->network
->bind_carrier
))
808 if (strv_fnmatch(carrier
->network
->bind_carrier
, link
->ifname
)) {
809 r
= link_put_carrier(link
, carrier
, &link
->bound_by_links
);
815 HASHMAP_FOREACH(carrier
, link
->bound_by_links
) {
816 r
= link_put_carrier(carrier
, link
, &carrier
->bound_to_links
);
824 static int link_new_bound_to_list(Link
*link
) {
830 assert(link
->manager
);
835 if (strv_isempty(link
->network
->bind_carrier
))
840 HASHMAP_FOREACH(carrier
, m
->links_by_index
) {
841 if (strv_fnmatch(link
->network
->bind_carrier
, carrier
->ifname
)) {
842 r
= link_put_carrier(link
, carrier
, &link
->bound_to_links
);
848 HASHMAP_FOREACH(carrier
, link
->bound_to_links
) {
849 r
= link_put_carrier(carrier
, link
, &carrier
->bound_by_links
);
857 static int link_new_carrier_maps(Link
*link
) {
860 r
= link_new_bound_by_list(link
);
864 r
= link_handle_bound_by_list(link
);
868 r
= link_new_bound_to_list(link
);
872 return link_handle_bound_to_list(link
);
875 static void link_free_bound_to_list(Link
*link
) {
876 bool updated
= false;
881 while ((bound_to
= hashmap_steal_first(link
->bound_to_links
))) {
884 if (hashmap_remove(bound_to
->bound_by_links
, INT_TO_PTR(link
->ifindex
)))
885 link_dirty(bound_to
);
892 static void link_free_bound_by_list(Link
*link
) {
893 bool updated
= false;
898 while ((bound_by
= hashmap_steal_first(link
->bound_by_links
))) {
901 if (hashmap_remove(bound_by
->bound_to_links
, INT_TO_PTR(link
->ifindex
))) {
902 link_dirty(bound_by
);
903 link_handle_bound_to_list(bound_by
);
911 static void link_free_carrier_maps(Link
*link
) {
914 link_free_bound_to_list(link
);
915 link_free_bound_by_list(link
);
918 static int link_append_to_master(Link
*link
) {
924 /* - The link may have no master.
925 * - RTM_NEWLINK message about master interface may not be received yet. */
926 if (link_get_master(link
, &master
) < 0)
929 r
= set_ensure_put(&master
->slaves
, NULL
, link
);
937 static void link_drop_from_master(Link
*link
) {
945 if (link_get_master(link
, &master
) < 0)
948 link_unref(set_remove(master
->slaves
, link
));
951 static void link_drop_requests(Link
*link
) {
955 assert(link
->manager
);
957 ORDERED_SET_FOREACH(req
, link
->manager
->request_queue
)
958 if (req
->link
== link
)
962 static Link
*link_drop(Link
*link
) {
968 assert(link
->manager
);
970 link_set_state(link
, LINK_STATE_LINGER
);
972 /* Drop all references from other links and manager. Note that async netlink calls may have
973 * references to the link, and they will be dropped when we receive replies. */
975 link_drop_requests(link
);
977 link_free_carrier_maps(link
);
979 link_drop_from_master(link
);
981 link_unref(set_remove(link
->manager
->links_requesting_uuid
, link
));
983 (void) unlink(link
->state_file
);
986 STRV_FOREACH(n
, link
->alternative_names
)
987 hashmap_remove(link
->manager
->links_by_name
, *n
);
988 hashmap_remove(link
->manager
->links_by_name
, link
->ifname
);
990 /* bonding master and its slaves have the same hardware address. */
991 if (hashmap_get(link
->manager
->links_by_hw_addr
, &link
->hw_addr
) == link
)
992 hashmap_remove(link
->manager
->links_by_hw_addr
, &link
->hw_addr
);
994 /* The following must be called at last. */
995 assert_se(hashmap_remove(link
->manager
->links_by_index
, INT_TO_PTR(link
->ifindex
)) == link
);
996 return link_unref(link
);
999 static int link_drop_foreign_config(Link
*link
) {
1003 assert(link
->manager
);
1005 r
= link_drop_foreign_routes(link
);
1007 k
= link_drop_foreign_nexthops(link
);
1008 if (k
< 0 && r
>= 0)
1011 k
= link_drop_foreign_addresses(link
);
1012 if (k
< 0 && r
>= 0)
1015 k
= link_drop_foreign_neighbors(link
);
1016 if (k
< 0 && r
>= 0)
1019 k
= manager_drop_foreign_routing_policy_rules(link
->manager
);
1020 if (k
< 0 && r
>= 0)
1026 static int link_drop_config(Link
*link
) {
1030 assert(link
->manager
);
1032 r
= link_drop_routes(link
);
1034 k
= link_drop_nexthops(link
);
1035 if (k
< 0 && r
>= 0)
1038 k
= link_drop_addresses(link
);
1039 if (k
< 0 && r
>= 0)
1042 k
= link_drop_neighbors(link
);
1043 if (k
< 0 && r
>= 0)
1046 k
= manager_drop_routing_policy_rules(link
->manager
, link
);
1047 if (k
< 0 && r
>= 0)
1055 static int link_configure(Link
*link
) {
1059 assert(link
->network
);
1060 assert(link
->state
== LINK_STATE_INITIALIZED
);
1062 link_set_state(link
, LINK_STATE_CONFIGURING
);
1064 r
= link_configure_traffic_control(link
);
1068 if (link
->iftype
== ARPHRD_CAN
) {
1069 /* let's shortcut things for CAN which doesn't need most of what's done below. */
1070 r
= link_request_to_set_can(link
);
1074 return link_request_to_activate(link
);
1077 r
= link_configure_sr_iov(link
);
1081 r
= link_set_sysctl(link
);
1085 r
= link_request_to_set_mac(link
, /* allow_retry = */ true);
1089 r
= link_request_to_set_flags(link
);
1093 r
= link_request_to_set_group(link
);
1097 r
= link_configure_mtu(link
);
1101 r
= link_request_to_set_addrgen_mode(link
);
1105 r
= link_request_to_set_master(link
);
1109 r
= link_request_stacked_netdevs(link
);
1113 r
= link_request_to_set_bond(link
);
1117 r
= link_request_to_set_bridge(link
);
1121 r
= link_request_to_set_bridge_vlan(link
);
1125 r
= link_request_to_activate(link
);
1129 r
= ipv4ll_configure(link
);
1133 r
= dhcp4_configure(link
);
1137 r
= dhcp6_configure(link
);
1141 r
= ndisc_configure(link
);
1145 r
= link_request_dhcp_server(link
);
1149 r
= radv_configure(link
);
1153 r
= link_lldp_rx_configure(link
);
1157 /* Drop foreign config, but ignore loopback or critical devices.
1158 * We do not want to remove loopback address or addresses used for root NFS. */
1159 if (!(link
->flags
& IFF_LOOPBACK
) &&
1160 link
->network
->keep_configuration
!= KEEP_CONFIGURATION_YES
) {
1161 r
= link_drop_foreign_config(link
);
1166 r
= link_request_static_configs(link
);
1170 if (!link_has_carrier(link
))
1173 return link_acquire_dynamic_conf(link
);
1176 static int link_get_network(Link
*link
, Network
**ret
) {
1181 assert(link
->manager
);
1184 ORDERED_HASHMAP_FOREACH(network
, link
->manager
->networks
) {
1187 r
= net_match_config(
1190 &link
->hw_addr
.ether
,
1191 &link
->permanent_mac
,
1195 link
->alternative_names
,
1204 if (network
->match
.ifname
&& link
->sd_device
) {
1205 uint8_t name_assign_type
= NET_NAME_UNKNOWN
;
1208 if (sd_device_get_sysattr_value(link
->sd_device
, "name_assign_type", &attr
) >= 0)
1209 (void) safe_atou8(attr
, &name_assign_type
);
1211 warn
= name_assign_type
== NET_NAME_ENUM
;
1214 log_link_full(link
, warn
? LOG_WARNING
: LOG_DEBUG
,
1215 "found matching network '%s'%s.",
1217 warn
? ", based on potentially unpredictable interface name" : "");
1219 if (network
->unmanaged
)
1229 static int link_reconfigure_impl(Link
*link
, bool force
) {
1235 r
= link_get_network(link
, &network
);
1237 link_set_state(link
, LINK_STATE_UNMANAGED
);
1243 if (link
->network
== network
&& !force
)
1246 log_link_info(link
, "Re-configuring with %s", network
->filename
);
1248 /* Dropping old .network file */
1249 r
= link_stop_engines(link
, false);
1253 link_drop_requests(link
);
1255 r
= link_drop_config(link
);
1259 if (!IN_SET(link
->state
, LINK_STATE_UNMANAGED
, LINK_STATE_PENDING
, LINK_STATE_INITIALIZED
)) {
1260 log_link_debug(link
, "State is %s, dropping foreign config", link_state_to_string(link
->state
));
1261 r
= link_drop_foreign_config(link
);
1266 link_free_carrier_maps(link
);
1267 link_free_engines(link
);
1268 link
->network
= network_unref(link
->network
);
1269 link_unref(set_remove(link
->manager
->links_requesting_uuid
, link
));
1271 /* Then, apply new .network file */
1272 link
->network
= network_ref(network
);
1273 link_update_operstate(link
, true);
1276 r
= link_new_carrier_maps(link
);
1280 link_set_state(link
, LINK_STATE_INITIALIZED
);
1281 link
->activated
= false;
1283 r
= link_configure(link
);
1290 static int link_reconfigure_handler_internal(sd_netlink
*rtnl
, sd_netlink_message
*m
, Link
*link
, bool force
) {
1293 r
= link_getlink_handler_internal(rtnl
, m
, link
, "Failed to update link state");
1297 r
= link_reconfigure_impl(link
, force
);
1299 link_enter_failed(link
);
1304 static int link_reconfigure_handler(sd_netlink
*rtnl
, sd_netlink_message
*m
, Link
*link
) {
1305 return link_reconfigure_handler_internal(rtnl
, m
, link
, false);
1308 static int link_force_reconfigure_handler(sd_netlink
*rtnl
, sd_netlink_message
*m
, Link
*link
) {
1309 return link_reconfigure_handler_internal(rtnl
, m
, link
, true);
1312 int link_reconfigure(Link
*link
, bool force
) {
1315 /* When link in pending or initialized state, then link_configure() will be called. To prevent
1316 * the function from being called multiple times simultaneously, refuse to reconfigure the
1317 * interface in these cases. */
1318 if (IN_SET(link
->state
, LINK_STATE_PENDING
, LINK_STATE_INITIALIZED
, LINK_STATE_LINGER
))
1319 return 0; /* 0 means no-op. */
1321 r
= link_call_getlink(link
, force
? link_force_reconfigure_handler
: link_reconfigure_handler
);
1325 return 1; /* 1 means the interface will be reconfigured. */
1328 static int link_initialized_and_synced(Link
*link
) {
1333 assert(link
->ifname
);
1334 assert(link
->manager
);
1336 /* We may get called either from the asynchronous netlink callback,
1337 * or directly from link_check_initialized() if running in a container. */
1338 if (!IN_SET(link
->state
, LINK_STATE_PENDING
, LINK_STATE_INITIALIZED
))
1341 log_link_debug(link
, "Link state is up-to-date");
1342 link_set_state(link
, LINK_STATE_INITIALIZED
);
1344 r
= link_new_bound_by_list(link
);
1348 r
= link_handle_bound_by_list(link
);
1352 if (!link
->network
) {
1353 r
= wifi_get_info(link
);
1357 r
= link_get_network(link
, &network
);
1359 link_set_state(link
, LINK_STATE_UNMANAGED
);
1365 if (link
->flags
& IFF_LOOPBACK
) {
1366 if (network
->link_local
!= ADDRESS_FAMILY_NO
)
1367 log_link_debug(link
, "Ignoring link-local autoconfiguration for loopback link");
1369 if (network
->dhcp
!= ADDRESS_FAMILY_NO
)
1370 log_link_debug(link
, "Ignoring DHCP clients for loopback link");
1372 if (network
->dhcp_server
)
1373 log_link_debug(link
, "Ignoring DHCP server for loopback link");
1376 link
->network
= network_ref(network
);
1377 link_update_operstate(link
, false);
1381 r
= link_new_bound_to_list(link
);
1385 return link_configure(link
);
1388 static int link_initialized_handler(sd_netlink
*rtnl
, sd_netlink_message
*m
, Link
*link
) {
1391 r
= link_getlink_handler_internal(rtnl
, m
, link
, "Failed to wait for the interface to be initialized");
1395 r
= link_initialized_and_synced(link
);
1397 link_enter_failed(link
);
1402 static int link_initialized(Link
*link
, sd_device
*device
) {
1406 if (link
->state
!= LINK_STATE_PENDING
)
1409 if (link
->sd_device
)
1412 log_link_debug(link
, "udev initialized link");
1413 link_set_state(link
, LINK_STATE_INITIALIZED
);
1415 link
->sd_device
= sd_device_ref(device
);
1417 /* udev has initialized the link, but we don't know if we have yet
1418 * processed the NEWLINK messages with the latest state. Do a GETLINK,
1419 * when it returns we know that the pending NEWLINKs have already been
1420 * processed and that we are up-to-date */
1422 return link_call_getlink(link
, link_initialized_handler
);
1425 static int link_check_initialized(Link
*link
) {
1426 _cleanup_(sd_device_unrefp
) sd_device
*device
= NULL
;
1431 if (path_is_read_only_fs("/sys") > 0)
1433 return link_initialized_and_synced(link
);
1435 /* udev should be around */
1436 r
= sd_device_new_from_ifindex(&device
, link
->ifindex
);
1438 log_link_debug_errno(link
, r
, "Could not find device, waiting for device initialization: %m");
1442 r
= sd_device_get_is_initialized(device
);
1444 return log_link_warning_errno(link
, r
, "Could not determine whether the device is initialized: %m");
1447 log_link_debug(link
, "link pending udev initialization...");
1451 r
= device_is_renaming(device
);
1453 return log_link_warning_errno(link
, r
, "Failed to determine the device is being renamed: %m");
1455 log_link_debug(link
, "Interface is being renamed, pending initialization.");
1459 return link_initialized(link
, device
);
1462 int manager_udev_process_link(sd_device_monitor
*monitor
, sd_device
*device
, void *userdata
) {
1463 sd_device_action_t action
;
1464 Manager
*m
= userdata
;
1471 r
= sd_device_get_action(device
, &action
);
1473 log_device_debug_errno(device
, r
, "Failed to get udev action, ignoring device: %m");
1477 /* Ignore the "remove" uevent — let's remove a device only if rtnetlink says so. All other uevents
1478 * are "positive" events in some form, i.e. inform us about a changed or new network interface, that
1479 * still exists — and we are interested in that. */
1480 if (action
== SD_DEVICE_REMOVE
)
1483 r
= sd_device_get_ifindex(device
, &ifindex
);
1485 log_device_debug_errno(device
, r
, "Ignoring udev %s event for device without ifindex or with invalid ifindex: %m",
1486 device_action_to_string(action
));
1490 r
= device_is_renaming(device
);
1492 log_device_debug_errno(device
, r
, "Failed to determine the device is renamed or not, ignoring '%s' uevent: %m",
1493 device_action_to_string(action
));
1497 log_device_debug(device
, "Interface is under renaming, wait for the interface to be renamed.");
1501 r
= link_get_by_index(m
, ifindex
, &link
);
1503 log_device_debug_errno(device
, r
, "Failed to get link from ifindex %i, ignoring: %m", ifindex
);
1507 r
= link_initialized(link
, device
);
1509 link_enter_failed(link
);
1514 static int link_carrier_gained(Link
*link
) {
1519 r
= link_handle_bound_by_list(link
);
1523 if (link
->iftype
== ARPHRD_CAN
)
1524 /* let's shortcut things for CAN which doesn't need most of what's done below. */
1527 if (IN_SET(link
->state
, LINK_STATE_CONFIGURING
, LINK_STATE_CONFIGURED
)) {
1528 r
= link_acquire_dynamic_conf(link
);
1532 r
= link_request_static_configs(link
);
1540 static int link_carrier_lost(Link
*link
) {
1545 r
= link_handle_bound_by_list(link
);
1549 if (link
->iftype
== ARPHRD_CAN
)
1550 /* let's shortcut things for CAN which doesn't need most of what's done below. */
1553 if (link
->network
&& link
->network
->ignore_carrier_loss
)
1556 r
= link_stop_engines(link
, false);
1558 link_enter_failed(link
);
1562 r
= link_drop_config(link
);
1566 if (!IN_SET(link
->state
, LINK_STATE_UNMANAGED
, LINK_STATE_PENDING
, LINK_STATE_INITIALIZED
)) {
1567 log_link_debug(link
, "State is %s, dropping foreign config", link_state_to_string(link
->state
));
1568 r
= link_drop_foreign_config(link
);
1576 int link_carrier_reset(Link
*link
) {
1581 if (!link_has_carrier(link
))
1584 r
= link_carrier_lost(link
);
1588 r
= link_carrier_gained(link
);
1592 log_link_info(link
, "Reset carrier");
1596 static int link_admin_state_up(Link
*link
) {
1601 /* This is called every time an interface admin state changes to up;
1602 * specifically, when IFF_UP flag changes from unset to set. */
1607 if (link
->activated
&& link
->network
->activation_policy
== ACTIVATION_POLICY_ALWAYS_DOWN
) {
1608 log_link_info(link
, "ActivationPolicy is \"always-off\", forcing link down.");
1609 return link_request_to_bring_up_or_down(link
, /* up = */ false);
1612 /* We set the ipv6 mtu after the device mtu, but the kernel resets
1613 * ipv6 mtu on NETDEV_UP, so we need to reset it. */
1614 r
= link_set_ipv6_mtu(link
);
1616 log_link_warning_errno(link
, r
, "Cannot set IPv6 MTU, ignoring: %m");
1621 static int link_admin_state_down(Link
*link
) {
1627 if (link
->activated
&& link
->network
->activation_policy
== ACTIVATION_POLICY_ALWAYS_UP
) {
1628 log_link_info(link
, "ActivationPolicy is \"always-on\", forcing link up.");
1629 return link_request_to_bring_up_or_down(link
, /* up = */ true);
1635 bool link_has_carrier(Link
*link
) {
1636 /* see Documentation/networking/operstates.txt in the kernel sources */
1638 if (link
->kernel_operstate
== IF_OPER_UP
)
1641 if (link
->kernel_operstate
== IF_OPER_UNKNOWN
)
1642 /* operstate may not be implemented, so fall back to flags */
1643 if (FLAGS_SET(link
->flags
, IFF_LOWER_UP
| IFF_RUNNING
) &&
1644 !FLAGS_SET(link
->flags
, IFF_DORMANT
))
1650 static bool link_is_enslaved(Link
*link
) {
1651 if (link
->flags
& IFF_SLAVE
)
1652 /* Even if the link is not managed by networkd, honor IFF_SLAVE flag. */
1658 if (link
->master_ifindex
> 0 && link
->network
->bridge
)
1661 /* TODO: add conditions for other netdevs. */
1666 static LinkAddressState
address_state_from_scope(uint8_t scope
) {
1667 if (scope
< RT_SCOPE_SITE
)
1668 /* universally accessible addresses found */
1669 return LINK_ADDRESS_STATE_ROUTABLE
;
1671 if (scope
< RT_SCOPE_HOST
)
1672 /* only link or site local addresses found */
1673 return LINK_ADDRESS_STATE_DEGRADED
;
1675 /* no useful addresses found */
1676 return LINK_ADDRESS_STATE_OFF
;
1679 void link_update_operstate(Link
*link
, bool also_update_master
) {
1680 LinkOperationalState operstate
;
1681 LinkCarrierState carrier_state
;
1682 LinkAddressState ipv4_address_state
, ipv6_address_state
, address_state
;
1683 LinkOnlineState online_state
;
1684 _cleanup_strv_free_
char **p
= NULL
;
1685 uint8_t ipv4_scope
= RT_SCOPE_NOWHERE
, ipv6_scope
= RT_SCOPE_NOWHERE
;
1686 bool changed
= false;
1691 if (link
->kernel_operstate
== IF_OPER_DORMANT
)
1692 carrier_state
= LINK_CARRIER_STATE_DORMANT
;
1693 else if (link_has_carrier(link
)) {
1694 if (link_is_enslaved(link
))
1695 carrier_state
= LINK_CARRIER_STATE_ENSLAVED
;
1697 carrier_state
= LINK_CARRIER_STATE_CARRIER
;
1698 } else if (link
->flags
& IFF_UP
)
1699 carrier_state
= LINK_CARRIER_STATE_NO_CARRIER
;
1701 carrier_state
= LINK_CARRIER_STATE_OFF
;
1703 if (carrier_state
>= LINK_CARRIER_STATE_CARRIER
) {
1706 SET_FOREACH(slave
, link
->slaves
) {
1707 link_update_operstate(slave
, false);
1709 if (slave
->carrier_state
< LINK_CARRIER_STATE_CARRIER
)
1710 carrier_state
= LINK_CARRIER_STATE_DEGRADED_CARRIER
;
1714 SET_FOREACH(address
, link
->addresses
) {
1715 if (!address_is_ready(address
))
1718 if (address
->family
== AF_INET
)
1719 ipv4_scope
= MIN(ipv4_scope
, address
->scope
);
1721 if (address
->family
== AF_INET6
)
1722 ipv6_scope
= MIN(ipv6_scope
, address
->scope
);
1725 /* for operstate we also take foreign addresses into account */
1726 SET_FOREACH(address
, link
->addresses_foreign
) {
1727 if (!address_is_ready(address
))
1730 if (address
->family
== AF_INET
)
1731 ipv4_scope
= MIN(ipv4_scope
, address
->scope
);
1733 if (address
->family
== AF_INET6
)
1734 ipv6_scope
= MIN(ipv6_scope
, address
->scope
);
1737 ipv4_address_state
= address_state_from_scope(ipv4_scope
);
1738 ipv6_address_state
= address_state_from_scope(ipv6_scope
);
1739 address_state
= address_state_from_scope(MIN(ipv4_scope
, ipv6_scope
));
1741 /* Mapping of address and carrier state vs operational state
1743 * | off | no-carrier | dormant | degraded-carrier | carrier | enslaved
1744 * ------------------------------------------------------------------------------
1745 * off | off | no-carrier | dormant | degraded-carrier | carrier | enslaved
1746 * address_state degraded | off | no-carrier | dormant | degraded-carrier | degraded | enslaved
1747 * routable | off | no-carrier | dormant | degraded-carrier | routable | routable
1750 if (carrier_state
< LINK_CARRIER_STATE_CARRIER
|| address_state
== LINK_ADDRESS_STATE_OFF
)
1751 operstate
= (LinkOperationalState
) carrier_state
;
1752 else if (address_state
== LINK_ADDRESS_STATE_ROUTABLE
)
1753 operstate
= LINK_OPERSTATE_ROUTABLE
;
1754 else if (carrier_state
== LINK_CARRIER_STATE_CARRIER
)
1755 operstate
= LINK_OPERSTATE_DEGRADED
;
1757 operstate
= LINK_OPERSTATE_ENSLAVED
;
1759 /* Only determine online state for managed links with RequiredForOnline=yes */
1760 if (!link
->network
|| !link
->network
->required_for_online
)
1761 online_state
= _LINK_ONLINE_STATE_INVALID
;
1762 else if (operstate
< link
->network
->required_operstate_for_online
.min
||
1763 operstate
> link
->network
->required_operstate_for_online
.max
)
1764 online_state
= LINK_ONLINE_STATE_OFFLINE
;
1766 AddressFamily required_family
= link
->network
->required_family_for_online
;
1767 bool needs_ipv4
= required_family
& ADDRESS_FAMILY_IPV4
;
1768 bool needs_ipv6
= required_family
& ADDRESS_FAMILY_IPV6
;
1770 /* The operational state is within the range required for online.
1771 * If a particular address family is also required, we might revert
1772 * to offline in the blocks below. */
1773 online_state
= LINK_ONLINE_STATE_ONLINE
;
1775 if (link
->network
->required_operstate_for_online
.min
>= LINK_OPERSTATE_DEGRADED
) {
1776 if (needs_ipv4
&& ipv4_address_state
< LINK_ADDRESS_STATE_DEGRADED
)
1777 online_state
= LINK_ONLINE_STATE_OFFLINE
;
1778 if (needs_ipv6
&& ipv6_address_state
< LINK_ADDRESS_STATE_DEGRADED
)
1779 online_state
= LINK_ONLINE_STATE_OFFLINE
;
1782 if (link
->network
->required_operstate_for_online
.min
>= LINK_OPERSTATE_ROUTABLE
) {
1783 if (needs_ipv4
&& ipv4_address_state
< LINK_ADDRESS_STATE_ROUTABLE
)
1784 online_state
= LINK_ONLINE_STATE_OFFLINE
;
1785 if (needs_ipv6
&& ipv6_address_state
< LINK_ADDRESS_STATE_ROUTABLE
)
1786 online_state
= LINK_ONLINE_STATE_OFFLINE
;
1790 if (link
->carrier_state
!= carrier_state
) {
1791 link
->carrier_state
= carrier_state
;
1793 if (strv_extend(&p
, "CarrierState") < 0)
1797 if (link
->address_state
!= address_state
) {
1798 link
->address_state
= address_state
;
1800 if (strv_extend(&p
, "AddressState") < 0)
1804 if (link
->ipv4_address_state
!= ipv4_address_state
) {
1805 link
->ipv4_address_state
= ipv4_address_state
;
1807 if (strv_extend(&p
, "IPv4AddressState") < 0)
1811 if (link
->ipv6_address_state
!= ipv6_address_state
) {
1812 link
->ipv6_address_state
= ipv6_address_state
;
1814 if (strv_extend(&p
, "IPv6AddressState") < 0)
1818 if (link
->operstate
!= operstate
) {
1819 link
->operstate
= operstate
;
1821 if (strv_extend(&p
, "OperationalState") < 0)
1825 if (link
->online_state
!= online_state
) {
1826 link
->online_state
= online_state
;
1828 if (strv_extend(&p
, "OnlineState") < 0)
1833 link_send_changed_strv(link
, p
);
1837 if (also_update_master
) {
1840 if (link_get_master(link
, &master
) >= 0)
1841 link_update_operstate(master
, true);
1845 #define FLAG_STRING(string, flag, old, new) \
1846 (((old ^ new) & flag) \
1847 ? ((old & flag) ? (" -" string) : (" +" string)) \
1850 static int link_update_flags(Link
*link
, sd_netlink_message
*message
) {
1851 bool link_was_lower_up
, link_was_admin_up
, had_carrier
;
1859 r
= sd_rtnl_message_link_get_flags(message
, &flags
);
1861 return log_link_debug_errno(link
, r
, "rtnl: failed to read link flags: %m");
1863 r
= sd_netlink_message_read_u8(message
, IFLA_OPERSTATE
, &operstate
);
1865 /* If we got a message without operstate, assume the state was unchanged. */
1866 operstate
= link
->kernel_operstate
;
1868 return log_link_debug_errno(link
, r
, "rtnl: failed to read operational state: %m");
1870 if (link
->flags
== flags
&& link
->kernel_operstate
== operstate
)
1873 if (link
->flags
!= flags
) {
1874 unsigned unknown_flags
, unknown_flags_added
, unknown_flags_removed
;
1876 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",
1877 FLAG_STRING("LOOPBACK", IFF_LOOPBACK
, link
->flags
, flags
),
1878 FLAG_STRING("MASTER", IFF_MASTER
, link
->flags
, flags
),
1879 FLAG_STRING("SLAVE", IFF_SLAVE
, link
->flags
, flags
),
1880 FLAG_STRING("UP", IFF_UP
, link
->flags
, flags
),
1881 FLAG_STRING("DORMANT", IFF_DORMANT
, link
->flags
, flags
),
1882 FLAG_STRING("LOWER_UP", IFF_LOWER_UP
, link
->flags
, flags
),
1883 FLAG_STRING("RUNNING", IFF_RUNNING
, link
->flags
, flags
),
1884 FLAG_STRING("MULTICAST", IFF_MULTICAST
, link
->flags
, flags
),
1885 FLAG_STRING("BROADCAST", IFF_BROADCAST
, link
->flags
, flags
),
1886 FLAG_STRING("POINTOPOINT", IFF_POINTOPOINT
, link
->flags
, flags
),
1887 FLAG_STRING("PROMISC", IFF_PROMISC
, link
->flags
, flags
),
1888 FLAG_STRING("ALLMULTI", IFF_ALLMULTI
, link
->flags
, flags
),
1889 FLAG_STRING("PORTSEL", IFF_PORTSEL
, link
->flags
, flags
),
1890 FLAG_STRING("AUTOMEDIA", IFF_AUTOMEDIA
, link
->flags
, flags
),
1891 FLAG_STRING("DYNAMIC", IFF_DYNAMIC
, link
->flags
, flags
),
1892 FLAG_STRING("NOARP", IFF_NOARP
, link
->flags
, flags
),
1893 FLAG_STRING("NOTRAILERS", IFF_NOTRAILERS
, link
->flags
, flags
),
1894 FLAG_STRING("DEBUG", IFF_DEBUG
, link
->flags
, flags
),
1895 FLAG_STRING("ECHO", IFF_ECHO
, link
->flags
, flags
));
1897 unknown_flags
= ~(IFF_LOOPBACK
| IFF_MASTER
| IFF_SLAVE
| IFF_UP
|
1898 IFF_DORMANT
| IFF_LOWER_UP
| IFF_RUNNING
|
1899 IFF_MULTICAST
| IFF_BROADCAST
| IFF_POINTOPOINT
|
1900 IFF_PROMISC
| IFF_ALLMULTI
| IFF_PORTSEL
|
1901 IFF_AUTOMEDIA
| IFF_DYNAMIC
| IFF_NOARP
|
1902 IFF_NOTRAILERS
| IFF_DEBUG
| IFF_ECHO
);
1903 unknown_flags_added
= ((link
->flags
^ flags
) & flags
& unknown_flags
);
1904 unknown_flags_removed
= ((link
->flags
^ flags
) & link
->flags
& unknown_flags
);
1906 if (unknown_flags_added
)
1907 log_link_debug(link
, "Unknown link flags gained, ignoring: %#.5x", unknown_flags_added
);
1909 if (unknown_flags_removed
)
1910 log_link_debug(link
, "Unknown link flags lost, ignoring: %#.5x", unknown_flags_removed
);
1913 link_was_lower_up
= link
->flags
& IFF_LOWER_UP
;
1914 link_was_admin_up
= link
->flags
& IFF_UP
;
1915 had_carrier
= link_has_carrier(link
);
1917 link
->flags
= flags
;
1918 link
->kernel_operstate
= operstate
;
1920 link_update_operstate(link
, true);
1922 if (!link_was_lower_up
&& (link
->flags
& IFF_LOWER_UP
)) {
1923 r
= wifi_get_info(link
);
1927 /* All link information is up-to-date. So, it is not necessary to call
1928 * RTM_GETLINK netlink method again. */
1929 r
= link_reconfigure_impl(link
, /* force = */ false);
1935 if (!link_was_admin_up
&& (link
->flags
& IFF_UP
)) {
1936 log_link_info(link
, "Link UP");
1938 r
= link_admin_state_up(link
);
1941 } else if (link_was_admin_up
&& !(link
->flags
& IFF_UP
)) {
1942 log_link_info(link
, "Link DOWN");
1944 r
= link_admin_state_down(link
);
1949 r
= link_update_lldp(link
);
1953 if (!had_carrier
&& link_has_carrier(link
)) {
1954 log_link_info(link
, "Gained carrier");
1956 r
= link_carrier_gained(link
);
1959 } else if (had_carrier
&& !link_has_carrier(link
)) {
1960 log_link_info(link
, "Lost carrier");
1962 r
= link_carrier_lost(link
);
1970 static int link_update_master(Link
*link
, sd_netlink_message
*message
) {
1971 int master_ifindex
, r
;
1976 r
= sd_netlink_message_read_u32(message
, IFLA_MASTER
, (uint32_t*) &master_ifindex
);
1980 return log_link_debug_errno(link
, r
, "rtnl: failed to read master ifindex: %m");
1982 if (master_ifindex
== link
->master_ifindex
)
1985 if (link
->master_ifindex
== 0)
1986 log_link_debug(link
, "Joined to master interface: %i", master_ifindex
);
1987 else if (master_ifindex
== 0)
1988 log_link_debug(link
, "Leaved from master interface: %i", link
->master_ifindex
);
1990 log_link_debug(link
, "Master interface is changed: %i → %i", link
->master_ifindex
, master_ifindex
);
1992 link_drop_from_master(link
);
1994 link
->master_ifindex
= master_ifindex
;
1996 r
= link_append_to_master(link
);
1998 return log_link_debug_errno(link
, r
, "Failed to append link to master: %m");
2003 static int link_update_hardware_address(Link
*link
, sd_netlink_message
*message
) {
2004 struct hw_addr_data addr
;
2010 r
= netlink_message_read_hw_addr(message
, IFLA_BROADCAST
, &link
->bcast_addr
);
2011 if (r
< 0 && r
!= -ENODATA
)
2012 return log_link_debug_errno(link
, r
, "rtnl: failed to read broadcast address: %m");
2014 r
= netlink_message_read_hw_addr(message
, IFLA_ADDRESS
, &addr
);
2018 return log_link_debug_errno(link
, r
, "rtnl: failed to read hardware address: %m");
2020 if (hw_addr_equal(&link
->hw_addr
, &addr
))
2023 if (hw_addr_is_null(&link
->hw_addr
))
2024 log_link_debug(link
, "Saved hardware address: %s", HW_ADDR_TO_STR(&addr
));
2026 log_link_debug(link
, "Hardware address is changed: %s → %s",
2027 HW_ADDR_TO_STR(&link
->hw_addr
), HW_ADDR_TO_STR(&addr
));
2029 if (hashmap_get(link
->manager
->links_by_hw_addr
, &link
->hw_addr
) == link
)
2030 hashmap_remove(link
->manager
->links_by_hw_addr
, &link
->hw_addr
);
2033 link
->hw_addr
= addr
;
2035 if (!hw_addr_is_null(&link
->hw_addr
)) {
2036 r
= hashmap_ensure_put(&link
->manager
->links_by_hw_addr
, &hw_addr_hash_ops
, &link
->hw_addr
, link
);
2037 if (r
== -EEXIST
&& streq_ptr(link
->kind
, "bond"))
2038 /* bonding master and its slaves have the same hardware address. */
2039 r
= hashmap_replace(link
->manager
->links_by_hw_addr
, &link
->hw_addr
, link
);
2041 log_link_debug_errno(link
, r
, "Failed to manage link by its new hardware address, ignoring: %m");
2044 r
= ipv4ll_update_mac(link
);
2046 return log_link_debug_errno(link
, r
, "Could not update MAC address in IPv4 ACD client: %m");
2048 r
= ipv4ll_update_mac(link
);
2050 return log_link_debug_errno(link
, r
, "Could not update MAC address in IPv4LL client: %m");
2052 r
= dhcp4_update_mac(link
);
2054 return log_link_debug_errno(link
, r
, "Could not update MAC address in DHCP client: %m");
2056 r
= dhcp6_update_mac(link
);
2058 return log_link_debug_errno(link
, r
, "Could not update MAC address in DHCPv6 client: %m");
2060 r
= radv_update_mac(link
);
2062 return log_link_debug_errno(link
, r
, "Could not update MAC address for Router Advertisement: %m");
2065 r
= sd_ndisc_set_mac(link
->ndisc
, &link
->hw_addr
.ether
);
2067 return log_link_debug_errno(link
, r
, "Could not update MAC for NDisc: %m");
2071 r
= sd_lldp_set_filter_address(link
->lldp
, &link
->hw_addr
.ether
);
2073 return log_link_debug_errno(link
, r
, "Could not update MAC address for LLDP: %m");
2079 static int link_update_mtu(Link
*link
, sd_netlink_message
*message
) {
2080 uint32_t mtu
, min_mtu
= 0, max_mtu
= UINT32_MAX
;
2086 r
= sd_netlink_message_read_u32(message
, IFLA_MTU
, &mtu
);
2090 return log_link_debug_errno(link
, r
, "rtnl: failed to read MTU in RTM_NEWLINK message: %m");
2094 r
= sd_netlink_message_read_u32(message
, IFLA_MIN_MTU
, &min_mtu
);
2095 if (r
< 0 && r
!= -ENODATA
)
2096 return log_link_debug_errno(link
, r
, "rtnl: failed to read minimum MTU in RTM_NEWLINK message: %m");
2098 r
= sd_netlink_message_read_u32(message
, IFLA_MAX_MTU
, &max_mtu
);
2099 if (r
< 0 && r
!= -ENODATA
)
2100 return log_link_debug_errno(link
, r
, "rtnl: failed to read maximum MTU in RTM_NEWLINK message: %m");
2103 max_mtu
= UINT32_MAX
;
2105 link
->min_mtu
= min_mtu
;
2106 link
->max_mtu
= max_mtu
;
2108 if (link
->original_mtu
== 0) {
2109 link
->original_mtu
= mtu
;
2110 log_link_debug(link
, "Saved original MTU %" PRIu32
" (min: %"PRIu32
", max: %"PRIu32
")",
2111 link
->original_mtu
, link
->min_mtu
, link
->max_mtu
);
2114 if (link
->mtu
== mtu
)
2118 log_link_debug(link
, "MTU is changed: %"PRIu32
" → %"PRIu32
" (min: %"PRIu32
", max: %"PRIu32
")",
2119 link
->mtu
, mtu
, link
->min_mtu
, link
->max_mtu
);
2123 if (link
->dhcp_client
) {
2124 r
= sd_dhcp_client_set_mtu(link
->dhcp_client
, link
->mtu
);
2126 return log_link_debug_errno(link
, r
, "Could not update MTU in DHCP client: %m");
2130 r
= sd_radv_set_mtu(link
->radv
, link
->mtu
);
2132 return log_link_debug_errno(link
, r
, "Could not set MTU for Router Advertisement: %m");
2138 static int link_update_alternative_names(Link
*link
, sd_netlink_message
*message
) {
2139 _cleanup_strv_free_
char **altnames
= NULL
;
2146 r
= sd_netlink_message_read_strv(message
, IFLA_PROP_LIST
, IFLA_ALT_IFNAME
, &altnames
);
2147 if (r
< 0 && r
!= -ENODATA
)
2148 return log_link_debug_errno(link
, r
, "rtnl: failed to read alternative names: %m");
2150 STRV_FOREACH(n
, link
->alternative_names
)
2151 hashmap_remove(link
->manager
->links_by_name
, *n
);
2153 strv_free_and_replace(link
->alternative_names
, altnames
);
2155 STRV_FOREACH(n
, link
->alternative_names
) {
2156 r
= hashmap_ensure_put(&link
->manager
->links_by_name
, &string_hash_ops
, *n
, link
);
2158 return log_link_debug_errno(link
, r
, "Failed to manage link by its new alternative names: %m");
2164 static int link_update_name(Link
*link
, sd_netlink_message
*message
) {
2165 char ifname_from_index
[IF_NAMESIZE
+ 1];
2172 r
= sd_netlink_message_read_string(message
, IFLA_IFNAME
, &ifname
);
2177 return log_link_debug_errno(link
, r
, "Failed to read interface name in RTM_NEWLINK message: %m");
2179 if (streq(ifname
, link
->ifname
))
2182 if (!format_ifname(link
->ifindex
, ifname_from_index
))
2183 return log_link_debug_errno(link
, SYNTHETIC_ERRNO(ENXIO
), "Could not get interface name for index %i.", link
->ifindex
);
2185 if (!streq(ifname
, ifname_from_index
)) {
2186 log_link_debug(link
, "New interface name '%s' received from the kernel does not correspond "
2187 "with the name currently configured on the actual interface '%s'. Ignoring.",
2188 ifname
, ifname_from_index
);
2192 log_link_info(link
, "Interface name change detected, renamed to %s.", ifname
);
2194 hashmap_remove(link
->manager
->links_by_name
, link
->ifname
);
2196 r
= free_and_strdup(&link
->ifname
, ifname
);
2198 return log_oom_debug();
2200 r
= hashmap_ensure_put(&link
->manager
->links_by_name
, &string_hash_ops
, link
->ifname
, link
);
2202 return log_link_debug_errno(link
, r
, "Failed to manage link by its new name: %m");
2204 if (link
->dhcp_client
) {
2205 r
= sd_dhcp_client_set_ifname(link
->dhcp_client
, link
->ifname
);
2207 return log_link_debug_errno(link
, r
, "Failed to update interface name in DHCP client: %m");
2210 if (link
->dhcp6_client
) {
2211 r
= sd_dhcp6_client_set_ifname(link
->dhcp6_client
, link
->ifname
);
2213 return log_link_debug_errno(link
, r
, "Failed to update interface name in DHCP6 client: %m");
2217 r
= sd_ndisc_set_ifname(link
->ndisc
, link
->ifname
);
2219 return log_link_debug_errno(link
, r
, "Failed to update interface name in NDisc: %m");
2222 if (link
->dhcp_server
) {
2223 r
= sd_dhcp_server_set_ifname(link
->dhcp_server
, link
->ifname
);
2225 return log_link_debug_errno(link
, r
, "Failed to update interface name in DHCP server: %m");
2229 r
= sd_radv_set_ifname(link
->radv
, link
->ifname
);
2231 return log_link_debug_errno(link
, r
, "Failed to update interface name in Router Advertisement: %m");
2235 r
= sd_lldp_set_ifname(link
->lldp
, link
->ifname
);
2237 return log_link_debug_errno(link
, r
, "Failed to update interface name in LLDP: %m");
2241 r
= sd_ipv4ll_set_ifname(link
->ipv4ll
, link
->ifname
);
2243 return log_link_debug_errno(link
, r
, "Failed to update interface name in IPv4LL client: %m");
2247 SET_FOREACH(a
, link
->addresses_ipv4acd
) {
2248 r
= sd_ipv4acd_set_ifname(a
->acd
, link
->ifname
);
2250 return log_link_debug_errno(link
, r
, "Failed to update interface name in IPv4ACD client: %m");
2256 static int link_update(Link
*link
, sd_netlink_message
*message
) {
2262 r
= link_update_name(link
, message
);
2266 r
= link_update_alternative_names(link
, message
);
2270 r
= link_update_mtu(link
, message
);
2274 r
= link_update_hardware_address(link
, message
);
2278 r
= link_update_master(link
, message
);
2282 return link_update_flags(link
, message
);
2285 static Link
*link_drop_or_unref(Link
*link
) {
2289 return link_unref(link
);
2290 return link_drop(link
);
2293 DEFINE_TRIVIAL_CLEANUP_FUNC(Link
*, link_drop_or_unref
);
2295 static int link_new(Manager
*manager
, sd_netlink_message
*message
, Link
**ret
) {
2296 _cleanup_free_
char *ifname
= NULL
, *kind
= NULL
, *state_file
= NULL
, *lease_file
= NULL
, *lldp_file
= NULL
;
2297 _cleanup_(link_drop_or_unrefp
) Link
*link
= NULL
;
2298 unsigned short iftype
;
2305 r
= sd_rtnl_message_link_get_ifindex(message
, &ifindex
);
2307 return log_debug_errno(r
, "rtnl: failed to read ifindex from link message: %m");
2308 else if (ifindex
<= 0)
2309 return log_debug_errno(SYNTHETIC_ERRNO(EINVAL
), "rtnl: received link message without valid ifindex.");
2311 r
= sd_rtnl_message_link_get_type(message
, &iftype
);
2313 return log_debug_errno(r
, "rtnl: failed to read interface type from link message: %m");
2315 r
= sd_netlink_message_read_string_strdup(message
, IFLA_IFNAME
, &ifname
);
2317 return log_debug_errno(r
, "rtnl: failed to read interface name from link message: %m");
2319 /* check for link kind */
2320 r
= sd_netlink_message_enter_container(message
, IFLA_LINKINFO
);
2322 r
= sd_netlink_message_read_string_strdup(message
, IFLA_INFO_KIND
, &kind
);
2323 if (r
< 0 && r
!= -ENODATA
)
2324 return log_debug_errno(r
, "rtnl: failed to read interface kind from link message: %m");
2325 r
= sd_netlink_message_exit_container(message
);
2327 return log_debug_errno(r
, "rtnl: failed to exit IFLA_LINKINFO container: %m");
2330 if (asprintf(&state_file
, "/run/systemd/netif/links/%d", ifindex
) < 0)
2331 return log_oom_debug();
2333 if (asprintf(&lease_file
, "/run/systemd/netif/leases/%d", ifindex
) < 0)
2334 return log_oom_debug();
2336 if (asprintf(&lldp_file
, "/run/systemd/netif/lldp/%d", ifindex
) < 0)
2337 return log_oom_debug();
2339 link
= new(Link
, 1);
2345 .state
= LINK_STATE_PENDING
,
2346 .online_state
= _LINK_ONLINE_STATE_INVALID
,
2349 .ifname
= TAKE_PTR(ifname
),
2350 .kind
= TAKE_PTR(kind
),
2352 .state_file
= TAKE_PTR(state_file
),
2353 .lease_file
= TAKE_PTR(lease_file
),
2354 .lldp_file
= TAKE_PTR(lldp_file
),
2357 .dns_default_route
= -1,
2358 .llmnr
= _RESOLVE_SUPPORT_INVALID
,
2359 .mdns
= _RESOLVE_SUPPORT_INVALID
,
2360 .dnssec_mode
= _DNSSEC_MODE_INVALID
,
2361 .dns_over_tls_mode
= _DNS_OVER_TLS_MODE_INVALID
,
2364 r
= hashmap_ensure_put(&manager
->links_by_index
, NULL
, INT_TO_PTR(link
->ifindex
), link
);
2366 return log_link_debug_errno(link
, r
, "Failed to store link into manager: %m");
2368 link
->manager
= manager
;
2370 r
= hashmap_ensure_put(&manager
->links_by_name
, &string_hash_ops
, link
->ifname
, link
);
2372 return log_link_debug_errno(link
, r
, "Failed to manage link by its interface name: %m");
2374 r
= ethtool_get_permanent_macaddr(&manager
->ethtool_fd
, link
->ifname
, &link
->permanent_mac
);
2376 log_link_debug_errno(link
, r
, "Permanent MAC address not found for new device, continuing without: %m");
2378 r
= ethtool_get_driver(&manager
->ethtool_fd
, link
->ifname
, &link
->driver
);
2380 log_link_debug_errno(link
, r
, "Failed to get driver, continuing without: %m");
2382 log_link_debug(link
, "Link %d added", link
->ifindex
);
2383 *ret
= TAKE_PTR(link
);
2387 int manager_rtnl_process_link(sd_netlink
*rtnl
, sd_netlink_message
*message
, Manager
*manager
) {
2389 NetDev
*netdev
= NULL
;
2398 if (sd_netlink_message_is_error(message
)) {
2399 r
= sd_netlink_message_get_errno(message
);
2401 log_message_warning_errno(message
, r
, "rtnl: Could not receive link message, ignoring");
2406 r
= sd_netlink_message_get_type(message
, &type
);
2408 log_warning_errno(r
, "rtnl: Could not get message type, ignoring: %m");
2410 } else if (!IN_SET(type
, RTM_NEWLINK
, RTM_DELLINK
)) {
2411 log_warning("rtnl: Received unexpected message type %u when processing link, ignoring.", type
);
2415 r
= sd_rtnl_message_link_get_ifindex(message
, &ifindex
);
2417 log_warning_errno(r
, "rtnl: Could not get ifindex from link message, ignoring: %m");
2419 } else if (ifindex
<= 0) {
2420 log_warning("rtnl: received link message with invalid ifindex %d, ignoring.", ifindex
);
2424 r
= sd_netlink_message_read_string(message
, IFLA_IFNAME
, &name
);
2426 log_warning_errno(r
, "rtnl: Received link message without ifname, ignoring: %m");
2430 (void) link_get_by_index(manager
, ifindex
, &link
);
2431 (void) netdev_get(manager
, name
, &netdev
);
2436 /* netdev exists, so make sure the ifindex matches */
2437 r
= netdev_set_ifindex(netdev
, message
);
2439 log_warning_errno(r
, "Could not process new link message for netdev, ignoring: %m");
2445 /* link is new, so add it */
2446 r
= link_new(manager
, message
, &link
);
2448 log_warning_errno(r
, "Could not process new link message: %m");
2452 r
= link_update(link
, message
);
2454 log_warning_errno(r
, "Could not process link message: %m");
2455 link_enter_failed(link
);
2459 r
= link_check_initialized(link
);
2461 log_warning_errno(r
, "Failed to check link is initialized: %m");
2462 link_enter_failed(link
);
2466 r
= link_update(link
, message
);
2468 log_warning_errno(r
, "Could not process link message: %m");
2469 link_enter_failed(link
);
2478 netdev_drop(netdev
);
2483 assert_not_reached("Received link message with invalid RTNL message type.");
2489 int link_getlink_handler_internal(sd_netlink
*rtnl
, sd_netlink_message
*m
, Link
*link
, const char *error_msg
) {
2490 uint16_t message_type
;
2497 if (IN_SET(link
->state
, LINK_STATE_FAILED
, LINK_STATE_LINGER
))
2500 r
= sd_netlink_message_get_errno(m
);
2502 log_link_message_warning_errno(link
, m
, r
, error_msg
);
2503 link_enter_failed(link
);
2507 r
= sd_netlink_message_get_type(m
, &message_type
);
2509 log_link_debug_errno(link
, r
, "rtnl: failed to read link message type, ignoring: %m");
2512 if (message_type
!= RTM_NEWLINK
) {
2513 log_link_debug(link
, "rtnl: received invalid link message type, ignoring.");
2517 r
= link_update(link
, m
);
2519 link_enter_failed(link
);
2526 int link_call_getlink(Link
*link
, link_netlink_message_handler_t callback
) {
2527 _cleanup_(sd_netlink_message_unrefp
) sd_netlink_message
*req
= NULL
;
2531 assert(link
->manager
);
2532 assert(link
->manager
->rtnl
);
2535 r
= sd_rtnl_message_new_link(link
->manager
->rtnl
, &req
, RTM_GETLINK
, link
->ifindex
);
2539 r
= netlink_call_async(link
->manager
->rtnl
, NULL
, req
, callback
,
2540 link_netlink_destroy_callback
, link
);
2548 static const char* const link_state_table
[_LINK_STATE_MAX
] = {
2549 [LINK_STATE_PENDING
] = "pending",
2550 [LINK_STATE_INITIALIZED
] = "initialized",
2551 [LINK_STATE_CONFIGURING
] = "configuring",
2552 [LINK_STATE_CONFIGURED
] = "configured",
2553 [LINK_STATE_UNMANAGED
] = "unmanaged",
2554 [LINK_STATE_FAILED
] = "failed",
2555 [LINK_STATE_LINGER
] = "linger",
2558 DEFINE_STRING_TABLE_LOOKUP(link_state
, LinkState
);