]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/network/networkd-link.h
network: introduce link_request_to_set_master()
[thirdparty/systemd.git] / src / network / networkd-link.h
CommitLineData
db9ecf05 1/* SPDX-License-Identifier: LGPL-2.1-or-later */
fc2f9534
LP
2#pragma once
3
80431934 4#include <endian.h>
78404d22 5#include <linux/nl80211.h>
80431934 6
634f0f98 7#include "sd-bus.h"
51517f9e 8#include "sd-device.h"
fc2f9534
LP
9#include "sd-dhcp-client.h"
10#include "sd-dhcp-server.h"
fc2f9534 11#include "sd-dhcp6-client.h"
10fa21c0 12#include "sd-ipv4acd.h"
07630cea 13#include "sd-ipv4ll.h"
fc2f9534 14#include "sd-lldp.h"
07630cea 15#include "sd-ndisc.h"
9d5d0090 16#include "sd-radv.h"
634f0f98 17#include "sd-netlink.h"
fc2f9534 18
b8162cd2 19#include "ether-addr-util.h"
e67ae9f5 20#include "log-link.h"
2cd6b932 21#include "network-util.h"
910feb78 22#include "networkd-util.h"
15761549
YW
23#include "ordered-set.h"
24#include "resolve-util.h"
634f0f98 25#include "set.h"
0b1831c2
TG
26
27typedef enum LinkState {
bd08ce56
YW
28 LINK_STATE_PENDING, /* udev has not initialized the link */
29 LINK_STATE_INITIALIZED, /* udev has initialized the link */
30 LINK_STATE_CONFIGURING, /* configuring addresses, routes, etc. */
31 LINK_STATE_CONFIGURED, /* everything is configured */
32 LINK_STATE_UNMANAGED, /* Unmanaged=yes is set */
33 LINK_STATE_FAILED, /* at least one configuration process failed */
34 LINK_STATE_LINGER, /* RTM_DELLINK for the link has been received */
0b1831c2 35 _LINK_STATE_MAX,
2d93c20e 36 _LINK_STATE_INVALID = -EINVAL,
0b1831c2
TG
37} LinkState;
38
634f0f98
ZJS
39typedef struct Manager Manager;
40typedef struct Network Network;
41typedef struct Address Address;
f24648a6 42typedef struct DUID DUID;
fc2f9534 43
634f0f98 44typedef struct Link {
0b1831c2
TG
45 Manager *manager;
46
cf4b2f99 47 unsigned n_ref;
0b1831c2
TG
48
49 int ifindex;
cbff7170 50 int master_ifindex;
0b1831c2 51 char *ifname;
572b21d9 52 char **alternative_names;
6cad256d 53 char *kind;
b710e6b6 54 unsigned short iftype;
0b1831c2 55 char *state_file;
b8162cd2 56 hw_addr_data hw_addr;
14b66dbc 57 hw_addr_data bcast_addr;
4bb7cc82 58 struct ether_addr permanent_mac;
c601ebf7 59 struct in6_addr ipv6ll_address;
0b1831c2 60 uint32_t mtu;
51517f9e 61 sd_device *sd_device;
c643bda5 62 char *driver;
0b1831c2 63
8d968fdd 64 /* wlan */
78404d22 65 enum nl80211_iftype wlan_iftype;
8d968fdd 66 char *ssid;
0894cfe4 67 struct ether_addr bssid;
8d968fdd 68
0b1831c2
TG
69 unsigned flags;
70 uint8_t kernel_operstate;
71
72 Network *network;
73
74 LinkState state;
75 LinkOperationalState operstate;
1678fbb3
YW
76 LinkCarrierState carrier_state;
77 LinkAddressState address_state;
8430841b
L
78 LinkAddressState ipv4_address_state;
79 LinkAddressState ipv6_address_state;
bcdcc596 80 LinkOnlineState online_state;
0b1831c2 81
76c5a0f2 82 unsigned static_address_messages;
354bc760 83 unsigned static_address_label_messages;
e5b35bf6 84 unsigned static_bridge_fdb_messages;
ff9e0783 85 unsigned static_bridge_mdb_messages;
fdeba3f5 86 unsigned static_ipv6_proxy_ndp_messages;
40ca350e 87 unsigned static_neighbor_messages;
76c5a0f2
YW
88 unsigned static_nexthop_messages;
89 unsigned static_route_messages;
0e5ef6be 90 unsigned static_routing_policy_rule_messages;
76c5a0f2 91 unsigned address_remove_messages;
40ca350e 92 unsigned neighbor_remove_messages;
76c5a0f2
YW
93 unsigned nexthop_remove_messages;
94 unsigned route_remove_messages;
34658df2 95 unsigned tc_messages;
518cd6b5 96 unsigned sr_iov_messages;
0b1831c2 97 unsigned enslaving;
0fa8ee6c 98 unsigned set_link_messages;
0b1831c2 99
cf1d700d 100 Set *addresses;
adda1ed9 101 Set *addresses_foreign;
aa651e88 102 Set *pool_addresses;
e5526518 103 Set *static_addresses;
d1bdafd2
WKI
104 Set *neighbors;
105 Set *neighbors_foreign;
1c8e710c
TG
106 Set *routes;
107 Set *routes_foreign;
c16c7808
SS
108 Set *nexthops;
109 Set *nexthops_foreign;
c42ff3a1 110
0b1831c2 111 sd_dhcp_client *dhcp_client;
6e537f62
YW
112 sd_dhcp_lease *dhcp_lease;
113 Address *dhcp_address, *dhcp_address_old;
114 Set *dhcp_routes, *dhcp_routes_old;
0b1831c2 115 char *lease_file;
4e964aa0 116 uint32_t original_mtu;
3c9b8860 117 unsigned dhcp4_messages;
10fa21c0 118 sd_ipv4acd *dhcp_acd;
dd9b10c8
YW
119 bool dhcp4_route_failed:1;
120 bool dhcp4_route_retrying:1;
bd7e5909 121 bool dhcp4_configured:1;
153cf041 122 bool dhcp4_address_bind:1;
b22d8a00 123
0b1831c2 124 sd_ipv4ll *ipv4ll;
1c09d84e 125 bool ipv4ll_address_configured:1;
0b1831c2 126
76c5a0f2 127 bool static_addresses_configured:1;
354bc760 128 bool static_address_labels_configured:1;
e5b35bf6 129 bool static_bridge_fdb_configured:1;
ff9e0783 130 bool static_bridge_mdb_configured:1;
fdeba3f5 131 bool static_ipv6_proxy_ndp_configured:1;
40ca350e 132 bool static_neighbors_configured:1;
c16c7808 133 bool static_nexthops_configured:1;
76c5a0f2 134 bool static_routes_configured:1;
0e5ef6be 135 bool static_routing_policy_rules_configured:1;
34658df2 136 bool tc_configured:1;
518cd6b5 137 bool sr_iov_configured:1;
600b7898 138 bool can_configured:1;
61135582 139 bool activated:1;
0fa8ee6c 140 bool entering_to_join_netdev:1;
3c9b8860 141
0b1831c2
TG
142 sd_dhcp_server *dhcp_server;
143
1e7a0e21
LP
144 sd_ndisc *ndisc;
145 Set *ndisc_rdnss;
146 Set *ndisc_dnssl;
50550722
YW
147 Set *ndisc_addresses;
148 Set *ndisc_routes;
1633c457
YW
149 unsigned ndisc_addresses_messages;
150 unsigned ndisc_routes_messages;
151 bool ndisc_addresses_configured:1;
152 bool ndisc_routes_configured:1;
1e7a0e21 153
091214b6
PF
154 sd_radv *radv;
155
0b1831c2 156 sd_dhcp6_client *dhcp6_client;
1633c457
YW
157 sd_dhcp6_lease *dhcp6_lease;
158 Set *dhcp6_addresses, *dhcp6_addresses_old;
159 Set *dhcp6_routes, *dhcp6_routes_old;
4b409e85 160 Set *dhcp6_pd_prefixes;
1633c457
YW
161 Set *dhcp6_pd_addresses, *dhcp6_pd_addresses_old;
162 Set *dhcp6_pd_routes, *dhcp6_pd_routes_old;
163 unsigned dhcp6_address_messages;
164 unsigned dhcp6_route_messages;
165 unsigned dhcp6_pd_address_messages;
166 unsigned dhcp6_pd_route_messages;
167 bool dhcp6_address_configured:1;
168 bool dhcp6_route_configured:1;
169 bool dhcp6_pd_address_configured:1;
170 bool dhcp6_pd_route_configured:1;
171 bool dhcp6_pd_prefixes_assigned:1;
ce43e484 172
8e1ad1ea 173 /* This is about LLDP reception */
ce43e484 174 sd_lldp *lldp;
49699bac 175 char *lldp_file;
0d4ad91d 176
8e1ad1ea
LP
177 /* This is about LLDP transmission */
178 unsigned lldp_tx_fast; /* The LLDP txFast counter (See 802.1ab-2009, section 9.2.5.18) */
7272b25e 179 sd_event_source *lldp_emit_event_source;
8e1ad1ea 180
0d4ad91d
AR
181 Hashmap *bound_by_links;
182 Hashmap *bound_to_links;
5f707e12 183 Set *slaves;
a879e1a4
YW
184
185 /* For speed meter */
186 struct rtnl_link_stats64 stats_old, stats_new;
187 bool stats_updated;
bafa9641 188
2a71d57f 189 /* All kinds of DNS configuration the user configured via D-Bus */
e77bd3fd 190 struct in_addr_full **dns;
15761549
YW
191 unsigned n_dns;
192 OrderedSet *search_domains, *route_domains;
193
194 int dns_default_route;
195 ResolveSupport llmnr;
196 ResolveSupport mdns;
197 DnssecMode dnssec_mode;
198 DnsOverTlsMode dns_over_tls_mode;
199 Set *dnssec_negative_trust_anchors;
200
2a71d57f 201 /* Similar, but NTP server configuration */
15761549 202 char **ntp;
634f0f98 203} Link;
0b1831c2 204
302a796f
YW
205typedef int (*link_netlink_message_handler_t)(sd_netlink*, sd_netlink_message*, Link*);
206
7191a57a
YW
207bool link_is_ready_to_configure(Link *link, bool allow_unmanaged);
208
15761549
YW
209void link_ntp_settings_clear(Link *link);
210void link_dns_settings_clear(Link *link);
0b1831c2
TG
211Link *link_unref(Link *link);
212Link *link_ref(Link *link);
2c448c8a 213DEFINE_TRIVIAL_CLEANUP_FUNC(Link*, link_unref);
302a796f 214DEFINE_TRIVIAL_DESTRUCTOR(link_netlink_destroy_callback, Link, link_unref);
1046bf9b 215
0b1831c2 216int link_get(Manager *m, int ifindex, Link **ret);
0b54c870 217int link_get_by_name(Manager *m, const char *ifname, Link **ret);
0b1831c2 218
f282ce20 219int link_up(Link *link);
8e54db83 220int link_down(Link *link, link_netlink_message_handler_t callback);
04952b25 221int link_activate(Link *link);
14b6bb77 222
0fa8ee6c 223int link_enter_join_netdev(Link *link);
b22d8a00 224void link_enter_failed(Link *link);
0b1831c2 225
af9ba57a 226void link_set_state(Link *link, LinkState state);
8012cd39 227void link_check_ready(Link *link);
b22d8a00 228
959f65d3 229void link_update_operstate(Link *link, bool also_update_bond_master);
b22d8a00 230
9c0a72f9 231int link_carrier_reset(Link *link);
a61bb41c 232bool link_has_carrier(Link *link);
0b1831c2 233
5e0534f1 234bool link_ipv6_enabled(Link *link);
f8f2f880 235bool link_ipv6ll_enabled(Link *link);
c601ebf7 236int link_ipv6ll_gained(Link *link, const struct in6_addr *address);
e7ab854c 237
3ca1fab7 238bool link_ipv4ll_enabled(Link *link);
8bc17bb3 239
2a99eed0 240int link_stop_engines(Link *link, bool may_keep_dhcp);
946f8e14 241
0b1831c2
TG
242const char* link_state_to_string(LinkState s) _const_;
243LinkState link_state_from_string(const char *s) _pure_;
244
99b8517c 245int link_reconfigure(Link *link, bool force);
ad932b15 246
3be9d62a
YW
247int manager_udev_process_link(sd_device_monitor *monitor, sd_device *device, void *userdata);
248int manager_rtnl_process_link(sd_netlink *rtnl, sd_netlink_message *message, Manager *m);