]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/network/networkd-network.h
Merge pull request #12753 from jrouleau/fix/hibernate-resume-timeout
[thirdparty/systemd.git] / src / network / networkd-network.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 #pragma once
3
4 #include "sd-bus.h"
5 #include "sd-device.h"
6
7 #include "condition.h"
8 #include "conf-parser.h"
9 #include "dhcp-identifier.h"
10 #include "hashmap.h"
11 #include "netdev/bridge.h"
12 #include "netdev/netdev.h"
13 #include "networkd-address-label.h"
14 #include "networkd-address.h"
15 #include "networkd-brvlan.h"
16 #include "networkd-fdb.h"
17 #include "networkd-ipv6-proxy-ndp.h"
18 #include "networkd-lldp-rx.h"
19 #include "networkd-lldp-tx.h"
20 #include "networkd-neighbor.h"
21 #include "networkd-radv.h"
22 #include "networkd-route.h"
23 #include "networkd-routing-policy-rule.h"
24 #include "networkd-util.h"
25 #include "ordered-set.h"
26 #include "resolve-util.h"
27
28 #define DHCP_ROUTE_METRIC 1024
29 #define IPV4LL_ROUTE_METRIC 2048
30
31 #define BRIDGE_VLAN_BITMAP_MAX 4096
32 #define BRIDGE_VLAN_BITMAP_LEN (BRIDGE_VLAN_BITMAP_MAX / 32)
33
34 typedef enum DHCPClientIdentifier {
35 DHCP_CLIENT_ID_MAC,
36 DHCP_CLIENT_ID_DUID,
37 /* The following option may not be good for RFC regarding DHCP (3315 and 4361).
38 * But some setups require this. E.g., Sky Broadband, the second largest provider in the UK
39 * requires the client id to be set to a custom string, reported at
40 * https://github.com/systemd/systemd/issues/7828 */
41 DHCP_CLIENT_ID_DUID_ONLY,
42 _DHCP_CLIENT_ID_MAX,
43 _DHCP_CLIENT_ID_INVALID = -1,
44 } DHCPClientIdentifier;
45
46 typedef enum IPv6PrivacyExtensions {
47 /* The values map to the kernel's /proc/sys/net/ipv6/conf/xxx/use_tempaddr values */
48 IPV6_PRIVACY_EXTENSIONS_NO,
49 IPV6_PRIVACY_EXTENSIONS_PREFER_PUBLIC,
50 IPV6_PRIVACY_EXTENSIONS_YES, /* aka prefer-temporary */
51 _IPV6_PRIVACY_EXTENSIONS_MAX,
52 _IPV6_PRIVACY_EXTENSIONS_INVALID = -1,
53 } IPv6PrivacyExtensions;
54
55 typedef enum DHCPUseDomains {
56 DHCP_USE_DOMAINS_NO,
57 DHCP_USE_DOMAINS_YES,
58 DHCP_USE_DOMAINS_ROUTE,
59 _DHCP_USE_DOMAINS_MAX,
60 _DHCP_USE_DOMAINS_INVALID = -1,
61 } DHCPUseDomains;
62
63 typedef struct DUID {
64 /* Value of Type in [DHCP] section */
65 DUIDType type;
66
67 uint8_t raw_data_len;
68 uint8_t raw_data[MAX_DUID_LEN];
69 usec_t llt_time;
70 } DUID;
71
72 typedef enum RADVPrefixDelegation {
73 RADV_PREFIX_DELEGATION_NONE,
74 RADV_PREFIX_DELEGATION_STATIC,
75 RADV_PREFIX_DELEGATION_DHCP6,
76 RADV_PREFIX_DELEGATION_BOTH,
77 _RADV_PREFIX_DELEGATION_MAX,
78 _RADV_PREFIX_DELEGATION_INVALID = -1,
79 } RADVPrefixDelegation;
80
81 typedef enum KeepConfiguration {
82 KEEP_CONFIGURATION_NO = 0,
83 KEEP_CONFIGURATION_DHCP_ON_START = 1 << 0,
84 KEEP_CONFIGURATION_DHCP_ON_STOP = 1 << 1,
85 KEEP_CONFIGURATION_DHCP = KEEP_CONFIGURATION_DHCP_ON_START | KEEP_CONFIGURATION_DHCP_ON_STOP,
86 KEEP_CONFIGURATION_STATIC = 1 << 2,
87 KEEP_CONFIGURATION_YES = KEEP_CONFIGURATION_DHCP | KEEP_CONFIGURATION_STATIC,
88 _KEEP_CONFIGURATION_MAX,
89 _KEEP_CONFIGURATION_INVALID = -1,
90 } KeepConfiguration;
91
92 typedef struct Manager Manager;
93
94 struct Network {
95 Manager *manager;
96
97 char *filename;
98 char *name;
99
100 unsigned n_ref;
101
102 Set *match_mac;
103 char **match_path;
104 char **match_driver;
105 char **match_type;
106 char **match_name;
107 LIST_HEAD(Condition, conditions);
108
109 char *description;
110
111 NetDev *bridge;
112 NetDev *bond;
113 NetDev *vrf;
114 Hashmap *stacked_netdevs;
115 char *bridge_name;
116 char *bond_name;
117 char *vrf_name;
118 Hashmap *stacked_netdev_names;
119
120 /* DHCP Client Support */
121 AddressFamilyBoolean dhcp;
122 DHCPClientIdentifier dhcp_client_identifier;
123 char *dhcp_vendor_class_identifier;
124 char **dhcp_user_class;
125 char *dhcp_hostname;
126 uint64_t dhcp_max_attempts;
127 unsigned dhcp_route_metric;
128 uint32_t dhcp_route_table;
129 uint16_t dhcp_client_port;
130 bool dhcp_anonymize;
131 bool dhcp_send_hostname;
132 bool dhcp_broadcast;
133 int dhcp_critical;
134 bool dhcp_use_dns;
135 bool dhcp_use_ntp;
136 bool dhcp_use_mtu;
137 bool dhcp_use_routes;
138 bool dhcp_use_timezone;
139 bool rapid_commit;
140 bool dhcp_use_hostname;
141 bool dhcp_route_table_set;
142 bool dhcp_send_release;
143 DHCPUseDomains dhcp_use_domains;
144 Set *dhcp_black_listed_ip;
145
146 /* DHCP Server Support */
147 bool dhcp_server;
148 bool dhcp_server_emit_dns;
149 struct in_addr *dhcp_server_dns;
150 unsigned n_dhcp_server_dns;
151 bool dhcp_server_emit_ntp;
152 struct in_addr *dhcp_server_ntp;
153 unsigned n_dhcp_server_ntp;
154 bool dhcp_server_emit_router;
155 bool dhcp_server_emit_timezone;
156 char *dhcp_server_timezone;
157 usec_t dhcp_server_default_lease_time_usec, dhcp_server_max_lease_time_usec;
158 uint32_t dhcp_server_pool_offset;
159 uint32_t dhcp_server_pool_size;
160
161 /* IPV4LL Support */
162 AddressFamilyBoolean link_local;
163 bool ipv4ll_route;
164
165 bool default_route_on_device;
166
167 /* IPv6 prefix delegation support */
168 RADVPrefixDelegation router_prefix_delegation;
169 usec_t router_lifetime_usec;
170 uint8_t router_preference;
171 bool router_managed;
172 bool router_other_information;
173 bool router_emit_dns;
174 bool router_emit_domains;
175 usec_t router_dns_lifetime_usec;
176 struct in6_addr *router_dns;
177 unsigned n_router_dns;
178 OrderedSet *router_search_domains;
179 bool dhcp6_force_pd_other_information; /* Start DHCPv6 PD also when 'O'
180 RA flag is set, see RFC 7084,
181 WPD-4 */
182
183 /* Bridge Support */
184 int use_bpdu;
185 int hairpin;
186 int fast_leave;
187 int allow_port_to_be_root;
188 int unicast_flood;
189 int multicast_flood;
190 int multicast_to_unicast;
191 int neighbor_suppression;
192 int learning;
193 int bridge_proxy_arp;
194 int bridge_proxy_arp_wifi;
195 uint32_t cost;
196 uint16_t priority;
197 MulticastRouter multicast_router;
198
199 bool use_br_vlan;
200 uint16_t pvid;
201 uint32_t br_vid_bitmap[BRIDGE_VLAN_BITMAP_LEN];
202 uint32_t br_untagged_bitmap[BRIDGE_VLAN_BITMAP_LEN];
203
204 /* CAN support */
205 size_t can_bitrate;
206 unsigned can_sample_point;
207 usec_t can_restart_us;
208 int can_triple_sampling;
209
210 AddressFamilyBoolean ip_forward;
211 bool ip_masquerade;
212
213 int ipv6_accept_ra;
214 int ipv6_dad_transmits;
215 int ipv6_hop_limit;
216 int ipv6_proxy_ndp;
217 int proxy_arp;
218 uint32_t ipv6_mtu;
219
220 bool ipv6_accept_ra_use_dns;
221 bool ipv6_accept_ra_use_autonomous_prefix;
222 bool ipv6_accept_ra_use_onlink_prefix;
223 bool active_slave;
224 bool primary_slave;
225 DHCPUseDomains ipv6_accept_ra_use_domains;
226 uint32_t ipv6_accept_ra_route_table;
227 bool ipv6_accept_ra_route_table_set;
228 Set *ndisc_black_listed_prefix;
229
230 union in_addr_union ipv6_token;
231 IPv6PrivacyExtensions ipv6_privacy_extensions;
232
233 struct ether_addr *mac;
234 uint32_t mtu;
235 int arp;
236 int multicast;
237 int allmulticast;
238 bool unmanaged;
239 bool configure_without_carrier;
240 bool ignore_carrier_loss;
241 KeepConfiguration keep_configuration;
242 uint32_t iaid;
243 DUID duid;
244
245 bool iaid_set;
246
247 bool required_for_online; /* Is this network required to be considered online? */
248 LinkOperationalState required_operstate_for_online;
249
250 LLDPMode lldp_mode; /* LLDP reception */
251 LLDPEmit lldp_emit; /* LLDP transmission */
252
253 LIST_HEAD(Address, static_addresses);
254 LIST_HEAD(Route, static_routes);
255 LIST_HEAD(FdbEntry, static_fdb_entries);
256 LIST_HEAD(IPv6ProxyNDPAddress, ipv6_proxy_ndp_addresses);
257 LIST_HEAD(Neighbor, neighbors);
258 LIST_HEAD(AddressLabel, address_labels);
259 LIST_HEAD(Prefix, static_prefixes);
260 LIST_HEAD(RoutingPolicyRule, rules);
261
262 unsigned n_static_addresses;
263 unsigned n_static_routes;
264 unsigned n_static_fdb_entries;
265 unsigned n_ipv6_proxy_ndp_addresses;
266 unsigned n_neighbors;
267 unsigned n_address_labels;
268 unsigned n_static_prefixes;
269 unsigned n_rules;
270
271 Hashmap *addresses_by_section;
272 Hashmap *routes_by_section;
273 Hashmap *fdb_entries_by_section;
274 Hashmap *neighbors_by_section;
275 Hashmap *address_labels_by_section;
276 Hashmap *prefixes_by_section;
277 Hashmap *rules_by_section;
278
279 /* All kinds of DNS configuration */
280 struct in_addr_data *dns;
281 unsigned n_dns;
282 OrderedSet *search_domains, *route_domains;
283
284 int dns_default_route;
285 ResolveSupport llmnr;
286 ResolveSupport mdns;
287 DnssecMode dnssec_mode;
288 DnsOverTlsMode dns_over_tls_mode;
289 Set *dnssec_negative_trust_anchors;
290
291 char **ntp;
292 char **bind_carrier;
293 };
294
295 Network *network_ref(Network *network);
296 Network *network_unref(Network *network);
297 DEFINE_TRIVIAL_CLEANUP_FUNC(Network*, network_unref);
298
299 int network_load(Manager *manager);
300 int network_load_one(Manager *manager, const char *filename);
301 int network_verify(Network *network);
302
303 int network_get_by_name(Manager *manager, const char *name, Network **ret);
304 int network_get(Manager *manager, sd_device *device, const char *ifname, const struct ether_addr *mac, Network **ret);
305 int network_apply(Network *network, Link *link);
306 void network_apply_anonymize_if_set(Network *network);
307
308 bool network_has_static_ipv6_addresses(Network *network);
309
310 CONFIG_PARSER_PROTOTYPE(config_parse_stacked_netdev);
311 CONFIG_PARSER_PROTOTYPE(config_parse_domains);
312 CONFIG_PARSER_PROTOTYPE(config_parse_tunnel);
313 CONFIG_PARSER_PROTOTYPE(config_parse_dhcp);
314 CONFIG_PARSER_PROTOTYPE(config_parse_dns);
315 CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_client_identifier);
316 CONFIG_PARSER_PROTOTYPE(config_parse_ipv6token);
317 CONFIG_PARSER_PROTOTYPE(config_parse_ipv6_privacy_extensions);
318 CONFIG_PARSER_PROTOTYPE(config_parse_hostname);
319 CONFIG_PARSER_PROTOTYPE(config_parse_timezone);
320 CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_server_dns);
321 CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_black_listed_ip_address);
322 CONFIG_PARSER_PROTOTYPE(config_parse_radv_dns);
323 CONFIG_PARSER_PROTOTYPE(config_parse_radv_search_domains);
324 CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_server_ntp);
325 CONFIG_PARSER_PROTOTYPE(config_parse_dnssec_negative_trust_anchors);
326 CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_use_domains);
327 CONFIG_PARSER_PROTOTYPE(config_parse_section_route_table);
328 CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_user_class);
329 CONFIG_PARSER_PROTOTYPE(config_parse_ntp);
330 CONFIG_PARSER_PROTOTYPE(config_parse_iaid);
331 CONFIG_PARSER_PROTOTYPE(config_parse_required_for_online);
332 CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_max_attempts);
333 CONFIG_PARSER_PROTOTYPE(config_parse_keep_configuration);
334 /* Legacy IPv4LL support */
335 CONFIG_PARSER_PROTOTYPE(config_parse_ipv4ll);
336
337 const struct ConfigPerfItem* network_network_gperf_lookup(const char *key, GPERF_LEN_TYPE length);
338
339 extern const sd_bus_vtable network_vtable[];
340
341 int network_node_enumerator(sd_bus *bus, const char *path, void *userdata, char ***nodes, sd_bus_error *error);
342 int network_object_find(sd_bus *bus, const char *path, const char *interface, void *userdata, void **found, sd_bus_error *error);
343
344 const char* ipv6_privacy_extensions_to_string(IPv6PrivacyExtensions i) _const_;
345 IPv6PrivacyExtensions ipv6_privacy_extensions_from_string(const char *s) _pure_;
346
347 const char* dhcp_use_domains_to_string(DHCPUseDomains p) _const_;
348 DHCPUseDomains dhcp_use_domains_from_string(const char *s) _pure_;
349
350 const char* radv_prefix_delegation_to_string(RADVPrefixDelegation i) _const_;
351 RADVPrefixDelegation radv_prefix_delegation_from_string(const char *s) _pure_;
352
353 const char* keep_configuration_to_string(KeepConfiguration i) _const_;
354 KeepConfiguration keep_configuration_from_string(const char *s) _pure_;