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