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_bridge(cd) ((struct net_bridge *)netdev_priv(to_net_dev(cd)))
28 * Common code for storing bridge parameters.
30 static ssize_t
store_bridge_parm(struct device
*d
,
31 const char *buf
, size_t len
,
32 int (*set
)(struct net_bridge
*, unsigned long))
34 struct net_bridge
*br
= to_bridge(d
);
39 if (!ns_capable(dev_net(br
->dev
)->user_ns
, CAP_NET_ADMIN
))
42 val
= simple_strtoul(buf
, &endp
, 0);
47 return restart_syscall();
49 err
= (*set
)(br
, val
);
51 netdev_state_change(br
->dev
);
54 return err
? err
: len
;
58 static ssize_t
forward_delay_show(struct device
*d
,
59 struct device_attribute
*attr
, char *buf
)
61 struct net_bridge
*br
= to_bridge(d
);
62 return sprintf(buf
, "%lu\n", jiffies_to_clock_t(br
->forward_delay
));
65 static ssize_t
forward_delay_store(struct device
*d
,
66 struct device_attribute
*attr
,
67 const char *buf
, size_t len
)
69 return store_bridge_parm(d
, buf
, len
, br_set_forward_delay
);
71 static DEVICE_ATTR_RW(forward_delay
);
73 static ssize_t
hello_time_show(struct device
*d
, struct device_attribute
*attr
,
76 return sprintf(buf
, "%lu\n",
77 jiffies_to_clock_t(to_bridge(d
)->hello_time
));
80 static ssize_t
hello_time_store(struct device
*d
,
81 struct device_attribute
*attr
, const char *buf
,
84 return store_bridge_parm(d
, buf
, len
, br_set_hello_time
);
86 static DEVICE_ATTR_RW(hello_time
);
88 static ssize_t
max_age_show(struct device
*d
, struct device_attribute
*attr
,
91 return sprintf(buf
, "%lu\n",
92 jiffies_to_clock_t(to_bridge(d
)->max_age
));
95 static ssize_t
max_age_store(struct device
*d
, struct device_attribute
*attr
,
96 const char *buf
, size_t len
)
98 return store_bridge_parm(d
, buf
, len
, br_set_max_age
);
100 static DEVICE_ATTR_RW(max_age
);
102 static ssize_t
ageing_time_show(struct device
*d
,
103 struct device_attribute
*attr
, char *buf
)
105 struct net_bridge
*br
= to_bridge(d
);
106 return sprintf(buf
, "%lu\n", jiffies_to_clock_t(br
->ageing_time
));
109 static int set_ageing_time(struct net_bridge
*br
, unsigned long val
)
111 return br_set_ageing_time(br
, val
);
114 static ssize_t
ageing_time_store(struct device
*d
,
115 struct device_attribute
*attr
,
116 const char *buf
, size_t len
)
118 return store_bridge_parm(d
, buf
, len
, set_ageing_time
);
120 static DEVICE_ATTR_RW(ageing_time
);
122 static ssize_t
stp_state_show(struct device
*d
,
123 struct device_attribute
*attr
, char *buf
)
125 struct net_bridge
*br
= to_bridge(d
);
126 return sprintf(buf
, "%d\n", br
->stp_enabled
);
130 static int set_stp_state(struct net_bridge
*br
, unsigned long val
)
132 br_stp_set_enabled(br
, val
);
137 static ssize_t
stp_state_store(struct device
*d
,
138 struct device_attribute
*attr
, const char *buf
,
141 return store_bridge_parm(d
, buf
, len
, set_stp_state
);
143 static DEVICE_ATTR_RW(stp_state
);
145 static ssize_t
group_fwd_mask_show(struct device
*d
,
146 struct device_attribute
*attr
,
149 struct net_bridge
*br
= to_bridge(d
);
150 return sprintf(buf
, "%#x\n", br
->group_fwd_mask
);
153 static int set_group_fwd_mask(struct net_bridge
*br
, unsigned long val
)
155 if (val
& BR_GROUPFWD_RESTRICTED
)
158 br
->group_fwd_mask
= val
;
163 static ssize_t
group_fwd_mask_store(struct device
*d
,
164 struct device_attribute
*attr
,
168 return store_bridge_parm(d
, buf
, len
, set_group_fwd_mask
);
170 static DEVICE_ATTR_RW(group_fwd_mask
);
172 static ssize_t
priority_show(struct device
*d
, struct device_attribute
*attr
,
175 struct net_bridge
*br
= to_bridge(d
);
176 return sprintf(buf
, "%d\n",
177 (br
->bridge_id
.prio
[0] << 8) | br
->bridge_id
.prio
[1]);
180 static int set_priority(struct net_bridge
*br
, unsigned long val
)
182 br_stp_set_bridge_priority(br
, (u16
) val
);
186 static ssize_t
priority_store(struct device
*d
, struct device_attribute
*attr
,
187 const char *buf
, size_t len
)
189 return store_bridge_parm(d
, buf
, len
, set_priority
);
191 static DEVICE_ATTR_RW(priority
);
193 static ssize_t
root_id_show(struct device
*d
, struct device_attribute
*attr
,
196 return br_show_bridge_id(buf
, &to_bridge(d
)->designated_root
);
198 static DEVICE_ATTR_RO(root_id
);
200 static ssize_t
bridge_id_show(struct device
*d
, struct device_attribute
*attr
,
203 return br_show_bridge_id(buf
, &to_bridge(d
)->bridge_id
);
205 static DEVICE_ATTR_RO(bridge_id
);
207 static ssize_t
root_port_show(struct device
*d
, struct device_attribute
*attr
,
210 return sprintf(buf
, "%d\n", to_bridge(d
)->root_port
);
212 static DEVICE_ATTR_RO(root_port
);
214 static ssize_t
root_path_cost_show(struct device
*d
,
215 struct device_attribute
*attr
, char *buf
)
217 return sprintf(buf
, "%d\n", to_bridge(d
)->root_path_cost
);
219 static DEVICE_ATTR_RO(root_path_cost
);
221 static ssize_t
topology_change_show(struct device
*d
,
222 struct device_attribute
*attr
, char *buf
)
224 return sprintf(buf
, "%d\n", to_bridge(d
)->topology_change
);
226 static DEVICE_ATTR_RO(topology_change
);
228 static ssize_t
topology_change_detected_show(struct device
*d
,
229 struct device_attribute
*attr
,
232 struct net_bridge
*br
= to_bridge(d
);
233 return sprintf(buf
, "%d\n", br
->topology_change_detected
);
235 static DEVICE_ATTR_RO(topology_change_detected
);
237 static ssize_t
hello_timer_show(struct device
*d
,
238 struct device_attribute
*attr
, char *buf
)
240 struct net_bridge
*br
= to_bridge(d
);
241 return sprintf(buf
, "%ld\n", br_timer_value(&br
->hello_timer
));
243 static DEVICE_ATTR_RO(hello_timer
);
245 static ssize_t
tcn_timer_show(struct device
*d
, struct device_attribute
*attr
,
248 struct net_bridge
*br
= to_bridge(d
);
249 return sprintf(buf
, "%ld\n", br_timer_value(&br
->tcn_timer
));
251 static DEVICE_ATTR_RO(tcn_timer
);
253 static ssize_t
topology_change_timer_show(struct device
*d
,
254 struct device_attribute
*attr
,
257 struct net_bridge
*br
= to_bridge(d
);
258 return sprintf(buf
, "%ld\n", br_timer_value(&br
->topology_change_timer
));
260 static DEVICE_ATTR_RO(topology_change_timer
);
262 static ssize_t
gc_timer_show(struct device
*d
, struct device_attribute
*attr
,
265 struct net_bridge
*br
= to_bridge(d
);
266 return sprintf(buf
, "%ld\n", br_timer_value(&br
->gc_timer
));
268 static DEVICE_ATTR_RO(gc_timer
);
270 static ssize_t
group_addr_show(struct device
*d
,
271 struct device_attribute
*attr
, char *buf
)
273 struct net_bridge
*br
= to_bridge(d
);
274 return sprintf(buf
, "%x:%x:%x:%x:%x:%x\n",
275 br
->group_addr
[0], br
->group_addr
[1],
276 br
->group_addr
[2], br
->group_addr
[3],
277 br
->group_addr
[4], br
->group_addr
[5]);
280 static ssize_t
group_addr_store(struct device
*d
,
281 struct device_attribute
*attr
,
282 const char *buf
, size_t len
)
284 struct net_bridge
*br
= to_bridge(d
);
288 if (!ns_capable(dev_net(br
->dev
)->user_ns
, CAP_NET_ADMIN
))
291 if (sscanf(buf
, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx",
292 &new_addr
[0], &new_addr
[1], &new_addr
[2],
293 &new_addr
[3], &new_addr
[4], &new_addr
[5]) != 6)
296 if (!is_link_local_ether_addr(new_addr
))
299 if (new_addr
[5] == 1 || /* 802.3x Pause address */
300 new_addr
[5] == 2 || /* 802.3ad Slow protocols */
301 new_addr
[5] == 3) /* 802.1X PAE address */
305 return restart_syscall();
307 spin_lock_bh(&br
->lock
);
308 for (i
= 0; i
< 6; i
++)
309 br
->group_addr
[i
] = new_addr
[i
];
310 spin_unlock_bh(&br
->lock
);
312 br
->group_addr_set
= true;
313 br_recalculate_fwd_mask(br
);
314 netdev_state_change(br
->dev
);
321 static DEVICE_ATTR_RW(group_addr
);
323 static int set_flush(struct net_bridge
*br
, unsigned long val
)
329 static ssize_t
flush_store(struct device
*d
,
330 struct device_attribute
*attr
,
331 const char *buf
, size_t len
)
333 return store_bridge_parm(d
, buf
, len
, set_flush
);
335 static DEVICE_ATTR_WO(flush
);
337 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
338 static ssize_t
multicast_router_show(struct device
*d
,
339 struct device_attribute
*attr
, char *buf
)
341 struct net_bridge
*br
= to_bridge(d
);
342 return sprintf(buf
, "%d\n", br
->multicast_router
);
345 static ssize_t
multicast_router_store(struct device
*d
,
346 struct device_attribute
*attr
,
347 const char *buf
, size_t len
)
349 return store_bridge_parm(d
, buf
, len
, br_multicast_set_router
);
351 static DEVICE_ATTR_RW(multicast_router
);
353 static ssize_t
multicast_snooping_show(struct device
*d
,
354 struct device_attribute
*attr
,
357 struct net_bridge
*br
= to_bridge(d
);
358 return sprintf(buf
, "%d\n", !br
->multicast_disabled
);
361 static ssize_t
multicast_snooping_store(struct device
*d
,
362 struct device_attribute
*attr
,
363 const char *buf
, size_t len
)
365 return store_bridge_parm(d
, buf
, len
, br_multicast_toggle
);
367 static DEVICE_ATTR_RW(multicast_snooping
);
369 static ssize_t
multicast_query_use_ifaddr_show(struct device
*d
,
370 struct device_attribute
*attr
,
373 struct net_bridge
*br
= to_bridge(d
);
374 return sprintf(buf
, "%d\n", br
->multicast_query_use_ifaddr
);
377 static int set_query_use_ifaddr(struct net_bridge
*br
, unsigned long val
)
379 br
->multicast_query_use_ifaddr
= !!val
;
384 multicast_query_use_ifaddr_store(struct device
*d
,
385 struct device_attribute
*attr
,
386 const char *buf
, size_t len
)
388 return store_bridge_parm(d
, buf
, len
, set_query_use_ifaddr
);
390 static DEVICE_ATTR_RW(multicast_query_use_ifaddr
);
392 static ssize_t
multicast_querier_show(struct device
*d
,
393 struct device_attribute
*attr
,
396 struct net_bridge
*br
= to_bridge(d
);
397 return sprintf(buf
, "%d\n", br
->multicast_querier
);
400 static ssize_t
multicast_querier_store(struct device
*d
,
401 struct device_attribute
*attr
,
402 const char *buf
, size_t len
)
404 return store_bridge_parm(d
, buf
, len
, br_multicast_set_querier
);
406 static DEVICE_ATTR_RW(multicast_querier
);
408 static ssize_t
hash_elasticity_show(struct device
*d
,
409 struct device_attribute
*attr
, char *buf
)
411 struct net_bridge
*br
= to_bridge(d
);
412 return sprintf(buf
, "%u\n", br
->hash_elasticity
);
415 static int set_elasticity(struct net_bridge
*br
, unsigned long val
)
417 br
->hash_elasticity
= val
;
421 static ssize_t
hash_elasticity_store(struct device
*d
,
422 struct device_attribute
*attr
,
423 const char *buf
, size_t len
)
425 return store_bridge_parm(d
, buf
, len
, set_elasticity
);
427 static DEVICE_ATTR_RW(hash_elasticity
);
429 static ssize_t
hash_max_show(struct device
*d
, struct device_attribute
*attr
,
432 struct net_bridge
*br
= to_bridge(d
);
433 return sprintf(buf
, "%u\n", br
->hash_max
);
436 static ssize_t
hash_max_store(struct device
*d
, struct device_attribute
*attr
,
437 const char *buf
, size_t len
)
439 return store_bridge_parm(d
, buf
, len
, br_multicast_set_hash_max
);
441 static DEVICE_ATTR_RW(hash_max
);
443 static ssize_t
multicast_igmp_version_show(struct device
*d
,
444 struct device_attribute
*attr
,
447 struct net_bridge
*br
= to_bridge(d
);
449 return sprintf(buf
, "%u\n", br
->multicast_igmp_version
);
452 static ssize_t
multicast_igmp_version_store(struct device
*d
,
453 struct device_attribute
*attr
,
454 const char *buf
, size_t len
)
456 return store_bridge_parm(d
, buf
, len
, br_multicast_set_igmp_version
);
458 static DEVICE_ATTR_RW(multicast_igmp_version
);
460 static ssize_t
multicast_last_member_count_show(struct device
*d
,
461 struct device_attribute
*attr
,
464 struct net_bridge
*br
= to_bridge(d
);
465 return sprintf(buf
, "%u\n", br
->multicast_last_member_count
);
468 static int set_last_member_count(struct net_bridge
*br
, unsigned long val
)
470 br
->multicast_last_member_count
= val
;
474 static ssize_t
multicast_last_member_count_store(struct device
*d
,
475 struct device_attribute
*attr
,
476 const char *buf
, size_t len
)
478 return store_bridge_parm(d
, buf
, len
, set_last_member_count
);
480 static DEVICE_ATTR_RW(multicast_last_member_count
);
482 static ssize_t
multicast_startup_query_count_show(
483 struct device
*d
, struct device_attribute
*attr
, char *buf
)
485 struct net_bridge
*br
= to_bridge(d
);
486 return sprintf(buf
, "%u\n", br
->multicast_startup_query_count
);
489 static int set_startup_query_count(struct net_bridge
*br
, unsigned long val
)
491 br
->multicast_startup_query_count
= val
;
495 static ssize_t
multicast_startup_query_count_store(
496 struct device
*d
, struct device_attribute
*attr
, const char *buf
,
499 return store_bridge_parm(d
, buf
, len
, set_startup_query_count
);
501 static DEVICE_ATTR_RW(multicast_startup_query_count
);
503 static ssize_t
multicast_last_member_interval_show(
504 struct device
*d
, struct device_attribute
*attr
, char *buf
)
506 struct net_bridge
*br
= to_bridge(d
);
507 return sprintf(buf
, "%lu\n",
508 jiffies_to_clock_t(br
->multicast_last_member_interval
));
511 static int set_last_member_interval(struct net_bridge
*br
, unsigned long val
)
513 br
->multicast_last_member_interval
= clock_t_to_jiffies(val
);
517 static ssize_t
multicast_last_member_interval_store(
518 struct device
*d
, struct device_attribute
*attr
, const char *buf
,
521 return store_bridge_parm(d
, buf
, len
, set_last_member_interval
);
523 static DEVICE_ATTR_RW(multicast_last_member_interval
);
525 static ssize_t
multicast_membership_interval_show(
526 struct device
*d
, struct device_attribute
*attr
, char *buf
)
528 struct net_bridge
*br
= to_bridge(d
);
529 return sprintf(buf
, "%lu\n",
530 jiffies_to_clock_t(br
->multicast_membership_interval
));
533 static int set_membership_interval(struct net_bridge
*br
, unsigned long val
)
535 br
->multicast_membership_interval
= clock_t_to_jiffies(val
);
539 static ssize_t
multicast_membership_interval_store(
540 struct device
*d
, struct device_attribute
*attr
, const char *buf
,
543 return store_bridge_parm(d
, buf
, len
, set_membership_interval
);
545 static DEVICE_ATTR_RW(multicast_membership_interval
);
547 static ssize_t
multicast_querier_interval_show(struct device
*d
,
548 struct device_attribute
*attr
,
551 struct net_bridge
*br
= to_bridge(d
);
552 return sprintf(buf
, "%lu\n",
553 jiffies_to_clock_t(br
->multicast_querier_interval
));
556 static int set_querier_interval(struct net_bridge
*br
, unsigned long val
)
558 br
->multicast_querier_interval
= clock_t_to_jiffies(val
);
562 static ssize_t
multicast_querier_interval_store(struct device
*d
,
563 struct device_attribute
*attr
,
564 const char *buf
, size_t len
)
566 return store_bridge_parm(d
, buf
, len
, set_querier_interval
);
568 static DEVICE_ATTR_RW(multicast_querier_interval
);
570 static ssize_t
multicast_query_interval_show(struct device
*d
,
571 struct device_attribute
*attr
,
574 struct net_bridge
*br
= to_bridge(d
);
575 return sprintf(buf
, "%lu\n",
576 jiffies_to_clock_t(br
->multicast_query_interval
));
579 static int set_query_interval(struct net_bridge
*br
, unsigned long val
)
581 br
->multicast_query_interval
= clock_t_to_jiffies(val
);
585 static ssize_t
multicast_query_interval_store(struct device
*d
,
586 struct device_attribute
*attr
,
587 const char *buf
, size_t len
)
589 return store_bridge_parm(d
, buf
, len
, set_query_interval
);
591 static DEVICE_ATTR_RW(multicast_query_interval
);
593 static ssize_t
multicast_query_response_interval_show(
594 struct device
*d
, struct device_attribute
*attr
, char *buf
)
596 struct net_bridge
*br
= to_bridge(d
);
599 jiffies_to_clock_t(br
->multicast_query_response_interval
));
602 static int set_query_response_interval(struct net_bridge
*br
, unsigned long val
)
604 br
->multicast_query_response_interval
= clock_t_to_jiffies(val
);
608 static ssize_t
multicast_query_response_interval_store(
609 struct device
*d
, struct device_attribute
*attr
, const char *buf
,
612 return store_bridge_parm(d
, buf
, len
, set_query_response_interval
);
614 static DEVICE_ATTR_RW(multicast_query_response_interval
);
616 static ssize_t
multicast_startup_query_interval_show(
617 struct device
*d
, struct device_attribute
*attr
, char *buf
)
619 struct net_bridge
*br
= to_bridge(d
);
622 jiffies_to_clock_t(br
->multicast_startup_query_interval
));
625 static int set_startup_query_interval(struct net_bridge
*br
, unsigned long val
)
627 br
->multicast_startup_query_interval
= clock_t_to_jiffies(val
);
631 static ssize_t
multicast_startup_query_interval_store(
632 struct device
*d
, struct device_attribute
*attr
, const char *buf
,
635 return store_bridge_parm(d
, buf
, len
, set_startup_query_interval
);
637 static DEVICE_ATTR_RW(multicast_startup_query_interval
);
639 static ssize_t
multicast_stats_enabled_show(struct device
*d
,
640 struct device_attribute
*attr
,
643 struct net_bridge
*br
= to_bridge(d
);
645 return sprintf(buf
, "%u\n", br
->multicast_stats_enabled
);
648 static int set_stats_enabled(struct net_bridge
*br
, unsigned long val
)
650 br
->multicast_stats_enabled
= !!val
;
654 static ssize_t
multicast_stats_enabled_store(struct device
*d
,
655 struct device_attribute
*attr
,
659 return store_bridge_parm(d
, buf
, len
, set_stats_enabled
);
661 static DEVICE_ATTR_RW(multicast_stats_enabled
);
663 #if IS_ENABLED(CONFIG_IPV6)
664 static ssize_t
multicast_mld_version_show(struct device
*d
,
665 struct device_attribute
*attr
,
668 struct net_bridge
*br
= to_bridge(d
);
670 return sprintf(buf
, "%u\n", br
->multicast_mld_version
);
673 static ssize_t
multicast_mld_version_store(struct device
*d
,
674 struct device_attribute
*attr
,
675 const char *buf
, size_t len
)
677 return store_bridge_parm(d
, buf
, len
, br_multicast_set_mld_version
);
679 static DEVICE_ATTR_RW(multicast_mld_version
);
682 #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
683 static ssize_t
nf_call_iptables_show(
684 struct device
*d
, struct device_attribute
*attr
, char *buf
)
686 struct net_bridge
*br
= to_bridge(d
);
687 return sprintf(buf
, "%u\n", br
->nf_call_iptables
);
690 static int set_nf_call_iptables(struct net_bridge
*br
, unsigned long val
)
692 br
->nf_call_iptables
= val
? true : false;
696 static ssize_t
nf_call_iptables_store(
697 struct device
*d
, struct device_attribute
*attr
, const char *buf
,
700 return store_bridge_parm(d
, buf
, len
, set_nf_call_iptables
);
702 static DEVICE_ATTR_RW(nf_call_iptables
);
704 static ssize_t
nf_call_ip6tables_show(
705 struct device
*d
, struct device_attribute
*attr
, char *buf
)
707 struct net_bridge
*br
= to_bridge(d
);
708 return sprintf(buf
, "%u\n", br
->nf_call_ip6tables
);
711 static int set_nf_call_ip6tables(struct net_bridge
*br
, unsigned long val
)
713 br
->nf_call_ip6tables
= val
? true : false;
717 static ssize_t
nf_call_ip6tables_store(
718 struct device
*d
, struct device_attribute
*attr
, const char *buf
,
721 return store_bridge_parm(d
, buf
, len
, set_nf_call_ip6tables
);
723 static DEVICE_ATTR_RW(nf_call_ip6tables
);
725 static ssize_t
nf_call_arptables_show(
726 struct device
*d
, struct device_attribute
*attr
, char *buf
)
728 struct net_bridge
*br
= to_bridge(d
);
729 return sprintf(buf
, "%u\n", br
->nf_call_arptables
);
732 static int set_nf_call_arptables(struct net_bridge
*br
, unsigned long val
)
734 br
->nf_call_arptables
= val
? true : false;
738 static ssize_t
nf_call_arptables_store(
739 struct device
*d
, struct device_attribute
*attr
, const char *buf
,
742 return store_bridge_parm(d
, buf
, len
, set_nf_call_arptables
);
744 static DEVICE_ATTR_RW(nf_call_arptables
);
746 #ifdef CONFIG_BRIDGE_VLAN_FILTERING
747 static ssize_t
vlan_filtering_show(struct device
*d
,
748 struct device_attribute
*attr
,
751 struct net_bridge
*br
= to_bridge(d
);
752 return sprintf(buf
, "%d\n", br
->vlan_enabled
);
755 static ssize_t
vlan_filtering_store(struct device
*d
,
756 struct device_attribute
*attr
,
757 const char *buf
, size_t len
)
759 return store_bridge_parm(d
, buf
, len
, br_vlan_filter_toggle
);
761 static DEVICE_ATTR_RW(vlan_filtering
);
763 static ssize_t
vlan_protocol_show(struct device
*d
,
764 struct device_attribute
*attr
,
767 struct net_bridge
*br
= to_bridge(d
);
768 return sprintf(buf
, "%#06x\n", ntohs(br
->vlan_proto
));
771 static ssize_t
vlan_protocol_store(struct device
*d
,
772 struct device_attribute
*attr
,
773 const char *buf
, size_t len
)
775 return store_bridge_parm(d
, buf
, len
, br_vlan_set_proto
);
777 static DEVICE_ATTR_RW(vlan_protocol
);
779 static ssize_t
default_pvid_show(struct device
*d
,
780 struct device_attribute
*attr
,
783 struct net_bridge
*br
= to_bridge(d
);
784 return sprintf(buf
, "%d\n", br
->default_pvid
);
787 static ssize_t
default_pvid_store(struct device
*d
,
788 struct device_attribute
*attr
,
789 const char *buf
, size_t len
)
791 return store_bridge_parm(d
, buf
, len
, br_vlan_set_default_pvid
);
793 static DEVICE_ATTR_RW(default_pvid
);
795 static ssize_t
vlan_stats_enabled_show(struct device
*d
,
796 struct device_attribute
*attr
,
799 struct net_bridge
*br
= to_bridge(d
);
800 return sprintf(buf
, "%u\n", br
->vlan_stats_enabled
);
803 static ssize_t
vlan_stats_enabled_store(struct device
*d
,
804 struct device_attribute
*attr
,
805 const char *buf
, size_t len
)
807 return store_bridge_parm(d
, buf
, len
, br_vlan_set_stats
);
809 static DEVICE_ATTR_RW(vlan_stats_enabled
);
812 static struct attribute
*bridge_attrs
[] = {
813 &dev_attr_forward_delay
.attr
,
814 &dev_attr_hello_time
.attr
,
815 &dev_attr_max_age
.attr
,
816 &dev_attr_ageing_time
.attr
,
817 &dev_attr_stp_state
.attr
,
818 &dev_attr_group_fwd_mask
.attr
,
819 &dev_attr_priority
.attr
,
820 &dev_attr_bridge_id
.attr
,
821 &dev_attr_root_id
.attr
,
822 &dev_attr_root_path_cost
.attr
,
823 &dev_attr_root_port
.attr
,
824 &dev_attr_topology_change
.attr
,
825 &dev_attr_topology_change_detected
.attr
,
826 &dev_attr_hello_timer
.attr
,
827 &dev_attr_tcn_timer
.attr
,
828 &dev_attr_topology_change_timer
.attr
,
829 &dev_attr_gc_timer
.attr
,
830 &dev_attr_group_addr
.attr
,
831 &dev_attr_flush
.attr
,
832 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
833 &dev_attr_multicast_router
.attr
,
834 &dev_attr_multicast_snooping
.attr
,
835 &dev_attr_multicast_querier
.attr
,
836 &dev_attr_multicast_query_use_ifaddr
.attr
,
837 &dev_attr_hash_elasticity
.attr
,
838 &dev_attr_hash_max
.attr
,
839 &dev_attr_multicast_last_member_count
.attr
,
840 &dev_attr_multicast_startup_query_count
.attr
,
841 &dev_attr_multicast_last_member_interval
.attr
,
842 &dev_attr_multicast_membership_interval
.attr
,
843 &dev_attr_multicast_querier_interval
.attr
,
844 &dev_attr_multicast_query_interval
.attr
,
845 &dev_attr_multicast_query_response_interval
.attr
,
846 &dev_attr_multicast_startup_query_interval
.attr
,
847 &dev_attr_multicast_stats_enabled
.attr
,
848 &dev_attr_multicast_igmp_version
.attr
,
849 #if IS_ENABLED(CONFIG_IPV6)
850 &dev_attr_multicast_mld_version
.attr
,
853 #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
854 &dev_attr_nf_call_iptables
.attr
,
855 &dev_attr_nf_call_ip6tables
.attr
,
856 &dev_attr_nf_call_arptables
.attr
,
858 #ifdef CONFIG_BRIDGE_VLAN_FILTERING
859 &dev_attr_vlan_filtering
.attr
,
860 &dev_attr_vlan_protocol
.attr
,
861 &dev_attr_default_pvid
.attr
,
862 &dev_attr_vlan_stats_enabled
.attr
,
867 static struct attribute_group bridge_group
= {
868 .name
= SYSFS_BRIDGE_ATTR
,
869 .attrs
= bridge_attrs
,
873 * Export the forwarding information table as a binary file
874 * The records are struct __fdb_entry.
876 * Returns the number of bytes read.
878 static ssize_t
brforward_read(struct file
*filp
, struct kobject
*kobj
,
879 struct bin_attribute
*bin_attr
,
880 char *buf
, loff_t off
, size_t count
)
882 struct device
*dev
= kobj_to_dev(kobj
);
883 struct net_bridge
*br
= to_bridge(dev
);
886 /* must read whole records */
887 if (off
% sizeof(struct __fdb_entry
) != 0)
890 n
= br_fdb_fillbuf(br
, buf
,
891 count
/ sizeof(struct __fdb_entry
),
892 off
/ sizeof(struct __fdb_entry
));
895 n
*= sizeof(struct __fdb_entry
);
900 static struct bin_attribute bridge_forward
= {
901 .attr
= { .name
= SYSFS_BRIDGE_FDB
,
903 .read
= brforward_read
,
907 * Add entries in sysfs onto the existing network class device
909 * Adds a attribute group "bridge" containing tuning parameters.
910 * Binary attribute containing the forward table
911 * Sub directory to hold links to interfaces.
913 * Note: the ifobj exists only to be a subdirectory
914 * to hold links. The ifobj exists in same data structure
915 * as it's parent the bridge so reference counting works.
917 int br_sysfs_addbr(struct net_device
*dev
)
919 struct kobject
*brobj
= &dev
->dev
.kobj
;
920 struct net_bridge
*br
= netdev_priv(dev
);
923 err
= sysfs_create_group(brobj
, &bridge_group
);
925 pr_info("%s: can't create group %s/%s\n",
926 __func__
, dev
->name
, bridge_group
.name
);
930 err
= sysfs_create_bin_file(brobj
, &bridge_forward
);
932 pr_info("%s: can't create attribute file %s/%s\n",
933 __func__
, dev
->name
, bridge_forward
.attr
.name
);
937 br
->ifobj
= kobject_create_and_add(SYSFS_BRIDGE_PORT_SUBDIR
, brobj
);
939 pr_info("%s: can't add kobject (directory) %s/%s\n",
940 __func__
, dev
->name
, SYSFS_BRIDGE_PORT_SUBDIR
);
946 sysfs_remove_bin_file(&dev
->dev
.kobj
, &bridge_forward
);
948 sysfs_remove_group(&dev
->dev
.kobj
, &bridge_group
);
954 void br_sysfs_delbr(struct net_device
*dev
)
956 struct kobject
*kobj
= &dev
->dev
.kobj
;
957 struct net_bridge
*br
= netdev_priv(dev
);
959 kobject_put(br
->ifobj
);
960 sysfs_remove_bin_file(kobj
, &bridge_forward
);
961 sysfs_remove_group(kobj
, &bridge_group
);