]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/network/networkd-link.h
Merge pull request #11827 from keszybz/pkgconfig-variables
[thirdparty/systemd.git] / src / network / networkd-link.h
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 "set.h"
19
20 typedef enum LinkState {
21 LINK_STATE_PENDING,
22 LINK_STATE_CONFIGURING,
23 LINK_STATE_CONFIGURED,
24 LINK_STATE_UNMANAGED,
25 LINK_STATE_FAILED,
26 LINK_STATE_LINGER,
27 _LINK_STATE_MAX,
28 _LINK_STATE_INVALID = -1
29 } LinkState;
30
31 typedef enum LinkOperationalState {
32 LINK_OPERSTATE_OFF,
33 LINK_OPERSTATE_NO_CARRIER,
34 LINK_OPERSTATE_DORMANT,
35 LINK_OPERSTATE_CARRIER,
36 LINK_OPERSTATE_DEGRADED,
37 LINK_OPERSTATE_ENSLAVED,
38 LINK_OPERSTATE_ROUTABLE,
39 _LINK_OPERSTATE_MAX,
40 _LINK_OPERSTATE_INVALID = -1
41 } LinkOperationalState;
42
43 typedef struct Manager Manager;
44 typedef struct Network Network;
45 typedef struct Address Address;
46 typedef struct DUID DUID;
47
48 typedef struct Link {
49 Manager *manager;
50
51 unsigned n_ref;
52
53 int ifindex;
54 int master_ifindex;
55 char *ifname;
56 char *kind;
57 unsigned short iftype;
58 char *state_file;
59 struct ether_addr mac;
60 struct in6_addr ipv6ll_address;
61 uint32_t mtu;
62 sd_device *sd_device;
63
64 unsigned flags;
65 uint8_t kernel_operstate;
66
67 Network *network;
68
69 LinkState state;
70 LinkOperationalState operstate;
71
72 unsigned address_messages;
73 unsigned address_label_messages;
74 unsigned neighbor_messages;
75 unsigned route_messages;
76 unsigned routing_policy_rule_messages;
77 unsigned routing_policy_rule_remove_messages;
78 unsigned enslaving;
79 /* link_is_enslaved() has additional checks. So, it is named _raw. */
80 bool enslaved_raw;
81
82 Set *addresses;
83 Set *addresses_foreign;
84 Set *routes;
85 Set *routes_foreign;
86
87 bool addresses_configured;
88 bool addresses_ready;
89
90 sd_dhcp_client *dhcp_client;
91 sd_dhcp_lease *dhcp_lease;
92 char *lease_file;
93 uint32_t original_mtu;
94 unsigned dhcp4_messages;
95 bool dhcp4_configured;
96 bool dhcp6_configured;
97
98 unsigned ndisc_messages;
99 bool ndisc_configured;
100
101 sd_ipv4ll *ipv4ll;
102 bool ipv4ll_address:1;
103 bool ipv4ll_route:1;
104
105 bool neighbors_configured;
106
107 bool static_routes_configured;
108 bool routing_policy_rules_configured;
109 bool setting_mtu;
110
111 LIST_HEAD(Address, pool_addresses);
112
113 sd_dhcp_server *dhcp_server;
114
115 sd_ndisc *ndisc;
116 Set *ndisc_rdnss;
117 Set *ndisc_dnssl;
118
119 sd_radv *radv;
120
121 sd_dhcp6_client *dhcp6_client;
122 bool rtnl_extended_attrs;
123
124 /* This is about LLDP reception */
125 sd_lldp *lldp;
126 char *lldp_file;
127
128 /* This is about LLDP transmission */
129 unsigned lldp_tx_fast; /* The LLDP txFast counter (See 802.1ab-2009, section 9.2.5.18) */
130 sd_event_source *lldp_emit_event_source;
131
132 Hashmap *bound_by_links;
133 Hashmap *bound_to_links;
134 Hashmap *slaves;
135 } Link;
136
137 typedef int (*link_netlink_message_handler_t)(sd_netlink*, sd_netlink_message*, Link*);
138
139 DUID *link_get_duid(Link *link);
140 int get_product_uuid_handler(sd_bus_message *m, void *userdata, sd_bus_error *ret_error);
141
142 Link *link_unref(Link *link);
143 Link *link_ref(Link *link);
144 DEFINE_TRIVIAL_DESTRUCTOR(link_netlink_destroy_callback, Link, link_unref);
145
146 int link_get(Manager *m, int ifindex, Link **ret);
147 int link_add(Manager *manager, sd_netlink_message *message, Link **ret);
148 void link_drop(Link *link);
149
150 int link_down(Link *link);
151
152 void link_enter_failed(Link *link);
153 int link_initialized(Link *link, sd_device *device);
154
155 void link_check_ready(Link *link);
156
157 void link_update_operstate(Link *link, bool also_update_bond_master);
158 int link_update(Link *link, sd_netlink_message *message);
159
160 void link_dirty(Link *link);
161 void link_clean(Link *link);
162 int link_save(Link *link);
163
164 int link_carrier_reset(Link *link);
165 bool link_has_carrier(Link *link);
166
167 int link_ipv6ll_gained(Link *link, const struct in6_addr *address);
168
169 int link_set_mtu(Link *link, uint32_t mtu);
170
171 int ipv4ll_configure(Link *link);
172 int dhcp4_configure(Link *link);
173 int dhcp4_set_client_identifier(Link *link);
174 int dhcp4_set_promote_secondaries(Link *link);
175 int dhcp6_request_prefix_delegation(Link *link);
176 int dhcp6_configure(Link *link);
177 int dhcp6_request_address(Link *link, int ir);
178 int dhcp6_lease_pd_prefix_lost(sd_dhcp6_client *client, Link* link);
179
180 const char* link_state_to_string(LinkState s) _const_;
181 LinkState link_state_from_string(const char *s) _pure_;
182
183 const char* link_operstate_to_string(LinkOperationalState s) _const_;
184 LinkOperationalState link_operstate_from_string(const char *s) _pure_;
185
186 extern const sd_bus_vtable link_vtable[];
187
188 int link_node_enumerator(sd_bus *bus, const char *path, void *userdata, char ***nodes, sd_bus_error *error);
189 int link_object_find(sd_bus *bus, const char *path, const char *interface, void *userdata, void **found, sd_bus_error *error);
190 int link_send_changed(Link *link, const char *property, ...) _sentinel_;
191
192 uint32_t link_get_vrf_table(Link *link);
193 uint32_t link_get_dhcp_route_table(Link *link);
194 uint32_t link_get_ipv6_accept_ra_route_table(Link *link);
195
196 /* Macros which append INTERFACE= to the message */
197
198 #define log_link_full(link, level, error, ...) \
199 ({ \
200 const Link *_l = (link); \
201 _l ? log_object_internal(level, error, __FILE__, __LINE__, __func__, "INTERFACE=", _l->ifname, NULL, NULL, ##__VA_ARGS__) : \
202 log_internal(level, error, __FILE__, __LINE__, __func__, ##__VA_ARGS__); \
203 }) \
204
205 #define log_link_debug(link, ...) log_link_full(link, LOG_DEBUG, 0, ##__VA_ARGS__)
206 #define log_link_info(link, ...) log_link_full(link, LOG_INFO, 0, ##__VA_ARGS__)
207 #define log_link_notice(link, ...) log_link_full(link, LOG_NOTICE, 0, ##__VA_ARGS__)
208 #define log_link_warning(link, ...) log_link_full(link, LOG_WARNING, 0, ##__VA_ARGS__)
209 #define log_link_error(link, ...) log_link_full(link, LOG_ERR, 0, ##__VA_ARGS__)
210
211 #define log_link_debug_errno(link, error, ...) log_link_full(link, LOG_DEBUG, error, ##__VA_ARGS__)
212 #define log_link_info_errno(link, error, ...) log_link_full(link, LOG_INFO, error, ##__VA_ARGS__)
213 #define log_link_notice_errno(link, error, ...) log_link_full(link, LOG_NOTICE, error, ##__VA_ARGS__)
214 #define log_link_warning_errno(link, error, ...) log_link_full(link, LOG_WARNING, error, ##__VA_ARGS__)
215 #define log_link_error_errno(link, error, ...) log_link_full(link, LOG_ERR, error, ##__VA_ARGS__)
216
217 #define LOG_LINK_MESSAGE(link, fmt, ...) "MESSAGE=%s: " fmt, (link)->ifname, ##__VA_ARGS__
218 #define LOG_LINK_INTERFACE(link) "INTERFACE=%s", (link)->ifname
219
220 #define ADDRESS_FMT_VAL(address) \
221 be32toh((address).s_addr) >> 24, \
222 (be32toh((address).s_addr) >> 16) & 0xFFu, \
223 (be32toh((address).s_addr) >> 8) & 0xFFu, \
224 be32toh((address).s_addr) & 0xFFu