1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
4 #include "sd-dhcp-lease.h"
5 #include "sd-lldp-tx.h"
8 #include "firewall-util.h"
10 #include "net-condition.h"
11 #include "network-util.h"
12 #include "networkd-bridge-vlan.h"
13 #include "networkd-dhcp-common.h"
14 #include "networkd-dhcp-server.h"
15 #include "networkd-dhcp4.h"
16 #include "networkd-dhcp6.h"
17 #include "networkd-dns.h"
18 #include "networkd-forward.h"
19 #include "networkd-ipv6ll.h"
20 #include "networkd-lldp-rx.h"
21 #include "networkd-ndisc.h"
22 #include "networkd-radv.h"
23 #include "networkd-sysctl.h"
24 #include "resolve-util.h"
26 typedef enum KeepConfiguration
{
27 KEEP_CONFIGURATION_NO
= 0,
28 KEEP_CONFIGURATION_DYNAMIC_ON_START
= 1 << 0,
29 KEEP_CONFIGURATION_DYNAMIC_ON_STOP
= 1 << 1,
30 KEEP_CONFIGURATION_DYNAMIC
= KEEP_CONFIGURATION_DYNAMIC_ON_START
| KEEP_CONFIGURATION_DYNAMIC_ON_STOP
,
31 KEEP_CONFIGURATION_STATIC
= 1 << 2,
32 KEEP_CONFIGURATION_YES
= KEEP_CONFIGURATION_DYNAMIC
| KEEP_CONFIGURATION_STATIC
,
33 _KEEP_CONFIGURATION_MAX
,
34 _KEEP_CONFIGURATION_INVALID
= -EINVAL
,
37 typedef enum ActivationPolicy
{
39 ACTIVATION_POLICY_ALWAYS_UP
,
40 ACTIVATION_POLICY_MANUAL
,
41 ACTIVATION_POLICY_ALWAYS_DOWN
,
42 ACTIVATION_POLICY_DOWN
,
43 ACTIVATION_POLICY_BOUND
,
44 _ACTIVATION_POLICY_MAX
,
45 _ACTIVATION_POLICY_INVALID
= -EINVAL
,
48 typedef struct NetworkDHCPServerEmitAddress
{
50 struct in_addr
*addresses
;
52 } NetworkDHCPServerEmitAddress
;
54 typedef struct Network
{
62 Hashmap
*stats_by_path
;
67 LIST_HEAD(Condition
, conditions
);
69 /* Master or stacked netdevs */
76 Hashmap
*stacked_netdevs
;
81 Hashmap
*stacked_netdev_names
;
84 struct hw_addr_data hw_addr
;
92 int required_for_online
; /* Is this network required to be considered online? */
93 LinkOperationalStateRange required_operstate_for_online
;
94 AddressFamily required_family_for_online
;
95 ActivationPolicy activation_policy
;
98 bool configure_without_carrier
;
99 bool ignore_carrier_loss_set
;
100 usec_t ignore_carrier_loss_usec
; /* timespan */
101 KeepConfiguration keep_configuration
;
103 bool default_route_on_device
;
104 AddressFamily ip_masquerade
;
105 usec_t ipv4_dad_timeout_usec
;
107 /* Protocol independent settings */
108 UseDomains use_domains
;
110 /* For backward compatibility, only applied to DHCPv4 and DHCPv6. */
111 UseDomains compat_dhcp_use_domains
;
112 int compat_dhcp_use_dns
;
113 int compat_dhcp_use_ntp
;
115 /* DHCP Client Support */
117 struct in_addr dhcp_request_address
;
119 DHCPClientIdentifier dhcp_client_identifier
;
123 char *dhcp_vendor_class_identifier
;
125 char **dhcp_user_class
;
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
;
138 int dhcp_ip_service_type
;
139 int dhcp_socket_priority
;
140 bool dhcp_socket_priority_set
;
142 bool dhcp_send_hostname
;
143 bool dhcp_send_hostname_set
;
145 int dhcp_ipv6_only_mode
;
146 int dhcp_use_rapid_commit
;
149 bool dhcp_routes_to_dns
;
151 bool dhcp_routes_to_ntp
;
153 bool dhcp_use_captive_portal
;
155 bool dhcp_use_routes
;
156 int dhcp_use_gateway
;
158 uint32_t dhcp_initial_congestion_window
;
159 uint32_t dhcp_advertised_receive_window
;
160 bool dhcp_use_timezone
;
161 bool dhcp_use_hostname
;
163 uint8_t dhcp_6rd_prefix_route_type
;
164 bool dhcp_send_release
;
165 bool dhcp_send_decline
;
166 UseDomains dhcp_use_domains
;
167 Set
*dhcp_deny_listed_ip
;
168 Set
*dhcp_allow_listed_ip
;
169 Set
*dhcp_request_options
;
170 OrderedHashmap
*dhcp_client_send_options
;
171 OrderedHashmap
*dhcp_client_send_vendor_options
;
173 NFTSetContext dhcp_nft_set_context
;
175 /* DHCPv6 Client support */
176 bool dhcp6_use_address
;
177 bool dhcp6_use_pd_prefix
;
178 bool dhcp6_send_hostname
;
179 bool dhcp6_send_hostname_set
;
182 bool dhcp6_use_hostname
;
184 bool dhcp6_use_captive_portal
;
185 bool dhcp6_use_rapid_commit
;
186 UseDomains dhcp6_use_domains
;
189 bool dhcp6_iaid_set_explicitly
;
191 uint8_t dhcp6_pd_prefix_length
;
192 struct in6_addr dhcp6_pd_prefix_hint
;
193 uint8_t dhcp6_pd_prefix_route_type
;
194 char *dhcp6_hostname
;
196 char **dhcp6_user_class
;
197 char **dhcp6_vendor_class
;
198 DHCP6ClientStartMode dhcp6_client_start_mode
;
199 OrderedHashmap
*dhcp6_client_send_options
;
200 OrderedHashmap
*dhcp6_client_send_vendor_options
;
201 Set
*dhcp6_request_options
;
202 char *dhcp6_netlabel
;
203 bool dhcp6_send_release
;
204 NFTSetContext dhcp6_nft_set_context
;
206 /* DHCP Server Support */
208 bool dhcp_server_bind_to_interface
;
209 unsigned char dhcp_server_address_prefixlen
;
210 struct in_addr dhcp_server_address_in_addr
;
211 const Address
*dhcp_server_address
;
212 int dhcp_server_uplink_index
;
213 char *dhcp_server_uplink_name
;
214 struct in_addr dhcp_server_relay_target
;
215 char *dhcp_server_relay_agent_circuit_id
;
216 char *dhcp_server_relay_agent_remote_id
;
217 NetworkDHCPServerEmitAddress dhcp_server_emit
[_SD_DHCP_LEASE_SERVER_TYPE_MAX
];
218 bool dhcp_server_emit_router
;
219 struct in_addr dhcp_server_router
;
220 bool dhcp_server_emit_timezone
;
221 char *dhcp_server_timezone
;
222 usec_t dhcp_server_default_lease_time_usec
, dhcp_server_max_lease_time_usec
;
223 uint32_t dhcp_server_pool_offset
;
224 uint32_t dhcp_server_pool_size
;
225 OrderedHashmap
*dhcp_server_send_options
;
226 OrderedHashmap
*dhcp_server_send_vendor_options
;
227 struct in_addr dhcp_server_boot_server_address
;
228 char *dhcp_server_boot_server_name
;
229 char *dhcp_server_boot_filename
;
230 usec_t dhcp_server_ipv6_only_preferred_usec
;
231 bool dhcp_server_rapid_commit
;
232 DHCPServerPersistLeases dhcp_server_persist_leases
;
234 /* link-local addressing support */
235 AddressFamily link_local
;
236 IPv6LinkLocalAddressGenMode ipv6ll_address_gen_mode
;
237 struct in6_addr ipv6ll_stable_secret
;
238 struct in_addr ipv4ll_start_address
;
241 /* IPv6 RA support */
242 RADVPrefixDelegation router_prefix_delegation
;
243 usec_t router_lifetime_usec
;
244 uint8_t router_preference
;
245 usec_t router_reachable_usec
;
246 usec_t router_retransmit_usec
;
247 uint8_t router_hop_limit
;
249 bool router_other_information
;
250 bool router_emit_dns
;
251 bool router_emit_domains
;
252 usec_t router_dns_lifetime_usec
;
253 struct in6_addr
*router_dns
;
254 unsigned n_router_dns
;
255 OrderedSet
*router_search_domains
;
256 int router_uplink_index
;
257 char *router_uplink_name
;
258 /* Mobile IPv6 Home Agent */
259 bool router_home_agent_information
;
260 uint16_t router_home_agent_preference
;
261 usec_t home_agent_lifetime_usec
;
263 /* DHCP Prefix Delegation support */
265 bool dhcp_pd_announce
;
267 bool dhcp_pd_manage_temporary_address
;
268 int64_t dhcp_pd_subnet_id
;
269 uint32_t dhcp_pd_route_metric
;
271 int dhcp_pd_uplink_index
;
272 char *dhcp_pd_uplink_name
;
273 char *dhcp_pd_netlabel
;
274 NFTSetContext dhcp_pd_nft_set_context
;
281 int allow_port_to_be_root
;
284 int multicast_to_unicast
;
285 int neighbor_suppression
;
287 int bridge_proxy_arp
;
288 int bridge_proxy_arp_wifi
;
291 MulticastRouter multicast_router
;
293 int bridge_mac_authentication_bypass
;
294 int bridge_vlan_tunnel
;
297 uint16_t bridge_vlan_pvid
;
298 uint32_t bridge_vlan_bitmap
[BRIDGE_VLAN_BITMAP_LEN
];
299 uint32_t bridge_vlan_untagged_bitmap
[BRIDGE_VLAN_BITMAP_LEN
];
302 uint32_t can_bitrate
;
303 unsigned can_sample_point
;
304 nsec_t can_time_quanta_ns
;
305 uint32_t can_propagation_segment
;
306 uint32_t can_phase_buffer_segment_1
;
307 uint32_t can_phase_buffer_segment_2
;
308 uint32_t can_sync_jump_width
;
309 uint32_t can_data_bitrate
;
310 unsigned can_data_sample_point
;
311 nsec_t can_data_time_quanta_ns
;
312 uint32_t can_data_propagation_segment
;
313 uint32_t can_data_phase_buffer_segment_1
;
314 uint32_t can_data_phase_buffer_segment_2
;
315 uint32_t can_data_sync_jump_width
;
316 usec_t can_restart_us
;
317 uint32_t can_control_mode_mask
;
318 uint32_t can_control_mode_flags
;
319 uint16_t can_termination
;
320 bool can_termination_set
;
323 IPoIBMode ipoib_mode
;
326 /* sysctl settings */
327 int ip_forwarding
[2];
328 int ipv4_accept_local
;
329 int ipv4_route_localnet
;
330 int ipv6_dad_transmits
;
331 uint8_t ipv6_hop_limit
;
332 usec_t ipv6_retransmission_time
;
336 IPv6PrivacyExtensions ipv6_privacy_extensions
;
337 IPReversePathFilter ipv4_rp_filter
;
338 IPv4ForceIgmpVersion ipv4_force_igmp_version
;
340 Set
*ipv6_proxy_ndp_addresses
;
346 bool ndisc_use_redirect
;
348 bool ndisc_use_gateway
;
349 bool ndisc_use_route_prefix
;
350 bool ndisc_use_autonomous_prefix
;
351 bool ndisc_use_onlink_prefix
;
353 bool ndisc_use_hop_limit
;
354 bool ndisc_use_reachable_time
;
355 bool ndisc_use_retransmission_time
;
357 bool ndisc_use_captive_portal
;
358 bool ndisc_use_pref64
;
361 UseDomains ndisc_use_domains
;
362 IPv6AcceptRAStartDHCP6Client ndisc_start_dhcp6_client
;
363 uint32_t ndisc_route_table
;
364 bool ndisc_route_table_set
;
365 uint32_t ndisc_route_metric_high
;
366 uint32_t ndisc_route_metric_medium
;
367 uint32_t ndisc_route_metric_low
;
368 bool ndisc_route_metric_set
;
369 Set
*ndisc_deny_listed_router
;
370 Set
*ndisc_allow_listed_router
;
371 Set
*ndisc_deny_listed_prefix
;
372 Set
*ndisc_allow_listed_prefix
;
373 Set
*ndisc_deny_listed_route_prefix
;
374 Set
*ndisc_allow_listed_route_prefix
;
376 char *ndisc_netlabel
;
377 NFTSetContext ndisc_nft_set_context
;
380 LLDPMode lldp_mode
; /* LLDP reception */
381 sd_lldp_multicast_mode_t lldp_multicast_mode
; /* LLDP transmission */
382 char *lldp_mudurl
; /* LLDP MUD URL */
384 OrderedHashmap
*addresses_by_section
;
385 Hashmap
*routes_by_section
;
386 OrderedHashmap
*nexthops_by_section
;
387 Hashmap
*bridge_fdb_entries_by_section
;
388 Hashmap
*bridge_mdb_entries_by_section
;
389 OrderedHashmap
*neighbors_by_section
;
390 Hashmap
*address_labels_by_section
;
391 Hashmap
*prefixes_by_section
;
392 Hashmap
*route_prefixes_by_section
;
393 Hashmap
*pref64_prefixes_by_section
;
394 Hashmap
*rules_by_section
;
395 Hashmap
*dhcp_static_leases_by_section
;
396 Hashmap
*qdiscs_by_section
;
397 Hashmap
*tclasses_by_section
;
398 OrderedHashmap
*sr_iov_by_section
;
400 /* All kinds of DNS configuration */
401 struct in_addr_full
**dns
;
403 OrderedSet
*search_domains
, *route_domains
;
404 int dns_default_route
;
405 ResolveSupport llmnr
;
407 DnssecMode dnssec_mode
;
408 DnsOverTlsMode dns_over_tls_mode
;
409 Set
*dnssec_negative_trust_anchors
;
415 Network
*network_ref(Network
*network
);
416 Network
*network_unref(Network
*network
);
417 DEFINE_TRIVIAL_CLEANUP_FUNC(Network
*, network_unref
);
419 int network_load(Manager
*manager
, OrderedHashmap
**ret
);
420 int network_reload(Manager
*manager
);
421 int network_load_one(Manager
*manager
, OrderedHashmap
**networks
, const char *filename
);
422 int network_verify(Network
*network
);
424 int manager_build_dhcp_pd_subnet_ids(Manager
*manager
);
426 int network_get_by_name(Manager
*manager
, const char *name
, Network
**ret
);
427 void network_apply_anonymize_if_set(Network
*network
);
429 bool network_has_static_ipv6_configurations(Network
*network
);
431 CONFIG_PARSER_PROTOTYPE(config_parse_stacked_netdev
);
432 CONFIG_PARSER_PROTOTYPE(config_parse_tunnel
);
433 CONFIG_PARSER_PROTOTYPE(config_parse_required_for_online
);
434 CONFIG_PARSER_PROTOTYPE(config_parse_required_family_for_online
);
435 CONFIG_PARSER_PROTOTYPE(config_parse_keep_configuration
);
436 CONFIG_PARSER_PROTOTYPE(config_parse_activation_policy
);
437 CONFIG_PARSER_PROTOTYPE(config_parse_link_group
);
438 CONFIG_PARSER_PROTOTYPE(config_parse_ignore_carrier_loss
);
440 const struct ConfigPerfItem
* network_network_gperf_lookup(const char *key
, GPERF_LEN_TYPE length
);
442 const char* keep_configuration_to_string(KeepConfiguration i
) _const_
;
443 KeepConfiguration
keep_configuration_from_string(const char *s
) _pure_
;
445 const char* activation_policy_to_string(ActivationPolicy i
) _const_
;
446 ActivationPolicy
activation_policy_from_string(const char *s
) _pure_
;