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