Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris...
[linux/fpc-iii.git] / net / bridge / br_sysfs_br.c
blob8dac65552f1901817489421c2042553a663cbaf9
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 spin_lock_bh(&br->lock);
316 for (i = 0; i < 6; i++)
317 br->group_addr[i] = new_addr[i];
318 spin_unlock_bh(&br->lock);
319 return len;
322 static DEVICE_ATTR_RW(group_addr);
324 static ssize_t flush_store(struct device *d,
325 struct device_attribute *attr,
326 const char *buf, size_t len)
328 struct net_bridge *br = to_bridge(d);
330 if (!ns_capable(dev_net(br->dev)->user_ns, CAP_NET_ADMIN))
331 return -EPERM;
333 br_fdb_flush(br);
334 return len;
336 static DEVICE_ATTR_WO(flush);
338 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
339 static ssize_t multicast_router_show(struct device *d,
340 struct device_attribute *attr, char *buf)
342 struct net_bridge *br = to_bridge(d);
343 return sprintf(buf, "%d\n", br->multicast_router);
346 static ssize_t multicast_router_store(struct device *d,
347 struct device_attribute *attr,
348 const char *buf, size_t len)
350 return store_bridge_parm(d, buf, len, br_multicast_set_router);
352 static DEVICE_ATTR_RW(multicast_router);
354 static ssize_t multicast_snooping_show(struct device *d,
355 struct device_attribute *attr,
356 char *buf)
358 struct net_bridge *br = to_bridge(d);
359 return sprintf(buf, "%d\n", !br->multicast_disabled);
362 static ssize_t multicast_snooping_store(struct device *d,
363 struct device_attribute *attr,
364 const char *buf, size_t len)
366 return store_bridge_parm(d, buf, len, br_multicast_toggle);
368 static DEVICE_ATTR_RW(multicast_snooping);
370 static ssize_t multicast_query_use_ifaddr_show(struct device *d,
371 struct device_attribute *attr,
372 char *buf)
374 struct net_bridge *br = to_bridge(d);
375 return sprintf(buf, "%d\n", br->multicast_query_use_ifaddr);
378 static int set_query_use_ifaddr(struct net_bridge *br, unsigned long val)
380 br->multicast_query_use_ifaddr = !!val;
381 return 0;
384 static ssize_t
385 multicast_query_use_ifaddr_store(struct device *d,
386 struct device_attribute *attr,
387 const char *buf, size_t len)
389 return store_bridge_parm(d, buf, len, set_query_use_ifaddr);
391 static DEVICE_ATTR_RW(multicast_query_use_ifaddr);
393 static ssize_t multicast_querier_show(struct device *d,
394 struct device_attribute *attr,
395 char *buf)
397 struct net_bridge *br = to_bridge(d);
398 return sprintf(buf, "%d\n", br->multicast_querier);
401 static ssize_t multicast_querier_store(struct device *d,
402 struct device_attribute *attr,
403 const char *buf, size_t len)
405 return store_bridge_parm(d, buf, len, br_multicast_set_querier);
407 static DEVICE_ATTR_RW(multicast_querier);
409 static ssize_t hash_elasticity_show(struct device *d,
410 struct device_attribute *attr, char *buf)
412 struct net_bridge *br = to_bridge(d);
413 return sprintf(buf, "%u\n", br->hash_elasticity);
416 static int set_elasticity(struct net_bridge *br, unsigned long val)
418 br->hash_elasticity = val;
419 return 0;
422 static ssize_t hash_elasticity_store(struct device *d,
423 struct device_attribute *attr,
424 const char *buf, size_t len)
426 return store_bridge_parm(d, buf, len, set_elasticity);
428 static DEVICE_ATTR_RW(hash_elasticity);
430 static ssize_t hash_max_show(struct device *d, struct device_attribute *attr,
431 char *buf)
433 struct net_bridge *br = to_bridge(d);
434 return sprintf(buf, "%u\n", br->hash_max);
437 static ssize_t hash_max_store(struct device *d, struct device_attribute *attr,
438 const char *buf, size_t len)
440 return store_bridge_parm(d, buf, len, br_multicast_set_hash_max);
442 static DEVICE_ATTR_RW(hash_max);
444 static ssize_t multicast_last_member_count_show(struct device *d,
445 struct device_attribute *attr,
446 char *buf)
448 struct net_bridge *br = to_bridge(d);
449 return sprintf(buf, "%u\n", br->multicast_last_member_count);
452 static int set_last_member_count(struct net_bridge *br, unsigned long val)
454 br->multicast_last_member_count = val;
455 return 0;
458 static ssize_t multicast_last_member_count_store(struct device *d,
459 struct device_attribute *attr,
460 const char *buf, size_t len)
462 return store_bridge_parm(d, buf, len, set_last_member_count);
464 static DEVICE_ATTR_RW(multicast_last_member_count);
466 static ssize_t multicast_startup_query_count_show(
467 struct device *d, struct device_attribute *attr, char *buf)
469 struct net_bridge *br = to_bridge(d);
470 return sprintf(buf, "%u\n", br->multicast_startup_query_count);
473 static int set_startup_query_count(struct net_bridge *br, unsigned long val)
475 br->multicast_startup_query_count = val;
476 return 0;
479 static ssize_t multicast_startup_query_count_store(
480 struct device *d, struct device_attribute *attr, const char *buf,
481 size_t len)
483 return store_bridge_parm(d, buf, len, set_startup_query_count);
485 static DEVICE_ATTR_RW(multicast_startup_query_count);
487 static ssize_t multicast_last_member_interval_show(
488 struct device *d, struct device_attribute *attr, char *buf)
490 struct net_bridge *br = to_bridge(d);
491 return sprintf(buf, "%lu\n",
492 jiffies_to_clock_t(br->multicast_last_member_interval));
495 static int set_last_member_interval(struct net_bridge *br, unsigned long val)
497 br->multicast_last_member_interval = clock_t_to_jiffies(val);
498 return 0;
501 static ssize_t multicast_last_member_interval_store(
502 struct device *d, struct device_attribute *attr, const char *buf,
503 size_t len)
505 return store_bridge_parm(d, buf, len, set_last_member_interval);
507 static DEVICE_ATTR_RW(multicast_last_member_interval);
509 static ssize_t multicast_membership_interval_show(
510 struct device *d, struct device_attribute *attr, char *buf)
512 struct net_bridge *br = to_bridge(d);
513 return sprintf(buf, "%lu\n",
514 jiffies_to_clock_t(br->multicast_membership_interval));
517 static int set_membership_interval(struct net_bridge *br, unsigned long val)
519 br->multicast_membership_interval = clock_t_to_jiffies(val);
520 return 0;
523 static ssize_t multicast_membership_interval_store(
524 struct device *d, struct device_attribute *attr, const char *buf,
525 size_t len)
527 return store_bridge_parm(d, buf, len, set_membership_interval);
529 static DEVICE_ATTR_RW(multicast_membership_interval);
531 static ssize_t multicast_querier_interval_show(struct device *d,
532 struct device_attribute *attr,
533 char *buf)
535 struct net_bridge *br = to_bridge(d);
536 return sprintf(buf, "%lu\n",
537 jiffies_to_clock_t(br->multicast_querier_interval));
540 static int set_querier_interval(struct net_bridge *br, unsigned long val)
542 br->multicast_querier_interval = clock_t_to_jiffies(val);
543 return 0;
546 static ssize_t multicast_querier_interval_store(struct device *d,
547 struct device_attribute *attr,
548 const char *buf, size_t len)
550 return store_bridge_parm(d, buf, len, set_querier_interval);
552 static DEVICE_ATTR_RW(multicast_querier_interval);
554 static ssize_t multicast_query_interval_show(struct device *d,
555 struct device_attribute *attr,
556 char *buf)
558 struct net_bridge *br = to_bridge(d);
559 return sprintf(buf, "%lu\n",
560 jiffies_to_clock_t(br->multicast_query_interval));
563 static int set_query_interval(struct net_bridge *br, unsigned long val)
565 br->multicast_query_interval = clock_t_to_jiffies(val);
566 return 0;
569 static ssize_t multicast_query_interval_store(struct device *d,
570 struct device_attribute *attr,
571 const char *buf, size_t len)
573 return store_bridge_parm(d, buf, len, set_query_interval);
575 static DEVICE_ATTR_RW(multicast_query_interval);
577 static ssize_t multicast_query_response_interval_show(
578 struct device *d, struct device_attribute *attr, char *buf)
580 struct net_bridge *br = to_bridge(d);
581 return sprintf(
582 buf, "%lu\n",
583 jiffies_to_clock_t(br->multicast_query_response_interval));
586 static int set_query_response_interval(struct net_bridge *br, unsigned long val)
588 br->multicast_query_response_interval = clock_t_to_jiffies(val);
589 return 0;
592 static ssize_t multicast_query_response_interval_store(
593 struct device *d, struct device_attribute *attr, const char *buf,
594 size_t len)
596 return store_bridge_parm(d, buf, len, set_query_response_interval);
598 static DEVICE_ATTR_RW(multicast_query_response_interval);
600 static ssize_t multicast_startup_query_interval_show(
601 struct device *d, struct device_attribute *attr, char *buf)
603 struct net_bridge *br = to_bridge(d);
604 return sprintf(
605 buf, "%lu\n",
606 jiffies_to_clock_t(br->multicast_startup_query_interval));
609 static int set_startup_query_interval(struct net_bridge *br, unsigned long val)
611 br->multicast_startup_query_interval = clock_t_to_jiffies(val);
612 return 0;
615 static ssize_t multicast_startup_query_interval_store(
616 struct device *d, struct device_attribute *attr, const char *buf,
617 size_t len)
619 return store_bridge_parm(d, buf, len, set_startup_query_interval);
621 static DEVICE_ATTR_RW(multicast_startup_query_interval);
622 #endif
623 #ifdef CONFIG_BRIDGE_NETFILTER
624 static ssize_t nf_call_iptables_show(
625 struct device *d, struct device_attribute *attr, char *buf)
627 struct net_bridge *br = to_bridge(d);
628 return sprintf(buf, "%u\n", br->nf_call_iptables);
631 static int set_nf_call_iptables(struct net_bridge *br, unsigned long val)
633 br->nf_call_iptables = val ? true : false;
634 return 0;
637 static ssize_t nf_call_iptables_store(
638 struct device *d, struct device_attribute *attr, const char *buf,
639 size_t len)
641 return store_bridge_parm(d, buf, len, set_nf_call_iptables);
643 static DEVICE_ATTR_RW(nf_call_iptables);
645 static ssize_t nf_call_ip6tables_show(
646 struct device *d, struct device_attribute *attr, char *buf)
648 struct net_bridge *br = to_bridge(d);
649 return sprintf(buf, "%u\n", br->nf_call_ip6tables);
652 static int set_nf_call_ip6tables(struct net_bridge *br, unsigned long val)
654 br->nf_call_ip6tables = val ? true : false;
655 return 0;
658 static ssize_t nf_call_ip6tables_store(
659 struct device *d, struct device_attribute *attr, const char *buf,
660 size_t len)
662 return store_bridge_parm(d, buf, len, set_nf_call_ip6tables);
664 static DEVICE_ATTR_RW(nf_call_ip6tables);
666 static ssize_t nf_call_arptables_show(
667 struct device *d, struct device_attribute *attr, char *buf)
669 struct net_bridge *br = to_bridge(d);
670 return sprintf(buf, "%u\n", br->nf_call_arptables);
673 static int set_nf_call_arptables(struct net_bridge *br, unsigned long val)
675 br->nf_call_arptables = val ? true : false;
676 return 0;
679 static ssize_t nf_call_arptables_store(
680 struct device *d, struct device_attribute *attr, const char *buf,
681 size_t len)
683 return store_bridge_parm(d, buf, len, set_nf_call_arptables);
685 static DEVICE_ATTR_RW(nf_call_arptables);
686 #endif
687 #ifdef CONFIG_BRIDGE_VLAN_FILTERING
688 static ssize_t vlan_filtering_show(struct device *d,
689 struct device_attribute *attr,
690 char *buf)
692 struct net_bridge *br = to_bridge(d);
693 return sprintf(buf, "%d\n", br->vlan_enabled);
696 static ssize_t vlan_filtering_store(struct device *d,
697 struct device_attribute *attr,
698 const char *buf, size_t len)
700 return store_bridge_parm(d, buf, len, br_vlan_filter_toggle);
702 static DEVICE_ATTR_RW(vlan_filtering);
703 #endif
705 static struct attribute *bridge_attrs[] = {
706 &dev_attr_forward_delay.attr,
707 &dev_attr_hello_time.attr,
708 &dev_attr_max_age.attr,
709 &dev_attr_ageing_time.attr,
710 &dev_attr_stp_state.attr,
711 &dev_attr_group_fwd_mask.attr,
712 &dev_attr_priority.attr,
713 &dev_attr_bridge_id.attr,
714 &dev_attr_root_id.attr,
715 &dev_attr_root_path_cost.attr,
716 &dev_attr_root_port.attr,
717 &dev_attr_topology_change.attr,
718 &dev_attr_topology_change_detected.attr,
719 &dev_attr_hello_timer.attr,
720 &dev_attr_tcn_timer.attr,
721 &dev_attr_topology_change_timer.attr,
722 &dev_attr_gc_timer.attr,
723 &dev_attr_group_addr.attr,
724 &dev_attr_flush.attr,
725 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
726 &dev_attr_multicast_router.attr,
727 &dev_attr_multicast_snooping.attr,
728 &dev_attr_multicast_querier.attr,
729 &dev_attr_multicast_query_use_ifaddr.attr,
730 &dev_attr_hash_elasticity.attr,
731 &dev_attr_hash_max.attr,
732 &dev_attr_multicast_last_member_count.attr,
733 &dev_attr_multicast_startup_query_count.attr,
734 &dev_attr_multicast_last_member_interval.attr,
735 &dev_attr_multicast_membership_interval.attr,
736 &dev_attr_multicast_querier_interval.attr,
737 &dev_attr_multicast_query_interval.attr,
738 &dev_attr_multicast_query_response_interval.attr,
739 &dev_attr_multicast_startup_query_interval.attr,
740 #endif
741 #ifdef CONFIG_BRIDGE_NETFILTER
742 &dev_attr_nf_call_iptables.attr,
743 &dev_attr_nf_call_ip6tables.attr,
744 &dev_attr_nf_call_arptables.attr,
745 #endif
746 #ifdef CONFIG_BRIDGE_VLAN_FILTERING
747 &dev_attr_vlan_filtering.attr,
748 #endif
749 NULL
752 static struct attribute_group bridge_group = {
753 .name = SYSFS_BRIDGE_ATTR,
754 .attrs = bridge_attrs,
758 * Export the forwarding information table as a binary file
759 * The records are struct __fdb_entry.
761 * Returns the number of bytes read.
763 static ssize_t brforward_read(struct file *filp, struct kobject *kobj,
764 struct bin_attribute *bin_attr,
765 char *buf, loff_t off, size_t count)
767 struct device *dev = to_dev(kobj);
768 struct net_bridge *br = to_bridge(dev);
769 int n;
771 /* must read whole records */
772 if (off % sizeof(struct __fdb_entry) != 0)
773 return -EINVAL;
775 n = br_fdb_fillbuf(br, buf,
776 count / sizeof(struct __fdb_entry),
777 off / sizeof(struct __fdb_entry));
779 if (n > 0)
780 n *= sizeof(struct __fdb_entry);
782 return n;
785 static struct bin_attribute bridge_forward = {
786 .attr = { .name = SYSFS_BRIDGE_FDB,
787 .mode = S_IRUGO, },
788 .read = brforward_read,
792 * Add entries in sysfs onto the existing network class device
793 * for the bridge.
794 * Adds a attribute group "bridge" containing tuning parameters.
795 * Binary attribute containing the forward table
796 * Sub directory to hold links to interfaces.
798 * Note: the ifobj exists only to be a subdirectory
799 * to hold links. The ifobj exists in same data structure
800 * as it's parent the bridge so reference counting works.
802 int br_sysfs_addbr(struct net_device *dev)
804 struct kobject *brobj = &dev->dev.kobj;
805 struct net_bridge *br = netdev_priv(dev);
806 int err;
808 err = sysfs_create_group(brobj, &bridge_group);
809 if (err) {
810 pr_info("%s: can't create group %s/%s\n",
811 __func__, dev->name, bridge_group.name);
812 goto out1;
815 err = sysfs_create_bin_file(brobj, &bridge_forward);
816 if (err) {
817 pr_info("%s: can't create attribute file %s/%s\n",
818 __func__, dev->name, bridge_forward.attr.name);
819 goto out2;
822 br->ifobj = kobject_create_and_add(SYSFS_BRIDGE_PORT_SUBDIR, brobj);
823 if (!br->ifobj) {
824 pr_info("%s: can't add kobject (directory) %s/%s\n",
825 __func__, dev->name, SYSFS_BRIDGE_PORT_SUBDIR);
826 goto out3;
828 return 0;
829 out3:
830 sysfs_remove_bin_file(&dev->dev.kobj, &bridge_forward);
831 out2:
832 sysfs_remove_group(&dev->dev.kobj, &bridge_group);
833 out1:
834 return err;
838 void br_sysfs_delbr(struct net_device *dev)
840 struct kobject *kobj = &dev->dev.kobj;
841 struct net_bridge *br = netdev_priv(dev);
843 kobject_put(br->ifobj);
844 sysfs_remove_bin_file(kobj, &bridge_forward);
845 sysfs_remove_group(kobj, &bridge_group);