bonding: fix bond_arp_rcv setting and arp validate desync state
[deliverable/linux.git] / drivers / net / bonding / bond_sysfs.c
CommitLineData
b76cdba9
MW
1/*
2 * Copyright(c) 2004-2005 Intel Corporation. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 *
18 * The full GNU General Public License is included in this distribution in the
19 * file called LICENSE.
20 *
b76cdba9 21 */
a4aee5c8
JP
22
23#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
24
b76cdba9
MW
25#include <linux/kernel.h>
26#include <linux/module.h>
b76cdba9 27#include <linux/device.h>
d43c36dc 28#include <linux/sched.h>
b76cdba9
MW
29#include <linux/fs.h>
30#include <linux/types.h>
31#include <linux/string.h>
32#include <linux/netdevice.h>
33#include <linux/inetdevice.h>
34#include <linux/in.h>
35#include <linux/sysfs.h>
b76cdba9
MW
36#include <linux/ctype.h>
37#include <linux/inet.h>
38#include <linux/rtnetlink.h>
5c5129b5 39#include <linux/etherdevice.h>
881d966b 40#include <net/net_namespace.h>
ec87fd3b
EB
41#include <net/netns/generic.h>
42#include <linux/nsproxy.h>
b76cdba9 43
b76cdba9 44#include "bonding.h"
5a03cdb7 45
3d632c3f 46#define to_dev(obj) container_of(obj, struct device, kobj)
454d7c9b 47#define to_bond(cd) ((struct bonding *)(netdev_priv(to_net_dev(cd))))
b76cdba9 48
b76cdba9
MW
49/*
50 * "show" function for the bond_masters attribute.
51 * The class parameter is ignored.
52 */
28812fe1
AK
53static ssize_t bonding_show_bonds(struct class *cls,
54 struct class_attribute *attr,
55 char *buf)
b76cdba9 56{
4c22400a
EB
57 struct bond_net *bn =
58 container_of(attr, struct bond_net, class_attr_bonding_masters);
b76cdba9
MW
59 int res = 0;
60 struct bonding *bond;
61
7e083840 62 rtnl_lock();
b76cdba9 63
ec87fd3b 64 list_for_each_entry(bond, &bn->dev_list, bond_list) {
b76cdba9
MW
65 if (res > (PAGE_SIZE - IFNAMSIZ)) {
66 /* not enough space for another interface name */
67 if ((PAGE_SIZE - res) > 10)
68 res = PAGE_SIZE - 10;
b8843665 69 res += sprintf(buf + res, "++more++ ");
b76cdba9
MW
70 break;
71 }
b8843665 72 res += sprintf(buf + res, "%s ", bond->dev->name);
b76cdba9 73 }
1dcdcd69
WF
74 if (res)
75 buf[res-1] = '\n'; /* eat the leftover space */
7e083840
SH
76
77 rtnl_unlock();
b76cdba9
MW
78 return res;
79}
80
4c22400a 81static struct net_device *bond_get_by_name(struct bond_net *bn, const char *ifname)
373500db
SH
82{
83 struct bonding *bond;
84
ec87fd3b 85 list_for_each_entry(bond, &bn->dev_list, bond_list) {
373500db
SH
86 if (strncmp(bond->dev->name, ifname, IFNAMSIZ) == 0)
87 return bond->dev;
88 }
89 return NULL;
90}
91
b76cdba9
MW
92/*
93 * "store" function for the bond_masters attribute. This is what
94 * creates and deletes entire bonds.
95 *
96 * The class parameter is ignored.
97 *
98 */
99
3d632c3f 100static ssize_t bonding_store_bonds(struct class *cls,
28812fe1 101 struct class_attribute *attr,
3d632c3f 102 const char *buffer, size_t count)
b76cdba9 103{
4c22400a
EB
104 struct bond_net *bn =
105 container_of(attr, struct bond_net, class_attr_bonding_masters);
b76cdba9
MW
106 char command[IFNAMSIZ + 1] = {0, };
107 char *ifname;
027ea041 108 int rv, res = count;
b76cdba9 109
b76cdba9
MW
110 sscanf(buffer, "%16s", command); /* IFNAMSIZ*/
111 ifname = command + 1;
112 if ((strlen(command) <= 1) ||
113 !dev_valid_name(ifname))
114 goto err_no_cmd;
115
116 if (command[0] == '+') {
a4aee5c8 117 pr_info("%s is being created...\n", ifname);
4c22400a 118 rv = bond_create(bn->net, ifname);
027ea041 119 if (rv) {
5f86cad1
PO
120 if (rv == -EEXIST)
121 pr_info("%s already exists.\n", ifname);
122 else
123 pr_info("%s creation failed.\n", ifname);
027ea041 124 res = rv;
b76cdba9 125 }
373500db
SH
126 } else if (command[0] == '-') {
127 struct net_device *bond_dev;
b76cdba9 128
027ea041 129 rtnl_lock();
4c22400a 130 bond_dev = bond_get_by_name(bn, ifname);
373500db 131 if (bond_dev) {
a4aee5c8 132 pr_info("%s is being deleted...\n", ifname);
373500db
SH
133 unregister_netdevice(bond_dev);
134 } else {
a4aee5c8 135 pr_err("unable to delete non-existent %s\n", ifname);
373500db
SH
136 res = -ENODEV;
137 }
138 rtnl_unlock();
139 } else
140 goto err_no_cmd;
027ea041 141
373500db
SH
142 /* Always return either count or an error. If you return 0, you'll
143 * get called forever, which is bad.
144 */
145 return res;
b76cdba9
MW
146
147err_no_cmd:
a4aee5c8 148 pr_err("no command found in bonding_masters. Use +ifname or -ifname.\n");
c4ebc66a 149 return -EPERM;
b76cdba9 150}
373500db 151
4c22400a
EB
152static const void *bonding_namespace(struct class *cls,
153 const struct class_attribute *attr)
154{
155 const struct bond_net *bn =
156 container_of(attr, struct bond_net, class_attr_bonding_masters);
157 return bn->net;
158}
159
b76cdba9 160/* class attribute for bond_masters file. This ends up in /sys/class/net */
4c22400a
EB
161static const struct class_attribute class_attr_bonding_masters = {
162 .attr = {
163 .name = "bonding_masters",
164 .mode = S_IWUSR | S_IRUGO,
165 },
166 .show = bonding_show_bonds,
167 .store = bonding_store_bonds,
168 .namespace = bonding_namespace,
169};
b76cdba9 170
3d632c3f
SH
171int bond_create_slave_symlinks(struct net_device *master,
172 struct net_device *slave)
b76cdba9
MW
173{
174 char linkname[IFNAMSIZ+7];
175 int ret = 0;
176
177 /* first, create a link from the slave back to the master */
43cb76d9 178 ret = sysfs_create_link(&(slave->dev.kobj), &(master->dev.kobj),
b76cdba9
MW
179 "master");
180 if (ret)
181 return ret;
182 /* next, create a link from the master to the slave */
3d632c3f 183 sprintf(linkname, "slave_%s", slave->name);
43cb76d9 184 ret = sysfs_create_link(&(master->dev.kobj), &(slave->dev.kobj),
b76cdba9 185 linkname);
9fe16b78
VF
186
187 /* free the master link created earlier in case of error */
188 if (ret)
189 sysfs_remove_link(&(slave->dev.kobj), "master");
190
b76cdba9
MW
191 return ret;
192
193}
194
3d632c3f
SH
195void bond_destroy_slave_symlinks(struct net_device *master,
196 struct net_device *slave)
b76cdba9
MW
197{
198 char linkname[IFNAMSIZ+7];
199
43cb76d9 200 sysfs_remove_link(&(slave->dev.kobj), "master");
3d632c3f 201 sprintf(linkname, "slave_%s", slave->name);
43cb76d9 202 sysfs_remove_link(&(master->dev.kobj), linkname);
b76cdba9
MW
203}
204
205
206/*
207 * Show the slaves in the current bond.
208 */
43cb76d9
GKH
209static ssize_t bonding_show_slaves(struct device *d,
210 struct device_attribute *attr, char *buf)
b76cdba9 211{
43cb76d9 212 struct bonding *bond = to_bond(d);
dec1e90e 213 struct slave *slave;
214 int res = 0;
b76cdba9 215
6603a6f2 216 read_lock(&bond->lock);
dec1e90e 217 bond_for_each_slave(bond, slave) {
b76cdba9
MW
218 if (res > (PAGE_SIZE - IFNAMSIZ)) {
219 /* not enough space for another interface name */
220 if ((PAGE_SIZE - res) > 10)
221 res = PAGE_SIZE - 10;
7bd46508 222 res += sprintf(buf + res, "++more++ ");
b76cdba9
MW
223 break;
224 }
225 res += sprintf(buf + res, "%s ", slave->dev->name);
226 }
6603a6f2 227 read_unlock(&bond->lock);
1dcdcd69
WF
228 if (res)
229 buf[res-1] = '\n'; /* eat the leftover space */
dec1e90e 230
b76cdba9
MW
231 return res;
232}
233
234/*
d6641ccf 235 * Set the slaves in the current bond.
f9f3545e
JP
236 * This is supposed to be only thin wrapper for bond_enslave and bond_release.
237 * All hard work should be done there.
b76cdba9 238 */
43cb76d9
GKH
239static ssize_t bonding_store_slaves(struct device *d,
240 struct device_attribute *attr,
241 const char *buffer, size_t count)
b76cdba9
MW
242{
243 char command[IFNAMSIZ + 1] = { 0, };
244 char *ifname;
f9f3545e
JP
245 int res, ret = count;
246 struct net_device *dev;
43cb76d9 247 struct bonding *bond = to_bond(d);
b76cdba9 248
496a60cd
EB
249 if (!rtnl_trylock())
250 return restart_syscall();
027ea041 251
b76cdba9
MW
252 sscanf(buffer, "%16s", command); /* IFNAMSIZ*/
253 ifname = command + 1;
254 if ((strlen(command) <= 1) ||
255 !dev_valid_name(ifname))
256 goto err_no_cmd;
257
f9f3545e
JP
258 dev = __dev_get_by_name(dev_net(bond->dev), ifname);
259 if (!dev) {
260 pr_info("%s: Interface %s does not exist!\n",
261 bond->dev->name, ifname);
262 ret = -ENODEV;
263 goto out;
264 }
b76cdba9 265
f9f3545e
JP
266 switch (command[0]) {
267 case '+':
268 pr_info("%s: Adding slave %s.\n", bond->dev->name, dev->name);
b76cdba9 269 res = bond_enslave(bond->dev, dev);
f9f3545e 270 break;
3d632c3f 271
f9f3545e
JP
272 case '-':
273 pr_info("%s: Removing slave %s.\n", bond->dev->name, dev->name);
274 res = bond_release(bond->dev, dev);
275 break;
b76cdba9 276
f9f3545e
JP
277 default:
278 goto err_no_cmd;
b76cdba9
MW
279 }
280
f9f3545e
JP
281 if (res)
282 ret = res;
283 goto out;
284
b76cdba9 285err_no_cmd:
a4aee5c8
JP
286 pr_err("no command found in slaves file for bond %s. Use +ifname or -ifname.\n",
287 bond->dev->name);
b76cdba9
MW
288 ret = -EPERM;
289
290out:
027ea041 291 rtnl_unlock();
b76cdba9
MW
292 return ret;
293}
294
3d632c3f
SH
295static DEVICE_ATTR(slaves, S_IRUGO | S_IWUSR, bonding_show_slaves,
296 bonding_store_slaves);
b76cdba9
MW
297
298/*
299 * Show and set the bonding mode. The bond interface must be down to
300 * change the mode.
301 */
43cb76d9
GKH
302static ssize_t bonding_show_mode(struct device *d,
303 struct device_attribute *attr, char *buf)
b76cdba9 304{
43cb76d9 305 struct bonding *bond = to_bond(d);
b76cdba9
MW
306
307 return sprintf(buf, "%s %d\n",
308 bond_mode_tbl[bond->params.mode].modename,
7bd46508 309 bond->params.mode);
b76cdba9
MW
310}
311
43cb76d9
GKH
312static ssize_t bonding_store_mode(struct device *d,
313 struct device_attribute *attr,
314 const char *buf, size_t count)
b76cdba9
MW
315{
316 int new_value, ret = count;
43cb76d9 317 struct bonding *bond = to_bond(d);
b76cdba9 318
ea6836dd 319 if (!rtnl_trylock())
320 return restart_syscall();
321
b76cdba9 322 if (bond->dev->flags & IFF_UP) {
a4aee5c8
JP
323 pr_err("unable to update mode of %s because interface is up.\n",
324 bond->dev->name);
b76cdba9
MW
325 ret = -EPERM;
326 goto out;
327 }
328
dec1e90e 329 if (!list_empty(&bond->slave_list)) {
4a8bb7e2
VF
330 pr_err("unable to update mode of %s because it has slaves.\n",
331 bond->dev->name);
332 ret = -EPERM;
333 goto out;
334 }
335
ece95f7f 336 new_value = bond_parse_parm(buf, bond_mode_tbl);
b76cdba9 337 if (new_value < 0) {
a4aee5c8
JP
338 pr_err("%s: Ignoring invalid mode value %.*s.\n",
339 bond->dev->name, (int)strlen(buf) - 1, buf);
b76cdba9
MW
340 ret = -EINVAL;
341 goto out;
c5cb002f
AG
342 }
343 if ((new_value == BOND_MODE_ALB ||
344 new_value == BOND_MODE_TLB) &&
345 bond->params.arp_interval) {
346 pr_err("%s: %s mode is incompatible with arp monitoring.\n",
347 bond->dev->name, bond_mode_tbl[new_value].modename);
348 ret = -EINVAL;
349 goto out;
350 }
8f903c70 351
5bb9e0b5 352 /* don't cache arp_validate between modes */
353 bond->params.arp_validate = BOND_ARP_VALIDATE_NONE;
c5cb002f
AG
354 bond->params.mode = new_value;
355 bond_set_mode_ops(bond, bond->params.mode);
356 pr_info("%s: setting mode to %s (%d).\n",
357 bond->dev->name, bond_mode_tbl[new_value].modename,
358 new_value);
b76cdba9 359out:
ea6836dd 360 rtnl_unlock();
b76cdba9
MW
361 return ret;
362}
3d632c3f
SH
363static DEVICE_ATTR(mode, S_IRUGO | S_IWUSR,
364 bonding_show_mode, bonding_store_mode);
b76cdba9
MW
365
366/*
3d632c3f 367 * Show and set the bonding transmit hash method.
b76cdba9 368 */
43cb76d9
GKH
369static ssize_t bonding_show_xmit_hash(struct device *d,
370 struct device_attribute *attr,
371 char *buf)
b76cdba9 372{
43cb76d9 373 struct bonding *bond = to_bond(d);
b76cdba9 374
8e4b9329
WF
375 return sprintf(buf, "%s %d\n",
376 xmit_hashtype_tbl[bond->params.xmit_policy].modename,
377 bond->params.xmit_policy);
b76cdba9
MW
378}
379
43cb76d9
GKH
380static ssize_t bonding_store_xmit_hash(struct device *d,
381 struct device_attribute *attr,
382 const char *buf, size_t count)
b76cdba9
MW
383{
384 int new_value, ret = count;
43cb76d9 385 struct bonding *bond = to_bond(d);
b76cdba9 386
ece95f7f 387 new_value = bond_parse_parm(buf, xmit_hashtype_tbl);
b76cdba9 388 if (new_value < 0) {
a4aee5c8 389 pr_err("%s: Ignoring invalid xmit hash policy value %.*s.\n",
b76cdba9
MW
390 bond->dev->name,
391 (int)strlen(buf) - 1, buf);
392 ret = -EINVAL;
b76cdba9
MW
393 } else {
394 bond->params.xmit_policy = new_value;
395 bond_set_mode_ops(bond, bond->params.mode);
a4aee5c8 396 pr_info("%s: setting xmit hash policy to %s (%d).\n",
3d632c3f
SH
397 bond->dev->name,
398 xmit_hashtype_tbl[new_value].modename, new_value);
b76cdba9 399 }
53edee2c 400
b76cdba9
MW
401 return ret;
402}
3d632c3f
SH
403static DEVICE_ATTR(xmit_hash_policy, S_IRUGO | S_IWUSR,
404 bonding_show_xmit_hash, bonding_store_xmit_hash);
b76cdba9 405
f5b2b966
JV
406/*
407 * Show and set arp_validate.
408 */
43cb76d9
GKH
409static ssize_t bonding_show_arp_validate(struct device *d,
410 struct device_attribute *attr,
411 char *buf)
f5b2b966 412{
43cb76d9 413 struct bonding *bond = to_bond(d);
f5b2b966
JV
414
415 return sprintf(buf, "%s %d\n",
416 arp_validate_tbl[bond->params.arp_validate].modename,
7bd46508 417 bond->params.arp_validate);
f5b2b966
JV
418}
419
43cb76d9
GKH
420static ssize_t bonding_store_arp_validate(struct device *d,
421 struct device_attribute *attr,
422 const char *buf, size_t count)
f5b2b966 423{
43cb76d9 424 struct bonding *bond = to_bond(d);
5bb9e0b5 425 int new_value, ret = count;
f5b2b966 426
5c5038dc 427 if (!rtnl_trylock())
428 return restart_syscall();
ece95f7f 429 new_value = bond_parse_parm(buf, arp_validate_tbl);
f5b2b966 430 if (new_value < 0) {
a4aee5c8 431 pr_err("%s: Ignoring invalid arp_validate value %s\n",
f5b2b966 432 bond->dev->name, buf);
5c5038dc 433 ret = -EINVAL;
434 goto out;
f5b2b966 435 }
5bb9e0b5 436 if (bond->params.mode != BOND_MODE_ACTIVEBACKUP) {
a4aee5c8 437 pr_err("%s: arp_validate only supported in active-backup mode.\n",
f5b2b966 438 bond->dev->name);
5c5038dc 439 ret = -EINVAL;
440 goto out;
f5b2b966 441 }
a4aee5c8
JP
442 pr_info("%s: setting arp_validate to %s (%d).\n",
443 bond->dev->name, arp_validate_tbl[new_value].modename,
444 new_value);
f5b2b966 445
5bb9e0b5 446 if (bond->dev->flags & IFF_UP) {
447 if (!new_value)
448 bond->recv_probe = NULL;
449 else if (bond->params.arp_interval)
450 bond->recv_probe = bond_arp_rcv;
451 }
f5b2b966 452 bond->params.arp_validate = new_value;
5c5038dc 453out:
454 rtnl_unlock();
f5b2b966 455
5c5038dc 456 return ret;
f5b2b966
JV
457}
458
3d632c3f
SH
459static DEVICE_ATTR(arp_validate, S_IRUGO | S_IWUSR, bonding_show_arp_validate,
460 bonding_store_arp_validate);
8599b52e
VF
461/*
462 * Show and set arp_all_targets.
463 */
464static ssize_t bonding_show_arp_all_targets(struct device *d,
465 struct device_attribute *attr,
466 char *buf)
467{
468 struct bonding *bond = to_bond(d);
469 int value = bond->params.arp_all_targets;
470
471 return sprintf(buf, "%s %d\n", arp_all_targets_tbl[value].modename,
472 value);
473}
474
475static ssize_t bonding_store_arp_all_targets(struct device *d,
476 struct device_attribute *attr,
477 const char *buf, size_t count)
478{
479 struct bonding *bond = to_bond(d);
480 int new_value;
481
482 new_value = bond_parse_parm(buf, arp_all_targets_tbl);
483 if (new_value < 0) {
484 pr_err("%s: Ignoring invalid arp_all_targets value %s\n",
485 bond->dev->name, buf);
486 return -EINVAL;
487 }
488 pr_info("%s: setting arp_all_targets to %s (%d).\n",
489 bond->dev->name, arp_all_targets_tbl[new_value].modename,
490 new_value);
491
492 bond->params.arp_all_targets = new_value;
493
494 return count;
495}
496
497static DEVICE_ATTR(arp_all_targets, S_IRUGO | S_IWUSR,
498 bonding_show_arp_all_targets, bonding_store_arp_all_targets);
f5b2b966 499
dd957c57
JV
500/*
501 * Show and store fail_over_mac. User only allowed to change the
502 * value when there are no slaves.
503 */
3d632c3f
SH
504static ssize_t bonding_show_fail_over_mac(struct device *d,
505 struct device_attribute *attr,
506 char *buf)
dd957c57
JV
507{
508 struct bonding *bond = to_bond(d);
509
3915c1e8
JV
510 return sprintf(buf, "%s %d\n",
511 fail_over_mac_tbl[bond->params.fail_over_mac].modename,
512 bond->params.fail_over_mac);
dd957c57
JV
513}
514
3d632c3f
SH
515static ssize_t bonding_store_fail_over_mac(struct device *d,
516 struct device_attribute *attr,
517 const char *buf, size_t count)
dd957c57 518{
9402b746 519 int new_value, ret = count;
dd957c57
JV
520 struct bonding *bond = to_bond(d);
521
9402b746 522 if (!rtnl_trylock())
523 return restart_syscall();
524
dec1e90e 525 if (!list_empty(&bond->slave_list)) {
a4aee5c8 526 pr_err("%s: Can't alter fail_over_mac with slaves in bond.\n",
dd957c57 527 bond->dev->name);
9402b746 528 ret = -EPERM;
529 goto out;
dd957c57
JV
530 }
531
3915c1e8
JV
532 new_value = bond_parse_parm(buf, fail_over_mac_tbl);
533 if (new_value < 0) {
a4aee5c8 534 pr_err("%s: Ignoring invalid fail_over_mac value %s.\n",
3915c1e8 535 bond->dev->name, buf);
9402b746 536 ret = -EINVAL;
537 goto out;
dd957c57
JV
538 }
539
3915c1e8 540 bond->params.fail_over_mac = new_value;
a4aee5c8
JP
541 pr_info("%s: Setting fail_over_mac to %s (%d).\n",
542 bond->dev->name, fail_over_mac_tbl[new_value].modename,
543 new_value);
3915c1e8 544
9402b746 545out:
546 rtnl_unlock();
547 return ret;
dd957c57
JV
548}
549
3d632c3f
SH
550static DEVICE_ATTR(fail_over_mac, S_IRUGO | S_IWUSR,
551 bonding_show_fail_over_mac, bonding_store_fail_over_mac);
dd957c57 552
b76cdba9
MW
553/*
554 * Show and set the arp timer interval. There are two tricky bits
555 * here. First, if ARP monitoring is activated, then we must disable
556 * MII monitoring. Second, if the ARP timer isn't running, we must
557 * start it.
558 */
43cb76d9
GKH
559static ssize_t bonding_show_arp_interval(struct device *d,
560 struct device_attribute *attr,
561 char *buf)
b76cdba9 562{
43cb76d9 563 struct bonding *bond = to_bond(d);
b76cdba9 564
7bd46508 565 return sprintf(buf, "%d\n", bond->params.arp_interval);
b76cdba9
MW
566}
567
43cb76d9
GKH
568static ssize_t bonding_store_arp_interval(struct device *d,
569 struct device_attribute *attr,
570 const char *buf, size_t count)
b76cdba9 571{
43cb76d9 572 struct bonding *bond = to_bond(d);
5bb9e0b5 573 int new_value, ret = count;
b76cdba9 574
fbb0c41b 575 if (!rtnl_trylock())
576 return restart_syscall();
b76cdba9 577 if (sscanf(buf, "%d", &new_value) != 1) {
a4aee5c8 578 pr_err("%s: no arp_interval value specified.\n",
b76cdba9
MW
579 bond->dev->name);
580 ret = -EINVAL;
581 goto out;
582 }
583 if (new_value < 0) {
1bc7db16 584 pr_err("%s: Invalid arp_interval value %d not in range 0-%d; rejected.\n",
b76cdba9
MW
585 bond->dev->name, new_value, INT_MAX);
586 ret = -EINVAL;
587 goto out;
588 }
c5cb002f
AG
589 if (bond->params.mode == BOND_MODE_ALB ||
590 bond->params.mode == BOND_MODE_TLB) {
591 pr_info("%s: ARP monitoring cannot be used with ALB/TLB. Only MII monitoring is supported on %s.\n",
592 bond->dev->name, bond->dev->name);
593 ret = -EINVAL;
594 goto out;
595 }
a4aee5c8
JP
596 pr_info("%s: Setting ARP monitoring interval to %d.\n",
597 bond->dev->name, new_value);
b76cdba9 598 bond->params.arp_interval = new_value;
1bc7db16 599 if (new_value) {
600 if (bond->params.miimon) {
601 pr_info("%s: ARP monitoring cannot be used with MII monitoring. %s Disabling MII monitoring.\n",
602 bond->dev->name, bond->dev->name);
603 bond->params.miimon = 0;
604 }
605 if (!bond->params.arp_targets[0])
606 pr_info("%s: ARP monitoring has been set up, but no ARP targets have been specified.\n",
607 bond->dev->name);
b76cdba9
MW
608 }
609 if (bond->dev->flags & IFF_UP) {
610 /* If the interface is up, we may need to fire off
611 * the ARP timer. If the interface is down, the
612 * timer will get fired off when the open function
613 * is called.
614 */
1bc7db16 615 if (!new_value) {
5bb9e0b5 616 if (bond->params.arp_validate)
617 bond->recv_probe = NULL;
1bc7db16 618 cancel_delayed_work_sync(&bond->arp_work);
619 } else {
5bb9e0b5 620 /* arp_validate can be set only in active-backup mode */
621 if (bond->params.arp_validate)
622 bond->recv_probe = bond_arp_rcv;
1bc7db16 623 cancel_delayed_work_sync(&bond->mii_work);
624 queue_delayed_work(bond->wq, &bond->arp_work, 0);
625 }
b76cdba9 626 }
b76cdba9 627out:
fbb0c41b 628 rtnl_unlock();
b76cdba9
MW
629 return ret;
630}
3d632c3f
SH
631static DEVICE_ATTR(arp_interval, S_IRUGO | S_IWUSR,
632 bonding_show_arp_interval, bonding_store_arp_interval);
b76cdba9
MW
633
634/*
635 * Show and set the arp targets.
636 */
43cb76d9
GKH
637static ssize_t bonding_show_arp_targets(struct device *d,
638 struct device_attribute *attr,
639 char *buf)
b76cdba9
MW
640{
641 int i, res = 0;
43cb76d9 642 struct bonding *bond = to_bond(d);
b76cdba9
MW
643
644 for (i = 0; i < BOND_MAX_ARP_TARGETS; i++) {
645 if (bond->params.arp_targets[i])
63779436
HH
646 res += sprintf(buf + res, "%pI4 ",
647 &bond->params.arp_targets[i]);
b76cdba9 648 }
1dcdcd69
WF
649 if (res)
650 buf[res-1] = '\n'; /* eat the leftover space */
b76cdba9
MW
651 return res;
652}
653
43cb76d9
GKH
654static ssize_t bonding_store_arp_targets(struct device *d,
655 struct device_attribute *attr,
656 const char *buf, size_t count)
b76cdba9 657{
43cb76d9 658 struct bonding *bond = to_bond(d);
8599b52e
VF
659 struct slave *slave;
660 __be32 newtarget, *targets;
661 unsigned long *targets_rx;
662 int ind, i, j, ret = -EINVAL;
b76cdba9
MW
663
664 targets = bond->params.arp_targets;
665 newtarget = in_aton(buf + 1);
666 /* look for adds */
667 if (buf[0] == '+') {
d3bb52b0 668 if ((newtarget == 0) || (newtarget == htonl(INADDR_BROADCAST))) {
a4aee5c8 669 pr_err("%s: invalid ARP target %pI4 specified for addition\n",
63779436 670 bond->dev->name, &newtarget);
b76cdba9
MW
671 goto out;
672 }
87a7b84b
VF
673
674 if (bond_get_targets_ip(targets, newtarget) != -1) { /* dup */
675 pr_err("%s: ARP target %pI4 is already present\n",
676 bond->dev->name, &newtarget);
677 goto out;
b76cdba9 678 }
87a7b84b 679
8599b52e
VF
680 ind = bond_get_targets_ip(targets, 0); /* first free slot */
681 if (ind == -1) {
a4aee5c8 682 pr_err("%s: ARP target table is full!\n",
b76cdba9 683 bond->dev->name);
b76cdba9
MW
684 goto out;
685 }
686
87a7b84b
VF
687 pr_info("%s: adding ARP target %pI4.\n", bond->dev->name,
688 &newtarget);
8599b52e
VF
689 /* not to race with bond_arp_rcv */
690 write_lock_bh(&bond->lock);
dec1e90e 691 bond_for_each_slave(bond, slave)
8599b52e
VF
692 slave->target_last_arp_rx[ind] = jiffies;
693 targets[ind] = newtarget;
694 write_unlock_bh(&bond->lock);
3d632c3f 695 } else if (buf[0] == '-') {
d3bb52b0 696 if ((newtarget == 0) || (newtarget == htonl(INADDR_BROADCAST))) {
a4aee5c8 697 pr_err("%s: invalid ARP target %pI4 specified for removal\n",
63779436 698 bond->dev->name, &newtarget);
b76cdba9
MW
699 goto out;
700 }
701
8599b52e
VF
702 ind = bond_get_targets_ip(targets, newtarget);
703 if (ind == -1) {
704 pr_err("%s: unable to remove nonexistent ARP target %pI4.\n",
a4aee5c8 705 bond->dev->name, &newtarget);
b76cdba9
MW
706 goto out;
707 }
87a7b84b 708
8599b52e
VF
709 if (ind == 0 && !targets[1] && bond->params.arp_interval)
710 pr_warn("%s: removing last arp target with arp_interval on\n",
711 bond->dev->name);
712
87a7b84b
VF
713 pr_info("%s: removing ARP target %pI4.\n", bond->dev->name,
714 &newtarget);
8599b52e
VF
715
716 write_lock_bh(&bond->lock);
dec1e90e 717 bond_for_each_slave(bond, slave) {
8599b52e
VF
718 targets_rx = slave->target_last_arp_rx;
719 j = ind;
720 for (; (j < BOND_MAX_ARP_TARGETS-1) && targets[j+1]; j++)
721 targets_rx[j] = targets_rx[j+1];
722 targets_rx[j] = 0;
723 }
724 for (i = ind; (i < BOND_MAX_ARP_TARGETS-1) && targets[i+1]; i++)
87a7b84b
VF
725 targets[i] = targets[i+1];
726 targets[i] = 0;
8599b52e 727 write_unlock_bh(&bond->lock);
3d632c3f 728 } else {
a4aee5c8
JP
729 pr_err("no command found in arp_ip_targets file for bond %s. Use +<addr> or -<addr>.\n",
730 bond->dev->name);
b76cdba9
MW
731 ret = -EPERM;
732 goto out;
733 }
734
87a7b84b 735 ret = count;
b76cdba9
MW
736out:
737 return ret;
738}
43cb76d9 739static DEVICE_ATTR(arp_ip_target, S_IRUGO | S_IWUSR , bonding_show_arp_targets, bonding_store_arp_targets);
b76cdba9
MW
740
741/*
742 * Show and set the up and down delays. These must be multiples of the
743 * MII monitoring value, and are stored internally as the multiplier.
744 * Thus, we must translate to MS for the real world.
745 */
43cb76d9
GKH
746static ssize_t bonding_show_downdelay(struct device *d,
747 struct device_attribute *attr,
748 char *buf)
b76cdba9 749{
43cb76d9 750 struct bonding *bond = to_bond(d);
b76cdba9 751
7bd46508 752 return sprintf(buf, "%d\n", bond->params.downdelay * bond->params.miimon);
b76cdba9
MW
753}
754
43cb76d9
GKH
755static ssize_t bonding_store_downdelay(struct device *d,
756 struct device_attribute *attr,
757 const char *buf, size_t count)
b76cdba9
MW
758{
759 int new_value, ret = count;
43cb76d9 760 struct bonding *bond = to_bond(d);
b76cdba9
MW
761
762 if (!(bond->params.miimon)) {
a4aee5c8 763 pr_err("%s: Unable to set down delay as MII monitoring is disabled\n",
b76cdba9
MW
764 bond->dev->name);
765 ret = -EPERM;
766 goto out;
767 }
768
769 if (sscanf(buf, "%d", &new_value) != 1) {
a4aee5c8 770 pr_err("%s: no down delay value specified.\n", bond->dev->name);
b76cdba9
MW
771 ret = -EINVAL;
772 goto out;
773 }
774 if (new_value < 0) {
a4aee5c8 775 pr_err("%s: Invalid down delay value %d not in range %d-%d; rejected.\n",
1bc7db16 776 bond->dev->name, new_value, 0, INT_MAX);
b76cdba9
MW
777 ret = -EINVAL;
778 goto out;
779 } else {
780 if ((new_value % bond->params.miimon) != 0) {
a4aee5c8 781 pr_warning("%s: Warning: down delay (%d) is not a multiple of miimon (%d), delay rounded to %d ms\n",
e5e2a8fd
JP
782 bond->dev->name, new_value,
783 bond->params.miimon,
784 (new_value / bond->params.miimon) *
785 bond->params.miimon);
b76cdba9
MW
786 }
787 bond->params.downdelay = new_value / bond->params.miimon;
a4aee5c8
JP
788 pr_info("%s: Setting down delay to %d.\n",
789 bond->dev->name,
790 bond->params.downdelay * bond->params.miimon);
b76cdba9
MW
791
792 }
793
794out:
795 return ret;
796}
3d632c3f
SH
797static DEVICE_ATTR(downdelay, S_IRUGO | S_IWUSR,
798 bonding_show_downdelay, bonding_store_downdelay);
b76cdba9 799
43cb76d9
GKH
800static ssize_t bonding_show_updelay(struct device *d,
801 struct device_attribute *attr,
802 char *buf)
b76cdba9 803{
43cb76d9 804 struct bonding *bond = to_bond(d);
b76cdba9 805
7bd46508 806 return sprintf(buf, "%d\n", bond->params.updelay * bond->params.miimon);
b76cdba9
MW
807
808}
809
43cb76d9
GKH
810static ssize_t bonding_store_updelay(struct device *d,
811 struct device_attribute *attr,
812 const char *buf, size_t count)
b76cdba9
MW
813{
814 int new_value, ret = count;
43cb76d9 815 struct bonding *bond = to_bond(d);
b76cdba9
MW
816
817 if (!(bond->params.miimon)) {
a4aee5c8 818 pr_err("%s: Unable to set up delay as MII monitoring is disabled\n",
b76cdba9
MW
819 bond->dev->name);
820 ret = -EPERM;
821 goto out;
822 }
823
824 if (sscanf(buf, "%d", &new_value) != 1) {
a4aee5c8 825 pr_err("%s: no up delay value specified.\n",
b76cdba9
MW
826 bond->dev->name);
827 ret = -EINVAL;
828 goto out;
829 }
830 if (new_value < 0) {
1bc7db16 831 pr_err("%s: Invalid up delay value %d not in range %d-%d; rejected.\n",
832 bond->dev->name, new_value, 0, INT_MAX);
b76cdba9
MW
833 ret = -EINVAL;
834 goto out;
835 } else {
836 if ((new_value % bond->params.miimon) != 0) {
a4aee5c8 837 pr_warning("%s: Warning: up delay (%d) is not a multiple of miimon (%d), updelay rounded to %d ms\n",
e5e2a8fd
JP
838 bond->dev->name, new_value,
839 bond->params.miimon,
840 (new_value / bond->params.miimon) *
841 bond->params.miimon);
b76cdba9
MW
842 }
843 bond->params.updelay = new_value / bond->params.miimon;
a4aee5c8
JP
844 pr_info("%s: Setting up delay to %d.\n",
845 bond->dev->name,
846 bond->params.updelay * bond->params.miimon);
b76cdba9
MW
847 }
848
849out:
850 return ret;
851}
3d632c3f
SH
852static DEVICE_ATTR(updelay, S_IRUGO | S_IWUSR,
853 bonding_show_updelay, bonding_store_updelay);
b76cdba9
MW
854
855/*
856 * Show and set the LACP interval. Interface must be down, and the mode
857 * must be set to 802.3ad mode.
858 */
43cb76d9
GKH
859static ssize_t bonding_show_lacp(struct device *d,
860 struct device_attribute *attr,
861 char *buf)
b76cdba9 862{
43cb76d9 863 struct bonding *bond = to_bond(d);
b76cdba9
MW
864
865 return sprintf(buf, "%s %d\n",
866 bond_lacp_tbl[bond->params.lacp_fast].modename,
7bd46508 867 bond->params.lacp_fast);
b76cdba9
MW
868}
869
43cb76d9
GKH
870static ssize_t bonding_store_lacp(struct device *d,
871 struct device_attribute *attr,
872 const char *buf, size_t count)
b76cdba9 873{
43cb76d9 874 struct bonding *bond = to_bond(d);
c509316b 875 int new_value, ret = count;
876
877 if (!rtnl_trylock())
878 return restart_syscall();
b76cdba9
MW
879
880 if (bond->dev->flags & IFF_UP) {
a4aee5c8 881 pr_err("%s: Unable to update LACP rate because interface is up.\n",
b76cdba9
MW
882 bond->dev->name);
883 ret = -EPERM;
884 goto out;
885 }
886
887 if (bond->params.mode != BOND_MODE_8023AD) {
a4aee5c8 888 pr_err("%s: Unable to update LACP rate because bond is not in 802.3ad mode.\n",
b76cdba9
MW
889 bond->dev->name);
890 ret = -EPERM;
891 goto out;
892 }
893
ece95f7f 894 new_value = bond_parse_parm(buf, bond_lacp_tbl);
b76cdba9
MW
895
896 if ((new_value == 1) || (new_value == 0)) {
897 bond->params.lacp_fast = new_value;
ba824a8b 898 bond_3ad_update_lacp_rate(bond);
a4aee5c8 899 pr_info("%s: Setting LACP rate to %s (%d).\n",
3d632c3f
SH
900 bond->dev->name, bond_lacp_tbl[new_value].modename,
901 new_value);
b76cdba9 902 } else {
a4aee5c8 903 pr_err("%s: Ignoring invalid LACP rate value %.*s.\n",
3d632c3f 904 bond->dev->name, (int)strlen(buf) - 1, buf);
b76cdba9
MW
905 ret = -EINVAL;
906 }
907out:
c509316b 908 rtnl_unlock();
909
b76cdba9
MW
910 return ret;
911}
3d632c3f
SH
912static DEVICE_ATTR(lacp_rate, S_IRUGO | S_IWUSR,
913 bonding_show_lacp, bonding_store_lacp);
b76cdba9 914
655f8919 915static ssize_t bonding_show_min_links(struct device *d,
916 struct device_attribute *attr,
917 char *buf)
918{
919 struct bonding *bond = to_bond(d);
920
921 return sprintf(buf, "%d\n", bond->params.min_links);
922}
923
924static ssize_t bonding_store_min_links(struct device *d,
925 struct device_attribute *attr,
926 const char *buf, size_t count)
927{
928 struct bonding *bond = to_bond(d);
929 int ret;
930 unsigned int new_value;
931
932 ret = kstrtouint(buf, 0, &new_value);
933 if (ret < 0) {
934 pr_err("%s: Ignoring invalid min links value %s.\n",
935 bond->dev->name, buf);
936 return ret;
937 }
938
939 pr_info("%s: Setting min links value to %u\n",
940 bond->dev->name, new_value);
941 bond->params.min_links = new_value;
942 return count;
943}
944static DEVICE_ATTR(min_links, S_IRUGO | S_IWUSR,
945 bonding_show_min_links, bonding_store_min_links);
946
fd989c83
JV
947static ssize_t bonding_show_ad_select(struct device *d,
948 struct device_attribute *attr,
949 char *buf)
950{
951 struct bonding *bond = to_bond(d);
952
953 return sprintf(buf, "%s %d\n",
954 ad_select_tbl[bond->params.ad_select].modename,
955 bond->params.ad_select);
956}
957
958
959static ssize_t bonding_store_ad_select(struct device *d,
960 struct device_attribute *attr,
961 const char *buf, size_t count)
962{
963 int new_value, ret = count;
964 struct bonding *bond = to_bond(d);
965
966 if (bond->dev->flags & IFF_UP) {
a4aee5c8
JP
967 pr_err("%s: Unable to update ad_select because interface is up.\n",
968 bond->dev->name);
fd989c83
JV
969 ret = -EPERM;
970 goto out;
971 }
972
973 new_value = bond_parse_parm(buf, ad_select_tbl);
974
975 if (new_value != -1) {
976 bond->params.ad_select = new_value;
a4aee5c8
JP
977 pr_info("%s: Setting ad_select to %s (%d).\n",
978 bond->dev->name, ad_select_tbl[new_value].modename,
979 new_value);
fd989c83 980 } else {
a4aee5c8 981 pr_err("%s: Ignoring invalid ad_select value %.*s.\n",
fd989c83
JV
982 bond->dev->name, (int)strlen(buf) - 1, buf);
983 ret = -EINVAL;
984 }
985out:
986 return ret;
987}
3d632c3f
SH
988static DEVICE_ATTR(ad_select, S_IRUGO | S_IWUSR,
989 bonding_show_ad_select, bonding_store_ad_select);
fd989c83 990
ad246c99
BH
991/*
992 * Show and set the number of peer notifications to send after a failover event.
993 */
994static ssize_t bonding_show_num_peer_notif(struct device *d,
995 struct device_attribute *attr,
996 char *buf)
997{
998 struct bonding *bond = to_bond(d);
999 return sprintf(buf, "%d\n", bond->params.num_peer_notif);
1000}
1001
1002static ssize_t bonding_store_num_peer_notif(struct device *d,
1003 struct device_attribute *attr,
1004 const char *buf, size_t count)
1005{
1006 struct bonding *bond = to_bond(d);
1007 int err = kstrtou8(buf, 10, &bond->params.num_peer_notif);
1008 return err ? err : count;
1009}
1010static DEVICE_ATTR(num_grat_arp, S_IRUGO | S_IWUSR,
1011 bonding_show_num_peer_notif, bonding_store_num_peer_notif);
1012static DEVICE_ATTR(num_unsol_na, S_IRUGO | S_IWUSR,
1013 bonding_show_num_peer_notif, bonding_store_num_peer_notif);
1014
b76cdba9
MW
1015/*
1016 * Show and set the MII monitor interval. There are two tricky bits
1017 * here. First, if MII monitoring is activated, then we must disable
1018 * ARP monitoring. Second, if the timer isn't running, we must
1019 * start it.
1020 */
43cb76d9
GKH
1021static ssize_t bonding_show_miimon(struct device *d,
1022 struct device_attribute *attr,
1023 char *buf)
b76cdba9 1024{
43cb76d9 1025 struct bonding *bond = to_bond(d);
b76cdba9 1026
7bd46508 1027 return sprintf(buf, "%d\n", bond->params.miimon);
b76cdba9
MW
1028}
1029
43cb76d9
GKH
1030static ssize_t bonding_store_miimon(struct device *d,
1031 struct device_attribute *attr,
1032 const char *buf, size_t count)
b76cdba9
MW
1033{
1034 int new_value, ret = count;
43cb76d9 1035 struct bonding *bond = to_bond(d);
b76cdba9 1036
fbb0c41b 1037 if (!rtnl_trylock())
1038 return restart_syscall();
b76cdba9 1039 if (sscanf(buf, "%d", &new_value) != 1) {
a4aee5c8 1040 pr_err("%s: no miimon value specified.\n",
b76cdba9
MW
1041 bond->dev->name);
1042 ret = -EINVAL;
1043 goto out;
1044 }
1045 if (new_value < 0) {
a4aee5c8 1046 pr_err("%s: Invalid miimon value %d not in range %d-%d; rejected.\n",
1bc7db16 1047 bond->dev->name, new_value, 0, INT_MAX);
b76cdba9
MW
1048 ret = -EINVAL;
1049 goto out;
1bc7db16 1050 }
1051 pr_info("%s: Setting MII monitoring interval to %d.\n",
1052 bond->dev->name, new_value);
1053 bond->params.miimon = new_value;
1054 if (bond->params.updelay)
1055 pr_info("%s: Note: Updating updelay (to %d) since it is a multiple of the miimon value.\n",
1056 bond->dev->name,
1057 bond->params.updelay * bond->params.miimon);
1058 if (bond->params.downdelay)
1059 pr_info("%s: Note: Updating downdelay (to %d) since it is a multiple of the miimon value.\n",
1060 bond->dev->name,
1061 bond->params.downdelay * bond->params.miimon);
1062 if (new_value && bond->params.arp_interval) {
1063 pr_info("%s: MII monitoring cannot be used with ARP monitoring. Disabling ARP monitoring...\n",
1064 bond->dev->name);
1065 bond->params.arp_interval = 0;
1066 if (bond->params.arp_validate)
1067 bond->params.arp_validate = BOND_ARP_VALIDATE_NONE;
1068 }
1069 if (bond->dev->flags & IFF_UP) {
1070 /* If the interface is up, we may need to fire off
1071 * the MII timer. If the interface is down, the
1072 * timer will get fired off when the open function
1073 * is called.
1074 */
1075 if (!new_value) {
1076 cancel_delayed_work_sync(&bond->mii_work);
1077 } else {
fbb0c41b 1078 cancel_delayed_work_sync(&bond->arp_work);
1079 queue_delayed_work(bond->wq, &bond->mii_work, 0);
b76cdba9
MW
1080 }
1081 }
1082out:
fbb0c41b 1083 rtnl_unlock();
b76cdba9
MW
1084 return ret;
1085}
3d632c3f
SH
1086static DEVICE_ATTR(miimon, S_IRUGO | S_IWUSR,
1087 bonding_show_miimon, bonding_store_miimon);
b76cdba9
MW
1088
1089/*
1090 * Show and set the primary slave. The store function is much
1091 * simpler than bonding_store_slaves function because it only needs to
1092 * handle one interface name.
1093 * The bond must be a mode that supports a primary for this be
1094 * set.
1095 */
43cb76d9
GKH
1096static ssize_t bonding_show_primary(struct device *d,
1097 struct device_attribute *attr,
1098 char *buf)
b76cdba9
MW
1099{
1100 int count = 0;
43cb76d9 1101 struct bonding *bond = to_bond(d);
b76cdba9
MW
1102
1103 if (bond->primary_slave)
7bd46508 1104 count = sprintf(buf, "%s\n", bond->primary_slave->dev->name);
b76cdba9
MW
1105
1106 return count;
1107}
1108
43cb76d9
GKH
1109static ssize_t bonding_store_primary(struct device *d,
1110 struct device_attribute *attr,
1111 const char *buf, size_t count)
b76cdba9 1112{
43cb76d9 1113 struct bonding *bond = to_bond(d);
f4bb2e9c 1114 char ifname[IFNAMSIZ];
dec1e90e 1115 struct slave *slave;
b76cdba9 1116
496a60cd
EB
1117 if (!rtnl_trylock())
1118 return restart_syscall();
e843fa50 1119 block_netpoll_tx();
e934dd78
JV
1120 read_lock(&bond->lock);
1121 write_lock_bh(&bond->curr_slave_lock);
1122
b76cdba9 1123 if (!USES_PRIMARY(bond->params.mode)) {
a4aee5c8
JP
1124 pr_info("%s: Unable to set primary slave; %s is in mode %d\n",
1125 bond->dev->name, bond->dev->name, bond->params.mode);
f4bb2e9c
AG
1126 goto out;
1127 }
b76cdba9 1128
eb6e98a1 1129 sscanf(buf, "%15s", ifname); /* IFNAMSIZ */
b76cdba9 1130
f4bb2e9c
AG
1131 /* check to see if we are clearing primary */
1132 if (!strlen(ifname) || buf[0] == '\n') {
1133 pr_info("%s: Setting primary slave to None.\n",
1134 bond->dev->name);
1135 bond->primary_slave = NULL;
eb492f74 1136 memset(bond->params.primary, 0, sizeof(bond->params.primary));
f4bb2e9c
AG
1137 bond_select_active_slave(bond);
1138 goto out;
1139 }
1140
dec1e90e 1141 bond_for_each_slave(bond, slave) {
f4bb2e9c
AG
1142 if (strncmp(slave->dev->name, ifname, IFNAMSIZ) == 0) {
1143 pr_info("%s: Setting %s as primary slave.\n",
1144 bond->dev->name, slave->dev->name);
1145 bond->primary_slave = slave;
1146 strcpy(bond->params.primary, slave->dev->name);
1147 bond_select_active_slave(bond);
1148 goto out;
b76cdba9
MW
1149 }
1150 }
f4bb2e9c 1151
8a93664d
WP
1152 strncpy(bond->params.primary, ifname, IFNAMSIZ);
1153 bond->params.primary[IFNAMSIZ - 1] = 0;
1154
1155 pr_info("%s: Recording %s as primary, "
1156 "but it has not been enslaved to %s yet.\n",
1157 bond->dev->name, ifname, bond->dev->name);
b76cdba9 1158out:
e934dd78
JV
1159 write_unlock_bh(&bond->curr_slave_lock);
1160 read_unlock(&bond->lock);
e843fa50 1161 unblock_netpoll_tx();
6603a6f2
JV
1162 rtnl_unlock();
1163
b76cdba9
MW
1164 return count;
1165}
3d632c3f
SH
1166static DEVICE_ATTR(primary, S_IRUGO | S_IWUSR,
1167 bonding_show_primary, bonding_store_primary);
b76cdba9 1168
a549952a
JP
1169/*
1170 * Show and set the primary_reselect flag.
1171 */
1172static ssize_t bonding_show_primary_reselect(struct device *d,
1173 struct device_attribute *attr,
1174 char *buf)
1175{
1176 struct bonding *bond = to_bond(d);
1177
1178 return sprintf(buf, "%s %d\n",
1179 pri_reselect_tbl[bond->params.primary_reselect].modename,
1180 bond->params.primary_reselect);
1181}
1182
1183static ssize_t bonding_store_primary_reselect(struct device *d,
1184 struct device_attribute *attr,
1185 const char *buf, size_t count)
1186{
1187 int new_value, ret = count;
1188 struct bonding *bond = to_bond(d);
1189
1190 if (!rtnl_trylock())
1191 return restart_syscall();
1192
1193 new_value = bond_parse_parm(buf, pri_reselect_tbl);
1194 if (new_value < 0) {
a4aee5c8 1195 pr_err("%s: Ignoring invalid primary_reselect value %.*s.\n",
a549952a
JP
1196 bond->dev->name,
1197 (int) strlen(buf) - 1, buf);
1198 ret = -EINVAL;
1199 goto out;
1200 }
1201
1202 bond->params.primary_reselect = new_value;
a4aee5c8 1203 pr_info("%s: setting primary_reselect to %s (%d).\n",
a549952a
JP
1204 bond->dev->name, pri_reselect_tbl[new_value].modename,
1205 new_value);
1206
e843fa50 1207 block_netpoll_tx();
a549952a
JP
1208 read_lock(&bond->lock);
1209 write_lock_bh(&bond->curr_slave_lock);
1210 bond_select_active_slave(bond);
1211 write_unlock_bh(&bond->curr_slave_lock);
1212 read_unlock(&bond->lock);
e843fa50 1213 unblock_netpoll_tx();
a549952a
JP
1214out:
1215 rtnl_unlock();
1216 return ret;
1217}
1218static DEVICE_ATTR(primary_reselect, S_IRUGO | S_IWUSR,
1219 bonding_show_primary_reselect,
1220 bonding_store_primary_reselect);
1221
b76cdba9
MW
1222/*
1223 * Show and set the use_carrier flag.
1224 */
43cb76d9
GKH
1225static ssize_t bonding_show_carrier(struct device *d,
1226 struct device_attribute *attr,
1227 char *buf)
b76cdba9 1228{
43cb76d9 1229 struct bonding *bond = to_bond(d);
b76cdba9 1230
7bd46508 1231 return sprintf(buf, "%d\n", bond->params.use_carrier);
b76cdba9
MW
1232}
1233
43cb76d9
GKH
1234static ssize_t bonding_store_carrier(struct device *d,
1235 struct device_attribute *attr,
1236 const char *buf, size_t count)
b76cdba9
MW
1237{
1238 int new_value, ret = count;
43cb76d9 1239 struct bonding *bond = to_bond(d);
b76cdba9
MW
1240
1241
1242 if (sscanf(buf, "%d", &new_value) != 1) {
a4aee5c8 1243 pr_err("%s: no use_carrier value specified.\n",
b76cdba9
MW
1244 bond->dev->name);
1245 ret = -EINVAL;
1246 goto out;
1247 }
1248 if ((new_value == 0) || (new_value == 1)) {
1249 bond->params.use_carrier = new_value;
a4aee5c8
JP
1250 pr_info("%s: Setting use_carrier to %d.\n",
1251 bond->dev->name, new_value);
b76cdba9 1252 } else {
a4aee5c8
JP
1253 pr_info("%s: Ignoring invalid use_carrier value %d.\n",
1254 bond->dev->name, new_value);
b76cdba9
MW
1255 }
1256out:
672bda33 1257 return ret;
b76cdba9 1258}
3d632c3f
SH
1259static DEVICE_ATTR(use_carrier, S_IRUGO | S_IWUSR,
1260 bonding_show_carrier, bonding_store_carrier);
b76cdba9
MW
1261
1262
1263/*
1264 * Show and set currently active_slave.
1265 */
43cb76d9
GKH
1266static ssize_t bonding_show_active_slave(struct device *d,
1267 struct device_attribute *attr,
1268 char *buf)
b76cdba9 1269{
43cb76d9 1270 struct bonding *bond = to_bond(d);
278b2083 1271 struct slave *curr;
16cd0160 1272 int count = 0;
b76cdba9 1273
278b2083 1274 rcu_read_lock();
1275 curr = rcu_dereference(bond->curr_active_slave);
b76cdba9 1276 if (USES_PRIMARY(bond->params.mode) && curr)
7bd46508 1277 count = sprintf(buf, "%s\n", curr->dev->name);
278b2083 1278 rcu_read_unlock();
1279
b76cdba9
MW
1280 return count;
1281}
1282
43cb76d9
GKH
1283static ssize_t bonding_store_active_slave(struct device *d,
1284 struct device_attribute *attr,
1285 const char *buf, size_t count)
b76cdba9 1286{
dec1e90e 1287 struct slave *slave, *old_active, *new_active;
43cb76d9 1288 struct bonding *bond = to_bond(d);
f4bb2e9c 1289 char ifname[IFNAMSIZ];
b76cdba9 1290
496a60cd
EB
1291 if (!rtnl_trylock())
1292 return restart_syscall();
e843fa50 1293
dec1e90e 1294 old_active = new_active = NULL;
e843fa50 1295 block_netpoll_tx();
e934dd78
JV
1296 read_lock(&bond->lock);
1297 write_lock_bh(&bond->curr_slave_lock);
1466a219 1298
f4bb2e9c 1299 if (!USES_PRIMARY(bond->params.mode)) {
a4aee5c8 1300 pr_info("%s: Unable to change active slave; %s is in mode %d\n",
3d632c3f 1301 bond->dev->name, bond->dev->name, bond->params.mode);
f4bb2e9c
AG
1302 goto out;
1303 }
1304
c84e1590 1305 sscanf(buf, "%15s", ifname); /* IFNAMSIZ */
f4bb2e9c
AG
1306
1307 /* check to see if we are clearing active */
1308 if (!strlen(ifname) || buf[0] == '\n') {
1309 pr_info("%s: Clearing current active slave.\n",
1310 bond->dev->name);
278b2083 1311 rcu_assign_pointer(bond->curr_active_slave, NULL);
f4bb2e9c
AG
1312 bond_select_active_slave(bond);
1313 goto out;
1314 }
1315
dec1e90e 1316 bond_for_each_slave(bond, slave) {
f4bb2e9c
AG
1317 if (strncmp(slave->dev->name, ifname, IFNAMSIZ) == 0) {
1318 old_active = bond->curr_active_slave;
1319 new_active = slave;
1320 if (new_active == old_active) {
1321 /* do nothing */
1322 pr_info("%s: %s is already the current"
1323 " active slave.\n",
1324 bond->dev->name,
1325 slave->dev->name);
1326 goto out;
38c4916a 1327 } else {
f4bb2e9c
AG
1328 if ((new_active) &&
1329 (old_active) &&
1330 (new_active->link == BOND_LINK_UP) &&
1331 IS_UP(new_active->dev)) {
1332 pr_info("%s: Setting %s as active"
1333 " slave.\n",
a4aee5c8
JP
1334 bond->dev->name,
1335 slave->dev->name);
f4bb2e9c
AG
1336 bond_change_active_slave(bond,
1337 new_active);
38c4916a 1338 } else {
f4bb2e9c
AG
1339 pr_info("%s: Could not set %s as"
1340 " active slave; either %s is"
1341 " down or the link is down.\n",
1342 bond->dev->name,
1343 slave->dev->name,
1344 slave->dev->name);
b76cdba9 1345 }
f4bb2e9c 1346 goto out;
b76cdba9
MW
1347 }
1348 }
b76cdba9 1349 }
f4bb2e9c
AG
1350
1351 pr_info("%s: Unable to set %.*s as active slave.\n",
1352 bond->dev->name, (int)strlen(buf) - 1, buf);
3d632c3f 1353 out:
e934dd78
JV
1354 write_unlock_bh(&bond->curr_slave_lock);
1355 read_unlock(&bond->lock);
e843fa50
NH
1356 unblock_netpoll_tx();
1357
6603a6f2
JV
1358 rtnl_unlock();
1359
b76cdba9
MW
1360 return count;
1361
1362}
3d632c3f
SH
1363static DEVICE_ATTR(active_slave, S_IRUGO | S_IWUSR,
1364 bonding_show_active_slave, bonding_store_active_slave);
b76cdba9
MW
1365
1366
1367/*
1368 * Show link status of the bond interface.
1369 */
43cb76d9
GKH
1370static ssize_t bonding_show_mii_status(struct device *d,
1371 struct device_attribute *attr,
1372 char *buf)
b76cdba9 1373{
43cb76d9 1374 struct bonding *bond = to_bond(d);
b76cdba9 1375
278b2083 1376 return sprintf(buf, "%s\n", bond->curr_active_slave ? "up" : "down");
b76cdba9 1377}
43cb76d9 1378static DEVICE_ATTR(mii_status, S_IRUGO, bonding_show_mii_status, NULL);
b76cdba9 1379
b76cdba9
MW
1380/*
1381 * Show current 802.3ad aggregator ID.
1382 */
43cb76d9
GKH
1383static ssize_t bonding_show_ad_aggregator(struct device *d,
1384 struct device_attribute *attr,
1385 char *buf)
b76cdba9
MW
1386{
1387 int count = 0;
43cb76d9 1388 struct bonding *bond = to_bond(d);
b76cdba9
MW
1389
1390 if (bond->params.mode == BOND_MODE_8023AD) {
1391 struct ad_info ad_info;
3d632c3f 1392 count = sprintf(buf, "%d\n",
318debd8 1393 bond_3ad_get_active_agg_info(bond, &ad_info)
3d632c3f 1394 ? 0 : ad_info.aggregator_id);
b76cdba9 1395 }
b76cdba9
MW
1396
1397 return count;
1398}
43cb76d9 1399static DEVICE_ATTR(ad_aggregator, S_IRUGO, bonding_show_ad_aggregator, NULL);
b76cdba9
MW
1400
1401
1402/*
1403 * Show number of active 802.3ad ports.
1404 */
43cb76d9
GKH
1405static ssize_t bonding_show_ad_num_ports(struct device *d,
1406 struct device_attribute *attr,
1407 char *buf)
b76cdba9
MW
1408{
1409 int count = 0;
43cb76d9 1410 struct bonding *bond = to_bond(d);
b76cdba9
MW
1411
1412 if (bond->params.mode == BOND_MODE_8023AD) {
1413 struct ad_info ad_info;
3d632c3f 1414 count = sprintf(buf, "%d\n",
318debd8 1415 bond_3ad_get_active_agg_info(bond, &ad_info)
3d632c3f 1416 ? 0 : ad_info.ports);
b76cdba9 1417 }
b76cdba9
MW
1418
1419 return count;
1420}
43cb76d9 1421static DEVICE_ATTR(ad_num_ports, S_IRUGO, bonding_show_ad_num_ports, NULL);
b76cdba9
MW
1422
1423
1424/*
1425 * Show current 802.3ad actor key.
1426 */
43cb76d9
GKH
1427static ssize_t bonding_show_ad_actor_key(struct device *d,
1428 struct device_attribute *attr,
1429 char *buf)
b76cdba9
MW
1430{
1431 int count = 0;
43cb76d9 1432 struct bonding *bond = to_bond(d);
b76cdba9
MW
1433
1434 if (bond->params.mode == BOND_MODE_8023AD) {
1435 struct ad_info ad_info;
3d632c3f 1436 count = sprintf(buf, "%d\n",
318debd8 1437 bond_3ad_get_active_agg_info(bond, &ad_info)
3d632c3f 1438 ? 0 : ad_info.actor_key);
b76cdba9 1439 }
b76cdba9
MW
1440
1441 return count;
1442}
43cb76d9 1443static DEVICE_ATTR(ad_actor_key, S_IRUGO, bonding_show_ad_actor_key, NULL);
b76cdba9
MW
1444
1445
1446/*
1447 * Show current 802.3ad partner key.
1448 */
43cb76d9
GKH
1449static ssize_t bonding_show_ad_partner_key(struct device *d,
1450 struct device_attribute *attr,
1451 char *buf)
b76cdba9
MW
1452{
1453 int count = 0;
43cb76d9 1454 struct bonding *bond = to_bond(d);
b76cdba9
MW
1455
1456 if (bond->params.mode == BOND_MODE_8023AD) {
1457 struct ad_info ad_info;
3d632c3f 1458 count = sprintf(buf, "%d\n",
318debd8 1459 bond_3ad_get_active_agg_info(bond, &ad_info)
3d632c3f 1460 ? 0 : ad_info.partner_key);
b76cdba9 1461 }
b76cdba9
MW
1462
1463 return count;
1464}
43cb76d9 1465static DEVICE_ATTR(ad_partner_key, S_IRUGO, bonding_show_ad_partner_key, NULL);
b76cdba9
MW
1466
1467
1468/*
1469 * Show current 802.3ad partner mac.
1470 */
43cb76d9
GKH
1471static ssize_t bonding_show_ad_partner_mac(struct device *d,
1472 struct device_attribute *attr,
1473 char *buf)
b76cdba9
MW
1474{
1475 int count = 0;
43cb76d9 1476 struct bonding *bond = to_bond(d);
b76cdba9
MW
1477
1478 if (bond->params.mode == BOND_MODE_8023AD) {
1479 struct ad_info ad_info;
3d632c3f 1480 if (!bond_3ad_get_active_agg_info(bond, &ad_info))
e174961c 1481 count = sprintf(buf, "%pM\n", ad_info.partner_system);
b76cdba9 1482 }
b76cdba9
MW
1483
1484 return count;
1485}
43cb76d9 1486static DEVICE_ATTR(ad_partner_mac, S_IRUGO, bonding_show_ad_partner_mac, NULL);
b76cdba9 1487
bb1d9123
AG
1488/*
1489 * Show the queue_ids of the slaves in the current bond.
1490 */
1491static ssize_t bonding_show_queue_id(struct device *d,
1492 struct device_attribute *attr,
1493 char *buf)
1494{
bb1d9123 1495 struct bonding *bond = to_bond(d);
dec1e90e 1496 struct slave *slave;
1497 int res = 0;
bb1d9123
AG
1498
1499 if (!rtnl_trylock())
1500 return restart_syscall();
1501
1502 read_lock(&bond->lock);
dec1e90e 1503 bond_for_each_slave(bond, slave) {
79236680
NP
1504 if (res > (PAGE_SIZE - IFNAMSIZ - 6)) {
1505 /* not enough space for another interface_name:queue_id pair */
bb1d9123
AG
1506 if ((PAGE_SIZE - res) > 10)
1507 res = PAGE_SIZE - 10;
1508 res += sprintf(buf + res, "++more++ ");
1509 break;
1510 }
1511 res += sprintf(buf + res, "%s:%d ",
1512 slave->dev->name, slave->queue_id);
1513 }
1514 read_unlock(&bond->lock);
1515 if (res)
1516 buf[res-1] = '\n'; /* eat the leftover space */
1517 rtnl_unlock();
dec1e90e 1518
bb1d9123
AG
1519 return res;
1520}
1521
1522/*
1523 * Set the queue_ids of the slaves in the current bond. The bond
1524 * interface must be enslaved for this to work.
1525 */
1526static ssize_t bonding_store_queue_id(struct device *d,
1527 struct device_attribute *attr,
1528 const char *buffer, size_t count)
1529{
1530 struct slave *slave, *update_slave;
1531 struct bonding *bond = to_bond(d);
1532 u16 qid;
dec1e90e 1533 int ret = count;
bb1d9123
AG
1534 char *delim;
1535 struct net_device *sdev = NULL;
1536
1537 if (!rtnl_trylock())
1538 return restart_syscall();
1539
1540 /* delim will point to queue id if successful */
1541 delim = strchr(buffer, ':');
1542 if (!delim)
1543 goto err_no_cmd;
1544
1545 /*
1546 * Terminate string that points to device name and bump it
1547 * up one, so we can read the queue id there.
1548 */
1549 *delim = '\0';
1550 if (sscanf(++delim, "%hd\n", &qid) != 1)
1551 goto err_no_cmd;
1552
1553 /* Check buffer length, valid ifname and queue id */
1554 if (strlen(buffer) > IFNAMSIZ ||
1555 !dev_valid_name(buffer) ||
8a540ff9 1556 qid > bond->dev->real_num_tx_queues)
bb1d9123
AG
1557 goto err_no_cmd;
1558
1559 /* Get the pointer to that interface if it exists */
1560 sdev = __dev_get_by_name(dev_net(bond->dev), buffer);
1561 if (!sdev)
1562 goto err_no_cmd;
1563
1564 read_lock(&bond->lock);
1565
1566 /* Search for thes slave and check for duplicate qids */
1567 update_slave = NULL;
dec1e90e 1568 bond_for_each_slave(bond, slave) {
bb1d9123
AG
1569 if (sdev == slave->dev)
1570 /*
1571 * We don't need to check the matching
1572 * slave for dups, since we're overwriting it
1573 */
1574 update_slave = slave;
1575 else if (qid && qid == slave->queue_id) {
1576 goto err_no_cmd_unlock;
1577 }
1578 }
1579
1580 if (!update_slave)
1581 goto err_no_cmd_unlock;
1582
1583 /* Actually set the qids for the slave */
1584 update_slave->queue_id = qid;
1585
1586 read_unlock(&bond->lock);
1587out:
1588 rtnl_unlock();
1589 return ret;
1590
1591err_no_cmd_unlock:
1592 read_unlock(&bond->lock);
1593err_no_cmd:
1594 pr_info("invalid input for queue_id set for %s.\n",
1595 bond->dev->name);
1596 ret = -EPERM;
1597 goto out;
1598}
1599
1600static DEVICE_ATTR(queue_id, S_IRUGO | S_IWUSR, bonding_show_queue_id,
1601 bonding_store_queue_id);
1602
1603
ebd8e497
AG
1604/*
1605 * Show and set the all_slaves_active flag.
1606 */
1607static ssize_t bonding_show_slaves_active(struct device *d,
1608 struct device_attribute *attr,
1609 char *buf)
1610{
1611 struct bonding *bond = to_bond(d);
1612
1613 return sprintf(buf, "%d\n", bond->params.all_slaves_active);
1614}
1615
1616static ssize_t bonding_store_slaves_active(struct device *d,
1617 struct device_attribute *attr,
1618 const char *buf, size_t count)
1619{
ebd8e497 1620 struct bonding *bond = to_bond(d);
dec1e90e 1621 int new_value, ret = count;
ebd8e497
AG
1622 struct slave *slave;
1623
1624 if (sscanf(buf, "%d", &new_value) != 1) {
1625 pr_err("%s: no all_slaves_active value specified.\n",
1626 bond->dev->name);
1627 ret = -EINVAL;
1628 goto out;
1629 }
1630
1631 if (new_value == bond->params.all_slaves_active)
1632 goto out;
1633
1634 if ((new_value == 0) || (new_value == 1)) {
1635 bond->params.all_slaves_active = new_value;
1636 } else {
1637 pr_info("%s: Ignoring invalid all_slaves_active value %d.\n",
1638 bond->dev->name, new_value);
1639 ret = -EINVAL;
1640 goto out;
1641 }
b76cdba9 1642
e196c0e5 1643 read_lock(&bond->lock);
dec1e90e 1644 bond_for_each_slave(bond, slave) {
e30bc066 1645 if (!bond_is_active_slave(slave)) {
ebd8e497 1646 if (new_value)
2d7011ca 1647 slave->inactive = 0;
ebd8e497 1648 else
2d7011ca 1649 slave->inactive = 1;
ebd8e497
AG
1650 }
1651 }
e196c0e5 1652 read_unlock(&bond->lock);
ebd8e497 1653out:
672bda33 1654 return ret;
ebd8e497
AG
1655}
1656static DEVICE_ATTR(all_slaves_active, S_IRUGO | S_IWUSR,
1657 bonding_show_slaves_active, bonding_store_slaves_active);
b76cdba9 1658
c2952c31
FL
1659/*
1660 * Show and set the number of IGMP membership reports to send on link failure
1661 */
1662static ssize_t bonding_show_resend_igmp(struct device *d,
94265cf5
FL
1663 struct device_attribute *attr,
1664 char *buf)
c2952c31
FL
1665{
1666 struct bonding *bond = to_bond(d);
1667
1668 return sprintf(buf, "%d\n", bond->params.resend_igmp);
1669}
1670
1671static ssize_t bonding_store_resend_igmp(struct device *d,
94265cf5
FL
1672 struct device_attribute *attr,
1673 const char *buf, size_t count)
c2952c31
FL
1674{
1675 int new_value, ret = count;
1676 struct bonding *bond = to_bond(d);
1677
1678 if (sscanf(buf, "%d", &new_value) != 1) {
1679 pr_err("%s: no resend_igmp value specified.\n",
1680 bond->dev->name);
1681 ret = -EINVAL;
1682 goto out;
1683 }
1684
94265cf5 1685 if (new_value < 0 || new_value > 255) {
c2952c31
FL
1686 pr_err("%s: Invalid resend_igmp value %d not in range 0-255; rejected.\n",
1687 bond->dev->name, new_value);
1688 ret = -EINVAL;
1689 goto out;
1690 }
1691
1692 pr_info("%s: Setting resend_igmp to %d.\n",
1693 bond->dev->name, new_value);
1694 bond->params.resend_igmp = new_value;
1695out:
1696 return ret;
1697}
1698
1699static DEVICE_ATTR(resend_igmp, S_IRUGO | S_IWUSR,
1700 bonding_show_resend_igmp, bonding_store_resend_igmp);
1701
b76cdba9 1702static struct attribute *per_bond_attrs[] = {
43cb76d9
GKH
1703 &dev_attr_slaves.attr,
1704 &dev_attr_mode.attr,
dd957c57 1705 &dev_attr_fail_over_mac.attr,
43cb76d9 1706 &dev_attr_arp_validate.attr,
8599b52e 1707 &dev_attr_arp_all_targets.attr,
43cb76d9
GKH
1708 &dev_attr_arp_interval.attr,
1709 &dev_attr_arp_ip_target.attr,
1710 &dev_attr_downdelay.attr,
1711 &dev_attr_updelay.attr,
1712 &dev_attr_lacp_rate.attr,
fd989c83 1713 &dev_attr_ad_select.attr,
43cb76d9 1714 &dev_attr_xmit_hash_policy.attr,
ad246c99
BH
1715 &dev_attr_num_grat_arp.attr,
1716 &dev_attr_num_unsol_na.attr,
43cb76d9
GKH
1717 &dev_attr_miimon.attr,
1718 &dev_attr_primary.attr,
a549952a 1719 &dev_attr_primary_reselect.attr,
43cb76d9
GKH
1720 &dev_attr_use_carrier.attr,
1721 &dev_attr_active_slave.attr,
1722 &dev_attr_mii_status.attr,
1723 &dev_attr_ad_aggregator.attr,
1724 &dev_attr_ad_num_ports.attr,
1725 &dev_attr_ad_actor_key.attr,
1726 &dev_attr_ad_partner_key.attr,
1727 &dev_attr_ad_partner_mac.attr,
bb1d9123 1728 &dev_attr_queue_id.attr,
ebd8e497 1729 &dev_attr_all_slaves_active.attr,
c2952c31 1730 &dev_attr_resend_igmp.attr,
655f8919 1731 &dev_attr_min_links.attr,
b76cdba9
MW
1732 NULL,
1733};
1734
1735static struct attribute_group bonding_group = {
1736 .name = "bonding",
1737 .attrs = per_bond_attrs,
1738};
1739
1740/*
1741 * Initialize sysfs. This sets up the bonding_masters file in
1742 * /sys/class/net.
1743 */
4c22400a 1744int bond_create_sysfs(struct bond_net *bn)
b76cdba9 1745{
b8a9787e 1746 int ret;
b76cdba9 1747
4c22400a 1748 bn->class_attr_bonding_masters = class_attr_bonding_masters;
01718e36 1749 sysfs_attr_init(&bn->class_attr_bonding_masters.attr);
4c22400a
EB
1750
1751 ret = netdev_class_create_file(&bn->class_attr_bonding_masters);
877cbd36
JV
1752 /*
1753 * Permit multiple loads of the module by ignoring failures to
1754 * create the bonding_masters sysfs file. Bonding devices
1755 * created by second or subsequent loads of the module will
1756 * not be listed in, or controllable by, bonding_masters, but
1757 * will have the usual "bonding" sysfs directory.
1758 *
1759 * This is done to preserve backwards compatibility for
1760 * initscripts/sysconfig, which load bonding multiple times to
1761 * configure multiple bonding devices.
1762 */
1763 if (ret == -EEXIST) {
38d2f38b 1764 /* Is someone being kinky and naming a device bonding_master? */
4c22400a 1765 if (__dev_get_by_name(bn->net,
38d2f38b 1766 class_attr_bonding_masters.attr.name))
a4aee5c8 1767 pr_err("network device named %s already exists in sysfs",
38d2f38b 1768 class_attr_bonding_masters.attr.name);
130aa61a 1769 ret = 0;
877cbd36 1770 }
b76cdba9
MW
1771
1772 return ret;
1773
1774}
1775
1776/*
1777 * Remove /sys/class/net/bonding_masters.
1778 */
4c22400a 1779void bond_destroy_sysfs(struct bond_net *bn)
b76cdba9 1780{
4c22400a 1781 netdev_class_remove_file(&bn->class_attr_bonding_masters);
b76cdba9
MW
1782}
1783
1784/*
1785 * Initialize sysfs for each bond. This sets up and registers
1786 * the 'bondctl' directory for each individual bond under /sys/class/net.
1787 */
6151b3d4 1788void bond_prepare_sysfs_group(struct bonding *bond)
b76cdba9 1789{
6151b3d4 1790 bond->dev->sysfs_groups[0] = &bonding_group;
b76cdba9
MW
1791}
1792
This page took 0.927051 seconds and 5 git commands to generate.