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_opt_value bond_lacp_rate_tbl
[] = {
76 { "slow", AD_LACP_SLOW
, 0},
77 { "fast", AD_LACP_FAST
, 0},
81 static struct bond_opt_value bond_ad_select_tbl
[] = {
82 { "stable", BOND_AD_STABLE
, BOND_VALFLAG_DEFAULT
},
83 { "bandwidth", BOND_AD_BANDWIDTH
, 0},
84 { "count", BOND_AD_COUNT
, 0},
88 static struct bond_opt_value bond_num_peer_notif_tbl
[] = {
90 { "maxval", 255, BOND_VALFLAG_MAX
},
91 { "default", 1, BOND_VALFLAG_DEFAULT
},
95 static struct bond_opt_value bond_primary_reselect_tbl
[] = {
96 { "always", BOND_PRI_RESELECT_ALWAYS
, BOND_VALFLAG_DEFAULT
},
97 { "better", BOND_PRI_RESELECT_BETTER
, 0},
98 { "failure", BOND_PRI_RESELECT_FAILURE
, 0},
102 static struct bond_opt_value bond_use_carrier_tbl
[] = {
104 { "on", 1, BOND_VALFLAG_DEFAULT
},
108 static struct bond_opt_value bond_all_slaves_active_tbl
[] = {
109 { "off", 0, BOND_VALFLAG_DEFAULT
},
114 static struct bond_opt_value bond_resend_igmp_tbl
[] = {
116 { "maxval", 255, BOND_VALFLAG_MAX
},
117 { "default", 1, BOND_VALFLAG_DEFAULT
},
121 static struct bond_opt_value bond_lp_interval_tbl
[] = {
122 { "minval", 1, BOND_VALFLAG_MIN
| BOND_VALFLAG_DEFAULT
},
123 { "maxval", INT_MAX
, BOND_VALFLAG_MAX
},
126 static struct bond_option bond_opts
[] = {
130 .desc
= "bond device mode",
131 .flags
= BOND_OPTFLAG_NOSLAVES
| BOND_OPTFLAG_IFDOWN
,
132 .values
= bond_mode_tbl
,
133 .set
= bond_option_mode_set
135 [BOND_OPT_PACKETS_PER_SLAVE
] = {
136 .id
= BOND_OPT_PACKETS_PER_SLAVE
,
137 .name
= "packets_per_slave",
138 .desc
= "Packets to send per slave in RR mode",
139 .unsuppmodes
= BOND_MODE_ALL_EX(BIT(BOND_MODE_ROUNDROBIN
)),
140 .values
= bond_pps_tbl
,
141 .set
= bond_option_pps_set
143 [BOND_OPT_XMIT_HASH
] = {
144 .id
= BOND_OPT_XMIT_HASH
,
145 .name
= "xmit_hash_policy",
146 .desc
= "balance-xor and 802.3ad hashing method",
147 .values
= bond_xmit_hashtype_tbl
,
148 .set
= bond_option_xmit_hash_policy_set
150 [BOND_OPT_ARP_VALIDATE
] = {
151 .id
= BOND_OPT_ARP_VALIDATE
,
152 .name
= "arp_validate",
153 .desc
= "validate src/dst of ARP probes",
154 .unsuppmodes
= BOND_MODE_ALL_EX(BIT(BOND_MODE_ACTIVEBACKUP
)),
155 .values
= bond_arp_validate_tbl
,
156 .set
= bond_option_arp_validate_set
158 [BOND_OPT_ARP_ALL_TARGETS
] = {
159 .id
= BOND_OPT_ARP_ALL_TARGETS
,
160 .name
= "arp_all_targets",
161 .desc
= "fail on any/all arp targets timeout",
162 .values
= bond_arp_all_targets_tbl
,
163 .set
= bond_option_arp_all_targets_set
165 [BOND_OPT_FAIL_OVER_MAC
] = {
166 .id
= BOND_OPT_FAIL_OVER_MAC
,
167 .name
= "fail_over_mac",
168 .desc
= "For active-backup, do not set all slaves to the same MAC",
169 .flags
= BOND_OPTFLAG_NOSLAVES
,
170 .values
= bond_fail_over_mac_tbl
,
171 .set
= bond_option_fail_over_mac_set
173 [BOND_OPT_ARP_INTERVAL
] = {
174 .id
= BOND_OPT_ARP_INTERVAL
,
175 .name
= "arp_interval",
176 .desc
= "arp interval in milliseconds",
177 .unsuppmodes
= BIT(BOND_MODE_8023AD
) | BIT(BOND_MODE_TLB
) |
179 .values
= bond_intmax_tbl
,
180 .set
= bond_option_arp_interval_set
182 [BOND_OPT_ARP_TARGETS
] = {
183 .id
= BOND_OPT_ARP_TARGETS
,
184 .name
= "arp_ip_target",
185 .desc
= "arp targets in n.n.n.n form",
186 .flags
= BOND_OPTFLAG_RAWVAL
,
187 .set
= bond_option_arp_ip_targets_set
189 [BOND_OPT_DOWNDELAY
] = {
190 .id
= BOND_OPT_DOWNDELAY
,
192 .desc
= "Delay before considering link down, in milliseconds",
193 .values
= bond_intmax_tbl
,
194 .set
= bond_option_downdelay_set
196 [BOND_OPT_UPDELAY
] = {
197 .id
= BOND_OPT_UPDELAY
,
199 .desc
= "Delay before considering link up, in milliseconds",
200 .values
= bond_intmax_tbl
,
201 .set
= bond_option_updelay_set
203 [BOND_OPT_LACP_RATE
] = {
204 .id
= BOND_OPT_LACP_RATE
,
206 .desc
= "LACPDU tx rate to request from 802.3ad partner",
207 .flags
= BOND_OPTFLAG_IFDOWN
,
208 .unsuppmodes
= BOND_MODE_ALL_EX(BIT(BOND_MODE_8023AD
)),
209 .values
= bond_lacp_rate_tbl
,
210 .set
= bond_option_lacp_rate_set
212 [BOND_OPT_MINLINKS
] = {
213 .id
= BOND_OPT_MINLINKS
,
215 .desc
= "Minimum number of available links before turning on carrier",
216 .values
= bond_intmax_tbl
,
217 .set
= bond_option_min_links_set
219 [BOND_OPT_AD_SELECT
] = {
220 .id
= BOND_OPT_AD_SELECT
,
222 .desc
= "803.ad aggregation selection logic",
223 .flags
= BOND_OPTFLAG_IFDOWN
,
224 .values
= bond_ad_select_tbl
,
225 .set
= bond_option_ad_select_set
227 [BOND_OPT_NUM_PEER_NOTIF
] = {
228 .id
= BOND_OPT_NUM_PEER_NOTIF
,
229 .name
= "num_unsol_na",
230 .desc
= "Number of peer notifications to send on failover event",
231 .values
= bond_num_peer_notif_tbl
,
232 .set
= bond_option_num_peer_notif_set
234 [BOND_OPT_MIIMON
] = {
235 .id
= BOND_OPT_MIIMON
,
237 .desc
= "Link check interval in milliseconds",
238 .values
= bond_intmax_tbl
,
239 .set
= bond_option_miimon_set
241 [BOND_OPT_PRIMARY
] = {
242 .id
= BOND_OPT_PRIMARY
,
244 .desc
= "Primary network device to use",
245 .flags
= BOND_OPTFLAG_RAWVAL
,
246 .unsuppmodes
= BOND_MODE_ALL_EX(BIT(BOND_MODE_ACTIVEBACKUP
) |
249 .set
= bond_option_primary_set
251 [BOND_OPT_PRIMARY_RESELECT
] = {
252 .id
= BOND_OPT_PRIMARY_RESELECT
,
253 .name
= "primary_reselect",
254 .desc
= "Reselect primary slave once it comes up",
255 .values
= bond_primary_reselect_tbl
,
256 .set
= bond_option_primary_reselect_set
258 [BOND_OPT_USE_CARRIER
] = {
259 .id
= BOND_OPT_USE_CARRIER
,
260 .name
= "use_carrier",
261 .desc
= "Use netif_carrier_ok (vs MII ioctls) in miimon",
262 .values
= bond_use_carrier_tbl
,
263 .set
= bond_option_use_carrier_set
265 [BOND_OPT_ACTIVE_SLAVE
] = {
266 .id
= BOND_OPT_ACTIVE_SLAVE
,
267 .name
= "active_slave",
268 .desc
= "Currently active slave",
269 .flags
= BOND_OPTFLAG_RAWVAL
,
270 .unsuppmodes
= BOND_MODE_ALL_EX(BIT(BOND_MODE_ACTIVEBACKUP
) |
273 .set
= bond_option_active_slave_set
275 [BOND_OPT_QUEUE_ID
] = {
276 .id
= BOND_OPT_QUEUE_ID
,
278 .desc
= "Set queue id of a slave",
279 .flags
= BOND_OPTFLAG_RAWVAL
,
280 .set
= bond_option_queue_id_set
282 [BOND_OPT_ALL_SLAVES_ACTIVE
] = {
283 .id
= BOND_OPT_ALL_SLAVES_ACTIVE
,
284 .name
= "all_slaves_active",
285 .desc
= "Keep all frames received on an interface by setting active flag for all slaves",
286 .values
= bond_all_slaves_active_tbl
,
287 .set
= bond_option_all_slaves_active_set
289 [BOND_OPT_RESEND_IGMP
] = {
290 .id
= BOND_OPT_RESEND_IGMP
,
291 .name
= "resend_igmp",
292 .desc
= "Number of IGMP membership reports to send on link failure",
293 .values
= bond_resend_igmp_tbl
,
294 .set
= bond_option_resend_igmp_set
296 [BOND_OPT_LP_INTERVAL
] = {
297 .id
= BOND_OPT_LP_INTERVAL
,
298 .name
= "lp_interval",
299 .desc
= "The number of seconds between instances where the bonding driver sends learning packets to each slave's peer switch",
300 .values
= bond_lp_interval_tbl
,
301 .set
= bond_option_lp_interval_set
306 /* Searches for a value in opt's values[] table */
307 struct bond_opt_value
*bond_opt_get_val(unsigned int option
, u64 val
)
309 struct bond_option
*opt
;
312 opt
= bond_opt_get(option
);
315 for (i
= 0; opt
->values
&& opt
->values
[i
].string
; i
++)
316 if (opt
->values
[i
].value
== val
)
317 return &opt
->values
[i
];
322 /* Searches for a value in opt's values[] table which matches the flagmask */
323 static struct bond_opt_value
*bond_opt_get_flags(const struct bond_option
*opt
,
328 for (i
= 0; opt
->values
&& opt
->values
[i
].string
; i
++)
329 if (opt
->values
[i
].flags
& flagmask
)
330 return &opt
->values
[i
];
335 /* If maxval is missing then there's no range to check. In case minval is
336 * missing then it's considered to be 0.
338 static bool bond_opt_check_range(const struct bond_option
*opt
, u64 val
)
340 struct bond_opt_value
*minval
, *maxval
;
342 minval
= bond_opt_get_flags(opt
, BOND_VALFLAG_MIN
);
343 maxval
= bond_opt_get_flags(opt
, BOND_VALFLAG_MAX
);
344 if (!maxval
|| (minval
&& val
< minval
->value
) || val
> maxval
->value
)
351 * bond_opt_parse - parse option value
352 * @opt: the option to parse against
353 * @val: value to parse
355 * This function tries to extract the value from @val and check if it's
356 * a possible match for the option and returns NULL if a match isn't found,
357 * or the struct_opt_value that matched. It also strips the new line from
358 * @val->string if it's present.
360 struct bond_opt_value
*bond_opt_parse(const struct bond_option
*opt
,
361 struct bond_opt_value
*val
)
363 char *p
, valstr
[BOND_OPT_MAX_NAMELEN
+ 1] = { 0, };
364 struct bond_opt_value
*tbl
, *ret
= NULL
;
368 /* No parsing if the option wants a raw val */
369 if (opt
->flags
& BOND_OPTFLAG_RAWVAL
)
376 /* ULLONG_MAX is used to bypass string processing */
377 checkval
= val
->value
!= ULLONG_MAX
;
381 p
= strchr(val
->string
, '\n');
384 for (p
= val
->string
; *p
; p
++)
385 if (!(isdigit(*p
) || isspace(*p
)))
387 /* The following code extracts the string to match or the value
388 * and sets checkval appropriately
391 rv
= sscanf(val
->string
, "%32s", valstr
);
393 rv
= sscanf(val
->string
, "%llu", &val
->value
);
400 for (i
= 0; tbl
[i
].string
; i
++) {
401 /* Check for exact match */
403 if (val
->value
== tbl
[i
].value
)
406 if (!strcmp(valstr
, "default") &&
407 (tbl
[i
].flags
& BOND_VALFLAG_DEFAULT
))
410 if (!strcmp(valstr
, tbl
[i
].string
))
413 /* Found an exact match */
417 /* Possible range match */
418 if (checkval
&& bond_opt_check_range(opt
, val
->value
))
424 /* Check opt's dependencies against bond mode and currently set options */
425 static int bond_opt_check_deps(struct bonding
*bond
,
426 const struct bond_option
*opt
)
428 struct bond_params
*params
= &bond
->params
;
430 if (test_bit(params
->mode
, &opt
->unsuppmodes
))
432 if ((opt
->flags
& BOND_OPTFLAG_NOSLAVES
) && bond_has_slaves(bond
))
434 if ((opt
->flags
& BOND_OPTFLAG_IFDOWN
) && (bond
->dev
->flags
& IFF_UP
))
440 static void bond_opt_dep_print(struct bonding
*bond
,
441 const struct bond_option
*opt
)
443 struct bond_opt_value
*modeval
;
444 struct bond_params
*params
;
446 params
= &bond
->params
;
447 modeval
= bond_opt_get_val(BOND_OPT_MODE
, params
->mode
);
448 if (test_bit(params
->mode
, &opt
->unsuppmodes
))
449 pr_err("%s: option %s: mode dependency failed, not supported in mode %s(%llu)\n",
450 bond
->dev
->name
, opt
->name
,
451 modeval
->string
, modeval
->value
);
454 static void bond_opt_error_interpret(struct bonding
*bond
,
455 const struct bond_option
*opt
,
456 int error
, struct bond_opt_value
*val
)
458 struct bond_opt_value
*minval
, *maxval
;
465 /* sometimes RAWVAL opts may have new lines */
466 p
= strchr(val
->string
, '\n');
469 pr_err("%s: option %s: invalid value (%s).\n",
470 bond
->dev
->name
, opt
->name
, val
->string
);
472 pr_err("%s: option %s: invalid value (%llu).\n",
473 bond
->dev
->name
, opt
->name
, val
->value
);
476 minval
= bond_opt_get_flags(opt
, BOND_VALFLAG_MIN
);
477 maxval
= bond_opt_get_flags(opt
, BOND_VALFLAG_MAX
);
480 pr_err("%s: option %s: allowed values %llu - %llu.\n",
481 bond
->dev
->name
, opt
->name
, minval
? minval
->value
: 0,
485 bond_opt_dep_print(bond
, opt
);
488 pr_err("%s: option %s: unable to set because the bond device has slaves.\n",
489 bond
->dev
->name
, opt
->name
);
492 pr_err("%s: option %s: unable to set because the bond device is up.\n",
493 bond
->dev
->name
, opt
->name
);
501 * __bond_opt_set - set a bonding option
502 * @bond: target bond device
503 * @option: option to set
504 * @val: value to set it to
506 * This function is used to change the bond's option value, it can be
507 * used for both enabling/changing an option and for disabling it. RTNL lock
508 * must be obtained before calling this function.
510 int __bond_opt_set(struct bonding
*bond
,
511 unsigned int option
, struct bond_opt_value
*val
)
513 struct bond_opt_value
*retval
= NULL
;
514 const struct bond_option
*opt
;
519 opt
= bond_opt_get(option
);
520 if (WARN_ON(!val
) || WARN_ON(!opt
))
522 ret
= bond_opt_check_deps(bond
, opt
);
525 retval
= bond_opt_parse(opt
, val
);
530 ret
= opt
->set(bond
, retval
);
533 bond_opt_error_interpret(bond
, opt
, ret
, val
);
539 * bond_opt_tryset_rtnl - try to acquire rtnl and call __bond_opt_set
540 * @bond: target bond device
541 * @option: option to set
542 * @buf: value to set it to
544 * This function tries to acquire RTNL without blocking and if successful
545 * calls __bond_opt_set. It is mainly used for sysfs option manipulation.
547 int bond_opt_tryset_rtnl(struct bonding
*bond
, unsigned int option
, char *buf
)
549 struct bond_opt_value optval
;
553 return restart_syscall();
554 bond_opt_initstr(&optval
, buf
);
555 ret
= __bond_opt_set(bond
, option
, &optval
);
562 * bond_opt_get - get a pointer to an option
563 * @option: option for which to return a pointer
565 * This function checks if option is valid and if so returns a pointer
566 * to its entry in the bond_opts[] option array.
568 struct bond_option
*bond_opt_get(unsigned int option
)
570 if (!BOND_OPT_VALID(option
))
573 return &bond_opts
[option
];
576 int bond_option_mode_set(struct bonding
*bond
, struct bond_opt_value
*newval
)
578 if (BOND_NO_USES_ARP(newval
->value
) && bond
->params
.arp_interval
) {
579 pr_info("%s: %s mode is incompatible with arp monitoring, start mii monitoring\n",
580 bond
->dev
->name
, newval
->string
);
581 /* disable arp monitoring */
582 bond
->params
.arp_interval
= 0;
583 /* set miimon to default value */
584 bond
->params
.miimon
= BOND_DEFAULT_MIIMON
;
585 pr_info("%s: Setting MII monitoring interval to %d.\n",
586 bond
->dev
->name
, bond
->params
.miimon
);
589 /* don't cache arp_validate between modes */
590 bond
->params
.arp_validate
= BOND_ARP_VALIDATE_NONE
;
591 bond
->params
.mode
= newval
->value
;
596 static struct net_device
*__bond_option_active_slave_get(struct bonding
*bond
,
599 return USES_PRIMARY(bond
->params
.mode
) && slave
? slave
->dev
: NULL
;
602 struct net_device
*bond_option_active_slave_get_rcu(struct bonding
*bond
)
604 struct slave
*slave
= rcu_dereference(bond
->curr_active_slave
);
606 return __bond_option_active_slave_get(bond
, slave
);
609 struct net_device
*bond_option_active_slave_get(struct bonding
*bond
)
611 return __bond_option_active_slave_get(bond
, bond
->curr_active_slave
);
614 int bond_option_active_slave_set(struct bonding
*bond
,
615 struct bond_opt_value
*newval
)
617 char ifname
[IFNAMSIZ
] = { 0, };
618 struct net_device
*slave_dev
;
621 sscanf(newval
->string
, "%15s", ifname
); /* IFNAMSIZ */
622 if (!strlen(ifname
) || newval
->string
[0] == '\n') {
625 slave_dev
= __dev_get_by_name(dev_net(bond
->dev
), ifname
);
631 if (!netif_is_bond_slave(slave_dev
)) {
632 pr_err("Device %s is not bonding slave.\n",
637 if (bond
->dev
!= netdev_master_upper_dev_get(slave_dev
)) {
638 pr_err("%s: Device %s is not our slave.\n",
639 bond
->dev
->name
, slave_dev
->name
);
645 write_lock_bh(&bond
->curr_slave_lock
);
647 /* check to see if we are clearing active */
649 pr_info("%s: Clearing current active slave.\n",
651 rcu_assign_pointer(bond
->curr_active_slave
, NULL
);
652 bond_select_active_slave(bond
);
654 struct slave
*old_active
= bond
->curr_active_slave
;
655 struct slave
*new_active
= bond_slave_get_rtnl(slave_dev
);
659 if (new_active
== old_active
) {
661 pr_info("%s: %s is already the current active slave.\n",
662 bond
->dev
->name
, new_active
->dev
->name
);
664 if (old_active
&& (new_active
->link
== BOND_LINK_UP
) &&
665 IS_UP(new_active
->dev
)) {
666 pr_info("%s: Setting %s as active slave.\n",
667 bond
->dev
->name
, new_active
->dev
->name
);
668 bond_change_active_slave(bond
, new_active
);
670 pr_err("%s: Could not set %s as active slave; either %s is down or the link is down.\n",
671 bond
->dev
->name
, new_active
->dev
->name
,
672 new_active
->dev
->name
);
678 write_unlock_bh(&bond
->curr_slave_lock
);
679 unblock_netpoll_tx();
684 int bond_option_miimon_set(struct bonding
*bond
, struct bond_opt_value
*newval
)
686 pr_info("%s: Setting MII monitoring interval to %llu.\n",
687 bond
->dev
->name
, newval
->value
);
688 bond
->params
.miimon
= newval
->value
;
689 if (bond
->params
.updelay
)
690 pr_info("%s: Note: Updating updelay (to %d) since it is a multiple of the miimon value.\n",
692 bond
->params
.updelay
* bond
->params
.miimon
);
693 if (bond
->params
.downdelay
)
694 pr_info("%s: Note: Updating downdelay (to %d) since it is a multiple of the miimon value.\n",
696 bond
->params
.downdelay
* bond
->params
.miimon
);
697 if (newval
->value
&& bond
->params
.arp_interval
) {
698 pr_info("%s: MII monitoring cannot be used with ARP monitoring. Disabling ARP monitoring...\n",
700 bond
->params
.arp_interval
= 0;
701 if (bond
->params
.arp_validate
)
702 bond
->params
.arp_validate
= BOND_ARP_VALIDATE_NONE
;
704 if (bond
->dev
->flags
& IFF_UP
) {
705 /* If the interface is up, we may need to fire off
706 * the MII timer. If the interface is down, the
707 * timer will get fired off when the open function
710 if (!newval
->value
) {
711 cancel_delayed_work_sync(&bond
->mii_work
);
713 cancel_delayed_work_sync(&bond
->arp_work
);
714 queue_delayed_work(bond
->wq
, &bond
->mii_work
, 0);
721 int bond_option_updelay_set(struct bonding
*bond
, struct bond_opt_value
*newval
)
723 if (!bond
->params
.miimon
) {
724 pr_err("%s: Unable to set up delay as MII monitoring is disabled\n",
728 if ((newval
->value
% bond
->params
.miimon
) != 0) {
729 pr_warn("%s: Warning: up delay (%llu) is not a multiple of miimon (%d), updelay rounded to %llu ms\n",
730 bond
->dev
->name
, newval
->value
,
732 (newval
->value
/ bond
->params
.miimon
) *
733 bond
->params
.miimon
);
735 bond
->params
.updelay
= newval
->value
/ bond
->params
.miimon
;
736 pr_info("%s: Setting up delay to %d.\n",
738 bond
->params
.updelay
* bond
->params
.miimon
);
743 int bond_option_downdelay_set(struct bonding
*bond
,
744 struct bond_opt_value
*newval
)
746 if (!bond
->params
.miimon
) {
747 pr_err("%s: Unable to set down delay as MII monitoring is disabled\n",
751 if ((newval
->value
% bond
->params
.miimon
) != 0) {
752 pr_warn("%s: Warning: down delay (%llu) is not a multiple of miimon (%d), delay rounded to %llu ms\n",
753 bond
->dev
->name
, newval
->value
,
755 (newval
->value
/ bond
->params
.miimon
) *
756 bond
->params
.miimon
);
758 bond
->params
.downdelay
= newval
->value
/ bond
->params
.miimon
;
759 pr_info("%s: Setting down delay to %d.\n",
761 bond
->params
.downdelay
* bond
->params
.miimon
);
766 int bond_option_use_carrier_set(struct bonding
*bond
,
767 struct bond_opt_value
*newval
)
769 pr_info("%s: Setting use_carrier to %llu.\n",
770 bond
->dev
->name
, newval
->value
);
771 bond
->params
.use_carrier
= newval
->value
;
776 int bond_option_arp_interval_set(struct bonding
*bond
,
777 struct bond_opt_value
*newval
)
779 pr_info("%s: Setting ARP monitoring interval to %llu.\n",
780 bond
->dev
->name
, newval
->value
);
781 bond
->params
.arp_interval
= newval
->value
;
783 if (bond
->params
.miimon
) {
784 pr_info("%s: ARP monitoring cannot be used with MII monitoring. %s Disabling MII monitoring.\n",
785 bond
->dev
->name
, bond
->dev
->name
);
786 bond
->params
.miimon
= 0;
788 if (!bond
->params
.arp_targets
[0])
789 pr_info("%s: ARP monitoring has been set up, but no ARP targets have been specified.\n",
792 if (bond
->dev
->flags
& IFF_UP
) {
793 /* If the interface is up, we may need to fire off
794 * the ARP timer. If the interface is down, the
795 * timer will get fired off when the open function
798 if (!newval
->value
) {
799 if (bond
->params
.arp_validate
)
800 bond
->recv_probe
= NULL
;
801 cancel_delayed_work_sync(&bond
->arp_work
);
803 /* arp_validate can be set only in active-backup mode */
804 if (bond
->params
.arp_validate
)
805 bond
->recv_probe
= bond_arp_rcv
;
806 cancel_delayed_work_sync(&bond
->mii_work
);
807 queue_delayed_work(bond
->wq
, &bond
->arp_work
, 0);
814 static void _bond_options_arp_ip_target_set(struct bonding
*bond
, int slot
,
816 unsigned long last_rx
)
818 __be32
*targets
= bond
->params
.arp_targets
;
819 struct list_head
*iter
;
822 if (slot
>= 0 && slot
< BOND_MAX_ARP_TARGETS
) {
823 bond_for_each_slave(bond
, slave
, iter
)
824 slave
->target_last_arp_rx
[slot
] = last_rx
;
825 targets
[slot
] = target
;
829 static int _bond_option_arp_ip_target_add(struct bonding
*bond
, __be32 target
)
831 __be32
*targets
= bond
->params
.arp_targets
;
834 if (IS_IP_TARGET_UNUSABLE_ADDRESS(target
)) {
835 pr_err("%s: invalid ARP target %pI4 specified for addition\n",
836 bond
->dev
->name
, &target
);
840 if (bond_get_targets_ip(targets
, target
) != -1) { /* dup */
841 pr_err("%s: ARP target %pI4 is already present\n",
842 bond
->dev
->name
, &target
);
846 ind
= bond_get_targets_ip(targets
, 0); /* first free slot */
848 pr_err("%s: ARP target table is full!\n",
853 pr_info("%s: adding ARP target %pI4.\n", bond
->dev
->name
, &target
);
855 _bond_options_arp_ip_target_set(bond
, ind
, target
, jiffies
);
860 int bond_option_arp_ip_target_add(struct bonding
*bond
, __be32 target
)
864 /* not to race with bond_arp_rcv */
865 write_lock_bh(&bond
->lock
);
866 ret
= _bond_option_arp_ip_target_add(bond
, target
);
867 write_unlock_bh(&bond
->lock
);
872 int bond_option_arp_ip_target_rem(struct bonding
*bond
, __be32 target
)
874 __be32
*targets
= bond
->params
.arp_targets
;
875 struct list_head
*iter
;
877 unsigned long *targets_rx
;
880 if (IS_IP_TARGET_UNUSABLE_ADDRESS(target
)) {
881 pr_err("%s: invalid ARP target %pI4 specified for removal\n",
882 bond
->dev
->name
, &target
);
886 ind
= bond_get_targets_ip(targets
, target
);
888 pr_err("%s: unable to remove nonexistent ARP target %pI4.\n",
889 bond
->dev
->name
, &target
);
893 if (ind
== 0 && !targets
[1] && bond
->params
.arp_interval
)
894 pr_warn("%s: removing last arp target with arp_interval on\n",
897 pr_info("%s: removing ARP target %pI4.\n", bond
->dev
->name
,
900 /* not to race with bond_arp_rcv */
901 write_lock_bh(&bond
->lock
);
903 bond_for_each_slave(bond
, slave
, iter
) {
904 targets_rx
= slave
->target_last_arp_rx
;
905 for (i
= ind
; (i
< BOND_MAX_ARP_TARGETS
-1) && targets
[i
+1]; i
++)
906 targets_rx
[i
] = targets_rx
[i
+1];
909 for (i
= ind
; (i
< BOND_MAX_ARP_TARGETS
-1) && targets
[i
+1]; i
++)
910 targets
[i
] = targets
[i
+1];
913 write_unlock_bh(&bond
->lock
);
918 void bond_option_arp_ip_targets_clear(struct bonding
*bond
)
922 /* not to race with bond_arp_rcv */
923 write_lock_bh(&bond
->lock
);
924 for (i
= 0; i
< BOND_MAX_ARP_TARGETS
; i
++)
925 _bond_options_arp_ip_target_set(bond
, i
, 0, 0);
926 write_unlock_bh(&bond
->lock
);
929 int bond_option_arp_ip_targets_set(struct bonding
*bond
,
930 struct bond_opt_value
*newval
)
935 if (newval
->string
) {
936 if (!in4_pton(newval
->string
+1, -1, (u8
*)&target
, -1, NULL
)) {
937 pr_err("%s: invalid ARP target %pI4 specified\n",
938 bond
->dev
->name
, &target
);
941 if (newval
->string
[0] == '+')
942 ret
= bond_option_arp_ip_target_add(bond
, target
);
943 else if (newval
->string
[0] == '-')
944 ret
= bond_option_arp_ip_target_rem(bond
, target
);
946 pr_err("no command found in arp_ip_targets file for bond %s. Use +<addr> or -<addr>.\n",
949 target
= newval
->value
;
950 ret
= bond_option_arp_ip_target_add(bond
, target
);
956 int bond_option_arp_validate_set(struct bonding
*bond
,
957 struct bond_opt_value
*newval
)
959 pr_info("%s: setting arp_validate to %s (%llu).\n",
960 bond
->dev
->name
, newval
->string
, newval
->value
);
962 if (bond
->dev
->flags
& IFF_UP
) {
964 bond
->recv_probe
= NULL
;
965 else if (bond
->params
.arp_interval
)
966 bond
->recv_probe
= bond_arp_rcv
;
968 bond
->params
.arp_validate
= newval
->value
;
973 int bond_option_arp_all_targets_set(struct bonding
*bond
,
974 struct bond_opt_value
*newval
)
976 pr_info("%s: setting arp_all_targets to %s (%llu).\n",
977 bond
->dev
->name
, newval
->string
, newval
->value
);
978 bond
->params
.arp_all_targets
= newval
->value
;
983 int bond_option_primary_set(struct bonding
*bond
, struct bond_opt_value
*newval
)
985 char *p
, *primary
= newval
->string
;
986 struct list_head
*iter
;
990 read_lock(&bond
->lock
);
991 write_lock_bh(&bond
->curr_slave_lock
);
993 p
= strchr(primary
, '\n');
996 /* check to see if we are clearing primary */
997 if (!strlen(primary
)) {
998 pr_info("%s: Setting primary slave to None.\n",
1000 bond
->primary_slave
= NULL
;
1001 memset(bond
->params
.primary
, 0, sizeof(bond
->params
.primary
));
1002 bond_select_active_slave(bond
);
1006 bond_for_each_slave(bond
, slave
, iter
) {
1007 if (strncmp(slave
->dev
->name
, primary
, IFNAMSIZ
) == 0) {
1008 pr_info("%s: Setting %s as primary slave.\n",
1009 bond
->dev
->name
, slave
->dev
->name
);
1010 bond
->primary_slave
= slave
;
1011 strcpy(bond
->params
.primary
, slave
->dev
->name
);
1012 bond_select_active_slave(bond
);
1017 strncpy(bond
->params
.primary
, primary
, IFNAMSIZ
);
1018 bond
->params
.primary
[IFNAMSIZ
- 1] = 0;
1020 pr_info("%s: Recording %s as primary, but it has not been enslaved to %s yet.\n",
1021 bond
->dev
->name
, primary
, bond
->dev
->name
);
1024 write_unlock_bh(&bond
->curr_slave_lock
);
1025 read_unlock(&bond
->lock
);
1026 unblock_netpoll_tx();
1031 int bond_option_primary_reselect_set(struct bonding
*bond
,
1032 struct bond_opt_value
*newval
)
1034 pr_info("%s: setting primary_reselect to %s (%llu).\n",
1035 bond
->dev
->name
, newval
->string
, newval
->value
);
1036 bond
->params
.primary_reselect
= newval
->value
;
1039 write_lock_bh(&bond
->curr_slave_lock
);
1040 bond_select_active_slave(bond
);
1041 write_unlock_bh(&bond
->curr_slave_lock
);
1042 unblock_netpoll_tx();
1047 int bond_option_fail_over_mac_set(struct bonding
*bond
,
1048 struct bond_opt_value
*newval
)
1050 pr_info("%s: Setting fail_over_mac to %s (%llu).\n",
1051 bond
->dev
->name
, newval
->string
, newval
->value
);
1052 bond
->params
.fail_over_mac
= newval
->value
;
1057 int bond_option_xmit_hash_policy_set(struct bonding
*bond
,
1058 struct bond_opt_value
*newval
)
1060 pr_info("%s: setting xmit hash policy to %s (%llu).\n",
1061 bond
->dev
->name
, newval
->string
, newval
->value
);
1062 bond
->params
.xmit_policy
= newval
->value
;
1067 int bond_option_resend_igmp_set(struct bonding
*bond
,
1068 struct bond_opt_value
*newval
)
1070 pr_info("%s: Setting resend_igmp to %llu.\n",
1071 bond
->dev
->name
, newval
->value
);
1072 bond
->params
.resend_igmp
= newval
->value
;
1077 int bond_option_num_peer_notif_set(struct bonding
*bond
,
1078 struct bond_opt_value
*newval
)
1080 bond
->params
.num_peer_notif
= newval
->value
;
1085 int bond_option_all_slaves_active_set(struct bonding
*bond
,
1086 struct bond_opt_value
*newval
)
1088 struct list_head
*iter
;
1089 struct slave
*slave
;
1091 if (newval
->value
== bond
->params
.all_slaves_active
)
1093 bond
->params
.all_slaves_active
= newval
->value
;
1094 bond_for_each_slave(bond
, slave
, iter
) {
1095 if (!bond_is_active_slave(slave
)) {
1097 slave
->inactive
= 0;
1099 slave
->inactive
= 1;
1106 int bond_option_min_links_set(struct bonding
*bond
,
1107 struct bond_opt_value
*newval
)
1109 pr_info("%s: Setting min links value to %llu\n",
1110 bond
->dev
->name
, newval
->value
);
1111 bond
->params
.min_links
= newval
->value
;
1116 int bond_option_lp_interval_set(struct bonding
*bond
,
1117 struct bond_opt_value
*newval
)
1119 bond
->params
.lp_interval
= newval
->value
;
1124 int bond_option_pps_set(struct bonding
*bond
, struct bond_opt_value
*newval
)
1126 bond
->params
.packets_per_slave
= newval
->value
;
1127 if (newval
->value
> 0) {
1128 bond
->params
.reciprocal_packets_per_slave
=
1129 reciprocal_value(newval
->value
);
1131 /* reciprocal_packets_per_slave is unused if
1132 * packets_per_slave is 0 or 1, just initialize it
1134 bond
->params
.reciprocal_packets_per_slave
=
1135 (struct reciprocal_value
) { 0 };
1141 int bond_option_lacp_rate_set(struct bonding
*bond
,
1142 struct bond_opt_value
*newval
)
1144 pr_info("%s: Setting LACP rate to %s (%llu).\n",
1145 bond
->dev
->name
, newval
->string
, newval
->value
);
1146 bond
->params
.lacp_fast
= newval
->value
;
1147 bond_3ad_update_lacp_rate(bond
);
1152 int bond_option_ad_select_set(struct bonding
*bond
,
1153 struct bond_opt_value
*newval
)
1155 pr_info("%s: Setting ad_select to %s (%llu).\n",
1156 bond
->dev
->name
, newval
->string
, newval
->value
);
1157 bond
->params
.ad_select
= newval
->value
;
1162 int bond_option_queue_id_set(struct bonding
*bond
,
1163 struct bond_opt_value
*newval
)
1165 struct slave
*slave
, *update_slave
;
1166 struct net_device
*sdev
;
1167 struct list_head
*iter
;
1172 /* delim will point to queue id if successful */
1173 delim
= strchr(newval
->string
, ':');
1177 /* Terminate string that points to device name and bump it
1178 * up one, so we can read the queue id there.
1181 if (sscanf(++delim
, "%hd\n", &qid
) != 1)
1184 /* Check buffer length, valid ifname and queue id */
1185 if (strlen(newval
->string
) > IFNAMSIZ
||
1186 !dev_valid_name(newval
->string
) ||
1187 qid
> bond
->dev
->real_num_tx_queues
)
1190 /* Get the pointer to that interface if it exists */
1191 sdev
= __dev_get_by_name(dev_net(bond
->dev
), newval
->string
);
1195 /* Search for thes slave and check for duplicate qids */
1196 update_slave
= NULL
;
1197 bond_for_each_slave(bond
, slave
, iter
) {
1198 if (sdev
== slave
->dev
)
1199 /* We don't need to check the matching
1200 * slave for dups, since we're overwriting it
1202 update_slave
= slave
;
1203 else if (qid
&& qid
== slave
->queue_id
) {
1211 /* Actually set the qids for the slave */
1212 update_slave
->queue_id
= qid
;
1218 pr_info("invalid input for queue_id set for %s.\n",