]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/network/networkd-network.h
Merge pull request #12753 from jrouleau/fix/hibernate-resume-timeout
[thirdparty/systemd.git] / src / network / networkd-network.h
CommitLineData
53e1b683 1/* SPDX-License-Identifier: LGPL-2.1+ */
fc2f9534
LP
2#pragma once
3
634f0f98 4#include "sd-bus.h"
51517f9e 5#include "sd-device.h"
634f0f98 6
fc2f9534 7#include "condition.h"
a2106925 8#include "conf-parser.h"
634f0f98
ZJS
9#include "dhcp-identifier.h"
10#include "hashmap.h"
8e2cb51c 11#include "netdev/bridge.h"
a2106925 12#include "netdev/netdev.h"
95b74ef6 13#include "networkd-address-label.h"
a2106925 14#include "networkd-address.h"
13b498f9 15#include "networkd-brvlan.h"
fc2f9534 16#include "networkd-fdb.h"
a0e5c15d 17#include "networkd-ipv6-proxy-ndp.h"
7f853950 18#include "networkd-lldp-rx.h"
a2106925 19#include "networkd-lldp-tx.h"
e4a71bf3 20#include "networkd-neighbor.h"
6e849e95 21#include "networkd-radv.h"
71d35b6b 22#include "networkd-route.h"
bce67bbe 23#include "networkd-routing-policy-rule.h"
fc2f9534 24#include "networkd-util.h"
5e2a51d5 25#include "ordered-set.h"
a2106925 26#include "resolve-util.h"
fc2f9534
LP
27
28#define DHCP_ROUTE_METRIC 1024
29#define IPV4LL_ROUTE_METRIC 2048
30
13b498f9
TJ
31#define BRIDGE_VLAN_BITMAP_MAX 4096
32#define BRIDGE_VLAN_BITMAP_LEN (BRIDGE_VLAN_BITMAP_MAX / 32)
33
499d555a 34typedef enum DHCPClientIdentifier {
fc2f9534
LP
35 DHCP_CLIENT_ID_MAC,
36 DHCP_CLIENT_ID_DUID,
dace710c
YW
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,
fc2f9534
LP
42 _DHCP_CLIENT_ID_MAX,
43 _DHCP_CLIENT_ID_INVALID = -1,
499d555a 44} DHCPClientIdentifier;
fc2f9534
LP
45
46typedef 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
b2a81c0b
LP
55typedef 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
8341a5c3
ZJS
63typedef 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];
0cf7c3fd 69 usec_t llt_time;
8341a5c3
ZJS
70} DUID;
71
56a23cb4
PF
72typedef enum RADVPrefixDelegation {
73 RADV_PREFIX_DELEGATION_NONE,
74 RADV_PREFIX_DELEGATION_STATIC,
75 RADV_PREFIX_DELEGATION_DHCP6,
76 RADV_PREFIX_DELEGATION_BOTH,
6b1dec66
YW
77 _RADV_PREFIX_DELEGATION_MAX,
78 _RADV_PREFIX_DELEGATION_INVALID = -1,
56a23cb4
PF
79} RADVPrefixDelegation;
80
7da377ef 81typedef enum KeepConfiguration {
95355a28
YW
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,
7da377ef
SS
88 _KEEP_CONFIGURATION_MAX,
89 _KEEP_CONFIGURATION_INVALID = -1,
90} KeepConfiguration;
91
634f0f98
ZJS
92typedef struct Manager Manager;
93
fc2f9534
LP
94struct Network {
95 Manager *manager;
96
97 char *filename;
98 char *name;
99
35ac3b76
YW
100 unsigned n_ref;
101
e90d0374 102 Set *match_mac;
fc2f9534
LP
103 char **match_path;
104 char **match_driver;
105 char **match_type;
106 char **match_name;
1beabe08 107 LIST_HEAD(Condition, conditions);
fc2f9534
LP
108
109 char *description;
110
111 NetDev *bridge;
112 NetDev *bond;
6cb955c6 113 NetDev *vrf;
fc2f9534 114 Hashmap *stacked_netdevs;
cebe1257
YW
115 char *bridge_name;
116 char *bond_name;
117 char *vrf_name;
118 Hashmap *stacked_netdev_names;
fc2f9534
LP
119
120 /* DHCP Client Support */
121 AddressFamilyBoolean dhcp;
499d555a 122 DHCPClientIdentifier dhcp_client_identifier;
fc2f9534 123 char *dhcp_vendor_class_identifier;
af1c0de0 124 char **dhcp_user_class;
27cb34f5 125 char *dhcp_hostname;
715cedfb 126 uint64_t dhcp_max_attempts;
94e9bd57
LP
127 unsigned dhcp_route_metric;
128 uint32_t dhcp_route_table;
9c77d107 129 uint16_t dhcp_client_port;
7585baa0 130 bool dhcp_anonymize;
27cb34f5 131 bool dhcp_send_hostname;
fc2f9534 132 bool dhcp_broadcast;
7da377ef 133 int dhcp_critical;
94e9bd57
LP
134 bool dhcp_use_dns;
135 bool dhcp_use_ntp;
136 bool dhcp_use_mtu;
27cb34f5
LP
137 bool dhcp_use_routes;
138 bool dhcp_use_timezone;
fb5c8216 139 bool rapid_commit;
94e9bd57 140 bool dhcp_use_hostname;
fc1ba79d 141 bool dhcp_route_table_set;
1501b429 142 bool dhcp_send_release;
94e9bd57 143 DHCPUseDomains dhcp_use_domains;
727b5734 144 Set *dhcp_black_listed_ip;
fc2f9534
LP
145
146 /* DHCP Server Support */
147 bool dhcp_server;
1a04db0f
LP
148 bool dhcp_server_emit_dns;
149 struct in_addr *dhcp_server_dns;
150 unsigned n_dhcp_server_dns;
151 bool dhcp_server_emit_ntp;
152 struct in_addr *dhcp_server_ntp;
153 unsigned n_dhcp_server_ntp;
77ff6022 154 bool dhcp_server_emit_router;
fc2f9534 155 bool dhcp_server_emit_timezone;
1a04db0f 156 char *dhcp_server_timezone;
fc2f9534 157 usec_t dhcp_server_default_lease_time_usec, dhcp_server_max_lease_time_usec;
9b3a67c5
TG
158 uint32_t dhcp_server_pool_offset;
159 uint32_t dhcp_server_pool_size;
fc2f9534
LP
160
161 /* IPV4LL Support */
162 AddressFamilyBoolean link_local;
163 bool ipv4ll_route;
164
5d5003ab
YW
165 bool default_route_on_device;
166
7d5cac19 167 /* IPv6 prefix delegation support */
56a23cb4 168 RADVPrefixDelegation router_prefix_delegation;
7d5cac19
PF
169 usec_t router_lifetime_usec;
170 uint8_t router_preference;
171 bool router_managed;
172 bool router_other_information;
9e25315c
PF
173 bool router_emit_dns;
174 bool router_emit_domains;
88295a05
PF
175 usec_t router_dns_lifetime_usec;
176 struct in6_addr *router_dns;
177 unsigned n_router_dns;
5e2a51d5 178 OrderedSet *router_search_domains;
125f20b4
PF
179 bool dhcp6_force_pd_other_information; /* Start DHCPv6 PD also when 'O'
180 RA flag is set, see RFC 7084,
181 WPD-4 */
7d5cac19 182
fc2f9534 183 /* Bridge Support */
7f9915f0
SS
184 int use_bpdu;
185 int hairpin;
186 int fast_leave;
187 int allow_port_to_be_root;
188 int unicast_flood;
7f15b714 189 int multicast_flood;
d3aa8b49 190 int multicast_to_unicast;
7f15b714
TJ
191 int neighbor_suppression;
192 int learning;
1087623b
SS
193 int bridge_proxy_arp;
194 int bridge_proxy_arp_wifi;
b56be296
DJL
195 uint32_t cost;
196 uint16_t priority;
0fadb2a4 197 MulticastRouter multicast_router;
fc2f9534 198
ffff9abe 199 bool use_br_vlan;
13b498f9
TJ
200 uint16_t pvid;
201 uint32_t br_vid_bitmap[BRIDGE_VLAN_BITMAP_LEN];
202 uint32_t br_untagged_bitmap[BRIDGE_VLAN_BITMAP_LEN];
203
06828bb6
HP
204 /* CAN support */
205 size_t can_bitrate;
206 unsigned can_sample_point;
207 usec_t can_restart_us;
c423be28 208 int can_triple_sampling;
06828bb6 209
fc2f9534
LP
210 AddressFamilyBoolean ip_forward;
211 bool ip_masquerade;
212
4f2e437a 213 int ipv6_accept_ra;
8749cbcd 214 int ipv6_dad_transmits;
b69c3180 215 int ipv6_hop_limit;
465dfe59 216 int ipv6_proxy_ndp;
23d8b221 217 int proxy_arp;
4e964aa0 218 uint32_t ipv6_mtu;
4f2e437a 219
1e7a0e21 220 bool ipv6_accept_ra_use_dns;
062c2eea
SS
221 bool ipv6_accept_ra_use_autonomous_prefix;
222 bool ipv6_accept_ra_use_onlink_prefix;
eb64b435
SS
223 bool active_slave;
224 bool primary_slave;
1e7a0e21 225 DHCPUseDomains ipv6_accept_ra_use_domains;
2ba31d29 226 uint32_t ipv6_accept_ra_route_table;
d5fa3339 227 bool ipv6_accept_ra_route_table_set;
e520ce64 228 Set *ndisc_black_listed_prefix;
1e7a0e21 229
fc2f9534
LP
230 union in_addr_union ipv6_token;
231 IPv6PrivacyExtensions ipv6_privacy_extensions;
232
233 struct ether_addr *mac;
4e964aa0 234 uint32_t mtu;
99d2baa2 235 int arp;
e6ebebbe 236 int multicast;
866e6b7a 237 int allmulticast;
a09dc546 238 bool unmanaged;
dad2d78e 239 bool configure_without_carrier;
93b4dab5 240 bool ignore_carrier_loss;
7da377ef 241 KeepConfiguration keep_configuration;
413708d1 242 uint32_t iaid;
8341a5c3 243 DUID duid;
fc2f9534 244
8217ed5e
TH
245 bool iaid_set;
246
c1a38904 247 bool required_for_online; /* Is this network required to be considered online? */
4ac77d63 248 LinkOperationalState required_operstate_for_online;
c1a38904 249
8e1ad1ea 250 LLDPMode lldp_mode; /* LLDP reception */
7272b25e 251 LLDPEmit lldp_emit; /* LLDP transmission */
fc2f9534
LP
252
253 LIST_HEAD(Address, static_addresses);
254 LIST_HEAD(Route, static_routes);
255 LIST_HEAD(FdbEntry, static_fdb_entries);
a0e5c15d 256 LIST_HEAD(IPv6ProxyNDPAddress, ipv6_proxy_ndp_addresses);
e4a71bf3 257 LIST_HEAD(Neighbor, neighbors);
95b74ef6 258 LIST_HEAD(AddressLabel, address_labels);
057abfd8 259 LIST_HEAD(Prefix, static_prefixes);
bce67bbe 260 LIST_HEAD(RoutingPolicyRule, rules);
fc2f9534 261
8c34b963
LP
262 unsigned n_static_addresses;
263 unsigned n_static_routes;
264 unsigned n_static_fdb_entries;
a0e5c15d 265 unsigned n_ipv6_proxy_ndp_addresses;
e4a71bf3 266 unsigned n_neighbors;
95b74ef6 267 unsigned n_address_labels;
057abfd8 268 unsigned n_static_prefixes;
bce67bbe 269 unsigned n_rules;
8c34b963 270
fc2f9534
LP
271 Hashmap *addresses_by_section;
272 Hashmap *routes_by_section;
273 Hashmap *fdb_entries_by_section;
e4a71bf3 274 Hashmap *neighbors_by_section;
95b74ef6 275 Hashmap *address_labels_by_section;
057abfd8 276 Hashmap *prefixes_by_section;
bce67bbe 277 Hashmap *rules_by_section;
fc2f9534 278
7ece6f58 279 /* All kinds of DNS configuration */
5512a963
LP
280 struct in_addr_data *dns;
281 unsigned n_dns;
5e2a51d5
ZJS
282 OrderedSet *search_domains, *route_domains;
283
7ece6f58 284 int dns_default_route;
fc2f9534 285 ResolveSupport llmnr;
aaa297d4 286 ResolveSupport mdns;
ad6c0475 287 DnssecMode dnssec_mode;
c9299be2 288 DnsOverTlsMode dns_over_tls_mode;
8a516214 289 Set *dnssec_negative_trust_anchors;
fc2f9534 290
7ece6f58
LP
291 char **ntp;
292 char **bind_carrier;
fc2f9534
LP
293};
294
35ac3b76
YW
295Network *network_ref(Network *network);
296Network *network_unref(Network *network);
297DEFINE_TRIVIAL_CLEANUP_FUNC(Network*, network_unref);
fc2f9534
LP
298
299int network_load(Manager *manager);
212bd73c 300int network_load_one(Manager *manager, const char *filename);
96db6412 301int network_verify(Network *network);
fc2f9534
LP
302
303int network_get_by_name(Manager *manager, const char *name, Network **ret);
51517f9e 304int network_get(Manager *manager, sd_device *device, const char *ifname, const struct ether_addr *mac, Network **ret);
7d342c03 305int network_apply(Network *network, Link *link);
add8d07d 306void network_apply_anonymize_if_set(Network *network);
fc2f9534 307
439689c6
SS
308bool network_has_static_ipv6_addresses(Network *network);
309
cebe1257 310CONFIG_PARSER_PROTOTYPE(config_parse_stacked_netdev);
a2106925
LP
311CONFIG_PARSER_PROTOTYPE(config_parse_domains);
312CONFIG_PARSER_PROTOTYPE(config_parse_tunnel);
313CONFIG_PARSER_PROTOTYPE(config_parse_dhcp);
314CONFIG_PARSER_PROTOTYPE(config_parse_dns);
315CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_client_identifier);
316CONFIG_PARSER_PROTOTYPE(config_parse_ipv6token);
317CONFIG_PARSER_PROTOTYPE(config_parse_ipv6_privacy_extensions);
318CONFIG_PARSER_PROTOTYPE(config_parse_hostname);
319CONFIG_PARSER_PROTOTYPE(config_parse_timezone);
320CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_server_dns);
727b5734 321CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_black_listed_ip_address);
a2106925
LP
322CONFIG_PARSER_PROTOTYPE(config_parse_radv_dns);
323CONFIG_PARSER_PROTOTYPE(config_parse_radv_search_domains);
324CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_server_ntp);
325CONFIG_PARSER_PROTOTYPE(config_parse_dnssec_negative_trust_anchors);
326CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_use_domains);
d5fa3339 327CONFIG_PARSER_PROTOTYPE(config_parse_section_route_table);
a2106925
LP
328CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_user_class);
329CONFIG_PARSER_PROTOTYPE(config_parse_ntp);
8217ed5e 330CONFIG_PARSER_PROTOTYPE(config_parse_iaid);
4ac77d63 331CONFIG_PARSER_PROTOTYPE(config_parse_required_for_online);
715cedfb 332CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_max_attempts);
7da377ef 333CONFIG_PARSER_PROTOTYPE(config_parse_keep_configuration);
fc2f9534 334/* Legacy IPv4LL support */
a2106925 335CONFIG_PARSER_PROTOTYPE(config_parse_ipv4ll);
fc2f9534 336
c9f7b4d3 337const struct ConfigPerfItem* network_network_gperf_lookup(const char *key, GPERF_LEN_TYPE length);
fc2f9534
LP
338
339extern const sd_bus_vtable network_vtable[];
340
341int network_node_enumerator(sd_bus *bus, const char *path, void *userdata, char ***nodes, sd_bus_error *error);
342int network_object_find(sd_bus *bus, const char *path, const char *interface, void *userdata, void **found, sd_bus_error *error);
343
344const char* ipv6_privacy_extensions_to_string(IPv6PrivacyExtensions i) _const_;
345IPv6PrivacyExtensions ipv6_privacy_extensions_from_string(const char *s) _pure_;
b2a81c0b
LP
346
347const char* dhcp_use_domains_to_string(DHCPUseDomains p) _const_;
348DHCPUseDomains dhcp_use_domains_from_string(const char *s) _pure_;
34437b4f 349
6b1dec66
YW
350const char* radv_prefix_delegation_to_string(RADVPrefixDelegation i) _const_;
351RADVPrefixDelegation radv_prefix_delegation_from_string(const char *s) _pure_;
7da377ef
SS
352
353const char* keep_configuration_to_string(KeepConfiguration i) _const_;
354KeepConfiguration keep_configuration_from_string(const char *s) _pure_;