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
, "%x:%x:%x:%x:%x:%x\n",
276 br
->group_addr
[0], br
->group_addr
[1],
277 br
->group_addr
[2], br
->group_addr
[3],
278 br
->group_addr
[4], br
->group_addr
[5]);
281 static ssize_t
group_addr_store(struct device
*d
,
282 struct device_attribute
*attr
,
283 const char *buf
, size_t len
)
285 struct net_bridge
*br
= to_bridge(d
);
289 if (!ns_capable(dev_net(br
->dev
)->user_ns
, CAP_NET_ADMIN
))
292 if (sscanf(buf
, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx",
293 &new_addr
[0], &new_addr
[1], &new_addr
[2],
294 &new_addr
[3], &new_addr
[4], &new_addr
[5]) != 6)
297 if (!is_link_local_ether_addr(new_addr
))
300 if (new_addr
[5] == 1 || /* 802.3x Pause address */
301 new_addr
[5] == 2 || /* 802.3ad Slow protocols */
302 new_addr
[5] == 3) /* 802.1X PAE address */
306 return restart_syscall();
308 spin_lock_bh(&br
->lock
);
309 for (i
= 0; i
< 6; i
++)
310 br
->group_addr
[i
] = new_addr
[i
];
311 spin_unlock_bh(&br
->lock
);
313 br
->group_addr_set
= true;
314 br_recalculate_fwd_mask(br
);
315 netdev_state_change(br
->dev
);
322 static DEVICE_ATTR_RW(group_addr
);
324 static int set_flush(struct net_bridge
*br
, unsigned long val
)
330 static ssize_t
flush_store(struct device
*d
,
331 struct device_attribute
*attr
,
332 const char *buf
, size_t len
)
334 return store_bridge_parm(d
, buf
, len
, set_flush
);
336 static DEVICE_ATTR_WO(flush
);
338 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
339 static ssize_t
multicast_router_show(struct device
*d
,
340 struct device_attribute
*attr
, char *buf
)
342 struct net_bridge
*br
= to_bridge(d
);
343 return sprintf(buf
, "%d\n", br
->multicast_router
);
346 static ssize_t
multicast_router_store(struct device
*d
,
347 struct device_attribute
*attr
,
348 const char *buf
, size_t len
)
350 return store_bridge_parm(d
, buf
, len
, br_multicast_set_router
);
352 static DEVICE_ATTR_RW(multicast_router
);
354 static ssize_t
multicast_snooping_show(struct device
*d
,
355 struct device_attribute
*attr
,
358 struct net_bridge
*br
= to_bridge(d
);
359 return sprintf(buf
, "%d\n", !br
->multicast_disabled
);
362 static ssize_t
multicast_snooping_store(struct device
*d
,
363 struct device_attribute
*attr
,
364 const char *buf
, size_t len
)
366 return store_bridge_parm(d
, buf
, len
, br_multicast_toggle
);
368 static DEVICE_ATTR_RW(multicast_snooping
);
370 static ssize_t
multicast_query_use_ifaddr_show(struct device
*d
,
371 struct device_attribute
*attr
,
374 struct net_bridge
*br
= to_bridge(d
);
375 return sprintf(buf
, "%d\n", br
->multicast_query_use_ifaddr
);
378 static int set_query_use_ifaddr(struct net_bridge
*br
, unsigned long val
)
380 br
->multicast_query_use_ifaddr
= !!val
;
385 multicast_query_use_ifaddr_store(struct device
*d
,
386 struct device_attribute
*attr
,
387 const char *buf
, size_t len
)
389 return store_bridge_parm(d
, buf
, len
, set_query_use_ifaddr
);
391 static DEVICE_ATTR_RW(multicast_query_use_ifaddr
);
393 static ssize_t
multicast_querier_show(struct device
*d
,
394 struct device_attribute
*attr
,
397 struct net_bridge
*br
= to_bridge(d
);
398 return sprintf(buf
, "%d\n", br
->multicast_querier
);
401 static ssize_t
multicast_querier_store(struct device
*d
,
402 struct device_attribute
*attr
,
403 const char *buf
, size_t len
)
405 return store_bridge_parm(d
, buf
, len
, br_multicast_set_querier
);
407 static DEVICE_ATTR_RW(multicast_querier
);
409 static ssize_t
hash_elasticity_show(struct device
*d
,
410 struct device_attribute
*attr
, char *buf
)
412 struct net_bridge
*br
= to_bridge(d
);
413 return sprintf(buf
, "%u\n", br
->hash_elasticity
);
416 static int set_elasticity(struct net_bridge
*br
, unsigned long val
)
418 br
->hash_elasticity
= val
;
422 static ssize_t
hash_elasticity_store(struct device
*d
,
423 struct device_attribute
*attr
,
424 const char *buf
, size_t len
)
426 return store_bridge_parm(d
, buf
, len
, set_elasticity
);
428 static DEVICE_ATTR_RW(hash_elasticity
);
430 static ssize_t
hash_max_show(struct device
*d
, struct device_attribute
*attr
,
433 struct net_bridge
*br
= to_bridge(d
);
434 return sprintf(buf
, "%u\n", br
->hash_max
);
437 static ssize_t
hash_max_store(struct device
*d
, struct device_attribute
*attr
,
438 const char *buf
, size_t len
)
440 return store_bridge_parm(d
, buf
, len
, br_multicast_set_hash_max
);
442 static DEVICE_ATTR_RW(hash_max
);
444 static ssize_t
multicast_igmp_version_show(struct device
*d
,
445 struct device_attribute
*attr
,
448 struct net_bridge
*br
= to_bridge(d
);
450 return sprintf(buf
, "%u\n", br
->multicast_igmp_version
);
453 static ssize_t
multicast_igmp_version_store(struct device
*d
,
454 struct device_attribute
*attr
,
455 const char *buf
, size_t len
)
457 return store_bridge_parm(d
, buf
, len
, br_multicast_set_igmp_version
);
459 static DEVICE_ATTR_RW(multicast_igmp_version
);
461 static ssize_t
multicast_last_member_count_show(struct device
*d
,
462 struct device_attribute
*attr
,
465 struct net_bridge
*br
= to_bridge(d
);
466 return sprintf(buf
, "%u\n", br
->multicast_last_member_count
);
469 static int set_last_member_count(struct net_bridge
*br
, unsigned long val
)
471 br
->multicast_last_member_count
= val
;
475 static ssize_t
multicast_last_member_count_store(struct device
*d
,
476 struct device_attribute
*attr
,
477 const char *buf
, size_t len
)
479 return store_bridge_parm(d
, buf
, len
, set_last_member_count
);
481 static DEVICE_ATTR_RW(multicast_last_member_count
);
483 static ssize_t
multicast_startup_query_count_show(
484 struct device
*d
, struct device_attribute
*attr
, char *buf
)
486 struct net_bridge
*br
= to_bridge(d
);
487 return sprintf(buf
, "%u\n", br
->multicast_startup_query_count
);
490 static int set_startup_query_count(struct net_bridge
*br
, unsigned long val
)
492 br
->multicast_startup_query_count
= val
;
496 static ssize_t
multicast_startup_query_count_store(
497 struct device
*d
, struct device_attribute
*attr
, const char *buf
,
500 return store_bridge_parm(d
, buf
, len
, set_startup_query_count
);
502 static DEVICE_ATTR_RW(multicast_startup_query_count
);
504 static ssize_t
multicast_last_member_interval_show(
505 struct device
*d
, struct device_attribute
*attr
, char *buf
)
507 struct net_bridge
*br
= to_bridge(d
);
508 return sprintf(buf
, "%lu\n",
509 jiffies_to_clock_t(br
->multicast_last_member_interval
));
512 static int set_last_member_interval(struct net_bridge
*br
, unsigned long val
)
514 br
->multicast_last_member_interval
= clock_t_to_jiffies(val
);
518 static ssize_t
multicast_last_member_interval_store(
519 struct device
*d
, struct device_attribute
*attr
, const char *buf
,
522 return store_bridge_parm(d
, buf
, len
, set_last_member_interval
);
524 static DEVICE_ATTR_RW(multicast_last_member_interval
);
526 static ssize_t
multicast_membership_interval_show(
527 struct device
*d
, struct device_attribute
*attr
, char *buf
)
529 struct net_bridge
*br
= to_bridge(d
);
530 return sprintf(buf
, "%lu\n",
531 jiffies_to_clock_t(br
->multicast_membership_interval
));
534 static int set_membership_interval(struct net_bridge
*br
, unsigned long val
)
536 br
->multicast_membership_interval
= clock_t_to_jiffies(val
);
540 static ssize_t
multicast_membership_interval_store(
541 struct device
*d
, struct device_attribute
*attr
, const char *buf
,
544 return store_bridge_parm(d
, buf
, len
, set_membership_interval
);
546 static DEVICE_ATTR_RW(multicast_membership_interval
);
548 static ssize_t
multicast_querier_interval_show(struct device
*d
,
549 struct device_attribute
*attr
,
552 struct net_bridge
*br
= to_bridge(d
);
553 return sprintf(buf
, "%lu\n",
554 jiffies_to_clock_t(br
->multicast_querier_interval
));
557 static int set_querier_interval(struct net_bridge
*br
, unsigned long val
)
559 br
->multicast_querier_interval
= clock_t_to_jiffies(val
);
563 static ssize_t
multicast_querier_interval_store(struct device
*d
,
564 struct device_attribute
*attr
,
565 const char *buf
, size_t len
)
567 return store_bridge_parm(d
, buf
, len
, set_querier_interval
);
569 static DEVICE_ATTR_RW(multicast_querier_interval
);
571 static ssize_t
multicast_query_interval_show(struct device
*d
,
572 struct device_attribute
*attr
,
575 struct net_bridge
*br
= to_bridge(d
);
576 return sprintf(buf
, "%lu\n",
577 jiffies_to_clock_t(br
->multicast_query_interval
));
580 static int set_query_interval(struct net_bridge
*br
, unsigned long val
)
582 br
->multicast_query_interval
= clock_t_to_jiffies(val
);
586 static ssize_t
multicast_query_interval_store(struct device
*d
,
587 struct device_attribute
*attr
,
588 const char *buf
, size_t len
)
590 return store_bridge_parm(d
, buf
, len
, set_query_interval
);
592 static DEVICE_ATTR_RW(multicast_query_interval
);
594 static ssize_t
multicast_query_response_interval_show(
595 struct device
*d
, struct device_attribute
*attr
, char *buf
)
597 struct net_bridge
*br
= to_bridge(d
);
600 jiffies_to_clock_t(br
->multicast_query_response_interval
));
603 static int set_query_response_interval(struct net_bridge
*br
, unsigned long val
)
605 br
->multicast_query_response_interval
= clock_t_to_jiffies(val
);
609 static ssize_t
multicast_query_response_interval_store(
610 struct device
*d
, struct device_attribute
*attr
, const char *buf
,
613 return store_bridge_parm(d
, buf
, len
, set_query_response_interval
);
615 static DEVICE_ATTR_RW(multicast_query_response_interval
);
617 static ssize_t
multicast_startup_query_interval_show(
618 struct device
*d
, struct device_attribute
*attr
, char *buf
)
620 struct net_bridge
*br
= to_bridge(d
);
623 jiffies_to_clock_t(br
->multicast_startup_query_interval
));
626 static int set_startup_query_interval(struct net_bridge
*br
, unsigned long val
)
628 br
->multicast_startup_query_interval
= clock_t_to_jiffies(val
);
632 static ssize_t
multicast_startup_query_interval_store(
633 struct device
*d
, struct device_attribute
*attr
, const char *buf
,
636 return store_bridge_parm(d
, buf
, len
, set_startup_query_interval
);
638 static DEVICE_ATTR_RW(multicast_startup_query_interval
);
640 static ssize_t
multicast_stats_enabled_show(struct device
*d
,
641 struct device_attribute
*attr
,
644 struct net_bridge
*br
= to_bridge(d
);
646 return sprintf(buf
, "%u\n", br
->multicast_stats_enabled
);
649 static int set_stats_enabled(struct net_bridge
*br
, unsigned long val
)
651 br
->multicast_stats_enabled
= !!val
;
655 static ssize_t
multicast_stats_enabled_store(struct device
*d
,
656 struct device_attribute
*attr
,
660 return store_bridge_parm(d
, buf
, len
, set_stats_enabled
);
662 static DEVICE_ATTR_RW(multicast_stats_enabled
);
664 #if IS_ENABLED(CONFIG_IPV6)
665 static ssize_t
multicast_mld_version_show(struct device
*d
,
666 struct device_attribute
*attr
,
669 struct net_bridge
*br
= to_bridge(d
);
671 return sprintf(buf
, "%u\n", br
->multicast_mld_version
);
674 static ssize_t
multicast_mld_version_store(struct device
*d
,
675 struct device_attribute
*attr
,
676 const char *buf
, size_t len
)
678 return store_bridge_parm(d
, buf
, len
, br_multicast_set_mld_version
);
680 static DEVICE_ATTR_RW(multicast_mld_version
);
683 #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
684 static ssize_t
nf_call_iptables_show(
685 struct device
*d
, struct device_attribute
*attr
, char *buf
)
687 struct net_bridge
*br
= to_bridge(d
);
688 return sprintf(buf
, "%u\n", br
->nf_call_iptables
);
691 static int set_nf_call_iptables(struct net_bridge
*br
, unsigned long val
)
693 br
->nf_call_iptables
= val
? true : false;
697 static ssize_t
nf_call_iptables_store(
698 struct device
*d
, struct device_attribute
*attr
, const char *buf
,
701 return store_bridge_parm(d
, buf
, len
, set_nf_call_iptables
);
703 static DEVICE_ATTR_RW(nf_call_iptables
);
705 static ssize_t
nf_call_ip6tables_show(
706 struct device
*d
, struct device_attribute
*attr
, char *buf
)
708 struct net_bridge
*br
= to_bridge(d
);
709 return sprintf(buf
, "%u\n", br
->nf_call_ip6tables
);
712 static int set_nf_call_ip6tables(struct net_bridge
*br
, unsigned long val
)
714 br
->nf_call_ip6tables
= val
? true : false;
718 static ssize_t
nf_call_ip6tables_store(
719 struct device
*d
, struct device_attribute
*attr
, const char *buf
,
722 return store_bridge_parm(d
, buf
, len
, set_nf_call_ip6tables
);
724 static DEVICE_ATTR_RW(nf_call_ip6tables
);
726 static ssize_t
nf_call_arptables_show(
727 struct device
*d
, struct device_attribute
*attr
, char *buf
)
729 struct net_bridge
*br
= to_bridge(d
);
730 return sprintf(buf
, "%u\n", br
->nf_call_arptables
);
733 static int set_nf_call_arptables(struct net_bridge
*br
, unsigned long val
)
735 br
->nf_call_arptables
= val
? true : false;
739 static ssize_t
nf_call_arptables_store(
740 struct device
*d
, struct device_attribute
*attr
, const char *buf
,
743 return store_bridge_parm(d
, buf
, len
, set_nf_call_arptables
);
745 static DEVICE_ATTR_RW(nf_call_arptables
);
747 #ifdef CONFIG_BRIDGE_VLAN_FILTERING
748 static ssize_t
vlan_filtering_show(struct device
*d
,
749 struct device_attribute
*attr
,
752 struct net_bridge
*br
= to_bridge(d
);
753 return sprintf(buf
, "%d\n", br
->vlan_enabled
);
756 static ssize_t
vlan_filtering_store(struct device
*d
,
757 struct device_attribute
*attr
,
758 const char *buf
, size_t len
)
760 return store_bridge_parm(d
, buf
, len
, br_vlan_filter_toggle
);
762 static DEVICE_ATTR_RW(vlan_filtering
);
764 static ssize_t
vlan_protocol_show(struct device
*d
,
765 struct device_attribute
*attr
,
768 struct net_bridge
*br
= to_bridge(d
);
769 return sprintf(buf
, "%#06x\n", ntohs(br
->vlan_proto
));
772 static ssize_t
vlan_protocol_store(struct device
*d
,
773 struct device_attribute
*attr
,
774 const char *buf
, size_t len
)
776 return store_bridge_parm(d
, buf
, len
, br_vlan_set_proto
);
778 static DEVICE_ATTR_RW(vlan_protocol
);
780 static ssize_t
default_pvid_show(struct device
*d
,
781 struct device_attribute
*attr
,
784 struct net_bridge
*br
= to_bridge(d
);
785 return sprintf(buf
, "%d\n", br
->default_pvid
);
788 static ssize_t
default_pvid_store(struct device
*d
,
789 struct device_attribute
*attr
,
790 const char *buf
, size_t len
)
792 return store_bridge_parm(d
, buf
, len
, br_vlan_set_default_pvid
);
794 static DEVICE_ATTR_RW(default_pvid
);
796 static ssize_t
vlan_stats_enabled_show(struct device
*d
,
797 struct device_attribute
*attr
,
800 struct net_bridge
*br
= to_bridge(d
);
801 return sprintf(buf
, "%u\n", br
->vlan_stats_enabled
);
804 static ssize_t
vlan_stats_enabled_store(struct device
*d
,
805 struct device_attribute
*attr
,
806 const char *buf
, size_t len
)
808 return store_bridge_parm(d
, buf
, len
, br_vlan_set_stats
);
810 static DEVICE_ATTR_RW(vlan_stats_enabled
);
813 static struct attribute
*bridge_attrs
[] = {
814 &dev_attr_forward_delay
.attr
,
815 &dev_attr_hello_time
.attr
,
816 &dev_attr_max_age
.attr
,
817 &dev_attr_ageing_time
.attr
,
818 &dev_attr_stp_state
.attr
,
819 &dev_attr_group_fwd_mask
.attr
,
820 &dev_attr_priority
.attr
,
821 &dev_attr_bridge_id
.attr
,
822 &dev_attr_root_id
.attr
,
823 &dev_attr_root_path_cost
.attr
,
824 &dev_attr_root_port
.attr
,
825 &dev_attr_topology_change
.attr
,
826 &dev_attr_topology_change_detected
.attr
,
827 &dev_attr_hello_timer
.attr
,
828 &dev_attr_tcn_timer
.attr
,
829 &dev_attr_topology_change_timer
.attr
,
830 &dev_attr_gc_timer
.attr
,
831 &dev_attr_group_addr
.attr
,
832 &dev_attr_flush
.attr
,
833 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
834 &dev_attr_multicast_router
.attr
,
835 &dev_attr_multicast_snooping
.attr
,
836 &dev_attr_multicast_querier
.attr
,
837 &dev_attr_multicast_query_use_ifaddr
.attr
,
838 &dev_attr_hash_elasticity
.attr
,
839 &dev_attr_hash_max
.attr
,
840 &dev_attr_multicast_last_member_count
.attr
,
841 &dev_attr_multicast_startup_query_count
.attr
,
842 &dev_attr_multicast_last_member_interval
.attr
,
843 &dev_attr_multicast_membership_interval
.attr
,
844 &dev_attr_multicast_querier_interval
.attr
,
845 &dev_attr_multicast_query_interval
.attr
,
846 &dev_attr_multicast_query_response_interval
.attr
,
847 &dev_attr_multicast_startup_query_interval
.attr
,
848 &dev_attr_multicast_stats_enabled
.attr
,
849 &dev_attr_multicast_igmp_version
.attr
,
850 #if IS_ENABLED(CONFIG_IPV6)
851 &dev_attr_multicast_mld_version
.attr
,
854 #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
855 &dev_attr_nf_call_iptables
.attr
,
856 &dev_attr_nf_call_ip6tables
.attr
,
857 &dev_attr_nf_call_arptables
.attr
,
859 #ifdef CONFIG_BRIDGE_VLAN_FILTERING
860 &dev_attr_vlan_filtering
.attr
,
861 &dev_attr_vlan_protocol
.attr
,
862 &dev_attr_default_pvid
.attr
,
863 &dev_attr_vlan_stats_enabled
.attr
,
868 static struct attribute_group bridge_group
= {
869 .name
= SYSFS_BRIDGE_ATTR
,
870 .attrs
= bridge_attrs
,
874 * Export the forwarding information table as a binary file
875 * The records are struct __fdb_entry.
877 * Returns the number of bytes read.
879 static ssize_t
brforward_read(struct file
*filp
, struct kobject
*kobj
,
880 struct bin_attribute
*bin_attr
,
881 char *buf
, loff_t off
, size_t count
)
883 struct device
*dev
= kobj_to_dev(kobj
);
884 struct net_bridge
*br
= to_bridge(dev
);
887 /* must read whole records */
888 if (off
% sizeof(struct __fdb_entry
) != 0)
891 n
= br_fdb_fillbuf(br
, buf
,
892 count
/ sizeof(struct __fdb_entry
),
893 off
/ sizeof(struct __fdb_entry
));
896 n
*= sizeof(struct __fdb_entry
);
901 static struct bin_attribute bridge_forward
= {
902 .attr
= { .name
= SYSFS_BRIDGE_FDB
,
904 .read
= brforward_read
,
908 * Add entries in sysfs onto the existing network class device
910 * Adds a attribute group "bridge" containing tuning parameters.
911 * Binary attribute containing the forward table
912 * Sub directory to hold links to interfaces.
914 * Note: the ifobj exists only to be a subdirectory
915 * to hold links. The ifobj exists in same data structure
916 * as it's parent the bridge so reference counting works.
918 int br_sysfs_addbr(struct net_device
*dev
)
920 struct kobject
*brobj
= &dev
->dev
.kobj
;
921 struct net_bridge
*br
= netdev_priv(dev
);
924 err
= sysfs_create_group(brobj
, &bridge_group
);
926 pr_info("%s: can't create group %s/%s\n",
927 __func__
, dev
->name
, bridge_group
.name
);
931 err
= sysfs_create_bin_file(brobj
, &bridge_forward
);
933 pr_info("%s: can't create attribute file %s/%s\n",
934 __func__
, dev
->name
, bridge_forward
.attr
.name
);
938 br
->ifobj
= kobject_create_and_add(SYSFS_BRIDGE_PORT_SUBDIR
, brobj
);
940 pr_info("%s: can't add kobject (directory) %s/%s\n",
941 __func__
, dev
->name
, SYSFS_BRIDGE_PORT_SUBDIR
);
947 sysfs_remove_bin_file(&dev
->dev
.kobj
, &bridge_forward
);
949 sysfs_remove_group(&dev
->dev
.kobj
, &bridge_group
);
955 void br_sysfs_delbr(struct net_device
*dev
)
957 struct kobject
*kobj
= &dev
->dev
.kobj
;
958 struct net_bridge
*br
= netdev_priv(dev
);
960 kobject_put(br
->ifobj
);
961 sysfs_remove_bin_file(kobj
, &bridge_forward
);
962 sysfs_remove_group(kobj
, &bridge_group
);