| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
#pragma once |
| 3 |
|
| 4 |
#include <linux/nl80211.h> |
| 5 |
|
| 6 |
#include "ether-addr-util.h" |
| 7 |
#include "network-util.h" |
| 8 |
#include "networkd-bridge-vlan.h" |
| 9 |
#include "networkd-forward.h" |
| 10 |
#include "networkd-ipv6ll.h" |
| 11 |
#include "ratelimit.h" |
| 12 |
#include "resolve-util.h" |
| 13 |
|
| 14 |
typedef enum LinkState { |
| 15 |
LINK_STATE_PENDING, /* udev has not initialized the link */ |
| 16 |
LINK_STATE_INITIALIZED, /* udev has initialized the link */ |
| 17 |
LINK_STATE_CONFIGURING, /* configuring addresses, routes, etc. */ |
| 18 |
LINK_STATE_CONFIGURED, /* everything is configured */ |
| 19 |
LINK_STATE_UNMANAGED, /* Unmanaged=yes is set */ |
| 20 |
LINK_STATE_FAILED, /* at least one configuration process failed */ |
| 21 |
LINK_STATE_LINGER, /* RTM_DELLINK for the link has been received */ |
| 22 |
_LINK_STATE_MAX, |
| 23 |
_LINK_STATE_INVALID = -EINVAL, |
| 24 |
} LinkState; |
| 25 |
|
| 26 |
typedef enum LinkReconfigurationFlag { |
| 27 |
LINK_RECONFIGURE_UNCONDITIONALLY = 1 << 0, /* Reconfigure an interface even if .network file is unchanged. */ |
| 28 |
LINK_RECONFIGURE_CLEANLY = 1 << 1, /* Drop all existing configs before reconfiguring. Otherwise, reuse existing configs as possible as we can. */ |
| 29 |
} LinkReconfigurationFlag; |
| 30 |
|
| 31 |
typedef struct Link { |
| 32 |
Manager *manager; |
| 33 |
|
| 34 |
unsigned n_ref; |
| 35 |
|
| 36 |
int ifindex; |
| 37 |
int master_ifindex; |
| 38 |
int dsa_master_ifindex; |
| 39 |
int sr_iov_phys_port_ifindex; |
| 40 |
Set *sr_iov_virt_port_ifindices; |
| 41 |
|
| 42 |
char *ifname; |
| 43 |
char **alternative_names; |
| 44 |
char *kind; |
| 45 |
unsigned short iftype; |
| 46 |
char *state_file; |
| 47 |
struct hw_addr_data hw_addr; |
| 48 |
struct hw_addr_data bcast_addr; |
| 49 |
struct hw_addr_data permanent_hw_addr; |
| 50 |
struct hw_addr_data requested_hw_addr; |
| 51 |
struct in6_addr ipv6ll_address; |
| 52 |
uint32_t mtu; |
| 53 |
uint32_t min_mtu; |
| 54 |
uint32_t max_mtu; |
| 55 |
uint32_t original_mtu; |
| 56 |
sd_device *dev; |
| 57 |
char *driver; |
| 58 |
|
| 59 |
sd_event_source *ipv6_mtu_wait_synced_event_source; |
| 60 |
unsigned ipv6_mtu_wait_trial_count; |
| 61 |
|
| 62 |
/* bridge vlan */ |
| 63 |
uint16_t bridge_vlan_pvid; |
| 64 |
bool bridge_vlan_pvid_is_untagged; |
| 65 |
uint32_t bridge_vlan_bitmap[BRIDGE_VLAN_BITMAP_LEN]; |
| 66 |
|
| 67 |
/* to prevent multiple ethtool calls */ |
| 68 |
bool ethtool_driver_read; |
| 69 |
bool ethtool_permanent_hw_addr_read; |
| 70 |
|
| 71 |
/* link-local addressing */ |
| 72 |
IPv6LinkLocalAddressGenMode ipv6ll_address_gen_mode; |
| 73 |
|
| 74 |
/* wlan */ |
| 75 |
enum nl80211_iftype wlan_iftype; |
| 76 |
char *ssid; |
| 77 |
char *previous_ssid; |
| 78 |
struct ether_addr bssid; |
| 79 |
|
| 80 |
unsigned flags; |
| 81 |
uint8_t kernel_operstate; |
| 82 |
|
| 83 |
sd_event_source *carrier_lost_timer; |
| 84 |
|
| 85 |
Network *network; |
| 86 |
NetDev *netdev; |
| 87 |
|
| 88 |
LinkState state; |
| 89 |
LinkOperationalState operstate; |
| 90 |
LinkCarrierState carrier_state; |
| 91 |
LinkAddressState address_state; |
| 92 |
LinkAddressState ipv4_address_state; |
| 93 |
LinkAddressState ipv6_address_state; |
| 94 |
LinkOnlineState online_state; |
| 95 |
RateLimit automatic_reconfigure_ratelimit; |
| 96 |
|
| 97 |
unsigned static_address_messages; |
| 98 |
unsigned static_address_label_messages; |
| 99 |
unsigned static_bridge_fdb_messages; |
| 100 |
unsigned static_bridge_mdb_messages; |
| 101 |
unsigned static_ipv6_proxy_ndp_messages; |
| 102 |
unsigned static_neighbor_messages; |
| 103 |
unsigned static_nexthop_messages; |
| 104 |
unsigned static_route_messages; |
| 105 |
unsigned static_routing_policy_rule_messages; |
| 106 |
unsigned tc_messages; |
| 107 |
unsigned sr_iov_messages; |
| 108 |
unsigned set_link_messages; |
| 109 |
unsigned set_flags_messages; |
| 110 |
unsigned create_stacked_netdev_messages; |
| 111 |
unsigned bearer_messages; |
| 112 |
|
| 113 |
Set *addresses; |
| 114 |
Set *neighbors; |
| 115 |
Set *qdiscs; |
| 116 |
Set *tclasses; |
| 117 |
|
| 118 |
sd_dhcp_client *dhcp_client; |
| 119 |
sd_dhcp_lease *dhcp_lease; |
| 120 |
unsigned dhcp4_messages; |
| 121 |
bool dhcp4_configured; |
| 122 |
char *dhcp4_6rd_tunnel_name; |
| 123 |
|
| 124 |
Hashmap *ipv4acd_by_address; |
| 125 |
|
| 126 |
sd_ipv4ll *ipv4ll; |
| 127 |
bool ipv4ll_address_configured:1; |
| 128 |
|
| 129 |
bool static_addresses_configured:1; |
| 130 |
bool static_address_labels_configured:1; |
| 131 |
bool static_bridge_fdb_configured:1; |
| 132 |
bool static_bridge_mdb_configured:1; |
| 133 |
bool static_ipv6_proxy_ndp_configured:1; |
| 134 |
bool static_neighbors_configured:1; |
| 135 |
bool static_nexthops_configured:1; |
| 136 |
bool static_routes_configured:1; |
| 137 |
bool static_routing_policy_rules_configured:1; |
| 138 |
bool tc_configured:1; |
| 139 |
bool sr_iov_configured:1; |
| 140 |
bool activated:1; |
| 141 |
bool master_set:1; |
| 142 |
bool stacked_netdevs_created:1; |
| 143 |
bool bridge_vlan_set:1; |
| 144 |
bool bearer_configured:1; |
| 145 |
|
| 146 |
sd_dhcp_relay_interface *dhcp_relay_interface; |
| 147 |
sd_dhcp_relay_interface *dhcp_relay_interface_compat; |
| 148 |
sd_dhcp_server *dhcp_server; |
| 149 |
|
| 150 |
sd_ndisc *ndisc; |
| 151 |
sd_event_source *ndisc_expire; |
| 152 |
Hashmap *ndisc_routers_by_sender; |
| 153 |
Set *ndisc_rdnss; |
| 154 |
Set *ndisc_dnssl; |
| 155 |
Set *ndisc_captive_portals; |
| 156 |
Set *ndisc_pref64; |
| 157 |
Set *ndisc_redirects; |
| 158 |
Set *ndisc_dnr; |
| 159 |
uint32_t ndisc_mtu; |
| 160 |
unsigned ndisc_messages; |
| 161 |
bool ndisc_configured; |
| 162 |
|
| 163 |
sd_radv *radv; |
| 164 |
|
| 165 |
sd_dhcp6_client *dhcp6_client; |
| 166 |
sd_dhcp6_lease *dhcp6_lease; |
| 167 |
unsigned dhcp6_messages; |
| 168 |
bool dhcp6_configured; |
| 169 |
|
| 170 |
Set *dhcp_pd_prefixes; |
| 171 |
unsigned dhcp_pd_messages; |
| 172 |
bool dhcp_pd_configured; |
| 173 |
|
| 174 |
/* This is about LLDP reception */ |
| 175 |
sd_lldp_rx *lldp_rx; |
| 176 |
|
| 177 |
/* This is about LLDP transmission */ |
| 178 |
sd_lldp_tx *lldp_tx; |
| 179 |
|
| 180 |
Hashmap *bound_by_links; |
| 181 |
Hashmap *bound_to_links; |
| 182 |
Set *slaves; |
| 183 |
|
| 184 |
/* For speed meter */ |
| 185 |
struct rtnl_link_stats64 stats_old, stats_new; |
| 186 |
bool stats_updated; |
| 187 |
|
| 188 |
/* All kinds of DNS configuration the user configured via D-Bus */ |
| 189 |
struct in_addr_full **dns; |
| 190 |
unsigned n_dns; |
| 191 |
OrderedSet *search_domains, *route_domains; |
| 192 |
|
| 193 |
int dns_default_route; |
| 194 |
ResolveSupport llmnr; |
| 195 |
ResolveSupport mdns; |
| 196 |
DnssecMode dnssec_mode; |
| 197 |
DnsOverTlsMode dns_over_tls_mode; |
| 198 |
Set *dnssec_negative_trust_anchors; |
| 199 |
|
| 200 |
/* Similar, but NTP server configuration */ |
| 201 |
char **ntp; |
| 202 |
} Link; |
| 203 |
|
| 204 |
extern const struct hash_ops link_hash_ops; |
| 205 |
|
| 206 |
typedef int (*link_netlink_message_handler_t)(sd_netlink*, sd_netlink_message*, Link*); |
| 207 |
|
| 208 |
bool link_is_ready_to_configure(Link *link, bool allow_unmanaged); |
| 209 |
bool link_is_ready_to_configure_by_name(Manager *manager, const char *name, bool allow_unmanaged); |
| 210 |
|
| 211 |
void link_ntp_settings_clear(Link *link); |
| 212 |
void link_dns_settings_clear(Link *link); |
| 213 |
DECLARE_TRIVIAL_REF_UNREF_FUNC(Link, link); |
| 214 |
DEFINE_TRIVIAL_CLEANUP_FUNC(Link*, link_unref); |
| 215 |
DEFINE_TRIVIAL_DESTRUCTOR(link_netlink_destroy_callback, Link, link_unref); |
| 216 |
|
| 217 |
int link_get_by_index(Manager *m, int ifindex, Link **ret); |
| 218 |
int link_get_by_name(Manager *m, const char *ifname, Link **ret); |
| 219 |
int link_get_by_hw_addr(Manager *m, const struct hw_addr_data *hw_addr, Link **ret); |
| 220 |
int link_get_master(Link *link, Link **ret); |
| 221 |
|
| 222 |
int link_getlink_handler_internal(sd_netlink *rtnl, sd_netlink_message *m, Link *link, const char *error_msg); |
| 223 |
int link_call_getlink(Link *link, link_netlink_message_handler_t callback); |
| 224 |
int link_handle_bound_to_list(Link *link); |
| 225 |
|
| 226 |
void link_enter_failed(Link *link); |
| 227 |
void link_set_state(Link *link, LinkState state); |
| 228 |
void link_check_ready(Link *link); |
| 229 |
|
| 230 |
void link_update_operstate(Link *link, bool also_update_master); |
| 231 |
|
| 232 |
bool link_has_carrier(Link *link); |
| 233 |
bool link_is_up(Link *link); |
| 234 |
bool link_multicast_enabled(Link *link); |
| 235 |
|
| 236 |
bool link_ipv6_enabled(Link *link); |
| 237 |
int link_ipv6ll_gained(Link *link); |
| 238 |
int link_ipv6ll_lost(Link *link, const struct in6_addr *dropped_ipv6ll, bool has_replacement); |
| 239 |
bool link_has_ipv6_connectivity(Link *link); |
| 240 |
|
| 241 |
int link_stop_engines(Link *link, bool may_keep_dynamic); |
| 242 |
|
| 243 |
DECLARE_STRING_TABLE_LOOKUP(link_state, LinkState); |
| 244 |
|
| 245 |
int link_request_stacked_netdevs(Link *link, NetDevLocalAddressType type); |
| 246 |
|
| 247 |
int link_reconfigure_impl(Link *link, LinkReconfigurationFlag flags); |
| 248 |
int link_reconfigure_full(Link *link, LinkReconfigurationFlag flags, sd_bus_message *message, sd_varlink *varlink, unsigned *counter); |
| 249 |
static inline int link_reconfigure(Link *link, LinkReconfigurationFlag flags) { |
| 250 |
return link_reconfigure_full(link, flags, NULL, NULL, NULL); |
| 251 |
} |
| 252 |
|
| 253 |
int link_check_initialized(Link *link); |
| 254 |
|
| 255 |
int manager_udev_process_link(Manager *m, sd_device *device, sd_device_action_t action); |
| 256 |
int manager_rtnl_process_link(sd_netlink *rtnl, sd_netlink_message *message, Manager *m); |
| 257 |
|
| 258 |
DECLARE_STRING_TABLE_LOOKUP_TO_STRING_FALLBACK(link_flags, uint32_t); |
| 259 |
DECLARE_STRING_TABLE_LOOKUP_TO_STRING(kernel_operstate, int); |
| 260 |
|
| 261 |
void link_required_operstate_for_online(Link *link, LinkOperationalStateRange *ret); |
| 262 |
AddressFamily link_required_family_for_online(Link *link); |
| 263 |
|
| 264 |
bool link_has_local_lease_domain(Link *link); |