ALSA: hda - Fix beep frequency on IDT 92HD73xx and 92HD71Bxx codecs
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / net / bonding / bond_sysfs.c
blobb8bec086daa155b2c6f36884a059f4749f5636fd
1 /*
2 * Copyright(c) 2004-2005 Intel Corporation. All rights reserved.
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.
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.
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.
18 * The full GNU General Public License is included in this distribution in the
19 * file called LICENSE.
23 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
25 #include <linux/kernel.h>
26 #include <linux/module.h>
27 #include <linux/device.h>
28 #include <linux/sched.h>
29 #include <linux/sysdev.h>
30 #include <linux/fs.h>
31 #include <linux/types.h>
32 #include <linux/string.h>
33 #include <linux/netdevice.h>
34 #include <linux/inetdevice.h>
35 #include <linux/in.h>
36 #include <linux/sysfs.h>
37 #include <linux/ctype.h>
38 #include <linux/inet.h>
39 #include <linux/rtnetlink.h>
40 #include <linux/etherdevice.h>
41 #include <net/net_namespace.h>
42 #include <net/netns/generic.h>
43 #include <linux/nsproxy.h>
45 #include "bonding.h"
47 #define to_dev(obj) container_of(obj, struct device, kobj)
48 #define to_bond(cd) ((struct bonding *)(netdev_priv(to_net_dev(cd))))
51 * "show" function for the bond_masters attribute.
52 * The class parameter is ignored.
54 static ssize_t bonding_show_bonds(struct class *cls,
55 struct class_attribute *attr,
56 char *buf)
58 struct net *net = current->nsproxy->net_ns;
59 struct bond_net *bn = net_generic(net, bond_net_id);
60 int res = 0;
61 struct bonding *bond;
63 rtnl_lock();
65 list_for_each_entry(bond, &bn->dev_list, bond_list) {
66 if (res > (PAGE_SIZE - IFNAMSIZ)) {
67 /* not enough space for another interface name */
68 if ((PAGE_SIZE - res) > 10)
69 res = PAGE_SIZE - 10;
70 res += sprintf(buf + res, "++more++ ");
71 break;
73 res += sprintf(buf + res, "%s ", bond->dev->name);
75 if (res)
76 buf[res-1] = '\n'; /* eat the leftover space */
78 rtnl_unlock();
79 return res;
82 static struct net_device *bond_get_by_name(struct net *net, const char *ifname)
84 struct bond_net *bn = net_generic(net, bond_net_id);
85 struct bonding *bond;
87 list_for_each_entry(bond, &bn->dev_list, bond_list) {
88 if (strncmp(bond->dev->name, ifname, IFNAMSIZ) == 0)
89 return bond->dev;
91 return NULL;
95 * "store" function for the bond_masters attribute. This is what
96 * creates and deletes entire bonds.
98 * The class parameter is ignored.
102 static ssize_t bonding_store_bonds(struct class *cls,
103 struct class_attribute *attr,
104 const char *buffer, size_t count)
106 struct net *net = current->nsproxy->net_ns;
107 char command[IFNAMSIZ + 1] = {0, };
108 char *ifname;
109 int rv, res = count;
111 sscanf(buffer, "%16s", command); /* IFNAMSIZ*/
112 ifname = command + 1;
113 if ((strlen(command) <= 1) ||
114 !dev_valid_name(ifname))
115 goto err_no_cmd;
117 if (command[0] == '+') {
118 pr_info("%s is being created...\n", ifname);
119 rv = bond_create(net, ifname);
120 if (rv) {
121 pr_info("Bond creation failed.\n");
122 res = rv;
124 } else if (command[0] == '-') {
125 struct net_device *bond_dev;
127 rtnl_lock();
128 bond_dev = bond_get_by_name(net, ifname);
129 if (bond_dev) {
130 pr_info("%s is being deleted...\n", ifname);
131 unregister_netdevice(bond_dev);
132 } else {
133 pr_err("unable to delete non-existent %s\n", ifname);
134 res = -ENODEV;
136 rtnl_unlock();
137 } else
138 goto err_no_cmd;
140 /* Always return either count or an error. If you return 0, you'll
141 * get called forever, which is bad.
143 return res;
145 err_no_cmd:
146 pr_err("no command found in bonding_masters. Use +ifname or -ifname.\n");
147 return -EPERM;
150 /* class attribute for bond_masters file. This ends up in /sys/class/net */
151 static CLASS_ATTR(bonding_masters, S_IWUSR | S_IRUGO,
152 bonding_show_bonds, bonding_store_bonds);
154 int bond_create_slave_symlinks(struct net_device *master,
155 struct net_device *slave)
157 char linkname[IFNAMSIZ+7];
158 int ret = 0;
160 /* first, create a link from the slave back to the master */
161 ret = sysfs_create_link(&(slave->dev.kobj), &(master->dev.kobj),
162 "master");
163 if (ret)
164 return ret;
165 /* next, create a link from the master to the slave */
166 sprintf(linkname, "slave_%s", slave->name);
167 ret = sysfs_create_link(&(master->dev.kobj), &(slave->dev.kobj),
168 linkname);
169 return ret;
173 void bond_destroy_slave_symlinks(struct net_device *master,
174 struct net_device *slave)
176 char linkname[IFNAMSIZ+7];
178 sysfs_remove_link(&(slave->dev.kobj), "master");
179 sprintf(linkname, "slave_%s", slave->name);
180 sysfs_remove_link(&(master->dev.kobj), linkname);
185 * Show the slaves in the current bond.
187 static ssize_t bonding_show_slaves(struct device *d,
188 struct device_attribute *attr, char *buf)
190 struct slave *slave;
191 int i, res = 0;
192 struct bonding *bond = to_bond(d);
194 read_lock(&bond->lock);
195 bond_for_each_slave(bond, slave, i) {
196 if (res > (PAGE_SIZE - IFNAMSIZ)) {
197 /* not enough space for another interface name */
198 if ((PAGE_SIZE - res) > 10)
199 res = PAGE_SIZE - 10;
200 res += sprintf(buf + res, "++more++ ");
201 break;
203 res += sprintf(buf + res, "%s ", slave->dev->name);
205 read_unlock(&bond->lock);
206 if (res)
207 buf[res-1] = '\n'; /* eat the leftover space */
208 return res;
212 * Set the slaves in the current bond. The bond interface must be
213 * up for this to succeed.
214 * This function is largely the same flow as bonding_update_bonds().
216 static ssize_t bonding_store_slaves(struct device *d,
217 struct device_attribute *attr,
218 const char *buffer, size_t count)
220 char command[IFNAMSIZ + 1] = { 0, };
221 char *ifname;
222 int i, res, found, ret = count;
223 u32 original_mtu;
224 struct slave *slave;
225 struct net_device *dev = NULL;
226 struct bonding *bond = to_bond(d);
228 /* Quick sanity check -- is the bond interface up? */
229 if (!(bond->dev->flags & IFF_UP)) {
230 pr_warning("%s: doing slave updates when interface is down.\n",
231 bond->dev->name);
234 /* Note: We can't hold bond->lock here, as bond_create grabs it. */
236 if (!rtnl_trylock())
237 return restart_syscall();
239 sscanf(buffer, "%16s", command); /* IFNAMSIZ*/
240 ifname = command + 1;
241 if ((strlen(command) <= 1) ||
242 !dev_valid_name(ifname))
243 goto err_no_cmd;
245 if (command[0] == '+') {
247 /* Got a slave name in ifname. Is it already in the list? */
248 found = 0;
250 dev = __dev_get_by_name(dev_net(bond->dev), ifname);
251 if (!dev) {
252 pr_info("%s: Interface %s does not exist!\n",
253 bond->dev->name, ifname);
254 ret = -ENODEV;
255 goto out;
258 if (dev->flags & IFF_UP) {
259 pr_err("%s: Error: Unable to enslave %s because it is already up.\n",
260 bond->dev->name, dev->name);
261 ret = -EPERM;
262 goto out;
265 read_lock(&bond->lock);
266 bond_for_each_slave(bond, slave, i)
267 if (slave->dev == dev) {
268 pr_err("%s: Interface %s is already enslaved!\n",
269 bond->dev->name, ifname);
270 ret = -EPERM;
271 read_unlock(&bond->lock);
272 goto out;
274 read_unlock(&bond->lock);
276 pr_info("%s: Adding slave %s.\n", bond->dev->name, ifname);
278 /* If this is the first slave, then we need to set
279 the master's hardware address to be the same as the
280 slave's. */
281 if (is_zero_ether_addr(bond->dev->dev_addr))
282 memcpy(bond->dev->dev_addr, dev->dev_addr,
283 dev->addr_len);
285 /* Set the slave's MTU to match the bond */
286 original_mtu = dev->mtu;
287 res = dev_set_mtu(dev, bond->dev->mtu);
288 if (res) {
289 ret = res;
290 goto out;
293 res = bond_enslave(bond->dev, dev);
294 bond_for_each_slave(bond, slave, i)
295 if (strnicmp(slave->dev->name, ifname, IFNAMSIZ) == 0)
296 slave->original_mtu = original_mtu;
297 if (res)
298 ret = res;
300 goto out;
303 if (command[0] == '-') {
304 dev = NULL;
305 original_mtu = 0;
306 bond_for_each_slave(bond, slave, i)
307 if (strnicmp(slave->dev->name, ifname, IFNAMSIZ) == 0) {
308 dev = slave->dev;
309 original_mtu = slave->original_mtu;
310 break;
312 if (dev) {
313 pr_info("%s: Removing slave %s\n",
314 bond->dev->name, dev->name);
315 res = bond_release(bond->dev, dev);
316 if (res) {
317 ret = res;
318 goto out;
320 /* set the slave MTU to the default */
321 dev_set_mtu(dev, original_mtu);
322 } else {
323 pr_err("unable to remove non-existent slave %s for bond %s.\n",
324 ifname, bond->dev->name);
325 ret = -ENODEV;
327 goto out;
330 err_no_cmd:
331 pr_err("no command found in slaves file for bond %s. Use +ifname or -ifname.\n",
332 bond->dev->name);
333 ret = -EPERM;
335 out:
336 rtnl_unlock();
337 return ret;
340 static DEVICE_ATTR(slaves, S_IRUGO | S_IWUSR, bonding_show_slaves,
341 bonding_store_slaves);
344 * Show and set the bonding mode. The bond interface must be down to
345 * change the mode.
347 static ssize_t bonding_show_mode(struct device *d,
348 struct device_attribute *attr, char *buf)
350 struct bonding *bond = to_bond(d);
352 return sprintf(buf, "%s %d\n",
353 bond_mode_tbl[bond->params.mode].modename,
354 bond->params.mode);
357 static ssize_t bonding_store_mode(struct device *d,
358 struct device_attribute *attr,
359 const char *buf, size_t count)
361 int new_value, ret = count;
362 struct bonding *bond = to_bond(d);
364 if (bond->dev->flags & IFF_UP) {
365 pr_err("unable to update mode of %s because interface is up.\n",
366 bond->dev->name);
367 ret = -EPERM;
368 goto out;
371 new_value = bond_parse_parm(buf, bond_mode_tbl);
372 if (new_value < 0) {
373 pr_err("%s: Ignoring invalid mode value %.*s.\n",
374 bond->dev->name, (int)strlen(buf) - 1, buf);
375 ret = -EINVAL;
376 goto out;
377 } else {
378 if (bond->params.mode == BOND_MODE_8023AD)
379 bond_unset_master_3ad_flags(bond);
381 if (bond->params.mode == BOND_MODE_ALB)
382 bond_unset_master_alb_flags(bond);
384 bond->params.mode = new_value;
385 bond_set_mode_ops(bond, bond->params.mode);
386 pr_info("%s: setting mode to %s (%d).\n",
387 bond->dev->name, bond_mode_tbl[new_value].modename,
388 new_value);
390 out:
391 return ret;
393 static DEVICE_ATTR(mode, S_IRUGO | S_IWUSR,
394 bonding_show_mode, bonding_store_mode);
397 * Show and set the bonding transmit hash method.
398 * The bond interface must be down to change the xmit hash policy.
400 static ssize_t bonding_show_xmit_hash(struct device *d,
401 struct device_attribute *attr,
402 char *buf)
404 struct bonding *bond = to_bond(d);
406 return sprintf(buf, "%s %d\n",
407 xmit_hashtype_tbl[bond->params.xmit_policy].modename,
408 bond->params.xmit_policy);
411 static ssize_t bonding_store_xmit_hash(struct device *d,
412 struct device_attribute *attr,
413 const char *buf, size_t count)
415 int new_value, ret = count;
416 struct bonding *bond = to_bond(d);
418 if (bond->dev->flags & IFF_UP) {
419 pr_err("%s: Interface is up. Unable to update xmit policy.\n",
420 bond->dev->name);
421 ret = -EPERM;
422 goto out;
425 new_value = bond_parse_parm(buf, xmit_hashtype_tbl);
426 if (new_value < 0) {
427 pr_err("%s: Ignoring invalid xmit hash policy value %.*s.\n",
428 bond->dev->name,
429 (int)strlen(buf) - 1, buf);
430 ret = -EINVAL;
431 goto out;
432 } else {
433 bond->params.xmit_policy = new_value;
434 bond_set_mode_ops(bond, bond->params.mode);
435 pr_info("%s: setting xmit hash policy to %s (%d).\n",
436 bond->dev->name,
437 xmit_hashtype_tbl[new_value].modename, new_value);
439 out:
440 return ret;
442 static DEVICE_ATTR(xmit_hash_policy, S_IRUGO | S_IWUSR,
443 bonding_show_xmit_hash, bonding_store_xmit_hash);
446 * Show and set arp_validate.
448 static ssize_t bonding_show_arp_validate(struct device *d,
449 struct device_attribute *attr,
450 char *buf)
452 struct bonding *bond = to_bond(d);
454 return sprintf(buf, "%s %d\n",
455 arp_validate_tbl[bond->params.arp_validate].modename,
456 bond->params.arp_validate);
459 static ssize_t bonding_store_arp_validate(struct device *d,
460 struct device_attribute *attr,
461 const char *buf, size_t count)
463 int new_value;
464 struct bonding *bond = to_bond(d);
466 new_value = bond_parse_parm(buf, arp_validate_tbl);
467 if (new_value < 0) {
468 pr_err("%s: Ignoring invalid arp_validate value %s\n",
469 bond->dev->name, buf);
470 return -EINVAL;
472 if (new_value && (bond->params.mode != BOND_MODE_ACTIVEBACKUP)) {
473 pr_err("%s: arp_validate only supported in active-backup mode.\n",
474 bond->dev->name);
475 return -EINVAL;
477 pr_info("%s: setting arp_validate to %s (%d).\n",
478 bond->dev->name, arp_validate_tbl[new_value].modename,
479 new_value);
481 if (!bond->params.arp_validate && new_value)
482 bond_register_arp(bond);
483 else if (bond->params.arp_validate && !new_value)
484 bond_unregister_arp(bond);
486 bond->params.arp_validate = new_value;
488 return count;
491 static DEVICE_ATTR(arp_validate, S_IRUGO | S_IWUSR, bonding_show_arp_validate,
492 bonding_store_arp_validate);
495 * Show and store fail_over_mac. User only allowed to change the
496 * value when there are no slaves.
498 static ssize_t bonding_show_fail_over_mac(struct device *d,
499 struct device_attribute *attr,
500 char *buf)
502 struct bonding *bond = to_bond(d);
504 return sprintf(buf, "%s %d\n",
505 fail_over_mac_tbl[bond->params.fail_over_mac].modename,
506 bond->params.fail_over_mac);
509 static ssize_t bonding_store_fail_over_mac(struct device *d,
510 struct device_attribute *attr,
511 const char *buf, size_t count)
513 int new_value;
514 struct bonding *bond = to_bond(d);
516 if (bond->slave_cnt != 0) {
517 pr_err("%s: Can't alter fail_over_mac with slaves in bond.\n",
518 bond->dev->name);
519 return -EPERM;
522 new_value = bond_parse_parm(buf, fail_over_mac_tbl);
523 if (new_value < 0) {
524 pr_err("%s: Ignoring invalid fail_over_mac value %s.\n",
525 bond->dev->name, buf);
526 return -EINVAL;
529 bond->params.fail_over_mac = new_value;
530 pr_info("%s: Setting fail_over_mac to %s (%d).\n",
531 bond->dev->name, fail_over_mac_tbl[new_value].modename,
532 new_value);
534 return count;
537 static DEVICE_ATTR(fail_over_mac, S_IRUGO | S_IWUSR,
538 bonding_show_fail_over_mac, bonding_store_fail_over_mac);
541 * Show and set the arp timer interval. There are two tricky bits
542 * here. First, if ARP monitoring is activated, then we must disable
543 * MII monitoring. Second, if the ARP timer isn't running, we must
544 * start it.
546 static ssize_t bonding_show_arp_interval(struct device *d,
547 struct device_attribute *attr,
548 char *buf)
550 struct bonding *bond = to_bond(d);
552 return sprintf(buf, "%d\n", bond->params.arp_interval);
555 static ssize_t bonding_store_arp_interval(struct device *d,
556 struct device_attribute *attr,
557 const char *buf, size_t count)
559 int new_value, ret = count;
560 struct bonding *bond = to_bond(d);
562 if (sscanf(buf, "%d", &new_value) != 1) {
563 pr_err("%s: no arp_interval value specified.\n",
564 bond->dev->name);
565 ret = -EINVAL;
566 goto out;
568 if (new_value < 0) {
569 pr_err("%s: Invalid arp_interval value %d not in range 1-%d; rejected.\n",
570 bond->dev->name, new_value, INT_MAX);
571 ret = -EINVAL;
572 goto out;
575 pr_info("%s: Setting ARP monitoring interval to %d.\n",
576 bond->dev->name, new_value);
577 bond->params.arp_interval = new_value;
578 if (bond->params.arp_interval)
579 bond->dev->priv_flags |= IFF_MASTER_ARPMON;
580 if (bond->params.miimon) {
581 pr_info("%s: ARP monitoring cannot be used with MII monitoring. %s Disabling MII monitoring.\n",
582 bond->dev->name, bond->dev->name);
583 bond->params.miimon = 0;
584 if (delayed_work_pending(&bond->mii_work)) {
585 cancel_delayed_work(&bond->mii_work);
586 flush_workqueue(bond->wq);
589 if (!bond->params.arp_targets[0]) {
590 pr_info("%s: ARP monitoring has been set up, but no ARP targets have been specified.\n",
591 bond->dev->name);
593 if (bond->dev->flags & IFF_UP) {
594 /* If the interface is up, we may need to fire off
595 * the ARP timer. If the interface is down, the
596 * timer will get fired off when the open function
597 * is called.
599 if (!delayed_work_pending(&bond->arp_work)) {
600 if (bond->params.mode == BOND_MODE_ACTIVEBACKUP)
601 INIT_DELAYED_WORK(&bond->arp_work,
602 bond_activebackup_arp_mon);
603 else
604 INIT_DELAYED_WORK(&bond->arp_work,
605 bond_loadbalance_arp_mon);
607 queue_delayed_work(bond->wq, &bond->arp_work, 0);
611 out:
612 return ret;
614 static DEVICE_ATTR(arp_interval, S_IRUGO | S_IWUSR,
615 bonding_show_arp_interval, bonding_store_arp_interval);
618 * Show and set the arp targets.
620 static ssize_t bonding_show_arp_targets(struct device *d,
621 struct device_attribute *attr,
622 char *buf)
624 int i, res = 0;
625 struct bonding *bond = to_bond(d);
627 for (i = 0; i < BOND_MAX_ARP_TARGETS; i++) {
628 if (bond->params.arp_targets[i])
629 res += sprintf(buf + res, "%pI4 ",
630 &bond->params.arp_targets[i]);
632 if (res)
633 buf[res-1] = '\n'; /* eat the leftover space */
634 return res;
637 static ssize_t bonding_store_arp_targets(struct device *d,
638 struct device_attribute *attr,
639 const char *buf, size_t count)
641 __be32 newtarget;
642 int i = 0, done = 0, ret = count;
643 struct bonding *bond = to_bond(d);
644 __be32 *targets;
646 targets = bond->params.arp_targets;
647 newtarget = in_aton(buf + 1);
648 /* look for adds */
649 if (buf[0] == '+') {
650 if ((newtarget == 0) || (newtarget == htonl(INADDR_BROADCAST))) {
651 pr_err("%s: invalid ARP target %pI4 specified for addition\n",
652 bond->dev->name, &newtarget);
653 ret = -EINVAL;
654 goto out;
656 /* look for an empty slot to put the target in, and check for dupes */
657 for (i = 0; (i < BOND_MAX_ARP_TARGETS) && !done; i++) {
658 if (targets[i] == newtarget) { /* duplicate */
659 pr_err("%s: ARP target %pI4 is already present\n",
660 bond->dev->name, &newtarget);
661 ret = -EINVAL;
662 goto out;
664 if (targets[i] == 0) {
665 pr_info("%s: adding ARP target %pI4.\n",
666 bond->dev->name, &newtarget);
667 done = 1;
668 targets[i] = newtarget;
671 if (!done) {
672 pr_err("%s: ARP target table is full!\n",
673 bond->dev->name);
674 ret = -EINVAL;
675 goto out;
678 } else if (buf[0] == '-') {
679 if ((newtarget == 0) || (newtarget == htonl(INADDR_BROADCAST))) {
680 pr_err("%s: invalid ARP target %pI4 specified for removal\n",
681 bond->dev->name, &newtarget);
682 ret = -EINVAL;
683 goto out;
686 for (i = 0; (i < BOND_MAX_ARP_TARGETS) && !done; i++) {
687 if (targets[i] == newtarget) {
688 int j;
689 pr_info("%s: removing ARP target %pI4.\n",
690 bond->dev->name, &newtarget);
691 for (j = i; (j < (BOND_MAX_ARP_TARGETS-1)) && targets[j+1]; j++)
692 targets[j] = targets[j+1];
694 targets[j] = 0;
695 done = 1;
698 if (!done) {
699 pr_info("%s: unable to remove nonexistent ARP target %pI4.\n",
700 bond->dev->name, &newtarget);
701 ret = -EINVAL;
702 goto out;
704 } else {
705 pr_err("no command found in arp_ip_targets file for bond %s. Use +<addr> or -<addr>.\n",
706 bond->dev->name);
707 ret = -EPERM;
708 goto out;
711 out:
712 return ret;
714 static DEVICE_ATTR(arp_ip_target, S_IRUGO | S_IWUSR , bonding_show_arp_targets, bonding_store_arp_targets);
717 * Show and set the up and down delays. These must be multiples of the
718 * MII monitoring value, and are stored internally as the multiplier.
719 * Thus, we must translate to MS for the real world.
721 static ssize_t bonding_show_downdelay(struct device *d,
722 struct device_attribute *attr,
723 char *buf)
725 struct bonding *bond = to_bond(d);
727 return sprintf(buf, "%d\n", bond->params.downdelay * bond->params.miimon);
730 static ssize_t bonding_store_downdelay(struct device *d,
731 struct device_attribute *attr,
732 const char *buf, size_t count)
734 int new_value, ret = count;
735 struct bonding *bond = to_bond(d);
737 if (!(bond->params.miimon)) {
738 pr_err("%s: Unable to set down delay as MII monitoring is disabled\n",
739 bond->dev->name);
740 ret = -EPERM;
741 goto out;
744 if (sscanf(buf, "%d", &new_value) != 1) {
745 pr_err("%s: no down delay value specified.\n", bond->dev->name);
746 ret = -EINVAL;
747 goto out;
749 if (new_value < 0) {
750 pr_err("%s: Invalid down delay value %d not in range %d-%d; rejected.\n",
751 bond->dev->name, new_value, 1, INT_MAX);
752 ret = -EINVAL;
753 goto out;
754 } else {
755 if ((new_value % bond->params.miimon) != 0) {
756 pr_warning("%s: Warning: down delay (%d) is not a multiple of miimon (%d), delay rounded to %d ms\n",
757 bond->dev->name, new_value,
758 bond->params.miimon,
759 (new_value / bond->params.miimon) *
760 bond->params.miimon);
762 bond->params.downdelay = new_value / bond->params.miimon;
763 pr_info("%s: Setting down delay to %d.\n",
764 bond->dev->name,
765 bond->params.downdelay * bond->params.miimon);
769 out:
770 return ret;
772 static DEVICE_ATTR(downdelay, S_IRUGO | S_IWUSR,
773 bonding_show_downdelay, bonding_store_downdelay);
775 static ssize_t bonding_show_updelay(struct device *d,
776 struct device_attribute *attr,
777 char *buf)
779 struct bonding *bond = to_bond(d);
781 return sprintf(buf, "%d\n", bond->params.updelay * bond->params.miimon);
785 static ssize_t bonding_store_updelay(struct device *d,
786 struct device_attribute *attr,
787 const char *buf, size_t count)
789 int new_value, ret = count;
790 struct bonding *bond = to_bond(d);
792 if (!(bond->params.miimon)) {
793 pr_err("%s: Unable to set up delay as MII monitoring is disabled\n",
794 bond->dev->name);
795 ret = -EPERM;
796 goto out;
799 if (sscanf(buf, "%d", &new_value) != 1) {
800 pr_err("%s: no up delay value specified.\n",
801 bond->dev->name);
802 ret = -EINVAL;
803 goto out;
805 if (new_value < 0) {
806 pr_err("%s: Invalid down delay value %d not in range %d-%d; rejected.\n",
807 bond->dev->name, new_value, 1, INT_MAX);
808 ret = -EINVAL;
809 goto out;
810 } else {
811 if ((new_value % bond->params.miimon) != 0) {
812 pr_warning("%s: Warning: up delay (%d) is not a multiple of miimon (%d), updelay rounded to %d ms\n",
813 bond->dev->name, new_value,
814 bond->params.miimon,
815 (new_value / bond->params.miimon) *
816 bond->params.miimon);
818 bond->params.updelay = new_value / bond->params.miimon;
819 pr_info("%s: Setting up delay to %d.\n",
820 bond->dev->name,
821 bond->params.updelay * bond->params.miimon);
824 out:
825 return ret;
827 static DEVICE_ATTR(updelay, S_IRUGO | S_IWUSR,
828 bonding_show_updelay, bonding_store_updelay);
831 * Show and set the LACP interval. Interface must be down, and the mode
832 * must be set to 802.3ad mode.
834 static ssize_t bonding_show_lacp(struct device *d,
835 struct device_attribute *attr,
836 char *buf)
838 struct bonding *bond = to_bond(d);
840 return sprintf(buf, "%s %d\n",
841 bond_lacp_tbl[bond->params.lacp_fast].modename,
842 bond->params.lacp_fast);
845 static ssize_t bonding_store_lacp(struct device *d,
846 struct device_attribute *attr,
847 const char *buf, size_t count)
849 int new_value, ret = count;
850 struct bonding *bond = to_bond(d);
852 if (bond->dev->flags & IFF_UP) {
853 pr_err("%s: Unable to update LACP rate because interface is up.\n",
854 bond->dev->name);
855 ret = -EPERM;
856 goto out;
859 if (bond->params.mode != BOND_MODE_8023AD) {
860 pr_err("%s: Unable to update LACP rate because bond is not in 802.3ad mode.\n",
861 bond->dev->name);
862 ret = -EPERM;
863 goto out;
866 new_value = bond_parse_parm(buf, bond_lacp_tbl);
868 if ((new_value == 1) || (new_value == 0)) {
869 bond->params.lacp_fast = new_value;
870 pr_info("%s: Setting LACP rate to %s (%d).\n",
871 bond->dev->name, bond_lacp_tbl[new_value].modename,
872 new_value);
873 } else {
874 pr_err("%s: Ignoring invalid LACP rate value %.*s.\n",
875 bond->dev->name, (int)strlen(buf) - 1, buf);
876 ret = -EINVAL;
878 out:
879 return ret;
881 static DEVICE_ATTR(lacp_rate, S_IRUGO | S_IWUSR,
882 bonding_show_lacp, bonding_store_lacp);
884 static ssize_t bonding_show_ad_select(struct device *d,
885 struct device_attribute *attr,
886 char *buf)
888 struct bonding *bond = to_bond(d);
890 return sprintf(buf, "%s %d\n",
891 ad_select_tbl[bond->params.ad_select].modename,
892 bond->params.ad_select);
896 static ssize_t bonding_store_ad_select(struct device *d,
897 struct device_attribute *attr,
898 const char *buf, size_t count)
900 int new_value, ret = count;
901 struct bonding *bond = to_bond(d);
903 if (bond->dev->flags & IFF_UP) {
904 pr_err("%s: Unable to update ad_select because interface is up.\n",
905 bond->dev->name);
906 ret = -EPERM;
907 goto out;
910 new_value = bond_parse_parm(buf, ad_select_tbl);
912 if (new_value != -1) {
913 bond->params.ad_select = new_value;
914 pr_info("%s: Setting ad_select to %s (%d).\n",
915 bond->dev->name, ad_select_tbl[new_value].modename,
916 new_value);
917 } else {
918 pr_err("%s: Ignoring invalid ad_select value %.*s.\n",
919 bond->dev->name, (int)strlen(buf) - 1, buf);
920 ret = -EINVAL;
922 out:
923 return ret;
925 static DEVICE_ATTR(ad_select, S_IRUGO | S_IWUSR,
926 bonding_show_ad_select, bonding_store_ad_select);
929 * Show and set the number of grat ARP to send after a failover event.
931 static ssize_t bonding_show_n_grat_arp(struct device *d,
932 struct device_attribute *attr,
933 char *buf)
935 struct bonding *bond = to_bond(d);
937 return sprintf(buf, "%d\n", bond->params.num_grat_arp);
940 static ssize_t bonding_store_n_grat_arp(struct device *d,
941 struct device_attribute *attr,
942 const char *buf, size_t count)
944 int new_value, ret = count;
945 struct bonding *bond = to_bond(d);
947 if (sscanf(buf, "%d", &new_value) != 1) {
948 pr_err("%s: no num_grat_arp value specified.\n",
949 bond->dev->name);
950 ret = -EINVAL;
951 goto out;
953 if (new_value < 0 || new_value > 255) {
954 pr_err("%s: Invalid num_grat_arp value %d not in range 0-255; rejected.\n",
955 bond->dev->name, new_value);
956 ret = -EINVAL;
957 goto out;
958 } else {
959 bond->params.num_grat_arp = new_value;
961 out:
962 return ret;
964 static DEVICE_ATTR(num_grat_arp, S_IRUGO | S_IWUSR,
965 bonding_show_n_grat_arp, bonding_store_n_grat_arp);
968 * Show and set the number of unsolicited NA's to send after a failover event.
970 static ssize_t bonding_show_n_unsol_na(struct device *d,
971 struct device_attribute *attr,
972 char *buf)
974 struct bonding *bond = to_bond(d);
976 return sprintf(buf, "%d\n", bond->params.num_unsol_na);
979 static ssize_t bonding_store_n_unsol_na(struct device *d,
980 struct device_attribute *attr,
981 const char *buf, size_t count)
983 int new_value, ret = count;
984 struct bonding *bond = to_bond(d);
986 if (sscanf(buf, "%d", &new_value) != 1) {
987 pr_err("%s: no num_unsol_na value specified.\n",
988 bond->dev->name);
989 ret = -EINVAL;
990 goto out;
993 if (new_value < 0 || new_value > 255) {
994 pr_err("%s: Invalid num_unsol_na value %d not in range 0-255; rejected.\n",
995 bond->dev->name, new_value);
996 ret = -EINVAL;
997 goto out;
998 } else
999 bond->params.num_unsol_na = new_value;
1000 out:
1001 return ret;
1003 static DEVICE_ATTR(num_unsol_na, S_IRUGO | S_IWUSR,
1004 bonding_show_n_unsol_na, bonding_store_n_unsol_na);
1007 * Show and set the MII monitor interval. There are two tricky bits
1008 * here. First, if MII monitoring is activated, then we must disable
1009 * ARP monitoring. Second, if the timer isn't running, we must
1010 * start it.
1012 static ssize_t bonding_show_miimon(struct device *d,
1013 struct device_attribute *attr,
1014 char *buf)
1016 struct bonding *bond = to_bond(d);
1018 return sprintf(buf, "%d\n", bond->params.miimon);
1021 static ssize_t bonding_store_miimon(struct device *d,
1022 struct device_attribute *attr,
1023 const char *buf, size_t count)
1025 int new_value, ret = count;
1026 struct bonding *bond = to_bond(d);
1028 if (sscanf(buf, "%d", &new_value) != 1) {
1029 pr_err("%s: no miimon value specified.\n",
1030 bond->dev->name);
1031 ret = -EINVAL;
1032 goto out;
1034 if (new_value < 0) {
1035 pr_err("%s: Invalid miimon value %d not in range %d-%d; rejected.\n",
1036 bond->dev->name, new_value, 1, INT_MAX);
1037 ret = -EINVAL;
1038 goto out;
1039 } else {
1040 pr_info("%s: Setting MII monitoring interval to %d.\n",
1041 bond->dev->name, new_value);
1042 bond->params.miimon = new_value;
1043 if (bond->params.updelay)
1044 pr_info("%s: Note: Updating updelay (to %d) since it is a multiple of the miimon value.\n",
1045 bond->dev->name,
1046 bond->params.updelay * bond->params.miimon);
1047 if (bond->params.downdelay)
1048 pr_info("%s: Note: Updating downdelay (to %d) since it is a multiple of the miimon value.\n",
1049 bond->dev->name,
1050 bond->params.downdelay * bond->params.miimon);
1051 if (bond->params.arp_interval) {
1052 pr_info("%s: MII monitoring cannot be used with ARP monitoring. Disabling ARP monitoring...\n",
1053 bond->dev->name);
1054 bond->params.arp_interval = 0;
1055 bond->dev->priv_flags &= ~IFF_MASTER_ARPMON;
1056 if (bond->params.arp_validate) {
1057 bond_unregister_arp(bond);
1058 bond->params.arp_validate =
1059 BOND_ARP_VALIDATE_NONE;
1061 if (delayed_work_pending(&bond->arp_work)) {
1062 cancel_delayed_work(&bond->arp_work);
1063 flush_workqueue(bond->wq);
1067 if (bond->dev->flags & IFF_UP) {
1068 /* If the interface is up, we may need to fire off
1069 * the MII timer. If the interface is down, the
1070 * timer will get fired off when the open function
1071 * is called.
1073 if (!delayed_work_pending(&bond->mii_work)) {
1074 INIT_DELAYED_WORK(&bond->mii_work,
1075 bond_mii_monitor);
1076 queue_delayed_work(bond->wq,
1077 &bond->mii_work, 0);
1081 out:
1082 return ret;
1084 static DEVICE_ATTR(miimon, S_IRUGO | S_IWUSR,
1085 bonding_show_miimon, bonding_store_miimon);
1088 * Show and set the primary slave. The store function is much
1089 * simpler than bonding_store_slaves function because it only needs to
1090 * handle one interface name.
1091 * The bond must be a mode that supports a primary for this be
1092 * set.
1094 static ssize_t bonding_show_primary(struct device *d,
1095 struct device_attribute *attr,
1096 char *buf)
1098 int count = 0;
1099 struct bonding *bond = to_bond(d);
1101 if (bond->primary_slave)
1102 count = sprintf(buf, "%s\n", bond->primary_slave->dev->name);
1104 return count;
1107 static ssize_t bonding_store_primary(struct device *d,
1108 struct device_attribute *attr,
1109 const char *buf, size_t count)
1111 int i;
1112 struct slave *slave;
1113 struct bonding *bond = to_bond(d);
1115 if (!rtnl_trylock())
1116 return restart_syscall();
1117 read_lock(&bond->lock);
1118 write_lock_bh(&bond->curr_slave_lock);
1120 if (!USES_PRIMARY(bond->params.mode)) {
1121 pr_info("%s: Unable to set primary slave; %s is in mode %d\n",
1122 bond->dev->name, bond->dev->name, bond->params.mode);
1123 } else {
1124 bond_for_each_slave(bond, slave, i) {
1125 if (strnicmp
1126 (slave->dev->name, buf,
1127 strlen(slave->dev->name)) == 0) {
1128 pr_info("%s: Setting %s as primary slave.\n",
1129 bond->dev->name, slave->dev->name);
1130 bond->primary_slave = slave;
1131 strcpy(bond->params.primary, slave->dev->name);
1132 bond_select_active_slave(bond);
1133 goto out;
1137 /* if we got here, then we didn't match the name of any slave */
1139 if (strlen(buf) == 0 || buf[0] == '\n') {
1140 pr_info("%s: Setting primary slave to None.\n",
1141 bond->dev->name);
1142 bond->primary_slave = NULL;
1143 bond_select_active_slave(bond);
1144 } else {
1145 pr_info("%s: Unable to set %.*s as primary slave as it is not a slave.\n",
1146 bond->dev->name, (int)strlen(buf) - 1, buf);
1149 out:
1150 write_unlock_bh(&bond->curr_slave_lock);
1151 read_unlock(&bond->lock);
1152 rtnl_unlock();
1154 return count;
1156 static DEVICE_ATTR(primary, S_IRUGO | S_IWUSR,
1157 bonding_show_primary, bonding_store_primary);
1160 * Show and set the primary_reselect flag.
1162 static ssize_t bonding_show_primary_reselect(struct device *d,
1163 struct device_attribute *attr,
1164 char *buf)
1166 struct bonding *bond = to_bond(d);
1168 return sprintf(buf, "%s %d\n",
1169 pri_reselect_tbl[bond->params.primary_reselect].modename,
1170 bond->params.primary_reselect);
1173 static ssize_t bonding_store_primary_reselect(struct device *d,
1174 struct device_attribute *attr,
1175 const char *buf, size_t count)
1177 int new_value, ret = count;
1178 struct bonding *bond = to_bond(d);
1180 if (!rtnl_trylock())
1181 return restart_syscall();
1183 new_value = bond_parse_parm(buf, pri_reselect_tbl);
1184 if (new_value < 0) {
1185 pr_err("%s: Ignoring invalid primary_reselect value %.*s.\n",
1186 bond->dev->name,
1187 (int) strlen(buf) - 1, buf);
1188 ret = -EINVAL;
1189 goto out;
1192 bond->params.primary_reselect = new_value;
1193 pr_info("%s: setting primary_reselect to %s (%d).\n",
1194 bond->dev->name, pri_reselect_tbl[new_value].modename,
1195 new_value);
1197 read_lock(&bond->lock);
1198 write_lock_bh(&bond->curr_slave_lock);
1199 bond_select_active_slave(bond);
1200 write_unlock_bh(&bond->curr_slave_lock);
1201 read_unlock(&bond->lock);
1202 out:
1203 rtnl_unlock();
1204 return ret;
1206 static DEVICE_ATTR(primary_reselect, S_IRUGO | S_IWUSR,
1207 bonding_show_primary_reselect,
1208 bonding_store_primary_reselect);
1211 * Show and set the use_carrier flag.
1213 static ssize_t bonding_show_carrier(struct device *d,
1214 struct device_attribute *attr,
1215 char *buf)
1217 struct bonding *bond = to_bond(d);
1219 return sprintf(buf, "%d\n", bond->params.use_carrier);
1222 static ssize_t bonding_store_carrier(struct device *d,
1223 struct device_attribute *attr,
1224 const char *buf, size_t count)
1226 int new_value, ret = count;
1227 struct bonding *bond = to_bond(d);
1230 if (sscanf(buf, "%d", &new_value) != 1) {
1231 pr_err("%s: no use_carrier value specified.\n",
1232 bond->dev->name);
1233 ret = -EINVAL;
1234 goto out;
1236 if ((new_value == 0) || (new_value == 1)) {
1237 bond->params.use_carrier = new_value;
1238 pr_info("%s: Setting use_carrier to %d.\n",
1239 bond->dev->name, new_value);
1240 } else {
1241 pr_info("%s: Ignoring invalid use_carrier value %d.\n",
1242 bond->dev->name, new_value);
1244 out:
1245 return count;
1247 static DEVICE_ATTR(use_carrier, S_IRUGO | S_IWUSR,
1248 bonding_show_carrier, bonding_store_carrier);
1252 * Show and set currently active_slave.
1254 static ssize_t bonding_show_active_slave(struct device *d,
1255 struct device_attribute *attr,
1256 char *buf)
1258 struct slave *curr;
1259 struct bonding *bond = to_bond(d);
1260 int count = 0;
1262 read_lock(&bond->curr_slave_lock);
1263 curr = bond->curr_active_slave;
1264 read_unlock(&bond->curr_slave_lock);
1266 if (USES_PRIMARY(bond->params.mode) && curr)
1267 count = sprintf(buf, "%s\n", curr->dev->name);
1268 return count;
1271 static ssize_t bonding_store_active_slave(struct device *d,
1272 struct device_attribute *attr,
1273 const char *buf, size_t count)
1275 int i;
1276 struct slave *slave;
1277 struct slave *old_active = NULL;
1278 struct slave *new_active = NULL;
1279 struct bonding *bond = to_bond(d);
1281 if (!rtnl_trylock())
1282 return restart_syscall();
1283 read_lock(&bond->lock);
1284 write_lock_bh(&bond->curr_slave_lock);
1286 if (!USES_PRIMARY(bond->params.mode))
1287 pr_info("%s: Unable to change active slave; %s is in mode %d\n",
1288 bond->dev->name, bond->dev->name, bond->params.mode);
1289 else {
1290 bond_for_each_slave(bond, slave, i) {
1291 if (strnicmp
1292 (slave->dev->name, buf,
1293 strlen(slave->dev->name)) == 0) {
1294 old_active = bond->curr_active_slave;
1295 new_active = slave;
1296 if (new_active == old_active) {
1297 /* do nothing */
1298 pr_info("%s: %s is already the current active slave.\n",
1299 bond->dev->name,
1300 slave->dev->name);
1301 goto out;
1303 else {
1304 if ((new_active) &&
1305 (old_active) &&
1306 (new_active->link == BOND_LINK_UP) &&
1307 IS_UP(new_active->dev)) {
1308 pr_info("%s: Setting %s as active slave.\n",
1309 bond->dev->name,
1310 slave->dev->name);
1311 bond_change_active_slave(bond, new_active);
1313 else {
1314 pr_info("%s: Could not set %s as active slave; either %s is down or the link is down.\n",
1315 bond->dev->name,
1316 slave->dev->name,
1317 slave->dev->name);
1319 goto out;
1324 /* if we got here, then we didn't match the name of any slave */
1326 if (strlen(buf) == 0 || buf[0] == '\n') {
1327 pr_info("%s: Setting active slave to None.\n",
1328 bond->dev->name);
1329 bond->primary_slave = NULL;
1330 bond_select_active_slave(bond);
1331 } else {
1332 pr_info("%s: Unable to set %.*s as active slave as it is not a slave.\n",
1333 bond->dev->name, (int)strlen(buf) - 1, buf);
1336 out:
1337 write_unlock_bh(&bond->curr_slave_lock);
1338 read_unlock(&bond->lock);
1339 rtnl_unlock();
1341 return count;
1344 static DEVICE_ATTR(active_slave, S_IRUGO | S_IWUSR,
1345 bonding_show_active_slave, bonding_store_active_slave);
1349 * Show link status of the bond interface.
1351 static ssize_t bonding_show_mii_status(struct device *d,
1352 struct device_attribute *attr,
1353 char *buf)
1355 struct slave *curr;
1356 struct bonding *bond = to_bond(d);
1358 read_lock(&bond->curr_slave_lock);
1359 curr = bond->curr_active_slave;
1360 read_unlock(&bond->curr_slave_lock);
1362 return sprintf(buf, "%s\n", curr ? "up" : "down");
1364 static DEVICE_ATTR(mii_status, S_IRUGO, bonding_show_mii_status, NULL);
1368 * Show current 802.3ad aggregator ID.
1370 static ssize_t bonding_show_ad_aggregator(struct device *d,
1371 struct device_attribute *attr,
1372 char *buf)
1374 int count = 0;
1375 struct bonding *bond = to_bond(d);
1377 if (bond->params.mode == BOND_MODE_8023AD) {
1378 struct ad_info ad_info;
1379 count = sprintf(buf, "%d\n",
1380 (bond_3ad_get_active_agg_info(bond, &ad_info))
1381 ? 0 : ad_info.aggregator_id);
1384 return count;
1386 static DEVICE_ATTR(ad_aggregator, S_IRUGO, bonding_show_ad_aggregator, NULL);
1390 * Show number of active 802.3ad ports.
1392 static ssize_t bonding_show_ad_num_ports(struct device *d,
1393 struct device_attribute *attr,
1394 char *buf)
1396 int count = 0;
1397 struct bonding *bond = to_bond(d);
1399 if (bond->params.mode == BOND_MODE_8023AD) {
1400 struct ad_info ad_info;
1401 count = sprintf(buf, "%d\n",
1402 (bond_3ad_get_active_agg_info(bond, &ad_info))
1403 ? 0 : ad_info.ports);
1406 return count;
1408 static DEVICE_ATTR(ad_num_ports, S_IRUGO, bonding_show_ad_num_ports, NULL);
1412 * Show current 802.3ad actor key.
1414 static ssize_t bonding_show_ad_actor_key(struct device *d,
1415 struct device_attribute *attr,
1416 char *buf)
1418 int count = 0;
1419 struct bonding *bond = to_bond(d);
1421 if (bond->params.mode == BOND_MODE_8023AD) {
1422 struct ad_info ad_info;
1423 count = sprintf(buf, "%d\n",
1424 (bond_3ad_get_active_agg_info(bond, &ad_info))
1425 ? 0 : ad_info.actor_key);
1428 return count;
1430 static DEVICE_ATTR(ad_actor_key, S_IRUGO, bonding_show_ad_actor_key, NULL);
1434 * Show current 802.3ad partner key.
1436 static ssize_t bonding_show_ad_partner_key(struct device *d,
1437 struct device_attribute *attr,
1438 char *buf)
1440 int count = 0;
1441 struct bonding *bond = to_bond(d);
1443 if (bond->params.mode == BOND_MODE_8023AD) {
1444 struct ad_info ad_info;
1445 count = sprintf(buf, "%d\n",
1446 (bond_3ad_get_active_agg_info(bond, &ad_info))
1447 ? 0 : ad_info.partner_key);
1450 return count;
1452 static DEVICE_ATTR(ad_partner_key, S_IRUGO, bonding_show_ad_partner_key, NULL);
1456 * Show current 802.3ad partner mac.
1458 static ssize_t bonding_show_ad_partner_mac(struct device *d,
1459 struct device_attribute *attr,
1460 char *buf)
1462 int count = 0;
1463 struct bonding *bond = to_bond(d);
1465 if (bond->params.mode == BOND_MODE_8023AD) {
1466 struct ad_info ad_info;
1467 if (!bond_3ad_get_active_agg_info(bond, &ad_info))
1468 count = sprintf(buf, "%pM\n", ad_info.partner_system);
1471 return count;
1473 static DEVICE_ATTR(ad_partner_mac, S_IRUGO, bonding_show_ad_partner_mac, NULL);
1477 static struct attribute *per_bond_attrs[] = {
1478 &dev_attr_slaves.attr,
1479 &dev_attr_mode.attr,
1480 &dev_attr_fail_over_mac.attr,
1481 &dev_attr_arp_validate.attr,
1482 &dev_attr_arp_interval.attr,
1483 &dev_attr_arp_ip_target.attr,
1484 &dev_attr_downdelay.attr,
1485 &dev_attr_updelay.attr,
1486 &dev_attr_lacp_rate.attr,
1487 &dev_attr_ad_select.attr,
1488 &dev_attr_xmit_hash_policy.attr,
1489 &dev_attr_num_grat_arp.attr,
1490 &dev_attr_num_unsol_na.attr,
1491 &dev_attr_miimon.attr,
1492 &dev_attr_primary.attr,
1493 &dev_attr_primary_reselect.attr,
1494 &dev_attr_use_carrier.attr,
1495 &dev_attr_active_slave.attr,
1496 &dev_attr_mii_status.attr,
1497 &dev_attr_ad_aggregator.attr,
1498 &dev_attr_ad_num_ports.attr,
1499 &dev_attr_ad_actor_key.attr,
1500 &dev_attr_ad_partner_key.attr,
1501 &dev_attr_ad_partner_mac.attr,
1502 NULL,
1505 static struct attribute_group bonding_group = {
1506 .name = "bonding",
1507 .attrs = per_bond_attrs,
1511 * Initialize sysfs. This sets up the bonding_masters file in
1512 * /sys/class/net.
1514 int bond_create_sysfs(void)
1516 int ret;
1518 ret = netdev_class_create_file(&class_attr_bonding_masters);
1520 * Permit multiple loads of the module by ignoring failures to
1521 * create the bonding_masters sysfs file. Bonding devices
1522 * created by second or subsequent loads of the module will
1523 * not be listed in, or controllable by, bonding_masters, but
1524 * will have the usual "bonding" sysfs directory.
1526 * This is done to preserve backwards compatibility for
1527 * initscripts/sysconfig, which load bonding multiple times to
1528 * configure multiple bonding devices.
1530 if (ret == -EEXIST) {
1531 /* Is someone being kinky and naming a device bonding_master? */
1532 if (__dev_get_by_name(&init_net,
1533 class_attr_bonding_masters.attr.name))
1534 pr_err("network device named %s already exists in sysfs",
1535 class_attr_bonding_masters.attr.name);
1536 ret = 0;
1539 return ret;
1544 * Remove /sys/class/net/bonding_masters.
1546 void bond_destroy_sysfs(void)
1548 netdev_class_remove_file(&class_attr_bonding_masters);
1552 * Initialize sysfs for each bond. This sets up and registers
1553 * the 'bondctl' directory for each individual bond under /sys/class/net.
1555 void bond_prepare_sysfs_group(struct bonding *bond)
1557 bond->dev->sysfs_groups[0] = &bonding_group;