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-brvlan.h"
16 #include "networkd-dhcp-common.h"
17 #include "networkd-dhcp4.h"
18 #include "networkd-dhcp6.h"
19 #include "networkd-dhcp-server.h"
20 #include "networkd-lldp-rx.h"
21 #include "networkd-lldp-tx.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
;
81 LIST_HEAD(Condition
, conditions
);
83 /* Master or stacked netdevs */
89 Hashmap
*stacked_netdevs
;
94 Hashmap
*stacked_netdev_names
;
97 struct ether_addr
*mac
;
105 bool required_for_online
; /* Is this network required to be considered online? */
106 LinkOperationalStateRange required_operstate_for_online
;
107 AddressFamily required_family_for_online
;
108 ActivationPolicy activation_policy
;
111 bool configure_without_carrier
;
112 int ignore_carrier_loss
;
113 KeepConfiguration keep_configuration
;
115 bool default_route_on_device
;
116 AddressFamily ip_masquerade
;
118 /* DHCP Client Support */
120 DHCPClientIdentifier dhcp_client_identifier
;
124 char *dhcp_vendor_class_identifier
;
126 char **dhcp_user_class
;
128 uint64_t dhcp_max_attempts
;
129 uint32_t dhcp_route_metric
;
130 bool dhcp_route_metric_set
;
131 uint32_t dhcp_route_table
;
132 uint32_t dhcp_fallback_lease_lifetime
;
133 uint32_t dhcp_route_mtu
;
134 uint16_t dhcp_client_port
;
136 int dhcp_ip_service_type
;
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
;
148 bool dhcp_use_routes
;
149 int dhcp_use_gateway
;
150 bool dhcp_use_timezone
;
151 bool dhcp_use_hostname
;
152 bool dhcp_route_table_set
;
153 bool dhcp_send_release
;
154 bool dhcp_send_decline
;
155 DHCPUseDomains dhcp_use_domains
;
156 bool dhcp_use_domains_set
;
157 Set
*dhcp_deny_listed_ip
;
158 Set
*dhcp_allow_listed_ip
;
159 Set
*dhcp_request_options
;
160 OrderedHashmap
*dhcp_client_send_options
;
161 OrderedHashmap
*dhcp_client_send_vendor_options
;
163 /* DHCPv6 Client support*/
164 bool dhcp6_use_address
;
166 bool dhcp6_use_dns_set
;
167 bool dhcp6_use_hostname
;
169 bool dhcp6_use_ntp_set
;
170 bool dhcp6_rapid_commit
;
171 DHCPUseDomains dhcp6_use_domains
;
172 bool dhcp6_use_domains_set
;
175 bool dhcp6_iaid_set_explicitly
;
177 uint8_t dhcp6_pd_length
;
179 char **dhcp6_user_class
;
180 char **dhcp6_vendor_class
;
181 struct in6_addr dhcp6_pd_address
;
182 DHCP6ClientStartMode dhcp6_without_ra
;
183 OrderedHashmap
*dhcp6_client_send_options
;
184 OrderedHashmap
*dhcp6_client_send_vendor_options
;
185 Set
*dhcp6_request_options
;
186 /* Start DHCPv6 PD also when 'O' RA flag is set, see RFC 7084, WPD-4 */
187 bool dhcp6_force_pd_other_information
;
189 /* DHCP Server Support */
191 bool dhcp_server_bind_to_interface
;
192 unsigned char dhcp_server_address_prefixlen
;
193 struct in_addr dhcp_server_address
;
194 struct in_addr dhcp_server_relay_target
;
195 char *dhcp_server_relay_agent_circuit_id
;
196 char *dhcp_server_relay_agent_remote_id
;
197 NetworkDHCPServerEmitAddress dhcp_server_emit
[_SD_DHCP_LEASE_SERVER_TYPE_MAX
];
198 bool dhcp_server_emit_router
;
199 bool dhcp_server_emit_timezone
;
200 char *dhcp_server_timezone
;
201 usec_t dhcp_server_default_lease_time_usec
, dhcp_server_max_lease_time_usec
;
202 uint32_t dhcp_server_pool_offset
;
203 uint32_t dhcp_server_pool_size
;
204 OrderedHashmap
*dhcp_server_send_options
;
205 OrderedHashmap
*dhcp_server_send_vendor_options
;
207 /* link local addressing support */
208 AddressFamily link_local
;
209 IPv6LinkLocalAddressGenMode ipv6ll_address_gen_mode
;
212 /* IPv6 RA support */
213 RADVPrefixDelegation router_prefix_delegation
;
214 usec_t router_lifetime_usec
;
215 uint8_t router_preference
;
217 bool router_other_information
;
218 bool router_emit_dns
;
219 bool router_emit_domains
;
220 usec_t router_dns_lifetime_usec
;
221 struct in6_addr
*router_dns
;
222 unsigned n_router_dns
;
223 OrderedSet
*router_search_domains
;
225 /* DHCPv6 Prefix Delegation support */
227 bool dhcp6_pd_announce
;
228 bool dhcp6_pd_assign
;
229 bool dhcp6_pd_manage_temporary_address
;
230 int64_t dhcp6_pd_subnet_id
;
231 uint32_t dhcp6_pd_route_metric
;
232 struct in6_addr dhcp6_pd_token
;
238 int allow_port_to_be_root
;
241 int multicast_to_unicast
;
242 int neighbor_suppression
;
244 int bridge_proxy_arp
;
245 int bridge_proxy_arp_wifi
;
248 MulticastRouter multicast_router
;
253 uint32_t br_vid_bitmap
[BRIDGE_VLAN_BITMAP_LEN
];
254 uint32_t br_untagged_bitmap
[BRIDGE_VLAN_BITMAP_LEN
];
257 uint32_t can_bitrate
;
258 unsigned can_sample_point
;
259 uint32_t can_data_bitrate
;
260 unsigned can_data_sample_point
;
261 usec_t can_restart_us
;
262 int can_triple_sampling
;
263 int can_berr_reporting
;
269 /* sysctl settings */
270 AddressFamily ip_forward
;
271 int ipv4_accept_local
;
272 int ipv4_route_localnet
;
273 int ipv6_dad_transmits
;
277 IPv6PrivacyExtensions ipv6_privacy_extensions
;
279 Set
*ipv6_proxy_ndp_addresses
;
283 bool ipv6_accept_ra_use_dns
;
284 bool ipv6_accept_ra_use_autonomous_prefix
;
285 bool ipv6_accept_ra_use_onlink_prefix
;
288 DHCPUseDomains ipv6_accept_ra_use_domains
;
289 IPv6AcceptRAStartDHCP6Client ipv6_accept_ra_start_dhcp6_client
;
290 uint32_t ipv6_accept_ra_route_table
;
291 bool ipv6_accept_ra_route_table_set
;
292 uint32_t ipv6_accept_ra_route_metric
;
293 bool ipv6_accept_ra_route_metric_set
;
294 Set
*ndisc_deny_listed_router
;
295 Set
*ndisc_allow_listed_router
;
296 Set
*ndisc_deny_listed_prefix
;
297 Set
*ndisc_allow_listed_prefix
;
298 Set
*ndisc_deny_listed_route_prefix
;
299 Set
*ndisc_allow_listed_route_prefix
;
300 OrderedSet
*ipv6_tokens
;
303 LLDPMode lldp_mode
; /* LLDP reception */
304 LLDPEmit lldp_emit
; /* LLDP transmission */
305 char *lldp_mud
; /* LLDP MUD URL */
307 OrderedHashmap
*addresses_by_section
;
308 Hashmap
*routes_by_section
;
309 Hashmap
*nexthops_by_section
;
310 Hashmap
*bridge_fdb_entries_by_section
;
311 Hashmap
*mdb_entries_by_section
;
312 Hashmap
*neighbors_by_section
;
313 Hashmap
*address_labels_by_section
;
314 Hashmap
*prefixes_by_section
;
315 Hashmap
*route_prefixes_by_section
;
316 Hashmap
*rules_by_section
;
317 OrderedHashmap
*tc_by_section
;
318 OrderedHashmap
*sr_iov_by_section
;
320 /* All kinds of DNS configuration */
321 struct in_addr_full
**dns
;
323 OrderedSet
*search_domains
, *route_domains
;
324 int dns_default_route
;
325 ResolveSupport llmnr
;
327 DnssecMode dnssec_mode
;
328 DnsOverTlsMode dns_over_tls_mode
;
329 Set
*dnssec_negative_trust_anchors
;
335 Network
*network_ref(Network
*network
);
336 Network
*network_unref(Network
*network
);
337 DEFINE_TRIVIAL_CLEANUP_FUNC(Network
*, network_unref
);
339 int network_load(Manager
*manager
, OrderedHashmap
**networks
);
340 int network_reload(Manager
*manager
);
341 int network_load_one(Manager
*manager
, OrderedHashmap
**networks
, const char *filename
);
342 int network_verify(Network
*network
);
344 int network_get_by_name(Manager
*manager
, const char *name
, Network
**ret
);
345 void network_apply_anonymize_if_set(Network
*network
);
347 bool network_has_static_ipv6_configurations(Network
*network
);
349 CONFIG_PARSER_PROTOTYPE(config_parse_stacked_netdev
);
350 CONFIG_PARSER_PROTOTYPE(config_parse_tunnel
);
351 CONFIG_PARSER_PROTOTYPE(config_parse_domains
);
352 CONFIG_PARSER_PROTOTYPE(config_parse_dns
);
353 CONFIG_PARSER_PROTOTYPE(config_parse_hostname
);
354 CONFIG_PARSER_PROTOTYPE(config_parse_timezone
);
355 CONFIG_PARSER_PROTOTYPE(config_parse_dnssec_negative_trust_anchors
);
356 CONFIG_PARSER_PROTOTYPE(config_parse_ntp
);
357 CONFIG_PARSER_PROTOTYPE(config_parse_required_for_online
);
358 CONFIG_PARSER_PROTOTYPE(config_parse_required_family_for_online
);
359 CONFIG_PARSER_PROTOTYPE(config_parse_keep_configuration
);
360 CONFIG_PARSER_PROTOTYPE(config_parse_ipv6_link_local_address_gen_mode
);
361 CONFIG_PARSER_PROTOTYPE(config_parse_activation_policy
);
363 const struct ConfigPerfItem
* network_network_gperf_lookup(const char *key
, GPERF_LEN_TYPE length
);
365 const char* keep_configuration_to_string(KeepConfiguration i
) _const_
;
366 KeepConfiguration
keep_configuration_from_string(const char *s
) _pure_
;
368 const char* ipv6_link_local_address_gen_mode_to_string(IPv6LinkLocalAddressGenMode s
) _const_
;
369 IPv6LinkLocalAddressGenMode
ipv6_link_local_address_gen_mode_from_string(const char *s
) _pure_
;
371 const char* activation_policy_to_string(ActivationPolicy i
) _const_
;
372 ActivationPolicy
activation_policy_from_string(const char *s
) _pure_
;