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
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>
30 #include <linux/types.h>
31 #include <linux/string.h>
32 #include <linux/netdevice.h>
33 #include <linux/inetdevice.h>
35 #include <linux/sysfs.h>
36 #include <linux/ctype.h>
37 #include <linux/inet.h>
38 #include <linux/rtnetlink.h>
39 #include <linux/etherdevice.h>
40 #include <net/net_namespace.h>
41 #include <net/netns/generic.h>
42 #include <linux/nsproxy.h>
46 #define to_dev(obj) container_of(obj, struct device, kobj)
47 #define to_bond(cd) ((struct bonding *)(netdev_priv(to_net_dev(cd))))
50 * "show" function for the bond_masters attribute.
51 * The class parameter is ignored.
53 static ssize_t
bonding_show_bonds(struct class *cls
,
54 struct class_attribute
*attr
,
58 container_of(attr
, struct bond_net
, class_attr_bonding_masters
);
64 list_for_each_entry(bond
, &bn
->dev_list
, bond_list
) {
65 if (res
> (PAGE_SIZE
- IFNAMSIZ
)) {
66 /* not enough space for another interface name */
67 if ((PAGE_SIZE
- res
) > 10)
69 res
+= sprintf(buf
+ res
, "++more++ ");
72 res
+= sprintf(buf
+ res
, "%s ", bond
->dev
->name
);
75 buf
[res
-1] = '\n'; /* eat the leftover space */
81 static struct net_device
*bond_get_by_name(struct bond_net
*bn
, const char *ifname
)
85 list_for_each_entry(bond
, &bn
->dev_list
, bond_list
) {
86 if (strncmp(bond
->dev
->name
, ifname
, IFNAMSIZ
) == 0)
93 * "store" function for the bond_masters attribute. This is what
94 * creates and deletes entire bonds.
96 * The class parameter is ignored.
100 static ssize_t
bonding_store_bonds(struct class *cls
,
101 struct class_attribute
*attr
,
102 const char *buffer
, size_t count
)
104 struct bond_net
*bn
=
105 container_of(attr
, struct bond_net
, class_attr_bonding_masters
);
106 char command
[IFNAMSIZ
+ 1] = {0, };
110 sscanf(buffer
, "%16s", command
); /* IFNAMSIZ*/
111 ifname
= command
+ 1;
112 if ((strlen(command
) <= 1) ||
113 !dev_valid_name(ifname
))
116 if (command
[0] == '+') {
117 pr_info("%s is being created...\n", ifname
);
118 rv
= bond_create(bn
->net
, ifname
);
121 pr_info("%s already exists.\n", ifname
);
123 pr_info("%s creation failed.\n", ifname
);
126 } else if (command
[0] == '-') {
127 struct net_device
*bond_dev
;
130 bond_dev
= bond_get_by_name(bn
, ifname
);
132 pr_info("%s is being deleted...\n", ifname
);
133 unregister_netdevice(bond_dev
);
135 pr_err("unable to delete non-existent %s\n", ifname
);
142 /* Always return either count or an error. If you return 0, you'll
143 * get called forever, which is bad.
148 pr_err("no command found in bonding_masters. Use +ifname or -ifname.\n");
152 static const void *bonding_namespace(struct class *cls
,
153 const struct class_attribute
*attr
)
155 const struct bond_net
*bn
=
156 container_of(attr
, struct bond_net
, class_attr_bonding_masters
);
160 /* class attribute for bond_masters file. This ends up in /sys/class/net */
161 static const struct class_attribute class_attr_bonding_masters
= {
163 .name
= "bonding_masters",
164 .mode
= S_IWUSR
| S_IRUGO
,
166 .show
= bonding_show_bonds
,
167 .store
= bonding_store_bonds
,
168 .namespace = bonding_namespace
,
171 int bond_create_slave_symlinks(struct net_device
*master
,
172 struct net_device
*slave
)
174 char linkname
[IFNAMSIZ
+7];
177 /* first, create a link from the slave back to the master */
178 ret
= sysfs_create_link(&(slave
->dev
.kobj
), &(master
->dev
.kobj
),
182 /* next, create a link from the master to the slave */
183 sprintf(linkname
, "slave_%s", slave
->name
);
184 ret
= sysfs_create_link(&(master
->dev
.kobj
), &(slave
->dev
.kobj
),
187 /* free the master link created earlier in case of error */
189 sysfs_remove_link(&(slave
->dev
.kobj
), "master");
195 void bond_destroy_slave_symlinks(struct net_device
*master
,
196 struct net_device
*slave
)
198 char linkname
[IFNAMSIZ
+7];
200 sysfs_remove_link(&(slave
->dev
.kobj
), "master");
201 sprintf(linkname
, "slave_%s", slave
->name
);
202 sysfs_remove_link(&(master
->dev
.kobj
), linkname
);
207 * Show the slaves in the current bond.
209 static ssize_t
bonding_show_slaves(struct device
*d
,
210 struct device_attribute
*attr
, char *buf
)
212 struct bonding
*bond
= to_bond(d
);
216 read_lock(&bond
->lock
);
217 bond_for_each_slave(bond
, slave
) {
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;
222 res
+= sprintf(buf
+ res
, "++more++ ");
225 res
+= sprintf(buf
+ res
, "%s ", slave
->dev
->name
);
227 read_unlock(&bond
->lock
);
229 buf
[res
-1] = '\n'; /* eat the leftover space */
235 * Set the slaves in the current bond.
236 * This is supposed to be only thin wrapper for bond_enslave and bond_release.
237 * All hard work should be done there.
239 static ssize_t
bonding_store_slaves(struct device
*d
,
240 struct device_attribute
*attr
,
241 const char *buffer
, size_t count
)
243 char command
[IFNAMSIZ
+ 1] = { 0, };
245 int res
, ret
= count
;
246 struct net_device
*dev
;
247 struct bonding
*bond
= to_bond(d
);
250 return restart_syscall();
252 sscanf(buffer
, "%16s", command
); /* IFNAMSIZ*/
253 ifname
= command
+ 1;
254 if ((strlen(command
) <= 1) ||
255 !dev_valid_name(ifname
))
258 dev
= __dev_get_by_name(dev_net(bond
->dev
), ifname
);
260 pr_info("%s: Interface %s does not exist!\n",
261 bond
->dev
->name
, ifname
);
266 switch (command
[0]) {
268 pr_info("%s: Adding slave %s.\n", bond
->dev
->name
, dev
->name
);
269 res
= bond_enslave(bond
->dev
, dev
);
273 pr_info("%s: Removing slave %s.\n", bond
->dev
->name
, dev
->name
);
274 res
= bond_release(bond
->dev
, dev
);
286 pr_err("no command found in slaves file for bond %s. Use +ifname or -ifname.\n",
295 static DEVICE_ATTR(slaves
, S_IRUGO
| S_IWUSR
, bonding_show_slaves
,
296 bonding_store_slaves
);
299 * Show and set the bonding mode. The bond interface must be down to
302 static ssize_t
bonding_show_mode(struct device
*d
,
303 struct device_attribute
*attr
, char *buf
)
305 struct bonding
*bond
= to_bond(d
);
307 return sprintf(buf
, "%s %d\n",
308 bond_mode_tbl
[bond
->params
.mode
].modename
,
312 static ssize_t
bonding_store_mode(struct device
*d
,
313 struct device_attribute
*attr
,
314 const char *buf
, size_t count
)
316 int new_value
, ret
= count
;
317 struct bonding
*bond
= to_bond(d
);
320 return restart_syscall();
322 if (bond
->dev
->flags
& IFF_UP
) {
323 pr_err("unable to update mode of %s because interface is up.\n",
329 if (!list_empty(&bond
->slave_list
)) {
330 pr_err("unable to update mode of %s because it has slaves.\n",
336 new_value
= bond_parse_parm(buf
, bond_mode_tbl
);
338 pr_err("%s: Ignoring invalid mode value %.*s.\n",
339 bond
->dev
->name
, (int)strlen(buf
) - 1, buf
);
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
);
352 /* don't cache arp_validate between modes */
353 bond
->params
.arp_validate
= BOND_ARP_VALIDATE_NONE
;
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
,
363 static DEVICE_ATTR(mode
, S_IRUGO
| S_IWUSR
,
364 bonding_show_mode
, bonding_store_mode
);
367 * Show and set the bonding transmit hash method.
369 static ssize_t
bonding_show_xmit_hash(struct device
*d
,
370 struct device_attribute
*attr
,
373 struct bonding
*bond
= to_bond(d
);
375 return sprintf(buf
, "%s %d\n",
376 xmit_hashtype_tbl
[bond
->params
.xmit_policy
].modename
,
377 bond
->params
.xmit_policy
);
380 static ssize_t
bonding_store_xmit_hash(struct device
*d
,
381 struct device_attribute
*attr
,
382 const char *buf
, size_t count
)
384 int new_value
, ret
= count
;
385 struct bonding
*bond
= to_bond(d
);
387 new_value
= bond_parse_parm(buf
, xmit_hashtype_tbl
);
389 pr_err("%s: Ignoring invalid xmit hash policy value %.*s.\n",
391 (int)strlen(buf
) - 1, buf
);
394 bond
->params
.xmit_policy
= new_value
;
395 bond_set_mode_ops(bond
, bond
->params
.mode
);
396 pr_info("%s: setting xmit hash policy to %s (%d).\n",
398 xmit_hashtype_tbl
[new_value
].modename
, new_value
);
403 static DEVICE_ATTR(xmit_hash_policy
, S_IRUGO
| S_IWUSR
,
404 bonding_show_xmit_hash
, bonding_store_xmit_hash
);
407 * Show and set arp_validate.
409 static ssize_t
bonding_show_arp_validate(struct device
*d
,
410 struct device_attribute
*attr
,
413 struct bonding
*bond
= to_bond(d
);
415 return sprintf(buf
, "%s %d\n",
416 arp_validate_tbl
[bond
->params
.arp_validate
].modename
,
417 bond
->params
.arp_validate
);
420 static ssize_t
bonding_store_arp_validate(struct device
*d
,
421 struct device_attribute
*attr
,
422 const char *buf
, size_t count
)
424 struct bonding
*bond
= to_bond(d
);
425 int new_value
, ret
= count
;
428 return restart_syscall();
429 new_value
= bond_parse_parm(buf
, arp_validate_tbl
);
431 pr_err("%s: Ignoring invalid arp_validate value %s\n",
432 bond
->dev
->name
, buf
);
436 if (bond
->params
.mode
!= BOND_MODE_ACTIVEBACKUP
) {
437 pr_err("%s: arp_validate only supported in active-backup mode.\n",
442 pr_info("%s: setting arp_validate to %s (%d).\n",
443 bond
->dev
->name
, arp_validate_tbl
[new_value
].modename
,
446 if (bond
->dev
->flags
& IFF_UP
) {
448 bond
->recv_probe
= NULL
;
449 else if (bond
->params
.arp_interval
)
450 bond
->recv_probe
= bond_arp_rcv
;
452 bond
->params
.arp_validate
= new_value
;
459 static DEVICE_ATTR(arp_validate
, S_IRUGO
| S_IWUSR
, bonding_show_arp_validate
,
460 bonding_store_arp_validate
);
462 * Show and set arp_all_targets.
464 static ssize_t
bonding_show_arp_all_targets(struct device
*d
,
465 struct device_attribute
*attr
,
468 struct bonding
*bond
= to_bond(d
);
469 int value
= bond
->params
.arp_all_targets
;
471 return sprintf(buf
, "%s %d\n", arp_all_targets_tbl
[value
].modename
,
475 static ssize_t
bonding_store_arp_all_targets(struct device
*d
,
476 struct device_attribute
*attr
,
477 const char *buf
, size_t count
)
479 struct bonding
*bond
= to_bond(d
);
482 new_value
= bond_parse_parm(buf
, arp_all_targets_tbl
);
484 pr_err("%s: Ignoring invalid arp_all_targets value %s\n",
485 bond
->dev
->name
, buf
);
488 pr_info("%s: setting arp_all_targets to %s (%d).\n",
489 bond
->dev
->name
, arp_all_targets_tbl
[new_value
].modename
,
492 bond
->params
.arp_all_targets
= new_value
;
497 static DEVICE_ATTR(arp_all_targets
, S_IRUGO
| S_IWUSR
,
498 bonding_show_arp_all_targets
, bonding_store_arp_all_targets
);
501 * Show and store fail_over_mac. User only allowed to change the
502 * value when there are no slaves.
504 static ssize_t
bonding_show_fail_over_mac(struct device
*d
,
505 struct device_attribute
*attr
,
508 struct bonding
*bond
= to_bond(d
);
510 return sprintf(buf
, "%s %d\n",
511 fail_over_mac_tbl
[bond
->params
.fail_over_mac
].modename
,
512 bond
->params
.fail_over_mac
);
515 static ssize_t
bonding_store_fail_over_mac(struct device
*d
,
516 struct device_attribute
*attr
,
517 const char *buf
, size_t count
)
519 int new_value
, ret
= count
;
520 struct bonding
*bond
= to_bond(d
);
523 return restart_syscall();
525 if (!list_empty(&bond
->slave_list
)) {
526 pr_err("%s: Can't alter fail_over_mac with slaves in bond.\n",
532 new_value
= bond_parse_parm(buf
, fail_over_mac_tbl
);
534 pr_err("%s: Ignoring invalid fail_over_mac value %s.\n",
535 bond
->dev
->name
, buf
);
540 bond
->params
.fail_over_mac
= new_value
;
541 pr_info("%s: Setting fail_over_mac to %s (%d).\n",
542 bond
->dev
->name
, fail_over_mac_tbl
[new_value
].modename
,
550 static DEVICE_ATTR(fail_over_mac
, S_IRUGO
| S_IWUSR
,
551 bonding_show_fail_over_mac
, bonding_store_fail_over_mac
);
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
559 static ssize_t
bonding_show_arp_interval(struct device
*d
,
560 struct device_attribute
*attr
,
563 struct bonding
*bond
= to_bond(d
);
565 return sprintf(buf
, "%d\n", bond
->params
.arp_interval
);
568 static ssize_t
bonding_store_arp_interval(struct device
*d
,
569 struct device_attribute
*attr
,
570 const char *buf
, size_t count
)
572 struct bonding
*bond
= to_bond(d
);
573 int new_value
, ret
= count
;
576 return restart_syscall();
577 if (sscanf(buf
, "%d", &new_value
) != 1) {
578 pr_err("%s: no arp_interval value specified.\n",
584 pr_err("%s: Invalid arp_interval value %d not in range 0-%d; rejected.\n",
585 bond
->dev
->name
, new_value
, INT_MAX
);
589 if (bond
->params
.mode
== BOND_MODE_ALB
||
590 bond
->params
.mode
== BOND_MODE_TLB
||
591 bond
->params
.mode
== BOND_MODE_8023AD
) {
592 pr_info("%s: ARP monitoring cannot be used with ALB/TLB/802.3ad. Only MII monitoring is supported on %s.\n",
593 bond
->dev
->name
, bond
->dev
->name
);
597 pr_info("%s: Setting ARP monitoring interval to %d.\n",
598 bond
->dev
->name
, new_value
);
599 bond
->params
.arp_interval
= new_value
;
601 if (bond
->params
.miimon
) {
602 pr_info("%s: ARP monitoring cannot be used with MII monitoring. %s Disabling MII monitoring.\n",
603 bond
->dev
->name
, bond
->dev
->name
);
604 bond
->params
.miimon
= 0;
606 if (!bond
->params
.arp_targets
[0])
607 pr_info("%s: ARP monitoring has been set up, but no ARP targets have been specified.\n",
610 if (bond
->dev
->flags
& IFF_UP
) {
611 /* If the interface is up, we may need to fire off
612 * the ARP timer. If the interface is down, the
613 * timer will get fired off when the open function
617 if (bond
->params
.arp_validate
)
618 bond
->recv_probe
= NULL
;
619 cancel_delayed_work_sync(&bond
->arp_work
);
621 /* arp_validate can be set only in active-backup mode */
622 if (bond
->params
.arp_validate
)
623 bond
->recv_probe
= bond_arp_rcv
;
624 cancel_delayed_work_sync(&bond
->mii_work
);
625 queue_delayed_work(bond
->wq
, &bond
->arp_work
, 0);
632 static DEVICE_ATTR(arp_interval
, S_IRUGO
| S_IWUSR
,
633 bonding_show_arp_interval
, bonding_store_arp_interval
);
636 * Show and set the arp targets.
638 static ssize_t
bonding_show_arp_targets(struct device
*d
,
639 struct device_attribute
*attr
,
643 struct bonding
*bond
= to_bond(d
);
645 for (i
= 0; i
< BOND_MAX_ARP_TARGETS
; i
++) {
646 if (bond
->params
.arp_targets
[i
])
647 res
+= sprintf(buf
+ res
, "%pI4 ",
648 &bond
->params
.arp_targets
[i
]);
651 buf
[res
-1] = '\n'; /* eat the leftover space */
655 static ssize_t
bonding_store_arp_targets(struct device
*d
,
656 struct device_attribute
*attr
,
657 const char *buf
, size_t count
)
659 struct bonding
*bond
= to_bond(d
);
661 __be32 newtarget
, *targets
;
662 unsigned long *targets_rx
;
663 int ind
, i
, j
, ret
= -EINVAL
;
665 targets
= bond
->params
.arp_targets
;
666 newtarget
= in_aton(buf
+ 1);
669 if ((newtarget
== 0) || (newtarget
== htonl(INADDR_BROADCAST
))) {
670 pr_err("%s: invalid ARP target %pI4 specified for addition\n",
671 bond
->dev
->name
, &newtarget
);
675 if (bond_get_targets_ip(targets
, newtarget
) != -1) { /* dup */
676 pr_err("%s: ARP target %pI4 is already present\n",
677 bond
->dev
->name
, &newtarget
);
681 ind
= bond_get_targets_ip(targets
, 0); /* first free slot */
683 pr_err("%s: ARP target table is full!\n",
688 pr_info("%s: adding ARP target %pI4.\n", bond
->dev
->name
,
690 /* not to race with bond_arp_rcv */
691 write_lock_bh(&bond
->lock
);
692 bond_for_each_slave(bond
, slave
)
693 slave
->target_last_arp_rx
[ind
] = jiffies
;
694 targets
[ind
] = newtarget
;
695 write_unlock_bh(&bond
->lock
);
696 } else if (buf
[0] == '-') {
697 if ((newtarget
== 0) || (newtarget
== htonl(INADDR_BROADCAST
))) {
698 pr_err("%s: invalid ARP target %pI4 specified for removal\n",
699 bond
->dev
->name
, &newtarget
);
703 ind
= bond_get_targets_ip(targets
, newtarget
);
705 pr_err("%s: unable to remove nonexistent ARP target %pI4.\n",
706 bond
->dev
->name
, &newtarget
);
710 if (ind
== 0 && !targets
[1] && bond
->params
.arp_interval
)
711 pr_warn("%s: removing last arp target with arp_interval on\n",
714 pr_info("%s: removing ARP target %pI4.\n", bond
->dev
->name
,
717 write_lock_bh(&bond
->lock
);
718 bond_for_each_slave(bond
, slave
) {
719 targets_rx
= slave
->target_last_arp_rx
;
721 for (; (j
< BOND_MAX_ARP_TARGETS
-1) && targets
[j
+1]; j
++)
722 targets_rx
[j
] = targets_rx
[j
+1];
725 for (i
= ind
; (i
< BOND_MAX_ARP_TARGETS
-1) && targets
[i
+1]; i
++)
726 targets
[i
] = targets
[i
+1];
728 write_unlock_bh(&bond
->lock
);
730 pr_err("no command found in arp_ip_targets file for bond %s. Use +<addr> or -<addr>.\n",
740 static DEVICE_ATTR(arp_ip_target
, S_IRUGO
| S_IWUSR
, bonding_show_arp_targets
, bonding_store_arp_targets
);
743 * Show and set the up and down delays. These must be multiples of the
744 * MII monitoring value, and are stored internally as the multiplier.
745 * Thus, we must translate to MS for the real world.
747 static ssize_t
bonding_show_downdelay(struct device
*d
,
748 struct device_attribute
*attr
,
751 struct bonding
*bond
= to_bond(d
);
753 return sprintf(buf
, "%d\n", bond
->params
.downdelay
* bond
->params
.miimon
);
756 static ssize_t
bonding_store_downdelay(struct device
*d
,
757 struct device_attribute
*attr
,
758 const char *buf
, size_t count
)
760 int new_value
, ret
= count
;
761 struct bonding
*bond
= to_bond(d
);
764 return restart_syscall();
765 if (!(bond
->params
.miimon
)) {
766 pr_err("%s: Unable to set down delay as MII monitoring is disabled\n",
772 if (sscanf(buf
, "%d", &new_value
) != 1) {
773 pr_err("%s: no down delay value specified.\n", bond
->dev
->name
);
778 pr_err("%s: Invalid down delay value %d not in range %d-%d; rejected.\n",
779 bond
->dev
->name
, new_value
, 0, INT_MAX
);
783 if ((new_value
% bond
->params
.miimon
) != 0) {
784 pr_warning("%s: Warning: down delay (%d) is not a multiple of miimon (%d), delay rounded to %d ms\n",
785 bond
->dev
->name
, new_value
,
787 (new_value
/ bond
->params
.miimon
) *
788 bond
->params
.miimon
);
790 bond
->params
.downdelay
= new_value
/ bond
->params
.miimon
;
791 pr_info("%s: Setting down delay to %d.\n",
793 bond
->params
.downdelay
* bond
->params
.miimon
);
801 static DEVICE_ATTR(downdelay
, S_IRUGO
| S_IWUSR
,
802 bonding_show_downdelay
, bonding_store_downdelay
);
804 static ssize_t
bonding_show_updelay(struct device
*d
,
805 struct device_attribute
*attr
,
808 struct bonding
*bond
= to_bond(d
);
810 return sprintf(buf
, "%d\n", bond
->params
.updelay
* bond
->params
.miimon
);
814 static ssize_t
bonding_store_updelay(struct device
*d
,
815 struct device_attribute
*attr
,
816 const char *buf
, size_t count
)
818 int new_value
, ret
= count
;
819 struct bonding
*bond
= to_bond(d
);
822 return restart_syscall();
823 if (!(bond
->params
.miimon
)) {
824 pr_err("%s: Unable to set up delay as MII monitoring is disabled\n",
830 if (sscanf(buf
, "%d", &new_value
) != 1) {
831 pr_err("%s: no up delay value specified.\n",
837 pr_err("%s: Invalid up delay value %d not in range %d-%d; rejected.\n",
838 bond
->dev
->name
, new_value
, 0, INT_MAX
);
842 if ((new_value
% bond
->params
.miimon
) != 0) {
843 pr_warning("%s: Warning: up delay (%d) is not a multiple of miimon (%d), updelay rounded to %d ms\n",
844 bond
->dev
->name
, new_value
,
846 (new_value
/ bond
->params
.miimon
) *
847 bond
->params
.miimon
);
849 bond
->params
.updelay
= new_value
/ bond
->params
.miimon
;
850 pr_info("%s: Setting up delay to %d.\n",
852 bond
->params
.updelay
* bond
->params
.miimon
);
859 static DEVICE_ATTR(updelay
, S_IRUGO
| S_IWUSR
,
860 bonding_show_updelay
, bonding_store_updelay
);
863 * Show and set the LACP interval. Interface must be down, and the mode
864 * must be set to 802.3ad mode.
866 static ssize_t
bonding_show_lacp(struct device
*d
,
867 struct device_attribute
*attr
,
870 struct bonding
*bond
= to_bond(d
);
872 return sprintf(buf
, "%s %d\n",
873 bond_lacp_tbl
[bond
->params
.lacp_fast
].modename
,
874 bond
->params
.lacp_fast
);
877 static ssize_t
bonding_store_lacp(struct device
*d
,
878 struct device_attribute
*attr
,
879 const char *buf
, size_t count
)
881 struct bonding
*bond
= to_bond(d
);
882 int new_value
, ret
= count
;
885 return restart_syscall();
887 if (bond
->dev
->flags
& IFF_UP
) {
888 pr_err("%s: Unable to update LACP rate because interface is up.\n",
894 if (bond
->params
.mode
!= BOND_MODE_8023AD
) {
895 pr_err("%s: Unable to update LACP rate because bond is not in 802.3ad mode.\n",
901 new_value
= bond_parse_parm(buf
, bond_lacp_tbl
);
903 if ((new_value
== 1) || (new_value
== 0)) {
904 bond
->params
.lacp_fast
= new_value
;
905 bond_3ad_update_lacp_rate(bond
);
906 pr_info("%s: Setting LACP rate to %s (%d).\n",
907 bond
->dev
->name
, bond_lacp_tbl
[new_value
].modename
,
910 pr_err("%s: Ignoring invalid LACP rate value %.*s.\n",
911 bond
->dev
->name
, (int)strlen(buf
) - 1, buf
);
919 static DEVICE_ATTR(lacp_rate
, S_IRUGO
| S_IWUSR
,
920 bonding_show_lacp
, bonding_store_lacp
);
922 static ssize_t
bonding_show_min_links(struct device
*d
,
923 struct device_attribute
*attr
,
926 struct bonding
*bond
= to_bond(d
);
928 return sprintf(buf
, "%d\n", bond
->params
.min_links
);
931 static ssize_t
bonding_store_min_links(struct device
*d
,
932 struct device_attribute
*attr
,
933 const char *buf
, size_t count
)
935 struct bonding
*bond
= to_bond(d
);
937 unsigned int new_value
;
939 ret
= kstrtouint(buf
, 0, &new_value
);
941 pr_err("%s: Ignoring invalid min links value %s.\n",
942 bond
->dev
->name
, buf
);
946 pr_info("%s: Setting min links value to %u\n",
947 bond
->dev
->name
, new_value
);
948 bond
->params
.min_links
= new_value
;
951 static DEVICE_ATTR(min_links
, S_IRUGO
| S_IWUSR
,
952 bonding_show_min_links
, bonding_store_min_links
);
954 static ssize_t
bonding_show_ad_select(struct device
*d
,
955 struct device_attribute
*attr
,
958 struct bonding
*bond
= to_bond(d
);
960 return sprintf(buf
, "%s %d\n",
961 ad_select_tbl
[bond
->params
.ad_select
].modename
,
962 bond
->params
.ad_select
);
966 static ssize_t
bonding_store_ad_select(struct device
*d
,
967 struct device_attribute
*attr
,
968 const char *buf
, size_t count
)
970 int new_value
, ret
= count
;
971 struct bonding
*bond
= to_bond(d
);
973 if (bond
->dev
->flags
& IFF_UP
) {
974 pr_err("%s: Unable to update ad_select because interface is up.\n",
980 new_value
= bond_parse_parm(buf
, ad_select_tbl
);
982 if (new_value
!= -1) {
983 bond
->params
.ad_select
= new_value
;
984 pr_info("%s: Setting ad_select to %s (%d).\n",
985 bond
->dev
->name
, ad_select_tbl
[new_value
].modename
,
988 pr_err("%s: Ignoring invalid ad_select value %.*s.\n",
989 bond
->dev
->name
, (int)strlen(buf
) - 1, buf
);
995 static DEVICE_ATTR(ad_select
, S_IRUGO
| S_IWUSR
,
996 bonding_show_ad_select
, bonding_store_ad_select
);
999 * Show and set the number of peer notifications to send after a failover event.
1001 static ssize_t
bonding_show_num_peer_notif(struct device
*d
,
1002 struct device_attribute
*attr
,
1005 struct bonding
*bond
= to_bond(d
);
1006 return sprintf(buf
, "%d\n", bond
->params
.num_peer_notif
);
1009 static ssize_t
bonding_store_num_peer_notif(struct device
*d
,
1010 struct device_attribute
*attr
,
1011 const char *buf
, size_t count
)
1013 struct bonding
*bond
= to_bond(d
);
1014 int err
= kstrtou8(buf
, 10, &bond
->params
.num_peer_notif
);
1015 return err
? err
: count
;
1017 static DEVICE_ATTR(num_grat_arp
, S_IRUGO
| S_IWUSR
,
1018 bonding_show_num_peer_notif
, bonding_store_num_peer_notif
);
1019 static DEVICE_ATTR(num_unsol_na
, S_IRUGO
| S_IWUSR
,
1020 bonding_show_num_peer_notif
, bonding_store_num_peer_notif
);
1023 * Show and set the MII monitor interval. There are two tricky bits
1024 * here. First, if MII monitoring is activated, then we must disable
1025 * ARP monitoring. Second, if the timer isn't running, we must
1028 static ssize_t
bonding_show_miimon(struct device
*d
,
1029 struct device_attribute
*attr
,
1032 struct bonding
*bond
= to_bond(d
);
1034 return sprintf(buf
, "%d\n", bond
->params
.miimon
);
1037 static ssize_t
bonding_store_miimon(struct device
*d
,
1038 struct device_attribute
*attr
,
1039 const char *buf
, size_t count
)
1041 int new_value
, ret
= count
;
1042 struct bonding
*bond
= to_bond(d
);
1044 if (!rtnl_trylock())
1045 return restart_syscall();
1046 if (sscanf(buf
, "%d", &new_value
) != 1) {
1047 pr_err("%s: no miimon value specified.\n",
1052 if (new_value
< 0) {
1053 pr_err("%s: Invalid miimon value %d not in range %d-%d; rejected.\n",
1054 bond
->dev
->name
, new_value
, 0, INT_MAX
);
1058 pr_info("%s: Setting MII monitoring interval to %d.\n",
1059 bond
->dev
->name
, new_value
);
1060 bond
->params
.miimon
= new_value
;
1061 if (bond
->params
.updelay
)
1062 pr_info("%s: Note: Updating updelay (to %d) since it is a multiple of the miimon value.\n",
1064 bond
->params
.updelay
* bond
->params
.miimon
);
1065 if (bond
->params
.downdelay
)
1066 pr_info("%s: Note: Updating downdelay (to %d) since it is a multiple of the miimon value.\n",
1068 bond
->params
.downdelay
* bond
->params
.miimon
);
1069 if (new_value
&& bond
->params
.arp_interval
) {
1070 pr_info("%s: MII monitoring cannot be used with ARP monitoring. Disabling ARP monitoring...\n",
1072 bond
->params
.arp_interval
= 0;
1073 if (bond
->params
.arp_validate
)
1074 bond
->params
.arp_validate
= BOND_ARP_VALIDATE_NONE
;
1076 if (bond
->dev
->flags
& IFF_UP
) {
1077 /* If the interface is up, we may need to fire off
1078 * the MII timer. If the interface is down, the
1079 * timer will get fired off when the open function
1083 cancel_delayed_work_sync(&bond
->mii_work
);
1085 cancel_delayed_work_sync(&bond
->arp_work
);
1086 queue_delayed_work(bond
->wq
, &bond
->mii_work
, 0);
1093 static DEVICE_ATTR(miimon
, S_IRUGO
| S_IWUSR
,
1094 bonding_show_miimon
, bonding_store_miimon
);
1097 * Show and set the primary slave. The store function is much
1098 * simpler than bonding_store_slaves function because it only needs to
1099 * handle one interface name.
1100 * The bond must be a mode that supports a primary for this be
1103 static ssize_t
bonding_show_primary(struct device
*d
,
1104 struct device_attribute
*attr
,
1108 struct bonding
*bond
= to_bond(d
);
1110 if (bond
->primary_slave
)
1111 count
= sprintf(buf
, "%s\n", bond
->primary_slave
->dev
->name
);
1116 static ssize_t
bonding_store_primary(struct device
*d
,
1117 struct device_attribute
*attr
,
1118 const char *buf
, size_t count
)
1120 struct bonding
*bond
= to_bond(d
);
1121 char ifname
[IFNAMSIZ
];
1122 struct slave
*slave
;
1124 if (!rtnl_trylock())
1125 return restart_syscall();
1127 read_lock(&bond
->lock
);
1128 write_lock_bh(&bond
->curr_slave_lock
);
1130 if (!USES_PRIMARY(bond
->params
.mode
)) {
1131 pr_info("%s: Unable to set primary slave; %s is in mode %d\n",
1132 bond
->dev
->name
, bond
->dev
->name
, bond
->params
.mode
);
1136 sscanf(buf
, "%15s", ifname
); /* IFNAMSIZ */
1138 /* check to see if we are clearing primary */
1139 if (!strlen(ifname
) || buf
[0] == '\n') {
1140 pr_info("%s: Setting primary slave to None.\n",
1142 bond
->primary_slave
= NULL
;
1143 memset(bond
->params
.primary
, 0, sizeof(bond
->params
.primary
));
1144 bond_select_active_slave(bond
);
1148 bond_for_each_slave(bond
, slave
) {
1149 if (strncmp(slave
->dev
->name
, ifname
, IFNAMSIZ
) == 0) {
1150 pr_info("%s: Setting %s as primary slave.\n",
1151 bond
->dev
->name
, slave
->dev
->name
);
1152 bond
->primary_slave
= slave
;
1153 strcpy(bond
->params
.primary
, slave
->dev
->name
);
1154 bond_select_active_slave(bond
);
1159 strncpy(bond
->params
.primary
, ifname
, IFNAMSIZ
);
1160 bond
->params
.primary
[IFNAMSIZ
- 1] = 0;
1162 pr_info("%s: Recording %s as primary, "
1163 "but it has not been enslaved to %s yet.\n",
1164 bond
->dev
->name
, ifname
, bond
->dev
->name
);
1166 write_unlock_bh(&bond
->curr_slave_lock
);
1167 read_unlock(&bond
->lock
);
1168 unblock_netpoll_tx();
1173 static DEVICE_ATTR(primary
, S_IRUGO
| S_IWUSR
,
1174 bonding_show_primary
, bonding_store_primary
);
1177 * Show and set the primary_reselect flag.
1179 static ssize_t
bonding_show_primary_reselect(struct device
*d
,
1180 struct device_attribute
*attr
,
1183 struct bonding
*bond
= to_bond(d
);
1185 return sprintf(buf
, "%s %d\n",
1186 pri_reselect_tbl
[bond
->params
.primary_reselect
].modename
,
1187 bond
->params
.primary_reselect
);
1190 static ssize_t
bonding_store_primary_reselect(struct device
*d
,
1191 struct device_attribute
*attr
,
1192 const char *buf
, size_t count
)
1194 int new_value
, ret
= count
;
1195 struct bonding
*bond
= to_bond(d
);
1197 if (!rtnl_trylock())
1198 return restart_syscall();
1200 new_value
= bond_parse_parm(buf
, pri_reselect_tbl
);
1201 if (new_value
< 0) {
1202 pr_err("%s: Ignoring invalid primary_reselect value %.*s.\n",
1204 (int) strlen(buf
) - 1, buf
);
1209 bond
->params
.primary_reselect
= new_value
;
1210 pr_info("%s: setting primary_reselect to %s (%d).\n",
1211 bond
->dev
->name
, pri_reselect_tbl
[new_value
].modename
,
1215 read_lock(&bond
->lock
);
1216 write_lock_bh(&bond
->curr_slave_lock
);
1217 bond_select_active_slave(bond
);
1218 write_unlock_bh(&bond
->curr_slave_lock
);
1219 read_unlock(&bond
->lock
);
1220 unblock_netpoll_tx();
1225 static DEVICE_ATTR(primary_reselect
, S_IRUGO
| S_IWUSR
,
1226 bonding_show_primary_reselect
,
1227 bonding_store_primary_reselect
);
1230 * Show and set the use_carrier flag.
1232 static ssize_t
bonding_show_carrier(struct device
*d
,
1233 struct device_attribute
*attr
,
1236 struct bonding
*bond
= to_bond(d
);
1238 return sprintf(buf
, "%d\n", bond
->params
.use_carrier
);
1241 static ssize_t
bonding_store_carrier(struct device
*d
,
1242 struct device_attribute
*attr
,
1243 const char *buf
, size_t count
)
1245 int new_value
, ret
= count
;
1246 struct bonding
*bond
= to_bond(d
);
1249 if (sscanf(buf
, "%d", &new_value
) != 1) {
1250 pr_err("%s: no use_carrier value specified.\n",
1255 if ((new_value
== 0) || (new_value
== 1)) {
1256 bond
->params
.use_carrier
= new_value
;
1257 pr_info("%s: Setting use_carrier to %d.\n",
1258 bond
->dev
->name
, new_value
);
1260 pr_info("%s: Ignoring invalid use_carrier value %d.\n",
1261 bond
->dev
->name
, new_value
);
1266 static DEVICE_ATTR(use_carrier
, S_IRUGO
| S_IWUSR
,
1267 bonding_show_carrier
, bonding_store_carrier
);
1271 * Show and set currently active_slave.
1273 static ssize_t
bonding_show_active_slave(struct device
*d
,
1274 struct device_attribute
*attr
,
1277 struct bonding
*bond
= to_bond(d
);
1282 curr
= rcu_dereference(bond
->curr_active_slave
);
1283 if (USES_PRIMARY(bond
->params
.mode
) && curr
)
1284 count
= sprintf(buf
, "%s\n", curr
->dev
->name
);
1290 static ssize_t
bonding_store_active_slave(struct device
*d
,
1291 struct device_attribute
*attr
,
1292 const char *buf
, size_t count
)
1294 struct slave
*slave
, *old_active
, *new_active
;
1295 struct bonding
*bond
= to_bond(d
);
1296 char ifname
[IFNAMSIZ
];
1298 if (!rtnl_trylock())
1299 return restart_syscall();
1301 old_active
= new_active
= NULL
;
1303 read_lock(&bond
->lock
);
1304 write_lock_bh(&bond
->curr_slave_lock
);
1306 if (!USES_PRIMARY(bond
->params
.mode
)) {
1307 pr_info("%s: Unable to change active slave; %s is in mode %d\n",
1308 bond
->dev
->name
, bond
->dev
->name
, bond
->params
.mode
);
1312 sscanf(buf
, "%15s", ifname
); /* IFNAMSIZ */
1314 /* check to see if we are clearing active */
1315 if (!strlen(ifname
) || buf
[0] == '\n') {
1316 pr_info("%s: Clearing current active slave.\n",
1318 rcu_assign_pointer(bond
->curr_active_slave
, NULL
);
1319 bond_select_active_slave(bond
);
1323 bond_for_each_slave(bond
, slave
) {
1324 if (strncmp(slave
->dev
->name
, ifname
, IFNAMSIZ
) == 0) {
1325 old_active
= bond
->curr_active_slave
;
1327 if (new_active
== old_active
) {
1329 pr_info("%s: %s is already the current"
1337 (new_active
->link
== BOND_LINK_UP
) &&
1338 IS_UP(new_active
->dev
)) {
1339 pr_info("%s: Setting %s as active"
1343 bond_change_active_slave(bond
,
1346 pr_info("%s: Could not set %s as"
1347 " active slave; either %s is"
1348 " down or the link is down.\n",
1358 pr_info("%s: Unable to set %.*s as active slave.\n",
1359 bond
->dev
->name
, (int)strlen(buf
) - 1, buf
);
1361 write_unlock_bh(&bond
->curr_slave_lock
);
1362 read_unlock(&bond
->lock
);
1363 unblock_netpoll_tx();
1370 static DEVICE_ATTR(active_slave
, S_IRUGO
| S_IWUSR
,
1371 bonding_show_active_slave
, bonding_store_active_slave
);
1375 * Show link status of the bond interface.
1377 static ssize_t
bonding_show_mii_status(struct device
*d
,
1378 struct device_attribute
*attr
,
1381 struct bonding
*bond
= to_bond(d
);
1383 return sprintf(buf
, "%s\n", bond
->curr_active_slave
? "up" : "down");
1385 static DEVICE_ATTR(mii_status
, S_IRUGO
, bonding_show_mii_status
, NULL
);
1388 * Show current 802.3ad aggregator ID.
1390 static ssize_t
bonding_show_ad_aggregator(struct device
*d
,
1391 struct device_attribute
*attr
,
1395 struct bonding
*bond
= to_bond(d
);
1397 if (bond
->params
.mode
== BOND_MODE_8023AD
) {
1398 struct ad_info ad_info
;
1399 count
= sprintf(buf
, "%d\n",
1400 bond_3ad_get_active_agg_info(bond
, &ad_info
)
1401 ? 0 : ad_info
.aggregator_id
);
1406 static DEVICE_ATTR(ad_aggregator
, S_IRUGO
, bonding_show_ad_aggregator
, NULL
);
1410 * Show number of active 802.3ad ports.
1412 static ssize_t
bonding_show_ad_num_ports(struct device
*d
,
1413 struct device_attribute
*attr
,
1417 struct bonding
*bond
= to_bond(d
);
1419 if (bond
->params
.mode
== BOND_MODE_8023AD
) {
1420 struct ad_info ad_info
;
1421 count
= sprintf(buf
, "%d\n",
1422 bond_3ad_get_active_agg_info(bond
, &ad_info
)
1423 ? 0 : ad_info
.ports
);
1428 static DEVICE_ATTR(ad_num_ports
, S_IRUGO
, bonding_show_ad_num_ports
, NULL
);
1432 * Show current 802.3ad actor key.
1434 static ssize_t
bonding_show_ad_actor_key(struct device
*d
,
1435 struct device_attribute
*attr
,
1439 struct bonding
*bond
= to_bond(d
);
1441 if (bond
->params
.mode
== BOND_MODE_8023AD
) {
1442 struct ad_info ad_info
;
1443 count
= sprintf(buf
, "%d\n",
1444 bond_3ad_get_active_agg_info(bond
, &ad_info
)
1445 ? 0 : ad_info
.actor_key
);
1450 static DEVICE_ATTR(ad_actor_key
, S_IRUGO
, bonding_show_ad_actor_key
, NULL
);
1454 * Show current 802.3ad partner key.
1456 static ssize_t
bonding_show_ad_partner_key(struct device
*d
,
1457 struct device_attribute
*attr
,
1461 struct bonding
*bond
= to_bond(d
);
1463 if (bond
->params
.mode
== BOND_MODE_8023AD
) {
1464 struct ad_info ad_info
;
1465 count
= sprintf(buf
, "%d\n",
1466 bond_3ad_get_active_agg_info(bond
, &ad_info
)
1467 ? 0 : ad_info
.partner_key
);
1472 static DEVICE_ATTR(ad_partner_key
, S_IRUGO
, bonding_show_ad_partner_key
, NULL
);
1476 * Show current 802.3ad partner mac.
1478 static ssize_t
bonding_show_ad_partner_mac(struct device
*d
,
1479 struct device_attribute
*attr
,
1483 struct bonding
*bond
= to_bond(d
);
1485 if (bond
->params
.mode
== BOND_MODE_8023AD
) {
1486 struct ad_info ad_info
;
1487 if (!bond_3ad_get_active_agg_info(bond
, &ad_info
))
1488 count
= sprintf(buf
, "%pM\n", ad_info
.partner_system
);
1493 static DEVICE_ATTR(ad_partner_mac
, S_IRUGO
, bonding_show_ad_partner_mac
, NULL
);
1496 * Show the queue_ids of the slaves in the current bond.
1498 static ssize_t
bonding_show_queue_id(struct device
*d
,
1499 struct device_attribute
*attr
,
1502 struct bonding
*bond
= to_bond(d
);
1503 struct slave
*slave
;
1506 if (!rtnl_trylock())
1507 return restart_syscall();
1509 read_lock(&bond
->lock
);
1510 bond_for_each_slave(bond
, slave
) {
1511 if (res
> (PAGE_SIZE
- IFNAMSIZ
- 6)) {
1512 /* not enough space for another interface_name:queue_id pair */
1513 if ((PAGE_SIZE
- res
) > 10)
1514 res
= PAGE_SIZE
- 10;
1515 res
+= sprintf(buf
+ res
, "++more++ ");
1518 res
+= sprintf(buf
+ res
, "%s:%d ",
1519 slave
->dev
->name
, slave
->queue_id
);
1521 read_unlock(&bond
->lock
);
1523 buf
[res
-1] = '\n'; /* eat the leftover space */
1530 * Set the queue_ids of the slaves in the current bond. The bond
1531 * interface must be enslaved for this to work.
1533 static ssize_t
bonding_store_queue_id(struct device
*d
,
1534 struct device_attribute
*attr
,
1535 const char *buffer
, size_t count
)
1537 struct slave
*slave
, *update_slave
;
1538 struct bonding
*bond
= to_bond(d
);
1542 struct net_device
*sdev
= NULL
;
1544 if (!rtnl_trylock())
1545 return restart_syscall();
1547 /* delim will point to queue id if successful */
1548 delim
= strchr(buffer
, ':');
1553 * Terminate string that points to device name and bump it
1554 * up one, so we can read the queue id there.
1557 if (sscanf(++delim
, "%hd\n", &qid
) != 1)
1560 /* Check buffer length, valid ifname and queue id */
1561 if (strlen(buffer
) > IFNAMSIZ
||
1562 !dev_valid_name(buffer
) ||
1563 qid
> bond
->dev
->real_num_tx_queues
)
1566 /* Get the pointer to that interface if it exists */
1567 sdev
= __dev_get_by_name(dev_net(bond
->dev
), buffer
);
1571 read_lock(&bond
->lock
);
1573 /* Search for thes slave and check for duplicate qids */
1574 update_slave
= NULL
;
1575 bond_for_each_slave(bond
, slave
) {
1576 if (sdev
== slave
->dev
)
1578 * We don't need to check the matching
1579 * slave for dups, since we're overwriting it
1581 update_slave
= slave
;
1582 else if (qid
&& qid
== slave
->queue_id
) {
1583 goto err_no_cmd_unlock
;
1588 goto err_no_cmd_unlock
;
1590 /* Actually set the qids for the slave */
1591 update_slave
->queue_id
= qid
;
1593 read_unlock(&bond
->lock
);
1599 read_unlock(&bond
->lock
);
1601 pr_info("invalid input for queue_id set for %s.\n",
1607 static DEVICE_ATTR(queue_id
, S_IRUGO
| S_IWUSR
, bonding_show_queue_id
,
1608 bonding_store_queue_id
);
1612 * Show and set the all_slaves_active flag.
1614 static ssize_t
bonding_show_slaves_active(struct device
*d
,
1615 struct device_attribute
*attr
,
1618 struct bonding
*bond
= to_bond(d
);
1620 return sprintf(buf
, "%d\n", bond
->params
.all_slaves_active
);
1623 static ssize_t
bonding_store_slaves_active(struct device
*d
,
1624 struct device_attribute
*attr
,
1625 const char *buf
, size_t count
)
1627 struct bonding
*bond
= to_bond(d
);
1628 int new_value
, ret
= count
;
1629 struct slave
*slave
;
1631 if (sscanf(buf
, "%d", &new_value
) != 1) {
1632 pr_err("%s: no all_slaves_active value specified.\n",
1638 if (new_value
== bond
->params
.all_slaves_active
)
1641 if ((new_value
== 0) || (new_value
== 1)) {
1642 bond
->params
.all_slaves_active
= new_value
;
1644 pr_info("%s: Ignoring invalid all_slaves_active value %d.\n",
1645 bond
->dev
->name
, new_value
);
1650 read_lock(&bond
->lock
);
1651 bond_for_each_slave(bond
, slave
) {
1652 if (!bond_is_active_slave(slave
)) {
1654 slave
->inactive
= 0;
1656 slave
->inactive
= 1;
1659 read_unlock(&bond
->lock
);
1663 static DEVICE_ATTR(all_slaves_active
, S_IRUGO
| S_IWUSR
,
1664 bonding_show_slaves_active
, bonding_store_slaves_active
);
1667 * Show and set the number of IGMP membership reports to send on link failure
1669 static ssize_t
bonding_show_resend_igmp(struct device
*d
,
1670 struct device_attribute
*attr
,
1673 struct bonding
*bond
= to_bond(d
);
1675 return sprintf(buf
, "%d\n", bond
->params
.resend_igmp
);
1678 static ssize_t
bonding_store_resend_igmp(struct device
*d
,
1679 struct device_attribute
*attr
,
1680 const char *buf
, size_t count
)
1682 int new_value
, ret
= count
;
1683 struct bonding
*bond
= to_bond(d
);
1685 if (sscanf(buf
, "%d", &new_value
) != 1) {
1686 pr_err("%s: no resend_igmp value specified.\n",
1692 if (new_value
< 0 || new_value
> 255) {
1693 pr_err("%s: Invalid resend_igmp value %d not in range 0-255; rejected.\n",
1694 bond
->dev
->name
, new_value
);
1699 pr_info("%s: Setting resend_igmp to %d.\n",
1700 bond
->dev
->name
, new_value
);
1701 bond
->params
.resend_igmp
= new_value
;
1706 static DEVICE_ATTR(resend_igmp
, S_IRUGO
| S_IWUSR
,
1707 bonding_show_resend_igmp
, bonding_store_resend_igmp
);
1710 static ssize_t
bonding_show_lp_interval(struct device
*d
,
1711 struct device_attribute
*attr
,
1714 struct bonding
*bond
= to_bond(d
);
1715 return sprintf(buf
, "%d\n", bond
->params
.lp_interval
);
1718 static ssize_t
bonding_store_lp_interval(struct device
*d
,
1719 struct device_attribute
*attr
,
1720 const char *buf
, size_t count
)
1722 struct bonding
*bond
= to_bond(d
);
1723 int new_value
, ret
= count
;
1725 if (sscanf(buf
, "%d", &new_value
) != 1) {
1726 pr_err("%s: no lp interval value specified.\n",
1732 if (new_value
<= 0) {
1733 pr_err ("%s: lp_interval must be between 1 and %d\n",
1734 bond
->dev
->name
, INT_MAX
);
1739 bond
->params
.lp_interval
= new_value
;
1744 static DEVICE_ATTR(lp_interval
, S_IRUGO
| S_IWUSR
,
1745 bonding_show_lp_interval
, bonding_store_lp_interval
);
1747 static struct attribute
*per_bond_attrs
[] = {
1748 &dev_attr_slaves
.attr
,
1749 &dev_attr_mode
.attr
,
1750 &dev_attr_fail_over_mac
.attr
,
1751 &dev_attr_arp_validate
.attr
,
1752 &dev_attr_arp_all_targets
.attr
,
1753 &dev_attr_arp_interval
.attr
,
1754 &dev_attr_arp_ip_target
.attr
,
1755 &dev_attr_downdelay
.attr
,
1756 &dev_attr_updelay
.attr
,
1757 &dev_attr_lacp_rate
.attr
,
1758 &dev_attr_ad_select
.attr
,
1759 &dev_attr_xmit_hash_policy
.attr
,
1760 &dev_attr_num_grat_arp
.attr
,
1761 &dev_attr_num_unsol_na
.attr
,
1762 &dev_attr_miimon
.attr
,
1763 &dev_attr_primary
.attr
,
1764 &dev_attr_primary_reselect
.attr
,
1765 &dev_attr_use_carrier
.attr
,
1766 &dev_attr_active_slave
.attr
,
1767 &dev_attr_mii_status
.attr
,
1768 &dev_attr_ad_aggregator
.attr
,
1769 &dev_attr_ad_num_ports
.attr
,
1770 &dev_attr_ad_actor_key
.attr
,
1771 &dev_attr_ad_partner_key
.attr
,
1772 &dev_attr_ad_partner_mac
.attr
,
1773 &dev_attr_queue_id
.attr
,
1774 &dev_attr_all_slaves_active
.attr
,
1775 &dev_attr_resend_igmp
.attr
,
1776 &dev_attr_min_links
.attr
,
1777 &dev_attr_lp_interval
.attr
,
1781 static struct attribute_group bonding_group
= {
1783 .attrs
= per_bond_attrs
,
1787 * Initialize sysfs. This sets up the bonding_masters file in
1790 int bond_create_sysfs(struct bond_net
*bn
)
1794 bn
->class_attr_bonding_masters
= class_attr_bonding_masters
;
1795 sysfs_attr_init(&bn
->class_attr_bonding_masters
.attr
);
1797 ret
= netdev_class_create_file(&bn
->class_attr_bonding_masters
);
1799 * Permit multiple loads of the module by ignoring failures to
1800 * create the bonding_masters sysfs file. Bonding devices
1801 * created by second or subsequent loads of the module will
1802 * not be listed in, or controllable by, bonding_masters, but
1803 * will have the usual "bonding" sysfs directory.
1805 * This is done to preserve backwards compatibility for
1806 * initscripts/sysconfig, which load bonding multiple times to
1807 * configure multiple bonding devices.
1809 if (ret
== -EEXIST
) {
1810 /* Is someone being kinky and naming a device bonding_master? */
1811 if (__dev_get_by_name(bn
->net
,
1812 class_attr_bonding_masters
.attr
.name
))
1813 pr_err("network device named %s already exists in sysfs",
1814 class_attr_bonding_masters
.attr
.name
);
1823 * Remove /sys/class/net/bonding_masters.
1825 void bond_destroy_sysfs(struct bond_net
*bn
)
1827 netdev_class_remove_file(&bn
->class_attr_bonding_masters
);
1831 * Initialize sysfs for each bond. This sets up and registers
1832 * the 'bondctl' directory for each individual bond under /sys/class/net.
1834 void bond_prepare_sysfs_group(struct bonding
*bond
)
1836 bond
->dev
->sysfs_groups
[0] = &bonding_group
;