Commit | Line | Data |
---|---|---|
72be35fe JP |
1 | /* |
2 | * drivers/net/bond/bond_options.c - bonding options | |
3 | * Copyright (c) 2013 Jiri Pirko <jiri@resnulli.us> | |
eecdaa6e | 4 | * Copyright (c) 2013 Scott Feldman <sfeldma@cumulusnetworks.com> |
72be35fe JP |
5 | * |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License as published by | |
8 | * the Free Software Foundation; either version 2 of the License, or | |
9 | * (at your option) any later version. | |
10 | */ | |
11 | ||
12 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | |
13 | ||
14 | #include <linux/errno.h> | |
15 | #include <linux/if.h> | |
d9e32b21 JP |
16 | #include <linux/netdevice.h> |
17 | #include <linux/rwlock.h> | |
18 | #include <linux/rcupdate.h> | |
09117362 | 19 | #include <linux/ctype.h> |
4fb0ef58 | 20 | #include <linux/inet.h> |
72be35fe JP |
21 | #include "bonding.h" |
22 | ||
2b3798d5 NA |
23 | static struct bond_opt_value bond_mode_tbl[] = { |
24 | { "balance-rr", BOND_MODE_ROUNDROBIN, BOND_VALFLAG_DEFAULT}, | |
25 | { "active-backup", BOND_MODE_ACTIVEBACKUP, 0}, | |
26 | { "balance-xor", BOND_MODE_XOR, 0}, | |
27 | { "broadcast", BOND_MODE_BROADCAST, 0}, | |
28 | { "802.3ad", BOND_MODE_8023AD, 0}, | |
29 | { "balance-tlb", BOND_MODE_TLB, 0}, | |
30 | { "balance-alb", BOND_MODE_ALB, 0}, | |
31 | { NULL, -1, 0}, | |
32 | }; | |
33 | ||
aa59d851 NA |
34 | static struct bond_opt_value bond_pps_tbl[] = { |
35 | { "default", 1, BOND_VALFLAG_DEFAULT}, | |
36 | { "maxval", USHRT_MAX, BOND_VALFLAG_MAX}, | |
37 | { NULL, -1, 0}, | |
38 | }; | |
39 | ||
a4b32ce7 NA |
40 | static struct bond_opt_value bond_xmit_hashtype_tbl[] = { |
41 | { "layer2", BOND_XMIT_POLICY_LAYER2, BOND_VALFLAG_DEFAULT}, | |
42 | { "layer3+4", BOND_XMIT_POLICY_LAYER34, 0}, | |
43 | { "layer2+3", BOND_XMIT_POLICY_LAYER23, 0}, | |
44 | { "encap2+3", BOND_XMIT_POLICY_ENCAP23, 0}, | |
45 | { "encap3+4", BOND_XMIT_POLICY_ENCAP34, 0}, | |
46 | { NULL, -1, 0}, | |
47 | }; | |
48 | ||
16228881 NA |
49 | static struct bond_opt_value bond_arp_validate_tbl[] = { |
50 | { "none", BOND_ARP_VALIDATE_NONE, BOND_VALFLAG_DEFAULT}, | |
51 | { "active", BOND_ARP_VALIDATE_ACTIVE, 0}, | |
52 | { "backup", BOND_ARP_VALIDATE_BACKUP, 0}, | |
53 | { "all", BOND_ARP_VALIDATE_ALL, 0}, | |
54 | { NULL, -1, 0}, | |
55 | }; | |
56 | ||
edf36b24 NA |
57 | static struct bond_opt_value bond_arp_all_targets_tbl[] = { |
58 | { "any", BOND_ARP_TARGETS_ANY, BOND_VALFLAG_DEFAULT}, | |
59 | { "all", BOND_ARP_TARGETS_ALL, 0}, | |
60 | { NULL, -1, 0}, | |
61 | }; | |
62 | ||
1df6b6aa NA |
63 | static struct bond_opt_value bond_fail_over_mac_tbl[] = { |
64 | { "none", BOND_FOM_NONE, BOND_VALFLAG_DEFAULT}, | |
65 | { "active", BOND_FOM_ACTIVE, 0}, | |
66 | { "follow", BOND_FOM_FOLLOW, 0}, | |
67 | { NULL, -1, 0}, | |
68 | }; | |
69 | ||
7bdb04ed NA |
70 | static struct bond_opt_value bond_intmax_tbl[] = { |
71 | { "off", 0, BOND_VALFLAG_DEFAULT}, | |
72 | { "maxval", INT_MAX, BOND_VALFLAG_MAX}, | |
73 | }; | |
74 | ||
d3131de7 NA |
75 | static struct bond_opt_value bond_lacp_rate_tbl[] = { |
76 | { "slow", AD_LACP_SLOW, 0}, | |
77 | { "fast", AD_LACP_FAST, 0}, | |
78 | { NULL, -1, 0}, | |
79 | }; | |
80 | ||
9e5f5eeb NA |
81 | static struct bond_opt_value bond_ad_select_tbl[] = { |
82 | { "stable", BOND_AD_STABLE, BOND_VALFLAG_DEFAULT}, | |
83 | { "bandwidth", BOND_AD_BANDWIDTH, 0}, | |
84 | { "count", BOND_AD_COUNT, 0}, | |
85 | { NULL, -1, 0}, | |
86 | }; | |
87 | ||
ef56becb NA |
88 | static struct bond_opt_value bond_num_peer_notif_tbl[] = { |
89 | { "off", 0, 0}, | |
90 | { "maxval", 255, BOND_VALFLAG_MAX}, | |
91 | { "default", 1, BOND_VALFLAG_DEFAULT}, | |
92 | { NULL, -1, 0} | |
93 | }; | |
94 | ||
388d3a6d NA |
95 | static struct bond_opt_value bond_primary_reselect_tbl[] = { |
96 | { "always", BOND_PRI_RESELECT_ALWAYS, BOND_VALFLAG_DEFAULT}, | |
97 | { "better", BOND_PRI_RESELECT_BETTER, 0}, | |
98 | { "failure", BOND_PRI_RESELECT_FAILURE, 0}, | |
99 | { NULL, -1}, | |
100 | }; | |
101 | ||
09117362 | 102 | static struct bond_option bond_opts[] = { |
2b3798d5 NA |
103 | [BOND_OPT_MODE] = { |
104 | .id = BOND_OPT_MODE, | |
105 | .name = "mode", | |
106 | .desc = "bond device mode", | |
107 | .flags = BOND_OPTFLAG_NOSLAVES | BOND_OPTFLAG_IFDOWN, | |
108 | .values = bond_mode_tbl, | |
109 | .set = bond_option_mode_set | |
110 | }, | |
aa59d851 NA |
111 | [BOND_OPT_PACKETS_PER_SLAVE] = { |
112 | .id = BOND_OPT_PACKETS_PER_SLAVE, | |
113 | .name = "packets_per_slave", | |
114 | .desc = "Packets to send per slave in RR mode", | |
115 | .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_ROUNDROBIN)), | |
116 | .values = bond_pps_tbl, | |
117 | .set = bond_option_pps_set | |
118 | }, | |
a4b32ce7 NA |
119 | [BOND_OPT_XMIT_HASH] = { |
120 | .id = BOND_OPT_XMIT_HASH, | |
121 | .name = "xmit_hash_policy", | |
122 | .desc = "balance-xor and 802.3ad hashing method", | |
123 | .values = bond_xmit_hashtype_tbl, | |
124 | .set = bond_option_xmit_hash_policy_set | |
125 | }, | |
16228881 NA |
126 | [BOND_OPT_ARP_VALIDATE] = { |
127 | .id = BOND_OPT_ARP_VALIDATE, | |
128 | .name = "arp_validate", | |
129 | .desc = "validate src/dst of ARP probes", | |
130 | .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_ACTIVEBACKUP)), | |
131 | .values = bond_arp_validate_tbl, | |
132 | .set = bond_option_arp_validate_set | |
133 | }, | |
edf36b24 NA |
134 | [BOND_OPT_ARP_ALL_TARGETS] = { |
135 | .id = BOND_OPT_ARP_ALL_TARGETS, | |
136 | .name = "arp_all_targets", | |
137 | .desc = "fail on any/all arp targets timeout", | |
138 | .values = bond_arp_all_targets_tbl, | |
139 | .set = bond_option_arp_all_targets_set | |
140 | }, | |
1df6b6aa NA |
141 | [BOND_OPT_FAIL_OVER_MAC] = { |
142 | .id = BOND_OPT_FAIL_OVER_MAC, | |
143 | .name = "fail_over_mac", | |
144 | .desc = "For active-backup, do not set all slaves to the same MAC", | |
145 | .flags = BOND_OPTFLAG_NOSLAVES, | |
146 | .values = bond_fail_over_mac_tbl, | |
147 | .set = bond_option_fail_over_mac_set | |
148 | }, | |
7bdb04ed NA |
149 | [BOND_OPT_ARP_INTERVAL] = { |
150 | .id = BOND_OPT_ARP_INTERVAL, | |
151 | .name = "arp_interval", | |
152 | .desc = "arp interval in milliseconds", | |
153 | .unsuppmodes = BIT(BOND_MODE_8023AD) | BIT(BOND_MODE_TLB) | | |
154 | BIT(BOND_MODE_ALB), | |
155 | .values = bond_intmax_tbl, | |
156 | .set = bond_option_arp_interval_set | |
157 | }, | |
4fb0ef58 NA |
158 | [BOND_OPT_ARP_TARGETS] = { |
159 | .id = BOND_OPT_ARP_TARGETS, | |
160 | .name = "arp_ip_target", | |
161 | .desc = "arp targets in n.n.n.n form", | |
162 | .flags = BOND_OPTFLAG_RAWVAL, | |
163 | .set = bond_option_arp_ip_targets_set | |
164 | }, | |
25a9b54a NA |
165 | [BOND_OPT_DOWNDELAY] = { |
166 | .id = BOND_OPT_DOWNDELAY, | |
167 | .name = "downdelay", | |
168 | .desc = "Delay before considering link down, in milliseconds", | |
169 | .values = bond_intmax_tbl, | |
170 | .set = bond_option_downdelay_set | |
171 | }, | |
e4994612 NA |
172 | [BOND_OPT_UPDELAY] = { |
173 | .id = BOND_OPT_UPDELAY, | |
174 | .name = "updelay", | |
175 | .desc = "Delay before considering link up, in milliseconds", | |
176 | .values = bond_intmax_tbl, | |
177 | .set = bond_option_updelay_set | |
178 | }, | |
d3131de7 NA |
179 | [BOND_OPT_LACP_RATE] = { |
180 | .id = BOND_OPT_LACP_RATE, | |
181 | .name = "lacp_rate", | |
182 | .desc = "LACPDU tx rate to request from 802.3ad partner", | |
183 | .flags = BOND_OPTFLAG_IFDOWN, | |
184 | .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_8023AD)), | |
185 | .values = bond_lacp_rate_tbl, | |
186 | .set = bond_option_lacp_rate_set | |
187 | }, | |
633ddc9e NA |
188 | [BOND_OPT_MINLINKS] = { |
189 | .id = BOND_OPT_MINLINKS, | |
190 | .name = "min_links", | |
191 | .desc = "Minimum number of available links before turning on carrier", | |
192 | .values = bond_intmax_tbl, | |
193 | .set = bond_option_min_links_set | |
194 | }, | |
9e5f5eeb NA |
195 | [BOND_OPT_AD_SELECT] = { |
196 | .id = BOND_OPT_AD_SELECT, | |
197 | .name = "ad_select", | |
198 | .desc = "803.ad aggregation selection logic", | |
199 | .flags = BOND_OPTFLAG_IFDOWN, | |
200 | .values = bond_ad_select_tbl, | |
201 | .set = bond_option_ad_select_set | |
202 | }, | |
ef56becb NA |
203 | [BOND_OPT_NUM_PEER_NOTIF] = { |
204 | .id = BOND_OPT_NUM_PEER_NOTIF, | |
205 | .name = "num_unsol_na", | |
206 | .desc = "Number of peer notifications to send on failover event", | |
207 | .values = bond_num_peer_notif_tbl, | |
208 | .set = bond_option_num_peer_notif_set | |
209 | }, | |
b98d9c66 NA |
210 | [BOND_OPT_MIIMON] = { |
211 | .id = BOND_OPT_MIIMON, | |
212 | .name = "miimon", | |
213 | .desc = "Link check interval in milliseconds", | |
214 | .values = bond_intmax_tbl, | |
215 | .set = bond_option_miimon_set | |
216 | }, | |
180222f0 NA |
217 | [BOND_OPT_PRIMARY] = { |
218 | .id = BOND_OPT_PRIMARY, | |
219 | .name = "primary", | |
220 | .desc = "Primary network device to use", | |
221 | .flags = BOND_OPTFLAG_RAWVAL, | |
222 | .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_ACTIVEBACKUP) | | |
223 | BIT(BOND_MODE_TLB) | | |
224 | BIT(BOND_MODE_ALB)), | |
225 | .set = bond_option_primary_set | |
226 | }, | |
388d3a6d NA |
227 | [BOND_OPT_PRIMARY_RESELECT] = { |
228 | .id = BOND_OPT_PRIMARY_RESELECT, | |
229 | .name = "primary_reselect", | |
230 | .desc = "Reselect primary slave once it comes up", | |
231 | .values = bond_primary_reselect_tbl, | |
232 | .set = bond_option_primary_reselect_set | |
233 | }, | |
09117362 NA |
234 | { } |
235 | }; | |
236 | ||
237 | /* Searches for a value in opt's values[] table */ | |
238 | struct bond_opt_value *bond_opt_get_val(unsigned int option, u64 val) | |
239 | { | |
240 | struct bond_option *opt; | |
241 | int i; | |
242 | ||
243 | opt = bond_opt_get(option); | |
244 | if (WARN_ON(!opt)) | |
245 | return NULL; | |
246 | for (i = 0; opt->values && opt->values[i].string; i++) | |
247 | if (opt->values[i].value == val) | |
248 | return &opt->values[i]; | |
249 | ||
250 | return NULL; | |
251 | } | |
252 | ||
253 | /* Searches for a value in opt's values[] table which matches the flagmask */ | |
254 | static struct bond_opt_value *bond_opt_get_flags(const struct bond_option *opt, | |
255 | u32 flagmask) | |
256 | { | |
257 | int i; | |
258 | ||
259 | for (i = 0; opt->values && opt->values[i].string; i++) | |
260 | if (opt->values[i].flags & flagmask) | |
261 | return &opt->values[i]; | |
262 | ||
263 | return NULL; | |
264 | } | |
265 | ||
266 | /* If maxval is missing then there's no range to check. In case minval is | |
267 | * missing then it's considered to be 0. | |
268 | */ | |
269 | static bool bond_opt_check_range(const struct bond_option *opt, u64 val) | |
270 | { | |
271 | struct bond_opt_value *minval, *maxval; | |
272 | ||
273 | minval = bond_opt_get_flags(opt, BOND_VALFLAG_MIN); | |
274 | maxval = bond_opt_get_flags(opt, BOND_VALFLAG_MAX); | |
275 | if (!maxval || (minval && val < minval->value) || val > maxval->value) | |
276 | return false; | |
277 | ||
278 | return true; | |
279 | } | |
280 | ||
281 | /** | |
282 | * bond_opt_parse - parse option value | |
283 | * @opt: the option to parse against | |
284 | * @val: value to parse | |
285 | * | |
286 | * This function tries to extract the value from @val and check if it's | |
287 | * a possible match for the option and returns NULL if a match isn't found, | |
288 | * or the struct_opt_value that matched. It also strips the new line from | |
289 | * @val->string if it's present. | |
290 | */ | |
291 | struct bond_opt_value *bond_opt_parse(const struct bond_option *opt, | |
292 | struct bond_opt_value *val) | |
293 | { | |
294 | char *p, valstr[BOND_OPT_MAX_NAMELEN + 1] = { 0, }; | |
295 | struct bond_opt_value *tbl, *ret = NULL; | |
296 | bool checkval; | |
297 | int i, rv; | |
298 | ||
299 | /* No parsing if the option wants a raw val */ | |
300 | if (opt->flags & BOND_OPTFLAG_RAWVAL) | |
301 | return val; | |
302 | ||
303 | tbl = opt->values; | |
304 | if (!tbl) | |
305 | goto out; | |
306 | ||
307 | /* ULLONG_MAX is used to bypass string processing */ | |
308 | checkval = val->value != ULLONG_MAX; | |
309 | if (!checkval) { | |
310 | if (!val->string) | |
311 | goto out; | |
312 | p = strchr(val->string, '\n'); | |
313 | if (p) | |
314 | *p = '\0'; | |
315 | for (p = val->string; *p; p++) | |
316 | if (!(isdigit(*p) || isspace(*p))) | |
317 | break; | |
318 | /* The following code extracts the string to match or the value | |
319 | * and sets checkval appropriately | |
320 | */ | |
321 | if (*p) { | |
322 | rv = sscanf(val->string, "%32s", valstr); | |
323 | } else { | |
324 | rv = sscanf(val->string, "%llu", &val->value); | |
325 | checkval = true; | |
326 | } | |
327 | if (!rv) | |
328 | goto out; | |
329 | } | |
330 | ||
331 | for (i = 0; tbl[i].string; i++) { | |
332 | /* Check for exact match */ | |
333 | if (checkval) { | |
334 | if (val->value == tbl[i].value) | |
335 | ret = &tbl[i]; | |
336 | } else { | |
337 | if (!strcmp(valstr, "default") && | |
338 | (tbl[i].flags & BOND_VALFLAG_DEFAULT)) | |
339 | ret = &tbl[i]; | |
340 | ||
341 | if (!strcmp(valstr, tbl[i].string)) | |
342 | ret = &tbl[i]; | |
343 | } | |
344 | /* Found an exact match */ | |
345 | if (ret) | |
346 | goto out; | |
347 | } | |
348 | /* Possible range match */ | |
349 | if (checkval && bond_opt_check_range(opt, val->value)) | |
350 | ret = val; | |
351 | out: | |
352 | return ret; | |
353 | } | |
354 | ||
355 | /* Check opt's dependencies against bond mode and currently set options */ | |
356 | static int bond_opt_check_deps(struct bonding *bond, | |
357 | const struct bond_option *opt) | |
358 | { | |
359 | struct bond_params *params = &bond->params; | |
360 | ||
361 | if (test_bit(params->mode, &opt->unsuppmodes)) | |
362 | return -EACCES; | |
363 | if ((opt->flags & BOND_OPTFLAG_NOSLAVES) && bond_has_slaves(bond)) | |
364 | return -ENOTEMPTY; | |
365 | if ((opt->flags & BOND_OPTFLAG_IFDOWN) && (bond->dev->flags & IFF_UP)) | |
366 | return -EBUSY; | |
367 | ||
368 | return 0; | |
369 | } | |
370 | ||
371 | static void bond_opt_dep_print(struct bonding *bond, | |
372 | const struct bond_option *opt) | |
373 | { | |
2b3798d5 | 374 | struct bond_opt_value *modeval; |
09117362 NA |
375 | struct bond_params *params; |
376 | ||
377 | params = &bond->params; | |
2b3798d5 | 378 | modeval = bond_opt_get_val(BOND_OPT_MODE, params->mode); |
09117362 | 379 | if (test_bit(params->mode, &opt->unsuppmodes)) |
2b3798d5 NA |
380 | pr_err("%s: option %s: mode dependency failed, not supported in mode %s(%llu)\n", |
381 | bond->dev->name, opt->name, | |
382 | modeval->string, modeval->value); | |
09117362 NA |
383 | } |
384 | ||
385 | static void bond_opt_error_interpret(struct bonding *bond, | |
386 | const struct bond_option *opt, | |
387 | int error, struct bond_opt_value *val) | |
388 | { | |
389 | struct bond_opt_value *minval, *maxval; | |
390 | char *p; | |
391 | ||
392 | switch (error) { | |
393 | case -EINVAL: | |
394 | if (val) { | |
395 | if (val->string) { | |
396 | /* sometimes RAWVAL opts may have new lines */ | |
397 | p = strchr(val->string, '\n'); | |
398 | if (p) | |
399 | *p = '\0'; | |
400 | pr_err("%s: option %s: invalid value (%s).\n", | |
401 | bond->dev->name, opt->name, val->string); | |
402 | } else { | |
403 | pr_err("%s: option %s: invalid value (%llu).\n", | |
404 | bond->dev->name, opt->name, val->value); | |
405 | } | |
406 | } | |
407 | minval = bond_opt_get_flags(opt, BOND_VALFLAG_MIN); | |
408 | maxval = bond_opt_get_flags(opt, BOND_VALFLAG_MAX); | |
409 | if (!maxval) | |
410 | break; | |
411 | pr_err("%s: option %s: allowed values %llu - %llu.\n", | |
412 | bond->dev->name, opt->name, minval ? minval->value : 0, | |
413 | maxval->value); | |
414 | break; | |
415 | case -EACCES: | |
416 | bond_opt_dep_print(bond, opt); | |
417 | break; | |
418 | case -ENOTEMPTY: | |
419 | pr_err("%s: option %s: unable to set because the bond device has slaves.\n", | |
420 | bond->dev->name, opt->name); | |
421 | break; | |
422 | case -EBUSY: | |
423 | pr_err("%s: option %s: unable to set because the bond device is up.\n", | |
424 | bond->dev->name, opt->name); | |
425 | break; | |
426 | default: | |
427 | break; | |
428 | } | |
429 | } | |
430 | ||
431 | /** | |
432 | * __bond_opt_set - set a bonding option | |
433 | * @bond: target bond device | |
434 | * @option: option to set | |
435 | * @val: value to set it to | |
436 | * | |
437 | * This function is used to change the bond's option value, it can be | |
438 | * used for both enabling/changing an option and for disabling it. RTNL lock | |
439 | * must be obtained before calling this function. | |
440 | */ | |
441 | int __bond_opt_set(struct bonding *bond, | |
442 | unsigned int option, struct bond_opt_value *val) | |
443 | { | |
444 | struct bond_opt_value *retval = NULL; | |
445 | const struct bond_option *opt; | |
446 | int ret = -ENOENT; | |
447 | ||
448 | ASSERT_RTNL(); | |
449 | ||
450 | opt = bond_opt_get(option); | |
451 | if (WARN_ON(!val) || WARN_ON(!opt)) | |
452 | goto out; | |
453 | ret = bond_opt_check_deps(bond, opt); | |
454 | if (ret) | |
455 | goto out; | |
456 | retval = bond_opt_parse(opt, val); | |
457 | if (!retval) { | |
458 | ret = -EINVAL; | |
459 | goto out; | |
460 | } | |
461 | ret = opt->set(bond, retval); | |
462 | out: | |
463 | if (ret) | |
464 | bond_opt_error_interpret(bond, opt, ret, val); | |
465 | ||
466 | return ret; | |
467 | } | |
468 | ||
469 | /** | |
470 | * bond_opt_tryset_rtnl - try to acquire rtnl and call __bond_opt_set | |
471 | * @bond: target bond device | |
472 | * @option: option to set | |
473 | * @buf: value to set it to | |
474 | * | |
475 | * This function tries to acquire RTNL without blocking and if successful | |
476 | * calls __bond_opt_set. It is mainly used for sysfs option manipulation. | |
477 | */ | |
478 | int bond_opt_tryset_rtnl(struct bonding *bond, unsigned int option, char *buf) | |
479 | { | |
480 | struct bond_opt_value optval; | |
481 | int ret; | |
482 | ||
483 | if (!rtnl_trylock()) | |
484 | return restart_syscall(); | |
485 | bond_opt_initstr(&optval, buf); | |
486 | ret = __bond_opt_set(bond, option, &optval); | |
487 | rtnl_unlock(); | |
488 | ||
489 | return ret; | |
490 | } | |
491 | ||
492 | /** | |
493 | * bond_opt_get - get a pointer to an option | |
494 | * @option: option for which to return a pointer | |
495 | * | |
496 | * This function checks if option is valid and if so returns a pointer | |
497 | * to its entry in the bond_opts[] option array. | |
498 | */ | |
499 | struct bond_option *bond_opt_get(unsigned int option) | |
500 | { | |
501 | if (!BOND_OPT_VALID(option)) | |
502 | return NULL; | |
503 | ||
504 | return &bond_opts[option]; | |
505 | } | |
506 | ||
2b3798d5 | 507 | int bond_option_mode_set(struct bonding *bond, struct bond_opt_value *newval) |
72be35fe | 508 | { |
2b3798d5 | 509 | if (BOND_NO_USES_ARP(newval->value) && bond->params.arp_interval) { |
fe9d04af | 510 | pr_info("%s: %s mode is incompatible with arp monitoring, start mii monitoring\n", |
2b3798d5 | 511 | bond->dev->name, newval->string); |
fe9d04af | 512 | /* disable arp monitoring */ |
513 | bond->params.arp_interval = 0; | |
514 | /* set miimon to default value */ | |
515 | bond->params.miimon = BOND_DEFAULT_MIIMON; | |
516 | pr_info("%s: Setting MII monitoring interval to %d.\n", | |
517 | bond->dev->name, bond->params.miimon); | |
72be35fe JP |
518 | } |
519 | ||
520 | /* don't cache arp_validate between modes */ | |
521 | bond->params.arp_validate = BOND_ARP_VALIDATE_NONE; | |
2b3798d5 NA |
522 | bond->params.mode = newval->value; |
523 | ||
72be35fe JP |
524 | return 0; |
525 | } | |
d9e32b21 | 526 | |
752d48b5 JP |
527 | static struct net_device *__bond_option_active_slave_get(struct bonding *bond, |
528 | struct slave *slave) | |
529 | { | |
530 | return USES_PRIMARY(bond->params.mode) && slave ? slave->dev : NULL; | |
531 | } | |
532 | ||
533 | struct net_device *bond_option_active_slave_get_rcu(struct bonding *bond) | |
534 | { | |
535 | struct slave *slave = rcu_dereference(bond->curr_active_slave); | |
536 | ||
537 | return __bond_option_active_slave_get(bond, slave); | |
538 | } | |
539 | ||
540 | struct net_device *bond_option_active_slave_get(struct bonding *bond) | |
541 | { | |
542 | return __bond_option_active_slave_get(bond, bond->curr_active_slave); | |
543 | } | |
544 | ||
d9e32b21 JP |
545 | int bond_option_active_slave_set(struct bonding *bond, |
546 | struct net_device *slave_dev) | |
547 | { | |
548 | int ret = 0; | |
549 | ||
550 | if (slave_dev) { | |
551 | if (!netif_is_bond_slave(slave_dev)) { | |
552 | pr_err("Device %s is not bonding slave.\n", | |
553 | slave_dev->name); | |
554 | return -EINVAL; | |
555 | } | |
556 | ||
557 | if (bond->dev != netdev_master_upper_dev_get(slave_dev)) { | |
558 | pr_err("%s: Device %s is not our slave.\n", | |
559 | bond->dev->name, slave_dev->name); | |
560 | return -EINVAL; | |
561 | } | |
562 | } | |
563 | ||
564 | if (!USES_PRIMARY(bond->params.mode)) { | |
565 | pr_err("%s: Unable to change active slave; %s is in mode %d\n", | |
566 | bond->dev->name, bond->dev->name, bond->params.mode); | |
567 | return -EINVAL; | |
568 | } | |
569 | ||
570 | block_netpoll_tx(); | |
d9e32b21 JP |
571 | write_lock_bh(&bond->curr_slave_lock); |
572 | ||
573 | /* check to see if we are clearing active */ | |
574 | if (!slave_dev) { | |
575 | pr_info("%s: Clearing current active slave.\n", | |
576 | bond->dev->name); | |
577 | rcu_assign_pointer(bond->curr_active_slave, NULL); | |
578 | bond_select_active_slave(bond); | |
579 | } else { | |
580 | struct slave *old_active = bond->curr_active_slave; | |
581 | struct slave *new_active = bond_slave_get_rtnl(slave_dev); | |
582 | ||
583 | BUG_ON(!new_active); | |
584 | ||
585 | if (new_active == old_active) { | |
586 | /* do nothing */ | |
587 | pr_info("%s: %s is already the current active slave.\n", | |
588 | bond->dev->name, new_active->dev->name); | |
589 | } else { | |
590 | if (old_active && (new_active->link == BOND_LINK_UP) && | |
591 | IS_UP(new_active->dev)) { | |
592 | pr_info("%s: Setting %s as active slave.\n", | |
593 | bond->dev->name, new_active->dev->name); | |
594 | bond_change_active_slave(bond, new_active); | |
595 | } else { | |
596 | pr_err("%s: Could not set %s as active slave; either %s is down or the link is down.\n", | |
597 | bond->dev->name, new_active->dev->name, | |
598 | new_active->dev->name); | |
599 | ret = -EINVAL; | |
600 | } | |
601 | } | |
602 | } | |
603 | ||
604 | write_unlock_bh(&bond->curr_slave_lock); | |
d9e32b21 JP |
605 | unblock_netpoll_tx(); |
606 | return ret; | |
607 | } | |
eecdaa6e | 608 | |
b98d9c66 | 609 | int bond_option_miimon_set(struct bonding *bond, struct bond_opt_value *newval) |
eecdaa6e | 610 | { |
b98d9c66 NA |
611 | pr_info("%s: Setting MII monitoring interval to %llu.\n", |
612 | bond->dev->name, newval->value); | |
613 | bond->params.miimon = newval->value; | |
eecdaa6e | 614 | if (bond->params.updelay) |
615 | pr_info("%s: Note: Updating updelay (to %d) since it is a multiple of the miimon value.\n", | |
616 | bond->dev->name, | |
617 | bond->params.updelay * bond->params.miimon); | |
618 | if (bond->params.downdelay) | |
619 | pr_info("%s: Note: Updating downdelay (to %d) since it is a multiple of the miimon value.\n", | |
620 | bond->dev->name, | |
621 | bond->params.downdelay * bond->params.miimon); | |
b98d9c66 | 622 | if (newval->value && bond->params.arp_interval) { |
eecdaa6e | 623 | pr_info("%s: MII monitoring cannot be used with ARP monitoring. Disabling ARP monitoring...\n", |
624 | bond->dev->name); | |
625 | bond->params.arp_interval = 0; | |
626 | if (bond->params.arp_validate) | |
627 | bond->params.arp_validate = BOND_ARP_VALIDATE_NONE; | |
628 | } | |
629 | if (bond->dev->flags & IFF_UP) { | |
630 | /* If the interface is up, we may need to fire off | |
631 | * the MII timer. If the interface is down, the | |
632 | * timer will get fired off when the open function | |
633 | * is called. | |
634 | */ | |
b98d9c66 | 635 | if (!newval->value) { |
eecdaa6e | 636 | cancel_delayed_work_sync(&bond->mii_work); |
637 | } else { | |
638 | cancel_delayed_work_sync(&bond->arp_work); | |
639 | queue_delayed_work(bond->wq, &bond->mii_work, 0); | |
640 | } | |
641 | } | |
b98d9c66 | 642 | |
eecdaa6e | 643 | return 0; |
644 | } | |
25852e29 | 645 | |
e4994612 | 646 | int bond_option_updelay_set(struct bonding *bond, struct bond_opt_value *newval) |
25852e29 | 647 | { |
e4994612 | 648 | if (!bond->params.miimon) { |
25852e29 | 649 | pr_err("%s: Unable to set up delay as MII monitoring is disabled\n", |
650 | bond->dev->name); | |
651 | return -EPERM; | |
652 | } | |
e4994612 NA |
653 | if ((newval->value % bond->params.miimon) != 0) { |
654 | pr_warn("%s: Warning: up delay (%llu) is not a multiple of miimon (%d), updelay rounded to %llu ms\n", | |
655 | bond->dev->name, newval->value, | |
656 | bond->params.miimon, | |
657 | (newval->value / bond->params.miimon) * | |
658 | bond->params.miimon); | |
25852e29 | 659 | } |
e4994612 NA |
660 | bond->params.updelay = newval->value / bond->params.miimon; |
661 | pr_info("%s: Setting up delay to %d.\n", | |
662 | bond->dev->name, | |
663 | bond->params.updelay * bond->params.miimon); | |
25852e29 | 664 | |
665 | return 0; | |
666 | } | |
c7461f9b | 667 | |
25a9b54a NA |
668 | int bond_option_downdelay_set(struct bonding *bond, |
669 | struct bond_opt_value *newval) | |
c7461f9b | 670 | { |
25a9b54a | 671 | if (!bond->params.miimon) { |
c7461f9b | 672 | pr_err("%s: Unable to set down delay as MII monitoring is disabled\n", |
673 | bond->dev->name); | |
674 | return -EPERM; | |
675 | } | |
25a9b54a NA |
676 | if ((newval->value % bond->params.miimon) != 0) { |
677 | pr_warn("%s: Warning: down delay (%llu) is not a multiple of miimon (%d), delay rounded to %llu ms\n", | |
678 | bond->dev->name, newval->value, | |
679 | bond->params.miimon, | |
680 | (newval->value / bond->params.miimon) * | |
681 | bond->params.miimon); | |
c7461f9b | 682 | } |
25a9b54a NA |
683 | bond->params.downdelay = newval->value / bond->params.miimon; |
684 | pr_info("%s: Setting down delay to %d.\n", | |
685 | bond->dev->name, | |
686 | bond->params.downdelay * bond->params.miimon); | |
c7461f9b | 687 | |
688 | return 0; | |
689 | } | |
9f53e14e | 690 | |
691 | int bond_option_use_carrier_set(struct bonding *bond, int use_carrier) | |
692 | { | |
693 | if ((use_carrier == 0) || (use_carrier == 1)) { | |
694 | bond->params.use_carrier = use_carrier; | |
695 | pr_info("%s: Setting use_carrier to %d.\n", | |
696 | bond->dev->name, use_carrier); | |
697 | } else { | |
698 | pr_info("%s: Ignoring invalid use_carrier value %d.\n", | |
699 | bond->dev->name, use_carrier); | |
700 | } | |
701 | ||
702 | return 0; | |
703 | } | |
06151dbc | 704 | |
7bdb04ed NA |
705 | int bond_option_arp_interval_set(struct bonding *bond, |
706 | struct bond_opt_value *newval) | |
06151dbc | 707 | { |
7bdb04ed NA |
708 | pr_info("%s: Setting ARP monitoring interval to %llu.\n", |
709 | bond->dev->name, newval->value); | |
710 | bond->params.arp_interval = newval->value; | |
711 | if (newval->value) { | |
06151dbc | 712 | if (bond->params.miimon) { |
713 | pr_info("%s: ARP monitoring cannot be used with MII monitoring. %s Disabling MII monitoring.\n", | |
714 | bond->dev->name, bond->dev->name); | |
715 | bond->params.miimon = 0; | |
716 | } | |
717 | if (!bond->params.arp_targets[0]) | |
718 | pr_info("%s: ARP monitoring has been set up, but no ARP targets have been specified.\n", | |
719 | bond->dev->name); | |
720 | } | |
721 | if (bond->dev->flags & IFF_UP) { | |
722 | /* If the interface is up, we may need to fire off | |
723 | * the ARP timer. If the interface is down, the | |
724 | * timer will get fired off when the open function | |
725 | * is called. | |
726 | */ | |
7bdb04ed | 727 | if (!newval->value) { |
06151dbc | 728 | if (bond->params.arp_validate) |
729 | bond->recv_probe = NULL; | |
730 | cancel_delayed_work_sync(&bond->arp_work); | |
731 | } else { | |
732 | /* arp_validate can be set only in active-backup mode */ | |
733 | if (bond->params.arp_validate) | |
734 | bond->recv_probe = bond_arp_rcv; | |
735 | cancel_delayed_work_sync(&bond->mii_work); | |
736 | queue_delayed_work(bond->wq, &bond->arp_work, 0); | |
737 | } | |
738 | } | |
739 | ||
740 | return 0; | |
741 | } | |
7f28fa10 | 742 | |
743 | static void _bond_options_arp_ip_target_set(struct bonding *bond, int slot, | |
744 | __be32 target, | |
745 | unsigned long last_rx) | |
746 | { | |
747 | __be32 *targets = bond->params.arp_targets; | |
748 | struct list_head *iter; | |
749 | struct slave *slave; | |
750 | ||
751 | if (slot >= 0 && slot < BOND_MAX_ARP_TARGETS) { | |
752 | bond_for_each_slave(bond, slave, iter) | |
753 | slave->target_last_arp_rx[slot] = last_rx; | |
754 | targets[slot] = target; | |
755 | } | |
756 | } | |
757 | ||
758 | static int _bond_option_arp_ip_target_add(struct bonding *bond, __be32 target) | |
759 | { | |
760 | __be32 *targets = bond->params.arp_targets; | |
761 | int ind; | |
762 | ||
763 | if (IS_IP_TARGET_UNUSABLE_ADDRESS(target)) { | |
764 | pr_err("%s: invalid ARP target %pI4 specified for addition\n", | |
765 | bond->dev->name, &target); | |
766 | return -EINVAL; | |
767 | } | |
768 | ||
769 | if (bond_get_targets_ip(targets, target) != -1) { /* dup */ | |
770 | pr_err("%s: ARP target %pI4 is already present\n", | |
771 | bond->dev->name, &target); | |
772 | return -EINVAL; | |
773 | } | |
774 | ||
775 | ind = bond_get_targets_ip(targets, 0); /* first free slot */ | |
776 | if (ind == -1) { | |
777 | pr_err("%s: ARP target table is full!\n", | |
778 | bond->dev->name); | |
779 | return -EINVAL; | |
780 | } | |
781 | ||
782 | pr_info("%s: adding ARP target %pI4.\n", bond->dev->name, &target); | |
783 | ||
784 | _bond_options_arp_ip_target_set(bond, ind, target, jiffies); | |
785 | ||
786 | return 0; | |
787 | } | |
788 | ||
789 | int bond_option_arp_ip_target_add(struct bonding *bond, __be32 target) | |
790 | { | |
791 | int ret; | |
792 | ||
793 | /* not to race with bond_arp_rcv */ | |
794 | write_lock_bh(&bond->lock); | |
795 | ret = _bond_option_arp_ip_target_add(bond, target); | |
796 | write_unlock_bh(&bond->lock); | |
797 | ||
798 | return ret; | |
799 | } | |
800 | ||
801 | int bond_option_arp_ip_target_rem(struct bonding *bond, __be32 target) | |
802 | { | |
803 | __be32 *targets = bond->params.arp_targets; | |
804 | struct list_head *iter; | |
805 | struct slave *slave; | |
806 | unsigned long *targets_rx; | |
807 | int ind, i; | |
808 | ||
809 | if (IS_IP_TARGET_UNUSABLE_ADDRESS(target)) { | |
810 | pr_err("%s: invalid ARP target %pI4 specified for removal\n", | |
811 | bond->dev->name, &target); | |
812 | return -EINVAL; | |
813 | } | |
814 | ||
815 | ind = bond_get_targets_ip(targets, target); | |
816 | if (ind == -1) { | |
817 | pr_err("%s: unable to remove nonexistent ARP target %pI4.\n", | |
818 | bond->dev->name, &target); | |
819 | return -EINVAL; | |
820 | } | |
821 | ||
822 | if (ind == 0 && !targets[1] && bond->params.arp_interval) | |
823 | pr_warn("%s: removing last arp target with arp_interval on\n", | |
824 | bond->dev->name); | |
825 | ||
826 | pr_info("%s: removing ARP target %pI4.\n", bond->dev->name, | |
827 | &target); | |
828 | ||
829 | /* not to race with bond_arp_rcv */ | |
830 | write_lock_bh(&bond->lock); | |
831 | ||
832 | bond_for_each_slave(bond, slave, iter) { | |
833 | targets_rx = slave->target_last_arp_rx; | |
834 | for (i = ind; (i < BOND_MAX_ARP_TARGETS-1) && targets[i+1]; i++) | |
835 | targets_rx[i] = targets_rx[i+1]; | |
836 | targets_rx[i] = 0; | |
837 | } | |
838 | for (i = ind; (i < BOND_MAX_ARP_TARGETS-1) && targets[i+1]; i++) | |
839 | targets[i] = targets[i+1]; | |
840 | targets[i] = 0; | |
841 | ||
842 | write_unlock_bh(&bond->lock); | |
843 | ||
844 | return 0; | |
845 | } | |
846 | ||
4fb0ef58 | 847 | void bond_option_arp_ip_targets_clear(struct bonding *bond) |
7f28fa10 | 848 | { |
4fb0ef58 | 849 | int i; |
7f28fa10 | 850 | |
851 | /* not to race with bond_arp_rcv */ | |
852 | write_lock_bh(&bond->lock); | |
7f28fa10 | 853 | for (i = 0; i < BOND_MAX_ARP_TARGETS; i++) |
854 | _bond_options_arp_ip_target_set(bond, i, 0, 0); | |
4fb0ef58 NA |
855 | write_unlock_bh(&bond->lock); |
856 | } | |
7f28fa10 | 857 | |
4fb0ef58 NA |
858 | int bond_option_arp_ip_targets_set(struct bonding *bond, |
859 | struct bond_opt_value *newval) | |
860 | { | |
861 | int ret = -EPERM; | |
862 | __be32 target; | |
863 | ||
864 | if (newval->string) { | |
865 | if (!in4_pton(newval->string+1, -1, (u8 *)&target, -1, NULL)) { | |
866 | pr_err("%s: invalid ARP target %pI4 specified\n", | |
867 | bond->dev->name, &target); | |
868 | return ret; | |
869 | } | |
870 | if (newval->string[0] == '+') | |
871 | ret = bond_option_arp_ip_target_add(bond, target); | |
872 | else if (newval->string[0] == '-') | |
873 | ret = bond_option_arp_ip_target_rem(bond, target); | |
874 | else | |
875 | pr_err("no command found in arp_ip_targets file for bond %s. Use +<addr> or -<addr>.\n", | |
876 | bond->dev->name); | |
877 | } else { | |
878 | target = newval->value; | |
879 | ret = bond_option_arp_ip_target_add(bond, target); | |
7f28fa10 | 880 | } |
881 | ||
7f28fa10 | 882 | return ret; |
883 | } | |
29c49482 | 884 | |
16228881 NA |
885 | int bond_option_arp_validate_set(struct bonding *bond, |
886 | struct bond_opt_value *newval) | |
29c49482 | 887 | { |
16228881 NA |
888 | pr_info("%s: setting arp_validate to %s (%llu).\n", |
889 | bond->dev->name, newval->string, newval->value); | |
29c49482 | 890 | |
891 | if (bond->dev->flags & IFF_UP) { | |
16228881 | 892 | if (!newval->value) |
29c49482 | 893 | bond->recv_probe = NULL; |
894 | else if (bond->params.arp_interval) | |
895 | bond->recv_probe = bond_arp_rcv; | |
896 | } | |
16228881 | 897 | bond->params.arp_validate = newval->value; |
29c49482 | 898 | |
899 | return 0; | |
900 | } | |
d5c84254 | 901 | |
edf36b24 NA |
902 | int bond_option_arp_all_targets_set(struct bonding *bond, |
903 | struct bond_opt_value *newval) | |
d5c84254 | 904 | { |
edf36b24 NA |
905 | pr_info("%s: setting arp_all_targets to %s (%llu).\n", |
906 | bond->dev->name, newval->string, newval->value); | |
907 | bond->params.arp_all_targets = newval->value; | |
d5c84254 | 908 | |
909 | return 0; | |
910 | } | |
0a98a0d1 | 911 | |
180222f0 | 912 | int bond_option_primary_set(struct bonding *bond, struct bond_opt_value *newval) |
0a98a0d1 | 913 | { |
180222f0 | 914 | char *p, *primary = newval->string; |
0a98a0d1 | 915 | struct list_head *iter; |
916 | struct slave *slave; | |
0a98a0d1 | 917 | |
918 | block_netpoll_tx(); | |
919 | read_lock(&bond->lock); | |
920 | write_lock_bh(&bond->curr_slave_lock); | |
921 | ||
180222f0 NA |
922 | p = strchr(primary, '\n'); |
923 | if (p) | |
924 | *p = '\0'; | |
0a98a0d1 | 925 | /* check to see if we are clearing primary */ |
926 | if (!strlen(primary)) { | |
927 | pr_info("%s: Setting primary slave to None.\n", | |
928 | bond->dev->name); | |
929 | bond->primary_slave = NULL; | |
930 | memset(bond->params.primary, 0, sizeof(bond->params.primary)); | |
931 | bond_select_active_slave(bond); | |
932 | goto out; | |
933 | } | |
934 | ||
935 | bond_for_each_slave(bond, slave, iter) { | |
936 | if (strncmp(slave->dev->name, primary, IFNAMSIZ) == 0) { | |
937 | pr_info("%s: Setting %s as primary slave.\n", | |
938 | bond->dev->name, slave->dev->name); | |
939 | bond->primary_slave = slave; | |
940 | strcpy(bond->params.primary, slave->dev->name); | |
941 | bond_select_active_slave(bond); | |
942 | goto out; | |
943 | } | |
944 | } | |
945 | ||
946 | strncpy(bond->params.primary, primary, IFNAMSIZ); | |
947 | bond->params.primary[IFNAMSIZ - 1] = 0; | |
948 | ||
949 | pr_info("%s: Recording %s as primary, but it has not been enslaved to %s yet.\n", | |
950 | bond->dev->name, primary, bond->dev->name); | |
951 | ||
952 | out: | |
953 | write_unlock_bh(&bond->curr_slave_lock); | |
954 | read_unlock(&bond->lock); | |
955 | unblock_netpoll_tx(); | |
956 | ||
180222f0 | 957 | return 0; |
0a98a0d1 | 958 | } |
8a41ae44 | 959 | |
388d3a6d NA |
960 | int bond_option_primary_reselect_set(struct bonding *bond, |
961 | struct bond_opt_value *newval) | |
8a41ae44 | 962 | { |
388d3a6d NA |
963 | pr_info("%s: setting primary_reselect to %s (%llu).\n", |
964 | bond->dev->name, newval->string, newval->value); | |
965 | bond->params.primary_reselect = newval->value; | |
8a41ae44 | 966 | |
967 | block_netpoll_tx(); | |
968 | write_lock_bh(&bond->curr_slave_lock); | |
969 | bond_select_active_slave(bond); | |
970 | write_unlock_bh(&bond->curr_slave_lock); | |
971 | unblock_netpoll_tx(); | |
972 | ||
973 | return 0; | |
974 | } | |
89901972 | 975 | |
1df6b6aa NA |
976 | int bond_option_fail_over_mac_set(struct bonding *bond, |
977 | struct bond_opt_value *newval) | |
89901972 | 978 | { |
1df6b6aa NA |
979 | pr_info("%s: Setting fail_over_mac to %s (%llu).\n", |
980 | bond->dev->name, newval->string, newval->value); | |
981 | bond->params.fail_over_mac = newval->value; | |
89901972 | 982 | |
983 | return 0; | |
984 | } | |
f70161c6 | 985 | |
a4b32ce7 NA |
986 | int bond_option_xmit_hash_policy_set(struct bonding *bond, |
987 | struct bond_opt_value *newval) | |
f70161c6 | 988 | { |
a4b32ce7 NA |
989 | pr_info("%s: setting xmit hash policy to %s (%llu).\n", |
990 | bond->dev->name, newval->string, newval->value); | |
991 | bond->params.xmit_policy = newval->value; | |
f70161c6 | 992 | |
993 | return 0; | |
994 | } | |
d8838de7 | 995 | |
996 | int bond_option_resend_igmp_set(struct bonding *bond, int resend_igmp) | |
997 | { | |
998 | if (resend_igmp < 0 || resend_igmp > 255) { | |
999 | pr_err("%s: Invalid resend_igmp value %d not in range 0-255; rejected.\n", | |
1000 | bond->dev->name, resend_igmp); | |
1001 | return -EINVAL; | |
1002 | } | |
1003 | ||
1004 | bond->params.resend_igmp = resend_igmp; | |
1005 | pr_info("%s: Setting resend_igmp to %d.\n", | |
1006 | bond->dev->name, resend_igmp); | |
1007 | ||
1008 | return 0; | |
1009 | } | |
2c9839c1 | 1010 | |
ef56becb NA |
1011 | int bond_option_num_peer_notif_set(struct bonding *bond, |
1012 | struct bond_opt_value *newval) | |
2c9839c1 | 1013 | { |
ef56becb NA |
1014 | bond->params.num_peer_notif = newval->value; |
1015 | ||
2c9839c1 | 1016 | return 0; |
1017 | } | |
1cc0b1e3 | 1018 | |
1019 | int bond_option_all_slaves_active_set(struct bonding *bond, | |
1020 | int all_slaves_active) | |
1021 | { | |
1022 | struct list_head *iter; | |
1023 | struct slave *slave; | |
1024 | ||
1025 | if (all_slaves_active == bond->params.all_slaves_active) | |
1026 | return 0; | |
1027 | ||
1028 | if ((all_slaves_active == 0) || (all_slaves_active == 1)) { | |
1029 | bond->params.all_slaves_active = all_slaves_active; | |
1030 | } else { | |
1031 | pr_info("%s: Ignoring invalid all_slaves_active value %d.\n", | |
1032 | bond->dev->name, all_slaves_active); | |
1033 | return -EINVAL; | |
1034 | } | |
1035 | ||
1036 | bond_for_each_slave(bond, slave, iter) { | |
1037 | if (!bond_is_active_slave(slave)) { | |
1038 | if (all_slaves_active) | |
1039 | slave->inactive = 0; | |
1040 | else | |
1041 | slave->inactive = 1; | |
1042 | } | |
1043 | } | |
1044 | ||
1045 | return 0; | |
1046 | } | |
7d101008 | 1047 | |
633ddc9e NA |
1048 | int bond_option_min_links_set(struct bonding *bond, |
1049 | struct bond_opt_value *newval) | |
7d101008 | 1050 | { |
633ddc9e NA |
1051 | pr_info("%s: Setting min links value to %llu\n", |
1052 | bond->dev->name, newval->value); | |
1053 | bond->params.min_links = newval->value; | |
7d101008 | 1054 | |
1055 | return 0; | |
1056 | } | |
8d836d09 | 1057 | |
1058 | int bond_option_lp_interval_set(struct bonding *bond, int lp_interval) | |
1059 | { | |
1060 | if (lp_interval <= 0) { | |
1061 | pr_err("%s: lp_interval must be between 1 and %d\n", | |
1062 | bond->dev->name, INT_MAX); | |
1063 | return -EINVAL; | |
1064 | } | |
1065 | ||
1066 | bond->params.lp_interval = lp_interval; | |
1067 | ||
1068 | return 0; | |
1069 | } | |
c13ab3ff | 1070 | |
aa59d851 | 1071 | int bond_option_pps_set(struct bonding *bond, struct bond_opt_value *newval) |
c13ab3ff | 1072 | { |
aa59d851 NA |
1073 | bond->params.packets_per_slave = newval->value; |
1074 | if (newval->value > 0) { | |
809fa972 | 1075 | bond->params.reciprocal_packets_per_slave = |
aa59d851 | 1076 | reciprocal_value(newval->value); |
809fa972 HFS |
1077 | } else { |
1078 | /* reciprocal_packets_per_slave is unused if | |
1079 | * packets_per_slave is 0 or 1, just initialize it | |
1080 | */ | |
1081 | bond->params.reciprocal_packets_per_slave = | |
1082 | (struct reciprocal_value) { 0 }; | |
1083 | } | |
c13ab3ff | 1084 | |
1085 | return 0; | |
1086 | } | |
998e40bb | 1087 | |
d3131de7 NA |
1088 | int bond_option_lacp_rate_set(struct bonding *bond, |
1089 | struct bond_opt_value *newval) | |
998e40bb | 1090 | { |
d3131de7 NA |
1091 | pr_info("%s: Setting LACP rate to %s (%llu).\n", |
1092 | bond->dev->name, newval->string, newval->value); | |
1093 | bond->params.lacp_fast = newval->value; | |
3243c47b | 1094 | bond_3ad_update_lacp_rate(bond); |
998e40bb | 1095 | |
1096 | return 0; | |
1097 | } | |
ec029fac | 1098 | |
9e5f5eeb NA |
1099 | int bond_option_ad_select_set(struct bonding *bond, |
1100 | struct bond_opt_value *newval) | |
ec029fac | 1101 | { |
9e5f5eeb NA |
1102 | pr_info("%s: Setting ad_select to %s (%llu).\n", |
1103 | bond->dev->name, newval->string, newval->value); | |
1104 | bond->params.ad_select = newval->value; | |
ec029fac | 1105 | |
1106 | return 0; | |
1107 | } |