Line data Source code
1 : /* SPDX-License-Identifier: LGPL-2.1+ */
2 : #pragma once
3 :
4 : #include <endian.h>
5 :
6 : #include "sd-bus.h"
7 : #include "sd-device.h"
8 : #include "sd-dhcp-client.h"
9 : #include "sd-dhcp-server.h"
10 : #include "sd-dhcp6-client.h"
11 : #include "sd-ipv4ll.h"
12 : #include "sd-lldp.h"
13 : #include "sd-ndisc.h"
14 : #include "sd-radv.h"
15 : #include "sd-netlink.h"
16 :
17 : #include "list.h"
18 : #include "log-link.h"
19 : #include "network-util.h"
20 : #include "networkd-util.h"
21 : #include "ordered-set.h"
22 : #include "resolve-util.h"
23 : #include "set.h"
24 :
25 : typedef enum LinkState {
26 : LINK_STATE_PENDING, /* udev has not initialized the link */
27 : LINK_STATE_INITIALIZED, /* udev has initialized the link */
28 : LINK_STATE_CONFIGURING, /* configuring addresses, routes, etc. */
29 : LINK_STATE_CONFIGURED, /* everything is configured */
30 : LINK_STATE_UNMANAGED, /* Unmanaged=yes is set */
31 : LINK_STATE_FAILED, /* at least one configuration process failed */
32 : LINK_STATE_LINGER, /* RTM_DELLINK for the link has been received */
33 : _LINK_STATE_MAX,
34 : _LINK_STATE_INVALID = -1
35 : } LinkState;
36 :
37 : typedef struct Manager Manager;
38 : typedef struct Network Network;
39 : typedef struct Address Address;
40 : typedef struct DUID DUID;
41 :
42 : typedef struct Link {
43 : Manager *manager;
44 :
45 : unsigned n_ref;
46 :
47 : int ifindex;
48 : int master_ifindex;
49 : char *ifname;
50 : char *kind;
51 : unsigned short iftype;
52 : char *state_file;
53 : struct ether_addr mac;
54 : struct in6_addr ipv6ll_address;
55 : uint32_t mtu;
56 : sd_device *sd_device;
57 :
58 : unsigned flags;
59 : uint8_t kernel_operstate;
60 :
61 : Network *network;
62 :
63 : LinkState state;
64 : LinkOperationalState operstate;
65 : LinkCarrierState carrier_state;
66 : LinkAddressState address_state;
67 :
68 : unsigned address_messages;
69 : unsigned address_label_messages;
70 : unsigned neighbor_messages;
71 : unsigned route_messages;
72 : unsigned routing_policy_rule_messages;
73 : unsigned routing_policy_rule_remove_messages;
74 : unsigned enslaving;
75 :
76 : Set *addresses;
77 : Set *addresses_foreign;
78 : Set *neighbors;
79 : Set *neighbors_foreign;
80 : Set *routes;
81 : Set *routes_foreign;
82 :
83 : bool addresses_configured;
84 : bool addresses_ready;
85 :
86 : sd_dhcp_client *dhcp_client;
87 : sd_dhcp_lease *dhcp_lease, *dhcp_lease_old;
88 : Set *dhcp_routes;
89 : char *lease_file;
90 : uint32_t original_mtu;
91 : unsigned dhcp4_messages;
92 : bool dhcp4_configured;
93 : bool dhcp6_configured;
94 :
95 : unsigned ndisc_messages;
96 : bool ndisc_configured;
97 :
98 : sd_ipv4ll *ipv4ll;
99 : bool ipv4ll_address:1;
100 : bool ipv4ll_route:1;
101 :
102 : bool neighbors_configured;
103 :
104 : bool static_routes_configured;
105 : bool routing_policy_rules_configured;
106 : bool setting_mtu;
107 :
108 : LIST_HEAD(Address, pool_addresses);
109 :
110 : sd_dhcp_server *dhcp_server;
111 :
112 : sd_ndisc *ndisc;
113 : Set *ndisc_rdnss;
114 : Set *ndisc_dnssl;
115 :
116 : sd_radv *radv;
117 :
118 : sd_dhcp6_client *dhcp6_client;
119 :
120 : /* This is about LLDP reception */
121 : sd_lldp *lldp;
122 : char *lldp_file;
123 :
124 : /* This is about LLDP transmission */
125 : unsigned lldp_tx_fast; /* The LLDP txFast counter (See 802.1ab-2009, section 9.2.5.18) */
126 : sd_event_source *lldp_emit_event_source;
127 :
128 : Hashmap *bound_by_links;
129 : Hashmap *bound_to_links;
130 : Set *slaves;
131 :
132 : /* For speed meter */
133 : struct rtnl_link_stats64 stats_old, stats_new;
134 : bool stats_updated;
135 :
136 : int sysctl_ipv6_enabled;
137 :
138 : /* All kinds of DNS configuration */
139 : struct in_addr_data *dns;
140 : unsigned n_dns;
141 : OrderedSet *search_domains, *route_domains;
142 :
143 : int dns_default_route;
144 : ResolveSupport llmnr;
145 : ResolveSupport mdns;
146 : DnssecMode dnssec_mode;
147 : DnsOverTlsMode dns_over_tls_mode;
148 : Set *dnssec_negative_trust_anchors;
149 :
150 : char **ntp;
151 : } Link;
152 :
153 : typedef int (*link_netlink_message_handler_t)(sd_netlink*, sd_netlink_message*, Link*);
154 :
155 : DUID *link_get_duid(Link *link);
156 : int get_product_uuid_handler(sd_bus_message *m, void *userdata, sd_bus_error *ret_error);
157 :
158 : void link_ntp_settings_clear(Link *link);
159 : void link_dns_settings_clear(Link *link);
160 : Link *link_unref(Link *link);
161 : Link *link_ref(Link *link);
162 6 : DEFINE_TRIVIAL_CLEANUP_FUNC(Link*, link_unref);
163 6 : DEFINE_TRIVIAL_DESTRUCTOR(link_netlink_destroy_callback, Link, link_unref);
164 :
165 : int link_get(Manager *m, int ifindex, Link **ret);
166 : int link_add(Manager *manager, sd_netlink_message *message, Link **ret);
167 : void link_drop(Link *link);
168 :
169 : int link_down(Link *link, link_netlink_message_handler_t callback);
170 :
171 : void link_enter_failed(Link *link);
172 : int link_initialized(Link *link, sd_device *device);
173 :
174 : void link_set_state(Link *link, LinkState state);
175 : void link_check_ready(Link *link);
176 :
177 : void link_update_operstate(Link *link, bool also_update_bond_master);
178 : int link_update(Link *link, sd_netlink_message *message);
179 :
180 : void link_dirty(Link *link);
181 : void link_clean(Link *link);
182 : int link_save(Link *link);
183 :
184 : int link_carrier_reset(Link *link);
185 : bool link_has_carrier(Link *link);
186 :
187 : int link_ipv6ll_gained(Link *link, const struct in6_addr *address);
188 :
189 : int link_set_mtu(Link *link, uint32_t mtu);
190 :
191 : bool link_ipv4ll_enabled(Link *link, AddressFamily mask);
192 :
193 : int link_stop_clients(Link *link, bool may_keep_dhcp);
194 :
195 : const char* link_state_to_string(LinkState s) _const_;
196 : LinkState link_state_from_string(const char *s) _pure_;
197 :
198 : uint32_t link_get_vrf_table(Link *link);
199 : uint32_t link_get_dhcp_route_table(Link *link);
200 : uint32_t link_get_ipv6_accept_ra_route_table(Link *link);
201 : int link_request_set_routes(Link *link);
202 :
203 : int link_sysctl_ipv6_enabled(Link *link);
204 :
205 : #define ADDRESS_FMT_VAL(address) \
206 : be32toh((address).s_addr) >> 24, \
207 : (be32toh((address).s_addr) >> 16) & 0xFFu, \
208 : (be32toh((address).s_addr) >> 8) & 0xFFu, \
209 : be32toh((address).s_addr) & 0xFFu
|