1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Sysfs attributes of bridge
4 * Linux ethernet bridge
7 * Stephen Hemminger <shemminger@osdl.org>
10 #include <linux/capability.h>
11 #include <linux/kernel.h>
12 #include <linux/netdevice.h>
13 #include <linux/etherdevice.h>
14 #include <linux/if_bridge.h>
15 #include <linux/rtnetlink.h>
16 #include <linux/spinlock.h>
17 #include <linux/times.h>
18 #include <linux/sched/signal.h>
20 #include "br_private.h"
22 /* IMPORTANT: new bridge options must be added with netlink support only
23 * please do not add new sysfs entries
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
*br
, unsigned long val
,
34 struct netlink_ext_ack
*extack
))
36 struct net_bridge
*br
= to_bridge(d
);
37 struct netlink_ext_ack extack
= {0};
41 if (!ns_capable(dev_net(br
->dev
)->user_ns
, CAP_NET_ADMIN
))
44 err
= kstrtoul(buf
, 0, &val
);
49 return restart_syscall();
51 err
= (*set
)(br
, val
, &extack
);
53 netdev_state_change(br
->dev
);
56 br_err(br
, "%s\n", extack
._msg
);
58 br_warn(br
, "%s\n", extack
._msg
);
62 return err
? err
: len
;
66 static ssize_t
forward_delay_show(struct device
*d
,
67 struct device_attribute
*attr
, char *buf
)
69 struct net_bridge
*br
= to_bridge(d
);
70 return sprintf(buf
, "%lu\n", jiffies_to_clock_t(br
->forward_delay
));
73 static int set_forward_delay(struct net_bridge
*br
, unsigned long val
,
74 struct netlink_ext_ack
*extack
)
76 return br_set_forward_delay(br
, val
);
79 static ssize_t
forward_delay_store(struct device
*d
,
80 struct device_attribute
*attr
,
81 const char *buf
, size_t len
)
83 return store_bridge_parm(d
, buf
, len
, set_forward_delay
);
85 static DEVICE_ATTR_RW(forward_delay
);
87 static ssize_t
hello_time_show(struct device
*d
, struct device_attribute
*attr
,
90 return sprintf(buf
, "%lu\n",
91 jiffies_to_clock_t(to_bridge(d
)->hello_time
));
94 static int set_hello_time(struct net_bridge
*br
, unsigned long val
,
95 struct netlink_ext_ack
*extack
)
97 return br_set_hello_time(br
, val
);
100 static ssize_t
hello_time_store(struct device
*d
,
101 struct device_attribute
*attr
, const char *buf
,
104 return store_bridge_parm(d
, buf
, len
, set_hello_time
);
106 static DEVICE_ATTR_RW(hello_time
);
108 static ssize_t
max_age_show(struct device
*d
, struct device_attribute
*attr
,
111 return sprintf(buf
, "%lu\n",
112 jiffies_to_clock_t(to_bridge(d
)->max_age
));
115 static int set_max_age(struct net_bridge
*br
, unsigned long val
,
116 struct netlink_ext_ack
*extack
)
118 return br_set_max_age(br
, val
);
121 static ssize_t
max_age_store(struct device
*d
, struct device_attribute
*attr
,
122 const char *buf
, size_t len
)
124 return store_bridge_parm(d
, buf
, len
, set_max_age
);
126 static DEVICE_ATTR_RW(max_age
);
128 static ssize_t
ageing_time_show(struct device
*d
,
129 struct device_attribute
*attr
, char *buf
)
131 struct net_bridge
*br
= to_bridge(d
);
132 return sprintf(buf
, "%lu\n", jiffies_to_clock_t(br
->ageing_time
));
135 static int set_ageing_time(struct net_bridge
*br
, unsigned long val
,
136 struct netlink_ext_ack
*extack
)
138 return br_set_ageing_time(br
, val
);
141 static ssize_t
ageing_time_store(struct device
*d
,
142 struct device_attribute
*attr
,
143 const char *buf
, size_t len
)
145 return store_bridge_parm(d
, buf
, len
, set_ageing_time
);
147 static DEVICE_ATTR_RW(ageing_time
);
149 static ssize_t
stp_state_show(struct device
*d
,
150 struct device_attribute
*attr
, char *buf
)
152 struct net_bridge
*br
= to_bridge(d
);
153 return sprintf(buf
, "%d\n", br
->stp_enabled
);
157 static int set_stp_state(struct net_bridge
*br
, unsigned long val
,
158 struct netlink_ext_ack
*extack
)
160 return br_stp_set_enabled(br
, val
, extack
);
163 static ssize_t
stp_state_store(struct device
*d
,
164 struct device_attribute
*attr
, const char *buf
,
167 return store_bridge_parm(d
, buf
, len
, set_stp_state
);
169 static DEVICE_ATTR_RW(stp_state
);
171 static ssize_t
group_fwd_mask_show(struct device
*d
,
172 struct device_attribute
*attr
,
175 struct net_bridge
*br
= to_bridge(d
);
176 return sprintf(buf
, "%#x\n", br
->group_fwd_mask
);
179 static int set_group_fwd_mask(struct net_bridge
*br
, unsigned long val
,
180 struct netlink_ext_ack
*extack
)
182 if (val
& BR_GROUPFWD_RESTRICTED
)
185 br
->group_fwd_mask
= val
;
190 static ssize_t
group_fwd_mask_store(struct device
*d
,
191 struct device_attribute
*attr
,
195 return store_bridge_parm(d
, buf
, len
, set_group_fwd_mask
);
197 static DEVICE_ATTR_RW(group_fwd_mask
);
199 static ssize_t
priority_show(struct device
*d
, struct device_attribute
*attr
,
202 struct net_bridge
*br
= to_bridge(d
);
203 return sprintf(buf
, "%d\n",
204 (br
->bridge_id
.prio
[0] << 8) | br
->bridge_id
.prio
[1]);
207 static int set_priority(struct net_bridge
*br
, unsigned long val
,
208 struct netlink_ext_ack
*extack
)
210 br_stp_set_bridge_priority(br
, (u16
) val
);
214 static ssize_t
priority_store(struct device
*d
, struct device_attribute
*attr
,
215 const char *buf
, size_t len
)
217 return store_bridge_parm(d
, buf
, len
, set_priority
);
219 static DEVICE_ATTR_RW(priority
);
221 static ssize_t
root_id_show(struct device
*d
, struct device_attribute
*attr
,
224 return br_show_bridge_id(buf
, &to_bridge(d
)->designated_root
);
226 static DEVICE_ATTR_RO(root_id
);
228 static ssize_t
bridge_id_show(struct device
*d
, struct device_attribute
*attr
,
231 return br_show_bridge_id(buf
, &to_bridge(d
)->bridge_id
);
233 static DEVICE_ATTR_RO(bridge_id
);
235 static ssize_t
root_port_show(struct device
*d
, struct device_attribute
*attr
,
238 return sprintf(buf
, "%d\n", to_bridge(d
)->root_port
);
240 static DEVICE_ATTR_RO(root_port
);
242 static ssize_t
root_path_cost_show(struct device
*d
,
243 struct device_attribute
*attr
, char *buf
)
245 return sprintf(buf
, "%d\n", to_bridge(d
)->root_path_cost
);
247 static DEVICE_ATTR_RO(root_path_cost
);
249 static ssize_t
topology_change_show(struct device
*d
,
250 struct device_attribute
*attr
, char *buf
)
252 return sprintf(buf
, "%d\n", to_bridge(d
)->topology_change
);
254 static DEVICE_ATTR_RO(topology_change
);
256 static ssize_t
topology_change_detected_show(struct device
*d
,
257 struct device_attribute
*attr
,
260 struct net_bridge
*br
= to_bridge(d
);
261 return sprintf(buf
, "%d\n", br
->topology_change_detected
);
263 static DEVICE_ATTR_RO(topology_change_detected
);
265 static ssize_t
hello_timer_show(struct device
*d
,
266 struct device_attribute
*attr
, char *buf
)
268 struct net_bridge
*br
= to_bridge(d
);
269 return sprintf(buf
, "%ld\n", br_timer_value(&br
->hello_timer
));
271 static DEVICE_ATTR_RO(hello_timer
);
273 static ssize_t
tcn_timer_show(struct device
*d
, struct device_attribute
*attr
,
276 struct net_bridge
*br
= to_bridge(d
);
277 return sprintf(buf
, "%ld\n", br_timer_value(&br
->tcn_timer
));
279 static DEVICE_ATTR_RO(tcn_timer
);
281 static ssize_t
topology_change_timer_show(struct device
*d
,
282 struct device_attribute
*attr
,
285 struct net_bridge
*br
= to_bridge(d
);
286 return sprintf(buf
, "%ld\n", br_timer_value(&br
->topology_change_timer
));
288 static DEVICE_ATTR_RO(topology_change_timer
);
290 static ssize_t
gc_timer_show(struct device
*d
, struct device_attribute
*attr
,
293 struct net_bridge
*br
= to_bridge(d
);
294 return sprintf(buf
, "%ld\n", br_timer_value(&br
->gc_work
.timer
));
296 static DEVICE_ATTR_RO(gc_timer
);
298 static ssize_t
group_addr_show(struct device
*d
,
299 struct device_attribute
*attr
, char *buf
)
301 struct net_bridge
*br
= to_bridge(d
);
302 return sprintf(buf
, "%pM\n", br
->group_addr
);
305 static ssize_t
group_addr_store(struct device
*d
,
306 struct device_attribute
*attr
,
307 const char *buf
, size_t len
)
309 struct net_bridge
*br
= to_bridge(d
);
312 if (!ns_capable(dev_net(br
->dev
)->user_ns
, CAP_NET_ADMIN
))
315 if (!mac_pton(buf
, new_addr
))
318 if (!is_link_local_ether_addr(new_addr
))
321 if (new_addr
[5] == 1 || /* 802.3x Pause address */
322 new_addr
[5] == 2 || /* 802.3ad Slow protocols */
323 new_addr
[5] == 3) /* 802.1X PAE address */
327 return restart_syscall();
329 spin_lock_bh(&br
->lock
);
330 ether_addr_copy(br
->group_addr
, new_addr
);
331 spin_unlock_bh(&br
->lock
);
333 br_opt_toggle(br
, BROPT_GROUP_ADDR_SET
, true);
334 br_recalculate_fwd_mask(br
);
335 netdev_state_change(br
->dev
);
342 static DEVICE_ATTR_RW(group_addr
);
344 static int set_flush(struct net_bridge
*br
, unsigned long val
,
345 struct netlink_ext_ack
*extack
)
347 struct net_bridge_fdb_flush_desc desc
= {
348 .flags_mask
= BIT(BR_FDB_STATIC
)
351 br_fdb_flush(br
, &desc
);
355 static ssize_t
flush_store(struct device
*d
,
356 struct device_attribute
*attr
,
357 const char *buf
, size_t len
)
359 return store_bridge_parm(d
, buf
, len
, set_flush
);
361 static DEVICE_ATTR_WO(flush
);
363 static ssize_t
no_linklocal_learn_show(struct device
*d
,
364 struct device_attribute
*attr
,
367 struct net_bridge
*br
= to_bridge(d
);
368 return sprintf(buf
, "%d\n", br_boolopt_get(br
, BR_BOOLOPT_NO_LL_LEARN
));
371 static int set_no_linklocal_learn(struct net_bridge
*br
, unsigned long val
,
372 struct netlink_ext_ack
*extack
)
374 return br_boolopt_toggle(br
, BR_BOOLOPT_NO_LL_LEARN
, !!val
, extack
);
377 static ssize_t
no_linklocal_learn_store(struct device
*d
,
378 struct device_attribute
*attr
,
379 const char *buf
, size_t len
)
381 return store_bridge_parm(d
, buf
, len
, set_no_linklocal_learn
);
383 static DEVICE_ATTR_RW(no_linklocal_learn
);
385 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
386 static ssize_t
multicast_router_show(struct device
*d
,
387 struct device_attribute
*attr
, char *buf
)
389 struct net_bridge
*br
= to_bridge(d
);
390 return sprintf(buf
, "%d\n", br
->multicast_ctx
.multicast_router
);
393 static int set_multicast_router(struct net_bridge
*br
, unsigned long val
,
394 struct netlink_ext_ack
*extack
)
396 return br_multicast_set_router(&br
->multicast_ctx
, val
);
399 static ssize_t
multicast_router_store(struct device
*d
,
400 struct device_attribute
*attr
,
401 const char *buf
, size_t len
)
403 return store_bridge_parm(d
, buf
, len
, set_multicast_router
);
405 static DEVICE_ATTR_RW(multicast_router
);
407 static ssize_t
multicast_snooping_show(struct device
*d
,
408 struct device_attribute
*attr
,
411 struct net_bridge
*br
= to_bridge(d
);
412 return sprintf(buf
, "%d\n", br_opt_get(br
, BROPT_MULTICAST_ENABLED
));
415 static ssize_t
multicast_snooping_store(struct device
*d
,
416 struct device_attribute
*attr
,
417 const char *buf
, size_t len
)
419 return store_bridge_parm(d
, buf
, len
, br_multicast_toggle
);
421 static DEVICE_ATTR_RW(multicast_snooping
);
423 static ssize_t
multicast_query_use_ifaddr_show(struct device
*d
,
424 struct device_attribute
*attr
,
427 struct net_bridge
*br
= to_bridge(d
);
428 return sprintf(buf
, "%d\n",
429 br_opt_get(br
, BROPT_MULTICAST_QUERY_USE_IFADDR
));
432 static int set_query_use_ifaddr(struct net_bridge
*br
, unsigned long val
,
433 struct netlink_ext_ack
*extack
)
435 br_opt_toggle(br
, BROPT_MULTICAST_QUERY_USE_IFADDR
, !!val
);
440 multicast_query_use_ifaddr_store(struct device
*d
,
441 struct device_attribute
*attr
,
442 const char *buf
, size_t len
)
444 return store_bridge_parm(d
, buf
, len
, set_query_use_ifaddr
);
446 static DEVICE_ATTR_RW(multicast_query_use_ifaddr
);
448 static ssize_t
multicast_querier_show(struct device
*d
,
449 struct device_attribute
*attr
,
452 struct net_bridge
*br
= to_bridge(d
);
453 return sprintf(buf
, "%d\n", br
->multicast_ctx
.multicast_querier
);
456 static int set_multicast_querier(struct net_bridge
*br
, unsigned long val
,
457 struct netlink_ext_ack
*extack
)
459 return br_multicast_set_querier(&br
->multicast_ctx
, val
);
462 static ssize_t
multicast_querier_store(struct device
*d
,
463 struct device_attribute
*attr
,
464 const char *buf
, size_t len
)
466 return store_bridge_parm(d
, buf
, len
, set_multicast_querier
);
468 static DEVICE_ATTR_RW(multicast_querier
);
470 static ssize_t
hash_elasticity_show(struct device
*d
,
471 struct device_attribute
*attr
, char *buf
)
473 return sprintf(buf
, "%u\n", RHT_ELASTICITY
);
476 static int set_elasticity(struct net_bridge
*br
, unsigned long val
,
477 struct netlink_ext_ack
*extack
)
479 /* 16 is RHT_ELASTICITY */
480 NL_SET_ERR_MSG_MOD(extack
,
481 "the hash_elasticity option has been deprecated and is always 16");
485 static ssize_t
hash_elasticity_store(struct device
*d
,
486 struct device_attribute
*attr
,
487 const char *buf
, size_t len
)
489 return store_bridge_parm(d
, buf
, len
, set_elasticity
);
491 static DEVICE_ATTR_RW(hash_elasticity
);
493 static ssize_t
hash_max_show(struct device
*d
, struct device_attribute
*attr
,
496 struct net_bridge
*br
= to_bridge(d
);
497 return sprintf(buf
, "%u\n", br
->hash_max
);
500 static int set_hash_max(struct net_bridge
*br
, unsigned long val
,
501 struct netlink_ext_ack
*extack
)
507 static ssize_t
hash_max_store(struct device
*d
, struct device_attribute
*attr
,
508 const char *buf
, size_t len
)
510 return store_bridge_parm(d
, buf
, len
, set_hash_max
);
512 static DEVICE_ATTR_RW(hash_max
);
514 static ssize_t
multicast_igmp_version_show(struct device
*d
,
515 struct device_attribute
*attr
,
518 struct net_bridge
*br
= to_bridge(d
);
520 return sprintf(buf
, "%u\n", br
->multicast_ctx
.multicast_igmp_version
);
523 static int set_multicast_igmp_version(struct net_bridge
*br
, unsigned long val
,
524 struct netlink_ext_ack
*extack
)
526 return br_multicast_set_igmp_version(&br
->multicast_ctx
, val
);
529 static ssize_t
multicast_igmp_version_store(struct device
*d
,
530 struct device_attribute
*attr
,
531 const char *buf
, size_t len
)
533 return store_bridge_parm(d
, buf
, len
, set_multicast_igmp_version
);
535 static DEVICE_ATTR_RW(multicast_igmp_version
);
537 static ssize_t
multicast_last_member_count_show(struct device
*d
,
538 struct device_attribute
*attr
,
541 struct net_bridge
*br
= to_bridge(d
);
542 return sprintf(buf
, "%u\n", br
->multicast_ctx
.multicast_last_member_count
);
545 static int set_last_member_count(struct net_bridge
*br
, unsigned long val
,
546 struct netlink_ext_ack
*extack
)
548 br
->multicast_ctx
.multicast_last_member_count
= val
;
552 static ssize_t
multicast_last_member_count_store(struct device
*d
,
553 struct device_attribute
*attr
,
554 const char *buf
, size_t len
)
556 return store_bridge_parm(d
, buf
, len
, set_last_member_count
);
558 static DEVICE_ATTR_RW(multicast_last_member_count
);
560 static ssize_t
multicast_startup_query_count_show(
561 struct device
*d
, struct device_attribute
*attr
, char *buf
)
563 struct net_bridge
*br
= to_bridge(d
);
564 return sprintf(buf
, "%u\n", br
->multicast_ctx
.multicast_startup_query_count
);
567 static int set_startup_query_count(struct net_bridge
*br
, unsigned long val
,
568 struct netlink_ext_ack
*extack
)
570 br
->multicast_ctx
.multicast_startup_query_count
= val
;
574 static ssize_t
multicast_startup_query_count_store(
575 struct device
*d
, struct device_attribute
*attr
, const char *buf
,
578 return store_bridge_parm(d
, buf
, len
, set_startup_query_count
);
580 static DEVICE_ATTR_RW(multicast_startup_query_count
);
582 static ssize_t
multicast_last_member_interval_show(
583 struct device
*d
, struct device_attribute
*attr
, char *buf
)
585 struct net_bridge
*br
= to_bridge(d
);
586 return sprintf(buf
, "%lu\n",
587 jiffies_to_clock_t(br
->multicast_ctx
.multicast_last_member_interval
));
590 static int set_last_member_interval(struct net_bridge
*br
, unsigned long val
,
591 struct netlink_ext_ack
*extack
)
593 br
->multicast_ctx
.multicast_last_member_interval
= clock_t_to_jiffies(val
);
597 static ssize_t
multicast_last_member_interval_store(
598 struct device
*d
, struct device_attribute
*attr
, const char *buf
,
601 return store_bridge_parm(d
, buf
, len
, set_last_member_interval
);
603 static DEVICE_ATTR_RW(multicast_last_member_interval
);
605 static ssize_t
multicast_membership_interval_show(
606 struct device
*d
, struct device_attribute
*attr
, char *buf
)
608 struct net_bridge
*br
= to_bridge(d
);
609 return sprintf(buf
, "%lu\n",
610 jiffies_to_clock_t(br
->multicast_ctx
.multicast_membership_interval
));
613 static int set_membership_interval(struct net_bridge
*br
, unsigned long val
,
614 struct netlink_ext_ack
*extack
)
616 br
->multicast_ctx
.multicast_membership_interval
= clock_t_to_jiffies(val
);
620 static ssize_t
multicast_membership_interval_store(
621 struct device
*d
, struct device_attribute
*attr
, const char *buf
,
624 return store_bridge_parm(d
, buf
, len
, set_membership_interval
);
626 static DEVICE_ATTR_RW(multicast_membership_interval
);
628 static ssize_t
multicast_querier_interval_show(struct device
*d
,
629 struct device_attribute
*attr
,
632 struct net_bridge
*br
= to_bridge(d
);
633 return sprintf(buf
, "%lu\n",
634 jiffies_to_clock_t(br
->multicast_ctx
.multicast_querier_interval
));
637 static int set_querier_interval(struct net_bridge
*br
, unsigned long val
,
638 struct netlink_ext_ack
*extack
)
640 br
->multicast_ctx
.multicast_querier_interval
= clock_t_to_jiffies(val
);
644 static ssize_t
multicast_querier_interval_store(struct device
*d
,
645 struct device_attribute
*attr
,
646 const char *buf
, size_t len
)
648 return store_bridge_parm(d
, buf
, len
, set_querier_interval
);
650 static DEVICE_ATTR_RW(multicast_querier_interval
);
652 static ssize_t
multicast_query_interval_show(struct device
*d
,
653 struct device_attribute
*attr
,
656 struct net_bridge
*br
= to_bridge(d
);
657 return sprintf(buf
, "%lu\n",
658 jiffies_to_clock_t(br
->multicast_ctx
.multicast_query_interval
));
661 static int set_query_interval(struct net_bridge
*br
, unsigned long val
,
662 struct netlink_ext_ack
*extack
)
664 br_multicast_set_query_intvl(&br
->multicast_ctx
, val
);
668 static ssize_t
multicast_query_interval_store(struct device
*d
,
669 struct device_attribute
*attr
,
670 const char *buf
, size_t len
)
672 return store_bridge_parm(d
, buf
, len
, set_query_interval
);
674 static DEVICE_ATTR_RW(multicast_query_interval
);
676 static ssize_t
multicast_query_response_interval_show(
677 struct device
*d
, struct device_attribute
*attr
, char *buf
)
679 struct net_bridge
*br
= to_bridge(d
);
682 jiffies_to_clock_t(br
->multicast_ctx
.multicast_query_response_interval
));
685 static int set_query_response_interval(struct net_bridge
*br
, unsigned long val
,
686 struct netlink_ext_ack
*extack
)
688 br
->multicast_ctx
.multicast_query_response_interval
= clock_t_to_jiffies(val
);
692 static ssize_t
multicast_query_response_interval_store(
693 struct device
*d
, struct device_attribute
*attr
, const char *buf
,
696 return store_bridge_parm(d
, buf
, len
, set_query_response_interval
);
698 static DEVICE_ATTR_RW(multicast_query_response_interval
);
700 static ssize_t
multicast_startup_query_interval_show(
701 struct device
*d
, struct device_attribute
*attr
, char *buf
)
703 struct net_bridge
*br
= to_bridge(d
);
706 jiffies_to_clock_t(br
->multicast_ctx
.multicast_startup_query_interval
));
709 static int set_startup_query_interval(struct net_bridge
*br
, unsigned long val
,
710 struct netlink_ext_ack
*extack
)
712 br_multicast_set_startup_query_intvl(&br
->multicast_ctx
, val
);
716 static ssize_t
multicast_startup_query_interval_store(
717 struct device
*d
, struct device_attribute
*attr
, const char *buf
,
720 return store_bridge_parm(d
, buf
, len
, set_startup_query_interval
);
722 static DEVICE_ATTR_RW(multicast_startup_query_interval
);
724 static ssize_t
multicast_stats_enabled_show(struct device
*d
,
725 struct device_attribute
*attr
,
728 struct net_bridge
*br
= to_bridge(d
);
730 return sprintf(buf
, "%d\n",
731 br_opt_get(br
, BROPT_MULTICAST_STATS_ENABLED
));
734 static int set_stats_enabled(struct net_bridge
*br
, unsigned long val
,
735 struct netlink_ext_ack
*extack
)
737 br_opt_toggle(br
, BROPT_MULTICAST_STATS_ENABLED
, !!val
);
741 static ssize_t
multicast_stats_enabled_store(struct device
*d
,
742 struct device_attribute
*attr
,
746 return store_bridge_parm(d
, buf
, len
, set_stats_enabled
);
748 static DEVICE_ATTR_RW(multicast_stats_enabled
);
750 #if IS_ENABLED(CONFIG_IPV6)
751 static ssize_t
multicast_mld_version_show(struct device
*d
,
752 struct device_attribute
*attr
,
755 struct net_bridge
*br
= to_bridge(d
);
757 return sprintf(buf
, "%u\n", br
->multicast_ctx
.multicast_mld_version
);
760 static int set_multicast_mld_version(struct net_bridge
*br
, unsigned long val
,
761 struct netlink_ext_ack
*extack
)
763 return br_multicast_set_mld_version(&br
->multicast_ctx
, val
);
766 static ssize_t
multicast_mld_version_store(struct device
*d
,
767 struct device_attribute
*attr
,
768 const char *buf
, size_t len
)
770 return store_bridge_parm(d
, buf
, len
, set_multicast_mld_version
);
772 static DEVICE_ATTR_RW(multicast_mld_version
);
775 #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
776 static ssize_t
nf_call_iptables_show(
777 struct device
*d
, struct device_attribute
*attr
, char *buf
)
779 struct net_bridge
*br
= to_bridge(d
);
780 return sprintf(buf
, "%u\n", br_opt_get(br
, BROPT_NF_CALL_IPTABLES
));
783 static int set_nf_call_iptables(struct net_bridge
*br
, unsigned long val
,
784 struct netlink_ext_ack
*extack
)
786 br_opt_toggle(br
, BROPT_NF_CALL_IPTABLES
, !!val
);
790 static ssize_t
nf_call_iptables_store(
791 struct device
*d
, struct device_attribute
*attr
, const char *buf
,
794 return store_bridge_parm(d
, buf
, len
, set_nf_call_iptables
);
796 static DEVICE_ATTR_RW(nf_call_iptables
);
798 static ssize_t
nf_call_ip6tables_show(
799 struct device
*d
, struct device_attribute
*attr
, char *buf
)
801 struct net_bridge
*br
= to_bridge(d
);
802 return sprintf(buf
, "%u\n", br_opt_get(br
, BROPT_NF_CALL_IP6TABLES
));
805 static int set_nf_call_ip6tables(struct net_bridge
*br
, unsigned long val
,
806 struct netlink_ext_ack
*extack
)
808 br_opt_toggle(br
, BROPT_NF_CALL_IP6TABLES
, !!val
);
812 static ssize_t
nf_call_ip6tables_store(
813 struct device
*d
, struct device_attribute
*attr
, const char *buf
,
816 return store_bridge_parm(d
, buf
, len
, set_nf_call_ip6tables
);
818 static DEVICE_ATTR_RW(nf_call_ip6tables
);
820 static ssize_t
nf_call_arptables_show(
821 struct device
*d
, struct device_attribute
*attr
, char *buf
)
823 struct net_bridge
*br
= to_bridge(d
);
824 return sprintf(buf
, "%u\n", br_opt_get(br
, BROPT_NF_CALL_ARPTABLES
));
827 static int set_nf_call_arptables(struct net_bridge
*br
, unsigned long val
,
828 struct netlink_ext_ack
*extack
)
830 br_opt_toggle(br
, BROPT_NF_CALL_ARPTABLES
, !!val
);
834 static ssize_t
nf_call_arptables_store(
835 struct device
*d
, struct device_attribute
*attr
, const char *buf
,
838 return store_bridge_parm(d
, buf
, len
, set_nf_call_arptables
);
840 static DEVICE_ATTR_RW(nf_call_arptables
);
842 #ifdef CONFIG_BRIDGE_VLAN_FILTERING
843 static ssize_t
vlan_filtering_show(struct device
*d
,
844 struct device_attribute
*attr
,
847 struct net_bridge
*br
= to_bridge(d
);
848 return sprintf(buf
, "%d\n", br_opt_get(br
, BROPT_VLAN_ENABLED
));
851 static ssize_t
vlan_filtering_store(struct device
*d
,
852 struct device_attribute
*attr
,
853 const char *buf
, size_t len
)
855 return store_bridge_parm(d
, buf
, len
, br_vlan_filter_toggle
);
857 static DEVICE_ATTR_RW(vlan_filtering
);
859 static ssize_t
vlan_protocol_show(struct device
*d
,
860 struct device_attribute
*attr
,
863 struct net_bridge
*br
= to_bridge(d
);
864 return sprintf(buf
, "%#06x\n", ntohs(br
->vlan_proto
));
867 static ssize_t
vlan_protocol_store(struct device
*d
,
868 struct device_attribute
*attr
,
869 const char *buf
, size_t len
)
871 return store_bridge_parm(d
, buf
, len
, br_vlan_set_proto
);
873 static DEVICE_ATTR_RW(vlan_protocol
);
875 static ssize_t
default_pvid_show(struct device
*d
,
876 struct device_attribute
*attr
,
879 struct net_bridge
*br
= to_bridge(d
);
880 return sprintf(buf
, "%d\n", br
->default_pvid
);
883 static ssize_t
default_pvid_store(struct device
*d
,
884 struct device_attribute
*attr
,
885 const char *buf
, size_t len
)
887 return store_bridge_parm(d
, buf
, len
, br_vlan_set_default_pvid
);
889 static DEVICE_ATTR_RW(default_pvid
);
891 static ssize_t
vlan_stats_enabled_show(struct device
*d
,
892 struct device_attribute
*attr
,
895 struct net_bridge
*br
= to_bridge(d
);
896 return sprintf(buf
, "%u\n", br_opt_get(br
, BROPT_VLAN_STATS_ENABLED
));
899 static int set_vlan_stats_enabled(struct net_bridge
*br
, unsigned long val
,
900 struct netlink_ext_ack
*extack
)
902 return br_vlan_set_stats(br
, val
);
905 static ssize_t
vlan_stats_enabled_store(struct device
*d
,
906 struct device_attribute
*attr
,
907 const char *buf
, size_t len
)
909 return store_bridge_parm(d
, buf
, len
, set_vlan_stats_enabled
);
911 static DEVICE_ATTR_RW(vlan_stats_enabled
);
913 static ssize_t
vlan_stats_per_port_show(struct device
*d
,
914 struct device_attribute
*attr
,
917 struct net_bridge
*br
= to_bridge(d
);
918 return sprintf(buf
, "%u\n", br_opt_get(br
, BROPT_VLAN_STATS_PER_PORT
));
921 static int set_vlan_stats_per_port(struct net_bridge
*br
, unsigned long val
,
922 struct netlink_ext_ack
*extack
)
924 return br_vlan_set_stats_per_port(br
, val
);
927 static ssize_t
vlan_stats_per_port_store(struct device
*d
,
928 struct device_attribute
*attr
,
929 const char *buf
, size_t len
)
931 return store_bridge_parm(d
, buf
, len
, set_vlan_stats_per_port
);
933 static DEVICE_ATTR_RW(vlan_stats_per_port
);
936 static struct attribute
*bridge_attrs
[] = {
937 &dev_attr_forward_delay
.attr
,
938 &dev_attr_hello_time
.attr
,
939 &dev_attr_max_age
.attr
,
940 &dev_attr_ageing_time
.attr
,
941 &dev_attr_stp_state
.attr
,
942 &dev_attr_group_fwd_mask
.attr
,
943 &dev_attr_priority
.attr
,
944 &dev_attr_bridge_id
.attr
,
945 &dev_attr_root_id
.attr
,
946 &dev_attr_root_path_cost
.attr
,
947 &dev_attr_root_port
.attr
,
948 &dev_attr_topology_change
.attr
,
949 &dev_attr_topology_change_detected
.attr
,
950 &dev_attr_hello_timer
.attr
,
951 &dev_attr_tcn_timer
.attr
,
952 &dev_attr_topology_change_timer
.attr
,
953 &dev_attr_gc_timer
.attr
,
954 &dev_attr_group_addr
.attr
,
955 &dev_attr_flush
.attr
,
956 &dev_attr_no_linklocal_learn
.attr
,
957 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
958 &dev_attr_multicast_router
.attr
,
959 &dev_attr_multicast_snooping
.attr
,
960 &dev_attr_multicast_querier
.attr
,
961 &dev_attr_multicast_query_use_ifaddr
.attr
,
962 &dev_attr_hash_elasticity
.attr
,
963 &dev_attr_hash_max
.attr
,
964 &dev_attr_multicast_last_member_count
.attr
,
965 &dev_attr_multicast_startup_query_count
.attr
,
966 &dev_attr_multicast_last_member_interval
.attr
,
967 &dev_attr_multicast_membership_interval
.attr
,
968 &dev_attr_multicast_querier_interval
.attr
,
969 &dev_attr_multicast_query_interval
.attr
,
970 &dev_attr_multicast_query_response_interval
.attr
,
971 &dev_attr_multicast_startup_query_interval
.attr
,
972 &dev_attr_multicast_stats_enabled
.attr
,
973 &dev_attr_multicast_igmp_version
.attr
,
974 #if IS_ENABLED(CONFIG_IPV6)
975 &dev_attr_multicast_mld_version
.attr
,
978 #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
979 &dev_attr_nf_call_iptables
.attr
,
980 &dev_attr_nf_call_ip6tables
.attr
,
981 &dev_attr_nf_call_arptables
.attr
,
983 #ifdef CONFIG_BRIDGE_VLAN_FILTERING
984 &dev_attr_vlan_filtering
.attr
,
985 &dev_attr_vlan_protocol
.attr
,
986 &dev_attr_default_pvid
.attr
,
987 &dev_attr_vlan_stats_enabled
.attr
,
988 &dev_attr_vlan_stats_per_port
.attr
,
993 static const struct attribute_group bridge_group
= {
994 .name
= SYSFS_BRIDGE_ATTR
,
995 .attrs
= bridge_attrs
,
999 * Export the forwarding information table as a binary file
1000 * The records are struct __fdb_entry.
1002 * Returns the number of bytes read.
1004 static ssize_t
brforward_read(struct file
*filp
, struct kobject
*kobj
,
1005 const struct bin_attribute
*bin_attr
,
1006 char *buf
, loff_t off
, size_t count
)
1008 struct device
*dev
= kobj_to_dev(kobj
);
1009 struct net_bridge
*br
= to_bridge(dev
);
1012 /* must read whole records */
1013 if (off
% sizeof(struct __fdb_entry
) != 0)
1016 n
= br_fdb_fillbuf(br
, buf
,
1017 count
/ sizeof(struct __fdb_entry
),
1018 off
/ sizeof(struct __fdb_entry
));
1021 n
*= sizeof(struct __fdb_entry
);
1026 static const struct bin_attribute bridge_forward
= {
1027 .attr
= { .name
= SYSFS_BRIDGE_FDB
,
1029 .read_new
= brforward_read
,
1033 * Add entries in sysfs onto the existing network class device
1035 * Adds a attribute group "bridge" containing tuning parameters.
1036 * Binary attribute containing the forward table
1037 * Sub directory to hold links to interfaces.
1039 * Note: the ifobj exists only to be a subdirectory
1040 * to hold links. The ifobj exists in same data structure
1041 * as it's parent the bridge so reference counting works.
1043 int br_sysfs_addbr(struct net_device
*dev
)
1045 struct kobject
*brobj
= &dev
->dev
.kobj
;
1046 struct net_bridge
*br
= netdev_priv(dev
);
1049 err
= sysfs_create_group(brobj
, &bridge_group
);
1051 pr_info("%s: can't create group %s/%s\n",
1052 __func__
, dev
->name
, bridge_group
.name
);
1056 err
= sysfs_create_bin_file(brobj
, &bridge_forward
);
1058 pr_info("%s: can't create attribute file %s/%s\n",
1059 __func__
, dev
->name
, bridge_forward
.attr
.name
);
1063 br
->ifobj
= kobject_create_and_add(SYSFS_BRIDGE_PORT_SUBDIR
, brobj
);
1065 pr_info("%s: can't add kobject (directory) %s/%s\n",
1066 __func__
, dev
->name
, SYSFS_BRIDGE_PORT_SUBDIR
);
1072 sysfs_remove_bin_file(&dev
->dev
.kobj
, &bridge_forward
);
1074 sysfs_remove_group(&dev
->dev
.kobj
, &bridge_group
);
1080 void br_sysfs_delbr(struct net_device
*dev
)
1082 struct kobject
*kobj
= &dev
->dev
.kobj
;
1083 struct net_bridge
*br
= netdev_priv(dev
);
1085 kobject_put(br
->ifobj
);
1086 sysfs_remove_bin_file(kobj
, &bridge_forward
);
1087 sysfs_remove_group(kobj
, &bridge_group
);