]>
Commit | Line | Data |
---|---|---|
1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ | |
2 | #pragma once | |
3 | ||
4 | #include <endian.h> | |
5 | #include <linux/nl80211.h> | |
6 | ||
7 | #include "sd-bus.h" | |
8 | #include "sd-device.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" | |
16 | #include "sd-ndisc.h" | |
17 | #include "sd-radv.h" | |
18 | #include "sd-netlink.h" | |
19 | ||
20 | #include "ether-addr-util.h" | |
21 | #include "log-link.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 "ratelimit.h" | |
29 | #include "resolve-util.h" | |
30 | #include "set.h" | |
31 | ||
32 | typedef enum LinkState { | |
33 | LINK_STATE_PENDING, /* udev has not initialized the link */ | |
34 | LINK_STATE_INITIALIZED, /* udev has initialized the link */ | |
35 | LINK_STATE_CONFIGURING, /* configuring addresses, routes, etc. */ | |
36 | LINK_STATE_CONFIGURED, /* everything is configured */ | |
37 | LINK_STATE_UNMANAGED, /* Unmanaged=yes is set */ | |
38 | LINK_STATE_FAILED, /* at least one configuration process failed */ | |
39 | LINK_STATE_LINGER, /* RTM_DELLINK for the link has been received */ | |
40 | _LINK_STATE_MAX, | |
41 | _LINK_STATE_INVALID = -EINVAL, | |
42 | } LinkState; | |
43 | ||
44 | typedef struct Manager Manager; | |
45 | typedef struct Network Network; | |
46 | typedef struct NetDev NetDev; | |
47 | typedef struct DUID DUID; | |
48 | ||
49 | typedef struct Link { | |
50 | Manager *manager; | |
51 | ||
52 | unsigned n_ref; | |
53 | ||
54 | int ifindex; | |
55 | int master_ifindex; | |
56 | int dsa_master_ifindex; | |
57 | int sr_iov_phys_port_ifindex; | |
58 | Set *sr_iov_virt_port_ifindices; | |
59 | ||
60 | char *ifname; | |
61 | char **alternative_names; | |
62 | char *kind; | |
63 | unsigned short iftype; | |
64 | char *state_file; | |
65 | struct hw_addr_data hw_addr; | |
66 | struct hw_addr_data bcast_addr; | |
67 | struct hw_addr_data permanent_hw_addr; | |
68 | struct hw_addr_data requested_hw_addr; | |
69 | struct in6_addr ipv6ll_address; | |
70 | uint32_t mtu; | |
71 | uint32_t min_mtu; | |
72 | uint32_t max_mtu; | |
73 | uint32_t original_mtu; | |
74 | sd_device *dev; | |
75 | char *driver; | |
76 | ||
77 | /* bridge vlan */ | |
78 | uint16_t bridge_vlan_pvid; | |
79 | bool bridge_vlan_pvid_is_untagged; | |
80 | uint32_t bridge_vlan_bitmap[BRIDGE_VLAN_BITMAP_LEN]; | |
81 | ||
82 | /* to prevent multiple ethtool calls */ | |
83 | bool ethtool_driver_read; | |
84 | bool ethtool_permanent_hw_addr_read; | |
85 | ||
86 | /* link-local addressing */ | |
87 | IPv6LinkLocalAddressGenMode ipv6ll_address_gen_mode; | |
88 | ||
89 | /* wlan */ | |
90 | enum nl80211_iftype wlan_iftype; | |
91 | char *ssid; | |
92 | char *previous_ssid; | |
93 | struct ether_addr bssid; | |
94 | ||
95 | unsigned flags; | |
96 | uint8_t kernel_operstate; | |
97 | ||
98 | sd_event_source *carrier_lost_timer; | |
99 | ||
100 | Network *network; | |
101 | NetDev *netdev; | |
102 | ||
103 | LinkState state; | |
104 | LinkOperationalState operstate; | |
105 | LinkCarrierState carrier_state; | |
106 | LinkAddressState address_state; | |
107 | LinkAddressState ipv4_address_state; | |
108 | LinkAddressState ipv6_address_state; | |
109 | LinkOnlineState online_state; | |
110 | RateLimit automatic_reconfigure_ratelimit; | |
111 | ||
112 | unsigned static_address_messages; | |
113 | unsigned static_address_label_messages; | |
114 | unsigned static_bridge_fdb_messages; | |
115 | unsigned static_bridge_mdb_messages; | |
116 | unsigned static_ipv6_proxy_ndp_messages; | |
117 | unsigned static_neighbor_messages; | |
118 | unsigned static_nexthop_messages; | |
119 | unsigned static_route_messages; | |
120 | unsigned static_routing_policy_rule_messages; | |
121 | unsigned tc_messages; | |
122 | unsigned sr_iov_messages; | |
123 | unsigned set_link_messages; | |
124 | unsigned set_flags_messages; | |
125 | unsigned create_stacked_netdev_messages; | |
126 | ||
127 | Set *addresses; | |
128 | Set *neighbors; | |
129 | Set *qdiscs; | |
130 | Set *tclasses; | |
131 | ||
132 | sd_dhcp_client *dhcp_client; | |
133 | sd_dhcp_lease *dhcp_lease; | |
134 | char *lease_file; | |
135 | unsigned dhcp4_messages; | |
136 | bool dhcp4_configured; | |
137 | char *dhcp4_6rd_tunnel_name; | |
138 | ||
139 | Hashmap *ipv4acd_by_address; | |
140 | ||
141 | sd_ipv4ll *ipv4ll; | |
142 | bool ipv4ll_address_configured:1; | |
143 | ||
144 | bool static_addresses_configured:1; | |
145 | bool static_address_labels_configured:1; | |
146 | bool static_bridge_fdb_configured:1; | |
147 | bool static_bridge_mdb_configured:1; | |
148 | bool static_ipv6_proxy_ndp_configured:1; | |
149 | bool static_neighbors_configured:1; | |
150 | bool static_nexthops_configured:1; | |
151 | bool static_routes_configured:1; | |
152 | bool static_routing_policy_rules_configured:1; | |
153 | bool tc_configured:1; | |
154 | bool sr_iov_configured:1; | |
155 | bool activated:1; | |
156 | bool master_set:1; | |
157 | bool stacked_netdevs_created:1; | |
158 | bool bridge_vlan_set:1; | |
159 | ||
160 | sd_dhcp_server *dhcp_server; | |
161 | ||
162 | sd_ndisc *ndisc; | |
163 | sd_ndisc_router *ndisc_default_router; | |
164 | sd_event_source *ndisc_expire; | |
165 | Set *ndisc_rdnss; | |
166 | Set *ndisc_dnssl; | |
167 | Set *ndisc_captive_portals; | |
168 | Set *ndisc_pref64; | |
169 | Set *ndisc_redirects; | |
170 | uint32_t ndisc_mtu; | |
171 | unsigned ndisc_messages; | |
172 | bool ndisc_configured:1; | |
173 | ||
174 | sd_radv *radv; | |
175 | ||
176 | sd_dhcp6_client *dhcp6_client; | |
177 | sd_dhcp6_lease *dhcp6_lease; | |
178 | unsigned dhcp6_messages; | |
179 | bool dhcp6_configured; | |
180 | ||
181 | Set *dhcp_pd_prefixes; | |
182 | unsigned dhcp_pd_messages; | |
183 | bool dhcp_pd_configured; | |
184 | ||
185 | /* This is about LLDP reception */ | |
186 | sd_lldp_rx *lldp_rx; | |
187 | ||
188 | /* This is about LLDP transmission */ | |
189 | sd_lldp_tx *lldp_tx; | |
190 | ||
191 | Hashmap *bound_by_links; | |
192 | Hashmap *bound_to_links; | |
193 | Set *slaves; | |
194 | ||
195 | /* For speed meter */ | |
196 | struct rtnl_link_stats64 stats_old, stats_new; | |
197 | bool stats_updated; | |
198 | ||
199 | /* All kinds of DNS configuration the user configured via D-Bus */ | |
200 | struct in_addr_full **dns; | |
201 | unsigned n_dns; | |
202 | OrderedSet *search_domains, *route_domains; | |
203 | ||
204 | int dns_default_route; | |
205 | ResolveSupport llmnr; | |
206 | ResolveSupport mdns; | |
207 | DnssecMode dnssec_mode; | |
208 | DnsOverTlsMode dns_over_tls_mode; | |
209 | Set *dnssec_negative_trust_anchors; | |
210 | ||
211 | /* Similar, but NTP server configuration */ | |
212 | char **ntp; | |
213 | } Link; | |
214 | ||
215 | typedef int (*link_netlink_message_handler_t)(sd_netlink*, sd_netlink_message*, Link*); | |
216 | ||
217 | bool link_is_ready_to_configure(Link *link, bool allow_unmanaged); | |
218 | ||
219 | void link_ntp_settings_clear(Link *link); | |
220 | void link_dns_settings_clear(Link *link); | |
221 | Link *link_unref(Link *link); | |
222 | Link *link_ref(Link *link); | |
223 | DEFINE_TRIVIAL_CLEANUP_FUNC(Link*, link_unref); | |
224 | DEFINE_TRIVIAL_DESTRUCTOR(link_netlink_destroy_callback, Link, link_unref); | |
225 | ||
226 | int link_get_by_index(Manager *m, int ifindex, Link **ret); | |
227 | int link_get_by_name(Manager *m, const char *ifname, Link **ret); | |
228 | int link_get_by_hw_addr(Manager *m, const struct hw_addr_data *hw_addr, Link **ret); | |
229 | int link_get_master(Link *link, Link **ret); | |
230 | ||
231 | int link_getlink_handler_internal(sd_netlink *rtnl, sd_netlink_message *m, Link *link, const char *error_msg); | |
232 | int link_call_getlink(Link *link, link_netlink_message_handler_t callback); | |
233 | int link_handle_bound_to_list(Link *link); | |
234 | ||
235 | void link_enter_failed(Link *link); | |
236 | void link_set_state(Link *link, LinkState state); | |
237 | void link_check_ready(Link *link); | |
238 | ||
239 | void link_update_operstate(Link *link, bool also_update_bond_master); | |
240 | ||
241 | static inline bool link_has_carrier(Link *link) { | |
242 | assert(link); | |
243 | return netif_has_carrier(link->kernel_operstate, link->flags); | |
244 | } | |
245 | ||
246 | bool link_ipv6_enabled(Link *link); | |
247 | int link_ipv6ll_gained(Link *link); | |
248 | bool link_has_ipv6_connectivity(Link *link); | |
249 | ||
250 | int link_stop_engines(Link *link, bool may_keep_dhcp); | |
251 | ||
252 | const char* link_state_to_string(LinkState s) _const_; | |
253 | LinkState link_state_from_string(const char *s) _pure_; | |
254 | ||
255 | int link_reconfigure_impl(Link *link, bool force); | |
256 | int link_reconfigure(Link *link, bool force); | |
257 | int link_reconfigure_on_bus_method_reload(Link *link, sd_bus_message *message); | |
258 | ||
259 | int manager_udev_process_link(Manager *m, sd_device *device, sd_device_action_t action); | |
260 | int manager_rtnl_process_link(sd_netlink *rtnl, sd_netlink_message *message, Manager *m); | |
261 | ||
262 | int link_flags_to_string_alloc(uint32_t flags, char **ret); | |
263 | const char *kernel_operstate_to_string(int t) _const_; | |
264 | ||
265 | void link_required_operstate_for_online(Link *link, LinkOperationalStateRange *ret); | |
266 | AddressFamily link_required_family_for_online(Link *link); |