]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/network/networkd-link.h
network: read driver name from ethtool
[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 enum LinkIPv6AddressGenMode {
39 LINK_IPV6_ADDRESSS_GEN_MODE_EUI64 = IN6_ADDR_GEN_MODE_EUI64,
40 LINK_IPV6_ADDRESSS_GEN_MODE_NONE = IN6_ADDR_GEN_MODE_NONE,
41 LINK_IPV6_ADDRESSS_GEN_MODE_STABLE_PRIVACY = IN6_ADDR_GEN_MODE_STABLE_PRIVACY,
42 LINK_IPV6_ADDRESSS_GEN_MODE_RANDOM = IN6_ADDR_GEN_MODE_RANDOM,
43 _LINK_IPV6_ADDRESS_GEN_MODE_MAX,
44 _LINK_IPV6_ADDRESS_GEN_MODE_INVALID = -1
45 } LinkIPv6AddressGenMode;
46
47 typedef struct Manager Manager;
48 typedef struct Network Network;
49 typedef struct Address Address;
50 typedef struct DUID DUID;
51
52 typedef struct Link {
53 Manager *manager;
54
55 unsigned n_ref;
56
57 int ifindex;
58 int master_ifindex;
59 char *ifname;
60 char **alternative_names;
61 char *kind;
62 unsigned short iftype;
63 char *state_file;
64 struct ether_addr mac;
65 struct ether_addr permanent_mac;
66 struct in6_addr ipv6ll_address;
67 uint32_t mtu;
68 sd_device *sd_device;
69 char *driver;
70
71 /* wlan */
72 enum nl80211_iftype wlan_iftype;
73 char *ssid;
74 struct ether_addr bssid;
75
76 unsigned flags;
77 uint8_t kernel_operstate;
78
79 Network *network;
80
81 LinkState state;
82 LinkOperationalState operstate;
83 LinkCarrierState carrier_state;
84 LinkAddressState address_state;
85
86 unsigned address_messages;
87 unsigned address_label_messages;
88 unsigned neighbor_messages;
89 unsigned route_messages;
90 unsigned nexthop_messages;
91 unsigned routing_policy_rule_messages;
92 unsigned routing_policy_rule_remove_messages;
93 unsigned tc_messages;
94 unsigned enslaving;
95
96 Set *addresses;
97 Set *addresses_foreign;
98 Set *neighbors;
99 Set *neighbors_foreign;
100 Set *routes;
101 Set *routes_foreign;
102 Set *nexthops;
103 Set *nexthops_foreign;
104
105 sd_dhcp_client *dhcp_client;
106 sd_dhcp_lease *dhcp_lease, *dhcp_lease_old;
107 Set *dhcp_routes;
108 char *lease_file;
109 uint32_t original_mtu;
110 unsigned dhcp4_messages;
111 bool dhcp4_route_failed:1;
112 bool dhcp4_route_retrying:1;
113 bool dhcp4_configured:1;
114 bool dhcp6_configured:1;
115
116 unsigned ndisc_messages;
117 bool ndisc_configured;
118
119 sd_ipv4ll *ipv4ll;
120 bool ipv4ll_address:1;
121
122 bool addresses_configured:1;
123 bool addresses_ready:1;
124 bool neighbors_configured:1;
125 bool static_routes_configured:1;
126 bool static_routes_ready:1;
127 bool static_nexthops_configured:1;
128 bool routing_policy_rules_configured:1;
129 bool tc_configured:1;
130 bool setting_mtu:1;
131 bool setting_genmode:1;
132 bool ipv6_mtu_set:1;
133
134 LIST_HEAD(Address, pool_addresses);
135
136 sd_dhcp_server *dhcp_server;
137
138 sd_ndisc *ndisc;
139 Set *ndisc_rdnss;
140 Set *ndisc_dnssl;
141
142 sd_radv *radv;
143
144 sd_dhcp6_client *dhcp6_client;
145
146 /* This is about LLDP reception */
147 sd_lldp *lldp;
148 char *lldp_file;
149
150 /* This is about LLDP transmission */
151 unsigned lldp_tx_fast; /* The LLDP txFast counter (See 802.1ab-2009, section 9.2.5.18) */
152 sd_event_source *lldp_emit_event_source;
153
154 Hashmap *bound_by_links;
155 Hashmap *bound_to_links;
156 Set *slaves;
157
158 /* For speed meter */
159 struct rtnl_link_stats64 stats_old, stats_new;
160 bool stats_updated;
161
162 /* All kinds of DNS configuration */
163 struct in_addr_data *dns;
164 unsigned n_dns;
165 OrderedSet *search_domains, *route_domains;
166
167 int dns_default_route;
168 ResolveSupport llmnr;
169 ResolveSupport mdns;
170 DnssecMode dnssec_mode;
171 DnsOverTlsMode dns_over_tls_mode;
172 Set *dnssec_negative_trust_anchors;
173
174 char **ntp;
175 } Link;
176
177 typedef int (*link_netlink_message_handler_t)(sd_netlink*, sd_netlink_message*, Link*);
178
179 DUID *link_get_duid(Link *link);
180 int get_product_uuid_handler(sd_bus_message *m, void *userdata, sd_bus_error *ret_error);
181
182 void link_ntp_settings_clear(Link *link);
183 void link_dns_settings_clear(Link *link);
184 Link *link_unref(Link *link);
185 Link *link_ref(Link *link);
186 DEFINE_TRIVIAL_CLEANUP_FUNC(Link*, link_unref);
187 DEFINE_TRIVIAL_DESTRUCTOR(link_netlink_destroy_callback, Link, link_unref);
188
189 int link_get(Manager *m, int ifindex, Link **ret);
190 int link_add(Manager *manager, sd_netlink_message *message, Link **ret);
191 void link_drop(Link *link);
192
193 int link_down(Link *link, link_netlink_message_handler_t callback);
194
195 void link_enter_failed(Link *link);
196 int link_initialized(Link *link, sd_device *device);
197
198 void link_set_state(Link *link, LinkState state);
199 void link_check_ready(Link *link);
200
201 void link_update_operstate(Link *link, bool also_update_bond_master);
202 int link_update(Link *link, sd_netlink_message *message);
203
204 void link_dirty(Link *link);
205 void link_clean(Link *link);
206 int link_save(Link *link);
207
208 int link_carrier_reset(Link *link);
209 bool link_has_carrier(Link *link);
210
211 int link_ipv6ll_gained(Link *link, const struct in6_addr *address);
212
213 int link_set_mtu(Link *link, uint32_t mtu);
214
215 bool link_ipv4ll_enabled(Link *link, AddressFamily mask);
216
217 int link_stop_clients(Link *link, bool may_keep_dhcp);
218
219 const char* link_state_to_string(LinkState s) _const_;
220 LinkState link_state_from_string(const char *s) _pure_;
221
222 const char* link_ipv6_address_gen_mode_to_string(LinkIPv6AddressGenMode s) _const_;
223 LinkIPv6AddressGenMode link_ipv6_address_gen_mode_from_string(const char *s) _pure_;
224
225 uint32_t link_get_vrf_table(Link *link);
226 uint32_t link_get_dhcp_route_table(Link *link);
227 uint32_t link_get_ipv6_accept_ra_route_table(Link *link);
228 int link_request_set_routes(Link *link);
229 int link_request_set_nexthop(Link *link);
230
231 int link_reconfigure(Link *link, bool force);
232 int address_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link);
233
234 CONFIG_PARSER_PROTOTYPE(config_parse_link_ipv6_address_gen_mode);
235
236 int log_link_message_full_errno(Link *link, sd_netlink_message *m, int level, int err, const char *msg);
237 #define log_link_message_error_errno(link, m, err, msg) log_link_message_full_errno(link, m, LOG_ERR, err, msg)
238 #define log_link_message_warning_errno(link, m, err, msg) log_link_message_full_errno(link, m, LOG_WARNING, err, msg)
239 #define log_link_message_notice_errno(link, m, err, msg) log_link_message_full_errno(link, m, LOG_NOTICE, err, msg)
240 #define log_link_message_info_errno(link, m, err, msg) log_link_message_full_errno(link, m, LOG_INFO, err, msg)
241 #define log_link_message_debug_errno(link, m, err, msg) log_link_message_full_errno(link, m, LOG_DEBUG, err, msg)
242
243 #define ADDRESS_FMT_VAL(address) \
244 be32toh((address).s_addr) >> 24, \
245 (be32toh((address).s_addr) >> 16) & 0xFFu, \
246 (be32toh((address).s_addr) >> 8) & 0xFFu, \
247 be32toh((address).s_addr) & 0xFFu