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