Debian Codegraph @

src/network/networkd-network.h

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