]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/network/networkd.h
networkd: various fixes for the IPv6 privacy extensions support
[thirdparty/systemd.git] / src / network / networkd.h
CommitLineData
f579559b
TG
1/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3/***
4 This file is part of systemd.
5
6 Copyright 2013 Tom Gundersen <teg@jklm.no>
7
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
12
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20***/
21
22#pragma once
23
24#include <arpa/inet.h>
f579559b
TG
25
26#include "sd-event.h"
1c4baffc 27#include "sd-netlink.h"
1346b1f0 28#include "sd-bus.h"
f5be5601 29#include "sd-dhcp-client.h"
dd43110f 30#include "sd-dhcp-server.h"
5c1d3fc9 31#include "sd-ipv4ll.h"
4138fb2c
PF
32#include "sd-icmp6-nd.h"
33#include "sd-dhcp6-client.h"
f579559b 34#include "udev.h"
ce43e484 35#include "sd-lldp.h"
f579559b 36
1c4baffc 37#include "netlink-util.h"
f579559b
TG
38#include "hashmap.h"
39#include "list.h"
06f021a8 40#include "set.h"
134e56dc 41#include "condition.h"
3b653205 42#include "in-addr-util.h"
f579559b 43
aba496a5 44#define CACHE_INFO_INFINITY_LIFE_TIME 0xFFFFFFFFU
4faefc7f
LP
45#define DHCP_ROUTE_METRIC 1024
46#define IPV4LL_ROUTE_METRIC 2048
aba496a5 47
1a436809 48typedef struct NetDev NetDev;
f579559b
TG
49typedef struct Network Network;
50typedef struct Link Link;
51typedef struct Address Address;
52typedef struct Route Route;
53typedef struct Manager Manager;
11bf3cce 54typedef struct AddressPool AddressPool;
b98b483b 55typedef struct FdbEntry FdbEntry;
f579559b 56
cb9fc36a 57typedef enum AddressFamilyBoolean {
769d324c
LP
58 /* This is a bitmask, though it usually doesn't feel that way! */
59 ADDRESS_FAMILY_NO = 0,
60 ADDRESS_FAMILY_IPV4 = 1,
61 ADDRESS_FAMILY_IPV6 = 2,
62 ADDRESS_FAMILY_YES = 3,
cb9fc36a
LP
63 _ADDRESS_FAMILY_BOOLEAN_MAX,
64 _ADDRESS_FAMILY_BOOLEAN_INVALID = -1,
65} AddressFamilyBoolean;
ed942a9e 66
bd8f6538
TG
67typedef enum LLMNRSupport {
68 LLMNR_SUPPORT_NO,
69 LLMNR_SUPPORT_YES,
70 LLMNR_SUPPORT_RESOLVE,
71 _LLMNR_SUPPORT_MAX,
72 _LLMNR_SUPPORT_INVALID = -1,
73} LLMNRSupport;
74
e331e246
TG
75typedef enum LinkOperationalState {
76 LINK_OPERSTATE_OFF,
77 LINK_OPERSTATE_NO_CARRIER,
78 LINK_OPERSTATE_DORMANT,
79 LINK_OPERSTATE_CARRIER,
80 LINK_OPERSTATE_DEGRADED,
81 LINK_OPERSTATE_ROUTABLE,
82 _LINK_OPERSTATE_MAX,
83 _LINK_OPERSTATE_INVALID = -1
84} LinkOperationalState;
85
3e43b2cd
JJ
86typedef enum DCHPClientIdentifier {
87 DHCP_CLIENT_ID_MAC,
88 DHCP_CLIENT_ID_DUID,
89 _DHCP_CLIENT_ID_MAX,
90 _DHCP_CLIENT_ID_INVALID = -1,
91} DCHPClientIdentifier;
92
49092e22 93typedef enum IPv6PrivacyExtensions {
1f0d9695
LP
94 /* The values map to the kernel's /proc/sys/net/ipv6/conf/xxx/use_tempaddr values */
95 IPV6_PRIVACY_EXTENSIONS_NO,
49092e22 96 IPV6_PRIVACY_EXTENSIONS_PREFER_PUBLIC,
1f0d9695 97 IPV6_PRIVACY_EXTENSIONS_YES, /* aka prefer-temporary */
49092e22
SS
98 _IPV6_PRIVACY_EXTENSIONS_MAX,
99 _IPV6_PRIVACY_EXTENSIONS_INVALID = -1,
100} IPv6PrivacyExtensions;
101
b98b483b
AR
102struct FdbEntry {
103 Network *network;
104 unsigned section;
105
106 struct ether_addr *mac_addr;
107 uint16_t vlan_id;
108
109 LIST_FIELDS(FdbEntry, static_fdb_entries);
110};
111
f579559b
TG
112struct Network {
113 Manager *manager;
114
115 char *filename;
dbffab87 116 char *name;
f579559b
TG
117
118 struct ether_addr *match_mac;
5256e00e
TG
119 char **match_path;
120 char **match_driver;
121 char **match_type;
122 char **match_name;
edb85f0d 123
2cc412b5
TG
124 Condition *match_host;
125 Condition *match_virt;
126 Condition *match_kernel;
edbb03e9 127 Condition *match_arch;
f579559b
TG
128
129 char *description;
1a436809
TG
130 NetDev *bridge;
131 NetDev *bond;
6a0a2f86 132 Hashmap *stacked_netdevs;
cb9fc36a 133 AddressFamilyBoolean dhcp;
3e43b2cd 134 DCHPClientIdentifier dhcp_client_identifier;
3175fcde 135 char *dhcp_vendor_class_identifier;
5be4d38e 136 bool dhcp_dns;
bcb7a07e 137 bool dhcp_ntp;
4f882b2a 138 bool dhcp_mtu;
1346b1f0 139 bool dhcp_hostname;
ad0734e8 140 bool dhcp_domains;
4cc7a82c 141 bool dhcp_sendhost;
f5de5b00 142 bool dhcp_broadcast;
eb27aeca 143 bool dhcp_critical;
e1ea665e 144 bool dhcp_routes;
84b5b79a 145 unsigned dhcp_route_metric;
d0d6a4cd 146 AddressFamilyBoolean link_local;
bfa695b5 147 bool ipv4ll_route;
7f77697a 148 union in_addr_union ipv6_token;
f579559b 149
dd43110f
TG
150 bool dhcp_server;
151
e1853b00
SS
152 unsigned cost;
153
769d324c 154 AddressFamilyBoolean ip_forward;
5a8bcb67 155 bool ip_masquerade;
5a8bcb67 156
49092e22
SS
157 IPv6PrivacyExtensions ipv6_privacy_extensions;
158
c106cc36
TG
159 struct ether_addr *mac;
160 unsigned mtu;
161
ce43e484
SS
162 bool lldp;
163
f048a16b
TG
164 LIST_HEAD(Address, static_addresses);
165 LIST_HEAD(Route, static_routes);
b98b483b 166 LIST_HEAD(FdbEntry, static_fdb_entries);
f579559b 167
6ae115c1
TG
168 Hashmap *addresses_by_section;
169 Hashmap *routes_by_section;
b98b483b 170 Hashmap *fdb_entries_by_section;
6ae115c1 171
67272d15 172 bool wildcard_domain;
0d4ad91d 173 char **domains, **dns, **ntp, **bind_carrier;
06f021a8 174
bd8f6538
TG
175 LLMNRSupport llmnr;
176
f579559b
TG
177 LIST_FIELDS(Network, networks);
178};
179
180struct Address {
181 Network *network;
16aa63a0 182 unsigned section;
f579559b 183
0dd25fb9 184 int family;
f579559b 185 unsigned char prefixlen;
5c1d3fc9 186 unsigned char scope;
851c9f82 187 uint32_t flags;
f579559b
TG
188 char *label;
189
eb0ea358 190 struct in_addr broadcast;
aba496a5 191 struct ifa_cacheinfo cinfo;
8cd11a0f 192
5d3de3fe 193 union in_addr_union in_addr;
c081882f 194 union in_addr_union in_addr_peer;
f579559b 195
fd6d906c 196 bool ip_masquerade_done;
5a8bcb67 197
3d3d4255 198 LIST_FIELDS(Address, addresses);
f579559b
TG
199};
200
201struct Route {
202 Network *network;
16aa63a0 203 unsigned section;
f579559b 204
0dd25fb9 205 int family;
6ae115c1 206 unsigned char dst_prefixlen;
9e7e4408 207 unsigned char src_prefixlen;
5c1d3fc9
UTL
208 unsigned char scope;
209 uint32_t metrics;
28cc555d 210 unsigned char protocol; /* RTPROT_* */
f579559b 211
5d3de3fe
LP
212 union in_addr_union in_addr;
213 union in_addr_union dst_addr;
9e7e4408 214 union in_addr_union src_addr;
46b0c76e 215 union in_addr_union prefsrc_addr;
6ae115c1 216
3d3d4255 217 LIST_FIELDS(Route, routes);
f579559b
TG
218};
219
11bf3cce
LP
220struct AddressPool {
221 Manager *manager;
222
0dd25fb9 223 int family;
11bf3cce
LP
224 unsigned prefixlen;
225
226 union in_addr_union in_addr;
227
228 LIST_FIELDS(AddressPool, address_pools);
229};
230
f579559b 231struct Manager {
1c4baffc 232 sd_netlink *rtnl;
f579559b 233 sd_event *event;
9c0a72f9 234 sd_event_source *bus_retry_event_source;
1346b1f0 235 sd_bus *bus;
9c0a72f9 236 sd_bus_slot *prepare_for_sleep_slot;
f579559b
TG
237 struct udev *udev;
238 struct udev_monitor *udev_monitor;
239 sd_event_source *udev_event_source;
240
6a24f148
TG
241 bool enumerating;
242
bbf7c048 243 char *state_file;
e331e246 244 LinkOperationalState operational_state;
bbf7c048 245
f579559b 246 Hashmap *links;
52433f6b 247 Hashmap *netdevs;
dbffab87 248 Hashmap *networks_by_name;
f579559b 249 LIST_HEAD(Network, networks);
11bf3cce 250 LIST_HEAD(AddressPool, address_pools);
f579559b 251
f579559b
TG
252 usec_t network_dirs_ts_usec;
253};
254
2ad8416d
ZJS
255extern const char* const network_dirs[];
256
f579559b
TG
257/* Manager */
258
e331e246
TG
259extern const sd_bus_vtable manager_vtable[];
260
f579559b
TG
261int manager_new(Manager **ret);
262void manager_free(Manager *m);
263
8f203c16 264int manager_connect_bus(Manager *m);
a97dcc12
TG
265int manager_run(Manager *m);
266
02b59d57
TG
267int manager_load_config(Manager *m);
268bool manager_should_reload(Manager *m);
269
505f8da7 270int manager_rtnl_enumerate_links(Manager *m);
45af44d4 271int manager_rtnl_enumerate_addresses(Manager *m);
f579559b 272
e331e246 273int manager_send_changed(Manager *m, const char *property, ...) _sentinel_;
bbf7c048 274int manager_save(Manager *m);
3bef724f 275
0dd25fb9 276int manager_address_pool_acquire(Manager *m, int family, unsigned prefixlen, union in_addr_union *found);
11bf3cce 277
f579559b
TG
278DEFINE_TRIVIAL_CLEANUP_FUNC(Manager*, manager_free);
279#define _cleanup_manager_free_ _cleanup_(manager_freep)
280
281/* Network */
282
283int network_load(Manager *manager);
f579559b
TG
284
285void network_free(Network *network);
286
287DEFINE_TRIVIAL_CLEANUP_FUNC(Network*, network_free);
288#define _cleanup_network_free_ _cleanup_(network_freep)
289
dbffab87 290int network_get_by_name(Manager *manager, const char *name, Network **ret);
505f8da7
TG
291int network_get(Manager *manager, struct udev_device *device,
292 const char *ifname, const struct ether_addr *mac,
293 Network **ret);
f579559b
TG
294int network_apply(Manager *manager, Network *network, Link *link);
295
69a93e7d 296int config_parse_netdev(const char *unit, const char *filename, unsigned line,
02b59d57
TG
297 const char *section, unsigned section_line, const char *lvalue,
298 int ltype, const char *rvalue, void *data, void *userdata);
299
6192b846
TG
300int config_parse_domains(const char *unit,
301 const char *filename,
302 unsigned line,
303 const char *section,
304 unsigned section_line,
305 const char *lvalue,
306 int ltype,
307 const char *rvalue,
308 void *data,
309 void *userdata);
310
7951dea2
SS
311int config_parse_tunnel(const char *unit,
312 const char *filename,
313 unsigned line,
314 const char *section,
315 unsigned section_line,
316 const char *lvalue,
317 int ltype,
318 const char *rvalue,
319 void *data,
320 void *userdata);
321
322int config_parse_tunnel_address(const char *unit,
323 const char *filename,
324 unsigned line,
325 const char *section,
326 unsigned section_line,
327 const char *lvalue,
328 int ltype,
329 const char *rvalue,
330 void *data,
331 void *userdata);
332
85a8eeee
SS
333int config_parse_vxlan_group_address(const char *unit,
334 const char *filename,
335 unsigned line,
336 const char *section,
337 unsigned section_line,
338 const char *lvalue,
339 int ltype,
340 const char *rvalue,
341 void *data,
342 void *userdata);
343
3175fcde
TG
344extern const sd_bus_vtable network_vtable[];
345
346int network_node_enumerator(sd_bus *bus, const char *path, void *userdata, char ***nodes, sd_bus_error *error);
347int network_object_find(sd_bus *bus, const char *path, const char *interface, void *userdata, void **found, sd_bus_error *error);
348
02b59d57 349/* gperf */
c0dda186 350const struct ConfigPerfItem* network_network_gperf_lookup(const char *key, unsigned length);
f579559b
TG
351
352/* Route */
f048a16b 353int route_new_static(Network *network, unsigned section, Route **ret);
28cc555d 354int route_new_dynamic(Route **ret, unsigned char rtm_protocol);
f579559b 355void route_free(Route *route);
1c4baffc
TG
356int route_configure(Route *route, Link *link, sd_netlink_message_handler_t callback);
357int route_drop(Route *route, Link *link, sd_netlink_message_handler_t callback);
5c1d3fc9 358
f579559b
TG
359
360DEFINE_TRIVIAL_CLEANUP_FUNC(Route*, route_free);
361#define _cleanup_route_free_ _cleanup_(route_freep)
362
363int config_parse_gateway(const char *unit, const char *filename, unsigned line,
71a61510
TG
364 const char *section, unsigned section_line, const char *lvalue,
365 int ltype, const char *rvalue, void *data, void *userdata);
f579559b 366
6ae115c1
TG
367int config_parse_destination(const char *unit, const char *filename, unsigned line,
368 const char *section, unsigned section_line, const char *lvalue,
369 int ltype, const char *rvalue, void *data, void *userdata);
370
5d8e593d
SS
371int config_parse_route_priority(const char *unit, const char *filename, unsigned line,
372 const char *section, unsigned section_line, const char *lvalue,
373 int ltype, const char *rvalue, void *data, void *userdata);
769b56a3
TG
374
375int config_parse_route_scope(const char *unit, const char *filename, unsigned line,
376 const char *section, unsigned section_line, const char *lvalue,
377 int ltype, const char *rvalue, void *data, void *userdata);
f579559b 378/* Address */
f048a16b
TG
379int address_new_static(Network *network, unsigned section, Address **ret);
380int address_new_dynamic(Address **ret);
f579559b 381void address_free(Address *address);
1c4baffc
TG
382int address_configure(Address *address, Link *link, sd_netlink_message_handler_t callback);
383int address_update(Address *address, Link *link, sd_netlink_message_handler_t callback);
384int address_drop(Address *address, Link *link, sd_netlink_message_handler_t callback);
5a8bcb67
LP
385int address_establish(Address *address, Link *link);
386int address_release(Address *address, Link *link);
9505d3c6 387bool address_equal(Address *a1, Address *a2);
f579559b
TG
388
389DEFINE_TRIVIAL_CLEANUP_FUNC(Address*, address_free);
390#define _cleanup_address_free_ _cleanup_(address_freep)
391
392int config_parse_address(const char *unit, const char *filename, unsigned line,
71a61510
TG
393 const char *section, unsigned section_line, const char *lvalue,
394 int ltype, const char *rvalue, void *data, void *userdata);
f579559b 395
eb0ea358
TG
396int config_parse_broadcast(const char *unit, const char *filename, unsigned line,
397 const char *section, unsigned section_line, const char *lvalue,
398 int ltype, const char *rvalue, void *data, void *userdata);
399
6ae115c1
TG
400int config_parse_label(const char *unit, const char *filename, unsigned line,
401 const char *section, unsigned section_line, const char *lvalue,
402 int ltype, const char *rvalue, void *data, void *userdata);
403
b98b483b 404/* Forwarding database table. */
a245ced0 405int fdb_entry_configure(Link *const link, FdbEntry *const fdb_entry);
b98b483b
AR
406void fdb_entry_free(FdbEntry *fdb_entry);
407int fdb_entry_new_static(Network *const network, const unsigned section, FdbEntry **ret);
408
409DEFINE_TRIVIAL_CLEANUP_FUNC(FdbEntry*, fdb_entry_free);
410#define _cleanup_fdbentry_free_ _cleanup_(fdb_entry_freep)
411
412int config_parse_fdb_hwaddr(const char *unit, const char *filename, unsigned line,
413 const char *section, unsigned section_line, const char *lvalue,
414 int ltype, const char *rvalue, void *data, void *userdata);
415
416int config_parse_fdb_vlan_id(const char *unit, const char *filename, unsigned line,
417 const char *section, unsigned section_line, const char *lvalue,
418 int ltype, const char *rvalue, void *data, void *userdata);
419
ed942a9e
TG
420/* DHCP support */
421
ed942a9e
TG
422int config_parse_dhcp(const char *unit, const char *filename, unsigned line,
423 const char *section, unsigned section_line, const char *lvalue,
424 int ltype, const char *rvalue, void *data, void *userdata);
3e43b2cd
JJ
425int config_parse_dhcp_client_identifier(const char *unit, const char *filename, unsigned line,
426 const char *section, unsigned section_line, const char *lvalue,
427 int ltype, const char *rvalue, void *data, void *userdata);
ed942a9e 428
d0d6a4cd
TG
429/* IPv4LL support (legacy) */
430
431int config_parse_ipv4ll(const char *unit, const char *filename, unsigned line,
432 const char *section, unsigned section_line, const char *lvalue,
433 int ltype, const char *rvalue, void *data, void *userdata);
434
7f77697a 435/* IPv6 support */
60c35566
TG
436int config_parse_ipv6token(const char *unit, const char *filename, unsigned line,
437 const char *section, unsigned section_line, const char *lvalue,
438 int ltype, const char *rvalue, void *data, void *userdata);
7f77697a 439
bd8f6538
TG
440/* LLMNR support */
441
442const char* llmnr_support_to_string(LLMNRSupport i) _const_;
443LLMNRSupport llmnr_support_from_string(const char *s) _pure_;
444
445int config_parse_llmnr(const char *unit, const char *filename, unsigned line,
446 const char *section, unsigned section_line, const char *lvalue,
447 int ltype, const char *rvalue, void *data, void *userdata);
448
11bf3cce
LP
449/* Address Pool */
450
0dd25fb9
LP
451int address_pool_new(Manager *m, AddressPool **ret, int family, const union in_addr_union *u, unsigned prefixlen);
452int address_pool_new_from_string(Manager *m, AddressPool **ret, int family, const char *p, unsigned prefixlen);
11bf3cce
LP
453void address_pool_free(AddressPool *p);
454
455int address_pool_acquire(AddressPool *p, unsigned prefixlen, union in_addr_union *found);
cb9fc36a
LP
456
457const char *address_family_boolean_to_string(AddressFamilyBoolean b) _const_;
458AddressFamilyBoolean address_family_boolean_from_string(const char *s) _const_;
769d324c
LP
459
460int config_parse_address_family_boolean(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);
e331e246 461
8add5f79
NO
462/* IPForwarding parser */
463int config_parse_address_family_boolean_with_kernel(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);
464
6a7a4e4d 465/* Operational State */
e331e246
TG
466
467const char* link_operstate_to_string(LinkOperationalState s) _const_;
468LinkOperationalState link_operstate_from_string(const char *s) _pure_;
49092e22 469
aa6b0ac4 470/* IPv6 privacy extensions support */
49092e22
SS
471
472const char* ipv6_privacy_extensions_to_string(IPv6PrivacyExtensions i) _const_;
473IPv6PrivacyExtensions ipv6_privacy_extensions_from_string(const char *s) _pure_;
474
475int 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);