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);
46 err
= (*set
)(br
, val
);
47 return err
? err
: len
;
51 static ssize_t
forward_delay_show(struct device
*d
,
52 struct device_attribute
*attr
, char *buf
)
54 struct net_bridge
*br
= to_bridge(d
);
55 return sprintf(buf
, "%lu\n", jiffies_to_clock_t(br
->forward_delay
));
58 static ssize_t
forward_delay_store(struct device
*d
,
59 struct device_attribute
*attr
,
60 const char *buf
, size_t len
)
62 return store_bridge_parm(d
, buf
, len
, br_set_forward_delay
);
64 static DEVICE_ATTR_RW(forward_delay
);
66 static ssize_t
hello_time_show(struct device
*d
, struct device_attribute
*attr
,
69 return sprintf(buf
, "%lu\n",
70 jiffies_to_clock_t(to_bridge(d
)->hello_time
));
73 static ssize_t
hello_time_store(struct device
*d
,
74 struct device_attribute
*attr
, const char *buf
,
77 return store_bridge_parm(d
, buf
, len
, br_set_hello_time
);
79 static DEVICE_ATTR_RW(hello_time
);
81 static ssize_t
max_age_show(struct device
*d
, struct device_attribute
*attr
,
84 return sprintf(buf
, "%lu\n",
85 jiffies_to_clock_t(to_bridge(d
)->max_age
));
88 static ssize_t
max_age_store(struct device
*d
, struct device_attribute
*attr
,
89 const char *buf
, size_t len
)
91 return store_bridge_parm(d
, buf
, len
, br_set_max_age
);
93 static DEVICE_ATTR_RW(max_age
);
95 static ssize_t
ageing_time_show(struct device
*d
,
96 struct device_attribute
*attr
, char *buf
)
98 struct net_bridge
*br
= to_bridge(d
);
99 return sprintf(buf
, "%lu\n", jiffies_to_clock_t(br
->ageing_time
));
102 static int set_ageing_time(struct net_bridge
*br
, unsigned long val
)
107 return restart_syscall();
109 ret
= 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 ssize_t
stp_state_store(struct device
*d
,
132 struct device_attribute
*attr
, const char *buf
,
135 struct net_bridge
*br
= to_bridge(d
);
139 if (!ns_capable(dev_net(br
->dev
)->user_ns
, CAP_NET_ADMIN
))
142 val
= simple_strtoul(buf
, &endp
, 0);
147 return restart_syscall();
148 br_stp_set_enabled(br
, val
);
153 static DEVICE_ATTR_RW(stp_state
);
155 static ssize_t
group_fwd_mask_show(struct device
*d
,
156 struct device_attribute
*attr
,
159 struct net_bridge
*br
= to_bridge(d
);
160 return sprintf(buf
, "%#x\n", br
->group_fwd_mask
);
164 static ssize_t
group_fwd_mask_store(struct device
*d
,
165 struct device_attribute
*attr
,
169 struct net_bridge
*br
= to_bridge(d
);
173 if (!ns_capable(dev_net(br
->dev
)->user_ns
, CAP_NET_ADMIN
))
176 val
= simple_strtoul(buf
, &endp
, 0);
180 if (val
& BR_GROUPFWD_RESTRICTED
)
183 br
->group_fwd_mask
= val
;
187 static DEVICE_ATTR_RW(group_fwd_mask
);
189 static ssize_t
priority_show(struct device
*d
, struct device_attribute
*attr
,
192 struct net_bridge
*br
= to_bridge(d
);
193 return sprintf(buf
, "%d\n",
194 (br
->bridge_id
.prio
[0] << 8) | br
->bridge_id
.prio
[1]);
197 static int set_priority(struct net_bridge
*br
, unsigned long val
)
199 br_stp_set_bridge_priority(br
, (u16
) val
);
203 static ssize_t
priority_store(struct device
*d
, struct device_attribute
*attr
,
204 const char *buf
, size_t len
)
206 return store_bridge_parm(d
, buf
, len
, set_priority
);
208 static DEVICE_ATTR_RW(priority
);
210 static ssize_t
root_id_show(struct device
*d
, struct device_attribute
*attr
,
213 return br_show_bridge_id(buf
, &to_bridge(d
)->designated_root
);
215 static DEVICE_ATTR_RO(root_id
);
217 static ssize_t
bridge_id_show(struct device
*d
, struct device_attribute
*attr
,
220 return br_show_bridge_id(buf
, &to_bridge(d
)->bridge_id
);
222 static DEVICE_ATTR_RO(bridge_id
);
224 static ssize_t
root_port_show(struct device
*d
, struct device_attribute
*attr
,
227 return sprintf(buf
, "%d\n", to_bridge(d
)->root_port
);
229 static DEVICE_ATTR_RO(root_port
);
231 static ssize_t
root_path_cost_show(struct device
*d
,
232 struct device_attribute
*attr
, char *buf
)
234 return sprintf(buf
, "%d\n", to_bridge(d
)->root_path_cost
);
236 static DEVICE_ATTR_RO(root_path_cost
);
238 static ssize_t
topology_change_show(struct device
*d
,
239 struct device_attribute
*attr
, char *buf
)
241 return sprintf(buf
, "%d\n", to_bridge(d
)->topology_change
);
243 static DEVICE_ATTR_RO(topology_change
);
245 static ssize_t
topology_change_detected_show(struct device
*d
,
246 struct device_attribute
*attr
,
249 struct net_bridge
*br
= to_bridge(d
);
250 return sprintf(buf
, "%d\n", br
->topology_change_detected
);
252 static DEVICE_ATTR_RO(topology_change_detected
);
254 static ssize_t
hello_timer_show(struct device
*d
,
255 struct device_attribute
*attr
, char *buf
)
257 struct net_bridge
*br
= to_bridge(d
);
258 return sprintf(buf
, "%ld\n", br_timer_value(&br
->hello_timer
));
260 static DEVICE_ATTR_RO(hello_timer
);
262 static ssize_t
tcn_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
->tcn_timer
));
268 static DEVICE_ATTR_RO(tcn_timer
);
270 static ssize_t
topology_change_timer_show(struct device
*d
,
271 struct device_attribute
*attr
,
274 struct net_bridge
*br
= to_bridge(d
);
275 return sprintf(buf
, "%ld\n", br_timer_value(&br
->topology_change_timer
));
277 static DEVICE_ATTR_RO(topology_change_timer
);
279 static ssize_t
gc_timer_show(struct device
*d
, struct device_attribute
*attr
,
282 struct net_bridge
*br
= to_bridge(d
);
283 return sprintf(buf
, "%ld\n", br_timer_value(&br
->gc_timer
));
285 static DEVICE_ATTR_RO(gc_timer
);
287 static ssize_t
group_addr_show(struct device
*d
,
288 struct device_attribute
*attr
, char *buf
)
290 struct net_bridge
*br
= to_bridge(d
);
291 return sprintf(buf
, "%x:%x:%x:%x:%x:%x\n",
292 br
->group_addr
[0], br
->group_addr
[1],
293 br
->group_addr
[2], br
->group_addr
[3],
294 br
->group_addr
[4], br
->group_addr
[5]);
297 static ssize_t
group_addr_store(struct device
*d
,
298 struct device_attribute
*attr
,
299 const char *buf
, size_t len
)
301 struct net_bridge
*br
= to_bridge(d
);
305 if (!ns_capable(dev_net(br
->dev
)->user_ns
, CAP_NET_ADMIN
))
308 if (sscanf(buf
, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx",
309 &new_addr
[0], &new_addr
[1], &new_addr
[2],
310 &new_addr
[3], &new_addr
[4], &new_addr
[5]) != 6)
313 if (!is_link_local_ether_addr(new_addr
))
316 if (new_addr
[5] == 1 || /* 802.3x Pause address */
317 new_addr
[5] == 2 || /* 802.3ad Slow protocols */
318 new_addr
[5] == 3) /* 802.1X PAE address */
322 return restart_syscall();
324 spin_lock_bh(&br
->lock
);
325 for (i
= 0; i
< 6; i
++)
326 br
->group_addr
[i
] = new_addr
[i
];
327 spin_unlock_bh(&br
->lock
);
329 br
->group_addr_set
= true;
330 br_recalculate_fwd_mask(br
);
337 static DEVICE_ATTR_RW(group_addr
);
339 static ssize_t
flush_store(struct device
*d
,
340 struct device_attribute
*attr
,
341 const char *buf
, size_t len
)
343 struct net_bridge
*br
= to_bridge(d
);
345 if (!ns_capable(dev_net(br
->dev
)->user_ns
, CAP_NET_ADMIN
))
351 static DEVICE_ATTR_WO(flush
);
353 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
354 static ssize_t
multicast_router_show(struct device
*d
,
355 struct device_attribute
*attr
, char *buf
)
357 struct net_bridge
*br
= to_bridge(d
);
358 return sprintf(buf
, "%d\n", br
->multicast_router
);
361 static ssize_t
multicast_router_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_set_router
);
367 static DEVICE_ATTR_RW(multicast_router
);
369 static ssize_t
multicast_snooping_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_disabled
);
377 static ssize_t
multicast_snooping_store(struct device
*d
,
378 struct device_attribute
*attr
,
379 const char *buf
, size_t len
)
381 return store_bridge_parm(d
, buf
, len
, br_multicast_toggle
);
383 static DEVICE_ATTR_RW(multicast_snooping
);
385 static ssize_t
multicast_query_use_ifaddr_show(struct device
*d
,
386 struct device_attribute
*attr
,
389 struct net_bridge
*br
= to_bridge(d
);
390 return sprintf(buf
, "%d\n", br
->multicast_query_use_ifaddr
);
393 static int set_query_use_ifaddr(struct net_bridge
*br
, unsigned long val
)
395 br
->multicast_query_use_ifaddr
= !!val
;
400 multicast_query_use_ifaddr_store(struct device
*d
,
401 struct device_attribute
*attr
,
402 const char *buf
, size_t len
)
404 return store_bridge_parm(d
, buf
, len
, set_query_use_ifaddr
);
406 static DEVICE_ATTR_RW(multicast_query_use_ifaddr
);
408 static ssize_t
multicast_querier_show(struct device
*d
,
409 struct device_attribute
*attr
,
412 struct net_bridge
*br
= to_bridge(d
);
413 return sprintf(buf
, "%d\n", br
->multicast_querier
);
416 static ssize_t
multicast_querier_store(struct device
*d
,
417 struct device_attribute
*attr
,
418 const char *buf
, size_t len
)
420 return store_bridge_parm(d
, buf
, len
, br_multicast_set_querier
);
422 static DEVICE_ATTR_RW(multicast_querier
);
424 static ssize_t
hash_elasticity_show(struct device
*d
,
425 struct device_attribute
*attr
, char *buf
)
427 struct net_bridge
*br
= to_bridge(d
);
428 return sprintf(buf
, "%u\n", br
->hash_elasticity
);
431 static int set_elasticity(struct net_bridge
*br
, unsigned long val
)
433 br
->hash_elasticity
= val
;
437 static ssize_t
hash_elasticity_store(struct device
*d
,
438 struct device_attribute
*attr
,
439 const char *buf
, size_t len
)
441 return store_bridge_parm(d
, buf
, len
, set_elasticity
);
443 static DEVICE_ATTR_RW(hash_elasticity
);
445 static ssize_t
hash_max_show(struct device
*d
, struct device_attribute
*attr
,
448 struct net_bridge
*br
= to_bridge(d
);
449 return sprintf(buf
, "%u\n", br
->hash_max
);
452 static ssize_t
hash_max_store(struct device
*d
, struct device_attribute
*attr
,
453 const char *buf
, size_t len
)
455 return store_bridge_parm(d
, buf
, len
, br_multicast_set_hash_max
);
457 static DEVICE_ATTR_RW(hash_max
);
459 static ssize_t
multicast_last_member_count_show(struct device
*d
,
460 struct device_attribute
*attr
,
463 struct net_bridge
*br
= to_bridge(d
);
464 return sprintf(buf
, "%u\n", br
->multicast_last_member_count
);
467 static int set_last_member_count(struct net_bridge
*br
, unsigned long val
)
469 br
->multicast_last_member_count
= val
;
473 static ssize_t
multicast_last_member_count_store(struct device
*d
,
474 struct device_attribute
*attr
,
475 const char *buf
, size_t len
)
477 return store_bridge_parm(d
, buf
, len
, set_last_member_count
);
479 static DEVICE_ATTR_RW(multicast_last_member_count
);
481 static ssize_t
multicast_startup_query_count_show(
482 struct device
*d
, struct device_attribute
*attr
, char *buf
)
484 struct net_bridge
*br
= to_bridge(d
);
485 return sprintf(buf
, "%u\n", br
->multicast_startup_query_count
);
488 static int set_startup_query_count(struct net_bridge
*br
, unsigned long val
)
490 br
->multicast_startup_query_count
= val
;
494 static ssize_t
multicast_startup_query_count_store(
495 struct device
*d
, struct device_attribute
*attr
, const char *buf
,
498 return store_bridge_parm(d
, buf
, len
, set_startup_query_count
);
500 static DEVICE_ATTR_RW(multicast_startup_query_count
);
502 static ssize_t
multicast_last_member_interval_show(
503 struct device
*d
, struct device_attribute
*attr
, char *buf
)
505 struct net_bridge
*br
= to_bridge(d
);
506 return sprintf(buf
, "%lu\n",
507 jiffies_to_clock_t(br
->multicast_last_member_interval
));
510 static int set_last_member_interval(struct net_bridge
*br
, unsigned long val
)
512 br
->multicast_last_member_interval
= clock_t_to_jiffies(val
);
516 static ssize_t
multicast_last_member_interval_store(
517 struct device
*d
, struct device_attribute
*attr
, const char *buf
,
520 return store_bridge_parm(d
, buf
, len
, set_last_member_interval
);
522 static DEVICE_ATTR_RW(multicast_last_member_interval
);
524 static ssize_t
multicast_membership_interval_show(
525 struct device
*d
, struct device_attribute
*attr
, char *buf
)
527 struct net_bridge
*br
= to_bridge(d
);
528 return sprintf(buf
, "%lu\n",
529 jiffies_to_clock_t(br
->multicast_membership_interval
));
532 static int set_membership_interval(struct net_bridge
*br
, unsigned long val
)
534 br
->multicast_membership_interval
= clock_t_to_jiffies(val
);
538 static ssize_t
multicast_membership_interval_store(
539 struct device
*d
, struct device_attribute
*attr
, const char *buf
,
542 return store_bridge_parm(d
, buf
, len
, set_membership_interval
);
544 static DEVICE_ATTR_RW(multicast_membership_interval
);
546 static ssize_t
multicast_querier_interval_show(struct device
*d
,
547 struct device_attribute
*attr
,
550 struct net_bridge
*br
= to_bridge(d
);
551 return sprintf(buf
, "%lu\n",
552 jiffies_to_clock_t(br
->multicast_querier_interval
));
555 static int set_querier_interval(struct net_bridge
*br
, unsigned long val
)
557 br
->multicast_querier_interval
= clock_t_to_jiffies(val
);
561 static ssize_t
multicast_querier_interval_store(struct device
*d
,
562 struct device_attribute
*attr
,
563 const char *buf
, size_t len
)
565 return store_bridge_parm(d
, buf
, len
, set_querier_interval
);
567 static DEVICE_ATTR_RW(multicast_querier_interval
);
569 static ssize_t
multicast_query_interval_show(struct device
*d
,
570 struct device_attribute
*attr
,
573 struct net_bridge
*br
= to_bridge(d
);
574 return sprintf(buf
, "%lu\n",
575 jiffies_to_clock_t(br
->multicast_query_interval
));
578 static int set_query_interval(struct net_bridge
*br
, unsigned long val
)
580 br
->multicast_query_interval
= clock_t_to_jiffies(val
);
584 static ssize_t
multicast_query_interval_store(struct device
*d
,
585 struct device_attribute
*attr
,
586 const char *buf
, size_t len
)
588 return store_bridge_parm(d
, buf
, len
, set_query_interval
);
590 static DEVICE_ATTR_RW(multicast_query_interval
);
592 static ssize_t
multicast_query_response_interval_show(
593 struct device
*d
, struct device_attribute
*attr
, char *buf
)
595 struct net_bridge
*br
= to_bridge(d
);
598 jiffies_to_clock_t(br
->multicast_query_response_interval
));
601 static int set_query_response_interval(struct net_bridge
*br
, unsigned long val
)
603 br
->multicast_query_response_interval
= clock_t_to_jiffies(val
);
607 static ssize_t
multicast_query_response_interval_store(
608 struct device
*d
, struct device_attribute
*attr
, const char *buf
,
611 return store_bridge_parm(d
, buf
, len
, set_query_response_interval
);
613 static DEVICE_ATTR_RW(multicast_query_response_interval
);
615 static ssize_t
multicast_startup_query_interval_show(
616 struct device
*d
, struct device_attribute
*attr
, char *buf
)
618 struct net_bridge
*br
= to_bridge(d
);
621 jiffies_to_clock_t(br
->multicast_startup_query_interval
));
624 static int set_startup_query_interval(struct net_bridge
*br
, unsigned long val
)
626 br
->multicast_startup_query_interval
= clock_t_to_jiffies(val
);
630 static ssize_t
multicast_startup_query_interval_store(
631 struct device
*d
, struct device_attribute
*attr
, const char *buf
,
634 return store_bridge_parm(d
, buf
, len
, set_startup_query_interval
);
636 static DEVICE_ATTR_RW(multicast_startup_query_interval
);
638 #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
639 static ssize_t
nf_call_iptables_show(
640 struct device
*d
, struct device_attribute
*attr
, char *buf
)
642 struct net_bridge
*br
= to_bridge(d
);
643 return sprintf(buf
, "%u\n", br
->nf_call_iptables
);
646 static int set_nf_call_iptables(struct net_bridge
*br
, unsigned long val
)
648 br
->nf_call_iptables
= val
? true : false;
652 static ssize_t
nf_call_iptables_store(
653 struct device
*d
, struct device_attribute
*attr
, const char *buf
,
656 return store_bridge_parm(d
, buf
, len
, set_nf_call_iptables
);
658 static DEVICE_ATTR_RW(nf_call_iptables
);
660 static ssize_t
nf_call_ip6tables_show(
661 struct device
*d
, struct device_attribute
*attr
, char *buf
)
663 struct net_bridge
*br
= to_bridge(d
);
664 return sprintf(buf
, "%u\n", br
->nf_call_ip6tables
);
667 static int set_nf_call_ip6tables(struct net_bridge
*br
, unsigned long val
)
669 br
->nf_call_ip6tables
= val
? true : false;
673 static ssize_t
nf_call_ip6tables_store(
674 struct device
*d
, struct device_attribute
*attr
, const char *buf
,
677 return store_bridge_parm(d
, buf
, len
, set_nf_call_ip6tables
);
679 static DEVICE_ATTR_RW(nf_call_ip6tables
);
681 static ssize_t
nf_call_arptables_show(
682 struct device
*d
, struct device_attribute
*attr
, char *buf
)
684 struct net_bridge
*br
= to_bridge(d
);
685 return sprintf(buf
, "%u\n", br
->nf_call_arptables
);
688 static int set_nf_call_arptables(struct net_bridge
*br
, unsigned long val
)
690 br
->nf_call_arptables
= val
? true : false;
694 static ssize_t
nf_call_arptables_store(
695 struct device
*d
, struct device_attribute
*attr
, const char *buf
,
698 return store_bridge_parm(d
, buf
, len
, set_nf_call_arptables
);
700 static DEVICE_ATTR_RW(nf_call_arptables
);
702 #ifdef CONFIG_BRIDGE_VLAN_FILTERING
703 static ssize_t
vlan_filtering_show(struct device
*d
,
704 struct device_attribute
*attr
,
707 struct net_bridge
*br
= to_bridge(d
);
708 return sprintf(buf
, "%d\n", br
->vlan_enabled
);
711 static ssize_t
vlan_filtering_store(struct device
*d
,
712 struct device_attribute
*attr
,
713 const char *buf
, size_t len
)
715 return store_bridge_parm(d
, buf
, len
, br_vlan_filter_toggle
);
717 static DEVICE_ATTR_RW(vlan_filtering
);
719 static ssize_t
vlan_protocol_show(struct device
*d
,
720 struct device_attribute
*attr
,
723 struct net_bridge
*br
= to_bridge(d
);
724 return sprintf(buf
, "%#06x\n", ntohs(br
->vlan_proto
));
727 static ssize_t
vlan_protocol_store(struct device
*d
,
728 struct device_attribute
*attr
,
729 const char *buf
, size_t len
)
731 return store_bridge_parm(d
, buf
, len
, br_vlan_set_proto
);
733 static DEVICE_ATTR_RW(vlan_protocol
);
735 static ssize_t
default_pvid_show(struct device
*d
,
736 struct device_attribute
*attr
,
739 struct net_bridge
*br
= to_bridge(d
);
740 return sprintf(buf
, "%d\n", br
->default_pvid
);
743 static ssize_t
default_pvid_store(struct device
*d
,
744 struct device_attribute
*attr
,
745 const char *buf
, size_t len
)
747 return store_bridge_parm(d
, buf
, len
, br_vlan_set_default_pvid
);
749 static DEVICE_ATTR_RW(default_pvid
);
752 static struct attribute
*bridge_attrs
[] = {
753 &dev_attr_forward_delay
.attr
,
754 &dev_attr_hello_time
.attr
,
755 &dev_attr_max_age
.attr
,
756 &dev_attr_ageing_time
.attr
,
757 &dev_attr_stp_state
.attr
,
758 &dev_attr_group_fwd_mask
.attr
,
759 &dev_attr_priority
.attr
,
760 &dev_attr_bridge_id
.attr
,
761 &dev_attr_root_id
.attr
,
762 &dev_attr_root_path_cost
.attr
,
763 &dev_attr_root_port
.attr
,
764 &dev_attr_topology_change
.attr
,
765 &dev_attr_topology_change_detected
.attr
,
766 &dev_attr_hello_timer
.attr
,
767 &dev_attr_tcn_timer
.attr
,
768 &dev_attr_topology_change_timer
.attr
,
769 &dev_attr_gc_timer
.attr
,
770 &dev_attr_group_addr
.attr
,
771 &dev_attr_flush
.attr
,
772 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
773 &dev_attr_multicast_router
.attr
,
774 &dev_attr_multicast_snooping
.attr
,
775 &dev_attr_multicast_querier
.attr
,
776 &dev_attr_multicast_query_use_ifaddr
.attr
,
777 &dev_attr_hash_elasticity
.attr
,
778 &dev_attr_hash_max
.attr
,
779 &dev_attr_multicast_last_member_count
.attr
,
780 &dev_attr_multicast_startup_query_count
.attr
,
781 &dev_attr_multicast_last_member_interval
.attr
,
782 &dev_attr_multicast_membership_interval
.attr
,
783 &dev_attr_multicast_querier_interval
.attr
,
784 &dev_attr_multicast_query_interval
.attr
,
785 &dev_attr_multicast_query_response_interval
.attr
,
786 &dev_attr_multicast_startup_query_interval
.attr
,
788 #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
789 &dev_attr_nf_call_iptables
.attr
,
790 &dev_attr_nf_call_ip6tables
.attr
,
791 &dev_attr_nf_call_arptables
.attr
,
793 #ifdef CONFIG_BRIDGE_VLAN_FILTERING
794 &dev_attr_vlan_filtering
.attr
,
795 &dev_attr_vlan_protocol
.attr
,
796 &dev_attr_default_pvid
.attr
,
801 static struct attribute_group bridge_group
= {
802 .name
= SYSFS_BRIDGE_ATTR
,
803 .attrs
= bridge_attrs
,
807 * Export the forwarding information table as a binary file
808 * The records are struct __fdb_entry.
810 * Returns the number of bytes read.
812 static ssize_t
brforward_read(struct file
*filp
, struct kobject
*kobj
,
813 struct bin_attribute
*bin_attr
,
814 char *buf
, loff_t off
, size_t count
)
816 struct device
*dev
= kobj_to_dev(kobj
);
817 struct net_bridge
*br
= to_bridge(dev
);
820 /* must read whole records */
821 if (off
% sizeof(struct __fdb_entry
) != 0)
824 n
= br_fdb_fillbuf(br
, buf
,
825 count
/ sizeof(struct __fdb_entry
),
826 off
/ sizeof(struct __fdb_entry
));
829 n
*= sizeof(struct __fdb_entry
);
834 static struct bin_attribute bridge_forward
= {
835 .attr
= { .name
= SYSFS_BRIDGE_FDB
,
837 .read
= brforward_read
,
841 * Add entries in sysfs onto the existing network class device
843 * Adds a attribute group "bridge" containing tuning parameters.
844 * Binary attribute containing the forward table
845 * Sub directory to hold links to interfaces.
847 * Note: the ifobj exists only to be a subdirectory
848 * to hold links. The ifobj exists in same data structure
849 * as it's parent the bridge so reference counting works.
851 int br_sysfs_addbr(struct net_device
*dev
)
853 struct kobject
*brobj
= &dev
->dev
.kobj
;
854 struct net_bridge
*br
= netdev_priv(dev
);
857 err
= sysfs_create_group(brobj
, &bridge_group
);
859 pr_info("%s: can't create group %s/%s\n",
860 __func__
, dev
->name
, bridge_group
.name
);
864 err
= sysfs_create_bin_file(brobj
, &bridge_forward
);
866 pr_info("%s: can't create attribute file %s/%s\n",
867 __func__
, dev
->name
, bridge_forward
.attr
.name
);
871 br
->ifobj
= kobject_create_and_add(SYSFS_BRIDGE_PORT_SUBDIR
, brobj
);
873 pr_info("%s: can't add kobject (directory) %s/%s\n",
874 __func__
, dev
->name
, SYSFS_BRIDGE_PORT_SUBDIR
);
879 sysfs_remove_bin_file(&dev
->dev
.kobj
, &bridge_forward
);
881 sysfs_remove_group(&dev
->dev
.kobj
, &bridge_group
);
887 void br_sysfs_delbr(struct net_device
*dev
)
889 struct kobject
*kobj
= &dev
->dev
.kobj
;
890 struct net_bridge
*br
= netdev_priv(dev
);
892 kobject_put(br
->ifobj
);
893 sysfs_remove_bin_file(kobj
, &bridge_forward
);
894 sysfs_remove_group(kobj
, &bridge_group
);