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-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"
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
,
44 typedef enum ActivationPolicy
{
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
,
55 typedef struct Manager Manager
;
57 typedef struct NetworkDHCPServerEmitAddress
{
59 struct in_addr
*addresses
;
61 } NetworkDHCPServerEmitAddress
;
71 Hashmap
*stats_by_path
;
76 LIST_HEAD(Condition
, conditions
);
78 /* Master or stacked netdevs */
85 Hashmap
*stacked_netdevs
;
90 Hashmap
*stacked_netdev_names
;
93 struct hw_addr_data hw_addr
;
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
;
107 bool configure_without_carrier
;
108 bool ignore_carrier_loss_set
;
109 usec_t ignore_carrier_loss_usec
; /* timespan */
110 KeepConfiguration keep_configuration
;
112 bool default_route_on_device
;
113 AddressFamily ip_masquerade
;
115 /* DHCP Client Support */
117 struct in_addr dhcp_request_address
;
118 DHCPClientIdentifier dhcp_client_identifier
;
122 char *dhcp_vendor_class_identifier
;
124 char **dhcp_user_class
;
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
;
136 int dhcp_ip_service_type
;
137 int dhcp_socket_priority
;
138 bool dhcp_socket_priority_set
;
140 bool dhcp_send_hostname
;
142 int dhcp_ipv6_only_mode
;
144 bool dhcp_use_dns_set
;
145 bool dhcp_routes_to_dns
;
147 bool dhcp_use_ntp_set
;
148 bool dhcp_routes_to_ntp
;
150 bool dhcp_use_captive_portal
;
152 bool dhcp_use_routes
;
153 int dhcp_use_gateway
;
155 uint32_t dhcp_initial_congestion_window
;
156 uint32_t dhcp_advertised_receive_window
;
157 bool dhcp_use_timezone
;
158 bool dhcp_use_hostname
;
160 bool dhcp_send_release
;
161 bool dhcp_send_decline
;
162 DHCPUseDomains dhcp_use_domains
;
163 bool dhcp_use_domains_set
;
164 Set
*dhcp_deny_listed_ip
;
165 Set
*dhcp_allow_listed_ip
;
166 Set
*dhcp_request_options
;
167 OrderedHashmap
*dhcp_client_send_options
;
168 OrderedHashmap
*dhcp_client_send_vendor_options
;
170 NFTSetContext dhcp_nft_set_context
;
172 /* DHCPv6 Client support */
173 bool dhcp6_use_address
;
174 bool dhcp6_use_pd_prefix
;
176 bool dhcp6_use_dns_set
;
177 bool dhcp6_use_hostname
;
179 bool dhcp6_use_ntp_set
;
180 bool dhcp6_use_captive_portal
;
181 bool dhcp6_use_rapid_commit
;
182 DHCPUseDomains dhcp6_use_domains
;
183 bool dhcp6_use_domains_set
;
186 bool dhcp6_iaid_set_explicitly
;
188 uint8_t dhcp6_pd_prefix_length
;
189 struct in6_addr dhcp6_pd_prefix_hint
;
191 char **dhcp6_user_class
;
192 char **dhcp6_vendor_class
;
193 DHCP6ClientStartMode dhcp6_client_start_mode
;
194 OrderedHashmap
*dhcp6_client_send_options
;
195 OrderedHashmap
*dhcp6_client_send_vendor_options
;
196 Set
*dhcp6_request_options
;
197 char *dhcp6_netlabel
;
198 bool dhcp6_send_release
;
199 NFTSetContext dhcp6_nft_set_context
;
201 /* DHCP Server Support */
203 bool dhcp_server_bind_to_interface
;
204 unsigned char dhcp_server_address_prefixlen
;
205 struct in_addr dhcp_server_address_in_addr
;
206 const Address
*dhcp_server_address
;
207 int dhcp_server_uplink_index
;
208 char *dhcp_server_uplink_name
;
209 struct in_addr dhcp_server_relay_target
;
210 char *dhcp_server_relay_agent_circuit_id
;
211 char *dhcp_server_relay_agent_remote_id
;
212 NetworkDHCPServerEmitAddress dhcp_server_emit
[_SD_DHCP_LEASE_SERVER_TYPE_MAX
];
213 bool dhcp_server_emit_router
;
214 struct in_addr dhcp_server_router
;
215 bool dhcp_server_emit_timezone
;
216 char *dhcp_server_timezone
;
217 usec_t dhcp_server_default_lease_time_usec
, dhcp_server_max_lease_time_usec
;
218 uint32_t dhcp_server_pool_offset
;
219 uint32_t dhcp_server_pool_size
;
220 OrderedHashmap
*dhcp_server_send_options
;
221 OrderedHashmap
*dhcp_server_send_vendor_options
;
222 struct in_addr dhcp_server_boot_server_address
;
223 char *dhcp_server_boot_server_name
;
224 char *dhcp_server_boot_filename
;
225 usec_t dhcp_server_ipv6_only_preferred_usec
;
227 /* link-local addressing support */
228 AddressFamily link_local
;
229 IPv6LinkLocalAddressGenMode ipv6ll_address_gen_mode
;
230 struct in6_addr ipv6ll_stable_secret
;
231 struct in_addr ipv4ll_start_address
;
234 /* IPv6 RA support */
235 RADVPrefixDelegation router_prefix_delegation
;
236 usec_t router_lifetime_usec
;
237 uint8_t router_preference
;
238 usec_t router_retransmit_usec
;
239 uint8_t router_hop_limit
;
241 bool router_other_information
;
242 bool router_emit_dns
;
243 bool router_emit_domains
;
244 usec_t router_dns_lifetime_usec
;
245 struct in6_addr
*router_dns
;
246 unsigned n_router_dns
;
247 OrderedSet
*router_search_domains
;
248 int router_uplink_index
;
249 char *router_uplink_name
;
250 /* Mobile IPv6 Home Agent */
251 bool router_home_agent_information
;
252 uint16_t router_home_agent_preference
;
253 usec_t home_agent_lifetime_usec
;
255 /* DHCP Prefix Delegation support */
257 bool dhcp_pd_announce
;
259 bool dhcp_pd_manage_temporary_address
;
260 int64_t dhcp_pd_subnet_id
;
261 uint32_t dhcp_pd_route_metric
;
263 int dhcp_pd_uplink_index
;
264 char *dhcp_pd_uplink_name
;
265 char *dhcp_pd_netlabel
;
266 NFTSetContext dhcp_pd_nft_set_context
;
273 int allow_port_to_be_root
;
276 int multicast_to_unicast
;
277 int neighbor_suppression
;
279 int bridge_proxy_arp
;
280 int bridge_proxy_arp_wifi
;
283 MulticastRouter multicast_router
;
288 uint32_t br_vid_bitmap
[BRIDGE_VLAN_BITMAP_LEN
];
289 uint32_t br_untagged_bitmap
[BRIDGE_VLAN_BITMAP_LEN
];
292 uint32_t can_bitrate
;
293 unsigned can_sample_point
;
294 nsec_t can_time_quanta_ns
;
295 uint32_t can_propagation_segment
;
296 uint32_t can_phase_buffer_segment_1
;
297 uint32_t can_phase_buffer_segment_2
;
298 uint32_t can_sync_jump_width
;
299 uint32_t can_data_bitrate
;
300 unsigned can_data_sample_point
;
301 nsec_t can_data_time_quanta_ns
;
302 uint32_t can_data_propagation_segment
;
303 uint32_t can_data_phase_buffer_segment_1
;
304 uint32_t can_data_phase_buffer_segment_2
;
305 uint32_t can_data_sync_jump_width
;
306 usec_t can_restart_us
;
307 uint32_t can_control_mode_mask
;
308 uint32_t can_control_mode_flags
;
309 uint16_t can_termination
;
310 bool can_termination_set
;
313 IPoIBMode ipoib_mode
;
316 /* sysctl settings */
317 AddressFamily ip_forward
;
318 int ipv4_accept_local
;
319 int ipv4_route_localnet
;
320 int ipv6_dad_transmits
;
324 IPv6PrivacyExtensions ipv6_privacy_extensions
;
325 IPReversePathFilter ipv4_rp_filter
;
327 Set
*ipv6_proxy_ndp_addresses
;
331 bool ipv6_accept_ra_use_dns
;
332 bool ipv6_accept_ra_use_gateway
;
333 bool ipv6_accept_ra_use_route_prefix
;
334 bool ipv6_accept_ra_use_autonomous_prefix
;
335 bool ipv6_accept_ra_use_onlink_prefix
;
336 bool ipv6_accept_ra_use_mtu
;
337 bool ipv6_accept_ra_use_hop_limit
;
338 bool ipv6_accept_ra_use_icmp6_ratelimit
;
339 bool ipv6_accept_ra_quickack
;
340 bool ipv6_accept_ra_use_captive_portal
;
341 bool ipv6_accept_ra_use_pref64
;
344 DHCPUseDomains ipv6_accept_ra_use_domains
;
345 IPv6AcceptRAStartDHCP6Client ipv6_accept_ra_start_dhcp6_client
;
346 uint32_t ipv6_accept_ra_route_table
;
347 bool ipv6_accept_ra_route_table_set
;
348 uint32_t ipv6_accept_ra_route_metric_high
;
349 uint32_t ipv6_accept_ra_route_metric_medium
;
350 uint32_t ipv6_accept_ra_route_metric_low
;
351 bool ipv6_accept_ra_route_metric_set
;
352 Set
*ndisc_deny_listed_router
;
353 Set
*ndisc_allow_listed_router
;
354 Set
*ndisc_deny_listed_prefix
;
355 Set
*ndisc_allow_listed_prefix
;
356 Set
*ndisc_deny_listed_route_prefix
;
357 Set
*ndisc_allow_listed_route_prefix
;
359 char *ndisc_netlabel
;
360 NFTSetContext ndisc_nft_set_context
;
363 LLDPMode lldp_mode
; /* LLDP reception */
364 sd_lldp_multicast_mode_t lldp_multicast_mode
; /* LLDP transmission */
365 char *lldp_mudurl
; /* LLDP MUD URL */
367 OrderedHashmap
*addresses_by_section
;
368 Hashmap
*routes_by_section
;
369 Hashmap
*nexthops_by_section
;
370 Hashmap
*bridge_fdb_entries_by_section
;
371 Hashmap
*bridge_mdb_entries_by_section
;
372 OrderedHashmap
*neighbors_by_section
;
373 Hashmap
*address_labels_by_section
;
374 Hashmap
*prefixes_by_section
;
375 Hashmap
*route_prefixes_by_section
;
376 Hashmap
*pref64_prefixes_by_section
;
377 Hashmap
*rules_by_section
;
378 Hashmap
*dhcp_static_leases_by_section
;
379 Hashmap
*qdiscs_by_section
;
380 Hashmap
*tclasses_by_section
;
381 OrderedHashmap
*sr_iov_by_section
;
383 /* All kinds of DNS configuration */
384 struct in_addr_full
**dns
;
386 OrderedSet
*search_domains
, *route_domains
;
387 int dns_default_route
;
388 ResolveSupport llmnr
;
390 DnssecMode dnssec_mode
;
391 DnsOverTlsMode dns_over_tls_mode
;
392 Set
*dnssec_negative_trust_anchors
;
398 Network
*network_ref(Network
*network
);
399 Network
*network_unref(Network
*network
);
400 DEFINE_TRIVIAL_CLEANUP_FUNC(Network
*, network_unref
);
402 int network_load(Manager
*manager
, OrderedHashmap
**networks
);
403 int network_reload(Manager
*manager
);
404 int network_load_one(Manager
*manager
, OrderedHashmap
**networks
, const char *filename
);
405 int network_verify(Network
*network
);
407 int manager_build_dhcp_pd_subnet_ids(Manager
*manager
);
409 int network_get_by_name(Manager
*manager
, const char *name
, Network
**ret
);
410 void network_apply_anonymize_if_set(Network
*network
);
412 bool network_has_static_ipv6_configurations(Network
*network
);
414 CONFIG_PARSER_PROTOTYPE(config_parse_stacked_netdev
);
415 CONFIG_PARSER_PROTOTYPE(config_parse_tunnel
);
416 CONFIG_PARSER_PROTOTYPE(config_parse_domains
);
417 CONFIG_PARSER_PROTOTYPE(config_parse_dns
);
418 CONFIG_PARSER_PROTOTYPE(config_parse_timezone
);
419 CONFIG_PARSER_PROTOTYPE(config_parse_dnssec_negative_trust_anchors
);
420 CONFIG_PARSER_PROTOTYPE(config_parse_ntp
);
421 CONFIG_PARSER_PROTOTYPE(config_parse_required_for_online
);
422 CONFIG_PARSER_PROTOTYPE(config_parse_required_family_for_online
);
423 CONFIG_PARSER_PROTOTYPE(config_parse_keep_configuration
);
424 CONFIG_PARSER_PROTOTYPE(config_parse_activation_policy
);
425 CONFIG_PARSER_PROTOTYPE(config_parse_link_group
);
426 CONFIG_PARSER_PROTOTYPE(config_parse_ignore_carrier_loss
);
428 const struct ConfigPerfItem
* network_network_gperf_lookup(const char *key
, GPERF_LEN_TYPE length
);
430 const char* keep_configuration_to_string(KeepConfiguration i
) _const_
;
431 KeepConfiguration
keep_configuration_from_string(const char *s
) _pure_
;
433 const char* activation_policy_to_string(ActivationPolicy i
) _const_
;
434 ActivationPolicy
activation_policy_from_string(const char *s
) _pure_
;