1 /* SPDX-License-Identifier: LGPL-2.1+ */
8 #include "conf-parser.h"
10 #include "netdev/bridge.h"
11 #include "netdev/netdev.h"
12 #include "networkd-address-label.h"
13 #include "networkd-address.h"
14 #include "networkd-brvlan.h"
15 #include "networkd-dhcp-common.h"
16 #include "networkd-dhcp4.h"
17 #include "networkd-fdb.h"
18 #include "networkd-ipv6-proxy-ndp.h"
19 #include "networkd-lldp-rx.h"
20 #include "networkd-lldp-tx.h"
21 #include "networkd-neighbor.h"
22 #include "networkd-nexthop.h"
23 #include "networkd-radv.h"
24 #include "networkd-route.h"
25 #include "networkd-routing-policy-rule.h"
26 #include "networkd-util.h"
27 #include "ordered-set.h"
28 #include "resolve-util.h"
30 typedef enum IPv6PrivacyExtensions
{
31 /* The values map to the kernel's /proc/sys/net/ipv6/conf/xxx/use_tempaddr values */
32 IPV6_PRIVACY_EXTENSIONS_NO
,
33 IPV6_PRIVACY_EXTENSIONS_PREFER_PUBLIC
,
34 IPV6_PRIVACY_EXTENSIONS_YES
, /* aka prefer-temporary */
35 _IPV6_PRIVACY_EXTENSIONS_MAX
,
36 _IPV6_PRIVACY_EXTENSIONS_INVALID
= -1,
37 } IPv6PrivacyExtensions
;
39 typedef enum KeepConfiguration
{
40 KEEP_CONFIGURATION_NO
= 0,
41 KEEP_CONFIGURATION_DHCP_ON_START
= 1 << 0,
42 KEEP_CONFIGURATION_DHCP_ON_STOP
= 1 << 1,
43 KEEP_CONFIGURATION_DHCP
= KEEP_CONFIGURATION_DHCP_ON_START
| KEEP_CONFIGURATION_DHCP_ON_STOP
,
44 KEEP_CONFIGURATION_STATIC
= 1 << 2,
45 KEEP_CONFIGURATION_YES
= KEEP_CONFIGURATION_DHCP
| KEEP_CONFIGURATION_STATIC
,
46 _KEEP_CONFIGURATION_MAX
,
47 _KEEP_CONFIGURATION_INVALID
= -1,
50 typedef struct Manager Manager
;
65 char **match_property
;
68 LIST_HEAD(Condition
, conditions
);
76 Hashmap
*stacked_netdevs
;
80 Hashmap
*stacked_netdev_names
;
82 /* DHCP Client Support */
84 DHCPClientIdentifier dhcp_client_identifier
;
85 char *dhcp_vendor_class_identifier
;
86 char **dhcp_user_class
;
88 uint64_t dhcp_max_attempts
;
89 unsigned dhcp_route_metric
;
90 uint32_t dhcp_route_table
;
91 uint16_t dhcp_client_port
;
95 bool dhcp_send_hostname
;
98 bool dhcp_routes_to_dns
;
102 bool dhcp_use_routes
;
103 bool dhcp_use_timezone
;
105 bool dhcp_use_hostname
;
106 bool dhcp_route_table_set
;
107 bool dhcp_send_release
;
108 DHCPUseDomains dhcp_use_domains
;
109 Set
*dhcp_black_listed_ip
;
110 Set
*dhcp_request_options
;
111 OrderedHashmap
*dhcp_send_options
;
113 /* DHCPv6 Client support*/
116 uint8_t dhcp6_pd_length
;
117 struct in6_addr dhcp6_pd_address
;
119 /* DHCP Server Support */
122 bool dhcp_server_emit_dns
;
123 struct in_addr
*dhcp_server_dns
;
124 unsigned n_dhcp_server_dns
;
126 bool dhcp_server_emit_ntp
;
127 struct in_addr
*dhcp_server_ntp
;
128 unsigned n_dhcp_server_ntp
;
130 bool dhcp_server_emit_sip
;
131 struct in_addr
*dhcp_server_sip
;
132 unsigned n_dhcp_server_sip
;
134 bool dhcp_server_emit_router
;
135 bool dhcp_server_emit_timezone
;
136 char *dhcp_server_timezone
;
137 usec_t dhcp_server_default_lease_time_usec
, dhcp_server_max_lease_time_usec
;
138 uint32_t dhcp_server_pool_offset
;
139 uint32_t dhcp_server_pool_size
;
142 AddressFamily link_local
;
145 bool default_route_on_device
;
147 /* IPv6 prefix delegation support */
148 RADVPrefixDelegation router_prefix_delegation
;
149 usec_t router_lifetime_usec
;
150 uint8_t router_preference
;
152 bool router_other_information
;
153 bool router_emit_dns
;
154 bool router_emit_domains
;
155 usec_t router_dns_lifetime_usec
;
156 struct in6_addr
*router_dns
;
157 unsigned n_router_dns
;
158 OrderedSet
*router_search_domains
;
159 bool dhcp6_force_pd_other_information
; /* Start DHCPv6 PD also when 'O'
160 RA flag is set, see RFC 7084,
167 int allow_port_to_be_root
;
170 int multicast_to_unicast
;
171 int neighbor_suppression
;
173 int bridge_proxy_arp
;
174 int bridge_proxy_arp_wifi
;
177 MulticastRouter multicast_router
;
181 uint32_t br_vid_bitmap
[BRIDGE_VLAN_BITMAP_LEN
];
182 uint32_t br_untagged_bitmap
[BRIDGE_VLAN_BITMAP_LEN
];
186 unsigned can_sample_point
;
187 usec_t can_restart_us
;
188 int can_triple_sampling
;
190 AddressFamily ip_forward
;
194 int ipv6_dad_transmits
;
200 bool ipv6_accept_ra_use_dns
;
201 bool ipv6_accept_ra_use_autonomous_prefix
;
202 bool ipv6_accept_ra_use_onlink_prefix
;
205 DHCPUseDomains ipv6_accept_ra_use_domains
;
206 uint32_t ipv6_accept_ra_route_table
;
207 bool ipv6_accept_ra_route_table_set
;
208 Set
*ndisc_black_listed_prefix
;
210 union in_addr_union ipv6_token
;
211 IPv6PrivacyExtensions ipv6_privacy_extensions
;
213 struct ether_addr
*mac
;
219 bool configure_without_carrier
;
220 bool ignore_carrier_loss
;
221 KeepConfiguration keep_configuration
;
227 bool required_for_online
; /* Is this network required to be considered online? */
228 LinkOperationalState required_operstate_for_online
;
230 LLDPMode lldp_mode
; /* LLDP reception */
231 LLDPEmit lldp_emit
; /* LLDP transmission */
233 LIST_HEAD(Address
, static_addresses
);
234 LIST_HEAD(Route
, static_routes
);
235 LIST_HEAD(NextHop
, static_nexthops
);
236 LIST_HEAD(FdbEntry
, static_fdb_entries
);
237 LIST_HEAD(IPv6ProxyNDPAddress
, ipv6_proxy_ndp_addresses
);
238 LIST_HEAD(Neighbor
, neighbors
);
239 LIST_HEAD(AddressLabel
, address_labels
);
240 LIST_HEAD(Prefix
, static_prefixes
);
241 LIST_HEAD(Prefix
, static_route_prefixes
);
242 LIST_HEAD(RoutingPolicyRule
, rules
);
244 unsigned n_static_addresses
;
245 unsigned n_static_routes
;
246 unsigned n_static_nexthops
;
247 unsigned n_static_fdb_entries
;
248 unsigned n_ipv6_proxy_ndp_addresses
;
249 unsigned n_neighbors
;
250 unsigned n_address_labels
;
251 unsigned n_static_prefixes
;
252 unsigned n_static_route_prefixes
;
255 Hashmap
*addresses_by_section
;
256 Hashmap
*routes_by_section
;
257 Hashmap
*nexthops_by_section
;
258 Hashmap
*fdb_entries_by_section
;
259 Hashmap
*neighbors_by_section
;
260 Hashmap
*address_labels_by_section
;
261 Hashmap
*prefixes_by_section
;
262 Hashmap
*route_prefixes_by_section
;
263 Hashmap
*rules_by_section
;
265 /* All kinds of DNS configuration */
266 struct in_addr_data
*dns
;
268 OrderedSet
*search_domains
, *route_domains
;
270 int dns_default_route
;
271 ResolveSupport llmnr
;
273 DnssecMode dnssec_mode
;
274 DnsOverTlsMode dns_over_tls_mode
;
275 Set
*dnssec_negative_trust_anchors
;
282 Network
*network_ref(Network
*network
);
283 Network
*network_unref(Network
*network
);
284 DEFINE_TRIVIAL_CLEANUP_FUNC(Network
*, network_unref
);
286 int network_load(Manager
*manager
);
287 int network_load_one(Manager
*manager
, const char *filename
);
288 int network_verify(Network
*network
);
290 int network_get_by_name(Manager
*manager
, const char *name
, Network
**ret
);
291 int network_get(Manager
*manager
, sd_device
*device
, const char *ifname
, const struct ether_addr
*mac
,
292 const char *ssid
, const struct ether_addr
*bssid
, Network
**ret
);
293 int network_apply(Network
*network
, Link
*link
);
294 void network_apply_anonymize_if_set(Network
*network
);
296 bool network_has_static_ipv6_configurations(Network
*network
);
298 CONFIG_PARSER_PROTOTYPE(config_parse_stacked_netdev
);
299 CONFIG_PARSER_PROTOTYPE(config_parse_tunnel
);
300 CONFIG_PARSER_PROTOTYPE(config_parse_ipv6token
);
301 CONFIG_PARSER_PROTOTYPE(config_parse_ipv6_privacy_extensions
);
302 CONFIG_PARSER_PROTOTYPE(config_parse_domains
);
303 CONFIG_PARSER_PROTOTYPE(config_parse_dns
);
304 CONFIG_PARSER_PROTOTYPE(config_parse_hostname
);
305 CONFIG_PARSER_PROTOTYPE(config_parse_timezone
);
306 CONFIG_PARSER_PROTOTYPE(config_parse_dnssec_negative_trust_anchors
);
307 CONFIG_PARSER_PROTOTYPE(config_parse_ntp
);
308 CONFIG_PARSER_PROTOTYPE(config_parse_required_for_online
);
309 CONFIG_PARSER_PROTOTYPE(config_parse_keep_configuration
);
311 const struct ConfigPerfItem
* network_network_gperf_lookup(const char *key
, GPERF_LEN_TYPE length
);
313 const char* ipv6_privacy_extensions_to_string(IPv6PrivacyExtensions i
) _const_
;
314 IPv6PrivacyExtensions
ipv6_privacy_extensions_from_string(const char *s
) _pure_
;
316 const char* keep_configuration_to_string(KeepConfiguration i
) _const_
;
317 KeepConfiguration
keep_configuration_from_string(const char *s
) _pure_
;