1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * drivers/net/bond/bond_options.c - bonding options
4 * Copyright (c) 2013 Jiri Pirko <jiri@resnulli.us>
5 * Copyright (c) 2013 Scott Feldman <sfeldma@cumulusnetworks.com>
6 */
7
8 #include <linux/errno.h>
9 #include <linux/if.h>
10 #include <linux/netdevice.h>
11 #include <linux/spinlock.h>
12 #include <linux/rcupdate.h>
13 #include <linux/ctype.h>
14 #include <linux/inet.h>
15 #include <linux/sched/signal.h>
16
17 #include <net/bonding.h>
18 #include <net/ndisc.h>
19
20 static int bond_option_active_slave_set(struct bonding *bond,
21 const struct bond_opt_value *newval);
22 static int bond_option_miimon_set(struct bonding *bond,
23 const struct bond_opt_value *newval);
24 static int bond_option_updelay_set(struct bonding *bond,
25 const struct bond_opt_value *newval);
26 static int bond_option_downdelay_set(struct bonding *bond,
27 const struct bond_opt_value *newval);
28 static int bond_option_peer_notif_delay_set(struct bonding *bond,
29 const struct bond_opt_value *newval);
30 static int bond_option_use_carrier_set(struct bonding *bond,
31 const struct bond_opt_value *newval);
32 static int bond_option_arp_interval_set(struct bonding *bond,
33 const struct bond_opt_value *newval);
34 static int bond_option_arp_ip_target_add(struct bonding *bond, __be32 target);
35 static int bond_option_arp_ip_target_rem(struct bonding *bond, __be32 target);
36 static int bond_option_arp_ip_targets_set(struct bonding *bond,
37 const struct bond_opt_value *newval);
38 static int bond_option_ns_ip6_targets_set(struct bonding *bond,
39 const struct bond_opt_value *newval);
40 static int bond_option_arp_validate_set(struct bonding *bond,
41 const struct bond_opt_value *newval);
42 static int bond_option_arp_all_targets_set(struct bonding *bond,
43 const struct bond_opt_value *newval);
44 static int bond_option_prio_set(struct bonding *bond,
45 const struct bond_opt_value *newval);
46 static int bond_option_primary_set(struct bonding *bond,
47 const struct bond_opt_value *newval);
48 static int bond_option_primary_reselect_set(struct bonding *bond,
49 const struct bond_opt_value *newval);
50 static int bond_option_fail_over_mac_set(struct bonding *bond,
51 const struct bond_opt_value *newval);
52 static int bond_option_xmit_hash_policy_set(struct bonding *bond,
53 const struct bond_opt_value *newval);
54 static int bond_option_resend_igmp_set(struct bonding *bond,
55 const struct bond_opt_value *newval);
56 static int bond_option_num_peer_notif_set(struct bonding *bond,
57 const struct bond_opt_value *newval);
58 static int bond_option_all_slaves_active_set(struct bonding *bond,
59 const struct bond_opt_value *newval);
60 static int bond_option_min_links_set(struct bonding *bond,
61 const struct bond_opt_value *newval);
62 static int bond_option_lp_interval_set(struct bonding *bond,
63 const struct bond_opt_value *newval);
64 static int bond_option_pps_set(struct bonding *bond,
65 const struct bond_opt_value *newval);
66 static int bond_option_lacp_active_set(struct bonding *bond,
67 const struct bond_opt_value *newval);
68 static int bond_option_lacp_rate_set(struct bonding *bond,
69 const struct bond_opt_value *newval);
70 static int bond_option_ad_select_set(struct bonding *bond,
71 const struct bond_opt_value *newval);
72 static int bond_option_queue_id_set(struct bonding *bond,
73 const struct bond_opt_value *newval);
74 static int bond_option_mode_set(struct bonding *bond,
75 const struct bond_opt_value *newval);
76 static int bond_option_slaves_set(struct bonding *bond,
77 const struct bond_opt_value *newval);
78 static int bond_option_tlb_dynamic_lb_set(struct bonding *bond,
79 const struct bond_opt_value *newval);
80 static int bond_option_ad_actor_sys_prio_set(struct bonding *bond,
81 const struct bond_opt_value *newval);
82 static int bond_option_ad_actor_system_set(struct bonding *bond,
83 const struct bond_opt_value *newval);
84 static int bond_option_ad_user_port_key_set(struct bonding *bond,
85 const struct bond_opt_value *newval);
86 static int bond_option_missed_max_set(struct bonding *bond,
87 const struct bond_opt_value *newval);
88 static int bond_option_coupled_control_set(struct bonding *bond,
89 const struct bond_opt_value *newval);
90
91 static const struct bond_opt_value bond_mode_tbl[] = {
92 { "balance-rr", BOND_MODE_ROUNDROBIN, BOND_VALFLAG_DEFAULT},
93 { "active-backup", BOND_MODE_ACTIVEBACKUP, 0},
94 { "balance-xor", BOND_MODE_XOR, 0},
95 { "broadcast", BOND_MODE_BROADCAST, 0},
96 { "802.3ad", BOND_MODE_8023AD, 0},
97 { "balance-tlb", BOND_MODE_TLB, 0},
98 { "balance-alb", BOND_MODE_ALB, 0},
99 { NULL, -1, 0},
100 };
101
102 static const struct bond_opt_value bond_pps_tbl[] = {
103 { "default", 1, BOND_VALFLAG_DEFAULT},
104 { "maxval", USHRT_MAX, BOND_VALFLAG_MAX},
105 { NULL, -1, 0},
106 };
107
108 static const struct bond_opt_value bond_xmit_hashtype_tbl[] = {
109 { "layer2", BOND_XMIT_POLICY_LAYER2, BOND_VALFLAG_DEFAULT},
110 { "layer3+4", BOND_XMIT_POLICY_LAYER34, 0},
111 { "layer2+3", BOND_XMIT_POLICY_LAYER23, 0},
112 { "encap2+3", BOND_XMIT_POLICY_ENCAP23, 0},
113 { "encap3+4", BOND_XMIT_POLICY_ENCAP34, 0},
114 { "vlan+srcmac", BOND_XMIT_POLICY_VLAN_SRCMAC, 0},
115 { NULL, -1, 0},
116 };
117
118 static const struct bond_opt_value bond_arp_validate_tbl[] = {
119 { "none", BOND_ARP_VALIDATE_NONE, BOND_VALFLAG_DEFAULT},
120 { "active", BOND_ARP_VALIDATE_ACTIVE, 0},
121 { "backup", BOND_ARP_VALIDATE_BACKUP, 0},
122 { "all", BOND_ARP_VALIDATE_ALL, 0},
123 { "filter", BOND_ARP_FILTER, 0},
124 { "filter_active", BOND_ARP_FILTER_ACTIVE, 0},
125 { "filter_backup", BOND_ARP_FILTER_BACKUP, 0},
126 { NULL, -1, 0},
127 };
128
129 static const struct bond_opt_value bond_arp_all_targets_tbl[] = {
130 { "any", BOND_ARP_TARGETS_ANY, BOND_VALFLAG_DEFAULT},
131 { "all", BOND_ARP_TARGETS_ALL, 0},
132 { NULL, -1, 0},
133 };
134
135 static const struct bond_opt_value bond_fail_over_mac_tbl[] = {
136 { "none", BOND_FOM_NONE, BOND_VALFLAG_DEFAULT},
137 { "active", BOND_FOM_ACTIVE, 0},
138 { "follow", BOND_FOM_FOLLOW, 0},
139 { NULL, -1, 0},
140 };
141
142 static const struct bond_opt_value bond_intmax_tbl[] = {
143 { "off", 0, BOND_VALFLAG_DEFAULT},
144 { "maxval", INT_MAX, BOND_VALFLAG_MAX},
145 { NULL, -1, 0}
146 };
147
148 static const struct bond_opt_value bond_lacp_active[] = {
149 { "off", 0, 0},
150 { "on", 1, BOND_VALFLAG_DEFAULT},
151 { NULL, -1, 0}
152 };
153
154 static const struct bond_opt_value bond_lacp_rate_tbl[] = {
155 { "slow", AD_LACP_SLOW, 0},
156 { "fast", AD_LACP_FAST, 0},
157 { NULL, -1, 0},
158 };
159
160 static const struct bond_opt_value bond_ad_select_tbl[] = {
161 { "stable", BOND_AD_STABLE, BOND_VALFLAG_DEFAULT},
162 { "bandwidth", BOND_AD_BANDWIDTH, 0},
163 { "count", BOND_AD_COUNT, 0},
164 { NULL, -1, 0},
165 };
166
167 static const struct bond_opt_value bond_num_peer_notif_tbl[] = {
168 { "off", 0, 0},
169 { "maxval", 255, BOND_VALFLAG_MAX},
170 { "default", 1, BOND_VALFLAG_DEFAULT},
171 { NULL, -1, 0}
172 };
173
174 static const struct bond_opt_value bond_peer_notif_delay_tbl[] = {
175 { "off", 0, 0},
176 { "maxval", 300000, BOND_VALFLAG_MAX},
177 { NULL, -1, 0}
178 };
179
180 static const struct bond_opt_value bond_primary_reselect_tbl[] = {
181 { "always", BOND_PRI_RESELECT_ALWAYS, BOND_VALFLAG_DEFAULT},
182 { "better", BOND_PRI_RESELECT_BETTER, 0},
183 { "failure", BOND_PRI_RESELECT_FAILURE, 0},
184 { NULL, -1},
185 };
186
187 static const struct bond_opt_value bond_use_carrier_tbl[] = {
188 { "off", 0, 0},
189 { "on", 1, BOND_VALFLAG_DEFAULT},
190 { NULL, -1, 0}
191 };
192
193 static const struct bond_opt_value bond_all_slaves_active_tbl[] = {
194 { "off", 0, BOND_VALFLAG_DEFAULT},
195 { "on", 1, 0},
196 { NULL, -1, 0}
197 };
198
199 static const struct bond_opt_value bond_resend_igmp_tbl[] = {
200 { "off", 0, 0},
201 { "maxval", 255, BOND_VALFLAG_MAX},
202 { "default", 1, BOND_VALFLAG_DEFAULT},
203 { NULL, -1, 0}
204 };
205
206 static const struct bond_opt_value bond_lp_interval_tbl[] = {
207 { "minval", 1, BOND_VALFLAG_MIN | BOND_VALFLAG_DEFAULT},
208 { "maxval", INT_MAX, BOND_VALFLAG_MAX},
209 { NULL, -1, 0},
210 };
211
212 static const struct bond_opt_value bond_tlb_dynamic_lb_tbl[] = {
213 { "off", 0, 0},
214 { "on", 1, BOND_VALFLAG_DEFAULT},
215 { NULL, -1, 0}
216 };
217
218 static const struct bond_opt_value bond_ad_actor_sys_prio_tbl[] = {
219 { "minval", 1, BOND_VALFLAG_MIN},
220 { "maxval", 65535, BOND_VALFLAG_MAX | BOND_VALFLAG_DEFAULT},
221 { NULL, -1, 0},
222 };
223
224 static const struct bond_opt_value bond_ad_user_port_key_tbl[] = {
225 { "minval", 0, BOND_VALFLAG_MIN | BOND_VALFLAG_DEFAULT},
226 { "maxval", 1023, BOND_VALFLAG_MAX},
227 { NULL, -1, 0},
228 };
229
230 static const struct bond_opt_value bond_missed_max_tbl[] = {
231 { "minval", 1, BOND_VALFLAG_MIN},
232 { "maxval", 255, BOND_VALFLAG_MAX},
233 { "default", 2, BOND_VALFLAG_DEFAULT},
234 { NULL, -1, 0},
235 };
236
237 static const struct bond_opt_value bond_coupled_control_tbl[] = {
238 { "on", 1, BOND_VALFLAG_DEFAULT},
239 { "off", 0, 0},
240 { NULL, -1, 0},
241 };
242
243 static const struct bond_option bond_opts[BOND_OPT_LAST] = {
244 [BOND_OPT_MODE] = {
245 .id = BOND_OPT_MODE,
246 .name = "mode",
247 .desc = "bond device mode",
248 .flags = BOND_OPTFLAG_NOSLAVES | BOND_OPTFLAG_IFDOWN,
249 .values = bond_mode_tbl,
250 .set = bond_option_mode_set
251 },
252 [BOND_OPT_PACKETS_PER_SLAVE] = {
253 .id = BOND_OPT_PACKETS_PER_SLAVE,
254 .name = "packets_per_slave",
255 .desc = "Packets to send per slave in RR mode",
256 .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_ROUNDROBIN)),
257 .values = bond_pps_tbl,
258 .set = bond_option_pps_set
259 },
260 [BOND_OPT_XMIT_HASH] = {
261 .id = BOND_OPT_XMIT_HASH,
262 .name = "xmit_hash_policy",
263 .desc = "balance-xor, 802.3ad, and tlb hashing method",
264 .values = bond_xmit_hashtype_tbl,
265 .set = bond_option_xmit_hash_policy_set
266 },
267 [BOND_OPT_ARP_VALIDATE] = {
268 .id = BOND_OPT_ARP_VALIDATE,
269 .name = "arp_validate",
270 .desc = "validate src/dst of ARP probes",
271 .unsuppmodes = BIT(BOND_MODE_8023AD) | BIT(BOND_MODE_TLB) |
272 BIT(BOND_MODE_ALB),
273 .values = bond_arp_validate_tbl,
274 .set = bond_option_arp_validate_set
275 },
276 [BOND_OPT_ARP_ALL_TARGETS] = {
277 .id = BOND_OPT_ARP_ALL_TARGETS,
278 .name = "arp_all_targets",
279 .desc = "fail on any/all arp targets timeout",
280 .values = bond_arp_all_targets_tbl,
281 .set = bond_option_arp_all_targets_set
282 },
283 [BOND_OPT_FAIL_OVER_MAC] = {
284 .id = BOND_OPT_FAIL_OVER_MAC,
285 .name = "fail_over_mac",
286 .desc = "For active-backup, do not set all slaves to the same MAC",
287 .flags = BOND_OPTFLAG_NOSLAVES,
288 .values = bond_fail_over_mac_tbl,
289 .set = bond_option_fail_over_mac_set
290 },
291 [BOND_OPT_ARP_INTERVAL] = {
292 .id = BOND_OPT_ARP_INTERVAL,
293 .name = "arp_interval",
294 .desc = "arp interval in milliseconds",
295 .unsuppmodes = BIT(BOND_MODE_8023AD) | BIT(BOND_MODE_TLB) |
296 BIT(BOND_MODE_ALB),
297 .values = bond_intmax_tbl,
298 .set = bond_option_arp_interval_set
299 },
300 [BOND_OPT_MISSED_MAX] = {
301 .id = BOND_OPT_MISSED_MAX,
302 .name = "arp_missed_max",
303 .desc = "Maximum number of missed ARP interval",
304 .unsuppmodes = BIT(BOND_MODE_8023AD) | BIT(BOND_MODE_TLB) |
305 BIT(BOND_MODE_ALB),
306 .values = bond_missed_max_tbl,
307 .set = bond_option_missed_max_set
308 },
309 [BOND_OPT_ARP_TARGETS] = {
310 .id = BOND_OPT_ARP_TARGETS,
311 .name = "arp_ip_target",
312 .desc = "arp targets in n.n.n.n form",
313 .flags = BOND_OPTFLAG_RAWVAL,
314 .set = bond_option_arp_ip_targets_set
315 },
316 [BOND_OPT_NS_TARGETS] = {
317 .id = BOND_OPT_NS_TARGETS,
318 .name = "ns_ip6_target",
319 .desc = "NS targets in ffff:ffff::ffff:ffff form",
320 .flags = BOND_OPTFLAG_RAWVAL,
321 .set = bond_option_ns_ip6_targets_set
322 },
323 [BOND_OPT_DOWNDELAY] = {
324 .id = BOND_OPT_DOWNDELAY,
325 .name = "downdelay",
326 .desc = "Delay before considering link down, in milliseconds",
327 .values = bond_intmax_tbl,
328 .set = bond_option_downdelay_set
329 },
330 [BOND_OPT_UPDELAY] = {
331 .id = BOND_OPT_UPDELAY,
332 .name = "updelay",
333 .desc = "Delay before considering link up, in milliseconds",
334 .values = bond_intmax_tbl,
335 .set = bond_option_updelay_set
336 },
337 [BOND_OPT_LACP_ACTIVE] = {
338 .id = BOND_OPT_LACP_ACTIVE,
339 .name = "lacp_active",
340 .desc = "Send LACPDU frames with configured lacp rate or acts as speak when spoken to",
341 .flags = BOND_OPTFLAG_IFDOWN,
342 .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_8023AD)),
343 .values = bond_lacp_active,
344 .set = bond_option_lacp_active_set
345 },
346 [BOND_OPT_LACP_RATE] = {
347 .id = BOND_OPT_LACP_RATE,
348 .name = "lacp_rate",
349 .desc = "LACPDU tx rate to request from 802.3ad partner",
350 .flags = BOND_OPTFLAG_IFDOWN,
351 .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_8023AD)),
352 .values = bond_lacp_rate_tbl,
353 .set = bond_option_lacp_rate_set
354 },
355 [BOND_OPT_MINLINKS] = {
356 .id = BOND_OPT_MINLINKS,
357 .name = "min_links",
358 .desc = "Minimum number of available links before turning on carrier",
359 .values = bond_intmax_tbl,
360 .set = bond_option_min_links_set
361 },
362 [BOND_OPT_AD_SELECT] = {
363 .id = BOND_OPT_AD_SELECT,
364 .name = "ad_select",
365 .desc = "803.ad aggregation selection logic",
366 .flags = BOND_OPTFLAG_IFDOWN,
367 .values = bond_ad_select_tbl,
368 .set = bond_option_ad_select_set
369 },
370 [BOND_OPT_NUM_PEER_NOTIF] = {
371 .id = BOND_OPT_NUM_PEER_NOTIF,
372 .name = "num_unsol_na",
373 .desc = "Number of peer notifications to send on failover event",
374 .values = bond_num_peer_notif_tbl,
375 .set = bond_option_num_peer_notif_set
376 },
377 [BOND_OPT_MIIMON] = {
378 .id = BOND_OPT_MIIMON,
379 .name = "miimon",
380 .desc = "Link check interval in milliseconds",
381 .values = bond_intmax_tbl,
382 .set = bond_option_miimon_set
383 },
384 [BOND_OPT_PRIO] = {
385 .id = BOND_OPT_PRIO,
386 .name = "prio",
387 .desc = "Link priority for failover re-selection",
388 .flags = BOND_OPTFLAG_RAWVAL,
389 .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_ACTIVEBACKUP) |
390 BIT(BOND_MODE_TLB) |
391 BIT(BOND_MODE_ALB)),
392 .set = bond_option_prio_set
393 },
394 [BOND_OPT_PRIMARY] = {
395 .id = BOND_OPT_PRIMARY,
396 .name = "primary",
397 .desc = "Primary network device to use",
398 .flags = BOND_OPTFLAG_RAWVAL,
399 .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_ACTIVEBACKUP) |
400 BIT(BOND_MODE_TLB) |
401 BIT(BOND_MODE_ALB)),
402 .set = bond_option_primary_set
403 },
404 [BOND_OPT_PRIMARY_RESELECT] = {
405 .id = BOND_OPT_PRIMARY_RESELECT,
406 .name = "primary_reselect",
407 .desc = "Reselect primary slave once it comes up",
408 .values = bond_primary_reselect_tbl,
409 .set = bond_option_primary_reselect_set
410 },
411 [BOND_OPT_USE_CARRIER] = {
412 .id = BOND_OPT_USE_CARRIER,
413 .name = "use_carrier",
414 .desc = "Use netif_carrier_ok (vs MII ioctls) in miimon",
415 .values = bond_use_carrier_tbl,
416 .set = bond_option_use_carrier_set
417 },
418 [BOND_OPT_ACTIVE_SLAVE] = {
419 .id = BOND_OPT_ACTIVE_SLAVE,
420 .name = "active_slave",
421 .desc = "Currently active slave",
422 .flags = BOND_OPTFLAG_RAWVAL,
423 .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_ACTIVEBACKUP) |
424 BIT(BOND_MODE_TLB) |
425 BIT(BOND_MODE_ALB)),
426 .set = bond_option_active_slave_set
427 },
428 [BOND_OPT_QUEUE_ID] = {
429 .id = BOND_OPT_QUEUE_ID,
430 .name = "queue_id",
431 .desc = "Set queue id of a slave",
432 .flags = BOND_OPTFLAG_RAWVAL,
433 .set = bond_option_queue_id_set
434 },
435 [BOND_OPT_ALL_SLAVES_ACTIVE] = {
436 .id = BOND_OPT_ALL_SLAVES_ACTIVE,
437 .name = "all_slaves_active",
438 .desc = "Keep all frames received on an interface by setting active flag for all slaves",
439 .values = bond_all_slaves_active_tbl,
440 .set = bond_option_all_slaves_active_set
441 },
442 [BOND_OPT_RESEND_IGMP] = {
443 .id = BOND_OPT_RESEND_IGMP,
444 .name = "resend_igmp",
445 .desc = "Number of IGMP membership reports to send on link failure",
446 .values = bond_resend_igmp_tbl,
447 .set = bond_option_resend_igmp_set
448 },
449 [BOND_OPT_LP_INTERVAL] = {
450 .id = BOND_OPT_LP_INTERVAL,
451 .name = "lp_interval",
452 .desc = "The number of seconds between instances where the bonding driver sends learning packets to each slave's peer switch",
453 .values = bond_lp_interval_tbl,
454 .set = bond_option_lp_interval_set
455 },
456 [BOND_OPT_SLAVES] = {
457 .id = BOND_OPT_SLAVES,
458 .name = "slaves",
459 .desc = "Slave membership management",
460 .flags = BOND_OPTFLAG_RAWVAL,
461 .set = bond_option_slaves_set
462 },
463 [BOND_OPT_TLB_DYNAMIC_LB] = {
464 .id = BOND_OPT_TLB_DYNAMIC_LB,
465 .name = "tlb_dynamic_lb",
466 .desc = "Enable dynamic flow shuffling",
467 .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_TLB) | BIT(BOND_MODE_ALB)),
468 .values = bond_tlb_dynamic_lb_tbl,
469 .flags = BOND_OPTFLAG_IFDOWN,
470 .set = bond_option_tlb_dynamic_lb_set,
471 },
472 [BOND_OPT_AD_ACTOR_SYS_PRIO] = {
473 .id = BOND_OPT_AD_ACTOR_SYS_PRIO,
474 .name = "ad_actor_sys_prio",
475 .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_8023AD)),
476 .values = bond_ad_actor_sys_prio_tbl,
477 .set = bond_option_ad_actor_sys_prio_set,
478 },
479 [BOND_OPT_AD_ACTOR_SYSTEM] = {
480 .id = BOND_OPT_AD_ACTOR_SYSTEM,
481 .name = "ad_actor_system",
482 .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_8023AD)),
483 .flags = BOND_OPTFLAG_RAWVAL,
484 .set = bond_option_ad_actor_system_set,
485 },
486 [BOND_OPT_AD_USER_PORT_KEY] = {
487 .id = BOND_OPT_AD_USER_PORT_KEY,
488 .name = "ad_user_port_key",
489 .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_8023AD)),
490 .flags = BOND_OPTFLAG_IFDOWN,
491 .values = bond_ad_user_port_key_tbl,
492 .set = bond_option_ad_user_port_key_set,
493 },
494 [BOND_OPT_NUM_PEER_NOTIF_ALIAS] = {
495 .id = BOND_OPT_NUM_PEER_NOTIF_ALIAS,
496 .name = "num_grat_arp",
497 .desc = "Number of peer notifications to send on failover event",
498 .values = bond_num_peer_notif_tbl,
499 .set = bond_option_num_peer_notif_set
500 },
501 [BOND_OPT_PEER_NOTIF_DELAY] = {
502 .id = BOND_OPT_PEER_NOTIF_DELAY,
503 .name = "peer_notif_delay",
504 .desc = "Delay between each peer notification on failover event, in milliseconds",
505 .values = bond_peer_notif_delay_tbl,
506 .set = bond_option_peer_notif_delay_set
507 },
508 [BOND_OPT_COUPLED_CONTROL] = {
509 .id = BOND_OPT_COUPLED_CONTROL,
510 .name = "coupled_control",
511 .desc = "Opt into using coupled control MUX for LACP states",
512 .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_8023AD)),
513 .flags = BOND_OPTFLAG_IFDOWN,
514 .values = bond_coupled_control_tbl,
515 .set = bond_option_coupled_control_set,
516 }
517 };
518
519 /* Searches for an option by name */
bond_opt_get_by_name(const char * name)520 const struct bond_option *bond_opt_get_by_name(const char *name)
521 {
522 const struct bond_option *opt;
523 int option;
524
525 for (option = 0; option < BOND_OPT_LAST; option++) {
526 opt = bond_opt_get(option);
527 if (opt && !strcmp(opt->name, name))
528 return opt;
529 }
530
531 return NULL;
532 }
533
534 /* Searches for a value in opt's values[] table */
bond_opt_get_val(unsigned int option,u64 val)535 const struct bond_opt_value *bond_opt_get_val(unsigned int option, u64 val)
536 {
537 const struct bond_option *opt;
538 int i;
539
540 opt = bond_opt_get(option);
541 if (WARN_ON(!opt))
542 return NULL;
543 for (i = 0; opt->values && opt->values[i].string; i++)
544 if (opt->values[i].value == val)
545 return &opt->values[i];
546
547 return NULL;
548 }
549
550 /* Searches for a value in opt's values[] table which matches the flagmask */
bond_opt_get_flags(const struct bond_option * opt,u32 flagmask)551 static const struct bond_opt_value *bond_opt_get_flags(const struct bond_option *opt,
552 u32 flagmask)
553 {
554 int i;
555
556 for (i = 0; opt->values && opt->values[i].string; i++)
557 if (opt->values[i].flags & flagmask)
558 return &opt->values[i];
559
560 return NULL;
561 }
562
563 /* If maxval is missing then there's no range to check. In case minval is
564 * missing then it's considered to be 0.
565 */
bond_opt_check_range(const struct bond_option * opt,u64 val)566 static bool bond_opt_check_range(const struct bond_option *opt, u64 val)
567 {
568 const struct bond_opt_value *minval, *maxval;
569
570 minval = bond_opt_get_flags(opt, BOND_VALFLAG_MIN);
571 maxval = bond_opt_get_flags(opt, BOND_VALFLAG_MAX);
572 if (!maxval || (minval && val < minval->value) || val > maxval->value)
573 return false;
574
575 return true;
576 }
577
578 /**
579 * bond_opt_parse - parse option value
580 * @opt: the option to parse against
581 * @val: value to parse
582 *
583 * This function tries to extract the value from @val and check if it's
584 * a possible match for the option and returns NULL if a match isn't found,
585 * or the struct_opt_value that matched. It also strips the new line from
586 * @val->string if it's present.
587 */
bond_opt_parse(const struct bond_option * opt,struct bond_opt_value * val)588 const struct bond_opt_value *bond_opt_parse(const struct bond_option *opt,
589 struct bond_opt_value *val)
590 {
591 char *p, valstr[BOND_OPT_MAX_NAMELEN + 1] = { 0, };
592 const struct bond_opt_value *tbl;
593 const struct bond_opt_value *ret = NULL;
594 bool checkval;
595 int i, rv;
596
597 /* No parsing if the option wants a raw val */
598 if (opt->flags & BOND_OPTFLAG_RAWVAL)
599 return val;
600
601 tbl = opt->values;
602 if (!tbl)
603 goto out;
604
605 /* ULLONG_MAX is used to bypass string processing */
606 checkval = val->value != ULLONG_MAX;
607 if (!checkval) {
608 if (!val->string)
609 goto out;
610 p = strchr(val->string, '\n');
611 if (p)
612 *p = '\0';
613 for (p = val->string; *p; p++)
614 if (!(isdigit(*p) || isspace(*p)))
615 break;
616 /* The following code extracts the string to match or the value
617 * and sets checkval appropriately
618 */
619 if (*p) {
620 rv = sscanf(val->string, "%32s", valstr);
621 } else {
622 rv = sscanf(val->string, "%llu", &val->value);
623 checkval = true;
624 }
625 if (!rv)
626 goto out;
627 }
628
629 for (i = 0; tbl[i].string; i++) {
630 /* Check for exact match */
631 if (checkval) {
632 if (val->value == tbl[i].value)
633 ret = &tbl[i];
634 } else {
635 if (!strcmp(valstr, "default") &&
636 (tbl[i].flags & BOND_VALFLAG_DEFAULT))
637 ret = &tbl[i];
638
639 if (!strcmp(valstr, tbl[i].string))
640 ret = &tbl[i];
641 }
642 /* Found an exact match */
643 if (ret)
644 goto out;
645 }
646 /* Possible range match */
647 if (checkval && bond_opt_check_range(opt, val->value))
648 ret = val;
649 out:
650 return ret;
651 }
652
653 /* Check opt's dependencies against bond mode and currently set options */
bond_opt_check_deps(struct bonding * bond,const struct bond_option * opt)654 static int bond_opt_check_deps(struct bonding *bond,
655 const struct bond_option *opt)
656 {
657 struct bond_params *params = &bond->params;
658
659 if (test_bit(params->mode, &opt->unsuppmodes))
660 return -EACCES;
661 if ((opt->flags & BOND_OPTFLAG_NOSLAVES) && bond_has_slaves(bond))
662 return -ENOTEMPTY;
663 if ((opt->flags & BOND_OPTFLAG_IFDOWN) && (bond->dev->flags & IFF_UP))
664 return -EBUSY;
665
666 return 0;
667 }
668
bond_opt_dep_print(struct bonding * bond,const struct bond_option * opt,struct nlattr * bad_attr,struct netlink_ext_ack * extack)669 static void bond_opt_dep_print(struct bonding *bond,
670 const struct bond_option *opt,
671 struct nlattr *bad_attr,
672 struct netlink_ext_ack *extack)
673 {
674 const struct bond_opt_value *modeval;
675 struct bond_params *params;
676
677 params = &bond->params;
678 modeval = bond_opt_get_val(BOND_OPT_MODE, params->mode);
679 if (test_bit(params->mode, &opt->unsuppmodes)) {
680 netdev_err(bond->dev, "option %s: mode dependency failed, not supported in mode %s(%llu)\n",
681 opt->name, modeval->string, modeval->value);
682 NL_SET_ERR_MSG_ATTR(extack, bad_attr,
683 "option not supported in mode");
684 }
685 }
686
bond_opt_error_interpret(struct bonding * bond,const struct bond_option * opt,int error,const struct bond_opt_value * val,struct nlattr * bad_attr,struct netlink_ext_ack * extack)687 static void bond_opt_error_interpret(struct bonding *bond,
688 const struct bond_option *opt,
689 int error, const struct bond_opt_value *val,
690 struct nlattr *bad_attr,
691 struct netlink_ext_ack *extack)
692 {
693 const struct bond_opt_value *minval, *maxval;
694 char *p;
695
696 switch (error) {
697 case -EINVAL:
698 NL_SET_ERR_MSG_ATTR(extack, bad_attr, "invalid option value");
699 if (val) {
700 if (val->string) {
701 /* sometimes RAWVAL opts may have new lines */
702 p = strchr(val->string, '\n');
703 if (p)
704 *p = '\0';
705 netdev_err(bond->dev, "option %s: invalid value (%s)\n",
706 opt->name, val->string);
707 } else {
708 netdev_err(bond->dev, "option %s: invalid value (%llu)\n",
709 opt->name, val->value);
710 }
711 }
712 minval = bond_opt_get_flags(opt, BOND_VALFLAG_MIN);
713 maxval = bond_opt_get_flags(opt, BOND_VALFLAG_MAX);
714 if (!maxval)
715 break;
716 netdev_err(bond->dev, "option %s: allowed values %llu - %llu\n",
717 opt->name, minval ? minval->value : 0, maxval->value);
718 break;
719 case -EACCES:
720 bond_opt_dep_print(bond, opt, bad_attr, extack);
721 break;
722 case -ENOTEMPTY:
723 NL_SET_ERR_MSG_ATTR(extack, bad_attr,
724 "unable to set option because the bond device has slaves");
725 netdev_err(bond->dev, "option %s: unable to set because the bond device has slaves\n",
726 opt->name);
727 break;
728 case -EBUSY:
729 NL_SET_ERR_MSG_ATTR(extack, bad_attr,
730 "unable to set option because the bond is up");
731 netdev_err(bond->dev, "option %s: unable to set because the bond device is up\n",
732 opt->name);
733 break;
734 case -ENODEV:
735 if (val && val->string) {
736 p = strchr(val->string, '\n');
737 if (p)
738 *p = '\0';
739 netdev_err(bond->dev, "option %s: interface %s does not exist!\n",
740 opt->name, val->string);
741 NL_SET_ERR_MSG_ATTR(extack, bad_attr,
742 "interface does not exist");
743 }
744 break;
745 default:
746 break;
747 }
748 }
749
750 /**
751 * __bond_opt_set - set a bonding option
752 * @bond: target bond device
753 * @option: option to set
754 * @val: value to set it to
755 * @bad_attr: netlink attribue that caused the error
756 * @extack: extended netlink error structure, used when an error message
757 * needs to be returned to the caller via netlink
758 *
759 * This function is used to change the bond's option value, it can be
760 * used for both enabling/changing an option and for disabling it. RTNL lock
761 * must be obtained before calling this function.
762 */
__bond_opt_set(struct bonding * bond,unsigned int option,struct bond_opt_value * val,struct nlattr * bad_attr,struct netlink_ext_ack * extack)763 int __bond_opt_set(struct bonding *bond,
764 unsigned int option, struct bond_opt_value *val,
765 struct nlattr *bad_attr, struct netlink_ext_ack *extack)
766 {
767 const struct bond_opt_value *retval = NULL;
768 const struct bond_option *opt;
769 int ret = -ENOENT;
770
771 ASSERT_RTNL();
772
773 opt = bond_opt_get(option);
774 if (WARN_ON(!val) || WARN_ON(!opt))
775 goto out;
776 ret = bond_opt_check_deps(bond, opt);
777 if (ret)
778 goto out;
779 retval = bond_opt_parse(opt, val);
780 if (!retval) {
781 ret = -EINVAL;
782 goto out;
783 }
784 ret = opt->set(bond, retval);
785 out:
786 if (ret)
787 bond_opt_error_interpret(bond, opt, ret, val, bad_attr, extack);
788
789 return ret;
790 }
791 /**
792 * __bond_opt_set_notify - set a bonding option
793 * @bond: target bond device
794 * @option: option to set
795 * @val: value to set it to
796 *
797 * This function is used to change the bond's option value and trigger
798 * a notification to user sapce. It can be used for both enabling/changing
799 * an option and for disabling it. RTNL lock must be obtained before calling
800 * this function.
801 */
__bond_opt_set_notify(struct bonding * bond,unsigned int option,struct bond_opt_value * val)802 int __bond_opt_set_notify(struct bonding *bond,
803 unsigned int option, struct bond_opt_value *val)
804 {
805 int ret;
806
807 ASSERT_RTNL();
808
809 ret = __bond_opt_set(bond, option, val, NULL, NULL);
810
811 if (!ret && (bond->dev->reg_state == NETREG_REGISTERED))
812 call_netdevice_notifiers(NETDEV_CHANGEINFODATA, bond->dev);
813
814 return ret;
815 }
816
817 /**
818 * bond_opt_tryset_rtnl - try to acquire rtnl and call __bond_opt_set
819 * @bond: target bond device
820 * @option: option to set
821 * @buf: value to set it to
822 *
823 * This function tries to acquire RTNL without blocking and if successful
824 * calls __bond_opt_set. It is mainly used for sysfs option manipulation.
825 */
bond_opt_tryset_rtnl(struct bonding * bond,unsigned int option,char * buf)826 int bond_opt_tryset_rtnl(struct bonding *bond, unsigned int option, char *buf)
827 {
828 struct bond_opt_value optval;
829 int ret;
830
831 if (!rtnl_trylock())
832 return restart_syscall();
833 bond_opt_initstr(&optval, buf);
834 ret = __bond_opt_set_notify(bond, option, &optval);
835 rtnl_unlock();
836
837 return ret;
838 }
839
840 /**
841 * bond_opt_get - get a pointer to an option
842 * @option: option for which to return a pointer
843 *
844 * This function checks if option is valid and if so returns a pointer
845 * to its entry in the bond_opts[] option array.
846 */
bond_opt_get(unsigned int option)847 const struct bond_option *bond_opt_get(unsigned int option)
848 {
849 if (!BOND_OPT_VALID(option))
850 return NULL;
851
852 return &bond_opts[option];
853 }
854
bond_set_xfrm_features(struct bonding * bond)855 static bool bond_set_xfrm_features(struct bonding *bond)
856 {
857 if (!IS_ENABLED(CONFIG_XFRM_OFFLOAD))
858 return false;
859
860 if (BOND_MODE(bond) == BOND_MODE_ACTIVEBACKUP)
861 bond->dev->wanted_features |= BOND_XFRM_FEATURES;
862 else
863 bond->dev->wanted_features &= ~BOND_XFRM_FEATURES;
864
865 return true;
866 }
867
bond_option_mode_set(struct bonding * bond,const struct bond_opt_value * newval)868 static int bond_option_mode_set(struct bonding *bond,
869 const struct bond_opt_value *newval)
870 {
871 if (!bond_mode_uses_arp(newval->value)) {
872 if (bond->params.arp_interval) {
873 netdev_dbg(bond->dev, "%s mode is incompatible with arp monitoring, start mii monitoring\n",
874 newval->string);
875 /* disable arp monitoring */
876 bond->params.arp_interval = 0;
877 }
878
879 if (!bond->params.miimon) {
880 /* set miimon to default value */
881 bond->params.miimon = BOND_DEFAULT_MIIMON;
882 netdev_dbg(bond->dev, "Setting MII monitoring interval to %d\n",
883 bond->params.miimon);
884 }
885 }
886
887 if (newval->value == BOND_MODE_ALB)
888 bond->params.tlb_dynamic_lb = 1;
889
890 /* don't cache arp_validate between modes */
891 bond->params.arp_validate = BOND_ARP_VALIDATE_NONE;
892 bond->params.mode = newval->value;
893
894 if (bond->dev->reg_state == NETREG_REGISTERED) {
895 bool update = false;
896
897 update |= bond_set_xfrm_features(bond);
898
899 if (update)
900 netdev_update_features(bond->dev);
901 }
902
903 bond_xdp_set_features(bond->dev);
904
905 return 0;
906 }
907
bond_option_active_slave_set(struct bonding * bond,const struct bond_opt_value * newval)908 static int bond_option_active_slave_set(struct bonding *bond,
909 const struct bond_opt_value *newval)
910 {
911 char ifname[IFNAMSIZ] = { 0, };
912 struct net_device *slave_dev;
913 int ret = 0;
914
915 sscanf(newval->string, "%15s", ifname); /* IFNAMSIZ */
916 if (!strlen(ifname) || newval->string[0] == '\n') {
917 slave_dev = NULL;
918 } else {
919 slave_dev = __dev_get_by_name(dev_net(bond->dev), ifname);
920 if (!slave_dev)
921 return -ENODEV;
922 }
923
924 if (slave_dev) {
925 if (!netif_is_bond_slave(slave_dev)) {
926 slave_err(bond->dev, slave_dev, "Device is not bonding slave\n");
927 return -EINVAL;
928 }
929
930 if (bond->dev != netdev_master_upper_dev_get(slave_dev)) {
931 slave_err(bond->dev, slave_dev, "Device is not our slave\n");
932 return -EINVAL;
933 }
934 }
935
936 block_netpoll_tx();
937 /* check to see if we are clearing active */
938 if (!slave_dev) {
939 netdev_dbg(bond->dev, "Clearing current active slave\n");
940 bond_change_active_slave(bond, NULL);
941 bond_select_active_slave(bond);
942 } else {
943 struct slave *old_active = rtnl_dereference(bond->curr_active_slave);
944 struct slave *new_active = bond_slave_get_rtnl(slave_dev);
945
946 BUG_ON(!new_active);
947
948 if (new_active == old_active) {
949 /* do nothing */
950 slave_dbg(bond->dev, new_active->dev, "is already the current active slave\n");
951 } else {
952 if (old_active && (new_active->link == BOND_LINK_UP) &&
953 bond_slave_is_up(new_active)) {
954 slave_dbg(bond->dev, new_active->dev, "Setting as active slave\n");
955 bond_change_active_slave(bond, new_active);
956 } else {
957 slave_err(bond->dev, new_active->dev, "Could not set as active slave; either %s is down or the link is down\n",
958 new_active->dev->name);
959 ret = -EINVAL;
960 }
961 }
962 }
963 unblock_netpoll_tx();
964
965 return ret;
966 }
967
968 /* There are two tricky bits here. First, if MII monitoring is activated, then
969 * we must disable ARP monitoring. Second, if the timer isn't running, we must
970 * start it.
971 */
bond_option_miimon_set(struct bonding * bond,const struct bond_opt_value * newval)972 static int bond_option_miimon_set(struct bonding *bond,
973 const struct bond_opt_value *newval)
974 {
975 netdev_dbg(bond->dev, "Setting MII monitoring interval to %llu\n",
976 newval->value);
977 bond->params.miimon = newval->value;
978 if (bond->params.updelay)
979 netdev_dbg(bond->dev, "Note: Updating updelay (to %d) since it is a multiple of the miimon value\n",
980 bond->params.updelay * bond->params.miimon);
981 if (bond->params.downdelay)
982 netdev_dbg(bond->dev, "Note: Updating downdelay (to %d) since it is a multiple of the miimon value\n",
983 bond->params.downdelay * bond->params.miimon);
984 if (bond->params.peer_notif_delay)
985 netdev_dbg(bond->dev, "Note: Updating peer_notif_delay (to %d) since it is a multiple of the miimon value\n",
986 bond->params.peer_notif_delay * bond->params.miimon);
987 if (newval->value && bond->params.arp_interval) {
988 netdev_dbg(bond->dev, "MII monitoring cannot be used with ARP monitoring - disabling ARP monitoring...\n");
989 bond->params.arp_interval = 0;
990 if (bond->params.arp_validate)
991 bond->params.arp_validate = BOND_ARP_VALIDATE_NONE;
992 }
993 if (bond->dev->flags & IFF_UP) {
994 /* If the interface is up, we may need to fire off
995 * the MII timer. If the interface is down, the
996 * timer will get fired off when the open function
997 * is called.
998 */
999 if (!newval->value) {
1000 cancel_delayed_work_sync(&bond->mii_work);
1001 } else {
1002 cancel_delayed_work_sync(&bond->arp_work);
1003 queue_delayed_work(bond->wq, &bond->mii_work, 0);
1004 }
1005 }
1006
1007 return 0;
1008 }
1009
1010 /* Set up, down and peer notification delays. These must be multiples
1011 * of the MII monitoring value, and are stored internally as the
1012 * multiplier. Thus, we must translate to MS for the real world.
1013 */
_bond_option_delay_set(struct bonding * bond,const struct bond_opt_value * newval,const char * name,int * target)1014 static int _bond_option_delay_set(struct bonding *bond,
1015 const struct bond_opt_value *newval,
1016 const char *name,
1017 int *target)
1018 {
1019 int value = newval->value;
1020
1021 if (!bond->params.miimon) {
1022 netdev_err(bond->dev, "Unable to set %s as MII monitoring is disabled\n",
1023 name);
1024 return -EPERM;
1025 }
1026 if ((value % bond->params.miimon) != 0) {
1027 netdev_warn(bond->dev,
1028 "%s (%d) is not a multiple of miimon (%d), value rounded to %d ms\n",
1029 name,
1030 value, bond->params.miimon,
1031 (value / bond->params.miimon) *
1032 bond->params.miimon);
1033 }
1034 *target = value / bond->params.miimon;
1035 netdev_dbg(bond->dev, "Setting %s to %d\n",
1036 name,
1037 *target * bond->params.miimon);
1038
1039 return 0;
1040 }
1041
bond_option_updelay_set(struct bonding * bond,const struct bond_opt_value * newval)1042 static int bond_option_updelay_set(struct bonding *bond,
1043 const struct bond_opt_value *newval)
1044 {
1045 return _bond_option_delay_set(bond, newval, "up delay",
1046 &bond->params.updelay);
1047 }
1048
bond_option_downdelay_set(struct bonding * bond,const struct bond_opt_value * newval)1049 static int bond_option_downdelay_set(struct bonding *bond,
1050 const struct bond_opt_value *newval)
1051 {
1052 return _bond_option_delay_set(bond, newval, "down delay",
1053 &bond->params.downdelay);
1054 }
1055
bond_option_peer_notif_delay_set(struct bonding * bond,const struct bond_opt_value * newval)1056 static int bond_option_peer_notif_delay_set(struct bonding *bond,
1057 const struct bond_opt_value *newval)
1058 {
1059 int ret = _bond_option_delay_set(bond, newval,
1060 "peer notification delay",
1061 &bond->params.peer_notif_delay);
1062 return ret;
1063 }
1064
bond_option_use_carrier_set(struct bonding * bond,const struct bond_opt_value * newval)1065 static int bond_option_use_carrier_set(struct bonding *bond,
1066 const struct bond_opt_value *newval)
1067 {
1068 netdev_dbg(bond->dev, "Setting use_carrier to %llu\n",
1069 newval->value);
1070 bond->params.use_carrier = newval->value;
1071
1072 return 0;
1073 }
1074
1075 /* There are two tricky bits here. First, if ARP monitoring is activated, then
1076 * we must disable MII monitoring. Second, if the ARP timer isn't running,
1077 * we must start it.
1078 */
bond_option_arp_interval_set(struct bonding * bond,const struct bond_opt_value * newval)1079 static int bond_option_arp_interval_set(struct bonding *bond,
1080 const struct bond_opt_value *newval)
1081 {
1082 netdev_dbg(bond->dev, "Setting ARP monitoring interval to %llu\n",
1083 newval->value);
1084 bond->params.arp_interval = newval->value;
1085 if (newval->value) {
1086 if (bond->params.miimon) {
1087 netdev_dbg(bond->dev, "ARP monitoring cannot be used with MII monitoring. Disabling MII monitoring\n");
1088 bond->params.miimon = 0;
1089 }
1090 if (!bond->params.arp_targets[0])
1091 netdev_dbg(bond->dev, "ARP monitoring has been set up, but no ARP targets have been specified\n");
1092 }
1093 if (bond->dev->flags & IFF_UP) {
1094 /* If the interface is up, we may need to fire off
1095 * the ARP timer. If the interface is down, the
1096 * timer will get fired off when the open function
1097 * is called.
1098 */
1099 if (!newval->value) {
1100 if (bond->params.arp_validate)
1101 bond->recv_probe = NULL;
1102 cancel_delayed_work_sync(&bond->arp_work);
1103 } else {
1104 /* arp_validate can be set only in active-backup mode */
1105 bond->recv_probe = bond_rcv_validate;
1106 cancel_delayed_work_sync(&bond->mii_work);
1107 queue_delayed_work(bond->wq, &bond->arp_work, 0);
1108 }
1109 }
1110
1111 return 0;
1112 }
1113
_bond_options_arp_ip_target_set(struct bonding * bond,int slot,__be32 target,unsigned long last_rx)1114 static void _bond_options_arp_ip_target_set(struct bonding *bond, int slot,
1115 __be32 target,
1116 unsigned long last_rx)
1117 {
1118 __be32 *targets = bond->params.arp_targets;
1119 struct list_head *iter;
1120 struct slave *slave;
1121
1122 if (slot >= 0 && slot < BOND_MAX_ARP_TARGETS) {
1123 bond_for_each_slave(bond, slave, iter)
1124 slave->target_last_arp_rx[slot] = last_rx;
1125 targets[slot] = target;
1126 }
1127 }
1128
_bond_option_arp_ip_target_add(struct bonding * bond,__be32 target)1129 static int _bond_option_arp_ip_target_add(struct bonding *bond, __be32 target)
1130 {
1131 __be32 *targets = bond->params.arp_targets;
1132 int ind;
1133
1134 if (!bond_is_ip_target_ok(target)) {
1135 netdev_err(bond->dev, "invalid ARP target %pI4 specified for addition\n",
1136 &target);
1137 return -EINVAL;
1138 }
1139
1140 if (bond_get_targets_ip(targets, target) != -1) { /* dup */
1141 netdev_err(bond->dev, "ARP target %pI4 is already present\n",
1142 &target);
1143 return -EINVAL;
1144 }
1145
1146 ind = bond_get_targets_ip(targets, 0); /* first free slot */
1147 if (ind == -1) {
1148 netdev_err(bond->dev, "ARP target table is full!\n");
1149 return -EINVAL;
1150 }
1151
1152 netdev_dbg(bond->dev, "Adding ARP target %pI4\n", &target);
1153
1154 _bond_options_arp_ip_target_set(bond, ind, target, jiffies);
1155
1156 return 0;
1157 }
1158
bond_option_arp_ip_target_add(struct bonding * bond,__be32 target)1159 static int bond_option_arp_ip_target_add(struct bonding *bond, __be32 target)
1160 {
1161 return _bond_option_arp_ip_target_add(bond, target);
1162 }
1163
bond_option_arp_ip_target_rem(struct bonding * bond,__be32 target)1164 static int bond_option_arp_ip_target_rem(struct bonding *bond, __be32 target)
1165 {
1166 __be32 *targets = bond->params.arp_targets;
1167 struct list_head *iter;
1168 struct slave *slave;
1169 unsigned long *targets_rx;
1170 int ind, i;
1171
1172 if (!bond_is_ip_target_ok(target)) {
1173 netdev_err(bond->dev, "invalid ARP target %pI4 specified for removal\n",
1174 &target);
1175 return -EINVAL;
1176 }
1177
1178 ind = bond_get_targets_ip(targets, target);
1179 if (ind == -1) {
1180 netdev_err(bond->dev, "unable to remove nonexistent ARP target %pI4\n",
1181 &target);
1182 return -EINVAL;
1183 }
1184
1185 if (ind == 0 && !targets[1] && bond->params.arp_interval)
1186 netdev_warn(bond->dev, "Removing last arp target with arp_interval on\n");
1187
1188 netdev_dbg(bond->dev, "Removing ARP target %pI4\n", &target);
1189
1190 bond_for_each_slave(bond, slave, iter) {
1191 targets_rx = slave->target_last_arp_rx;
1192 for (i = ind; (i < BOND_MAX_ARP_TARGETS-1) && targets[i+1]; i++)
1193 targets_rx[i] = targets_rx[i+1];
1194 targets_rx[i] = 0;
1195 }
1196 for (i = ind; (i < BOND_MAX_ARP_TARGETS-1) && targets[i+1]; i++)
1197 targets[i] = targets[i+1];
1198 targets[i] = 0;
1199
1200 return 0;
1201 }
1202
bond_option_arp_ip_targets_clear(struct bonding * bond)1203 void bond_option_arp_ip_targets_clear(struct bonding *bond)
1204 {
1205 int i;
1206
1207 for (i = 0; i < BOND_MAX_ARP_TARGETS; i++)
1208 _bond_options_arp_ip_target_set(bond, i, 0, 0);
1209 }
1210
bond_option_arp_ip_targets_set(struct bonding * bond,const struct bond_opt_value * newval)1211 static int bond_option_arp_ip_targets_set(struct bonding *bond,
1212 const struct bond_opt_value *newval)
1213 {
1214 int ret = -EPERM;
1215 __be32 target;
1216
1217 if (newval->string) {
1218 if (strlen(newval->string) < 1 ||
1219 !in4_pton(newval->string + 1, -1, (u8 *)&target, -1, NULL)) {
1220 netdev_err(bond->dev, "invalid ARP target specified\n");
1221 return ret;
1222 }
1223 if (newval->string[0] == '+')
1224 ret = bond_option_arp_ip_target_add(bond, target);
1225 else if (newval->string[0] == '-')
1226 ret = bond_option_arp_ip_target_rem(bond, target);
1227 else
1228 netdev_err(bond->dev, "no command found in arp_ip_targets file - use +<addr> or -<addr>\n");
1229 } else {
1230 target = newval->value;
1231 ret = bond_option_arp_ip_target_add(bond, target);
1232 }
1233
1234 return ret;
1235 }
1236
1237 #if IS_ENABLED(CONFIG_IPV6)
slave_can_set_ns_maddr(const struct bonding * bond,struct slave * slave)1238 static bool slave_can_set_ns_maddr(const struct bonding *bond, struct slave *slave)
1239 {
1240 return BOND_MODE(bond) == BOND_MODE_ACTIVEBACKUP &&
1241 !bond_is_active_slave(slave) &&
1242 slave->dev->flags & IFF_MULTICAST;
1243 }
1244
1245 /**
1246 * slave_set_ns_maddrs - add/del all NS mac addresses for slave
1247 * @bond: bond device
1248 * @slave: slave device
1249 * @add: add or remove all the NS mac addresses
1250 *
1251 * This function tries to add or delete all the NS mac addresses on the slave
1252 *
1253 * Note, the IPv6 NS target address is the unicast address in Neighbor
1254 * Solicitation (NS) message. The dest address of NS message should be
1255 * solicited-node multicast address of the target. The dest mac of NS message
1256 * is converted from the solicited-node multicast address.
1257 *
1258 * This function is called when
1259 * * arp_validate changes
1260 * * enslaving, releasing new slaves
1261 */
slave_set_ns_maddrs(struct bonding * bond,struct slave * slave,bool add)1262 static void slave_set_ns_maddrs(struct bonding *bond, struct slave *slave, bool add)
1263 {
1264 struct in6_addr *targets = bond->params.ns_targets;
1265 char slot_maddr[MAX_ADDR_LEN];
1266 struct in6_addr mcaddr;
1267 int i;
1268
1269 if (!slave_can_set_ns_maddr(bond, slave))
1270 return;
1271
1272 for (i = 0; i < BOND_MAX_NS_TARGETS; i++) {
1273 if (ipv6_addr_any(&targets[i]))
1274 break;
1275
1276 addrconf_addr_solict_mult(&targets[i], &mcaddr);
1277 if (!ndisc_mc_map(&mcaddr, slot_maddr, slave->dev, 0)) {
1278 if (add)
1279 dev_mc_add(slave->dev, slot_maddr);
1280 else
1281 dev_mc_del(slave->dev, slot_maddr);
1282 }
1283 }
1284 }
1285
bond_slave_ns_maddrs_add(struct bonding * bond,struct slave * slave)1286 void bond_slave_ns_maddrs_add(struct bonding *bond, struct slave *slave)
1287 {
1288 if (!bond->params.arp_validate)
1289 return;
1290 slave_set_ns_maddrs(bond, slave, true);
1291 }
1292
bond_slave_ns_maddrs_del(struct bonding * bond,struct slave * slave)1293 void bond_slave_ns_maddrs_del(struct bonding *bond, struct slave *slave)
1294 {
1295 if (!bond->params.arp_validate)
1296 return;
1297 slave_set_ns_maddrs(bond, slave, false);
1298 }
1299
1300 /**
1301 * slave_set_ns_maddr - set new NS mac address for slave
1302 * @bond: bond device
1303 * @slave: slave device
1304 * @target: the new IPv6 target
1305 * @slot: the old IPv6 target in the slot
1306 *
1307 * This function tries to replace the old mac address to new one on the slave.
1308 *
1309 * Note, the target/slot IPv6 address is the unicast address in Neighbor
1310 * Solicitation (NS) message. The dest address of NS message should be
1311 * solicited-node multicast address of the target. The dest mac of NS message
1312 * is converted from the solicited-node multicast address.
1313 *
1314 * This function is called when
1315 * * An IPv6 NS target is added or removed.
1316 */
slave_set_ns_maddr(struct bonding * bond,struct slave * slave,struct in6_addr * target,struct in6_addr * slot)1317 static void slave_set_ns_maddr(struct bonding *bond, struct slave *slave,
1318 struct in6_addr *target, struct in6_addr *slot)
1319 {
1320 char mac_addr[MAX_ADDR_LEN];
1321 struct in6_addr mcast_addr;
1322
1323 if (!bond->params.arp_validate || !slave_can_set_ns_maddr(bond, slave))
1324 return;
1325
1326 /* remove the previous mac addr from slave */
1327 addrconf_addr_solict_mult(slot, &mcast_addr);
1328 if (!ipv6_addr_any(slot) &&
1329 !ndisc_mc_map(&mcast_addr, mac_addr, slave->dev, 0))
1330 dev_mc_del(slave->dev, mac_addr);
1331
1332 /* add new mac addr on slave if target is set */
1333 addrconf_addr_solict_mult(target, &mcast_addr);
1334 if (!ipv6_addr_any(target) &&
1335 !ndisc_mc_map(&mcast_addr, mac_addr, slave->dev, 0))
1336 dev_mc_add(slave->dev, mac_addr);
1337 }
1338
_bond_options_ns_ip6_target_set(struct bonding * bond,int slot,struct in6_addr * target,unsigned long last_rx)1339 static void _bond_options_ns_ip6_target_set(struct bonding *bond, int slot,
1340 struct in6_addr *target,
1341 unsigned long last_rx)
1342 {
1343 struct in6_addr *targets = bond->params.ns_targets;
1344 struct list_head *iter;
1345 struct slave *slave;
1346
1347 if (slot >= 0 && slot < BOND_MAX_NS_TARGETS) {
1348 bond_for_each_slave(bond, slave, iter) {
1349 slave->target_last_arp_rx[slot] = last_rx;
1350 slave_set_ns_maddr(bond, slave, target, &targets[slot]);
1351 }
1352 targets[slot] = *target;
1353 }
1354 }
1355
bond_option_ns_ip6_targets_clear(struct bonding * bond)1356 void bond_option_ns_ip6_targets_clear(struct bonding *bond)
1357 {
1358 struct in6_addr addr_any = in6addr_any;
1359 int i;
1360
1361 for (i = 0; i < BOND_MAX_NS_TARGETS; i++)
1362 _bond_options_ns_ip6_target_set(bond, i, &addr_any, 0);
1363 }
1364
bond_option_ns_ip6_targets_set(struct bonding * bond,const struct bond_opt_value * newval)1365 static int bond_option_ns_ip6_targets_set(struct bonding *bond,
1366 const struct bond_opt_value *newval)
1367 {
1368 struct in6_addr *target = (struct in6_addr *)newval->extra;
1369 struct in6_addr *targets = bond->params.ns_targets;
1370 struct in6_addr addr_any = in6addr_any;
1371 int index;
1372
1373 if (!bond_is_ip6_target_ok(target)) {
1374 netdev_err(bond->dev, "invalid NS target %pI6c specified for addition\n",
1375 target);
1376 return -EINVAL;
1377 }
1378
1379 if (bond_get_targets_ip6(targets, target) != -1) { /* dup */
1380 netdev_err(bond->dev, "NS target %pI6c is already present\n",
1381 target);
1382 return -EINVAL;
1383 }
1384
1385 index = bond_get_targets_ip6(targets, &addr_any); /* first free slot */
1386 if (index == -1) {
1387 netdev_err(bond->dev, "NS target table is full!\n");
1388 return -EINVAL;
1389 }
1390
1391 netdev_dbg(bond->dev, "Adding NS target %pI6c\n", target);
1392
1393 _bond_options_ns_ip6_target_set(bond, index, target, jiffies);
1394
1395 return 0;
1396 }
1397 #else
bond_option_ns_ip6_targets_set(struct bonding * bond,const struct bond_opt_value * newval)1398 static int bond_option_ns_ip6_targets_set(struct bonding *bond,
1399 const struct bond_opt_value *newval)
1400 {
1401 return -EPERM;
1402 }
1403
slave_set_ns_maddrs(struct bonding * bond,struct slave * slave,bool add)1404 static void slave_set_ns_maddrs(struct bonding *bond, struct slave *slave, bool add) {}
1405
bond_slave_ns_maddrs_add(struct bonding * bond,struct slave * slave)1406 void bond_slave_ns_maddrs_add(struct bonding *bond, struct slave *slave) {}
1407
bond_slave_ns_maddrs_del(struct bonding * bond,struct slave * slave)1408 void bond_slave_ns_maddrs_del(struct bonding *bond, struct slave *slave) {}
1409 #endif
1410
bond_option_arp_validate_set(struct bonding * bond,const struct bond_opt_value * newval)1411 static int bond_option_arp_validate_set(struct bonding *bond,
1412 const struct bond_opt_value *newval)
1413 {
1414 bool changed = !!bond->params.arp_validate != !!newval->value;
1415 struct list_head *iter;
1416 struct slave *slave;
1417
1418 netdev_dbg(bond->dev, "Setting arp_validate to %s (%llu)\n",
1419 newval->string, newval->value);
1420 bond->params.arp_validate = newval->value;
1421
1422 if (changed) {
1423 bond_for_each_slave(bond, slave, iter)
1424 slave_set_ns_maddrs(bond, slave, !!bond->params.arp_validate);
1425 }
1426
1427 return 0;
1428 }
1429
bond_option_arp_all_targets_set(struct bonding * bond,const struct bond_opt_value * newval)1430 static int bond_option_arp_all_targets_set(struct bonding *bond,
1431 const struct bond_opt_value *newval)
1432 {
1433 netdev_dbg(bond->dev, "Setting arp_all_targets to %s (%llu)\n",
1434 newval->string, newval->value);
1435 bond->params.arp_all_targets = newval->value;
1436
1437 return 0;
1438 }
1439
bond_option_missed_max_set(struct bonding * bond,const struct bond_opt_value * newval)1440 static int bond_option_missed_max_set(struct bonding *bond,
1441 const struct bond_opt_value *newval)
1442 {
1443 netdev_dbg(bond->dev, "Setting missed max to %s (%llu)\n",
1444 newval->string, newval->value);
1445 bond->params.missed_max = newval->value;
1446
1447 return 0;
1448 }
1449
bond_option_prio_set(struct bonding * bond,const struct bond_opt_value * newval)1450 static int bond_option_prio_set(struct bonding *bond,
1451 const struct bond_opt_value *newval)
1452 {
1453 struct slave *slave;
1454
1455 slave = bond_slave_get_rtnl(newval->slave_dev);
1456 if (!slave) {
1457 netdev_dbg(newval->slave_dev, "%s called on NULL slave\n", __func__);
1458 return -ENODEV;
1459 }
1460 slave->prio = newval->value;
1461
1462 if (rtnl_dereference(bond->primary_slave))
1463 slave_warn(bond->dev, slave->dev,
1464 "prio updated, but will not affect failover re-selection as primary slave have been set\n");
1465 else
1466 bond_select_active_slave(bond);
1467
1468 return 0;
1469 }
1470
bond_option_primary_set(struct bonding * bond,const struct bond_opt_value * newval)1471 static int bond_option_primary_set(struct bonding *bond,
1472 const struct bond_opt_value *newval)
1473 {
1474 char *p, *primary = newval->string;
1475 struct list_head *iter;
1476 struct slave *slave;
1477
1478 block_netpoll_tx();
1479
1480 p = strchr(primary, '\n');
1481 if (p)
1482 *p = '\0';
1483 /* check to see if we are clearing primary */
1484 if (!strlen(primary)) {
1485 netdev_dbg(bond->dev, "Setting primary slave to None\n");
1486 RCU_INIT_POINTER(bond->primary_slave, NULL);
1487 memset(bond->params.primary, 0, sizeof(bond->params.primary));
1488 bond_select_active_slave(bond);
1489 goto out;
1490 }
1491
1492 bond_for_each_slave(bond, slave, iter) {
1493 if (strncmp(slave->dev->name, primary, IFNAMSIZ) == 0) {
1494 slave_dbg(bond->dev, slave->dev, "Setting as primary slave\n");
1495 rcu_assign_pointer(bond->primary_slave, slave);
1496 strcpy(bond->params.primary, slave->dev->name);
1497 bond->force_primary = true;
1498 bond_select_active_slave(bond);
1499 goto out;
1500 }
1501 }
1502
1503 if (rtnl_dereference(bond->primary_slave)) {
1504 netdev_dbg(bond->dev, "Setting primary slave to None\n");
1505 RCU_INIT_POINTER(bond->primary_slave, NULL);
1506 bond_select_active_slave(bond);
1507 }
1508 strscpy_pad(bond->params.primary, primary, IFNAMSIZ);
1509
1510 netdev_dbg(bond->dev, "Recording %s as primary, but it has not been enslaved yet\n",
1511 primary);
1512
1513 out:
1514 unblock_netpoll_tx();
1515
1516 return 0;
1517 }
1518
bond_option_primary_reselect_set(struct bonding * bond,const struct bond_opt_value * newval)1519 static int bond_option_primary_reselect_set(struct bonding *bond,
1520 const struct bond_opt_value *newval)
1521 {
1522 netdev_dbg(bond->dev, "Setting primary_reselect to %s (%llu)\n",
1523 newval->string, newval->value);
1524 bond->params.primary_reselect = newval->value;
1525
1526 block_netpoll_tx();
1527 bond_select_active_slave(bond);
1528 unblock_netpoll_tx();
1529
1530 return 0;
1531 }
1532
bond_option_fail_over_mac_set(struct bonding * bond,const struct bond_opt_value * newval)1533 static int bond_option_fail_over_mac_set(struct bonding *bond,
1534 const struct bond_opt_value *newval)
1535 {
1536 netdev_dbg(bond->dev, "Setting fail_over_mac to %s (%llu)\n",
1537 newval->string, newval->value);
1538 bond->params.fail_over_mac = newval->value;
1539
1540 return 0;
1541 }
1542
bond_option_xmit_hash_policy_set(struct bonding * bond,const struct bond_opt_value * newval)1543 static int bond_option_xmit_hash_policy_set(struct bonding *bond,
1544 const struct bond_opt_value *newval)
1545 {
1546 netdev_dbg(bond->dev, "Setting xmit hash policy to %s (%llu)\n",
1547 newval->string, newval->value);
1548 bond->params.xmit_policy = newval->value;
1549
1550 return 0;
1551 }
1552
bond_option_resend_igmp_set(struct bonding * bond,const struct bond_opt_value * newval)1553 static int bond_option_resend_igmp_set(struct bonding *bond,
1554 const struct bond_opt_value *newval)
1555 {
1556 netdev_dbg(bond->dev, "Setting resend_igmp to %llu\n",
1557 newval->value);
1558 bond->params.resend_igmp = newval->value;
1559
1560 return 0;
1561 }
1562
bond_option_num_peer_notif_set(struct bonding * bond,const struct bond_opt_value * newval)1563 static int bond_option_num_peer_notif_set(struct bonding *bond,
1564 const struct bond_opt_value *newval)
1565 {
1566 bond->params.num_peer_notif = newval->value;
1567
1568 return 0;
1569 }
1570
bond_option_all_slaves_active_set(struct bonding * bond,const struct bond_opt_value * newval)1571 static int bond_option_all_slaves_active_set(struct bonding *bond,
1572 const struct bond_opt_value *newval)
1573 {
1574 struct list_head *iter;
1575 struct slave *slave;
1576
1577 if (newval->value == bond->params.all_slaves_active)
1578 return 0;
1579 bond->params.all_slaves_active = newval->value;
1580 bond_for_each_slave(bond, slave, iter) {
1581 if (!bond_is_active_slave(slave)) {
1582 if (newval->value)
1583 slave->inactive = 0;
1584 else
1585 slave->inactive = 1;
1586 }
1587 }
1588
1589 return 0;
1590 }
1591
bond_option_min_links_set(struct bonding * bond,const struct bond_opt_value * newval)1592 static int bond_option_min_links_set(struct bonding *bond,
1593 const struct bond_opt_value *newval)
1594 {
1595 netdev_dbg(bond->dev, "Setting min links value to %llu\n",
1596 newval->value);
1597 bond->params.min_links = newval->value;
1598 bond_set_carrier(bond);
1599
1600 return 0;
1601 }
1602
bond_option_lp_interval_set(struct bonding * bond,const struct bond_opt_value * newval)1603 static int bond_option_lp_interval_set(struct bonding *bond,
1604 const struct bond_opt_value *newval)
1605 {
1606 bond->params.lp_interval = newval->value;
1607
1608 return 0;
1609 }
1610
bond_option_pps_set(struct bonding * bond,const struct bond_opt_value * newval)1611 static int bond_option_pps_set(struct bonding *bond,
1612 const struct bond_opt_value *newval)
1613 {
1614 netdev_dbg(bond->dev, "Setting packets per slave to %llu\n",
1615 newval->value);
1616 bond->params.packets_per_slave = newval->value;
1617 if (newval->value > 0) {
1618 bond->params.reciprocal_packets_per_slave =
1619 reciprocal_value(newval->value);
1620 } else {
1621 /* reciprocal_packets_per_slave is unused if
1622 * packets_per_slave is 0 or 1, just initialize it
1623 */
1624 bond->params.reciprocal_packets_per_slave =
1625 (struct reciprocal_value) { 0 };
1626 }
1627
1628 return 0;
1629 }
1630
bond_option_lacp_active_set(struct bonding * bond,const struct bond_opt_value * newval)1631 static int bond_option_lacp_active_set(struct bonding *bond,
1632 const struct bond_opt_value *newval)
1633 {
1634 netdev_dbg(bond->dev, "Setting LACP active to %s (%llu)\n",
1635 newval->string, newval->value);
1636 bond->params.lacp_active = newval->value;
1637
1638 return 0;
1639 }
1640
bond_option_lacp_rate_set(struct bonding * bond,const struct bond_opt_value * newval)1641 static int bond_option_lacp_rate_set(struct bonding *bond,
1642 const struct bond_opt_value *newval)
1643 {
1644 netdev_dbg(bond->dev, "Setting LACP rate to %s (%llu)\n",
1645 newval->string, newval->value);
1646 bond->params.lacp_fast = newval->value;
1647 bond_3ad_update_lacp_rate(bond);
1648
1649 return 0;
1650 }
1651
bond_option_ad_select_set(struct bonding * bond,const struct bond_opt_value * newval)1652 static int bond_option_ad_select_set(struct bonding *bond,
1653 const struct bond_opt_value *newval)
1654 {
1655 netdev_dbg(bond->dev, "Setting ad_select to %s (%llu)\n",
1656 newval->string, newval->value);
1657 bond->params.ad_select = newval->value;
1658
1659 return 0;
1660 }
1661
bond_option_queue_id_set(struct bonding * bond,const struct bond_opt_value * newval)1662 static int bond_option_queue_id_set(struct bonding *bond,
1663 const struct bond_opt_value *newval)
1664 {
1665 struct slave *slave, *update_slave;
1666 struct net_device *sdev;
1667 struct list_head *iter;
1668 char *delim;
1669 int ret = 0;
1670 u16 qid;
1671
1672 /* delim will point to queue id if successful */
1673 delim = strchr(newval->string, ':');
1674 if (!delim)
1675 goto err_no_cmd;
1676
1677 /* Terminate string that points to device name and bump it
1678 * up one, so we can read the queue id there.
1679 */
1680 *delim = '\0';
1681 if (sscanf(++delim, "%hd\n", &qid) != 1)
1682 goto err_no_cmd;
1683
1684 /* Check buffer length, valid ifname and queue id */
1685 if (!dev_valid_name(newval->string) ||
1686 qid > bond->dev->real_num_tx_queues)
1687 goto err_no_cmd;
1688
1689 /* Get the pointer to that interface if it exists */
1690 sdev = __dev_get_by_name(dev_net(bond->dev), newval->string);
1691 if (!sdev)
1692 goto err_no_cmd;
1693
1694 /* Search for thes slave and check for duplicate qids */
1695 update_slave = NULL;
1696 bond_for_each_slave(bond, slave, iter) {
1697 if (sdev == slave->dev)
1698 /* We don't need to check the matching
1699 * slave for dups, since we're overwriting it
1700 */
1701 update_slave = slave;
1702 else if (qid && qid == slave->queue_id) {
1703 goto err_no_cmd;
1704 }
1705 }
1706
1707 if (!update_slave)
1708 goto err_no_cmd;
1709
1710 /* Actually set the qids for the slave */
1711 WRITE_ONCE(update_slave->queue_id, qid);
1712
1713 out:
1714 return ret;
1715
1716 err_no_cmd:
1717 netdev_dbg(bond->dev, "invalid input for queue_id set\n");
1718 ret = -EPERM;
1719 goto out;
1720
1721 }
1722
bond_option_slaves_set(struct bonding * bond,const struct bond_opt_value * newval)1723 static int bond_option_slaves_set(struct bonding *bond,
1724 const struct bond_opt_value *newval)
1725 {
1726 char command[IFNAMSIZ + 1] = { 0, };
1727 struct net_device *dev;
1728 char *ifname;
1729 int ret;
1730
1731 sscanf(newval->string, "%16s", command); /* IFNAMSIZ*/
1732 ifname = command + 1;
1733 if ((strlen(command) <= 1) ||
1734 (command[0] != '+' && command[0] != '-') ||
1735 !dev_valid_name(ifname))
1736 goto err_no_cmd;
1737
1738 dev = __dev_get_by_name(dev_net(bond->dev), ifname);
1739 if (!dev) {
1740 netdev_dbg(bond->dev, "interface %s does not exist!\n",
1741 ifname);
1742 ret = -ENODEV;
1743 goto out;
1744 }
1745
1746 switch (command[0]) {
1747 case '+':
1748 slave_dbg(bond->dev, dev, "Enslaving interface\n");
1749 ret = bond_enslave(bond->dev, dev, NULL);
1750 break;
1751
1752 case '-':
1753 slave_dbg(bond->dev, dev, "Releasing interface\n");
1754 ret = bond_release(bond->dev, dev);
1755 break;
1756
1757 default:
1758 /* should not run here. */
1759 goto err_no_cmd;
1760 }
1761
1762 out:
1763 return ret;
1764
1765 err_no_cmd:
1766 netdev_err(bond->dev, "no command found in slaves file - use +ifname or -ifname\n");
1767 ret = -EPERM;
1768 goto out;
1769 }
1770
bond_option_tlb_dynamic_lb_set(struct bonding * bond,const struct bond_opt_value * newval)1771 static int bond_option_tlb_dynamic_lb_set(struct bonding *bond,
1772 const struct bond_opt_value *newval)
1773 {
1774 netdev_dbg(bond->dev, "Setting dynamic-lb to %s (%llu)\n",
1775 newval->string, newval->value);
1776 bond->params.tlb_dynamic_lb = newval->value;
1777
1778 return 0;
1779 }
1780
bond_option_ad_actor_sys_prio_set(struct bonding * bond,const struct bond_opt_value * newval)1781 static int bond_option_ad_actor_sys_prio_set(struct bonding *bond,
1782 const struct bond_opt_value *newval)
1783 {
1784 netdev_dbg(bond->dev, "Setting ad_actor_sys_prio to %llu\n",
1785 newval->value);
1786
1787 bond->params.ad_actor_sys_prio = newval->value;
1788 bond_3ad_update_ad_actor_settings(bond);
1789
1790 return 0;
1791 }
1792
bond_option_ad_actor_system_set(struct bonding * bond,const struct bond_opt_value * newval)1793 static int bond_option_ad_actor_system_set(struct bonding *bond,
1794 const struct bond_opt_value *newval)
1795 {
1796 u8 macaddr[ETH_ALEN];
1797 u8 *mac;
1798
1799 if (newval->string) {
1800 if (!mac_pton(newval->string, macaddr))
1801 goto err;
1802 mac = macaddr;
1803 } else {
1804 mac = (u8 *)&newval->value;
1805 }
1806
1807 if (is_multicast_ether_addr(mac))
1808 goto err;
1809
1810 netdev_dbg(bond->dev, "Setting ad_actor_system to %pM\n", mac);
1811 ether_addr_copy(bond->params.ad_actor_system, mac);
1812 bond_3ad_update_ad_actor_settings(bond);
1813
1814 return 0;
1815
1816 err:
1817 netdev_err(bond->dev, "Invalid ad_actor_system MAC address.\n");
1818 return -EINVAL;
1819 }
1820
bond_option_ad_user_port_key_set(struct bonding * bond,const struct bond_opt_value * newval)1821 static int bond_option_ad_user_port_key_set(struct bonding *bond,
1822 const struct bond_opt_value *newval)
1823 {
1824 netdev_dbg(bond->dev, "Setting ad_user_port_key to %llu\n",
1825 newval->value);
1826
1827 bond->params.ad_user_port_key = newval->value;
1828 return 0;
1829 }
1830
bond_option_coupled_control_set(struct bonding * bond,const struct bond_opt_value * newval)1831 static int bond_option_coupled_control_set(struct bonding *bond,
1832 const struct bond_opt_value *newval)
1833 {
1834 netdev_info(bond->dev, "Setting coupled_control to %s (%llu)\n",
1835 newval->string, newval->value);
1836
1837 bond->params.coupled_control = newval->value;
1838 return 0;
1839 }
1840