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 LIST_HEAD(Condition
, conditions
);
114 Hashmap
*stacked_netdevs
;
118 Hashmap
*stacked_netdev_names
;
120 /* DHCP Client Support */
121 AddressFamilyBoolean dhcp
;
122 DHCPClientIdentifier dhcp_client_identifier
;
123 char *dhcp_vendor_class_identifier
;
124 char **dhcp_user_class
;
126 uint64_t dhcp_max_attempts
;
127 unsigned dhcp_route_metric
;
128 uint32_t dhcp_route_table
;
129 uint16_t dhcp_client_port
;
131 bool dhcp_send_hostname
;
137 bool dhcp_use_routes
;
138 bool dhcp_use_timezone
;
140 bool dhcp_use_hostname
;
141 bool dhcp_route_table_set
;
142 bool dhcp_send_release
;
143 DHCPUseDomains dhcp_use_domains
;
144 Set
*dhcp_black_listed_ip
;
146 /* DHCP Server Support */
148 bool dhcp_server_emit_dns
;
149 struct in_addr
*dhcp_server_dns
;
150 unsigned n_dhcp_server_dns
;
151 bool dhcp_server_emit_ntp
;
152 struct in_addr
*dhcp_server_ntp
;
153 unsigned n_dhcp_server_ntp
;
154 bool dhcp_server_emit_router
;
155 bool dhcp_server_emit_timezone
;
156 char *dhcp_server_timezone
;
157 usec_t dhcp_server_default_lease_time_usec
, dhcp_server_max_lease_time_usec
;
158 uint32_t dhcp_server_pool_offset
;
159 uint32_t dhcp_server_pool_size
;
162 AddressFamilyBoolean link_local
;
165 bool default_route_on_device
;
167 /* IPv6 prefix delegation support */
168 RADVPrefixDelegation router_prefix_delegation
;
169 usec_t router_lifetime_usec
;
170 uint8_t router_preference
;
172 bool router_other_information
;
173 bool router_emit_dns
;
174 bool router_emit_domains
;
175 usec_t router_dns_lifetime_usec
;
176 struct in6_addr
*router_dns
;
177 unsigned n_router_dns
;
178 OrderedSet
*router_search_domains
;
179 bool dhcp6_force_pd_other_information
; /* Start DHCPv6 PD also when 'O'
180 RA flag is set, see RFC 7084,
187 int allow_port_to_be_root
;
190 int multicast_to_unicast
;
191 int neighbor_suppression
;
193 int bridge_proxy_arp
;
194 int bridge_proxy_arp_wifi
;
197 MulticastRouter multicast_router
;
201 uint32_t br_vid_bitmap
[BRIDGE_VLAN_BITMAP_LEN
];
202 uint32_t br_untagged_bitmap
[BRIDGE_VLAN_BITMAP_LEN
];
206 unsigned can_sample_point
;
207 usec_t can_restart_us
;
208 int can_triple_sampling
;
210 AddressFamilyBoolean ip_forward
;
214 int ipv6_dad_transmits
;
220 bool ipv6_accept_ra_use_dns
;
221 bool ipv6_accept_ra_use_autonomous_prefix
;
222 bool ipv6_accept_ra_use_onlink_prefix
;
225 DHCPUseDomains ipv6_accept_ra_use_domains
;
226 uint32_t ipv6_accept_ra_route_table
;
227 bool ipv6_accept_ra_route_table_set
;
228 Set
*ndisc_black_listed_prefix
;
230 union in_addr_union ipv6_token
;
231 IPv6PrivacyExtensions ipv6_privacy_extensions
;
233 struct ether_addr
*mac
;
239 bool configure_without_carrier
;
240 bool ignore_carrier_loss
;
241 KeepConfiguration keep_configuration
;
247 bool required_for_online
; /* Is this network required to be considered online? */
248 LinkOperationalState required_operstate_for_online
;
250 LLDPMode lldp_mode
; /* LLDP reception */
251 LLDPEmit lldp_emit
; /* LLDP transmission */
253 LIST_HEAD(Address
, static_addresses
);
254 LIST_HEAD(Route
, static_routes
);
255 LIST_HEAD(FdbEntry
, static_fdb_entries
);
256 LIST_HEAD(IPv6ProxyNDPAddress
, ipv6_proxy_ndp_addresses
);
257 LIST_HEAD(Neighbor
, neighbors
);
258 LIST_HEAD(AddressLabel
, address_labels
);
259 LIST_HEAD(Prefix
, static_prefixes
);
260 LIST_HEAD(RoutingPolicyRule
, rules
);
262 unsigned n_static_addresses
;
263 unsigned n_static_routes
;
264 unsigned n_static_fdb_entries
;
265 unsigned n_ipv6_proxy_ndp_addresses
;
266 unsigned n_neighbors
;
267 unsigned n_address_labels
;
268 unsigned n_static_prefixes
;
271 Hashmap
*addresses_by_section
;
272 Hashmap
*routes_by_section
;
273 Hashmap
*fdb_entries_by_section
;
274 Hashmap
*neighbors_by_section
;
275 Hashmap
*address_labels_by_section
;
276 Hashmap
*prefixes_by_section
;
277 Hashmap
*rules_by_section
;
279 /* All kinds of DNS configuration */
280 struct in_addr_data
*dns
;
282 OrderedSet
*search_domains
, *route_domains
;
284 int dns_default_route
;
285 ResolveSupport llmnr
;
287 DnssecMode dnssec_mode
;
288 DnsOverTlsMode dns_over_tls_mode
;
289 Set
*dnssec_negative_trust_anchors
;
295 Network
*network_ref(Network
*network
);
296 Network
*network_unref(Network
*network
);
297 DEFINE_TRIVIAL_CLEANUP_FUNC(Network
*, network_unref
);
299 int network_load(Manager
*manager
);
300 int network_load_one(Manager
*manager
, const char *filename
);
301 int network_verify(Network
*network
);
303 int network_get_by_name(Manager
*manager
, const char *name
, Network
**ret
);
304 int network_get(Manager
*manager
, sd_device
*device
, const char *ifname
, const struct ether_addr
*mac
, Network
**ret
);
305 int network_apply(Network
*network
, Link
*link
);
306 void network_apply_anonymize_if_set(Network
*network
);
308 bool network_has_static_ipv6_addresses(Network
*network
);
310 CONFIG_PARSER_PROTOTYPE(config_parse_stacked_netdev
);
311 CONFIG_PARSER_PROTOTYPE(config_parse_domains
);
312 CONFIG_PARSER_PROTOTYPE(config_parse_tunnel
);
313 CONFIG_PARSER_PROTOTYPE(config_parse_dhcp
);
314 CONFIG_PARSER_PROTOTYPE(config_parse_dns
);
315 CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_client_identifier
);
316 CONFIG_PARSER_PROTOTYPE(config_parse_ipv6token
);
317 CONFIG_PARSER_PROTOTYPE(config_parse_ipv6_privacy_extensions
);
318 CONFIG_PARSER_PROTOTYPE(config_parse_hostname
);
319 CONFIG_PARSER_PROTOTYPE(config_parse_timezone
);
320 CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_server_dns
);
321 CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_black_listed_ip_address
);
322 CONFIG_PARSER_PROTOTYPE(config_parse_radv_dns
);
323 CONFIG_PARSER_PROTOTYPE(config_parse_radv_search_domains
);
324 CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_server_ntp
);
325 CONFIG_PARSER_PROTOTYPE(config_parse_dnssec_negative_trust_anchors
);
326 CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_use_domains
);
327 CONFIG_PARSER_PROTOTYPE(config_parse_section_route_table
);
328 CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_user_class
);
329 CONFIG_PARSER_PROTOTYPE(config_parse_ntp
);
330 CONFIG_PARSER_PROTOTYPE(config_parse_iaid
);
331 CONFIG_PARSER_PROTOTYPE(config_parse_required_for_online
);
332 CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_max_attempts
);
333 CONFIG_PARSER_PROTOTYPE(config_parse_keep_configuration
);
334 /* Legacy IPv4LL support */
335 CONFIG_PARSER_PROTOTYPE(config_parse_ipv4ll
);
337 const struct ConfigPerfItem
* network_network_gperf_lookup(const char *key
, GPERF_LEN_TYPE length
);
339 extern const sd_bus_vtable network_vtable
[];
341 int network_node_enumerator(sd_bus
*bus
, const char *path
, void *userdata
, char ***nodes
, sd_bus_error
*error
);
342 int network_object_find(sd_bus
*bus
, const char *path
, const char *interface
, void *userdata
, void **found
, sd_bus_error
*error
);
344 const char* ipv6_privacy_extensions_to_string(IPv6PrivacyExtensions i
) _const_
;
345 IPv6PrivacyExtensions
ipv6_privacy_extensions_from_string(const char *s
) _pure_
;
347 const char* dhcp_use_domains_to_string(DHCPUseDomains p
) _const_
;
348 DHCPUseDomains
dhcp_use_domains_from_string(const char *s
) _pure_
;
350 const char* radv_prefix_delegation_to_string(RADVPrefixDelegation i
) _const_
;
351 RADVPrefixDelegation
radv_prefix_delegation_from_string(const char *s
) _pure_
;
353 const char* keep_configuration_to_string(KeepConfiguration i
) _const_
;
354 KeepConfiguration
keep_configuration_from_string(const char *s
) _pure_
;