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-bridge-vlan.h"
19 #include "networkd-dhcp-common.h"
20 #include "networkd-dhcp4.h"
21 #include "networkd-dhcp6.h"
22 #include "networkd-ipv6ll.h"
23 #include "networkd-lldp-rx.h"
24 #include "networkd-ndisc.h"
25 #include "networkd-radv.h"
26 #include "networkd-sysctl.h"
27 #include "networkd-util.h"
28 #include "ordered-set.h"
29 #include "resolve-util.h"
30 #include "socket-netlink.h"
32 typedef enum KeepConfiguration
{
33 KEEP_CONFIGURATION_NO
= 0,
34 KEEP_CONFIGURATION_DHCP_ON_START
= 1 << 0,
35 KEEP_CONFIGURATION_DHCP_ON_STOP
= 1 << 1,
36 KEEP_CONFIGURATION_DHCP
= KEEP_CONFIGURATION_DHCP_ON_START
| KEEP_CONFIGURATION_DHCP_ON_STOP
,
37 KEEP_CONFIGURATION_STATIC
= 1 << 2,
38 KEEP_CONFIGURATION_YES
= KEEP_CONFIGURATION_DHCP
| KEEP_CONFIGURATION_STATIC
,
39 _KEEP_CONFIGURATION_MAX
,
40 _KEEP_CONFIGURATION_INVALID
= -EINVAL
,
43 typedef enum ActivationPolicy
{
45 ACTIVATION_POLICY_ALWAYS_UP
,
46 ACTIVATION_POLICY_MANUAL
,
47 ACTIVATION_POLICY_ALWAYS_DOWN
,
48 ACTIVATION_POLICY_DOWN
,
49 ACTIVATION_POLICY_BOUND
,
50 _ACTIVATION_POLICY_MAX
,
51 _ACTIVATION_POLICY_INVALID
= -EINVAL
,
54 typedef struct Manager Manager
;
56 typedef struct NetworkDHCPServerEmitAddress
{
58 struct in_addr
*addresses
;
60 } NetworkDHCPServerEmitAddress
;
70 Hashmap
*stats_by_path
;
75 LIST_HEAD(Condition
, conditions
);
77 /* Master or stacked netdevs */
84 Hashmap
*stacked_netdevs
;
89 Hashmap
*stacked_netdev_names
;
92 struct hw_addr_data hw_addr
;
100 int required_for_online
; /* Is this network required to be considered online? */
101 LinkOperationalStateRange required_operstate_for_online
;
102 AddressFamily required_family_for_online
;
103 ActivationPolicy activation_policy
;
106 bool configure_without_carrier
;
107 bool ignore_carrier_loss_set
;
108 usec_t ignore_carrier_loss_usec
; /* timespan */
109 KeepConfiguration keep_configuration
;
111 bool default_route_on_device
;
112 AddressFamily ip_masquerade
;
114 /* DHCP Client Support */
116 DHCPClientIdentifier dhcp_client_identifier
;
120 char *dhcp_vendor_class_identifier
;
122 char **dhcp_user_class
;
125 uint64_t dhcp_max_attempts
;
126 uint32_t dhcp_route_metric
;
127 bool dhcp_route_metric_set
;
128 uint32_t dhcp_route_table
;
129 bool dhcp_route_table_set
;
130 uint32_t dhcp_fallback_lease_lifetime
;
131 uint32_t dhcp_route_mtu
;
132 uint16_t dhcp_client_port
;
134 int dhcp_ip_service_type
;
135 int dhcp_socket_priority
;
136 bool dhcp_socket_priority_set
;
138 bool dhcp_send_hostname
;
141 bool dhcp_use_dns_set
;
142 bool dhcp_routes_to_dns
;
144 bool dhcp_use_ntp_set
;
145 bool dhcp_routes_to_ntp
;
147 bool dhcp_use_captive_portal
;
149 bool dhcp_use_routes
;
150 int dhcp_use_gateway
;
152 uint32_t dhcp_initial_congestion_window
;
153 uint32_t dhcp_advertised_receive_window
;
154 bool dhcp_use_timezone
;
155 bool dhcp_use_hostname
;
157 bool dhcp_send_release
;
158 bool dhcp_send_decline
;
159 DHCPUseDomains dhcp_use_domains
;
160 bool dhcp_use_domains_set
;
161 Set
*dhcp_deny_listed_ip
;
162 Set
*dhcp_allow_listed_ip
;
163 Set
*dhcp_request_options
;
164 OrderedHashmap
*dhcp_client_send_options
;
165 OrderedHashmap
*dhcp_client_send_vendor_options
;
167 NFTSetContext dhcp_nft_set_context
;
169 /* DHCPv6 Client support */
170 bool dhcp6_use_address
;
171 bool dhcp6_use_pd_prefix
;
173 bool dhcp6_use_dns_set
;
174 bool dhcp6_use_hostname
;
176 bool dhcp6_use_ntp_set
;
177 bool dhcp6_use_captive_portal
;
178 bool dhcp6_use_rapid_commit
;
179 DHCPUseDomains dhcp6_use_domains
;
180 bool dhcp6_use_domains_set
;
183 bool dhcp6_iaid_set_explicitly
;
185 uint8_t dhcp6_pd_prefix_length
;
186 struct in6_addr dhcp6_pd_prefix_hint
;
188 char **dhcp6_user_class
;
189 char **dhcp6_vendor_class
;
190 DHCP6ClientStartMode dhcp6_client_start_mode
;
191 OrderedHashmap
*dhcp6_client_send_options
;
192 OrderedHashmap
*dhcp6_client_send_vendor_options
;
193 Set
*dhcp6_request_options
;
194 char *dhcp6_netlabel
;
195 bool dhcp6_send_release
;
196 NFTSetContext dhcp6_nft_set_context
;
198 /* DHCP Server Support */
200 bool dhcp_server_bind_to_interface
;
201 unsigned char dhcp_server_address_prefixlen
;
202 struct in_addr dhcp_server_address
;
203 int dhcp_server_uplink_index
;
204 char *dhcp_server_uplink_name
;
205 struct in_addr dhcp_server_relay_target
;
206 char *dhcp_server_relay_agent_circuit_id
;
207 char *dhcp_server_relay_agent_remote_id
;
208 NetworkDHCPServerEmitAddress dhcp_server_emit
[_SD_DHCP_LEASE_SERVER_TYPE_MAX
];
209 bool dhcp_server_emit_router
;
210 struct in_addr dhcp_server_router
;
211 bool dhcp_server_emit_timezone
;
212 char *dhcp_server_timezone
;
213 usec_t dhcp_server_default_lease_time_usec
, dhcp_server_max_lease_time_usec
;
214 uint32_t dhcp_server_pool_offset
;
215 uint32_t dhcp_server_pool_size
;
216 OrderedHashmap
*dhcp_server_send_options
;
217 OrderedHashmap
*dhcp_server_send_vendor_options
;
218 struct in_addr dhcp_server_boot_server_address
;
219 char *dhcp_server_boot_server_name
;
220 char *dhcp_server_boot_filename
;
222 /* link-local addressing support */
223 AddressFamily link_local
;
224 IPv6LinkLocalAddressGenMode ipv6ll_address_gen_mode
;
225 struct in6_addr ipv6ll_stable_secret
;
226 struct in_addr ipv4ll_start_address
;
229 /* IPv6 RA support */
230 RADVPrefixDelegation router_prefix_delegation
;
231 usec_t router_lifetime_usec
;
232 uint8_t router_preference
;
233 usec_t router_retransmit_usec
;
234 uint8_t router_hop_limit
;
236 bool router_other_information
;
237 bool router_emit_dns
;
238 bool router_emit_domains
;
239 usec_t router_dns_lifetime_usec
;
240 struct in6_addr
*router_dns
;
241 unsigned n_router_dns
;
242 OrderedSet
*router_search_domains
;
243 int router_uplink_index
;
244 char *router_uplink_name
;
245 /* Mobile IPv6 Home Agent */
246 bool router_home_agent_information
;
247 uint16_t router_home_agent_preference
;
248 usec_t home_agent_lifetime_usec
;
250 /* DHCP Prefix Delegation support */
252 bool dhcp_pd_announce
;
254 bool dhcp_pd_manage_temporary_address
;
255 int64_t dhcp_pd_subnet_id
;
256 uint32_t dhcp_pd_route_metric
;
258 int dhcp_pd_uplink_index
;
259 char *dhcp_pd_uplink_name
;
260 char *dhcp_pd_netlabel
;
261 NFTSetContext dhcp_pd_nft_set_context
;
268 int allow_port_to_be_root
;
271 int multicast_to_unicast
;
272 int neighbor_suppression
;
274 int bridge_proxy_arp
;
275 int bridge_proxy_arp_wifi
;
278 MulticastRouter multicast_router
;
283 uint32_t br_vid_bitmap
[BRIDGE_VLAN_BITMAP_LEN
];
284 uint32_t br_untagged_bitmap
[BRIDGE_VLAN_BITMAP_LEN
];
287 uint32_t can_bitrate
;
288 unsigned can_sample_point
;
289 nsec_t can_time_quanta_ns
;
290 uint32_t can_propagation_segment
;
291 uint32_t can_phase_buffer_segment_1
;
292 uint32_t can_phase_buffer_segment_2
;
293 uint32_t can_sync_jump_width
;
294 uint32_t can_data_bitrate
;
295 unsigned can_data_sample_point
;
296 nsec_t can_data_time_quanta_ns
;
297 uint32_t can_data_propagation_segment
;
298 uint32_t can_data_phase_buffer_segment_1
;
299 uint32_t can_data_phase_buffer_segment_2
;
300 uint32_t can_data_sync_jump_width
;
301 usec_t can_restart_us
;
302 uint32_t can_control_mode_mask
;
303 uint32_t can_control_mode_flags
;
304 uint16_t can_termination
;
305 bool can_termination_set
;
308 IPoIBMode ipoib_mode
;
311 /* sysctl settings */
312 AddressFamily ip_forward
;
313 int ipv4_accept_local
;
314 int ipv4_route_localnet
;
315 int ipv6_dad_transmits
;
319 IPv6PrivacyExtensions ipv6_privacy_extensions
;
320 IPReversePathFilter ipv4_rp_filter
;
322 Set
*ipv6_proxy_ndp_addresses
;
326 bool ipv6_accept_ra_use_dns
;
327 bool ipv6_accept_ra_use_gateway
;
328 bool ipv6_accept_ra_use_route_prefix
;
329 bool ipv6_accept_ra_use_autonomous_prefix
;
330 bool ipv6_accept_ra_use_onlink_prefix
;
331 bool ipv6_accept_ra_use_mtu
;
332 bool ipv6_accept_ra_use_hop_limit
;
333 bool ipv6_accept_ra_use_icmp6_ratelimit
;
334 bool ipv6_accept_ra_quickack
;
335 bool ipv6_accept_ra_use_captive_portal
;
336 bool ipv6_accept_ra_use_pref64
;
339 DHCPUseDomains ipv6_accept_ra_use_domains
;
340 IPv6AcceptRAStartDHCP6Client ipv6_accept_ra_start_dhcp6_client
;
341 uint32_t ipv6_accept_ra_route_table
;
342 bool ipv6_accept_ra_route_table_set
;
343 uint32_t ipv6_accept_ra_route_metric_high
;
344 uint32_t ipv6_accept_ra_route_metric_medium
;
345 uint32_t ipv6_accept_ra_route_metric_low
;
346 bool ipv6_accept_ra_route_metric_set
;
347 Set
*ndisc_deny_listed_router
;
348 Set
*ndisc_allow_listed_router
;
349 Set
*ndisc_deny_listed_prefix
;
350 Set
*ndisc_allow_listed_prefix
;
351 Set
*ndisc_deny_listed_route_prefix
;
352 Set
*ndisc_allow_listed_route_prefix
;
354 char *ndisc_netlabel
;
355 NFTSetContext ndisc_nft_set_context
;
358 LLDPMode lldp_mode
; /* LLDP reception */
359 sd_lldp_multicast_mode_t lldp_multicast_mode
; /* LLDP transmission */
360 char *lldp_mudurl
; /* LLDP MUD URL */
362 OrderedHashmap
*addresses_by_section
;
363 Hashmap
*routes_by_section
;
364 Hashmap
*nexthops_by_section
;
365 Hashmap
*bridge_fdb_entries_by_section
;
366 Hashmap
*bridge_mdb_entries_by_section
;
367 OrderedHashmap
*neighbors_by_section
;
368 Hashmap
*address_labels_by_section
;
369 Hashmap
*prefixes_by_section
;
370 Hashmap
*route_prefixes_by_section
;
371 Hashmap
*pref64_prefixes_by_section
;
372 Hashmap
*rules_by_section
;
373 Hashmap
*dhcp_static_leases_by_section
;
374 Hashmap
*qdiscs_by_section
;
375 Hashmap
*tclasses_by_section
;
376 OrderedHashmap
*sr_iov_by_section
;
378 /* All kinds of DNS configuration */
379 struct in_addr_full
**dns
;
381 OrderedSet
*search_domains
, *route_domains
;
382 int dns_default_route
;
383 ResolveSupport llmnr
;
385 DnssecMode dnssec_mode
;
386 DnsOverTlsMode dns_over_tls_mode
;
387 Set
*dnssec_negative_trust_anchors
;
393 Network
*network_ref(Network
*network
);
394 Network
*network_unref(Network
*network
);
395 DEFINE_TRIVIAL_CLEANUP_FUNC(Network
*, network_unref
);
397 int network_load(Manager
*manager
, OrderedHashmap
**networks
);
398 int network_reload(Manager
*manager
);
399 int network_load_one(Manager
*manager
, OrderedHashmap
**networks
, const char *filename
);
400 int network_verify(Network
*network
);
402 int manager_build_dhcp_pd_subnet_ids(Manager
*manager
);
404 int network_get_by_name(Manager
*manager
, const char *name
, Network
**ret
);
405 void network_apply_anonymize_if_set(Network
*network
);
407 bool network_has_static_ipv6_configurations(Network
*network
);
409 CONFIG_PARSER_PROTOTYPE(config_parse_stacked_netdev
);
410 CONFIG_PARSER_PROTOTYPE(config_parse_tunnel
);
411 CONFIG_PARSER_PROTOTYPE(config_parse_domains
);
412 CONFIG_PARSER_PROTOTYPE(config_parse_dns
);
413 CONFIG_PARSER_PROTOTYPE(config_parse_timezone
);
414 CONFIG_PARSER_PROTOTYPE(config_parse_dnssec_negative_trust_anchors
);
415 CONFIG_PARSER_PROTOTYPE(config_parse_ntp
);
416 CONFIG_PARSER_PROTOTYPE(config_parse_required_for_online
);
417 CONFIG_PARSER_PROTOTYPE(config_parse_required_family_for_online
);
418 CONFIG_PARSER_PROTOTYPE(config_parse_keep_configuration
);
419 CONFIG_PARSER_PROTOTYPE(config_parse_activation_policy
);
420 CONFIG_PARSER_PROTOTYPE(config_parse_link_group
);
421 CONFIG_PARSER_PROTOTYPE(config_parse_ignore_carrier_loss
);
423 const struct ConfigPerfItem
* network_network_gperf_lookup(const char *key
, GPERF_LEN_TYPE length
);
425 const char* keep_configuration_to_string(KeepConfiguration i
) _const_
;
426 KeepConfiguration
keep_configuration_from_string(const char *s
) _pure_
;
428 const char* activation_policy_to_string(ActivationPolicy i
) _const_
;
429 ActivationPolicy
activation_policy_from_string(const char *s
) _pure_
;