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