xref: /openbmc/linux/net/bridge/br_sysfs_br.c (revision 43cb76d91ee85f579a69d42bc8efc08bac560278)
11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds  *	Sysfs attributes of bridge ports
31da177e4SLinus Torvalds  *	Linux ethernet bridge
41da177e4SLinus Torvalds  *
51da177e4SLinus Torvalds  *	Authors:
61da177e4SLinus Torvalds  *	Stephen Hemminger		<shemminger@osdl.org>
71da177e4SLinus Torvalds  *
81da177e4SLinus Torvalds  *	This program is free software; you can redistribute it and/or
91da177e4SLinus Torvalds  *	modify it under the terms of the GNU General Public License
101da177e4SLinus Torvalds  *	as published by the Free Software Foundation; either version
111da177e4SLinus Torvalds  *	2 of the License, or (at your option) any later version.
121da177e4SLinus Torvalds  */
131da177e4SLinus Torvalds 
144fc268d2SRandy Dunlap #include <linux/capability.h>
151da177e4SLinus Torvalds #include <linux/kernel.h>
161da177e4SLinus Torvalds #include <linux/netdevice.h>
171da177e4SLinus Torvalds #include <linux/if_bridge.h>
181da177e4SLinus Torvalds #include <linux/rtnetlink.h>
191da177e4SLinus Torvalds #include <linux/spinlock.h>
201da177e4SLinus Torvalds #include <linux/times.h>
211da177e4SLinus Torvalds 
221da177e4SLinus Torvalds #include "br_private.h"
231da177e4SLinus Torvalds 
24*43cb76d9SGreg Kroah-Hartman #define to_dev(obj)	container_of(obj, struct device, kobj)
251da177e4SLinus Torvalds #define to_bridge(cd)	((struct net_bridge *)(to_net_dev(cd)->priv))
261da177e4SLinus Torvalds 
271da177e4SLinus Torvalds /*
281da177e4SLinus Torvalds  * Common code for storing bridge parameters.
291da177e4SLinus Torvalds  */
30*43cb76d9SGreg Kroah-Hartman static ssize_t store_bridge_parm(struct device *d,
311da177e4SLinus Torvalds 				 const char *buf, size_t len,
321da177e4SLinus Torvalds 				 void (*set)(struct net_bridge *, unsigned long))
331da177e4SLinus Torvalds {
34*43cb76d9SGreg Kroah-Hartman 	struct net_bridge *br = to_bridge(d);
351da177e4SLinus Torvalds 	char *endp;
361da177e4SLinus Torvalds 	unsigned long val;
371da177e4SLinus Torvalds 
381da177e4SLinus Torvalds 	if (!capable(CAP_NET_ADMIN))
391da177e4SLinus Torvalds 		return -EPERM;
401da177e4SLinus Torvalds 
411da177e4SLinus Torvalds 	val = simple_strtoul(buf, &endp, 0);
421da177e4SLinus Torvalds 	if (endp == buf)
431da177e4SLinus Torvalds 		return -EINVAL;
441da177e4SLinus Torvalds 
451da177e4SLinus Torvalds 	spin_lock_bh(&br->lock);
461da177e4SLinus Torvalds 	(*set)(br, val);
471da177e4SLinus Torvalds 	spin_unlock_bh(&br->lock);
481da177e4SLinus Torvalds 	return len;
491da177e4SLinus Torvalds }
501da177e4SLinus Torvalds 
511da177e4SLinus Torvalds 
52*43cb76d9SGreg Kroah-Hartman static ssize_t show_forward_delay(struct device *d,
53*43cb76d9SGreg Kroah-Hartman 				  struct device_attribute *attr, char *buf)
541da177e4SLinus Torvalds {
55*43cb76d9SGreg Kroah-Hartman 	struct net_bridge *br = to_bridge(d);
561da177e4SLinus Torvalds 	return sprintf(buf, "%lu\n", jiffies_to_clock_t(br->forward_delay));
571da177e4SLinus Torvalds }
581da177e4SLinus Torvalds 
591da177e4SLinus Torvalds static void set_forward_delay(struct net_bridge *br, unsigned long val)
601da177e4SLinus Torvalds {
611da177e4SLinus Torvalds 	unsigned long delay = clock_t_to_jiffies(val);
621da177e4SLinus Torvalds 	br->forward_delay = delay;
631da177e4SLinus Torvalds 	if (br_is_root_bridge(br))
641da177e4SLinus Torvalds 		br->bridge_forward_delay = delay;
651da177e4SLinus Torvalds }
661da177e4SLinus Torvalds 
67*43cb76d9SGreg Kroah-Hartman static ssize_t store_forward_delay(struct device *d,
68*43cb76d9SGreg Kroah-Hartman 				   struct device_attribute *attr,
69*43cb76d9SGreg Kroah-Hartman 				   const char *buf, size_t len)
701da177e4SLinus Torvalds {
71*43cb76d9SGreg Kroah-Hartman 	return store_bridge_parm(d, buf, len, set_forward_delay);
721da177e4SLinus Torvalds }
73*43cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(forward_delay, S_IRUGO | S_IWUSR,
741da177e4SLinus Torvalds 		   show_forward_delay, store_forward_delay);
751da177e4SLinus Torvalds 
76*43cb76d9SGreg Kroah-Hartman static ssize_t show_hello_time(struct device *d, struct device_attribute *attr,
77*43cb76d9SGreg Kroah-Hartman 			       char *buf)
781da177e4SLinus Torvalds {
791da177e4SLinus Torvalds 	return sprintf(buf, "%lu\n",
80*43cb76d9SGreg Kroah-Hartman 		       jiffies_to_clock_t(to_bridge(d)->hello_time));
811da177e4SLinus Torvalds }
821da177e4SLinus Torvalds 
831da177e4SLinus Torvalds static void set_hello_time(struct net_bridge *br, unsigned long val)
841da177e4SLinus Torvalds {
851da177e4SLinus Torvalds 	unsigned long t = clock_t_to_jiffies(val);
861da177e4SLinus Torvalds 	br->hello_time = t;
871da177e4SLinus Torvalds 	if (br_is_root_bridge(br))
881da177e4SLinus Torvalds 		br->bridge_hello_time = t;
891da177e4SLinus Torvalds }
901da177e4SLinus Torvalds 
91*43cb76d9SGreg Kroah-Hartman static ssize_t store_hello_time(struct device *d,
92*43cb76d9SGreg Kroah-Hartman 				struct device_attribute *attr, const char *buf,
931da177e4SLinus Torvalds 				size_t len)
941da177e4SLinus Torvalds {
95*43cb76d9SGreg Kroah-Hartman 	return store_bridge_parm(d, buf, len, set_hello_time);
961da177e4SLinus Torvalds }
97*43cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(hello_time, S_IRUGO | S_IWUSR, show_hello_time,
981da177e4SLinus Torvalds 		   store_hello_time);
991da177e4SLinus Torvalds 
100*43cb76d9SGreg Kroah-Hartman static ssize_t show_max_age(struct device *d, struct device_attribute *attr,
101*43cb76d9SGreg Kroah-Hartman 			    char *buf)
1021da177e4SLinus Torvalds {
1031da177e4SLinus Torvalds 	return sprintf(buf, "%lu\n",
104*43cb76d9SGreg Kroah-Hartman 		       jiffies_to_clock_t(to_bridge(d)->max_age));
1051da177e4SLinus Torvalds }
1061da177e4SLinus Torvalds 
1071da177e4SLinus Torvalds static void set_max_age(struct net_bridge *br, unsigned long val)
1081da177e4SLinus Torvalds {
1091da177e4SLinus Torvalds 	unsigned long t = clock_t_to_jiffies(val);
1101da177e4SLinus Torvalds 	br->max_age = t;
1111da177e4SLinus Torvalds 	if (br_is_root_bridge(br))
1121da177e4SLinus Torvalds 		br->bridge_max_age = t;
1131da177e4SLinus Torvalds }
1141da177e4SLinus Torvalds 
115*43cb76d9SGreg Kroah-Hartman static ssize_t store_max_age(struct device *d, struct device_attribute *attr,
116*43cb76d9SGreg Kroah-Hartman 			     const char *buf, size_t len)
1171da177e4SLinus Torvalds {
118*43cb76d9SGreg Kroah-Hartman 	return store_bridge_parm(d, buf, len, set_max_age);
1191da177e4SLinus Torvalds }
120*43cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(max_age, S_IRUGO | S_IWUSR, show_max_age, store_max_age);
1211da177e4SLinus Torvalds 
122*43cb76d9SGreg Kroah-Hartman static ssize_t show_ageing_time(struct device *d,
123*43cb76d9SGreg Kroah-Hartman 				struct device_attribute *attr, char *buf)
1241da177e4SLinus Torvalds {
125*43cb76d9SGreg Kroah-Hartman 	struct net_bridge *br = to_bridge(d);
1261da177e4SLinus Torvalds 	return sprintf(buf, "%lu\n", jiffies_to_clock_t(br->ageing_time));
1271da177e4SLinus Torvalds }
1281da177e4SLinus Torvalds 
1291da177e4SLinus Torvalds static void set_ageing_time(struct net_bridge *br, unsigned long val)
1301da177e4SLinus Torvalds {
1311da177e4SLinus Torvalds 	br->ageing_time = clock_t_to_jiffies(val);
1321da177e4SLinus Torvalds }
1331da177e4SLinus Torvalds 
134*43cb76d9SGreg Kroah-Hartman static ssize_t store_ageing_time(struct device *d,
135*43cb76d9SGreg Kroah-Hartman 				 struct device_attribute *attr,
136*43cb76d9SGreg Kroah-Hartman 				 const char *buf, size_t len)
1371da177e4SLinus Torvalds {
138*43cb76d9SGreg Kroah-Hartman 	return store_bridge_parm(d, buf, len, set_ageing_time);
1391da177e4SLinus Torvalds }
140*43cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(ageing_time, S_IRUGO | S_IWUSR, show_ageing_time,
1411da177e4SLinus Torvalds 		   store_ageing_time);
142*43cb76d9SGreg Kroah-Hartman 
143*43cb76d9SGreg Kroah-Hartman static ssize_t show_stp_state(struct device *d,
144*43cb76d9SGreg Kroah-Hartman 			      struct device_attribute *attr, char *buf)
1451da177e4SLinus Torvalds {
146*43cb76d9SGreg Kroah-Hartman 	struct net_bridge *br = to_bridge(d);
1471da177e4SLinus Torvalds 	return sprintf(buf, "%d\n", br->stp_enabled);
1481da177e4SLinus Torvalds }
1491da177e4SLinus Torvalds 
1501da177e4SLinus Torvalds static void set_stp_state(struct net_bridge *br, unsigned long val)
1511da177e4SLinus Torvalds {
1521da177e4SLinus Torvalds 	br->stp_enabled = val;
1531da177e4SLinus Torvalds }
1541da177e4SLinus Torvalds 
155*43cb76d9SGreg Kroah-Hartman static ssize_t store_stp_state(struct device *d,
156*43cb76d9SGreg Kroah-Hartman 			       struct device_attribute *attr, const char *buf,
157*43cb76d9SGreg Kroah-Hartman 			       size_t len)
1581da177e4SLinus Torvalds {
159*43cb76d9SGreg Kroah-Hartman 	return store_bridge_parm(d, buf, len, set_stp_state);
1601da177e4SLinus Torvalds }
161*43cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(stp_state, S_IRUGO | S_IWUSR, show_stp_state,
1621da177e4SLinus Torvalds 		   store_stp_state);
1631da177e4SLinus Torvalds 
164*43cb76d9SGreg Kroah-Hartman static ssize_t show_priority(struct device *d, struct device_attribute *attr,
165*43cb76d9SGreg Kroah-Hartman 			     char *buf)
1661da177e4SLinus Torvalds {
167*43cb76d9SGreg Kroah-Hartman 	struct net_bridge *br = to_bridge(d);
1681da177e4SLinus Torvalds 	return sprintf(buf, "%d\n",
1691da177e4SLinus Torvalds 		       (br->bridge_id.prio[0] << 8) | br->bridge_id.prio[1]);
1701da177e4SLinus Torvalds }
1711da177e4SLinus Torvalds 
1721da177e4SLinus Torvalds static void set_priority(struct net_bridge *br, unsigned long val)
1731da177e4SLinus Torvalds {
1741da177e4SLinus Torvalds 	br_stp_set_bridge_priority(br, (u16) val);
1751da177e4SLinus Torvalds }
1761da177e4SLinus Torvalds 
177*43cb76d9SGreg Kroah-Hartman static ssize_t store_priority(struct device *d, struct device_attribute *attr,
1781da177e4SLinus Torvalds 			       const char *buf, size_t len)
1791da177e4SLinus Torvalds {
180*43cb76d9SGreg Kroah-Hartman 	return store_bridge_parm(d, buf, len, set_priority);
1811da177e4SLinus Torvalds }
182*43cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(priority, S_IRUGO | S_IWUSR, show_priority, store_priority);
1831da177e4SLinus Torvalds 
184*43cb76d9SGreg Kroah-Hartman static ssize_t show_root_id(struct device *d, struct device_attribute *attr,
185*43cb76d9SGreg Kroah-Hartman 			    char *buf)
1861da177e4SLinus Torvalds {
187*43cb76d9SGreg Kroah-Hartman 	return br_show_bridge_id(buf, &to_bridge(d)->designated_root);
1881da177e4SLinus Torvalds }
189*43cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(root_id, S_IRUGO, show_root_id, NULL);
1901da177e4SLinus Torvalds 
191*43cb76d9SGreg Kroah-Hartman static ssize_t show_bridge_id(struct device *d, struct device_attribute *attr,
192*43cb76d9SGreg Kroah-Hartman 			      char *buf)
1931da177e4SLinus Torvalds {
194*43cb76d9SGreg Kroah-Hartman 	return br_show_bridge_id(buf, &to_bridge(d)->bridge_id);
1951da177e4SLinus Torvalds }
196*43cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(bridge_id, S_IRUGO, show_bridge_id, NULL);
1971da177e4SLinus Torvalds 
198*43cb76d9SGreg Kroah-Hartman static ssize_t show_root_port(struct device *d, struct device_attribute *attr,
199*43cb76d9SGreg Kroah-Hartman 			      char *buf)
2001da177e4SLinus Torvalds {
201*43cb76d9SGreg Kroah-Hartman 	return sprintf(buf, "%d\n", to_bridge(d)->root_port);
2021da177e4SLinus Torvalds }
203*43cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(root_port, S_IRUGO, show_root_port, NULL);
2041da177e4SLinus Torvalds 
205*43cb76d9SGreg Kroah-Hartman static ssize_t show_root_path_cost(struct device *d,
206*43cb76d9SGreg Kroah-Hartman 				   struct device_attribute *attr, char *buf)
2071da177e4SLinus Torvalds {
208*43cb76d9SGreg Kroah-Hartman 	return sprintf(buf, "%d\n", to_bridge(d)->root_path_cost);
2091da177e4SLinus Torvalds }
210*43cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(root_path_cost, S_IRUGO, show_root_path_cost, NULL);
2111da177e4SLinus Torvalds 
212*43cb76d9SGreg Kroah-Hartman static ssize_t show_topology_change(struct device *d,
213*43cb76d9SGreg Kroah-Hartman 				    struct device_attribute *attr, char *buf)
2141da177e4SLinus Torvalds {
215*43cb76d9SGreg Kroah-Hartman 	return sprintf(buf, "%d\n", to_bridge(d)->topology_change);
2161da177e4SLinus Torvalds }
217*43cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(topology_change, S_IRUGO, show_topology_change, NULL);
2181da177e4SLinus Torvalds 
219*43cb76d9SGreg Kroah-Hartman static ssize_t show_topology_change_detected(struct device *d,
220*43cb76d9SGreg Kroah-Hartman 					     struct device_attribute *attr,
221*43cb76d9SGreg Kroah-Hartman 					     char *buf)
2221da177e4SLinus Torvalds {
223*43cb76d9SGreg Kroah-Hartman 	struct net_bridge *br = to_bridge(d);
2241da177e4SLinus Torvalds 	return sprintf(buf, "%d\n", br->topology_change_detected);
2251da177e4SLinus Torvalds }
226*43cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(topology_change_detected, S_IRUGO,
227*43cb76d9SGreg Kroah-Hartman 		   show_topology_change_detected, NULL);
2281da177e4SLinus Torvalds 
229*43cb76d9SGreg Kroah-Hartman static ssize_t show_hello_timer(struct device *d,
230*43cb76d9SGreg Kroah-Hartman 				struct device_attribute *attr, char *buf)
2311da177e4SLinus Torvalds {
232*43cb76d9SGreg Kroah-Hartman 	struct net_bridge *br = to_bridge(d);
2331da177e4SLinus Torvalds 	return sprintf(buf, "%ld\n", br_timer_value(&br->hello_timer));
2341da177e4SLinus Torvalds }
235*43cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(hello_timer, S_IRUGO, show_hello_timer, NULL);
2361da177e4SLinus Torvalds 
237*43cb76d9SGreg Kroah-Hartman static ssize_t show_tcn_timer(struct device *d, struct device_attribute *attr,
238*43cb76d9SGreg Kroah-Hartman 			      char *buf)
2391da177e4SLinus Torvalds {
240*43cb76d9SGreg Kroah-Hartman 	struct net_bridge *br = to_bridge(d);
2411da177e4SLinus Torvalds 	return sprintf(buf, "%ld\n", br_timer_value(&br->tcn_timer));
2421da177e4SLinus Torvalds }
243*43cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(tcn_timer, S_IRUGO, show_tcn_timer, NULL);
2441da177e4SLinus Torvalds 
245*43cb76d9SGreg Kroah-Hartman static ssize_t show_topology_change_timer(struct device *d,
246*43cb76d9SGreg Kroah-Hartman 					  struct device_attribute *attr,
247*43cb76d9SGreg Kroah-Hartman 					  char *buf)
2481da177e4SLinus Torvalds {
249*43cb76d9SGreg Kroah-Hartman 	struct net_bridge *br = to_bridge(d);
2501da177e4SLinus Torvalds 	return sprintf(buf, "%ld\n", br_timer_value(&br->topology_change_timer));
2511da177e4SLinus Torvalds }
252*43cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(topology_change_timer, S_IRUGO, show_topology_change_timer,
253*43cb76d9SGreg Kroah-Hartman 		   NULL);
2541da177e4SLinus Torvalds 
255*43cb76d9SGreg Kroah-Hartman static ssize_t show_gc_timer(struct device *d, struct device_attribute *attr,
256*43cb76d9SGreg Kroah-Hartman 			     char *buf)
2571da177e4SLinus Torvalds {
258*43cb76d9SGreg Kroah-Hartman 	struct net_bridge *br = to_bridge(d);
2591da177e4SLinus Torvalds 	return sprintf(buf, "%ld\n", br_timer_value(&br->gc_timer));
2601da177e4SLinus Torvalds }
261*43cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(gc_timer, S_IRUGO, show_gc_timer, NULL);
2621da177e4SLinus Torvalds 
263*43cb76d9SGreg Kroah-Hartman static ssize_t show_group_addr(struct device *d,
264*43cb76d9SGreg Kroah-Hartman 			       struct device_attribute *attr, char *buf)
265fda93d92SStephen Hemminger {
266*43cb76d9SGreg Kroah-Hartman 	struct net_bridge *br = to_bridge(d);
267fda93d92SStephen Hemminger 	return sprintf(buf, "%x:%x:%x:%x:%x:%x\n",
268fda93d92SStephen Hemminger 		       br->group_addr[0], br->group_addr[1],
269fda93d92SStephen Hemminger 		       br->group_addr[2], br->group_addr[3],
270fda93d92SStephen Hemminger 		       br->group_addr[4], br->group_addr[5]);
271fda93d92SStephen Hemminger }
272fda93d92SStephen Hemminger 
273*43cb76d9SGreg Kroah-Hartman static ssize_t store_group_addr(struct device *d,
274*43cb76d9SGreg Kroah-Hartman 				struct device_attribute *attr,
275*43cb76d9SGreg Kroah-Hartman 				const char *buf, size_t len)
276fda93d92SStephen Hemminger {
277*43cb76d9SGreg Kroah-Hartman 	struct net_bridge *br = to_bridge(d);
278fda93d92SStephen Hemminger 	unsigned new_addr[6];
279fda93d92SStephen Hemminger 	int i;
280fda93d92SStephen Hemminger 
281fda93d92SStephen Hemminger 	if (!capable(CAP_NET_ADMIN))
282fda93d92SStephen Hemminger 		return -EPERM;
283fda93d92SStephen Hemminger 
284fda93d92SStephen Hemminger 	if (sscanf(buf, "%x:%x:%x:%x:%x:%x",
285fda93d92SStephen Hemminger 		   &new_addr[0], &new_addr[1], &new_addr[2],
286fda93d92SStephen Hemminger 		   &new_addr[3], &new_addr[4], &new_addr[5]) != 6)
287fda93d92SStephen Hemminger 		return -EINVAL;
288fda93d92SStephen Hemminger 
289fda93d92SStephen Hemminger 	/* Must be 01:80:c2:00:00:0X */
290fda93d92SStephen Hemminger 	for (i = 0; i < 5; i++)
291fda93d92SStephen Hemminger 		if (new_addr[i] != br_group_address[i])
292fda93d92SStephen Hemminger 			return -EINVAL;
293fda93d92SStephen Hemminger 
294fda93d92SStephen Hemminger 	if (new_addr[5] & ~0xf)
295fda93d92SStephen Hemminger 		return -EINVAL;
296fda93d92SStephen Hemminger 
297fda93d92SStephen Hemminger 	if (new_addr[5] == 1 	/* 802.3x Pause address */
298fda93d92SStephen Hemminger 	    || new_addr[5] == 2 /* 802.3ad Slow protocols */
299fda93d92SStephen Hemminger 	    || new_addr[5] == 3) /* 802.1X PAE address */
300fda93d92SStephen Hemminger 		return -EINVAL;
301fda93d92SStephen Hemminger 
302fda93d92SStephen Hemminger 	spin_lock_bh(&br->lock);
303fda93d92SStephen Hemminger 	for (i = 0; i < 6; i++)
304fda93d92SStephen Hemminger 		br->group_addr[i] = new_addr[i];
305fda93d92SStephen Hemminger 	spin_unlock_bh(&br->lock);
306fda93d92SStephen Hemminger 	return len;
307fda93d92SStephen Hemminger }
308fda93d92SStephen Hemminger 
309*43cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(group_addr, S_IRUGO | S_IWUSR,
310fda93d92SStephen Hemminger 		   show_group_addr, store_group_addr);
311fda93d92SStephen Hemminger 
312fda93d92SStephen Hemminger 
3131da177e4SLinus Torvalds static struct attribute *bridge_attrs[] = {
314*43cb76d9SGreg Kroah-Hartman 	&dev_attr_forward_delay.attr,
315*43cb76d9SGreg Kroah-Hartman 	&dev_attr_hello_time.attr,
316*43cb76d9SGreg Kroah-Hartman 	&dev_attr_max_age.attr,
317*43cb76d9SGreg Kroah-Hartman 	&dev_attr_ageing_time.attr,
318*43cb76d9SGreg Kroah-Hartman 	&dev_attr_stp_state.attr,
319*43cb76d9SGreg Kroah-Hartman 	&dev_attr_priority.attr,
320*43cb76d9SGreg Kroah-Hartman 	&dev_attr_bridge_id.attr,
321*43cb76d9SGreg Kroah-Hartman 	&dev_attr_root_id.attr,
322*43cb76d9SGreg Kroah-Hartman 	&dev_attr_root_path_cost.attr,
323*43cb76d9SGreg Kroah-Hartman 	&dev_attr_root_port.attr,
324*43cb76d9SGreg Kroah-Hartman 	&dev_attr_topology_change.attr,
325*43cb76d9SGreg Kroah-Hartman 	&dev_attr_topology_change_detected.attr,
326*43cb76d9SGreg Kroah-Hartman 	&dev_attr_hello_timer.attr,
327*43cb76d9SGreg Kroah-Hartman 	&dev_attr_tcn_timer.attr,
328*43cb76d9SGreg Kroah-Hartman 	&dev_attr_topology_change_timer.attr,
329*43cb76d9SGreg Kroah-Hartman 	&dev_attr_gc_timer.attr,
330*43cb76d9SGreg Kroah-Hartman 	&dev_attr_group_addr.attr,
3311da177e4SLinus Torvalds 	NULL
3321da177e4SLinus Torvalds };
3331da177e4SLinus Torvalds 
3341da177e4SLinus Torvalds static struct attribute_group bridge_group = {
3351da177e4SLinus Torvalds 	.name = SYSFS_BRIDGE_ATTR,
3361da177e4SLinus Torvalds 	.attrs = bridge_attrs,
3371da177e4SLinus Torvalds };
3381da177e4SLinus Torvalds 
3391da177e4SLinus Torvalds /*
3401da177e4SLinus Torvalds  * Export the forwarding information table as a binary file
3411da177e4SLinus Torvalds  * The records are struct __fdb_entry.
3421da177e4SLinus Torvalds  *
3431da177e4SLinus Torvalds  * Returns the number of bytes read.
3441da177e4SLinus Torvalds  */
3451da177e4SLinus Torvalds static ssize_t brforward_read(struct kobject *kobj, char *buf,
3461da177e4SLinus Torvalds 			   loff_t off, size_t count)
3471da177e4SLinus Torvalds {
348*43cb76d9SGreg Kroah-Hartman 	struct device *dev = to_dev(kobj);
349*43cb76d9SGreg Kroah-Hartman 	struct net_bridge *br = to_bridge(dev);
3501da177e4SLinus Torvalds 	int n;
3511da177e4SLinus Torvalds 
3521da177e4SLinus Torvalds 	/* must read whole records */
3531da177e4SLinus Torvalds 	if (off % sizeof(struct __fdb_entry) != 0)
3541da177e4SLinus Torvalds 		return -EINVAL;
3551da177e4SLinus Torvalds 
3561da177e4SLinus Torvalds 	n =  br_fdb_fillbuf(br, buf,
3571da177e4SLinus Torvalds 			    count / sizeof(struct __fdb_entry),
3581da177e4SLinus Torvalds 			    off / sizeof(struct __fdb_entry));
3591da177e4SLinus Torvalds 
3601da177e4SLinus Torvalds 	if (n > 0)
3611da177e4SLinus Torvalds 		n *= sizeof(struct __fdb_entry);
3621da177e4SLinus Torvalds 
3631da177e4SLinus Torvalds 	return n;
3641da177e4SLinus Torvalds }
3651da177e4SLinus Torvalds 
3661da177e4SLinus Torvalds static struct bin_attribute bridge_forward = {
3671da177e4SLinus Torvalds 	.attr = { .name = SYSFS_BRIDGE_FDB,
3681da177e4SLinus Torvalds 		  .mode = S_IRUGO,
3691da177e4SLinus Torvalds 		  .owner = THIS_MODULE, },
3701da177e4SLinus Torvalds 	.read = brforward_read,
3711da177e4SLinus Torvalds };
3721da177e4SLinus Torvalds 
3731da177e4SLinus Torvalds /*
3741da177e4SLinus Torvalds  * Add entries in sysfs onto the existing network class device
3751da177e4SLinus Torvalds  * for the bridge.
3761da177e4SLinus Torvalds  *   Adds a attribute group "bridge" containing tuning parameters.
3771da177e4SLinus Torvalds  *   Binary attribute containing the forward table
3781da177e4SLinus Torvalds  *   Sub directory to hold links to interfaces.
3791da177e4SLinus Torvalds  *
3801da177e4SLinus Torvalds  * Note: the ifobj exists only to be a subdirectory
3811da177e4SLinus Torvalds  *   to hold links.  The ifobj exists in same data structure
3821da177e4SLinus Torvalds  *   as it's parent the bridge so reference counting works.
3831da177e4SLinus Torvalds  */
3841da177e4SLinus Torvalds int br_sysfs_addbr(struct net_device *dev)
3851da177e4SLinus Torvalds {
386*43cb76d9SGreg Kroah-Hartman 	struct kobject *brobj = &dev->dev.kobj;
3871da177e4SLinus Torvalds 	struct net_bridge *br = netdev_priv(dev);
3881da177e4SLinus Torvalds 	int err;
3891da177e4SLinus Torvalds 
3901da177e4SLinus Torvalds 	err = sysfs_create_group(brobj, &bridge_group);
3911da177e4SLinus Torvalds 	if (err) {
3921da177e4SLinus Torvalds 		pr_info("%s: can't create group %s/%s\n",
3931da177e4SLinus Torvalds 			__FUNCTION__, dev->name, bridge_group.name);
3941da177e4SLinus Torvalds 		goto out1;
3951da177e4SLinus Torvalds 	}
3961da177e4SLinus Torvalds 
3971da177e4SLinus Torvalds 	err = sysfs_create_bin_file(brobj, &bridge_forward);
3981da177e4SLinus Torvalds 	if (err) {
3991842c4beSRandy Dunlap 		pr_info("%s: can't create attribute file %s/%s\n",
4001da177e4SLinus Torvalds 			__FUNCTION__, dev->name, bridge_forward.attr.name);
4011da177e4SLinus Torvalds 		goto out2;
4021da177e4SLinus Torvalds 	}
4031da177e4SLinus Torvalds 
4041da177e4SLinus Torvalds 
4051da177e4SLinus Torvalds 	kobject_set_name(&br->ifobj, SYSFS_BRIDGE_PORT_SUBDIR);
4061da177e4SLinus Torvalds 	br->ifobj.ktype = NULL;
4071da177e4SLinus Torvalds 	br->ifobj.kset = NULL;
4081da177e4SLinus Torvalds 	br->ifobj.parent = brobj;
4091da177e4SLinus Torvalds 
4101da177e4SLinus Torvalds 	err = kobject_register(&br->ifobj);
4111da177e4SLinus Torvalds 	if (err) {
4121da177e4SLinus Torvalds 		pr_info("%s: can't add kobject (directory) %s/%s\n",
4131da177e4SLinus Torvalds 			__FUNCTION__, dev->name, br->ifobj.name);
4141da177e4SLinus Torvalds 		goto out3;
4151da177e4SLinus Torvalds 	}
4161da177e4SLinus Torvalds 	return 0;
4171da177e4SLinus Torvalds  out3:
418*43cb76d9SGreg Kroah-Hartman 	sysfs_remove_bin_file(&dev->dev.kobj, &bridge_forward);
4191da177e4SLinus Torvalds  out2:
420*43cb76d9SGreg Kroah-Hartman 	sysfs_remove_group(&dev->dev.kobj, &bridge_group);
4211da177e4SLinus Torvalds  out1:
4221da177e4SLinus Torvalds 	return err;
4231da177e4SLinus Torvalds 
4241da177e4SLinus Torvalds }
4251da177e4SLinus Torvalds 
4261da177e4SLinus Torvalds void br_sysfs_delbr(struct net_device *dev)
4271da177e4SLinus Torvalds {
428*43cb76d9SGreg Kroah-Hartman 	struct kobject *kobj = &dev->dev.kobj;
4291da177e4SLinus Torvalds 	struct net_bridge *br = netdev_priv(dev);
4301da177e4SLinus Torvalds 
4311da177e4SLinus Torvalds 	kobject_unregister(&br->ifobj);
4321da177e4SLinus Torvalds 	sysfs_remove_bin_file(kobj, &bridge_forward);
4331da177e4SLinus Torvalds 	sysfs_remove_group(kobj, &bridge_group);
4341da177e4SLinus Torvalds }
435