1 /* SPDX-License-Identifier: LGPL-2.1+ */
8 #include "conf-parser.h"
9 #include "dhcp-identifier.h"
11 #include "netdev/bridge.h"
12 #include "netdev/netdev.h"
13 #include "networkd-address-label.h"
14 #include "networkd-address.h"
15 #include "networkd-brvlan.h"
16 #include "networkd-fdb.h"
17 #include "networkd-ipv6-proxy-ndp.h"
18 #include "networkd-lldp-rx.h"
19 #include "networkd-lldp-tx.h"
20 #include "networkd-neighbor.h"
21 #include "networkd-radv.h"
22 #include "networkd-route.h"
23 #include "networkd-routing-policy-rule.h"
24 #include "networkd-util.h"
25 #include "ordered-set.h"
26 #include "resolve-util.h"
28 #define DHCP_ROUTE_METRIC 1024
29 #define IPV4LL_ROUTE_METRIC 2048
31 #define BRIDGE_VLAN_BITMAP_MAX 4096
32 #define BRIDGE_VLAN_BITMAP_LEN (BRIDGE_VLAN_BITMAP_MAX / 32)
34 typedef enum DHCPClientIdentifier
{
37 /* The following option may not be good for RFC regarding DHCP (3315 and 4361).
38 * But some setups require this. E.g., Sky Broadband, the second largest provider in the UK
39 * requires the client id to be set to a custom string, reported at
40 * https://github.com/systemd/systemd/issues/7828 */
41 DHCP_CLIENT_ID_DUID_ONLY
,
43 _DHCP_CLIENT_ID_INVALID
= -1,
44 } DHCPClientIdentifier
;
46 typedef enum IPv6PrivacyExtensions
{
47 /* The values map to the kernel's /proc/sys/net/ipv6/conf/xxx/use_tempaddr values */
48 IPV6_PRIVACY_EXTENSIONS_NO
,
49 IPV6_PRIVACY_EXTENSIONS_PREFER_PUBLIC
,
50 IPV6_PRIVACY_EXTENSIONS_YES
, /* aka prefer-temporary */
51 _IPV6_PRIVACY_EXTENSIONS_MAX
,
52 _IPV6_PRIVACY_EXTENSIONS_INVALID
= -1,
53 } IPv6PrivacyExtensions
;
55 typedef enum DHCPUseDomains
{
58 DHCP_USE_DOMAINS_ROUTE
,
59 _DHCP_USE_DOMAINS_MAX
,
60 _DHCP_USE_DOMAINS_INVALID
= -1,
64 /* Value of Type in [DHCP] section */
68 uint8_t raw_data
[MAX_DUID_LEN
];
72 typedef enum RADVPrefixDelegation
{
73 RADV_PREFIX_DELEGATION_NONE
,
74 RADV_PREFIX_DELEGATION_STATIC
,
75 RADV_PREFIX_DELEGATION_DHCP6
,
76 RADV_PREFIX_DELEGATION_BOTH
,
77 _RADV_PREFIX_DELEGATION_MAX
,
78 _RADV_PREFIX_DELEGATION_INVALID
= -1,
79 } RADVPrefixDelegation
;
81 typedef enum KeepConfiguration
{
82 KEEP_CONFIGURATION_NO
= 0,
83 KEEP_CONFIGURATION_DHCP_ON_START
= 1 << 0,
84 KEEP_CONFIGURATION_DHCP_ON_STOP
= 1 << 1,
85 KEEP_CONFIGURATION_DHCP
= KEEP_CONFIGURATION_DHCP_ON_START
| KEEP_CONFIGURATION_DHCP_ON_STOP
,
86 KEEP_CONFIGURATION_STATIC
= 1 << 2,
87 KEEP_CONFIGURATION_YES
= KEEP_CONFIGURATION_DHCP
| KEEP_CONFIGURATION_STATIC
,
88 _KEEP_CONFIGURATION_MAX
,
89 _KEEP_CONFIGURATION_INVALID
= -1,
92 typedef struct Manager Manager
;
107 char **match_property
;
108 LIST_HEAD(Condition
, conditions
);
115 Hashmap
*stacked_netdevs
;
119 Hashmap
*stacked_netdev_names
;
121 /* DHCP Client Support */
122 AddressFamilyBoolean dhcp
;
123 DHCPClientIdentifier dhcp_client_identifier
;
124 char *dhcp_vendor_class_identifier
;
125 char **dhcp_user_class
;
127 uint64_t dhcp_max_attempts
;
128 unsigned dhcp_route_metric
;
129 uint32_t dhcp_route_table
;
130 uint16_t dhcp_client_port
;
132 bool dhcp_send_hostname
;
138 bool dhcp_use_routes
;
139 bool dhcp_use_timezone
;
141 bool dhcp_use_hostname
;
142 bool dhcp_route_table_set
;
143 bool dhcp_send_release
;
144 DHCPUseDomains dhcp_use_domains
;
145 Set
*dhcp_black_listed_ip
;
147 /* DHCP Server Support */
149 bool dhcp_server_emit_dns
;
150 struct in_addr
*dhcp_server_dns
;
151 unsigned n_dhcp_server_dns
;
152 bool dhcp_server_emit_ntp
;
153 struct in_addr
*dhcp_server_ntp
;
154 unsigned n_dhcp_server_ntp
;
155 bool dhcp_server_emit_router
;
156 bool dhcp_server_emit_timezone
;
157 char *dhcp_server_timezone
;
158 usec_t dhcp_server_default_lease_time_usec
, dhcp_server_max_lease_time_usec
;
159 uint32_t dhcp_server_pool_offset
;
160 uint32_t dhcp_server_pool_size
;
163 AddressFamilyBoolean link_local
;
166 bool default_route_on_device
;
168 /* IPv6 prefix delegation support */
169 RADVPrefixDelegation router_prefix_delegation
;
170 usec_t router_lifetime_usec
;
171 uint8_t router_preference
;
173 bool router_other_information
;
174 bool router_emit_dns
;
175 bool router_emit_domains
;
176 usec_t router_dns_lifetime_usec
;
177 struct in6_addr
*router_dns
;
178 unsigned n_router_dns
;
179 OrderedSet
*router_search_domains
;
180 bool dhcp6_force_pd_other_information
; /* Start DHCPv6 PD also when 'O'
181 RA flag is set, see RFC 7084,
188 int allow_port_to_be_root
;
191 int multicast_to_unicast
;
192 int neighbor_suppression
;
194 int bridge_proxy_arp
;
195 int bridge_proxy_arp_wifi
;
198 MulticastRouter multicast_router
;
202 uint32_t br_vid_bitmap
[BRIDGE_VLAN_BITMAP_LEN
];
203 uint32_t br_untagged_bitmap
[BRIDGE_VLAN_BITMAP_LEN
];
207 unsigned can_sample_point
;
208 usec_t can_restart_us
;
209 int can_triple_sampling
;
211 AddressFamilyBoolean ip_forward
;
215 int ipv6_dad_transmits
;
221 bool ipv6_accept_ra_use_dns
;
222 bool ipv6_accept_ra_use_autonomous_prefix
;
223 bool ipv6_accept_ra_use_onlink_prefix
;
226 DHCPUseDomains ipv6_accept_ra_use_domains
;
227 uint32_t ipv6_accept_ra_route_table
;
228 bool ipv6_accept_ra_route_table_set
;
229 Set
*ndisc_black_listed_prefix
;
231 union in_addr_union ipv6_token
;
232 IPv6PrivacyExtensions ipv6_privacy_extensions
;
234 struct ether_addr
*mac
;
240 bool configure_without_carrier
;
241 bool ignore_carrier_loss
;
242 KeepConfiguration keep_configuration
;
248 bool required_for_online
; /* Is this network required to be considered online? */
249 LinkOperationalState required_operstate_for_online
;
251 LLDPMode lldp_mode
; /* LLDP reception */
252 LLDPEmit lldp_emit
; /* LLDP transmission */
254 LIST_HEAD(Address
, static_addresses
);
255 LIST_HEAD(Route
, static_routes
);
256 LIST_HEAD(FdbEntry
, static_fdb_entries
);
257 LIST_HEAD(IPv6ProxyNDPAddress
, ipv6_proxy_ndp_addresses
);
258 LIST_HEAD(Neighbor
, neighbors
);
259 LIST_HEAD(AddressLabel
, address_labels
);
260 LIST_HEAD(Prefix
, static_prefixes
);
261 LIST_HEAD(RoutingPolicyRule
, rules
);
263 unsigned n_static_addresses
;
264 unsigned n_static_routes
;
265 unsigned n_static_fdb_entries
;
266 unsigned n_ipv6_proxy_ndp_addresses
;
267 unsigned n_neighbors
;
268 unsigned n_address_labels
;
269 unsigned n_static_prefixes
;
272 Hashmap
*addresses_by_section
;
273 Hashmap
*routes_by_section
;
274 Hashmap
*fdb_entries_by_section
;
275 Hashmap
*neighbors_by_section
;
276 Hashmap
*address_labels_by_section
;
277 Hashmap
*prefixes_by_section
;
278 Hashmap
*rules_by_section
;
280 /* All kinds of DNS configuration */
281 struct in_addr_data
*dns
;
283 OrderedSet
*search_domains
, *route_domains
;
285 int dns_default_route
;
286 ResolveSupport llmnr
;
288 DnssecMode dnssec_mode
;
289 DnsOverTlsMode dns_over_tls_mode
;
290 Set
*dnssec_negative_trust_anchors
;
296 Network
*network_ref(Network
*network
);
297 Network
*network_unref(Network
*network
);
298 DEFINE_TRIVIAL_CLEANUP_FUNC(Network
*, network_unref
);
300 int network_load(Manager
*manager
);
301 int network_load_one(Manager
*manager
, const char *filename
);
302 int network_verify(Network
*network
);
304 int network_get_by_name(Manager
*manager
, const char *name
, Network
**ret
);
305 int network_get(Manager
*manager
, sd_device
*device
, const char *ifname
, const struct ether_addr
*mac
, Network
**ret
);
306 int network_apply(Network
*network
, Link
*link
);
307 void network_apply_anonymize_if_set(Network
*network
);
309 bool network_has_static_ipv6_addresses(Network
*network
);
311 CONFIG_PARSER_PROTOTYPE(config_parse_stacked_netdev
);
312 CONFIG_PARSER_PROTOTYPE(config_parse_domains
);
313 CONFIG_PARSER_PROTOTYPE(config_parse_tunnel
);
314 CONFIG_PARSER_PROTOTYPE(config_parse_dhcp
);
315 CONFIG_PARSER_PROTOTYPE(config_parse_dns
);
316 CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_client_identifier
);
317 CONFIG_PARSER_PROTOTYPE(config_parse_ipv6token
);
318 CONFIG_PARSER_PROTOTYPE(config_parse_ipv6_privacy_extensions
);
319 CONFIG_PARSER_PROTOTYPE(config_parse_hostname
);
320 CONFIG_PARSER_PROTOTYPE(config_parse_timezone
);
321 CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_server_dns
);
322 CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_black_listed_ip_address
);
323 CONFIG_PARSER_PROTOTYPE(config_parse_radv_dns
);
324 CONFIG_PARSER_PROTOTYPE(config_parse_radv_search_domains
);
325 CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_server_ntp
);
326 CONFIG_PARSER_PROTOTYPE(config_parse_dnssec_negative_trust_anchors
);
327 CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_use_domains
);
328 CONFIG_PARSER_PROTOTYPE(config_parse_section_route_table
);
329 CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_user_class
);
330 CONFIG_PARSER_PROTOTYPE(config_parse_ntp
);
331 CONFIG_PARSER_PROTOTYPE(config_parse_iaid
);
332 CONFIG_PARSER_PROTOTYPE(config_parse_required_for_online
);
333 CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_max_attempts
);
334 CONFIG_PARSER_PROTOTYPE(config_parse_keep_configuration
);
335 /* Legacy IPv4LL support */
336 CONFIG_PARSER_PROTOTYPE(config_parse_ipv4ll
);
338 const struct ConfigPerfItem
* network_network_gperf_lookup(const char *key
, GPERF_LEN_TYPE length
);
340 extern const sd_bus_vtable network_vtable
[];
342 int network_node_enumerator(sd_bus
*bus
, const char *path
, void *userdata
, char ***nodes
, sd_bus_error
*error
);
343 int network_object_find(sd_bus
*bus
, const char *path
, const char *interface
, void *userdata
, void **found
, sd_bus_error
*error
);
345 const char* ipv6_privacy_extensions_to_string(IPv6PrivacyExtensions i
) _const_
;
346 IPv6PrivacyExtensions
ipv6_privacy_extensions_from_string(const char *s
) _pure_
;
348 const char* dhcp_use_domains_to_string(DHCPUseDomains p
) _const_
;
349 DHCPUseDomains
dhcp_use_domains_from_string(const char *s
) _pure_
;
351 const char* radv_prefix_delegation_to_string(RADVPrefixDelegation i
) _const_
;
352 RADVPrefixDelegation
radv_prefix_delegation_from_string(const char *s
) _pure_
;
354 const char* keep_configuration_to_string(KeepConfiguration i
) _const_
;
355 KeepConfiguration
keep_configuration_from_string(const char *s
) _pure_
;