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