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(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;
174 return restart_syscall();
176 bond_for_each_slave(bond, slave, iter) {
177 if (res > (PAGE_SIZE - IFNAMSIZ)) {
178 /* not enough space for another interface name */
179 if ((PAGE_SIZE - res) > 10)
180 res = PAGE_SIZE - 10;
181 res += sysfs_emit_at(buf, res, "++more++ ");
184 res += sysfs_emit_at(buf, res, "%s ", slave->dev->name);
190 buf[res-1] = '\n'; /* eat the leftover space */
194 static DEVICE_ATTR(slaves, 0644, bonding_show_slaves,
195 bonding_sysfs_store_option);
197 /* Show the bonding mode. */
198 static ssize_t bonding_show_mode(struct device *d,
199 struct device_attribute *attr, char *buf)
201 struct bonding *bond = to_bond(d);
202 const struct bond_opt_value *val;
204 val = bond_opt_get_val(BOND_OPT_MODE, BOND_MODE(bond));
206 return sysfs_emit(buf, "%s %d\n", val->string, BOND_MODE(bond));
208 static DEVICE_ATTR(mode, 0644, bonding_show_mode, bonding_sysfs_store_option);
210 /* Show the bonding transmit hash method. */
211 static ssize_t bonding_show_xmit_hash(struct device *d,
212 struct device_attribute *attr,
215 struct bonding *bond = to_bond(d);
216 const struct bond_opt_value *val;
218 val = bond_opt_get_val(BOND_OPT_XMIT_HASH, bond->params.xmit_policy);
220 return sysfs_emit(buf, "%s %d\n", val->string, bond->params.xmit_policy);
222 static DEVICE_ATTR(xmit_hash_policy, 0644,
223 bonding_show_xmit_hash, bonding_sysfs_store_option);
225 /* Show arp_validate. */
226 static ssize_t bonding_show_arp_validate(struct device *d,
227 struct device_attribute *attr,
230 struct bonding *bond = to_bond(d);
231 const struct bond_opt_value *val;
233 val = bond_opt_get_val(BOND_OPT_ARP_VALIDATE,
234 bond->params.arp_validate);
236 return sysfs_emit(buf, "%s %d\n", val->string, bond->params.arp_validate);
238 static DEVICE_ATTR(arp_validate, 0644, bonding_show_arp_validate,
239 bonding_sysfs_store_option);
241 /* Show arp_all_targets. */
242 static ssize_t bonding_show_arp_all_targets(struct device *d,
243 struct device_attribute *attr,
246 struct bonding *bond = to_bond(d);
247 const struct bond_opt_value *val;
249 val = bond_opt_get_val(BOND_OPT_ARP_ALL_TARGETS,
250 bond->params.arp_all_targets);
251 return sysfs_emit(buf, "%s %d\n",
252 val->string, bond->params.arp_all_targets);
254 static DEVICE_ATTR(arp_all_targets, 0644,
255 bonding_show_arp_all_targets, bonding_sysfs_store_option);
257 /* Show fail_over_mac. */
258 static ssize_t bonding_show_fail_over_mac(struct device *d,
259 struct device_attribute *attr,
262 struct bonding *bond = to_bond(d);
263 const struct bond_opt_value *val;
265 val = bond_opt_get_val(BOND_OPT_FAIL_OVER_MAC,
266 bond->params.fail_over_mac);
268 return sysfs_emit(buf, "%s %d\n", val->string, bond->params.fail_over_mac);
270 static DEVICE_ATTR(fail_over_mac, 0644,
271 bonding_show_fail_over_mac, bonding_sysfs_store_option);
273 /* Show the arp timer interval. */
274 static ssize_t bonding_show_arp_interval(struct device *d,
275 struct device_attribute *attr,
278 struct bonding *bond = to_bond(d);
280 return sysfs_emit(buf, "%d\n", bond->params.arp_interval);
282 static DEVICE_ATTR(arp_interval, 0644,
283 bonding_show_arp_interval, bonding_sysfs_store_option);
285 /* Show the arp targets. */
286 static ssize_t bonding_show_arp_targets(struct device *d,
287 struct device_attribute *attr,
290 struct bonding *bond = to_bond(d);
293 for (i = 0; i < BOND_MAX_ARP_TARGETS; i++) {
294 if (bond->params.arp_targets[i])
295 res += sysfs_emit_at(buf, res, "%pI4 ",
296 &bond->params.arp_targets[i]);
299 buf[res-1] = '\n'; /* eat the leftover space */
303 static DEVICE_ATTR(arp_ip_target, 0644,
304 bonding_show_arp_targets, bonding_sysfs_store_option);
306 /* Show the arp missed max. */
307 static ssize_t bonding_show_missed_max(struct device *d,
308 struct device_attribute *attr,
311 struct bonding *bond = to_bond(d);
313 return sysfs_emit(buf, "%u\n", bond->params.missed_max);
315 static DEVICE_ATTR(arp_missed_max, 0644,
316 bonding_show_missed_max, bonding_sysfs_store_option);
318 /* Show the up and down delays. */
319 static ssize_t bonding_show_downdelay(struct device *d,
320 struct device_attribute *attr,
323 struct bonding *bond = to_bond(d);
325 return sysfs_emit(buf, "%d\n", bond->params.downdelay * bond->params.miimon);
327 static DEVICE_ATTR(downdelay, 0644,
328 bonding_show_downdelay, bonding_sysfs_store_option);
330 static ssize_t bonding_show_updelay(struct device *d,
331 struct device_attribute *attr,
334 struct bonding *bond = to_bond(d);
336 return sysfs_emit(buf, "%d\n", bond->params.updelay * bond->params.miimon);
339 static DEVICE_ATTR(updelay, 0644,
340 bonding_show_updelay, bonding_sysfs_store_option);
342 static ssize_t bonding_show_peer_notif_delay(struct device *d,
343 struct device_attribute *attr,
346 struct bonding *bond = to_bond(d);
348 return sysfs_emit(buf, "%d\n",
349 bond->params.peer_notif_delay * bond->params.miimon);
351 static DEVICE_ATTR(peer_notif_delay, 0644,
352 bonding_show_peer_notif_delay, bonding_sysfs_store_option);
354 /* Show the LACP activity and interval. */
355 static ssize_t bonding_show_lacp_active(struct device *d,
356 struct device_attribute *attr,
359 struct bonding *bond = to_bond(d);
360 const struct bond_opt_value *val;
362 val = bond_opt_get_val(BOND_OPT_LACP_ACTIVE, bond->params.lacp_active);
364 return sysfs_emit(buf, "%s %d\n", val->string, bond->params.lacp_active);
366 static DEVICE_ATTR(lacp_active, 0644,
367 bonding_show_lacp_active, bonding_sysfs_store_option);
369 static ssize_t bonding_show_lacp_rate(struct device *d,
370 struct device_attribute *attr,
373 struct bonding *bond = to_bond(d);
374 const struct bond_opt_value *val;
376 val = bond_opt_get_val(BOND_OPT_LACP_RATE, bond->params.lacp_fast);
378 return sysfs_emit(buf, "%s %d\n", val->string, bond->params.lacp_fast);
380 static DEVICE_ATTR(lacp_rate, 0644,
381 bonding_show_lacp_rate, bonding_sysfs_store_option);
383 static ssize_t bonding_show_min_links(struct device *d,
384 struct device_attribute *attr,
387 struct bonding *bond = to_bond(d);
389 return sysfs_emit(buf, "%u\n", bond->params.min_links);
391 static DEVICE_ATTR(min_links, 0644,
392 bonding_show_min_links, bonding_sysfs_store_option);
394 static ssize_t bonding_show_ad_select(struct device *d,
395 struct device_attribute *attr,
398 struct bonding *bond = to_bond(d);
399 const struct bond_opt_value *val;
401 val = bond_opt_get_val(BOND_OPT_AD_SELECT, bond->params.ad_select);
403 return sysfs_emit(buf, "%s %d\n", val->string, bond->params.ad_select);
405 static DEVICE_ATTR(ad_select, 0644,
406 bonding_show_ad_select, bonding_sysfs_store_option);
408 /* Show the number of peer notifications to send after a failover event. */
409 static ssize_t bonding_show_num_peer_notif(struct device *d,
410 struct device_attribute *attr,
413 struct bonding *bond = to_bond(d);
415 return sysfs_emit(buf, "%d\n", bond->params.num_peer_notif);
417 static DEVICE_ATTR(num_grat_arp, 0644,
418 bonding_show_num_peer_notif, bonding_sysfs_store_option);
419 static DEVICE_ATTR(num_unsol_na, 0644,
420 bonding_show_num_peer_notif, bonding_sysfs_store_option);
422 /* Show the MII monitor interval. */
423 static ssize_t bonding_show_miimon(struct device *d,
424 struct device_attribute *attr,
427 struct bonding *bond = to_bond(d);
429 return sysfs_emit(buf, "%d\n", bond->params.miimon);
431 static DEVICE_ATTR(miimon, 0644,
432 bonding_show_miimon, bonding_sysfs_store_option);
434 /* Show the primary slave. */
435 static ssize_t bonding_show_primary(struct device *d,
436 struct device_attribute *attr,
439 struct bonding *bond = to_bond(d);
440 struct slave *primary;
444 primary = rcu_dereference(bond->primary_slave);
446 count = sysfs_emit(buf, "%s\n", primary->dev->name);
451 static DEVICE_ATTR(primary, 0644,
452 bonding_show_primary, bonding_sysfs_store_option);
454 /* Show the primary_reselect flag. */
455 static ssize_t bonding_show_primary_reselect(struct device *d,
456 struct device_attribute *attr,
459 struct bonding *bond = to_bond(d);
460 const struct bond_opt_value *val;
462 val = bond_opt_get_val(BOND_OPT_PRIMARY_RESELECT,
463 bond->params.primary_reselect);
465 return sysfs_emit(buf, "%s %d\n",
466 val->string, bond->params.primary_reselect);
468 static DEVICE_ATTR(primary_reselect, 0644,
469 bonding_show_primary_reselect, bonding_sysfs_store_option);
471 /* Show the use_carrier flag. */
472 static ssize_t bonding_show_carrier(struct device *d,
473 struct device_attribute *attr,
476 struct bonding *bond = to_bond(d);
478 return sysfs_emit(buf, "%d\n", bond->params.use_carrier);
480 static DEVICE_ATTR(use_carrier, 0644,
481 bonding_show_carrier, bonding_sysfs_store_option);
484 /* Show currently active_slave. */
485 static ssize_t bonding_show_active_slave(struct device *d,
486 struct device_attribute *attr,
489 struct bonding *bond = to_bond(d);
490 struct net_device *slave_dev;
494 slave_dev = bond_option_active_slave_get_rcu(bond);
496 count = sysfs_emit(buf, "%s\n", slave_dev->name);
501 static DEVICE_ATTR(active_slave, 0644,
502 bonding_show_active_slave, bonding_sysfs_store_option);
504 /* Show link status of the bond interface. */
505 static ssize_t bonding_show_mii_status(struct device *d,
506 struct device_attribute *attr,
509 struct bonding *bond = to_bond(d);
510 bool active = netif_carrier_ok(bond->dev);
512 return sysfs_emit(buf, "%s\n", active ? "up" : "down");
514 static DEVICE_ATTR(mii_status, 0444, bonding_show_mii_status, NULL);
516 /* Show current 802.3ad aggregator ID. */
517 static ssize_t bonding_show_ad_aggregator(struct device *d,
518 struct device_attribute *attr,
522 struct bonding *bond = to_bond(d);
524 if (BOND_MODE(bond) == BOND_MODE_8023AD) {
525 struct ad_info ad_info;
527 count = sysfs_emit(buf, "%d\n",
528 bond_3ad_get_active_agg_info(bond, &ad_info)
529 ? 0 : ad_info.aggregator_id);
534 static DEVICE_ATTR(ad_aggregator, 0444, bonding_show_ad_aggregator, NULL);
537 /* Show number of active 802.3ad ports. */
538 static ssize_t bonding_show_ad_num_ports(struct device *d,
539 struct device_attribute *attr,
543 struct bonding *bond = to_bond(d);
545 if (BOND_MODE(bond) == BOND_MODE_8023AD) {
546 struct ad_info ad_info;
548 count = sysfs_emit(buf, "%d\n",
549 bond_3ad_get_active_agg_info(bond, &ad_info)
550 ? 0 : ad_info.ports);
555 static DEVICE_ATTR(ad_num_ports, 0444, bonding_show_ad_num_ports, NULL);
558 /* Show current 802.3ad actor key. */
559 static ssize_t bonding_show_ad_actor_key(struct device *d,
560 struct device_attribute *attr,
564 struct bonding *bond = to_bond(d);
566 if (BOND_MODE(bond) == BOND_MODE_8023AD && capable(CAP_NET_ADMIN)) {
567 struct ad_info ad_info;
569 count = sysfs_emit(buf, "%d\n",
570 bond_3ad_get_active_agg_info(bond, &ad_info)
571 ? 0 : ad_info.actor_key);
576 static DEVICE_ATTR(ad_actor_key, 0444, bonding_show_ad_actor_key, NULL);
579 /* Show current 802.3ad partner key. */
580 static ssize_t bonding_show_ad_partner_key(struct device *d,
581 struct device_attribute *attr,
585 struct bonding *bond = to_bond(d);
587 if (BOND_MODE(bond) == BOND_MODE_8023AD && capable(CAP_NET_ADMIN)) {
588 struct ad_info ad_info;
590 count = sysfs_emit(buf, "%d\n",
591 bond_3ad_get_active_agg_info(bond, &ad_info)
592 ? 0 : ad_info.partner_key);
597 static DEVICE_ATTR(ad_partner_key, 0444, bonding_show_ad_partner_key, NULL);
600 /* Show current 802.3ad partner mac. */
601 static ssize_t bonding_show_ad_partner_mac(struct device *d,
602 struct device_attribute *attr,
606 struct bonding *bond = to_bond(d);
608 if (BOND_MODE(bond) == BOND_MODE_8023AD && capable(CAP_NET_ADMIN)) {
609 struct ad_info ad_info;
611 if (!bond_3ad_get_active_agg_info(bond, &ad_info))
612 count = sysfs_emit(buf, "%pM\n", ad_info.partner_system);
617 static DEVICE_ATTR(ad_partner_mac, 0444, bonding_show_ad_partner_mac, NULL);
619 /* Show the queue_ids of the slaves in the current bond. */
620 static ssize_t bonding_show_queue_id(struct device *d,
621 struct device_attribute *attr,
624 struct bonding *bond = to_bond(d);
625 struct list_head *iter;
630 return restart_syscall();
632 bond_for_each_slave(bond, slave, iter) {
633 if (res > (PAGE_SIZE - IFNAMSIZ - 6)) {
634 /* not enough space for another interface_name:queue_id pair */
635 if ((PAGE_SIZE - res) > 10)
636 res = PAGE_SIZE - 10;
637 res += sysfs_emit_at(buf, res, "++more++ ");
640 res += sysfs_emit_at(buf, res, "%s:%d ",
641 slave->dev->name, slave->queue_id);
644 buf[res-1] = '\n'; /* eat the leftover space */
650 static DEVICE_ATTR(queue_id, 0644, bonding_show_queue_id,
651 bonding_sysfs_store_option);
654 /* Show the all_slaves_active flag. */
655 static ssize_t bonding_show_slaves_active(struct device *d,
656 struct device_attribute *attr,
659 struct bonding *bond = to_bond(d);
661 return sysfs_emit(buf, "%d\n", bond->params.all_slaves_active);
663 static DEVICE_ATTR(all_slaves_active, 0644,
664 bonding_show_slaves_active, bonding_sysfs_store_option);
666 /* Show the number of IGMP membership reports to send on link failure */
667 static ssize_t bonding_show_resend_igmp(struct device *d,
668 struct device_attribute *attr,
671 struct bonding *bond = to_bond(d);
673 return sysfs_emit(buf, "%d\n", bond->params.resend_igmp);
675 static DEVICE_ATTR(resend_igmp, 0644,
676 bonding_show_resend_igmp, bonding_sysfs_store_option);
679 static ssize_t bonding_show_lp_interval(struct device *d,
680 struct device_attribute *attr,
683 struct bonding *bond = to_bond(d);
685 return sysfs_emit(buf, "%d\n", bond->params.lp_interval);
687 static DEVICE_ATTR(lp_interval, 0644,
688 bonding_show_lp_interval, bonding_sysfs_store_option);
690 static ssize_t bonding_show_tlb_dynamic_lb(struct device *d,
691 struct device_attribute *attr,
694 struct bonding *bond = to_bond(d);
696 return sysfs_emit(buf, "%d\n", bond->params.tlb_dynamic_lb);
698 static DEVICE_ATTR(tlb_dynamic_lb, 0644,
699 bonding_show_tlb_dynamic_lb, bonding_sysfs_store_option);
701 static ssize_t bonding_show_packets_per_slave(struct device *d,
702 struct device_attribute *attr,
705 struct bonding *bond = to_bond(d);
706 unsigned int packets_per_slave = bond->params.packets_per_slave;
708 return sysfs_emit(buf, "%u\n", packets_per_slave);
710 static DEVICE_ATTR(packets_per_slave, 0644,
711 bonding_show_packets_per_slave, bonding_sysfs_store_option);
713 static ssize_t bonding_show_ad_actor_sys_prio(struct device *d,
714 struct device_attribute *attr,
717 struct bonding *bond = to_bond(d);
719 if (BOND_MODE(bond) == BOND_MODE_8023AD && capable(CAP_NET_ADMIN))
720 return sysfs_emit(buf, "%hu\n", bond->params.ad_actor_sys_prio);
724 static DEVICE_ATTR(ad_actor_sys_prio, 0644,
725 bonding_show_ad_actor_sys_prio, bonding_sysfs_store_option);
727 static ssize_t bonding_show_ad_actor_system(struct device *d,
728 struct device_attribute *attr,
731 struct bonding *bond = to_bond(d);
733 if (BOND_MODE(bond) == BOND_MODE_8023AD && capable(CAP_NET_ADMIN))
734 return sysfs_emit(buf, "%pM\n", bond->params.ad_actor_system);
739 static DEVICE_ATTR(ad_actor_system, 0644,
740 bonding_show_ad_actor_system, bonding_sysfs_store_option);
742 static ssize_t bonding_show_ad_user_port_key(struct device *d,
743 struct device_attribute *attr,
746 struct bonding *bond = to_bond(d);
748 if (BOND_MODE(bond) == BOND_MODE_8023AD && capable(CAP_NET_ADMIN))
749 return sysfs_emit(buf, "%hu\n", bond->params.ad_user_port_key);
753 static DEVICE_ATTR(ad_user_port_key, 0644,
754 bonding_show_ad_user_port_key, bonding_sysfs_store_option);
756 static struct attribute *per_bond_attrs[] = {
757 &dev_attr_slaves.attr,
759 &dev_attr_fail_over_mac.attr,
760 &dev_attr_arp_validate.attr,
761 &dev_attr_arp_all_targets.attr,
762 &dev_attr_arp_interval.attr,
763 &dev_attr_arp_ip_target.attr,
764 &dev_attr_downdelay.attr,
765 &dev_attr_updelay.attr,
766 &dev_attr_peer_notif_delay.attr,
767 &dev_attr_lacp_active.attr,
768 &dev_attr_lacp_rate.attr,
769 &dev_attr_ad_select.attr,
770 &dev_attr_xmit_hash_policy.attr,
771 &dev_attr_num_grat_arp.attr,
772 &dev_attr_num_unsol_na.attr,
773 &dev_attr_miimon.attr,
774 &dev_attr_primary.attr,
775 &dev_attr_primary_reselect.attr,
776 &dev_attr_use_carrier.attr,
777 &dev_attr_active_slave.attr,
778 &dev_attr_mii_status.attr,
779 &dev_attr_ad_aggregator.attr,
780 &dev_attr_ad_num_ports.attr,
781 &dev_attr_ad_actor_key.attr,
782 &dev_attr_ad_partner_key.attr,
783 &dev_attr_ad_partner_mac.attr,
784 &dev_attr_queue_id.attr,
785 &dev_attr_all_slaves_active.attr,
786 &dev_attr_resend_igmp.attr,
787 &dev_attr_min_links.attr,
788 &dev_attr_lp_interval.attr,
789 &dev_attr_packets_per_slave.attr,
790 &dev_attr_tlb_dynamic_lb.attr,
791 &dev_attr_ad_actor_sys_prio.attr,
792 &dev_attr_ad_actor_system.attr,
793 &dev_attr_ad_user_port_key.attr,
794 &dev_attr_arp_missed_max.attr,
798 static const struct attribute_group bonding_group = {
800 .attrs = per_bond_attrs,
803 /* Initialize sysfs. This sets up the bonding_masters file in
806 int __net_init bond_create_sysfs(struct bond_net *bn)
810 bn->class_attr_bonding_masters = class_attr_bonding_masters;
811 sysfs_attr_init(&bn->class_attr_bonding_masters.attr);
813 ret = netdev_class_create_file_ns(&bn->class_attr_bonding_masters,
815 /* Permit multiple loads of the module by ignoring failures to
816 * create the bonding_masters sysfs file. Bonding devices
817 * created by second or subsequent loads of the module will
818 * not be listed in, or controllable by, bonding_masters, but
819 * will have the usual "bonding" sysfs directory.
821 * This is done to preserve backwards compatibility for
822 * initscripts/sysconfig, which load bonding multiple times to
823 * configure multiple bonding devices.
825 if (ret == -EEXIST) {
826 /* Is someone being kinky and naming a device bonding_master? */
827 if (netdev_name_in_use(bn->net,
828 class_attr_bonding_masters.attr.name))
829 pr_err("network device named %s already exists in sysfs\n",
830 class_attr_bonding_masters.attr.name);
838 /* Remove /sys/class/net/bonding_masters. */
839 void __net_exit bond_destroy_sysfs(struct bond_net *bn)
841 netdev_class_remove_file_ns(&bn->class_attr_bonding_masters, bn->net);
844 /* Initialize sysfs for each bond. This sets up and registers
845 * the 'bondctl' directory for each individual bond under /sys/class/net.
847 void bond_prepare_sysfs_group(struct bonding *bond)
849 bond->dev->sysfs_groups[0] = &bonding_group;