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