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"
17 #include "sd-netlink.h"
19 #include "ether-addr-util.h"
21 #include "network-util.h"
22 #include "networkd-util.h"
23 #include "ordered-set.h"
24 #include "resolve-util.h"
27 typedef enum LinkState
{
28 LINK_STATE_PENDING
, /* udev has not initialized the link */
29 LINK_STATE_INITIALIZED
, /* udev has initialized the link */
30 LINK_STATE_CONFIGURING
, /* configuring addresses, routes, etc. */
31 LINK_STATE_CONFIGURED
, /* everything is configured */
32 LINK_STATE_UNMANAGED
, /* Unmanaged=yes is set */
33 LINK_STATE_FAILED
, /* at least one configuration process failed */
34 LINK_STATE_LINGER
, /* RTM_DELLINK for the link has been received */
36 _LINK_STATE_INVALID
= -EINVAL
,
39 typedef struct Manager Manager
;
40 typedef struct Network Network
;
41 typedef struct Address Address
;
42 typedef struct DUID DUID
;
52 char **alternative_names
;
54 unsigned short iftype
;
57 hw_addr_data bcast_addr
;
58 struct ether_addr permanent_mac
;
59 struct in6_addr ipv6ll_address
;
65 enum nl80211_iftype wlan_iftype
;
67 struct ether_addr bssid
;
70 uint8_t kernel_operstate
;
75 LinkOperationalState operstate
;
76 LinkCarrierState carrier_state
;
77 LinkAddressState address_state
;
78 LinkAddressState ipv4_address_state
;
79 LinkAddressState ipv6_address_state
;
80 LinkOnlineState online_state
;
82 unsigned address_label_messages
;
83 unsigned static_address_messages
;
84 unsigned static_neighbor_messages
;
85 unsigned static_nexthop_messages
;
86 unsigned static_route_messages
;
87 unsigned static_routing_policy_rule_messages
;
88 unsigned address_remove_messages
;
89 unsigned neighbor_remove_messages
;
90 unsigned nexthop_remove_messages
;
91 unsigned route_remove_messages
;
93 unsigned sr_iov_messages
;
95 unsigned bridge_mdb_messages
;
98 Set
*addresses_foreign
;
100 Set
*static_addresses
;
102 Set
*neighbors_foreign
;
106 Set
*nexthops_foreign
;
108 sd_dhcp_client
*dhcp_client
;
109 sd_dhcp_lease
*dhcp_lease
;
110 Address
*dhcp_address
, *dhcp_address_old
;
111 Set
*dhcp_routes
, *dhcp_routes_old
;
113 uint32_t original_mtu
;
114 unsigned dhcp4_messages
;
115 sd_ipv4acd
*dhcp_acd
;
116 bool dhcp4_route_failed
:1;
117 bool dhcp4_route_retrying
:1;
118 bool dhcp4_configured
:1;
119 bool dhcp4_address_bind
:1;
122 bool ipv4ll_address_configured
:1;
124 bool static_addresses_configured
:1;
125 bool static_neighbors_configured
:1;
126 bool static_nexthops_configured
:1;
127 bool static_routes_configured
:1;
128 bool static_routing_policy_rules_configured
:1;
129 bool tc_configured
:1;
130 bool sr_iov_configured
:1;
132 bool setting_genmode
:1;
134 bool bridge_mdb_configured
:1;
135 bool can_configured
:1;
138 sd_dhcp_server
*dhcp_server
;
143 Set
*ndisc_addresses
;
145 unsigned ndisc_addresses_messages
;
146 unsigned ndisc_routes_messages
;
147 bool ndisc_addresses_configured
:1;
148 bool ndisc_routes_configured
:1;
152 sd_dhcp6_client
*dhcp6_client
;
153 sd_dhcp6_lease
*dhcp6_lease
;
154 Set
*dhcp6_addresses
, *dhcp6_addresses_old
;
155 Set
*dhcp6_routes
, *dhcp6_routes_old
;
156 Set
*dhcp6_pd_prefixes
;
157 Set
*dhcp6_pd_addresses
, *dhcp6_pd_addresses_old
;
158 Set
*dhcp6_pd_routes
, *dhcp6_pd_routes_old
;
159 unsigned dhcp6_address_messages
;
160 unsigned dhcp6_route_messages
;
161 unsigned dhcp6_pd_address_messages
;
162 unsigned dhcp6_pd_route_messages
;
163 bool dhcp6_address_configured
:1;
164 bool dhcp6_route_configured
:1;
165 bool dhcp6_pd_address_configured
:1;
166 bool dhcp6_pd_route_configured
:1;
167 bool dhcp6_pd_prefixes_assigned
:1;
169 /* This is about LLDP reception */
173 /* This is about LLDP transmission */
174 unsigned lldp_tx_fast
; /* The LLDP txFast counter (See 802.1ab-2009, section 9.2.5.18) */
175 sd_event_source
*lldp_emit_event_source
;
177 Hashmap
*bound_by_links
;
178 Hashmap
*bound_to_links
;
181 /* For speed meter */
182 struct rtnl_link_stats64 stats_old
, stats_new
;
185 /* All kinds of DNS configuration the user configured via D-Bus */
186 struct in_addr_full
**dns
;
188 OrderedSet
*search_domains
, *route_domains
;
190 int dns_default_route
;
191 ResolveSupport llmnr
;
193 DnssecMode dnssec_mode
;
194 DnsOverTlsMode dns_over_tls_mode
;
195 Set
*dnssec_negative_trust_anchors
;
197 /* Similar, but NTP server configuration */
201 typedef int (*link_netlink_message_handler_t
)(sd_netlink
*, sd_netlink_message
*, Link
*);
203 bool link_is_ready_to_configure(Link
*link
, bool allow_unmanaged
);
205 void link_ntp_settings_clear(Link
*link
);
206 void link_dns_settings_clear(Link
*link
);
207 Link
*link_unref(Link
*link
);
208 Link
*link_ref(Link
*link
);
209 DEFINE_TRIVIAL_CLEANUP_FUNC(Link
*, link_unref
);
210 DEFINE_TRIVIAL_DESTRUCTOR(link_netlink_destroy_callback
, Link
, link_unref
);
212 int link_get(Manager
*m
, int ifindex
, Link
**ret
);
213 int link_get_by_name(Manager
*m
, const char *ifname
, Link
**ret
);
215 int link_up(Link
*link
);
216 int link_down(Link
*link
, link_netlink_message_handler_t callback
);
217 int link_activate(Link
*link
);
219 void link_enter_failed(Link
*link
);
221 void link_set_state(Link
*link
, LinkState state
);
222 void link_check_ready(Link
*link
);
224 void link_update_operstate(Link
*link
, bool also_update_bond_master
);
226 int link_carrier_reset(Link
*link
);
227 bool link_has_carrier(Link
*link
);
229 bool link_ipv6_enabled(Link
*link
);
230 bool link_ipv6ll_enabled(Link
*link
);
231 int link_ipv6ll_gained(Link
*link
, const struct in6_addr
*address
);
233 int link_set_mtu(Link
*link
, uint32_t mtu
);
235 bool link_ipv4ll_enabled(Link
*link
);
237 int link_stop_engines(Link
*link
, bool may_keep_dhcp
);
239 const char* link_state_to_string(LinkState s
) _const_
;
240 LinkState
link_state_from_string(const char *s
) _pure_
;
242 int link_configure(Link
*link
);
243 int link_reconfigure(Link
*link
, bool force
);
245 int manager_udev_process_link(sd_device_monitor
*monitor
, sd_device
*device
, void *userdata
);
246 int manager_rtnl_process_link(sd_netlink
*rtnl
, sd_netlink_message
*message
, Manager
*m
);