]>
Commit | Line | Data |
---|---|---|
db9ecf05 | 1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ |
fc2f9534 LP |
2 | #pragma once |
3 | ||
78404d22 | 4 | #include <linux/nl80211.h> |
80431934 | 5 | |
b8162cd2 | 6 | #include "ether-addr-util.h" |
baa3fadf | 7 | #include "forward.h" |
2cd6b932 | 8 | #include "network-util.h" |
11cee6ef | 9 | #include "networkd-bridge-vlan.h" |
baa3fadf | 10 | #include "networkd-forward.h" |
de2f372e | 11 | #include "networkd-ipv6ll.h" |
c2eb7753 | 12 | #include "ratelimit.h" |
15761549 | 13 | #include "resolve-util.h" |
0b1831c2 TG |
14 | |
15 | typedef enum LinkState { | |
bd08ce56 YW |
16 | LINK_STATE_PENDING, /* udev has not initialized the link */ |
17 | LINK_STATE_INITIALIZED, /* udev has initialized the link */ | |
18 | LINK_STATE_CONFIGURING, /* configuring addresses, routes, etc. */ | |
19 | LINK_STATE_CONFIGURED, /* everything is configured */ | |
20 | LINK_STATE_UNMANAGED, /* Unmanaged=yes is set */ | |
21 | LINK_STATE_FAILED, /* at least one configuration process failed */ | |
22 | LINK_STATE_LINGER, /* RTM_DELLINK for the link has been received */ | |
0b1831c2 | 23 | _LINK_STATE_MAX, |
2d93c20e | 24 | _LINK_STATE_INVALID = -EINVAL, |
0b1831c2 TG |
25 | } LinkState; |
26 | ||
2b07a321 YW |
27 | typedef enum LinkReconfigurationFlag { |
28 | LINK_RECONFIGURE_UNCONDITIONALLY = 1 << 0, /* Reconfigure an interface even if .network file is unchanged. */ | |
6e0c9b7d | 29 | LINK_RECONFIGURE_CLEANLY = 1 << 1, /* Drop all existing configs before reconfiguring. Otherwise, reuse existing configs as possible as we can. */ |
2b07a321 YW |
30 | } LinkReconfigurationFlag; |
31 | ||
634f0f98 | 32 | typedef struct Link { |
0b1831c2 TG |
33 | Manager *manager; |
34 | ||
cf4b2f99 | 35 | unsigned n_ref; |
0b1831c2 TG |
36 | |
37 | int ifindex; | |
cbff7170 | 38 | int master_ifindex; |
b1d9c504 | 39 | int dsa_master_ifindex; |
b0ff6dea YW |
40 | int sr_iov_phys_port_ifindex; |
41 | Set *sr_iov_virt_port_ifindices; | |
42 | ||
0b1831c2 | 43 | char *ifname; |
572b21d9 | 44 | char **alternative_names; |
6cad256d | 45 | char *kind; |
b710e6b6 | 46 | unsigned short iftype; |
0b1831c2 | 47 | char *state_file; |
ca2b7cd8 YW |
48 | struct hw_addr_data hw_addr; |
49 | struct hw_addr_data bcast_addr; | |
ed9fa69f | 50 | struct hw_addr_data permanent_hw_addr; |
a8840714 | 51 | struct hw_addr_data requested_hw_addr; |
c601ebf7 | 52 | struct in6_addr ipv6ll_address; |
0b1831c2 | 53 | uint32_t mtu; |
717ba5fc YW |
54 | uint32_t min_mtu; |
55 | uint32_t max_mtu; | |
56 | uint32_t original_mtu; | |
8de56fb3 | 57 | sd_device *dev; |
c643bda5 | 58 | char *driver; |
0b1831c2 | 59 | |
39283a1f YW |
60 | sd_event_source *ipv6_mtu_wait_synced_event_source; |
61 | unsigned ipv6_mtu_wait_trial_count; | |
62 | ||
11cee6ef YW |
63 | /* bridge vlan */ |
64 | uint16_t bridge_vlan_pvid; | |
65 | bool bridge_vlan_pvid_is_untagged; | |
66 | uint32_t bridge_vlan_bitmap[BRIDGE_VLAN_BITMAP_LEN]; | |
67 | ||
6625c39e YW |
68 | /* to prevent multiple ethtool calls */ |
69 | bool ethtool_driver_read; | |
70 | bool ethtool_permanent_hw_addr_read; | |
71 | ||
f81ac115 | 72 | /* link-local addressing */ |
7d0d832d YW |
73 | IPv6LinkLocalAddressGenMode ipv6ll_address_gen_mode; |
74 | ||
8d968fdd | 75 | /* wlan */ |
78404d22 | 76 | enum nl80211_iftype wlan_iftype; |
8d968fdd | 77 | char *ssid; |
6706ce2f | 78 | char *previous_ssid; |
0894cfe4 | 79 | struct ether_addr bssid; |
8d968fdd | 80 | |
0b1831c2 TG |
81 | unsigned flags; |
82 | uint8_t kernel_operstate; | |
83 | ||
6706ce2f YW |
84 | sd_event_source *carrier_lost_timer; |
85 | ||
0b1831c2 | 86 | Network *network; |
9aa2585e | 87 | NetDev *netdev; |
0b1831c2 TG |
88 | |
89 | LinkState state; | |
90 | LinkOperationalState operstate; | |
1678fbb3 YW |
91 | LinkCarrierState carrier_state; |
92 | LinkAddressState address_state; | |
8430841b L |
93 | LinkAddressState ipv4_address_state; |
94 | LinkAddressState ipv6_address_state; | |
bcdcc596 | 95 | LinkOnlineState online_state; |
c2eb7753 | 96 | RateLimit automatic_reconfigure_ratelimit; |
0b1831c2 | 97 | |
76c5a0f2 | 98 | unsigned static_address_messages; |
354bc760 | 99 | unsigned static_address_label_messages; |
e5b35bf6 | 100 | unsigned static_bridge_fdb_messages; |
ff9e0783 | 101 | unsigned static_bridge_mdb_messages; |
fdeba3f5 | 102 | unsigned static_ipv6_proxy_ndp_messages; |
40ca350e | 103 | unsigned static_neighbor_messages; |
76c5a0f2 YW |
104 | unsigned static_nexthop_messages; |
105 | unsigned static_route_messages; | |
0e5ef6be | 106 | unsigned static_routing_policy_rule_messages; |
34658df2 | 107 | unsigned tc_messages; |
518cd6b5 | 108 | unsigned sr_iov_messages; |
0fa8ee6c | 109 | unsigned set_link_messages; |
baa95d22 | 110 | unsigned set_flags_messages; |
71a754f7 | 111 | unsigned create_stacked_netdev_messages; |
0b1831c2 | 112 | |
cf1d700d | 113 | Set *addresses; |
d1bdafd2 | 114 | Set *neighbors; |
3a67b8bb YW |
115 | Set *qdiscs; |
116 | Set *tclasses; | |
c42ff3a1 | 117 | |
0b1831c2 | 118 | sd_dhcp_client *dhcp_client; |
6e537f62 | 119 | sd_dhcp_lease *dhcp_lease; |
0b1831c2 | 120 | char *lease_file; |
3c9b8860 | 121 | unsigned dhcp4_messages; |
706cd859 | 122 | bool dhcp4_configured; |
e49bad01 | 123 | char *dhcp4_6rd_tunnel_name; |
b22d8a00 | 124 | |
5385e5f9 YW |
125 | Hashmap *ipv4acd_by_address; |
126 | ||
0b1831c2 | 127 | sd_ipv4ll *ipv4ll; |
1c09d84e | 128 | bool ipv4ll_address_configured:1; |
0b1831c2 | 129 | |
76c5a0f2 | 130 | bool static_addresses_configured:1; |
354bc760 | 131 | bool static_address_labels_configured:1; |
e5b35bf6 | 132 | bool static_bridge_fdb_configured:1; |
ff9e0783 | 133 | bool static_bridge_mdb_configured:1; |
fdeba3f5 | 134 | bool static_ipv6_proxy_ndp_configured:1; |
40ca350e | 135 | bool static_neighbors_configured:1; |
c16c7808 | 136 | bool static_nexthops_configured:1; |
76c5a0f2 | 137 | bool static_routes_configured:1; |
0e5ef6be | 138 | bool static_routing_policy_rules_configured:1; |
34658df2 | 139 | bool tc_configured:1; |
518cd6b5 | 140 | bool sr_iov_configured:1; |
61135582 | 141 | bool activated:1; |
440d40dc | 142 | bool master_set:1; |
71a754f7 | 143 | bool stacked_netdevs_created:1; |
228693af | 144 | bool bridge_vlan_set:1; |
3c9b8860 | 145 | |
0b1831c2 TG |
146 | sd_dhcp_server *dhcp_server; |
147 | ||
1e7a0e21 | 148 | sd_ndisc *ndisc; |
77302468 | 149 | sd_event_source *ndisc_expire; |
01420b2d | 150 | Hashmap *ndisc_routers_by_sender; |
1e7a0e21 LP |
151 | Set *ndisc_rdnss; |
152 | Set *ndisc_dnssl; | |
64de00c4 | 153 | Set *ndisc_captive_portals; |
6e8f5e4c | 154 | Set *ndisc_pref64; |
6df00594 | 155 | Set *ndisc_redirects; |
0c90d1d2 | 156 | Set *ndisc_dnr; |
8c9ef90b | 157 | uint32_t ndisc_mtu; |
3b6a3bde | 158 | unsigned ndisc_messages; |
525a582a | 159 | bool ndisc_configured; |
1e7a0e21 | 160 | |
091214b6 PF |
161 | sd_radv *radv; |
162 | ||
0b1831c2 | 163 | sd_dhcp6_client *dhcp6_client; |
1633c457 | 164 | sd_dhcp6_lease *dhcp6_lease; |
3b6a3bde | 165 | unsigned dhcp6_messages; |
a27588d4 YW |
166 | bool dhcp6_configured; |
167 | ||
168 | Set *dhcp_pd_prefixes; | |
169 | unsigned dhcp_pd_messages; | |
170 | bool dhcp_pd_configured; | |
ce43e484 | 171 | |
8e1ad1ea | 172 | /* This is about LLDP reception */ |
35778343 | 173 | sd_lldp_rx *lldp_rx; |
0d4ad91d | 174 | |
8e1ad1ea | 175 | /* This is about LLDP transmission */ |
c01b9b87 | 176 | sd_lldp_tx *lldp_tx; |
8e1ad1ea | 177 | |
0d4ad91d AR |
178 | Hashmap *bound_by_links; |
179 | Hashmap *bound_to_links; | |
5f707e12 | 180 | Set *slaves; |
a879e1a4 YW |
181 | |
182 | /* For speed meter */ | |
183 | struct rtnl_link_stats64 stats_old, stats_new; | |
184 | bool stats_updated; | |
bafa9641 | 185 | |
2a71d57f | 186 | /* All kinds of DNS configuration the user configured via D-Bus */ |
e77bd3fd | 187 | struct in_addr_full **dns; |
15761549 YW |
188 | unsigned n_dns; |
189 | OrderedSet *search_domains, *route_domains; | |
190 | ||
191 | int dns_default_route; | |
192 | ResolveSupport llmnr; | |
193 | ResolveSupport mdns; | |
194 | DnssecMode dnssec_mode; | |
195 | DnsOverTlsMode dns_over_tls_mode; | |
196 | Set *dnssec_negative_trust_anchors; | |
197 | ||
2a71d57f | 198 | /* Similar, but NTP server configuration */ |
15761549 | 199 | char **ntp; |
634f0f98 | 200 | } Link; |
0b1831c2 | 201 | |
4cf443e6 YW |
202 | extern const struct hash_ops link_hash_ops; |
203 | ||
302a796f YW |
204 | typedef int (*link_netlink_message_handler_t)(sd_netlink*, sd_netlink_message*, Link*); |
205 | ||
7191a57a | 206 | bool link_is_ready_to_configure(Link *link, bool allow_unmanaged); |
5078e366 | 207 | bool link_is_ready_to_configure_by_name(Manager *manager, const char *name, bool allow_unmanaged); |
7191a57a | 208 | |
15761549 YW |
209 | void link_ntp_settings_clear(Link *link); |
210 | void link_dns_settings_clear(Link *link); | |
525c53a9 YW |
211 | Link* link_unref(Link *link); |
212 | Link* link_ref(Link *link); | |
2c448c8a | 213 | DEFINE_TRIVIAL_CLEANUP_FUNC(Link*, link_unref); |
302a796f | 214 | DEFINE_TRIVIAL_DESTRUCTOR(link_netlink_destroy_callback, Link, link_unref); |
1046bf9b | 215 | |
6eab614d | 216 | int link_get_by_index(Manager *m, int ifindex, Link **ret); |
0b54c870 | 217 | int link_get_by_name(Manager *m, const char *ifname, Link **ret); |
fe321d45 | 218 | int link_get_by_hw_addr(Manager *m, const struct hw_addr_data *hw_addr, Link **ret); |
81357285 | 219 | int link_get_master(Link *link, Link **ret); |
0b1831c2 | 220 | |
79c6e114 YW |
221 | int link_getlink_handler_internal(sd_netlink *rtnl, sd_netlink_message *m, Link *link, const char *error_msg); |
222 | int link_call_getlink(Link *link, link_netlink_message_handler_t callback); | |
112a0972 | 223 | int link_handle_bound_to_list(Link *link); |
14b6bb77 | 224 | |
b22d8a00 | 225 | void link_enter_failed(Link *link); |
af9ba57a | 226 | void link_set_state(Link *link, LinkState state); |
8012cd39 | 227 | void link_check_ready(Link *link); |
b22d8a00 | 228 | |
959f65d3 | 229 | void link_update_operstate(Link *link, bool also_update_bond_master); |
b22d8a00 | 230 | |
baa3fadf | 231 | bool link_has_carrier(Link *link); |
0b1831c2 | 232 | |
5e0534f1 | 233 | bool link_ipv6_enabled(Link *link); |
7657ec3e | 234 | int link_ipv6ll_gained(Link *link); |
fc35a9f8 | 235 | bool link_has_ipv6_connectivity(Link *link); |
e7ab854c | 236 | |
80a89d1a | 237 | int link_stop_engines(Link *link, bool may_keep_dynamic); |
946f8e14 | 238 | |
0b1831c2 TG |
239 | const char* link_state_to_string(LinkState s) _const_; |
240 | LinkState link_state_from_string(const char *s) _pure_; | |
241 | ||
b8b0c1a0 YW |
242 | int link_request_stacked_netdevs(Link *link, NetDevLocalAddressType type); |
243 | ||
2b07a321 YW |
244 | int link_reconfigure_impl(Link *link, LinkReconfigurationFlag flags); |
245 | int link_reconfigure_full(Link *link, LinkReconfigurationFlag flags, sd_bus_message *message, unsigned *counter); | |
246 | static inline int link_reconfigure(Link *link, LinkReconfigurationFlag flags) { | |
247 | return link_reconfigure_full(link, flags, NULL, NULL); | |
248 | } | |
ad932b15 | 249 | |
9c402e3a YW |
250 | int link_check_initialized(Link *link); |
251 | ||
1fd3ac1e | 252 | int manager_udev_process_link(Manager *m, sd_device *device, sd_device_action_t action); |
3be9d62a | 253 | int manager_rtnl_process_link(sd_netlink *rtnl, sd_netlink_message *message, Manager *m); |
7ae55b78 YW |
254 | |
255 | int link_flags_to_string_alloc(uint32_t flags, char **ret); | |
bfd5a068 | 256 | const char* kernel_operstate_to_string(int t) _const_; |
2278d9f6 YW |
257 | |
258 | void link_required_operstate_for_online(Link *link, LinkOperationalStateRange *ret); | |
a853cc99 | 259 | AddressFamily link_required_family_for_online(Link *link); |