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>
20 #include <linux/inet.h>
23 static struct bond_opt_value bond_mode_tbl
[] = {
24 { "balance-rr", BOND_MODE_ROUNDROBIN
, BOND_VALFLAG_DEFAULT
},
25 { "active-backup", BOND_MODE_ACTIVEBACKUP
, 0},
26 { "balance-xor", BOND_MODE_XOR
, 0},
27 { "broadcast", BOND_MODE_BROADCAST
, 0},
28 { "802.3ad", BOND_MODE_8023AD
, 0},
29 { "balance-tlb", BOND_MODE_TLB
, 0},
30 { "balance-alb", BOND_MODE_ALB
, 0},
34 static struct bond_opt_value bond_pps_tbl
[] = {
35 { "default", 1, BOND_VALFLAG_DEFAULT
},
36 { "maxval", USHRT_MAX
, BOND_VALFLAG_MAX
},
40 static struct bond_opt_value bond_xmit_hashtype_tbl
[] = {
41 { "layer2", BOND_XMIT_POLICY_LAYER2
, BOND_VALFLAG_DEFAULT
},
42 { "layer3+4", BOND_XMIT_POLICY_LAYER34
, 0},
43 { "layer2+3", BOND_XMIT_POLICY_LAYER23
, 0},
44 { "encap2+3", BOND_XMIT_POLICY_ENCAP23
, 0},
45 { "encap3+4", BOND_XMIT_POLICY_ENCAP34
, 0},
49 static struct bond_opt_value bond_arp_validate_tbl
[] = {
50 { "none", BOND_ARP_VALIDATE_NONE
, BOND_VALFLAG_DEFAULT
},
51 { "active", BOND_ARP_VALIDATE_ACTIVE
, 0},
52 { "backup", BOND_ARP_VALIDATE_BACKUP
, 0},
53 { "all", BOND_ARP_VALIDATE_ALL
, 0},
57 static struct bond_opt_value bond_arp_all_targets_tbl
[] = {
58 { "any", BOND_ARP_TARGETS_ANY
, BOND_VALFLAG_DEFAULT
},
59 { "all", BOND_ARP_TARGETS_ALL
, 0},
63 static struct bond_opt_value bond_fail_over_mac_tbl
[] = {
64 { "none", BOND_FOM_NONE
, BOND_VALFLAG_DEFAULT
},
65 { "active", BOND_FOM_ACTIVE
, 0},
66 { "follow", BOND_FOM_FOLLOW
, 0},
70 static struct bond_opt_value bond_intmax_tbl
[] = {
71 { "off", 0, BOND_VALFLAG_DEFAULT
},
72 { "maxval", INT_MAX
, BOND_VALFLAG_MAX
},
75 static struct bond_option bond_opts
[] = {
79 .desc
= "bond device mode",
80 .flags
= BOND_OPTFLAG_NOSLAVES
| BOND_OPTFLAG_IFDOWN
,
81 .values
= bond_mode_tbl
,
82 .set
= bond_option_mode_set
84 [BOND_OPT_PACKETS_PER_SLAVE
] = {
85 .id
= BOND_OPT_PACKETS_PER_SLAVE
,
86 .name
= "packets_per_slave",
87 .desc
= "Packets to send per slave in RR mode",
88 .unsuppmodes
= BOND_MODE_ALL_EX(BIT(BOND_MODE_ROUNDROBIN
)),
89 .values
= bond_pps_tbl
,
90 .set
= bond_option_pps_set
92 [BOND_OPT_XMIT_HASH
] = {
93 .id
= BOND_OPT_XMIT_HASH
,
94 .name
= "xmit_hash_policy",
95 .desc
= "balance-xor and 802.3ad hashing method",
96 .values
= bond_xmit_hashtype_tbl
,
97 .set
= bond_option_xmit_hash_policy_set
99 [BOND_OPT_ARP_VALIDATE
] = {
100 .id
= BOND_OPT_ARP_VALIDATE
,
101 .name
= "arp_validate",
102 .desc
= "validate src/dst of ARP probes",
103 .unsuppmodes
= BOND_MODE_ALL_EX(BIT(BOND_MODE_ACTIVEBACKUP
)),
104 .values
= bond_arp_validate_tbl
,
105 .set
= bond_option_arp_validate_set
107 [BOND_OPT_ARP_ALL_TARGETS
] = {
108 .id
= BOND_OPT_ARP_ALL_TARGETS
,
109 .name
= "arp_all_targets",
110 .desc
= "fail on any/all arp targets timeout",
111 .values
= bond_arp_all_targets_tbl
,
112 .set
= bond_option_arp_all_targets_set
114 [BOND_OPT_FAIL_OVER_MAC
] = {
115 .id
= BOND_OPT_FAIL_OVER_MAC
,
116 .name
= "fail_over_mac",
117 .desc
= "For active-backup, do not set all slaves to the same MAC",
118 .flags
= BOND_OPTFLAG_NOSLAVES
,
119 .values
= bond_fail_over_mac_tbl
,
120 .set
= bond_option_fail_over_mac_set
122 [BOND_OPT_ARP_INTERVAL
] = {
123 .id
= BOND_OPT_ARP_INTERVAL
,
124 .name
= "arp_interval",
125 .desc
= "arp interval in milliseconds",
126 .unsuppmodes
= BIT(BOND_MODE_8023AD
) | BIT(BOND_MODE_TLB
) |
128 .values
= bond_intmax_tbl
,
129 .set
= bond_option_arp_interval_set
131 [BOND_OPT_ARP_TARGETS
] = {
132 .id
= BOND_OPT_ARP_TARGETS
,
133 .name
= "arp_ip_target",
134 .desc
= "arp targets in n.n.n.n form",
135 .flags
= BOND_OPTFLAG_RAWVAL
,
136 .set
= bond_option_arp_ip_targets_set
138 [BOND_OPT_DOWNDELAY
] = {
139 .id
= BOND_OPT_DOWNDELAY
,
141 .desc
= "Delay before considering link down, in milliseconds",
142 .values
= bond_intmax_tbl
,
143 .set
= bond_option_downdelay_set
148 /* Searches for a value in opt's values[] table */
149 struct bond_opt_value
*bond_opt_get_val(unsigned int option
, u64 val
)
151 struct bond_option
*opt
;
154 opt
= bond_opt_get(option
);
157 for (i
= 0; opt
->values
&& opt
->values
[i
].string
; i
++)
158 if (opt
->values
[i
].value
== val
)
159 return &opt
->values
[i
];
164 /* Searches for a value in opt's values[] table which matches the flagmask */
165 static struct bond_opt_value
*bond_opt_get_flags(const struct bond_option
*opt
,
170 for (i
= 0; opt
->values
&& opt
->values
[i
].string
; i
++)
171 if (opt
->values
[i
].flags
& flagmask
)
172 return &opt
->values
[i
];
177 /* If maxval is missing then there's no range to check. In case minval is
178 * missing then it's considered to be 0.
180 static bool bond_opt_check_range(const struct bond_option
*opt
, u64 val
)
182 struct bond_opt_value
*minval
, *maxval
;
184 minval
= bond_opt_get_flags(opt
, BOND_VALFLAG_MIN
);
185 maxval
= bond_opt_get_flags(opt
, BOND_VALFLAG_MAX
);
186 if (!maxval
|| (minval
&& val
< minval
->value
) || val
> maxval
->value
)
193 * bond_opt_parse - parse option value
194 * @opt: the option to parse against
195 * @val: value to parse
197 * This function tries to extract the value from @val and check if it's
198 * a possible match for the option and returns NULL if a match isn't found,
199 * or the struct_opt_value that matched. It also strips the new line from
200 * @val->string if it's present.
202 struct bond_opt_value
*bond_opt_parse(const struct bond_option
*opt
,
203 struct bond_opt_value
*val
)
205 char *p
, valstr
[BOND_OPT_MAX_NAMELEN
+ 1] = { 0, };
206 struct bond_opt_value
*tbl
, *ret
= NULL
;
210 /* No parsing if the option wants a raw val */
211 if (opt
->flags
& BOND_OPTFLAG_RAWVAL
)
218 /* ULLONG_MAX is used to bypass string processing */
219 checkval
= val
->value
!= ULLONG_MAX
;
223 p
= strchr(val
->string
, '\n');
226 for (p
= val
->string
; *p
; p
++)
227 if (!(isdigit(*p
) || isspace(*p
)))
229 /* The following code extracts the string to match or the value
230 * and sets checkval appropriately
233 rv
= sscanf(val
->string
, "%32s", valstr
);
235 rv
= sscanf(val
->string
, "%llu", &val
->value
);
242 for (i
= 0; tbl
[i
].string
; i
++) {
243 /* Check for exact match */
245 if (val
->value
== tbl
[i
].value
)
248 if (!strcmp(valstr
, "default") &&
249 (tbl
[i
].flags
& BOND_VALFLAG_DEFAULT
))
252 if (!strcmp(valstr
, tbl
[i
].string
))
255 /* Found an exact match */
259 /* Possible range match */
260 if (checkval
&& bond_opt_check_range(opt
, val
->value
))
266 /* Check opt's dependencies against bond mode and currently set options */
267 static int bond_opt_check_deps(struct bonding
*bond
,
268 const struct bond_option
*opt
)
270 struct bond_params
*params
= &bond
->params
;
272 if (test_bit(params
->mode
, &opt
->unsuppmodes
))
274 if ((opt
->flags
& BOND_OPTFLAG_NOSLAVES
) && bond_has_slaves(bond
))
276 if ((opt
->flags
& BOND_OPTFLAG_IFDOWN
) && (bond
->dev
->flags
& IFF_UP
))
282 static void bond_opt_dep_print(struct bonding
*bond
,
283 const struct bond_option
*opt
)
285 struct bond_opt_value
*modeval
;
286 struct bond_params
*params
;
288 params
= &bond
->params
;
289 modeval
= bond_opt_get_val(BOND_OPT_MODE
, params
->mode
);
290 if (test_bit(params
->mode
, &opt
->unsuppmodes
))
291 pr_err("%s: option %s: mode dependency failed, not supported in mode %s(%llu)\n",
292 bond
->dev
->name
, opt
->name
,
293 modeval
->string
, modeval
->value
);
296 static void bond_opt_error_interpret(struct bonding
*bond
,
297 const struct bond_option
*opt
,
298 int error
, struct bond_opt_value
*val
)
300 struct bond_opt_value
*minval
, *maxval
;
307 /* sometimes RAWVAL opts may have new lines */
308 p
= strchr(val
->string
, '\n');
311 pr_err("%s: option %s: invalid value (%s).\n",
312 bond
->dev
->name
, opt
->name
, val
->string
);
314 pr_err("%s: option %s: invalid value (%llu).\n",
315 bond
->dev
->name
, opt
->name
, val
->value
);
318 minval
= bond_opt_get_flags(opt
, BOND_VALFLAG_MIN
);
319 maxval
= bond_opt_get_flags(opt
, BOND_VALFLAG_MAX
);
322 pr_err("%s: option %s: allowed values %llu - %llu.\n",
323 bond
->dev
->name
, opt
->name
, minval
? minval
->value
: 0,
327 bond_opt_dep_print(bond
, opt
);
330 pr_err("%s: option %s: unable to set because the bond device has slaves.\n",
331 bond
->dev
->name
, opt
->name
);
334 pr_err("%s: option %s: unable to set because the bond device is up.\n",
335 bond
->dev
->name
, opt
->name
);
343 * __bond_opt_set - set a bonding option
344 * @bond: target bond device
345 * @option: option to set
346 * @val: value to set it to
348 * This function is used to change the bond's option value, it can be
349 * used for both enabling/changing an option and for disabling it. RTNL lock
350 * must be obtained before calling this function.
352 int __bond_opt_set(struct bonding
*bond
,
353 unsigned int option
, struct bond_opt_value
*val
)
355 struct bond_opt_value
*retval
= NULL
;
356 const struct bond_option
*opt
;
361 opt
= bond_opt_get(option
);
362 if (WARN_ON(!val
) || WARN_ON(!opt
))
364 ret
= bond_opt_check_deps(bond
, opt
);
367 retval
= bond_opt_parse(opt
, val
);
372 ret
= opt
->set(bond
, retval
);
375 bond_opt_error_interpret(bond
, opt
, ret
, val
);
381 * bond_opt_tryset_rtnl - try to acquire rtnl and call __bond_opt_set
382 * @bond: target bond device
383 * @option: option to set
384 * @buf: value to set it to
386 * This function tries to acquire RTNL without blocking and if successful
387 * calls __bond_opt_set. It is mainly used for sysfs option manipulation.
389 int bond_opt_tryset_rtnl(struct bonding
*bond
, unsigned int option
, char *buf
)
391 struct bond_opt_value optval
;
395 return restart_syscall();
396 bond_opt_initstr(&optval
, buf
);
397 ret
= __bond_opt_set(bond
, option
, &optval
);
404 * bond_opt_get - get a pointer to an option
405 * @option: option for which to return a pointer
407 * This function checks if option is valid and if so returns a pointer
408 * to its entry in the bond_opts[] option array.
410 struct bond_option
*bond_opt_get(unsigned int option
)
412 if (!BOND_OPT_VALID(option
))
415 return &bond_opts
[option
];
418 int bond_option_mode_set(struct bonding
*bond
, struct bond_opt_value
*newval
)
420 if (BOND_NO_USES_ARP(newval
->value
) && bond
->params
.arp_interval
) {
421 pr_info("%s: %s mode is incompatible with arp monitoring, start mii monitoring\n",
422 bond
->dev
->name
, newval
->string
);
423 /* disable arp monitoring */
424 bond
->params
.arp_interval
= 0;
425 /* set miimon to default value */
426 bond
->params
.miimon
= BOND_DEFAULT_MIIMON
;
427 pr_info("%s: Setting MII monitoring interval to %d.\n",
428 bond
->dev
->name
, bond
->params
.miimon
);
431 /* don't cache arp_validate between modes */
432 bond
->params
.arp_validate
= BOND_ARP_VALIDATE_NONE
;
433 bond
->params
.mode
= newval
->value
;
438 static struct net_device
*__bond_option_active_slave_get(struct bonding
*bond
,
441 return USES_PRIMARY(bond
->params
.mode
) && slave
? slave
->dev
: NULL
;
444 struct net_device
*bond_option_active_slave_get_rcu(struct bonding
*bond
)
446 struct slave
*slave
= rcu_dereference(bond
->curr_active_slave
);
448 return __bond_option_active_slave_get(bond
, slave
);
451 struct net_device
*bond_option_active_slave_get(struct bonding
*bond
)
453 return __bond_option_active_slave_get(bond
, bond
->curr_active_slave
);
456 int bond_option_active_slave_set(struct bonding
*bond
,
457 struct net_device
*slave_dev
)
462 if (!netif_is_bond_slave(slave_dev
)) {
463 pr_err("Device %s is not bonding slave.\n",
468 if (bond
->dev
!= netdev_master_upper_dev_get(slave_dev
)) {
469 pr_err("%s: Device %s is not our slave.\n",
470 bond
->dev
->name
, slave_dev
->name
);
475 if (!USES_PRIMARY(bond
->params
.mode
)) {
476 pr_err("%s: Unable to change active slave; %s is in mode %d\n",
477 bond
->dev
->name
, bond
->dev
->name
, bond
->params
.mode
);
482 write_lock_bh(&bond
->curr_slave_lock
);
484 /* check to see if we are clearing active */
486 pr_info("%s: Clearing current active slave.\n",
488 rcu_assign_pointer(bond
->curr_active_slave
, NULL
);
489 bond_select_active_slave(bond
);
491 struct slave
*old_active
= bond
->curr_active_slave
;
492 struct slave
*new_active
= bond_slave_get_rtnl(slave_dev
);
496 if (new_active
== old_active
) {
498 pr_info("%s: %s is already the current active slave.\n",
499 bond
->dev
->name
, new_active
->dev
->name
);
501 if (old_active
&& (new_active
->link
== BOND_LINK_UP
) &&
502 IS_UP(new_active
->dev
)) {
503 pr_info("%s: Setting %s as active slave.\n",
504 bond
->dev
->name
, new_active
->dev
->name
);
505 bond_change_active_slave(bond
, new_active
);
507 pr_err("%s: Could not set %s as active slave; either %s is down or the link is down.\n",
508 bond
->dev
->name
, new_active
->dev
->name
,
509 new_active
->dev
->name
);
515 write_unlock_bh(&bond
->curr_slave_lock
);
516 unblock_netpoll_tx();
520 int bond_option_miimon_set(struct bonding
*bond
, int miimon
)
523 pr_err("%s: Invalid miimon value %d not in range %d-%d; rejected.\n",
524 bond
->dev
->name
, miimon
, 0, INT_MAX
);
527 pr_info("%s: Setting MII monitoring interval to %d.\n",
528 bond
->dev
->name
, miimon
);
529 bond
->params
.miimon
= miimon
;
530 if (bond
->params
.updelay
)
531 pr_info("%s: Note: Updating updelay (to %d) since it is a multiple of the miimon value.\n",
533 bond
->params
.updelay
* bond
->params
.miimon
);
534 if (bond
->params
.downdelay
)
535 pr_info("%s: Note: Updating downdelay (to %d) since it is a multiple of the miimon value.\n",
537 bond
->params
.downdelay
* bond
->params
.miimon
);
538 if (miimon
&& bond
->params
.arp_interval
) {
539 pr_info("%s: MII monitoring cannot be used with ARP monitoring. Disabling ARP monitoring...\n",
541 bond
->params
.arp_interval
= 0;
542 if (bond
->params
.arp_validate
)
543 bond
->params
.arp_validate
= BOND_ARP_VALIDATE_NONE
;
545 if (bond
->dev
->flags
& IFF_UP
) {
546 /* If the interface is up, we may need to fire off
547 * the MII timer. If the interface is down, the
548 * timer will get fired off when the open function
552 cancel_delayed_work_sync(&bond
->mii_work
);
554 cancel_delayed_work_sync(&bond
->arp_work
);
555 queue_delayed_work(bond
->wq
, &bond
->mii_work
, 0);
561 int bond_option_updelay_set(struct bonding
*bond
, int updelay
)
563 if (!(bond
->params
.miimon
)) {
564 pr_err("%s: Unable to set up delay as MII monitoring is disabled\n",
570 pr_err("%s: Invalid up delay value %d not in range %d-%d; rejected.\n",
571 bond
->dev
->name
, updelay
, 0, INT_MAX
);
574 if ((updelay
% bond
->params
.miimon
) != 0) {
575 pr_warn("%s: Warning: up delay (%d) is not a multiple of miimon (%d), updelay rounded to %d ms\n",
576 bond
->dev
->name
, updelay
,
578 (updelay
/ bond
->params
.miimon
) *
579 bond
->params
.miimon
);
581 bond
->params
.updelay
= updelay
/ bond
->params
.miimon
;
582 pr_info("%s: Setting up delay to %d.\n",
584 bond
->params
.updelay
* bond
->params
.miimon
);
590 int bond_option_downdelay_set(struct bonding
*bond
,
591 struct bond_opt_value
*newval
)
593 if (!bond
->params
.miimon
) {
594 pr_err("%s: Unable to set down delay as MII monitoring is disabled\n",
598 if ((newval
->value
% bond
->params
.miimon
) != 0) {
599 pr_warn("%s: Warning: down delay (%llu) is not a multiple of miimon (%d), delay rounded to %llu ms\n",
600 bond
->dev
->name
, newval
->value
,
602 (newval
->value
/ bond
->params
.miimon
) *
603 bond
->params
.miimon
);
605 bond
->params
.downdelay
= newval
->value
/ bond
->params
.miimon
;
606 pr_info("%s: Setting down delay to %d.\n",
608 bond
->params
.downdelay
* bond
->params
.miimon
);
613 int bond_option_use_carrier_set(struct bonding
*bond
, int use_carrier
)
615 if ((use_carrier
== 0) || (use_carrier
== 1)) {
616 bond
->params
.use_carrier
= use_carrier
;
617 pr_info("%s: Setting use_carrier to %d.\n",
618 bond
->dev
->name
, use_carrier
);
620 pr_info("%s: Ignoring invalid use_carrier value %d.\n",
621 bond
->dev
->name
, use_carrier
);
627 int bond_option_arp_interval_set(struct bonding
*bond
,
628 struct bond_opt_value
*newval
)
630 pr_info("%s: Setting ARP monitoring interval to %llu.\n",
631 bond
->dev
->name
, newval
->value
);
632 bond
->params
.arp_interval
= newval
->value
;
634 if (bond
->params
.miimon
) {
635 pr_info("%s: ARP monitoring cannot be used with MII monitoring. %s Disabling MII monitoring.\n",
636 bond
->dev
->name
, bond
->dev
->name
);
637 bond
->params
.miimon
= 0;
639 if (!bond
->params
.arp_targets
[0])
640 pr_info("%s: ARP monitoring has been set up, but no ARP targets have been specified.\n",
643 if (bond
->dev
->flags
& IFF_UP
) {
644 /* If the interface is up, we may need to fire off
645 * the ARP timer. If the interface is down, the
646 * timer will get fired off when the open function
649 if (!newval
->value
) {
650 if (bond
->params
.arp_validate
)
651 bond
->recv_probe
= NULL
;
652 cancel_delayed_work_sync(&bond
->arp_work
);
654 /* arp_validate can be set only in active-backup mode */
655 if (bond
->params
.arp_validate
)
656 bond
->recv_probe
= bond_arp_rcv
;
657 cancel_delayed_work_sync(&bond
->mii_work
);
658 queue_delayed_work(bond
->wq
, &bond
->arp_work
, 0);
665 static void _bond_options_arp_ip_target_set(struct bonding
*bond
, int slot
,
667 unsigned long last_rx
)
669 __be32
*targets
= bond
->params
.arp_targets
;
670 struct list_head
*iter
;
673 if (slot
>= 0 && slot
< BOND_MAX_ARP_TARGETS
) {
674 bond_for_each_slave(bond
, slave
, iter
)
675 slave
->target_last_arp_rx
[slot
] = last_rx
;
676 targets
[slot
] = target
;
680 static int _bond_option_arp_ip_target_add(struct bonding
*bond
, __be32 target
)
682 __be32
*targets
= bond
->params
.arp_targets
;
685 if (IS_IP_TARGET_UNUSABLE_ADDRESS(target
)) {
686 pr_err("%s: invalid ARP target %pI4 specified for addition\n",
687 bond
->dev
->name
, &target
);
691 if (bond_get_targets_ip(targets
, target
) != -1) { /* dup */
692 pr_err("%s: ARP target %pI4 is already present\n",
693 bond
->dev
->name
, &target
);
697 ind
= bond_get_targets_ip(targets
, 0); /* first free slot */
699 pr_err("%s: ARP target table is full!\n",
704 pr_info("%s: adding ARP target %pI4.\n", bond
->dev
->name
, &target
);
706 _bond_options_arp_ip_target_set(bond
, ind
, target
, jiffies
);
711 int bond_option_arp_ip_target_add(struct bonding
*bond
, __be32 target
)
715 /* not to race with bond_arp_rcv */
716 write_lock_bh(&bond
->lock
);
717 ret
= _bond_option_arp_ip_target_add(bond
, target
);
718 write_unlock_bh(&bond
->lock
);
723 int bond_option_arp_ip_target_rem(struct bonding
*bond
, __be32 target
)
725 __be32
*targets
= bond
->params
.arp_targets
;
726 struct list_head
*iter
;
728 unsigned long *targets_rx
;
731 if (IS_IP_TARGET_UNUSABLE_ADDRESS(target
)) {
732 pr_err("%s: invalid ARP target %pI4 specified for removal\n",
733 bond
->dev
->name
, &target
);
737 ind
= bond_get_targets_ip(targets
, target
);
739 pr_err("%s: unable to remove nonexistent ARP target %pI4.\n",
740 bond
->dev
->name
, &target
);
744 if (ind
== 0 && !targets
[1] && bond
->params
.arp_interval
)
745 pr_warn("%s: removing last arp target with arp_interval on\n",
748 pr_info("%s: removing ARP target %pI4.\n", bond
->dev
->name
,
751 /* not to race with bond_arp_rcv */
752 write_lock_bh(&bond
->lock
);
754 bond_for_each_slave(bond
, slave
, iter
) {
755 targets_rx
= slave
->target_last_arp_rx
;
756 for (i
= ind
; (i
< BOND_MAX_ARP_TARGETS
-1) && targets
[i
+1]; i
++)
757 targets_rx
[i
] = targets_rx
[i
+1];
760 for (i
= ind
; (i
< BOND_MAX_ARP_TARGETS
-1) && targets
[i
+1]; i
++)
761 targets
[i
] = targets
[i
+1];
764 write_unlock_bh(&bond
->lock
);
769 void bond_option_arp_ip_targets_clear(struct bonding
*bond
)
773 /* not to race with bond_arp_rcv */
774 write_lock_bh(&bond
->lock
);
775 for (i
= 0; i
< BOND_MAX_ARP_TARGETS
; i
++)
776 _bond_options_arp_ip_target_set(bond
, i
, 0, 0);
777 write_unlock_bh(&bond
->lock
);
780 int bond_option_arp_ip_targets_set(struct bonding
*bond
,
781 struct bond_opt_value
*newval
)
786 if (newval
->string
) {
787 if (!in4_pton(newval
->string
+1, -1, (u8
*)&target
, -1, NULL
)) {
788 pr_err("%s: invalid ARP target %pI4 specified\n",
789 bond
->dev
->name
, &target
);
792 if (newval
->string
[0] == '+')
793 ret
= bond_option_arp_ip_target_add(bond
, target
);
794 else if (newval
->string
[0] == '-')
795 ret
= bond_option_arp_ip_target_rem(bond
, target
);
797 pr_err("no command found in arp_ip_targets file for bond %s. Use +<addr> or -<addr>.\n",
800 target
= newval
->value
;
801 ret
= bond_option_arp_ip_target_add(bond
, target
);
807 int bond_option_arp_validate_set(struct bonding
*bond
,
808 struct bond_opt_value
*newval
)
810 pr_info("%s: setting arp_validate to %s (%llu).\n",
811 bond
->dev
->name
, newval
->string
, newval
->value
);
813 if (bond
->dev
->flags
& IFF_UP
) {
815 bond
->recv_probe
= NULL
;
816 else if (bond
->params
.arp_interval
)
817 bond
->recv_probe
= bond_arp_rcv
;
819 bond
->params
.arp_validate
= newval
->value
;
824 int bond_option_arp_all_targets_set(struct bonding
*bond
,
825 struct bond_opt_value
*newval
)
827 pr_info("%s: setting arp_all_targets to %s (%llu).\n",
828 bond
->dev
->name
, newval
->string
, newval
->value
);
829 bond
->params
.arp_all_targets
= newval
->value
;
834 int bond_option_primary_set(struct bonding
*bond
, const char *primary
)
836 struct list_head
*iter
;
841 read_lock(&bond
->lock
);
842 write_lock_bh(&bond
->curr_slave_lock
);
844 if (!USES_PRIMARY(bond
->params
.mode
)) {
845 pr_err("%s: Unable to set primary slave; %s is in mode %d\n",
846 bond
->dev
->name
, bond
->dev
->name
, bond
->params
.mode
);
851 /* check to see if we are clearing primary */
852 if (!strlen(primary
)) {
853 pr_info("%s: Setting primary slave to None.\n",
855 bond
->primary_slave
= NULL
;
856 memset(bond
->params
.primary
, 0, sizeof(bond
->params
.primary
));
857 bond_select_active_slave(bond
);
861 bond_for_each_slave(bond
, slave
, iter
) {
862 if (strncmp(slave
->dev
->name
, primary
, IFNAMSIZ
) == 0) {
863 pr_info("%s: Setting %s as primary slave.\n",
864 bond
->dev
->name
, slave
->dev
->name
);
865 bond
->primary_slave
= slave
;
866 strcpy(bond
->params
.primary
, slave
->dev
->name
);
867 bond_select_active_slave(bond
);
872 strncpy(bond
->params
.primary
, primary
, IFNAMSIZ
);
873 bond
->params
.primary
[IFNAMSIZ
- 1] = 0;
875 pr_info("%s: Recording %s as primary, but it has not been enslaved to %s yet.\n",
876 bond
->dev
->name
, primary
, bond
->dev
->name
);
879 write_unlock_bh(&bond
->curr_slave_lock
);
880 read_unlock(&bond
->lock
);
881 unblock_netpoll_tx();
886 int bond_option_primary_reselect_set(struct bonding
*bond
, int primary_reselect
)
888 if (bond_parm_tbl_lookup(primary_reselect
, pri_reselect_tbl
) < 0) {
889 pr_err("%s: Ignoring invalid primary_reselect value %d.\n",
890 bond
->dev
->name
, primary_reselect
);
894 bond
->params
.primary_reselect
= primary_reselect
;
895 pr_info("%s: setting primary_reselect to %s (%d).\n",
896 bond
->dev
->name
, pri_reselect_tbl
[primary_reselect
].modename
,
900 write_lock_bh(&bond
->curr_slave_lock
);
901 bond_select_active_slave(bond
);
902 write_unlock_bh(&bond
->curr_slave_lock
);
903 unblock_netpoll_tx();
908 int bond_option_fail_over_mac_set(struct bonding
*bond
,
909 struct bond_opt_value
*newval
)
911 pr_info("%s: Setting fail_over_mac to %s (%llu).\n",
912 bond
->dev
->name
, newval
->string
, newval
->value
);
913 bond
->params
.fail_over_mac
= newval
->value
;
918 int bond_option_xmit_hash_policy_set(struct bonding
*bond
,
919 struct bond_opt_value
*newval
)
921 pr_info("%s: setting xmit hash policy to %s (%llu).\n",
922 bond
->dev
->name
, newval
->string
, newval
->value
);
923 bond
->params
.xmit_policy
= newval
->value
;
928 int bond_option_resend_igmp_set(struct bonding
*bond
, int resend_igmp
)
930 if (resend_igmp
< 0 || resend_igmp
> 255) {
931 pr_err("%s: Invalid resend_igmp value %d not in range 0-255; rejected.\n",
932 bond
->dev
->name
, resend_igmp
);
936 bond
->params
.resend_igmp
= resend_igmp
;
937 pr_info("%s: Setting resend_igmp to %d.\n",
938 bond
->dev
->name
, resend_igmp
);
943 int bond_option_num_peer_notif_set(struct bonding
*bond
, int num_peer_notif
)
945 bond
->params
.num_peer_notif
= num_peer_notif
;
949 int bond_option_all_slaves_active_set(struct bonding
*bond
,
950 int all_slaves_active
)
952 struct list_head
*iter
;
955 if (all_slaves_active
== bond
->params
.all_slaves_active
)
958 if ((all_slaves_active
== 0) || (all_slaves_active
== 1)) {
959 bond
->params
.all_slaves_active
= all_slaves_active
;
961 pr_info("%s: Ignoring invalid all_slaves_active value %d.\n",
962 bond
->dev
->name
, all_slaves_active
);
966 bond_for_each_slave(bond
, slave
, iter
) {
967 if (!bond_is_active_slave(slave
)) {
968 if (all_slaves_active
)
978 int bond_option_min_links_set(struct bonding
*bond
, int min_links
)
980 pr_info("%s: Setting min links value to %u\n",
981 bond
->dev
->name
, min_links
);
982 bond
->params
.min_links
= min_links
;
987 int bond_option_lp_interval_set(struct bonding
*bond
, int lp_interval
)
989 if (lp_interval
<= 0) {
990 pr_err("%s: lp_interval must be between 1 and %d\n",
991 bond
->dev
->name
, INT_MAX
);
995 bond
->params
.lp_interval
= lp_interval
;
1000 int bond_option_pps_set(struct bonding
*bond
, struct bond_opt_value
*newval
)
1002 bond
->params
.packets_per_slave
= newval
->value
;
1003 if (newval
->value
> 0) {
1004 bond
->params
.reciprocal_packets_per_slave
=
1005 reciprocal_value(newval
->value
);
1007 /* reciprocal_packets_per_slave is unused if
1008 * packets_per_slave is 0 or 1, just initialize it
1010 bond
->params
.reciprocal_packets_per_slave
=
1011 (struct reciprocal_value
) { 0 };
1017 int bond_option_lacp_rate_set(struct bonding
*bond
, int lacp_rate
)
1019 if (bond_parm_tbl_lookup(lacp_rate
, bond_lacp_tbl
) < 0) {
1020 pr_err("%s: Ignoring invalid LACP rate value %d.\n",
1021 bond
->dev
->name
, lacp_rate
);
1025 if (bond
->dev
->flags
& IFF_UP
) {
1026 pr_err("%s: Unable to update LACP rate because interface is up.\n",
1031 if (bond
->params
.mode
!= BOND_MODE_8023AD
) {
1032 pr_err("%s: Unable to update LACP rate because bond is not in 802.3ad mode.\n",
1037 bond
->params
.lacp_fast
= lacp_rate
;
1038 bond_3ad_update_lacp_rate(bond
);
1039 pr_info("%s: Setting LACP rate to %s (%d).\n",
1040 bond
->dev
->name
, bond_lacp_tbl
[lacp_rate
].modename
,
1046 int bond_option_ad_select_set(struct bonding
*bond
, int ad_select
)
1048 if (bond_parm_tbl_lookup(ad_select
, ad_select_tbl
) < 0) {
1049 pr_err("%s: Ignoring invalid ad_select value %d.\n",
1050 bond
->dev
->name
, ad_select
);
1054 if (bond
->dev
->flags
& IFF_UP
) {
1055 pr_err("%s: Unable to update ad_select because interface is up.\n",
1060 bond
->params
.ad_select
= ad_select
;
1061 pr_info("%s: Setting ad_select to %s (%d).\n",
1062 bond
->dev
->name
, ad_select_tbl
[ad_select
].modename
,