blob: 1bd19f1f1af25f4d54d1b5280e68477f5192815b [file] [log] [blame]
Jiri Pirko72be35f2013-10-18 17:43:34 +02001/*
2 * drivers/net/bond/bond_options.c - bonding options
3 * Copyright (c) 2013 Jiri Pirko <jiri@resnulli.us>
sfeldma@cumulusnetworks.comeecdaa62013-12-12 14:09:55 -08004 * Copyright (c) 2013 Scott Feldman <sfeldma@cumulusnetworks.com>
Jiri Pirko72be35f2013-10-18 17:43:34 +02005 *
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>
Jiri Pirkod9e32b22013-10-18 17:43:35 +020016#include <linux/netdevice.h>
17#include <linux/rwlock.h>
18#include <linux/rcupdate.h>
Nikolay Aleksandrov09117362014-01-22 14:53:16 +010019#include <linux/ctype.h>
Nikolay Aleksandrov4fb0ef52014-01-22 14:53:24 +010020#include <linux/inet.h>
Jiri Pirko72be35f2013-10-18 17:43:34 +020021#include "bonding.h"
22
Nikolay Aleksandrov2b3798d2014-01-22 14:53:17 +010023static 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
Nikolay Aleksandrovaa59d852014-01-22 14:53:18 +010034static 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
Nikolay Aleksandrova4b32ce2014-01-22 14:53:19 +010040static 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
Nikolay Aleksandrov16228882014-01-22 14:53:20 +010049static 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
Nikolay Aleksandrovedf36b22014-01-22 14:53:21 +010057static 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
Nikolay Aleksandrov1df6b6a2014-01-22 14:53:22 +010063static 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
Nikolay Aleksandrov7bdb04e2014-01-22 14:53:23 +010070static struct bond_opt_value bond_intmax_tbl[] = {
71 { "off", 0, BOND_VALFLAG_DEFAULT},
72 { "maxval", INT_MAX, BOND_VALFLAG_MAX},
73};
74
Nikolay Aleksandrovd3131de2014-01-22 14:53:27 +010075static 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
Nikolay Aleksandrov9e5f5ee2014-01-22 14:53:29 +010081static 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
Nikolay Aleksandrovef56bec2014-01-22 14:53:30 +010088static 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
Nikolay Aleksandrov09117362014-01-22 14:53:16 +010095static struct bond_option bond_opts[] = {
Nikolay Aleksandrov2b3798d2014-01-22 14:53:17 +010096 [BOND_OPT_MODE] = {
97 .id = BOND_OPT_MODE,
98 .name = "mode",
99 .desc = "bond device mode",
100 .flags = BOND_OPTFLAG_NOSLAVES | BOND_OPTFLAG_IFDOWN,
101 .values = bond_mode_tbl,
102 .set = bond_option_mode_set
103 },
Nikolay Aleksandrovaa59d852014-01-22 14:53:18 +0100104 [BOND_OPT_PACKETS_PER_SLAVE] = {
105 .id = BOND_OPT_PACKETS_PER_SLAVE,
106 .name = "packets_per_slave",
107 .desc = "Packets to send per slave in RR mode",
108 .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_ROUNDROBIN)),
109 .values = bond_pps_tbl,
110 .set = bond_option_pps_set
111 },
Nikolay Aleksandrova4b32ce2014-01-22 14:53:19 +0100112 [BOND_OPT_XMIT_HASH] = {
113 .id = BOND_OPT_XMIT_HASH,
114 .name = "xmit_hash_policy",
115 .desc = "balance-xor and 802.3ad hashing method",
116 .values = bond_xmit_hashtype_tbl,
117 .set = bond_option_xmit_hash_policy_set
118 },
Nikolay Aleksandrov16228882014-01-22 14:53:20 +0100119 [BOND_OPT_ARP_VALIDATE] = {
120 .id = BOND_OPT_ARP_VALIDATE,
121 .name = "arp_validate",
122 .desc = "validate src/dst of ARP probes",
123 .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_ACTIVEBACKUP)),
124 .values = bond_arp_validate_tbl,
125 .set = bond_option_arp_validate_set
126 },
Nikolay Aleksandrovedf36b22014-01-22 14:53:21 +0100127 [BOND_OPT_ARP_ALL_TARGETS] = {
128 .id = BOND_OPT_ARP_ALL_TARGETS,
129 .name = "arp_all_targets",
130 .desc = "fail on any/all arp targets timeout",
131 .values = bond_arp_all_targets_tbl,
132 .set = bond_option_arp_all_targets_set
133 },
Nikolay Aleksandrov1df6b6a2014-01-22 14:53:22 +0100134 [BOND_OPT_FAIL_OVER_MAC] = {
135 .id = BOND_OPT_FAIL_OVER_MAC,
136 .name = "fail_over_mac",
137 .desc = "For active-backup, do not set all slaves to the same MAC",
138 .flags = BOND_OPTFLAG_NOSLAVES,
139 .values = bond_fail_over_mac_tbl,
140 .set = bond_option_fail_over_mac_set
141 },
Nikolay Aleksandrov7bdb04e2014-01-22 14:53:23 +0100142 [BOND_OPT_ARP_INTERVAL] = {
143 .id = BOND_OPT_ARP_INTERVAL,
144 .name = "arp_interval",
145 .desc = "arp interval in milliseconds",
146 .unsuppmodes = BIT(BOND_MODE_8023AD) | BIT(BOND_MODE_TLB) |
147 BIT(BOND_MODE_ALB),
148 .values = bond_intmax_tbl,
149 .set = bond_option_arp_interval_set
150 },
Nikolay Aleksandrov4fb0ef52014-01-22 14:53:24 +0100151 [BOND_OPT_ARP_TARGETS] = {
152 .id = BOND_OPT_ARP_TARGETS,
153 .name = "arp_ip_target",
154 .desc = "arp targets in n.n.n.n form",
155 .flags = BOND_OPTFLAG_RAWVAL,
156 .set = bond_option_arp_ip_targets_set
157 },
Nikolay Aleksandrov25a9b542014-01-22 14:53:25 +0100158 [BOND_OPT_DOWNDELAY] = {
159 .id = BOND_OPT_DOWNDELAY,
160 .name = "downdelay",
161 .desc = "Delay before considering link down, in milliseconds",
162 .values = bond_intmax_tbl,
163 .set = bond_option_downdelay_set
164 },
Nikolay Aleksandrove4994612014-01-22 14:53:26 +0100165 [BOND_OPT_UPDELAY] = {
166 .id = BOND_OPT_UPDELAY,
167 .name = "updelay",
168 .desc = "Delay before considering link up, in milliseconds",
169 .values = bond_intmax_tbl,
170 .set = bond_option_updelay_set
171 },
Nikolay Aleksandrovd3131de2014-01-22 14:53:27 +0100172 [BOND_OPT_LACP_RATE] = {
173 .id = BOND_OPT_LACP_RATE,
174 .name = "lacp_rate",
175 .desc = "LACPDU tx rate to request from 802.3ad partner",
176 .flags = BOND_OPTFLAG_IFDOWN,
177 .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_8023AD)),
178 .values = bond_lacp_rate_tbl,
179 .set = bond_option_lacp_rate_set
180 },
Nikolay Aleksandrov633ddc92014-01-22 14:53:28 +0100181 [BOND_OPT_MINLINKS] = {
182 .id = BOND_OPT_MINLINKS,
183 .name = "min_links",
184 .desc = "Minimum number of available links before turning on carrier",
185 .values = bond_intmax_tbl,
186 .set = bond_option_min_links_set
187 },
Nikolay Aleksandrov9e5f5ee2014-01-22 14:53:29 +0100188 [BOND_OPT_AD_SELECT] = {
189 .id = BOND_OPT_AD_SELECT,
190 .name = "ad_select",
191 .desc = "803.ad aggregation selection logic",
192 .flags = BOND_OPTFLAG_IFDOWN,
193 .values = bond_ad_select_tbl,
194 .set = bond_option_ad_select_set
195 },
Nikolay Aleksandrovef56bec2014-01-22 14:53:30 +0100196 [BOND_OPT_NUM_PEER_NOTIF] = {
197 .id = BOND_OPT_NUM_PEER_NOTIF,
198 .name = "num_unsol_na",
199 .desc = "Number of peer notifications to send on failover event",
200 .values = bond_num_peer_notif_tbl,
201 .set = bond_option_num_peer_notif_set
202 },
Nikolay Aleksandrov09117362014-01-22 14:53:16 +0100203 { }
204};
205
206/* Searches for a value in opt's values[] table */
207struct bond_opt_value *bond_opt_get_val(unsigned int option, u64 val)
208{
209 struct bond_option *opt;
210 int i;
211
212 opt = bond_opt_get(option);
213 if (WARN_ON(!opt))
214 return NULL;
215 for (i = 0; opt->values && opt->values[i].string; i++)
216 if (opt->values[i].value == val)
217 return &opt->values[i];
218
219 return NULL;
220}
221
222/* Searches for a value in opt's values[] table which matches the flagmask */
223static struct bond_opt_value *bond_opt_get_flags(const struct bond_option *opt,
224 u32 flagmask)
225{
226 int i;
227
228 for (i = 0; opt->values && opt->values[i].string; i++)
229 if (opt->values[i].flags & flagmask)
230 return &opt->values[i];
231
232 return NULL;
233}
234
235/* If maxval is missing then there's no range to check. In case minval is
236 * missing then it's considered to be 0.
237 */
238static bool bond_opt_check_range(const struct bond_option *opt, u64 val)
239{
240 struct bond_opt_value *minval, *maxval;
241
242 minval = bond_opt_get_flags(opt, BOND_VALFLAG_MIN);
243 maxval = bond_opt_get_flags(opt, BOND_VALFLAG_MAX);
244 if (!maxval || (minval && val < minval->value) || val > maxval->value)
245 return false;
246
247 return true;
248}
249
250/**
251 * bond_opt_parse - parse option value
252 * @opt: the option to parse against
253 * @val: value to parse
254 *
255 * This function tries to extract the value from @val and check if it's
256 * a possible match for the option and returns NULL if a match isn't found,
257 * or the struct_opt_value that matched. It also strips the new line from
258 * @val->string if it's present.
259 */
260struct bond_opt_value *bond_opt_parse(const struct bond_option *opt,
261 struct bond_opt_value *val)
262{
263 char *p, valstr[BOND_OPT_MAX_NAMELEN + 1] = { 0, };
264 struct bond_opt_value *tbl, *ret = NULL;
265 bool checkval;
266 int i, rv;
267
268 /* No parsing if the option wants a raw val */
269 if (opt->flags & BOND_OPTFLAG_RAWVAL)
270 return val;
271
272 tbl = opt->values;
273 if (!tbl)
274 goto out;
275
276 /* ULLONG_MAX is used to bypass string processing */
277 checkval = val->value != ULLONG_MAX;
278 if (!checkval) {
279 if (!val->string)
280 goto out;
281 p = strchr(val->string, '\n');
282 if (p)
283 *p = '\0';
284 for (p = val->string; *p; p++)
285 if (!(isdigit(*p) || isspace(*p)))
286 break;
287 /* The following code extracts the string to match or the value
288 * and sets checkval appropriately
289 */
290 if (*p) {
291 rv = sscanf(val->string, "%32s", valstr);
292 } else {
293 rv = sscanf(val->string, "%llu", &val->value);
294 checkval = true;
295 }
296 if (!rv)
297 goto out;
298 }
299
300 for (i = 0; tbl[i].string; i++) {
301 /* Check for exact match */
302 if (checkval) {
303 if (val->value == tbl[i].value)
304 ret = &tbl[i];
305 } else {
306 if (!strcmp(valstr, "default") &&
307 (tbl[i].flags & BOND_VALFLAG_DEFAULT))
308 ret = &tbl[i];
309
310 if (!strcmp(valstr, tbl[i].string))
311 ret = &tbl[i];
312 }
313 /* Found an exact match */
314 if (ret)
315 goto out;
316 }
317 /* Possible range match */
318 if (checkval && bond_opt_check_range(opt, val->value))
319 ret = val;
320out:
321 return ret;
322}
323
324/* Check opt's dependencies against bond mode and currently set options */
325static int bond_opt_check_deps(struct bonding *bond,
326 const struct bond_option *opt)
327{
328 struct bond_params *params = &bond->params;
329
330 if (test_bit(params->mode, &opt->unsuppmodes))
331 return -EACCES;
332 if ((opt->flags & BOND_OPTFLAG_NOSLAVES) && bond_has_slaves(bond))
333 return -ENOTEMPTY;
334 if ((opt->flags & BOND_OPTFLAG_IFDOWN) && (bond->dev->flags & IFF_UP))
335 return -EBUSY;
336
337 return 0;
338}
339
340static void bond_opt_dep_print(struct bonding *bond,
341 const struct bond_option *opt)
342{
Nikolay Aleksandrov2b3798d2014-01-22 14:53:17 +0100343 struct bond_opt_value *modeval;
Nikolay Aleksandrov09117362014-01-22 14:53:16 +0100344 struct bond_params *params;
345
346 params = &bond->params;
Nikolay Aleksandrov2b3798d2014-01-22 14:53:17 +0100347 modeval = bond_opt_get_val(BOND_OPT_MODE, params->mode);
Nikolay Aleksandrov09117362014-01-22 14:53:16 +0100348 if (test_bit(params->mode, &opt->unsuppmodes))
Nikolay Aleksandrov2b3798d2014-01-22 14:53:17 +0100349 pr_err("%s: option %s: mode dependency failed, not supported in mode %s(%llu)\n",
350 bond->dev->name, opt->name,
351 modeval->string, modeval->value);
Nikolay Aleksandrov09117362014-01-22 14:53:16 +0100352}
353
354static void bond_opt_error_interpret(struct bonding *bond,
355 const struct bond_option *opt,
356 int error, struct bond_opt_value *val)
357{
358 struct bond_opt_value *minval, *maxval;
359 char *p;
360
361 switch (error) {
362 case -EINVAL:
363 if (val) {
364 if (val->string) {
365 /* sometimes RAWVAL opts may have new lines */
366 p = strchr(val->string, '\n');
367 if (p)
368 *p = '\0';
369 pr_err("%s: option %s: invalid value (%s).\n",
370 bond->dev->name, opt->name, val->string);
371 } else {
372 pr_err("%s: option %s: invalid value (%llu).\n",
373 bond->dev->name, opt->name, val->value);
374 }
375 }
376 minval = bond_opt_get_flags(opt, BOND_VALFLAG_MIN);
377 maxval = bond_opt_get_flags(opt, BOND_VALFLAG_MAX);
378 if (!maxval)
379 break;
380 pr_err("%s: option %s: allowed values %llu - %llu.\n",
381 bond->dev->name, opt->name, minval ? minval->value : 0,
382 maxval->value);
383 break;
384 case -EACCES:
385 bond_opt_dep_print(bond, opt);
386 break;
387 case -ENOTEMPTY:
388 pr_err("%s: option %s: unable to set because the bond device has slaves.\n",
389 bond->dev->name, opt->name);
390 break;
391 case -EBUSY:
392 pr_err("%s: option %s: unable to set because the bond device is up.\n",
393 bond->dev->name, opt->name);
394 break;
395 default:
396 break;
397 }
398}
399
400/**
401 * __bond_opt_set - set a bonding option
402 * @bond: target bond device
403 * @option: option to set
404 * @val: value to set it to
405 *
406 * This function is used to change the bond's option value, it can be
407 * used for both enabling/changing an option and for disabling it. RTNL lock
408 * must be obtained before calling this function.
409 */
410int __bond_opt_set(struct bonding *bond,
411 unsigned int option, struct bond_opt_value *val)
412{
413 struct bond_opt_value *retval = NULL;
414 const struct bond_option *opt;
415 int ret = -ENOENT;
416
417 ASSERT_RTNL();
418
419 opt = bond_opt_get(option);
420 if (WARN_ON(!val) || WARN_ON(!opt))
421 goto out;
422 ret = bond_opt_check_deps(bond, opt);
423 if (ret)
424 goto out;
425 retval = bond_opt_parse(opt, val);
426 if (!retval) {
427 ret = -EINVAL;
428 goto out;
429 }
430 ret = opt->set(bond, retval);
431out:
432 if (ret)
433 bond_opt_error_interpret(bond, opt, ret, val);
434
435 return ret;
436}
437
438/**
439 * bond_opt_tryset_rtnl - try to acquire rtnl and call __bond_opt_set
440 * @bond: target bond device
441 * @option: option to set
442 * @buf: value to set it to
443 *
444 * This function tries to acquire RTNL without blocking and if successful
445 * calls __bond_opt_set. It is mainly used for sysfs option manipulation.
446 */
447int bond_opt_tryset_rtnl(struct bonding *bond, unsigned int option, char *buf)
448{
449 struct bond_opt_value optval;
450 int ret;
451
452 if (!rtnl_trylock())
453 return restart_syscall();
454 bond_opt_initstr(&optval, buf);
455 ret = __bond_opt_set(bond, option, &optval);
456 rtnl_unlock();
457
458 return ret;
459}
460
461/**
462 * bond_opt_get - get a pointer to an option
463 * @option: option for which to return a pointer
464 *
465 * This function checks if option is valid and if so returns a pointer
466 * to its entry in the bond_opts[] option array.
467 */
468struct bond_option *bond_opt_get(unsigned int option)
469{
470 if (!BOND_OPT_VALID(option))
471 return NULL;
472
473 return &bond_opts[option];
474}
475
Nikolay Aleksandrov2b3798d2014-01-22 14:53:17 +0100476int bond_option_mode_set(struct bonding *bond, struct bond_opt_value *newval)
Jiri Pirko72be35f2013-10-18 17:43:34 +0200477{
Nikolay Aleksandrov2b3798d2014-01-22 14:53:17 +0100478 if (BOND_NO_USES_ARP(newval->value) && bond->params.arp_interval) {
dingtianhongfe9d04a2013-11-22 22:28:43 +0800479 pr_info("%s: %s mode is incompatible with arp monitoring, start mii monitoring\n",
Nikolay Aleksandrov2b3798d2014-01-22 14:53:17 +0100480 bond->dev->name, newval->string);
dingtianhongfe9d04a2013-11-22 22:28:43 +0800481 /* disable arp monitoring */
482 bond->params.arp_interval = 0;
483 /* set miimon to default value */
484 bond->params.miimon = BOND_DEFAULT_MIIMON;
485 pr_info("%s: Setting MII monitoring interval to %d.\n",
486 bond->dev->name, bond->params.miimon);
Jiri Pirko72be35f2013-10-18 17:43:34 +0200487 }
488
489 /* don't cache arp_validate between modes */
490 bond->params.arp_validate = BOND_ARP_VALIDATE_NONE;
Nikolay Aleksandrov2b3798d2014-01-22 14:53:17 +0100491 bond->params.mode = newval->value;
492
Jiri Pirko72be35f2013-10-18 17:43:34 +0200493 return 0;
494}
Jiri Pirkod9e32b22013-10-18 17:43:35 +0200495
Jiri Pirko752d48b2013-10-18 17:43:37 +0200496static struct net_device *__bond_option_active_slave_get(struct bonding *bond,
497 struct slave *slave)
498{
499 return USES_PRIMARY(bond->params.mode) && slave ? slave->dev : NULL;
500}
501
502struct net_device *bond_option_active_slave_get_rcu(struct bonding *bond)
503{
504 struct slave *slave = rcu_dereference(bond->curr_active_slave);
505
506 return __bond_option_active_slave_get(bond, slave);
507}
508
509struct net_device *bond_option_active_slave_get(struct bonding *bond)
510{
511 return __bond_option_active_slave_get(bond, bond->curr_active_slave);
512}
513
Jiri Pirkod9e32b22013-10-18 17:43:35 +0200514int bond_option_active_slave_set(struct bonding *bond,
515 struct net_device *slave_dev)
516{
517 int ret = 0;
518
519 if (slave_dev) {
520 if (!netif_is_bond_slave(slave_dev)) {
521 pr_err("Device %s is not bonding slave.\n",
522 slave_dev->name);
523 return -EINVAL;
524 }
525
526 if (bond->dev != netdev_master_upper_dev_get(slave_dev)) {
527 pr_err("%s: Device %s is not our slave.\n",
528 bond->dev->name, slave_dev->name);
529 return -EINVAL;
530 }
531 }
532
533 if (!USES_PRIMARY(bond->params.mode)) {
534 pr_err("%s: Unable to change active slave; %s is in mode %d\n",
535 bond->dev->name, bond->dev->name, bond->params.mode);
536 return -EINVAL;
537 }
538
539 block_netpoll_tx();
Jiri Pirkod9e32b22013-10-18 17:43:35 +0200540 write_lock_bh(&bond->curr_slave_lock);
541
542 /* check to see if we are clearing active */
543 if (!slave_dev) {
544 pr_info("%s: Clearing current active slave.\n",
545 bond->dev->name);
546 rcu_assign_pointer(bond->curr_active_slave, NULL);
547 bond_select_active_slave(bond);
548 } else {
549 struct slave *old_active = bond->curr_active_slave;
550 struct slave *new_active = bond_slave_get_rtnl(slave_dev);
551
552 BUG_ON(!new_active);
553
554 if (new_active == old_active) {
555 /* do nothing */
556 pr_info("%s: %s is already the current active slave.\n",
557 bond->dev->name, new_active->dev->name);
558 } else {
559 if (old_active && (new_active->link == BOND_LINK_UP) &&
560 IS_UP(new_active->dev)) {
561 pr_info("%s: Setting %s as active slave.\n",
562 bond->dev->name, new_active->dev->name);
563 bond_change_active_slave(bond, new_active);
564 } else {
565 pr_err("%s: Could not set %s as active slave; either %s is down or the link is down.\n",
566 bond->dev->name, new_active->dev->name,
567 new_active->dev->name);
568 ret = -EINVAL;
569 }
570 }
571 }
572
573 write_unlock_bh(&bond->curr_slave_lock);
Jiri Pirkod9e32b22013-10-18 17:43:35 +0200574 unblock_netpoll_tx();
575 return ret;
576}
sfeldma@cumulusnetworks.comeecdaa62013-12-12 14:09:55 -0800577
578int bond_option_miimon_set(struct bonding *bond, int miimon)
579{
580 if (miimon < 0) {
581 pr_err("%s: Invalid miimon value %d not in range %d-%d; rejected.\n",
582 bond->dev->name, miimon, 0, INT_MAX);
583 return -EINVAL;
584 }
585 pr_info("%s: Setting MII monitoring interval to %d.\n",
586 bond->dev->name, miimon);
587 bond->params.miimon = miimon;
588 if (bond->params.updelay)
589 pr_info("%s: Note: Updating updelay (to %d) since it is a multiple of the miimon value.\n",
590 bond->dev->name,
591 bond->params.updelay * bond->params.miimon);
592 if (bond->params.downdelay)
593 pr_info("%s: Note: Updating downdelay (to %d) since it is a multiple of the miimon value.\n",
594 bond->dev->name,
595 bond->params.downdelay * bond->params.miimon);
596 if (miimon && bond->params.arp_interval) {
597 pr_info("%s: MII monitoring cannot be used with ARP monitoring. Disabling ARP monitoring...\n",
598 bond->dev->name);
599 bond->params.arp_interval = 0;
600 if (bond->params.arp_validate)
601 bond->params.arp_validate = BOND_ARP_VALIDATE_NONE;
602 }
603 if (bond->dev->flags & IFF_UP) {
604 /* If the interface is up, we may need to fire off
605 * the MII timer. If the interface is down, the
606 * timer will get fired off when the open function
607 * is called.
608 */
609 if (!miimon) {
610 cancel_delayed_work_sync(&bond->mii_work);
611 } else {
612 cancel_delayed_work_sync(&bond->arp_work);
613 queue_delayed_work(bond->wq, &bond->mii_work, 0);
614 }
615 }
616 return 0;
617}
sfeldma@cumulusnetworks.com25852e22013-12-12 14:10:02 -0800618
Nikolay Aleksandrove4994612014-01-22 14:53:26 +0100619int bond_option_updelay_set(struct bonding *bond, struct bond_opt_value *newval)
sfeldma@cumulusnetworks.com25852e22013-12-12 14:10:02 -0800620{
Nikolay Aleksandrove4994612014-01-22 14:53:26 +0100621 if (!bond->params.miimon) {
sfeldma@cumulusnetworks.com25852e22013-12-12 14:10:02 -0800622 pr_err("%s: Unable to set up delay as MII monitoring is disabled\n",
623 bond->dev->name);
624 return -EPERM;
625 }
Nikolay Aleksandrove4994612014-01-22 14:53:26 +0100626 if ((newval->value % bond->params.miimon) != 0) {
627 pr_warn("%s: Warning: up delay (%llu) is not a multiple of miimon (%d), updelay rounded to %llu ms\n",
628 bond->dev->name, newval->value,
629 bond->params.miimon,
630 (newval->value / bond->params.miimon) *
631 bond->params.miimon);
sfeldma@cumulusnetworks.com25852e22013-12-12 14:10:02 -0800632 }
Nikolay Aleksandrove4994612014-01-22 14:53:26 +0100633 bond->params.updelay = newval->value / bond->params.miimon;
634 pr_info("%s: Setting up delay to %d.\n",
635 bond->dev->name,
636 bond->params.updelay * bond->params.miimon);
sfeldma@cumulusnetworks.com25852e22013-12-12 14:10:02 -0800637
638 return 0;
639}
sfeldma@cumulusnetworks.comc7461f92013-12-12 14:10:09 -0800640
Nikolay Aleksandrov25a9b542014-01-22 14:53:25 +0100641int bond_option_downdelay_set(struct bonding *bond,
642 struct bond_opt_value *newval)
sfeldma@cumulusnetworks.comc7461f92013-12-12 14:10:09 -0800643{
Nikolay Aleksandrov25a9b542014-01-22 14:53:25 +0100644 if (!bond->params.miimon) {
sfeldma@cumulusnetworks.comc7461f92013-12-12 14:10:09 -0800645 pr_err("%s: Unable to set down delay as MII monitoring is disabled\n",
646 bond->dev->name);
647 return -EPERM;
648 }
Nikolay Aleksandrov25a9b542014-01-22 14:53:25 +0100649 if ((newval->value % bond->params.miimon) != 0) {
650 pr_warn("%s: Warning: down delay (%llu) is not a multiple of miimon (%d), delay rounded to %llu ms\n",
651 bond->dev->name, newval->value,
652 bond->params.miimon,
653 (newval->value / bond->params.miimon) *
654 bond->params.miimon);
sfeldma@cumulusnetworks.comc7461f92013-12-12 14:10:09 -0800655 }
Nikolay Aleksandrov25a9b542014-01-22 14:53:25 +0100656 bond->params.downdelay = newval->value / bond->params.miimon;
657 pr_info("%s: Setting down delay to %d.\n",
658 bond->dev->name,
659 bond->params.downdelay * bond->params.miimon);
sfeldma@cumulusnetworks.comc7461f92013-12-12 14:10:09 -0800660
661 return 0;
662}
sfeldma@cumulusnetworks.com9f53e142013-12-12 14:10:16 -0800663
664int bond_option_use_carrier_set(struct bonding *bond, int use_carrier)
665{
666 if ((use_carrier == 0) || (use_carrier == 1)) {
667 bond->params.use_carrier = use_carrier;
668 pr_info("%s: Setting use_carrier to %d.\n",
669 bond->dev->name, use_carrier);
670 } else {
671 pr_info("%s: Ignoring invalid use_carrier value %d.\n",
672 bond->dev->name, use_carrier);
673 }
674
675 return 0;
676}
sfeldma@cumulusnetworks.com06151db2013-12-12 14:10:24 -0800677
Nikolay Aleksandrov7bdb04e2014-01-22 14:53:23 +0100678int bond_option_arp_interval_set(struct bonding *bond,
679 struct bond_opt_value *newval)
sfeldma@cumulusnetworks.com06151db2013-12-12 14:10:24 -0800680{
Nikolay Aleksandrov7bdb04e2014-01-22 14:53:23 +0100681 pr_info("%s: Setting ARP monitoring interval to %llu.\n",
682 bond->dev->name, newval->value);
683 bond->params.arp_interval = newval->value;
684 if (newval->value) {
sfeldma@cumulusnetworks.com06151db2013-12-12 14:10:24 -0800685 if (bond->params.miimon) {
686 pr_info("%s: ARP monitoring cannot be used with MII monitoring. %s Disabling MII monitoring.\n",
687 bond->dev->name, bond->dev->name);
688 bond->params.miimon = 0;
689 }
690 if (!bond->params.arp_targets[0])
691 pr_info("%s: ARP monitoring has been set up, but no ARP targets have been specified.\n",
692 bond->dev->name);
693 }
694 if (bond->dev->flags & IFF_UP) {
695 /* If the interface is up, we may need to fire off
696 * the ARP timer. If the interface is down, the
697 * timer will get fired off when the open function
698 * is called.
699 */
Nikolay Aleksandrov7bdb04e2014-01-22 14:53:23 +0100700 if (!newval->value) {
sfeldma@cumulusnetworks.com06151db2013-12-12 14:10:24 -0800701 if (bond->params.arp_validate)
702 bond->recv_probe = NULL;
703 cancel_delayed_work_sync(&bond->arp_work);
704 } else {
705 /* arp_validate can be set only in active-backup mode */
706 if (bond->params.arp_validate)
707 bond->recv_probe = bond_arp_rcv;
708 cancel_delayed_work_sync(&bond->mii_work);
709 queue_delayed_work(bond->wq, &bond->arp_work, 0);
710 }
711 }
712
713 return 0;
714}
sfeldma@cumulusnetworks.com7f28fa12013-12-12 14:10:31 -0800715
716static void _bond_options_arp_ip_target_set(struct bonding *bond, int slot,
717 __be32 target,
718 unsigned long last_rx)
719{
720 __be32 *targets = bond->params.arp_targets;
721 struct list_head *iter;
722 struct slave *slave;
723
724 if (slot >= 0 && slot < BOND_MAX_ARP_TARGETS) {
725 bond_for_each_slave(bond, slave, iter)
726 slave->target_last_arp_rx[slot] = last_rx;
727 targets[slot] = target;
728 }
729}
730
731static int _bond_option_arp_ip_target_add(struct bonding *bond, __be32 target)
732{
733 __be32 *targets = bond->params.arp_targets;
734 int ind;
735
736 if (IS_IP_TARGET_UNUSABLE_ADDRESS(target)) {
737 pr_err("%s: invalid ARP target %pI4 specified for addition\n",
738 bond->dev->name, &target);
739 return -EINVAL;
740 }
741
742 if (bond_get_targets_ip(targets, target) != -1) { /* dup */
743 pr_err("%s: ARP target %pI4 is already present\n",
744 bond->dev->name, &target);
745 return -EINVAL;
746 }
747
748 ind = bond_get_targets_ip(targets, 0); /* first free slot */
749 if (ind == -1) {
750 pr_err("%s: ARP target table is full!\n",
751 bond->dev->name);
752 return -EINVAL;
753 }
754
755 pr_info("%s: adding ARP target %pI4.\n", bond->dev->name, &target);
756
757 _bond_options_arp_ip_target_set(bond, ind, target, jiffies);
758
759 return 0;
760}
761
762int bond_option_arp_ip_target_add(struct bonding *bond, __be32 target)
763{
764 int ret;
765
766 /* not to race with bond_arp_rcv */
767 write_lock_bh(&bond->lock);
768 ret = _bond_option_arp_ip_target_add(bond, target);
769 write_unlock_bh(&bond->lock);
770
771 return ret;
772}
773
774int bond_option_arp_ip_target_rem(struct bonding *bond, __be32 target)
775{
776 __be32 *targets = bond->params.arp_targets;
777 struct list_head *iter;
778 struct slave *slave;
779 unsigned long *targets_rx;
780 int ind, i;
781
782 if (IS_IP_TARGET_UNUSABLE_ADDRESS(target)) {
783 pr_err("%s: invalid ARP target %pI4 specified for removal\n",
784 bond->dev->name, &target);
785 return -EINVAL;
786 }
787
788 ind = bond_get_targets_ip(targets, target);
789 if (ind == -1) {
790 pr_err("%s: unable to remove nonexistent ARP target %pI4.\n",
791 bond->dev->name, &target);
792 return -EINVAL;
793 }
794
795 if (ind == 0 && !targets[1] && bond->params.arp_interval)
796 pr_warn("%s: removing last arp target with arp_interval on\n",
797 bond->dev->name);
798
799 pr_info("%s: removing ARP target %pI4.\n", bond->dev->name,
800 &target);
801
802 /* not to race with bond_arp_rcv */
803 write_lock_bh(&bond->lock);
804
805 bond_for_each_slave(bond, slave, iter) {
806 targets_rx = slave->target_last_arp_rx;
807 for (i = ind; (i < BOND_MAX_ARP_TARGETS-1) && targets[i+1]; i++)
808 targets_rx[i] = targets_rx[i+1];
809 targets_rx[i] = 0;
810 }
811 for (i = ind; (i < BOND_MAX_ARP_TARGETS-1) && targets[i+1]; i++)
812 targets[i] = targets[i+1];
813 targets[i] = 0;
814
815 write_unlock_bh(&bond->lock);
816
817 return 0;
818}
819
Nikolay Aleksandrov4fb0ef52014-01-22 14:53:24 +0100820void bond_option_arp_ip_targets_clear(struct bonding *bond)
sfeldma@cumulusnetworks.com7f28fa12013-12-12 14:10:31 -0800821{
Nikolay Aleksandrov4fb0ef52014-01-22 14:53:24 +0100822 int i;
sfeldma@cumulusnetworks.com7f28fa12013-12-12 14:10:31 -0800823
824 /* not to race with bond_arp_rcv */
825 write_lock_bh(&bond->lock);
sfeldma@cumulusnetworks.com7f28fa12013-12-12 14:10:31 -0800826 for (i = 0; i < BOND_MAX_ARP_TARGETS; i++)
827 _bond_options_arp_ip_target_set(bond, i, 0, 0);
Nikolay Aleksandrov4fb0ef52014-01-22 14:53:24 +0100828 write_unlock_bh(&bond->lock);
829}
sfeldma@cumulusnetworks.com7f28fa12013-12-12 14:10:31 -0800830
Nikolay Aleksandrov4fb0ef52014-01-22 14:53:24 +0100831int bond_option_arp_ip_targets_set(struct bonding *bond,
832 struct bond_opt_value *newval)
833{
834 int ret = -EPERM;
835 __be32 target;
sfeldma@cumulusnetworks.com7f28fa12013-12-12 14:10:31 -0800836
Nikolay Aleksandrov4fb0ef52014-01-22 14:53:24 +0100837 if (newval->string) {
838 if (!in4_pton(newval->string+1, -1, (u8 *)&target, -1, NULL)) {
839 pr_err("%s: invalid ARP target %pI4 specified\n",
840 bond->dev->name, &target);
841 return ret;
842 }
843 if (newval->string[0] == '+')
844 ret = bond_option_arp_ip_target_add(bond, target);
845 else if (newval->string[0] == '-')
846 ret = bond_option_arp_ip_target_rem(bond, target);
847 else
848 pr_err("no command found in arp_ip_targets file for bond %s. Use +<addr> or -<addr>.\n",
849 bond->dev->name);
850 } else {
851 target = newval->value;
852 ret = bond_option_arp_ip_target_add(bond, target);
sfeldma@cumulusnetworks.com7f28fa12013-12-12 14:10:31 -0800853 }
854
sfeldma@cumulusnetworks.com7f28fa12013-12-12 14:10:31 -0800855 return ret;
856}
sfeldma@cumulusnetworks.com29c49482013-12-12 14:10:38 -0800857
Nikolay Aleksandrov16228882014-01-22 14:53:20 +0100858int bond_option_arp_validate_set(struct bonding *bond,
859 struct bond_opt_value *newval)
sfeldma@cumulusnetworks.com29c49482013-12-12 14:10:38 -0800860{
Nikolay Aleksandrov16228882014-01-22 14:53:20 +0100861 pr_info("%s: setting arp_validate to %s (%llu).\n",
862 bond->dev->name, newval->string, newval->value);
sfeldma@cumulusnetworks.com29c49482013-12-12 14:10:38 -0800863
864 if (bond->dev->flags & IFF_UP) {
Nikolay Aleksandrov16228882014-01-22 14:53:20 +0100865 if (!newval->value)
sfeldma@cumulusnetworks.com29c49482013-12-12 14:10:38 -0800866 bond->recv_probe = NULL;
867 else if (bond->params.arp_interval)
868 bond->recv_probe = bond_arp_rcv;
869 }
Nikolay Aleksandrov16228882014-01-22 14:53:20 +0100870 bond->params.arp_validate = newval->value;
sfeldma@cumulusnetworks.com29c49482013-12-12 14:10:38 -0800871
872 return 0;
873}
sfeldma@cumulusnetworks.comd5c84252013-12-12 14:10:45 -0800874
Nikolay Aleksandrovedf36b22014-01-22 14:53:21 +0100875int bond_option_arp_all_targets_set(struct bonding *bond,
876 struct bond_opt_value *newval)
sfeldma@cumulusnetworks.comd5c84252013-12-12 14:10:45 -0800877{
Nikolay Aleksandrovedf36b22014-01-22 14:53:21 +0100878 pr_info("%s: setting arp_all_targets to %s (%llu).\n",
879 bond->dev->name, newval->string, newval->value);
880 bond->params.arp_all_targets = newval->value;
sfeldma@cumulusnetworks.comd5c84252013-12-12 14:10:45 -0800881
882 return 0;
883}
sfeldma@cumulusnetworks.com0a98a0d2013-12-15 16:41:51 -0800884
885int bond_option_primary_set(struct bonding *bond, const char *primary)
886{
887 struct list_head *iter;
888 struct slave *slave;
889 int err = 0;
890
891 block_netpoll_tx();
892 read_lock(&bond->lock);
893 write_lock_bh(&bond->curr_slave_lock);
894
895 if (!USES_PRIMARY(bond->params.mode)) {
896 pr_err("%s: Unable to set primary slave; %s is in mode %d\n",
897 bond->dev->name, bond->dev->name, bond->params.mode);
898 err = -EINVAL;
899 goto out;
900 }
901
902 /* check to see if we are clearing primary */
903 if (!strlen(primary)) {
904 pr_info("%s: Setting primary slave to None.\n",
905 bond->dev->name);
906 bond->primary_slave = NULL;
907 memset(bond->params.primary, 0, sizeof(bond->params.primary));
908 bond_select_active_slave(bond);
909 goto out;
910 }
911
912 bond_for_each_slave(bond, slave, iter) {
913 if (strncmp(slave->dev->name, primary, IFNAMSIZ) == 0) {
914 pr_info("%s: Setting %s as primary slave.\n",
915 bond->dev->name, slave->dev->name);
916 bond->primary_slave = slave;
917 strcpy(bond->params.primary, slave->dev->name);
918 bond_select_active_slave(bond);
919 goto out;
920 }
921 }
922
923 strncpy(bond->params.primary, primary, IFNAMSIZ);
924 bond->params.primary[IFNAMSIZ - 1] = 0;
925
926 pr_info("%s: Recording %s as primary, but it has not been enslaved to %s yet.\n",
927 bond->dev->name, primary, bond->dev->name);
928
929out:
930 write_unlock_bh(&bond->curr_slave_lock);
931 read_unlock(&bond->lock);
932 unblock_netpoll_tx();
933
934 return err;
935}
sfeldma@cumulusnetworks.com8a41ae42013-12-15 16:41:58 -0800936
937int bond_option_primary_reselect_set(struct bonding *bond, int primary_reselect)
938{
sfeldma@cumulusnetworks.com3243c472014-01-03 14:28:18 -0800939 if (bond_parm_tbl_lookup(primary_reselect, pri_reselect_tbl) < 0) {
940 pr_err("%s: Ignoring invalid primary_reselect value %d.\n",
941 bond->dev->name, primary_reselect);
942 return -EINVAL;
943 }
944
sfeldma@cumulusnetworks.com8a41ae42013-12-15 16:41:58 -0800945 bond->params.primary_reselect = primary_reselect;
946 pr_info("%s: setting primary_reselect to %s (%d).\n",
947 bond->dev->name, pri_reselect_tbl[primary_reselect].modename,
948 primary_reselect);
949
950 block_netpoll_tx();
951 write_lock_bh(&bond->curr_slave_lock);
952 bond_select_active_slave(bond);
953 write_unlock_bh(&bond->curr_slave_lock);
954 unblock_netpoll_tx();
955
956 return 0;
957}
sfeldma@cumulusnetworks.com89901972013-12-15 16:42:05 -0800958
Nikolay Aleksandrov1df6b6a2014-01-22 14:53:22 +0100959int bond_option_fail_over_mac_set(struct bonding *bond,
960 struct bond_opt_value *newval)
sfeldma@cumulusnetworks.com89901972013-12-15 16:42:05 -0800961{
Nikolay Aleksandrov1df6b6a2014-01-22 14:53:22 +0100962 pr_info("%s: Setting fail_over_mac to %s (%llu).\n",
963 bond->dev->name, newval->string, newval->value);
964 bond->params.fail_over_mac = newval->value;
sfeldma@cumulusnetworks.com89901972013-12-15 16:42:05 -0800965
966 return 0;
967}
sfeldma@cumulusnetworks.comf70161c2013-12-15 16:42:12 -0800968
Nikolay Aleksandrova4b32ce2014-01-22 14:53:19 +0100969int bond_option_xmit_hash_policy_set(struct bonding *bond,
970 struct bond_opt_value *newval)
sfeldma@cumulusnetworks.comf70161c2013-12-15 16:42:12 -0800971{
Nikolay Aleksandrova4b32ce2014-01-22 14:53:19 +0100972 pr_info("%s: setting xmit hash policy to %s (%llu).\n",
973 bond->dev->name, newval->string, newval->value);
974 bond->params.xmit_policy = newval->value;
sfeldma@cumulusnetworks.comf70161c2013-12-15 16:42:12 -0800975
976 return 0;
977}
sfeldma@cumulusnetworks.comd8838de72013-12-15 16:42:19 -0800978
979int bond_option_resend_igmp_set(struct bonding *bond, int resend_igmp)
980{
981 if (resend_igmp < 0 || resend_igmp > 255) {
982 pr_err("%s: Invalid resend_igmp value %d not in range 0-255; rejected.\n",
983 bond->dev->name, resend_igmp);
984 return -EINVAL;
985 }
986
987 bond->params.resend_igmp = resend_igmp;
988 pr_info("%s: Setting resend_igmp to %d.\n",
989 bond->dev->name, resend_igmp);
990
991 return 0;
992}
sfeldma@cumulusnetworks.com2c9839c2013-12-17 21:30:09 -0800993
Nikolay Aleksandrovef56bec2014-01-22 14:53:30 +0100994int bond_option_num_peer_notif_set(struct bonding *bond,
995 struct bond_opt_value *newval)
sfeldma@cumulusnetworks.com2c9839c2013-12-17 21:30:09 -0800996{
Nikolay Aleksandrovef56bec2014-01-22 14:53:30 +0100997 bond->params.num_peer_notif = newval->value;
998
sfeldma@cumulusnetworks.com2c9839c2013-12-17 21:30:09 -0800999 return 0;
1000}
sfeldma@cumulusnetworks.com1cc0b1e2013-12-17 21:30:16 -08001001
1002int bond_option_all_slaves_active_set(struct bonding *bond,
1003 int all_slaves_active)
1004{
1005 struct list_head *iter;
1006 struct slave *slave;
1007
1008 if (all_slaves_active == bond->params.all_slaves_active)
1009 return 0;
1010
1011 if ((all_slaves_active == 0) || (all_slaves_active == 1)) {
1012 bond->params.all_slaves_active = all_slaves_active;
1013 } else {
1014 pr_info("%s: Ignoring invalid all_slaves_active value %d.\n",
1015 bond->dev->name, all_slaves_active);
1016 return -EINVAL;
1017 }
1018
1019 bond_for_each_slave(bond, slave, iter) {
1020 if (!bond_is_active_slave(slave)) {
1021 if (all_slaves_active)
1022 slave->inactive = 0;
1023 else
1024 slave->inactive = 1;
1025 }
1026 }
1027
1028 return 0;
1029}
sfeldma@cumulusnetworks.com7d101002013-12-17 21:30:23 -08001030
Nikolay Aleksandrov633ddc92014-01-22 14:53:28 +01001031int bond_option_min_links_set(struct bonding *bond,
1032 struct bond_opt_value *newval)
sfeldma@cumulusnetworks.com7d101002013-12-17 21:30:23 -08001033{
Nikolay Aleksandrov633ddc92014-01-22 14:53:28 +01001034 pr_info("%s: Setting min links value to %llu\n",
1035 bond->dev->name, newval->value);
1036 bond->params.min_links = newval->value;
sfeldma@cumulusnetworks.com7d101002013-12-17 21:30:23 -08001037
1038 return 0;
1039}
sfeldma@cumulusnetworks.com8d836d02013-12-17 21:30:30 -08001040
1041int bond_option_lp_interval_set(struct bonding *bond, int lp_interval)
1042{
1043 if (lp_interval <= 0) {
1044 pr_err("%s: lp_interval must be between 1 and %d\n",
1045 bond->dev->name, INT_MAX);
1046 return -EINVAL;
1047 }
1048
1049 bond->params.lp_interval = lp_interval;
1050
1051 return 0;
1052}
sfeldma@cumulusnetworks.comc13ab3f2013-12-17 21:30:37 -08001053
Nikolay Aleksandrovaa59d852014-01-22 14:53:18 +01001054int bond_option_pps_set(struct bonding *bond, struct bond_opt_value *newval)
sfeldma@cumulusnetworks.comc13ab3f2013-12-17 21:30:37 -08001055{
Nikolay Aleksandrovaa59d852014-01-22 14:53:18 +01001056 bond->params.packets_per_slave = newval->value;
1057 if (newval->value > 0) {
Hannes Frederic Sowa809fa972014-01-22 02:29:41 +01001058 bond->params.reciprocal_packets_per_slave =
Nikolay Aleksandrovaa59d852014-01-22 14:53:18 +01001059 reciprocal_value(newval->value);
Hannes Frederic Sowa809fa972014-01-22 02:29:41 +01001060 } else {
1061 /* reciprocal_packets_per_slave is unused if
1062 * packets_per_slave is 0 or 1, just initialize it
1063 */
1064 bond->params.reciprocal_packets_per_slave =
1065 (struct reciprocal_value) { 0 };
1066 }
sfeldma@cumulusnetworks.comc13ab3f2013-12-17 21:30:37 -08001067
1068 return 0;
1069}
sfeldma@cumulusnetworks.com998e40bb2014-01-03 14:18:41 -08001070
Nikolay Aleksandrovd3131de2014-01-22 14:53:27 +01001071int bond_option_lacp_rate_set(struct bonding *bond,
1072 struct bond_opt_value *newval)
sfeldma@cumulusnetworks.com998e40bb2014-01-03 14:18:41 -08001073{
Nikolay Aleksandrovd3131de2014-01-22 14:53:27 +01001074 pr_info("%s: Setting LACP rate to %s (%llu).\n",
1075 bond->dev->name, newval->string, newval->value);
1076 bond->params.lacp_fast = newval->value;
sfeldma@cumulusnetworks.com3243c472014-01-03 14:28:18 -08001077 bond_3ad_update_lacp_rate(bond);
sfeldma@cumulusnetworks.com998e40bb2014-01-03 14:18:41 -08001078
1079 return 0;
1080}
sfeldma@cumulusnetworks.comec029fa2014-01-03 14:18:49 -08001081
Nikolay Aleksandrov9e5f5ee2014-01-22 14:53:29 +01001082int bond_option_ad_select_set(struct bonding *bond,
1083 struct bond_opt_value *newval)
sfeldma@cumulusnetworks.comec029fa2014-01-03 14:18:49 -08001084{
Nikolay Aleksandrov9e5f5ee2014-01-22 14:53:29 +01001085 pr_info("%s: Setting ad_select to %s (%llu).\n",
1086 bond->dev->name, newval->string, newval->value);
1087 bond->params.ad_select = newval->value;
sfeldma@cumulusnetworks.comec029fa2014-01-03 14:18:49 -08001088
1089 return 0;
1090}