]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/network/netdev/bond.c
tree-wide: define iterator inside of the macro
[thirdparty/systemd.git] / src / network / netdev / bond.c
CommitLineData
53e1b683 1/* SPDX-License-Identifier: LGPL-2.1+ */
fe8ac65b 2
b5efdb8a 3#include "alloc-util.h"
f2000933 4#include "bond.h"
5fe5908e 5#include "bond-util.h"
07630cea 6#include "conf-parser.h"
99f68ef0 7#include "ether-addr-util.h"
634f0f98 8#include "extract-word.h"
4799f19e
YW
9#include "netlink-util.h"
10#include "networkd-manager.h"
8b43440b 11#include "string-table.h"
fe8ac65b 12
81bd37a8
SS
13/*
14 * Number of seconds between instances where the bonding
15 * driver sends learning packets to each slaves peer switch
16 */
17#define LEARNING_PACKETS_INTERVAL_MIN_SEC (1 * USEC_PER_SEC)
18#define LEARNING_PACKETS_INTERVAL_MAX_SEC (0x7fffffff * USEC_PER_SEC)
19
20/* Number of IGMP membership reports to be issued after
21 * a failover event.
22 */
23#define RESEND_IGMP_MIN 0
24#define RESEND_IGMP_MAX 255
25#define RESEND_IGMP_DEFAULT 1
26
27/*
28 * Number of packets to transmit through a slave before
29 * moving to the next one.
30 */
31#define PACKETS_PER_SLAVE_MIN 0
32#define PACKETS_PER_SLAVE_MAX 65535
33#define PACKETS_PER_SLAVE_DEFAULT 1
34
35/*
36 * Number of peer notifications (gratuitous ARPs and
37 * unsolicited IPv6 Neighbor Advertisements) to be issued after a
38 * failover event.
39 */
40#define GRATUITOUS_ARP_MIN 0
41#define GRATUITOUS_ARP_MAX 255
42#define GRATUITOUS_ARP_DEFAULT 1
43
fe8ac65b 44DEFINE_CONFIG_PARSE_ENUM(config_parse_bond_mode, bond_mode, BondMode, "Failed to parse bond mode");
227cdf2c
SS
45DEFINE_CONFIG_PARSE_ENUM(config_parse_bond_xmit_hash_policy,
46 bond_xmit_hash_policy,
47 BondXmitHashPolicy,
5fe5908e
SS
48 "Failed to parse bond transmit hash policy");
49DEFINE_CONFIG_PARSE_ENUM(config_parse_bond_lacp_rate, bond_lacp_rate, BondLacpRate, "Failed to parse bond lacp rate");
81bd37a8 50DEFINE_CONFIG_PARSE_ENUM(config_parse_bond_ad_select, bond_ad_select, BondAdSelect, "Failed to parse bond AD select");
81bd37a8 51DEFINE_CONFIG_PARSE_ENUM(config_parse_bond_fail_over_mac, bond_fail_over_mac, BondFailOverMac, "Failed to parse bond fail over MAC");
81bd37a8 52DEFINE_CONFIG_PARSE_ENUM(config_parse_bond_arp_validate, bond_arp_validate, BondArpValidate, "Failed to parse bond arp validate");
81bd37a8 53DEFINE_CONFIG_PARSE_ENUM(config_parse_bond_arp_all_targets, bond_arp_all_targets, BondArpAllTargets, "Failed to parse bond Arp all targets");
81bd37a8
SS
54DEFINE_CONFIG_PARSE_ENUM(config_parse_bond_primary_reselect, bond_primary_reselect, BondPrimaryReselect, "Failed to parse bond primary reselect");
55
1c4baffc 56static int netdev_bond_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) {
ae185f48 57 Bond *b;
674c96fc 58 int r;
fe8ac65b 59
aa9f1140
TG
60 assert(netdev);
61 assert(!link);
fe8ac65b
SS
62 assert(m);
63
ae185f48
SS
64 b = BOND(netdev);
65
66 assert(b);
67
aa9f1140 68 if (b->mode != _NETDEV_BOND_MODE_INVALID) {
f2000933 69 r = sd_netlink_message_append_u8(m, IFLA_BOND_MODE, b->mode);
a668086e
SS
70 if (r < 0)
71 return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_MODE attribute: %m");
fe8ac65b
SS
72 }
73
227cdf2c 74 if (b->xmit_hash_policy != _NETDEV_BOND_XMIT_HASH_POLICY_INVALID) {
f2000933 75 r = sd_netlink_message_append_u8(m, IFLA_BOND_XMIT_HASH_POLICY, b->xmit_hash_policy);
a668086e
SS
76 if (r < 0)
77 return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_XMIT_HASH_POLICY attribute: %m");
227cdf2c
SS
78 }
79
fb1021a2
SS
80 if (b->lacp_rate != _NETDEV_BOND_LACP_RATE_INVALID &&
81 b->mode == NETDEV_BOND_MODE_802_3AD) {
3f7cc080 82 r = sd_netlink_message_append_u8(m, IFLA_BOND_AD_LACP_RATE, b->lacp_rate);
ece174c5 83 if (r < 0)
a668086e 84 return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_AD_LACP_RATE attribute: %m");
fb1021a2
SS
85 }
86
d9c52fa0 87 if (b->miimon != 0) {
1c4baffc 88 r = sd_netlink_message_append_u32(m, IFLA_BOND_MIIMON, b->miimon / USEC_PER_MSEC);
a668086e
SS
89 if (r < 0)
90 log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_BOND_MIIMON attribute: %m");
d9c52fa0
SS
91 }
92
93 if (b->downdelay != 0) {
1c4baffc 94 r = sd_netlink_message_append_u32(m, IFLA_BOND_DOWNDELAY, b->downdelay / USEC_PER_MSEC);
a668086e
SS
95 if (r < 0)
96 return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_DOWNDELAY attribute: %m");
d9c52fa0
SS
97 }
98
99 if (b->updelay != 0) {
1c4baffc 100 r = sd_netlink_message_append_u32(m, IFLA_BOND_UPDELAY, b->updelay / USEC_PER_MSEC);
a668086e
SS
101 if (r < 0)
102 return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_UPDELAY attribute: %m");
d9c52fa0
SS
103 }
104
81bd37a8 105 if (b->arp_interval != 0) {
1c4baffc 106 r = sd_netlink_message_append_u32(m, IFLA_BOND_ARP_INTERVAL, b->arp_interval / USEC_PER_MSEC);
a668086e
SS
107 if (r < 0)
108 return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_ARP_INTERVAL attribute: %m");
109
3f7cc080
YW
110 if (b->lp_interval >= LEARNING_PACKETS_INTERVAL_MIN_SEC &&
111 b->lp_interval <= LEARNING_PACKETS_INTERVAL_MAX_SEC) {
1c4baffc 112 r = sd_netlink_message_append_u32(m, IFLA_BOND_LP_INTERVAL, b->lp_interval / USEC_PER_SEC);
a668086e
SS
113 if (r < 0)
114 return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_LP_INTERVAL attribute: %m");
81bd37a8
SS
115 }
116 }
117
118 if (b->ad_select != _NETDEV_BOND_AD_SELECT_INVALID &&
76f0a567 119 b->mode == NETDEV_BOND_MODE_802_3AD) {
1c4baffc 120 r = sd_netlink_message_append_u8(m, IFLA_BOND_AD_SELECT, b->ad_select);
a668086e
SS
121 if (r < 0)
122 return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_AD_SELECT attribute: %m");
81bd37a8
SS
123 }
124
125 if (b->fail_over_mac != _NETDEV_BOND_FAIL_OVER_MAC_INVALID &&
126 b->mode == NETDEV_BOND_MODE_ACTIVE_BACKUP) {
1c4baffc 127 r = sd_netlink_message_append_u8(m, IFLA_BOND_FAIL_OVER_MAC, b->fail_over_mac);
a668086e
SS
128 if (r < 0)
129 return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_FAIL_OVER_MAC attribute: %m");
81bd37a8
SS
130 }
131
132 if (b->arp_validate != _NETDEV_BOND_ARP_VALIDATE_INVALID) {
1c4baffc 133 r = sd_netlink_message_append_u32(m, IFLA_BOND_ARP_VALIDATE, b->arp_validate);
a668086e
SS
134 if (r < 0)
135 return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_ARP_VALIDATE attribute: %m");
81bd37a8
SS
136 }
137
138 if (b->arp_all_targets != _NETDEV_BOND_ARP_ALL_TARGETS_INVALID) {
1c4baffc 139 r = sd_netlink_message_append_u32(m, IFLA_BOND_ARP_ALL_TARGETS, b->arp_all_targets);
a668086e 140 if (r < 0)
e59ace18 141 return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_ARP_ALL_TARGETS attribute: %m");
81bd37a8
SS
142 }
143
144 if (b->primary_reselect != _NETDEV_BOND_PRIMARY_RESELECT_INVALID) {
e59ace18 145 r = sd_netlink_message_append_u8(m, IFLA_BOND_PRIMARY_RESELECT, b->primary_reselect);
a668086e 146 if (r < 0)
e59ace18 147 return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_PRIMARY_RESELECT attribute: %m");
81bd37a8
SS
148 }
149
150 if (b->resend_igmp <= RESEND_IGMP_MAX) {
1c4baffc 151 r = sd_netlink_message_append_u32(m, IFLA_BOND_RESEND_IGMP, b->resend_igmp);
a668086e
SS
152 if (r < 0)
153 return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_RESEND_IGMP attribute: %m");
81bd37a8
SS
154 }
155
76f0a567
TG
156 if (b->packets_per_slave <= PACKETS_PER_SLAVE_MAX &&
157 b->mode == NETDEV_BOND_MODE_BALANCE_RR) {
1c4baffc 158 r = sd_netlink_message_append_u32(m, IFLA_BOND_PACKETS_PER_SLAVE, b->packets_per_slave);
a668086e
SS
159 if (r < 0)
160 return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_PACKETS_PER_SLAVE attribute: %m");
81bd37a8
SS
161 }
162
163 if (b->num_grat_arp <= GRATUITOUS_ARP_MAX) {
1c4baffc 164 r = sd_netlink_message_append_u8(m, IFLA_BOND_NUM_PEER_NOTIF, b->num_grat_arp);
a668086e
SS
165 if (r < 0)
166 return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_NUM_PEER_NOTIF attribute: %m");
81bd37a8
SS
167 }
168
169 if (b->min_links != 0) {
1c4baffc 170 r = sd_netlink_message_append_u32(m, IFLA_BOND_MIN_LINKS, b->min_links);
a668086e
SS
171 if (r < 0)
172 return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_MIN_LINKS attribute: %m");
81bd37a8
SS
173 }
174
99f68ef0
TJ
175 if (b->ad_actor_sys_prio != 0) {
176 r = sd_netlink_message_append_u16(m, IFLA_BOND_AD_ACTOR_SYS_PRIO, b->ad_actor_sys_prio);
177 if (r < 0)
178 return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_AD_ACTOR_SYS_PRIO attribute: %m");
179 }
180
181 if (b->ad_user_port_key != 0) {
182 r = sd_netlink_message_append_u16(m, IFLA_BOND_AD_USER_PORT_KEY, b->ad_user_port_key);
183 if (r < 0)
184 return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_AD_USER_PORT_KEY attribute: %m");
185 }
186
1e2a490e
YW
187 if (!ether_addr_is_null(&b->ad_actor_system)) {
188 r = sd_netlink_message_append_ether_addr(m, IFLA_BOND_AD_ACTOR_SYSTEM, &b->ad_actor_system);
99f68ef0
TJ
189 if (r < 0)
190 return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_AD_ACTOR_SYSTEM attribute: %m");
191 }
192
1c4baffc 193 r = sd_netlink_message_append_u8(m, IFLA_BOND_ALL_SLAVES_ACTIVE, b->all_slaves_active);
a668086e
SS
194 if (r < 0)
195 return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_ALL_SLAVES_ACTIVE attribute: %m");
81bd37a8 196
fde60a42
SS
197 if (b->tlb_dynamic_lb >= 0) {
198 r = sd_netlink_message_append_u8(m, IFLA_BOND_TLB_DYNAMIC_LB, b->tlb_dynamic_lb);
199 if (r < 0)
200 return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_TLB_DYNAMIC_LB attribute: %m");
201 }
202
674c96fc 203 if (b->arp_interval > 0 && !ordered_set_isempty(b->arp_ip_targets)) {
674c96fc
YW
204 void *val;
205 int n = 0;
206
3f7cc080
YW
207 r = sd_netlink_message_open_container(m, IFLA_BOND_ARP_IP_TARGET);
208 if (r < 0)
209 return log_netdev_error_errno(netdev, r, "Could not open contaniner IFLA_BOND_ARP_IP_TARGET : %m");
81bd37a8 210
90e74a66 211 ORDERED_SET_FOREACH(val, b->arp_ip_targets) {
674c96fc 212 r = sd_netlink_message_append_u32(m, n++, PTR_TO_UINT32(val));
a668086e 213 if (r < 0)
3f7cc080 214 return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_ARP_ALL_TARGETS attribute: %m");
81bd37a8 215 }
3f7cc080
YW
216
217 r = sd_netlink_message_close_container(m);
218 if (r < 0)
219 return log_netdev_error_errno(netdev, r, "Could not close contaniner IFLA_BOND_ARP_IP_TARGET : %m");
81bd37a8
SS
220 }
221
aa9f1140
TG
222 return 0;
223}
fe8ac65b 224
4799f19e
YW
225static int link_set_bond_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
226 int r;
227
228 assert(m);
229 assert(link);
230 assert(link->ifname);
231
232 if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER))
233 return 1;
234
235 r = sd_netlink_message_get_errno(m);
236 if (r < 0) {
237 log_link_warning_errno(link, r, "Could not set bonding interface: %m");
238 return 1;
239 }
240
241 return 1;
242}
243
244int link_set_bond(Link *link) {
245 _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *req = NULL;
246 int r;
247
248 assert(link);
249 assert(link->network);
250
251 r = sd_rtnl_message_new_link(link->manager->rtnl, &req, RTM_NEWLINK, link->network->bond->ifindex);
252 if (r < 0)
253 return log_link_error_errno(link, r, "Could not allocate RTM_SETLINK message: %m");
254
255 r = sd_netlink_message_set_flags(req, NLM_F_REQUEST | NLM_F_ACK);
256 if (r < 0)
257 return log_link_error_errno(link, r, "Could not set netlink flags: %m");
258
259 r = sd_netlink_message_open_container(req, IFLA_LINKINFO);
260 if (r < 0)
261 return log_link_error_errno(link, r, "Could not append IFLA_PROTINFO attribute: %m");
262
263 r = sd_netlink_message_open_container_union(req, IFLA_INFO_DATA, "bond");
264 if (r < 0)
265 return log_link_error_errno(link, r, "Could not append IFLA_INFO_DATA attribute: %m");
266
267 if (link->network->active_slave) {
268 r = sd_netlink_message_append_u32(req, IFLA_BOND_ACTIVE_SLAVE, link->ifindex);
269 if (r < 0)
270 return log_link_error_errno(link, r, "Could not append IFLA_BOND_ACTIVE_SLAVE attribute: %m");
271 }
272
273 if (link->network->primary_slave) {
274 r = sd_netlink_message_append_u32(req, IFLA_BOND_PRIMARY, link->ifindex);
275 if (r < 0)
276 return log_link_error_errno(link, r, "Could not append IFLA_BOND_PRIMARY attribute: %m");
277 }
278
279 r = sd_netlink_message_close_container(req);
280 if (r < 0)
281 return log_link_error_errno(link, r, "Could not append IFLA_LINKINFO attribute: %m");
282
283 r = sd_netlink_message_close_container(req);
284 if (r < 0)
285 return log_link_error_errno(link, r, "Could not append IFLA_INFO_DATA attribute: %m");
286
287 r = netlink_call_async(link->manager->rtnl, NULL, req, link_set_bond_handler,
288 link_netlink_destroy_callback, link);
289 if (r < 0)
43bf2874 290 return log_link_error_errno(link, r, "Could not send rtnetlink message: %m");
4799f19e
YW
291
292 link_ref(link);
293
294 return r;
295}
296
674c96fc
YW
297int config_parse_arp_ip_target_address(
298 const char *unit,
299 const char *filename,
300 unsigned line,
301 const char *section,
302 unsigned section_line,
303 const char *lvalue,
304 int ltype,
305 const char *rvalue,
306 void *data,
307 void *userdata) {
308
81bd37a8 309 Bond *b = userdata;
81bd37a8
SS
310 int r;
311
312 assert(filename);
313 assert(lvalue);
314 assert(rvalue);
315 assert(data);
316
674c96fc
YW
317 if (isempty(rvalue)) {
318 b->arp_ip_targets = ordered_set_free(b->arp_ip_targets);
319 return 0;
320 }
321
d96edb2c 322 for (const char *p = rvalue;;) {
81bd37a8 323 _cleanup_free_ char *n = NULL;
674c96fc 324 union in_addr_union ip;
81bd37a8 325
d96edb2c
YW
326 r = extract_first_word(&p, &n, NULL, 0);
327 if (r == -ENOMEM)
328 return log_oom();
022833c8 329 if (r < 0) {
d96edb2c 330 log_syntax(unit, LOG_WARNING, filename, line, r,
0da425df 331 "Failed to parse Bond ARP IP target address, ignoring assignment: %s",
674c96fc 332 rvalue);
022833c8
SS
333 return 0;
334 }
022833c8 335 if (r == 0)
674c96fc 336 return 0;
81bd37a8 337
674c96fc 338 r = in_addr_from_string(AF_INET, n, &ip);
81bd37a8 339 if (r < 0) {
d96edb2c 340 log_syntax(unit, LOG_WARNING, filename, line, r,
0da425df 341 "Bond ARP IP target address is invalid, ignoring assignment: %s", n);
674c96fc 342 continue;
81bd37a8
SS
343 }
344
674c96fc
YW
345 r = ordered_set_ensure_allocated(&b->arp_ip_targets, NULL);
346 if (r < 0)
347 return log_oom();
348
349 if (ordered_set_size(b->arp_ip_targets) >= NETDEV_BOND_ARP_TARGETS_MAX) {
350 log_syntax(unit, LOG_WARNING, filename, line, 0,
0da425df 351 "Too many ARP IP targets are specified. The maximum number is %d. Ignoring assignment: %s",
674c96fc
YW
352 NETDEV_BOND_ARP_TARGETS_MAX, n);
353 continue;
81bd37a8
SS
354 }
355
674c96fc
YW
356 r = ordered_set_put(b->arp_ip_targets, UINT32_TO_PTR(ip.in.s_addr));
357 if (r == -EEXIST)
358 log_syntax(unit, LOG_WARNING, filename, line, r,
0da425df 359 "Bond ARP IP target address is duplicated, ignoring assignment: %s", n);
674c96fc 360 if (r < 0)
d96edb2c 361 log_syntax(unit, LOG_WARNING, filename, line, r,
0da425df 362 "Failed to store bond ARP IP target address '%s', ignoring assignment: %m", n);
81bd37a8 363 }
81bd37a8
SS
364}
365
3e8afae5
YW
366int config_parse_ad_actor_sys_prio(
367 const char *unit,
368 const char *filename,
369 unsigned line,
370 const char *section,
371 unsigned section_line,
372 const char *lvalue,
373 int ltype,
374 const char *rvalue,
375 void *data,
376 void *userdata) {
99f68ef0
TJ
377 Bond *b = userdata;
378 uint16_t v;
379 int r;
380
381 assert(filename);
382 assert(lvalue);
383 assert(rvalue);
384 assert(data);
385
386 r = safe_atou16(rvalue, &v);
387 if (r < 0) {
d96edb2c 388 log_syntax(unit, LOG_WARNING, filename, line, r,
3e8afae5 389 "Failed to parse actor system priority '%s', ignoring: %m", rvalue);
99f68ef0
TJ
390 return 0;
391 }
392
393 if (v == 0) {
d96edb2c 394 log_syntax(unit, LOG_WARNING, filename, line, 0,
3e8afae5
YW
395 "Failed to parse actor system priority '%s'. Range is [1,65535], ignoring.",
396 rvalue);
99f68ef0
TJ
397 return 0;
398 }
399
400 b->ad_actor_sys_prio = v;
401
402 return 0;
403}
404
3e8afae5
YW
405int config_parse_ad_user_port_key(
406 const char *unit,
407 const char *filename,
408 unsigned line,
409 const char *section,
410 unsigned section_line,
411 const char *lvalue,
412 int ltype,
413 const char *rvalue,
414 void *data,
415 void *userdata) {
99f68ef0
TJ
416 Bond *b = userdata;
417 uint16_t v;
418 int r;
419
420 assert(filename);
421 assert(lvalue);
422 assert(rvalue);
423 assert(data);
424
425 r = safe_atou16(rvalue, &v);
426 if (r < 0) {
d96edb2c 427 log_syntax(unit, LOG_WARNING, filename, line, r,
3e8afae5 428 "Failed to parse user port key '%s', ignoring: %m", rvalue);
99f68ef0
TJ
429 return 0;
430 }
431
432 if (v > 1023) {
d96edb2c 433 log_syntax(unit, LOG_WARNING, filename, line, 0,
3e8afae5 434 "Failed to parse user port key '%s'. Range is [0…1023], ignoring.", rvalue);
99f68ef0
TJ
435 return 0;
436 }
437
438 b->ad_user_port_key = v;
439
440 return 0;
441}
442
1e2a490e
YW
443int config_parse_ad_actor_system(
444 const char *unit,
445 const char *filename,
446 unsigned line,
447 const char *section,
448 unsigned section_line,
449 const char *lvalue,
450 int ltype,
451 const char *rvalue,
452 void *data,
453 void *userdata) {
99f68ef0 454 Bond *b = userdata;
1e2a490e 455 struct ether_addr n;
99f68ef0
TJ
456 int r;
457
458 assert(filename);
459 assert(lvalue);
460 assert(rvalue);
461 assert(data);
462
1e2a490e 463 r = ether_addr_from_string(rvalue, &n);
99f68ef0 464 if (r < 0) {
d96edb2c 465 log_syntax(unit, LOG_WARNING, filename, line, r,
1e2a490e
YW
466 "Not a valid MAC address %s. Ignoring assignment: %m",
467 rvalue);
99f68ef0
TJ
468 return 0;
469 }
1e2a490e 470 if (ether_addr_is_null(&n) || (n.ether_addr_octet[0] & 0x01)) {
d96edb2c 471 log_syntax(unit, LOG_WARNING, filename, line, 0,
1e2a490e
YW
472 "Not a valid MAC address %s, can not be null or multicast. Ignoring assignment.",
473 rvalue);
99f68ef0
TJ
474 return 0;
475 }
476
1e2a490e 477 b->ad_actor_system = n;
99f68ef0
TJ
478
479 return 0;
480}
481
81bd37a8 482static void bond_done(NetDev *netdev) {
ae185f48 483 Bond *b;
81bd37a8
SS
484
485 assert(netdev);
ae185f48 486 b = BOND(netdev);
81bd37a8
SS
487 assert(b);
488
674c96fc 489 ordered_set_free(b->arp_ip_targets);
81bd37a8
SS
490}
491
aa9f1140 492static void bond_init(NetDev *netdev) {
ae185f48 493 Bond *b;
aa9f1140
TG
494
495 assert(netdev);
ae185f48
SS
496
497 b = BOND(netdev);
498
aa9f1140 499 assert(b);
fe8ac65b 500
aa9f1140 501 b->mode = _NETDEV_BOND_MODE_INVALID;
227cdf2c 502 b->xmit_hash_policy = _NETDEV_BOND_XMIT_HASH_POLICY_INVALID;
fb1021a2 503 b->lacp_rate = _NETDEV_BOND_LACP_RATE_INVALID;
81bd37a8
SS
504 b->ad_select = _NETDEV_BOND_AD_SELECT_INVALID;
505 b->fail_over_mac = _NETDEV_BOND_FAIL_OVER_MAC_INVALID;
506 b->arp_validate = _NETDEV_BOND_ARP_VALIDATE_INVALID;
507 b->arp_all_targets = _NETDEV_BOND_ARP_ALL_TARGETS_INVALID;
508 b->primary_reselect = _NETDEV_BOND_PRIMARY_RESELECT_INVALID;
509
510 b->all_slaves_active = false;
fde60a42 511 b->tlb_dynamic_lb = -1;
81bd37a8
SS
512
513 b->resend_igmp = RESEND_IGMP_DEFAULT;
514 b->packets_per_slave = PACKETS_PER_SLAVE_DEFAULT;
515 b->num_grat_arp = GRATUITOUS_ARP_DEFAULT;
516 b->lp_interval = LEARNING_PACKETS_INTERVAL_MIN_SEC;
fe8ac65b
SS
517}
518
3be1d7e0 519const NetDevVTable bond_vtable = {
aa9f1140
TG
520 .object_size = sizeof(Bond),
521 .init = bond_init,
81bd37a8 522 .done = bond_done,
130b812f 523 .sections = NETDEV_COMMON_SECTIONS "Bond\0",
3be1d7e0 524 .fill_message_create = netdev_bond_fill_message_create,
aa9f1140 525 .create_type = NETDEV_CREATE_MASTER,
daf0f8ca 526 .generate_mac = true,
3be1d7e0 527};