1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
4 #include <linux/nl80211.h>
10 #include "condition.h"
11 #include "conf-parser.h"
14 #include "networkd-brvlan.h"
15 #include "networkd-dhcp-common.h"
16 #include "networkd-dhcp4.h"
17 #include "networkd-dhcp6.h"
18 #include "networkd-dhcp-server.h"
19 #include "networkd-lldp-rx.h"
20 #include "networkd-lldp-tx.h"
21 #include "networkd-ndisc.h"
22 #include "networkd-radv.h"
23 #include "networkd-sysctl.h"
24 #include "networkd-util.h"
25 #include "ordered-set.h"
26 #include "resolve-util.h"
27 #include "socket-netlink.h"
29 typedef enum KeepConfiguration
{
30 KEEP_CONFIGURATION_NO
= 0,
31 KEEP_CONFIGURATION_DHCP_ON_START
= 1 << 0,
32 KEEP_CONFIGURATION_DHCP_ON_STOP
= 1 << 1,
33 KEEP_CONFIGURATION_DHCP
= KEEP_CONFIGURATION_DHCP_ON_START
| KEEP_CONFIGURATION_DHCP_ON_STOP
,
34 KEEP_CONFIGURATION_STATIC
= 1 << 2,
35 KEEP_CONFIGURATION_YES
= KEEP_CONFIGURATION_DHCP
| KEEP_CONFIGURATION_STATIC
,
36 _KEEP_CONFIGURATION_MAX
,
37 _KEEP_CONFIGURATION_INVALID
= -1,
40 typedef enum IPv6LinkLocalAddressGenMode
{
41 IPV6_LINK_LOCAL_ADDRESSS_GEN_MODE_EUI64
= IN6_ADDR_GEN_MODE_EUI64
,
42 IPV6_LINK_LOCAL_ADDRESSS_GEN_MODE_NONE
= IN6_ADDR_GEN_MODE_NONE
,
43 IPV6_LINK_LOCAL_ADDRESSS_GEN_MODE_STABLE_PRIVACY
= IN6_ADDR_GEN_MODE_STABLE_PRIVACY
,
44 IPV6_LINK_LOCAL_ADDRESSS_GEN_MODE_RANDOM
= IN6_ADDR_GEN_MODE_RANDOM
,
45 _IPV6_LINK_LOCAL_ADDRESS_GEN_MODE_MAX
,
46 _IPV6_LINK_LOCAL_ADDRESS_GEN_MODE_INVALID
= -1
47 } IPv6LinkLocalAddressGenMode
;
49 typedef struct Manager Manager
;
51 typedef struct NetworkDHCPServerEmitAddress
{
53 struct in_addr
*addresses
;
55 } NetworkDHCPServerEmitAddress
;
69 Set
*match_permanent_mac
;
74 char **match_property
;
75 char **match_wlan_iftype
;
78 LIST_HEAD(Condition
, conditions
);
80 /* Master or stacked netdevs */
85 Hashmap
*stacked_netdevs
;
89 Hashmap
*stacked_netdev_names
;
92 struct ether_addr
*mac
;
99 bool required_for_online
; /* Is this network required to be considered online? */
100 LinkOperationalStateRange required_operstate_for_online
;
103 bool configure_without_carrier
;
104 int ignore_carrier_loss
;
105 KeepConfiguration keep_configuration
;
107 bool default_route_on_device
;
110 /* DHCP Client Support */
112 DHCPClientIdentifier dhcp_client_identifier
;
116 char *dhcp_vendor_class_identifier
;
118 char **dhcp_user_class
;
120 uint64_t dhcp_max_attempts
;
121 uint32_t dhcp_route_metric
;
122 bool dhcp_route_metric_set
;
123 uint32_t dhcp_route_table
;
124 uint32_t dhcp_fallback_lease_lifetime
;
125 uint32_t dhcp_route_mtu
;
126 uint16_t dhcp_client_port
;
128 int dhcp_ip_service_type
;
130 bool dhcp_send_hostname
;
133 bool dhcp_use_dns_set
;
134 bool dhcp_routes_to_dns
;
136 bool dhcp_use_ntp_set
;
139 bool dhcp_use_routes
;
140 int dhcp_use_gateway
;
141 bool dhcp_use_timezone
;
142 bool dhcp_use_hostname
;
143 bool dhcp_route_table_set
;
144 bool dhcp_send_release
;
145 bool dhcp_send_decline
;
146 DHCPUseDomains dhcp_use_domains
;
147 Set
*dhcp_deny_listed_ip
;
148 Set
*dhcp_allow_listed_ip
;
149 Set
*dhcp_request_options
;
150 OrderedHashmap
*dhcp_client_send_options
;
151 OrderedHashmap
*dhcp_client_send_vendor_options
;
153 /* DHCPv6 Client support*/
155 bool dhcp6_use_dns_set
;
157 bool dhcp6_use_ntp_set
;
158 bool dhcp6_rapid_commit
;
159 uint8_t dhcp6_pd_length
;
160 uint32_t dhcp6_route_metric
;
161 bool dhcp6_route_metric_set
;
163 char **dhcp6_user_class
;
164 char **dhcp6_vendor_class
;
165 struct in6_addr dhcp6_pd_address
;
166 DHCP6ClientStartMode dhcp6_without_ra
;
167 OrderedHashmap
*dhcp6_client_send_options
;
168 OrderedHashmap
*dhcp6_client_send_vendor_options
;
169 Set
*dhcp6_request_options
;
170 /* Start DHCPv6 PD also when 'O' RA flag is set, see RFC 7084, WPD-4 */
171 bool dhcp6_force_pd_other_information
;
173 /* DHCP Server Support */
175 NetworkDHCPServerEmitAddress dhcp_server_emit
[_SD_DHCP_LEASE_SERVER_TYPE_MAX
];
176 bool dhcp_server_emit_router
;
177 bool dhcp_server_emit_timezone
;
178 char *dhcp_server_timezone
;
179 usec_t dhcp_server_default_lease_time_usec
, dhcp_server_max_lease_time_usec
;
180 uint32_t dhcp_server_pool_offset
;
181 uint32_t dhcp_server_pool_size
;
182 OrderedHashmap
*dhcp_server_send_options
;
183 OrderedHashmap
*dhcp_server_send_vendor_options
;
185 /* link local addressing support */
186 AddressFamily link_local
;
187 IPv6LinkLocalAddressGenMode ipv6ll_address_gen_mode
;
190 /* IPv6 RA support */
191 RADVPrefixDelegation router_prefix_delegation
;
192 usec_t router_lifetime_usec
;
193 uint8_t router_preference
;
195 bool router_other_information
;
196 bool router_emit_dns
;
197 bool router_emit_domains
;
198 usec_t router_dns_lifetime_usec
;
199 struct in6_addr
*router_dns
;
200 unsigned n_router_dns
;
201 OrderedSet
*router_search_domains
;
203 /* DHCPv6 Prefix Delegation support */
205 bool dhcp6_pd_announce
;
206 bool dhcp6_pd_assign
;
207 int64_t dhcp6_pd_subnet_id
;
208 union in_addr_union dhcp6_pd_token
;
214 int allow_port_to_be_root
;
217 int multicast_to_unicast
;
218 int neighbor_suppression
;
220 int bridge_proxy_arp
;
221 int bridge_proxy_arp_wifi
;
224 MulticastRouter multicast_router
;
229 uint32_t br_vid_bitmap
[BRIDGE_VLAN_BITMAP_LEN
];
230 uint32_t br_untagged_bitmap
[BRIDGE_VLAN_BITMAP_LEN
];
233 uint32_t can_bitrate
;
234 unsigned can_sample_point
;
235 uint32_t can_data_bitrate
;
236 unsigned can_data_sample_point
;
237 usec_t can_restart_us
;
238 int can_triple_sampling
;
244 /* sysctl settings */
245 AddressFamily ip_forward
;
246 int ipv4_accept_local
;
247 int ipv6_dad_transmits
;
251 IPv6PrivacyExtensions ipv6_privacy_extensions
;
253 Set
*ipv6_proxy_ndp_addresses
;
257 bool ipv6_accept_ra_use_dns
;
258 bool ipv6_accept_ra_use_autonomous_prefix
;
259 bool ipv6_accept_ra_use_onlink_prefix
;
262 bool ipv6_accept_ra_route_table_set
;
263 DHCPUseDomains ipv6_accept_ra_use_domains
;
264 IPv6AcceptRAStartDHCP6Client ipv6_accept_ra_start_dhcp6_client
;
265 uint32_t ipv6_accept_ra_route_table
;
266 Set
*ndisc_deny_listed_prefix
;
267 OrderedSet
*ipv6_tokens
;
270 LLDPMode lldp_mode
; /* LLDP reception */
271 LLDPEmit lldp_emit
; /* LLDP transmission */
272 char *lldp_mud
; /* LLDP MUD URL */
274 OrderedHashmap
*addresses_by_section
;
275 Hashmap
*routes_by_section
;
276 Hashmap
*nexthops_by_section
;
277 Hashmap
*fdb_entries_by_section
;
278 Hashmap
*mdb_entries_by_section
;
279 Hashmap
*neighbors_by_section
;
280 Hashmap
*address_labels_by_section
;
281 Hashmap
*prefixes_by_section
;
282 Hashmap
*route_prefixes_by_section
;
283 Hashmap
*rules_by_section
;
284 OrderedHashmap
*tc_by_section
;
285 OrderedHashmap
*sr_iov_by_section
;
287 /* All kinds of DNS configuration */
288 struct in_addr_full
**dns
;
290 OrderedSet
*search_domains
, *route_domains
;
291 int dns_default_route
;
292 ResolveSupport llmnr
;
294 DnssecMode dnssec_mode
;
295 DnsOverTlsMode dns_over_tls_mode
;
296 Set
*dnssec_negative_trust_anchors
;
302 Network
*network_ref(Network
*network
);
303 Network
*network_unref(Network
*network
);
304 DEFINE_TRIVIAL_CLEANUP_FUNC(Network
*, network_unref
);
306 int network_load(Manager
*manager
, OrderedHashmap
**networks
);
307 int network_reload(Manager
*manager
);
308 int network_load_one(Manager
*manager
, OrderedHashmap
**networks
, const char *filename
);
309 int network_verify(Network
*network
);
311 int network_get_by_name(Manager
*manager
, const char *name
, Network
**ret
);
312 int network_get(Manager
*manager
, unsigned short iftype
, sd_device
*device
,
313 const char *ifname
, char * const *alternative_names
, const char *driver
,
314 const struct ether_addr
*mac
, const struct ether_addr
*permanent_mac
,
315 enum nl80211_iftype wlan_iftype
, const char *ssid
, const struct ether_addr
*bssid
,
317 int network_apply(Network
*network
, Link
*link
);
318 void network_apply_anonymize_if_set(Network
*network
);
320 bool network_has_static_ipv6_configurations(Network
*network
);
322 CONFIG_PARSER_PROTOTYPE(config_parse_stacked_netdev
);
323 CONFIG_PARSER_PROTOTYPE(config_parse_tunnel
);
324 CONFIG_PARSER_PROTOTYPE(config_parse_domains
);
325 CONFIG_PARSER_PROTOTYPE(config_parse_dns
);
326 CONFIG_PARSER_PROTOTYPE(config_parse_hostname
);
327 CONFIG_PARSER_PROTOTYPE(config_parse_timezone
);
328 CONFIG_PARSER_PROTOTYPE(config_parse_dnssec_negative_trust_anchors
);
329 CONFIG_PARSER_PROTOTYPE(config_parse_ntp
);
330 CONFIG_PARSER_PROTOTYPE(config_parse_required_for_online
);
331 CONFIG_PARSER_PROTOTYPE(config_parse_keep_configuration
);
332 CONFIG_PARSER_PROTOTYPE(config_parse_ipv6_link_local_address_gen_mode
);
334 const struct ConfigPerfItem
* network_network_gperf_lookup(const char *key
, GPERF_LEN_TYPE length
);
336 const char* keep_configuration_to_string(KeepConfiguration i
) _const_
;
337 KeepConfiguration
keep_configuration_from_string(const char *s
) _pure_
;
339 const char* ipv6_link_local_address_gen_mode_to_string(IPv6LinkLocalAddressGenMode s
) _const_
;
340 IPv6LinkLocalAddressGenMode
ipv6_link_local_address_gen_mode_from_string(const char *s
) _pure_
;