1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Sysfs attributes of bridge
4 * Linux ethernet bridge
7 * Stephen Hemminger <shemminger@osdl.org>
10 #include <linux/capability.h>
11 #include <linux/kernel.h>
12 #include <linux/netdevice.h>
13 #include <linux/etherdevice.h>
14 #include <linux/if_bridge.h>
15 #include <linux/rtnetlink.h>
16 #include <linux/spinlock.h>
17 #include <linux/times.h>
18 #include <linux/sched/signal.h>
20 #include "br_private.h"
22 /* IMPORTANT: new bridge options must be added with netlink support only
23 * please do not add new sysfs entries
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 *br, unsigned long val,
34 struct netlink_ext_ack *extack))
36 struct net_bridge *br = to_bridge(d);
37 struct netlink_ext_ack extack = {0};
42 if (!ns_capable(dev_net(br->dev)->user_ns, CAP_NET_ADMIN))
45 val = simple_strtoul(buf, &endp, 0);
50 return restart_syscall();
52 err = (*set)(br, val, &extack);
54 netdev_state_change(br->dev);
57 br_err(br, "%s\n", extack._msg);
59 br_warn(br, "%s\n", extack._msg);
63 return err ? err : len;
67 static ssize_t forward_delay_show(struct device *d,
68 struct device_attribute *attr, char *buf)
70 struct net_bridge *br = to_bridge(d);
71 return sprintf(buf, "%lu\n", jiffies_to_clock_t(br->forward_delay));
74 static int set_forward_delay(struct net_bridge *br, unsigned long val,
75 struct netlink_ext_ack *extack)
77 return br_set_forward_delay(br, val);
80 static ssize_t forward_delay_store(struct device *d,
81 struct device_attribute *attr,
82 const char *buf, size_t len)
84 return store_bridge_parm(d, buf, len, set_forward_delay);
86 static DEVICE_ATTR_RW(forward_delay);
88 static ssize_t hello_time_show(struct device *d, struct device_attribute *attr,
91 return sprintf(buf, "%lu\n",
92 jiffies_to_clock_t(to_bridge(d)->hello_time));
95 static int set_hello_time(struct net_bridge *br, unsigned long val,
96 struct netlink_ext_ack *extack)
98 return br_set_hello_time(br, val);
101 static ssize_t hello_time_store(struct device *d,
102 struct device_attribute *attr, const char *buf,
105 return store_bridge_parm(d, buf, len, set_hello_time);
107 static DEVICE_ATTR_RW(hello_time);
109 static ssize_t max_age_show(struct device *d, struct device_attribute *attr,
112 return sprintf(buf, "%lu\n",
113 jiffies_to_clock_t(to_bridge(d)->max_age));
116 static int set_max_age(struct net_bridge *br, unsigned long val,
117 struct netlink_ext_ack *extack)
119 return br_set_max_age(br, val);
122 static ssize_t max_age_store(struct device *d, struct device_attribute *attr,
123 const char *buf, size_t len)
125 return store_bridge_parm(d, buf, len, set_max_age);
127 static DEVICE_ATTR_RW(max_age);
129 static ssize_t ageing_time_show(struct device *d,
130 struct device_attribute *attr, char *buf)
132 struct net_bridge *br = to_bridge(d);
133 return sprintf(buf, "%lu\n", jiffies_to_clock_t(br->ageing_time));
136 static int set_ageing_time(struct net_bridge *br, unsigned long val,
137 struct netlink_ext_ack *extack)
139 return br_set_ageing_time(br, val);
142 static ssize_t ageing_time_store(struct device *d,
143 struct device_attribute *attr,
144 const char *buf, size_t len)
146 return store_bridge_parm(d, buf, len, set_ageing_time);
148 static DEVICE_ATTR_RW(ageing_time);
150 static ssize_t stp_state_show(struct device *d,
151 struct device_attribute *attr, char *buf)
153 struct net_bridge *br = to_bridge(d);
154 return sprintf(buf, "%d\n", br->stp_enabled);
158 static int set_stp_state(struct net_bridge *br, unsigned long val,
159 struct netlink_ext_ack *extack)
161 return br_stp_set_enabled(br, val, extack);
164 static ssize_t stp_state_store(struct device *d,
165 struct device_attribute *attr, const char *buf,
168 return store_bridge_parm(d, buf, len, set_stp_state);
170 static DEVICE_ATTR_RW(stp_state);
172 static ssize_t group_fwd_mask_show(struct device *d,
173 struct device_attribute *attr,
176 struct net_bridge *br = to_bridge(d);
177 return sprintf(buf, "%#x\n", br->group_fwd_mask);
180 static int set_group_fwd_mask(struct net_bridge *br, unsigned long val,
181 struct netlink_ext_ack *extack)
183 if (val & BR_GROUPFWD_RESTRICTED)
186 br->group_fwd_mask = val;
191 static ssize_t group_fwd_mask_store(struct device *d,
192 struct device_attribute *attr,
196 return store_bridge_parm(d, buf, len, set_group_fwd_mask);
198 static DEVICE_ATTR_RW(group_fwd_mask);
200 static ssize_t priority_show(struct device *d, struct device_attribute *attr,
203 struct net_bridge *br = to_bridge(d);
204 return sprintf(buf, "%d\n",
205 (br->bridge_id.prio[0] << 8) | br->bridge_id.prio[1]);
208 static int set_priority(struct net_bridge *br, unsigned long val,
209 struct netlink_ext_ack *extack)
211 br_stp_set_bridge_priority(br, (u16) val);
215 static ssize_t priority_store(struct device *d, struct device_attribute *attr,
216 const char *buf, size_t len)
218 return store_bridge_parm(d, buf, len, set_priority);
220 static DEVICE_ATTR_RW(priority);
222 static ssize_t root_id_show(struct device *d, struct device_attribute *attr,
225 return br_show_bridge_id(buf, &to_bridge(d)->designated_root);
227 static DEVICE_ATTR_RO(root_id);
229 static ssize_t bridge_id_show(struct device *d, struct device_attribute *attr,
232 return br_show_bridge_id(buf, &to_bridge(d)->bridge_id);
234 static DEVICE_ATTR_RO(bridge_id);
236 static ssize_t root_port_show(struct device *d, struct device_attribute *attr,
239 return sprintf(buf, "%d\n", to_bridge(d)->root_port);
241 static DEVICE_ATTR_RO(root_port);
243 static ssize_t root_path_cost_show(struct device *d,
244 struct device_attribute *attr, char *buf)
246 return sprintf(buf, "%d\n", to_bridge(d)->root_path_cost);
248 static DEVICE_ATTR_RO(root_path_cost);
250 static ssize_t topology_change_show(struct device *d,
251 struct device_attribute *attr, char *buf)
253 return sprintf(buf, "%d\n", to_bridge(d)->topology_change);
255 static DEVICE_ATTR_RO(topology_change);
257 static ssize_t topology_change_detected_show(struct device *d,
258 struct device_attribute *attr,
261 struct net_bridge *br = to_bridge(d);
262 return sprintf(buf, "%d\n", br->topology_change_detected);
264 static DEVICE_ATTR_RO(topology_change_detected);
266 static ssize_t hello_timer_show(struct device *d,
267 struct device_attribute *attr, char *buf)
269 struct net_bridge *br = to_bridge(d);
270 return sprintf(buf, "%ld\n", br_timer_value(&br->hello_timer));
272 static DEVICE_ATTR_RO(hello_timer);
274 static ssize_t tcn_timer_show(struct device *d, struct device_attribute *attr,
277 struct net_bridge *br = to_bridge(d);
278 return sprintf(buf, "%ld\n", br_timer_value(&br->tcn_timer));
280 static DEVICE_ATTR_RO(tcn_timer);
282 static ssize_t topology_change_timer_show(struct device *d,
283 struct device_attribute *attr,
286 struct net_bridge *br = to_bridge(d);
287 return sprintf(buf, "%ld\n", br_timer_value(&br->topology_change_timer));
289 static DEVICE_ATTR_RO(topology_change_timer);
291 static ssize_t gc_timer_show(struct device *d, struct device_attribute *attr,
294 struct net_bridge *br = to_bridge(d);
295 return sprintf(buf, "%ld\n", br_timer_value(&br->gc_work.timer));
297 static DEVICE_ATTR_RO(gc_timer);
299 static ssize_t group_addr_show(struct device *d,
300 struct device_attribute *attr, char *buf)
302 struct net_bridge *br = to_bridge(d);
303 return sprintf(buf, "%pM\n", br->group_addr);
306 static ssize_t group_addr_store(struct device *d,
307 struct device_attribute *attr,
308 const char *buf, size_t len)
310 struct net_bridge *br = to_bridge(d);
313 if (!ns_capable(dev_net(br->dev)->user_ns, CAP_NET_ADMIN))
316 if (!mac_pton(buf, new_addr))
319 if (!is_link_local_ether_addr(new_addr))
322 if (new_addr[5] == 1 || /* 802.3x Pause address */
323 new_addr[5] == 2 || /* 802.3ad Slow protocols */
324 new_addr[5] == 3) /* 802.1X PAE address */
328 return restart_syscall();
330 spin_lock_bh(&br->lock);
331 ether_addr_copy(br->group_addr, new_addr);
332 spin_unlock_bh(&br->lock);
334 br_opt_toggle(br, BROPT_GROUP_ADDR_SET, true);
335 br_recalculate_fwd_mask(br);
336 netdev_state_change(br->dev);
343 static DEVICE_ATTR_RW(group_addr);
345 static int set_flush(struct net_bridge *br, unsigned long val,
346 struct netlink_ext_ack *extack)
352 static ssize_t flush_store(struct device *d,
353 struct device_attribute *attr,
354 const char *buf, size_t len)
356 return store_bridge_parm(d, buf, len, set_flush);
358 static DEVICE_ATTR_WO(flush);
360 static ssize_t no_linklocal_learn_show(struct device *d,
361 struct device_attribute *attr,
364 struct net_bridge *br = to_bridge(d);
365 return sprintf(buf, "%d\n", br_boolopt_get(br, BR_BOOLOPT_NO_LL_LEARN));
368 static int set_no_linklocal_learn(struct net_bridge *br, unsigned long val,
369 struct netlink_ext_ack *extack)
371 return br_boolopt_toggle(br, BR_BOOLOPT_NO_LL_LEARN, !!val, extack);
374 static ssize_t no_linklocal_learn_store(struct device *d,
375 struct device_attribute *attr,
376 const char *buf, size_t len)
378 return store_bridge_parm(d, buf, len, set_no_linklocal_learn);
380 static DEVICE_ATTR_RW(no_linklocal_learn);
382 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
383 static ssize_t multicast_router_show(struct device *d,
384 struct device_attribute *attr, char *buf)
386 struct net_bridge *br = to_bridge(d);
387 return sprintf(buf, "%d\n", br->multicast_ctx.multicast_router);
390 static int set_multicast_router(struct net_bridge *br, unsigned long val,
391 struct netlink_ext_ack *extack)
393 return br_multicast_set_router(&br->multicast_ctx, val);
396 static ssize_t multicast_router_store(struct device *d,
397 struct device_attribute *attr,
398 const char *buf, size_t len)
400 return store_bridge_parm(d, buf, len, set_multicast_router);
402 static DEVICE_ATTR_RW(multicast_router);
404 static ssize_t multicast_snooping_show(struct device *d,
405 struct device_attribute *attr,
408 struct net_bridge *br = to_bridge(d);
409 return sprintf(buf, "%d\n", br_opt_get(br, BROPT_MULTICAST_ENABLED));
412 static ssize_t multicast_snooping_store(struct device *d,
413 struct device_attribute *attr,
414 const char *buf, size_t len)
416 return store_bridge_parm(d, buf, len, br_multicast_toggle);
418 static DEVICE_ATTR_RW(multicast_snooping);
420 static ssize_t multicast_query_use_ifaddr_show(struct device *d,
421 struct device_attribute *attr,
424 struct net_bridge *br = to_bridge(d);
425 return sprintf(buf, "%d\n",
426 br_opt_get(br, BROPT_MULTICAST_QUERY_USE_IFADDR));
429 static int set_query_use_ifaddr(struct net_bridge *br, unsigned long val,
430 struct netlink_ext_ack *extack)
432 br_opt_toggle(br, BROPT_MULTICAST_QUERY_USE_IFADDR, !!val);
437 multicast_query_use_ifaddr_store(struct device *d,
438 struct device_attribute *attr,
439 const char *buf, size_t len)
441 return store_bridge_parm(d, buf, len, set_query_use_ifaddr);
443 static DEVICE_ATTR_RW(multicast_query_use_ifaddr);
445 static ssize_t multicast_querier_show(struct device *d,
446 struct device_attribute *attr,
449 struct net_bridge *br = to_bridge(d);
450 return sprintf(buf, "%d\n", br->multicast_ctx.multicast_querier);
453 static int set_multicast_querier(struct net_bridge *br, unsigned long val,
454 struct netlink_ext_ack *extack)
456 return br_multicast_set_querier(&br->multicast_ctx, val);
459 static ssize_t multicast_querier_store(struct device *d,
460 struct device_attribute *attr,
461 const char *buf, size_t len)
463 return store_bridge_parm(d, buf, len, set_multicast_querier);
465 static DEVICE_ATTR_RW(multicast_querier);
467 static ssize_t hash_elasticity_show(struct device *d,
468 struct device_attribute *attr, char *buf)
470 return sprintf(buf, "%u\n", RHT_ELASTICITY);
473 static int set_elasticity(struct net_bridge *br, unsigned long val,
474 struct netlink_ext_ack *extack)
476 /* 16 is RHT_ELASTICITY */
477 NL_SET_ERR_MSG_MOD(extack,
478 "the hash_elasticity option has been deprecated and is always 16");
482 static ssize_t hash_elasticity_store(struct device *d,
483 struct device_attribute *attr,
484 const char *buf, size_t len)
486 return store_bridge_parm(d, buf, len, set_elasticity);
488 static DEVICE_ATTR_RW(hash_elasticity);
490 static ssize_t hash_max_show(struct device *d, struct device_attribute *attr,
493 struct net_bridge *br = to_bridge(d);
494 return sprintf(buf, "%u\n", br->hash_max);
497 static int set_hash_max(struct net_bridge *br, unsigned long val,
498 struct netlink_ext_ack *extack)
504 static ssize_t hash_max_store(struct device *d, struct device_attribute *attr,
505 const char *buf, size_t len)
507 return store_bridge_parm(d, buf, len, set_hash_max);
509 static DEVICE_ATTR_RW(hash_max);
511 static ssize_t multicast_igmp_version_show(struct device *d,
512 struct device_attribute *attr,
515 struct net_bridge *br = to_bridge(d);
517 return sprintf(buf, "%u\n", br->multicast_ctx.multicast_igmp_version);
520 static int set_multicast_igmp_version(struct net_bridge *br, unsigned long val,
521 struct netlink_ext_ack *extack)
523 return br_multicast_set_igmp_version(&br->multicast_ctx, val);
526 static ssize_t multicast_igmp_version_store(struct device *d,
527 struct device_attribute *attr,
528 const char *buf, size_t len)
530 return store_bridge_parm(d, buf, len, set_multicast_igmp_version);
532 static DEVICE_ATTR_RW(multicast_igmp_version);
534 static ssize_t multicast_last_member_count_show(struct device *d,
535 struct device_attribute *attr,
538 struct net_bridge *br = to_bridge(d);
539 return sprintf(buf, "%u\n", br->multicast_ctx.multicast_last_member_count);
542 static int set_last_member_count(struct net_bridge *br, unsigned long val,
543 struct netlink_ext_ack *extack)
545 br->multicast_ctx.multicast_last_member_count = val;
549 static ssize_t multicast_last_member_count_store(struct device *d,
550 struct device_attribute *attr,
551 const char *buf, size_t len)
553 return store_bridge_parm(d, buf, len, set_last_member_count);
555 static DEVICE_ATTR_RW(multicast_last_member_count);
557 static ssize_t multicast_startup_query_count_show(
558 struct device *d, struct device_attribute *attr, char *buf)
560 struct net_bridge *br = to_bridge(d);
561 return sprintf(buf, "%u\n", br->multicast_ctx.multicast_startup_query_count);
564 static int set_startup_query_count(struct net_bridge *br, unsigned long val,
565 struct netlink_ext_ack *extack)
567 br->multicast_ctx.multicast_startup_query_count = val;
571 static ssize_t multicast_startup_query_count_store(
572 struct device *d, struct device_attribute *attr, const char *buf,
575 return store_bridge_parm(d, buf, len, set_startup_query_count);
577 static DEVICE_ATTR_RW(multicast_startup_query_count);
579 static ssize_t multicast_last_member_interval_show(
580 struct device *d, struct device_attribute *attr, char *buf)
582 struct net_bridge *br = to_bridge(d);
583 return sprintf(buf, "%lu\n",
584 jiffies_to_clock_t(br->multicast_ctx.multicast_last_member_interval));
587 static int set_last_member_interval(struct net_bridge *br, unsigned long val,
588 struct netlink_ext_ack *extack)
590 br->multicast_ctx.multicast_last_member_interval = clock_t_to_jiffies(val);
594 static ssize_t multicast_last_member_interval_store(
595 struct device *d, struct device_attribute *attr, const char *buf,
598 return store_bridge_parm(d, buf, len, set_last_member_interval);
600 static DEVICE_ATTR_RW(multicast_last_member_interval);
602 static ssize_t multicast_membership_interval_show(
603 struct device *d, struct device_attribute *attr, char *buf)
605 struct net_bridge *br = to_bridge(d);
606 return sprintf(buf, "%lu\n",
607 jiffies_to_clock_t(br->multicast_ctx.multicast_membership_interval));
610 static int set_membership_interval(struct net_bridge *br, unsigned long val,
611 struct netlink_ext_ack *extack)
613 br->multicast_ctx.multicast_membership_interval = clock_t_to_jiffies(val);
617 static ssize_t multicast_membership_interval_store(
618 struct device *d, struct device_attribute *attr, const char *buf,
621 return store_bridge_parm(d, buf, len, set_membership_interval);
623 static DEVICE_ATTR_RW(multicast_membership_interval);
625 static ssize_t multicast_querier_interval_show(struct device *d,
626 struct device_attribute *attr,
629 struct net_bridge *br = to_bridge(d);
630 return sprintf(buf, "%lu\n",
631 jiffies_to_clock_t(br->multicast_ctx.multicast_querier_interval));
634 static int set_querier_interval(struct net_bridge *br, unsigned long val,
635 struct netlink_ext_ack *extack)
637 br->multicast_ctx.multicast_querier_interval = clock_t_to_jiffies(val);
641 static ssize_t multicast_querier_interval_store(struct device *d,
642 struct device_attribute *attr,
643 const char *buf, size_t len)
645 return store_bridge_parm(d, buf, len, set_querier_interval);
647 static DEVICE_ATTR_RW(multicast_querier_interval);
649 static ssize_t multicast_query_interval_show(struct device *d,
650 struct device_attribute *attr,
653 struct net_bridge *br = to_bridge(d);
654 return sprintf(buf, "%lu\n",
655 jiffies_to_clock_t(br->multicast_ctx.multicast_query_interval));
658 static int set_query_interval(struct net_bridge *br, unsigned long val,
659 struct netlink_ext_ack *extack)
661 br->multicast_ctx.multicast_query_interval = clock_t_to_jiffies(val);
665 static ssize_t multicast_query_interval_store(struct device *d,
666 struct device_attribute *attr,
667 const char *buf, size_t len)
669 return store_bridge_parm(d, buf, len, set_query_interval);
671 static DEVICE_ATTR_RW(multicast_query_interval);
673 static ssize_t multicast_query_response_interval_show(
674 struct device *d, struct device_attribute *attr, char *buf)
676 struct net_bridge *br = to_bridge(d);
679 jiffies_to_clock_t(br->multicast_ctx.multicast_query_response_interval));
682 static int set_query_response_interval(struct net_bridge *br, unsigned long val,
683 struct netlink_ext_ack *extack)
685 br->multicast_ctx.multicast_query_response_interval = clock_t_to_jiffies(val);
689 static ssize_t multicast_query_response_interval_store(
690 struct device *d, struct device_attribute *attr, const char *buf,
693 return store_bridge_parm(d, buf, len, set_query_response_interval);
695 static DEVICE_ATTR_RW(multicast_query_response_interval);
697 static ssize_t multicast_startup_query_interval_show(
698 struct device *d, struct device_attribute *attr, char *buf)
700 struct net_bridge *br = to_bridge(d);
703 jiffies_to_clock_t(br->multicast_ctx.multicast_startup_query_interval));
706 static int set_startup_query_interval(struct net_bridge *br, unsigned long val,
707 struct netlink_ext_ack *extack)
709 br->multicast_ctx.multicast_startup_query_interval = clock_t_to_jiffies(val);
713 static ssize_t multicast_startup_query_interval_store(
714 struct device *d, struct device_attribute *attr, const char *buf,
717 return store_bridge_parm(d, buf, len, set_startup_query_interval);
719 static DEVICE_ATTR_RW(multicast_startup_query_interval);
721 static ssize_t multicast_stats_enabled_show(struct device *d,
722 struct device_attribute *attr,
725 struct net_bridge *br = to_bridge(d);
727 return sprintf(buf, "%d\n",
728 br_opt_get(br, BROPT_MULTICAST_STATS_ENABLED));
731 static int set_stats_enabled(struct net_bridge *br, unsigned long val,
732 struct netlink_ext_ack *extack)
734 br_opt_toggle(br, BROPT_MULTICAST_STATS_ENABLED, !!val);
738 static ssize_t multicast_stats_enabled_store(struct device *d,
739 struct device_attribute *attr,
743 return store_bridge_parm(d, buf, len, set_stats_enabled);
745 static DEVICE_ATTR_RW(multicast_stats_enabled);
747 #if IS_ENABLED(CONFIG_IPV6)
748 static ssize_t multicast_mld_version_show(struct device *d,
749 struct device_attribute *attr,
752 struct net_bridge *br = to_bridge(d);
754 return sprintf(buf, "%u\n", br->multicast_ctx.multicast_mld_version);
757 static int set_multicast_mld_version(struct net_bridge *br, unsigned long val,
758 struct netlink_ext_ack *extack)
760 return br_multicast_set_mld_version(&br->multicast_ctx, val);
763 static ssize_t multicast_mld_version_store(struct device *d,
764 struct device_attribute *attr,
765 const char *buf, size_t len)
767 return store_bridge_parm(d, buf, len, set_multicast_mld_version);
769 static DEVICE_ATTR_RW(multicast_mld_version);
772 #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
773 static ssize_t nf_call_iptables_show(
774 struct device *d, struct device_attribute *attr, char *buf)
776 struct net_bridge *br = to_bridge(d);
777 return sprintf(buf, "%u\n", br_opt_get(br, BROPT_NF_CALL_IPTABLES));
780 static int set_nf_call_iptables(struct net_bridge *br, unsigned long val,
781 struct netlink_ext_ack *extack)
783 br_opt_toggle(br, BROPT_NF_CALL_IPTABLES, !!val);
787 static ssize_t nf_call_iptables_store(
788 struct device *d, struct device_attribute *attr, const char *buf,
791 return store_bridge_parm(d, buf, len, set_nf_call_iptables);
793 static DEVICE_ATTR_RW(nf_call_iptables);
795 static ssize_t nf_call_ip6tables_show(
796 struct device *d, struct device_attribute *attr, char *buf)
798 struct net_bridge *br = to_bridge(d);
799 return sprintf(buf, "%u\n", br_opt_get(br, BROPT_NF_CALL_IP6TABLES));
802 static int set_nf_call_ip6tables(struct net_bridge *br, unsigned long val,
803 struct netlink_ext_ack *extack)
805 br_opt_toggle(br, BROPT_NF_CALL_IP6TABLES, !!val);
809 static ssize_t nf_call_ip6tables_store(
810 struct device *d, struct device_attribute *attr, const char *buf,
813 return store_bridge_parm(d, buf, len, set_nf_call_ip6tables);
815 static DEVICE_ATTR_RW(nf_call_ip6tables);
817 static ssize_t nf_call_arptables_show(
818 struct device *d, struct device_attribute *attr, char *buf)
820 struct net_bridge *br = to_bridge(d);
821 return sprintf(buf, "%u\n", br_opt_get(br, BROPT_NF_CALL_ARPTABLES));
824 static int set_nf_call_arptables(struct net_bridge *br, unsigned long val,
825 struct netlink_ext_ack *extack)
827 br_opt_toggle(br, BROPT_NF_CALL_ARPTABLES, !!val);
831 static ssize_t nf_call_arptables_store(
832 struct device *d, struct device_attribute *attr, const char *buf,
835 return store_bridge_parm(d, buf, len, set_nf_call_arptables);
837 static DEVICE_ATTR_RW(nf_call_arptables);
839 #ifdef CONFIG_BRIDGE_VLAN_FILTERING
840 static ssize_t vlan_filtering_show(struct device *d,
841 struct device_attribute *attr,
844 struct net_bridge *br = to_bridge(d);
845 return sprintf(buf, "%d\n", br_opt_get(br, BROPT_VLAN_ENABLED));
848 static ssize_t vlan_filtering_store(struct device *d,
849 struct device_attribute *attr,
850 const char *buf, size_t len)
852 return store_bridge_parm(d, buf, len, br_vlan_filter_toggle);
854 static DEVICE_ATTR_RW(vlan_filtering);
856 static ssize_t vlan_protocol_show(struct device *d,
857 struct device_attribute *attr,
860 struct net_bridge *br = to_bridge(d);
861 return sprintf(buf, "%#06x\n", ntohs(br->vlan_proto));
864 static ssize_t vlan_protocol_store(struct device *d,
865 struct device_attribute *attr,
866 const char *buf, size_t len)
868 return store_bridge_parm(d, buf, len, br_vlan_set_proto);
870 static DEVICE_ATTR_RW(vlan_protocol);
872 static ssize_t default_pvid_show(struct device *d,
873 struct device_attribute *attr,
876 struct net_bridge *br = to_bridge(d);
877 return sprintf(buf, "%d\n", br->default_pvid);
880 static ssize_t default_pvid_store(struct device *d,
881 struct device_attribute *attr,
882 const char *buf, size_t len)
884 return store_bridge_parm(d, buf, len, br_vlan_set_default_pvid);
886 static DEVICE_ATTR_RW(default_pvid);
888 static ssize_t vlan_stats_enabled_show(struct device *d,
889 struct device_attribute *attr,
892 struct net_bridge *br = to_bridge(d);
893 return sprintf(buf, "%u\n", br_opt_get(br, BROPT_VLAN_STATS_ENABLED));
896 static int set_vlan_stats_enabled(struct net_bridge *br, unsigned long val,
897 struct netlink_ext_ack *extack)
899 return br_vlan_set_stats(br, val);
902 static ssize_t vlan_stats_enabled_store(struct device *d,
903 struct device_attribute *attr,
904 const char *buf, size_t len)
906 return store_bridge_parm(d, buf, len, set_vlan_stats_enabled);
908 static DEVICE_ATTR_RW(vlan_stats_enabled);
910 static ssize_t vlan_stats_per_port_show(struct device *d,
911 struct device_attribute *attr,
914 struct net_bridge *br = to_bridge(d);
915 return sprintf(buf, "%u\n", br_opt_get(br, BROPT_VLAN_STATS_PER_PORT));
918 static int set_vlan_stats_per_port(struct net_bridge *br, unsigned long val,
919 struct netlink_ext_ack *extack)
921 return br_vlan_set_stats_per_port(br, val);
924 static ssize_t vlan_stats_per_port_store(struct device *d,
925 struct device_attribute *attr,
926 const char *buf, size_t len)
928 return store_bridge_parm(d, buf, len, set_vlan_stats_per_port);
930 static DEVICE_ATTR_RW(vlan_stats_per_port);
933 static struct attribute *bridge_attrs[] = {
934 &dev_attr_forward_delay.attr,
935 &dev_attr_hello_time.attr,
936 &dev_attr_max_age.attr,
937 &dev_attr_ageing_time.attr,
938 &dev_attr_stp_state.attr,
939 &dev_attr_group_fwd_mask.attr,
940 &dev_attr_priority.attr,
941 &dev_attr_bridge_id.attr,
942 &dev_attr_root_id.attr,
943 &dev_attr_root_path_cost.attr,
944 &dev_attr_root_port.attr,
945 &dev_attr_topology_change.attr,
946 &dev_attr_topology_change_detected.attr,
947 &dev_attr_hello_timer.attr,
948 &dev_attr_tcn_timer.attr,
949 &dev_attr_topology_change_timer.attr,
950 &dev_attr_gc_timer.attr,
951 &dev_attr_group_addr.attr,
952 &dev_attr_flush.attr,
953 &dev_attr_no_linklocal_learn.attr,
954 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
955 &dev_attr_multicast_router.attr,
956 &dev_attr_multicast_snooping.attr,
957 &dev_attr_multicast_querier.attr,
958 &dev_attr_multicast_query_use_ifaddr.attr,
959 &dev_attr_hash_elasticity.attr,
960 &dev_attr_hash_max.attr,
961 &dev_attr_multicast_last_member_count.attr,
962 &dev_attr_multicast_startup_query_count.attr,
963 &dev_attr_multicast_last_member_interval.attr,
964 &dev_attr_multicast_membership_interval.attr,
965 &dev_attr_multicast_querier_interval.attr,
966 &dev_attr_multicast_query_interval.attr,
967 &dev_attr_multicast_query_response_interval.attr,
968 &dev_attr_multicast_startup_query_interval.attr,
969 &dev_attr_multicast_stats_enabled.attr,
970 &dev_attr_multicast_igmp_version.attr,
971 #if IS_ENABLED(CONFIG_IPV6)
972 &dev_attr_multicast_mld_version.attr,
975 #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
976 &dev_attr_nf_call_iptables.attr,
977 &dev_attr_nf_call_ip6tables.attr,
978 &dev_attr_nf_call_arptables.attr,
980 #ifdef CONFIG_BRIDGE_VLAN_FILTERING
981 &dev_attr_vlan_filtering.attr,
982 &dev_attr_vlan_protocol.attr,
983 &dev_attr_default_pvid.attr,
984 &dev_attr_vlan_stats_enabled.attr,
985 &dev_attr_vlan_stats_per_port.attr,
990 static const struct attribute_group bridge_group = {
991 .name = SYSFS_BRIDGE_ATTR,
992 .attrs = bridge_attrs,
996 * Export the forwarding information table as a binary file
997 * The records are struct __fdb_entry.
999 * Returns the number of bytes read.
1001 static ssize_t brforward_read(struct file *filp, struct kobject *kobj,
1002 struct bin_attribute *bin_attr,
1003 char *buf, loff_t off, size_t count)
1005 struct device *dev = kobj_to_dev(kobj);
1006 struct net_bridge *br = to_bridge(dev);
1009 /* must read whole records */
1010 if (off % sizeof(struct __fdb_entry) != 0)
1013 n = br_fdb_fillbuf(br, buf,
1014 count / sizeof(struct __fdb_entry),
1015 off / sizeof(struct __fdb_entry));
1018 n *= sizeof(struct __fdb_entry);
1023 static struct bin_attribute bridge_forward = {
1024 .attr = { .name = SYSFS_BRIDGE_FDB,
1026 .read = brforward_read,
1030 * Add entries in sysfs onto the existing network class device
1032 * Adds a attribute group "bridge" containing tuning parameters.
1033 * Binary attribute containing the forward table
1034 * Sub directory to hold links to interfaces.
1036 * Note: the ifobj exists only to be a subdirectory
1037 * to hold links. The ifobj exists in same data structure
1038 * as it's parent the bridge so reference counting works.
1040 int br_sysfs_addbr(struct net_device *dev)
1042 struct kobject *brobj = &dev->dev.kobj;
1043 struct net_bridge *br = netdev_priv(dev);
1046 err = sysfs_create_group(brobj, &bridge_group);
1048 pr_info("%s: can't create group %s/%s\n",
1049 __func__, dev->name, bridge_group.name);
1053 err = sysfs_create_bin_file(brobj, &bridge_forward);
1055 pr_info("%s: can't create attribute file %s/%s\n",
1056 __func__, dev->name, bridge_forward.attr.name);
1060 br->ifobj = kobject_create_and_add(SYSFS_BRIDGE_PORT_SUBDIR, brobj);
1062 pr_info("%s: can't add kobject (directory) %s/%s\n",
1063 __func__, dev->name, SYSFS_BRIDGE_PORT_SUBDIR);
1069 sysfs_remove_bin_file(&dev->dev.kobj, &bridge_forward);
1071 sysfs_remove_group(&dev->dev.kobj, &bridge_group);
1077 void br_sysfs_delbr(struct net_device *dev)
1079 struct kobject *kobj = &dev->dev.kobj;
1080 struct net_bridge *br = netdev_priv(dev);
1082 kobject_put(br->ifobj);
1083 sysfs_remove_bin_file(kobj, &bridge_forward);
1084 sysfs_remove_group(kobj, &bridge_group);