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-ipv6ll.h"
22 #include "networkd-lldp-rx.h"
23 #include "networkd-ndisc.h"
24 #include "networkd-radv.h"
25 #include "networkd-sysctl.h"
26 #include "networkd-util.h"
27 #include "ordered-set.h"
28 #include "resolve-util.h"
29 #include "socket-netlink.h"
31 typedef enum KeepConfiguration
{
32 KEEP_CONFIGURATION_NO
= 0,
33 KEEP_CONFIGURATION_DHCP_ON_START
= 1 << 0,
34 KEEP_CONFIGURATION_DHCP_ON_STOP
= 1 << 1,
35 KEEP_CONFIGURATION_DHCP
= KEEP_CONFIGURATION_DHCP_ON_START
| KEEP_CONFIGURATION_DHCP_ON_STOP
,
36 KEEP_CONFIGURATION_STATIC
= 1 << 2,
37 KEEP_CONFIGURATION_YES
= KEEP_CONFIGURATION_DHCP
| KEEP_CONFIGURATION_STATIC
,
38 _KEEP_CONFIGURATION_MAX
,
39 _KEEP_CONFIGURATION_INVALID
= -EINVAL
,
42 typedef enum ActivationPolicy
{
44 ACTIVATION_POLICY_ALWAYS_UP
,
45 ACTIVATION_POLICY_MANUAL
,
46 ACTIVATION_POLICY_ALWAYS_DOWN
,
47 ACTIVATION_POLICY_DOWN
,
48 ACTIVATION_POLICY_BOUND
,
49 _ACTIVATION_POLICY_MAX
,
50 _ACTIVATION_POLICY_INVALID
= -EINVAL
,
53 typedef struct Manager Manager
;
55 typedef struct NetworkDHCPServerEmitAddress
{
57 struct in_addr
*addresses
;
59 } NetworkDHCPServerEmitAddress
;
68 Hashmap
*stats_by_path
;
73 LIST_HEAD(Condition
, conditions
);
75 /* Master or stacked netdevs */
82 Hashmap
*stacked_netdevs
;
87 Hashmap
*stacked_netdev_names
;
90 struct hw_addr_data hw_addr
;
98 int required_for_online
; /* Is this network required to be considered online? */
99 LinkOperationalStateRange required_operstate_for_online
;
100 AddressFamily required_family_for_online
;
101 ActivationPolicy activation_policy
;
104 bool configure_without_carrier
;
105 bool ignore_carrier_loss_set
;
106 usec_t ignore_carrier_loss_usec
; /* timespan */
107 KeepConfiguration keep_configuration
;
109 bool default_route_on_device
;
110 AddressFamily ip_masquerade
;
112 /* DHCP Client Support */
114 DHCPClientIdentifier dhcp_client_identifier
;
118 char *dhcp_vendor_class_identifier
;
120 char **dhcp_user_class
;
123 uint64_t dhcp_max_attempts
;
124 uint32_t dhcp_route_metric
;
125 bool dhcp_route_metric_set
;
126 uint32_t dhcp_route_table
;
127 bool dhcp_route_table_set
;
128 uint32_t dhcp_fallback_lease_lifetime
;
129 uint32_t dhcp_route_mtu
;
130 uint16_t dhcp_client_port
;
132 int dhcp_ip_service_type
;
134 bool dhcp_send_hostname
;
137 bool dhcp_use_dns_set
;
138 bool dhcp_routes_to_dns
;
140 bool dhcp_use_ntp_set
;
141 bool dhcp_routes_to_ntp
;
144 bool dhcp_use_routes
;
145 int dhcp_use_gateway
;
146 bool dhcp_use_timezone
;
147 bool dhcp_use_hostname
;
149 bool dhcp_send_release
;
150 bool dhcp_send_decline
;
151 DHCPUseDomains dhcp_use_domains
;
152 bool dhcp_use_domains_set
;
153 Set
*dhcp_deny_listed_ip
;
154 Set
*dhcp_allow_listed_ip
;
155 Set
*dhcp_request_options
;
156 OrderedHashmap
*dhcp_client_send_options
;
157 OrderedHashmap
*dhcp_client_send_vendor_options
;
159 /* DHCPv6 Client support */
160 bool dhcp6_use_address
;
161 bool dhcp6_use_pd_prefix
;
163 bool dhcp6_use_dns_set
;
164 bool dhcp6_use_hostname
;
166 bool dhcp6_use_ntp_set
;
167 DHCPUseDomains dhcp6_use_domains
;
168 bool dhcp6_use_domains_set
;
171 bool dhcp6_iaid_set_explicitly
;
173 uint8_t dhcp6_pd_prefix_length
;
174 struct in6_addr dhcp6_pd_prefix_hint
;
176 char **dhcp6_user_class
;
177 char **dhcp6_vendor_class
;
178 DHCP6ClientStartMode dhcp6_client_start_mode
;
179 OrderedHashmap
*dhcp6_client_send_options
;
180 OrderedHashmap
*dhcp6_client_send_vendor_options
;
181 Set
*dhcp6_request_options
;
183 /* DHCP Server Support */
185 bool dhcp_server_bind_to_interface
;
186 unsigned char dhcp_server_address_prefixlen
;
187 struct in_addr dhcp_server_address
;
188 int dhcp_server_uplink_index
;
189 char *dhcp_server_uplink_name
;
190 struct in_addr dhcp_server_relay_target
;
191 char *dhcp_server_relay_agent_circuit_id
;
192 char *dhcp_server_relay_agent_remote_id
;
193 NetworkDHCPServerEmitAddress dhcp_server_emit
[_SD_DHCP_LEASE_SERVER_TYPE_MAX
];
194 bool dhcp_server_emit_router
;
195 struct in_addr dhcp_server_router
;
196 bool dhcp_server_emit_timezone
;
197 char *dhcp_server_timezone
;
198 usec_t dhcp_server_default_lease_time_usec
, dhcp_server_max_lease_time_usec
;
199 uint32_t dhcp_server_pool_offset
;
200 uint32_t dhcp_server_pool_size
;
201 OrderedHashmap
*dhcp_server_send_options
;
202 OrderedHashmap
*dhcp_server_send_vendor_options
;
203 struct in_addr dhcp_server_boot_server_address
;
204 char *dhcp_server_boot_server_name
;
205 char *dhcp_server_boot_filename
;
207 /* link local addressing support */
208 AddressFamily link_local
;
209 IPv6LinkLocalAddressGenMode ipv6ll_address_gen_mode
;
210 struct in6_addr ipv6ll_stable_secret
;
213 /* IPv6 RA support */
214 RADVPrefixDelegation router_prefix_delegation
;
215 usec_t router_lifetime_usec
;
216 uint8_t router_preference
;
218 bool router_other_information
;
219 bool router_emit_dns
;
220 bool router_emit_domains
;
221 usec_t router_dns_lifetime_usec
;
222 struct in6_addr
*router_dns
;
223 unsigned n_router_dns
;
224 OrderedSet
*router_search_domains
;
225 int router_uplink_index
;
226 char *router_uplink_name
;
228 /* DHCP Prefix Delegation support */
230 bool dhcp_pd_announce
;
232 bool dhcp_pd_manage_temporary_address
;
233 int64_t dhcp_pd_subnet_id
;
234 uint32_t dhcp_pd_route_metric
;
236 int dhcp_pd_uplink_index
;
237 char *dhcp_pd_uplink_name
;
244 int allow_port_to_be_root
;
247 int multicast_to_unicast
;
248 int neighbor_suppression
;
250 int bridge_proxy_arp
;
251 int bridge_proxy_arp_wifi
;
254 MulticastRouter multicast_router
;
259 uint32_t br_vid_bitmap
[BRIDGE_VLAN_BITMAP_LEN
];
260 uint32_t br_untagged_bitmap
[BRIDGE_VLAN_BITMAP_LEN
];
263 uint32_t can_bitrate
;
264 unsigned can_sample_point
;
265 nsec_t can_time_quanta_ns
;
266 uint32_t can_propagation_segment
;
267 uint32_t can_phase_buffer_segment_1
;
268 uint32_t can_phase_buffer_segment_2
;
269 uint32_t can_sync_jump_width
;
270 uint32_t can_data_bitrate
;
271 unsigned can_data_sample_point
;
272 nsec_t can_data_time_quanta_ns
;
273 uint32_t can_data_propagation_segment
;
274 uint32_t can_data_phase_buffer_segment_1
;
275 uint32_t can_data_phase_buffer_segment_2
;
276 uint32_t can_data_sync_jump_width
;
277 usec_t can_restart_us
;
278 uint32_t can_control_mode_mask
;
279 uint32_t can_control_mode_flags
;
280 uint16_t can_termination
;
281 bool can_termination_set
;
284 IPoIBMode ipoib_mode
;
287 /* sysctl settings */
288 AddressFamily ip_forward
;
289 int ipv4_accept_local
;
290 int ipv4_route_localnet
;
291 int ipv6_dad_transmits
;
295 IPv6PrivacyExtensions ipv6_privacy_extensions
;
297 Set
*ipv6_proxy_ndp_addresses
;
301 bool ipv6_accept_ra_use_dns
;
302 bool ipv6_accept_ra_use_gateway
;
303 bool ipv6_accept_ra_use_route_prefix
;
304 bool ipv6_accept_ra_use_autonomous_prefix
;
305 bool ipv6_accept_ra_use_onlink_prefix
;
306 bool ipv6_accept_ra_use_mtu
;
309 DHCPUseDomains ipv6_accept_ra_use_domains
;
310 IPv6AcceptRAStartDHCP6Client ipv6_accept_ra_start_dhcp6_client
;
311 uint32_t ipv6_accept_ra_route_table
;
312 bool ipv6_accept_ra_route_table_set
;
313 uint32_t ipv6_accept_ra_route_metric
;
314 bool ipv6_accept_ra_route_metric_set
;
315 Set
*ndisc_deny_listed_router
;
316 Set
*ndisc_allow_listed_router
;
317 Set
*ndisc_deny_listed_prefix
;
318 Set
*ndisc_allow_listed_prefix
;
319 Set
*ndisc_deny_listed_route_prefix
;
320 Set
*ndisc_allow_listed_route_prefix
;
324 LLDPMode lldp_mode
; /* LLDP reception */
325 sd_lldp_multicast_mode_t lldp_multicast_mode
; /* LLDP transmission */
326 char *lldp_mudurl
; /* LLDP MUD URL */
328 OrderedHashmap
*addresses_by_section
;
329 Hashmap
*routes_by_section
;
330 Hashmap
*nexthops_by_section
;
331 Hashmap
*bridge_fdb_entries_by_section
;
332 Hashmap
*bridge_mdb_entries_by_section
;
333 Hashmap
*neighbors_by_section
;
334 Hashmap
*address_labels_by_section
;
335 Hashmap
*prefixes_by_section
;
336 Hashmap
*route_prefixes_by_section
;
337 Hashmap
*rules_by_section
;
338 Hashmap
*dhcp_static_leases_by_section
;
339 Hashmap
*qdiscs_by_section
;
340 Hashmap
*tclasses_by_section
;
341 OrderedHashmap
*sr_iov_by_section
;
343 /* All kinds of DNS configuration */
344 struct in_addr_full
**dns
;
346 OrderedSet
*search_domains
, *route_domains
;
347 int dns_default_route
;
348 ResolveSupport llmnr
;
350 DnssecMode dnssec_mode
;
351 DnsOverTlsMode dns_over_tls_mode
;
352 Set
*dnssec_negative_trust_anchors
;
358 Network
*network_ref(Network
*network
);
359 Network
*network_unref(Network
*network
);
360 DEFINE_TRIVIAL_CLEANUP_FUNC(Network
*, network_unref
);
362 int network_load(Manager
*manager
, OrderedHashmap
**networks
);
363 int network_reload(Manager
*manager
);
364 int network_load_one(Manager
*manager
, OrderedHashmap
**networks
, const char *filename
);
365 int network_verify(Network
*network
);
367 int manager_build_dhcp_pd_subnet_ids(Manager
*manager
);
369 int network_get_by_name(Manager
*manager
, const char *name
, Network
**ret
);
370 void network_apply_anonymize_if_set(Network
*network
);
372 bool network_has_static_ipv6_configurations(Network
*network
);
374 CONFIG_PARSER_PROTOTYPE(config_parse_stacked_netdev
);
375 CONFIG_PARSER_PROTOTYPE(config_parse_tunnel
);
376 CONFIG_PARSER_PROTOTYPE(config_parse_domains
);
377 CONFIG_PARSER_PROTOTYPE(config_parse_dns
);
378 CONFIG_PARSER_PROTOTYPE(config_parse_timezone
);
379 CONFIG_PARSER_PROTOTYPE(config_parse_dnssec_negative_trust_anchors
);
380 CONFIG_PARSER_PROTOTYPE(config_parse_ntp
);
381 CONFIG_PARSER_PROTOTYPE(config_parse_required_for_online
);
382 CONFIG_PARSER_PROTOTYPE(config_parse_required_family_for_online
);
383 CONFIG_PARSER_PROTOTYPE(config_parse_keep_configuration
);
384 CONFIG_PARSER_PROTOTYPE(config_parse_activation_policy
);
385 CONFIG_PARSER_PROTOTYPE(config_parse_link_group
);
386 CONFIG_PARSER_PROTOTYPE(config_parse_ignore_carrier_loss
);
388 const struct ConfigPerfItem
* network_network_gperf_lookup(const char *key
, GPERF_LEN_TYPE length
);
390 const char* keep_configuration_to_string(KeepConfiguration i
) _const_
;
391 KeepConfiguration
keep_configuration_from_string(const char *s
) _pure_
;
393 const char* activation_policy_to_string(ActivationPolicy i
) _const_
;
394 ActivationPolicy
activation_policy_from_string(const char *s
) _pure_
;