]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/network/networkd-link.h
Merge pull request #16624 from keszybz/timesync-retry-interval
[thirdparty/systemd.git] / src / network / networkd-link.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
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-ipv4ll.h"
13 #include "sd-lldp.h"
14 #include "sd-ndisc.h"
15 #include "sd-radv.h"
16 #include "sd-netlink.h"
17
18 #include "list.h"
19 #include "log-link.h"
20 #include "network-util.h"
21 #include "networkd-util.h"
22 #include "ordered-set.h"
23 #include "resolve-util.h"
24 #include "set.h"
25
26 typedef enum LinkState {
27 LINK_STATE_PENDING, /* udev has not initialized the link */
28 LINK_STATE_INITIALIZED, /* udev has initialized the link */
29 LINK_STATE_CONFIGURING, /* configuring addresses, routes, etc. */
30 LINK_STATE_CONFIGURED, /* everything is configured */
31 LINK_STATE_UNMANAGED, /* Unmanaged=yes is set */
32 LINK_STATE_FAILED, /* at least one configuration process failed */
33 LINK_STATE_LINGER, /* RTM_DELLINK for the link has been received */
34 _LINK_STATE_MAX,
35 _LINK_STATE_INVALID = -1
36 } LinkState;
37
38 typedef struct Manager Manager;
39 typedef struct Network Network;
40 typedef struct Address Address;
41 typedef struct DUID DUID;
42
43 typedef struct Link {
44 Manager *manager;
45
46 unsigned n_ref;
47
48 int ifindex;
49 int master_ifindex;
50 char *ifname;
51 char **alternative_names;
52 char *kind;
53 unsigned short iftype;
54 char *state_file;
55 struct ether_addr mac;
56 struct ether_addr permanent_mac;
57 struct in6_addr ipv6ll_address;
58 uint32_t mtu;
59 sd_device *sd_device;
60 char *driver;
61
62 /* wlan */
63 enum nl80211_iftype wlan_iftype;
64 char *ssid;
65 struct ether_addr bssid;
66
67 unsigned flags;
68 uint8_t kernel_operstate;
69
70 Network *network;
71
72 LinkState state;
73 LinkOperationalState operstate;
74 LinkCarrierState carrier_state;
75 LinkAddressState address_state;
76
77 unsigned address_messages;
78 unsigned address_label_messages;
79 unsigned neighbor_messages;
80 unsigned route_messages;
81 unsigned nexthop_messages;
82 unsigned routing_policy_rule_messages;
83 unsigned routing_policy_rule_remove_messages;
84 unsigned tc_messages;
85 unsigned sr_iov_messages;
86 unsigned enslaving;
87
88 Set *addresses;
89 Set *addresses_foreign;
90 Set *static_addresses;
91 Set *neighbors;
92 Set *neighbors_foreign;
93 Set *routes;
94 Set *routes_foreign;
95 Set *nexthops;
96 Set *nexthops_foreign;
97
98 sd_dhcp_client *dhcp_client;
99 sd_dhcp_lease *dhcp_lease;
100 Address *dhcp_address, *dhcp_address_old;
101 Set *dhcp_routes, *dhcp_routes_old;
102 char *lease_file;
103 uint32_t original_mtu;
104 unsigned dhcp4_messages;
105 unsigned dhcp4_remove_messages;
106 bool dhcp4_route_failed:1;
107 bool dhcp4_route_retrying:1;
108 bool dhcp4_configured:1;
109 bool dhcp4_address_bind:1;
110
111 sd_ipv4ll *ipv4ll;
112 bool ipv4ll_address_configured:1;
113
114 bool addresses_configured:1;
115 bool addresses_ready:1;
116 bool neighbors_configured:1;
117 bool static_routes_configured:1;
118 bool static_nexthops_configured:1;
119 bool routing_policy_rules_configured:1;
120 bool tc_configured:1;
121 bool sr_iov_configured:1;
122 bool setting_mtu:1;
123 bool setting_genmode:1;
124 bool ipv6_mtu_set:1;
125
126 LIST_HEAD(Address, pool_addresses);
127
128 sd_dhcp_server *dhcp_server;
129
130 sd_ndisc *ndisc;
131 Set *ndisc_rdnss;
132 Set *ndisc_dnssl;
133 Set *ndisc_addresses, *ndisc_addresses_old;
134 Set *ndisc_routes, *ndisc_routes_old;
135 unsigned ndisc_addresses_messages;
136 unsigned ndisc_routes_messages;
137 bool ndisc_addresses_configured:1;
138 bool ndisc_routes_configured:1;
139
140 sd_radv *radv;
141
142 sd_dhcp6_client *dhcp6_client;
143 sd_dhcp6_lease *dhcp6_lease;
144 Set *dhcp6_addresses, *dhcp6_addresses_old;
145 Set *dhcp6_routes, *dhcp6_routes_old;
146 Set *dhcp6_pd_addresses, *dhcp6_pd_addresses_old;
147 Set *dhcp6_pd_routes, *dhcp6_pd_routes_old;
148 unsigned dhcp6_address_messages;
149 unsigned dhcp6_route_messages;
150 unsigned dhcp6_pd_address_messages;
151 unsigned dhcp6_pd_route_messages;
152 bool dhcp6_address_configured:1;
153 bool dhcp6_route_configured:1;
154 bool dhcp6_pd_address_configured:1;
155 bool dhcp6_pd_route_configured:1;
156 bool dhcp6_pd_prefixes_assigned:1;
157
158 /* This is about LLDP reception */
159 sd_lldp *lldp;
160 char *lldp_file;
161
162 /* This is about LLDP transmission */
163 unsigned lldp_tx_fast; /* The LLDP txFast counter (See 802.1ab-2009, section 9.2.5.18) */
164 sd_event_source *lldp_emit_event_source;
165
166 Hashmap *bound_by_links;
167 Hashmap *bound_to_links;
168 Set *slaves;
169
170 /* For speed meter */
171 struct rtnl_link_stats64 stats_old, stats_new;
172 bool stats_updated;
173
174 /* All kinds of DNS configuration the user configured via D-Bus */
175 struct in_addr_full **dns;
176 unsigned n_dns;
177 OrderedSet *search_domains, *route_domains;
178
179 int dns_default_route;
180 ResolveSupport llmnr;
181 ResolveSupport mdns;
182 DnssecMode dnssec_mode;
183 DnsOverTlsMode dns_over_tls_mode;
184 Set *dnssec_negative_trust_anchors;
185
186 /* Similar, but NTP server configuration */
187 char **ntp;
188 } Link;
189
190 typedef int (*link_netlink_message_handler_t)(sd_netlink*, sd_netlink_message*, Link*);
191
192 DUID *link_get_duid(Link *link);
193 int get_product_uuid_handler(sd_bus_message *m, void *userdata, sd_bus_error *ret_error);
194
195 void link_ntp_settings_clear(Link *link);
196 void link_dns_settings_clear(Link *link);
197 Link *link_unref(Link *link);
198 Link *link_ref(Link *link);
199 DEFINE_TRIVIAL_CLEANUP_FUNC(Link*, link_unref);
200 DEFINE_TRIVIAL_DESTRUCTOR(link_netlink_destroy_callback, Link, link_unref);
201
202 int link_get(Manager *m, int ifindex, Link **ret);
203 int link_add(Manager *manager, sd_netlink_message *message, Link **ret);
204 void link_drop(Link *link);
205
206 int link_down(Link *link, link_netlink_message_handler_t callback);
207
208 void link_enter_failed(Link *link);
209 int link_initialized(Link *link, sd_device *device);
210
211 void link_set_state(Link *link, LinkState state);
212 void link_check_ready(Link *link);
213
214 void link_update_operstate(Link *link, bool also_update_bond_master);
215 int link_update(Link *link, sd_netlink_message *message);
216
217 void link_dirty(Link *link);
218 void link_clean(Link *link);
219 int link_save(Link *link);
220 int link_save_and_clean(Link *link);
221
222 int link_carrier_reset(Link *link);
223 bool link_has_carrier(Link *link);
224
225 int link_ipv6ll_gained(Link *link, const struct in6_addr *address);
226
227 int link_set_mtu(Link *link, uint32_t mtu);
228
229 bool link_ipv4ll_enabled(Link *link, AddressFamily mask);
230
231 int link_stop_clients(Link *link, bool may_keep_dhcp);
232
233 const char* link_state_to_string(LinkState s) _const_;
234 LinkState link_state_from_string(const char *s) _pure_;
235
236 uint32_t link_get_vrf_table(Link *link);
237 uint32_t link_get_dhcp_route_table(Link *link);
238 uint32_t link_get_ipv6_accept_ra_route_table(Link *link);
239 int link_request_set_routes(Link *link);
240
241 int link_reconfigure(Link *link, bool force);
242
243 int log_link_message_full_errno(Link *link, sd_netlink_message *m, int level, int err, const char *msg);
244 #define log_link_message_error_errno(link, m, err, msg) log_link_message_full_errno(link, m, LOG_ERR, err, msg)
245 #define log_link_message_warning_errno(link, m, err, msg) log_link_message_full_errno(link, m, LOG_WARNING, err, msg)
246 #define log_link_message_notice_errno(link, m, err, msg) log_link_message_full_errno(link, m, LOG_NOTICE, err, msg)
247 #define log_link_message_info_errno(link, m, err, msg) log_link_message_full_errno(link, m, LOG_INFO, err, msg)
248 #define log_link_message_debug_errno(link, m, err, msg) log_link_message_full_errno(link, m, LOG_DEBUG, err, msg)
249
250 #define ADDRESS_FMT_VAL(address) \
251 be32toh((address).s_addr) >> 24, \
252 (be32toh((address).s_addr) >> 16) & 0xFFu, \
253 (be32toh((address).s_addr) >> 8) & 0xFFu, \
254 be32toh((address).s_addr) & 0xFFu