1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
4 #include <linux/nl80211.h>
10 #include "condition.h"
11 #include "conf-parser.h"
13 #include "net-condition.h"
15 #include "networkd-bridge-vlan.h"
16 #include "networkd-dhcp-common.h"
17 #include "networkd-dhcp4.h"
18 #include "networkd-dhcp6.h"
19 #include "networkd-lldp-rx.h"
20 #include "networkd-lldp-tx.h"
21 #include "networkd-ndisc.h"
22 #include "networkd-radv.h"
23 #include "networkd-sysctl.h"
24 #include "networkd-util.h"
25 #include "ordered-set.h"
26 #include "resolve-util.h"
27 #include "socket-netlink.h"
29 /* Special values for *_uplink_index. */
30 #define UPLINK_INDEX_AUTO 0 /* uplink will be selected automatically */
31 #define UPLINK_INDEX_NONE -1 /* uplink will not be selected automatically */
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 IPv6LinkLocalAddressGenMode
{
45 IPV6_LINK_LOCAL_ADDRESSS_GEN_MODE_EUI64
= IN6_ADDR_GEN_MODE_EUI64
,
46 IPV6_LINK_LOCAL_ADDRESSS_GEN_MODE_NONE
= IN6_ADDR_GEN_MODE_NONE
,
47 IPV6_LINK_LOCAL_ADDRESSS_GEN_MODE_STABLE_PRIVACY
= IN6_ADDR_GEN_MODE_STABLE_PRIVACY
,
48 IPV6_LINK_LOCAL_ADDRESSS_GEN_MODE_RANDOM
= IN6_ADDR_GEN_MODE_RANDOM
,
49 _IPV6_LINK_LOCAL_ADDRESS_GEN_MODE_MAX
,
50 _IPV6_LINK_LOCAL_ADDRESS_GEN_MODE_INVALID
= -EINVAL
,
51 } IPv6LinkLocalAddressGenMode
;
53 typedef enum ActivationPolicy
{
55 ACTIVATION_POLICY_ALWAYS_UP
,
56 ACTIVATION_POLICY_MANUAL
,
57 ACTIVATION_POLICY_ALWAYS_DOWN
,
58 ACTIVATION_POLICY_DOWN
,
59 ACTIVATION_POLICY_BOUND
,
60 _ACTIVATION_POLICY_MAX
,
61 _ACTIVATION_POLICY_INVALID
= -EINVAL
,
64 typedef struct Manager Manager
;
66 typedef struct NetworkDHCPServerEmitAddress
{
68 struct in_addr
*addresses
;
70 } NetworkDHCPServerEmitAddress
;
84 LIST_HEAD(Condition
, conditions
);
86 /* Master or stacked netdevs */
92 Hashmap
*stacked_netdevs
;
97 Hashmap
*stacked_netdev_names
;
100 struct ether_addr
*mac
;
109 int required_for_online
; /* Is this network required to be considered online? */
110 LinkOperationalStateRange required_operstate_for_online
;
111 AddressFamily required_family_for_online
;
112 ActivationPolicy activation_policy
;
115 bool configure_without_carrier
;
116 int ignore_carrier_loss
;
117 KeepConfiguration keep_configuration
;
119 bool default_route_on_device
;
120 AddressFamily ip_masquerade
;
122 /* DHCP Client Support */
124 DHCPClientIdentifier dhcp_client_identifier
;
128 char *dhcp_vendor_class_identifier
;
130 char **dhcp_user_class
;
132 uint64_t dhcp_max_attempts
;
133 uint32_t dhcp_route_metric
;
134 bool dhcp_route_metric_set
;
135 uint32_t dhcp_route_table
;
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_route_table_set
;
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 /* DHCPv6 Client support */
168 bool dhcp6_use_address
;
170 bool dhcp6_use_dns_set
;
171 bool dhcp6_use_hostname
;
173 bool dhcp6_use_ntp_set
;
174 bool dhcp6_rapid_commit
;
175 DHCPUseDomains dhcp6_use_domains
;
176 bool dhcp6_use_domains_set
;
179 bool dhcp6_iaid_set_explicitly
;
181 uint8_t dhcp6_pd_length
;
183 char **dhcp6_user_class
;
184 char **dhcp6_vendor_class
;
185 struct in6_addr dhcp6_pd_address
;
186 DHCP6ClientStartMode dhcp6_without_ra
;
187 OrderedHashmap
*dhcp6_client_send_options
;
188 OrderedHashmap
*dhcp6_client_send_vendor_options
;
189 Set
*dhcp6_request_options
;
190 /* Start DHCPv6 PD also when 'O' RA flag is set, see RFC 7084, WPD-4 */
191 bool dhcp6_force_pd_other_information
;
193 /* DHCP Server Support */
195 bool dhcp_server_bind_to_interface
;
196 unsigned char dhcp_server_address_prefixlen
;
197 struct in_addr dhcp_server_address
;
198 int dhcp_server_uplink_index
;
199 char *dhcp_server_uplink_name
;
200 struct in_addr dhcp_server_relay_target
;
201 char *dhcp_server_relay_agent_circuit_id
;
202 char *dhcp_server_relay_agent_remote_id
;
203 NetworkDHCPServerEmitAddress dhcp_server_emit
[_SD_DHCP_LEASE_SERVER_TYPE_MAX
];
204 bool dhcp_server_emit_router
;
205 bool dhcp_server_emit_timezone
;
206 char *dhcp_server_timezone
;
207 usec_t dhcp_server_default_lease_time_usec
, dhcp_server_max_lease_time_usec
;
208 uint32_t dhcp_server_pool_offset
;
209 uint32_t dhcp_server_pool_size
;
210 OrderedHashmap
*dhcp_server_send_options
;
211 OrderedHashmap
*dhcp_server_send_vendor_options
;
213 /* link local addressing support */
214 AddressFamily link_local
;
215 IPv6LinkLocalAddressGenMode ipv6ll_address_gen_mode
;
216 struct in6_addr ipv6ll_stable_secret
;
219 /* IPv6 RA support */
220 RADVPrefixDelegation router_prefix_delegation
;
221 usec_t router_lifetime_usec
;
222 uint8_t router_preference
;
224 bool router_other_information
;
225 bool router_emit_dns
;
226 bool router_emit_domains
;
227 usec_t router_dns_lifetime_usec
;
228 struct in6_addr
*router_dns
;
229 unsigned n_router_dns
;
230 OrderedSet
*router_search_domains
;
231 int router_uplink_index
;
232 char *router_uplink_name
;
234 /* DHCPv6 Prefix Delegation support */
236 bool dhcp6_pd_announce
;
237 bool dhcp6_pd_assign
;
238 bool dhcp6_pd_manage_temporary_address
;
239 int64_t dhcp6_pd_subnet_id
;
240 uint32_t dhcp6_pd_route_metric
;
241 struct in6_addr dhcp6_pd_token
;
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
;
286 /* sysctl settings */
287 AddressFamily ip_forward
;
288 int ipv4_accept_local
;
289 int ipv4_route_localnet
;
290 int ipv6_dad_transmits
;
294 IPv6PrivacyExtensions ipv6_privacy_extensions
;
296 Set
*ipv6_proxy_ndp_addresses
;
300 bool ipv6_accept_ra_use_dns
;
301 bool ipv6_accept_ra_use_autonomous_prefix
;
302 bool ipv6_accept_ra_use_onlink_prefix
;
305 DHCPUseDomains ipv6_accept_ra_use_domains
;
306 IPv6AcceptRAStartDHCP6Client ipv6_accept_ra_start_dhcp6_client
;
307 uint32_t ipv6_accept_ra_route_table
;
308 bool ipv6_accept_ra_route_table_set
;
309 uint32_t ipv6_accept_ra_route_metric
;
310 bool ipv6_accept_ra_route_metric_set
;
311 Set
*ndisc_deny_listed_router
;
312 Set
*ndisc_allow_listed_router
;
313 Set
*ndisc_deny_listed_prefix
;
314 Set
*ndisc_allow_listed_prefix
;
315 Set
*ndisc_deny_listed_route_prefix
;
316 Set
*ndisc_allow_listed_route_prefix
;
317 OrderedSet
*ipv6_tokens
;
320 LLDPMode lldp_mode
; /* LLDP reception */
321 LLDPEmit lldp_emit
; /* LLDP transmission */
322 char *lldp_mud
; /* LLDP MUD URL */
324 OrderedHashmap
*addresses_by_section
;
325 Hashmap
*routes_by_section
;
326 Hashmap
*nexthops_by_section
;
327 Hashmap
*bridge_fdb_entries_by_section
;
328 Hashmap
*bridge_mdb_entries_by_section
;
329 Hashmap
*neighbors_by_section
;
330 Hashmap
*address_labels_by_section
;
331 Hashmap
*prefixes_by_section
;
332 Hashmap
*route_prefixes_by_section
;
333 Hashmap
*rules_by_section
;
334 Hashmap
*dhcp_static_leases_by_section
;
335 OrderedHashmap
*tc_by_section
;
336 OrderedHashmap
*sr_iov_by_section
;
338 /* All kinds of DNS configuration */
339 struct in_addr_full
**dns
;
341 OrderedSet
*search_domains
, *route_domains
;
342 int dns_default_route
;
343 ResolveSupport llmnr
;
345 DnssecMode dnssec_mode
;
346 DnsOverTlsMode dns_over_tls_mode
;
347 Set
*dnssec_negative_trust_anchors
;
353 Network
*network_ref(Network
*network
);
354 Network
*network_unref(Network
*network
);
355 DEFINE_TRIVIAL_CLEANUP_FUNC(Network
*, network_unref
);
357 int network_load(Manager
*manager
, OrderedHashmap
**networks
);
358 int network_reload(Manager
*manager
);
359 int network_load_one(Manager
*manager
, OrderedHashmap
**networks
, const char *filename
);
360 int network_verify(Network
*network
);
362 int network_get_by_name(Manager
*manager
, const char *name
, Network
**ret
);
363 void network_apply_anonymize_if_set(Network
*network
);
365 bool network_has_static_ipv6_configurations(Network
*network
);
367 CONFIG_PARSER_PROTOTYPE(config_parse_stacked_netdev
);
368 CONFIG_PARSER_PROTOTYPE(config_parse_tunnel
);
369 CONFIG_PARSER_PROTOTYPE(config_parse_domains
);
370 CONFIG_PARSER_PROTOTYPE(config_parse_dns
);
371 CONFIG_PARSER_PROTOTYPE(config_parse_hostname
);
372 CONFIG_PARSER_PROTOTYPE(config_parse_timezone
);
373 CONFIG_PARSER_PROTOTYPE(config_parse_dnssec_negative_trust_anchors
);
374 CONFIG_PARSER_PROTOTYPE(config_parse_ntp
);
375 CONFIG_PARSER_PROTOTYPE(config_parse_required_for_online
);
376 CONFIG_PARSER_PROTOTYPE(config_parse_required_family_for_online
);
377 CONFIG_PARSER_PROTOTYPE(config_parse_keep_configuration
);
378 CONFIG_PARSER_PROTOTYPE(config_parse_ipv6_link_local_address_gen_mode
);
379 CONFIG_PARSER_PROTOTYPE(config_parse_activation_policy
);
380 CONFIG_PARSER_PROTOTYPE(config_parse_link_group
);
381 CONFIG_PARSER_PROTOTYPE(config_parse_uplink
);
383 const struct ConfigPerfItem
* network_network_gperf_lookup(const char *key
, GPERF_LEN_TYPE length
);
385 const char* keep_configuration_to_string(KeepConfiguration i
) _const_
;
386 KeepConfiguration
keep_configuration_from_string(const char *s
) _pure_
;
388 const char* ipv6_link_local_address_gen_mode_to_string(IPv6LinkLocalAddressGenMode s
) _const_
;
389 IPv6LinkLocalAddressGenMode
ipv6_link_local_address_gen_mode_from_string(const char *s
) _pure_
;
391 const char* activation_policy_to_string(ActivationPolicy i
) _const_
;
392 ActivationPolicy
activation_policy_from_string(const char *s
) _pure_
;