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_option bond_opts
[] = {
26 /* Searches for a value in opt's values[] table */
27 struct bond_opt_value
*bond_opt_get_val(unsigned int option
, u64 val
)
29 struct bond_option
*opt
;
32 opt
= bond_opt_get(option
);
35 for (i
= 0; opt
->values
&& opt
->values
[i
].string
; i
++)
36 if (opt
->values
[i
].value
== val
)
37 return &opt
->values
[i
];
42 /* Searches for a value in opt's values[] table which matches the flagmask */
43 static struct bond_opt_value
*bond_opt_get_flags(const struct bond_option
*opt
,
48 for (i
= 0; opt
->values
&& opt
->values
[i
].string
; i
++)
49 if (opt
->values
[i
].flags
& flagmask
)
50 return &opt
->values
[i
];
55 /* If maxval is missing then there's no range to check. In case minval is
56 * missing then it's considered to be 0.
58 static bool bond_opt_check_range(const struct bond_option
*opt
, u64 val
)
60 struct bond_opt_value
*minval
, *maxval
;
62 minval
= bond_opt_get_flags(opt
, BOND_VALFLAG_MIN
);
63 maxval
= bond_opt_get_flags(opt
, BOND_VALFLAG_MAX
);
64 if (!maxval
|| (minval
&& val
< minval
->value
) || val
> maxval
->value
)
71 * bond_opt_parse - parse option value
72 * @opt: the option to parse against
73 * @val: value to parse
75 * This function tries to extract the value from @val and check if it's
76 * a possible match for the option and returns NULL if a match isn't found,
77 * or the struct_opt_value that matched. It also strips the new line from
78 * @val->string if it's present.
80 struct bond_opt_value
*bond_opt_parse(const struct bond_option
*opt
,
81 struct bond_opt_value
*val
)
83 char *p
, valstr
[BOND_OPT_MAX_NAMELEN
+ 1] = { 0, };
84 struct bond_opt_value
*tbl
, *ret
= NULL
;
88 /* No parsing if the option wants a raw val */
89 if (opt
->flags
& BOND_OPTFLAG_RAWVAL
)
96 /* ULLONG_MAX is used to bypass string processing */
97 checkval
= val
->value
!= ULLONG_MAX
;
101 p
= strchr(val
->string
, '\n');
104 for (p
= val
->string
; *p
; p
++)
105 if (!(isdigit(*p
) || isspace(*p
)))
107 /* The following code extracts the string to match or the value
108 * and sets checkval appropriately
111 rv
= sscanf(val
->string
, "%32s", valstr
);
113 rv
= sscanf(val
->string
, "%llu", &val
->value
);
120 for (i
= 0; tbl
[i
].string
; i
++) {
121 /* Check for exact match */
123 if (val
->value
== tbl
[i
].value
)
126 if (!strcmp(valstr
, "default") &&
127 (tbl
[i
].flags
& BOND_VALFLAG_DEFAULT
))
130 if (!strcmp(valstr
, tbl
[i
].string
))
133 /* Found an exact match */
137 /* Possible range match */
138 if (checkval
&& bond_opt_check_range(opt
, val
->value
))
144 /* Check opt's dependencies against bond mode and currently set options */
145 static int bond_opt_check_deps(struct bonding
*bond
,
146 const struct bond_option
*opt
)
148 struct bond_params
*params
= &bond
->params
;
150 if (test_bit(params
->mode
, &opt
->unsuppmodes
))
152 if ((opt
->flags
& BOND_OPTFLAG_NOSLAVES
) && bond_has_slaves(bond
))
154 if ((opt
->flags
& BOND_OPTFLAG_IFDOWN
) && (bond
->dev
->flags
& IFF_UP
))
160 static void bond_opt_dep_print(struct bonding
*bond
,
161 const struct bond_option
*opt
)
163 struct bond_params
*params
;
165 params
= &bond
->params
;
166 if (test_bit(params
->mode
, &opt
->unsuppmodes
))
167 pr_err("%s: option %s: mode dependency failed\n",
168 bond
->dev
->name
, opt
->name
);
171 static void bond_opt_error_interpret(struct bonding
*bond
,
172 const struct bond_option
*opt
,
173 int error
, struct bond_opt_value
*val
)
175 struct bond_opt_value
*minval
, *maxval
;
182 /* sometimes RAWVAL opts may have new lines */
183 p
= strchr(val
->string
, '\n');
186 pr_err("%s: option %s: invalid value (%s).\n",
187 bond
->dev
->name
, opt
->name
, val
->string
);
189 pr_err("%s: option %s: invalid value (%llu).\n",
190 bond
->dev
->name
, opt
->name
, val
->value
);
193 minval
= bond_opt_get_flags(opt
, BOND_VALFLAG_MIN
);
194 maxval
= bond_opt_get_flags(opt
, BOND_VALFLAG_MAX
);
197 pr_err("%s: option %s: allowed values %llu - %llu.\n",
198 bond
->dev
->name
, opt
->name
, minval
? minval
->value
: 0,
202 bond_opt_dep_print(bond
, opt
);
205 pr_err("%s: option %s: unable to set because the bond device has slaves.\n",
206 bond
->dev
->name
, opt
->name
);
209 pr_err("%s: option %s: unable to set because the bond device is up.\n",
210 bond
->dev
->name
, opt
->name
);
218 * __bond_opt_set - set a bonding option
219 * @bond: target bond device
220 * @option: option to set
221 * @val: value to set it to
223 * This function is used to change the bond's option value, it can be
224 * used for both enabling/changing an option and for disabling it. RTNL lock
225 * must be obtained before calling this function.
227 int __bond_opt_set(struct bonding
*bond
,
228 unsigned int option
, struct bond_opt_value
*val
)
230 struct bond_opt_value
*retval
= NULL
;
231 const struct bond_option
*opt
;
236 opt
= bond_opt_get(option
);
237 if (WARN_ON(!val
) || WARN_ON(!opt
))
239 ret
= bond_opt_check_deps(bond
, opt
);
242 retval
= bond_opt_parse(opt
, val
);
247 ret
= opt
->set(bond
, retval
);
250 bond_opt_error_interpret(bond
, opt
, ret
, val
);
256 * bond_opt_tryset_rtnl - try to acquire rtnl and call __bond_opt_set
257 * @bond: target bond device
258 * @option: option to set
259 * @buf: value to set it to
261 * This function tries to acquire RTNL without blocking and if successful
262 * calls __bond_opt_set. It is mainly used for sysfs option manipulation.
264 int bond_opt_tryset_rtnl(struct bonding
*bond
, unsigned int option
, char *buf
)
266 struct bond_opt_value optval
;
270 return restart_syscall();
271 bond_opt_initstr(&optval
, buf
);
272 ret
= __bond_opt_set(bond
, option
, &optval
);
279 * bond_opt_get - get a pointer to an option
280 * @option: option for which to return a pointer
282 * This function checks if option is valid and if so returns a pointer
283 * to its entry in the bond_opts[] option array.
285 struct bond_option
*bond_opt_get(unsigned int option
)
287 if (!BOND_OPT_VALID(option
))
290 return &bond_opts
[option
];
293 int bond_option_mode_set(struct bonding
*bond
, int mode
)
295 if (bond_parm_tbl_lookup(mode
, bond_mode_tbl
) < 0) {
296 pr_err("%s: Ignoring invalid mode value %d.\n",
297 bond
->dev
->name
, mode
);
301 if (bond
->dev
->flags
& IFF_UP
) {
302 pr_err("%s: unable to update mode because interface is up.\n",
307 if (bond_has_slaves(bond
)) {
308 pr_err("%s: unable to update mode because bond has slaves.\n",
313 if (BOND_NO_USES_ARP(mode
) && bond
->params
.arp_interval
) {
314 pr_info("%s: %s mode is incompatible with arp monitoring, start mii monitoring\n",
315 bond
->dev
->name
, bond_mode_tbl
[mode
].modename
);
316 /* disable arp monitoring */
317 bond
->params
.arp_interval
= 0;
318 /* set miimon to default value */
319 bond
->params
.miimon
= BOND_DEFAULT_MIIMON
;
320 pr_info("%s: Setting MII monitoring interval to %d.\n",
321 bond
->dev
->name
, bond
->params
.miimon
);
324 /* don't cache arp_validate between modes */
325 bond
->params
.arp_validate
= BOND_ARP_VALIDATE_NONE
;
326 bond
->params
.mode
= mode
;
330 static struct net_device
*__bond_option_active_slave_get(struct bonding
*bond
,
333 return USES_PRIMARY(bond
->params
.mode
) && slave
? slave
->dev
: NULL
;
336 struct net_device
*bond_option_active_slave_get_rcu(struct bonding
*bond
)
338 struct slave
*slave
= rcu_dereference(bond
->curr_active_slave
);
340 return __bond_option_active_slave_get(bond
, slave
);
343 struct net_device
*bond_option_active_slave_get(struct bonding
*bond
)
345 return __bond_option_active_slave_get(bond
, bond
->curr_active_slave
);
348 int bond_option_active_slave_set(struct bonding
*bond
,
349 struct net_device
*slave_dev
)
354 if (!netif_is_bond_slave(slave_dev
)) {
355 pr_err("Device %s is not bonding slave.\n",
360 if (bond
->dev
!= netdev_master_upper_dev_get(slave_dev
)) {
361 pr_err("%s: Device %s is not our slave.\n",
362 bond
->dev
->name
, slave_dev
->name
);
367 if (!USES_PRIMARY(bond
->params
.mode
)) {
368 pr_err("%s: Unable to change active slave; %s is in mode %d\n",
369 bond
->dev
->name
, bond
->dev
->name
, bond
->params
.mode
);
374 write_lock_bh(&bond
->curr_slave_lock
);
376 /* check to see if we are clearing active */
378 pr_info("%s: Clearing current active slave.\n",
380 rcu_assign_pointer(bond
->curr_active_slave
, NULL
);
381 bond_select_active_slave(bond
);
383 struct slave
*old_active
= bond
->curr_active_slave
;
384 struct slave
*new_active
= bond_slave_get_rtnl(slave_dev
);
388 if (new_active
== old_active
) {
390 pr_info("%s: %s is already the current active slave.\n",
391 bond
->dev
->name
, new_active
->dev
->name
);
393 if (old_active
&& (new_active
->link
== BOND_LINK_UP
) &&
394 IS_UP(new_active
->dev
)) {
395 pr_info("%s: Setting %s as active slave.\n",
396 bond
->dev
->name
, new_active
->dev
->name
);
397 bond_change_active_slave(bond
, new_active
);
399 pr_err("%s: Could not set %s as active slave; either %s is down or the link is down.\n",
400 bond
->dev
->name
, new_active
->dev
->name
,
401 new_active
->dev
->name
);
407 write_unlock_bh(&bond
->curr_slave_lock
);
408 unblock_netpoll_tx();
412 int bond_option_miimon_set(struct bonding
*bond
, int miimon
)
415 pr_err("%s: Invalid miimon value %d not in range %d-%d; rejected.\n",
416 bond
->dev
->name
, miimon
, 0, INT_MAX
);
419 pr_info("%s: Setting MII monitoring interval to %d.\n",
420 bond
->dev
->name
, miimon
);
421 bond
->params
.miimon
= miimon
;
422 if (bond
->params
.updelay
)
423 pr_info("%s: Note: Updating updelay (to %d) since it is a multiple of the miimon value.\n",
425 bond
->params
.updelay
* bond
->params
.miimon
);
426 if (bond
->params
.downdelay
)
427 pr_info("%s: Note: Updating downdelay (to %d) since it is a multiple of the miimon value.\n",
429 bond
->params
.downdelay
* bond
->params
.miimon
);
430 if (miimon
&& bond
->params
.arp_interval
) {
431 pr_info("%s: MII monitoring cannot be used with ARP monitoring. Disabling ARP monitoring...\n",
433 bond
->params
.arp_interval
= 0;
434 if (bond
->params
.arp_validate
)
435 bond
->params
.arp_validate
= BOND_ARP_VALIDATE_NONE
;
437 if (bond
->dev
->flags
& IFF_UP
) {
438 /* If the interface is up, we may need to fire off
439 * the MII timer. If the interface is down, the
440 * timer will get fired off when the open function
444 cancel_delayed_work_sync(&bond
->mii_work
);
446 cancel_delayed_work_sync(&bond
->arp_work
);
447 queue_delayed_work(bond
->wq
, &bond
->mii_work
, 0);
453 int bond_option_updelay_set(struct bonding
*bond
, int updelay
)
455 if (!(bond
->params
.miimon
)) {
456 pr_err("%s: Unable to set up delay as MII monitoring is disabled\n",
462 pr_err("%s: Invalid up delay value %d not in range %d-%d; rejected.\n",
463 bond
->dev
->name
, updelay
, 0, INT_MAX
);
466 if ((updelay
% bond
->params
.miimon
) != 0) {
467 pr_warn("%s: Warning: up delay (%d) is not a multiple of miimon (%d), updelay rounded to %d ms\n",
468 bond
->dev
->name
, updelay
,
470 (updelay
/ bond
->params
.miimon
) *
471 bond
->params
.miimon
);
473 bond
->params
.updelay
= updelay
/ bond
->params
.miimon
;
474 pr_info("%s: Setting up delay to %d.\n",
476 bond
->params
.updelay
* bond
->params
.miimon
);
482 int bond_option_downdelay_set(struct bonding
*bond
, int downdelay
)
484 if (!(bond
->params
.miimon
)) {
485 pr_err("%s: Unable to set down delay as MII monitoring is disabled\n",
491 pr_err("%s: Invalid down delay value %d not in range %d-%d; rejected.\n",
492 bond
->dev
->name
, downdelay
, 0, INT_MAX
);
495 if ((downdelay
% bond
->params
.miimon
) != 0) {
496 pr_warn("%s: Warning: down delay (%d) is not a multiple of miimon (%d), delay rounded to %d ms\n",
497 bond
->dev
->name
, downdelay
,
499 (downdelay
/ bond
->params
.miimon
) *
500 bond
->params
.miimon
);
502 bond
->params
.downdelay
= downdelay
/ bond
->params
.miimon
;
503 pr_info("%s: Setting down delay to %d.\n",
505 bond
->params
.downdelay
* bond
->params
.miimon
);
511 int bond_option_use_carrier_set(struct bonding
*bond
, int use_carrier
)
513 if ((use_carrier
== 0) || (use_carrier
== 1)) {
514 bond
->params
.use_carrier
= use_carrier
;
515 pr_info("%s: Setting use_carrier to %d.\n",
516 bond
->dev
->name
, use_carrier
);
518 pr_info("%s: Ignoring invalid use_carrier value %d.\n",
519 bond
->dev
->name
, use_carrier
);
525 int bond_option_arp_interval_set(struct bonding
*bond
, int arp_interval
)
527 if (arp_interval
< 0) {
528 pr_err("%s: Invalid arp_interval value %d not in range 0-%d; rejected.\n",
529 bond
->dev
->name
, arp_interval
, INT_MAX
);
532 if (BOND_NO_USES_ARP(bond
->params
.mode
)) {
533 pr_info("%s: ARP monitoring cannot be used with ALB/TLB/802.3ad. Only MII monitoring is supported on %s.\n",
534 bond
->dev
->name
, bond
->dev
->name
);
537 pr_info("%s: Setting ARP monitoring interval to %d.\n",
538 bond
->dev
->name
, arp_interval
);
539 bond
->params
.arp_interval
= arp_interval
;
541 if (bond
->params
.miimon
) {
542 pr_info("%s: ARP monitoring cannot be used with MII monitoring. %s Disabling MII monitoring.\n",
543 bond
->dev
->name
, bond
->dev
->name
);
544 bond
->params
.miimon
= 0;
546 if (!bond
->params
.arp_targets
[0])
547 pr_info("%s: ARP monitoring has been set up, but no ARP targets have been specified.\n",
550 if (bond
->dev
->flags
& IFF_UP
) {
551 /* If the interface is up, we may need to fire off
552 * the ARP timer. If the interface is down, the
553 * timer will get fired off when the open function
557 if (bond
->params
.arp_validate
)
558 bond
->recv_probe
= NULL
;
559 cancel_delayed_work_sync(&bond
->arp_work
);
561 /* arp_validate can be set only in active-backup mode */
562 if (bond
->params
.arp_validate
)
563 bond
->recv_probe
= bond_arp_rcv
;
564 cancel_delayed_work_sync(&bond
->mii_work
);
565 queue_delayed_work(bond
->wq
, &bond
->arp_work
, 0);
572 static void _bond_options_arp_ip_target_set(struct bonding
*bond
, int slot
,
574 unsigned long last_rx
)
576 __be32
*targets
= bond
->params
.arp_targets
;
577 struct list_head
*iter
;
580 if (slot
>= 0 && slot
< BOND_MAX_ARP_TARGETS
) {
581 bond_for_each_slave(bond
, slave
, iter
)
582 slave
->target_last_arp_rx
[slot
] = last_rx
;
583 targets
[slot
] = target
;
587 static int _bond_option_arp_ip_target_add(struct bonding
*bond
, __be32 target
)
589 __be32
*targets
= bond
->params
.arp_targets
;
592 if (IS_IP_TARGET_UNUSABLE_ADDRESS(target
)) {
593 pr_err("%s: invalid ARP target %pI4 specified for addition\n",
594 bond
->dev
->name
, &target
);
598 if (bond_get_targets_ip(targets
, target
) != -1) { /* dup */
599 pr_err("%s: ARP target %pI4 is already present\n",
600 bond
->dev
->name
, &target
);
604 ind
= bond_get_targets_ip(targets
, 0); /* first free slot */
606 pr_err("%s: ARP target table is full!\n",
611 pr_info("%s: adding ARP target %pI4.\n", bond
->dev
->name
, &target
);
613 _bond_options_arp_ip_target_set(bond
, ind
, target
, jiffies
);
618 int bond_option_arp_ip_target_add(struct bonding
*bond
, __be32 target
)
622 /* not to race with bond_arp_rcv */
623 write_lock_bh(&bond
->lock
);
624 ret
= _bond_option_arp_ip_target_add(bond
, target
);
625 write_unlock_bh(&bond
->lock
);
630 int bond_option_arp_ip_target_rem(struct bonding
*bond
, __be32 target
)
632 __be32
*targets
= bond
->params
.arp_targets
;
633 struct list_head
*iter
;
635 unsigned long *targets_rx
;
638 if (IS_IP_TARGET_UNUSABLE_ADDRESS(target
)) {
639 pr_err("%s: invalid ARP target %pI4 specified for removal\n",
640 bond
->dev
->name
, &target
);
644 ind
= bond_get_targets_ip(targets
, target
);
646 pr_err("%s: unable to remove nonexistent ARP target %pI4.\n",
647 bond
->dev
->name
, &target
);
651 if (ind
== 0 && !targets
[1] && bond
->params
.arp_interval
)
652 pr_warn("%s: removing last arp target with arp_interval on\n",
655 pr_info("%s: removing ARP target %pI4.\n", bond
->dev
->name
,
658 /* not to race with bond_arp_rcv */
659 write_lock_bh(&bond
->lock
);
661 bond_for_each_slave(bond
, slave
, iter
) {
662 targets_rx
= slave
->target_last_arp_rx
;
663 for (i
= ind
; (i
< BOND_MAX_ARP_TARGETS
-1) && targets
[i
+1]; i
++)
664 targets_rx
[i
] = targets_rx
[i
+1];
667 for (i
= ind
; (i
< BOND_MAX_ARP_TARGETS
-1) && targets
[i
+1]; i
++)
668 targets
[i
] = targets
[i
+1];
671 write_unlock_bh(&bond
->lock
);
676 int bond_option_arp_ip_targets_set(struct bonding
*bond
, __be32
*targets
,
681 /* not to race with bond_arp_rcv */
682 write_lock_bh(&bond
->lock
);
685 for (i
= 0; i
< BOND_MAX_ARP_TARGETS
; i
++)
686 _bond_options_arp_ip_target_set(bond
, i
, 0, 0);
688 if (count
== 0 && bond
->params
.arp_interval
)
689 pr_warn("%s: removing last arp target with arp_interval on\n",
692 for (i
= 0; i
< count
; i
++) {
693 ret
= _bond_option_arp_ip_target_add(bond
, targets
[i
]);
698 write_unlock_bh(&bond
->lock
);
702 int bond_option_arp_validate_set(struct bonding
*bond
, int arp_validate
)
704 if (bond_parm_tbl_lookup(arp_validate
, arp_validate_tbl
) < 0) {
705 pr_err("%s: Ignoring invalid arp_validate value %d.\n",
706 bond
->dev
->name
, arp_validate
);
710 if (bond
->params
.mode
!= BOND_MODE_ACTIVEBACKUP
) {
711 pr_err("%s: arp_validate only supported in active-backup mode.\n",
716 pr_info("%s: setting arp_validate to %s (%d).\n",
717 bond
->dev
->name
, arp_validate_tbl
[arp_validate
].modename
,
720 if (bond
->dev
->flags
& IFF_UP
) {
722 bond
->recv_probe
= NULL
;
723 else if (bond
->params
.arp_interval
)
724 bond
->recv_probe
= bond_arp_rcv
;
726 bond
->params
.arp_validate
= arp_validate
;
731 int bond_option_arp_all_targets_set(struct bonding
*bond
, int arp_all_targets
)
733 if (bond_parm_tbl_lookup(arp_all_targets
, arp_all_targets_tbl
) < 0) {
734 pr_err("%s: Ignoring invalid arp_all_targets value %d.\n",
735 bond
->dev
->name
, arp_all_targets
);
739 pr_info("%s: setting arp_all_targets to %s (%d).\n",
740 bond
->dev
->name
, arp_all_targets_tbl
[arp_all_targets
].modename
,
743 bond
->params
.arp_all_targets
= arp_all_targets
;
748 int bond_option_primary_set(struct bonding
*bond
, const char *primary
)
750 struct list_head
*iter
;
755 read_lock(&bond
->lock
);
756 write_lock_bh(&bond
->curr_slave_lock
);
758 if (!USES_PRIMARY(bond
->params
.mode
)) {
759 pr_err("%s: Unable to set primary slave; %s is in mode %d\n",
760 bond
->dev
->name
, bond
->dev
->name
, bond
->params
.mode
);
765 /* check to see if we are clearing primary */
766 if (!strlen(primary
)) {
767 pr_info("%s: Setting primary slave to None.\n",
769 bond
->primary_slave
= NULL
;
770 memset(bond
->params
.primary
, 0, sizeof(bond
->params
.primary
));
771 bond_select_active_slave(bond
);
775 bond_for_each_slave(bond
, slave
, iter
) {
776 if (strncmp(slave
->dev
->name
, primary
, IFNAMSIZ
) == 0) {
777 pr_info("%s: Setting %s as primary slave.\n",
778 bond
->dev
->name
, slave
->dev
->name
);
779 bond
->primary_slave
= slave
;
780 strcpy(bond
->params
.primary
, slave
->dev
->name
);
781 bond_select_active_slave(bond
);
786 strncpy(bond
->params
.primary
, primary
, IFNAMSIZ
);
787 bond
->params
.primary
[IFNAMSIZ
- 1] = 0;
789 pr_info("%s: Recording %s as primary, but it has not been enslaved to %s yet.\n",
790 bond
->dev
->name
, primary
, bond
->dev
->name
);
793 write_unlock_bh(&bond
->curr_slave_lock
);
794 read_unlock(&bond
->lock
);
795 unblock_netpoll_tx();
800 int bond_option_primary_reselect_set(struct bonding
*bond
, int primary_reselect
)
802 if (bond_parm_tbl_lookup(primary_reselect
, pri_reselect_tbl
) < 0) {
803 pr_err("%s: Ignoring invalid primary_reselect value %d.\n",
804 bond
->dev
->name
, primary_reselect
);
808 bond
->params
.primary_reselect
= primary_reselect
;
809 pr_info("%s: setting primary_reselect to %s (%d).\n",
810 bond
->dev
->name
, pri_reselect_tbl
[primary_reselect
].modename
,
814 write_lock_bh(&bond
->curr_slave_lock
);
815 bond_select_active_slave(bond
);
816 write_unlock_bh(&bond
->curr_slave_lock
);
817 unblock_netpoll_tx();
822 int bond_option_fail_over_mac_set(struct bonding
*bond
, int fail_over_mac
)
824 if (bond_parm_tbl_lookup(fail_over_mac
, fail_over_mac_tbl
) < 0) {
825 pr_err("%s: Ignoring invalid fail_over_mac value %d.\n",
826 bond
->dev
->name
, fail_over_mac
);
830 if (bond_has_slaves(bond
)) {
831 pr_err("%s: Can't alter fail_over_mac with slaves in bond.\n",
836 bond
->params
.fail_over_mac
= fail_over_mac
;
837 pr_info("%s: Setting fail_over_mac to %s (%d).\n",
838 bond
->dev
->name
, fail_over_mac_tbl
[fail_over_mac
].modename
,
844 int bond_option_xmit_hash_policy_set(struct bonding
*bond
, int xmit_hash_policy
)
846 if (bond_parm_tbl_lookup(xmit_hash_policy
, xmit_hashtype_tbl
) < 0) {
847 pr_err("%s: Ignoring invalid xmit_hash_policy value %d.\n",
848 bond
->dev
->name
, xmit_hash_policy
);
852 bond
->params
.xmit_policy
= xmit_hash_policy
;
853 pr_info("%s: setting xmit hash policy to %s (%d).\n",
855 xmit_hashtype_tbl
[xmit_hash_policy
].modename
, xmit_hash_policy
);
860 int bond_option_resend_igmp_set(struct bonding
*bond
, int resend_igmp
)
862 if (resend_igmp
< 0 || resend_igmp
> 255) {
863 pr_err("%s: Invalid resend_igmp value %d not in range 0-255; rejected.\n",
864 bond
->dev
->name
, resend_igmp
);
868 bond
->params
.resend_igmp
= resend_igmp
;
869 pr_info("%s: Setting resend_igmp to %d.\n",
870 bond
->dev
->name
, resend_igmp
);
875 int bond_option_num_peer_notif_set(struct bonding
*bond
, int num_peer_notif
)
877 bond
->params
.num_peer_notif
= num_peer_notif
;
881 int bond_option_all_slaves_active_set(struct bonding
*bond
,
882 int all_slaves_active
)
884 struct list_head
*iter
;
887 if (all_slaves_active
== bond
->params
.all_slaves_active
)
890 if ((all_slaves_active
== 0) || (all_slaves_active
== 1)) {
891 bond
->params
.all_slaves_active
= all_slaves_active
;
893 pr_info("%s: Ignoring invalid all_slaves_active value %d.\n",
894 bond
->dev
->name
, all_slaves_active
);
898 bond_for_each_slave(bond
, slave
, iter
) {
899 if (!bond_is_active_slave(slave
)) {
900 if (all_slaves_active
)
910 int bond_option_min_links_set(struct bonding
*bond
, int min_links
)
912 pr_info("%s: Setting min links value to %u\n",
913 bond
->dev
->name
, min_links
);
914 bond
->params
.min_links
= min_links
;
919 int bond_option_lp_interval_set(struct bonding
*bond
, int lp_interval
)
921 if (lp_interval
<= 0) {
922 pr_err("%s: lp_interval must be between 1 and %d\n",
923 bond
->dev
->name
, INT_MAX
);
927 bond
->params
.lp_interval
= lp_interval
;
932 int bond_option_packets_per_slave_set(struct bonding
*bond
,
933 int packets_per_slave
)
935 if (packets_per_slave
< 0 || packets_per_slave
> USHRT_MAX
) {
936 pr_err("%s: packets_per_slave must be between 0 and %u\n",
937 bond
->dev
->name
, USHRT_MAX
);
941 if (bond
->params
.mode
!= BOND_MODE_ROUNDROBIN
)
942 pr_warn("%s: Warning: packets_per_slave has effect only in balance-rr mode\n",
945 bond
->params
.packets_per_slave
= packets_per_slave
;
946 if (packets_per_slave
> 0) {
947 bond
->params
.reciprocal_packets_per_slave
=
948 reciprocal_value(packets_per_slave
);
950 /* reciprocal_packets_per_slave is unused if
951 * packets_per_slave is 0 or 1, just initialize it
953 bond
->params
.reciprocal_packets_per_slave
=
954 (struct reciprocal_value
) { 0 };
960 int bond_option_lacp_rate_set(struct bonding
*bond
, int lacp_rate
)
962 if (bond_parm_tbl_lookup(lacp_rate
, bond_lacp_tbl
) < 0) {
963 pr_err("%s: Ignoring invalid LACP rate value %d.\n",
964 bond
->dev
->name
, lacp_rate
);
968 if (bond
->dev
->flags
& IFF_UP
) {
969 pr_err("%s: Unable to update LACP rate because interface is up.\n",
974 if (bond
->params
.mode
!= BOND_MODE_8023AD
) {
975 pr_err("%s: Unable to update LACP rate because bond is not in 802.3ad mode.\n",
980 bond
->params
.lacp_fast
= lacp_rate
;
981 bond_3ad_update_lacp_rate(bond
);
982 pr_info("%s: Setting LACP rate to %s (%d).\n",
983 bond
->dev
->name
, bond_lacp_tbl
[lacp_rate
].modename
,
989 int bond_option_ad_select_set(struct bonding
*bond
, int ad_select
)
991 if (bond_parm_tbl_lookup(ad_select
, ad_select_tbl
) < 0) {
992 pr_err("%s: Ignoring invalid ad_select value %d.\n",
993 bond
->dev
->name
, ad_select
);
997 if (bond
->dev
->flags
& IFF_UP
) {
998 pr_err("%s: Unable to update ad_select because interface is up.\n",
1003 bond
->params
.ad_select
= ad_select
;
1004 pr_info("%s: Setting ad_select to %s (%d).\n",
1005 bond
->dev
->name
, ad_select_tbl
[ad_select
].modename
,