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
;
137 int dhcp_ip_service_type
;
138 int dhcp_socket_priority
;
139 bool dhcp_socket_priority_set
;
141 bool dhcp_send_hostname
;
142 bool dhcp_send_hostname_set
;
144 int dhcp_ipv6_only_mode
;
145 int dhcp_use_rapid_commit
;
147 bool dhcp_use_dns_set
;
148 bool dhcp_routes_to_dns
;
150 bool dhcp_use_ntp_set
;
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 bool dhcp_send_release
;
164 bool dhcp_send_decline
;
165 DHCPUseDomains dhcp_use_domains
;
166 bool dhcp_use_domains_set
;
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
;
181 bool dhcp6_use_dns_set
;
182 bool dhcp6_use_hostname
;
184 bool dhcp6_use_ntp_set
;
185 bool dhcp6_use_captive_portal
;
186 bool dhcp6_use_rapid_commit
;
187 DHCPUseDomains dhcp6_use_domains
;
188 bool dhcp6_use_domains_set
;
191 bool dhcp6_iaid_set_explicitly
;
193 uint8_t dhcp6_pd_prefix_length
;
194 struct in6_addr dhcp6_pd_prefix_hint
;
195 char *dhcp6_hostname
;
197 char **dhcp6_user_class
;
198 char **dhcp6_vendor_class
;
199 DHCP6ClientStartMode dhcp6_client_start_mode
;
200 OrderedHashmap
*dhcp6_client_send_options
;
201 OrderedHashmap
*dhcp6_client_send_vendor_options
;
202 Set
*dhcp6_request_options
;
203 char *dhcp6_netlabel
;
204 bool dhcp6_send_release
;
205 NFTSetContext dhcp6_nft_set_context
;
207 /* DHCP Server Support */
209 bool dhcp_server_bind_to_interface
;
210 unsigned char dhcp_server_address_prefixlen
;
211 struct in_addr dhcp_server_address_in_addr
;
212 const Address
*dhcp_server_address
;
213 int dhcp_server_uplink_index
;
214 char *dhcp_server_uplink_name
;
215 struct in_addr dhcp_server_relay_target
;
216 char *dhcp_server_relay_agent_circuit_id
;
217 char *dhcp_server_relay_agent_remote_id
;
218 NetworkDHCPServerEmitAddress dhcp_server_emit
[_SD_DHCP_LEASE_SERVER_TYPE_MAX
];
219 bool dhcp_server_emit_router
;
220 struct in_addr dhcp_server_router
;
221 bool dhcp_server_emit_timezone
;
222 char *dhcp_server_timezone
;
223 usec_t dhcp_server_default_lease_time_usec
, dhcp_server_max_lease_time_usec
;
224 uint32_t dhcp_server_pool_offset
;
225 uint32_t dhcp_server_pool_size
;
226 OrderedHashmap
*dhcp_server_send_options
;
227 OrderedHashmap
*dhcp_server_send_vendor_options
;
228 struct in_addr dhcp_server_boot_server_address
;
229 char *dhcp_server_boot_server_name
;
230 char *dhcp_server_boot_filename
;
231 usec_t dhcp_server_ipv6_only_preferred_usec
;
232 bool dhcp_server_rapid_commit
;
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_retransmit_usec
;
246 uint8_t router_hop_limit
;
248 bool router_other_information
;
249 bool router_emit_dns
;
250 bool router_emit_domains
;
251 usec_t router_dns_lifetime_usec
;
252 struct in6_addr
*router_dns
;
253 unsigned n_router_dns
;
254 OrderedSet
*router_search_domains
;
255 int router_uplink_index
;
256 char *router_uplink_name
;
257 /* Mobile IPv6 Home Agent */
258 bool router_home_agent_information
;
259 uint16_t router_home_agent_preference
;
260 usec_t home_agent_lifetime_usec
;
262 /* DHCP Prefix Delegation support */
264 bool dhcp_pd_announce
;
266 bool dhcp_pd_manage_temporary_address
;
267 int64_t dhcp_pd_subnet_id
;
268 uint32_t dhcp_pd_route_metric
;
270 int dhcp_pd_uplink_index
;
271 char *dhcp_pd_uplink_name
;
272 char *dhcp_pd_netlabel
;
273 NFTSetContext dhcp_pd_nft_set_context
;
280 int allow_port_to_be_root
;
283 int multicast_to_unicast
;
284 int neighbor_suppression
;
286 int bridge_proxy_arp
;
287 int bridge_proxy_arp_wifi
;
290 MulticastRouter multicast_router
;
293 uint16_t bridge_vlan_pvid
;
294 uint32_t bridge_vlan_bitmap
[BRIDGE_VLAN_BITMAP_LEN
];
295 uint32_t bridge_vlan_untagged_bitmap
[BRIDGE_VLAN_BITMAP_LEN
];
298 uint32_t can_bitrate
;
299 unsigned can_sample_point
;
300 nsec_t can_time_quanta_ns
;
301 uint32_t can_propagation_segment
;
302 uint32_t can_phase_buffer_segment_1
;
303 uint32_t can_phase_buffer_segment_2
;
304 uint32_t can_sync_jump_width
;
305 uint32_t can_data_bitrate
;
306 unsigned can_data_sample_point
;
307 nsec_t can_data_time_quanta_ns
;
308 uint32_t can_data_propagation_segment
;
309 uint32_t can_data_phase_buffer_segment_1
;
310 uint32_t can_data_phase_buffer_segment_2
;
311 uint32_t can_data_sync_jump_width
;
312 usec_t can_restart_us
;
313 uint32_t can_control_mode_mask
;
314 uint32_t can_control_mode_flags
;
315 uint16_t can_termination
;
316 bool can_termination_set
;
319 IPoIBMode ipoib_mode
;
322 /* sysctl settings */
323 int ip_forwarding
[2];
324 int ipv4_accept_local
;
325 int ipv4_route_localnet
;
326 int ipv6_dad_transmits
;
327 uint8_t ipv6_hop_limit
;
328 usec_t ipv6_retransmission_time
;
332 IPv6PrivacyExtensions ipv6_privacy_extensions
;
333 IPReversePathFilter ipv4_rp_filter
;
335 Set
*ipv6_proxy_ndp_addresses
;
340 bool ndisc_use_gateway
;
341 bool ndisc_use_route_prefix
;
342 bool ndisc_use_autonomous_prefix
;
343 bool ndisc_use_onlink_prefix
;
345 bool ndisc_use_hop_limit
;
346 bool ndisc_use_reachable_time
;
347 bool ndisc_use_retransmission_time
;
348 bool ndisc_use_icmp6_ratelimit
;
350 bool ndisc_use_captive_portal
;
351 bool ndisc_use_pref64
;
354 DHCPUseDomains ndisc_use_domains
;
355 IPv6AcceptRAStartDHCP6Client ndisc_start_dhcp6_client
;
356 uint32_t ndisc_route_table
;
357 bool ndisc_route_table_set
;
358 uint32_t ndisc_route_metric_high
;
359 uint32_t ndisc_route_metric_medium
;
360 uint32_t ndisc_route_metric_low
;
361 bool ndisc_route_metric_set
;
362 Set
*ndisc_deny_listed_router
;
363 Set
*ndisc_allow_listed_router
;
364 Set
*ndisc_deny_listed_prefix
;
365 Set
*ndisc_allow_listed_prefix
;
366 Set
*ndisc_deny_listed_route_prefix
;
367 Set
*ndisc_allow_listed_route_prefix
;
369 char *ndisc_netlabel
;
370 NFTSetContext ndisc_nft_set_context
;
373 LLDPMode lldp_mode
; /* LLDP reception */
374 sd_lldp_multicast_mode_t lldp_multicast_mode
; /* LLDP transmission */
375 char *lldp_mudurl
; /* LLDP MUD URL */
377 OrderedHashmap
*addresses_by_section
;
378 Hashmap
*routes_by_section
;
379 OrderedHashmap
*nexthops_by_section
;
380 Hashmap
*bridge_fdb_entries_by_section
;
381 Hashmap
*bridge_mdb_entries_by_section
;
382 OrderedHashmap
*neighbors_by_section
;
383 Hashmap
*address_labels_by_section
;
384 Hashmap
*prefixes_by_section
;
385 Hashmap
*route_prefixes_by_section
;
386 Hashmap
*pref64_prefixes_by_section
;
387 Hashmap
*rules_by_section
;
388 Hashmap
*dhcp_static_leases_by_section
;
389 Hashmap
*qdiscs_by_section
;
390 Hashmap
*tclasses_by_section
;
391 OrderedHashmap
*sr_iov_by_section
;
393 /* All kinds of DNS configuration */
394 struct in_addr_full
**dns
;
396 OrderedSet
*search_domains
, *route_domains
;
397 int dns_default_route
;
398 ResolveSupport llmnr
;
400 DnssecMode dnssec_mode
;
401 DnsOverTlsMode dns_over_tls_mode
;
402 Set
*dnssec_negative_trust_anchors
;
408 Network
*network_ref(Network
*network
);
409 Network
*network_unref(Network
*network
);
410 DEFINE_TRIVIAL_CLEANUP_FUNC(Network
*, network_unref
);
412 int network_load(Manager
*manager
, OrderedHashmap
**networks
);
413 int network_reload(Manager
*manager
);
414 int network_load_one(Manager
*manager
, OrderedHashmap
**networks
, const char *filename
);
415 int network_verify(Network
*network
);
417 int manager_build_dhcp_pd_subnet_ids(Manager
*manager
);
419 int network_get_by_name(Manager
*manager
, const char *name
, Network
**ret
);
420 void network_apply_anonymize_if_set(Network
*network
);
422 bool network_has_static_ipv6_configurations(Network
*network
);
424 CONFIG_PARSER_PROTOTYPE(config_parse_stacked_netdev
);
425 CONFIG_PARSER_PROTOTYPE(config_parse_tunnel
);
426 CONFIG_PARSER_PROTOTYPE(config_parse_domains
);
427 CONFIG_PARSER_PROTOTYPE(config_parse_dns
);
428 CONFIG_PARSER_PROTOTYPE(config_parse_timezone
);
429 CONFIG_PARSER_PROTOTYPE(config_parse_dnssec_negative_trust_anchors
);
430 CONFIG_PARSER_PROTOTYPE(config_parse_ntp
);
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_
;