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