]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/network/networkd-network.h
295b2dbefae01616c2c7270eba229ba23b5cb0cc
[thirdparty/systemd.git] / src / network / networkd-network.h
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3
4 #include <linux/nl80211.h>
5
6 #include "sd-bus.h"
7 #include "sd-device.h"
8 #include "sd-lldp-tx.h"
9
10 #include "bridge.h"
11 #include "condition.h"
12 #include "conf-parser.h"
13 #include "hashmap.h"
14 #include "ipoib.h"
15 #include "net-condition.h"
16 #include "netdev.h"
17 #include "networkd-bridge-vlan.h"
18 #include "networkd-dhcp-common.h"
19 #include "networkd-dhcp4.h"
20 #include "networkd-dhcp6.h"
21 #include "networkd-lldp-rx.h"
22 #include "networkd-ndisc.h"
23 #include "networkd-radv.h"
24 #include "networkd-sysctl.h"
25 #include "networkd-util.h"
26 #include "ordered-set.h"
27 #include "resolve-util.h"
28 #include "socket-netlink.h"
29
30 typedef enum KeepConfiguration {
31 KEEP_CONFIGURATION_NO = 0,
32 KEEP_CONFIGURATION_DHCP_ON_START = 1 << 0,
33 KEEP_CONFIGURATION_DHCP_ON_STOP = 1 << 1,
34 KEEP_CONFIGURATION_DHCP = KEEP_CONFIGURATION_DHCP_ON_START | KEEP_CONFIGURATION_DHCP_ON_STOP,
35 KEEP_CONFIGURATION_STATIC = 1 << 2,
36 KEEP_CONFIGURATION_YES = KEEP_CONFIGURATION_DHCP | KEEP_CONFIGURATION_STATIC,
37 _KEEP_CONFIGURATION_MAX,
38 _KEEP_CONFIGURATION_INVALID = -EINVAL,
39 } KeepConfiguration;
40
41 typedef enum IPv6LinkLocalAddressGenMode {
42 IPV6_LINK_LOCAL_ADDRESSS_GEN_MODE_EUI64 = IN6_ADDR_GEN_MODE_EUI64,
43 IPV6_LINK_LOCAL_ADDRESSS_GEN_MODE_NONE = IN6_ADDR_GEN_MODE_NONE,
44 IPV6_LINK_LOCAL_ADDRESSS_GEN_MODE_STABLE_PRIVACY = IN6_ADDR_GEN_MODE_STABLE_PRIVACY,
45 IPV6_LINK_LOCAL_ADDRESSS_GEN_MODE_RANDOM = IN6_ADDR_GEN_MODE_RANDOM,
46 _IPV6_LINK_LOCAL_ADDRESS_GEN_MODE_MAX,
47 _IPV6_LINK_LOCAL_ADDRESS_GEN_MODE_INVALID = -EINVAL,
48 } IPv6LinkLocalAddressGenMode;
49
50 typedef enum ActivationPolicy {
51 ACTIVATION_POLICY_UP,
52 ACTIVATION_POLICY_ALWAYS_UP,
53 ACTIVATION_POLICY_MANUAL,
54 ACTIVATION_POLICY_ALWAYS_DOWN,
55 ACTIVATION_POLICY_DOWN,
56 ACTIVATION_POLICY_BOUND,
57 _ACTIVATION_POLICY_MAX,
58 _ACTIVATION_POLICY_INVALID = -EINVAL,
59 } ActivationPolicy;
60
61 typedef struct Manager Manager;
62
63 typedef struct NetworkDHCPServerEmitAddress {
64 bool emit;
65 struct in_addr *addresses;
66 size_t n_addresses;
67 } NetworkDHCPServerEmitAddress;
68
69 struct Network {
70 Manager *manager;
71
72 unsigned n_ref;
73
74 char *name;
75 char *filename;
76 Hashmap *stats_by_path;
77 char *description;
78
79 /* [Match] section */
80 NetMatch match;
81 LIST_HEAD(Condition, conditions);
82
83 /* Master or stacked netdevs */
84 bool keep_master;
85 NetDev *batadv;
86 NetDev *bridge;
87 NetDev *bond;
88 NetDev *vrf;
89 NetDev *xfrm;
90 Hashmap *stacked_netdevs;
91 char *batadv_name;
92 char *bridge_name;
93 char *bond_name;
94 char *vrf_name;
95 Hashmap *stacked_netdev_names;
96
97 /* [Link] section */
98 struct hw_addr_data hw_addr;
99 uint32_t mtu;
100 int32_t group;
101 int arp;
102 int multicast;
103 int allmulticast;
104 int promiscuous;
105 bool unmanaged;
106 int required_for_online; /* Is this network required to be considered online? */
107 LinkOperationalStateRange required_operstate_for_online;
108 AddressFamily required_family_for_online;
109 ActivationPolicy activation_policy;
110
111 /* misc settings */
112 bool configure_without_carrier;
113 bool ignore_carrier_loss_set;
114 usec_t ignore_carrier_loss_usec; /* timespan */
115 KeepConfiguration keep_configuration;
116 char **bind_carrier;
117 bool default_route_on_device;
118 AddressFamily ip_masquerade;
119
120 /* DHCP Client Support */
121 AddressFamily dhcp;
122 DHCPClientIdentifier dhcp_client_identifier;
123 DUID dhcp_duid;
124 uint32_t dhcp_iaid;
125 bool dhcp_iaid_set;
126 char *dhcp_vendor_class_identifier;
127 char *dhcp_mudurl;
128 char **dhcp_user_class;
129 char *dhcp_hostname;
130 char *dhcp_label;
131 uint64_t dhcp_max_attempts;
132 uint32_t dhcp_route_metric;
133 bool dhcp_route_metric_set;
134 uint32_t dhcp_route_table;
135 bool dhcp_route_table_set;
136 uint32_t dhcp_fallback_lease_lifetime;
137 uint32_t dhcp_route_mtu;
138 uint16_t dhcp_client_port;
139 int dhcp_critical;
140 int dhcp_ip_service_type;
141 bool dhcp_anonymize;
142 bool dhcp_send_hostname;
143 int dhcp_broadcast;
144 bool dhcp_use_dns;
145 bool dhcp_use_dns_set;
146 bool dhcp_routes_to_dns;
147 bool dhcp_use_ntp;
148 bool dhcp_use_ntp_set;
149 bool dhcp_routes_to_ntp;
150 bool dhcp_use_sip;
151 bool dhcp_use_mtu;
152 bool dhcp_use_routes;
153 int dhcp_use_gateway;
154 bool dhcp_use_timezone;
155 bool dhcp_use_hostname;
156 bool dhcp_send_release;
157 bool dhcp_send_decline;
158 DHCPUseDomains dhcp_use_domains;
159 bool dhcp_use_domains_set;
160 Set *dhcp_deny_listed_ip;
161 Set *dhcp_allow_listed_ip;
162 Set *dhcp_request_options;
163 OrderedHashmap *dhcp_client_send_options;
164 OrderedHashmap *dhcp_client_send_vendor_options;
165
166 /* DHCPv6 Client support */
167 bool dhcp6_use_address;
168 bool dhcp6_use_pd_prefix;
169 bool dhcp6_use_dns;
170 bool dhcp6_use_dns_set;
171 bool dhcp6_use_hostname;
172 bool dhcp6_use_ntp;
173 bool dhcp6_use_ntp_set;
174 DHCPUseDomains dhcp6_use_domains;
175 bool dhcp6_use_domains_set;
176 uint32_t dhcp6_iaid;
177 bool dhcp6_iaid_set;
178 bool dhcp6_iaid_set_explicitly;
179 DUID dhcp6_duid;
180 uint8_t dhcp6_pd_prefix_length;
181 struct in6_addr dhcp6_pd_prefix_hint;
182 char *dhcp6_mudurl;
183 char **dhcp6_user_class;
184 char **dhcp6_vendor_class;
185 DHCP6ClientStartMode dhcp6_client_start_mode;
186 OrderedHashmap *dhcp6_client_send_options;
187 OrderedHashmap *dhcp6_client_send_vendor_options;
188 Set *dhcp6_request_options;
189
190 /* DHCP Server Support */
191 bool dhcp_server;
192 bool dhcp_server_bind_to_interface;
193 unsigned char dhcp_server_address_prefixlen;
194 struct in_addr dhcp_server_address;
195 int dhcp_server_uplink_index;
196 char *dhcp_server_uplink_name;
197 struct in_addr dhcp_server_relay_target;
198 char *dhcp_server_relay_agent_circuit_id;
199 char *dhcp_server_relay_agent_remote_id;
200 NetworkDHCPServerEmitAddress dhcp_server_emit[_SD_DHCP_LEASE_SERVER_TYPE_MAX];
201 bool dhcp_server_emit_router;
202 struct in_addr dhcp_server_router;
203 bool dhcp_server_emit_timezone;
204 char *dhcp_server_timezone;
205 usec_t dhcp_server_default_lease_time_usec, dhcp_server_max_lease_time_usec;
206 uint32_t dhcp_server_pool_offset;
207 uint32_t dhcp_server_pool_size;
208 OrderedHashmap *dhcp_server_send_options;
209 OrderedHashmap *dhcp_server_send_vendor_options;
210
211 /* link local addressing support */
212 AddressFamily link_local;
213 IPv6LinkLocalAddressGenMode ipv6ll_address_gen_mode;
214 struct in6_addr ipv6ll_stable_secret;
215 bool ipv4ll_route;
216
217 /* IPv6 RA support */
218 RADVPrefixDelegation router_prefix_delegation;
219 usec_t router_lifetime_usec;
220 uint8_t router_preference;
221 bool router_managed;
222 bool router_other_information;
223 bool router_emit_dns;
224 bool router_emit_domains;
225 usec_t router_dns_lifetime_usec;
226 struct in6_addr *router_dns;
227 unsigned n_router_dns;
228 OrderedSet *router_search_domains;
229 int router_uplink_index;
230 char *router_uplink_name;
231
232 /* DHCPv6 Prefix Delegation support */
233 int dhcp6_pd;
234 bool dhcp6_pd_announce;
235 bool dhcp6_pd_assign;
236 bool dhcp6_pd_manage_temporary_address;
237 int64_t dhcp6_pd_subnet_id;
238 uint32_t dhcp6_pd_route_metric;
239 Set *dhcp6_pd_tokens;
240 int dhcp6_pd_uplink_index;
241 char *dhcp6_pd_uplink_name;
242
243 /* Bridge Support */
244 int use_bpdu;
245 int hairpin;
246 int fast_leave;
247 int allow_port_to_be_root;
248 int unicast_flood;
249 int multicast_flood;
250 int multicast_to_unicast;
251 int neighbor_suppression;
252 int learning;
253 int bridge_proxy_arp;
254 int bridge_proxy_arp_wifi;
255 uint32_t cost;
256 uint16_t priority;
257 MulticastRouter multicast_router;
258
259 /* Bridge VLAN */
260 bool use_br_vlan;
261 uint16_t pvid;
262 uint32_t br_vid_bitmap[BRIDGE_VLAN_BITMAP_LEN];
263 uint32_t br_untagged_bitmap[BRIDGE_VLAN_BITMAP_LEN];
264
265 /* CAN support */
266 uint32_t can_bitrate;
267 unsigned can_sample_point;
268 nsec_t can_time_quanta_ns;
269 uint32_t can_propagation_segment;
270 uint32_t can_phase_buffer_segment_1;
271 uint32_t can_phase_buffer_segment_2;
272 uint32_t can_sync_jump_width;
273 uint32_t can_data_bitrate;
274 unsigned can_data_sample_point;
275 nsec_t can_data_time_quanta_ns;
276 uint32_t can_data_propagation_segment;
277 uint32_t can_data_phase_buffer_segment_1;
278 uint32_t can_data_phase_buffer_segment_2;
279 uint32_t can_data_sync_jump_width;
280 usec_t can_restart_us;
281 uint32_t can_control_mode_mask;
282 uint32_t can_control_mode_flags;
283 uint16_t can_termination;
284 bool can_termination_set;
285
286 /* IPoIB support */
287 IPoIBMode ipoib_mode;
288 int ipoib_umcast;
289
290 /* sysctl settings */
291 AddressFamily ip_forward;
292 int ipv4_accept_local;
293 int ipv4_route_localnet;
294 int ipv6_dad_transmits;
295 int ipv6_hop_limit;
296 int proxy_arp;
297 uint32_t ipv6_mtu;
298 IPv6PrivacyExtensions ipv6_privacy_extensions;
299 int ipv6_proxy_ndp;
300 Set *ipv6_proxy_ndp_addresses;
301
302 /* IPv6 accept RA */
303 int ipv6_accept_ra;
304 bool ipv6_accept_ra_use_dns;
305 bool ipv6_accept_ra_use_gateway;
306 bool ipv6_accept_ra_use_route_prefix;
307 bool ipv6_accept_ra_use_autonomous_prefix;
308 bool ipv6_accept_ra_use_onlink_prefix;
309 bool ipv6_accept_ra_use_mtu;
310 bool active_slave;
311 bool primary_slave;
312 DHCPUseDomains ipv6_accept_ra_use_domains;
313 IPv6AcceptRAStartDHCP6Client ipv6_accept_ra_start_dhcp6_client;
314 uint32_t ipv6_accept_ra_route_table;
315 bool ipv6_accept_ra_route_table_set;
316 uint32_t ipv6_accept_ra_route_metric;
317 bool ipv6_accept_ra_route_metric_set;
318 Set *ndisc_deny_listed_router;
319 Set *ndisc_allow_listed_router;
320 Set *ndisc_deny_listed_prefix;
321 Set *ndisc_allow_listed_prefix;
322 Set *ndisc_deny_listed_route_prefix;
323 Set *ndisc_allow_listed_route_prefix;
324 Set *ndisc_tokens;
325
326 /* LLDP support */
327 LLDPMode lldp_mode; /* LLDP reception */
328 sd_lldp_multicast_mode_t lldp_multicast_mode; /* LLDP transmission */
329 char *lldp_mudurl; /* LLDP MUD URL */
330
331 OrderedHashmap *addresses_by_section;
332 Hashmap *routes_by_section;
333 Hashmap *nexthops_by_section;
334 Hashmap *bridge_fdb_entries_by_section;
335 Hashmap *bridge_mdb_entries_by_section;
336 Hashmap *neighbors_by_section;
337 Hashmap *address_labels_by_section;
338 Hashmap *prefixes_by_section;
339 Hashmap *route_prefixes_by_section;
340 Hashmap *rules_by_section;
341 Hashmap *dhcp_static_leases_by_section;
342 OrderedHashmap *tc_by_section;
343 OrderedHashmap *sr_iov_by_section;
344
345 /* All kinds of DNS configuration */
346 struct in_addr_full **dns;
347 unsigned n_dns;
348 OrderedSet *search_domains, *route_domains;
349 int dns_default_route;
350 ResolveSupport llmnr;
351 ResolveSupport mdns;
352 DnssecMode dnssec_mode;
353 DnsOverTlsMode dns_over_tls_mode;
354 Set *dnssec_negative_trust_anchors;
355
356 /* NTP */
357 char **ntp;
358 };
359
360 Network *network_ref(Network *network);
361 Network *network_unref(Network *network);
362 DEFINE_TRIVIAL_CLEANUP_FUNC(Network*, network_unref);
363
364 int network_load(Manager *manager, OrderedHashmap **networks);
365 int network_reload(Manager *manager);
366 int network_load_one(Manager *manager, OrderedHashmap **networks, const char *filename);
367 int network_verify(Network *network);
368
369 int manager_build_dhcp6_pd_subnet_ids(Manager *manager);
370
371 int network_get_by_name(Manager *manager, const char *name, Network **ret);
372 void network_apply_anonymize_if_set(Network *network);
373
374 bool network_has_static_ipv6_configurations(Network *network);
375
376 CONFIG_PARSER_PROTOTYPE(config_parse_stacked_netdev);
377 CONFIG_PARSER_PROTOTYPE(config_parse_tunnel);
378 CONFIG_PARSER_PROTOTYPE(config_parse_domains);
379 CONFIG_PARSER_PROTOTYPE(config_parse_dns);
380 CONFIG_PARSER_PROTOTYPE(config_parse_hostname);
381 CONFIG_PARSER_PROTOTYPE(config_parse_timezone);
382 CONFIG_PARSER_PROTOTYPE(config_parse_dnssec_negative_trust_anchors);
383 CONFIG_PARSER_PROTOTYPE(config_parse_ntp);
384 CONFIG_PARSER_PROTOTYPE(config_parse_required_for_online);
385 CONFIG_PARSER_PROTOTYPE(config_parse_required_family_for_online);
386 CONFIG_PARSER_PROTOTYPE(config_parse_keep_configuration);
387 CONFIG_PARSER_PROTOTYPE(config_parse_ipv6_link_local_address_gen_mode);
388 CONFIG_PARSER_PROTOTYPE(config_parse_activation_policy);
389 CONFIG_PARSER_PROTOTYPE(config_parse_link_group);
390 CONFIG_PARSER_PROTOTYPE(config_parse_ignore_carrier_loss);
391
392 const struct ConfigPerfItem* network_network_gperf_lookup(const char *key, GPERF_LEN_TYPE length);
393
394 const char* keep_configuration_to_string(KeepConfiguration i) _const_;
395 KeepConfiguration keep_configuration_from_string(const char *s) _pure_;
396
397 const char* ipv6_link_local_address_gen_mode_to_string(IPv6LinkLocalAddressGenMode s) _const_;
398 IPv6LinkLocalAddressGenMode ipv6_link_local_address_gen_mode_from_string(const char *s) _pure_;
399
400 const char* activation_policy_to_string(ActivationPolicy i) _const_;
401 ActivationPolicy activation_policy_from_string(const char *s) _pure_;