1 /* SPDX-License-Identifier: LGPL-2.1+ */
4 #include <netinet/in.h>
5 #include <linux/if_bridge.h>
10 #include "condition.h"
11 #include "conf-parser.h"
12 #include "dhcp-identifier.h"
14 #include "netdev/netdev.h"
15 #include "networkd-address-label.h"
16 #include "networkd-address.h"
17 #include "networkd-brvlan.h"
18 #include "networkd-fdb.h"
19 #include "networkd-ipv6-proxy-ndp.h"
20 #include "networkd-lldp-tx.h"
21 #include "networkd-neighbor.h"
22 #include "networkd-radv.h"
23 #include "networkd-route.h"
24 #include "networkd-routing-policy-rule.h"
25 #include "networkd-util.h"
26 #include "ordered-set.h"
27 #include "resolve-util.h"
29 #define DHCP_ROUTE_METRIC 1024
30 #define IPV4LL_ROUTE_METRIC 2048
32 #define BRIDGE_VLAN_BITMAP_MAX 4096
33 #define BRIDGE_VLAN_BITMAP_LEN (BRIDGE_VLAN_BITMAP_MAX / 32)
35 typedef enum DHCPClientIdentifier
{
38 /* The following option may not be good for RFC regarding DHCP (3315 and 4361).
39 * But some setups require this. E.g., Sky Broadband, the second largest provider in the UK
40 * requires the client id to be set to a custom string, reported at
41 * https://github.com/systemd/systemd/issues/7828 */
42 DHCP_CLIENT_ID_DUID_ONLY
,
44 _DHCP_CLIENT_ID_INVALID
= -1,
45 } DHCPClientIdentifier
;
47 typedef enum IPv6PrivacyExtensions
{
48 /* The values map to the kernel's /proc/sys/net/ipv6/conf/xxx/use_tempaddr values */
49 IPV6_PRIVACY_EXTENSIONS_NO
,
50 IPV6_PRIVACY_EXTENSIONS_PREFER_PUBLIC
,
51 IPV6_PRIVACY_EXTENSIONS_YES
, /* aka prefer-temporary */
52 _IPV6_PRIVACY_EXTENSIONS_MAX
,
53 _IPV6_PRIVACY_EXTENSIONS_INVALID
= -1,
54 } IPv6PrivacyExtensions
;
56 typedef enum DHCPUseDomains
{
59 DHCP_USE_DOMAINS_ROUTE
,
60 _DHCP_USE_DOMAINS_MAX
,
61 _DHCP_USE_DOMAINS_INVALID
= -1,
64 typedef enum LLDPMode
{
67 LLDP_MODE_ROUTERS_ONLY
= 2,
69 _LLDP_MODE_INVALID
= -1,
73 /* Value of Type in [DHCP] section */
77 uint8_t raw_data
[MAX_DUID_LEN
];
81 typedef enum RADVPrefixDelegation
{
82 RADV_PREFIX_DELEGATION_NONE
,
83 RADV_PREFIX_DELEGATION_STATIC
,
84 RADV_PREFIX_DELEGATION_DHCP6
,
85 RADV_PREFIX_DELEGATION_BOTH
,
86 _RADV_PREFIX_DELEGATION_MAX
,
87 _RADV_PREFIX_DELEGATION_INVALID
= -1,
88 } RADVPrefixDelegation
;
90 typedef enum MulticastRouter
{
91 MULTICAST_ROUTER_NONE
= MDB_RTR_TYPE_DISABLED
,
92 MULTICAST_ROUTER_TEMPORARY_QUERY
= MDB_RTR_TYPE_TEMP_QUERY
,
93 MULTICAST_ROUTER_PERMANENT
= MDB_RTR_TYPE_PERM
,
94 MULTICAST_ROUTER_TEMPORARY
= MDB_RTR_TYPE_TEMP
,
95 _MULTICAST_ROUTER_MAX
,
96 _MULTICAST_ROUTER_INVALID
= -1,
99 typedef struct Manager Manager
;
114 LIST_HEAD(Condition
, conditions
);
121 Hashmap
*stacked_netdevs
;
125 Hashmap
*stacked_netdev_names
;
127 /* DHCP Client Support */
128 AddressFamilyBoolean dhcp
;
129 DHCPClientIdentifier dhcp_client_identifier
;
130 char *dhcp_vendor_class_identifier
;
131 char **dhcp_user_class
;
133 uint64_t dhcp_max_attempts
;
134 unsigned dhcp_route_metric
;
135 uint32_t dhcp_route_table
;
136 uint16_t dhcp_client_port
;
138 bool dhcp_send_hostname
;
144 bool dhcp_use_routes
;
145 bool dhcp_use_timezone
;
147 bool dhcp_use_hostname
;
148 bool dhcp_route_table_set
;
149 DHCPUseDomains dhcp_use_domains
;
150 Set
*dhcp_black_listed_ip
;
152 /* DHCP Server Support */
154 bool dhcp_server_emit_dns
;
155 struct in_addr
*dhcp_server_dns
;
156 unsigned n_dhcp_server_dns
;
157 bool dhcp_server_emit_ntp
;
158 struct in_addr
*dhcp_server_ntp
;
159 unsigned n_dhcp_server_ntp
;
160 bool dhcp_server_emit_router
;
161 bool dhcp_server_emit_timezone
;
162 char *dhcp_server_timezone
;
163 usec_t dhcp_server_default_lease_time_usec
, dhcp_server_max_lease_time_usec
;
164 uint32_t dhcp_server_pool_offset
;
165 uint32_t dhcp_server_pool_size
;
168 AddressFamilyBoolean link_local
;
171 /* IPv6 prefix delegation support */
172 RADVPrefixDelegation router_prefix_delegation
;
173 usec_t router_lifetime_usec
;
174 uint8_t router_preference
;
176 bool router_other_information
;
177 bool router_emit_dns
;
178 bool router_emit_domains
;
179 usec_t router_dns_lifetime_usec
;
180 struct in6_addr
*router_dns
;
181 unsigned n_router_dns
;
182 OrderedSet
*router_search_domains
;
183 bool dhcp6_force_pd_other_information
; /* Start DHCPv6 PD also when 'O'
184 RA flag is set, see RFC 7084,
191 int allow_port_to_be_root
;
194 int multicast_to_unicast
;
195 int neighbor_suppression
;
197 int bridge_proxy_arp
;
198 int bridge_proxy_arp_wifi
;
201 MulticastRouter multicast_router
;
205 uint32_t br_vid_bitmap
[BRIDGE_VLAN_BITMAP_LEN
];
206 uint32_t br_untagged_bitmap
[BRIDGE_VLAN_BITMAP_LEN
];
210 unsigned can_sample_point
;
211 usec_t can_restart_us
;
212 int can_triple_sampling
;
214 AddressFamilyBoolean ip_forward
;
218 int ipv6_dad_transmits
;
224 bool ipv6_accept_ra_use_dns
;
225 bool ipv6_accept_ra_use_autonomous_prefix
;
226 bool ipv6_accept_ra_use_onlink_prefix
;
229 DHCPUseDomains ipv6_accept_ra_use_domains
;
230 uint32_t ipv6_accept_ra_route_table
;
231 bool ipv6_accept_ra_route_table_set
;
233 union in_addr_union ipv6_token
;
234 IPv6PrivacyExtensions ipv6_privacy_extensions
;
236 struct ether_addr
*mac
;
238 bool mtu_is_set
; /* Indicate MTUBytes= is specified. */
243 bool configure_without_carrier
;
244 bool ignore_carrier_loss
;
250 bool required_for_online
; /* Is this network required to be considered online? */
251 LinkOperationalState required_operstate_for_online
;
253 LLDPMode lldp_mode
; /* LLDP reception */
254 LLDPEmit lldp_emit
; /* LLDP transmission */
256 LIST_HEAD(Address
, static_addresses
);
257 LIST_HEAD(Route
, static_routes
);
258 LIST_HEAD(FdbEntry
, static_fdb_entries
);
259 LIST_HEAD(IPv6ProxyNDPAddress
, ipv6_proxy_ndp_addresses
);
260 LIST_HEAD(Neighbor
, neighbors
);
261 LIST_HEAD(AddressLabel
, address_labels
);
262 LIST_HEAD(Prefix
, static_prefixes
);
263 LIST_HEAD(RoutingPolicyRule
, rules
);
265 unsigned n_static_addresses
;
266 unsigned n_static_routes
;
267 unsigned n_static_fdb_entries
;
268 unsigned n_ipv6_proxy_ndp_addresses
;
269 unsigned n_neighbors
;
270 unsigned n_address_labels
;
271 unsigned n_static_prefixes
;
274 Hashmap
*addresses_by_section
;
275 Hashmap
*routes_by_section
;
276 Hashmap
*fdb_entries_by_section
;
277 Hashmap
*neighbors_by_section
;
278 Hashmap
*address_labels_by_section
;
279 Hashmap
*prefixes_by_section
;
280 Hashmap
*rules_by_section
;
282 /* All kinds of DNS configuration */
283 struct in_addr_data
*dns
;
285 OrderedSet
*search_domains
, *route_domains
;
287 int dns_default_route
;
288 ResolveSupport llmnr
;
290 DnssecMode dnssec_mode
;
291 DnsOverTlsMode dns_over_tls_mode
;
292 Set
*dnssec_negative_trust_anchors
;
298 Network
*network_ref(Network
*network
);
299 Network
*network_unref(Network
*network
);
300 DEFINE_TRIVIAL_CLEANUP_FUNC(Network
*, network_unref
);
302 int network_load(Manager
*manager
);
303 int network_load_one(Manager
*manager
, const char *filename
);
304 int network_verify(Network
*network
);
306 int network_get_by_name(Manager
*manager
, const char *name
, Network
**ret
);
307 int network_get(Manager
*manager
, sd_device
*device
, const char *ifname
, const struct ether_addr
*mac
, Network
**ret
);
308 int network_apply(Network
*network
, Link
*link
);
309 void network_apply_anonymize_if_set(Network
*network
);
311 bool network_has_static_ipv6_addresses(Network
*network
);
313 CONFIG_PARSER_PROTOTYPE(config_parse_stacked_netdev
);
314 CONFIG_PARSER_PROTOTYPE(config_parse_domains
);
315 CONFIG_PARSER_PROTOTYPE(config_parse_tunnel
);
316 CONFIG_PARSER_PROTOTYPE(config_parse_dhcp
);
317 CONFIG_PARSER_PROTOTYPE(config_parse_dns
);
318 CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_client_identifier
);
319 CONFIG_PARSER_PROTOTYPE(config_parse_ipv6token
);
320 CONFIG_PARSER_PROTOTYPE(config_parse_ipv6_privacy_extensions
);
321 CONFIG_PARSER_PROTOTYPE(config_parse_hostname
);
322 CONFIG_PARSER_PROTOTYPE(config_parse_timezone
);
323 CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_server_dns
);
324 CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_black_listed_ip_address
);
325 CONFIG_PARSER_PROTOTYPE(config_parse_radv_dns
);
326 CONFIG_PARSER_PROTOTYPE(config_parse_radv_search_domains
);
327 CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_server_ntp
);
328 CONFIG_PARSER_PROTOTYPE(config_parse_dnssec_negative_trust_anchors
);
329 CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_use_domains
);
330 CONFIG_PARSER_PROTOTYPE(config_parse_lldp_mode
);
331 CONFIG_PARSER_PROTOTYPE(config_parse_section_route_table
);
332 CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_user_class
);
333 CONFIG_PARSER_PROTOTYPE(config_parse_ntp
);
334 CONFIG_PARSER_PROTOTYPE(config_parse_iaid
);
335 CONFIG_PARSER_PROTOTYPE(config_parse_required_for_online
);
336 CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_max_attempts
);
337 CONFIG_PARSER_PROTOTYPE(config_parse_multicast_router
);
338 /* Legacy IPv4LL support */
339 CONFIG_PARSER_PROTOTYPE(config_parse_ipv4ll
);
341 const struct ConfigPerfItem
* network_network_gperf_lookup(const char *key
, GPERF_LEN_TYPE length
);
343 extern const sd_bus_vtable network_vtable
[];
345 int network_node_enumerator(sd_bus
*bus
, const char *path
, void *userdata
, char ***nodes
, sd_bus_error
*error
);
346 int network_object_find(sd_bus
*bus
, const char *path
, const char *interface
, void *userdata
, void **found
, sd_bus_error
*error
);
348 const char* ipv6_privacy_extensions_to_string(IPv6PrivacyExtensions i
) _const_
;
349 IPv6PrivacyExtensions
ipv6_privacy_extensions_from_string(const char *s
) _pure_
;
351 const char* dhcp_use_domains_to_string(DHCPUseDomains p
) _const_
;
352 DHCPUseDomains
dhcp_use_domains_from_string(const char *s
) _pure_
;
354 const char* lldp_mode_to_string(LLDPMode m
) _const_
;
355 LLDPMode
lldp_mode_from_string(const char *s
) _pure_
;
357 const char* radv_prefix_delegation_to_string(RADVPrefixDelegation i
) _const_
;
358 RADVPrefixDelegation
radv_prefix_delegation_from_string(const char *s
) _pure_
;
360 const char* multicast_router_to_string(MulticastRouter i
) _const_
;
361 MulticastRouter
multicast_router_from_string(const char *s
) _pure_
;