]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/network/networkd-link.h
Merge pull request #23893 from yuwata/core-mount-re-read-mountinfo
[thirdparty/systemd.git] / src / network / networkd-link.h
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
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-ipv4acd.h"
13 #include "sd-ipv4ll.h"
14 #include "sd-lldp-rx.h"
15 #include "sd-lldp-tx.h"
16 #include "sd-ndisc.h"
17 #include "sd-radv.h"
18 #include "sd-netlink.h"
19
20 #include "ether-addr-util.h"
21 #include "log-link.h"
22 #include "netif-util.h"
23 #include "network-util.h"
24 #include "networkd-ipv6ll.h"
25 #include "networkd-util.h"
26 #include "ordered-set.h"
27 #include "resolve-util.h"
28 #include "set.h"
29
30 typedef enum LinkState {
31 LINK_STATE_PENDING, /* udev has not initialized the link */
32 LINK_STATE_INITIALIZED, /* udev has initialized the link */
33 LINK_STATE_CONFIGURING, /* configuring addresses, routes, etc. */
34 LINK_STATE_CONFIGURED, /* everything is configured */
35 LINK_STATE_UNMANAGED, /* Unmanaged=yes is set */
36 LINK_STATE_FAILED, /* at least one configuration process failed */
37 LINK_STATE_LINGER, /* RTM_DELLINK for the link has been received */
38 _LINK_STATE_MAX,
39 _LINK_STATE_INVALID = -EINVAL,
40 } LinkState;
41
42 typedef struct Manager Manager;
43 typedef struct Network Network;
44 typedef struct NetDev NetDev;
45 typedef struct DUID DUID;
46
47 typedef struct Link {
48 Manager *manager;
49
50 unsigned n_ref;
51
52 int ifindex;
53 int master_ifindex;
54 int dsa_master_ifindex;
55 int sr_iov_phys_port_ifindex;
56 Set *sr_iov_virt_port_ifindices;
57
58 char *ifname;
59 char **alternative_names;
60 char *kind;
61 unsigned short iftype;
62 char *state_file;
63 struct hw_addr_data hw_addr;
64 struct hw_addr_data bcast_addr;
65 struct hw_addr_data permanent_hw_addr;
66 struct hw_addr_data requested_hw_addr;
67 struct in6_addr ipv6ll_address;
68 uint32_t mtu;
69 uint32_t min_mtu;
70 uint32_t max_mtu;
71 uint32_t original_mtu;
72 sd_device *dev;
73 char *driver;
74
75 /* link-local addressing */
76 IPv6LinkLocalAddressGenMode ipv6ll_address_gen_mode;
77
78 /* wlan */
79 enum nl80211_iftype wlan_iftype;
80 char *ssid;
81 char *previous_ssid;
82 struct ether_addr bssid;
83
84 unsigned flags;
85 uint8_t kernel_operstate;
86
87 sd_event_source *carrier_lost_timer;
88
89 Network *network;
90 NetDev *netdev;
91
92 LinkState state;
93 LinkOperationalState operstate;
94 LinkCarrierState carrier_state;
95 LinkAddressState address_state;
96 LinkAddressState ipv4_address_state;
97 LinkAddressState ipv6_address_state;
98 LinkOnlineState online_state;
99
100 unsigned static_address_messages;
101 unsigned static_address_label_messages;
102 unsigned static_bridge_fdb_messages;
103 unsigned static_bridge_mdb_messages;
104 unsigned static_ipv6_proxy_ndp_messages;
105 unsigned static_neighbor_messages;
106 unsigned static_nexthop_messages;
107 unsigned static_route_messages;
108 unsigned static_routing_policy_rule_messages;
109 unsigned tc_messages;
110 unsigned sr_iov_messages;
111 unsigned set_link_messages;
112 unsigned set_flags_messages;
113 unsigned create_stacked_netdev_messages;
114
115 Set *addresses;
116 Set *neighbors;
117 Set *routes;
118 Set *nexthops;
119 Set *qdiscs;
120 Set *tclasses;
121
122 sd_dhcp_client *dhcp_client;
123 sd_dhcp_lease *dhcp_lease;
124 char *lease_file;
125 unsigned dhcp4_messages;
126 bool dhcp4_configured:1;
127 char *dhcp4_6rd_tunnel_name;
128
129 sd_ipv4ll *ipv4ll;
130 bool ipv4ll_address_configured:1;
131
132 bool static_addresses_configured:1;
133 bool static_address_labels_configured:1;
134 bool static_bridge_fdb_configured:1;
135 bool static_bridge_mdb_configured:1;
136 bool static_ipv6_proxy_ndp_configured:1;
137 bool static_neighbors_configured:1;
138 bool static_nexthops_configured:1;
139 bool static_routes_configured:1;
140 bool static_routing_policy_rules_configured:1;
141 bool tc_configured:1;
142 bool sr_iov_configured:1;
143 bool activated:1;
144 bool master_set:1;
145 bool stacked_netdevs_created:1;
146
147 sd_dhcp_server *dhcp_server;
148
149 sd_ndisc *ndisc;
150 Set *ndisc_rdnss;
151 Set *ndisc_dnssl;
152 unsigned ndisc_messages;
153 bool ndisc_configured:1;
154
155 sd_radv *radv;
156
157 sd_dhcp6_client *dhcp6_client;
158 sd_dhcp6_lease *dhcp6_lease;
159 unsigned dhcp6_messages;
160 bool dhcp6_configured;
161
162 Set *dhcp_pd_prefixes;
163 unsigned dhcp_pd_messages;
164 bool dhcp_pd_configured;
165
166 /* This is about LLDP reception */
167 sd_lldp_rx *lldp_rx;
168 char *lldp_file;
169
170 /* This is about LLDP transmission */
171 sd_lldp_tx *lldp_tx;
172
173 Hashmap *bound_by_links;
174 Hashmap *bound_to_links;
175 Set *slaves;
176
177 /* For speed meter */
178 struct rtnl_link_stats64 stats_old, stats_new;
179 bool stats_updated;
180
181 /* All kinds of DNS configuration the user configured via D-Bus */
182 struct in_addr_full **dns;
183 unsigned n_dns;
184 OrderedSet *search_domains, *route_domains;
185
186 int dns_default_route;
187 ResolveSupport llmnr;
188 ResolveSupport mdns;
189 DnssecMode dnssec_mode;
190 DnsOverTlsMode dns_over_tls_mode;
191 Set *dnssec_negative_trust_anchors;
192
193 /* Similar, but NTP server configuration */
194 char **ntp;
195 } Link;
196
197 typedef int (*link_netlink_message_handler_t)(sd_netlink*, sd_netlink_message*, Link*);
198
199 bool link_is_ready_to_configure(Link *link, bool allow_unmanaged);
200
201 void link_ntp_settings_clear(Link *link);
202 void link_dns_settings_clear(Link *link);
203 Link *link_unref(Link *link);
204 Link *link_ref(Link *link);
205 DEFINE_TRIVIAL_CLEANUP_FUNC(Link*, link_unref);
206 DEFINE_TRIVIAL_DESTRUCTOR(link_netlink_destroy_callback, Link, link_unref);
207
208 int link_get_by_index(Manager *m, int ifindex, Link **ret);
209 int link_get_by_name(Manager *m, const char *ifname, Link **ret);
210 int link_get_by_hw_addr(Manager *m, const struct hw_addr_data *hw_addr, Link **ret);
211 int link_get_master(Link *link, Link **ret);
212
213 int link_getlink_handler_internal(sd_netlink *rtnl, sd_netlink_message *m, Link *link, const char *error_msg);
214 int link_call_getlink(Link *link, link_netlink_message_handler_t callback);
215 int link_handle_bound_to_list(Link *link);
216
217 void link_enter_failed(Link *link);
218 void link_set_state(Link *link, LinkState state);
219 void link_check_ready(Link *link);
220
221 void link_update_operstate(Link *link, bool also_update_bond_master);
222
223 static inline bool link_has_carrier(Link *link) {
224 assert(link);
225 return netif_has_carrier(link->kernel_operstate, link->flags);
226 }
227
228 bool link_ipv6_enabled(Link *link);
229 int link_ipv6ll_gained(Link *link);
230
231 int link_stop_engines(Link *link, bool may_keep_dhcp);
232
233 const char* link_state_to_string(LinkState s) _const_;
234 LinkState link_state_from_string(const char *s) _pure_;
235
236 int link_reconfigure(Link *link, bool force);
237 int link_reconfigure_after_sleep(Link *link);
238
239 int manager_udev_process_link(Manager *m, sd_device *device, sd_device_action_t action);
240 int manager_rtnl_process_link(sd_netlink *rtnl, sd_netlink_message *message, Manager *m);
241
242 int link_flags_to_string_alloc(uint32_t flags, char **ret);
243 const char *kernel_operstate_to_string(int t) _const_;