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>
22 #include <linux/sched/signal.h>
24 #include "br_private.h"
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);
48 return restart_syscall();
50 err
= (*set
)(br
, val
);
52 netdev_state_change(br
->dev
);
55 return err
? err
: len
;
59 static ssize_t
forward_delay_show(struct device
*d
,
60 struct device_attribute
*attr
, char *buf
)
62 struct net_bridge
*br
= to_bridge(d
);
63 return sprintf(buf
, "%lu\n", jiffies_to_clock_t(br
->forward_delay
));
66 static ssize_t
forward_delay_store(struct device
*d
,
67 struct device_attribute
*attr
,
68 const char *buf
, size_t len
)
70 return store_bridge_parm(d
, buf
, len
, br_set_forward_delay
);
72 static DEVICE_ATTR_RW(forward_delay
);
74 static ssize_t
hello_time_show(struct device
*d
, struct device_attribute
*attr
,
77 return sprintf(buf
, "%lu\n",
78 jiffies_to_clock_t(to_bridge(d
)->hello_time
));
81 static ssize_t
hello_time_store(struct device
*d
,
82 struct device_attribute
*attr
, const char *buf
,
85 return store_bridge_parm(d
, buf
, len
, br_set_hello_time
);
87 static DEVICE_ATTR_RW(hello_time
);
89 static ssize_t
max_age_show(struct device
*d
, struct device_attribute
*attr
,
92 return sprintf(buf
, "%lu\n",
93 jiffies_to_clock_t(to_bridge(d
)->max_age
));
96 static ssize_t
max_age_store(struct device
*d
, struct device_attribute
*attr
,
97 const char *buf
, size_t len
)
99 return store_bridge_parm(d
, buf
, len
, br_set_max_age
);
101 static DEVICE_ATTR_RW(max_age
);
103 static ssize_t
ageing_time_show(struct device
*d
,
104 struct device_attribute
*attr
, char *buf
)
106 struct net_bridge
*br
= to_bridge(d
);
107 return sprintf(buf
, "%lu\n", jiffies_to_clock_t(br
->ageing_time
));
110 static int set_ageing_time(struct net_bridge
*br
, unsigned long val
)
112 return br_set_ageing_time(br
, val
);
115 static ssize_t
ageing_time_store(struct device
*d
,
116 struct device_attribute
*attr
,
117 const char *buf
, size_t len
)
119 return store_bridge_parm(d
, buf
, len
, set_ageing_time
);
121 static DEVICE_ATTR_RW(ageing_time
);
123 static ssize_t
stp_state_show(struct device
*d
,
124 struct device_attribute
*attr
, char *buf
)
126 struct net_bridge
*br
= to_bridge(d
);
127 return sprintf(buf
, "%d\n", br
->stp_enabled
);
131 static int set_stp_state(struct net_bridge
*br
, unsigned long val
)
133 br_stp_set_enabled(br
, val
);
138 static ssize_t
stp_state_store(struct device
*d
,
139 struct device_attribute
*attr
, const char *buf
,
142 return store_bridge_parm(d
, buf
, len
, set_stp_state
);
144 static DEVICE_ATTR_RW(stp_state
);
146 static ssize_t
group_fwd_mask_show(struct device
*d
,
147 struct device_attribute
*attr
,
150 struct net_bridge
*br
= to_bridge(d
);
151 return sprintf(buf
, "%#x\n", br
->group_fwd_mask
);
154 static int set_group_fwd_mask(struct net_bridge
*br
, unsigned long val
)
156 if (val
& BR_GROUPFWD_RESTRICTED
)
159 br
->group_fwd_mask
= val
;
164 static ssize_t
group_fwd_mask_store(struct device
*d
,
165 struct device_attribute
*attr
,
169 return store_bridge_parm(d
, buf
, len
, set_group_fwd_mask
);
171 static DEVICE_ATTR_RW(group_fwd_mask
);
173 static ssize_t
priority_show(struct device
*d
, struct device_attribute
*attr
,
176 struct net_bridge
*br
= to_bridge(d
);
177 return sprintf(buf
, "%d\n",
178 (br
->bridge_id
.prio
[0] << 8) | br
->bridge_id
.prio
[1]);
181 static int set_priority(struct net_bridge
*br
, unsigned long val
)
183 br_stp_set_bridge_priority(br
, (u16
) val
);
187 static ssize_t
priority_store(struct device
*d
, struct device_attribute
*attr
,
188 const char *buf
, size_t len
)
190 return store_bridge_parm(d
, buf
, len
, set_priority
);
192 static DEVICE_ATTR_RW(priority
);
194 static ssize_t
root_id_show(struct device
*d
, struct device_attribute
*attr
,
197 return br_show_bridge_id(buf
, &to_bridge(d
)->designated_root
);
199 static DEVICE_ATTR_RO(root_id
);
201 static ssize_t
bridge_id_show(struct device
*d
, struct device_attribute
*attr
,
204 return br_show_bridge_id(buf
, &to_bridge(d
)->bridge_id
);
206 static DEVICE_ATTR_RO(bridge_id
);
208 static ssize_t
root_port_show(struct device
*d
, struct device_attribute
*attr
,
211 return sprintf(buf
, "%d\n", to_bridge(d
)->root_port
);
213 static DEVICE_ATTR_RO(root_port
);
215 static ssize_t
root_path_cost_show(struct device
*d
,
216 struct device_attribute
*attr
, char *buf
)
218 return sprintf(buf
, "%d\n", to_bridge(d
)->root_path_cost
);
220 static DEVICE_ATTR_RO(root_path_cost
);
222 static ssize_t
topology_change_show(struct device
*d
,
223 struct device_attribute
*attr
, char *buf
)
225 return sprintf(buf
, "%d\n", to_bridge(d
)->topology_change
);
227 static DEVICE_ATTR_RO(topology_change
);
229 static ssize_t
topology_change_detected_show(struct device
*d
,
230 struct device_attribute
*attr
,
233 struct net_bridge
*br
= to_bridge(d
);
234 return sprintf(buf
, "%d\n", br
->topology_change_detected
);
236 static DEVICE_ATTR_RO(topology_change_detected
);
238 static ssize_t
hello_timer_show(struct device
*d
,
239 struct device_attribute
*attr
, char *buf
)
241 struct net_bridge
*br
= to_bridge(d
);
242 return sprintf(buf
, "%ld\n", br_timer_value(&br
->hello_timer
));
244 static DEVICE_ATTR_RO(hello_timer
);
246 static ssize_t
tcn_timer_show(struct device
*d
, struct device_attribute
*attr
,
249 struct net_bridge
*br
= to_bridge(d
);
250 return sprintf(buf
, "%ld\n", br_timer_value(&br
->tcn_timer
));
252 static DEVICE_ATTR_RO(tcn_timer
);
254 static ssize_t
topology_change_timer_show(struct device
*d
,
255 struct device_attribute
*attr
,
258 struct net_bridge
*br
= to_bridge(d
);
259 return sprintf(buf
, "%ld\n", br_timer_value(&br
->topology_change_timer
));
261 static DEVICE_ATTR_RO(topology_change_timer
);
263 static ssize_t
gc_timer_show(struct device
*d
, struct device_attribute
*attr
,
266 struct net_bridge
*br
= to_bridge(d
);
267 return sprintf(buf
, "%ld\n", br_timer_value(&br
->gc_work
.timer
));
269 static DEVICE_ATTR_RO(gc_timer
);
271 static ssize_t
group_addr_show(struct device
*d
,
272 struct device_attribute
*attr
, char *buf
)
274 struct net_bridge
*br
= to_bridge(d
);
275 return sprintf(buf
, "%pM\n", br
->group_addr
);
278 static ssize_t
group_addr_store(struct device
*d
,
279 struct device_attribute
*attr
,
280 const char *buf
, size_t len
)
282 struct net_bridge
*br
= to_bridge(d
);
285 if (!ns_capable(dev_net(br
->dev
)->user_ns
, CAP_NET_ADMIN
))
288 if (!mac_pton(buf
, new_addr
))
291 if (!is_link_local_ether_addr(new_addr
))
294 if (new_addr
[5] == 1 || /* 802.3x Pause address */
295 new_addr
[5] == 2 || /* 802.3ad Slow protocols */
296 new_addr
[5] == 3) /* 802.1X PAE address */
300 return restart_syscall();
302 spin_lock_bh(&br
->lock
);
303 ether_addr_copy(br
->group_addr
, new_addr
);
304 spin_unlock_bh(&br
->lock
);
306 br
->group_addr_set
= true;
307 br_recalculate_fwd_mask(br
);
308 netdev_state_change(br
->dev
);
315 static DEVICE_ATTR_RW(group_addr
);
317 static int set_flush(struct net_bridge
*br
, unsigned long val
)
323 static ssize_t
flush_store(struct device
*d
,
324 struct device_attribute
*attr
,
325 const char *buf
, size_t len
)
327 return store_bridge_parm(d
, buf
, len
, set_flush
);
329 static DEVICE_ATTR_WO(flush
);
331 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
332 static ssize_t
multicast_router_show(struct device
*d
,
333 struct device_attribute
*attr
, char *buf
)
335 struct net_bridge
*br
= to_bridge(d
);
336 return sprintf(buf
, "%d\n", br
->multicast_router
);
339 static ssize_t
multicast_router_store(struct device
*d
,
340 struct device_attribute
*attr
,
341 const char *buf
, size_t len
)
343 return store_bridge_parm(d
, buf
, len
, br_multicast_set_router
);
345 static DEVICE_ATTR_RW(multicast_router
);
347 static ssize_t
multicast_snooping_show(struct device
*d
,
348 struct device_attribute
*attr
,
351 struct net_bridge
*br
= to_bridge(d
);
352 return sprintf(buf
, "%d\n", !br
->multicast_disabled
);
355 static ssize_t
multicast_snooping_store(struct device
*d
,
356 struct device_attribute
*attr
,
357 const char *buf
, size_t len
)
359 return store_bridge_parm(d
, buf
, len
, br_multicast_toggle
);
361 static DEVICE_ATTR_RW(multicast_snooping
);
363 static ssize_t
multicast_query_use_ifaddr_show(struct device
*d
,
364 struct device_attribute
*attr
,
367 struct net_bridge
*br
= to_bridge(d
);
368 return sprintf(buf
, "%d\n", br
->multicast_query_use_ifaddr
);
371 static int set_query_use_ifaddr(struct net_bridge
*br
, unsigned long val
)
373 br
->multicast_query_use_ifaddr
= !!val
;
378 multicast_query_use_ifaddr_store(struct device
*d
,
379 struct device_attribute
*attr
,
380 const char *buf
, size_t len
)
382 return store_bridge_parm(d
, buf
, len
, set_query_use_ifaddr
);
384 static DEVICE_ATTR_RW(multicast_query_use_ifaddr
);
386 static ssize_t
multicast_querier_show(struct device
*d
,
387 struct device_attribute
*attr
,
390 struct net_bridge
*br
= to_bridge(d
);
391 return sprintf(buf
, "%d\n", br
->multicast_querier
);
394 static ssize_t
multicast_querier_store(struct device
*d
,
395 struct device_attribute
*attr
,
396 const char *buf
, size_t len
)
398 return store_bridge_parm(d
, buf
, len
, br_multicast_set_querier
);
400 static DEVICE_ATTR_RW(multicast_querier
);
402 static ssize_t
hash_elasticity_show(struct device
*d
,
403 struct device_attribute
*attr
, char *buf
)
405 struct net_bridge
*br
= to_bridge(d
);
406 return sprintf(buf
, "%u\n", br
->hash_elasticity
);
409 static int set_elasticity(struct net_bridge
*br
, unsigned long val
)
411 br
->hash_elasticity
= val
;
415 static ssize_t
hash_elasticity_store(struct device
*d
,
416 struct device_attribute
*attr
,
417 const char *buf
, size_t len
)
419 return store_bridge_parm(d
, buf
, len
, set_elasticity
);
421 static DEVICE_ATTR_RW(hash_elasticity
);
423 static ssize_t
hash_max_show(struct device
*d
, struct device_attribute
*attr
,
426 struct net_bridge
*br
= to_bridge(d
);
427 return sprintf(buf
, "%u\n", br
->hash_max
);
430 static ssize_t
hash_max_store(struct device
*d
, struct device_attribute
*attr
,
431 const char *buf
, size_t len
)
433 return store_bridge_parm(d
, buf
, len
, br_multicast_set_hash_max
);
435 static DEVICE_ATTR_RW(hash_max
);
437 static ssize_t
multicast_igmp_version_show(struct device
*d
,
438 struct device_attribute
*attr
,
441 struct net_bridge
*br
= to_bridge(d
);
443 return sprintf(buf
, "%u\n", br
->multicast_igmp_version
);
446 static ssize_t
multicast_igmp_version_store(struct device
*d
,
447 struct device_attribute
*attr
,
448 const char *buf
, size_t len
)
450 return store_bridge_parm(d
, buf
, len
, br_multicast_set_igmp_version
);
452 static DEVICE_ATTR_RW(multicast_igmp_version
);
454 static ssize_t
multicast_last_member_count_show(struct device
*d
,
455 struct device_attribute
*attr
,
458 struct net_bridge
*br
= to_bridge(d
);
459 return sprintf(buf
, "%u\n", br
->multicast_last_member_count
);
462 static int set_last_member_count(struct net_bridge
*br
, unsigned long val
)
464 br
->multicast_last_member_count
= val
;
468 static ssize_t
multicast_last_member_count_store(struct device
*d
,
469 struct device_attribute
*attr
,
470 const char *buf
, size_t len
)
472 return store_bridge_parm(d
, buf
, len
, set_last_member_count
);
474 static DEVICE_ATTR_RW(multicast_last_member_count
);
476 static ssize_t
multicast_startup_query_count_show(
477 struct device
*d
, struct device_attribute
*attr
, char *buf
)
479 struct net_bridge
*br
= to_bridge(d
);
480 return sprintf(buf
, "%u\n", br
->multicast_startup_query_count
);
483 static int set_startup_query_count(struct net_bridge
*br
, unsigned long val
)
485 br
->multicast_startup_query_count
= val
;
489 static ssize_t
multicast_startup_query_count_store(
490 struct device
*d
, struct device_attribute
*attr
, const char *buf
,
493 return store_bridge_parm(d
, buf
, len
, set_startup_query_count
);
495 static DEVICE_ATTR_RW(multicast_startup_query_count
);
497 static ssize_t
multicast_last_member_interval_show(
498 struct device
*d
, struct device_attribute
*attr
, char *buf
)
500 struct net_bridge
*br
= to_bridge(d
);
501 return sprintf(buf
, "%lu\n",
502 jiffies_to_clock_t(br
->multicast_last_member_interval
));
505 static int set_last_member_interval(struct net_bridge
*br
, unsigned long val
)
507 br
->multicast_last_member_interval
= clock_t_to_jiffies(val
);
511 static ssize_t
multicast_last_member_interval_store(
512 struct device
*d
, struct device_attribute
*attr
, const char *buf
,
515 return store_bridge_parm(d
, buf
, len
, set_last_member_interval
);
517 static DEVICE_ATTR_RW(multicast_last_member_interval
);
519 static ssize_t
multicast_membership_interval_show(
520 struct device
*d
, struct device_attribute
*attr
, char *buf
)
522 struct net_bridge
*br
= to_bridge(d
);
523 return sprintf(buf
, "%lu\n",
524 jiffies_to_clock_t(br
->multicast_membership_interval
));
527 static int set_membership_interval(struct net_bridge
*br
, unsigned long val
)
529 br
->multicast_membership_interval
= clock_t_to_jiffies(val
);
533 static ssize_t
multicast_membership_interval_store(
534 struct device
*d
, struct device_attribute
*attr
, const char *buf
,
537 return store_bridge_parm(d
, buf
, len
, set_membership_interval
);
539 static DEVICE_ATTR_RW(multicast_membership_interval
);
541 static ssize_t
multicast_querier_interval_show(struct device
*d
,
542 struct device_attribute
*attr
,
545 struct net_bridge
*br
= to_bridge(d
);
546 return sprintf(buf
, "%lu\n",
547 jiffies_to_clock_t(br
->multicast_querier_interval
));
550 static int set_querier_interval(struct net_bridge
*br
, unsigned long val
)
552 br
->multicast_querier_interval
= clock_t_to_jiffies(val
);
556 static ssize_t
multicast_querier_interval_store(struct device
*d
,
557 struct device_attribute
*attr
,
558 const char *buf
, size_t len
)
560 return store_bridge_parm(d
, buf
, len
, set_querier_interval
);
562 static DEVICE_ATTR_RW(multicast_querier_interval
);
564 static ssize_t
multicast_query_interval_show(struct device
*d
,
565 struct device_attribute
*attr
,
568 struct net_bridge
*br
= to_bridge(d
);
569 return sprintf(buf
, "%lu\n",
570 jiffies_to_clock_t(br
->multicast_query_interval
));
573 static int set_query_interval(struct net_bridge
*br
, unsigned long val
)
575 br
->multicast_query_interval
= clock_t_to_jiffies(val
);
579 static ssize_t
multicast_query_interval_store(struct device
*d
,
580 struct device_attribute
*attr
,
581 const char *buf
, size_t len
)
583 return store_bridge_parm(d
, buf
, len
, set_query_interval
);
585 static DEVICE_ATTR_RW(multicast_query_interval
);
587 static ssize_t
multicast_query_response_interval_show(
588 struct device
*d
, struct device_attribute
*attr
, char *buf
)
590 struct net_bridge
*br
= to_bridge(d
);
593 jiffies_to_clock_t(br
->multicast_query_response_interval
));
596 static int set_query_response_interval(struct net_bridge
*br
, unsigned long val
)
598 br
->multicast_query_response_interval
= clock_t_to_jiffies(val
);
602 static ssize_t
multicast_query_response_interval_store(
603 struct device
*d
, struct device_attribute
*attr
, const char *buf
,
606 return store_bridge_parm(d
, buf
, len
, set_query_response_interval
);
608 static DEVICE_ATTR_RW(multicast_query_response_interval
);
610 static ssize_t
multicast_startup_query_interval_show(
611 struct device
*d
, struct device_attribute
*attr
, char *buf
)
613 struct net_bridge
*br
= to_bridge(d
);
616 jiffies_to_clock_t(br
->multicast_startup_query_interval
));
619 static int set_startup_query_interval(struct net_bridge
*br
, unsigned long val
)
621 br
->multicast_startup_query_interval
= clock_t_to_jiffies(val
);
625 static ssize_t
multicast_startup_query_interval_store(
626 struct device
*d
, struct device_attribute
*attr
, const char *buf
,
629 return store_bridge_parm(d
, buf
, len
, set_startup_query_interval
);
631 static DEVICE_ATTR_RW(multicast_startup_query_interval
);
633 static ssize_t
multicast_stats_enabled_show(struct device
*d
,
634 struct device_attribute
*attr
,
637 struct net_bridge
*br
= to_bridge(d
);
639 return sprintf(buf
, "%u\n", br
->multicast_stats_enabled
);
642 static int set_stats_enabled(struct net_bridge
*br
, unsigned long val
)
644 br
->multicast_stats_enabled
= !!val
;
648 static ssize_t
multicast_stats_enabled_store(struct device
*d
,
649 struct device_attribute
*attr
,
653 return store_bridge_parm(d
, buf
, len
, set_stats_enabled
);
655 static DEVICE_ATTR_RW(multicast_stats_enabled
);
657 #if IS_ENABLED(CONFIG_IPV6)
658 static ssize_t
multicast_mld_version_show(struct device
*d
,
659 struct device_attribute
*attr
,
662 struct net_bridge
*br
= to_bridge(d
);
664 return sprintf(buf
, "%u\n", br
->multicast_mld_version
);
667 static ssize_t
multicast_mld_version_store(struct device
*d
,
668 struct device_attribute
*attr
,
669 const char *buf
, size_t len
)
671 return store_bridge_parm(d
, buf
, len
, br_multicast_set_mld_version
);
673 static DEVICE_ATTR_RW(multicast_mld_version
);
676 #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
677 static ssize_t
nf_call_iptables_show(
678 struct device
*d
, struct device_attribute
*attr
, char *buf
)
680 struct net_bridge
*br
= to_bridge(d
);
681 return sprintf(buf
, "%u\n", br
->nf_call_iptables
);
684 static int set_nf_call_iptables(struct net_bridge
*br
, unsigned long val
)
686 br
->nf_call_iptables
= val
? true : false;
690 static ssize_t
nf_call_iptables_store(
691 struct device
*d
, struct device_attribute
*attr
, const char *buf
,
694 return store_bridge_parm(d
, buf
, len
, set_nf_call_iptables
);
696 static DEVICE_ATTR_RW(nf_call_iptables
);
698 static ssize_t
nf_call_ip6tables_show(
699 struct device
*d
, struct device_attribute
*attr
, char *buf
)
701 struct net_bridge
*br
= to_bridge(d
);
702 return sprintf(buf
, "%u\n", br
->nf_call_ip6tables
);
705 static int set_nf_call_ip6tables(struct net_bridge
*br
, unsigned long val
)
707 br
->nf_call_ip6tables
= val
? true : false;
711 static ssize_t
nf_call_ip6tables_store(
712 struct device
*d
, struct device_attribute
*attr
, const char *buf
,
715 return store_bridge_parm(d
, buf
, len
, set_nf_call_ip6tables
);
717 static DEVICE_ATTR_RW(nf_call_ip6tables
);
719 static ssize_t
nf_call_arptables_show(
720 struct device
*d
, struct device_attribute
*attr
, char *buf
)
722 struct net_bridge
*br
= to_bridge(d
);
723 return sprintf(buf
, "%u\n", br
->nf_call_arptables
);
726 static int set_nf_call_arptables(struct net_bridge
*br
, unsigned long val
)
728 br
->nf_call_arptables
= val
? true : false;
732 static ssize_t
nf_call_arptables_store(
733 struct device
*d
, struct device_attribute
*attr
, const char *buf
,
736 return store_bridge_parm(d
, buf
, len
, set_nf_call_arptables
);
738 static DEVICE_ATTR_RW(nf_call_arptables
);
740 #ifdef CONFIG_BRIDGE_VLAN_FILTERING
741 static ssize_t
vlan_filtering_show(struct device
*d
,
742 struct device_attribute
*attr
,
745 struct net_bridge
*br
= to_bridge(d
);
746 return sprintf(buf
, "%d\n", br
->vlan_enabled
);
749 static ssize_t
vlan_filtering_store(struct device
*d
,
750 struct device_attribute
*attr
,
751 const char *buf
, size_t len
)
753 return store_bridge_parm(d
, buf
, len
, br_vlan_filter_toggle
);
755 static DEVICE_ATTR_RW(vlan_filtering
);
757 static ssize_t
vlan_protocol_show(struct device
*d
,
758 struct device_attribute
*attr
,
761 struct net_bridge
*br
= to_bridge(d
);
762 return sprintf(buf
, "%#06x\n", ntohs(br
->vlan_proto
));
765 static ssize_t
vlan_protocol_store(struct device
*d
,
766 struct device_attribute
*attr
,
767 const char *buf
, size_t len
)
769 return store_bridge_parm(d
, buf
, len
, br_vlan_set_proto
);
771 static DEVICE_ATTR_RW(vlan_protocol
);
773 static ssize_t
default_pvid_show(struct device
*d
,
774 struct device_attribute
*attr
,
777 struct net_bridge
*br
= to_bridge(d
);
778 return sprintf(buf
, "%d\n", br
->default_pvid
);
781 static ssize_t
default_pvid_store(struct device
*d
,
782 struct device_attribute
*attr
,
783 const char *buf
, size_t len
)
785 return store_bridge_parm(d
, buf
, len
, br_vlan_set_default_pvid
);
787 static DEVICE_ATTR_RW(default_pvid
);
789 static ssize_t
vlan_stats_enabled_show(struct device
*d
,
790 struct device_attribute
*attr
,
793 struct net_bridge
*br
= to_bridge(d
);
794 return sprintf(buf
, "%u\n", br
->vlan_stats_enabled
);
797 static ssize_t
vlan_stats_enabled_store(struct device
*d
,
798 struct device_attribute
*attr
,
799 const char *buf
, size_t len
)
801 return store_bridge_parm(d
, buf
, len
, br_vlan_set_stats
);
803 static DEVICE_ATTR_RW(vlan_stats_enabled
);
806 static struct attribute
*bridge_attrs
[] = {
807 &dev_attr_forward_delay
.attr
,
808 &dev_attr_hello_time
.attr
,
809 &dev_attr_max_age
.attr
,
810 &dev_attr_ageing_time
.attr
,
811 &dev_attr_stp_state
.attr
,
812 &dev_attr_group_fwd_mask
.attr
,
813 &dev_attr_priority
.attr
,
814 &dev_attr_bridge_id
.attr
,
815 &dev_attr_root_id
.attr
,
816 &dev_attr_root_path_cost
.attr
,
817 &dev_attr_root_port
.attr
,
818 &dev_attr_topology_change
.attr
,
819 &dev_attr_topology_change_detected
.attr
,
820 &dev_attr_hello_timer
.attr
,
821 &dev_attr_tcn_timer
.attr
,
822 &dev_attr_topology_change_timer
.attr
,
823 &dev_attr_gc_timer
.attr
,
824 &dev_attr_group_addr
.attr
,
825 &dev_attr_flush
.attr
,
826 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
827 &dev_attr_multicast_router
.attr
,
828 &dev_attr_multicast_snooping
.attr
,
829 &dev_attr_multicast_querier
.attr
,
830 &dev_attr_multicast_query_use_ifaddr
.attr
,
831 &dev_attr_hash_elasticity
.attr
,
832 &dev_attr_hash_max
.attr
,
833 &dev_attr_multicast_last_member_count
.attr
,
834 &dev_attr_multicast_startup_query_count
.attr
,
835 &dev_attr_multicast_last_member_interval
.attr
,
836 &dev_attr_multicast_membership_interval
.attr
,
837 &dev_attr_multicast_querier_interval
.attr
,
838 &dev_attr_multicast_query_interval
.attr
,
839 &dev_attr_multicast_query_response_interval
.attr
,
840 &dev_attr_multicast_startup_query_interval
.attr
,
841 &dev_attr_multicast_stats_enabled
.attr
,
842 &dev_attr_multicast_igmp_version
.attr
,
843 #if IS_ENABLED(CONFIG_IPV6)
844 &dev_attr_multicast_mld_version
.attr
,
847 #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
848 &dev_attr_nf_call_iptables
.attr
,
849 &dev_attr_nf_call_ip6tables
.attr
,
850 &dev_attr_nf_call_arptables
.attr
,
852 #ifdef CONFIG_BRIDGE_VLAN_FILTERING
853 &dev_attr_vlan_filtering
.attr
,
854 &dev_attr_vlan_protocol
.attr
,
855 &dev_attr_default_pvid
.attr
,
856 &dev_attr_vlan_stats_enabled
.attr
,
861 static const struct attribute_group bridge_group
= {
862 .name
= SYSFS_BRIDGE_ATTR
,
863 .attrs
= bridge_attrs
,
867 * Export the forwarding information table as a binary file
868 * The records are struct __fdb_entry.
870 * Returns the number of bytes read.
872 static ssize_t
brforward_read(struct file
*filp
, struct kobject
*kobj
,
873 struct bin_attribute
*bin_attr
,
874 char *buf
, loff_t off
, size_t count
)
876 struct device
*dev
= kobj_to_dev(kobj
);
877 struct net_bridge
*br
= to_bridge(dev
);
880 /* must read whole records */
881 if (off
% sizeof(struct __fdb_entry
) != 0)
884 n
= br_fdb_fillbuf(br
, buf
,
885 count
/ sizeof(struct __fdb_entry
),
886 off
/ sizeof(struct __fdb_entry
));
889 n
*= sizeof(struct __fdb_entry
);
894 static struct bin_attribute bridge_forward
= {
895 .attr
= { .name
= SYSFS_BRIDGE_FDB
,
897 .read
= brforward_read
,
901 * Add entries in sysfs onto the existing network class device
903 * Adds a attribute group "bridge" containing tuning parameters.
904 * Binary attribute containing the forward table
905 * Sub directory to hold links to interfaces.
907 * Note: the ifobj exists only to be a subdirectory
908 * to hold links. The ifobj exists in same data structure
909 * as it's parent the bridge so reference counting works.
911 int br_sysfs_addbr(struct net_device
*dev
)
913 struct kobject
*brobj
= &dev
->dev
.kobj
;
914 struct net_bridge
*br
= netdev_priv(dev
);
917 err
= sysfs_create_group(brobj
, &bridge_group
);
919 pr_info("%s: can't create group %s/%s\n",
920 __func__
, dev
->name
, bridge_group
.name
);
924 err
= sysfs_create_bin_file(brobj
, &bridge_forward
);
926 pr_info("%s: can't create attribute file %s/%s\n",
927 __func__
, dev
->name
, bridge_forward
.attr
.name
);
931 br
->ifobj
= kobject_create_and_add(SYSFS_BRIDGE_PORT_SUBDIR
, brobj
);
933 pr_info("%s: can't add kobject (directory) %s/%s\n",
934 __func__
, dev
->name
, SYSFS_BRIDGE_PORT_SUBDIR
);
940 sysfs_remove_bin_file(&dev
->dev
.kobj
, &bridge_forward
);
942 sysfs_remove_group(&dev
->dev
.kobj
, &bridge_group
);
948 void br_sysfs_delbr(struct net_device
*dev
)
950 struct kobject
*kobj
= &dev
->dev
.kobj
;
951 struct net_bridge
*br
= netdev_priv(dev
);
953 kobject_put(br
->ifobj
);
954 sysfs_remove_bin_file(kobj
, &bridge_forward
);
955 sysfs_remove_group(kobj
, &bridge_group
);