xref: /openbmc/linux/net/bridge/br_sysfs_br.c (revision 91a6902958f052358899f58683d44e36228d85c2)
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 
2443cb76d9SGreg 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  */
3043cb76d9SGreg 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 {
3443cb76d9SGreg 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 
5243cb76d9SGreg Kroah-Hartman static ssize_t show_forward_delay(struct device *d,
5343cb76d9SGreg Kroah-Hartman 				  struct device_attribute *attr, char *buf)
541da177e4SLinus Torvalds {
5543cb76d9SGreg 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 
6743cb76d9SGreg Kroah-Hartman static ssize_t store_forward_delay(struct device *d,
6843cb76d9SGreg Kroah-Hartman 				   struct device_attribute *attr,
6943cb76d9SGreg Kroah-Hartman 				   const char *buf, size_t len)
701da177e4SLinus Torvalds {
7143cb76d9SGreg Kroah-Hartman 	return store_bridge_parm(d, buf, len, set_forward_delay);
721da177e4SLinus Torvalds }
7343cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(forward_delay, S_IRUGO | S_IWUSR,
741da177e4SLinus Torvalds 		   show_forward_delay, store_forward_delay);
751da177e4SLinus Torvalds 
7643cb76d9SGreg Kroah-Hartman static ssize_t show_hello_time(struct device *d, struct device_attribute *attr,
7743cb76d9SGreg Kroah-Hartman 			       char *buf)
781da177e4SLinus Torvalds {
791da177e4SLinus Torvalds 	return sprintf(buf, "%lu\n",
8043cb76d9SGreg 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 
9143cb76d9SGreg Kroah-Hartman static ssize_t store_hello_time(struct device *d,
9243cb76d9SGreg Kroah-Hartman 				struct device_attribute *attr, const char *buf,
931da177e4SLinus Torvalds 				size_t len)
941da177e4SLinus Torvalds {
9543cb76d9SGreg Kroah-Hartman 	return store_bridge_parm(d, buf, len, set_hello_time);
961da177e4SLinus Torvalds }
9743cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(hello_time, S_IRUGO | S_IWUSR, show_hello_time,
981da177e4SLinus Torvalds 		   store_hello_time);
991da177e4SLinus Torvalds 
10043cb76d9SGreg Kroah-Hartman static ssize_t show_max_age(struct device *d, struct device_attribute *attr,
10143cb76d9SGreg Kroah-Hartman 			    char *buf)
1021da177e4SLinus Torvalds {
1031da177e4SLinus Torvalds 	return sprintf(buf, "%lu\n",
10443cb76d9SGreg 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 
11543cb76d9SGreg Kroah-Hartman static ssize_t store_max_age(struct device *d, struct device_attribute *attr,
11643cb76d9SGreg Kroah-Hartman 			     const char *buf, size_t len)
1171da177e4SLinus Torvalds {
11843cb76d9SGreg Kroah-Hartman 	return store_bridge_parm(d, buf, len, set_max_age);
1191da177e4SLinus Torvalds }
12043cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(max_age, S_IRUGO | S_IWUSR, show_max_age, store_max_age);
1211da177e4SLinus Torvalds 
12243cb76d9SGreg Kroah-Hartman static ssize_t show_ageing_time(struct device *d,
12343cb76d9SGreg Kroah-Hartman 				struct device_attribute *attr, char *buf)
1241da177e4SLinus Torvalds {
12543cb76d9SGreg 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 
13443cb76d9SGreg Kroah-Hartman static ssize_t store_ageing_time(struct device *d,
13543cb76d9SGreg Kroah-Hartman 				 struct device_attribute *attr,
13643cb76d9SGreg Kroah-Hartman 				 const char *buf, size_t len)
1371da177e4SLinus Torvalds {
13843cb76d9SGreg Kroah-Hartman 	return store_bridge_parm(d, buf, len, set_ageing_time);
1391da177e4SLinus Torvalds }
14043cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(ageing_time, S_IRUGO | S_IWUSR, show_ageing_time,
1411da177e4SLinus Torvalds 		   store_ageing_time);
14243cb76d9SGreg Kroah-Hartman 
14343cb76d9SGreg Kroah-Hartman static ssize_t show_stp_state(struct device *d,
14443cb76d9SGreg Kroah-Hartman 			      struct device_attribute *attr, char *buf)
1451da177e4SLinus Torvalds {
14643cb76d9SGreg 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 {
15298486fa2SStephen Hemminger 	rtnl_lock();
1539cde0708SStephen Hemminger 	spin_unlock_bh(&br->lock);
1549cde0708SStephen Hemminger 	br_stp_set_enabled(br, val);
1559cde0708SStephen Hemminger 	spin_lock_bh(&br->lock);
15698486fa2SStephen Hemminger 	rtnl_unlock();
1571da177e4SLinus Torvalds }
1581da177e4SLinus Torvalds 
15943cb76d9SGreg Kroah-Hartman static ssize_t store_stp_state(struct device *d,
16043cb76d9SGreg Kroah-Hartman 			       struct device_attribute *attr, const char *buf,
16143cb76d9SGreg Kroah-Hartman 			       size_t len)
1621da177e4SLinus Torvalds {
16343cb76d9SGreg Kroah-Hartman 	return store_bridge_parm(d, buf, len, set_stp_state);
1641da177e4SLinus Torvalds }
16543cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(stp_state, S_IRUGO | S_IWUSR, show_stp_state,
1661da177e4SLinus Torvalds 		   store_stp_state);
1671da177e4SLinus Torvalds 
16843cb76d9SGreg Kroah-Hartman static ssize_t show_priority(struct device *d, struct device_attribute *attr,
16943cb76d9SGreg Kroah-Hartman 			     char *buf)
1701da177e4SLinus Torvalds {
17143cb76d9SGreg Kroah-Hartman 	struct net_bridge *br = to_bridge(d);
1721da177e4SLinus Torvalds 	return sprintf(buf, "%d\n",
1731da177e4SLinus Torvalds 		       (br->bridge_id.prio[0] << 8) | br->bridge_id.prio[1]);
1741da177e4SLinus Torvalds }
1751da177e4SLinus Torvalds 
1761da177e4SLinus Torvalds static void set_priority(struct net_bridge *br, unsigned long val)
1771da177e4SLinus Torvalds {
1781da177e4SLinus Torvalds 	br_stp_set_bridge_priority(br, (u16) val);
1791da177e4SLinus Torvalds }
1801da177e4SLinus Torvalds 
18143cb76d9SGreg Kroah-Hartman static ssize_t store_priority(struct device *d, struct device_attribute *attr,
1821da177e4SLinus Torvalds 			       const char *buf, size_t len)
1831da177e4SLinus Torvalds {
18443cb76d9SGreg Kroah-Hartman 	return store_bridge_parm(d, buf, len, set_priority);
1851da177e4SLinus Torvalds }
18643cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(priority, S_IRUGO | S_IWUSR, show_priority, store_priority);
1871da177e4SLinus Torvalds 
18843cb76d9SGreg Kroah-Hartman static ssize_t show_root_id(struct device *d, struct device_attribute *attr,
18943cb76d9SGreg Kroah-Hartman 			    char *buf)
1901da177e4SLinus Torvalds {
19143cb76d9SGreg Kroah-Hartman 	return br_show_bridge_id(buf, &to_bridge(d)->designated_root);
1921da177e4SLinus Torvalds }
19343cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(root_id, S_IRUGO, show_root_id, NULL);
1941da177e4SLinus Torvalds 
19543cb76d9SGreg Kroah-Hartman static ssize_t show_bridge_id(struct device *d, struct device_attribute *attr,
19643cb76d9SGreg Kroah-Hartman 			      char *buf)
1971da177e4SLinus Torvalds {
19843cb76d9SGreg Kroah-Hartman 	return br_show_bridge_id(buf, &to_bridge(d)->bridge_id);
1991da177e4SLinus Torvalds }
20043cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(bridge_id, S_IRUGO, show_bridge_id, NULL);
2011da177e4SLinus Torvalds 
20243cb76d9SGreg Kroah-Hartman static ssize_t show_root_port(struct device *d, struct device_attribute *attr,
20343cb76d9SGreg Kroah-Hartman 			      char *buf)
2041da177e4SLinus Torvalds {
20543cb76d9SGreg Kroah-Hartman 	return sprintf(buf, "%d\n", to_bridge(d)->root_port);
2061da177e4SLinus Torvalds }
20743cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(root_port, S_IRUGO, show_root_port, NULL);
2081da177e4SLinus Torvalds 
20943cb76d9SGreg Kroah-Hartman static ssize_t show_root_path_cost(struct device *d,
21043cb76d9SGreg Kroah-Hartman 				   struct device_attribute *attr, char *buf)
2111da177e4SLinus Torvalds {
21243cb76d9SGreg Kroah-Hartman 	return sprintf(buf, "%d\n", to_bridge(d)->root_path_cost);
2131da177e4SLinus Torvalds }
21443cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(root_path_cost, S_IRUGO, show_root_path_cost, NULL);
2151da177e4SLinus Torvalds 
21643cb76d9SGreg Kroah-Hartman static ssize_t show_topology_change(struct device *d,
21743cb76d9SGreg Kroah-Hartman 				    struct device_attribute *attr, char *buf)
2181da177e4SLinus Torvalds {
21943cb76d9SGreg Kroah-Hartman 	return sprintf(buf, "%d\n", to_bridge(d)->topology_change);
2201da177e4SLinus Torvalds }
22143cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(topology_change, S_IRUGO, show_topology_change, NULL);
2221da177e4SLinus Torvalds 
22343cb76d9SGreg Kroah-Hartman static ssize_t show_topology_change_detected(struct device *d,
22443cb76d9SGreg Kroah-Hartman 					     struct device_attribute *attr,
22543cb76d9SGreg Kroah-Hartman 					     char *buf)
2261da177e4SLinus Torvalds {
22743cb76d9SGreg Kroah-Hartman 	struct net_bridge *br = to_bridge(d);
2281da177e4SLinus Torvalds 	return sprintf(buf, "%d\n", br->topology_change_detected);
2291da177e4SLinus Torvalds }
23043cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(topology_change_detected, S_IRUGO,
23143cb76d9SGreg Kroah-Hartman 		   show_topology_change_detected, NULL);
2321da177e4SLinus Torvalds 
23343cb76d9SGreg Kroah-Hartman static ssize_t show_hello_timer(struct device *d,
23443cb76d9SGreg Kroah-Hartman 				struct device_attribute *attr, char *buf)
2351da177e4SLinus Torvalds {
23643cb76d9SGreg Kroah-Hartman 	struct net_bridge *br = to_bridge(d);
2371da177e4SLinus Torvalds 	return sprintf(buf, "%ld\n", br_timer_value(&br->hello_timer));
2381da177e4SLinus Torvalds }
23943cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(hello_timer, S_IRUGO, show_hello_timer, NULL);
2401da177e4SLinus Torvalds 
24143cb76d9SGreg Kroah-Hartman static ssize_t show_tcn_timer(struct device *d, struct device_attribute *attr,
24243cb76d9SGreg Kroah-Hartman 			      char *buf)
2431da177e4SLinus Torvalds {
24443cb76d9SGreg Kroah-Hartman 	struct net_bridge *br = to_bridge(d);
2451da177e4SLinus Torvalds 	return sprintf(buf, "%ld\n", br_timer_value(&br->tcn_timer));
2461da177e4SLinus Torvalds }
24743cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(tcn_timer, S_IRUGO, show_tcn_timer, NULL);
2481da177e4SLinus Torvalds 
24943cb76d9SGreg Kroah-Hartman static ssize_t show_topology_change_timer(struct device *d,
25043cb76d9SGreg Kroah-Hartman 					  struct device_attribute *attr,
25143cb76d9SGreg Kroah-Hartman 					  char *buf)
2521da177e4SLinus Torvalds {
25343cb76d9SGreg Kroah-Hartman 	struct net_bridge *br = to_bridge(d);
2541da177e4SLinus Torvalds 	return sprintf(buf, "%ld\n", br_timer_value(&br->topology_change_timer));
2551da177e4SLinus Torvalds }
25643cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(topology_change_timer, S_IRUGO, show_topology_change_timer,
25743cb76d9SGreg Kroah-Hartman 		   NULL);
2581da177e4SLinus Torvalds 
25943cb76d9SGreg Kroah-Hartman static ssize_t show_gc_timer(struct device *d, struct device_attribute *attr,
26043cb76d9SGreg Kroah-Hartman 			     char *buf)
2611da177e4SLinus Torvalds {
26243cb76d9SGreg Kroah-Hartman 	struct net_bridge *br = to_bridge(d);
2631da177e4SLinus Torvalds 	return sprintf(buf, "%ld\n", br_timer_value(&br->gc_timer));
2641da177e4SLinus Torvalds }
26543cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(gc_timer, S_IRUGO, show_gc_timer, NULL);
2661da177e4SLinus Torvalds 
26743cb76d9SGreg Kroah-Hartman static ssize_t show_group_addr(struct device *d,
26843cb76d9SGreg Kroah-Hartman 			       struct device_attribute *attr, char *buf)
269fda93d92SStephen Hemminger {
27043cb76d9SGreg Kroah-Hartman 	struct net_bridge *br = to_bridge(d);
271fda93d92SStephen Hemminger 	return sprintf(buf, "%x:%x:%x:%x:%x:%x\n",
272fda93d92SStephen Hemminger 		       br->group_addr[0], br->group_addr[1],
273fda93d92SStephen Hemminger 		       br->group_addr[2], br->group_addr[3],
274fda93d92SStephen Hemminger 		       br->group_addr[4], br->group_addr[5]);
275fda93d92SStephen Hemminger }
276fda93d92SStephen Hemminger 
27743cb76d9SGreg Kroah-Hartman static ssize_t store_group_addr(struct device *d,
27843cb76d9SGreg Kroah-Hartman 				struct device_attribute *attr,
27943cb76d9SGreg Kroah-Hartman 				const char *buf, size_t len)
280fda93d92SStephen Hemminger {
28143cb76d9SGreg Kroah-Hartman 	struct net_bridge *br = to_bridge(d);
282fda93d92SStephen Hemminger 	unsigned new_addr[6];
283fda93d92SStephen Hemminger 	int i;
284fda93d92SStephen Hemminger 
285fda93d92SStephen Hemminger 	if (!capable(CAP_NET_ADMIN))
286fda93d92SStephen Hemminger 		return -EPERM;
287fda93d92SStephen Hemminger 
288fda93d92SStephen Hemminger 	if (sscanf(buf, "%x:%x:%x:%x:%x:%x",
289fda93d92SStephen Hemminger 		   &new_addr[0], &new_addr[1], &new_addr[2],
290fda93d92SStephen Hemminger 		   &new_addr[3], &new_addr[4], &new_addr[5]) != 6)
291fda93d92SStephen Hemminger 		return -EINVAL;
292fda93d92SStephen Hemminger 
293fda93d92SStephen Hemminger 	/* Must be 01:80:c2:00:00:0X */
294fda93d92SStephen Hemminger 	for (i = 0; i < 5; i++)
295fda93d92SStephen Hemminger 		if (new_addr[i] != br_group_address[i])
296fda93d92SStephen Hemminger 			return -EINVAL;
297fda93d92SStephen Hemminger 
298fda93d92SStephen Hemminger 	if (new_addr[5] & ~0xf)
299fda93d92SStephen Hemminger 		return -EINVAL;
300fda93d92SStephen Hemminger 
301fda93d92SStephen Hemminger 	if (new_addr[5] == 1 	/* 802.3x Pause address */
302fda93d92SStephen Hemminger 	    || new_addr[5] == 2 /* 802.3ad Slow protocols */
303fda93d92SStephen Hemminger 	    || new_addr[5] == 3) /* 802.1X PAE address */
304fda93d92SStephen Hemminger 		return -EINVAL;
305fda93d92SStephen Hemminger 
306fda93d92SStephen Hemminger 	spin_lock_bh(&br->lock);
307fda93d92SStephen Hemminger 	for (i = 0; i < 6; i++)
308fda93d92SStephen Hemminger 		br->group_addr[i] = new_addr[i];
309fda93d92SStephen Hemminger 	spin_unlock_bh(&br->lock);
310fda93d92SStephen Hemminger 	return len;
311fda93d92SStephen Hemminger }
312fda93d92SStephen Hemminger 
31343cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(group_addr, S_IRUGO | S_IWUSR,
314fda93d92SStephen Hemminger 		   show_group_addr, store_group_addr);
315fda93d92SStephen Hemminger 
3169cf63747SStephen Hemminger static ssize_t store_flush(struct device *d,
3179cf63747SStephen Hemminger 			   struct device_attribute *attr,
3189cf63747SStephen Hemminger 			   const char *buf, size_t len)
3199cf63747SStephen Hemminger {
3209cf63747SStephen Hemminger 	struct net_bridge *br = to_bridge(d);
3219cf63747SStephen Hemminger 
3229cf63747SStephen Hemminger 	if (!capable(CAP_NET_ADMIN))
3239cf63747SStephen Hemminger 		return -EPERM;
3249cf63747SStephen Hemminger 
3259cf63747SStephen Hemminger 	br_fdb_flush(br);
3269cf63747SStephen Hemminger 	return len;
3279cf63747SStephen Hemminger }
3289cf63747SStephen Hemminger static DEVICE_ATTR(flush, S_IWUSR, NULL, store_flush);
329fda93d92SStephen Hemminger 
3301da177e4SLinus Torvalds static struct attribute *bridge_attrs[] = {
33143cb76d9SGreg Kroah-Hartman 	&dev_attr_forward_delay.attr,
33243cb76d9SGreg Kroah-Hartman 	&dev_attr_hello_time.attr,
33343cb76d9SGreg Kroah-Hartman 	&dev_attr_max_age.attr,
33443cb76d9SGreg Kroah-Hartman 	&dev_attr_ageing_time.attr,
33543cb76d9SGreg Kroah-Hartman 	&dev_attr_stp_state.attr,
33643cb76d9SGreg Kroah-Hartman 	&dev_attr_priority.attr,
33743cb76d9SGreg Kroah-Hartman 	&dev_attr_bridge_id.attr,
33843cb76d9SGreg Kroah-Hartman 	&dev_attr_root_id.attr,
33943cb76d9SGreg Kroah-Hartman 	&dev_attr_root_path_cost.attr,
34043cb76d9SGreg Kroah-Hartman 	&dev_attr_root_port.attr,
34143cb76d9SGreg Kroah-Hartman 	&dev_attr_topology_change.attr,
34243cb76d9SGreg Kroah-Hartman 	&dev_attr_topology_change_detected.attr,
34343cb76d9SGreg Kroah-Hartman 	&dev_attr_hello_timer.attr,
34443cb76d9SGreg Kroah-Hartman 	&dev_attr_tcn_timer.attr,
34543cb76d9SGreg Kroah-Hartman 	&dev_attr_topology_change_timer.attr,
34643cb76d9SGreg Kroah-Hartman 	&dev_attr_gc_timer.attr,
34743cb76d9SGreg Kroah-Hartman 	&dev_attr_group_addr.attr,
3489cf63747SStephen Hemminger 	&dev_attr_flush.attr,
3491da177e4SLinus Torvalds 	NULL
3501da177e4SLinus Torvalds };
3511da177e4SLinus Torvalds 
3521da177e4SLinus Torvalds static struct attribute_group bridge_group = {
3531da177e4SLinus Torvalds 	.name = SYSFS_BRIDGE_ATTR,
3541da177e4SLinus Torvalds 	.attrs = bridge_attrs,
3551da177e4SLinus Torvalds };
3561da177e4SLinus Torvalds 
3571da177e4SLinus Torvalds /*
3581da177e4SLinus Torvalds  * Export the forwarding information table as a binary file
3591da177e4SLinus Torvalds  * The records are struct __fdb_entry.
3601da177e4SLinus Torvalds  *
3611da177e4SLinus Torvalds  * Returns the number of bytes read.
3621da177e4SLinus Torvalds  */
363*91a69029SZhang Rui static ssize_t brforward_read(struct kobject *kobj,
364*91a69029SZhang Rui 			      struct bin_attribute *bin_attr,
365*91a69029SZhang Rui 			      char *buf, loff_t off, size_t count)
3661da177e4SLinus Torvalds {
36743cb76d9SGreg Kroah-Hartman 	struct device *dev = to_dev(kobj);
36843cb76d9SGreg Kroah-Hartman 	struct net_bridge *br = to_bridge(dev);
3691da177e4SLinus Torvalds 	int n;
3701da177e4SLinus Torvalds 
3711da177e4SLinus Torvalds 	/* must read whole records */
3721da177e4SLinus Torvalds 	if (off % sizeof(struct __fdb_entry) != 0)
3731da177e4SLinus Torvalds 		return -EINVAL;
3741da177e4SLinus Torvalds 
3751da177e4SLinus Torvalds 	n =  br_fdb_fillbuf(br, buf,
3761da177e4SLinus Torvalds 			    count / sizeof(struct __fdb_entry),
3771da177e4SLinus Torvalds 			    off / sizeof(struct __fdb_entry));
3781da177e4SLinus Torvalds 
3791da177e4SLinus Torvalds 	if (n > 0)
3801da177e4SLinus Torvalds 		n *= sizeof(struct __fdb_entry);
3811da177e4SLinus Torvalds 
3821da177e4SLinus Torvalds 	return n;
3831da177e4SLinus Torvalds }
3841da177e4SLinus Torvalds 
3851da177e4SLinus Torvalds static struct bin_attribute bridge_forward = {
3861da177e4SLinus Torvalds 	.attr = { .name = SYSFS_BRIDGE_FDB,
3877b595756STejun Heo 		  .mode = S_IRUGO, },
3881da177e4SLinus Torvalds 	.read = brforward_read,
3891da177e4SLinus Torvalds };
3901da177e4SLinus Torvalds 
3911da177e4SLinus Torvalds /*
3921da177e4SLinus Torvalds  * Add entries in sysfs onto the existing network class device
3931da177e4SLinus Torvalds  * for the bridge.
3941da177e4SLinus Torvalds  *   Adds a attribute group "bridge" containing tuning parameters.
3951da177e4SLinus Torvalds  *   Binary attribute containing the forward table
3961da177e4SLinus Torvalds  *   Sub directory to hold links to interfaces.
3971da177e4SLinus Torvalds  *
3981da177e4SLinus Torvalds  * Note: the ifobj exists only to be a subdirectory
3991da177e4SLinus Torvalds  *   to hold links.  The ifobj exists in same data structure
4001da177e4SLinus Torvalds  *   as it's parent the bridge so reference counting works.
4011da177e4SLinus Torvalds  */
4021da177e4SLinus Torvalds int br_sysfs_addbr(struct net_device *dev)
4031da177e4SLinus Torvalds {
40443cb76d9SGreg Kroah-Hartman 	struct kobject *brobj = &dev->dev.kobj;
4051da177e4SLinus Torvalds 	struct net_bridge *br = netdev_priv(dev);
4061da177e4SLinus Torvalds 	int err;
4071da177e4SLinus Torvalds 
4081da177e4SLinus Torvalds 	err = sysfs_create_group(brobj, &bridge_group);
4091da177e4SLinus Torvalds 	if (err) {
4101da177e4SLinus Torvalds 		pr_info("%s: can't create group %s/%s\n",
4111da177e4SLinus Torvalds 			__FUNCTION__, dev->name, bridge_group.name);
4121da177e4SLinus Torvalds 		goto out1;
4131da177e4SLinus Torvalds 	}
4141da177e4SLinus Torvalds 
4151da177e4SLinus Torvalds 	err = sysfs_create_bin_file(brobj, &bridge_forward);
4161da177e4SLinus Torvalds 	if (err) {
4171842c4beSRandy Dunlap 		pr_info("%s: can't create attribute file %s/%s\n",
4181da177e4SLinus Torvalds 			__FUNCTION__, dev->name, bridge_forward.attr.name);
4191da177e4SLinus Torvalds 		goto out2;
4201da177e4SLinus Torvalds 	}
4211da177e4SLinus Torvalds 
4221da177e4SLinus Torvalds 
4231da177e4SLinus Torvalds 	kobject_set_name(&br->ifobj, SYSFS_BRIDGE_PORT_SUBDIR);
4241da177e4SLinus Torvalds 	br->ifobj.ktype = NULL;
4251da177e4SLinus Torvalds 	br->ifobj.kset = NULL;
4261da177e4SLinus Torvalds 	br->ifobj.parent = brobj;
4271da177e4SLinus Torvalds 
4281da177e4SLinus Torvalds 	err = kobject_register(&br->ifobj);
4291da177e4SLinus Torvalds 	if (err) {
4301da177e4SLinus Torvalds 		pr_info("%s: can't add kobject (directory) %s/%s\n",
4311da177e4SLinus Torvalds 			__FUNCTION__, dev->name, br->ifobj.name);
4321da177e4SLinus Torvalds 		goto out3;
4331da177e4SLinus Torvalds 	}
4341da177e4SLinus Torvalds 	return 0;
4351da177e4SLinus Torvalds  out3:
43643cb76d9SGreg Kroah-Hartman 	sysfs_remove_bin_file(&dev->dev.kobj, &bridge_forward);
4371da177e4SLinus Torvalds  out2:
43843cb76d9SGreg Kroah-Hartman 	sysfs_remove_group(&dev->dev.kobj, &bridge_group);
4391da177e4SLinus Torvalds  out1:
4401da177e4SLinus Torvalds 	return err;
4411da177e4SLinus Torvalds 
4421da177e4SLinus Torvalds }
4431da177e4SLinus Torvalds 
4441da177e4SLinus Torvalds void br_sysfs_delbr(struct net_device *dev)
4451da177e4SLinus Torvalds {
44643cb76d9SGreg Kroah-Hartman 	struct kobject *kobj = &dev->dev.kobj;
4471da177e4SLinus Torvalds 	struct net_bridge *br = netdev_priv(dev);
4481da177e4SLinus Torvalds 
4491da177e4SLinus Torvalds 	kobject_unregister(&br->ifobj);
4501da177e4SLinus Torvalds 	sysfs_remove_bin_file(kobj, &bridge_forward);
4511da177e4SLinus Torvalds 	sysfs_remove_group(kobj, &bridge_group);
4521da177e4SLinus Torvalds }
453