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"
15 #include "net-condition.h"
17 #include "networkd-bridge-vlan.h"
18 #include "networkd-dhcp-common.h"
19 #include "networkd-dhcp4.h"
20 #include "networkd-dhcp6.h"
21 #include "networkd-lldp-rx.h"
22 #include "networkd-ndisc.h"
23 #include "networkd-radv.h"
24 #include "networkd-sysctl.h"
25 #include "networkd-util.h"
26 #include "ordered-set.h"
27 #include "resolve-util.h"
28 #include "socket-netlink.h"
30 typedef enum KeepConfiguration
{
31 KEEP_CONFIGURATION_NO
= 0,
32 KEEP_CONFIGURATION_DHCP_ON_START
= 1 << 0,
33 KEEP_CONFIGURATION_DHCP_ON_STOP
= 1 << 1,
34 KEEP_CONFIGURATION_DHCP
= KEEP_CONFIGURATION_DHCP_ON_START
| KEEP_CONFIGURATION_DHCP_ON_STOP
,
35 KEEP_CONFIGURATION_STATIC
= 1 << 2,
36 KEEP_CONFIGURATION_YES
= KEEP_CONFIGURATION_DHCP
| KEEP_CONFIGURATION_STATIC
,
37 _KEEP_CONFIGURATION_MAX
,
38 _KEEP_CONFIGURATION_INVALID
= -EINVAL
,
41 typedef enum IPv6LinkLocalAddressGenMode
{
42 IPV6_LINK_LOCAL_ADDRESSS_GEN_MODE_EUI64
= IN6_ADDR_GEN_MODE_EUI64
,
43 IPV6_LINK_LOCAL_ADDRESSS_GEN_MODE_NONE
= IN6_ADDR_GEN_MODE_NONE
,
44 IPV6_LINK_LOCAL_ADDRESSS_GEN_MODE_STABLE_PRIVACY
= IN6_ADDR_GEN_MODE_STABLE_PRIVACY
,
45 IPV6_LINK_LOCAL_ADDRESSS_GEN_MODE_RANDOM
= IN6_ADDR_GEN_MODE_RANDOM
,
46 _IPV6_LINK_LOCAL_ADDRESS_GEN_MODE_MAX
,
47 _IPV6_LINK_LOCAL_ADDRESS_GEN_MODE_INVALID
= -EINVAL
,
48 } IPv6LinkLocalAddressGenMode
;
50 typedef enum ActivationPolicy
{
52 ACTIVATION_POLICY_ALWAYS_UP
,
53 ACTIVATION_POLICY_MANUAL
,
54 ACTIVATION_POLICY_ALWAYS_DOWN
,
55 ACTIVATION_POLICY_DOWN
,
56 ACTIVATION_POLICY_BOUND
,
57 _ACTIVATION_POLICY_MAX
,
58 _ACTIVATION_POLICY_INVALID
= -EINVAL
,
61 typedef struct Manager Manager
;
63 typedef struct NetworkDHCPServerEmitAddress
{
65 struct in_addr
*addresses
;
67 } NetworkDHCPServerEmitAddress
;
76 Hashmap
*stats_by_path
;
81 LIST_HEAD(Condition
, conditions
);
83 /* Master or stacked netdevs */
90 Hashmap
*stacked_netdevs
;
95 Hashmap
*stacked_netdev_names
;
98 struct hw_addr_data hw_addr
;
106 int required_for_online
; /* Is this network required to be considered online? */
107 LinkOperationalStateRange required_operstate_for_online
;
108 AddressFamily required_family_for_online
;
109 ActivationPolicy activation_policy
;
112 bool configure_without_carrier
;
113 bool ignore_carrier_loss_set
;
114 usec_t ignore_carrier_loss_usec
; /* timespan */
115 KeepConfiguration keep_configuration
;
117 bool default_route_on_device
;
118 AddressFamily ip_masquerade
;
120 /* DHCP Client Support */
122 DHCPClientIdentifier dhcp_client_identifier
;
126 char *dhcp_vendor_class_identifier
;
128 char **dhcp_user_class
;
131 uint64_t dhcp_max_attempts
;
132 uint32_t dhcp_route_metric
;
133 bool dhcp_route_metric_set
;
134 uint32_t dhcp_route_table
;
135 bool dhcp_route_table_set
;
136 uint32_t dhcp_fallback_lease_lifetime
;
137 uint32_t dhcp_route_mtu
;
138 uint16_t dhcp_client_port
;
140 int dhcp_ip_service_type
;
142 bool dhcp_send_hostname
;
145 bool dhcp_use_dns_set
;
146 bool dhcp_routes_to_dns
;
148 bool dhcp_use_ntp_set
;
149 bool dhcp_routes_to_ntp
;
152 bool dhcp_use_routes
;
153 int dhcp_use_gateway
;
154 bool dhcp_use_timezone
;
155 bool dhcp_use_hostname
;
156 bool dhcp_send_release
;
157 bool dhcp_send_decline
;
158 DHCPUseDomains dhcp_use_domains
;
159 bool dhcp_use_domains_set
;
160 Set
*dhcp_deny_listed_ip
;
161 Set
*dhcp_allow_listed_ip
;
162 Set
*dhcp_request_options
;
163 OrderedHashmap
*dhcp_client_send_options
;
164 OrderedHashmap
*dhcp_client_send_vendor_options
;
166 /* DHCPv6 Client support */
167 bool dhcp6_use_address
;
168 bool dhcp6_use_pd_prefix
;
170 bool dhcp6_use_dns_set
;
171 bool dhcp6_use_hostname
;
173 bool dhcp6_use_ntp_set
;
174 DHCPUseDomains dhcp6_use_domains
;
175 bool dhcp6_use_domains_set
;
178 bool dhcp6_iaid_set_explicitly
;
180 uint8_t dhcp6_pd_prefix_length
;
181 struct in6_addr dhcp6_pd_prefix_hint
;
183 char **dhcp6_user_class
;
184 char **dhcp6_vendor_class
;
185 DHCP6ClientStartMode dhcp6_client_start_mode
;
186 OrderedHashmap
*dhcp6_client_send_options
;
187 OrderedHashmap
*dhcp6_client_send_vendor_options
;
188 Set
*dhcp6_request_options
;
190 /* DHCP Server Support */
192 bool dhcp_server_bind_to_interface
;
193 unsigned char dhcp_server_address_prefixlen
;
194 struct in_addr dhcp_server_address
;
195 int dhcp_server_uplink_index
;
196 char *dhcp_server_uplink_name
;
197 struct in_addr dhcp_server_relay_target
;
198 char *dhcp_server_relay_agent_circuit_id
;
199 char *dhcp_server_relay_agent_remote_id
;
200 NetworkDHCPServerEmitAddress dhcp_server_emit
[_SD_DHCP_LEASE_SERVER_TYPE_MAX
];
201 bool dhcp_server_emit_router
;
202 struct in_addr dhcp_server_router
;
203 bool dhcp_server_emit_timezone
;
204 char *dhcp_server_timezone
;
205 usec_t dhcp_server_default_lease_time_usec
, dhcp_server_max_lease_time_usec
;
206 uint32_t dhcp_server_pool_offset
;
207 uint32_t dhcp_server_pool_size
;
208 OrderedHashmap
*dhcp_server_send_options
;
209 OrderedHashmap
*dhcp_server_send_vendor_options
;
211 /* link local addressing support */
212 AddressFamily link_local
;
213 IPv6LinkLocalAddressGenMode ipv6ll_address_gen_mode
;
214 struct in6_addr ipv6ll_stable_secret
;
217 /* IPv6 RA support */
218 RADVPrefixDelegation router_prefix_delegation
;
219 usec_t router_lifetime_usec
;
220 uint8_t router_preference
;
222 bool router_other_information
;
223 bool router_emit_dns
;
224 bool router_emit_domains
;
225 usec_t router_dns_lifetime_usec
;
226 struct in6_addr
*router_dns
;
227 unsigned n_router_dns
;
228 OrderedSet
*router_search_domains
;
229 int router_uplink_index
;
230 char *router_uplink_name
;
232 /* DHCPv6 Prefix Delegation support */
234 bool dhcp6_pd_announce
;
235 bool dhcp6_pd_assign
;
236 bool dhcp6_pd_manage_temporary_address
;
237 int64_t dhcp6_pd_subnet_id
;
238 uint32_t dhcp6_pd_route_metric
;
239 Set
*dhcp6_pd_tokens
;
240 int dhcp6_pd_uplink_index
;
241 char *dhcp6_pd_uplink_name
;
247 int allow_port_to_be_root
;
250 int multicast_to_unicast
;
251 int neighbor_suppression
;
253 int bridge_proxy_arp
;
254 int bridge_proxy_arp_wifi
;
257 MulticastRouter multicast_router
;
262 uint32_t br_vid_bitmap
[BRIDGE_VLAN_BITMAP_LEN
];
263 uint32_t br_untagged_bitmap
[BRIDGE_VLAN_BITMAP_LEN
];
266 uint32_t can_bitrate
;
267 unsigned can_sample_point
;
268 nsec_t can_time_quanta_ns
;
269 uint32_t can_propagation_segment
;
270 uint32_t can_phase_buffer_segment_1
;
271 uint32_t can_phase_buffer_segment_2
;
272 uint32_t can_sync_jump_width
;
273 uint32_t can_data_bitrate
;
274 unsigned can_data_sample_point
;
275 nsec_t can_data_time_quanta_ns
;
276 uint32_t can_data_propagation_segment
;
277 uint32_t can_data_phase_buffer_segment_1
;
278 uint32_t can_data_phase_buffer_segment_2
;
279 uint32_t can_data_sync_jump_width
;
280 usec_t can_restart_us
;
281 uint32_t can_control_mode_mask
;
282 uint32_t can_control_mode_flags
;
283 uint16_t can_termination
;
284 bool can_termination_set
;
287 IPoIBMode ipoib_mode
;
290 /* sysctl settings */
291 AddressFamily ip_forward
;
292 int ipv4_accept_local
;
293 int ipv4_route_localnet
;
294 int ipv6_dad_transmits
;
298 IPv6PrivacyExtensions ipv6_privacy_extensions
;
300 Set
*ipv6_proxy_ndp_addresses
;
304 bool ipv6_accept_ra_use_dns
;
305 bool ipv6_accept_ra_use_gateway
;
306 bool ipv6_accept_ra_use_route_prefix
;
307 bool ipv6_accept_ra_use_autonomous_prefix
;
308 bool ipv6_accept_ra_use_onlink_prefix
;
309 bool ipv6_accept_ra_use_mtu
;
312 DHCPUseDomains ipv6_accept_ra_use_domains
;
313 IPv6AcceptRAStartDHCP6Client ipv6_accept_ra_start_dhcp6_client
;
314 uint32_t ipv6_accept_ra_route_table
;
315 bool ipv6_accept_ra_route_table_set
;
316 uint32_t ipv6_accept_ra_route_metric
;
317 bool ipv6_accept_ra_route_metric_set
;
318 Set
*ndisc_deny_listed_router
;
319 Set
*ndisc_allow_listed_router
;
320 Set
*ndisc_deny_listed_prefix
;
321 Set
*ndisc_allow_listed_prefix
;
322 Set
*ndisc_deny_listed_route_prefix
;
323 Set
*ndisc_allow_listed_route_prefix
;
327 LLDPMode lldp_mode
; /* LLDP reception */
328 sd_lldp_multicast_mode_t lldp_multicast_mode
; /* LLDP transmission */
329 char *lldp_mudurl
; /* LLDP MUD URL */
331 OrderedHashmap
*addresses_by_section
;
332 Hashmap
*routes_by_section
;
333 Hashmap
*nexthops_by_section
;
334 Hashmap
*bridge_fdb_entries_by_section
;
335 Hashmap
*bridge_mdb_entries_by_section
;
336 Hashmap
*neighbors_by_section
;
337 Hashmap
*address_labels_by_section
;
338 Hashmap
*prefixes_by_section
;
339 Hashmap
*route_prefixes_by_section
;
340 Hashmap
*rules_by_section
;
341 Hashmap
*dhcp_static_leases_by_section
;
342 OrderedHashmap
*tc_by_section
;
343 OrderedHashmap
*sr_iov_by_section
;
345 /* All kinds of DNS configuration */
346 struct in_addr_full
**dns
;
348 OrderedSet
*search_domains
, *route_domains
;
349 int dns_default_route
;
350 ResolveSupport llmnr
;
352 DnssecMode dnssec_mode
;
353 DnsOverTlsMode dns_over_tls_mode
;
354 Set
*dnssec_negative_trust_anchors
;
360 Network
*network_ref(Network
*network
);
361 Network
*network_unref(Network
*network
);
362 DEFINE_TRIVIAL_CLEANUP_FUNC(Network
*, network_unref
);
364 int network_load(Manager
*manager
, OrderedHashmap
**networks
);
365 int network_reload(Manager
*manager
);
366 int network_load_one(Manager
*manager
, OrderedHashmap
**networks
, const char *filename
);
367 int network_verify(Network
*network
);
369 int manager_build_dhcp6_pd_subnet_ids(Manager
*manager
);
371 int network_get_by_name(Manager
*manager
, const char *name
, Network
**ret
);
372 void network_apply_anonymize_if_set(Network
*network
);
374 bool network_has_static_ipv6_configurations(Network
*network
);
376 CONFIG_PARSER_PROTOTYPE(config_parse_stacked_netdev
);
377 CONFIG_PARSER_PROTOTYPE(config_parse_tunnel
);
378 CONFIG_PARSER_PROTOTYPE(config_parse_domains
);
379 CONFIG_PARSER_PROTOTYPE(config_parse_dns
);
380 CONFIG_PARSER_PROTOTYPE(config_parse_hostname
);
381 CONFIG_PARSER_PROTOTYPE(config_parse_timezone
);
382 CONFIG_PARSER_PROTOTYPE(config_parse_dnssec_negative_trust_anchors
);
383 CONFIG_PARSER_PROTOTYPE(config_parse_ntp
);
384 CONFIG_PARSER_PROTOTYPE(config_parse_required_for_online
);
385 CONFIG_PARSER_PROTOTYPE(config_parse_required_family_for_online
);
386 CONFIG_PARSER_PROTOTYPE(config_parse_keep_configuration
);
387 CONFIG_PARSER_PROTOTYPE(config_parse_ipv6_link_local_address_gen_mode
);
388 CONFIG_PARSER_PROTOTYPE(config_parse_activation_policy
);
389 CONFIG_PARSER_PROTOTYPE(config_parse_link_group
);
390 CONFIG_PARSER_PROTOTYPE(config_parse_ignore_carrier_loss
);
392 const struct ConfigPerfItem
* network_network_gperf_lookup(const char *key
, GPERF_LEN_TYPE length
);
394 const char* keep_configuration_to_string(KeepConfiguration i
) _const_
;
395 KeepConfiguration
keep_configuration_from_string(const char *s
) _pure_
;
397 const char* ipv6_link_local_address_gen_mode_to_string(IPv6LinkLocalAddressGenMode s
) _const_
;
398 IPv6LinkLocalAddressGenMode
ipv6_link_local_address_gen_mode_from_string(const char *s
) _pure_
;
400 const char* activation_policy_to_string(ActivationPolicy i
) _const_
;
401 ActivationPolicy
activation_policy_from_string(const char *s
) _pure_
;