cxl: Configure PSL for kernel contexts and merge code
[linux/fpc-iii.git] / net / bridge / br_sysfs_br.c
blob4c97fc50fb704265bd2f51d96527cf3227a65118
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 br->ageing_time = clock_t_to_jiffies(val);
106 return 0;
109 static ssize_t ageing_time_store(struct device *d,
110 struct device_attribute *attr,
111 const char *buf, size_t len)
113 return store_bridge_parm(d, buf, len, set_ageing_time);
115 static DEVICE_ATTR_RW(ageing_time);
117 static ssize_t stp_state_show(struct device *d,
118 struct device_attribute *attr, char *buf)
120 struct net_bridge *br = to_bridge(d);
121 return sprintf(buf, "%d\n", br->stp_enabled);
125 static ssize_t stp_state_store(struct device *d,
126 struct device_attribute *attr, const char *buf,
127 size_t len)
129 struct net_bridge *br = to_bridge(d);
130 char *endp;
131 unsigned long val;
133 if (!ns_capable(dev_net(br->dev)->user_ns, CAP_NET_ADMIN))
134 return -EPERM;
136 val = simple_strtoul(buf, &endp, 0);
137 if (endp == buf)
138 return -EINVAL;
140 if (!rtnl_trylock())
141 return restart_syscall();
142 br_stp_set_enabled(br, val);
143 rtnl_unlock();
145 return len;
147 static DEVICE_ATTR_RW(stp_state);
149 static ssize_t group_fwd_mask_show(struct device *d,
150 struct device_attribute *attr,
151 char *buf)
153 struct net_bridge *br = to_bridge(d);
154 return sprintf(buf, "%#x\n", br->group_fwd_mask);
158 static ssize_t group_fwd_mask_store(struct device *d,
159 struct device_attribute *attr,
160 const char *buf,
161 size_t len)
163 struct net_bridge *br = to_bridge(d);
164 char *endp;
165 unsigned long val;
167 if (!ns_capable(dev_net(br->dev)->user_ns, CAP_NET_ADMIN))
168 return -EPERM;
170 val = simple_strtoul(buf, &endp, 0);
171 if (endp == buf)
172 return -EINVAL;
174 if (val & BR_GROUPFWD_RESTRICTED)
175 return -EINVAL;
177 br->group_fwd_mask = val;
179 return len;
181 static DEVICE_ATTR_RW(group_fwd_mask);
183 static ssize_t priority_show(struct device *d, struct device_attribute *attr,
184 char *buf)
186 struct net_bridge *br = to_bridge(d);
187 return sprintf(buf, "%d\n",
188 (br->bridge_id.prio[0] << 8) | br->bridge_id.prio[1]);
191 static int set_priority(struct net_bridge *br, unsigned long val)
193 br_stp_set_bridge_priority(br, (u16) val);
194 return 0;
197 static ssize_t priority_store(struct device *d, struct device_attribute *attr,
198 const char *buf, size_t len)
200 return store_bridge_parm(d, buf, len, set_priority);
202 static DEVICE_ATTR_RW(priority);
204 static ssize_t root_id_show(struct device *d, struct device_attribute *attr,
205 char *buf)
207 return br_show_bridge_id(buf, &to_bridge(d)->designated_root);
209 static DEVICE_ATTR_RO(root_id);
211 static ssize_t bridge_id_show(struct device *d, struct device_attribute *attr,
212 char *buf)
214 return br_show_bridge_id(buf, &to_bridge(d)->bridge_id);
216 static DEVICE_ATTR_RO(bridge_id);
218 static ssize_t root_port_show(struct device *d, struct device_attribute *attr,
219 char *buf)
221 return sprintf(buf, "%d\n", to_bridge(d)->root_port);
223 static DEVICE_ATTR_RO(root_port);
225 static ssize_t root_path_cost_show(struct device *d,
226 struct device_attribute *attr, char *buf)
228 return sprintf(buf, "%d\n", to_bridge(d)->root_path_cost);
230 static DEVICE_ATTR_RO(root_path_cost);
232 static ssize_t topology_change_show(struct device *d,
233 struct device_attribute *attr, char *buf)
235 return sprintf(buf, "%d\n", to_bridge(d)->topology_change);
237 static DEVICE_ATTR_RO(topology_change);
239 static ssize_t topology_change_detected_show(struct device *d,
240 struct device_attribute *attr,
241 char *buf)
243 struct net_bridge *br = to_bridge(d);
244 return sprintf(buf, "%d\n", br->topology_change_detected);
246 static DEVICE_ATTR_RO(topology_change_detected);
248 static ssize_t hello_timer_show(struct device *d,
249 struct device_attribute *attr, char *buf)
251 struct net_bridge *br = to_bridge(d);
252 return sprintf(buf, "%ld\n", br_timer_value(&br->hello_timer));
254 static DEVICE_ATTR_RO(hello_timer);
256 static ssize_t tcn_timer_show(struct device *d, struct device_attribute *attr,
257 char *buf)
259 struct net_bridge *br = to_bridge(d);
260 return sprintf(buf, "%ld\n", br_timer_value(&br->tcn_timer));
262 static DEVICE_ATTR_RO(tcn_timer);
264 static ssize_t topology_change_timer_show(struct device *d,
265 struct device_attribute *attr,
266 char *buf)
268 struct net_bridge *br = to_bridge(d);
269 return sprintf(buf, "%ld\n", br_timer_value(&br->topology_change_timer));
271 static DEVICE_ATTR_RO(topology_change_timer);
273 static ssize_t gc_timer_show(struct device *d, struct device_attribute *attr,
274 char *buf)
276 struct net_bridge *br = to_bridge(d);
277 return sprintf(buf, "%ld\n", br_timer_value(&br->gc_timer));
279 static DEVICE_ATTR_RO(gc_timer);
281 static ssize_t group_addr_show(struct device *d,
282 struct device_attribute *attr, char *buf)
284 struct net_bridge *br = to_bridge(d);
285 return sprintf(buf, "%x:%x:%x:%x:%x:%x\n",
286 br->group_addr[0], br->group_addr[1],
287 br->group_addr[2], br->group_addr[3],
288 br->group_addr[4], br->group_addr[5]);
291 static ssize_t group_addr_store(struct device *d,
292 struct device_attribute *attr,
293 const char *buf, size_t len)
295 struct net_bridge *br = to_bridge(d);
296 u8 new_addr[6];
297 int i;
299 if (!ns_capable(dev_net(br->dev)->user_ns, CAP_NET_ADMIN))
300 return -EPERM;
302 if (sscanf(buf, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx",
303 &new_addr[0], &new_addr[1], &new_addr[2],
304 &new_addr[3], &new_addr[4], &new_addr[5]) != 6)
305 return -EINVAL;
307 if (!is_link_local_ether_addr(new_addr))
308 return -EINVAL;
310 if (new_addr[5] == 1 || /* 802.3x Pause address */
311 new_addr[5] == 2 || /* 802.3ad Slow protocols */
312 new_addr[5] == 3) /* 802.1X PAE address */
313 return -EINVAL;
315 if (!rtnl_trylock())
316 return restart_syscall();
318 spin_lock_bh(&br->lock);
319 for (i = 0; i < 6; i++)
320 br->group_addr[i] = new_addr[i];
321 spin_unlock_bh(&br->lock);
323 br->group_addr_set = true;
324 br_recalculate_fwd_mask(br);
326 rtnl_unlock();
328 return len;
331 static DEVICE_ATTR_RW(group_addr);
333 static ssize_t flush_store(struct device *d,
334 struct device_attribute *attr,
335 const char *buf, size_t len)
337 struct net_bridge *br = to_bridge(d);
339 if (!ns_capable(dev_net(br->dev)->user_ns, CAP_NET_ADMIN))
340 return -EPERM;
342 br_fdb_flush(br);
343 return len;
345 static DEVICE_ATTR_WO(flush);
347 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
348 static ssize_t multicast_router_show(struct device *d,
349 struct device_attribute *attr, char *buf)
351 struct net_bridge *br = to_bridge(d);
352 return sprintf(buf, "%d\n", br->multicast_router);
355 static ssize_t multicast_router_store(struct device *d,
356 struct device_attribute *attr,
357 const char *buf, size_t len)
359 return store_bridge_parm(d, buf, len, br_multicast_set_router);
361 static DEVICE_ATTR_RW(multicast_router);
363 static ssize_t multicast_snooping_show(struct device *d,
364 struct device_attribute *attr,
365 char *buf)
367 struct net_bridge *br = to_bridge(d);
368 return sprintf(buf, "%d\n", !br->multicast_disabled);
371 static ssize_t multicast_snooping_store(struct device *d,
372 struct device_attribute *attr,
373 const char *buf, size_t len)
375 return store_bridge_parm(d, buf, len, br_multicast_toggle);
377 static DEVICE_ATTR_RW(multicast_snooping);
379 static ssize_t multicast_query_use_ifaddr_show(struct device *d,
380 struct device_attribute *attr,
381 char *buf)
383 struct net_bridge *br = to_bridge(d);
384 return sprintf(buf, "%d\n", br->multicast_query_use_ifaddr);
387 static int set_query_use_ifaddr(struct net_bridge *br, unsigned long val)
389 br->multicast_query_use_ifaddr = !!val;
390 return 0;
393 static ssize_t
394 multicast_query_use_ifaddr_store(struct device *d,
395 struct device_attribute *attr,
396 const char *buf, size_t len)
398 return store_bridge_parm(d, buf, len, set_query_use_ifaddr);
400 static DEVICE_ATTR_RW(multicast_query_use_ifaddr);
402 static ssize_t multicast_querier_show(struct device *d,
403 struct device_attribute *attr,
404 char *buf)
406 struct net_bridge *br = to_bridge(d);
407 return sprintf(buf, "%d\n", br->multicast_querier);
410 static ssize_t multicast_querier_store(struct device *d,
411 struct device_attribute *attr,
412 const char *buf, size_t len)
414 return store_bridge_parm(d, buf, len, br_multicast_set_querier);
416 static DEVICE_ATTR_RW(multicast_querier);
418 static ssize_t hash_elasticity_show(struct device *d,
419 struct device_attribute *attr, char *buf)
421 struct net_bridge *br = to_bridge(d);
422 return sprintf(buf, "%u\n", br->hash_elasticity);
425 static int set_elasticity(struct net_bridge *br, unsigned long val)
427 br->hash_elasticity = val;
428 return 0;
431 static ssize_t hash_elasticity_store(struct device *d,
432 struct device_attribute *attr,
433 const char *buf, size_t len)
435 return store_bridge_parm(d, buf, len, set_elasticity);
437 static DEVICE_ATTR_RW(hash_elasticity);
439 static ssize_t hash_max_show(struct device *d, struct device_attribute *attr,
440 char *buf)
442 struct net_bridge *br = to_bridge(d);
443 return sprintf(buf, "%u\n", br->hash_max);
446 static ssize_t hash_max_store(struct device *d, struct device_attribute *attr,
447 const char *buf, size_t len)
449 return store_bridge_parm(d, buf, len, br_multicast_set_hash_max);
451 static DEVICE_ATTR_RW(hash_max);
453 static ssize_t multicast_last_member_count_show(struct device *d,
454 struct device_attribute *attr,
455 char *buf)
457 struct net_bridge *br = to_bridge(d);
458 return sprintf(buf, "%u\n", br->multicast_last_member_count);
461 static int set_last_member_count(struct net_bridge *br, unsigned long val)
463 br->multicast_last_member_count = val;
464 return 0;
467 static ssize_t multicast_last_member_count_store(struct device *d,
468 struct device_attribute *attr,
469 const char *buf, size_t len)
471 return store_bridge_parm(d, buf, len, set_last_member_count);
473 static DEVICE_ATTR_RW(multicast_last_member_count);
475 static ssize_t multicast_startup_query_count_show(
476 struct device *d, struct device_attribute *attr, char *buf)
478 struct net_bridge *br = to_bridge(d);
479 return sprintf(buf, "%u\n", br->multicast_startup_query_count);
482 static int set_startup_query_count(struct net_bridge *br, unsigned long val)
484 br->multicast_startup_query_count = val;
485 return 0;
488 static ssize_t multicast_startup_query_count_store(
489 struct device *d, struct device_attribute *attr, const char *buf,
490 size_t len)
492 return store_bridge_parm(d, buf, len, set_startup_query_count);
494 static DEVICE_ATTR_RW(multicast_startup_query_count);
496 static ssize_t multicast_last_member_interval_show(
497 struct device *d, struct device_attribute *attr, char *buf)
499 struct net_bridge *br = to_bridge(d);
500 return sprintf(buf, "%lu\n",
501 jiffies_to_clock_t(br->multicast_last_member_interval));
504 static int set_last_member_interval(struct net_bridge *br, unsigned long val)
506 br->multicast_last_member_interval = clock_t_to_jiffies(val);
507 return 0;
510 static ssize_t multicast_last_member_interval_store(
511 struct device *d, struct device_attribute *attr, const char *buf,
512 size_t len)
514 return store_bridge_parm(d, buf, len, set_last_member_interval);
516 static DEVICE_ATTR_RW(multicast_last_member_interval);
518 static ssize_t multicast_membership_interval_show(
519 struct device *d, struct device_attribute *attr, char *buf)
521 struct net_bridge *br = to_bridge(d);
522 return sprintf(buf, "%lu\n",
523 jiffies_to_clock_t(br->multicast_membership_interval));
526 static int set_membership_interval(struct net_bridge *br, unsigned long val)
528 br->multicast_membership_interval = clock_t_to_jiffies(val);
529 return 0;
532 static ssize_t multicast_membership_interval_store(
533 struct device *d, struct device_attribute *attr, const char *buf,
534 size_t len)
536 return store_bridge_parm(d, buf, len, set_membership_interval);
538 static DEVICE_ATTR_RW(multicast_membership_interval);
540 static ssize_t multicast_querier_interval_show(struct device *d,
541 struct device_attribute *attr,
542 char *buf)
544 struct net_bridge *br = to_bridge(d);
545 return sprintf(buf, "%lu\n",
546 jiffies_to_clock_t(br->multicast_querier_interval));
549 static int set_querier_interval(struct net_bridge *br, unsigned long val)
551 br->multicast_querier_interval = clock_t_to_jiffies(val);
552 return 0;
555 static ssize_t multicast_querier_interval_store(struct device *d,
556 struct device_attribute *attr,
557 const char *buf, size_t len)
559 return store_bridge_parm(d, buf, len, set_querier_interval);
561 static DEVICE_ATTR_RW(multicast_querier_interval);
563 static ssize_t multicast_query_interval_show(struct device *d,
564 struct device_attribute *attr,
565 char *buf)
567 struct net_bridge *br = to_bridge(d);
568 return sprintf(buf, "%lu\n",
569 jiffies_to_clock_t(br->multicast_query_interval));
572 static int set_query_interval(struct net_bridge *br, unsigned long val)
574 br->multicast_query_interval = clock_t_to_jiffies(val);
575 return 0;
578 static ssize_t multicast_query_interval_store(struct device *d,
579 struct device_attribute *attr,
580 const char *buf, size_t len)
582 return store_bridge_parm(d, buf, len, set_query_interval);
584 static DEVICE_ATTR_RW(multicast_query_interval);
586 static ssize_t multicast_query_response_interval_show(
587 struct device *d, struct device_attribute *attr, char *buf)
589 struct net_bridge *br = to_bridge(d);
590 return sprintf(
591 buf, "%lu\n",
592 jiffies_to_clock_t(br->multicast_query_response_interval));
595 static int set_query_response_interval(struct net_bridge *br, unsigned long val)
597 br->multicast_query_response_interval = clock_t_to_jiffies(val);
598 return 0;
601 static ssize_t multicast_query_response_interval_store(
602 struct device *d, struct device_attribute *attr, const char *buf,
603 size_t len)
605 return store_bridge_parm(d, buf, len, set_query_response_interval);
607 static DEVICE_ATTR_RW(multicast_query_response_interval);
609 static ssize_t multicast_startup_query_interval_show(
610 struct device *d, struct device_attribute *attr, char *buf)
612 struct net_bridge *br = to_bridge(d);
613 return sprintf(
614 buf, "%lu\n",
615 jiffies_to_clock_t(br->multicast_startup_query_interval));
618 static int set_startup_query_interval(struct net_bridge *br, unsigned long val)
620 br->multicast_startup_query_interval = clock_t_to_jiffies(val);
621 return 0;
624 static ssize_t multicast_startup_query_interval_store(
625 struct device *d, struct device_attribute *attr, const char *buf,
626 size_t len)
628 return store_bridge_parm(d, buf, len, set_startup_query_interval);
630 static DEVICE_ATTR_RW(multicast_startup_query_interval);
631 #endif
632 #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
633 static ssize_t nf_call_iptables_show(
634 struct device *d, struct device_attribute *attr, char *buf)
636 struct net_bridge *br = to_bridge(d);
637 return sprintf(buf, "%u\n", br->nf_call_iptables);
640 static int set_nf_call_iptables(struct net_bridge *br, unsigned long val)
642 br->nf_call_iptables = val ? true : false;
643 return 0;
646 static ssize_t nf_call_iptables_store(
647 struct device *d, struct device_attribute *attr, const char *buf,
648 size_t len)
650 return store_bridge_parm(d, buf, len, set_nf_call_iptables);
652 static DEVICE_ATTR_RW(nf_call_iptables);
654 static ssize_t nf_call_ip6tables_show(
655 struct device *d, struct device_attribute *attr, char *buf)
657 struct net_bridge *br = to_bridge(d);
658 return sprintf(buf, "%u\n", br->nf_call_ip6tables);
661 static int set_nf_call_ip6tables(struct net_bridge *br, unsigned long val)
663 br->nf_call_ip6tables = val ? true : false;
664 return 0;
667 static ssize_t nf_call_ip6tables_store(
668 struct device *d, struct device_attribute *attr, const char *buf,
669 size_t len)
671 return store_bridge_parm(d, buf, len, set_nf_call_ip6tables);
673 static DEVICE_ATTR_RW(nf_call_ip6tables);
675 static ssize_t nf_call_arptables_show(
676 struct device *d, struct device_attribute *attr, char *buf)
678 struct net_bridge *br = to_bridge(d);
679 return sprintf(buf, "%u\n", br->nf_call_arptables);
682 static int set_nf_call_arptables(struct net_bridge *br, unsigned long val)
684 br->nf_call_arptables = val ? true : false;
685 return 0;
688 static ssize_t nf_call_arptables_store(
689 struct device *d, struct device_attribute *attr, const char *buf,
690 size_t len)
692 return store_bridge_parm(d, buf, len, set_nf_call_arptables);
694 static DEVICE_ATTR_RW(nf_call_arptables);
695 #endif
696 #ifdef CONFIG_BRIDGE_VLAN_FILTERING
697 static ssize_t vlan_filtering_show(struct device *d,
698 struct device_attribute *attr,
699 char *buf)
701 struct net_bridge *br = to_bridge(d);
702 return sprintf(buf, "%d\n", br->vlan_enabled);
705 static ssize_t vlan_filtering_store(struct device *d,
706 struct device_attribute *attr,
707 const char *buf, size_t len)
709 return store_bridge_parm(d, buf, len, br_vlan_filter_toggle);
711 static DEVICE_ATTR_RW(vlan_filtering);
713 static ssize_t vlan_protocol_show(struct device *d,
714 struct device_attribute *attr,
715 char *buf)
717 struct net_bridge *br = to_bridge(d);
718 return sprintf(buf, "%#06x\n", ntohs(br->vlan_proto));
721 static ssize_t vlan_protocol_store(struct device *d,
722 struct device_attribute *attr,
723 const char *buf, size_t len)
725 return store_bridge_parm(d, buf, len, br_vlan_set_proto);
727 static DEVICE_ATTR_RW(vlan_protocol);
729 static ssize_t default_pvid_show(struct device *d,
730 struct device_attribute *attr,
731 char *buf)
733 struct net_bridge *br = to_bridge(d);
734 return sprintf(buf, "%d\n", br->default_pvid);
737 static ssize_t default_pvid_store(struct device *d,
738 struct device_attribute *attr,
739 const char *buf, size_t len)
741 return store_bridge_parm(d, buf, len, br_vlan_set_default_pvid);
743 static DEVICE_ATTR_RW(default_pvid);
744 #endif
746 static struct attribute *bridge_attrs[] = {
747 &dev_attr_forward_delay.attr,
748 &dev_attr_hello_time.attr,
749 &dev_attr_max_age.attr,
750 &dev_attr_ageing_time.attr,
751 &dev_attr_stp_state.attr,
752 &dev_attr_group_fwd_mask.attr,
753 &dev_attr_priority.attr,
754 &dev_attr_bridge_id.attr,
755 &dev_attr_root_id.attr,
756 &dev_attr_root_path_cost.attr,
757 &dev_attr_root_port.attr,
758 &dev_attr_topology_change.attr,
759 &dev_attr_topology_change_detected.attr,
760 &dev_attr_hello_timer.attr,
761 &dev_attr_tcn_timer.attr,
762 &dev_attr_topology_change_timer.attr,
763 &dev_attr_gc_timer.attr,
764 &dev_attr_group_addr.attr,
765 &dev_attr_flush.attr,
766 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
767 &dev_attr_multicast_router.attr,
768 &dev_attr_multicast_snooping.attr,
769 &dev_attr_multicast_querier.attr,
770 &dev_attr_multicast_query_use_ifaddr.attr,
771 &dev_attr_hash_elasticity.attr,
772 &dev_attr_hash_max.attr,
773 &dev_attr_multicast_last_member_count.attr,
774 &dev_attr_multicast_startup_query_count.attr,
775 &dev_attr_multicast_last_member_interval.attr,
776 &dev_attr_multicast_membership_interval.attr,
777 &dev_attr_multicast_querier_interval.attr,
778 &dev_attr_multicast_query_interval.attr,
779 &dev_attr_multicast_query_response_interval.attr,
780 &dev_attr_multicast_startup_query_interval.attr,
781 #endif
782 #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
783 &dev_attr_nf_call_iptables.attr,
784 &dev_attr_nf_call_ip6tables.attr,
785 &dev_attr_nf_call_arptables.attr,
786 #endif
787 #ifdef CONFIG_BRIDGE_VLAN_FILTERING
788 &dev_attr_vlan_filtering.attr,
789 &dev_attr_vlan_protocol.attr,
790 &dev_attr_default_pvid.attr,
791 #endif
792 NULL
795 static struct attribute_group bridge_group = {
796 .name = SYSFS_BRIDGE_ATTR,
797 .attrs = bridge_attrs,
801 * Export the forwarding information table as a binary file
802 * The records are struct __fdb_entry.
804 * Returns the number of bytes read.
806 static ssize_t brforward_read(struct file *filp, struct kobject *kobj,
807 struct bin_attribute *bin_attr,
808 char *buf, loff_t off, size_t count)
810 struct device *dev = to_dev(kobj);
811 struct net_bridge *br = to_bridge(dev);
812 int n;
814 /* must read whole records */
815 if (off % sizeof(struct __fdb_entry) != 0)
816 return -EINVAL;
818 n = br_fdb_fillbuf(br, buf,
819 count / sizeof(struct __fdb_entry),
820 off / sizeof(struct __fdb_entry));
822 if (n > 0)
823 n *= sizeof(struct __fdb_entry);
825 return n;
828 static struct bin_attribute bridge_forward = {
829 .attr = { .name = SYSFS_BRIDGE_FDB,
830 .mode = S_IRUGO, },
831 .read = brforward_read,
835 * Add entries in sysfs onto the existing network class device
836 * for the bridge.
837 * Adds a attribute group "bridge" containing tuning parameters.
838 * Binary attribute containing the forward table
839 * Sub directory to hold links to interfaces.
841 * Note: the ifobj exists only to be a subdirectory
842 * to hold links. The ifobj exists in same data structure
843 * as it's parent the bridge so reference counting works.
845 int br_sysfs_addbr(struct net_device *dev)
847 struct kobject *brobj = &dev->dev.kobj;
848 struct net_bridge *br = netdev_priv(dev);
849 int err;
851 err = sysfs_create_group(brobj, &bridge_group);
852 if (err) {
853 pr_info("%s: can't create group %s/%s\n",
854 __func__, dev->name, bridge_group.name);
855 goto out1;
858 err = sysfs_create_bin_file(brobj, &bridge_forward);
859 if (err) {
860 pr_info("%s: can't create attribute file %s/%s\n",
861 __func__, dev->name, bridge_forward.attr.name);
862 goto out2;
865 br->ifobj = kobject_create_and_add(SYSFS_BRIDGE_PORT_SUBDIR, brobj);
866 if (!br->ifobj) {
867 pr_info("%s: can't add kobject (directory) %s/%s\n",
868 __func__, dev->name, SYSFS_BRIDGE_PORT_SUBDIR);
869 goto out3;
871 return 0;
872 out3:
873 sysfs_remove_bin_file(&dev->dev.kobj, &bridge_forward);
874 out2:
875 sysfs_remove_group(&dev->dev.kobj, &bridge_group);
876 out1:
877 return err;
881 void br_sysfs_delbr(struct net_device *dev)
883 struct kobject *kobj = &dev->dev.kobj;
884 struct net_bridge *br = netdev_priv(dev);
886 kobject_put(br->ifobj);
887 sysfs_remove_bin_file(kobj, &bridge_forward);
888 sysfs_remove_group(kobj, &bridge_group);