]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/network/networkd-network.h
5b30b8e056a4cd88f7e0f20f910541c739f599db
[thirdparty/systemd.git] / src / network / networkd-network.h
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3
4 #include <linux/nl80211.h>
5
6 #include "sd-bus.h"
7 #include "sd-device.h"
8 #include "sd-lldp-tx.h"
9
10 #include "bridge.h"
11 #include "condition.h"
12 #include "conf-parser.h"
13 #include "firewall-util.h"
14 #include "hashmap.h"
15 #include "ipoib.h"
16 #include "net-condition.h"
17 #include "netdev.h"
18 #include "networkd-address.h"
19 #include "networkd-bridge-vlan.h"
20 #include "networkd-dhcp-common.h"
21 #include "networkd-dhcp4.h"
22 #include "networkd-dhcp6.h"
23 #include "networkd-dns.h"
24 #include "networkd-ipv6ll.h"
25 #include "networkd-lldp-rx.h"
26 #include "networkd-ndisc.h"
27 #include "networkd-radv.h"
28 #include "networkd-sysctl.h"
29 #include "networkd-util.h"
30 #include "ordered-set.h"
31 #include "resolve-util.h"
32 #include "socket-netlink.h"
33
34 typedef enum KeepConfiguration {
35 KEEP_CONFIGURATION_NO = 0,
36 KEEP_CONFIGURATION_DHCP_ON_START = 1 << 0,
37 KEEP_CONFIGURATION_DHCP_ON_STOP = 1 << 1,
38 KEEP_CONFIGURATION_DHCP = KEEP_CONFIGURATION_DHCP_ON_START | KEEP_CONFIGURATION_DHCP_ON_STOP,
39 KEEP_CONFIGURATION_STATIC = 1 << 2,
40 KEEP_CONFIGURATION_YES = KEEP_CONFIGURATION_DHCP | KEEP_CONFIGURATION_STATIC,
41 _KEEP_CONFIGURATION_MAX,
42 _KEEP_CONFIGURATION_INVALID = -EINVAL,
43 } KeepConfiguration;
44
45 typedef enum ActivationPolicy {
46 ACTIVATION_POLICY_UP,
47 ACTIVATION_POLICY_ALWAYS_UP,
48 ACTIVATION_POLICY_MANUAL,
49 ACTIVATION_POLICY_ALWAYS_DOWN,
50 ACTIVATION_POLICY_DOWN,
51 ACTIVATION_POLICY_BOUND,
52 _ACTIVATION_POLICY_MAX,
53 _ACTIVATION_POLICY_INVALID = -EINVAL,
54 } ActivationPolicy;
55
56 typedef struct Manager Manager;
57
58 typedef struct NetworkDHCPServerEmitAddress {
59 bool emit;
60 struct in_addr *addresses;
61 size_t n_addresses;
62 } NetworkDHCPServerEmitAddress;
63
64 struct Network {
65 Manager *manager;
66
67 unsigned n_ref;
68
69 char *name;
70 char *filename;
71 char **dropins;
72 Hashmap *stats_by_path;
73 char *description;
74
75 /* [Match] section */
76 NetMatch match;
77 LIST_HEAD(Condition, conditions);
78
79 /* Master or stacked netdevs */
80 bool keep_master;
81 NetDev *batadv;
82 NetDev *bridge;
83 NetDev *bond;
84 NetDev *vrf;
85 NetDev *xfrm;
86 Hashmap *stacked_netdevs;
87 char *batadv_name;
88 char *bridge_name;
89 char *bond_name;
90 char *vrf_name;
91 Hashmap *stacked_netdev_names;
92
93 /* [Link] section */
94 struct hw_addr_data hw_addr;
95 uint32_t mtu;
96 int32_t group;
97 int arp;
98 int multicast;
99 int allmulticast;
100 int promiscuous;
101 bool unmanaged;
102 int required_for_online; /* Is this network required to be considered online? */
103 LinkOperationalStateRange required_operstate_for_online;
104 AddressFamily required_family_for_online;
105 ActivationPolicy activation_policy;
106
107 /* misc settings */
108 bool configure_without_carrier;
109 bool ignore_carrier_loss_set;
110 usec_t ignore_carrier_loss_usec; /* timespan */
111 KeepConfiguration keep_configuration;
112 char **bind_carrier;
113 bool default_route_on_device;
114 AddressFamily ip_masquerade;
115
116 /* DHCP Client Support */
117 AddressFamily dhcp;
118 struct in_addr dhcp_request_address;
119 DHCPClientIdentifier dhcp_client_identifier;
120 DUID dhcp_duid;
121 uint32_t dhcp_iaid;
122 bool dhcp_iaid_set;
123 char *dhcp_vendor_class_identifier;
124 char *dhcp_mudurl;
125 char **dhcp_user_class;
126 char *dhcp_hostname;
127 char *dhcp_label;
128 uint64_t dhcp_max_attempts;
129 uint32_t dhcp_route_metric;
130 bool dhcp_route_metric_set;
131 uint32_t dhcp_route_table;
132 bool dhcp_route_table_set;
133 usec_t dhcp_fallback_lease_lifetime_usec;
134 uint32_t dhcp_route_mtu;
135 uint16_t dhcp_client_port;
136 uint16_t dhcp_port;
137 int dhcp_critical;
138 int dhcp_ip_service_type;
139 int dhcp_socket_priority;
140 bool dhcp_socket_priority_set;
141 bool dhcp_anonymize;
142 bool dhcp_send_hostname;
143 bool dhcp_send_hostname_set;
144 int dhcp_broadcast;
145 int dhcp_ipv6_only_mode;
146 int dhcp_use_rapid_commit;
147 bool dhcp_use_dns;
148 bool dhcp_use_dns_set;
149 bool dhcp_routes_to_dns;
150 bool dhcp_use_ntp;
151 bool dhcp_use_ntp_set;
152 bool dhcp_routes_to_ntp;
153 bool dhcp_use_sip;
154 bool dhcp_use_captive_portal;
155 bool dhcp_use_mtu;
156 bool dhcp_use_routes;
157 int dhcp_use_gateway;
158 bool dhcp_quickack;
159 uint32_t dhcp_initial_congestion_window;
160 uint32_t dhcp_advertised_receive_window;
161 bool dhcp_use_timezone;
162 bool dhcp_use_hostname;
163 bool dhcp_use_6rd;
164 bool dhcp_send_release;
165 bool dhcp_send_decline;
166 UseDomains dhcp_use_domains;
167 bool dhcp_use_domains_set;
168 Set *dhcp_deny_listed_ip;
169 Set *dhcp_allow_listed_ip;
170 Set *dhcp_request_options;
171 OrderedHashmap *dhcp_client_send_options;
172 OrderedHashmap *dhcp_client_send_vendor_options;
173 char *dhcp_netlabel;
174 NFTSetContext dhcp_nft_set_context;
175
176 /* DHCPv6 Client support */
177 bool dhcp6_use_address;
178 bool dhcp6_use_pd_prefix;
179 bool dhcp6_send_hostname;
180 bool dhcp6_send_hostname_set;
181 bool dhcp6_use_dns;
182 bool dhcp6_use_dns_set;
183 bool dhcp6_use_hostname;
184 bool dhcp6_use_ntp;
185 bool dhcp6_use_ntp_set;
186 bool dhcp6_use_captive_portal;
187 bool dhcp6_use_rapid_commit;
188 UseDomains dhcp6_use_domains;
189 bool dhcp6_use_domains_set;
190 uint32_t dhcp6_iaid;
191 bool dhcp6_iaid_set;
192 bool dhcp6_iaid_set_explicitly;
193 DUID dhcp6_duid;
194 uint8_t dhcp6_pd_prefix_length;
195 struct in6_addr dhcp6_pd_prefix_hint;
196 char *dhcp6_hostname;
197 char *dhcp6_mudurl;
198 char **dhcp6_user_class;
199 char **dhcp6_vendor_class;
200 DHCP6ClientStartMode dhcp6_client_start_mode;
201 OrderedHashmap *dhcp6_client_send_options;
202 OrderedHashmap *dhcp6_client_send_vendor_options;
203 Set *dhcp6_request_options;
204 char *dhcp6_netlabel;
205 bool dhcp6_send_release;
206 NFTSetContext dhcp6_nft_set_context;
207
208 /* DHCP Server Support */
209 bool dhcp_server;
210 bool dhcp_server_bind_to_interface;
211 unsigned char dhcp_server_address_prefixlen;
212 struct in_addr dhcp_server_address_in_addr;
213 const Address *dhcp_server_address;
214 int dhcp_server_uplink_index;
215 char *dhcp_server_uplink_name;
216 struct in_addr dhcp_server_relay_target;
217 char *dhcp_server_relay_agent_circuit_id;
218 char *dhcp_server_relay_agent_remote_id;
219 NetworkDHCPServerEmitAddress dhcp_server_emit[_SD_DHCP_LEASE_SERVER_TYPE_MAX];
220 bool dhcp_server_emit_router;
221 struct in_addr dhcp_server_router;
222 bool dhcp_server_emit_timezone;
223 char *dhcp_server_timezone;
224 usec_t dhcp_server_default_lease_time_usec, dhcp_server_max_lease_time_usec;
225 uint32_t dhcp_server_pool_offset;
226 uint32_t dhcp_server_pool_size;
227 OrderedHashmap *dhcp_server_send_options;
228 OrderedHashmap *dhcp_server_send_vendor_options;
229 struct in_addr dhcp_server_boot_server_address;
230 char *dhcp_server_boot_server_name;
231 char *dhcp_server_boot_filename;
232 usec_t dhcp_server_ipv6_only_preferred_usec;
233 bool dhcp_server_rapid_commit;
234 int dhcp_server_persist_leases;
235
236 /* link-local addressing support */
237 AddressFamily link_local;
238 IPv6LinkLocalAddressGenMode ipv6ll_address_gen_mode;
239 struct in6_addr ipv6ll_stable_secret;
240 struct in_addr ipv4ll_start_address;
241 bool ipv4ll_route;
242
243 /* IPv6 RA support */
244 RADVPrefixDelegation router_prefix_delegation;
245 usec_t router_lifetime_usec;
246 uint8_t router_preference;
247 usec_t router_retransmit_usec;
248 uint8_t router_hop_limit;
249 bool router_managed;
250 bool router_other_information;
251 bool router_emit_dns;
252 bool router_emit_domains;
253 usec_t router_dns_lifetime_usec;
254 struct in6_addr *router_dns;
255 unsigned n_router_dns;
256 OrderedSet *router_search_domains;
257 int router_uplink_index;
258 char *router_uplink_name;
259 /* Mobile IPv6 Home Agent */
260 bool router_home_agent_information;
261 uint16_t router_home_agent_preference;
262 usec_t home_agent_lifetime_usec;
263
264 /* DHCP Prefix Delegation support */
265 int dhcp_pd;
266 bool dhcp_pd_announce;
267 bool dhcp_pd_assign;
268 bool dhcp_pd_manage_temporary_address;
269 int64_t dhcp_pd_subnet_id;
270 uint32_t dhcp_pd_route_metric;
271 Set *dhcp_pd_tokens;
272 int dhcp_pd_uplink_index;
273 char *dhcp_pd_uplink_name;
274 char *dhcp_pd_netlabel;
275 NFTSetContext dhcp_pd_nft_set_context;
276
277 /* Bridge Support */
278 int use_bpdu;
279 int hairpin;
280 int isolated;
281 int fast_leave;
282 int allow_port_to_be_root;
283 int unicast_flood;
284 int multicast_flood;
285 int multicast_to_unicast;
286 int neighbor_suppression;
287 int learning;
288 int bridge_proxy_arp;
289 int bridge_proxy_arp_wifi;
290 uint32_t cost;
291 uint16_t priority;
292 MulticastRouter multicast_router;
293
294 /* Bridge VLAN */
295 uint16_t bridge_vlan_pvid;
296 uint32_t bridge_vlan_bitmap[BRIDGE_VLAN_BITMAP_LEN];
297 uint32_t bridge_vlan_untagged_bitmap[BRIDGE_VLAN_BITMAP_LEN];
298
299 /* CAN support */
300 uint32_t can_bitrate;
301 unsigned can_sample_point;
302 nsec_t can_time_quanta_ns;
303 uint32_t can_propagation_segment;
304 uint32_t can_phase_buffer_segment_1;
305 uint32_t can_phase_buffer_segment_2;
306 uint32_t can_sync_jump_width;
307 uint32_t can_data_bitrate;
308 unsigned can_data_sample_point;
309 nsec_t can_data_time_quanta_ns;
310 uint32_t can_data_propagation_segment;
311 uint32_t can_data_phase_buffer_segment_1;
312 uint32_t can_data_phase_buffer_segment_2;
313 uint32_t can_data_sync_jump_width;
314 usec_t can_restart_us;
315 uint32_t can_control_mode_mask;
316 uint32_t can_control_mode_flags;
317 uint16_t can_termination;
318 bool can_termination_set;
319
320 /* IPoIB support */
321 IPoIBMode ipoib_mode;
322 int ipoib_umcast;
323
324 /* sysctl settings */
325 int ip_forwarding[2];
326 int ipv4_accept_local;
327 int ipv4_route_localnet;
328 int ipv6_dad_transmits;
329 uint8_t ipv6_hop_limit;
330 usec_t ipv6_retransmission_time;
331 int proxy_arp;
332 int proxy_arp_pvlan;
333 uint32_t ipv6_mtu;
334 IPv6PrivacyExtensions ipv6_privacy_extensions;
335 IPReversePathFilter ipv4_rp_filter;
336 int ipv6_proxy_ndp;
337 Set *ipv6_proxy_ndp_addresses;
338
339 /* NDisc support */
340 int ndisc;
341 bool ndisc_use_redirect;
342 bool ndisc_use_dns;
343 bool ndisc_use_gateway;
344 bool ndisc_use_route_prefix;
345 bool ndisc_use_autonomous_prefix;
346 bool ndisc_use_onlink_prefix;
347 bool ndisc_use_mtu;
348 bool ndisc_use_hop_limit;
349 bool ndisc_use_reachable_time;
350 bool ndisc_use_retransmission_time;
351 bool ndisc_quickack;
352 bool ndisc_use_captive_portal;
353 bool ndisc_use_pref64;
354 bool active_slave;
355 bool primary_slave;
356 UseDomains ndisc_use_domains;
357 IPv6AcceptRAStartDHCP6Client ndisc_start_dhcp6_client;
358 uint32_t ndisc_route_table;
359 bool ndisc_route_table_set;
360 uint32_t ndisc_route_metric_high;
361 uint32_t ndisc_route_metric_medium;
362 uint32_t ndisc_route_metric_low;
363 bool ndisc_route_metric_set;
364 Set *ndisc_deny_listed_router;
365 Set *ndisc_allow_listed_router;
366 Set *ndisc_deny_listed_prefix;
367 Set *ndisc_allow_listed_prefix;
368 Set *ndisc_deny_listed_route_prefix;
369 Set *ndisc_allow_listed_route_prefix;
370 Set *ndisc_tokens;
371 char *ndisc_netlabel;
372 NFTSetContext ndisc_nft_set_context;
373
374 /* LLDP support */
375 LLDPMode lldp_mode; /* LLDP reception */
376 sd_lldp_multicast_mode_t lldp_multicast_mode; /* LLDP transmission */
377 char *lldp_mudurl; /* LLDP MUD URL */
378
379 OrderedHashmap *addresses_by_section;
380 Hashmap *routes_by_section;
381 OrderedHashmap *nexthops_by_section;
382 Hashmap *bridge_fdb_entries_by_section;
383 Hashmap *bridge_mdb_entries_by_section;
384 OrderedHashmap *neighbors_by_section;
385 Hashmap *address_labels_by_section;
386 Hashmap *prefixes_by_section;
387 Hashmap *route_prefixes_by_section;
388 Hashmap *pref64_prefixes_by_section;
389 Hashmap *rules_by_section;
390 Hashmap *dhcp_static_leases_by_section;
391 Hashmap *qdiscs_by_section;
392 Hashmap *tclasses_by_section;
393 OrderedHashmap *sr_iov_by_section;
394
395 /* All kinds of DNS configuration */
396 struct in_addr_full **dns;
397 unsigned n_dns;
398 OrderedSet *search_domains, *route_domains;
399 int dns_default_route;
400 ResolveSupport llmnr;
401 ResolveSupport mdns;
402 DnssecMode dnssec_mode;
403 DnsOverTlsMode dns_over_tls_mode;
404 Set *dnssec_negative_trust_anchors;
405
406 /* NTP */
407 char **ntp;
408 };
409
410 Network *network_ref(Network *network);
411 Network *network_unref(Network *network);
412 DEFINE_TRIVIAL_CLEANUP_FUNC(Network*, network_unref);
413
414 int network_load(Manager *manager, OrderedHashmap **networks);
415 int network_reload(Manager *manager);
416 int network_load_one(Manager *manager, OrderedHashmap **networks, const char *filename);
417 int network_verify(Network *network);
418
419 int manager_build_dhcp_pd_subnet_ids(Manager *manager);
420
421 int network_get_by_name(Manager *manager, const char *name, Network **ret);
422 void network_apply_anonymize_if_set(Network *network);
423
424 bool network_has_static_ipv6_configurations(Network *network);
425
426 CONFIG_PARSER_PROTOTYPE(config_parse_stacked_netdev);
427 CONFIG_PARSER_PROTOTYPE(config_parse_tunnel);
428 CONFIG_PARSER_PROTOTYPE(config_parse_timezone);
429 CONFIG_PARSER_PROTOTYPE(config_parse_ntp);
430 CONFIG_PARSER_PROTOTYPE(config_parse_required_for_online);
431 CONFIG_PARSER_PROTOTYPE(config_parse_required_family_for_online);
432 CONFIG_PARSER_PROTOTYPE(config_parse_keep_configuration);
433 CONFIG_PARSER_PROTOTYPE(config_parse_activation_policy);
434 CONFIG_PARSER_PROTOTYPE(config_parse_link_group);
435 CONFIG_PARSER_PROTOTYPE(config_parse_ignore_carrier_loss);
436
437 const struct ConfigPerfItem* network_network_gperf_lookup(const char *key, GPERF_LEN_TYPE length);
438
439 const char* keep_configuration_to_string(KeepConfiguration i) _const_;
440 KeepConfiguration keep_configuration_from_string(const char *s) _pure_;
441
442 const char* activation_policy_to_string(ActivationPolicy i) _const_;
443 ActivationPolicy activation_policy_from_string(const char *s) _pure_;