]>
Commit | Line | Data |
---|---|---|
1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ | |
2 | #pragma once | |
3 | ||
4 | #include <linux/nl80211.h> | |
5 | ||
6 | #include "ether-addr-util.h" | |
7 | #include "forward.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" | |
14 | ||
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 */ | |
23 | _LINK_STATE_MAX, | |
24 | _LINK_STATE_INVALID = -EINVAL, | |
25 | } LinkState; | |
26 | ||
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; | |
31 | ||
32 | typedef struct Link { | |
33 | Manager *manager; | |
34 | ||
35 | unsigned n_ref; | |
36 | ||
37 | int ifindex; | |
38 | int master_ifindex; | |
39 | int dsa_master_ifindex; | |
40 | int sr_iov_phys_port_ifindex; | |
41 | Set *sr_iov_virt_port_ifindices; | |
42 | ||
43 | char *ifname; | |
44 | char **alternative_names; | |
45 | char *kind; | |
46 | unsigned short iftype; | |
47 | char *state_file; | |
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; | |
53 | uint32_t mtu; | |
54 | uint32_t min_mtu; | |
55 | uint32_t max_mtu; | |
56 | uint32_t original_mtu; | |
57 | sd_device *dev; | |
58 | char *driver; | |
59 | ||
60 | sd_event_source *ipv6_mtu_wait_synced_event_source; | |
61 | unsigned ipv6_mtu_wait_trial_count; | |
62 | ||
63 | /* bridge vlan */ | |
64 | uint16_t bridge_vlan_pvid; | |
65 | bool bridge_vlan_pvid_is_untagged; | |
66 | uint32_t bridge_vlan_bitmap[BRIDGE_VLAN_BITMAP_LEN]; | |
67 | ||
68 | /* to prevent multiple ethtool calls */ | |
69 | bool ethtool_driver_read; | |
70 | bool ethtool_permanent_hw_addr_read; | |
71 | ||
72 | /* link-local addressing */ | |
73 | IPv6LinkLocalAddressGenMode ipv6ll_address_gen_mode; | |
74 | ||
75 | /* wlan */ | |
76 | enum nl80211_iftype wlan_iftype; | |
77 | char *ssid; | |
78 | char *previous_ssid; | |
79 | struct ether_addr bssid; | |
80 | ||
81 | unsigned flags; | |
82 | uint8_t kernel_operstate; | |
83 | ||
84 | sd_event_source *carrier_lost_timer; | |
85 | ||
86 | Network *network; | |
87 | NetDev *netdev; | |
88 | ||
89 | LinkState state; | |
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; | |
97 | ||
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; | |
112 | ||
113 | Set *addresses; | |
114 | Set *neighbors; | |
115 | Set *qdiscs; | |
116 | Set *tclasses; | |
117 | ||
118 | sd_dhcp_client *dhcp_client; | |
119 | sd_dhcp_lease *dhcp_lease; | |
120 | char *lease_file; | |
121 | unsigned dhcp4_messages; | |
122 | bool dhcp4_configured; | |
123 | char *dhcp4_6rd_tunnel_name; | |
124 | ||
125 | Hashmap *ipv4acd_by_address; | |
126 | ||
127 | sd_ipv4ll *ipv4ll; | |
128 | bool ipv4ll_address_configured:1; | |
129 | ||
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; | |
141 | bool activated:1; | |
142 | bool master_set:1; | |
143 | bool stacked_netdevs_created:1; | |
144 | bool bridge_vlan_set:1; | |
145 | ||
146 | sd_dhcp_server *dhcp_server; | |
147 | ||
148 | sd_ndisc *ndisc; | |
149 | sd_event_source *ndisc_expire; | |
150 | Hashmap *ndisc_routers_by_sender; | |
151 | Set *ndisc_rdnss; | |
152 | Set *ndisc_dnssl; | |
153 | Set *ndisc_captive_portals; | |
154 | Set *ndisc_pref64; | |
155 | Set *ndisc_redirects; | |
156 | Set *ndisc_dnr; | |
157 | uint32_t ndisc_mtu; | |
158 | unsigned ndisc_messages; | |
159 | bool ndisc_configured; | |
160 | ||
161 | sd_radv *radv; | |
162 | ||
163 | sd_dhcp6_client *dhcp6_client; | |
164 | sd_dhcp6_lease *dhcp6_lease; | |
165 | unsigned dhcp6_messages; | |
166 | bool dhcp6_configured; | |
167 | ||
168 | Set *dhcp_pd_prefixes; | |
169 | unsigned dhcp_pd_messages; | |
170 | bool dhcp_pd_configured; | |
171 | ||
172 | /* This is about LLDP reception */ | |
173 | sd_lldp_rx *lldp_rx; | |
174 | ||
175 | /* This is about LLDP transmission */ | |
176 | sd_lldp_tx *lldp_tx; | |
177 | ||
178 | Hashmap *bound_by_links; | |
179 | Hashmap *bound_to_links; | |
180 | Set *slaves; | |
181 | ||
182 | /* For speed meter */ | |
183 | struct rtnl_link_stats64 stats_old, stats_new; | |
184 | bool stats_updated; | |
185 | ||
186 | /* All kinds of DNS configuration the user configured via D-Bus */ | |
187 | struct in_addr_full **dns; | |
188 | unsigned n_dns; | |
189 | OrderedSet *search_domains, *route_domains; | |
190 | ||
191 | int dns_default_route; | |
192 | ResolveSupport llmnr; | |
193 | ResolveSupport mdns; | |
194 | DnssecMode dnssec_mode; | |
195 | DnsOverTlsMode dns_over_tls_mode; | |
196 | Set *dnssec_negative_trust_anchors; | |
197 | ||
198 | /* Similar, but NTP server configuration */ | |
199 | char **ntp; | |
200 | } Link; | |
201 | ||
202 | extern const struct hash_ops link_hash_ops; | |
203 | ||
204 | typedef int (*link_netlink_message_handler_t)(sd_netlink*, sd_netlink_message*, Link*); | |
205 | ||
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); | |
208 | ||
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); | |
215 | ||
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); | |
220 | ||
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); | |
224 | ||
225 | void link_enter_failed(Link *link); | |
226 | void link_set_state(Link *link, LinkState state); | |
227 | void link_check_ready(Link *link); | |
228 | ||
229 | void link_update_operstate(Link *link, bool also_update_bond_master); | |
230 | ||
231 | bool link_has_carrier(Link *link); | |
232 | ||
233 | bool link_ipv6_enabled(Link *link); | |
234 | int link_ipv6ll_gained(Link *link); | |
235 | bool link_has_ipv6_connectivity(Link *link); | |
236 | ||
237 | int link_stop_engines(Link *link, bool may_keep_dynamic); | |
238 | ||
239 | const char* link_state_to_string(LinkState s) _const_; | |
240 | LinkState link_state_from_string(const char *s) _pure_; | |
241 | ||
242 | int link_request_stacked_netdevs(Link *link, NetDevLocalAddressType type); | |
243 | ||
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); | |
248 | } | |
249 | ||
250 | int link_check_initialized(Link *link); | |
251 | ||
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); | |
254 | ||
255 | int link_flags_to_string_alloc(uint32_t flags, char **ret); | |
256 | const char* kernel_operstate_to_string(int t) _const_; | |
257 | ||
258 | void link_required_operstate_for_online(Link *link, LinkOperationalStateRange *ret); | |
259 | AddressFamily link_required_family_for_online(Link *link); |