1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright(c) 2004-2005 Intel Corporation. All rights reserved.
6 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
8 #include <linux/kernel.h>
9 #include <linux/module.h>
10 #include <linux/device.h>
11 #include <linux/sched/signal.h>
13 #include <linux/types.h>
14 #include <linux/string.h>
15 #include <linux/netdevice.h>
16 #include <linux/inetdevice.h>
18 #include <linux/sysfs.h>
19 #include <linux/ctype.h>
20 #include <linux/inet.h>
21 #include <linux/rtnetlink.h>
22 #include <linux/etherdevice.h>
23 #include <net/net_namespace.h>
24 #include <net/netns/generic.h>
25 #include <linux/nsproxy.h>
27 #include <net/bonding.h>
29 #define to_bond(cd) ((struct bonding *)(netdev_priv(to_net_dev(cd))))
31 /* "show" function for the bond_masters attribute.
32 * The class parameter is ignored.
34 static ssize_t
bonding_show_bonds(const struct class *cls
,
35 const struct class_attribute
*attr
,
38 const struct bond_net
*bn
=
39 container_of_const(attr
, struct bond_net
, class_attr_bonding_masters
);
45 list_for_each_entry_rcu(bond
, &bn
->dev_list
, bond_list
) {
46 if (res
> (PAGE_SIZE
- IFNAMSIZ
)) {
47 /* not enough space for another interface name */
48 if ((PAGE_SIZE
- res
) > 10)
50 res
+= sysfs_emit_at(buf
, res
, "++more++ ");
53 res
+= sysfs_emit_at(buf
, res
, "%s ", bond
->dev
->name
);
56 buf
[res
-1] = '\n'; /* eat the leftover space */
62 static struct net_device
*bond_get_by_name(const struct bond_net
*bn
, const char *ifname
)
66 list_for_each_entry(bond
, &bn
->dev_list
, bond_list
) {
67 if (strncmp(bond
->dev
->name
, ifname
, IFNAMSIZ
) == 0)
73 /* "store" function for the bond_masters attribute. This is what
74 * creates and deletes entire bonds.
76 * The class parameter is ignored.
78 static ssize_t
bonding_store_bonds(const struct class *cls
,
79 const struct class_attribute
*attr
,
80 const char *buffer
, size_t count
)
82 const struct bond_net
*bn
=
83 container_of_const(attr
, struct bond_net
, class_attr_bonding_masters
);
84 char command
[IFNAMSIZ
+ 1] = {0, };
88 sscanf(buffer
, "%16s", command
); /* IFNAMSIZ*/
90 if ((strlen(command
) <= 1) ||
91 !dev_valid_name(ifname
))
94 if (command
[0] == '+') {
95 pr_info("%s is being created...\n", ifname
);
96 rv
= bond_create(bn
->net
, ifname
);
99 pr_info("%s already exists\n", ifname
);
101 pr_info("%s creation failed\n", ifname
);
104 } else if (command
[0] == '-') {
105 struct net_device
*bond_dev
;
108 bond_dev
= bond_get_by_name(bn
, ifname
);
110 pr_info("%s is being deleted...\n", ifname
);
111 unregister_netdevice(bond_dev
);
113 pr_err("unable to delete non-existent %s\n", ifname
);
120 /* Always return either count or an error. If you return 0, you'll
121 * get called forever, which is bad.
126 pr_err("no command found in bonding_masters - use +ifname or -ifname\n");
130 /* class attribute for bond_masters file. This ends up in /sys/class/net */
131 static const struct class_attribute class_attr_bonding_masters
= {
133 .name
= "bonding_masters",
136 .show
= bonding_show_bonds
,
137 .store
= bonding_store_bonds
,
140 /* Generic "store" method for bonding sysfs option setting */
141 static ssize_t
bonding_sysfs_store_option(struct device
*d
,
142 struct device_attribute
*attr
,
143 const char *buffer
, size_t count
)
145 struct bonding
*bond
= to_bond(d
);
146 const struct bond_option
*opt
;
150 opt
= bond_opt_get_by_name(attr
->attr
.name
);
153 buffer_clone
= kstrndup(buffer
, count
, GFP_KERNEL
);
156 ret
= bond_opt_tryset_rtnl(bond
, opt
->id
, buffer_clone
);
164 /* Show the slaves in the current bond. */
165 static ssize_t
bonding_show_slaves(struct device
*d
,
166 struct device_attribute
*attr
, char *buf
)
168 struct bonding
*bond
= to_bond(d
);
169 struct list_head
*iter
;
175 bond_for_each_slave_rcu(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
+= sysfs_emit_at(buf
, res
, "++more++ ");
183 res
+= sysfs_emit_at(buf
, res
, "%s ", slave
->dev
->name
);
189 buf
[res
-1] = '\n'; /* eat the leftover space */
193 static DEVICE_ATTR(slaves
, 0644, bonding_show_slaves
,
194 bonding_sysfs_store_option
);
196 /* Show the bonding mode. */
197 static ssize_t
bonding_show_mode(struct device
*d
,
198 struct device_attribute
*attr
, char *buf
)
200 struct bonding
*bond
= to_bond(d
);
201 const struct bond_opt_value
*val
;
203 val
= bond_opt_get_val(BOND_OPT_MODE
, BOND_MODE(bond
));
205 return sysfs_emit(buf
, "%s %d\n", val
->string
, BOND_MODE(bond
));
207 static DEVICE_ATTR(mode
, 0644, bonding_show_mode
, bonding_sysfs_store_option
);
209 /* Show the bonding transmit hash method. */
210 static ssize_t
bonding_show_xmit_hash(struct device
*d
,
211 struct device_attribute
*attr
,
214 struct bonding
*bond
= to_bond(d
);
215 const struct bond_opt_value
*val
;
217 val
= bond_opt_get_val(BOND_OPT_XMIT_HASH
, bond
->params
.xmit_policy
);
219 return sysfs_emit(buf
, "%s %d\n", val
->string
, bond
->params
.xmit_policy
);
221 static DEVICE_ATTR(xmit_hash_policy
, 0644,
222 bonding_show_xmit_hash
, bonding_sysfs_store_option
);
224 /* Show arp_validate. */
225 static ssize_t
bonding_show_arp_validate(struct device
*d
,
226 struct device_attribute
*attr
,
229 struct bonding
*bond
= to_bond(d
);
230 const struct bond_opt_value
*val
;
232 val
= bond_opt_get_val(BOND_OPT_ARP_VALIDATE
,
233 bond
->params
.arp_validate
);
235 return sysfs_emit(buf
, "%s %d\n", val
->string
, bond
->params
.arp_validate
);
237 static DEVICE_ATTR(arp_validate
, 0644, bonding_show_arp_validate
,
238 bonding_sysfs_store_option
);
240 /* Show arp_all_targets. */
241 static ssize_t
bonding_show_arp_all_targets(struct device
*d
,
242 struct device_attribute
*attr
,
245 struct bonding
*bond
= to_bond(d
);
246 const struct bond_opt_value
*val
;
248 val
= bond_opt_get_val(BOND_OPT_ARP_ALL_TARGETS
,
249 bond
->params
.arp_all_targets
);
250 return sysfs_emit(buf
, "%s %d\n",
251 val
->string
, bond
->params
.arp_all_targets
);
253 static DEVICE_ATTR(arp_all_targets
, 0644,
254 bonding_show_arp_all_targets
, bonding_sysfs_store_option
);
256 /* Show fail_over_mac. */
257 static ssize_t
bonding_show_fail_over_mac(struct device
*d
,
258 struct device_attribute
*attr
,
261 struct bonding
*bond
= to_bond(d
);
262 const struct bond_opt_value
*val
;
264 val
= bond_opt_get_val(BOND_OPT_FAIL_OVER_MAC
,
265 bond
->params
.fail_over_mac
);
267 return sysfs_emit(buf
, "%s %d\n", val
->string
, bond
->params
.fail_over_mac
);
269 static DEVICE_ATTR(fail_over_mac
, 0644,
270 bonding_show_fail_over_mac
, bonding_sysfs_store_option
);
272 /* Show the arp timer interval. */
273 static ssize_t
bonding_show_arp_interval(struct device
*d
,
274 struct device_attribute
*attr
,
277 struct bonding
*bond
= to_bond(d
);
279 return sysfs_emit(buf
, "%d\n", bond
->params
.arp_interval
);
281 static DEVICE_ATTR(arp_interval
, 0644,
282 bonding_show_arp_interval
, bonding_sysfs_store_option
);
284 /* Show the arp targets. */
285 static ssize_t
bonding_show_arp_targets(struct device
*d
,
286 struct device_attribute
*attr
,
289 struct bonding
*bond
= to_bond(d
);
292 for (i
= 0; i
< BOND_MAX_ARP_TARGETS
; i
++) {
293 if (bond
->params
.arp_targets
[i
])
294 res
+= sysfs_emit_at(buf
, res
, "%pI4 ",
295 &bond
->params
.arp_targets
[i
]);
298 buf
[res
-1] = '\n'; /* eat the leftover space */
302 static DEVICE_ATTR(arp_ip_target
, 0644,
303 bonding_show_arp_targets
, bonding_sysfs_store_option
);
305 /* Show the arp missed max. */
306 static ssize_t
bonding_show_missed_max(struct device
*d
,
307 struct device_attribute
*attr
,
310 struct bonding
*bond
= to_bond(d
);
312 return sysfs_emit(buf
, "%u\n", bond
->params
.missed_max
);
314 static DEVICE_ATTR(arp_missed_max
, 0644,
315 bonding_show_missed_max
, bonding_sysfs_store_option
);
317 /* Show the up and down delays. */
318 static ssize_t
bonding_show_downdelay(struct device
*d
,
319 struct device_attribute
*attr
,
322 struct bonding
*bond
= to_bond(d
);
324 return sysfs_emit(buf
, "%d\n", bond
->params
.downdelay
* bond
->params
.miimon
);
326 static DEVICE_ATTR(downdelay
, 0644,
327 bonding_show_downdelay
, bonding_sysfs_store_option
);
329 static ssize_t
bonding_show_updelay(struct device
*d
,
330 struct device_attribute
*attr
,
333 struct bonding
*bond
= to_bond(d
);
335 return sysfs_emit(buf
, "%d\n", bond
->params
.updelay
* bond
->params
.miimon
);
338 static DEVICE_ATTR(updelay
, 0644,
339 bonding_show_updelay
, bonding_sysfs_store_option
);
341 static ssize_t
bonding_show_peer_notif_delay(struct device
*d
,
342 struct device_attribute
*attr
,
345 struct bonding
*bond
= to_bond(d
);
347 return sysfs_emit(buf
, "%d\n",
348 bond
->params
.peer_notif_delay
* bond
->params
.miimon
);
350 static DEVICE_ATTR(peer_notif_delay
, 0644,
351 bonding_show_peer_notif_delay
, bonding_sysfs_store_option
);
353 /* Show the LACP activity and interval. */
354 static ssize_t
bonding_show_lacp_active(struct device
*d
,
355 struct device_attribute
*attr
,
358 struct bonding
*bond
= to_bond(d
);
359 const struct bond_opt_value
*val
;
361 val
= bond_opt_get_val(BOND_OPT_LACP_ACTIVE
, bond
->params
.lacp_active
);
363 return sysfs_emit(buf
, "%s %d\n", val
->string
, bond
->params
.lacp_active
);
365 static DEVICE_ATTR(lacp_active
, 0644,
366 bonding_show_lacp_active
, bonding_sysfs_store_option
);
368 static ssize_t
bonding_show_lacp_rate(struct device
*d
,
369 struct device_attribute
*attr
,
372 struct bonding
*bond
= to_bond(d
);
373 const struct bond_opt_value
*val
;
375 val
= bond_opt_get_val(BOND_OPT_LACP_RATE
, bond
->params
.lacp_fast
);
377 return sysfs_emit(buf
, "%s %d\n", val
->string
, bond
->params
.lacp_fast
);
379 static DEVICE_ATTR(lacp_rate
, 0644,
380 bonding_show_lacp_rate
, bonding_sysfs_store_option
);
382 static ssize_t
bonding_show_min_links(struct device
*d
,
383 struct device_attribute
*attr
,
386 struct bonding
*bond
= to_bond(d
);
388 return sysfs_emit(buf
, "%u\n", bond
->params
.min_links
);
390 static DEVICE_ATTR(min_links
, 0644,
391 bonding_show_min_links
, bonding_sysfs_store_option
);
393 static ssize_t
bonding_show_ad_select(struct device
*d
,
394 struct device_attribute
*attr
,
397 struct bonding
*bond
= to_bond(d
);
398 const struct bond_opt_value
*val
;
400 val
= bond_opt_get_val(BOND_OPT_AD_SELECT
, bond
->params
.ad_select
);
402 return sysfs_emit(buf
, "%s %d\n", val
->string
, bond
->params
.ad_select
);
404 static DEVICE_ATTR(ad_select
, 0644,
405 bonding_show_ad_select
, bonding_sysfs_store_option
);
407 /* Show the number of peer notifications to send after a failover event. */
408 static ssize_t
bonding_show_num_peer_notif(struct device
*d
,
409 struct device_attribute
*attr
,
412 struct bonding
*bond
= to_bond(d
);
414 return sysfs_emit(buf
, "%d\n", bond
->params
.num_peer_notif
);
416 static DEVICE_ATTR(num_grat_arp
, 0644,
417 bonding_show_num_peer_notif
, bonding_sysfs_store_option
);
418 static DEVICE_ATTR(num_unsol_na
, 0644,
419 bonding_show_num_peer_notif
, bonding_sysfs_store_option
);
421 /* Show the MII monitor interval. */
422 static ssize_t
bonding_show_miimon(struct device
*d
,
423 struct device_attribute
*attr
,
426 struct bonding
*bond
= to_bond(d
);
428 return sysfs_emit(buf
, "%d\n", bond
->params
.miimon
);
430 static DEVICE_ATTR(miimon
, 0644,
431 bonding_show_miimon
, bonding_sysfs_store_option
);
433 /* Show the primary slave. */
434 static ssize_t
bonding_show_primary(struct device
*d
,
435 struct device_attribute
*attr
,
438 struct bonding
*bond
= to_bond(d
);
439 struct slave
*primary
;
443 primary
= rcu_dereference(bond
->primary_slave
);
445 count
= sysfs_emit(buf
, "%s\n", primary
->dev
->name
);
450 static DEVICE_ATTR(primary
, 0644,
451 bonding_show_primary
, bonding_sysfs_store_option
);
453 /* Show the primary_reselect flag. */
454 static ssize_t
bonding_show_primary_reselect(struct device
*d
,
455 struct device_attribute
*attr
,
458 struct bonding
*bond
= to_bond(d
);
459 const struct bond_opt_value
*val
;
461 val
= bond_opt_get_val(BOND_OPT_PRIMARY_RESELECT
,
462 bond
->params
.primary_reselect
);
464 return sysfs_emit(buf
, "%s %d\n",
465 val
->string
, bond
->params
.primary_reselect
);
467 static DEVICE_ATTR(primary_reselect
, 0644,
468 bonding_show_primary_reselect
, bonding_sysfs_store_option
);
470 /* Show the use_carrier flag. */
471 static ssize_t
bonding_show_carrier(struct device
*d
,
472 struct device_attribute
*attr
,
475 struct bonding
*bond
= to_bond(d
);
477 return sysfs_emit(buf
, "%d\n", bond
->params
.use_carrier
);
479 static DEVICE_ATTR(use_carrier
, 0644,
480 bonding_show_carrier
, bonding_sysfs_store_option
);
483 /* Show currently active_slave. */
484 static ssize_t
bonding_show_active_slave(struct device
*d
,
485 struct device_attribute
*attr
,
488 struct bonding
*bond
= to_bond(d
);
489 struct net_device
*slave_dev
;
493 slave_dev
= bond_option_active_slave_get_rcu(bond
);
495 count
= sysfs_emit(buf
, "%s\n", slave_dev
->name
);
500 static DEVICE_ATTR(active_slave
, 0644,
501 bonding_show_active_slave
, bonding_sysfs_store_option
);
503 /* Show link status of the bond interface. */
504 static ssize_t
bonding_show_mii_status(struct device
*d
,
505 struct device_attribute
*attr
,
508 struct bonding
*bond
= to_bond(d
);
509 bool active
= netif_carrier_ok(bond
->dev
);
511 return sysfs_emit(buf
, "%s\n", active
? "up" : "down");
513 static DEVICE_ATTR(mii_status
, 0444, bonding_show_mii_status
, NULL
);
515 /* Show current 802.3ad aggregator ID. */
516 static ssize_t
bonding_show_ad_aggregator(struct device
*d
,
517 struct device_attribute
*attr
,
521 struct bonding
*bond
= to_bond(d
);
523 if (BOND_MODE(bond
) == BOND_MODE_8023AD
) {
524 struct ad_info ad_info
;
526 count
= sysfs_emit(buf
, "%d\n",
527 bond_3ad_get_active_agg_info(bond
, &ad_info
)
528 ? 0 : ad_info
.aggregator_id
);
533 static DEVICE_ATTR(ad_aggregator
, 0444, bonding_show_ad_aggregator
, NULL
);
536 /* Show number of active 802.3ad ports. */
537 static ssize_t
bonding_show_ad_num_ports(struct device
*d
,
538 struct device_attribute
*attr
,
542 struct bonding
*bond
= to_bond(d
);
544 if (BOND_MODE(bond
) == BOND_MODE_8023AD
) {
545 struct ad_info ad_info
;
547 count
= sysfs_emit(buf
, "%d\n",
548 bond_3ad_get_active_agg_info(bond
, &ad_info
)
549 ? 0 : ad_info
.ports
);
554 static DEVICE_ATTR(ad_num_ports
, 0444, bonding_show_ad_num_ports
, NULL
);
557 /* Show current 802.3ad actor key. */
558 static ssize_t
bonding_show_ad_actor_key(struct device
*d
,
559 struct device_attribute
*attr
,
563 struct bonding
*bond
= to_bond(d
);
565 if (BOND_MODE(bond
) == BOND_MODE_8023AD
&& capable(CAP_NET_ADMIN
)) {
566 struct ad_info ad_info
;
568 count
= sysfs_emit(buf
, "%d\n",
569 bond_3ad_get_active_agg_info(bond
, &ad_info
)
570 ? 0 : ad_info
.actor_key
);
575 static DEVICE_ATTR(ad_actor_key
, 0444, bonding_show_ad_actor_key
, NULL
);
578 /* Show current 802.3ad partner key. */
579 static ssize_t
bonding_show_ad_partner_key(struct device
*d
,
580 struct device_attribute
*attr
,
584 struct bonding
*bond
= to_bond(d
);
586 if (BOND_MODE(bond
) == BOND_MODE_8023AD
&& capable(CAP_NET_ADMIN
)) {
587 struct ad_info ad_info
;
589 count
= sysfs_emit(buf
, "%d\n",
590 bond_3ad_get_active_agg_info(bond
, &ad_info
)
591 ? 0 : ad_info
.partner_key
);
596 static DEVICE_ATTR(ad_partner_key
, 0444, bonding_show_ad_partner_key
, NULL
);
599 /* Show current 802.3ad partner mac. */
600 static ssize_t
bonding_show_ad_partner_mac(struct device
*d
,
601 struct device_attribute
*attr
,
605 struct bonding
*bond
= to_bond(d
);
607 if (BOND_MODE(bond
) == BOND_MODE_8023AD
&& capable(CAP_NET_ADMIN
)) {
608 struct ad_info ad_info
;
610 if (!bond_3ad_get_active_agg_info(bond
, &ad_info
))
611 count
= sysfs_emit(buf
, "%pM\n", ad_info
.partner_system
);
616 static DEVICE_ATTR(ad_partner_mac
, 0444, bonding_show_ad_partner_mac
, NULL
);
618 /* Show the queue_ids of the slaves in the current bond. */
619 static ssize_t
bonding_show_queue_id(struct device
*d
,
620 struct device_attribute
*attr
,
623 struct bonding
*bond
= to_bond(d
);
624 struct list_head
*iter
;
630 bond_for_each_slave_rcu(bond
, slave
, iter
) {
631 if (res
> (PAGE_SIZE
- IFNAMSIZ
- 6)) {
632 /* not enough space for another interface_name:queue_id pair */
633 if ((PAGE_SIZE
- res
) > 10)
634 res
= PAGE_SIZE
- 10;
635 res
+= sysfs_emit_at(buf
, res
, "++more++ ");
638 res
+= sysfs_emit_at(buf
, res
, "%s:%d ",
640 READ_ONCE(slave
->queue_id
));
643 buf
[res
-1] = '\n'; /* eat the leftover space */
649 static DEVICE_ATTR(queue_id
, 0644, bonding_show_queue_id
,
650 bonding_sysfs_store_option
);
653 /* Show the all_slaves_active flag. */
654 static ssize_t
bonding_show_slaves_active(struct device
*d
,
655 struct device_attribute
*attr
,
658 struct bonding
*bond
= to_bond(d
);
660 return sysfs_emit(buf
, "%d\n", bond
->params
.all_slaves_active
);
662 static DEVICE_ATTR(all_slaves_active
, 0644,
663 bonding_show_slaves_active
, bonding_sysfs_store_option
);
665 /* Show the number of IGMP membership reports to send on link failure */
666 static ssize_t
bonding_show_resend_igmp(struct device
*d
,
667 struct device_attribute
*attr
,
670 struct bonding
*bond
= to_bond(d
);
672 return sysfs_emit(buf
, "%d\n", bond
->params
.resend_igmp
);
674 static DEVICE_ATTR(resend_igmp
, 0644,
675 bonding_show_resend_igmp
, bonding_sysfs_store_option
);
678 static ssize_t
bonding_show_lp_interval(struct device
*d
,
679 struct device_attribute
*attr
,
682 struct bonding
*bond
= to_bond(d
);
684 return sysfs_emit(buf
, "%d\n", bond
->params
.lp_interval
);
686 static DEVICE_ATTR(lp_interval
, 0644,
687 bonding_show_lp_interval
, bonding_sysfs_store_option
);
689 static ssize_t
bonding_show_tlb_dynamic_lb(struct device
*d
,
690 struct device_attribute
*attr
,
693 struct bonding
*bond
= to_bond(d
);
695 return sysfs_emit(buf
, "%d\n", bond
->params
.tlb_dynamic_lb
);
697 static DEVICE_ATTR(tlb_dynamic_lb
, 0644,
698 bonding_show_tlb_dynamic_lb
, bonding_sysfs_store_option
);
700 static ssize_t
bonding_show_packets_per_slave(struct device
*d
,
701 struct device_attribute
*attr
,
704 struct bonding
*bond
= to_bond(d
);
705 unsigned int packets_per_slave
= bond
->params
.packets_per_slave
;
707 return sysfs_emit(buf
, "%u\n", packets_per_slave
);
709 static DEVICE_ATTR(packets_per_slave
, 0644,
710 bonding_show_packets_per_slave
, bonding_sysfs_store_option
);
712 static ssize_t
bonding_show_ad_actor_sys_prio(struct device
*d
,
713 struct device_attribute
*attr
,
716 struct bonding
*bond
= to_bond(d
);
718 if (BOND_MODE(bond
) == BOND_MODE_8023AD
&& capable(CAP_NET_ADMIN
))
719 return sysfs_emit(buf
, "%hu\n", bond
->params
.ad_actor_sys_prio
);
723 static DEVICE_ATTR(ad_actor_sys_prio
, 0644,
724 bonding_show_ad_actor_sys_prio
, bonding_sysfs_store_option
);
726 static ssize_t
bonding_show_ad_actor_system(struct device
*d
,
727 struct device_attribute
*attr
,
730 struct bonding
*bond
= to_bond(d
);
732 if (BOND_MODE(bond
) == BOND_MODE_8023AD
&& capable(CAP_NET_ADMIN
))
733 return sysfs_emit(buf
, "%pM\n", bond
->params
.ad_actor_system
);
738 static DEVICE_ATTR(ad_actor_system
, 0644,
739 bonding_show_ad_actor_system
, bonding_sysfs_store_option
);
741 static ssize_t
bonding_show_ad_user_port_key(struct device
*d
,
742 struct device_attribute
*attr
,
745 struct bonding
*bond
= to_bond(d
);
747 if (BOND_MODE(bond
) == BOND_MODE_8023AD
&& capable(CAP_NET_ADMIN
))
748 return sysfs_emit(buf
, "%hu\n", bond
->params
.ad_user_port_key
);
752 static DEVICE_ATTR(ad_user_port_key
, 0644,
753 bonding_show_ad_user_port_key
, bonding_sysfs_store_option
);
755 static struct attribute
*per_bond_attrs
[] = {
756 &dev_attr_slaves
.attr
,
758 &dev_attr_fail_over_mac
.attr
,
759 &dev_attr_arp_validate
.attr
,
760 &dev_attr_arp_all_targets
.attr
,
761 &dev_attr_arp_interval
.attr
,
762 &dev_attr_arp_ip_target
.attr
,
763 &dev_attr_downdelay
.attr
,
764 &dev_attr_updelay
.attr
,
765 &dev_attr_peer_notif_delay
.attr
,
766 &dev_attr_lacp_active
.attr
,
767 &dev_attr_lacp_rate
.attr
,
768 &dev_attr_ad_select
.attr
,
769 &dev_attr_xmit_hash_policy
.attr
,
770 &dev_attr_num_grat_arp
.attr
,
771 &dev_attr_num_unsol_na
.attr
,
772 &dev_attr_miimon
.attr
,
773 &dev_attr_primary
.attr
,
774 &dev_attr_primary_reselect
.attr
,
775 &dev_attr_use_carrier
.attr
,
776 &dev_attr_active_slave
.attr
,
777 &dev_attr_mii_status
.attr
,
778 &dev_attr_ad_aggregator
.attr
,
779 &dev_attr_ad_num_ports
.attr
,
780 &dev_attr_ad_actor_key
.attr
,
781 &dev_attr_ad_partner_key
.attr
,
782 &dev_attr_ad_partner_mac
.attr
,
783 &dev_attr_queue_id
.attr
,
784 &dev_attr_all_slaves_active
.attr
,
785 &dev_attr_resend_igmp
.attr
,
786 &dev_attr_min_links
.attr
,
787 &dev_attr_lp_interval
.attr
,
788 &dev_attr_packets_per_slave
.attr
,
789 &dev_attr_tlb_dynamic_lb
.attr
,
790 &dev_attr_ad_actor_sys_prio
.attr
,
791 &dev_attr_ad_actor_system
.attr
,
792 &dev_attr_ad_user_port_key
.attr
,
793 &dev_attr_arp_missed_max
.attr
,
797 static const struct attribute_group bonding_group
= {
799 .attrs
= per_bond_attrs
,
802 /* Initialize sysfs. This sets up the bonding_masters file in
805 int __net_init
bond_create_sysfs(struct bond_net
*bn
)
809 bn
->class_attr_bonding_masters
= class_attr_bonding_masters
;
810 sysfs_attr_init(&bn
->class_attr_bonding_masters
.attr
);
812 ret
= netdev_class_create_file_ns(&bn
->class_attr_bonding_masters
,
814 /* Permit multiple loads of the module by ignoring failures to
815 * create the bonding_masters sysfs file. Bonding devices
816 * created by second or subsequent loads of the module will
817 * not be listed in, or controllable by, bonding_masters, but
818 * will have the usual "bonding" sysfs directory.
820 * This is done to preserve backwards compatibility for
821 * initscripts/sysconfig, which load bonding multiple times to
822 * configure multiple bonding devices.
824 if (ret
== -EEXIST
) {
825 /* Is someone being kinky and naming a device bonding_master? */
826 if (netdev_name_in_use(bn
->net
,
827 class_attr_bonding_masters
.attr
.name
))
828 pr_err("network device named %s already exists in sysfs\n",
829 class_attr_bonding_masters
.attr
.name
);
837 /* Remove /sys/class/net/bonding_masters. */
838 void __net_exit
bond_destroy_sysfs(struct bond_net
*bn
)
840 netdev_class_remove_file_ns(&bn
->class_attr_bonding_masters
, bn
->net
);
843 /* Initialize sysfs for each bond. This sets up and registers
844 * the 'bondctl' directory for each individual bond under /sys/class/net.
846 void bond_prepare_sysfs_group(struct bonding
*bond
)
848 bond
->dev
->sysfs_groups
[0] = &bonding_group
;