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 #define to_bridge(cd) ((struct net_bridge *)netdev_priv(to_net_dev(cd)))
25 * Common code for storing bridge parameters.
27 static ssize_t
store_bridge_parm(struct device
*d
,
28 const char *buf
, size_t len
,
29 int (*set
)(struct net_bridge
*, unsigned long))
31 struct net_bridge
*br
= to_bridge(d
);
36 if (!ns_capable(dev_net(br
->dev
)->user_ns
, CAP_NET_ADMIN
))
39 val
= simple_strtoul(buf
, &endp
, 0);
44 return restart_syscall();
46 err
= (*set
)(br
, val
);
48 netdev_state_change(br
->dev
);
51 return err
? err
: len
;
55 static ssize_t
forward_delay_show(struct device
*d
,
56 struct device_attribute
*attr
, char *buf
)
58 struct net_bridge
*br
= to_bridge(d
);
59 return sprintf(buf
, "%lu\n", jiffies_to_clock_t(br
->forward_delay
));
62 static ssize_t
forward_delay_store(struct device
*d
,
63 struct device_attribute
*attr
,
64 const char *buf
, size_t len
)
66 return store_bridge_parm(d
, buf
, len
, br_set_forward_delay
);
68 static DEVICE_ATTR_RW(forward_delay
);
70 static ssize_t
hello_time_show(struct device
*d
, struct device_attribute
*attr
,
73 return sprintf(buf
, "%lu\n",
74 jiffies_to_clock_t(to_bridge(d
)->hello_time
));
77 static ssize_t
hello_time_store(struct device
*d
,
78 struct device_attribute
*attr
, const char *buf
,
81 return store_bridge_parm(d
, buf
, len
, br_set_hello_time
);
83 static DEVICE_ATTR_RW(hello_time
);
85 static ssize_t
max_age_show(struct device
*d
, struct device_attribute
*attr
,
88 return sprintf(buf
, "%lu\n",
89 jiffies_to_clock_t(to_bridge(d
)->max_age
));
92 static ssize_t
max_age_store(struct device
*d
, struct device_attribute
*attr
,
93 const char *buf
, size_t len
)
95 return store_bridge_parm(d
, buf
, len
, br_set_max_age
);
97 static DEVICE_ATTR_RW(max_age
);
99 static ssize_t
ageing_time_show(struct device
*d
,
100 struct device_attribute
*attr
, char *buf
)
102 struct net_bridge
*br
= to_bridge(d
);
103 return sprintf(buf
, "%lu\n", jiffies_to_clock_t(br
->ageing_time
));
106 static int set_ageing_time(struct net_bridge
*br
, unsigned long val
)
108 return br_set_ageing_time(br
, val
);
111 static ssize_t
ageing_time_store(struct device
*d
,
112 struct device_attribute
*attr
,
113 const char *buf
, size_t len
)
115 return store_bridge_parm(d
, buf
, len
, set_ageing_time
);
117 static DEVICE_ATTR_RW(ageing_time
);
119 static ssize_t
stp_state_show(struct device
*d
,
120 struct device_attribute
*attr
, char *buf
)
122 struct net_bridge
*br
= to_bridge(d
);
123 return sprintf(buf
, "%d\n", br
->stp_enabled
);
127 static int set_stp_state(struct net_bridge
*br
, unsigned long val
)
129 br_stp_set_enabled(br
, val
);
134 static ssize_t
stp_state_store(struct device
*d
,
135 struct device_attribute
*attr
, const char *buf
,
138 return store_bridge_parm(d
, buf
, len
, set_stp_state
);
140 static DEVICE_ATTR_RW(stp_state
);
142 static ssize_t
group_fwd_mask_show(struct device
*d
,
143 struct device_attribute
*attr
,
146 struct net_bridge
*br
= to_bridge(d
);
147 return sprintf(buf
, "%#x\n", br
->group_fwd_mask
);
150 static int set_group_fwd_mask(struct net_bridge
*br
, unsigned long val
)
152 if (val
& BR_GROUPFWD_RESTRICTED
)
155 br
->group_fwd_mask
= val
;
160 static ssize_t
group_fwd_mask_store(struct device
*d
,
161 struct device_attribute
*attr
,
165 return store_bridge_parm(d
, buf
, len
, set_group_fwd_mask
);
167 static DEVICE_ATTR_RW(group_fwd_mask
);
169 static ssize_t
priority_show(struct device
*d
, struct device_attribute
*attr
,
172 struct net_bridge
*br
= to_bridge(d
);
173 return sprintf(buf
, "%d\n",
174 (br
->bridge_id
.prio
[0] << 8) | br
->bridge_id
.prio
[1]);
177 static int set_priority(struct net_bridge
*br
, unsigned long val
)
179 br_stp_set_bridge_priority(br
, (u16
) val
);
183 static ssize_t
priority_store(struct device
*d
, struct device_attribute
*attr
,
184 const char *buf
, size_t len
)
186 return store_bridge_parm(d
, buf
, len
, set_priority
);
188 static DEVICE_ATTR_RW(priority
);
190 static ssize_t
root_id_show(struct device
*d
, struct device_attribute
*attr
,
193 return br_show_bridge_id(buf
, &to_bridge(d
)->designated_root
);
195 static DEVICE_ATTR_RO(root_id
);
197 static ssize_t
bridge_id_show(struct device
*d
, struct device_attribute
*attr
,
200 return br_show_bridge_id(buf
, &to_bridge(d
)->bridge_id
);
202 static DEVICE_ATTR_RO(bridge_id
);
204 static ssize_t
root_port_show(struct device
*d
, struct device_attribute
*attr
,
207 return sprintf(buf
, "%d\n", to_bridge(d
)->root_port
);
209 static DEVICE_ATTR_RO(root_port
);
211 static ssize_t
root_path_cost_show(struct device
*d
,
212 struct device_attribute
*attr
, char *buf
)
214 return sprintf(buf
, "%d\n", to_bridge(d
)->root_path_cost
);
216 static DEVICE_ATTR_RO(root_path_cost
);
218 static ssize_t
topology_change_show(struct device
*d
,
219 struct device_attribute
*attr
, char *buf
)
221 return sprintf(buf
, "%d\n", to_bridge(d
)->topology_change
);
223 static DEVICE_ATTR_RO(topology_change
);
225 static ssize_t
topology_change_detected_show(struct device
*d
,
226 struct device_attribute
*attr
,
229 struct net_bridge
*br
= to_bridge(d
);
230 return sprintf(buf
, "%d\n", br
->topology_change_detected
);
232 static DEVICE_ATTR_RO(topology_change_detected
);
234 static ssize_t
hello_timer_show(struct device
*d
,
235 struct device_attribute
*attr
, char *buf
)
237 struct net_bridge
*br
= to_bridge(d
);
238 return sprintf(buf
, "%ld\n", br_timer_value(&br
->hello_timer
));
240 static DEVICE_ATTR_RO(hello_timer
);
242 static ssize_t
tcn_timer_show(struct device
*d
, struct device_attribute
*attr
,
245 struct net_bridge
*br
= to_bridge(d
);
246 return sprintf(buf
, "%ld\n", br_timer_value(&br
->tcn_timer
));
248 static DEVICE_ATTR_RO(tcn_timer
);
250 static ssize_t
topology_change_timer_show(struct device
*d
,
251 struct device_attribute
*attr
,
254 struct net_bridge
*br
= to_bridge(d
);
255 return sprintf(buf
, "%ld\n", br_timer_value(&br
->topology_change_timer
));
257 static DEVICE_ATTR_RO(topology_change_timer
);
259 static ssize_t
gc_timer_show(struct device
*d
, struct device_attribute
*attr
,
262 struct net_bridge
*br
= to_bridge(d
);
263 return sprintf(buf
, "%ld\n", br_timer_value(&br
->gc_work
.timer
));
265 static DEVICE_ATTR_RO(gc_timer
);
267 static ssize_t
group_addr_show(struct device
*d
,
268 struct device_attribute
*attr
, char *buf
)
270 struct net_bridge
*br
= to_bridge(d
);
271 return sprintf(buf
, "%pM\n", br
->group_addr
);
274 static ssize_t
group_addr_store(struct device
*d
,
275 struct device_attribute
*attr
,
276 const char *buf
, size_t len
)
278 struct net_bridge
*br
= to_bridge(d
);
281 if (!ns_capable(dev_net(br
->dev
)->user_ns
, CAP_NET_ADMIN
))
284 if (!mac_pton(buf
, new_addr
))
287 if (!is_link_local_ether_addr(new_addr
))
290 if (new_addr
[5] == 1 || /* 802.3x Pause address */
291 new_addr
[5] == 2 || /* 802.3ad Slow protocols */
292 new_addr
[5] == 3) /* 802.1X PAE address */
296 return restart_syscall();
298 spin_lock_bh(&br
->lock
);
299 ether_addr_copy(br
->group_addr
, new_addr
);
300 spin_unlock_bh(&br
->lock
);
302 br_opt_toggle(br
, BROPT_GROUP_ADDR_SET
, true);
303 br_recalculate_fwd_mask(br
);
304 netdev_state_change(br
->dev
);
311 static DEVICE_ATTR_RW(group_addr
);
313 static int set_flush(struct net_bridge
*br
, unsigned long val
)
319 static ssize_t
flush_store(struct device
*d
,
320 struct device_attribute
*attr
,
321 const char *buf
, size_t len
)
323 return store_bridge_parm(d
, buf
, len
, set_flush
);
325 static DEVICE_ATTR_WO(flush
);
327 static ssize_t
no_linklocal_learn_show(struct device
*d
,
328 struct device_attribute
*attr
,
331 struct net_bridge
*br
= to_bridge(d
);
332 return sprintf(buf
, "%d\n", br_boolopt_get(br
, BR_BOOLOPT_NO_LL_LEARN
));
335 static int set_no_linklocal_learn(struct net_bridge
*br
, unsigned long val
)
337 return br_boolopt_toggle(br
, BR_BOOLOPT_NO_LL_LEARN
, !!val
, NULL
);
340 static ssize_t
no_linklocal_learn_store(struct device
*d
,
341 struct device_attribute
*attr
,
342 const char *buf
, size_t len
)
344 return store_bridge_parm(d
, buf
, len
, set_no_linklocal_learn
);
346 static DEVICE_ATTR_RW(no_linklocal_learn
);
348 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
349 static ssize_t
multicast_router_show(struct device
*d
,
350 struct device_attribute
*attr
, char *buf
)
352 struct net_bridge
*br
= to_bridge(d
);
353 return sprintf(buf
, "%d\n", br
->multicast_router
);
356 static ssize_t
multicast_router_store(struct device
*d
,
357 struct device_attribute
*attr
,
358 const char *buf
, size_t len
)
360 return store_bridge_parm(d
, buf
, len
, br_multicast_set_router
);
362 static DEVICE_ATTR_RW(multicast_router
);
364 static ssize_t
multicast_snooping_show(struct device
*d
,
365 struct device_attribute
*attr
,
368 struct net_bridge
*br
= to_bridge(d
);
369 return sprintf(buf
, "%d\n", br_opt_get(br
, BROPT_MULTICAST_ENABLED
));
372 static ssize_t
multicast_snooping_store(struct device
*d
,
373 struct device_attribute
*attr
,
374 const char *buf
, size_t len
)
376 return store_bridge_parm(d
, buf
, len
, br_multicast_toggle
);
378 static DEVICE_ATTR_RW(multicast_snooping
);
380 static ssize_t
multicast_query_use_ifaddr_show(struct device
*d
,
381 struct device_attribute
*attr
,
384 struct net_bridge
*br
= to_bridge(d
);
385 return sprintf(buf
, "%d\n",
386 br_opt_get(br
, BROPT_MULTICAST_QUERY_USE_IFADDR
));
389 static int set_query_use_ifaddr(struct net_bridge
*br
, unsigned long val
)
391 br_opt_toggle(br
, BROPT_MULTICAST_QUERY_USE_IFADDR
, !!val
);
396 multicast_query_use_ifaddr_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_query_use_ifaddr
);
402 static DEVICE_ATTR_RW(multicast_query_use_ifaddr
);
404 static ssize_t
multicast_querier_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_QUERIER
));
412 static ssize_t
multicast_querier_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_set_querier
);
418 static DEVICE_ATTR_RW(multicast_querier
);
420 static ssize_t
hash_elasticity_show(struct device
*d
,
421 struct device_attribute
*attr
, char *buf
)
423 return sprintf(buf
, "%u\n", RHT_ELASTICITY
);
426 static int set_elasticity(struct net_bridge
*br
, unsigned long val
)
428 br_warn(br
, "the hash_elasticity option has been deprecated and is always %u\n",
433 static ssize_t
hash_elasticity_store(struct device
*d
,
434 struct device_attribute
*attr
,
435 const char *buf
, size_t len
)
437 return store_bridge_parm(d
, buf
, len
, set_elasticity
);
439 static DEVICE_ATTR_RW(hash_elasticity
);
441 static ssize_t
hash_max_show(struct device
*d
, struct device_attribute
*attr
,
444 struct net_bridge
*br
= to_bridge(d
);
445 return sprintf(buf
, "%u\n", br
->hash_max
);
448 static int set_hash_max(struct net_bridge
*br
, unsigned long val
)
454 static ssize_t
hash_max_store(struct device
*d
, struct device_attribute
*attr
,
455 const char *buf
, size_t len
)
457 return store_bridge_parm(d
, buf
, len
, set_hash_max
);
459 static DEVICE_ATTR_RW(hash_max
);
461 static ssize_t
multicast_igmp_version_show(struct device
*d
,
462 struct device_attribute
*attr
,
465 struct net_bridge
*br
= to_bridge(d
);
467 return sprintf(buf
, "%u\n", br
->multicast_igmp_version
);
470 static ssize_t
multicast_igmp_version_store(struct device
*d
,
471 struct device_attribute
*attr
,
472 const char *buf
, size_t len
)
474 return store_bridge_parm(d
, buf
, len
, br_multicast_set_igmp_version
);
476 static DEVICE_ATTR_RW(multicast_igmp_version
);
478 static ssize_t
multicast_last_member_count_show(struct device
*d
,
479 struct device_attribute
*attr
,
482 struct net_bridge
*br
= to_bridge(d
);
483 return sprintf(buf
, "%u\n", br
->multicast_last_member_count
);
486 static int set_last_member_count(struct net_bridge
*br
, unsigned long val
)
488 br
->multicast_last_member_count
= val
;
492 static ssize_t
multicast_last_member_count_store(struct device
*d
,
493 struct device_attribute
*attr
,
494 const char *buf
, size_t len
)
496 return store_bridge_parm(d
, buf
, len
, set_last_member_count
);
498 static DEVICE_ATTR_RW(multicast_last_member_count
);
500 static ssize_t
multicast_startup_query_count_show(
501 struct device
*d
, struct device_attribute
*attr
, char *buf
)
503 struct net_bridge
*br
= to_bridge(d
);
504 return sprintf(buf
, "%u\n", br
->multicast_startup_query_count
);
507 static int set_startup_query_count(struct net_bridge
*br
, unsigned long val
)
509 br
->multicast_startup_query_count
= val
;
513 static ssize_t
multicast_startup_query_count_store(
514 struct device
*d
, struct device_attribute
*attr
, const char *buf
,
517 return store_bridge_parm(d
, buf
, len
, set_startup_query_count
);
519 static DEVICE_ATTR_RW(multicast_startup_query_count
);
521 static ssize_t
multicast_last_member_interval_show(
522 struct device
*d
, struct device_attribute
*attr
, char *buf
)
524 struct net_bridge
*br
= to_bridge(d
);
525 return sprintf(buf
, "%lu\n",
526 jiffies_to_clock_t(br
->multicast_last_member_interval
));
529 static int set_last_member_interval(struct net_bridge
*br
, unsigned long val
)
531 br
->multicast_last_member_interval
= clock_t_to_jiffies(val
);
535 static ssize_t
multicast_last_member_interval_store(
536 struct device
*d
, struct device_attribute
*attr
, const char *buf
,
539 return store_bridge_parm(d
, buf
, len
, set_last_member_interval
);
541 static DEVICE_ATTR_RW(multicast_last_member_interval
);
543 static ssize_t
multicast_membership_interval_show(
544 struct device
*d
, struct device_attribute
*attr
, char *buf
)
546 struct net_bridge
*br
= to_bridge(d
);
547 return sprintf(buf
, "%lu\n",
548 jiffies_to_clock_t(br
->multicast_membership_interval
));
551 static int set_membership_interval(struct net_bridge
*br
, unsigned long val
)
553 br
->multicast_membership_interval
= clock_t_to_jiffies(val
);
557 static ssize_t
multicast_membership_interval_store(
558 struct device
*d
, struct device_attribute
*attr
, const char *buf
,
561 return store_bridge_parm(d
, buf
, len
, set_membership_interval
);
563 static DEVICE_ATTR_RW(multicast_membership_interval
);
565 static ssize_t
multicast_querier_interval_show(struct device
*d
,
566 struct device_attribute
*attr
,
569 struct net_bridge
*br
= to_bridge(d
);
570 return sprintf(buf
, "%lu\n",
571 jiffies_to_clock_t(br
->multicast_querier_interval
));
574 static int set_querier_interval(struct net_bridge
*br
, unsigned long val
)
576 br
->multicast_querier_interval
= clock_t_to_jiffies(val
);
580 static ssize_t
multicast_querier_interval_store(struct device
*d
,
581 struct device_attribute
*attr
,
582 const char *buf
, size_t len
)
584 return store_bridge_parm(d
, buf
, len
, set_querier_interval
);
586 static DEVICE_ATTR_RW(multicast_querier_interval
);
588 static ssize_t
multicast_query_interval_show(struct device
*d
,
589 struct device_attribute
*attr
,
592 struct net_bridge
*br
= to_bridge(d
);
593 return sprintf(buf
, "%lu\n",
594 jiffies_to_clock_t(br
->multicast_query_interval
));
597 static int set_query_interval(struct net_bridge
*br
, unsigned long val
)
599 br
->multicast_query_interval
= clock_t_to_jiffies(val
);
603 static ssize_t
multicast_query_interval_store(struct device
*d
,
604 struct device_attribute
*attr
,
605 const char *buf
, size_t len
)
607 return store_bridge_parm(d
, buf
, len
, set_query_interval
);
609 static DEVICE_ATTR_RW(multicast_query_interval
);
611 static ssize_t
multicast_query_response_interval_show(
612 struct device
*d
, struct device_attribute
*attr
, char *buf
)
614 struct net_bridge
*br
= to_bridge(d
);
617 jiffies_to_clock_t(br
->multicast_query_response_interval
));
620 static int set_query_response_interval(struct net_bridge
*br
, unsigned long val
)
622 br
->multicast_query_response_interval
= clock_t_to_jiffies(val
);
626 static ssize_t
multicast_query_response_interval_store(
627 struct device
*d
, struct device_attribute
*attr
, const char *buf
,
630 return store_bridge_parm(d
, buf
, len
, set_query_response_interval
);
632 static DEVICE_ATTR_RW(multicast_query_response_interval
);
634 static ssize_t
multicast_startup_query_interval_show(
635 struct device
*d
, struct device_attribute
*attr
, char *buf
)
637 struct net_bridge
*br
= to_bridge(d
);
640 jiffies_to_clock_t(br
->multicast_startup_query_interval
));
643 static int set_startup_query_interval(struct net_bridge
*br
, unsigned long val
)
645 br
->multicast_startup_query_interval
= clock_t_to_jiffies(val
);
649 static ssize_t
multicast_startup_query_interval_store(
650 struct device
*d
, struct device_attribute
*attr
, const char *buf
,
653 return store_bridge_parm(d
, buf
, len
, set_startup_query_interval
);
655 static DEVICE_ATTR_RW(multicast_startup_query_interval
);
657 static ssize_t
multicast_stats_enabled_show(struct device
*d
,
658 struct device_attribute
*attr
,
661 struct net_bridge
*br
= to_bridge(d
);
663 return sprintf(buf
, "%d\n",
664 br_opt_get(br
, BROPT_MULTICAST_STATS_ENABLED
));
667 static int set_stats_enabled(struct net_bridge
*br
, unsigned long val
)
669 br_opt_toggle(br
, BROPT_MULTICAST_STATS_ENABLED
, !!val
);
673 static ssize_t
multicast_stats_enabled_store(struct device
*d
,
674 struct device_attribute
*attr
,
678 return store_bridge_parm(d
, buf
, len
, set_stats_enabled
);
680 static DEVICE_ATTR_RW(multicast_stats_enabled
);
682 #if IS_ENABLED(CONFIG_IPV6)
683 static ssize_t
multicast_mld_version_show(struct device
*d
,
684 struct device_attribute
*attr
,
687 struct net_bridge
*br
= to_bridge(d
);
689 return sprintf(buf
, "%u\n", br
->multicast_mld_version
);
692 static ssize_t
multicast_mld_version_store(struct device
*d
,
693 struct device_attribute
*attr
,
694 const char *buf
, size_t len
)
696 return store_bridge_parm(d
, buf
, len
, br_multicast_set_mld_version
);
698 static DEVICE_ATTR_RW(multicast_mld_version
);
701 #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
702 static ssize_t
nf_call_iptables_show(
703 struct device
*d
, struct device_attribute
*attr
, char *buf
)
705 struct net_bridge
*br
= to_bridge(d
);
706 return sprintf(buf
, "%u\n", br_opt_get(br
, BROPT_NF_CALL_IPTABLES
));
709 static int set_nf_call_iptables(struct net_bridge
*br
, unsigned long val
)
711 br_opt_toggle(br
, BROPT_NF_CALL_IPTABLES
, !!val
);
715 static ssize_t
nf_call_iptables_store(
716 struct device
*d
, struct device_attribute
*attr
, const char *buf
,
719 return store_bridge_parm(d
, buf
, len
, set_nf_call_iptables
);
721 static DEVICE_ATTR_RW(nf_call_iptables
);
723 static ssize_t
nf_call_ip6tables_show(
724 struct device
*d
, struct device_attribute
*attr
, char *buf
)
726 struct net_bridge
*br
= to_bridge(d
);
727 return sprintf(buf
, "%u\n", br_opt_get(br
, BROPT_NF_CALL_IP6TABLES
));
730 static int set_nf_call_ip6tables(struct net_bridge
*br
, unsigned long val
)
732 br_opt_toggle(br
, BROPT_NF_CALL_IP6TABLES
, !!val
);
736 static ssize_t
nf_call_ip6tables_store(
737 struct device
*d
, struct device_attribute
*attr
, const char *buf
,
740 return store_bridge_parm(d
, buf
, len
, set_nf_call_ip6tables
);
742 static DEVICE_ATTR_RW(nf_call_ip6tables
);
744 static ssize_t
nf_call_arptables_show(
745 struct device
*d
, struct device_attribute
*attr
, char *buf
)
747 struct net_bridge
*br
= to_bridge(d
);
748 return sprintf(buf
, "%u\n", br_opt_get(br
, BROPT_NF_CALL_ARPTABLES
));
751 static int set_nf_call_arptables(struct net_bridge
*br
, unsigned long val
)
753 br_opt_toggle(br
, BROPT_NF_CALL_ARPTABLES
, !!val
);
757 static ssize_t
nf_call_arptables_store(
758 struct device
*d
, struct device_attribute
*attr
, const char *buf
,
761 return store_bridge_parm(d
, buf
, len
, set_nf_call_arptables
);
763 static DEVICE_ATTR_RW(nf_call_arptables
);
765 #ifdef CONFIG_BRIDGE_VLAN_FILTERING
766 static ssize_t
vlan_filtering_show(struct device
*d
,
767 struct device_attribute
*attr
,
770 struct net_bridge
*br
= to_bridge(d
);
771 return sprintf(buf
, "%d\n", br_opt_get(br
, BROPT_VLAN_ENABLED
));
774 static ssize_t
vlan_filtering_store(struct device
*d
,
775 struct device_attribute
*attr
,
776 const char *buf
, size_t len
)
778 return store_bridge_parm(d
, buf
, len
, br_vlan_filter_toggle
);
780 static DEVICE_ATTR_RW(vlan_filtering
);
782 static ssize_t
vlan_protocol_show(struct device
*d
,
783 struct device_attribute
*attr
,
786 struct net_bridge
*br
= to_bridge(d
);
787 return sprintf(buf
, "%#06x\n", ntohs(br
->vlan_proto
));
790 static ssize_t
vlan_protocol_store(struct device
*d
,
791 struct device_attribute
*attr
,
792 const char *buf
, size_t len
)
794 return store_bridge_parm(d
, buf
, len
, br_vlan_set_proto
);
796 static DEVICE_ATTR_RW(vlan_protocol
);
798 static ssize_t
default_pvid_show(struct device
*d
,
799 struct device_attribute
*attr
,
802 struct net_bridge
*br
= to_bridge(d
);
803 return sprintf(buf
, "%d\n", br
->default_pvid
);
806 static ssize_t
default_pvid_store(struct device
*d
,
807 struct device_attribute
*attr
,
808 const char *buf
, size_t len
)
810 return store_bridge_parm(d
, buf
, len
, br_vlan_set_default_pvid
);
812 static DEVICE_ATTR_RW(default_pvid
);
814 static ssize_t
vlan_stats_enabled_show(struct device
*d
,
815 struct device_attribute
*attr
,
818 struct net_bridge
*br
= to_bridge(d
);
819 return sprintf(buf
, "%u\n", br_opt_get(br
, BROPT_VLAN_STATS_ENABLED
));
822 static ssize_t
vlan_stats_enabled_store(struct device
*d
,
823 struct device_attribute
*attr
,
824 const char *buf
, size_t len
)
826 return store_bridge_parm(d
, buf
, len
, br_vlan_set_stats
);
828 static DEVICE_ATTR_RW(vlan_stats_enabled
);
830 static ssize_t
vlan_stats_per_port_show(struct device
*d
,
831 struct device_attribute
*attr
,
834 struct net_bridge
*br
= to_bridge(d
);
835 return sprintf(buf
, "%u\n", br_opt_get(br
, BROPT_VLAN_STATS_PER_PORT
));
838 static ssize_t
vlan_stats_per_port_store(struct device
*d
,
839 struct device_attribute
*attr
,
840 const char *buf
, size_t len
)
842 return store_bridge_parm(d
, buf
, len
, br_vlan_set_stats_per_port
);
844 static DEVICE_ATTR_RW(vlan_stats_per_port
);
847 static struct attribute
*bridge_attrs
[] = {
848 &dev_attr_forward_delay
.attr
,
849 &dev_attr_hello_time
.attr
,
850 &dev_attr_max_age
.attr
,
851 &dev_attr_ageing_time
.attr
,
852 &dev_attr_stp_state
.attr
,
853 &dev_attr_group_fwd_mask
.attr
,
854 &dev_attr_priority
.attr
,
855 &dev_attr_bridge_id
.attr
,
856 &dev_attr_root_id
.attr
,
857 &dev_attr_root_path_cost
.attr
,
858 &dev_attr_root_port
.attr
,
859 &dev_attr_topology_change
.attr
,
860 &dev_attr_topology_change_detected
.attr
,
861 &dev_attr_hello_timer
.attr
,
862 &dev_attr_tcn_timer
.attr
,
863 &dev_attr_topology_change_timer
.attr
,
864 &dev_attr_gc_timer
.attr
,
865 &dev_attr_group_addr
.attr
,
866 &dev_attr_flush
.attr
,
867 &dev_attr_no_linklocal_learn
.attr
,
868 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
869 &dev_attr_multicast_router
.attr
,
870 &dev_attr_multicast_snooping
.attr
,
871 &dev_attr_multicast_querier
.attr
,
872 &dev_attr_multicast_query_use_ifaddr
.attr
,
873 &dev_attr_hash_elasticity
.attr
,
874 &dev_attr_hash_max
.attr
,
875 &dev_attr_multicast_last_member_count
.attr
,
876 &dev_attr_multicast_startup_query_count
.attr
,
877 &dev_attr_multicast_last_member_interval
.attr
,
878 &dev_attr_multicast_membership_interval
.attr
,
879 &dev_attr_multicast_querier_interval
.attr
,
880 &dev_attr_multicast_query_interval
.attr
,
881 &dev_attr_multicast_query_response_interval
.attr
,
882 &dev_attr_multicast_startup_query_interval
.attr
,
883 &dev_attr_multicast_stats_enabled
.attr
,
884 &dev_attr_multicast_igmp_version
.attr
,
885 #if IS_ENABLED(CONFIG_IPV6)
886 &dev_attr_multicast_mld_version
.attr
,
889 #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
890 &dev_attr_nf_call_iptables
.attr
,
891 &dev_attr_nf_call_ip6tables
.attr
,
892 &dev_attr_nf_call_arptables
.attr
,
894 #ifdef CONFIG_BRIDGE_VLAN_FILTERING
895 &dev_attr_vlan_filtering
.attr
,
896 &dev_attr_vlan_protocol
.attr
,
897 &dev_attr_default_pvid
.attr
,
898 &dev_attr_vlan_stats_enabled
.attr
,
899 &dev_attr_vlan_stats_per_port
.attr
,
904 static const struct attribute_group bridge_group
= {
905 .name
= SYSFS_BRIDGE_ATTR
,
906 .attrs
= bridge_attrs
,
910 * Export the forwarding information table as a binary file
911 * The records are struct __fdb_entry.
913 * Returns the number of bytes read.
915 static ssize_t
brforward_read(struct file
*filp
, struct kobject
*kobj
,
916 struct bin_attribute
*bin_attr
,
917 char *buf
, loff_t off
, size_t count
)
919 struct device
*dev
= kobj_to_dev(kobj
);
920 struct net_bridge
*br
= to_bridge(dev
);
923 /* must read whole records */
924 if (off
% sizeof(struct __fdb_entry
) != 0)
927 n
= br_fdb_fillbuf(br
, buf
,
928 count
/ sizeof(struct __fdb_entry
),
929 off
/ sizeof(struct __fdb_entry
));
932 n
*= sizeof(struct __fdb_entry
);
937 static struct bin_attribute bridge_forward
= {
938 .attr
= { .name
= SYSFS_BRIDGE_FDB
,
940 .read
= brforward_read
,
944 * Add entries in sysfs onto the existing network class device
946 * Adds a attribute group "bridge" containing tuning parameters.
947 * Binary attribute containing the forward table
948 * Sub directory to hold links to interfaces.
950 * Note: the ifobj exists only to be a subdirectory
951 * to hold links. The ifobj exists in same data structure
952 * as it's parent the bridge so reference counting works.
954 int br_sysfs_addbr(struct net_device
*dev
)
956 struct kobject
*brobj
= &dev
->dev
.kobj
;
957 struct net_bridge
*br
= netdev_priv(dev
);
960 err
= sysfs_create_group(brobj
, &bridge_group
);
962 pr_info("%s: can't create group %s/%s\n",
963 __func__
, dev
->name
, bridge_group
.name
);
967 err
= sysfs_create_bin_file(brobj
, &bridge_forward
);
969 pr_info("%s: can't create attribute file %s/%s\n",
970 __func__
, dev
->name
, bridge_forward
.attr
.name
);
974 br
->ifobj
= kobject_create_and_add(SYSFS_BRIDGE_PORT_SUBDIR
, brobj
);
976 pr_info("%s: can't add kobject (directory) %s/%s\n",
977 __func__
, dev
->name
, SYSFS_BRIDGE_PORT_SUBDIR
);
983 sysfs_remove_bin_file(&dev
->dev
.kobj
, &bridge_forward
);
985 sysfs_remove_group(&dev
->dev
.kobj
, &bridge_group
);
991 void br_sysfs_delbr(struct net_device
*dev
)
993 struct kobject
*kobj
= &dev
->dev
.kobj
;
994 struct net_bridge
*br
= netdev_priv(dev
);
996 kobject_put(br
->ifobj
);
997 sysfs_remove_bin_file(kobj
, &bridge_forward
);
998 sysfs_remove_group(kobj
, &bridge_group
);