]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/network/networkd-network.h
Merge pull request #12912 from yuwata/network-move-functions
[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 "hashmap.h"
10 #include "netdev/bridge.h"
11 #include "netdev/netdev.h"
12 #include "networkd-address-label.h"
13 #include "networkd-address.h"
14 #include "networkd-brvlan.h"
15 #include "networkd-dhcp-common.h"
16 #include "networkd-dhcp4.h"
17 #include "networkd-fdb.h"
18 #include "networkd-ipv6-proxy-ndp.h"
19 #include "networkd-lldp-rx.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 typedef enum IPv6PrivacyExtensions {
30 /* The values map to the kernel's /proc/sys/net/ipv6/conf/xxx/use_tempaddr values */
31 IPV6_PRIVACY_EXTENSIONS_NO,
32 IPV6_PRIVACY_EXTENSIONS_PREFER_PUBLIC,
33 IPV6_PRIVACY_EXTENSIONS_YES, /* aka prefer-temporary */
34 _IPV6_PRIVACY_EXTENSIONS_MAX,
35 _IPV6_PRIVACY_EXTENSIONS_INVALID = -1,
36 } IPv6PrivacyExtensions;
37
38 typedef enum KeepConfiguration {
39 KEEP_CONFIGURATION_NO = 0,
40 KEEP_CONFIGURATION_DHCP_ON_START = 1 << 0,
41 KEEP_CONFIGURATION_DHCP_ON_STOP = 1 << 1,
42 KEEP_CONFIGURATION_DHCP = KEEP_CONFIGURATION_DHCP_ON_START | KEEP_CONFIGURATION_DHCP_ON_STOP,
43 KEEP_CONFIGURATION_STATIC = 1 << 2,
44 KEEP_CONFIGURATION_YES = KEEP_CONFIGURATION_DHCP | KEEP_CONFIGURATION_STATIC,
45 _KEEP_CONFIGURATION_MAX,
46 _KEEP_CONFIGURATION_INVALID = -1,
47 } KeepConfiguration;
48
49 typedef struct Manager Manager;
50
51 struct Network {
52 Manager *manager;
53
54 char *filename;
55 char *name;
56
57 unsigned n_ref;
58
59 Set *match_mac;
60 char **match_path;
61 char **match_driver;
62 char **match_type;
63 char **match_name;
64 char **match_property;
65 LIST_HEAD(Condition, conditions);
66
67 char *description;
68
69 NetDev *bridge;
70 NetDev *bond;
71 NetDev *vrf;
72 Hashmap *stacked_netdevs;
73 char *bridge_name;
74 char *bond_name;
75 char *vrf_name;
76 Hashmap *stacked_netdev_names;
77
78 /* DHCP Client Support */
79 AddressFamilyBoolean dhcp;
80 DHCPClientIdentifier dhcp_client_identifier;
81 char *dhcp_vendor_class_identifier;
82 char **dhcp_user_class;
83 char *dhcp_hostname;
84 uint64_t dhcp_max_attempts;
85 unsigned dhcp_route_metric;
86 uint32_t dhcp_route_table;
87 uint16_t dhcp_client_port;
88 bool dhcp_anonymize;
89 bool dhcp_send_hostname;
90 bool dhcp_broadcast;
91 int dhcp_critical;
92 bool dhcp_use_dns;
93 bool dhcp_use_ntp;
94 bool dhcp_use_mtu;
95 bool dhcp_use_routes;
96 bool dhcp_use_timezone;
97 bool rapid_commit;
98 bool dhcp_use_hostname;
99 bool dhcp_route_table_set;
100 bool dhcp_send_release;
101 DHCPUseDomains dhcp_use_domains;
102 Set *dhcp_black_listed_ip;
103
104 /* DHCP Server Support */
105 bool dhcp_server;
106 bool dhcp_server_emit_dns;
107 struct in_addr *dhcp_server_dns;
108 unsigned n_dhcp_server_dns;
109 bool dhcp_server_emit_ntp;
110 struct in_addr *dhcp_server_ntp;
111 unsigned n_dhcp_server_ntp;
112 bool dhcp_server_emit_router;
113 bool dhcp_server_emit_timezone;
114 char *dhcp_server_timezone;
115 usec_t dhcp_server_default_lease_time_usec, dhcp_server_max_lease_time_usec;
116 uint32_t dhcp_server_pool_offset;
117 uint32_t dhcp_server_pool_size;
118
119 /* IPV4LL Support */
120 AddressFamilyBoolean link_local;
121 bool ipv4ll_route;
122
123 bool default_route_on_device;
124
125 /* IPv6 prefix delegation support */
126 RADVPrefixDelegation router_prefix_delegation;
127 usec_t router_lifetime_usec;
128 uint8_t router_preference;
129 bool router_managed;
130 bool router_other_information;
131 bool router_emit_dns;
132 bool router_emit_domains;
133 usec_t router_dns_lifetime_usec;
134 struct in6_addr *router_dns;
135 unsigned n_router_dns;
136 OrderedSet *router_search_domains;
137 bool dhcp6_force_pd_other_information; /* Start DHCPv6 PD also when 'O'
138 RA flag is set, see RFC 7084,
139 WPD-4 */
140
141 /* Bridge Support */
142 int use_bpdu;
143 int hairpin;
144 int fast_leave;
145 int allow_port_to_be_root;
146 int unicast_flood;
147 int multicast_flood;
148 int multicast_to_unicast;
149 int neighbor_suppression;
150 int learning;
151 int bridge_proxy_arp;
152 int bridge_proxy_arp_wifi;
153 uint32_t cost;
154 uint16_t priority;
155 MulticastRouter multicast_router;
156
157 bool use_br_vlan;
158 uint16_t pvid;
159 uint32_t br_vid_bitmap[BRIDGE_VLAN_BITMAP_LEN];
160 uint32_t br_untagged_bitmap[BRIDGE_VLAN_BITMAP_LEN];
161
162 /* CAN support */
163 size_t can_bitrate;
164 unsigned can_sample_point;
165 usec_t can_restart_us;
166 int can_triple_sampling;
167
168 AddressFamilyBoolean ip_forward;
169 bool ip_masquerade;
170
171 int ipv6_accept_ra;
172 int ipv6_dad_transmits;
173 int ipv6_hop_limit;
174 int ipv6_proxy_ndp;
175 int proxy_arp;
176 uint32_t ipv6_mtu;
177
178 bool ipv6_accept_ra_use_dns;
179 bool ipv6_accept_ra_use_autonomous_prefix;
180 bool ipv6_accept_ra_use_onlink_prefix;
181 bool active_slave;
182 bool primary_slave;
183 DHCPUseDomains ipv6_accept_ra_use_domains;
184 uint32_t ipv6_accept_ra_route_table;
185 bool ipv6_accept_ra_route_table_set;
186 Set *ndisc_black_listed_prefix;
187
188 union in_addr_union ipv6_token;
189 IPv6PrivacyExtensions ipv6_privacy_extensions;
190
191 struct ether_addr *mac;
192 uint32_t mtu;
193 int arp;
194 int multicast;
195 int allmulticast;
196 bool unmanaged;
197 bool configure_without_carrier;
198 bool ignore_carrier_loss;
199 KeepConfiguration keep_configuration;
200 uint32_t iaid;
201 DUID duid;
202
203 bool iaid_set;
204
205 bool required_for_online; /* Is this network required to be considered online? */
206 LinkOperationalState required_operstate_for_online;
207
208 LLDPMode lldp_mode; /* LLDP reception */
209 LLDPEmit lldp_emit; /* LLDP transmission */
210
211 LIST_HEAD(Address, static_addresses);
212 LIST_HEAD(Route, static_routes);
213 LIST_HEAD(FdbEntry, static_fdb_entries);
214 LIST_HEAD(IPv6ProxyNDPAddress, ipv6_proxy_ndp_addresses);
215 LIST_HEAD(Neighbor, neighbors);
216 LIST_HEAD(AddressLabel, address_labels);
217 LIST_HEAD(Prefix, static_prefixes);
218 LIST_HEAD(RoutingPolicyRule, rules);
219
220 unsigned n_static_addresses;
221 unsigned n_static_routes;
222 unsigned n_static_fdb_entries;
223 unsigned n_ipv6_proxy_ndp_addresses;
224 unsigned n_neighbors;
225 unsigned n_address_labels;
226 unsigned n_static_prefixes;
227 unsigned n_rules;
228
229 Hashmap *addresses_by_section;
230 Hashmap *routes_by_section;
231 Hashmap *fdb_entries_by_section;
232 Hashmap *neighbors_by_section;
233 Hashmap *address_labels_by_section;
234 Hashmap *prefixes_by_section;
235 Hashmap *rules_by_section;
236
237 /* All kinds of DNS configuration */
238 struct in_addr_data *dns;
239 unsigned n_dns;
240 OrderedSet *search_domains, *route_domains;
241
242 int dns_default_route;
243 ResolveSupport llmnr;
244 ResolveSupport mdns;
245 DnssecMode dnssec_mode;
246 DnsOverTlsMode dns_over_tls_mode;
247 Set *dnssec_negative_trust_anchors;
248
249 char **ntp;
250 char **bind_carrier;
251 };
252
253 Network *network_ref(Network *network);
254 Network *network_unref(Network *network);
255 DEFINE_TRIVIAL_CLEANUP_FUNC(Network*, network_unref);
256
257 int network_load(Manager *manager);
258 int network_load_one(Manager *manager, const char *filename);
259 int network_verify(Network *network);
260
261 int network_get_by_name(Manager *manager, const char *name, Network **ret);
262 int network_get(Manager *manager, sd_device *device, const char *ifname, const struct ether_addr *mac, Network **ret);
263 int network_apply(Network *network, Link *link);
264 void network_apply_anonymize_if_set(Network *network);
265
266 bool network_has_static_ipv6_addresses(Network *network);
267
268 CONFIG_PARSER_PROTOTYPE(config_parse_stacked_netdev);
269 CONFIG_PARSER_PROTOTYPE(config_parse_tunnel);
270 CONFIG_PARSER_PROTOTYPE(config_parse_ipv6token);
271 CONFIG_PARSER_PROTOTYPE(config_parse_ipv6_privacy_extensions);
272 CONFIG_PARSER_PROTOTYPE(config_parse_domains);
273 CONFIG_PARSER_PROTOTYPE(config_parse_dns);
274 CONFIG_PARSER_PROTOTYPE(config_parse_hostname);
275 CONFIG_PARSER_PROTOTYPE(config_parse_timezone);
276 CONFIG_PARSER_PROTOTYPE(config_parse_dnssec_negative_trust_anchors);
277 CONFIG_PARSER_PROTOTYPE(config_parse_ntp);
278 CONFIG_PARSER_PROTOTYPE(config_parse_required_for_online);
279 CONFIG_PARSER_PROTOTYPE(config_parse_keep_configuration);
280
281 const struct ConfigPerfItem* network_network_gperf_lookup(const char *key, GPERF_LEN_TYPE length);
282
283 const char* ipv6_privacy_extensions_to_string(IPv6PrivacyExtensions i) _const_;
284 IPv6PrivacyExtensions ipv6_privacy_extensions_from_string(const char *s) _pure_;
285
286 const char* keep_configuration_to_string(KeepConfiguration i) _const_;
287 KeepConfiguration keep_configuration_from_string(const char *s) _pure_;