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, see <http://www.gnu.org/licenses/>.
17 * The full GNU General Public License is included in this distribution in the
18 * file called LICENSE.
22 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
24 #include <linux/kernel.h>
25 #include <linux/module.h>
26 #include <linux/device.h>
27 #include <linux/sched.h>
29 #include <linux/types.h>
30 #include <linux/string.h>
31 #include <linux/netdevice.h>
32 #include <linux/inetdevice.h>
34 #include <linux/sysfs.h>
35 #include <linux/ctype.h>
36 #include <linux/inet.h>
37 #include <linux/rtnetlink.h>
38 #include <linux/etherdevice.h>
39 #include <net/net_namespace.h>
40 #include <net/netns/generic.h>
41 #include <linux/nsproxy.h>
45 #define to_dev(obj) container_of(obj, struct device, kobj)
46 #define to_bond(cd) ((struct bonding *)(netdev_priv(to_net_dev(cd))))
49 * "show" function for the bond_masters attribute.
50 * The class parameter is ignored.
52 static ssize_t
bonding_show_bonds(struct class *cls
,
53 struct class_attribute
*attr
,
57 container_of(attr
, struct bond_net
, class_attr_bonding_masters
);
63 list_for_each_entry(bond
, &bn
->dev_list
, bond_list
) {
64 if (res
> (PAGE_SIZE
- IFNAMSIZ
)) {
65 /* not enough space for another interface name */
66 if ((PAGE_SIZE
- res
) > 10)
68 res
+= sprintf(buf
+ res
, "++more++ ");
71 res
+= sprintf(buf
+ res
, "%s ", bond
->dev
->name
);
74 buf
[res
-1] = '\n'; /* eat the leftover space */
80 static struct net_device
*bond_get_by_name(struct bond_net
*bn
, const char *ifname
)
84 list_for_each_entry(bond
, &bn
->dev_list
, bond_list
) {
85 if (strncmp(bond
->dev
->name
, ifname
, IFNAMSIZ
) == 0)
92 * "store" function for the bond_masters attribute. This is what
93 * creates and deletes entire bonds.
95 * The class parameter is ignored.
99 static ssize_t
bonding_store_bonds(struct class *cls
,
100 struct class_attribute
*attr
,
101 const char *buffer
, size_t count
)
103 struct bond_net
*bn
=
104 container_of(attr
, struct bond_net
, class_attr_bonding_masters
);
105 char command
[IFNAMSIZ
+ 1] = {0, };
109 sscanf(buffer
, "%16s", command
); /* IFNAMSIZ*/
110 ifname
= command
+ 1;
111 if ((strlen(command
) <= 1) ||
112 !dev_valid_name(ifname
))
115 if (command
[0] == '+') {
116 pr_info("%s is being created...\n", ifname
);
117 rv
= bond_create(bn
->net
, ifname
);
120 pr_info("%s already exists\n", ifname
);
122 pr_info("%s creation failed\n", ifname
);
125 } else if (command
[0] == '-') {
126 struct net_device
*bond_dev
;
129 bond_dev
= bond_get_by_name(bn
, ifname
);
131 pr_info("%s is being deleted...\n", ifname
);
132 unregister_netdevice(bond_dev
);
134 pr_err("unable to delete non-existent %s\n", ifname
);
141 /* Always return either count or an error. If you return 0, you'll
142 * get called forever, which is bad.
147 pr_err("no command found in bonding_masters - use +ifname or -ifname\n");
151 /* class attribute for bond_masters file. This ends up in /sys/class/net */
152 static const struct class_attribute class_attr_bonding_masters
= {
154 .name
= "bonding_masters",
155 .mode
= S_IWUSR
| S_IRUGO
,
157 .show
= bonding_show_bonds
,
158 .store
= bonding_store_bonds
,
162 * Show the slaves in the current bond.
164 static ssize_t
bonding_show_slaves(struct device
*d
,
165 struct device_attribute
*attr
, char *buf
)
167 struct bonding
*bond
= to_bond(d
);
168 struct list_head
*iter
;
173 return restart_syscall();
175 bond_for_each_slave(bond
, slave
, iter
) {
176 if (res
> (PAGE_SIZE
- IFNAMSIZ
)) {
177 /* not enough space for another interface name */
178 if ((PAGE_SIZE
- res
) > 10)
179 res
= PAGE_SIZE
- 10;
180 res
+= sprintf(buf
+ res
, "++more++ ");
183 res
+= sprintf(buf
+ res
, "%s ", slave
->dev
->name
);
189 buf
[res
-1] = '\n'; /* eat the leftover space */
195 * Set the slaves in the current bond.
196 * This is supposed to be only thin wrapper for bond_enslave and bond_release.
197 * All hard work should be done there.
199 static ssize_t
bonding_store_slaves(struct device
*d
,
200 struct device_attribute
*attr
,
201 const char *buffer
, size_t count
)
203 struct bonding
*bond
= to_bond(d
);
206 ret
= bond_opt_tryset_rtnl(bond
, BOND_OPT_SLAVES
, (char *)buffer
);
212 static DEVICE_ATTR(slaves
, S_IRUGO
| S_IWUSR
, bonding_show_slaves
,
213 bonding_store_slaves
);
216 * Show and set the bonding mode. The bond interface must be down to
219 static ssize_t
bonding_show_mode(struct device
*d
,
220 struct device_attribute
*attr
, char *buf
)
222 struct bonding
*bond
= to_bond(d
);
223 const struct bond_opt_value
*val
;
225 val
= bond_opt_get_val(BOND_OPT_MODE
, bond
->params
.mode
);
227 return sprintf(buf
, "%s %d\n", val
->string
, bond
->params
.mode
);
230 static ssize_t
bonding_store_mode(struct device
*d
,
231 struct device_attribute
*attr
,
232 const char *buf
, size_t count
)
234 struct bonding
*bond
= to_bond(d
);
237 ret
= bond_opt_tryset_rtnl(bond
, BOND_OPT_MODE
, (char *)buf
);
243 static DEVICE_ATTR(mode
, S_IRUGO
| S_IWUSR
,
244 bonding_show_mode
, bonding_store_mode
);
247 * Show and set the bonding transmit hash method.
249 static ssize_t
bonding_show_xmit_hash(struct device
*d
,
250 struct device_attribute
*attr
,
253 struct bonding
*bond
= to_bond(d
);
254 const struct bond_opt_value
*val
;
256 val
= bond_opt_get_val(BOND_OPT_XMIT_HASH
, bond
->params
.xmit_policy
);
258 return sprintf(buf
, "%s %d\n", val
->string
, bond
->params
.xmit_policy
);
261 static ssize_t
bonding_store_xmit_hash(struct device
*d
,
262 struct device_attribute
*attr
,
263 const char *buf
, size_t count
)
265 struct bonding
*bond
= to_bond(d
);
268 ret
= bond_opt_tryset_rtnl(bond
, BOND_OPT_XMIT_HASH
, (char *)buf
);
274 static DEVICE_ATTR(xmit_hash_policy
, S_IRUGO
| S_IWUSR
,
275 bonding_show_xmit_hash
, bonding_store_xmit_hash
);
278 * Show and set arp_validate.
280 static ssize_t
bonding_show_arp_validate(struct device
*d
,
281 struct device_attribute
*attr
,
284 struct bonding
*bond
= to_bond(d
);
285 const struct bond_opt_value
*val
;
287 val
= bond_opt_get_val(BOND_OPT_ARP_VALIDATE
,
288 bond
->params
.arp_validate
);
290 return sprintf(buf
, "%s %d\n", val
->string
, bond
->params
.arp_validate
);
293 static ssize_t
bonding_store_arp_validate(struct device
*d
,
294 struct device_attribute
*attr
,
295 const char *buf
, size_t count
)
297 struct bonding
*bond
= to_bond(d
);
300 ret
= bond_opt_tryset_rtnl(bond
, BOND_OPT_ARP_VALIDATE
, (char *)buf
);
307 static DEVICE_ATTR(arp_validate
, S_IRUGO
| S_IWUSR
, bonding_show_arp_validate
,
308 bonding_store_arp_validate
);
310 * Show and set arp_all_targets.
312 static ssize_t
bonding_show_arp_all_targets(struct device
*d
,
313 struct device_attribute
*attr
,
316 struct bonding
*bond
= to_bond(d
);
317 const struct bond_opt_value
*val
;
319 val
= bond_opt_get_val(BOND_OPT_ARP_ALL_TARGETS
,
320 bond
->params
.arp_all_targets
);
321 return sprintf(buf
, "%s %d\n",
322 val
->string
, bond
->params
.arp_all_targets
);
325 static ssize_t
bonding_store_arp_all_targets(struct device
*d
,
326 struct device_attribute
*attr
,
327 const char *buf
, size_t count
)
329 struct bonding
*bond
= to_bond(d
);
332 ret
= bond_opt_tryset_rtnl(bond
, BOND_OPT_ARP_ALL_TARGETS
, (char *)buf
);
339 static DEVICE_ATTR(arp_all_targets
, S_IRUGO
| S_IWUSR
,
340 bonding_show_arp_all_targets
, bonding_store_arp_all_targets
);
343 * Show and store fail_over_mac. User only allowed to change the
344 * value when there are no slaves.
346 static ssize_t
bonding_show_fail_over_mac(struct device
*d
,
347 struct device_attribute
*attr
,
350 struct bonding
*bond
= to_bond(d
);
351 const struct bond_opt_value
*val
;
353 val
= bond_opt_get_val(BOND_OPT_FAIL_OVER_MAC
,
354 bond
->params
.fail_over_mac
);
356 return sprintf(buf
, "%s %d\n", val
->string
, bond
->params
.fail_over_mac
);
359 static ssize_t
bonding_store_fail_over_mac(struct device
*d
,
360 struct device_attribute
*attr
,
361 const char *buf
, size_t count
)
363 struct bonding
*bond
= to_bond(d
);
366 ret
= bond_opt_tryset_rtnl(bond
, BOND_OPT_FAIL_OVER_MAC
, (char *)buf
);
373 static DEVICE_ATTR(fail_over_mac
, S_IRUGO
| S_IWUSR
,
374 bonding_show_fail_over_mac
, bonding_store_fail_over_mac
);
377 * Show and set the arp timer interval. There are two tricky bits
378 * here. First, if ARP monitoring is activated, then we must disable
379 * MII monitoring. Second, if the ARP timer isn't running, we must
382 static ssize_t
bonding_show_arp_interval(struct device
*d
,
383 struct device_attribute
*attr
,
386 struct bonding
*bond
= to_bond(d
);
388 return sprintf(buf
, "%d\n", bond
->params
.arp_interval
);
391 static ssize_t
bonding_store_arp_interval(struct device
*d
,
392 struct device_attribute
*attr
,
393 const char *buf
, size_t count
)
395 struct bonding
*bond
= to_bond(d
);
398 ret
= bond_opt_tryset_rtnl(bond
, BOND_OPT_ARP_INTERVAL
, (char *)buf
);
404 static DEVICE_ATTR(arp_interval
, S_IRUGO
| S_IWUSR
,
405 bonding_show_arp_interval
, bonding_store_arp_interval
);
408 * Show and set the arp targets.
410 static ssize_t
bonding_show_arp_targets(struct device
*d
,
411 struct device_attribute
*attr
,
414 struct bonding
*bond
= to_bond(d
);
417 for (i
= 0; i
< BOND_MAX_ARP_TARGETS
; i
++) {
418 if (bond
->params
.arp_targets
[i
])
419 res
+= sprintf(buf
+ res
, "%pI4 ",
420 &bond
->params
.arp_targets
[i
]);
423 buf
[res
-1] = '\n'; /* eat the leftover space */
428 static ssize_t
bonding_store_arp_targets(struct device
*d
,
429 struct device_attribute
*attr
,
430 const char *buf
, size_t count
)
432 struct bonding
*bond
= to_bond(d
);
435 ret
= bond_opt_tryset_rtnl(bond
, BOND_OPT_ARP_TARGETS
, (char *)buf
);
441 static DEVICE_ATTR(arp_ip_target
, S_IRUGO
| S_IWUSR
, bonding_show_arp_targets
, bonding_store_arp_targets
);
444 * Show and set the up and down delays. These must be multiples of the
445 * MII monitoring value, and are stored internally as the multiplier.
446 * Thus, we must translate to MS for the real world.
448 static ssize_t
bonding_show_downdelay(struct device
*d
,
449 struct device_attribute
*attr
,
452 struct bonding
*bond
= to_bond(d
);
454 return sprintf(buf
, "%d\n", bond
->params
.downdelay
* bond
->params
.miimon
);
457 static ssize_t
bonding_store_downdelay(struct device
*d
,
458 struct device_attribute
*attr
,
459 const char *buf
, size_t count
)
461 struct bonding
*bond
= to_bond(d
);
464 ret
= bond_opt_tryset_rtnl(bond
, BOND_OPT_DOWNDELAY
, (char *)buf
);
470 static DEVICE_ATTR(downdelay
, S_IRUGO
| S_IWUSR
,
471 bonding_show_downdelay
, bonding_store_downdelay
);
473 static ssize_t
bonding_show_updelay(struct device
*d
,
474 struct device_attribute
*attr
,
477 struct bonding
*bond
= to_bond(d
);
479 return sprintf(buf
, "%d\n", bond
->params
.updelay
* bond
->params
.miimon
);
483 static ssize_t
bonding_store_updelay(struct device
*d
,
484 struct device_attribute
*attr
,
485 const char *buf
, size_t count
)
487 struct bonding
*bond
= to_bond(d
);
490 ret
= bond_opt_tryset_rtnl(bond
, BOND_OPT_UPDELAY
, (char *)buf
);
496 static DEVICE_ATTR(updelay
, S_IRUGO
| S_IWUSR
,
497 bonding_show_updelay
, bonding_store_updelay
);
500 * Show and set the LACP interval. Interface must be down, and the mode
501 * must be set to 802.3ad mode.
503 static ssize_t
bonding_show_lacp(struct device
*d
,
504 struct device_attribute
*attr
,
507 struct bonding
*bond
= to_bond(d
);
508 const struct bond_opt_value
*val
;
510 val
= bond_opt_get_val(BOND_OPT_LACP_RATE
, bond
->params
.lacp_fast
);
512 return sprintf(buf
, "%s %d\n", val
->string
, bond
->params
.lacp_fast
);
515 static ssize_t
bonding_store_lacp(struct device
*d
,
516 struct device_attribute
*attr
,
517 const char *buf
, size_t count
)
519 struct bonding
*bond
= to_bond(d
);
522 ret
= bond_opt_tryset_rtnl(bond
, BOND_OPT_LACP_RATE
, (char *)buf
);
528 static DEVICE_ATTR(lacp_rate
, S_IRUGO
| S_IWUSR
,
529 bonding_show_lacp
, bonding_store_lacp
);
531 static ssize_t
bonding_show_min_links(struct device
*d
,
532 struct device_attribute
*attr
,
535 struct bonding
*bond
= to_bond(d
);
537 return sprintf(buf
, "%d\n", bond
->params
.min_links
);
540 static ssize_t
bonding_store_min_links(struct device
*d
,
541 struct device_attribute
*attr
,
542 const char *buf
, size_t count
)
544 struct bonding
*bond
= to_bond(d
);
547 ret
= bond_opt_tryset_rtnl(bond
, BOND_OPT_MINLINKS
, (char *)buf
);
553 static DEVICE_ATTR(min_links
, S_IRUGO
| S_IWUSR
,
554 bonding_show_min_links
, bonding_store_min_links
);
556 static ssize_t
bonding_show_ad_select(struct device
*d
,
557 struct device_attribute
*attr
,
560 struct bonding
*bond
= to_bond(d
);
561 const struct bond_opt_value
*val
;
563 val
= bond_opt_get_val(BOND_OPT_AD_SELECT
, bond
->params
.ad_select
);
565 return sprintf(buf
, "%s %d\n", val
->string
, bond
->params
.ad_select
);
569 static ssize_t
bonding_store_ad_select(struct device
*d
,
570 struct device_attribute
*attr
,
571 const char *buf
, size_t count
)
573 struct bonding
*bond
= to_bond(d
);
576 ret
= bond_opt_tryset_rtnl(bond
, BOND_OPT_AD_SELECT
, (char *)buf
);
582 static DEVICE_ATTR(ad_select
, S_IRUGO
| S_IWUSR
,
583 bonding_show_ad_select
, bonding_store_ad_select
);
586 * Show and set the number of peer notifications to send after a failover event.
588 static ssize_t
bonding_show_num_peer_notif(struct device
*d
,
589 struct device_attribute
*attr
,
592 struct bonding
*bond
= to_bond(d
);
593 return sprintf(buf
, "%d\n", bond
->params
.num_peer_notif
);
596 static ssize_t
bonding_store_num_peer_notif(struct device
*d
,
597 struct device_attribute
*attr
,
598 const char *buf
, size_t count
)
600 struct bonding
*bond
= to_bond(d
);
603 ret
= bond_opt_tryset_rtnl(bond
, BOND_OPT_NUM_PEER_NOTIF
, (char *)buf
);
609 static DEVICE_ATTR(num_grat_arp
, S_IRUGO
| S_IWUSR
,
610 bonding_show_num_peer_notif
, bonding_store_num_peer_notif
);
611 static DEVICE_ATTR(num_unsol_na
, S_IRUGO
| S_IWUSR
,
612 bonding_show_num_peer_notif
, bonding_store_num_peer_notif
);
615 * Show and set the MII monitor interval. There are two tricky bits
616 * here. First, if MII monitoring is activated, then we must disable
617 * ARP monitoring. Second, if the timer isn't running, we must
620 static ssize_t
bonding_show_miimon(struct device
*d
,
621 struct device_attribute
*attr
,
624 struct bonding
*bond
= to_bond(d
);
626 return sprintf(buf
, "%d\n", bond
->params
.miimon
);
629 static ssize_t
bonding_store_miimon(struct device
*d
,
630 struct device_attribute
*attr
,
631 const char *buf
, size_t count
)
633 struct bonding
*bond
= to_bond(d
);
636 ret
= bond_opt_tryset_rtnl(bond
, BOND_OPT_MIIMON
, (char *)buf
);
642 static DEVICE_ATTR(miimon
, S_IRUGO
| S_IWUSR
,
643 bonding_show_miimon
, bonding_store_miimon
);
646 * Show and set the primary slave. The store function is much
647 * simpler than bonding_store_slaves function because it only needs to
648 * handle one interface name.
649 * The bond must be a mode that supports a primary for this be
652 static ssize_t
bonding_show_primary(struct device
*d
,
653 struct device_attribute
*attr
,
657 struct bonding
*bond
= to_bond(d
);
659 if (bond
->primary_slave
)
660 count
= sprintf(buf
, "%s\n", bond
->primary_slave
->dev
->name
);
665 static ssize_t
bonding_store_primary(struct device
*d
,
666 struct device_attribute
*attr
,
667 const char *buf
, size_t count
)
669 struct bonding
*bond
= to_bond(d
);
672 ret
= bond_opt_tryset_rtnl(bond
, BOND_OPT_PRIMARY
, (char *)buf
);
678 static DEVICE_ATTR(primary
, S_IRUGO
| S_IWUSR
,
679 bonding_show_primary
, bonding_store_primary
);
682 * Show and set the primary_reselect flag.
684 static ssize_t
bonding_show_primary_reselect(struct device
*d
,
685 struct device_attribute
*attr
,
688 struct bonding
*bond
= to_bond(d
);
689 const struct bond_opt_value
*val
;
691 val
= bond_opt_get_val(BOND_OPT_PRIMARY_RESELECT
,
692 bond
->params
.primary_reselect
);
694 return sprintf(buf
, "%s %d\n",
695 val
->string
, bond
->params
.primary_reselect
);
698 static ssize_t
bonding_store_primary_reselect(struct device
*d
,
699 struct device_attribute
*attr
,
700 const char *buf
, size_t count
)
702 struct bonding
*bond
= to_bond(d
);
705 ret
= bond_opt_tryset_rtnl(bond
, BOND_OPT_PRIMARY_RESELECT
,
712 static DEVICE_ATTR(primary_reselect
, S_IRUGO
| S_IWUSR
,
713 bonding_show_primary_reselect
,
714 bonding_store_primary_reselect
);
717 * Show and set the use_carrier flag.
719 static ssize_t
bonding_show_carrier(struct device
*d
,
720 struct device_attribute
*attr
,
723 struct bonding
*bond
= to_bond(d
);
725 return sprintf(buf
, "%d\n", bond
->params
.use_carrier
);
728 static ssize_t
bonding_store_carrier(struct device
*d
,
729 struct device_attribute
*attr
,
730 const char *buf
, size_t count
)
732 struct bonding
*bond
= to_bond(d
);
735 ret
= bond_opt_tryset_rtnl(bond
, BOND_OPT_USE_CARRIER
, (char *)buf
);
741 static DEVICE_ATTR(use_carrier
, S_IRUGO
| S_IWUSR
,
742 bonding_show_carrier
, bonding_store_carrier
);
746 * Show and set currently active_slave.
748 static ssize_t
bonding_show_active_slave(struct device
*d
,
749 struct device_attribute
*attr
,
752 struct bonding
*bond
= to_bond(d
);
753 struct net_device
*slave_dev
;
757 slave_dev
= bond_option_active_slave_get_rcu(bond
);
759 count
= sprintf(buf
, "%s\n", slave_dev
->name
);
765 static ssize_t
bonding_store_active_slave(struct device
*d
,
766 struct device_attribute
*attr
,
767 const char *buf
, size_t count
)
769 struct bonding
*bond
= to_bond(d
);
772 ret
= bond_opt_tryset_rtnl(bond
, BOND_OPT_ACTIVE_SLAVE
, (char *)buf
);
778 static DEVICE_ATTR(active_slave
, S_IRUGO
| S_IWUSR
,
779 bonding_show_active_slave
, bonding_store_active_slave
);
783 * Show link status of the bond interface.
785 static ssize_t
bonding_show_mii_status(struct device
*d
,
786 struct device_attribute
*attr
,
789 struct bonding
*bond
= to_bond(d
);
791 return sprintf(buf
, "%s\n", bond
->curr_active_slave
? "up" : "down");
793 static DEVICE_ATTR(mii_status
, S_IRUGO
, bonding_show_mii_status
, NULL
);
796 * Show current 802.3ad aggregator ID.
798 static ssize_t
bonding_show_ad_aggregator(struct device
*d
,
799 struct device_attribute
*attr
,
803 struct bonding
*bond
= to_bond(d
);
805 if (bond
->params
.mode
== BOND_MODE_8023AD
) {
806 struct ad_info ad_info
;
807 count
= sprintf(buf
, "%d\n",
808 bond_3ad_get_active_agg_info(bond
, &ad_info
)
809 ? 0 : ad_info
.aggregator_id
);
814 static DEVICE_ATTR(ad_aggregator
, S_IRUGO
, bonding_show_ad_aggregator
, NULL
);
818 * Show number of active 802.3ad ports.
820 static ssize_t
bonding_show_ad_num_ports(struct device
*d
,
821 struct device_attribute
*attr
,
825 struct bonding
*bond
= to_bond(d
);
827 if (bond
->params
.mode
== BOND_MODE_8023AD
) {
828 struct ad_info ad_info
;
829 count
= sprintf(buf
, "%d\n",
830 bond_3ad_get_active_agg_info(bond
, &ad_info
)
831 ? 0 : ad_info
.ports
);
836 static DEVICE_ATTR(ad_num_ports
, S_IRUGO
, bonding_show_ad_num_ports
, NULL
);
840 * Show current 802.3ad actor key.
842 static ssize_t
bonding_show_ad_actor_key(struct device
*d
,
843 struct device_attribute
*attr
,
847 struct bonding
*bond
= to_bond(d
);
849 if (bond
->params
.mode
== BOND_MODE_8023AD
) {
850 struct ad_info ad_info
;
851 count
= sprintf(buf
, "%d\n",
852 bond_3ad_get_active_agg_info(bond
, &ad_info
)
853 ? 0 : ad_info
.actor_key
);
858 static DEVICE_ATTR(ad_actor_key
, S_IRUGO
, bonding_show_ad_actor_key
, NULL
);
862 * Show current 802.3ad partner key.
864 static ssize_t
bonding_show_ad_partner_key(struct device
*d
,
865 struct device_attribute
*attr
,
869 struct bonding
*bond
= to_bond(d
);
871 if (bond
->params
.mode
== BOND_MODE_8023AD
) {
872 struct ad_info ad_info
;
873 count
= sprintf(buf
, "%d\n",
874 bond_3ad_get_active_agg_info(bond
, &ad_info
)
875 ? 0 : ad_info
.partner_key
);
880 static DEVICE_ATTR(ad_partner_key
, S_IRUGO
, bonding_show_ad_partner_key
, NULL
);
884 * Show current 802.3ad partner mac.
886 static ssize_t
bonding_show_ad_partner_mac(struct device
*d
,
887 struct device_attribute
*attr
,
891 struct bonding
*bond
= to_bond(d
);
893 if (bond
->params
.mode
== BOND_MODE_8023AD
) {
894 struct ad_info ad_info
;
895 if (!bond_3ad_get_active_agg_info(bond
, &ad_info
))
896 count
= sprintf(buf
, "%pM\n", ad_info
.partner_system
);
901 static DEVICE_ATTR(ad_partner_mac
, S_IRUGO
, bonding_show_ad_partner_mac
, NULL
);
904 * Show the queue_ids of the slaves in the current bond.
906 static ssize_t
bonding_show_queue_id(struct device
*d
,
907 struct device_attribute
*attr
,
910 struct bonding
*bond
= to_bond(d
);
911 struct list_head
*iter
;
916 return restart_syscall();
918 bond_for_each_slave(bond
, slave
, iter
) {
919 if (res
> (PAGE_SIZE
- IFNAMSIZ
- 6)) {
920 /* not enough space for another interface_name:queue_id pair */
921 if ((PAGE_SIZE
- res
) > 10)
922 res
= PAGE_SIZE
- 10;
923 res
+= sprintf(buf
+ res
, "++more++ ");
926 res
+= sprintf(buf
+ res
, "%s:%d ",
927 slave
->dev
->name
, slave
->queue_id
);
930 buf
[res
-1] = '\n'; /* eat the leftover space */
938 * Set the queue_ids of the slaves in the current bond. The bond
939 * interface must be enslaved for this to work.
941 static ssize_t
bonding_store_queue_id(struct device
*d
,
942 struct device_attribute
*attr
,
943 const char *buffer
, size_t count
)
945 struct bonding
*bond
= to_bond(d
);
948 ret
= bond_opt_tryset_rtnl(bond
, BOND_OPT_QUEUE_ID
, (char *)buffer
);
954 static DEVICE_ATTR(queue_id
, S_IRUGO
| S_IWUSR
, bonding_show_queue_id
,
955 bonding_store_queue_id
);
959 * Show and set the all_slaves_active flag.
961 static ssize_t
bonding_show_slaves_active(struct device
*d
,
962 struct device_attribute
*attr
,
965 struct bonding
*bond
= to_bond(d
);
967 return sprintf(buf
, "%d\n", bond
->params
.all_slaves_active
);
970 static ssize_t
bonding_store_slaves_active(struct device
*d
,
971 struct device_attribute
*attr
,
972 const char *buf
, size_t count
)
974 struct bonding
*bond
= to_bond(d
);
977 ret
= bond_opt_tryset_rtnl(bond
, BOND_OPT_ALL_SLAVES_ACTIVE
,
984 static DEVICE_ATTR(all_slaves_active
, S_IRUGO
| S_IWUSR
,
985 bonding_show_slaves_active
, bonding_store_slaves_active
);
988 * Show and set the number of IGMP membership reports to send on link failure
990 static ssize_t
bonding_show_resend_igmp(struct device
*d
,
991 struct device_attribute
*attr
,
994 struct bonding
*bond
= to_bond(d
);
996 return sprintf(buf
, "%d\n", bond
->params
.resend_igmp
);
999 static ssize_t
bonding_store_resend_igmp(struct device
*d
,
1000 struct device_attribute
*attr
,
1001 const char *buf
, size_t count
)
1003 struct bonding
*bond
= to_bond(d
);
1006 ret
= bond_opt_tryset_rtnl(bond
, BOND_OPT_RESEND_IGMP
, (char *)buf
);
1013 static DEVICE_ATTR(resend_igmp
, S_IRUGO
| S_IWUSR
,
1014 bonding_show_resend_igmp
, bonding_store_resend_igmp
);
1017 static ssize_t
bonding_show_lp_interval(struct device
*d
,
1018 struct device_attribute
*attr
,
1021 struct bonding
*bond
= to_bond(d
);
1022 return sprintf(buf
, "%d\n", bond
->params
.lp_interval
);
1025 static ssize_t
bonding_store_lp_interval(struct device
*d
,
1026 struct device_attribute
*attr
,
1027 const char *buf
, size_t count
)
1029 struct bonding
*bond
= to_bond(d
);
1032 ret
= bond_opt_tryset_rtnl(bond
, BOND_OPT_LP_INTERVAL
, (char *)buf
);
1039 static DEVICE_ATTR(lp_interval
, S_IRUGO
| S_IWUSR
,
1040 bonding_show_lp_interval
, bonding_store_lp_interval
);
1042 static ssize_t
bonding_show_packets_per_slave(struct device
*d
,
1043 struct device_attribute
*attr
,
1046 struct bonding
*bond
= to_bond(d
);
1047 unsigned int packets_per_slave
= bond
->params
.packets_per_slave
;
1048 return sprintf(buf
, "%u\n", packets_per_slave
);
1051 static ssize_t
bonding_store_packets_per_slave(struct device
*d
,
1052 struct device_attribute
*attr
,
1053 const char *buf
, size_t count
)
1055 struct bonding
*bond
= to_bond(d
);
1058 ret
= bond_opt_tryset_rtnl(bond
, BOND_OPT_PACKETS_PER_SLAVE
,
1066 static DEVICE_ATTR(packets_per_slave
, S_IRUGO
| S_IWUSR
,
1067 bonding_show_packets_per_slave
,
1068 bonding_store_packets_per_slave
);
1070 static struct attribute
*per_bond_attrs
[] = {
1071 &dev_attr_slaves
.attr
,
1072 &dev_attr_mode
.attr
,
1073 &dev_attr_fail_over_mac
.attr
,
1074 &dev_attr_arp_validate
.attr
,
1075 &dev_attr_arp_all_targets
.attr
,
1076 &dev_attr_arp_interval
.attr
,
1077 &dev_attr_arp_ip_target
.attr
,
1078 &dev_attr_downdelay
.attr
,
1079 &dev_attr_updelay
.attr
,
1080 &dev_attr_lacp_rate
.attr
,
1081 &dev_attr_ad_select
.attr
,
1082 &dev_attr_xmit_hash_policy
.attr
,
1083 &dev_attr_num_grat_arp
.attr
,
1084 &dev_attr_num_unsol_na
.attr
,
1085 &dev_attr_miimon
.attr
,
1086 &dev_attr_primary
.attr
,
1087 &dev_attr_primary_reselect
.attr
,
1088 &dev_attr_use_carrier
.attr
,
1089 &dev_attr_active_slave
.attr
,
1090 &dev_attr_mii_status
.attr
,
1091 &dev_attr_ad_aggregator
.attr
,
1092 &dev_attr_ad_num_ports
.attr
,
1093 &dev_attr_ad_actor_key
.attr
,
1094 &dev_attr_ad_partner_key
.attr
,
1095 &dev_attr_ad_partner_mac
.attr
,
1096 &dev_attr_queue_id
.attr
,
1097 &dev_attr_all_slaves_active
.attr
,
1098 &dev_attr_resend_igmp
.attr
,
1099 &dev_attr_min_links
.attr
,
1100 &dev_attr_lp_interval
.attr
,
1101 &dev_attr_packets_per_slave
.attr
,
1105 static struct attribute_group bonding_group
= {
1107 .attrs
= per_bond_attrs
,
1111 * Initialize sysfs. This sets up the bonding_masters file in
1114 int bond_create_sysfs(struct bond_net
*bn
)
1118 bn
->class_attr_bonding_masters
= class_attr_bonding_masters
;
1119 sysfs_attr_init(&bn
->class_attr_bonding_masters
.attr
);
1121 ret
= netdev_class_create_file_ns(&bn
->class_attr_bonding_masters
,
1124 * Permit multiple loads of the module by ignoring failures to
1125 * create the bonding_masters sysfs file. Bonding devices
1126 * created by second or subsequent loads of the module will
1127 * not be listed in, or controllable by, bonding_masters, but
1128 * will have the usual "bonding" sysfs directory.
1130 * This is done to preserve backwards compatibility for
1131 * initscripts/sysconfig, which load bonding multiple times to
1132 * configure multiple bonding devices.
1134 if (ret
== -EEXIST
) {
1135 /* Is someone being kinky and naming a device bonding_master? */
1136 if (__dev_get_by_name(bn
->net
,
1137 class_attr_bonding_masters
.attr
.name
))
1138 pr_err("network device named %s already exists in sysfs\n",
1139 class_attr_bonding_masters
.attr
.name
);
1148 * Remove /sys/class/net/bonding_masters.
1150 void bond_destroy_sysfs(struct bond_net
*bn
)
1152 netdev_class_remove_file_ns(&bn
->class_attr_bonding_masters
, bn
->net
);
1156 * Initialize sysfs for each bond. This sets up and registers
1157 * the 'bondctl' directory for each individual bond under /sys/class/net.
1159 void bond_prepare_sysfs_group(struct bonding
*bond
)
1161 bond
->dev
->sysfs_groups
[0] = &bonding_group
;