1 /* SPDX-License-Identifier: LGPL-2.1+ */
4 #include <linux/nl80211.h>
10 #include "condition.h"
11 #include "conf-parser.h"
14 #include "networkd-address-label.h"
15 #include "networkd-address.h"
16 #include "networkd-brvlan.h"
17 #include "networkd-dhcp-common.h"
18 #include "networkd-dhcp4.h"
19 #include "networkd-dhcp-server.h"
20 #include "networkd-fdb.h"
21 #include "networkd-ipv6-proxy-ndp.h"
22 #include "networkd-lldp-rx.h"
23 #include "networkd-lldp-tx.h"
24 #include "networkd-neighbor.h"
25 #include "networkd-nexthop.h"
26 #include "networkd-radv.h"
27 #include "networkd-route.h"
28 #include "networkd-routing-policy-rule.h"
29 #include "networkd-util.h"
30 #include "ordered-set.h"
32 #include "resolve-util.h"
34 typedef enum IPv6PrivacyExtensions
{
35 /* The values map to the kernel's /proc/sys/net/ipv6/conf/xxx/use_tempaddr values */
36 IPV6_PRIVACY_EXTENSIONS_NO
,
37 IPV6_PRIVACY_EXTENSIONS_PREFER_PUBLIC
,
38 IPV6_PRIVACY_EXTENSIONS_YES
, /* aka prefer-temporary */
39 _IPV6_PRIVACY_EXTENSIONS_MAX
,
40 _IPV6_PRIVACY_EXTENSIONS_INVALID
= -1,
41 } IPv6PrivacyExtensions
;
43 typedef enum KeepConfiguration
{
44 KEEP_CONFIGURATION_NO
= 0,
45 KEEP_CONFIGURATION_DHCP_ON_START
= 1 << 0,
46 KEEP_CONFIGURATION_DHCP_ON_STOP
= 1 << 1,
47 KEEP_CONFIGURATION_DHCP
= KEEP_CONFIGURATION_DHCP_ON_START
| KEEP_CONFIGURATION_DHCP_ON_STOP
,
48 KEEP_CONFIGURATION_STATIC
= 1 << 2,
49 KEEP_CONFIGURATION_YES
= KEEP_CONFIGURATION_DHCP
| KEEP_CONFIGURATION_STATIC
,
50 _KEEP_CONFIGURATION_MAX
,
51 _KEEP_CONFIGURATION_INVALID
= -1,
54 typedef struct Manager Manager
;
70 char **match_property
;
71 char **match_wlan_iftype
;
74 LIST_HEAD(Condition
, conditions
);
82 Hashmap
*stacked_netdevs
;
86 Hashmap
*stacked_netdev_names
;
88 /* DHCP Client Support */
90 DHCPClientIdentifier dhcp_client_identifier
;
91 char *dhcp_vendor_class_identifier
;
92 char **dhcp_user_class
;
94 uint64_t dhcp_max_attempts
;
95 unsigned dhcp_route_metric
;
96 uint32_t dhcp_route_table
;
97 uint16_t dhcp_client_port
;
101 bool dhcp_send_hostname
;
104 bool dhcp_routes_to_dns
;
108 bool dhcp_use_routes
;
109 bool dhcp_use_timezone
;
111 bool dhcp_use_hostname
;
112 bool dhcp_route_table_set
;
113 bool dhcp_send_release
;
114 DHCPUseDomains dhcp_use_domains
;
115 Set
*dhcp_black_listed_ip
;
116 Set
*dhcp_request_options
;
117 OrderedHashmap
*dhcp_client_send_options
;
118 OrderedHashmap
*dhcp_server_send_options
;
120 /* DHCPv6 Client support*/
123 uint8_t dhcp6_pd_length
;
124 struct in6_addr dhcp6_pd_address
;
126 /* DHCP Server Support */
129 bool dhcp_server_emit_dns
;
130 struct in_addr
*dhcp_server_dns
;
131 unsigned n_dhcp_server_dns
;
133 bool dhcp_server_emit_ntp
;
134 struct in_addr
*dhcp_server_ntp
;
135 unsigned n_dhcp_server_ntp
;
137 bool dhcp_server_emit_sip
;
138 struct in_addr
*dhcp_server_sip
;
139 unsigned n_dhcp_server_sip
;
141 bool dhcp_server_emit_router
;
142 bool dhcp_server_emit_timezone
;
143 char *dhcp_server_timezone
;
144 usec_t dhcp_server_default_lease_time_usec
, dhcp_server_max_lease_time_usec
;
145 uint32_t dhcp_server_pool_offset
;
146 uint32_t dhcp_server_pool_size
;
149 AddressFamily link_local
;
152 bool default_route_on_device
;
154 /* IPv6 prefix delegation support */
155 RADVPrefixDelegation router_prefix_delegation
;
156 usec_t router_lifetime_usec
;
157 uint8_t router_preference
;
159 bool router_other_information
;
160 bool router_emit_dns
;
161 bool router_emit_domains
;
162 usec_t router_dns_lifetime_usec
;
163 struct in6_addr
*router_dns
;
164 unsigned n_router_dns
;
165 OrderedSet
*router_search_domains
;
166 bool dhcp6_force_pd_other_information
; /* Start DHCPv6 PD also when 'O'
167 RA flag is set, see RFC 7084,
174 int allow_port_to_be_root
;
177 int multicast_to_unicast
;
178 int neighbor_suppression
;
180 int bridge_proxy_arp
;
181 int bridge_proxy_arp_wifi
;
184 MulticastRouter multicast_router
;
188 uint32_t br_vid_bitmap
[BRIDGE_VLAN_BITMAP_LEN
];
189 uint32_t br_untagged_bitmap
[BRIDGE_VLAN_BITMAP_LEN
];
193 unsigned can_sample_point
;
194 usec_t can_restart_us
;
195 int can_triple_sampling
;
197 AddressFamily ip_forward
;
201 int ipv6_dad_transmits
;
207 bool ipv6_accept_ra_use_dns
;
208 bool ipv6_accept_ra_use_autonomous_prefix
;
209 bool ipv6_accept_ra_use_onlink_prefix
;
212 DHCPUseDomains ipv6_accept_ra_use_domains
;
213 uint32_t ipv6_accept_ra_route_table
;
214 bool ipv6_accept_ra_route_table_set
;
215 Set
*ndisc_black_listed_prefix
;
217 union in_addr_union ipv6_token
;
218 IPv6PrivacyExtensions ipv6_privacy_extensions
;
220 struct ether_addr
*mac
;
226 bool configure_without_carrier
;
227 bool ignore_carrier_loss
;
228 KeepConfiguration keep_configuration
;
234 bool required_for_online
; /* Is this network required to be considered online? */
235 LinkOperationalState required_operstate_for_online
;
237 LLDPMode lldp_mode
; /* LLDP reception */
238 LLDPEmit lldp_emit
; /* LLDP transmission */
240 LIST_HEAD(Address
, static_addresses
);
241 LIST_HEAD(Route
, static_routes
);
242 LIST_HEAD(NextHop
, static_nexthops
);
243 LIST_HEAD(FdbEntry
, static_fdb_entries
);
244 LIST_HEAD(IPv6ProxyNDPAddress
, ipv6_proxy_ndp_addresses
);
245 LIST_HEAD(Neighbor
, neighbors
);
246 LIST_HEAD(AddressLabel
, address_labels
);
247 LIST_HEAD(Prefix
, static_prefixes
);
248 LIST_HEAD(RoutePrefix
, static_route_prefixes
);
249 LIST_HEAD(RoutingPolicyRule
, rules
);
251 unsigned n_static_addresses
;
252 unsigned n_static_routes
;
253 unsigned n_static_nexthops
;
254 unsigned n_static_fdb_entries
;
255 unsigned n_ipv6_proxy_ndp_addresses
;
256 unsigned n_neighbors
;
257 unsigned n_address_labels
;
258 unsigned n_static_prefixes
;
259 unsigned n_static_route_prefixes
;
262 Hashmap
*addresses_by_section
;
263 Hashmap
*routes_by_section
;
264 Hashmap
*nexthops_by_section
;
265 Hashmap
*fdb_entries_by_section
;
266 Hashmap
*neighbors_by_section
;
267 Hashmap
*address_labels_by_section
;
268 Hashmap
*prefixes_by_section
;
269 Hashmap
*route_prefixes_by_section
;
270 Hashmap
*rules_by_section
;
271 OrderedHashmap
*qdiscs_by_section
;
273 /* All kinds of DNS configuration */
274 struct in_addr_data
*dns
;
276 OrderedSet
*search_domains
, *route_domains
;
278 int dns_default_route
;
279 ResolveSupport llmnr
;
281 DnssecMode dnssec_mode
;
282 DnsOverTlsMode dns_over_tls_mode
;
283 Set
*dnssec_negative_trust_anchors
;
290 Network
*network_ref(Network
*network
);
291 Network
*network_unref(Network
*network
);
292 DEFINE_TRIVIAL_CLEANUP_FUNC(Network
*, network_unref
);
294 int network_load(Manager
*manager
, OrderedHashmap
**networks
);
295 int network_reload(Manager
*manager
);
296 int network_load_one(Manager
*manager
, OrderedHashmap
**networks
, const char *filename
);
297 int network_verify(Network
*network
);
299 int network_get_by_name(Manager
*manager
, const char *name
, Network
**ret
);
300 int network_get(Manager
*manager
, sd_device
*device
, const char *ifname
, char * const *alternative_names
,
301 const struct ether_addr
*mac
, enum nl80211_iftype wlan_iftype
, const char *ssid
,
302 const struct ether_addr
*bssid
, Network
**ret
);
303 int network_apply(Network
*network
, Link
*link
);
304 void network_apply_anonymize_if_set(Network
*network
);
306 bool network_has_static_ipv6_configurations(Network
*network
);
308 CONFIG_PARSER_PROTOTYPE(config_parse_stacked_netdev
);
309 CONFIG_PARSER_PROTOTYPE(config_parse_tunnel
);
310 CONFIG_PARSER_PROTOTYPE(config_parse_ipv6token
);
311 CONFIG_PARSER_PROTOTYPE(config_parse_ipv6_privacy_extensions
);
312 CONFIG_PARSER_PROTOTYPE(config_parse_domains
);
313 CONFIG_PARSER_PROTOTYPE(config_parse_dns
);
314 CONFIG_PARSER_PROTOTYPE(config_parse_hostname
);
315 CONFIG_PARSER_PROTOTYPE(config_parse_timezone
);
316 CONFIG_PARSER_PROTOTYPE(config_parse_dnssec_negative_trust_anchors
);
317 CONFIG_PARSER_PROTOTYPE(config_parse_ntp
);
318 CONFIG_PARSER_PROTOTYPE(config_parse_required_for_online
);
319 CONFIG_PARSER_PROTOTYPE(config_parse_keep_configuration
);
321 const struct ConfigPerfItem
* network_network_gperf_lookup(const char *key
, GPERF_LEN_TYPE length
);
323 const char* ipv6_privacy_extensions_to_string(IPv6PrivacyExtensions i
) _const_
;
324 IPv6PrivacyExtensions
ipv6_privacy_extensions_from_string(const char *s
) _pure_
;
326 const char* keep_configuration_to_string(KeepConfiguration i
) _const_
;
327 KeepConfiguration
keep_configuration_from_string(const char *s
) _pure_
;