1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
4 #include <linux/nl80211.h>
6 #include "ether-addr-util.h"
8 #include "network-util.h"
9 #include "networkd-bridge-vlan.h"
10 #include "networkd-forward.h"
11 #include "networkd-ipv6ll.h"
12 #include "ratelimit.h"
13 #include "resolve-util.h"
15 typedef enum LinkState
{
16 LINK_STATE_PENDING
, /* udev has not initialized the link */
17 LINK_STATE_INITIALIZED
, /* udev has initialized the link */
18 LINK_STATE_CONFIGURING
, /* configuring addresses, routes, etc. */
19 LINK_STATE_CONFIGURED
, /* everything is configured */
20 LINK_STATE_UNMANAGED
, /* Unmanaged=yes is set */
21 LINK_STATE_FAILED
, /* at least one configuration process failed */
22 LINK_STATE_LINGER
, /* RTM_DELLINK for the link has been received */
24 _LINK_STATE_INVALID
= -EINVAL
,
27 typedef enum LinkReconfigurationFlag
{
28 LINK_RECONFIGURE_UNCONDITIONALLY
= 1 << 0, /* Reconfigure an interface even if .network file is unchanged. */
29 LINK_RECONFIGURE_CLEANLY
= 1 << 1, /* Drop all existing configs before reconfiguring. Otherwise, reuse existing configs as possible as we can. */
30 } LinkReconfigurationFlag
;
39 int dsa_master_ifindex
;
40 int sr_iov_phys_port_ifindex
;
41 Set
*sr_iov_virt_port_ifindices
;
44 char **alternative_names
;
46 unsigned short iftype
;
48 struct hw_addr_data hw_addr
;
49 struct hw_addr_data bcast_addr
;
50 struct hw_addr_data permanent_hw_addr
;
51 struct hw_addr_data requested_hw_addr
;
52 struct in6_addr ipv6ll_address
;
56 uint32_t original_mtu
;
60 sd_event_source
*ipv6_mtu_wait_synced_event_source
;
61 unsigned ipv6_mtu_wait_trial_count
;
64 uint16_t bridge_vlan_pvid
;
65 bool bridge_vlan_pvid_is_untagged
;
66 uint32_t bridge_vlan_bitmap
[BRIDGE_VLAN_BITMAP_LEN
];
68 /* to prevent multiple ethtool calls */
69 bool ethtool_driver_read
;
70 bool ethtool_permanent_hw_addr_read
;
72 /* link-local addressing */
73 IPv6LinkLocalAddressGenMode ipv6ll_address_gen_mode
;
76 enum nl80211_iftype wlan_iftype
;
79 struct ether_addr bssid
;
82 uint8_t kernel_operstate
;
84 sd_event_source
*carrier_lost_timer
;
90 LinkOperationalState operstate
;
91 LinkCarrierState carrier_state
;
92 LinkAddressState address_state
;
93 LinkAddressState ipv4_address_state
;
94 LinkAddressState ipv6_address_state
;
95 LinkOnlineState online_state
;
96 RateLimit automatic_reconfigure_ratelimit
;
98 unsigned static_address_messages
;
99 unsigned static_address_label_messages
;
100 unsigned static_bridge_fdb_messages
;
101 unsigned static_bridge_mdb_messages
;
102 unsigned static_ipv6_proxy_ndp_messages
;
103 unsigned static_neighbor_messages
;
104 unsigned static_nexthop_messages
;
105 unsigned static_route_messages
;
106 unsigned static_routing_policy_rule_messages
;
107 unsigned tc_messages
;
108 unsigned sr_iov_messages
;
109 unsigned set_link_messages
;
110 unsigned set_flags_messages
;
111 unsigned create_stacked_netdev_messages
;
118 sd_dhcp_client
*dhcp_client
;
119 sd_dhcp_lease
*dhcp_lease
;
121 unsigned dhcp4_messages
;
122 bool dhcp4_configured
;
123 char *dhcp4_6rd_tunnel_name
;
125 Hashmap
*ipv4acd_by_address
;
128 bool ipv4ll_address_configured
:1;
130 bool static_addresses_configured
:1;
131 bool static_address_labels_configured
:1;
132 bool static_bridge_fdb_configured
:1;
133 bool static_bridge_mdb_configured
:1;
134 bool static_ipv6_proxy_ndp_configured
:1;
135 bool static_neighbors_configured
:1;
136 bool static_nexthops_configured
:1;
137 bool static_routes_configured
:1;
138 bool static_routing_policy_rules_configured
:1;
139 bool tc_configured
:1;
140 bool sr_iov_configured
:1;
143 bool stacked_netdevs_created
:1;
144 bool bridge_vlan_set
:1;
146 sd_dhcp_server
*dhcp_server
;
149 sd_event_source
*ndisc_expire
;
150 Hashmap
*ndisc_routers_by_sender
;
153 Set
*ndisc_captive_portals
;
155 Set
*ndisc_redirects
;
158 unsigned ndisc_messages
;
159 bool ndisc_configured
;
163 sd_dhcp6_client
*dhcp6_client
;
164 sd_dhcp6_lease
*dhcp6_lease
;
165 unsigned dhcp6_messages
;
166 bool dhcp6_configured
;
168 Set
*dhcp_pd_prefixes
;
169 unsigned dhcp_pd_messages
;
170 bool dhcp_pd_configured
;
172 /* This is about LLDP reception */
175 /* This is about LLDP transmission */
178 Hashmap
*bound_by_links
;
179 Hashmap
*bound_to_links
;
182 /* For speed meter */
183 struct rtnl_link_stats64 stats_old
, stats_new
;
186 /* All kinds of DNS configuration the user configured via D-Bus */
187 struct in_addr_full
**dns
;
189 OrderedSet
*search_domains
, *route_domains
;
191 int dns_default_route
;
192 ResolveSupport llmnr
;
194 DnssecMode dnssec_mode
;
195 DnsOverTlsMode dns_over_tls_mode
;
196 Set
*dnssec_negative_trust_anchors
;
198 /* Similar, but NTP server configuration */
202 extern const struct hash_ops link_hash_ops
;
204 typedef int (*link_netlink_message_handler_t
)(sd_netlink
*, sd_netlink_message
*, Link
*);
206 bool link_is_ready_to_configure(Link
*link
, bool allow_unmanaged
);
207 bool link_is_ready_to_configure_by_name(Manager
*manager
, const char *name
, bool allow_unmanaged
);
209 void link_ntp_settings_clear(Link
*link
);
210 void link_dns_settings_clear(Link
*link
);
211 Link
* link_unref(Link
*link
);
212 Link
* link_ref(Link
*link
);
213 DEFINE_TRIVIAL_CLEANUP_FUNC(Link
*, link_unref
);
214 DEFINE_TRIVIAL_DESTRUCTOR(link_netlink_destroy_callback
, Link
, link_unref
);
216 int link_get_by_index(Manager
*m
, int ifindex
, Link
**ret
);
217 int link_get_by_name(Manager
*m
, const char *ifname
, Link
**ret
);
218 int link_get_by_hw_addr(Manager
*m
, const struct hw_addr_data
*hw_addr
, Link
**ret
);
219 int link_get_master(Link
*link
, Link
**ret
);
221 int link_getlink_handler_internal(sd_netlink
*rtnl
, sd_netlink_message
*m
, Link
*link
, const char *error_msg
);
222 int link_call_getlink(Link
*link
, link_netlink_message_handler_t callback
);
223 int link_handle_bound_to_list(Link
*link
);
225 void link_enter_failed(Link
*link
);
226 void link_set_state(Link
*link
, LinkState state
);
227 void link_check_ready(Link
*link
);
229 void link_update_operstate(Link
*link
, bool also_update_bond_master
);
231 bool link_has_carrier(Link
*link
);
233 bool link_ipv6_enabled(Link
*link
);
234 int link_ipv6ll_gained(Link
*link
);
235 bool link_has_ipv6_connectivity(Link
*link
);
237 int link_stop_engines(Link
*link
, bool may_keep_dynamic
);
239 const char* link_state_to_string(LinkState s
) _const_
;
240 LinkState
link_state_from_string(const char *s
) _pure_
;
242 int link_request_stacked_netdevs(Link
*link
, NetDevLocalAddressType type
);
244 int link_reconfigure_impl(Link
*link
, LinkReconfigurationFlag flags
);
245 int link_reconfigure_full(Link
*link
, LinkReconfigurationFlag flags
, sd_bus_message
*message
, unsigned *counter
);
246 static inline int link_reconfigure(Link
*link
, LinkReconfigurationFlag flags
) {
247 return link_reconfigure_full(link
, flags
, NULL
, NULL
);
250 int link_check_initialized(Link
*link
);
252 int manager_udev_process_link(Manager
*m
, sd_device
*device
, sd_device_action_t action
);
253 int manager_rtnl_process_link(sd_netlink
*rtnl
, sd_netlink_message
*message
, Manager
*m
);
255 int link_flags_to_string_alloc(uint32_t flags
, char **ret
);
256 const char* kernel_operstate_to_string(int t
) _const_
;
258 void link_required_operstate_for_online(Link
*link
, LinkOperationalStateRange
*ret
);
259 AddressFamily
link_required_family_for_online(Link
*link
);