]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/network/networkd-network.h
Merge pull request #12526 from keszybz/some-trivial-follow-ups-for-the-varlink-pr
[thirdparty/systemd.git] / src / network / networkd-network.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 #pragma once
3
4 #include <netinet/in.h>
5 #include <linux/if_bridge.h>
6
7 #include "sd-bus.h"
8 #include "sd-device.h"
9
10 #include "condition.h"
11 #include "conf-parser.h"
12 #include "dhcp-identifier.h"
13 #include "hashmap.h"
14 #include "netdev/netdev.h"
15 #include "networkd-address-label.h"
16 #include "networkd-address.h"
17 #include "networkd-brvlan.h"
18 #include "networkd-fdb.h"
19 #include "networkd-ipv6-proxy-ndp.h"
20 #include "networkd-lldp-tx.h"
21 #include "networkd-neighbor.h"
22 #include "networkd-radv.h"
23 #include "networkd-route.h"
24 #include "networkd-routing-policy-rule.h"
25 #include "networkd-util.h"
26 #include "ordered-set.h"
27 #include "resolve-util.h"
28
29 #define DHCP_ROUTE_METRIC 1024
30 #define IPV4LL_ROUTE_METRIC 2048
31
32 #define BRIDGE_VLAN_BITMAP_MAX 4096
33 #define BRIDGE_VLAN_BITMAP_LEN (BRIDGE_VLAN_BITMAP_MAX / 32)
34
35 typedef enum DHCPClientIdentifier {
36 DHCP_CLIENT_ID_MAC,
37 DHCP_CLIENT_ID_DUID,
38 /* The following option may not be good for RFC regarding DHCP (3315 and 4361).
39 * But some setups require this. E.g., Sky Broadband, the second largest provider in the UK
40 * requires the client id to be set to a custom string, reported at
41 * https://github.com/systemd/systemd/issues/7828 */
42 DHCP_CLIENT_ID_DUID_ONLY,
43 _DHCP_CLIENT_ID_MAX,
44 _DHCP_CLIENT_ID_INVALID = -1,
45 } DHCPClientIdentifier;
46
47 typedef enum IPv6PrivacyExtensions {
48 /* The values map to the kernel's /proc/sys/net/ipv6/conf/xxx/use_tempaddr values */
49 IPV6_PRIVACY_EXTENSIONS_NO,
50 IPV6_PRIVACY_EXTENSIONS_PREFER_PUBLIC,
51 IPV6_PRIVACY_EXTENSIONS_YES, /* aka prefer-temporary */
52 _IPV6_PRIVACY_EXTENSIONS_MAX,
53 _IPV6_PRIVACY_EXTENSIONS_INVALID = -1,
54 } IPv6PrivacyExtensions;
55
56 typedef enum DHCPUseDomains {
57 DHCP_USE_DOMAINS_NO,
58 DHCP_USE_DOMAINS_YES,
59 DHCP_USE_DOMAINS_ROUTE,
60 _DHCP_USE_DOMAINS_MAX,
61 _DHCP_USE_DOMAINS_INVALID = -1,
62 } DHCPUseDomains;
63
64 typedef enum LLDPMode {
65 LLDP_MODE_NO = 0,
66 LLDP_MODE_YES = 1,
67 LLDP_MODE_ROUTERS_ONLY = 2,
68 _LLDP_MODE_MAX,
69 _LLDP_MODE_INVALID = -1,
70 } LLDPMode;
71
72 typedef struct DUID {
73 /* Value of Type in [DHCP] section */
74 DUIDType type;
75
76 uint8_t raw_data_len;
77 uint8_t raw_data[MAX_DUID_LEN];
78 usec_t llt_time;
79 } DUID;
80
81 typedef enum RADVPrefixDelegation {
82 RADV_PREFIX_DELEGATION_NONE,
83 RADV_PREFIX_DELEGATION_STATIC,
84 RADV_PREFIX_DELEGATION_DHCP6,
85 RADV_PREFIX_DELEGATION_BOTH,
86 _RADV_PREFIX_DELEGATION_MAX,
87 _RADV_PREFIX_DELEGATION_INVALID = -1,
88 } RADVPrefixDelegation;
89
90 typedef enum MulticastRouter {
91 MULTICAST_ROUTER_NONE = MDB_RTR_TYPE_DISABLED,
92 MULTICAST_ROUTER_TEMPORARY_QUERY = MDB_RTR_TYPE_TEMP_QUERY,
93 MULTICAST_ROUTER_PERMANENT = MDB_RTR_TYPE_PERM,
94 MULTICAST_ROUTER_TEMPORARY = MDB_RTR_TYPE_TEMP,
95 _MULTICAST_ROUTER_MAX,
96 _MULTICAST_ROUTER_INVALID = -1,
97 } MulticastRouter;
98
99 typedef struct Manager Manager;
100
101 struct Network {
102 Manager *manager;
103
104 char *filename;
105 char *name;
106
107 unsigned n_ref;
108
109 Set *match_mac;
110 char **match_path;
111 char **match_driver;
112 char **match_type;
113 char **match_name;
114 LIST_HEAD(Condition, conditions);
115
116 char *description;
117
118 NetDev *bridge;
119 NetDev *bond;
120 NetDev *vrf;
121 Hashmap *stacked_netdevs;
122 char *bridge_name;
123 char *bond_name;
124 char *vrf_name;
125 Hashmap *stacked_netdev_names;
126
127 /* DHCP Client Support */
128 AddressFamilyBoolean dhcp;
129 DHCPClientIdentifier dhcp_client_identifier;
130 char *dhcp_vendor_class_identifier;
131 char **dhcp_user_class;
132 char *dhcp_hostname;
133 uint64_t dhcp_max_attempts;
134 unsigned dhcp_route_metric;
135 uint32_t dhcp_route_table;
136 uint16_t dhcp_client_port;
137 bool dhcp_anonymize;
138 bool dhcp_send_hostname;
139 bool dhcp_broadcast;
140 bool dhcp_critical;
141 bool dhcp_use_dns;
142 bool dhcp_use_ntp;
143 bool dhcp_use_mtu;
144 bool dhcp_use_routes;
145 bool dhcp_use_timezone;
146 bool rapid_commit;
147 bool dhcp_use_hostname;
148 bool dhcp_route_table_set;
149 DHCPUseDomains dhcp_use_domains;
150 Set *dhcp_black_listed_ip;
151
152 /* DHCP Server Support */
153 bool dhcp_server;
154 bool dhcp_server_emit_dns;
155 struct in_addr *dhcp_server_dns;
156 unsigned n_dhcp_server_dns;
157 bool dhcp_server_emit_ntp;
158 struct in_addr *dhcp_server_ntp;
159 unsigned n_dhcp_server_ntp;
160 bool dhcp_server_emit_router;
161 bool dhcp_server_emit_timezone;
162 char *dhcp_server_timezone;
163 usec_t dhcp_server_default_lease_time_usec, dhcp_server_max_lease_time_usec;
164 uint32_t dhcp_server_pool_offset;
165 uint32_t dhcp_server_pool_size;
166
167 /* IPV4LL Support */
168 AddressFamilyBoolean link_local;
169 bool ipv4ll_route;
170
171 /* IPv6 prefix delegation support */
172 RADVPrefixDelegation router_prefix_delegation;
173 usec_t router_lifetime_usec;
174 uint8_t router_preference;
175 bool router_managed;
176 bool router_other_information;
177 bool router_emit_dns;
178 bool router_emit_domains;
179 usec_t router_dns_lifetime_usec;
180 struct in6_addr *router_dns;
181 unsigned n_router_dns;
182 OrderedSet *router_search_domains;
183 bool dhcp6_force_pd_other_information; /* Start DHCPv6 PD also when 'O'
184 RA flag is set, see RFC 7084,
185 WPD-4 */
186
187 /* Bridge Support */
188 int use_bpdu;
189 int hairpin;
190 int fast_leave;
191 int allow_port_to_be_root;
192 int unicast_flood;
193 int multicast_flood;
194 int multicast_to_unicast;
195 int neighbor_suppression;
196 int learning;
197 int bridge_proxy_arp;
198 int bridge_proxy_arp_wifi;
199 uint32_t cost;
200 uint16_t priority;
201 MulticastRouter multicast_router;
202
203 bool use_br_vlan;
204 uint16_t pvid;
205 uint32_t br_vid_bitmap[BRIDGE_VLAN_BITMAP_LEN];
206 uint32_t br_untagged_bitmap[BRIDGE_VLAN_BITMAP_LEN];
207
208 /* CAN support */
209 size_t can_bitrate;
210 unsigned can_sample_point;
211 usec_t can_restart_us;
212 int can_triple_sampling;
213
214 AddressFamilyBoolean ip_forward;
215 bool ip_masquerade;
216
217 int ipv6_accept_ra;
218 int ipv6_dad_transmits;
219 int ipv6_hop_limit;
220 int ipv6_proxy_ndp;
221 int proxy_arp;
222 uint32_t ipv6_mtu;
223
224 bool ipv6_accept_ra_use_dns;
225 bool ipv6_accept_ra_use_autonomous_prefix;
226 bool ipv6_accept_ra_use_onlink_prefix;
227 bool active_slave;
228 bool primary_slave;
229 DHCPUseDomains ipv6_accept_ra_use_domains;
230 uint32_t ipv6_accept_ra_route_table;
231 bool ipv6_accept_ra_route_table_set;
232
233 union in_addr_union ipv6_token;
234 IPv6PrivacyExtensions ipv6_privacy_extensions;
235
236 struct ether_addr *mac;
237 uint32_t mtu;
238 bool mtu_is_set; /* Indicate MTUBytes= is specified. */
239 int arp;
240 int multicast;
241 int allmulticast;
242 bool unmanaged;
243 bool configure_without_carrier;
244 bool ignore_carrier_loss;
245 uint32_t iaid;
246 DUID duid;
247
248 bool iaid_set;
249
250 bool required_for_online; /* Is this network required to be considered online? */
251 LinkOperationalState required_operstate_for_online;
252
253 LLDPMode lldp_mode; /* LLDP reception */
254 LLDPEmit lldp_emit; /* LLDP transmission */
255
256 LIST_HEAD(Address, static_addresses);
257 LIST_HEAD(Route, static_routes);
258 LIST_HEAD(FdbEntry, static_fdb_entries);
259 LIST_HEAD(IPv6ProxyNDPAddress, ipv6_proxy_ndp_addresses);
260 LIST_HEAD(Neighbor, neighbors);
261 LIST_HEAD(AddressLabel, address_labels);
262 LIST_HEAD(Prefix, static_prefixes);
263 LIST_HEAD(RoutingPolicyRule, rules);
264
265 unsigned n_static_addresses;
266 unsigned n_static_routes;
267 unsigned n_static_fdb_entries;
268 unsigned n_ipv6_proxy_ndp_addresses;
269 unsigned n_neighbors;
270 unsigned n_address_labels;
271 unsigned n_static_prefixes;
272 unsigned n_rules;
273
274 Hashmap *addresses_by_section;
275 Hashmap *routes_by_section;
276 Hashmap *fdb_entries_by_section;
277 Hashmap *neighbors_by_section;
278 Hashmap *address_labels_by_section;
279 Hashmap *prefixes_by_section;
280 Hashmap *rules_by_section;
281
282 /* All kinds of DNS configuration */
283 struct in_addr_data *dns;
284 unsigned n_dns;
285 OrderedSet *search_domains, *route_domains;
286
287 int dns_default_route;
288 ResolveSupport llmnr;
289 ResolveSupport mdns;
290 DnssecMode dnssec_mode;
291 DnsOverTlsMode dns_over_tls_mode;
292 Set *dnssec_negative_trust_anchors;
293
294 char **ntp;
295 char **bind_carrier;
296 };
297
298 Network *network_ref(Network *network);
299 Network *network_unref(Network *network);
300 DEFINE_TRIVIAL_CLEANUP_FUNC(Network*, network_unref);
301
302 int network_load(Manager *manager);
303 int network_load_one(Manager *manager, const char *filename);
304 int network_verify(Network *network);
305
306 int network_get_by_name(Manager *manager, const char *name, Network **ret);
307 int network_get(Manager *manager, sd_device *device, const char *ifname, const struct ether_addr *mac, Network **ret);
308 int network_apply(Network *network, Link *link);
309 void network_apply_anonymize_if_set(Network *network);
310
311 bool network_has_static_ipv6_addresses(Network *network);
312
313 CONFIG_PARSER_PROTOTYPE(config_parse_stacked_netdev);
314 CONFIG_PARSER_PROTOTYPE(config_parse_domains);
315 CONFIG_PARSER_PROTOTYPE(config_parse_tunnel);
316 CONFIG_PARSER_PROTOTYPE(config_parse_dhcp);
317 CONFIG_PARSER_PROTOTYPE(config_parse_dns);
318 CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_client_identifier);
319 CONFIG_PARSER_PROTOTYPE(config_parse_ipv6token);
320 CONFIG_PARSER_PROTOTYPE(config_parse_ipv6_privacy_extensions);
321 CONFIG_PARSER_PROTOTYPE(config_parse_hostname);
322 CONFIG_PARSER_PROTOTYPE(config_parse_timezone);
323 CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_server_dns);
324 CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_black_listed_ip_address);
325 CONFIG_PARSER_PROTOTYPE(config_parse_radv_dns);
326 CONFIG_PARSER_PROTOTYPE(config_parse_radv_search_domains);
327 CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_server_ntp);
328 CONFIG_PARSER_PROTOTYPE(config_parse_dnssec_negative_trust_anchors);
329 CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_use_domains);
330 CONFIG_PARSER_PROTOTYPE(config_parse_lldp_mode);
331 CONFIG_PARSER_PROTOTYPE(config_parse_section_route_table);
332 CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_user_class);
333 CONFIG_PARSER_PROTOTYPE(config_parse_ntp);
334 CONFIG_PARSER_PROTOTYPE(config_parse_iaid);
335 CONFIG_PARSER_PROTOTYPE(config_parse_required_for_online);
336 CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_max_attempts);
337 CONFIG_PARSER_PROTOTYPE(config_parse_multicast_router);
338 /* Legacy IPv4LL support */
339 CONFIG_PARSER_PROTOTYPE(config_parse_ipv4ll);
340
341 const struct ConfigPerfItem* network_network_gperf_lookup(const char *key, GPERF_LEN_TYPE length);
342
343 extern const sd_bus_vtable network_vtable[];
344
345 int network_node_enumerator(sd_bus *bus, const char *path, void *userdata, char ***nodes, sd_bus_error *error);
346 int network_object_find(sd_bus *bus, const char *path, const char *interface, void *userdata, void **found, sd_bus_error *error);
347
348 const char* ipv6_privacy_extensions_to_string(IPv6PrivacyExtensions i) _const_;
349 IPv6PrivacyExtensions ipv6_privacy_extensions_from_string(const char *s) _pure_;
350
351 const char* dhcp_use_domains_to_string(DHCPUseDomains p) _const_;
352 DHCPUseDomains dhcp_use_domains_from_string(const char *s) _pure_;
353
354 const char* lldp_mode_to_string(LLDPMode m) _const_;
355 LLDPMode lldp_mode_from_string(const char *s) _pure_;
356
357 const char* radv_prefix_delegation_to_string(RADVPrefixDelegation i) _const_;
358 RADVPrefixDelegation radv_prefix_delegation_from_string(const char *s) _pure_;
359
360 const char* multicast_router_to_string(MulticastRouter i) _const_;
361 MulticastRouter multicast_router_from_string(const char *s) _pure_;