1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
5 #include <linux/nl80211.h>
9 #include "sd-dhcp-client.h"
10 #include "sd-dhcp-server.h"
11 #include "sd-dhcp6-client.h"
12 #include "sd-ipv4acd.h"
13 #include "sd-ipv4ll.h"
14 #include "sd-lldp-rx.h"
15 #include "sd-lldp-tx.h"
18 #include "sd-netlink.h"
20 #include "ether-addr-util.h"
22 #include "netif-util.h"
23 #include "network-util.h"
24 #include "networkd-bridge-vlan.h"
25 #include "networkd-ipv6ll.h"
26 #include "networkd-util.h"
27 #include "ordered-set.h"
28 #include "resolve-util.h"
31 typedef enum LinkState
{
32 LINK_STATE_PENDING
, /* udev has not initialized the link */
33 LINK_STATE_INITIALIZED
, /* udev has initialized the link */
34 LINK_STATE_CONFIGURING
, /* configuring addresses, routes, etc. */
35 LINK_STATE_CONFIGURED
, /* everything is configured */
36 LINK_STATE_UNMANAGED
, /* Unmanaged=yes is set */
37 LINK_STATE_FAILED
, /* at least one configuration process failed */
38 LINK_STATE_LINGER
, /* RTM_DELLINK for the link has been received */
40 _LINK_STATE_INVALID
= -EINVAL
,
43 typedef struct Manager Manager
;
44 typedef struct Network Network
;
45 typedef struct NetDev NetDev
;
46 typedef struct DUID DUID
;
55 int dsa_master_ifindex
;
56 int sr_iov_phys_port_ifindex
;
57 Set
*sr_iov_virt_port_ifindices
;
60 char **alternative_names
;
62 unsigned short iftype
;
64 struct hw_addr_data hw_addr
;
65 struct hw_addr_data bcast_addr
;
66 struct hw_addr_data permanent_hw_addr
;
67 struct hw_addr_data requested_hw_addr
;
68 struct in6_addr ipv6ll_address
;
72 uint32_t original_mtu
;
77 uint16_t bridge_vlan_pvid
;
78 bool bridge_vlan_pvid_is_untagged
;
79 uint32_t bridge_vlan_bitmap
[BRIDGE_VLAN_BITMAP_LEN
];
81 /* to prevent multiple ethtool calls */
82 bool ethtool_driver_read
;
83 bool ethtool_permanent_hw_addr_read
;
85 /* link-local addressing */
86 IPv6LinkLocalAddressGenMode ipv6ll_address_gen_mode
;
89 enum nl80211_iftype wlan_iftype
;
92 struct ether_addr bssid
;
95 uint8_t kernel_operstate
;
97 sd_event_source
*carrier_lost_timer
;
103 LinkOperationalState operstate
;
104 LinkCarrierState carrier_state
;
105 LinkAddressState address_state
;
106 LinkAddressState ipv4_address_state
;
107 LinkAddressState ipv6_address_state
;
108 LinkOnlineState online_state
;
110 unsigned static_address_messages
;
111 unsigned static_address_label_messages
;
112 unsigned static_bridge_fdb_messages
;
113 unsigned static_bridge_mdb_messages
;
114 unsigned static_ipv6_proxy_ndp_messages
;
115 unsigned static_neighbor_messages
;
116 unsigned static_nexthop_messages
;
117 unsigned static_route_messages
;
118 unsigned static_routing_policy_rule_messages
;
119 unsigned tc_messages
;
120 unsigned sr_iov_messages
;
121 unsigned set_link_messages
;
122 unsigned set_flags_messages
;
123 unsigned create_stacked_netdev_messages
;
131 sd_dhcp_client
*dhcp_client
;
132 sd_dhcp_lease
*dhcp_lease
;
134 unsigned dhcp4_messages
;
135 bool dhcp4_configured
;
136 char *dhcp4_6rd_tunnel_name
;
138 Hashmap
*ipv4acd_by_address
;
141 bool ipv4ll_address_configured
:1;
143 bool static_addresses_configured
:1;
144 bool static_address_labels_configured
:1;
145 bool static_bridge_fdb_configured
:1;
146 bool static_bridge_mdb_configured
:1;
147 bool static_ipv6_proxy_ndp_configured
:1;
148 bool static_neighbors_configured
:1;
149 bool static_nexthops_configured
:1;
150 bool static_routes_configured
:1;
151 bool static_routing_policy_rules_configured
:1;
152 bool tc_configured
:1;
153 bool sr_iov_configured
:1;
156 bool stacked_netdevs_created
:1;
157 bool bridge_vlan_set
:1;
159 sd_dhcp_server
*dhcp_server
;
162 sd_event_source
*ndisc_expire
;
165 Set
*ndisc_captive_portals
;
167 unsigned ndisc_messages
;
168 bool ndisc_configured
:1;
172 sd_dhcp6_client
*dhcp6_client
;
173 sd_dhcp6_lease
*dhcp6_lease
;
174 unsigned dhcp6_messages
;
175 bool dhcp6_configured
;
177 Set
*dhcp_pd_prefixes
;
178 unsigned dhcp_pd_messages
;
179 bool dhcp_pd_configured
;
181 /* This is about LLDP reception */
185 /* This is about LLDP transmission */
188 Hashmap
*bound_by_links
;
189 Hashmap
*bound_to_links
;
192 /* For speed meter */
193 struct rtnl_link_stats64 stats_old
, stats_new
;
196 /* All kinds of DNS configuration the user configured via D-Bus */
197 struct in_addr_full
**dns
;
199 OrderedSet
*search_domains
, *route_domains
;
201 int dns_default_route
;
202 ResolveSupport llmnr
;
204 DnssecMode dnssec_mode
;
205 DnsOverTlsMode dns_over_tls_mode
;
206 Set
*dnssec_negative_trust_anchors
;
208 /* Similar, but NTP server configuration */
212 typedef int (*link_netlink_message_handler_t
)(sd_netlink
*, sd_netlink_message
*, Link
*);
214 bool link_is_ready_to_configure(Link
*link
, bool allow_unmanaged
);
216 void link_ntp_settings_clear(Link
*link
);
217 void link_dns_settings_clear(Link
*link
);
218 Link
*link_unref(Link
*link
);
219 Link
*link_ref(Link
*link
);
220 DEFINE_TRIVIAL_CLEANUP_FUNC(Link
*, link_unref
);
221 DEFINE_TRIVIAL_DESTRUCTOR(link_netlink_destroy_callback
, Link
, link_unref
);
223 int link_get_by_index(Manager
*m
, int ifindex
, Link
**ret
);
224 int link_get_by_name(Manager
*m
, const char *ifname
, Link
**ret
);
225 int link_get_by_hw_addr(Manager
*m
, const struct hw_addr_data
*hw_addr
, Link
**ret
);
226 int link_get_master(Link
*link
, Link
**ret
);
228 int link_getlink_handler_internal(sd_netlink
*rtnl
, sd_netlink_message
*m
, Link
*link
, const char *error_msg
);
229 int link_call_getlink(Link
*link
, link_netlink_message_handler_t callback
);
230 int link_handle_bound_to_list(Link
*link
);
232 void link_enter_failed(Link
*link
);
233 void link_set_state(Link
*link
, LinkState state
);
234 void link_check_ready(Link
*link
);
236 void link_update_operstate(Link
*link
, bool also_update_bond_master
);
238 static inline bool link_has_carrier(Link
*link
) {
240 return netif_has_carrier(link
->kernel_operstate
, link
->flags
);
243 bool link_ipv6_enabled(Link
*link
);
244 int link_ipv6ll_gained(Link
*link
);
245 bool link_has_ipv6_connectivity(Link
*link
);
247 int link_stop_engines(Link
*link
, bool may_keep_dhcp
);
249 const char* link_state_to_string(LinkState s
) _const_
;
250 LinkState
link_state_from_string(const char *s
) _pure_
;
252 int link_reconfigure_impl(Link
*link
, bool force
);
253 int link_reconfigure(Link
*link
, bool force
);
255 int manager_udev_process_link(Manager
*m
, sd_device
*device
, sd_device_action_t action
);
256 int manager_rtnl_process_link(sd_netlink
*rtnl
, sd_netlink_message
*message
, Manager
*m
);
258 int link_flags_to_string_alloc(uint32_t flags
, char **ret
);
259 const char *kernel_operstate_to_string(int t
) _const_
;