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_option bond_opts[] = {
37 .desc = "bond device mode",
38 .flags = BOND_OPTFLAG_NOSLAVES | BOND_OPTFLAG_IFDOWN,
39 .values = bond_mode_tbl,
40 .set = bond_option_mode_set
45 /* Searches for a value in opt's values[] table */
46 struct bond_opt_value *bond_opt_get_val(unsigned int option, u64 val)
48 struct bond_option *opt;
51 opt = bond_opt_get(option);
54 for (i = 0; opt->values && opt->values[i].string; i++)
55 if (opt->values[i].value == val)
56 return &opt->values[i];
61 /* Searches for a value in opt's values[] table which matches the flagmask */
62 static struct bond_opt_value *bond_opt_get_flags(const struct bond_option *opt,
67 for (i = 0; opt->values && opt->values[i].string; i++)
68 if (opt->values[i].flags & flagmask)
69 return &opt->values[i];
74 /* If maxval is missing then there's no range to check. In case minval is
75 * missing then it's considered to be 0.
77 static bool bond_opt_check_range(const struct bond_option *opt, u64 val)
79 struct bond_opt_value *minval, *maxval;
81 minval = bond_opt_get_flags(opt, BOND_VALFLAG_MIN);
82 maxval = bond_opt_get_flags(opt, BOND_VALFLAG_MAX);
83 if (!maxval || (minval && val < minval->value) || val > maxval->value)
90 * bond_opt_parse - parse option value
91 * @opt: the option to parse against
92 * @val: value to parse
94 * This function tries to extract the value from @val and check if it's
95 * a possible match for the option and returns NULL if a match isn't found,
96 * or the struct_opt_value that matched. It also strips the new line from
97 * @val->string if it's present.
99 struct bond_opt_value *bond_opt_parse(const struct bond_option *opt,
100 struct bond_opt_value *val)
102 char *p, valstr[BOND_OPT_MAX_NAMELEN + 1] = { 0, };
103 struct bond_opt_value *tbl, *ret = NULL;
107 /* No parsing if the option wants a raw val */
108 if (opt->flags & BOND_OPTFLAG_RAWVAL)
115 /* ULLONG_MAX is used to bypass string processing */
116 checkval = val->value != ULLONG_MAX;
120 p = strchr(val->string, '\n');
123 for (p = val->string; *p; p++)
124 if (!(isdigit(*p) || isspace(*p)))
126 /* The following code extracts the string to match or the value
127 * and sets checkval appropriately
130 rv = sscanf(val->string, "%32s", valstr);
132 rv = sscanf(val->string, "%llu", &val->value);
139 for (i = 0; tbl[i].string; i++) {
140 /* Check for exact match */
142 if (val->value == tbl[i].value)
145 if (!strcmp(valstr, "default") &&
146 (tbl[i].flags & BOND_VALFLAG_DEFAULT))
149 if (!strcmp(valstr, tbl[i].string))
152 /* Found an exact match */
156 /* Possible range match */
157 if (checkval && bond_opt_check_range(opt, val->value))
163 /* Check opt's dependencies against bond mode and currently set options */
164 static int bond_opt_check_deps(struct bonding *bond,
165 const struct bond_option *opt)
167 struct bond_params *params = &bond->params;
169 if (test_bit(params->mode, &opt->unsuppmodes))
171 if ((opt->flags & BOND_OPTFLAG_NOSLAVES) && bond_has_slaves(bond))
173 if ((opt->flags & BOND_OPTFLAG_IFDOWN) && (bond->dev->flags & IFF_UP))
179 static void bond_opt_dep_print(struct bonding *bond,
180 const struct bond_option *opt)
182 struct bond_opt_value *modeval;
183 struct bond_params *params;
185 params = &bond->params;
186 modeval = bond_opt_get_val(BOND_OPT_MODE, params->mode);
187 if (test_bit(params->mode, &opt->unsuppmodes))
188 pr_err("%s: option %s: mode dependency failed, not supported in mode %s(%llu)\n",
189 bond->dev->name, opt->name,
190 modeval->string, modeval->value);
193 static void bond_opt_error_interpret(struct bonding *bond,
194 const struct bond_option *opt,
195 int error, struct bond_opt_value *val)
197 struct bond_opt_value *minval, *maxval;
204 /* sometimes RAWVAL opts may have new lines */
205 p = strchr(val->string, '\n');
208 pr_err("%s: option %s: invalid value (%s).\n",
209 bond->dev->name, opt->name, val->string);
211 pr_err("%s: option %s: invalid value (%llu).\n",
212 bond->dev->name, opt->name, val->value);
215 minval = bond_opt_get_flags(opt, BOND_VALFLAG_MIN);
216 maxval = bond_opt_get_flags(opt, BOND_VALFLAG_MAX);
219 pr_err("%s: option %s: allowed values %llu - %llu.\n",
220 bond->dev->name, opt->name, minval ? minval->value : 0,
224 bond_opt_dep_print(bond, opt);
227 pr_err("%s: option %s: unable to set because the bond device has slaves.\n",
228 bond->dev->name, opt->name);
231 pr_err("%s: option %s: unable to set because the bond device is up.\n",
232 bond->dev->name, opt->name);
240 * __bond_opt_set - set a bonding option
241 * @bond: target bond device
242 * @option: option to set
243 * @val: value to set it to
245 * This function is used to change the bond's option value, it can be
246 * used for both enabling/changing an option and for disabling it. RTNL lock
247 * must be obtained before calling this function.
249 int __bond_opt_set(struct bonding *bond,
250 unsigned int option, struct bond_opt_value *val)
252 struct bond_opt_value *retval = NULL;
253 const struct bond_option *opt;
258 opt = bond_opt_get(option);
259 if (WARN_ON(!val) || WARN_ON(!opt))
261 ret = bond_opt_check_deps(bond, opt);
264 retval = bond_opt_parse(opt, val);
269 ret = opt->set(bond, retval);
272 bond_opt_error_interpret(bond, opt, ret, val);
278 * bond_opt_tryset_rtnl - try to acquire rtnl and call __bond_opt_set
279 * @bond: target bond device
280 * @option: option to set
281 * @buf: value to set it to
283 * This function tries to acquire RTNL without blocking and if successful
284 * calls __bond_opt_set. It is mainly used for sysfs option manipulation.
286 int bond_opt_tryset_rtnl(struct bonding *bond, unsigned int option, char *buf)
288 struct bond_opt_value optval;
292 return restart_syscall();
293 bond_opt_initstr(&optval, buf);
294 ret = __bond_opt_set(bond, option, &optval);
301 * bond_opt_get - get a pointer to an option
302 * @option: option for which to return a pointer
304 * This function checks if option is valid and if so returns a pointer
305 * to its entry in the bond_opts[] option array.
307 struct bond_option *bond_opt_get(unsigned int option)
309 if (!BOND_OPT_VALID(option))
312 return &bond_opts[option];
315 int bond_option_mode_set(struct bonding *bond, struct bond_opt_value *newval)
317 if (BOND_NO_USES_ARP(newval->value) && bond->params.arp_interval) {
318 pr_info("%s: %s mode is incompatible with arp monitoring, start mii monitoring\n",
319 bond->dev->name, newval->string);
320 /* disable arp monitoring */
321 bond->params.arp_interval = 0;
322 /* set miimon to default value */
323 bond->params.miimon = BOND_DEFAULT_MIIMON;
324 pr_info("%s: Setting MII monitoring interval to %d.\n",
325 bond->dev->name, bond->params.miimon);
328 /* don't cache arp_validate between modes */
329 bond->params.arp_validate = BOND_ARP_VALIDATE_NONE;
330 bond->params.mode = newval->value;
335 static struct net_device *__bond_option_active_slave_get(struct bonding *bond,
338 return USES_PRIMARY(bond->params.mode) && slave ? slave->dev : NULL;
341 struct net_device *bond_option_active_slave_get_rcu(struct bonding *bond)
343 struct slave *slave = rcu_dereference(bond->curr_active_slave);
345 return __bond_option_active_slave_get(bond, slave);
348 struct net_device *bond_option_active_slave_get(struct bonding *bond)
350 return __bond_option_active_slave_get(bond, bond->curr_active_slave);
353 int bond_option_active_slave_set(struct bonding *bond,
354 struct net_device *slave_dev)
359 if (!netif_is_bond_slave(slave_dev)) {
360 pr_err("Device %s is not bonding slave.\n",
365 if (bond->dev != netdev_master_upper_dev_get(slave_dev)) {
366 pr_err("%s: Device %s is not our slave.\n",
367 bond->dev->name, slave_dev->name);
372 if (!USES_PRIMARY(bond->params.mode)) {
373 pr_err("%s: Unable to change active slave; %s is in mode %d\n",
374 bond->dev->name, bond->dev->name, bond->params.mode);
379 write_lock_bh(&bond->curr_slave_lock);
381 /* check to see if we are clearing active */
383 pr_info("%s: Clearing current active slave.\n",
385 rcu_assign_pointer(bond->curr_active_slave, NULL);
386 bond_select_active_slave(bond);
388 struct slave *old_active = bond->curr_active_slave;
389 struct slave *new_active = bond_slave_get_rtnl(slave_dev);
393 if (new_active == old_active) {
395 pr_info("%s: %s is already the current active slave.\n",
396 bond->dev->name, new_active->dev->name);
398 if (old_active && (new_active->link == BOND_LINK_UP) &&
399 IS_UP(new_active->dev)) {
400 pr_info("%s: Setting %s as active slave.\n",
401 bond->dev->name, new_active->dev->name);
402 bond_change_active_slave(bond, new_active);
404 pr_err("%s: Could not set %s as active slave; either %s is down or the link is down.\n",
405 bond->dev->name, new_active->dev->name,
406 new_active->dev->name);
412 write_unlock_bh(&bond->curr_slave_lock);
413 unblock_netpoll_tx();
417 int bond_option_miimon_set(struct bonding *bond, int miimon)
420 pr_err("%s: Invalid miimon value %d not in range %d-%d; rejected.\n",
421 bond->dev->name, miimon, 0, INT_MAX);
424 pr_info("%s: Setting MII monitoring interval to %d.\n",
425 bond->dev->name, miimon);
426 bond->params.miimon = miimon;
427 if (bond->params.updelay)
428 pr_info("%s: Note: Updating updelay (to %d) since it is a multiple of the miimon value.\n",
430 bond->params.updelay * bond->params.miimon);
431 if (bond->params.downdelay)
432 pr_info("%s: Note: Updating downdelay (to %d) since it is a multiple of the miimon value.\n",
434 bond->params.downdelay * bond->params.miimon);
435 if (miimon && bond->params.arp_interval) {
436 pr_info("%s: MII monitoring cannot be used with ARP monitoring. Disabling ARP monitoring...\n",
438 bond->params.arp_interval = 0;
439 if (bond->params.arp_validate)
440 bond->params.arp_validate = BOND_ARP_VALIDATE_NONE;
442 if (bond->dev->flags & IFF_UP) {
443 /* If the interface is up, we may need to fire off
444 * the MII timer. If the interface is down, the
445 * timer will get fired off when the open function
449 cancel_delayed_work_sync(&bond->mii_work);
451 cancel_delayed_work_sync(&bond->arp_work);
452 queue_delayed_work(bond->wq, &bond->mii_work, 0);
458 int bond_option_updelay_set(struct bonding *bond, int updelay)
460 if (!(bond->params.miimon)) {
461 pr_err("%s: Unable to set up delay as MII monitoring is disabled\n",
467 pr_err("%s: Invalid up delay value %d not in range %d-%d; rejected.\n",
468 bond->dev->name, updelay, 0, INT_MAX);
471 if ((updelay % bond->params.miimon) != 0) {
472 pr_warn("%s: Warning: up delay (%d) is not a multiple of miimon (%d), updelay rounded to %d ms\n",
473 bond->dev->name, updelay,
475 (updelay / bond->params.miimon) *
476 bond->params.miimon);
478 bond->params.updelay = updelay / bond->params.miimon;
479 pr_info("%s: Setting up delay to %d.\n",
481 bond->params.updelay * bond->params.miimon);
487 int bond_option_downdelay_set(struct bonding *bond, int downdelay)
489 if (!(bond->params.miimon)) {
490 pr_err("%s: Unable to set down delay as MII monitoring is disabled\n",
496 pr_err("%s: Invalid down delay value %d not in range %d-%d; rejected.\n",
497 bond->dev->name, downdelay, 0, INT_MAX);
500 if ((downdelay % bond->params.miimon) != 0) {
501 pr_warn("%s: Warning: down delay (%d) is not a multiple of miimon (%d), delay rounded to %d ms\n",
502 bond->dev->name, downdelay,
504 (downdelay / bond->params.miimon) *
505 bond->params.miimon);
507 bond->params.downdelay = downdelay / bond->params.miimon;
508 pr_info("%s: Setting down delay to %d.\n",
510 bond->params.downdelay * bond->params.miimon);
516 int bond_option_use_carrier_set(struct bonding *bond, int use_carrier)
518 if ((use_carrier == 0) || (use_carrier == 1)) {
519 bond->params.use_carrier = use_carrier;
520 pr_info("%s: Setting use_carrier to %d.\n",
521 bond->dev->name, use_carrier);
523 pr_info("%s: Ignoring invalid use_carrier value %d.\n",
524 bond->dev->name, use_carrier);
530 int bond_option_arp_interval_set(struct bonding *bond, int arp_interval)
532 if (arp_interval < 0) {
533 pr_err("%s: Invalid arp_interval value %d not in range 0-%d; rejected.\n",
534 bond->dev->name, arp_interval, INT_MAX);
537 if (BOND_NO_USES_ARP(bond->params.mode)) {
538 pr_info("%s: ARP monitoring cannot be used with ALB/TLB/802.3ad. Only MII monitoring is supported on %s.\n",
539 bond->dev->name, bond->dev->name);
542 pr_info("%s: Setting ARP monitoring interval to %d.\n",
543 bond->dev->name, arp_interval);
544 bond->params.arp_interval = arp_interval;
546 if (bond->params.miimon) {
547 pr_info("%s: ARP monitoring cannot be used with MII monitoring. %s Disabling MII monitoring.\n",
548 bond->dev->name, bond->dev->name);
549 bond->params.miimon = 0;
551 if (!bond->params.arp_targets[0])
552 pr_info("%s: ARP monitoring has been set up, but no ARP targets have been specified.\n",
555 if (bond->dev->flags & IFF_UP) {
556 /* If the interface is up, we may need to fire off
557 * the ARP timer. If the interface is down, the
558 * timer will get fired off when the open function
562 if (bond->params.arp_validate)
563 bond->recv_probe = NULL;
564 cancel_delayed_work_sync(&bond->arp_work);
566 /* arp_validate can be set only in active-backup mode */
567 if (bond->params.arp_validate)
568 bond->recv_probe = bond_arp_rcv;
569 cancel_delayed_work_sync(&bond->mii_work);
570 queue_delayed_work(bond->wq, &bond->arp_work, 0);
577 static void _bond_options_arp_ip_target_set(struct bonding *bond, int slot,
579 unsigned long last_rx)
581 __be32 *targets = bond->params.arp_targets;
582 struct list_head *iter;
585 if (slot >= 0 && slot < BOND_MAX_ARP_TARGETS) {
586 bond_for_each_slave(bond, slave, iter)
587 slave->target_last_arp_rx[slot] = last_rx;
588 targets[slot] = target;
592 static int _bond_option_arp_ip_target_add(struct bonding *bond, __be32 target)
594 __be32 *targets = bond->params.arp_targets;
597 if (IS_IP_TARGET_UNUSABLE_ADDRESS(target)) {
598 pr_err("%s: invalid ARP target %pI4 specified for addition\n",
599 bond->dev->name, &target);
603 if (bond_get_targets_ip(targets, target) != -1) { /* dup */
604 pr_err("%s: ARP target %pI4 is already present\n",
605 bond->dev->name, &target);
609 ind = bond_get_targets_ip(targets, 0); /* first free slot */
611 pr_err("%s: ARP target table is full!\n",
616 pr_info("%s: adding ARP target %pI4.\n", bond->dev->name, &target);
618 _bond_options_arp_ip_target_set(bond, ind, target, jiffies);
623 int bond_option_arp_ip_target_add(struct bonding *bond, __be32 target)
627 /* not to race with bond_arp_rcv */
628 write_lock_bh(&bond->lock);
629 ret = _bond_option_arp_ip_target_add(bond, target);
630 write_unlock_bh(&bond->lock);
635 int bond_option_arp_ip_target_rem(struct bonding *bond, __be32 target)
637 __be32 *targets = bond->params.arp_targets;
638 struct list_head *iter;
640 unsigned long *targets_rx;
643 if (IS_IP_TARGET_UNUSABLE_ADDRESS(target)) {
644 pr_err("%s: invalid ARP target %pI4 specified for removal\n",
645 bond->dev->name, &target);
649 ind = bond_get_targets_ip(targets, target);
651 pr_err("%s: unable to remove nonexistent ARP target %pI4.\n",
652 bond->dev->name, &target);
656 if (ind == 0 && !targets[1] && bond->params.arp_interval)
657 pr_warn("%s: removing last arp target with arp_interval on\n",
660 pr_info("%s: removing ARP target %pI4.\n", bond->dev->name,
663 /* not to race with bond_arp_rcv */
664 write_lock_bh(&bond->lock);
666 bond_for_each_slave(bond, slave, iter) {
667 targets_rx = slave->target_last_arp_rx;
668 for (i = ind; (i < BOND_MAX_ARP_TARGETS-1) && targets[i+1]; i++)
669 targets_rx[i] = targets_rx[i+1];
672 for (i = ind; (i < BOND_MAX_ARP_TARGETS-1) && targets[i+1]; i++)
673 targets[i] = targets[i+1];
676 write_unlock_bh(&bond->lock);
681 int bond_option_arp_ip_targets_set(struct bonding *bond, __be32 *targets,
686 /* not to race with bond_arp_rcv */
687 write_lock_bh(&bond->lock);
690 for (i = 0; i < BOND_MAX_ARP_TARGETS; i++)
691 _bond_options_arp_ip_target_set(bond, i, 0, 0);
693 if (count == 0 && bond->params.arp_interval)
694 pr_warn("%s: removing last arp target with arp_interval on\n",
697 for (i = 0; i < count; i++) {
698 ret = _bond_option_arp_ip_target_add(bond, targets[i]);
703 write_unlock_bh(&bond->lock);
707 int bond_option_arp_validate_set(struct bonding *bond, int arp_validate)
709 if (bond_parm_tbl_lookup(arp_validate, arp_validate_tbl) < 0) {
710 pr_err("%s: Ignoring invalid arp_validate value %d.\n",
711 bond->dev->name, arp_validate);
715 if (bond->params.mode != BOND_MODE_ACTIVEBACKUP) {
716 pr_err("%s: arp_validate only supported in active-backup mode.\n",
721 pr_info("%s: setting arp_validate to %s (%d).\n",
722 bond->dev->name, arp_validate_tbl[arp_validate].modename,
725 if (bond->dev->flags & IFF_UP) {
727 bond->recv_probe = NULL;
728 else if (bond->params.arp_interval)
729 bond->recv_probe = bond_arp_rcv;
731 bond->params.arp_validate = arp_validate;
736 int bond_option_arp_all_targets_set(struct bonding *bond, int arp_all_targets)
738 if (bond_parm_tbl_lookup(arp_all_targets, arp_all_targets_tbl) < 0) {
739 pr_err("%s: Ignoring invalid arp_all_targets value %d.\n",
740 bond->dev->name, arp_all_targets);
744 pr_info("%s: setting arp_all_targets to %s (%d).\n",
745 bond->dev->name, arp_all_targets_tbl[arp_all_targets].modename,
748 bond->params.arp_all_targets = arp_all_targets;
753 int bond_option_primary_set(struct bonding *bond, const char *primary)
755 struct list_head *iter;
760 read_lock(&bond->lock);
761 write_lock_bh(&bond->curr_slave_lock);
763 if (!USES_PRIMARY(bond->params.mode)) {
764 pr_err("%s: Unable to set primary slave; %s is in mode %d\n",
765 bond->dev->name, bond->dev->name, bond->params.mode);
770 /* check to see if we are clearing primary */
771 if (!strlen(primary)) {
772 pr_info("%s: Setting primary slave to None.\n",
774 bond->primary_slave = NULL;
775 memset(bond->params.primary, 0, sizeof(bond->params.primary));
776 bond_select_active_slave(bond);
780 bond_for_each_slave(bond, slave, iter) {
781 if (strncmp(slave->dev->name, primary, IFNAMSIZ) == 0) {
782 pr_info("%s: Setting %s as primary slave.\n",
783 bond->dev->name, slave->dev->name);
784 bond->primary_slave = slave;
785 strcpy(bond->params.primary, slave->dev->name);
786 bond_select_active_slave(bond);
791 strncpy(bond->params.primary, primary, IFNAMSIZ);
792 bond->params.primary[IFNAMSIZ - 1] = 0;
794 pr_info("%s: Recording %s as primary, but it has not been enslaved to %s yet.\n",
795 bond->dev->name, primary, bond->dev->name);
798 write_unlock_bh(&bond->curr_slave_lock);
799 read_unlock(&bond->lock);
800 unblock_netpoll_tx();
805 int bond_option_primary_reselect_set(struct bonding *bond, int primary_reselect)
807 if (bond_parm_tbl_lookup(primary_reselect, pri_reselect_tbl) < 0) {
808 pr_err("%s: Ignoring invalid primary_reselect value %d.\n",
809 bond->dev->name, primary_reselect);
813 bond->params.primary_reselect = primary_reselect;
814 pr_info("%s: setting primary_reselect to %s (%d).\n",
815 bond->dev->name, pri_reselect_tbl[primary_reselect].modename,
819 write_lock_bh(&bond->curr_slave_lock);
820 bond_select_active_slave(bond);
821 write_unlock_bh(&bond->curr_slave_lock);
822 unblock_netpoll_tx();
827 int bond_option_fail_over_mac_set(struct bonding *bond, int fail_over_mac)
829 if (bond_parm_tbl_lookup(fail_over_mac, fail_over_mac_tbl) < 0) {
830 pr_err("%s: Ignoring invalid fail_over_mac value %d.\n",
831 bond->dev->name, fail_over_mac);
835 if (bond_has_slaves(bond)) {
836 pr_err("%s: Can't alter fail_over_mac with slaves in bond.\n",
841 bond->params.fail_over_mac = fail_over_mac;
842 pr_info("%s: Setting fail_over_mac to %s (%d).\n",
843 bond->dev->name, fail_over_mac_tbl[fail_over_mac].modename,
849 int bond_option_xmit_hash_policy_set(struct bonding *bond, int xmit_hash_policy)
851 if (bond_parm_tbl_lookup(xmit_hash_policy, xmit_hashtype_tbl) < 0) {
852 pr_err("%s: Ignoring invalid xmit_hash_policy value %d.\n",
853 bond->dev->name, xmit_hash_policy);
857 bond->params.xmit_policy = xmit_hash_policy;
858 pr_info("%s: setting xmit hash policy to %s (%d).\n",
860 xmit_hashtype_tbl[xmit_hash_policy].modename, xmit_hash_policy);
865 int bond_option_resend_igmp_set(struct bonding *bond, int resend_igmp)
867 if (resend_igmp < 0 || resend_igmp > 255) {
868 pr_err("%s: Invalid resend_igmp value %d not in range 0-255; rejected.\n",
869 bond->dev->name, resend_igmp);
873 bond->params.resend_igmp = resend_igmp;
874 pr_info("%s: Setting resend_igmp to %d.\n",
875 bond->dev->name, resend_igmp);
880 int bond_option_num_peer_notif_set(struct bonding *bond, int num_peer_notif)
882 bond->params.num_peer_notif = num_peer_notif;
886 int bond_option_all_slaves_active_set(struct bonding *bond,
887 int all_slaves_active)
889 struct list_head *iter;
892 if (all_slaves_active == bond->params.all_slaves_active)
895 if ((all_slaves_active == 0) || (all_slaves_active == 1)) {
896 bond->params.all_slaves_active = all_slaves_active;
898 pr_info("%s: Ignoring invalid all_slaves_active value %d.\n",
899 bond->dev->name, all_slaves_active);
903 bond_for_each_slave(bond, slave, iter) {
904 if (!bond_is_active_slave(slave)) {
905 if (all_slaves_active)
915 int bond_option_min_links_set(struct bonding *bond, int min_links)
917 pr_info("%s: Setting min links value to %u\n",
918 bond->dev->name, min_links);
919 bond->params.min_links = min_links;
924 int bond_option_lp_interval_set(struct bonding *bond, int lp_interval)
926 if (lp_interval <= 0) {
927 pr_err("%s: lp_interval must be between 1 and %d\n",
928 bond->dev->name, INT_MAX);
932 bond->params.lp_interval = lp_interval;
937 int bond_option_packets_per_slave_set(struct bonding *bond,
938 int packets_per_slave)
940 if (packets_per_slave < 0 || packets_per_slave > USHRT_MAX) {
941 pr_err("%s: packets_per_slave must be between 0 and %u\n",
942 bond->dev->name, USHRT_MAX);
946 if (bond->params.mode != BOND_MODE_ROUNDROBIN)
947 pr_warn("%s: Warning: packets_per_slave has effect only in balance-rr mode\n",
950 bond->params.packets_per_slave = packets_per_slave;
951 if (packets_per_slave > 0) {
952 bond->params.reciprocal_packets_per_slave =
953 reciprocal_value(packets_per_slave);
955 /* reciprocal_packets_per_slave is unused if
956 * packets_per_slave is 0 or 1, just initialize it
958 bond->params.reciprocal_packets_per_slave =
959 (struct reciprocal_value) { 0 };
965 int bond_option_lacp_rate_set(struct bonding *bond, int lacp_rate)
967 if (bond_parm_tbl_lookup(lacp_rate, bond_lacp_tbl) < 0) {
968 pr_err("%s: Ignoring invalid LACP rate value %d.\n",
969 bond->dev->name, lacp_rate);
973 if (bond->dev->flags & IFF_UP) {
974 pr_err("%s: Unable to update LACP rate because interface is up.\n",
979 if (bond->params.mode != BOND_MODE_8023AD) {
980 pr_err("%s: Unable to update LACP rate because bond is not in 802.3ad mode.\n",
985 bond->params.lacp_fast = lacp_rate;
986 bond_3ad_update_lacp_rate(bond);
987 pr_info("%s: Setting LACP rate to %s (%d).\n",
988 bond->dev->name, bond_lacp_tbl[lacp_rate].modename,
994 int bond_option_ad_select_set(struct bonding *bond, int ad_select)
996 if (bond_parm_tbl_lookup(ad_select, ad_select_tbl) < 0) {
997 pr_err("%s: Ignoring invalid ad_select value %d.\n",
998 bond->dev->name, ad_select);
1002 if (bond->dev->flags & IFF_UP) {
1003 pr_err("%s: Unable to update ad_select because interface is up.\n",
1008 bond->params.ad_select = ad_select;
1009 pr_info("%s: Setting ad_select to %s (%d).\n",
1010 bond->dev->name, ad_select_tbl[ad_select].modename,