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>
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.
12 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
14 #include <linux/errno.h>
16 #include <linux/netdevice.h>
17 #include <linux/rwlock.h>
18 #include <linux/rcupdate.h>
19 #include <linux/ctype.h>
22 static struct bond_opt_value bond_mode_tbl[] = {
23 { "balance-rr", BOND_MODE_ROUNDROBIN, BOND_VALFLAG_DEFAULT},
24 { "active-backup", BOND_MODE_ACTIVEBACKUP, 0},
25 { "balance-xor", BOND_MODE_XOR, 0},
26 { "broadcast", BOND_MODE_BROADCAST, 0},
27 { "802.3ad", BOND_MODE_8023AD, 0},
28 { "balance-tlb", BOND_MODE_TLB, 0},
29 { "balance-alb", BOND_MODE_ALB, 0},
33 static struct bond_opt_value bond_pps_tbl[] = {
34 { "default", 1, BOND_VALFLAG_DEFAULT},
35 { "maxval", USHRT_MAX, BOND_VALFLAG_MAX},
39 static struct bond_opt_value bond_xmit_hashtype_tbl[] = {
40 { "layer2", BOND_XMIT_POLICY_LAYER2, BOND_VALFLAG_DEFAULT},
41 { "layer3+4", BOND_XMIT_POLICY_LAYER34, 0},
42 { "layer2+3", BOND_XMIT_POLICY_LAYER23, 0},
43 { "encap2+3", BOND_XMIT_POLICY_ENCAP23, 0},
44 { "encap3+4", BOND_XMIT_POLICY_ENCAP34, 0},
48 static struct bond_opt_value bond_arp_validate_tbl[] = {
49 { "none", BOND_ARP_VALIDATE_NONE, BOND_VALFLAG_DEFAULT},
50 { "active", BOND_ARP_VALIDATE_ACTIVE, 0},
51 { "backup", BOND_ARP_VALIDATE_BACKUP, 0},
52 { "all", BOND_ARP_VALIDATE_ALL, 0},
56 static struct bond_opt_value bond_arp_all_targets_tbl[] = {
57 { "any", BOND_ARP_TARGETS_ANY, BOND_VALFLAG_DEFAULT},
58 { "all", BOND_ARP_TARGETS_ALL, 0},
62 static struct bond_option bond_opts[] = {
66 .desc = "bond device mode",
67 .flags = BOND_OPTFLAG_NOSLAVES | BOND_OPTFLAG_IFDOWN,
68 .values = bond_mode_tbl,
69 .set = bond_option_mode_set
71 [BOND_OPT_PACKETS_PER_SLAVE] = {
72 .id = BOND_OPT_PACKETS_PER_SLAVE,
73 .name = "packets_per_slave",
74 .desc = "Packets to send per slave in RR mode",
75 .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_ROUNDROBIN)),
76 .values = bond_pps_tbl,
77 .set = bond_option_pps_set
79 [BOND_OPT_XMIT_HASH] = {
80 .id = BOND_OPT_XMIT_HASH,
81 .name = "xmit_hash_policy",
82 .desc = "balance-xor and 802.3ad hashing method",
83 .values = bond_xmit_hashtype_tbl,
84 .set = bond_option_xmit_hash_policy_set
86 [BOND_OPT_ARP_VALIDATE] = {
87 .id = BOND_OPT_ARP_VALIDATE,
88 .name = "arp_validate",
89 .desc = "validate src/dst of ARP probes",
90 .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_ACTIVEBACKUP)),
91 .values = bond_arp_validate_tbl,
92 .set = bond_option_arp_validate_set
94 [BOND_OPT_ARP_ALL_TARGETS] = {
95 .id = BOND_OPT_ARP_ALL_TARGETS,
96 .name = "arp_all_targets",
97 .desc = "fail on any/all arp targets timeout",
98 .values = bond_arp_all_targets_tbl,
99 .set = bond_option_arp_all_targets_set
104 /* Searches for a value in opt's values[] table */
105 struct bond_opt_value *bond_opt_get_val(unsigned int option, u64 val)
107 struct bond_option *opt;
110 opt = bond_opt_get(option);
113 for (i = 0; opt->values && opt->values[i].string; i++)
114 if (opt->values[i].value == val)
115 return &opt->values[i];
120 /* Searches for a value in opt's values[] table which matches the flagmask */
121 static struct bond_opt_value *bond_opt_get_flags(const struct bond_option *opt,
126 for (i = 0; opt->values && opt->values[i].string; i++)
127 if (opt->values[i].flags & flagmask)
128 return &opt->values[i];
133 /* If maxval is missing then there's no range to check. In case minval is
134 * missing then it's considered to be 0.
136 static bool bond_opt_check_range(const struct bond_option *opt, u64 val)
138 struct bond_opt_value *minval, *maxval;
140 minval = bond_opt_get_flags(opt, BOND_VALFLAG_MIN);
141 maxval = bond_opt_get_flags(opt, BOND_VALFLAG_MAX);
142 if (!maxval || (minval && val < minval->value) || val > maxval->value)
149 * bond_opt_parse - parse option value
150 * @opt: the option to parse against
151 * @val: value to parse
153 * This function tries to extract the value from @val and check if it's
154 * a possible match for the option and returns NULL if a match isn't found,
155 * or the struct_opt_value that matched. It also strips the new line from
156 * @val->string if it's present.
158 struct bond_opt_value *bond_opt_parse(const struct bond_option *opt,
159 struct bond_opt_value *val)
161 char *p, valstr[BOND_OPT_MAX_NAMELEN + 1] = { 0, };
162 struct bond_opt_value *tbl, *ret = NULL;
166 /* No parsing if the option wants a raw val */
167 if (opt->flags & BOND_OPTFLAG_RAWVAL)
174 /* ULLONG_MAX is used to bypass string processing */
175 checkval = val->value != ULLONG_MAX;
179 p = strchr(val->string, '\n');
182 for (p = val->string; *p; p++)
183 if (!(isdigit(*p) || isspace(*p)))
185 /* The following code extracts the string to match or the value
186 * and sets checkval appropriately
189 rv = sscanf(val->string, "%32s", valstr);
191 rv = sscanf(val->string, "%llu", &val->value);
198 for (i = 0; tbl[i].string; i++) {
199 /* Check for exact match */
201 if (val->value == tbl[i].value)
204 if (!strcmp(valstr, "default") &&
205 (tbl[i].flags & BOND_VALFLAG_DEFAULT))
208 if (!strcmp(valstr, tbl[i].string))
211 /* Found an exact match */
215 /* Possible range match */
216 if (checkval && bond_opt_check_range(opt, val->value))
222 /* Check opt's dependencies against bond mode and currently set options */
223 static int bond_opt_check_deps(struct bonding *bond,
224 const struct bond_option *opt)
226 struct bond_params *params = &bond->params;
228 if (test_bit(params->mode, &opt->unsuppmodes))
230 if ((opt->flags & BOND_OPTFLAG_NOSLAVES) && bond_has_slaves(bond))
232 if ((opt->flags & BOND_OPTFLAG_IFDOWN) && (bond->dev->flags & IFF_UP))
238 static void bond_opt_dep_print(struct bonding *bond,
239 const struct bond_option *opt)
241 struct bond_opt_value *modeval;
242 struct bond_params *params;
244 params = &bond->params;
245 modeval = bond_opt_get_val(BOND_OPT_MODE, params->mode);
246 if (test_bit(params->mode, &opt->unsuppmodes))
247 pr_err("%s: option %s: mode dependency failed, not supported in mode %s(%llu)\n",
248 bond->dev->name, opt->name,
249 modeval->string, modeval->value);
252 static void bond_opt_error_interpret(struct bonding *bond,
253 const struct bond_option *opt,
254 int error, struct bond_opt_value *val)
256 struct bond_opt_value *minval, *maxval;
263 /* sometimes RAWVAL opts may have new lines */
264 p = strchr(val->string, '\n');
267 pr_err("%s: option %s: invalid value (%s).\n",
268 bond->dev->name, opt->name, val->string);
270 pr_err("%s: option %s: invalid value (%llu).\n",
271 bond->dev->name, opt->name, val->value);
274 minval = bond_opt_get_flags(opt, BOND_VALFLAG_MIN);
275 maxval = bond_opt_get_flags(opt, BOND_VALFLAG_MAX);
278 pr_err("%s: option %s: allowed values %llu - %llu.\n",
279 bond->dev->name, opt->name, minval ? minval->value : 0,
283 bond_opt_dep_print(bond, opt);
286 pr_err("%s: option %s: unable to set because the bond device has slaves.\n",
287 bond->dev->name, opt->name);
290 pr_err("%s: option %s: unable to set because the bond device is up.\n",
291 bond->dev->name, opt->name);
299 * __bond_opt_set - set a bonding option
300 * @bond: target bond device
301 * @option: option to set
302 * @val: value to set it to
304 * This function is used to change the bond's option value, it can be
305 * used for both enabling/changing an option and for disabling it. RTNL lock
306 * must be obtained before calling this function.
308 int __bond_opt_set(struct bonding *bond,
309 unsigned int option, struct bond_opt_value *val)
311 struct bond_opt_value *retval = NULL;
312 const struct bond_option *opt;
317 opt = bond_opt_get(option);
318 if (WARN_ON(!val) || WARN_ON(!opt))
320 ret = bond_opt_check_deps(bond, opt);
323 retval = bond_opt_parse(opt, val);
328 ret = opt->set(bond, retval);
331 bond_opt_error_interpret(bond, opt, ret, val);
337 * bond_opt_tryset_rtnl - try to acquire rtnl and call __bond_opt_set
338 * @bond: target bond device
339 * @option: option to set
340 * @buf: value to set it to
342 * This function tries to acquire RTNL without blocking and if successful
343 * calls __bond_opt_set. It is mainly used for sysfs option manipulation.
345 int bond_opt_tryset_rtnl(struct bonding *bond, unsigned int option, char *buf)
347 struct bond_opt_value optval;
351 return restart_syscall();
352 bond_opt_initstr(&optval, buf);
353 ret = __bond_opt_set(bond, option, &optval);
360 * bond_opt_get - get a pointer to an option
361 * @option: option for which to return a pointer
363 * This function checks if option is valid and if so returns a pointer
364 * to its entry in the bond_opts[] option array.
366 struct bond_option *bond_opt_get(unsigned int option)
368 if (!BOND_OPT_VALID(option))
371 return &bond_opts[option];
374 int bond_option_mode_set(struct bonding *bond, struct bond_opt_value *newval)
376 if (BOND_NO_USES_ARP(newval->value) && bond->params.arp_interval) {
377 pr_info("%s: %s mode is incompatible with arp monitoring, start mii monitoring\n",
378 bond->dev->name, newval->string);
379 /* disable arp monitoring */
380 bond->params.arp_interval = 0;
381 /* set miimon to default value */
382 bond->params.miimon = BOND_DEFAULT_MIIMON;
383 pr_info("%s: Setting MII monitoring interval to %d.\n",
384 bond->dev->name, bond->params.miimon);
387 /* don't cache arp_validate between modes */
388 bond->params.arp_validate = BOND_ARP_VALIDATE_NONE;
389 bond->params.mode = newval->value;
394 static struct net_device *__bond_option_active_slave_get(struct bonding *bond,
397 return USES_PRIMARY(bond->params.mode) && slave ? slave->dev : NULL;
400 struct net_device *bond_option_active_slave_get_rcu(struct bonding *bond)
402 struct slave *slave = rcu_dereference(bond->curr_active_slave);
404 return __bond_option_active_slave_get(bond, slave);
407 struct net_device *bond_option_active_slave_get(struct bonding *bond)
409 return __bond_option_active_slave_get(bond, bond->curr_active_slave);
412 int bond_option_active_slave_set(struct bonding *bond,
413 struct net_device *slave_dev)
418 if (!netif_is_bond_slave(slave_dev)) {
419 pr_err("Device %s is not bonding slave.\n",
424 if (bond->dev != netdev_master_upper_dev_get(slave_dev)) {
425 pr_err("%s: Device %s is not our slave.\n",
426 bond->dev->name, slave_dev->name);
431 if (!USES_PRIMARY(bond->params.mode)) {
432 pr_err("%s: Unable to change active slave; %s is in mode %d\n",
433 bond->dev->name, bond->dev->name, bond->params.mode);
438 write_lock_bh(&bond->curr_slave_lock);
440 /* check to see if we are clearing active */
442 pr_info("%s: Clearing current active slave.\n",
444 rcu_assign_pointer(bond->curr_active_slave, NULL);
445 bond_select_active_slave(bond);
447 struct slave *old_active = bond->curr_active_slave;
448 struct slave *new_active = bond_slave_get_rtnl(slave_dev);
452 if (new_active == old_active) {
454 pr_info("%s: %s is already the current active slave.\n",
455 bond->dev->name, new_active->dev->name);
457 if (old_active && (new_active->link == BOND_LINK_UP) &&
458 IS_UP(new_active->dev)) {
459 pr_info("%s: Setting %s as active slave.\n",
460 bond->dev->name, new_active->dev->name);
461 bond_change_active_slave(bond, new_active);
463 pr_err("%s: Could not set %s as active slave; either %s is down or the link is down.\n",
464 bond->dev->name, new_active->dev->name,
465 new_active->dev->name);
471 write_unlock_bh(&bond->curr_slave_lock);
472 unblock_netpoll_tx();
476 int bond_option_miimon_set(struct bonding *bond, int miimon)
479 pr_err("%s: Invalid miimon value %d not in range %d-%d; rejected.\n",
480 bond->dev->name, miimon, 0, INT_MAX);
483 pr_info("%s: Setting MII monitoring interval to %d.\n",
484 bond->dev->name, miimon);
485 bond->params.miimon = miimon;
486 if (bond->params.updelay)
487 pr_info("%s: Note: Updating updelay (to %d) since it is a multiple of the miimon value.\n",
489 bond->params.updelay * bond->params.miimon);
490 if (bond->params.downdelay)
491 pr_info("%s: Note: Updating downdelay (to %d) since it is a multiple of the miimon value.\n",
493 bond->params.downdelay * bond->params.miimon);
494 if (miimon && bond->params.arp_interval) {
495 pr_info("%s: MII monitoring cannot be used with ARP monitoring. Disabling ARP monitoring...\n",
497 bond->params.arp_interval = 0;
498 if (bond->params.arp_validate)
499 bond->params.arp_validate = BOND_ARP_VALIDATE_NONE;
501 if (bond->dev->flags & IFF_UP) {
502 /* If the interface is up, we may need to fire off
503 * the MII timer. If the interface is down, the
504 * timer will get fired off when the open function
508 cancel_delayed_work_sync(&bond->mii_work);
510 cancel_delayed_work_sync(&bond->arp_work);
511 queue_delayed_work(bond->wq, &bond->mii_work, 0);
517 int bond_option_updelay_set(struct bonding *bond, int updelay)
519 if (!(bond->params.miimon)) {
520 pr_err("%s: Unable to set up delay as MII monitoring is disabled\n",
526 pr_err("%s: Invalid up delay value %d not in range %d-%d; rejected.\n",
527 bond->dev->name, updelay, 0, INT_MAX);
530 if ((updelay % bond->params.miimon) != 0) {
531 pr_warn("%s: Warning: up delay (%d) is not a multiple of miimon (%d), updelay rounded to %d ms\n",
532 bond->dev->name, updelay,
534 (updelay / bond->params.miimon) *
535 bond->params.miimon);
537 bond->params.updelay = updelay / bond->params.miimon;
538 pr_info("%s: Setting up delay to %d.\n",
540 bond->params.updelay * bond->params.miimon);
546 int bond_option_downdelay_set(struct bonding *bond, int downdelay)
548 if (!(bond->params.miimon)) {
549 pr_err("%s: Unable to set down delay as MII monitoring is disabled\n",
555 pr_err("%s: Invalid down delay value %d not in range %d-%d; rejected.\n",
556 bond->dev->name, downdelay, 0, INT_MAX);
559 if ((downdelay % bond->params.miimon) != 0) {
560 pr_warn("%s: Warning: down delay (%d) is not a multiple of miimon (%d), delay rounded to %d ms\n",
561 bond->dev->name, downdelay,
563 (downdelay / bond->params.miimon) *
564 bond->params.miimon);
566 bond->params.downdelay = downdelay / bond->params.miimon;
567 pr_info("%s: Setting down delay to %d.\n",
569 bond->params.downdelay * bond->params.miimon);
575 int bond_option_use_carrier_set(struct bonding *bond, int use_carrier)
577 if ((use_carrier == 0) || (use_carrier == 1)) {
578 bond->params.use_carrier = use_carrier;
579 pr_info("%s: Setting use_carrier to %d.\n",
580 bond->dev->name, use_carrier);
582 pr_info("%s: Ignoring invalid use_carrier value %d.\n",
583 bond->dev->name, use_carrier);
589 int bond_option_arp_interval_set(struct bonding *bond, int arp_interval)
591 if (arp_interval < 0) {
592 pr_err("%s: Invalid arp_interval value %d not in range 0-%d; rejected.\n",
593 bond->dev->name, arp_interval, INT_MAX);
596 if (BOND_NO_USES_ARP(bond->params.mode)) {
597 pr_info("%s: ARP monitoring cannot be used with ALB/TLB/802.3ad. Only MII monitoring is supported on %s.\n",
598 bond->dev->name, bond->dev->name);
601 pr_info("%s: Setting ARP monitoring interval to %d.\n",
602 bond->dev->name, arp_interval);
603 bond->params.arp_interval = arp_interval;
605 if (bond->params.miimon) {
606 pr_info("%s: ARP monitoring cannot be used with MII monitoring. %s Disabling MII monitoring.\n",
607 bond->dev->name, bond->dev->name);
608 bond->params.miimon = 0;
610 if (!bond->params.arp_targets[0])
611 pr_info("%s: ARP monitoring has been set up, but no ARP targets have been specified.\n",
614 if (bond->dev->flags & IFF_UP) {
615 /* If the interface is up, we may need to fire off
616 * the ARP timer. If the interface is down, the
617 * timer will get fired off when the open function
621 if (bond->params.arp_validate)
622 bond->recv_probe = NULL;
623 cancel_delayed_work_sync(&bond->arp_work);
625 /* arp_validate can be set only in active-backup mode */
626 if (bond->params.arp_validate)
627 bond->recv_probe = bond_arp_rcv;
628 cancel_delayed_work_sync(&bond->mii_work);
629 queue_delayed_work(bond->wq, &bond->arp_work, 0);
636 static void _bond_options_arp_ip_target_set(struct bonding *bond, int slot,
638 unsigned long last_rx)
640 __be32 *targets = bond->params.arp_targets;
641 struct list_head *iter;
644 if (slot >= 0 && slot < BOND_MAX_ARP_TARGETS) {
645 bond_for_each_slave(bond, slave, iter)
646 slave->target_last_arp_rx[slot] = last_rx;
647 targets[slot] = target;
651 static int _bond_option_arp_ip_target_add(struct bonding *bond, __be32 target)
653 __be32 *targets = bond->params.arp_targets;
656 if (IS_IP_TARGET_UNUSABLE_ADDRESS(target)) {
657 pr_err("%s: invalid ARP target %pI4 specified for addition\n",
658 bond->dev->name, &target);
662 if (bond_get_targets_ip(targets, target) != -1) { /* dup */
663 pr_err("%s: ARP target %pI4 is already present\n",
664 bond->dev->name, &target);
668 ind = bond_get_targets_ip(targets, 0); /* first free slot */
670 pr_err("%s: ARP target table is full!\n",
675 pr_info("%s: adding ARP target %pI4.\n", bond->dev->name, &target);
677 _bond_options_arp_ip_target_set(bond, ind, target, jiffies);
682 int bond_option_arp_ip_target_add(struct bonding *bond, __be32 target)
686 /* not to race with bond_arp_rcv */
687 write_lock_bh(&bond->lock);
688 ret = _bond_option_arp_ip_target_add(bond, target);
689 write_unlock_bh(&bond->lock);
694 int bond_option_arp_ip_target_rem(struct bonding *bond, __be32 target)
696 __be32 *targets = bond->params.arp_targets;
697 struct list_head *iter;
699 unsigned long *targets_rx;
702 if (IS_IP_TARGET_UNUSABLE_ADDRESS(target)) {
703 pr_err("%s: invalid ARP target %pI4 specified for removal\n",
704 bond->dev->name, &target);
708 ind = bond_get_targets_ip(targets, target);
710 pr_err("%s: unable to remove nonexistent ARP target %pI4.\n",
711 bond->dev->name, &target);
715 if (ind == 0 && !targets[1] && bond->params.arp_interval)
716 pr_warn("%s: removing last arp target with arp_interval on\n",
719 pr_info("%s: removing ARP target %pI4.\n", bond->dev->name,
722 /* not to race with bond_arp_rcv */
723 write_lock_bh(&bond->lock);
725 bond_for_each_slave(bond, slave, iter) {
726 targets_rx = slave->target_last_arp_rx;
727 for (i = ind; (i < BOND_MAX_ARP_TARGETS-1) && targets[i+1]; i++)
728 targets_rx[i] = targets_rx[i+1];
731 for (i = ind; (i < BOND_MAX_ARP_TARGETS-1) && targets[i+1]; i++)
732 targets[i] = targets[i+1];
735 write_unlock_bh(&bond->lock);
740 int bond_option_arp_ip_targets_set(struct bonding *bond, __be32 *targets,
745 /* not to race with bond_arp_rcv */
746 write_lock_bh(&bond->lock);
749 for (i = 0; i < BOND_MAX_ARP_TARGETS; i++)
750 _bond_options_arp_ip_target_set(bond, i, 0, 0);
752 if (count == 0 && bond->params.arp_interval)
753 pr_warn("%s: removing last arp target with arp_interval on\n",
756 for (i = 0; i < count; i++) {
757 ret = _bond_option_arp_ip_target_add(bond, targets[i]);
762 write_unlock_bh(&bond->lock);
766 int bond_option_arp_validate_set(struct bonding *bond,
767 struct bond_opt_value *newval)
769 pr_info("%s: setting arp_validate to %s (%llu).\n",
770 bond->dev->name, newval->string, newval->value);
772 if (bond->dev->flags & IFF_UP) {
774 bond->recv_probe = NULL;
775 else if (bond->params.arp_interval)
776 bond->recv_probe = bond_arp_rcv;
778 bond->params.arp_validate = newval->value;
783 int bond_option_arp_all_targets_set(struct bonding *bond,
784 struct bond_opt_value *newval)
786 pr_info("%s: setting arp_all_targets to %s (%llu).\n",
787 bond->dev->name, newval->string, newval->value);
788 bond->params.arp_all_targets = newval->value;
793 int bond_option_primary_set(struct bonding *bond, const char *primary)
795 struct list_head *iter;
800 read_lock(&bond->lock);
801 write_lock_bh(&bond->curr_slave_lock);
803 if (!USES_PRIMARY(bond->params.mode)) {
804 pr_err("%s: Unable to set primary slave; %s is in mode %d\n",
805 bond->dev->name, bond->dev->name, bond->params.mode);
810 /* check to see if we are clearing primary */
811 if (!strlen(primary)) {
812 pr_info("%s: Setting primary slave to None.\n",
814 bond->primary_slave = NULL;
815 memset(bond->params.primary, 0, sizeof(bond->params.primary));
816 bond_select_active_slave(bond);
820 bond_for_each_slave(bond, slave, iter) {
821 if (strncmp(slave->dev->name, primary, IFNAMSIZ) == 0) {
822 pr_info("%s: Setting %s as primary slave.\n",
823 bond->dev->name, slave->dev->name);
824 bond->primary_slave = slave;
825 strcpy(bond->params.primary, slave->dev->name);
826 bond_select_active_slave(bond);
831 strncpy(bond->params.primary, primary, IFNAMSIZ);
832 bond->params.primary[IFNAMSIZ - 1] = 0;
834 pr_info("%s: Recording %s as primary, but it has not been enslaved to %s yet.\n",
835 bond->dev->name, primary, bond->dev->name);
838 write_unlock_bh(&bond->curr_slave_lock);
839 read_unlock(&bond->lock);
840 unblock_netpoll_tx();
845 int bond_option_primary_reselect_set(struct bonding *bond, int primary_reselect)
847 if (bond_parm_tbl_lookup(primary_reselect, pri_reselect_tbl) < 0) {
848 pr_err("%s: Ignoring invalid primary_reselect value %d.\n",
849 bond->dev->name, primary_reselect);
853 bond->params.primary_reselect = primary_reselect;
854 pr_info("%s: setting primary_reselect to %s (%d).\n",
855 bond->dev->name, pri_reselect_tbl[primary_reselect].modename,
859 write_lock_bh(&bond->curr_slave_lock);
860 bond_select_active_slave(bond);
861 write_unlock_bh(&bond->curr_slave_lock);
862 unblock_netpoll_tx();
867 int bond_option_fail_over_mac_set(struct bonding *bond, int fail_over_mac)
869 if (bond_parm_tbl_lookup(fail_over_mac, fail_over_mac_tbl) < 0) {
870 pr_err("%s: Ignoring invalid fail_over_mac value %d.\n",
871 bond->dev->name, fail_over_mac);
875 if (bond_has_slaves(bond)) {
876 pr_err("%s: Can't alter fail_over_mac with slaves in bond.\n",
881 bond->params.fail_over_mac = fail_over_mac;
882 pr_info("%s: Setting fail_over_mac to %s (%d).\n",
883 bond->dev->name, fail_over_mac_tbl[fail_over_mac].modename,
889 int bond_option_xmit_hash_policy_set(struct bonding *bond,
890 struct bond_opt_value *newval)
892 pr_info("%s: setting xmit hash policy to %s (%llu).\n",
893 bond->dev->name, newval->string, newval->value);
894 bond->params.xmit_policy = newval->value;
899 int bond_option_resend_igmp_set(struct bonding *bond, int resend_igmp)
901 if (resend_igmp < 0 || resend_igmp > 255) {
902 pr_err("%s: Invalid resend_igmp value %d not in range 0-255; rejected.\n",
903 bond->dev->name, resend_igmp);
907 bond->params.resend_igmp = resend_igmp;
908 pr_info("%s: Setting resend_igmp to %d.\n",
909 bond->dev->name, resend_igmp);
914 int bond_option_num_peer_notif_set(struct bonding *bond, int num_peer_notif)
916 bond->params.num_peer_notif = num_peer_notif;
920 int bond_option_all_slaves_active_set(struct bonding *bond,
921 int all_slaves_active)
923 struct list_head *iter;
926 if (all_slaves_active == bond->params.all_slaves_active)
929 if ((all_slaves_active == 0) || (all_slaves_active == 1)) {
930 bond->params.all_slaves_active = all_slaves_active;
932 pr_info("%s: Ignoring invalid all_slaves_active value %d.\n",
933 bond->dev->name, all_slaves_active);
937 bond_for_each_slave(bond, slave, iter) {
938 if (!bond_is_active_slave(slave)) {
939 if (all_slaves_active)
949 int bond_option_min_links_set(struct bonding *bond, int min_links)
951 pr_info("%s: Setting min links value to %u\n",
952 bond->dev->name, min_links);
953 bond->params.min_links = min_links;
958 int bond_option_lp_interval_set(struct bonding *bond, int lp_interval)
960 if (lp_interval <= 0) {
961 pr_err("%s: lp_interval must be between 1 and %d\n",
962 bond->dev->name, INT_MAX);
966 bond->params.lp_interval = lp_interval;
971 int bond_option_pps_set(struct bonding *bond, struct bond_opt_value *newval)
973 bond->params.packets_per_slave = newval->value;
974 if (newval->value > 0) {
975 bond->params.reciprocal_packets_per_slave =
976 reciprocal_value(newval->value);
978 /* reciprocal_packets_per_slave is unused if
979 * packets_per_slave is 0 or 1, just initialize it
981 bond->params.reciprocal_packets_per_slave =
982 (struct reciprocal_value) { 0 };
988 int bond_option_lacp_rate_set(struct bonding *bond, int lacp_rate)
990 if (bond_parm_tbl_lookup(lacp_rate, bond_lacp_tbl) < 0) {
991 pr_err("%s: Ignoring invalid LACP rate value %d.\n",
992 bond->dev->name, lacp_rate);
996 if (bond->dev->flags & IFF_UP) {
997 pr_err("%s: Unable to update LACP rate because interface is up.\n",
1002 if (bond->params.mode != BOND_MODE_8023AD) {
1003 pr_err("%s: Unable to update LACP rate because bond is not in 802.3ad mode.\n",
1008 bond->params.lacp_fast = lacp_rate;
1009 bond_3ad_update_lacp_rate(bond);
1010 pr_info("%s: Setting LACP rate to %s (%d).\n",
1011 bond->dev->name, bond_lacp_tbl[lacp_rate].modename,
1017 int bond_option_ad_select_set(struct bonding *bond, int ad_select)
1019 if (bond_parm_tbl_lookup(ad_select, ad_select_tbl) < 0) {
1020 pr_err("%s: Ignoring invalid ad_select value %d.\n",
1021 bond->dev->name, ad_select);
1025 if (bond->dev->flags & IFF_UP) {
1026 pr_err("%s: Unable to update ad_select because interface is up.\n",
1031 bond->params.ad_select = ad_select;
1032 pr_info("%s: Setting ad_select to %s (%d).\n",
1033 bond->dev->name, ad_select_tbl[ad_select].modename,