2 * Sysfs attributes of bridge
3 * Linux ethernet bridge
6 * Stephen Hemminger <shemminger@osdl.org>
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version
11 * 2 of the License, or (at your option) any later version.
14 #include <linux/capability.h>
15 #include <linux/kernel.h>
16 #include <linux/netdevice.h>
17 #include <linux/etherdevice.h>
18 #include <linux/if_bridge.h>
19 #include <linux/rtnetlink.h>
20 #include <linux/spinlock.h>
21 #include <linux/times.h>
23 #include "br_private.h"
25 #define to_dev(obj) container_of(obj, struct device, kobj)
26 #define to_bridge(cd) ((struct net_bridge *)netdev_priv(to_net_dev(cd)))
29 * Common code for storing bridge parameters.
31 static ssize_t store_bridge_parm(struct device *d,
32 const char *buf, size_t len,
33 int (*set)(struct net_bridge *, unsigned long))
35 struct net_bridge *br = to_bridge(d);
40 if (!ns_capable(dev_net(br->dev)->user_ns, CAP_NET_ADMIN))
43 val = simple_strtoul(buf, &endp, 0);
47 err = (*set)(br, val);
48 return err ? err : len;
52 static ssize_t forward_delay_show(struct device *d,
53 struct device_attribute *attr, char *buf)
55 struct net_bridge *br = to_bridge(d);
56 return sprintf(buf, "%lu\n", jiffies_to_clock_t(br->forward_delay));
59 static ssize_t forward_delay_store(struct device *d,
60 struct device_attribute *attr,
61 const char *buf, size_t len)
63 return store_bridge_parm(d, buf, len, br_set_forward_delay);
65 static DEVICE_ATTR_RW(forward_delay);
67 static ssize_t hello_time_show(struct device *d, struct device_attribute *attr,
70 return sprintf(buf, "%lu\n",
71 jiffies_to_clock_t(to_bridge(d)->hello_time));
74 static ssize_t hello_time_store(struct device *d,
75 struct device_attribute *attr, const char *buf,
78 return store_bridge_parm(d, buf, len, br_set_hello_time);
80 static DEVICE_ATTR_RW(hello_time);
82 static ssize_t max_age_show(struct device *d, struct device_attribute *attr,
85 return sprintf(buf, "%lu\n",
86 jiffies_to_clock_t(to_bridge(d)->max_age));
89 static ssize_t max_age_store(struct device *d, struct device_attribute *attr,
90 const char *buf, size_t len)
92 return store_bridge_parm(d, buf, len, br_set_max_age);
94 static DEVICE_ATTR_RW(max_age);
96 static ssize_t ageing_time_show(struct device *d,
97 struct device_attribute *attr, char *buf)
99 struct net_bridge *br = to_bridge(d);
100 return sprintf(buf, "%lu\n", jiffies_to_clock_t(br->ageing_time));
103 static int set_ageing_time(struct net_bridge *br, unsigned long val)
105 return br_set_ageing_time(br, val);
108 static ssize_t ageing_time_store(struct device *d,
109 struct device_attribute *attr,
110 const char *buf, size_t len)
112 return store_bridge_parm(d, buf, len, set_ageing_time);
114 static DEVICE_ATTR_RW(ageing_time);
116 static ssize_t stp_state_show(struct device *d,
117 struct device_attribute *attr, char *buf)
119 struct net_bridge *br = to_bridge(d);
120 return sprintf(buf, "%d\n", br->stp_enabled);
124 static ssize_t stp_state_store(struct device *d,
125 struct device_attribute *attr, const char *buf,
128 struct net_bridge *br = to_bridge(d);
132 if (!ns_capable(dev_net(br->dev)->user_ns, CAP_NET_ADMIN))
135 val = simple_strtoul(buf, &endp, 0);
140 return restart_syscall();
141 br_stp_set_enabled(br, val);
146 static DEVICE_ATTR_RW(stp_state);
148 static ssize_t group_fwd_mask_show(struct device *d,
149 struct device_attribute *attr,
152 struct net_bridge *br = to_bridge(d);
153 return sprintf(buf, "%#x\n", br->group_fwd_mask);
157 static ssize_t group_fwd_mask_store(struct device *d,
158 struct device_attribute *attr,
162 struct net_bridge *br = to_bridge(d);
166 if (!ns_capable(dev_net(br->dev)->user_ns, CAP_NET_ADMIN))
169 val = simple_strtoul(buf, &endp, 0);
173 if (val & BR_GROUPFWD_RESTRICTED)
176 br->group_fwd_mask = val;
180 static DEVICE_ATTR_RW(group_fwd_mask);
182 static ssize_t priority_show(struct device *d, struct device_attribute *attr,
185 struct net_bridge *br = to_bridge(d);
186 return sprintf(buf, "%d\n",
187 (br->bridge_id.prio[0] << 8) | br->bridge_id.prio[1]);
190 static int set_priority(struct net_bridge *br, unsigned long val)
192 br_stp_set_bridge_priority(br, (u16) val);
196 static ssize_t priority_store(struct device *d, struct device_attribute *attr,
197 const char *buf, size_t len)
199 return store_bridge_parm(d, buf, len, set_priority);
201 static DEVICE_ATTR_RW(priority);
203 static ssize_t root_id_show(struct device *d, struct device_attribute *attr,
206 return br_show_bridge_id(buf, &to_bridge(d)->designated_root);
208 static DEVICE_ATTR_RO(root_id);
210 static ssize_t bridge_id_show(struct device *d, struct device_attribute *attr,
213 return br_show_bridge_id(buf, &to_bridge(d)->bridge_id);
215 static DEVICE_ATTR_RO(bridge_id);
217 static ssize_t root_port_show(struct device *d, struct device_attribute *attr,
220 return sprintf(buf, "%d\n", to_bridge(d)->root_port);
222 static DEVICE_ATTR_RO(root_port);
224 static ssize_t root_path_cost_show(struct device *d,
225 struct device_attribute *attr, char *buf)
227 return sprintf(buf, "%d\n", to_bridge(d)->root_path_cost);
229 static DEVICE_ATTR_RO(root_path_cost);
231 static ssize_t topology_change_show(struct device *d,
232 struct device_attribute *attr, char *buf)
234 return sprintf(buf, "%d\n", to_bridge(d)->topology_change);
236 static DEVICE_ATTR_RO(topology_change);
238 static ssize_t topology_change_detected_show(struct device *d,
239 struct device_attribute *attr,
242 struct net_bridge *br = to_bridge(d);
243 return sprintf(buf, "%d\n", br->topology_change_detected);
245 static DEVICE_ATTR_RO(topology_change_detected);
247 static ssize_t hello_timer_show(struct device *d,
248 struct device_attribute *attr, char *buf)
250 struct net_bridge *br = to_bridge(d);
251 return sprintf(buf, "%ld\n", br_timer_value(&br->hello_timer));
253 static DEVICE_ATTR_RO(hello_timer);
255 static ssize_t tcn_timer_show(struct device *d, struct device_attribute *attr,
258 struct net_bridge *br = to_bridge(d);
259 return sprintf(buf, "%ld\n", br_timer_value(&br->tcn_timer));
261 static DEVICE_ATTR_RO(tcn_timer);
263 static ssize_t topology_change_timer_show(struct device *d,
264 struct device_attribute *attr,
267 struct net_bridge *br = to_bridge(d);
268 return sprintf(buf, "%ld\n", br_timer_value(&br->topology_change_timer));
270 static DEVICE_ATTR_RO(topology_change_timer);
272 static ssize_t gc_timer_show(struct device *d, struct device_attribute *attr,
275 struct net_bridge *br = to_bridge(d);
276 return sprintf(buf, "%ld\n", br_timer_value(&br->gc_timer));
278 static DEVICE_ATTR_RO(gc_timer);
280 static ssize_t group_addr_show(struct device *d,
281 struct device_attribute *attr, char *buf)
283 struct net_bridge *br = to_bridge(d);
284 return sprintf(buf, "%x:%x:%x:%x:%x:%x\n",
285 br->group_addr[0], br->group_addr[1],
286 br->group_addr[2], br->group_addr[3],
287 br->group_addr[4], br->group_addr[5]);
290 static ssize_t group_addr_store(struct device *d,
291 struct device_attribute *attr,
292 const char *buf, size_t len)
294 struct net_bridge *br = to_bridge(d);
298 if (!ns_capable(dev_net(br->dev)->user_ns, CAP_NET_ADMIN))
301 if (sscanf(buf, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx",
302 &new_addr[0], &new_addr[1], &new_addr[2],
303 &new_addr[3], &new_addr[4], &new_addr[5]) != 6)
306 if (!is_link_local_ether_addr(new_addr))
309 if (new_addr[5] == 1 || /* 802.3x Pause address */
310 new_addr[5] == 2 || /* 802.3ad Slow protocols */
311 new_addr[5] == 3) /* 802.1X PAE address */
315 return restart_syscall();
317 spin_lock_bh(&br->lock);
318 for (i = 0; i < 6; i++)
319 br->group_addr[i] = new_addr[i];
320 spin_unlock_bh(&br->lock);
322 br->group_addr_set = true;
323 br_recalculate_fwd_mask(br);
330 static DEVICE_ATTR_RW(group_addr);
332 static ssize_t flush_store(struct device *d,
333 struct device_attribute *attr,
334 const char *buf, size_t len)
336 struct net_bridge *br = to_bridge(d);
338 if (!ns_capable(dev_net(br->dev)->user_ns, CAP_NET_ADMIN))
344 static DEVICE_ATTR_WO(flush);
346 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
347 static ssize_t multicast_router_show(struct device *d,
348 struct device_attribute *attr, char *buf)
350 struct net_bridge *br = to_bridge(d);
351 return sprintf(buf, "%d\n", br->multicast_router);
354 static ssize_t multicast_router_store(struct device *d,
355 struct device_attribute *attr,
356 const char *buf, size_t len)
358 return store_bridge_parm(d, buf, len, br_multicast_set_router);
360 static DEVICE_ATTR_RW(multicast_router);
362 static ssize_t multicast_snooping_show(struct device *d,
363 struct device_attribute *attr,
366 struct net_bridge *br = to_bridge(d);
367 return sprintf(buf, "%d\n", !br->multicast_disabled);
370 static ssize_t multicast_snooping_store(struct device *d,
371 struct device_attribute *attr,
372 const char *buf, size_t len)
374 return store_bridge_parm(d, buf, len, br_multicast_toggle);
376 static DEVICE_ATTR_RW(multicast_snooping);
378 static ssize_t multicast_query_use_ifaddr_show(struct device *d,
379 struct device_attribute *attr,
382 struct net_bridge *br = to_bridge(d);
383 return sprintf(buf, "%d\n", br->multicast_query_use_ifaddr);
386 static int set_query_use_ifaddr(struct net_bridge *br, unsigned long val)
388 br->multicast_query_use_ifaddr = !!val;
393 multicast_query_use_ifaddr_store(struct device *d,
394 struct device_attribute *attr,
395 const char *buf, size_t len)
397 return store_bridge_parm(d, buf, len, set_query_use_ifaddr);
399 static DEVICE_ATTR_RW(multicast_query_use_ifaddr);
401 static ssize_t multicast_querier_show(struct device *d,
402 struct device_attribute *attr,
405 struct net_bridge *br = to_bridge(d);
406 return sprintf(buf, "%d\n", br->multicast_querier);
409 static ssize_t multicast_querier_store(struct device *d,
410 struct device_attribute *attr,
411 const char *buf, size_t len)
413 return store_bridge_parm(d, buf, len, br_multicast_set_querier);
415 static DEVICE_ATTR_RW(multicast_querier);
417 static ssize_t hash_elasticity_show(struct device *d,
418 struct device_attribute *attr, char *buf)
420 struct net_bridge *br = to_bridge(d);
421 return sprintf(buf, "%u\n", br->hash_elasticity);
424 static int set_elasticity(struct net_bridge *br, unsigned long val)
426 br->hash_elasticity = val;
430 static ssize_t hash_elasticity_store(struct device *d,
431 struct device_attribute *attr,
432 const char *buf, size_t len)
434 return store_bridge_parm(d, buf, len, set_elasticity);
436 static DEVICE_ATTR_RW(hash_elasticity);
438 static ssize_t hash_max_show(struct device *d, struct device_attribute *attr,
441 struct net_bridge *br = to_bridge(d);
442 return sprintf(buf, "%u\n", br->hash_max);
445 static ssize_t hash_max_store(struct device *d, struct device_attribute *attr,
446 const char *buf, size_t len)
448 return store_bridge_parm(d, buf, len, br_multicast_set_hash_max);
450 static DEVICE_ATTR_RW(hash_max);
452 static ssize_t multicast_last_member_count_show(struct device *d,
453 struct device_attribute *attr,
456 struct net_bridge *br = to_bridge(d);
457 return sprintf(buf, "%u\n", br->multicast_last_member_count);
460 static int set_last_member_count(struct net_bridge *br, unsigned long val)
462 br->multicast_last_member_count = val;
466 static ssize_t multicast_last_member_count_store(struct device *d,
467 struct device_attribute *attr,
468 const char *buf, size_t len)
470 return store_bridge_parm(d, buf, len, set_last_member_count);
472 static DEVICE_ATTR_RW(multicast_last_member_count);
474 static ssize_t multicast_startup_query_count_show(
475 struct device *d, struct device_attribute *attr, char *buf)
477 struct net_bridge *br = to_bridge(d);
478 return sprintf(buf, "%u\n", br->multicast_startup_query_count);
481 static int set_startup_query_count(struct net_bridge *br, unsigned long val)
483 br->multicast_startup_query_count = val;
487 static ssize_t multicast_startup_query_count_store(
488 struct device *d, struct device_attribute *attr, const char *buf,
491 return store_bridge_parm(d, buf, len, set_startup_query_count);
493 static DEVICE_ATTR_RW(multicast_startup_query_count);
495 static ssize_t multicast_last_member_interval_show(
496 struct device *d, struct device_attribute *attr, char *buf)
498 struct net_bridge *br = to_bridge(d);
499 return sprintf(buf, "%lu\n",
500 jiffies_to_clock_t(br->multicast_last_member_interval));
503 static int set_last_member_interval(struct net_bridge *br, unsigned long val)
505 br->multicast_last_member_interval = clock_t_to_jiffies(val);
509 static ssize_t multicast_last_member_interval_store(
510 struct device *d, struct device_attribute *attr, const char *buf,
513 return store_bridge_parm(d, buf, len, set_last_member_interval);
515 static DEVICE_ATTR_RW(multicast_last_member_interval);
517 static ssize_t multicast_membership_interval_show(
518 struct device *d, struct device_attribute *attr, char *buf)
520 struct net_bridge *br = to_bridge(d);
521 return sprintf(buf, "%lu\n",
522 jiffies_to_clock_t(br->multicast_membership_interval));
525 static int set_membership_interval(struct net_bridge *br, unsigned long val)
527 br->multicast_membership_interval = clock_t_to_jiffies(val);
531 static ssize_t multicast_membership_interval_store(
532 struct device *d, struct device_attribute *attr, const char *buf,
535 return store_bridge_parm(d, buf, len, set_membership_interval);
537 static DEVICE_ATTR_RW(multicast_membership_interval);
539 static ssize_t multicast_querier_interval_show(struct device *d,
540 struct device_attribute *attr,
543 struct net_bridge *br = to_bridge(d);
544 return sprintf(buf, "%lu\n",
545 jiffies_to_clock_t(br->multicast_querier_interval));
548 static int set_querier_interval(struct net_bridge *br, unsigned long val)
550 br->multicast_querier_interval = clock_t_to_jiffies(val);
554 static ssize_t multicast_querier_interval_store(struct device *d,
555 struct device_attribute *attr,
556 const char *buf, size_t len)
558 return store_bridge_parm(d, buf, len, set_querier_interval);
560 static DEVICE_ATTR_RW(multicast_querier_interval);
562 static ssize_t multicast_query_interval_show(struct device *d,
563 struct device_attribute *attr,
566 struct net_bridge *br = to_bridge(d);
567 return sprintf(buf, "%lu\n",
568 jiffies_to_clock_t(br->multicast_query_interval));
571 static int set_query_interval(struct net_bridge *br, unsigned long val)
573 br->multicast_query_interval = clock_t_to_jiffies(val);
577 static ssize_t multicast_query_interval_store(struct device *d,
578 struct device_attribute *attr,
579 const char *buf, size_t len)
581 return store_bridge_parm(d, buf, len, set_query_interval);
583 static DEVICE_ATTR_RW(multicast_query_interval);
585 static ssize_t multicast_query_response_interval_show(
586 struct device *d, struct device_attribute *attr, char *buf)
588 struct net_bridge *br = to_bridge(d);
591 jiffies_to_clock_t(br->multicast_query_response_interval));
594 static int set_query_response_interval(struct net_bridge *br, unsigned long val)
596 br->multicast_query_response_interval = clock_t_to_jiffies(val);
600 static ssize_t multicast_query_response_interval_store(
601 struct device *d, struct device_attribute *attr, const char *buf,
604 return store_bridge_parm(d, buf, len, set_query_response_interval);
606 static DEVICE_ATTR_RW(multicast_query_response_interval);
608 static ssize_t multicast_startup_query_interval_show(
609 struct device *d, struct device_attribute *attr, char *buf)
611 struct net_bridge *br = to_bridge(d);
614 jiffies_to_clock_t(br->multicast_startup_query_interval));
617 static int set_startup_query_interval(struct net_bridge *br, unsigned long val)
619 br->multicast_startup_query_interval = clock_t_to_jiffies(val);
623 static ssize_t multicast_startup_query_interval_store(
624 struct device *d, struct device_attribute *attr, const char *buf,
627 return store_bridge_parm(d, buf, len, set_startup_query_interval);
629 static DEVICE_ATTR_RW(multicast_startup_query_interval);
631 #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
632 static ssize_t nf_call_iptables_show(
633 struct device *d, struct device_attribute *attr, char *buf)
635 struct net_bridge *br = to_bridge(d);
636 return sprintf(buf, "%u\n", br->nf_call_iptables);
639 static int set_nf_call_iptables(struct net_bridge *br, unsigned long val)
641 br->nf_call_iptables = val ? true : false;
645 static ssize_t nf_call_iptables_store(
646 struct device *d, struct device_attribute *attr, const char *buf,
649 return store_bridge_parm(d, buf, len, set_nf_call_iptables);
651 static DEVICE_ATTR_RW(nf_call_iptables);
653 static ssize_t nf_call_ip6tables_show(
654 struct device *d, struct device_attribute *attr, char *buf)
656 struct net_bridge *br = to_bridge(d);
657 return sprintf(buf, "%u\n", br->nf_call_ip6tables);
660 static int set_nf_call_ip6tables(struct net_bridge *br, unsigned long val)
662 br->nf_call_ip6tables = val ? true : false;
666 static ssize_t nf_call_ip6tables_store(
667 struct device *d, struct device_attribute *attr, const char *buf,
670 return store_bridge_parm(d, buf, len, set_nf_call_ip6tables);
672 static DEVICE_ATTR_RW(nf_call_ip6tables);
674 static ssize_t nf_call_arptables_show(
675 struct device *d, struct device_attribute *attr, char *buf)
677 struct net_bridge *br = to_bridge(d);
678 return sprintf(buf, "%u\n", br->nf_call_arptables);
681 static int set_nf_call_arptables(struct net_bridge *br, unsigned long val)
683 br->nf_call_arptables = val ? true : false;
687 static ssize_t nf_call_arptables_store(
688 struct device *d, struct device_attribute *attr, const char *buf,
691 return store_bridge_parm(d, buf, len, set_nf_call_arptables);
693 static DEVICE_ATTR_RW(nf_call_arptables);
695 #ifdef CONFIG_BRIDGE_VLAN_FILTERING
696 static ssize_t vlan_filtering_show(struct device *d,
697 struct device_attribute *attr,
700 struct net_bridge *br = to_bridge(d);
701 return sprintf(buf, "%d\n", br->vlan_enabled);
704 static ssize_t vlan_filtering_store(struct device *d,
705 struct device_attribute *attr,
706 const char *buf, size_t len)
708 return store_bridge_parm(d, buf, len, br_vlan_filter_toggle);
710 static DEVICE_ATTR_RW(vlan_filtering);
712 static ssize_t vlan_protocol_show(struct device *d,
713 struct device_attribute *attr,
716 struct net_bridge *br = to_bridge(d);
717 return sprintf(buf, "%#06x\n", ntohs(br->vlan_proto));
720 static ssize_t vlan_protocol_store(struct device *d,
721 struct device_attribute *attr,
722 const char *buf, size_t len)
724 return store_bridge_parm(d, buf, len, br_vlan_set_proto);
726 static DEVICE_ATTR_RW(vlan_protocol);
728 static ssize_t default_pvid_show(struct device *d,
729 struct device_attribute *attr,
732 struct net_bridge *br = to_bridge(d);
733 return sprintf(buf, "%d\n", br->default_pvid);
736 static ssize_t default_pvid_store(struct device *d,
737 struct device_attribute *attr,
738 const char *buf, size_t len)
740 return store_bridge_parm(d, buf, len, br_vlan_set_default_pvid);
742 static DEVICE_ATTR_RW(default_pvid);
745 static struct attribute *bridge_attrs[] = {
746 &dev_attr_forward_delay.attr,
747 &dev_attr_hello_time.attr,
748 &dev_attr_max_age.attr,
749 &dev_attr_ageing_time.attr,
750 &dev_attr_stp_state.attr,
751 &dev_attr_group_fwd_mask.attr,
752 &dev_attr_priority.attr,
753 &dev_attr_bridge_id.attr,
754 &dev_attr_root_id.attr,
755 &dev_attr_root_path_cost.attr,
756 &dev_attr_root_port.attr,
757 &dev_attr_topology_change.attr,
758 &dev_attr_topology_change_detected.attr,
759 &dev_attr_hello_timer.attr,
760 &dev_attr_tcn_timer.attr,
761 &dev_attr_topology_change_timer.attr,
762 &dev_attr_gc_timer.attr,
763 &dev_attr_group_addr.attr,
764 &dev_attr_flush.attr,
765 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
766 &dev_attr_multicast_router.attr,
767 &dev_attr_multicast_snooping.attr,
768 &dev_attr_multicast_querier.attr,
769 &dev_attr_multicast_query_use_ifaddr.attr,
770 &dev_attr_hash_elasticity.attr,
771 &dev_attr_hash_max.attr,
772 &dev_attr_multicast_last_member_count.attr,
773 &dev_attr_multicast_startup_query_count.attr,
774 &dev_attr_multicast_last_member_interval.attr,
775 &dev_attr_multicast_membership_interval.attr,
776 &dev_attr_multicast_querier_interval.attr,
777 &dev_attr_multicast_query_interval.attr,
778 &dev_attr_multicast_query_response_interval.attr,
779 &dev_attr_multicast_startup_query_interval.attr,
781 #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
782 &dev_attr_nf_call_iptables.attr,
783 &dev_attr_nf_call_ip6tables.attr,
784 &dev_attr_nf_call_arptables.attr,
786 #ifdef CONFIG_BRIDGE_VLAN_FILTERING
787 &dev_attr_vlan_filtering.attr,
788 &dev_attr_vlan_protocol.attr,
789 &dev_attr_default_pvid.attr,
794 static struct attribute_group bridge_group = {
795 .name = SYSFS_BRIDGE_ATTR,
796 .attrs = bridge_attrs,
800 * Export the forwarding information table as a binary file
801 * The records are struct __fdb_entry.
803 * Returns the number of bytes read.
805 static ssize_t brforward_read(struct file *filp, struct kobject *kobj,
806 struct bin_attribute *bin_attr,
807 char *buf, loff_t off, size_t count)
809 struct device *dev = to_dev(kobj);
810 struct net_bridge *br = to_bridge(dev);
813 /* must read whole records */
814 if (off % sizeof(struct __fdb_entry) != 0)
817 n = br_fdb_fillbuf(br, buf,
818 count / sizeof(struct __fdb_entry),
819 off / sizeof(struct __fdb_entry));
822 n *= sizeof(struct __fdb_entry);
827 static struct bin_attribute bridge_forward = {
828 .attr = { .name = SYSFS_BRIDGE_FDB,
830 .read = brforward_read,
834 * Add entries in sysfs onto the existing network class device
836 * Adds a attribute group "bridge" containing tuning parameters.
837 * Binary attribute containing the forward table
838 * Sub directory to hold links to interfaces.
840 * Note: the ifobj exists only to be a subdirectory
841 * to hold links. The ifobj exists in same data structure
842 * as it's parent the bridge so reference counting works.
844 int br_sysfs_addbr(struct net_device *dev)
846 struct kobject *brobj = &dev->dev.kobj;
847 struct net_bridge *br = netdev_priv(dev);
850 err = sysfs_create_group(brobj, &bridge_group);
852 pr_info("%s: can't create group %s/%s\n",
853 __func__, dev->name, bridge_group.name);
857 err = sysfs_create_bin_file(brobj, &bridge_forward);
859 pr_info("%s: can't create attribute file %s/%s\n",
860 __func__, dev->name, bridge_forward.attr.name);
864 br->ifobj = kobject_create_and_add(SYSFS_BRIDGE_PORT_SUBDIR, brobj);
866 pr_info("%s: can't add kobject (directory) %s/%s\n",
867 __func__, dev->name, SYSFS_BRIDGE_PORT_SUBDIR);
872 sysfs_remove_bin_file(&dev->dev.kobj, &bridge_forward);
874 sysfs_remove_group(&dev->dev.kobj, &bridge_group);
880 void br_sysfs_delbr(struct net_device *dev)
882 struct kobject *kobj = &dev->dev.kobj;
883 struct net_bridge *br = netdev_priv(dev);
885 kobject_put(br->ifobj);
886 sysfs_remove_bin_file(kobj, &bridge_forward);
887 sysfs_remove_group(kobj, &bridge_group);