of: MSI: Simplify irqdomain lookup
[linux/fpc-iii.git] / net / bridge / br_sysfs_br.c
blob8365bd53c42179dec15314fa99bf2346f729899f
1 /*
2 * Sysfs attributes of bridge
3 * Linux ethernet bridge
5 * Authors:
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_dev(obj) container_of(obj, struct device, kobj)
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);
36 char *endp;
37 unsigned long val;
38 int err;
40 if (!ns_capable(dev_net(br->dev)->user_ns, CAP_NET_ADMIN))
41 return -EPERM;
43 val = simple_strtoul(buf, &endp, 0);
44 if (endp == buf)
45 return -EINVAL;
47 err = (*set)(br, val);
48 return err ? err : len;
52 static ssize_t forward_delay_show(struct device *d,
53 struct device_attribute *attr, char *buf)
55 struct net_bridge *br = to_bridge(d);
56 return sprintf(buf, "%lu\n", jiffies_to_clock_t(br->forward_delay));
59 static ssize_t forward_delay_store(struct device *d,
60 struct device_attribute *attr,
61 const char *buf, size_t len)
63 return store_bridge_parm(d, buf, len, br_set_forward_delay);
65 static DEVICE_ATTR_RW(forward_delay);
67 static ssize_t hello_time_show(struct device *d, struct device_attribute *attr,
68 char *buf)
70 return sprintf(buf, "%lu\n",
71 jiffies_to_clock_t(to_bridge(d)->hello_time));
74 static ssize_t hello_time_store(struct device *d,
75 struct device_attribute *attr, const char *buf,
76 size_t len)
78 return store_bridge_parm(d, buf, len, br_set_hello_time);
80 static DEVICE_ATTR_RW(hello_time);
82 static ssize_t max_age_show(struct device *d, struct device_attribute *attr,
83 char *buf)
85 return sprintf(buf, "%lu\n",
86 jiffies_to_clock_t(to_bridge(d)->max_age));
89 static ssize_t max_age_store(struct device *d, struct device_attribute *attr,
90 const char *buf, size_t len)
92 return store_bridge_parm(d, buf, len, br_set_max_age);
94 static DEVICE_ATTR_RW(max_age);
96 static ssize_t ageing_time_show(struct device *d,
97 struct device_attribute *attr, char *buf)
99 struct net_bridge *br = to_bridge(d);
100 return sprintf(buf, "%lu\n", jiffies_to_clock_t(br->ageing_time));
103 static int set_ageing_time(struct net_bridge *br, unsigned long val)
105 int ret;
107 if (!rtnl_trylock())
108 return restart_syscall();
110 ret = br_set_ageing_time(br, val);
111 rtnl_unlock();
113 return ret;
116 static ssize_t ageing_time_store(struct device *d,
117 struct device_attribute *attr,
118 const char *buf, size_t len)
120 return store_bridge_parm(d, buf, len, set_ageing_time);
122 static DEVICE_ATTR_RW(ageing_time);
124 static ssize_t stp_state_show(struct device *d,
125 struct device_attribute *attr, char *buf)
127 struct net_bridge *br = to_bridge(d);
128 return sprintf(buf, "%d\n", br->stp_enabled);
132 static ssize_t stp_state_store(struct device *d,
133 struct device_attribute *attr, const char *buf,
134 size_t len)
136 struct net_bridge *br = to_bridge(d);
137 char *endp;
138 unsigned long val;
140 if (!ns_capable(dev_net(br->dev)->user_ns, CAP_NET_ADMIN))
141 return -EPERM;
143 val = simple_strtoul(buf, &endp, 0);
144 if (endp == buf)
145 return -EINVAL;
147 if (!rtnl_trylock())
148 return restart_syscall();
149 br_stp_set_enabled(br, val);
150 rtnl_unlock();
152 return len;
154 static DEVICE_ATTR_RW(stp_state);
156 static ssize_t group_fwd_mask_show(struct device *d,
157 struct device_attribute *attr,
158 char *buf)
160 struct net_bridge *br = to_bridge(d);
161 return sprintf(buf, "%#x\n", br->group_fwd_mask);
165 static ssize_t group_fwd_mask_store(struct device *d,
166 struct device_attribute *attr,
167 const char *buf,
168 size_t len)
170 struct net_bridge *br = to_bridge(d);
171 char *endp;
172 unsigned long val;
174 if (!ns_capable(dev_net(br->dev)->user_ns, CAP_NET_ADMIN))
175 return -EPERM;
177 val = simple_strtoul(buf, &endp, 0);
178 if (endp == buf)
179 return -EINVAL;
181 if (val & BR_GROUPFWD_RESTRICTED)
182 return -EINVAL;
184 br->group_fwd_mask = val;
186 return len;
188 static DEVICE_ATTR_RW(group_fwd_mask);
190 static ssize_t priority_show(struct device *d, struct device_attribute *attr,
191 char *buf)
193 struct net_bridge *br = to_bridge(d);
194 return sprintf(buf, "%d\n",
195 (br->bridge_id.prio[0] << 8) | br->bridge_id.prio[1]);
198 static int set_priority(struct net_bridge *br, unsigned long val)
200 br_stp_set_bridge_priority(br, (u16) val);
201 return 0;
204 static ssize_t priority_store(struct device *d, struct device_attribute *attr,
205 const char *buf, size_t len)
207 return store_bridge_parm(d, buf, len, set_priority);
209 static DEVICE_ATTR_RW(priority);
211 static ssize_t root_id_show(struct device *d, struct device_attribute *attr,
212 char *buf)
214 return br_show_bridge_id(buf, &to_bridge(d)->designated_root);
216 static DEVICE_ATTR_RO(root_id);
218 static ssize_t bridge_id_show(struct device *d, struct device_attribute *attr,
219 char *buf)
221 return br_show_bridge_id(buf, &to_bridge(d)->bridge_id);
223 static DEVICE_ATTR_RO(bridge_id);
225 static ssize_t root_port_show(struct device *d, struct device_attribute *attr,
226 char *buf)
228 return sprintf(buf, "%d\n", to_bridge(d)->root_port);
230 static DEVICE_ATTR_RO(root_port);
232 static ssize_t root_path_cost_show(struct device *d,
233 struct device_attribute *attr, char *buf)
235 return sprintf(buf, "%d\n", to_bridge(d)->root_path_cost);
237 static DEVICE_ATTR_RO(root_path_cost);
239 static ssize_t topology_change_show(struct device *d,
240 struct device_attribute *attr, char *buf)
242 return sprintf(buf, "%d\n", to_bridge(d)->topology_change);
244 static DEVICE_ATTR_RO(topology_change);
246 static ssize_t topology_change_detected_show(struct device *d,
247 struct device_attribute *attr,
248 char *buf)
250 struct net_bridge *br = to_bridge(d);
251 return sprintf(buf, "%d\n", br->topology_change_detected);
253 static DEVICE_ATTR_RO(topology_change_detected);
255 static ssize_t hello_timer_show(struct device *d,
256 struct device_attribute *attr, char *buf)
258 struct net_bridge *br = to_bridge(d);
259 return sprintf(buf, "%ld\n", br_timer_value(&br->hello_timer));
261 static DEVICE_ATTR_RO(hello_timer);
263 static ssize_t tcn_timer_show(struct device *d, struct device_attribute *attr,
264 char *buf)
266 struct net_bridge *br = to_bridge(d);
267 return sprintf(buf, "%ld\n", br_timer_value(&br->tcn_timer));
269 static DEVICE_ATTR_RO(tcn_timer);
271 static ssize_t topology_change_timer_show(struct device *d,
272 struct device_attribute *attr,
273 char *buf)
275 struct net_bridge *br = to_bridge(d);
276 return sprintf(buf, "%ld\n", br_timer_value(&br->topology_change_timer));
278 static DEVICE_ATTR_RO(topology_change_timer);
280 static ssize_t gc_timer_show(struct device *d, struct device_attribute *attr,
281 char *buf)
283 struct net_bridge *br = to_bridge(d);
284 return sprintf(buf, "%ld\n", br_timer_value(&br->gc_timer));
286 static DEVICE_ATTR_RO(gc_timer);
288 static ssize_t group_addr_show(struct device *d,
289 struct device_attribute *attr, char *buf)
291 struct net_bridge *br = to_bridge(d);
292 return sprintf(buf, "%x:%x:%x:%x:%x:%x\n",
293 br->group_addr[0], br->group_addr[1],
294 br->group_addr[2], br->group_addr[3],
295 br->group_addr[4], br->group_addr[5]);
298 static ssize_t group_addr_store(struct device *d,
299 struct device_attribute *attr,
300 const char *buf, size_t len)
302 struct net_bridge *br = to_bridge(d);
303 u8 new_addr[6];
304 int i;
306 if (!ns_capable(dev_net(br->dev)->user_ns, CAP_NET_ADMIN))
307 return -EPERM;
309 if (sscanf(buf, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx",
310 &new_addr[0], &new_addr[1], &new_addr[2],
311 &new_addr[3], &new_addr[4], &new_addr[5]) != 6)
312 return -EINVAL;
314 if (!is_link_local_ether_addr(new_addr))
315 return -EINVAL;
317 if (new_addr[5] == 1 || /* 802.3x Pause address */
318 new_addr[5] == 2 || /* 802.3ad Slow protocols */
319 new_addr[5] == 3) /* 802.1X PAE address */
320 return -EINVAL;
322 if (!rtnl_trylock())
323 return restart_syscall();
325 spin_lock_bh(&br->lock);
326 for (i = 0; i < 6; i++)
327 br->group_addr[i] = new_addr[i];
328 spin_unlock_bh(&br->lock);
330 br->group_addr_set = true;
331 br_recalculate_fwd_mask(br);
333 rtnl_unlock();
335 return len;
338 static DEVICE_ATTR_RW(group_addr);
340 static ssize_t flush_store(struct device *d,
341 struct device_attribute *attr,
342 const char *buf, size_t len)
344 struct net_bridge *br = to_bridge(d);
346 if (!ns_capable(dev_net(br->dev)->user_ns, CAP_NET_ADMIN))
347 return -EPERM;
349 br_fdb_flush(br);
350 return len;
352 static DEVICE_ATTR_WO(flush);
354 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
355 static ssize_t multicast_router_show(struct device *d,
356 struct device_attribute *attr, char *buf)
358 struct net_bridge *br = to_bridge(d);
359 return sprintf(buf, "%d\n", br->multicast_router);
362 static ssize_t multicast_router_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_set_router);
368 static DEVICE_ATTR_RW(multicast_router);
370 static ssize_t multicast_snooping_show(struct device *d,
371 struct device_attribute *attr,
372 char *buf)
374 struct net_bridge *br = to_bridge(d);
375 return sprintf(buf, "%d\n", !br->multicast_disabled);
378 static ssize_t multicast_snooping_store(struct device *d,
379 struct device_attribute *attr,
380 const char *buf, size_t len)
382 return store_bridge_parm(d, buf, len, br_multicast_toggle);
384 static DEVICE_ATTR_RW(multicast_snooping);
386 static ssize_t multicast_query_use_ifaddr_show(struct device *d,
387 struct device_attribute *attr,
388 char *buf)
390 struct net_bridge *br = to_bridge(d);
391 return sprintf(buf, "%d\n", br->multicast_query_use_ifaddr);
394 static int set_query_use_ifaddr(struct net_bridge *br, unsigned long val)
396 br->multicast_query_use_ifaddr = !!val;
397 return 0;
400 static ssize_t
401 multicast_query_use_ifaddr_store(struct device *d,
402 struct device_attribute *attr,
403 const char *buf, size_t len)
405 return store_bridge_parm(d, buf, len, set_query_use_ifaddr);
407 static DEVICE_ATTR_RW(multicast_query_use_ifaddr);
409 static ssize_t multicast_querier_show(struct device *d,
410 struct device_attribute *attr,
411 char *buf)
413 struct net_bridge *br = to_bridge(d);
414 return sprintf(buf, "%d\n", br->multicast_querier);
417 static ssize_t multicast_querier_store(struct device *d,
418 struct device_attribute *attr,
419 const char *buf, size_t len)
421 return store_bridge_parm(d, buf, len, br_multicast_set_querier);
423 static DEVICE_ATTR_RW(multicast_querier);
425 static ssize_t hash_elasticity_show(struct device *d,
426 struct device_attribute *attr, char *buf)
428 struct net_bridge *br = to_bridge(d);
429 return sprintf(buf, "%u\n", br->hash_elasticity);
432 static int set_elasticity(struct net_bridge *br, unsigned long val)
434 br->hash_elasticity = val;
435 return 0;
438 static ssize_t hash_elasticity_store(struct device *d,
439 struct device_attribute *attr,
440 const char *buf, size_t len)
442 return store_bridge_parm(d, buf, len, set_elasticity);
444 static DEVICE_ATTR_RW(hash_elasticity);
446 static ssize_t hash_max_show(struct device *d, struct device_attribute *attr,
447 char *buf)
449 struct net_bridge *br = to_bridge(d);
450 return sprintf(buf, "%u\n", br->hash_max);
453 static ssize_t hash_max_store(struct device *d, struct device_attribute *attr,
454 const char *buf, size_t len)
456 return store_bridge_parm(d, buf, len, br_multicast_set_hash_max);
458 static DEVICE_ATTR_RW(hash_max);
460 static ssize_t multicast_last_member_count_show(struct device *d,
461 struct device_attribute *attr,
462 char *buf)
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;
471 return 0;
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;
492 return 0;
495 static ssize_t multicast_startup_query_count_store(
496 struct device *d, struct device_attribute *attr, const char *buf,
497 size_t len)
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);
514 return 0;
517 static ssize_t multicast_last_member_interval_store(
518 struct device *d, struct device_attribute *attr, const char *buf,
519 size_t len)
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);
536 return 0;
539 static ssize_t multicast_membership_interval_store(
540 struct device *d, struct device_attribute *attr, const char *buf,
541 size_t len)
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,
549 char *buf)
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);
559 return 0;
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,
572 char *buf)
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);
582 return 0;
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);
597 return sprintf(
598 buf, "%lu\n",
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);
605 return 0;
608 static ssize_t multicast_query_response_interval_store(
609 struct device *d, struct device_attribute *attr, const char *buf,
610 size_t len)
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);
620 return sprintf(
621 buf, "%lu\n",
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);
628 return 0;
631 static ssize_t multicast_startup_query_interval_store(
632 struct device *d, struct device_attribute *attr, const char *buf,
633 size_t len)
635 return store_bridge_parm(d, buf, len, set_startup_query_interval);
637 static DEVICE_ATTR_RW(multicast_startup_query_interval);
638 #endif
639 #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
640 static ssize_t nf_call_iptables_show(
641 struct device *d, struct device_attribute *attr, char *buf)
643 struct net_bridge *br = to_bridge(d);
644 return sprintf(buf, "%u\n", br->nf_call_iptables);
647 static int set_nf_call_iptables(struct net_bridge *br, unsigned long val)
649 br->nf_call_iptables = val ? true : false;
650 return 0;
653 static ssize_t nf_call_iptables_store(
654 struct device *d, struct device_attribute *attr, const char *buf,
655 size_t len)
657 return store_bridge_parm(d, buf, len, set_nf_call_iptables);
659 static DEVICE_ATTR_RW(nf_call_iptables);
661 static ssize_t nf_call_ip6tables_show(
662 struct device *d, struct device_attribute *attr, char *buf)
664 struct net_bridge *br = to_bridge(d);
665 return sprintf(buf, "%u\n", br->nf_call_ip6tables);
668 static int set_nf_call_ip6tables(struct net_bridge *br, unsigned long val)
670 br->nf_call_ip6tables = val ? true : false;
671 return 0;
674 static ssize_t nf_call_ip6tables_store(
675 struct device *d, struct device_attribute *attr, const char *buf,
676 size_t len)
678 return store_bridge_parm(d, buf, len, set_nf_call_ip6tables);
680 static DEVICE_ATTR_RW(nf_call_ip6tables);
682 static ssize_t nf_call_arptables_show(
683 struct device *d, struct device_attribute *attr, char *buf)
685 struct net_bridge *br = to_bridge(d);
686 return sprintf(buf, "%u\n", br->nf_call_arptables);
689 static int set_nf_call_arptables(struct net_bridge *br, unsigned long val)
691 br->nf_call_arptables = val ? true : false;
692 return 0;
695 static ssize_t nf_call_arptables_store(
696 struct device *d, struct device_attribute *attr, const char *buf,
697 size_t len)
699 return store_bridge_parm(d, buf, len, set_nf_call_arptables);
701 static DEVICE_ATTR_RW(nf_call_arptables);
702 #endif
703 #ifdef CONFIG_BRIDGE_VLAN_FILTERING
704 static ssize_t vlan_filtering_show(struct device *d,
705 struct device_attribute *attr,
706 char *buf)
708 struct net_bridge *br = to_bridge(d);
709 return sprintf(buf, "%d\n", br->vlan_enabled);
712 static ssize_t vlan_filtering_store(struct device *d,
713 struct device_attribute *attr,
714 const char *buf, size_t len)
716 return store_bridge_parm(d, buf, len, br_vlan_filter_toggle);
718 static DEVICE_ATTR_RW(vlan_filtering);
720 static ssize_t vlan_protocol_show(struct device *d,
721 struct device_attribute *attr,
722 char *buf)
724 struct net_bridge *br = to_bridge(d);
725 return sprintf(buf, "%#06x\n", ntohs(br->vlan_proto));
728 static ssize_t vlan_protocol_store(struct device *d,
729 struct device_attribute *attr,
730 const char *buf, size_t len)
732 return store_bridge_parm(d, buf, len, br_vlan_set_proto);
734 static DEVICE_ATTR_RW(vlan_protocol);
736 static ssize_t default_pvid_show(struct device *d,
737 struct device_attribute *attr,
738 char *buf)
740 struct net_bridge *br = to_bridge(d);
741 return sprintf(buf, "%d\n", br->default_pvid);
744 static ssize_t default_pvid_store(struct device *d,
745 struct device_attribute *attr,
746 const char *buf, size_t len)
748 return store_bridge_parm(d, buf, len, br_vlan_set_default_pvid);
750 static DEVICE_ATTR_RW(default_pvid);
751 #endif
753 static struct attribute *bridge_attrs[] = {
754 &dev_attr_forward_delay.attr,
755 &dev_attr_hello_time.attr,
756 &dev_attr_max_age.attr,
757 &dev_attr_ageing_time.attr,
758 &dev_attr_stp_state.attr,
759 &dev_attr_group_fwd_mask.attr,
760 &dev_attr_priority.attr,
761 &dev_attr_bridge_id.attr,
762 &dev_attr_root_id.attr,
763 &dev_attr_root_path_cost.attr,
764 &dev_attr_root_port.attr,
765 &dev_attr_topology_change.attr,
766 &dev_attr_topology_change_detected.attr,
767 &dev_attr_hello_timer.attr,
768 &dev_attr_tcn_timer.attr,
769 &dev_attr_topology_change_timer.attr,
770 &dev_attr_gc_timer.attr,
771 &dev_attr_group_addr.attr,
772 &dev_attr_flush.attr,
773 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
774 &dev_attr_multicast_router.attr,
775 &dev_attr_multicast_snooping.attr,
776 &dev_attr_multicast_querier.attr,
777 &dev_attr_multicast_query_use_ifaddr.attr,
778 &dev_attr_hash_elasticity.attr,
779 &dev_attr_hash_max.attr,
780 &dev_attr_multicast_last_member_count.attr,
781 &dev_attr_multicast_startup_query_count.attr,
782 &dev_attr_multicast_last_member_interval.attr,
783 &dev_attr_multicast_membership_interval.attr,
784 &dev_attr_multicast_querier_interval.attr,
785 &dev_attr_multicast_query_interval.attr,
786 &dev_attr_multicast_query_response_interval.attr,
787 &dev_attr_multicast_startup_query_interval.attr,
788 #endif
789 #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
790 &dev_attr_nf_call_iptables.attr,
791 &dev_attr_nf_call_ip6tables.attr,
792 &dev_attr_nf_call_arptables.attr,
793 #endif
794 #ifdef CONFIG_BRIDGE_VLAN_FILTERING
795 &dev_attr_vlan_filtering.attr,
796 &dev_attr_vlan_protocol.attr,
797 &dev_attr_default_pvid.attr,
798 #endif
799 NULL
802 static struct attribute_group bridge_group = {
803 .name = SYSFS_BRIDGE_ATTR,
804 .attrs = bridge_attrs,
808 * Export the forwarding information table as a binary file
809 * The records are struct __fdb_entry.
811 * Returns the number of bytes read.
813 static ssize_t brforward_read(struct file *filp, struct kobject *kobj,
814 struct bin_attribute *bin_attr,
815 char *buf, loff_t off, size_t count)
817 struct device *dev = to_dev(kobj);
818 struct net_bridge *br = to_bridge(dev);
819 int n;
821 /* must read whole records */
822 if (off % sizeof(struct __fdb_entry) != 0)
823 return -EINVAL;
825 n = br_fdb_fillbuf(br, buf,
826 count / sizeof(struct __fdb_entry),
827 off / sizeof(struct __fdb_entry));
829 if (n > 0)
830 n *= sizeof(struct __fdb_entry);
832 return n;
835 static struct bin_attribute bridge_forward = {
836 .attr = { .name = SYSFS_BRIDGE_FDB,
837 .mode = S_IRUGO, },
838 .read = brforward_read,
842 * Add entries in sysfs onto the existing network class device
843 * for the bridge.
844 * Adds a attribute group "bridge" containing tuning parameters.
845 * Binary attribute containing the forward table
846 * Sub directory to hold links to interfaces.
848 * Note: the ifobj exists only to be a subdirectory
849 * to hold links. The ifobj exists in same data structure
850 * as it's parent the bridge so reference counting works.
852 int br_sysfs_addbr(struct net_device *dev)
854 struct kobject *brobj = &dev->dev.kobj;
855 struct net_bridge *br = netdev_priv(dev);
856 int err;
858 err = sysfs_create_group(brobj, &bridge_group);
859 if (err) {
860 pr_info("%s: can't create group %s/%s\n",
861 __func__, dev->name, bridge_group.name);
862 goto out1;
865 err = sysfs_create_bin_file(brobj, &bridge_forward);
866 if (err) {
867 pr_info("%s: can't create attribute file %s/%s\n",
868 __func__, dev->name, bridge_forward.attr.name);
869 goto out2;
872 br->ifobj = kobject_create_and_add(SYSFS_BRIDGE_PORT_SUBDIR, brobj);
873 if (!br->ifobj) {
874 pr_info("%s: can't add kobject (directory) %s/%s\n",
875 __func__, dev->name, SYSFS_BRIDGE_PORT_SUBDIR);
876 goto out3;
878 return 0;
879 out3:
880 sysfs_remove_bin_file(&dev->dev.kobj, &bridge_forward);
881 out2:
882 sysfs_remove_group(&dev->dev.kobj, &bridge_group);
883 out1:
884 return err;
888 void br_sysfs_delbr(struct net_device *dev)
890 struct kobject *kobj = &dev->dev.kobj;
891 struct net_bridge *br = netdev_priv(dev);
893 kobject_put(br->ifobj);
894 sysfs_remove_bin_file(kobj, &bridge_forward);
895 sysfs_remove_group(kobj, &bridge_group);