]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/network/networkd-network.h
network: bridgeFDB: rename FdbEntry -> BridgeFDB
[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-brvlan.h"
16 #include "networkd-dhcp-common.h"
17 #include "networkd-dhcp4.h"
18 #include "networkd-dhcp6.h"
19 #include "networkd-dhcp-server.h"
20 #include "networkd-lldp-rx.h"
21 #include "networkd-lldp-tx.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 usec_t timestamp;
77 char *description;
78
79 /* [Match] section */
80 NetMatch match;
81 LIST_HEAD(Condition, conditions);
82
83 /* Master or stacked netdevs */
84 NetDev *batadv;
85 NetDev *bridge;
86 NetDev *bond;
87 NetDev *vrf;
88 NetDev *xfrm;
89 Hashmap *stacked_netdevs;
90 char *batadv_name;
91 char *bridge_name;
92 char *bond_name;
93 char *vrf_name;
94 Hashmap *stacked_netdev_names;
95
96 /* [Link] section */
97 struct ether_addr *mac;
98 uint32_t mtu;
99 uint32_t group;
100 int arp;
101 int multicast;
102 int allmulticast;
103 int promiscuous;
104 bool unmanaged;
105 bool required_for_online; /* Is this network required to be considered online? */
106 LinkOperationalStateRange required_operstate_for_online;
107 AddressFamily required_family_for_online;
108 ActivationPolicy activation_policy;
109
110 /* misc settings */
111 bool configure_without_carrier;
112 int ignore_carrier_loss;
113 KeepConfiguration keep_configuration;
114 char **bind_carrier;
115 bool default_route_on_device;
116 AddressFamily ip_masquerade;
117
118 /* DHCP Client Support */
119 AddressFamily dhcp;
120 DHCPClientIdentifier dhcp_client_identifier;
121 DUID dhcp_duid;
122 uint32_t dhcp_iaid;
123 bool dhcp_iaid_set;
124 char *dhcp_vendor_class_identifier;
125 char *dhcp_mudurl;
126 char **dhcp_user_class;
127 char *dhcp_hostname;
128 uint64_t dhcp_max_attempts;
129 uint32_t dhcp_route_metric;
130 bool dhcp_route_metric_set;
131 uint32_t dhcp_route_table;
132 uint32_t dhcp_fallback_lease_lifetime;
133 uint32_t dhcp_route_mtu;
134 uint16_t dhcp_client_port;
135 int dhcp_critical;
136 int dhcp_ip_service_type;
137 bool dhcp_anonymize;
138 bool dhcp_send_hostname;
139 int dhcp_broadcast;
140 bool dhcp_use_dns;
141 bool dhcp_use_dns_set;
142 bool dhcp_routes_to_dns;
143 bool dhcp_use_ntp;
144 bool dhcp_use_ntp_set;
145 bool dhcp_routes_to_ntp;
146 bool dhcp_use_sip;
147 bool dhcp_use_mtu;
148 bool dhcp_use_routes;
149 int dhcp_use_gateway;
150 bool dhcp_use_timezone;
151 bool dhcp_use_hostname;
152 bool dhcp_route_table_set;
153 bool dhcp_send_release;
154 bool dhcp_send_decline;
155 DHCPUseDomains dhcp_use_domains;
156 bool dhcp_use_domains_set;
157 Set *dhcp_deny_listed_ip;
158 Set *dhcp_allow_listed_ip;
159 Set *dhcp_request_options;
160 OrderedHashmap *dhcp_client_send_options;
161 OrderedHashmap *dhcp_client_send_vendor_options;
162
163 /* DHCPv6 Client support*/
164 bool dhcp6_use_address;
165 bool dhcp6_use_dns;
166 bool dhcp6_use_dns_set;
167 bool dhcp6_use_hostname;
168 bool dhcp6_use_ntp;
169 bool dhcp6_use_ntp_set;
170 bool dhcp6_rapid_commit;
171 DHCPUseDomains dhcp6_use_domains;
172 bool dhcp6_use_domains_set;
173 uint32_t dhcp6_iaid;
174 bool dhcp6_iaid_set;
175 bool dhcp6_iaid_set_explicitly;
176 DUID dhcp6_duid;
177 uint8_t dhcp6_pd_length;
178 char *dhcp6_mudurl;
179 char **dhcp6_user_class;
180 char **dhcp6_vendor_class;
181 struct in6_addr dhcp6_pd_address;
182 DHCP6ClientStartMode dhcp6_without_ra;
183 OrderedHashmap *dhcp6_client_send_options;
184 OrderedHashmap *dhcp6_client_send_vendor_options;
185 Set *dhcp6_request_options;
186 /* Start DHCPv6 PD also when 'O' RA flag is set, see RFC 7084, WPD-4 */
187 bool dhcp6_force_pd_other_information;
188
189 /* DHCP Server Support */
190 bool dhcp_server;
191 bool dhcp_server_bind_to_interface;
192 unsigned char dhcp_server_address_prefixlen;
193 struct in_addr dhcp_server_address;
194 struct in_addr dhcp_server_relay_target;
195 char *dhcp_server_relay_agent_circuit_id;
196 char *dhcp_server_relay_agent_remote_id;
197 NetworkDHCPServerEmitAddress dhcp_server_emit[_SD_DHCP_LEASE_SERVER_TYPE_MAX];
198 bool dhcp_server_emit_router;
199 bool dhcp_server_emit_timezone;
200 char *dhcp_server_timezone;
201 usec_t dhcp_server_default_lease_time_usec, dhcp_server_max_lease_time_usec;
202 uint32_t dhcp_server_pool_offset;
203 uint32_t dhcp_server_pool_size;
204 OrderedHashmap *dhcp_server_send_options;
205 OrderedHashmap *dhcp_server_send_vendor_options;
206
207 /* link local addressing support */
208 AddressFamily link_local;
209 IPv6LinkLocalAddressGenMode ipv6ll_address_gen_mode;
210 bool ipv4ll_route;
211
212 /* IPv6 RA support */
213 RADVPrefixDelegation router_prefix_delegation;
214 usec_t router_lifetime_usec;
215 uint8_t router_preference;
216 bool router_managed;
217 bool router_other_information;
218 bool router_emit_dns;
219 bool router_emit_domains;
220 usec_t router_dns_lifetime_usec;
221 struct in6_addr *router_dns;
222 unsigned n_router_dns;
223 OrderedSet *router_search_domains;
224
225 /* DHCPv6 Prefix Delegation support */
226 int dhcp6_pd;
227 bool dhcp6_pd_announce;
228 bool dhcp6_pd_assign;
229 bool dhcp6_pd_manage_temporary_address;
230 int64_t dhcp6_pd_subnet_id;
231 uint32_t dhcp6_pd_route_metric;
232 struct in6_addr dhcp6_pd_token;
233
234 /* Bridge Support */
235 int use_bpdu;
236 int hairpin;
237 int fast_leave;
238 int allow_port_to_be_root;
239 int unicast_flood;
240 int multicast_flood;
241 int multicast_to_unicast;
242 int neighbor_suppression;
243 int learning;
244 int bridge_proxy_arp;
245 int bridge_proxy_arp_wifi;
246 uint32_t cost;
247 uint16_t priority;
248 MulticastRouter multicast_router;
249
250 /* Bridge VLAN */
251 bool use_br_vlan;
252 uint16_t pvid;
253 uint32_t br_vid_bitmap[BRIDGE_VLAN_BITMAP_LEN];
254 uint32_t br_untagged_bitmap[BRIDGE_VLAN_BITMAP_LEN];
255
256 /* CAN support */
257 uint32_t can_bitrate;
258 unsigned can_sample_point;
259 uint32_t can_data_bitrate;
260 unsigned can_data_sample_point;
261 usec_t can_restart_us;
262 int can_triple_sampling;
263 int can_berr_reporting;
264 int can_termination;
265 int can_listen_only;
266 int can_fd_mode;
267 int can_non_iso;
268
269 /* sysctl settings */
270 AddressFamily ip_forward;
271 int ipv4_accept_local;
272 int ipv4_route_localnet;
273 int ipv6_dad_transmits;
274 int ipv6_hop_limit;
275 int proxy_arp;
276 uint32_t ipv6_mtu;
277 IPv6PrivacyExtensions ipv6_privacy_extensions;
278 int ipv6_proxy_ndp;
279 Set *ipv6_proxy_ndp_addresses;
280
281 /* IPv6 accept RA */
282 int ipv6_accept_ra;
283 bool ipv6_accept_ra_use_dns;
284 bool ipv6_accept_ra_use_autonomous_prefix;
285 bool ipv6_accept_ra_use_onlink_prefix;
286 bool active_slave;
287 bool primary_slave;
288 DHCPUseDomains ipv6_accept_ra_use_domains;
289 IPv6AcceptRAStartDHCP6Client ipv6_accept_ra_start_dhcp6_client;
290 uint32_t ipv6_accept_ra_route_table;
291 bool ipv6_accept_ra_route_table_set;
292 uint32_t ipv6_accept_ra_route_metric;
293 bool ipv6_accept_ra_route_metric_set;
294 Set *ndisc_deny_listed_router;
295 Set *ndisc_allow_listed_router;
296 Set *ndisc_deny_listed_prefix;
297 Set *ndisc_allow_listed_prefix;
298 Set *ndisc_deny_listed_route_prefix;
299 Set *ndisc_allow_listed_route_prefix;
300 OrderedSet *ipv6_tokens;
301
302 /* LLDP support */
303 LLDPMode lldp_mode; /* LLDP reception */
304 LLDPEmit lldp_emit; /* LLDP transmission */
305 char *lldp_mud; /* LLDP MUD URL */
306
307 OrderedHashmap *addresses_by_section;
308 Hashmap *routes_by_section;
309 Hashmap *nexthops_by_section;
310 Hashmap *bridge_fdb_entries_by_section;
311 Hashmap *mdb_entries_by_section;
312 Hashmap *neighbors_by_section;
313 Hashmap *address_labels_by_section;
314 Hashmap *prefixes_by_section;
315 Hashmap *route_prefixes_by_section;
316 Hashmap *rules_by_section;
317 OrderedHashmap *tc_by_section;
318 OrderedHashmap *sr_iov_by_section;
319
320 /* All kinds of DNS configuration */
321 struct in_addr_full **dns;
322 unsigned n_dns;
323 OrderedSet *search_domains, *route_domains;
324 int dns_default_route;
325 ResolveSupport llmnr;
326 ResolveSupport mdns;
327 DnssecMode dnssec_mode;
328 DnsOverTlsMode dns_over_tls_mode;
329 Set *dnssec_negative_trust_anchors;
330
331 /* NTP */
332 char **ntp;
333 };
334
335 Network *network_ref(Network *network);
336 Network *network_unref(Network *network);
337 DEFINE_TRIVIAL_CLEANUP_FUNC(Network*, network_unref);
338
339 int network_load(Manager *manager, OrderedHashmap **networks);
340 int network_reload(Manager *manager);
341 int network_load_one(Manager *manager, OrderedHashmap **networks, const char *filename);
342 int network_verify(Network *network);
343
344 int network_get_by_name(Manager *manager, const char *name, Network **ret);
345 void network_apply_anonymize_if_set(Network *network);
346
347 bool network_has_static_ipv6_configurations(Network *network);
348
349 CONFIG_PARSER_PROTOTYPE(config_parse_stacked_netdev);
350 CONFIG_PARSER_PROTOTYPE(config_parse_tunnel);
351 CONFIG_PARSER_PROTOTYPE(config_parse_domains);
352 CONFIG_PARSER_PROTOTYPE(config_parse_dns);
353 CONFIG_PARSER_PROTOTYPE(config_parse_hostname);
354 CONFIG_PARSER_PROTOTYPE(config_parse_timezone);
355 CONFIG_PARSER_PROTOTYPE(config_parse_dnssec_negative_trust_anchors);
356 CONFIG_PARSER_PROTOTYPE(config_parse_ntp);
357 CONFIG_PARSER_PROTOTYPE(config_parse_required_for_online);
358 CONFIG_PARSER_PROTOTYPE(config_parse_required_family_for_online);
359 CONFIG_PARSER_PROTOTYPE(config_parse_keep_configuration);
360 CONFIG_PARSER_PROTOTYPE(config_parse_ipv6_link_local_address_gen_mode);
361 CONFIG_PARSER_PROTOTYPE(config_parse_activation_policy);
362
363 const struct ConfigPerfItem* network_network_gperf_lookup(const char *key, GPERF_LEN_TYPE length);
364
365 const char* keep_configuration_to_string(KeepConfiguration i) _const_;
366 KeepConfiguration keep_configuration_from_string(const char *s) _pure_;
367
368 const char* ipv6_link_local_address_gen_mode_to_string(IPv6LinkLocalAddressGenMode s) _const_;
369 IPv6LinkLocalAddressGenMode ipv6_link_local_address_gen_mode_from_string(const char *s) _pure_;
370
371 const char* activation_policy_to_string(ActivationPolicy i) _const_;
372 ActivationPolicy activation_policy_from_string(const char *s) _pure_;