]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/network/networkd-link.h
test: drop duplicated 's'
[thirdparty/systemd.git] / src / network / networkd-link.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 #pragma once
3
4 #include <endian.h>
5
6 #include "sd-bus.h"
7 #include "sd-device.h"
8 #include "sd-dhcp-client.h"
9 #include "sd-dhcp-server.h"
10 #include "sd-dhcp6-client.h"
11 #include "sd-ipv4ll.h"
12 #include "sd-lldp.h"
13 #include "sd-ndisc.h"
14 #include "sd-radv.h"
15 #include "sd-netlink.h"
16
17 #include "list.h"
18 #include "log-link.h"
19 #include "network-util.h"
20 #include "networkd-util.h"
21 #include "ordered-set.h"
22 #include "resolve-util.h"
23 #include "set.h"
24
25 typedef enum LinkState {
26 LINK_STATE_PENDING, /* udev has not initialized the link */
27 LINK_STATE_INITIALIZED, /* udev has initialized the link */
28 LINK_STATE_CONFIGURING, /* configuring addresses, routes, etc. */
29 LINK_STATE_CONFIGURED, /* everything is configured */
30 LINK_STATE_UNMANAGED, /* Unmanaged=yes is set */
31 LINK_STATE_FAILED, /* at least one configuration process failed */
32 LINK_STATE_LINGER, /* RTM_DELLINK for the link has been received */
33 _LINK_STATE_MAX,
34 _LINK_STATE_INVALID = -1
35 } LinkState;
36
37 typedef struct Manager Manager;
38 typedef struct Network Network;
39 typedef struct Address Address;
40 typedef struct DUID DUID;
41
42 typedef struct Link {
43 Manager *manager;
44
45 unsigned n_ref;
46
47 int ifindex;
48 int master_ifindex;
49 char *ifname;
50 char *kind;
51 unsigned short iftype;
52 char *state_file;
53 struct ether_addr mac;
54 struct in6_addr ipv6ll_address;
55 uint32_t mtu;
56 sd_device *sd_device;
57
58 /* wlan */
59 char *ssid;
60 struct ether_addr bssid;
61
62 unsigned flags;
63 uint8_t kernel_operstate;
64
65 Network *network;
66
67 LinkState state;
68 LinkOperationalState operstate;
69 LinkCarrierState carrier_state;
70 LinkAddressState address_state;
71
72 unsigned address_messages;
73 unsigned address_label_messages;
74 unsigned neighbor_messages;
75 unsigned route_messages;
76 unsigned nexthop_messages;
77 unsigned routing_policy_rule_messages;
78 unsigned routing_policy_rule_remove_messages;
79 unsigned enslaving;
80
81 Set *addresses;
82 Set *addresses_foreign;
83 Set *neighbors;
84 Set *neighbors_foreign;
85 Set *routes;
86 Set *routes_foreign;
87 Set *nexthops;
88 Set *nexthops_foreign;
89
90 sd_dhcp_client *dhcp_client;
91 sd_dhcp_lease *dhcp_lease, *dhcp_lease_old;
92 Set *dhcp_routes;
93 char *lease_file;
94 uint32_t original_mtu;
95 unsigned dhcp4_messages;
96 bool dhcp4_route_failed:1;
97 bool dhcp4_route_retrying:1;
98 bool dhcp4_configured:1;
99 bool dhcp6_configured:1;
100
101 unsigned ndisc_messages;
102 bool ndisc_configured;
103
104 sd_ipv4ll *ipv4ll;
105 bool ipv4ll_address:1;
106
107 bool addresses_configured:1;
108 bool addresses_ready:1;
109 bool neighbors_configured:1;
110 bool static_routes_configured:1;
111 bool static_routes_ready:1;
112 bool static_nexthops_configured:1;
113 bool routing_policy_rules_configured:1;
114 bool setting_mtu:1;
115
116 LIST_HEAD(Address, pool_addresses);
117
118 sd_dhcp_server *dhcp_server;
119
120 sd_ndisc *ndisc;
121 Set *ndisc_rdnss;
122 Set *ndisc_dnssl;
123
124 sd_radv *radv;
125
126 sd_dhcp6_client *dhcp6_client;
127
128 /* This is about LLDP reception */
129 sd_lldp *lldp;
130 char *lldp_file;
131
132 /* This is about LLDP transmission */
133 unsigned lldp_tx_fast; /* The LLDP txFast counter (See 802.1ab-2009, section 9.2.5.18) */
134 sd_event_source *lldp_emit_event_source;
135
136 Hashmap *bound_by_links;
137 Hashmap *bound_to_links;
138 Set *slaves;
139
140 /* For speed meter */
141 struct rtnl_link_stats64 stats_old, stats_new;
142 bool stats_updated;
143
144
145 /* All kinds of DNS configuration */
146 struct in_addr_data *dns;
147 unsigned n_dns;
148 OrderedSet *search_domains, *route_domains;
149
150 int dns_default_route;
151 ResolveSupport llmnr;
152 ResolveSupport mdns;
153 DnssecMode dnssec_mode;
154 DnsOverTlsMode dns_over_tls_mode;
155 Set *dnssec_negative_trust_anchors;
156
157 char **ntp;
158 } Link;
159
160 typedef int (*link_netlink_message_handler_t)(sd_netlink*, sd_netlink_message*, Link*);
161
162 DUID *link_get_duid(Link *link);
163 int get_product_uuid_handler(sd_bus_message *m, void *userdata, sd_bus_error *ret_error);
164
165 void link_ntp_settings_clear(Link *link);
166 void link_dns_settings_clear(Link *link);
167 Link *link_unref(Link *link);
168 Link *link_ref(Link *link);
169 DEFINE_TRIVIAL_CLEANUP_FUNC(Link*, link_unref);
170 DEFINE_TRIVIAL_DESTRUCTOR(link_netlink_destroy_callback, Link, link_unref);
171
172 int link_get(Manager *m, int ifindex, Link **ret);
173 int link_add(Manager *manager, sd_netlink_message *message, Link **ret);
174 void link_drop(Link *link);
175
176 int link_down(Link *link, link_netlink_message_handler_t callback);
177
178 void link_enter_failed(Link *link);
179 int link_initialized(Link *link, sd_device *device);
180
181 void link_set_state(Link *link, LinkState state);
182 void link_check_ready(Link *link);
183
184 void link_update_operstate(Link *link, bool also_update_bond_master);
185 int link_update(Link *link, sd_netlink_message *message);
186
187 void link_dirty(Link *link);
188 void link_clean(Link *link);
189 int link_save(Link *link);
190
191 int link_carrier_reset(Link *link);
192 bool link_has_carrier(Link *link);
193
194 int link_ipv6ll_gained(Link *link, const struct in6_addr *address);
195
196 int link_set_mtu(Link *link, uint32_t mtu);
197
198 bool link_ipv4ll_enabled(Link *link, AddressFamily mask);
199
200 int link_stop_clients(Link *link, bool may_keep_dhcp);
201
202 const char* link_state_to_string(LinkState s) _const_;
203 LinkState link_state_from_string(const char *s) _pure_;
204
205 uint32_t link_get_vrf_table(Link *link);
206 uint32_t link_get_dhcp_route_table(Link *link);
207 uint32_t link_get_ipv6_accept_ra_route_table(Link *link);
208 int link_request_set_routes(Link *link);
209 int link_request_set_nexthop(Link *link);
210
211 int link_reconfigure(Link *link);
212
213 #define ADDRESS_FMT_VAL(address) \
214 be32toh((address).s_addr) >> 24, \
215 (be32toh((address).s_addr) >> 16) & 0xFFu, \
216 (be32toh((address).s_addr) >> 8) & 0xFFu, \
217 be32toh((address).s_addr) & 0xFFu