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