]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/network/networkd-network.h
network: can: allow to specify bit-timing with TimeQuantaNSec= and friends
[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
9 #include "bridge.h"
10 #include "condition.h"
11 #include "conf-parser.h"
12 #include "hashmap.h"
13 #include "net-condition.h"
14 #include "netdev.h"
15 #include "networkd-bridge-vlan.h"
16 #include "networkd-dhcp-common.h"
17 #include "networkd-dhcp4.h"
18 #include "networkd-dhcp6.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"
28
29 /* Special values for *_uplink_index. */
30 #define UPLINK_INDEX_AUTO 0 /* uplink will be selected automatically */
31 #define UPLINK_INDEX_NONE -1 /* uplink will not be selected automatically */
32
33 typedef enum KeepConfiguration {
34 KEEP_CONFIGURATION_NO = 0,
35 KEEP_CONFIGURATION_DHCP_ON_START = 1 << 0,
36 KEEP_CONFIGURATION_DHCP_ON_STOP = 1 << 1,
37 KEEP_CONFIGURATION_DHCP = KEEP_CONFIGURATION_DHCP_ON_START | KEEP_CONFIGURATION_DHCP_ON_STOP,
38 KEEP_CONFIGURATION_STATIC = 1 << 2,
39 KEEP_CONFIGURATION_YES = KEEP_CONFIGURATION_DHCP | KEEP_CONFIGURATION_STATIC,
40 _KEEP_CONFIGURATION_MAX,
41 _KEEP_CONFIGURATION_INVALID = -EINVAL,
42 } KeepConfiguration;
43
44 typedef enum IPv6LinkLocalAddressGenMode {
45 IPV6_LINK_LOCAL_ADDRESSS_GEN_MODE_EUI64 = IN6_ADDR_GEN_MODE_EUI64,
46 IPV6_LINK_LOCAL_ADDRESSS_GEN_MODE_NONE = IN6_ADDR_GEN_MODE_NONE,
47 IPV6_LINK_LOCAL_ADDRESSS_GEN_MODE_STABLE_PRIVACY = IN6_ADDR_GEN_MODE_STABLE_PRIVACY,
48 IPV6_LINK_LOCAL_ADDRESSS_GEN_MODE_RANDOM = IN6_ADDR_GEN_MODE_RANDOM,
49 _IPV6_LINK_LOCAL_ADDRESS_GEN_MODE_MAX,
50 _IPV6_LINK_LOCAL_ADDRESS_GEN_MODE_INVALID = -EINVAL,
51 } IPv6LinkLocalAddressGenMode;
52
53 typedef enum ActivationPolicy {
54 ACTIVATION_POLICY_UP,
55 ACTIVATION_POLICY_ALWAYS_UP,
56 ACTIVATION_POLICY_MANUAL,
57 ACTIVATION_POLICY_ALWAYS_DOWN,
58 ACTIVATION_POLICY_DOWN,
59 ACTIVATION_POLICY_BOUND,
60 _ACTIVATION_POLICY_MAX,
61 _ACTIVATION_POLICY_INVALID = -EINVAL,
62 } ActivationPolicy;
63
64 typedef struct Manager Manager;
65
66 typedef struct NetworkDHCPServerEmitAddress {
67 bool emit;
68 struct in_addr *addresses;
69 size_t n_addresses;
70 } NetworkDHCPServerEmitAddress;
71
72 struct Network {
73 Manager *manager;
74
75 unsigned n_ref;
76
77 char *name;
78 char *filename;
79 usec_t timestamp;
80 char *description;
81
82 /* [Match] section */
83 NetMatch match;
84 LIST_HEAD(Condition, conditions);
85
86 /* Master or stacked netdevs */
87 NetDev *batadv;
88 NetDev *bridge;
89 NetDev *bond;
90 NetDev *vrf;
91 NetDev *xfrm;
92 Hashmap *stacked_netdevs;
93 char *batadv_name;
94 char *bridge_name;
95 char *bond_name;
96 char *vrf_name;
97 Hashmap *stacked_netdev_names;
98
99 /* [Link] section */
100 struct ether_addr *mac;
101 uint32_t mtu;
102 uint32_t group;
103 bool group_set;
104 int arp;
105 int multicast;
106 int allmulticast;
107 int promiscuous;
108 bool unmanaged;
109 int required_for_online; /* Is this network required to be considered online? */
110 LinkOperationalStateRange required_operstate_for_online;
111 AddressFamily required_family_for_online;
112 ActivationPolicy activation_policy;
113
114 /* misc settings */
115 bool configure_without_carrier;
116 int ignore_carrier_loss;
117 KeepConfiguration keep_configuration;
118 char **bind_carrier;
119 bool default_route_on_device;
120 AddressFamily ip_masquerade;
121
122 /* DHCP Client Support */
123 AddressFamily dhcp;
124 DHCPClientIdentifier dhcp_client_identifier;
125 DUID dhcp_duid;
126 uint32_t dhcp_iaid;
127 bool dhcp_iaid_set;
128 char *dhcp_vendor_class_identifier;
129 char *dhcp_mudurl;
130 char **dhcp_user_class;
131 char *dhcp_hostname;
132 uint64_t dhcp_max_attempts;
133 uint32_t dhcp_route_metric;
134 bool dhcp_route_metric_set;
135 uint32_t dhcp_route_table;
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_route_table_set;
157 bool dhcp_send_release;
158 bool dhcp_send_decline;
159 DHCPUseDomains dhcp_use_domains;
160 bool dhcp_use_domains_set;
161 Set *dhcp_deny_listed_ip;
162 Set *dhcp_allow_listed_ip;
163 Set *dhcp_request_options;
164 OrderedHashmap *dhcp_client_send_options;
165 OrderedHashmap *dhcp_client_send_vendor_options;
166
167 /* DHCPv6 Client support */
168 bool dhcp6_use_address;
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 bool dhcp6_rapid_commit;
175 DHCPUseDomains dhcp6_use_domains;
176 bool dhcp6_use_domains_set;
177 uint32_t dhcp6_iaid;
178 bool dhcp6_iaid_set;
179 bool dhcp6_iaid_set_explicitly;
180 DUID dhcp6_duid;
181 uint8_t dhcp6_pd_length;
182 char *dhcp6_mudurl;
183 char **dhcp6_user_class;
184 char **dhcp6_vendor_class;
185 struct in6_addr dhcp6_pd_address;
186 DHCP6ClientStartMode dhcp6_without_ra;
187 OrderedHashmap *dhcp6_client_send_options;
188 OrderedHashmap *dhcp6_client_send_vendor_options;
189 Set *dhcp6_request_options;
190 /* Start DHCPv6 PD also when 'O' RA flag is set, see RFC 7084, WPD-4 */
191 bool dhcp6_force_pd_other_information;
192
193 /* DHCP Server Support */
194 bool dhcp_server;
195 bool dhcp_server_bind_to_interface;
196 unsigned char dhcp_server_address_prefixlen;
197 struct in_addr dhcp_server_address;
198 int dhcp_server_uplink_index;
199 char *dhcp_server_uplink_name;
200 struct in_addr dhcp_server_relay_target;
201 char *dhcp_server_relay_agent_circuit_id;
202 char *dhcp_server_relay_agent_remote_id;
203 NetworkDHCPServerEmitAddress dhcp_server_emit[_SD_DHCP_LEASE_SERVER_TYPE_MAX];
204 bool dhcp_server_emit_router;
205 bool dhcp_server_emit_timezone;
206 char *dhcp_server_timezone;
207 usec_t dhcp_server_default_lease_time_usec, dhcp_server_max_lease_time_usec;
208 uint32_t dhcp_server_pool_offset;
209 uint32_t dhcp_server_pool_size;
210 OrderedHashmap *dhcp_server_send_options;
211 OrderedHashmap *dhcp_server_send_vendor_options;
212
213 /* link local addressing support */
214 AddressFamily link_local;
215 IPv6LinkLocalAddressGenMode ipv6ll_address_gen_mode;
216 struct in6_addr ipv6ll_stable_secret;
217 bool ipv4ll_route;
218
219 /* IPv6 RA support */
220 RADVPrefixDelegation router_prefix_delegation;
221 usec_t router_lifetime_usec;
222 uint8_t router_preference;
223 bool router_managed;
224 bool router_other_information;
225 bool router_emit_dns;
226 bool router_emit_domains;
227 usec_t router_dns_lifetime_usec;
228 struct in6_addr *router_dns;
229 unsigned n_router_dns;
230 OrderedSet *router_search_domains;
231 int router_uplink_index;
232 char *router_uplink_name;
233
234 /* DHCPv6 Prefix Delegation support */
235 int dhcp6_pd;
236 bool dhcp6_pd_announce;
237 bool dhcp6_pd_assign;
238 bool dhcp6_pd_manage_temporary_address;
239 int64_t dhcp6_pd_subnet_id;
240 uint32_t dhcp6_pd_route_metric;
241 struct in6_addr dhcp6_pd_token;
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 /* sysctl settings */
287 AddressFamily ip_forward;
288 int ipv4_accept_local;
289 int ipv4_route_localnet;
290 int ipv6_dad_transmits;
291 int ipv6_hop_limit;
292 int proxy_arp;
293 uint32_t ipv6_mtu;
294 IPv6PrivacyExtensions ipv6_privacy_extensions;
295 int ipv6_proxy_ndp;
296 Set *ipv6_proxy_ndp_addresses;
297
298 /* IPv6 accept RA */
299 int ipv6_accept_ra;
300 bool ipv6_accept_ra_use_dns;
301 bool ipv6_accept_ra_use_autonomous_prefix;
302 bool ipv6_accept_ra_use_onlink_prefix;
303 bool active_slave;
304 bool primary_slave;
305 DHCPUseDomains ipv6_accept_ra_use_domains;
306 IPv6AcceptRAStartDHCP6Client ipv6_accept_ra_start_dhcp6_client;
307 uint32_t ipv6_accept_ra_route_table;
308 bool ipv6_accept_ra_route_table_set;
309 uint32_t ipv6_accept_ra_route_metric;
310 bool ipv6_accept_ra_route_metric_set;
311 Set *ndisc_deny_listed_router;
312 Set *ndisc_allow_listed_router;
313 Set *ndisc_deny_listed_prefix;
314 Set *ndisc_allow_listed_prefix;
315 Set *ndisc_deny_listed_route_prefix;
316 Set *ndisc_allow_listed_route_prefix;
317 OrderedSet *ipv6_tokens;
318
319 /* LLDP support */
320 LLDPMode lldp_mode; /* LLDP reception */
321 LLDPEmit lldp_emit; /* LLDP transmission */
322 char *lldp_mud; /* LLDP MUD URL */
323
324 OrderedHashmap *addresses_by_section;
325 Hashmap *routes_by_section;
326 Hashmap *nexthops_by_section;
327 Hashmap *bridge_fdb_entries_by_section;
328 Hashmap *bridge_mdb_entries_by_section;
329 Hashmap *neighbors_by_section;
330 Hashmap *address_labels_by_section;
331 Hashmap *prefixes_by_section;
332 Hashmap *route_prefixes_by_section;
333 Hashmap *rules_by_section;
334 Hashmap *dhcp_static_leases_by_section;
335 OrderedHashmap *tc_by_section;
336 OrderedHashmap *sr_iov_by_section;
337
338 /* All kinds of DNS configuration */
339 struct in_addr_full **dns;
340 unsigned n_dns;
341 OrderedSet *search_domains, *route_domains;
342 int dns_default_route;
343 ResolveSupport llmnr;
344 ResolveSupport mdns;
345 DnssecMode dnssec_mode;
346 DnsOverTlsMode dns_over_tls_mode;
347 Set *dnssec_negative_trust_anchors;
348
349 /* NTP */
350 char **ntp;
351 };
352
353 Network *network_ref(Network *network);
354 Network *network_unref(Network *network);
355 DEFINE_TRIVIAL_CLEANUP_FUNC(Network*, network_unref);
356
357 int network_load(Manager *manager, OrderedHashmap **networks);
358 int network_reload(Manager *manager);
359 int network_load_one(Manager *manager, OrderedHashmap **networks, const char *filename);
360 int network_verify(Network *network);
361
362 int network_get_by_name(Manager *manager, const char *name, Network **ret);
363 void network_apply_anonymize_if_set(Network *network);
364
365 bool network_has_static_ipv6_configurations(Network *network);
366
367 CONFIG_PARSER_PROTOTYPE(config_parse_stacked_netdev);
368 CONFIG_PARSER_PROTOTYPE(config_parse_tunnel);
369 CONFIG_PARSER_PROTOTYPE(config_parse_domains);
370 CONFIG_PARSER_PROTOTYPE(config_parse_dns);
371 CONFIG_PARSER_PROTOTYPE(config_parse_hostname);
372 CONFIG_PARSER_PROTOTYPE(config_parse_timezone);
373 CONFIG_PARSER_PROTOTYPE(config_parse_dnssec_negative_trust_anchors);
374 CONFIG_PARSER_PROTOTYPE(config_parse_ntp);
375 CONFIG_PARSER_PROTOTYPE(config_parse_required_for_online);
376 CONFIG_PARSER_PROTOTYPE(config_parse_required_family_for_online);
377 CONFIG_PARSER_PROTOTYPE(config_parse_keep_configuration);
378 CONFIG_PARSER_PROTOTYPE(config_parse_ipv6_link_local_address_gen_mode);
379 CONFIG_PARSER_PROTOTYPE(config_parse_activation_policy);
380 CONFIG_PARSER_PROTOTYPE(config_parse_link_group);
381 CONFIG_PARSER_PROTOTYPE(config_parse_uplink);
382
383 const struct ConfigPerfItem* network_network_gperf_lookup(const char *key, GPERF_LEN_TYPE length);
384
385 const char* keep_configuration_to_string(KeepConfiguration i) _const_;
386 KeepConfiguration keep_configuration_from_string(const char *s) _pure_;
387
388 const char* ipv6_link_local_address_gen_mode_to_string(IPv6LinkLocalAddressGenMode s) _const_;
389 IPv6LinkLocalAddressGenMode ipv6_link_local_address_gen_mode_from_string(const char *s) _pure_;
390
391 const char* activation_policy_to_string(ActivationPolicy i) _const_;
392 ActivationPolicy activation_policy_from_string(const char *s) _pure_;