]>
Commit | Line | Data |
---|---|---|
72be35fe JP |
1 | /* |
2 | * drivers/net/bond/bond_options.c - bonding options | |
3 | * Copyright (c) 2013 Jiri Pirko <jiri@resnulli.us> | |
eecdaa6e | 4 | * Copyright (c) 2013 Scott Feldman <sfeldma@cumulusnetworks.com> |
72be35fe JP |
5 | * |
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. | |
10 | */ | |
11 | ||
12 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | |
13 | ||
14 | #include <linux/errno.h> | |
15 | #include <linux/if.h> | |
d9e32b21 JP |
16 | #include <linux/netdevice.h> |
17 | #include <linux/rwlock.h> | |
18 | #include <linux/rcupdate.h> | |
c13ab3ff | 19 | #include <linux/reciprocal_div.h> |
72be35fe JP |
20 | #include "bonding.h" |
21 | ||
72be35fe JP |
22 | int bond_option_mode_set(struct bonding *bond, int mode) |
23 | { | |
3243c47b | 24 | if (bond_parm_tbl_lookup(mode, bond_mode_tbl) < 0) { |
25 | pr_err("%s: Ignoring invalid mode value %d.\n", | |
26 | bond->dev->name, mode); | |
72be35fe JP |
27 | return -EINVAL; |
28 | } | |
29 | ||
30 | if (bond->dev->flags & IFF_UP) { | |
31 | pr_err("%s: unable to update mode because interface is up.\n", | |
32 | bond->dev->name); | |
33 | return -EPERM; | |
34 | } | |
35 | ||
36 | if (bond_has_slaves(bond)) { | |
37 | pr_err("%s: unable to update mode because bond has slaves.\n", | |
38 | bond->dev->name); | |
39 | return -EPERM; | |
40 | } | |
41 | ||
fe9d04af | 42 | if (BOND_NO_USES_ARP(mode) && bond->params.arp_interval) { |
43 | pr_info("%s: %s mode is incompatible with arp monitoring, start mii monitoring\n", | |
44 | bond->dev->name, bond_mode_tbl[mode].modename); | |
45 | /* disable arp monitoring */ | |
46 | bond->params.arp_interval = 0; | |
47 | /* set miimon to default value */ | |
48 | bond->params.miimon = BOND_DEFAULT_MIIMON; | |
49 | pr_info("%s: Setting MII monitoring interval to %d.\n", | |
50 | bond->dev->name, bond->params.miimon); | |
72be35fe JP |
51 | } |
52 | ||
53 | /* don't cache arp_validate between modes */ | |
54 | bond->params.arp_validate = BOND_ARP_VALIDATE_NONE; | |
55 | bond->params.mode = mode; | |
56 | return 0; | |
57 | } | |
d9e32b21 | 58 | |
752d48b5 JP |
59 | static struct net_device *__bond_option_active_slave_get(struct bonding *bond, |
60 | struct slave *slave) | |
61 | { | |
62 | return USES_PRIMARY(bond->params.mode) && slave ? slave->dev : NULL; | |
63 | } | |
64 | ||
65 | struct net_device *bond_option_active_slave_get_rcu(struct bonding *bond) | |
66 | { | |
67 | struct slave *slave = rcu_dereference(bond->curr_active_slave); | |
68 | ||
69 | return __bond_option_active_slave_get(bond, slave); | |
70 | } | |
71 | ||
72 | struct net_device *bond_option_active_slave_get(struct bonding *bond) | |
73 | { | |
74 | return __bond_option_active_slave_get(bond, bond->curr_active_slave); | |
75 | } | |
76 | ||
d9e32b21 JP |
77 | int bond_option_active_slave_set(struct bonding *bond, |
78 | struct net_device *slave_dev) | |
79 | { | |
80 | int ret = 0; | |
81 | ||
82 | if (slave_dev) { | |
83 | if (!netif_is_bond_slave(slave_dev)) { | |
84 | pr_err("Device %s is not bonding slave.\n", | |
85 | slave_dev->name); | |
86 | return -EINVAL; | |
87 | } | |
88 | ||
89 | if (bond->dev != netdev_master_upper_dev_get(slave_dev)) { | |
90 | pr_err("%s: Device %s is not our slave.\n", | |
91 | bond->dev->name, slave_dev->name); | |
92 | return -EINVAL; | |
93 | } | |
94 | } | |
95 | ||
96 | if (!USES_PRIMARY(bond->params.mode)) { | |
97 | pr_err("%s: Unable to change active slave; %s is in mode %d\n", | |
98 | bond->dev->name, bond->dev->name, bond->params.mode); | |
99 | return -EINVAL; | |
100 | } | |
101 | ||
102 | block_netpoll_tx(); | |
d9e32b21 JP |
103 | write_lock_bh(&bond->curr_slave_lock); |
104 | ||
105 | /* check to see if we are clearing active */ | |
106 | if (!slave_dev) { | |
107 | pr_info("%s: Clearing current active slave.\n", | |
108 | bond->dev->name); | |
109 | rcu_assign_pointer(bond->curr_active_slave, NULL); | |
110 | bond_select_active_slave(bond); | |
111 | } else { | |
112 | struct slave *old_active = bond->curr_active_slave; | |
113 | struct slave *new_active = bond_slave_get_rtnl(slave_dev); | |
114 | ||
115 | BUG_ON(!new_active); | |
116 | ||
117 | if (new_active == old_active) { | |
118 | /* do nothing */ | |
119 | pr_info("%s: %s is already the current active slave.\n", | |
120 | bond->dev->name, new_active->dev->name); | |
121 | } else { | |
122 | if (old_active && (new_active->link == BOND_LINK_UP) && | |
123 | IS_UP(new_active->dev)) { | |
124 | pr_info("%s: Setting %s as active slave.\n", | |
125 | bond->dev->name, new_active->dev->name); | |
126 | bond_change_active_slave(bond, new_active); | |
127 | } else { | |
128 | pr_err("%s: Could not set %s as active slave; either %s is down or the link is down.\n", | |
129 | bond->dev->name, new_active->dev->name, | |
130 | new_active->dev->name); | |
131 | ret = -EINVAL; | |
132 | } | |
133 | } | |
134 | } | |
135 | ||
136 | write_unlock_bh(&bond->curr_slave_lock); | |
d9e32b21 JP |
137 | unblock_netpoll_tx(); |
138 | return ret; | |
139 | } | |
eecdaa6e | 140 | |
141 | int bond_option_miimon_set(struct bonding *bond, int miimon) | |
142 | { | |
143 | if (miimon < 0) { | |
144 | pr_err("%s: Invalid miimon value %d not in range %d-%d; rejected.\n", | |
145 | bond->dev->name, miimon, 0, INT_MAX); | |
146 | return -EINVAL; | |
147 | } | |
148 | pr_info("%s: Setting MII monitoring interval to %d.\n", | |
149 | bond->dev->name, miimon); | |
150 | bond->params.miimon = miimon; | |
151 | if (bond->params.updelay) | |
152 | pr_info("%s: Note: Updating updelay (to %d) since it is a multiple of the miimon value.\n", | |
153 | bond->dev->name, | |
154 | bond->params.updelay * bond->params.miimon); | |
155 | if (bond->params.downdelay) | |
156 | pr_info("%s: Note: Updating downdelay (to %d) since it is a multiple of the miimon value.\n", | |
157 | bond->dev->name, | |
158 | bond->params.downdelay * bond->params.miimon); | |
159 | if (miimon && bond->params.arp_interval) { | |
160 | pr_info("%s: MII monitoring cannot be used with ARP monitoring. Disabling ARP monitoring...\n", | |
161 | bond->dev->name); | |
162 | bond->params.arp_interval = 0; | |
163 | if (bond->params.arp_validate) | |
164 | bond->params.arp_validate = BOND_ARP_VALIDATE_NONE; | |
165 | } | |
166 | if (bond->dev->flags & IFF_UP) { | |
167 | /* If the interface is up, we may need to fire off | |
168 | * the MII timer. If the interface is down, the | |
169 | * timer will get fired off when the open function | |
170 | * is called. | |
171 | */ | |
172 | if (!miimon) { | |
173 | cancel_delayed_work_sync(&bond->mii_work); | |
174 | } else { | |
175 | cancel_delayed_work_sync(&bond->arp_work); | |
176 | queue_delayed_work(bond->wq, &bond->mii_work, 0); | |
177 | } | |
178 | } | |
179 | return 0; | |
180 | } | |
25852e29 | 181 | |
182 | int bond_option_updelay_set(struct bonding *bond, int updelay) | |
183 | { | |
184 | if (!(bond->params.miimon)) { | |
185 | pr_err("%s: Unable to set up delay as MII monitoring is disabled\n", | |
186 | bond->dev->name); | |
187 | return -EPERM; | |
188 | } | |
189 | ||
190 | if (updelay < 0) { | |
191 | pr_err("%s: Invalid up delay value %d not in range %d-%d; rejected.\n", | |
192 | bond->dev->name, updelay, 0, INT_MAX); | |
193 | return -EINVAL; | |
194 | } else { | |
195 | if ((updelay % bond->params.miimon) != 0) { | |
196 | pr_warn("%s: Warning: up delay (%d) is not a multiple of miimon (%d), updelay rounded to %d ms\n", | |
197 | bond->dev->name, updelay, | |
198 | bond->params.miimon, | |
199 | (updelay / bond->params.miimon) * | |
200 | bond->params.miimon); | |
201 | } | |
202 | bond->params.updelay = updelay / bond->params.miimon; | |
203 | pr_info("%s: Setting up delay to %d.\n", | |
204 | bond->dev->name, | |
205 | bond->params.updelay * bond->params.miimon); | |
206 | } | |
207 | ||
208 | return 0; | |
209 | } | |
c7461f9b | 210 | |
211 | int bond_option_downdelay_set(struct bonding *bond, int downdelay) | |
212 | { | |
213 | if (!(bond->params.miimon)) { | |
214 | pr_err("%s: Unable to set down delay as MII monitoring is disabled\n", | |
215 | bond->dev->name); | |
216 | return -EPERM; | |
217 | } | |
218 | ||
219 | if (downdelay < 0) { | |
220 | pr_err("%s: Invalid down delay value %d not in range %d-%d; rejected.\n", | |
221 | bond->dev->name, downdelay, 0, INT_MAX); | |
222 | return -EINVAL; | |
223 | } else { | |
224 | if ((downdelay % bond->params.miimon) != 0) { | |
225 | pr_warn("%s: Warning: down delay (%d) is not a multiple of miimon (%d), delay rounded to %d ms\n", | |
226 | bond->dev->name, downdelay, | |
227 | bond->params.miimon, | |
228 | (downdelay / bond->params.miimon) * | |
229 | bond->params.miimon); | |
230 | } | |
231 | bond->params.downdelay = downdelay / bond->params.miimon; | |
232 | pr_info("%s: Setting down delay to %d.\n", | |
233 | bond->dev->name, | |
234 | bond->params.downdelay * bond->params.miimon); | |
235 | } | |
236 | ||
237 | return 0; | |
238 | } | |
9f53e14e | 239 | |
240 | int bond_option_use_carrier_set(struct bonding *bond, int use_carrier) | |
241 | { | |
242 | if ((use_carrier == 0) || (use_carrier == 1)) { | |
243 | bond->params.use_carrier = use_carrier; | |
244 | pr_info("%s: Setting use_carrier to %d.\n", | |
245 | bond->dev->name, use_carrier); | |
246 | } else { | |
247 | pr_info("%s: Ignoring invalid use_carrier value %d.\n", | |
248 | bond->dev->name, use_carrier); | |
249 | } | |
250 | ||
251 | return 0; | |
252 | } | |
06151dbc | 253 | |
254 | int bond_option_arp_interval_set(struct bonding *bond, int arp_interval) | |
255 | { | |
256 | if (arp_interval < 0) { | |
257 | pr_err("%s: Invalid arp_interval value %d not in range 0-%d; rejected.\n", | |
258 | bond->dev->name, arp_interval, INT_MAX); | |
259 | return -EINVAL; | |
260 | } | |
261 | if (BOND_NO_USES_ARP(bond->params.mode)) { | |
262 | pr_info("%s: ARP monitoring cannot be used with ALB/TLB/802.3ad. Only MII monitoring is supported on %s.\n", | |
263 | bond->dev->name, bond->dev->name); | |
264 | return -EINVAL; | |
265 | } | |
266 | pr_info("%s: Setting ARP monitoring interval to %d.\n", | |
267 | bond->dev->name, arp_interval); | |
268 | bond->params.arp_interval = arp_interval; | |
269 | if (arp_interval) { | |
270 | if (bond->params.miimon) { | |
271 | pr_info("%s: ARP monitoring cannot be used with MII monitoring. %s Disabling MII monitoring.\n", | |
272 | bond->dev->name, bond->dev->name); | |
273 | bond->params.miimon = 0; | |
274 | } | |
275 | if (!bond->params.arp_targets[0]) | |
276 | pr_info("%s: ARP monitoring has been set up, but no ARP targets have been specified.\n", | |
277 | bond->dev->name); | |
278 | } | |
279 | if (bond->dev->flags & IFF_UP) { | |
280 | /* If the interface is up, we may need to fire off | |
281 | * the ARP timer. If the interface is down, the | |
282 | * timer will get fired off when the open function | |
283 | * is called. | |
284 | */ | |
285 | if (!arp_interval) { | |
286 | if (bond->params.arp_validate) | |
287 | bond->recv_probe = NULL; | |
288 | cancel_delayed_work_sync(&bond->arp_work); | |
289 | } else { | |
290 | /* arp_validate can be set only in active-backup mode */ | |
291 | if (bond->params.arp_validate) | |
292 | bond->recv_probe = bond_arp_rcv; | |
293 | cancel_delayed_work_sync(&bond->mii_work); | |
294 | queue_delayed_work(bond->wq, &bond->arp_work, 0); | |
295 | } | |
296 | } | |
297 | ||
298 | return 0; | |
299 | } | |
7f28fa10 | 300 | |
301 | static void _bond_options_arp_ip_target_set(struct bonding *bond, int slot, | |
302 | __be32 target, | |
303 | unsigned long last_rx) | |
304 | { | |
305 | __be32 *targets = bond->params.arp_targets; | |
306 | struct list_head *iter; | |
307 | struct slave *slave; | |
308 | ||
309 | if (slot >= 0 && slot < BOND_MAX_ARP_TARGETS) { | |
310 | bond_for_each_slave(bond, slave, iter) | |
311 | slave->target_last_arp_rx[slot] = last_rx; | |
312 | targets[slot] = target; | |
313 | } | |
314 | } | |
315 | ||
316 | static int _bond_option_arp_ip_target_add(struct bonding *bond, __be32 target) | |
317 | { | |
318 | __be32 *targets = bond->params.arp_targets; | |
319 | int ind; | |
320 | ||
321 | if (IS_IP_TARGET_UNUSABLE_ADDRESS(target)) { | |
322 | pr_err("%s: invalid ARP target %pI4 specified for addition\n", | |
323 | bond->dev->name, &target); | |
324 | return -EINVAL; | |
325 | } | |
326 | ||
327 | if (bond_get_targets_ip(targets, target) != -1) { /* dup */ | |
328 | pr_err("%s: ARP target %pI4 is already present\n", | |
329 | bond->dev->name, &target); | |
330 | return -EINVAL; | |
331 | } | |
332 | ||
333 | ind = bond_get_targets_ip(targets, 0); /* first free slot */ | |
334 | if (ind == -1) { | |
335 | pr_err("%s: ARP target table is full!\n", | |
336 | bond->dev->name); | |
337 | return -EINVAL; | |
338 | } | |
339 | ||
340 | pr_info("%s: adding ARP target %pI4.\n", bond->dev->name, &target); | |
341 | ||
342 | _bond_options_arp_ip_target_set(bond, ind, target, jiffies); | |
343 | ||
344 | return 0; | |
345 | } | |
346 | ||
347 | int bond_option_arp_ip_target_add(struct bonding *bond, __be32 target) | |
348 | { | |
349 | int ret; | |
350 | ||
351 | /* not to race with bond_arp_rcv */ | |
352 | write_lock_bh(&bond->lock); | |
353 | ret = _bond_option_arp_ip_target_add(bond, target); | |
354 | write_unlock_bh(&bond->lock); | |
355 | ||
356 | return ret; | |
357 | } | |
358 | ||
359 | int bond_option_arp_ip_target_rem(struct bonding *bond, __be32 target) | |
360 | { | |
361 | __be32 *targets = bond->params.arp_targets; | |
362 | struct list_head *iter; | |
363 | struct slave *slave; | |
364 | unsigned long *targets_rx; | |
365 | int ind, i; | |
366 | ||
367 | if (IS_IP_TARGET_UNUSABLE_ADDRESS(target)) { | |
368 | pr_err("%s: invalid ARP target %pI4 specified for removal\n", | |
369 | bond->dev->name, &target); | |
370 | return -EINVAL; | |
371 | } | |
372 | ||
373 | ind = bond_get_targets_ip(targets, target); | |
374 | if (ind == -1) { | |
375 | pr_err("%s: unable to remove nonexistent ARP target %pI4.\n", | |
376 | bond->dev->name, &target); | |
377 | return -EINVAL; | |
378 | } | |
379 | ||
380 | if (ind == 0 && !targets[1] && bond->params.arp_interval) | |
381 | pr_warn("%s: removing last arp target with arp_interval on\n", | |
382 | bond->dev->name); | |
383 | ||
384 | pr_info("%s: removing ARP target %pI4.\n", bond->dev->name, | |
385 | &target); | |
386 | ||
387 | /* not to race with bond_arp_rcv */ | |
388 | write_lock_bh(&bond->lock); | |
389 | ||
390 | bond_for_each_slave(bond, slave, iter) { | |
391 | targets_rx = slave->target_last_arp_rx; | |
392 | for (i = ind; (i < BOND_MAX_ARP_TARGETS-1) && targets[i+1]; i++) | |
393 | targets_rx[i] = targets_rx[i+1]; | |
394 | targets_rx[i] = 0; | |
395 | } | |
396 | for (i = ind; (i < BOND_MAX_ARP_TARGETS-1) && targets[i+1]; i++) | |
397 | targets[i] = targets[i+1]; | |
398 | targets[i] = 0; | |
399 | ||
400 | write_unlock_bh(&bond->lock); | |
401 | ||
402 | return 0; | |
403 | } | |
404 | ||
405 | int bond_option_arp_ip_targets_set(struct bonding *bond, __be32 *targets, | |
406 | int count) | |
407 | { | |
408 | int i, ret = 0; | |
409 | ||
410 | /* not to race with bond_arp_rcv */ | |
411 | write_lock_bh(&bond->lock); | |
412 | ||
413 | /* clear table */ | |
414 | for (i = 0; i < BOND_MAX_ARP_TARGETS; i++) | |
415 | _bond_options_arp_ip_target_set(bond, i, 0, 0); | |
416 | ||
417 | if (count == 0 && bond->params.arp_interval) | |
418 | pr_warn("%s: removing last arp target with arp_interval on\n", | |
419 | bond->dev->name); | |
420 | ||
421 | for (i = 0; i < count; i++) { | |
422 | ret = _bond_option_arp_ip_target_add(bond, targets[i]); | |
423 | if (ret) | |
424 | break; | |
425 | } | |
426 | ||
427 | write_unlock_bh(&bond->lock); | |
428 | return ret; | |
429 | } | |
29c49482 | 430 | |
431 | int bond_option_arp_validate_set(struct bonding *bond, int arp_validate) | |
432 | { | |
3243c47b | 433 | if (bond_parm_tbl_lookup(arp_validate, arp_validate_tbl) < 0) { |
434 | pr_err("%s: Ignoring invalid arp_validate value %d.\n", | |
435 | bond->dev->name, arp_validate); | |
436 | return -EINVAL; | |
437 | } | |
438 | ||
29c49482 | 439 | if (bond->params.mode != BOND_MODE_ACTIVEBACKUP) { |
440 | pr_err("%s: arp_validate only supported in active-backup mode.\n", | |
441 | bond->dev->name); | |
442 | return -EINVAL; | |
443 | } | |
3243c47b | 444 | |
29c49482 | 445 | pr_info("%s: setting arp_validate to %s (%d).\n", |
446 | bond->dev->name, arp_validate_tbl[arp_validate].modename, | |
447 | arp_validate); | |
448 | ||
449 | if (bond->dev->flags & IFF_UP) { | |
450 | if (!arp_validate) | |
451 | bond->recv_probe = NULL; | |
452 | else if (bond->params.arp_interval) | |
453 | bond->recv_probe = bond_arp_rcv; | |
454 | } | |
455 | bond->params.arp_validate = arp_validate; | |
456 | ||
457 | return 0; | |
458 | } | |
d5c84254 | 459 | |
460 | int bond_option_arp_all_targets_set(struct bonding *bond, int arp_all_targets) | |
461 | { | |
3243c47b | 462 | if (bond_parm_tbl_lookup(arp_all_targets, arp_all_targets_tbl) < 0) { |
463 | pr_err("%s: Ignoring invalid arp_all_targets value %d.\n", | |
464 | bond->dev->name, arp_all_targets); | |
465 | return -EINVAL; | |
466 | } | |
467 | ||
d5c84254 | 468 | pr_info("%s: setting arp_all_targets to %s (%d).\n", |
469 | bond->dev->name, arp_all_targets_tbl[arp_all_targets].modename, | |
470 | arp_all_targets); | |
471 | ||
472 | bond->params.arp_all_targets = arp_all_targets; | |
473 | ||
474 | return 0; | |
475 | } | |
0a98a0d1 | 476 | |
477 | int bond_option_primary_set(struct bonding *bond, const char *primary) | |
478 | { | |
479 | struct list_head *iter; | |
480 | struct slave *slave; | |
481 | int err = 0; | |
482 | ||
483 | block_netpoll_tx(); | |
484 | read_lock(&bond->lock); | |
485 | write_lock_bh(&bond->curr_slave_lock); | |
486 | ||
487 | if (!USES_PRIMARY(bond->params.mode)) { | |
488 | pr_err("%s: Unable to set primary slave; %s is in mode %d\n", | |
489 | bond->dev->name, bond->dev->name, bond->params.mode); | |
490 | err = -EINVAL; | |
491 | goto out; | |
492 | } | |
493 | ||
494 | /* check to see if we are clearing primary */ | |
495 | if (!strlen(primary)) { | |
496 | pr_info("%s: Setting primary slave to None.\n", | |
497 | bond->dev->name); | |
498 | bond->primary_slave = NULL; | |
499 | memset(bond->params.primary, 0, sizeof(bond->params.primary)); | |
500 | bond_select_active_slave(bond); | |
501 | goto out; | |
502 | } | |
503 | ||
504 | bond_for_each_slave(bond, slave, iter) { | |
505 | if (strncmp(slave->dev->name, primary, IFNAMSIZ) == 0) { | |
506 | pr_info("%s: Setting %s as primary slave.\n", | |
507 | bond->dev->name, slave->dev->name); | |
508 | bond->primary_slave = slave; | |
509 | strcpy(bond->params.primary, slave->dev->name); | |
510 | bond_select_active_slave(bond); | |
511 | goto out; | |
512 | } | |
513 | } | |
514 | ||
515 | strncpy(bond->params.primary, primary, IFNAMSIZ); | |
516 | bond->params.primary[IFNAMSIZ - 1] = 0; | |
517 | ||
518 | pr_info("%s: Recording %s as primary, but it has not been enslaved to %s yet.\n", | |
519 | bond->dev->name, primary, bond->dev->name); | |
520 | ||
521 | out: | |
522 | write_unlock_bh(&bond->curr_slave_lock); | |
523 | read_unlock(&bond->lock); | |
524 | unblock_netpoll_tx(); | |
525 | ||
526 | return err; | |
527 | } | |
8a41ae44 | 528 | |
529 | int bond_option_primary_reselect_set(struct bonding *bond, int primary_reselect) | |
530 | { | |
3243c47b | 531 | if (bond_parm_tbl_lookup(primary_reselect, pri_reselect_tbl) < 0) { |
532 | pr_err("%s: Ignoring invalid primary_reselect value %d.\n", | |
533 | bond->dev->name, primary_reselect); | |
534 | return -EINVAL; | |
535 | } | |
536 | ||
8a41ae44 | 537 | bond->params.primary_reselect = primary_reselect; |
538 | pr_info("%s: setting primary_reselect to %s (%d).\n", | |
539 | bond->dev->name, pri_reselect_tbl[primary_reselect].modename, | |
540 | primary_reselect); | |
541 | ||
542 | block_netpoll_tx(); | |
543 | write_lock_bh(&bond->curr_slave_lock); | |
544 | bond_select_active_slave(bond); | |
545 | write_unlock_bh(&bond->curr_slave_lock); | |
546 | unblock_netpoll_tx(); | |
547 | ||
548 | return 0; | |
549 | } | |
89901972 | 550 | |
551 | int bond_option_fail_over_mac_set(struct bonding *bond, int fail_over_mac) | |
552 | { | |
3243c47b | 553 | if (bond_parm_tbl_lookup(fail_over_mac, fail_over_mac_tbl) < 0) { |
554 | pr_err("%s: Ignoring invalid fail_over_mac value %d.\n", | |
555 | bond->dev->name, fail_over_mac); | |
556 | return -EINVAL; | |
557 | } | |
558 | ||
89901972 | 559 | if (bond_has_slaves(bond)) { |
560 | pr_err("%s: Can't alter fail_over_mac with slaves in bond.\n", | |
561 | bond->dev->name); | |
562 | return -EPERM; | |
563 | } | |
564 | ||
565 | bond->params.fail_over_mac = fail_over_mac; | |
566 | pr_info("%s: Setting fail_over_mac to %s (%d).\n", | |
567 | bond->dev->name, fail_over_mac_tbl[fail_over_mac].modename, | |
568 | fail_over_mac); | |
569 | ||
570 | return 0; | |
571 | } | |
f70161c6 | 572 | |
573 | int bond_option_xmit_hash_policy_set(struct bonding *bond, int xmit_hash_policy) | |
574 | { | |
3243c47b | 575 | if (bond_parm_tbl_lookup(xmit_hash_policy, xmit_hashtype_tbl) < 0) { |
576 | pr_err("%s: Ignoring invalid xmit_hash_policy value %d.\n", | |
577 | bond->dev->name, xmit_hash_policy); | |
578 | return -EINVAL; | |
579 | } | |
580 | ||
f70161c6 | 581 | bond->params.xmit_policy = xmit_hash_policy; |
582 | pr_info("%s: setting xmit hash policy to %s (%d).\n", | |
583 | bond->dev->name, | |
584 | xmit_hashtype_tbl[xmit_hash_policy].modename, xmit_hash_policy); | |
585 | ||
586 | return 0; | |
587 | } | |
d8838de7 | 588 | |
589 | int bond_option_resend_igmp_set(struct bonding *bond, int resend_igmp) | |
590 | { | |
591 | if (resend_igmp < 0 || resend_igmp > 255) { | |
592 | pr_err("%s: Invalid resend_igmp value %d not in range 0-255; rejected.\n", | |
593 | bond->dev->name, resend_igmp); | |
594 | return -EINVAL; | |
595 | } | |
596 | ||
597 | bond->params.resend_igmp = resend_igmp; | |
598 | pr_info("%s: Setting resend_igmp to %d.\n", | |
599 | bond->dev->name, resend_igmp); | |
600 | ||
601 | return 0; | |
602 | } | |
2c9839c1 | 603 | |
604 | int bond_option_num_peer_notif_set(struct bonding *bond, int num_peer_notif) | |
605 | { | |
606 | bond->params.num_peer_notif = num_peer_notif; | |
607 | return 0; | |
608 | } | |
1cc0b1e3 | 609 | |
610 | int bond_option_all_slaves_active_set(struct bonding *bond, | |
611 | int all_slaves_active) | |
612 | { | |
613 | struct list_head *iter; | |
614 | struct slave *slave; | |
615 | ||
616 | if (all_slaves_active == bond->params.all_slaves_active) | |
617 | return 0; | |
618 | ||
619 | if ((all_slaves_active == 0) || (all_slaves_active == 1)) { | |
620 | bond->params.all_slaves_active = all_slaves_active; | |
621 | } else { | |
622 | pr_info("%s: Ignoring invalid all_slaves_active value %d.\n", | |
623 | bond->dev->name, all_slaves_active); | |
624 | return -EINVAL; | |
625 | } | |
626 | ||
627 | bond_for_each_slave(bond, slave, iter) { | |
628 | if (!bond_is_active_slave(slave)) { | |
629 | if (all_slaves_active) | |
630 | slave->inactive = 0; | |
631 | else | |
632 | slave->inactive = 1; | |
633 | } | |
634 | } | |
635 | ||
636 | return 0; | |
637 | } | |
7d101008 | 638 | |
639 | int bond_option_min_links_set(struct bonding *bond, int min_links) | |
640 | { | |
641 | pr_info("%s: Setting min links value to %u\n", | |
642 | bond->dev->name, min_links); | |
643 | bond->params.min_links = min_links; | |
644 | ||
645 | return 0; | |
646 | } | |
8d836d09 | 647 | |
648 | int bond_option_lp_interval_set(struct bonding *bond, int lp_interval) | |
649 | { | |
650 | if (lp_interval <= 0) { | |
651 | pr_err("%s: lp_interval must be between 1 and %d\n", | |
652 | bond->dev->name, INT_MAX); | |
653 | return -EINVAL; | |
654 | } | |
655 | ||
656 | bond->params.lp_interval = lp_interval; | |
657 | ||
658 | return 0; | |
659 | } | |
c13ab3ff | 660 | |
661 | int bond_option_packets_per_slave_set(struct bonding *bond, | |
662 | int packets_per_slave) | |
663 | { | |
664 | if (packets_per_slave < 0 || packets_per_slave > USHRT_MAX) { | |
665 | pr_err("%s: packets_per_slave must be between 0 and %u\n", | |
666 | bond->dev->name, USHRT_MAX); | |
667 | return -EINVAL; | |
668 | } | |
669 | ||
670 | if (bond->params.mode != BOND_MODE_ROUNDROBIN) | |
671 | pr_warn("%s: Warning: packets_per_slave has effect only in balance-rr mode\n", | |
672 | bond->dev->name); | |
673 | ||
674 | if (packets_per_slave > 1) | |
675 | bond->params.packets_per_slave = | |
676 | reciprocal_value(packets_per_slave); | |
677 | else | |
678 | bond->params.packets_per_slave = packets_per_slave; | |
679 | ||
680 | return 0; | |
681 | } | |
998e40bb | 682 | |
683 | int bond_option_lacp_rate_set(struct bonding *bond, int lacp_rate) | |
684 | { | |
3243c47b | 685 | if (bond_parm_tbl_lookup(lacp_rate, bond_lacp_tbl) < 0) { |
686 | pr_err("%s: Ignoring invalid LACP rate value %d.\n", | |
687 | bond->dev->name, lacp_rate); | |
688 | return -EINVAL; | |
689 | } | |
690 | ||
998e40bb | 691 | if (bond->dev->flags & IFF_UP) { |
692 | pr_err("%s: Unable to update LACP rate because interface is up.\n", | |
693 | bond->dev->name); | |
694 | return -EPERM; | |
695 | } | |
696 | ||
697 | if (bond->params.mode != BOND_MODE_8023AD) { | |
698 | pr_err("%s: Unable to update LACP rate because bond is not in 802.3ad mode.\n", | |
699 | bond->dev->name); | |
700 | return -EPERM; | |
701 | } | |
702 | ||
3243c47b | 703 | bond->params.lacp_fast = lacp_rate; |
704 | bond_3ad_update_lacp_rate(bond); | |
705 | pr_info("%s: Setting LACP rate to %s (%d).\n", | |
706 | bond->dev->name, bond_lacp_tbl[lacp_rate].modename, | |
707 | lacp_rate); | |
998e40bb | 708 | |
709 | return 0; | |
710 | } | |
ec029fac | 711 | |
712 | int bond_option_ad_select_set(struct bonding *bond, int ad_select) | |
713 | { | |
ec029fac | 714 | if (bond_parm_tbl_lookup(ad_select, ad_select_tbl) < 0) { |
715 | pr_err("%s: Ignoring invalid ad_select value %d.\n", | |
716 | bond->dev->name, ad_select); | |
717 | return -EINVAL; | |
718 | } | |
719 | ||
3243c47b | 720 | if (bond->dev->flags & IFF_UP) { |
721 | pr_err("%s: Unable to update ad_select because interface is up.\n", | |
722 | bond->dev->name); | |
723 | return -EPERM; | |
724 | } | |
725 | ||
ec029fac | 726 | bond->params.ad_select = ad_select; |
727 | pr_info("%s: Setting ad_select to %s (%d).\n", | |
728 | bond->dev->name, ad_select_tbl[ad_select].modename, | |
729 | ad_select); | |
730 | ||
731 | return 0; | |
732 | } |