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_option bond_opts[] = {
43 .desc = "bond device mode",
44 .flags = BOND_OPTFLAG_NOSLAVES | BOND_OPTFLAG_IFDOWN,
45 .values = bond_mode_tbl,
46 .set = bond_option_mode_set
48 [BOND_OPT_PACKETS_PER_SLAVE] = {
49 .id = BOND_OPT_PACKETS_PER_SLAVE,
50 .name = "packets_per_slave",
51 .desc = "Packets to send per slave in RR mode",
52 .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_ROUNDROBIN)),
53 .values = bond_pps_tbl,
54 .set = bond_option_pps_set
59 /* Searches for a value in opt's values[] table */
60 struct bond_opt_value *bond_opt_get_val(unsigned int option, u64 val)
62 struct bond_option *opt;
65 opt = bond_opt_get(option);
68 for (i = 0; opt->values && opt->values[i].string; i++)
69 if (opt->values[i].value == val)
70 return &opt->values[i];
75 /* Searches for a value in opt's values[] table which matches the flagmask */
76 static struct bond_opt_value *bond_opt_get_flags(const struct bond_option *opt,
81 for (i = 0; opt->values && opt->values[i].string; i++)
82 if (opt->values[i].flags & flagmask)
83 return &opt->values[i];
88 /* If maxval is missing then there's no range to check. In case minval is
89 * missing then it's considered to be 0.
91 static bool bond_opt_check_range(const struct bond_option *opt, u64 val)
93 struct bond_opt_value *minval, *maxval;
95 minval = bond_opt_get_flags(opt, BOND_VALFLAG_MIN);
96 maxval = bond_opt_get_flags(opt, BOND_VALFLAG_MAX);
97 if (!maxval || (minval && val < minval->value) || val > maxval->value)
104 * bond_opt_parse - parse option value
105 * @opt: the option to parse against
106 * @val: value to parse
108 * This function tries to extract the value from @val and check if it's
109 * a possible match for the option and returns NULL if a match isn't found,
110 * or the struct_opt_value that matched. It also strips the new line from
111 * @val->string if it's present.
113 struct bond_opt_value *bond_opt_parse(const struct bond_option *opt,
114 struct bond_opt_value *val)
116 char *p, valstr[BOND_OPT_MAX_NAMELEN + 1] = { 0, };
117 struct bond_opt_value *tbl, *ret = NULL;
121 /* No parsing if the option wants a raw val */
122 if (opt->flags & BOND_OPTFLAG_RAWVAL)
129 /* ULLONG_MAX is used to bypass string processing */
130 checkval = val->value != ULLONG_MAX;
134 p = strchr(val->string, '\n');
137 for (p = val->string; *p; p++)
138 if (!(isdigit(*p) || isspace(*p)))
140 /* The following code extracts the string to match or the value
141 * and sets checkval appropriately
144 rv = sscanf(val->string, "%32s", valstr);
146 rv = sscanf(val->string, "%llu", &val->value);
153 for (i = 0; tbl[i].string; i++) {
154 /* Check for exact match */
156 if (val->value == tbl[i].value)
159 if (!strcmp(valstr, "default") &&
160 (tbl[i].flags & BOND_VALFLAG_DEFAULT))
163 if (!strcmp(valstr, tbl[i].string))
166 /* Found an exact match */
170 /* Possible range match */
171 if (checkval && bond_opt_check_range(opt, val->value))
177 /* Check opt's dependencies against bond mode and currently set options */
178 static int bond_opt_check_deps(struct bonding *bond,
179 const struct bond_option *opt)
181 struct bond_params *params = &bond->params;
183 if (test_bit(params->mode, &opt->unsuppmodes))
185 if ((opt->flags & BOND_OPTFLAG_NOSLAVES) && bond_has_slaves(bond))
187 if ((opt->flags & BOND_OPTFLAG_IFDOWN) && (bond->dev->flags & IFF_UP))
193 static void bond_opt_dep_print(struct bonding *bond,
194 const struct bond_option *opt)
196 struct bond_opt_value *modeval;
197 struct bond_params *params;
199 params = &bond->params;
200 modeval = bond_opt_get_val(BOND_OPT_MODE, params->mode);
201 if (test_bit(params->mode, &opt->unsuppmodes))
202 pr_err("%s: option %s: mode dependency failed, not supported in mode %s(%llu)\n",
203 bond->dev->name, opt->name,
204 modeval->string, modeval->value);
207 static void bond_opt_error_interpret(struct bonding *bond,
208 const struct bond_option *opt,
209 int error, struct bond_opt_value *val)
211 struct bond_opt_value *minval, *maxval;
218 /* sometimes RAWVAL opts may have new lines */
219 p = strchr(val->string, '\n');
222 pr_err("%s: option %s: invalid value (%s).\n",
223 bond->dev->name, opt->name, val->string);
225 pr_err("%s: option %s: invalid value (%llu).\n",
226 bond->dev->name, opt->name, val->value);
229 minval = bond_opt_get_flags(opt, BOND_VALFLAG_MIN);
230 maxval = bond_opt_get_flags(opt, BOND_VALFLAG_MAX);
233 pr_err("%s: option %s: allowed values %llu - %llu.\n",
234 bond->dev->name, opt->name, minval ? minval->value : 0,
238 bond_opt_dep_print(bond, opt);
241 pr_err("%s: option %s: unable to set because the bond device has slaves.\n",
242 bond->dev->name, opt->name);
245 pr_err("%s: option %s: unable to set because the bond device is up.\n",
246 bond->dev->name, opt->name);
254 * __bond_opt_set - set a bonding option
255 * @bond: target bond device
256 * @option: option to set
257 * @val: value to set it to
259 * This function is used to change the bond's option value, it can be
260 * used for both enabling/changing an option and for disabling it. RTNL lock
261 * must be obtained before calling this function.
263 int __bond_opt_set(struct bonding *bond,
264 unsigned int option, struct bond_opt_value *val)
266 struct bond_opt_value *retval = NULL;
267 const struct bond_option *opt;
272 opt = bond_opt_get(option);
273 if (WARN_ON(!val) || WARN_ON(!opt))
275 ret = bond_opt_check_deps(bond, opt);
278 retval = bond_opt_parse(opt, val);
283 ret = opt->set(bond, retval);
286 bond_opt_error_interpret(bond, opt, ret, val);
292 * bond_opt_tryset_rtnl - try to acquire rtnl and call __bond_opt_set
293 * @bond: target bond device
294 * @option: option to set
295 * @buf: value to set it to
297 * This function tries to acquire RTNL without blocking and if successful
298 * calls __bond_opt_set. It is mainly used for sysfs option manipulation.
300 int bond_opt_tryset_rtnl(struct bonding *bond, unsigned int option, char *buf)
302 struct bond_opt_value optval;
306 return restart_syscall();
307 bond_opt_initstr(&optval, buf);
308 ret = __bond_opt_set(bond, option, &optval);
315 * bond_opt_get - get a pointer to an option
316 * @option: option for which to return a pointer
318 * This function checks if option is valid and if so returns a pointer
319 * to its entry in the bond_opts[] option array.
321 struct bond_option *bond_opt_get(unsigned int option)
323 if (!BOND_OPT_VALID(option))
326 return &bond_opts[option];
329 int bond_option_mode_set(struct bonding *bond, struct bond_opt_value *newval)
331 if (BOND_NO_USES_ARP(newval->value) && bond->params.arp_interval) {
332 pr_info("%s: %s mode is incompatible with arp monitoring, start mii monitoring\n",
333 bond->dev->name, newval->string);
334 /* disable arp monitoring */
335 bond->params.arp_interval = 0;
336 /* set miimon to default value */
337 bond->params.miimon = BOND_DEFAULT_MIIMON;
338 pr_info("%s: Setting MII monitoring interval to %d.\n",
339 bond->dev->name, bond->params.miimon);
342 /* don't cache arp_validate between modes */
343 bond->params.arp_validate = BOND_ARP_VALIDATE_NONE;
344 bond->params.mode = newval->value;
349 static struct net_device *__bond_option_active_slave_get(struct bonding *bond,
352 return USES_PRIMARY(bond->params.mode) && slave ? slave->dev : NULL;
355 struct net_device *bond_option_active_slave_get_rcu(struct bonding *bond)
357 struct slave *slave = rcu_dereference(bond->curr_active_slave);
359 return __bond_option_active_slave_get(bond, slave);
362 struct net_device *bond_option_active_slave_get(struct bonding *bond)
364 return __bond_option_active_slave_get(bond, bond->curr_active_slave);
367 int bond_option_active_slave_set(struct bonding *bond,
368 struct net_device *slave_dev)
373 if (!netif_is_bond_slave(slave_dev)) {
374 pr_err("Device %s is not bonding slave.\n",
379 if (bond->dev != netdev_master_upper_dev_get(slave_dev)) {
380 pr_err("%s: Device %s is not our slave.\n",
381 bond->dev->name, slave_dev->name);
386 if (!USES_PRIMARY(bond->params.mode)) {
387 pr_err("%s: Unable to change active slave; %s is in mode %d\n",
388 bond->dev->name, bond->dev->name, bond->params.mode);
393 write_lock_bh(&bond->curr_slave_lock);
395 /* check to see if we are clearing active */
397 pr_info("%s: Clearing current active slave.\n",
399 rcu_assign_pointer(bond->curr_active_slave, NULL);
400 bond_select_active_slave(bond);
402 struct slave *old_active = bond->curr_active_slave;
403 struct slave *new_active = bond_slave_get_rtnl(slave_dev);
407 if (new_active == old_active) {
409 pr_info("%s: %s is already the current active slave.\n",
410 bond->dev->name, new_active->dev->name);
412 if (old_active && (new_active->link == BOND_LINK_UP) &&
413 IS_UP(new_active->dev)) {
414 pr_info("%s: Setting %s as active slave.\n",
415 bond->dev->name, new_active->dev->name);
416 bond_change_active_slave(bond, new_active);
418 pr_err("%s: Could not set %s as active slave; either %s is down or the link is down.\n",
419 bond->dev->name, new_active->dev->name,
420 new_active->dev->name);
426 write_unlock_bh(&bond->curr_slave_lock);
427 unblock_netpoll_tx();
431 int bond_option_miimon_set(struct bonding *bond, int miimon)
434 pr_err("%s: Invalid miimon value %d not in range %d-%d; rejected.\n",
435 bond->dev->name, miimon, 0, INT_MAX);
438 pr_info("%s: Setting MII monitoring interval to %d.\n",
439 bond->dev->name, miimon);
440 bond->params.miimon = miimon;
441 if (bond->params.updelay)
442 pr_info("%s: Note: Updating updelay (to %d) since it is a multiple of the miimon value.\n",
444 bond->params.updelay * bond->params.miimon);
445 if (bond->params.downdelay)
446 pr_info("%s: Note: Updating downdelay (to %d) since it is a multiple of the miimon value.\n",
448 bond->params.downdelay * bond->params.miimon);
449 if (miimon && bond->params.arp_interval) {
450 pr_info("%s: MII monitoring cannot be used with ARP monitoring. Disabling ARP monitoring...\n",
452 bond->params.arp_interval = 0;
453 if (bond->params.arp_validate)
454 bond->params.arp_validate = BOND_ARP_VALIDATE_NONE;
456 if (bond->dev->flags & IFF_UP) {
457 /* If the interface is up, we may need to fire off
458 * the MII timer. If the interface is down, the
459 * timer will get fired off when the open function
463 cancel_delayed_work_sync(&bond->mii_work);
465 cancel_delayed_work_sync(&bond->arp_work);
466 queue_delayed_work(bond->wq, &bond->mii_work, 0);
472 int bond_option_updelay_set(struct bonding *bond, int updelay)
474 if (!(bond->params.miimon)) {
475 pr_err("%s: Unable to set up delay as MII monitoring is disabled\n",
481 pr_err("%s: Invalid up delay value %d not in range %d-%d; rejected.\n",
482 bond->dev->name, updelay, 0, INT_MAX);
485 if ((updelay % bond->params.miimon) != 0) {
486 pr_warn("%s: Warning: up delay (%d) is not a multiple of miimon (%d), updelay rounded to %d ms\n",
487 bond->dev->name, updelay,
489 (updelay / bond->params.miimon) *
490 bond->params.miimon);
492 bond->params.updelay = updelay / bond->params.miimon;
493 pr_info("%s: Setting up delay to %d.\n",
495 bond->params.updelay * bond->params.miimon);
501 int bond_option_downdelay_set(struct bonding *bond, int downdelay)
503 if (!(bond->params.miimon)) {
504 pr_err("%s: Unable to set down delay as MII monitoring is disabled\n",
510 pr_err("%s: Invalid down delay value %d not in range %d-%d; rejected.\n",
511 bond->dev->name, downdelay, 0, INT_MAX);
514 if ((downdelay % bond->params.miimon) != 0) {
515 pr_warn("%s: Warning: down delay (%d) is not a multiple of miimon (%d), delay rounded to %d ms\n",
516 bond->dev->name, downdelay,
518 (downdelay / bond->params.miimon) *
519 bond->params.miimon);
521 bond->params.downdelay = downdelay / bond->params.miimon;
522 pr_info("%s: Setting down delay to %d.\n",
524 bond->params.downdelay * bond->params.miimon);
530 int bond_option_use_carrier_set(struct bonding *bond, int use_carrier)
532 if ((use_carrier == 0) || (use_carrier == 1)) {
533 bond->params.use_carrier = use_carrier;
534 pr_info("%s: Setting use_carrier to %d.\n",
535 bond->dev->name, use_carrier);
537 pr_info("%s: Ignoring invalid use_carrier value %d.\n",
538 bond->dev->name, use_carrier);
544 int bond_option_arp_interval_set(struct bonding *bond, int arp_interval)
546 if (arp_interval < 0) {
547 pr_err("%s: Invalid arp_interval value %d not in range 0-%d; rejected.\n",
548 bond->dev->name, arp_interval, INT_MAX);
551 if (BOND_NO_USES_ARP(bond->params.mode)) {
552 pr_info("%s: ARP monitoring cannot be used with ALB/TLB/802.3ad. Only MII monitoring is supported on %s.\n",
553 bond->dev->name, bond->dev->name);
556 pr_info("%s: Setting ARP monitoring interval to %d.\n",
557 bond->dev->name, arp_interval);
558 bond->params.arp_interval = arp_interval;
560 if (bond->params.miimon) {
561 pr_info("%s: ARP monitoring cannot be used with MII monitoring. %s Disabling MII monitoring.\n",
562 bond->dev->name, bond->dev->name);
563 bond->params.miimon = 0;
565 if (!bond->params.arp_targets[0])
566 pr_info("%s: ARP monitoring has been set up, but no ARP targets have been specified.\n",
569 if (bond->dev->flags & IFF_UP) {
570 /* If the interface is up, we may need to fire off
571 * the ARP timer. If the interface is down, the
572 * timer will get fired off when the open function
576 if (bond->params.arp_validate)
577 bond->recv_probe = NULL;
578 cancel_delayed_work_sync(&bond->arp_work);
580 /* arp_validate can be set only in active-backup mode */
581 if (bond->params.arp_validate)
582 bond->recv_probe = bond_arp_rcv;
583 cancel_delayed_work_sync(&bond->mii_work);
584 queue_delayed_work(bond->wq, &bond->arp_work, 0);
591 static void _bond_options_arp_ip_target_set(struct bonding *bond, int slot,
593 unsigned long last_rx)
595 __be32 *targets = bond->params.arp_targets;
596 struct list_head *iter;
599 if (slot >= 0 && slot < BOND_MAX_ARP_TARGETS) {
600 bond_for_each_slave(bond, slave, iter)
601 slave->target_last_arp_rx[slot] = last_rx;
602 targets[slot] = target;
606 static int _bond_option_arp_ip_target_add(struct bonding *bond, __be32 target)
608 __be32 *targets = bond->params.arp_targets;
611 if (IS_IP_TARGET_UNUSABLE_ADDRESS(target)) {
612 pr_err("%s: invalid ARP target %pI4 specified for addition\n",
613 bond->dev->name, &target);
617 if (bond_get_targets_ip(targets, target) != -1) { /* dup */
618 pr_err("%s: ARP target %pI4 is already present\n",
619 bond->dev->name, &target);
623 ind = bond_get_targets_ip(targets, 0); /* first free slot */
625 pr_err("%s: ARP target table is full!\n",
630 pr_info("%s: adding ARP target %pI4.\n", bond->dev->name, &target);
632 _bond_options_arp_ip_target_set(bond, ind, target, jiffies);
637 int bond_option_arp_ip_target_add(struct bonding *bond, __be32 target)
641 /* not to race with bond_arp_rcv */
642 write_lock_bh(&bond->lock);
643 ret = _bond_option_arp_ip_target_add(bond, target);
644 write_unlock_bh(&bond->lock);
649 int bond_option_arp_ip_target_rem(struct bonding *bond, __be32 target)
651 __be32 *targets = bond->params.arp_targets;
652 struct list_head *iter;
654 unsigned long *targets_rx;
657 if (IS_IP_TARGET_UNUSABLE_ADDRESS(target)) {
658 pr_err("%s: invalid ARP target %pI4 specified for removal\n",
659 bond->dev->name, &target);
663 ind = bond_get_targets_ip(targets, target);
665 pr_err("%s: unable to remove nonexistent ARP target %pI4.\n",
666 bond->dev->name, &target);
670 if (ind == 0 && !targets[1] && bond->params.arp_interval)
671 pr_warn("%s: removing last arp target with arp_interval on\n",
674 pr_info("%s: removing ARP target %pI4.\n", bond->dev->name,
677 /* not to race with bond_arp_rcv */
678 write_lock_bh(&bond->lock);
680 bond_for_each_slave(bond, slave, iter) {
681 targets_rx = slave->target_last_arp_rx;
682 for (i = ind; (i < BOND_MAX_ARP_TARGETS-1) && targets[i+1]; i++)
683 targets_rx[i] = targets_rx[i+1];
686 for (i = ind; (i < BOND_MAX_ARP_TARGETS-1) && targets[i+1]; i++)
687 targets[i] = targets[i+1];
690 write_unlock_bh(&bond->lock);
695 int bond_option_arp_ip_targets_set(struct bonding *bond, __be32 *targets,
700 /* not to race with bond_arp_rcv */
701 write_lock_bh(&bond->lock);
704 for (i = 0; i < BOND_MAX_ARP_TARGETS; i++)
705 _bond_options_arp_ip_target_set(bond, i, 0, 0);
707 if (count == 0 && bond->params.arp_interval)
708 pr_warn("%s: removing last arp target with arp_interval on\n",
711 for (i = 0; i < count; i++) {
712 ret = _bond_option_arp_ip_target_add(bond, targets[i]);
717 write_unlock_bh(&bond->lock);
721 int bond_option_arp_validate_set(struct bonding *bond, int arp_validate)
723 if (bond_parm_tbl_lookup(arp_validate, arp_validate_tbl) < 0) {
724 pr_err("%s: Ignoring invalid arp_validate value %d.\n",
725 bond->dev->name, arp_validate);
729 if (bond->params.mode != BOND_MODE_ACTIVEBACKUP) {
730 pr_err("%s: arp_validate only supported in active-backup mode.\n",
735 pr_info("%s: setting arp_validate to %s (%d).\n",
736 bond->dev->name, arp_validate_tbl[arp_validate].modename,
739 if (bond->dev->flags & IFF_UP) {
741 bond->recv_probe = NULL;
742 else if (bond->params.arp_interval)
743 bond->recv_probe = bond_arp_rcv;
745 bond->params.arp_validate = arp_validate;
750 int bond_option_arp_all_targets_set(struct bonding *bond, int arp_all_targets)
752 if (bond_parm_tbl_lookup(arp_all_targets, arp_all_targets_tbl) < 0) {
753 pr_err("%s: Ignoring invalid arp_all_targets value %d.\n",
754 bond->dev->name, arp_all_targets);
758 pr_info("%s: setting arp_all_targets to %s (%d).\n",
759 bond->dev->name, arp_all_targets_tbl[arp_all_targets].modename,
762 bond->params.arp_all_targets = arp_all_targets;
767 int bond_option_primary_set(struct bonding *bond, const char *primary)
769 struct list_head *iter;
774 read_lock(&bond->lock);
775 write_lock_bh(&bond->curr_slave_lock);
777 if (!USES_PRIMARY(bond->params.mode)) {
778 pr_err("%s: Unable to set primary slave; %s is in mode %d\n",
779 bond->dev->name, bond->dev->name, bond->params.mode);
784 /* check to see if we are clearing primary */
785 if (!strlen(primary)) {
786 pr_info("%s: Setting primary slave to None.\n",
788 bond->primary_slave = NULL;
789 memset(bond->params.primary, 0, sizeof(bond->params.primary));
790 bond_select_active_slave(bond);
794 bond_for_each_slave(bond, slave, iter) {
795 if (strncmp(slave->dev->name, primary, IFNAMSIZ) == 0) {
796 pr_info("%s: Setting %s as primary slave.\n",
797 bond->dev->name, slave->dev->name);
798 bond->primary_slave = slave;
799 strcpy(bond->params.primary, slave->dev->name);
800 bond_select_active_slave(bond);
805 strncpy(bond->params.primary, primary, IFNAMSIZ);
806 bond->params.primary[IFNAMSIZ - 1] = 0;
808 pr_info("%s: Recording %s as primary, but it has not been enslaved to %s yet.\n",
809 bond->dev->name, primary, bond->dev->name);
812 write_unlock_bh(&bond->curr_slave_lock);
813 read_unlock(&bond->lock);
814 unblock_netpoll_tx();
819 int bond_option_primary_reselect_set(struct bonding *bond, int primary_reselect)
821 if (bond_parm_tbl_lookup(primary_reselect, pri_reselect_tbl) < 0) {
822 pr_err("%s: Ignoring invalid primary_reselect value %d.\n",
823 bond->dev->name, primary_reselect);
827 bond->params.primary_reselect = primary_reselect;
828 pr_info("%s: setting primary_reselect to %s (%d).\n",
829 bond->dev->name, pri_reselect_tbl[primary_reselect].modename,
833 write_lock_bh(&bond->curr_slave_lock);
834 bond_select_active_slave(bond);
835 write_unlock_bh(&bond->curr_slave_lock);
836 unblock_netpoll_tx();
841 int bond_option_fail_over_mac_set(struct bonding *bond, int fail_over_mac)
843 if (bond_parm_tbl_lookup(fail_over_mac, fail_over_mac_tbl) < 0) {
844 pr_err("%s: Ignoring invalid fail_over_mac value %d.\n",
845 bond->dev->name, fail_over_mac);
849 if (bond_has_slaves(bond)) {
850 pr_err("%s: Can't alter fail_over_mac with slaves in bond.\n",
855 bond->params.fail_over_mac = fail_over_mac;
856 pr_info("%s: Setting fail_over_mac to %s (%d).\n",
857 bond->dev->name, fail_over_mac_tbl[fail_over_mac].modename,
863 int bond_option_xmit_hash_policy_set(struct bonding *bond, int xmit_hash_policy)
865 if (bond_parm_tbl_lookup(xmit_hash_policy, xmit_hashtype_tbl) < 0) {
866 pr_err("%s: Ignoring invalid xmit_hash_policy value %d.\n",
867 bond->dev->name, xmit_hash_policy);
871 bond->params.xmit_policy = xmit_hash_policy;
872 pr_info("%s: setting xmit hash policy to %s (%d).\n",
874 xmit_hashtype_tbl[xmit_hash_policy].modename, xmit_hash_policy);
879 int bond_option_resend_igmp_set(struct bonding *bond, int resend_igmp)
881 if (resend_igmp < 0 || resend_igmp > 255) {
882 pr_err("%s: Invalid resend_igmp value %d not in range 0-255; rejected.\n",
883 bond->dev->name, resend_igmp);
887 bond->params.resend_igmp = resend_igmp;
888 pr_info("%s: Setting resend_igmp to %d.\n",
889 bond->dev->name, resend_igmp);
894 int bond_option_num_peer_notif_set(struct bonding *bond, int num_peer_notif)
896 bond->params.num_peer_notif = num_peer_notif;
900 int bond_option_all_slaves_active_set(struct bonding *bond,
901 int all_slaves_active)
903 struct list_head *iter;
906 if (all_slaves_active == bond->params.all_slaves_active)
909 if ((all_slaves_active == 0) || (all_slaves_active == 1)) {
910 bond->params.all_slaves_active = all_slaves_active;
912 pr_info("%s: Ignoring invalid all_slaves_active value %d.\n",
913 bond->dev->name, all_slaves_active);
917 bond_for_each_slave(bond, slave, iter) {
918 if (!bond_is_active_slave(slave)) {
919 if (all_slaves_active)
929 int bond_option_min_links_set(struct bonding *bond, int min_links)
931 pr_info("%s: Setting min links value to %u\n",
932 bond->dev->name, min_links);
933 bond->params.min_links = min_links;
938 int bond_option_lp_interval_set(struct bonding *bond, int lp_interval)
940 if (lp_interval <= 0) {
941 pr_err("%s: lp_interval must be between 1 and %d\n",
942 bond->dev->name, INT_MAX);
946 bond->params.lp_interval = lp_interval;
951 int bond_option_pps_set(struct bonding *bond, struct bond_opt_value *newval)
953 bond->params.packets_per_slave = newval->value;
954 if (newval->value > 0) {
955 bond->params.reciprocal_packets_per_slave =
956 reciprocal_value(newval->value);
958 /* reciprocal_packets_per_slave is unused if
959 * packets_per_slave is 0 or 1, just initialize it
961 bond->params.reciprocal_packets_per_slave =
962 (struct reciprocal_value) { 0 };
968 int bond_option_lacp_rate_set(struct bonding *bond, int lacp_rate)
970 if (bond_parm_tbl_lookup(lacp_rate, bond_lacp_tbl) < 0) {
971 pr_err("%s: Ignoring invalid LACP rate value %d.\n",
972 bond->dev->name, lacp_rate);
976 if (bond->dev->flags & IFF_UP) {
977 pr_err("%s: Unable to update LACP rate because interface is up.\n",
982 if (bond->params.mode != BOND_MODE_8023AD) {
983 pr_err("%s: Unable to update LACP rate because bond is not in 802.3ad mode.\n",
988 bond->params.lacp_fast = lacp_rate;
989 bond_3ad_update_lacp_rate(bond);
990 pr_info("%s: Setting LACP rate to %s (%d).\n",
991 bond->dev->name, bond_lacp_tbl[lacp_rate].modename,
997 int bond_option_ad_select_set(struct bonding *bond, int ad_select)
999 if (bond_parm_tbl_lookup(ad_select, ad_select_tbl) < 0) {
1000 pr_err("%s: Ignoring invalid ad_select value %d.\n",
1001 bond->dev->name, ad_select);
1005 if (bond->dev->flags & IFF_UP) {
1006 pr_err("%s: Unable to update ad_select because interface is up.\n",
1011 bond->params.ad_select = ad_select;
1012 pr_info("%s: Setting ad_select to %s (%d).\n",
1013 bond->dev->name, ad_select_tbl[ad_select].modename,