]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/network/networkd-network.h
tree-wide: drop redundant _cleanup_ macros (#8810)
[thirdparty/systemd.git] / src / network / networkd-network.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 #pragma once
3
4 /***
5 This file is part of systemd.
6
7 Copyright 2013 Tom Gundersen <teg@jklm.no>
8 ***/
9
10 #include "sd-bus.h"
11 #include "udev.h"
12
13 #include "condition.h"
14 #include "dhcp-identifier.h"
15 #include "hashmap.h"
16 #include "resolve-util.h"
17
18 #include "networkd-address.h"
19 #include "networkd-address-label.h"
20 #include "networkd-brvlan.h"
21 #include "networkd-fdb.h"
22 #include "networkd-lldp-tx.h"
23 #include "networkd-ipv6-proxy-ndp.h"
24 #include "networkd-radv.h"
25 #include "networkd-route.h"
26 #include "networkd-routing-policy-rule.h"
27 #include "networkd-util.h"
28 #include "netdev/netdev.h"
29
30 #define DHCP_ROUTE_METRIC 1024
31 #define IPV4LL_ROUTE_METRIC 2048
32
33 #define BRIDGE_VLAN_BITMAP_MAX 4096
34 #define BRIDGE_VLAN_BITMAP_LEN (BRIDGE_VLAN_BITMAP_MAX / 32)
35
36 #define IPV6_MIN_MTU 1280
37
38 typedef enum DHCPClientIdentifier {
39 DHCP_CLIENT_ID_MAC,
40 DHCP_CLIENT_ID_DUID,
41 /* The following option may not be good for RFC regarding DHCP (3315 and 4361).
42 * But some setups require this. E.g., Sky Broadband, the second largest provider in the UK
43 * requires the client id to be set to a custom string, reported at
44 * https://github.com/systemd/systemd/issues/7828 */
45 DHCP_CLIENT_ID_DUID_ONLY,
46 _DHCP_CLIENT_ID_MAX,
47 _DHCP_CLIENT_ID_INVALID = -1,
48 } DHCPClientIdentifier;
49
50 typedef enum IPv6PrivacyExtensions {
51 /* The values map to the kernel's /proc/sys/net/ipv6/conf/xxx/use_tempaddr values */
52 IPV6_PRIVACY_EXTENSIONS_NO,
53 IPV6_PRIVACY_EXTENSIONS_PREFER_PUBLIC,
54 IPV6_PRIVACY_EXTENSIONS_YES, /* aka prefer-temporary */
55 _IPV6_PRIVACY_EXTENSIONS_MAX,
56 _IPV6_PRIVACY_EXTENSIONS_INVALID = -1,
57 } IPv6PrivacyExtensions;
58
59 typedef enum DHCPUseDomains {
60 DHCP_USE_DOMAINS_NO,
61 DHCP_USE_DOMAINS_YES,
62 DHCP_USE_DOMAINS_ROUTE,
63 _DHCP_USE_DOMAINS_MAX,
64 _DHCP_USE_DOMAINS_INVALID = -1,
65 } DHCPUseDomains;
66
67 typedef enum LLDPMode {
68 LLDP_MODE_NO = 0,
69 LLDP_MODE_YES = 1,
70 LLDP_MODE_ROUTERS_ONLY = 2,
71 _LLDP_MODE_MAX,
72 _LLDP_MODE_INVALID = -1,
73 } LLDPMode;
74
75 typedef struct DUID {
76 /* Value of Type in [DHCP] section */
77 DUIDType type;
78
79 uint8_t raw_data_len;
80 uint8_t raw_data[MAX_DUID_LEN];
81 } DUID;
82
83 typedef enum RADVPrefixDelegation {
84 RADV_PREFIX_DELEGATION_NONE,
85 RADV_PREFIX_DELEGATION_STATIC,
86 RADV_PREFIX_DELEGATION_DHCP6,
87 RADV_PREFIX_DELEGATION_BOTH,
88 } RADVPrefixDelegation;
89
90 typedef struct NetworkConfigSection {
91 unsigned line;
92 char filename[];
93 } NetworkConfigSection;
94
95 int network_config_section_new(const char *filename, unsigned line, NetworkConfigSection **s);
96 void network_config_section_free(NetworkConfigSection *network);
97
98 DEFINE_TRIVIAL_CLEANUP_FUNC(NetworkConfigSection*, network_config_section_free);
99
100 typedef struct Manager Manager;
101
102 struct Network {
103 Manager *manager;
104
105 char *filename;
106 char *name;
107
108 struct ether_addr *match_mac;
109 char **match_path;
110 char **match_driver;
111 char **match_type;
112 char **match_name;
113
114 Condition *match_host;
115 Condition *match_virt;
116 Condition *match_kernel_cmdline;
117 Condition *match_kernel_version;
118 Condition *match_arch;
119
120 char *description;
121
122 NetDev *bridge;
123 NetDev *bond;
124 NetDev *vrf;
125 Hashmap *stacked_netdevs;
126
127 /* DHCP Client Support */
128 AddressFamilyBoolean dhcp;
129 DHCPClientIdentifier dhcp_client_identifier;
130 char *dhcp_vendor_class_identifier;
131 char *dhcp_hostname;
132 unsigned dhcp_route_metric;
133 uint32_t dhcp_route_table;
134 uint16_t dhcp_client_port;
135 bool dhcp_anonymize;
136 bool dhcp_send_hostname;
137 bool dhcp_broadcast;
138 bool dhcp_critical;
139 bool dhcp_use_dns;
140 bool dhcp_use_ntp;
141 bool dhcp_use_mtu;
142 bool dhcp_use_routes;
143 bool dhcp_use_timezone;
144 bool rapid_commit;
145 bool dhcp_use_hostname;
146 bool dhcp_route_table_set;
147 DHCPUseDomains dhcp_use_domains;
148
149 /* DHCP Server Support */
150 bool dhcp_server;
151 bool dhcp_server_emit_dns;
152 struct in_addr *dhcp_server_dns;
153 unsigned n_dhcp_server_dns;
154 bool dhcp_server_emit_ntp;
155 struct in_addr *dhcp_server_ntp;
156 unsigned n_dhcp_server_ntp;
157 bool dhcp_server_emit_router;
158 bool dhcp_server_emit_timezone;
159 char *dhcp_server_timezone;
160 usec_t dhcp_server_default_lease_time_usec, dhcp_server_max_lease_time_usec;
161 uint32_t dhcp_server_pool_offset;
162 uint32_t dhcp_server_pool_size;
163
164 /* IPV4LL Support */
165 AddressFamilyBoolean link_local;
166 bool ipv4ll_route;
167
168 /* IPv6 prefix delegation support */
169 RADVPrefixDelegation router_prefix_delegation;
170 usec_t router_lifetime_usec;
171 uint8_t router_preference;
172 bool router_managed;
173 bool router_other_information;
174 bool router_emit_dns;
175 bool router_emit_domains;
176 usec_t router_dns_lifetime_usec;
177 struct in6_addr *router_dns;
178 unsigned n_router_dns;
179 char **router_search_domains;
180
181 /* Bridge Support */
182 bool use_bpdu;
183 bool hairpin;
184 bool fast_leave;
185 bool allow_port_to_be_root;
186 bool unicast_flood;
187 uint32_t cost;
188 uint16_t priority;
189
190 bool use_br_vlan;
191 uint16_t pvid;
192 uint32_t br_vid_bitmap[BRIDGE_VLAN_BITMAP_LEN];
193 uint32_t br_untagged_bitmap[BRIDGE_VLAN_BITMAP_LEN];
194
195 AddressFamilyBoolean ip_forward;
196 bool ip_masquerade;
197
198 int ipv6_accept_ra;
199 int ipv6_dad_transmits;
200 int ipv6_hop_limit;
201 int ipv6_proxy_ndp;
202 int proxy_arp;
203 unsigned ipv6_mtu;
204
205 bool ipv6_accept_ra_use_dns;
206 bool active_slave;
207 bool primary_slave;
208 DHCPUseDomains ipv6_accept_ra_use_domains;
209 uint32_t ipv6_accept_ra_route_table;
210
211 union in_addr_union ipv6_token;
212 IPv6PrivacyExtensions ipv6_privacy_extensions;
213
214 struct ether_addr *mac;
215 size_t mtu;
216 int arp;
217 bool unmanaged;
218 bool configure_without_carrier;
219 uint32_t iaid;
220 DUID duid;
221
222 bool required_for_online; /* Is this network required to be considered online? */
223
224 LLDPMode lldp_mode; /* LLDP reception */
225 LLDPEmit lldp_emit; /* LLDP transmission */
226
227 LIST_HEAD(Address, static_addresses);
228 LIST_HEAD(Route, static_routes);
229 LIST_HEAD(FdbEntry, static_fdb_entries);
230 LIST_HEAD(IPv6ProxyNDPAddress, ipv6_proxy_ndp_addresses);
231 LIST_HEAD(AddressLabel, address_labels);
232 LIST_HEAD(Prefix, static_prefixes);
233 LIST_HEAD(RoutingPolicyRule, rules);
234
235 unsigned n_static_addresses;
236 unsigned n_static_routes;
237 unsigned n_static_fdb_entries;
238 unsigned n_ipv6_proxy_ndp_addresses;
239 unsigned n_address_labels;
240 unsigned n_static_prefixes;
241 unsigned n_rules;
242
243 Hashmap *addresses_by_section;
244 Hashmap *routes_by_section;
245 Hashmap *fdb_entries_by_section;
246 Hashmap *address_labels_by_section;
247 Hashmap *prefixes_by_section;
248 Hashmap *rules_by_section;
249
250 struct in_addr_data *dns;
251 unsigned n_dns;
252
253 char **search_domains, **route_domains, **ntp, **bind_carrier;
254
255 ResolveSupport llmnr;
256 ResolveSupport mdns;
257 DnssecMode dnssec_mode;
258 Set *dnssec_negative_trust_anchors;
259
260 LIST_FIELDS(Network, networks);
261 };
262
263 void network_free(Network *network);
264
265 DEFINE_TRIVIAL_CLEANUP_FUNC(Network*, network_free);
266
267 int network_load(Manager *manager);
268
269 int network_get_by_name(Manager *manager, const char *name, Network **ret);
270 int network_get(Manager *manager, struct udev_device *device, const char *ifname, const struct ether_addr *mac, Network **ret);
271 int network_apply(Network *network, Link *link);
272 void network_apply_anonymize_if_set(Network *network);
273
274 bool network_has_static_ipv6_addresses(Network *network);
275
276 int config_parse_netdev(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
277 int config_parse_domains(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
278 int config_parse_tunnel(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
279 int config_parse_dhcp(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
280 int config_parse_dns(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
281 int config_parse_dhcp_client_identifier(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
282 int config_parse_ipv6token(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
283 int config_parse_ipv6_privacy_extensions(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
284 int config_parse_hostname(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
285 int config_parse_timezone(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
286 int config_parse_dhcp_server_dns(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
287 int config_parse_radv_dns(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
288 int config_parse_radv_search_domains(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
289 int config_parse_dhcp_server_ntp(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
290 int config_parse_dnssec_negative_trust_anchors(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
291 int config_parse_dhcp_use_domains(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
292 int config_parse_lldp_mode(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
293 int config_parse_dhcp_route_table(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
294 int config_parse_ntp(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
295 int config_parse_ipv6_mtu(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
296 /* Legacy IPv4LL support */
297 int config_parse_ipv4ll(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
298
299 const struct ConfigPerfItem* network_network_gperf_lookup(const char *key, GPERF_LEN_TYPE length);
300
301 extern const sd_bus_vtable network_vtable[];
302
303 int network_node_enumerator(sd_bus *bus, const char *path, void *userdata, char ***nodes, sd_bus_error *error);
304 int network_object_find(sd_bus *bus, const char *path, const char *interface, void *userdata, void **found, sd_bus_error *error);
305
306 const char* ipv6_privacy_extensions_to_string(IPv6PrivacyExtensions i) _const_;
307 IPv6PrivacyExtensions ipv6_privacy_extensions_from_string(const char *s) _pure_;
308
309 const char* dhcp_use_domains_to_string(DHCPUseDomains p) _const_;
310 DHCPUseDomains dhcp_use_domains_from_string(const char *s) _pure_;
311
312 const char* lldp_mode_to_string(LLDPMode m) _const_;
313 LLDPMode lldp_mode_from_string(const char *s) _pure_;