1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
4 #include <linux/nl80211.h>
8 #include "sd-lldp-tx.h"
11 #include "condition.h"
12 #include "conf-parser.h"
13 #include "firewall-util.h"
16 #include "net-condition.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"
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
,
45 typedef enum ActivationPolicy
{
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
,
56 typedef struct Manager Manager
;
58 typedef struct NetworkDHCPServerEmitAddress
{
60 struct in_addr
*addresses
;
62 } NetworkDHCPServerEmitAddress
;
72 Hashmap
*stats_by_path
;
77 LIST_HEAD(Condition
, conditions
);
79 /* Master or stacked netdevs */
86 Hashmap
*stacked_netdevs
;
91 Hashmap
*stacked_netdev_names
;
94 struct hw_addr_data hw_addr
;
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
;
108 bool configure_without_carrier
;
109 bool ignore_carrier_loss_set
;
110 usec_t ignore_carrier_loss_usec
; /* timespan */
111 KeepConfiguration keep_configuration
;
113 bool default_route_on_device
;
114 AddressFamily ip_masquerade
;
116 /* Protocol independent settings */
117 UseDomains use_domains
;
119 /* For backward compatibility, only applied to DHCPv4 and DHCPv6. */
120 UseDomains compat_dhcp_use_domains
;
121 int compat_dhcp_use_dns
;
122 int compat_dhcp_use_ntp
;
124 /* DHCP Client Support */
126 struct in_addr dhcp_request_address
;
127 DHCPClientIdentifier dhcp_client_identifier
;
131 char *dhcp_vendor_class_identifier
;
133 char **dhcp_user_class
;
136 uint64_t dhcp_max_attempts
;
137 uint32_t dhcp_route_metric
;
138 bool dhcp_route_metric_set
;
139 uint32_t dhcp_route_table
;
140 bool dhcp_route_table_set
;
141 usec_t dhcp_fallback_lease_lifetime_usec
;
142 uint32_t dhcp_route_mtu
;
143 uint16_t dhcp_client_port
;
146 int dhcp_ip_service_type
;
147 int dhcp_socket_priority
;
148 bool dhcp_socket_priority_set
;
150 bool dhcp_send_hostname
;
151 bool dhcp_send_hostname_set
;
153 int dhcp_ipv6_only_mode
;
154 int dhcp_use_rapid_commit
;
156 bool dhcp_routes_to_dns
;
158 bool dhcp_routes_to_ntp
;
160 bool dhcp_use_captive_portal
;
162 bool dhcp_use_routes
;
163 int dhcp_use_gateway
;
165 uint32_t dhcp_initial_congestion_window
;
166 uint32_t dhcp_advertised_receive_window
;
167 bool dhcp_use_timezone
;
168 bool dhcp_use_hostname
;
170 bool dhcp_send_release
;
171 bool dhcp_send_decline
;
172 UseDomains dhcp_use_domains
;
173 Set
*dhcp_deny_listed_ip
;
174 Set
*dhcp_allow_listed_ip
;
175 Set
*dhcp_request_options
;
176 OrderedHashmap
*dhcp_client_send_options
;
177 OrderedHashmap
*dhcp_client_send_vendor_options
;
179 NFTSetContext dhcp_nft_set_context
;
181 /* DHCPv6 Client support */
182 bool dhcp6_use_address
;
183 bool dhcp6_use_pd_prefix
;
184 bool dhcp6_send_hostname
;
185 bool dhcp6_send_hostname_set
;
187 bool dhcp6_use_hostname
;
189 bool dhcp6_use_captive_portal
;
190 bool dhcp6_use_rapid_commit
;
191 UseDomains dhcp6_use_domains
;
194 bool dhcp6_iaid_set_explicitly
;
196 uint8_t dhcp6_pd_prefix_length
;
197 struct in6_addr dhcp6_pd_prefix_hint
;
198 char *dhcp6_hostname
;
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
;
210 /* DHCP Server Support */
212 bool dhcp_server_bind_to_interface
;
213 unsigned char dhcp_server_address_prefixlen
;
214 struct in_addr dhcp_server_address_in_addr
;
215 const Address
*dhcp_server_address
;
216 int dhcp_server_uplink_index
;
217 char *dhcp_server_uplink_name
;
218 struct in_addr dhcp_server_relay_target
;
219 char *dhcp_server_relay_agent_circuit_id
;
220 char *dhcp_server_relay_agent_remote_id
;
221 NetworkDHCPServerEmitAddress dhcp_server_emit
[_SD_DHCP_LEASE_SERVER_TYPE_MAX
];
222 bool dhcp_server_emit_router
;
223 struct in_addr dhcp_server_router
;
224 bool dhcp_server_emit_timezone
;
225 char *dhcp_server_timezone
;
226 usec_t dhcp_server_default_lease_time_usec
, dhcp_server_max_lease_time_usec
;
227 uint32_t dhcp_server_pool_offset
;
228 uint32_t dhcp_server_pool_size
;
229 OrderedHashmap
*dhcp_server_send_options
;
230 OrderedHashmap
*dhcp_server_send_vendor_options
;
231 struct in_addr dhcp_server_boot_server_address
;
232 char *dhcp_server_boot_server_name
;
233 char *dhcp_server_boot_filename
;
234 usec_t dhcp_server_ipv6_only_preferred_usec
;
235 bool dhcp_server_rapid_commit
;
236 int dhcp_server_persist_leases
;
238 /* link-local addressing support */
239 AddressFamily link_local
;
240 IPv6LinkLocalAddressGenMode ipv6ll_address_gen_mode
;
241 struct in6_addr ipv6ll_stable_secret
;
242 struct in_addr ipv4ll_start_address
;
245 /* IPv6 RA support */
246 RADVPrefixDelegation router_prefix_delegation
;
247 usec_t router_lifetime_usec
;
248 uint8_t router_preference
;
249 usec_t router_reachable_usec
;
250 usec_t router_retransmit_usec
;
251 uint8_t router_hop_limit
;
253 bool router_other_information
;
254 bool router_emit_dns
;
255 bool router_emit_domains
;
256 usec_t router_dns_lifetime_usec
;
257 struct in6_addr
*router_dns
;
258 unsigned n_router_dns
;
259 OrderedSet
*router_search_domains
;
260 int router_uplink_index
;
261 char *router_uplink_name
;
262 /* Mobile IPv6 Home Agent */
263 bool router_home_agent_information
;
264 uint16_t router_home_agent_preference
;
265 usec_t home_agent_lifetime_usec
;
267 /* DHCP Prefix Delegation support */
269 bool dhcp_pd_announce
;
271 bool dhcp_pd_manage_temporary_address
;
272 int64_t dhcp_pd_subnet_id
;
273 uint32_t dhcp_pd_route_metric
;
275 int dhcp_pd_uplink_index
;
276 char *dhcp_pd_uplink_name
;
277 char *dhcp_pd_netlabel
;
278 NFTSetContext dhcp_pd_nft_set_context
;
285 int allow_port_to_be_root
;
288 int multicast_to_unicast
;
289 int neighbor_suppression
;
291 int bridge_proxy_arp
;
292 int bridge_proxy_arp_wifi
;
295 MulticastRouter multicast_router
;
298 uint16_t bridge_vlan_pvid
;
299 uint32_t bridge_vlan_bitmap
[BRIDGE_VLAN_BITMAP_LEN
];
300 uint32_t bridge_vlan_untagged_bitmap
[BRIDGE_VLAN_BITMAP_LEN
];
303 uint32_t can_bitrate
;
304 unsigned can_sample_point
;
305 nsec_t can_time_quanta_ns
;
306 uint32_t can_propagation_segment
;
307 uint32_t can_phase_buffer_segment_1
;
308 uint32_t can_phase_buffer_segment_2
;
309 uint32_t can_sync_jump_width
;
310 uint32_t can_data_bitrate
;
311 unsigned can_data_sample_point
;
312 nsec_t can_data_time_quanta_ns
;
313 uint32_t can_data_propagation_segment
;
314 uint32_t can_data_phase_buffer_segment_1
;
315 uint32_t can_data_phase_buffer_segment_2
;
316 uint32_t can_data_sync_jump_width
;
317 usec_t can_restart_us
;
318 uint32_t can_control_mode_mask
;
319 uint32_t can_control_mode_flags
;
320 uint16_t can_termination
;
321 bool can_termination_set
;
324 IPoIBMode ipoib_mode
;
327 /* sysctl settings */
328 int ip_forwarding
[2];
329 int ipv4_accept_local
;
330 int ipv4_route_localnet
;
331 int ipv6_dad_transmits
;
332 uint8_t ipv6_hop_limit
;
333 usec_t ipv6_retransmission_time
;
337 IPv6PrivacyExtensions ipv6_privacy_extensions
;
338 IPReversePathFilter ipv4_rp_filter
;
340 Set
*ipv6_proxy_ndp_addresses
;
344 bool ndisc_use_redirect
;
346 bool ndisc_use_gateway
;
347 bool ndisc_use_route_prefix
;
348 bool ndisc_use_autonomous_prefix
;
349 bool ndisc_use_onlink_prefix
;
351 bool ndisc_use_hop_limit
;
352 bool ndisc_use_reachable_time
;
353 bool ndisc_use_retransmission_time
;
355 bool ndisc_use_captive_portal
;
356 bool ndisc_use_pref64
;
359 UseDomains ndisc_use_domains
;
360 IPv6AcceptRAStartDHCP6Client ndisc_start_dhcp6_client
;
361 uint32_t ndisc_route_table
;
362 bool ndisc_route_table_set
;
363 uint32_t ndisc_route_metric_high
;
364 uint32_t ndisc_route_metric_medium
;
365 uint32_t ndisc_route_metric_low
;
366 bool ndisc_route_metric_set
;
367 Set
*ndisc_deny_listed_router
;
368 Set
*ndisc_allow_listed_router
;
369 Set
*ndisc_deny_listed_prefix
;
370 Set
*ndisc_allow_listed_prefix
;
371 Set
*ndisc_deny_listed_route_prefix
;
372 Set
*ndisc_allow_listed_route_prefix
;
374 char *ndisc_netlabel
;
375 NFTSetContext ndisc_nft_set_context
;
378 LLDPMode lldp_mode
; /* LLDP reception */
379 sd_lldp_multicast_mode_t lldp_multicast_mode
; /* LLDP transmission */
380 char *lldp_mudurl
; /* LLDP MUD URL */
382 OrderedHashmap
*addresses_by_section
;
383 Hashmap
*routes_by_section
;
384 OrderedHashmap
*nexthops_by_section
;
385 Hashmap
*bridge_fdb_entries_by_section
;
386 Hashmap
*bridge_mdb_entries_by_section
;
387 OrderedHashmap
*neighbors_by_section
;
388 Hashmap
*address_labels_by_section
;
389 Hashmap
*prefixes_by_section
;
390 Hashmap
*route_prefixes_by_section
;
391 Hashmap
*pref64_prefixes_by_section
;
392 Hashmap
*rules_by_section
;
393 Hashmap
*dhcp_static_leases_by_section
;
394 Hashmap
*qdiscs_by_section
;
395 Hashmap
*tclasses_by_section
;
396 OrderedHashmap
*sr_iov_by_section
;
398 /* All kinds of DNS configuration */
399 struct in_addr_full
**dns
;
401 OrderedSet
*search_domains
, *route_domains
;
402 int dns_default_route
;
403 ResolveSupport llmnr
;
405 DnssecMode dnssec_mode
;
406 DnsOverTlsMode dns_over_tls_mode
;
407 Set
*dnssec_negative_trust_anchors
;
413 Network
*network_ref(Network
*network
);
414 Network
*network_unref(Network
*network
);
415 DEFINE_TRIVIAL_CLEANUP_FUNC(Network
*, network_unref
);
417 int network_load(Manager
*manager
, OrderedHashmap
**networks
);
418 int network_reload(Manager
*manager
);
419 int network_load_one(Manager
*manager
, OrderedHashmap
**networks
, const char *filename
);
420 int network_verify(Network
*network
);
422 int manager_build_dhcp_pd_subnet_ids(Manager
*manager
);
424 int network_get_by_name(Manager
*manager
, const char *name
, Network
**ret
);
425 void network_apply_anonymize_if_set(Network
*network
);
427 bool network_has_static_ipv6_configurations(Network
*network
);
429 CONFIG_PARSER_PROTOTYPE(config_parse_stacked_netdev
);
430 CONFIG_PARSER_PROTOTYPE(config_parse_tunnel
);
431 CONFIG_PARSER_PROTOTYPE(config_parse_required_for_online
);
432 CONFIG_PARSER_PROTOTYPE(config_parse_required_family_for_online
);
433 CONFIG_PARSER_PROTOTYPE(config_parse_keep_configuration
);
434 CONFIG_PARSER_PROTOTYPE(config_parse_activation_policy
);
435 CONFIG_PARSER_PROTOTYPE(config_parse_link_group
);
436 CONFIG_PARSER_PROTOTYPE(config_parse_ignore_carrier_loss
);
438 const struct ConfigPerfItem
* network_network_gperf_lookup(const char *key
, GPERF_LEN_TYPE length
);
440 const char* keep_configuration_to_string(KeepConfiguration i
) _const_
;
441 KeepConfiguration
keep_configuration_from_string(const char *s
) _pure_
;
443 const char* activation_policy_to_string(ActivationPolicy i
) _const_
;
444 ActivationPolicy
activation_policy_from_string(const char *s
) _pure_
;