xref: /openbmc/linux/net/bridge/br_sysfs_br.c (revision 1080ab95e3c7bdd77870e209aff83c763fdcf439)
11da177e4SLinus Torvalds /*
215401946SWang Sheng-Hui  *	Sysfs attributes of bridge
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>
17b3343a2aSJohn Fastabend #include <linux/etherdevice.h>
181da177e4SLinus Torvalds #include <linux/if_bridge.h>
191da177e4SLinus Torvalds #include <linux/rtnetlink.h>
201da177e4SLinus Torvalds #include <linux/spinlock.h>
211da177e4SLinus Torvalds #include <linux/times.h>
221da177e4SLinus Torvalds 
231da177e4SLinus Torvalds #include "br_private.h"
241da177e4SLinus Torvalds 
25524ad0a7SWang Chen #define to_bridge(cd)	((struct net_bridge *)netdev_priv(to_net_dev(cd)))
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,
328d4698f7SStephen Hemminger 				 int (*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;
378d4698f7SStephen Hemminger 	int err;
381da177e4SLinus Torvalds 
39cb990503SEric W. Biederman 	if (!ns_capable(dev_net(br->dev)->user_ns, CAP_NET_ADMIN))
401da177e4SLinus Torvalds 		return -EPERM;
411da177e4SLinus Torvalds 
421da177e4SLinus Torvalds 	val = simple_strtoul(buf, &endp, 0);
431da177e4SLinus Torvalds 	if (endp == buf)
441da177e4SLinus Torvalds 		return -EINVAL;
451da177e4SLinus Torvalds 
46047831a9SXin Long 	if (!rtnl_trylock())
47047831a9SXin Long 		return restart_syscall();
48047831a9SXin Long 
498d4698f7SStephen Hemminger 	err = (*set)(br, val);
50047831a9SXin Long 	if (!err)
51047831a9SXin Long 		netdev_state_change(br->dev);
52047831a9SXin Long 	rtnl_unlock();
53047831a9SXin Long 
548d4698f7SStephen Hemminger 	return err ? err : len;
551da177e4SLinus Torvalds }
561da177e4SLinus Torvalds 
571da177e4SLinus Torvalds 
58fbf2671bSsfeldma@cumulusnetworks.com static ssize_t forward_delay_show(struct device *d,
5943cb76d9SGreg Kroah-Hartman 				  struct device_attribute *attr, char *buf)
601da177e4SLinus Torvalds {
6143cb76d9SGreg Kroah-Hartman 	struct net_bridge *br = to_bridge(d);
621da177e4SLinus Torvalds 	return sprintf(buf, "%lu\n", jiffies_to_clock_t(br->forward_delay));
631da177e4SLinus Torvalds }
641da177e4SLinus Torvalds 
65fbf2671bSsfeldma@cumulusnetworks.com static ssize_t forward_delay_store(struct device *d,
6643cb76d9SGreg Kroah-Hartman 				   struct device_attribute *attr,
6743cb76d9SGreg Kroah-Hartman 				   const char *buf, size_t len)
681da177e4SLinus Torvalds {
6914f98f25Sstephen hemminger 	return store_bridge_parm(d, buf, len, br_set_forward_delay);
701da177e4SLinus Torvalds }
71fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(forward_delay);
721da177e4SLinus Torvalds 
73fbf2671bSsfeldma@cumulusnetworks.com static ssize_t hello_time_show(struct device *d, struct device_attribute *attr,
7443cb76d9SGreg Kroah-Hartman 			       char *buf)
751da177e4SLinus Torvalds {
761da177e4SLinus Torvalds 	return sprintf(buf, "%lu\n",
7743cb76d9SGreg Kroah-Hartman 		       jiffies_to_clock_t(to_bridge(d)->hello_time));
781da177e4SLinus Torvalds }
791da177e4SLinus Torvalds 
80fbf2671bSsfeldma@cumulusnetworks.com static ssize_t hello_time_store(struct device *d,
8143cb76d9SGreg Kroah-Hartman 				struct device_attribute *attr, const char *buf,
821da177e4SLinus Torvalds 				size_t len)
831da177e4SLinus Torvalds {
8414f98f25Sstephen hemminger 	return store_bridge_parm(d, buf, len, br_set_hello_time);
851da177e4SLinus Torvalds }
86fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(hello_time);
871da177e4SLinus Torvalds 
88fbf2671bSsfeldma@cumulusnetworks.com static ssize_t max_age_show(struct device *d, struct device_attribute *attr,
8943cb76d9SGreg Kroah-Hartman 			    char *buf)
901da177e4SLinus Torvalds {
911da177e4SLinus Torvalds 	return sprintf(buf, "%lu\n",
9243cb76d9SGreg Kroah-Hartman 		       jiffies_to_clock_t(to_bridge(d)->max_age));
931da177e4SLinus Torvalds }
941da177e4SLinus Torvalds 
95fbf2671bSsfeldma@cumulusnetworks.com static ssize_t max_age_store(struct device *d, struct device_attribute *attr,
9643cb76d9SGreg Kroah-Hartman 			     const char *buf, size_t len)
971da177e4SLinus Torvalds {
9814f98f25Sstephen hemminger 	return store_bridge_parm(d, buf, len, br_set_max_age);
991da177e4SLinus Torvalds }
100fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(max_age);
1011da177e4SLinus Torvalds 
102fbf2671bSsfeldma@cumulusnetworks.com static ssize_t ageing_time_show(struct device *d,
10343cb76d9SGreg Kroah-Hartman 				struct device_attribute *attr, char *buf)
1041da177e4SLinus Torvalds {
10543cb76d9SGreg Kroah-Hartman 	struct net_bridge *br = to_bridge(d);
1061da177e4SLinus Torvalds 	return sprintf(buf, "%lu\n", jiffies_to_clock_t(br->ageing_time));
1071da177e4SLinus Torvalds }
1081da177e4SLinus Torvalds 
1098d4698f7SStephen Hemminger static int set_ageing_time(struct net_bridge *br, unsigned long val)
1101da177e4SLinus Torvalds {
111047831a9SXin Long 	return br_set_ageing_time(br, val);
1121da177e4SLinus Torvalds }
1131da177e4SLinus Torvalds 
114fbf2671bSsfeldma@cumulusnetworks.com static ssize_t ageing_time_store(struct device *d,
11543cb76d9SGreg Kroah-Hartman 				 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_ageing_time);
1191da177e4SLinus Torvalds }
120fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(ageing_time);
12143cb76d9SGreg Kroah-Hartman 
122fbf2671bSsfeldma@cumulusnetworks.com static ssize_t stp_state_show(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, "%d\n", br->stp_enabled);
1271da177e4SLinus Torvalds }
1281da177e4SLinus Torvalds 
1291da177e4SLinus Torvalds 
1304436156bSXin Long static int set_stp_state(struct net_bridge *br, unsigned long val)
1311da177e4SLinus Torvalds {
13217120889SStephen Hemminger 	br_stp_set_enabled(br, val);
13317120889SStephen Hemminger 
1344436156bSXin Long 	return 0;
1354436156bSXin Long }
1364436156bSXin Long 
1374436156bSXin Long static ssize_t stp_state_store(struct device *d,
1384436156bSXin Long 			       struct device_attribute *attr, const char *buf,
1394436156bSXin Long 			       size_t len)
1404436156bSXin Long {
1414436156bSXin Long 	return store_bridge_parm(d, buf, len, set_stp_state);
1421da177e4SLinus Torvalds }
143fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(stp_state);
1441da177e4SLinus Torvalds 
145fbf2671bSsfeldma@cumulusnetworks.com static ssize_t group_fwd_mask_show(struct device *d,
146fbf2671bSsfeldma@cumulusnetworks.com 				   struct device_attribute *attr,
147fbf2671bSsfeldma@cumulusnetworks.com 				   char *buf)
148515853ccSstephen hemminger {
149515853ccSstephen hemminger 	struct net_bridge *br = to_bridge(d);
150515853ccSstephen hemminger 	return sprintf(buf, "%#x\n", br->group_fwd_mask);
151515853ccSstephen hemminger }
152515853ccSstephen hemminger 
153347db6b4SXin Long static int set_group_fwd_mask(struct net_bridge *br, unsigned long val)
154347db6b4SXin Long {
155347db6b4SXin Long 	if (val & BR_GROUPFWD_RESTRICTED)
156347db6b4SXin Long 		return -EINVAL;
157347db6b4SXin Long 
158347db6b4SXin Long 	br->group_fwd_mask = val;
159347db6b4SXin Long 
160347db6b4SXin Long 	return 0;
161347db6b4SXin Long }
162515853ccSstephen hemminger 
163fbf2671bSsfeldma@cumulusnetworks.com static ssize_t group_fwd_mask_store(struct device *d,
164fbf2671bSsfeldma@cumulusnetworks.com 				    struct device_attribute *attr,
165fbf2671bSsfeldma@cumulusnetworks.com 				    const char *buf,
166515853ccSstephen hemminger 				    size_t len)
167515853ccSstephen hemminger {
168347db6b4SXin Long 	return store_bridge_parm(d, buf, len, set_group_fwd_mask);
169515853ccSstephen hemminger }
170fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(group_fwd_mask);
171515853ccSstephen hemminger 
172fbf2671bSsfeldma@cumulusnetworks.com static ssize_t priority_show(struct device *d, struct device_attribute *attr,
17343cb76d9SGreg Kroah-Hartman 			     char *buf)
1741da177e4SLinus Torvalds {
17543cb76d9SGreg Kroah-Hartman 	struct net_bridge *br = to_bridge(d);
1761da177e4SLinus Torvalds 	return sprintf(buf, "%d\n",
1771da177e4SLinus Torvalds 		       (br->bridge_id.prio[0] << 8) | br->bridge_id.prio[1]);
1781da177e4SLinus Torvalds }
1791da177e4SLinus Torvalds 
1808d4698f7SStephen Hemminger static int set_priority(struct net_bridge *br, unsigned long val)
1811da177e4SLinus Torvalds {
1821da177e4SLinus Torvalds 	br_stp_set_bridge_priority(br, (u16) val);
1838d4698f7SStephen Hemminger 	return 0;
1841da177e4SLinus Torvalds }
1851da177e4SLinus Torvalds 
186fbf2671bSsfeldma@cumulusnetworks.com static ssize_t priority_store(struct device *d, struct device_attribute *attr,
1871da177e4SLinus Torvalds 			      const char *buf, size_t len)
1881da177e4SLinus Torvalds {
18943cb76d9SGreg Kroah-Hartman 	return store_bridge_parm(d, buf, len, set_priority);
1901da177e4SLinus Torvalds }
191fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(priority);
1921da177e4SLinus Torvalds 
193fbf2671bSsfeldma@cumulusnetworks.com static ssize_t root_id_show(struct device *d, struct device_attribute *attr,
19443cb76d9SGreg Kroah-Hartman 			    char *buf)
1951da177e4SLinus Torvalds {
19643cb76d9SGreg Kroah-Hartman 	return br_show_bridge_id(buf, &to_bridge(d)->designated_root);
1971da177e4SLinus Torvalds }
198fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RO(root_id);
1991da177e4SLinus Torvalds 
200fbf2671bSsfeldma@cumulusnetworks.com static ssize_t bridge_id_show(struct device *d, struct device_attribute *attr,
20143cb76d9SGreg Kroah-Hartman 			      char *buf)
2021da177e4SLinus Torvalds {
20343cb76d9SGreg Kroah-Hartman 	return br_show_bridge_id(buf, &to_bridge(d)->bridge_id);
2041da177e4SLinus Torvalds }
205fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RO(bridge_id);
2061da177e4SLinus Torvalds 
207fbf2671bSsfeldma@cumulusnetworks.com static ssize_t root_port_show(struct device *d, struct device_attribute *attr,
20843cb76d9SGreg Kroah-Hartman 			      char *buf)
2091da177e4SLinus Torvalds {
21043cb76d9SGreg Kroah-Hartman 	return sprintf(buf, "%d\n", to_bridge(d)->root_port);
2111da177e4SLinus Torvalds }
212fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RO(root_port);
2131da177e4SLinus Torvalds 
214fbf2671bSsfeldma@cumulusnetworks.com static ssize_t root_path_cost_show(struct device *d,
21543cb76d9SGreg Kroah-Hartman 				   struct device_attribute *attr, char *buf)
2161da177e4SLinus Torvalds {
21743cb76d9SGreg Kroah-Hartman 	return sprintf(buf, "%d\n", to_bridge(d)->root_path_cost);
2181da177e4SLinus Torvalds }
219fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RO(root_path_cost);
2201da177e4SLinus Torvalds 
221fbf2671bSsfeldma@cumulusnetworks.com static ssize_t topology_change_show(struct device *d,
22243cb76d9SGreg Kroah-Hartman 				    struct device_attribute *attr, char *buf)
2231da177e4SLinus Torvalds {
22443cb76d9SGreg Kroah-Hartman 	return sprintf(buf, "%d\n", to_bridge(d)->topology_change);
2251da177e4SLinus Torvalds }
226fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RO(topology_change);
2271da177e4SLinus Torvalds 
228fbf2671bSsfeldma@cumulusnetworks.com static ssize_t topology_change_detected_show(struct device *d,
22943cb76d9SGreg Kroah-Hartman 					     struct device_attribute *attr,
23043cb76d9SGreg Kroah-Hartman 					     char *buf)
2311da177e4SLinus Torvalds {
23243cb76d9SGreg Kroah-Hartman 	struct net_bridge *br = to_bridge(d);
2331da177e4SLinus Torvalds 	return sprintf(buf, "%d\n", br->topology_change_detected);
2341da177e4SLinus Torvalds }
235fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RO(topology_change_detected);
2361da177e4SLinus Torvalds 
237fbf2671bSsfeldma@cumulusnetworks.com static ssize_t hello_timer_show(struct device *d,
23843cb76d9SGreg Kroah-Hartman 				struct device_attribute *attr, char *buf)
2391da177e4SLinus Torvalds {
24043cb76d9SGreg Kroah-Hartman 	struct net_bridge *br = to_bridge(d);
2411da177e4SLinus Torvalds 	return sprintf(buf, "%ld\n", br_timer_value(&br->hello_timer));
2421da177e4SLinus Torvalds }
243fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RO(hello_timer);
2441da177e4SLinus Torvalds 
245fbf2671bSsfeldma@cumulusnetworks.com static ssize_t tcn_timer_show(struct device *d, struct device_attribute *attr,
24643cb76d9SGreg Kroah-Hartman 			      char *buf)
2471da177e4SLinus Torvalds {
24843cb76d9SGreg Kroah-Hartman 	struct net_bridge *br = to_bridge(d);
2491da177e4SLinus Torvalds 	return sprintf(buf, "%ld\n", br_timer_value(&br->tcn_timer));
2501da177e4SLinus Torvalds }
251fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RO(tcn_timer);
2521da177e4SLinus Torvalds 
253fbf2671bSsfeldma@cumulusnetworks.com static ssize_t topology_change_timer_show(struct device *d,
25443cb76d9SGreg Kroah-Hartman 					  struct device_attribute *attr,
25543cb76d9SGreg Kroah-Hartman 					  char *buf)
2561da177e4SLinus Torvalds {
25743cb76d9SGreg Kroah-Hartman 	struct net_bridge *br = to_bridge(d);
2581da177e4SLinus Torvalds 	return sprintf(buf, "%ld\n", br_timer_value(&br->topology_change_timer));
2591da177e4SLinus Torvalds }
260fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RO(topology_change_timer);
2611da177e4SLinus Torvalds 
262fbf2671bSsfeldma@cumulusnetworks.com static ssize_t gc_timer_show(struct device *d, struct device_attribute *attr,
26343cb76d9SGreg Kroah-Hartman 			     char *buf)
2641da177e4SLinus Torvalds {
26543cb76d9SGreg Kroah-Hartman 	struct net_bridge *br = to_bridge(d);
2661da177e4SLinus Torvalds 	return sprintf(buf, "%ld\n", br_timer_value(&br->gc_timer));
2671da177e4SLinus Torvalds }
268fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RO(gc_timer);
2691da177e4SLinus Torvalds 
270fbf2671bSsfeldma@cumulusnetworks.com static ssize_t group_addr_show(struct device *d,
27143cb76d9SGreg Kroah-Hartman 			       struct device_attribute *attr, char *buf)
272fda93d92SStephen Hemminger {
27343cb76d9SGreg Kroah-Hartman 	struct net_bridge *br = to_bridge(d);
274fda93d92SStephen Hemminger 	return sprintf(buf, "%x:%x:%x:%x:%x:%x\n",
275fda93d92SStephen Hemminger 		       br->group_addr[0], br->group_addr[1],
276fda93d92SStephen Hemminger 		       br->group_addr[2], br->group_addr[3],
277fda93d92SStephen Hemminger 		       br->group_addr[4], br->group_addr[5]);
278fda93d92SStephen Hemminger }
279fda93d92SStephen Hemminger 
280fbf2671bSsfeldma@cumulusnetworks.com static ssize_t group_addr_store(struct device *d,
28143cb76d9SGreg Kroah-Hartman 				struct device_attribute *attr,
28243cb76d9SGreg Kroah-Hartman 				const char *buf, size_t len)
283fda93d92SStephen Hemminger {
28443cb76d9SGreg Kroah-Hartman 	struct net_bridge *br = to_bridge(d);
2854197f24bSBen Hutchings 	u8 new_addr[6];
286fda93d92SStephen Hemminger 	int i;
287fda93d92SStephen Hemminger 
288cb990503SEric W. Biederman 	if (!ns_capable(dev_net(br->dev)->user_ns, CAP_NET_ADMIN))
289fda93d92SStephen Hemminger 		return -EPERM;
290fda93d92SStephen Hemminger 
2914197f24bSBen Hutchings 	if (sscanf(buf, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx",
292fda93d92SStephen Hemminger 		   &new_addr[0], &new_addr[1], &new_addr[2],
293fda93d92SStephen Hemminger 		   &new_addr[3], &new_addr[4], &new_addr[5]) != 6)
294fda93d92SStephen Hemminger 		return -EINVAL;
295fda93d92SStephen Hemminger 
29646acc460SBen Hutchings 	if (!is_link_local_ether_addr(new_addr))
297fda93d92SStephen Hemminger 		return -EINVAL;
298fda93d92SStephen Hemminger 
299f64f9e71SJoe Perches 	if (new_addr[5] == 1 ||		/* 802.3x Pause address */
300f64f9e71SJoe Perches 	    new_addr[5] == 2 ||		/* 802.3ad Slow protocols */
301f64f9e71SJoe Perches 	    new_addr[5] == 3)		/* 802.1X PAE address */
302fda93d92SStephen Hemminger 		return -EINVAL;
303fda93d92SStephen Hemminger 
304204177f3SToshiaki Makita 	if (!rtnl_trylock())
305204177f3SToshiaki Makita 		return restart_syscall();
306204177f3SToshiaki Makita 
307fda93d92SStephen Hemminger 	spin_lock_bh(&br->lock);
308fda93d92SStephen Hemminger 	for (i = 0; i < 6; i++)
309fda93d92SStephen Hemminger 		br->group_addr[i] = new_addr[i];
310fda93d92SStephen Hemminger 	spin_unlock_bh(&br->lock);
311204177f3SToshiaki Makita 
312204177f3SToshiaki Makita 	br->group_addr_set = true;
313204177f3SToshiaki Makita 	br_recalculate_fwd_mask(br);
314047831a9SXin Long 	netdev_state_change(br->dev);
315204177f3SToshiaki Makita 
316204177f3SToshiaki Makita 	rtnl_unlock();
317204177f3SToshiaki Makita 
318fda93d92SStephen Hemminger 	return len;
319fda93d92SStephen Hemminger }
320fda93d92SStephen Hemminger 
321fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(group_addr);
322fda93d92SStephen Hemminger 
32314f31bb3SXin Long static int set_flush(struct net_bridge *br, unsigned long val)
32414f31bb3SXin Long {
32514f31bb3SXin Long 	br_fdb_flush(br);
32614f31bb3SXin Long 	return 0;
32714f31bb3SXin Long }
32814f31bb3SXin Long 
329fbf2671bSsfeldma@cumulusnetworks.com static ssize_t flush_store(struct device *d,
3309cf63747SStephen Hemminger 			   struct device_attribute *attr,
3319cf63747SStephen Hemminger 			   const char *buf, size_t len)
3329cf63747SStephen Hemminger {
33314f31bb3SXin Long 	return store_bridge_parm(d, buf, len, set_flush);
3349cf63747SStephen Hemminger }
335fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_WO(flush);
336fda93d92SStephen Hemminger 
3370909e117SHerbert Xu #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
338fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_router_show(struct device *d,
3390909e117SHerbert Xu 				     struct device_attribute *attr, char *buf)
3400909e117SHerbert Xu {
3410909e117SHerbert Xu 	struct net_bridge *br = to_bridge(d);
3420909e117SHerbert Xu 	return sprintf(buf, "%d\n", br->multicast_router);
3430909e117SHerbert Xu }
3440909e117SHerbert Xu 
345fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_router_store(struct device *d,
3460909e117SHerbert Xu 				      struct device_attribute *attr,
3470909e117SHerbert Xu 				      const char *buf, size_t len)
3480909e117SHerbert Xu {
3490909e117SHerbert Xu 	return store_bridge_parm(d, buf, len, br_multicast_set_router);
3500909e117SHerbert Xu }
351fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(multicast_router);
352561f1103SHerbert Xu 
353fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_snooping_show(struct device *d,
354561f1103SHerbert Xu 				       struct device_attribute *attr,
355561f1103SHerbert Xu 				       char *buf)
356561f1103SHerbert Xu {
357561f1103SHerbert Xu 	struct net_bridge *br = to_bridge(d);
358561f1103SHerbert Xu 	return sprintf(buf, "%d\n", !br->multicast_disabled);
359561f1103SHerbert Xu }
360561f1103SHerbert Xu 
361fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_snooping_store(struct device *d,
362561f1103SHerbert Xu 					struct device_attribute *attr,
363561f1103SHerbert Xu 					const char *buf, size_t len)
364561f1103SHerbert Xu {
365561f1103SHerbert Xu 	return store_bridge_parm(d, buf, len, br_multicast_toggle);
366561f1103SHerbert Xu }
367fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(multicast_snooping);
368b195167fSHerbert Xu 
369fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_query_use_ifaddr_show(struct device *d,
3701c8ad5bfSCong Wang 					       struct device_attribute *attr,
3711c8ad5bfSCong Wang 					       char *buf)
3721c8ad5bfSCong Wang {
3731c8ad5bfSCong Wang 	struct net_bridge *br = to_bridge(d);
3741c8ad5bfSCong Wang 	return sprintf(buf, "%d\n", br->multicast_query_use_ifaddr);
3751c8ad5bfSCong Wang }
3761c8ad5bfSCong Wang 
3771c8ad5bfSCong Wang static int set_query_use_ifaddr(struct net_bridge *br, unsigned long val)
3781c8ad5bfSCong Wang {
3791c8ad5bfSCong Wang 	br->multicast_query_use_ifaddr = !!val;
3801c8ad5bfSCong Wang 	return 0;
3811c8ad5bfSCong Wang }
3821c8ad5bfSCong Wang 
3831c8ad5bfSCong Wang static ssize_t
384fbf2671bSsfeldma@cumulusnetworks.com multicast_query_use_ifaddr_store(struct device *d,
3851c8ad5bfSCong Wang 				 struct device_attribute *attr,
3861c8ad5bfSCong Wang 				 const char *buf, size_t len)
3871c8ad5bfSCong Wang {
3881c8ad5bfSCong Wang 	return store_bridge_parm(d, buf, len, set_query_use_ifaddr);
3891c8ad5bfSCong Wang }
390fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(multicast_query_use_ifaddr);
3911c8ad5bfSCong Wang 
392fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_querier_show(struct device *d,
393c5c23260SHerbert Xu 				      struct device_attribute *attr,
394c5c23260SHerbert Xu 				      char *buf)
395c5c23260SHerbert Xu {
396c5c23260SHerbert Xu 	struct net_bridge *br = to_bridge(d);
397c5c23260SHerbert Xu 	return sprintf(buf, "%d\n", br->multicast_querier);
398c5c23260SHerbert Xu }
399c5c23260SHerbert Xu 
400fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_querier_store(struct device *d,
401c5c23260SHerbert Xu 				       struct device_attribute *attr,
402c5c23260SHerbert Xu 				       const char *buf, size_t len)
403c5c23260SHerbert Xu {
404c5c23260SHerbert Xu 	return store_bridge_parm(d, buf, len, br_multicast_set_querier);
405c5c23260SHerbert Xu }
406fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(multicast_querier);
407c5c23260SHerbert Xu 
408fbf2671bSsfeldma@cumulusnetworks.com static ssize_t hash_elasticity_show(struct device *d,
409b195167fSHerbert Xu 				    struct device_attribute *attr, char *buf)
410b195167fSHerbert Xu {
411b195167fSHerbert Xu 	struct net_bridge *br = to_bridge(d);
412b195167fSHerbert Xu 	return sprintf(buf, "%u\n", br->hash_elasticity);
413b195167fSHerbert Xu }
414b195167fSHerbert Xu 
415b195167fSHerbert Xu static int set_elasticity(struct net_bridge *br, unsigned long val)
416b195167fSHerbert Xu {
417b195167fSHerbert Xu 	br->hash_elasticity = val;
418b195167fSHerbert Xu 	return 0;
419b195167fSHerbert Xu }
420b195167fSHerbert Xu 
421fbf2671bSsfeldma@cumulusnetworks.com static ssize_t hash_elasticity_store(struct device *d,
422b195167fSHerbert Xu 				     struct device_attribute *attr,
423b195167fSHerbert Xu 				     const char *buf, size_t len)
424b195167fSHerbert Xu {
425b195167fSHerbert Xu 	return store_bridge_parm(d, buf, len, set_elasticity);
426b195167fSHerbert Xu }
427fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(hash_elasticity);
428b195167fSHerbert Xu 
429fbf2671bSsfeldma@cumulusnetworks.com static ssize_t hash_max_show(struct device *d, struct device_attribute *attr,
430b195167fSHerbert Xu 			     char *buf)
431b195167fSHerbert Xu {
432b195167fSHerbert Xu 	struct net_bridge *br = to_bridge(d);
433b195167fSHerbert Xu 	return sprintf(buf, "%u\n", br->hash_max);
434b195167fSHerbert Xu }
435b195167fSHerbert Xu 
436fbf2671bSsfeldma@cumulusnetworks.com static ssize_t hash_max_store(struct device *d, struct device_attribute *attr,
437b195167fSHerbert Xu 			      const char *buf, size_t len)
438b195167fSHerbert Xu {
439b195167fSHerbert Xu 	return store_bridge_parm(d, buf, len, br_multicast_set_hash_max);
440b195167fSHerbert Xu }
441fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(hash_max);
442d902eee4SHerbert Xu 
443fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_last_member_count_show(struct device *d,
444d902eee4SHerbert Xu 						struct device_attribute *attr,
445d902eee4SHerbert Xu 						char *buf)
446d902eee4SHerbert Xu {
447d902eee4SHerbert Xu 	struct net_bridge *br = to_bridge(d);
448d902eee4SHerbert Xu 	return sprintf(buf, "%u\n", br->multicast_last_member_count);
449d902eee4SHerbert Xu }
450d902eee4SHerbert Xu 
451d902eee4SHerbert Xu static int set_last_member_count(struct net_bridge *br, unsigned long val)
452d902eee4SHerbert Xu {
453d902eee4SHerbert Xu 	br->multicast_last_member_count = val;
454d902eee4SHerbert Xu 	return 0;
455d902eee4SHerbert Xu }
456d902eee4SHerbert Xu 
457fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_last_member_count_store(struct device *d,
458d902eee4SHerbert Xu 						 struct device_attribute *attr,
459d902eee4SHerbert Xu 						 const char *buf, size_t len)
460d902eee4SHerbert Xu {
461d902eee4SHerbert Xu 	return store_bridge_parm(d, buf, len, set_last_member_count);
462d902eee4SHerbert Xu }
463fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(multicast_last_member_count);
464d902eee4SHerbert Xu 
465fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_startup_query_count_show(
466d902eee4SHerbert Xu 	struct device *d, struct device_attribute *attr, char *buf)
467d902eee4SHerbert Xu {
468d902eee4SHerbert Xu 	struct net_bridge *br = to_bridge(d);
469d902eee4SHerbert Xu 	return sprintf(buf, "%u\n", br->multicast_startup_query_count);
470d902eee4SHerbert Xu }
471d902eee4SHerbert Xu 
472d902eee4SHerbert Xu static int set_startup_query_count(struct net_bridge *br, unsigned long val)
473d902eee4SHerbert Xu {
474d902eee4SHerbert Xu 	br->multicast_startup_query_count = val;
475d902eee4SHerbert Xu 	return 0;
476d902eee4SHerbert Xu }
477d902eee4SHerbert Xu 
478fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_startup_query_count_store(
479d902eee4SHerbert Xu 	struct device *d, struct device_attribute *attr, const char *buf,
480d902eee4SHerbert Xu 	size_t len)
481d902eee4SHerbert Xu {
482d902eee4SHerbert Xu 	return store_bridge_parm(d, buf, len, set_startup_query_count);
483d902eee4SHerbert Xu }
484fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(multicast_startup_query_count);
485d902eee4SHerbert Xu 
486fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_last_member_interval_show(
487d902eee4SHerbert Xu 	struct device *d, struct device_attribute *attr, char *buf)
488d902eee4SHerbert Xu {
489d902eee4SHerbert Xu 	struct net_bridge *br = to_bridge(d);
490d902eee4SHerbert Xu 	return sprintf(buf, "%lu\n",
491d902eee4SHerbert Xu 		       jiffies_to_clock_t(br->multicast_last_member_interval));
492d902eee4SHerbert Xu }
493d902eee4SHerbert Xu 
494d902eee4SHerbert Xu static int set_last_member_interval(struct net_bridge *br, unsigned long val)
495d902eee4SHerbert Xu {
496d902eee4SHerbert Xu 	br->multicast_last_member_interval = clock_t_to_jiffies(val);
497d902eee4SHerbert Xu 	return 0;
498d902eee4SHerbert Xu }
499d902eee4SHerbert Xu 
500fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_last_member_interval_store(
501d902eee4SHerbert Xu 	struct device *d, struct device_attribute *attr, const char *buf,
502d902eee4SHerbert Xu 	size_t len)
503d902eee4SHerbert Xu {
504d902eee4SHerbert Xu 	return store_bridge_parm(d, buf, len, set_last_member_interval);
505d902eee4SHerbert Xu }
506fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(multicast_last_member_interval);
507d902eee4SHerbert Xu 
508fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_membership_interval_show(
509d902eee4SHerbert Xu 	struct device *d, struct device_attribute *attr, char *buf)
510d902eee4SHerbert Xu {
511d902eee4SHerbert Xu 	struct net_bridge *br = to_bridge(d);
512d902eee4SHerbert Xu 	return sprintf(buf, "%lu\n",
513d902eee4SHerbert Xu 		       jiffies_to_clock_t(br->multicast_membership_interval));
514d902eee4SHerbert Xu }
515d902eee4SHerbert Xu 
516d902eee4SHerbert Xu static int set_membership_interval(struct net_bridge *br, unsigned long val)
517d902eee4SHerbert Xu {
518d902eee4SHerbert Xu 	br->multicast_membership_interval = clock_t_to_jiffies(val);
519d902eee4SHerbert Xu 	return 0;
520d902eee4SHerbert Xu }
521d902eee4SHerbert Xu 
522fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_membership_interval_store(
523d902eee4SHerbert Xu 	struct device *d, struct device_attribute *attr, const char *buf,
524d902eee4SHerbert Xu 	size_t len)
525d902eee4SHerbert Xu {
526d902eee4SHerbert Xu 	return store_bridge_parm(d, buf, len, set_membership_interval);
527d902eee4SHerbert Xu }
528fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(multicast_membership_interval);
529d902eee4SHerbert Xu 
530fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_querier_interval_show(struct device *d,
531d902eee4SHerbert Xu 					       struct device_attribute *attr,
532d902eee4SHerbert Xu 					       char *buf)
533d902eee4SHerbert Xu {
534d902eee4SHerbert Xu 	struct net_bridge *br = to_bridge(d);
535d902eee4SHerbert Xu 	return sprintf(buf, "%lu\n",
536d902eee4SHerbert Xu 		       jiffies_to_clock_t(br->multicast_querier_interval));
537d902eee4SHerbert Xu }
538d902eee4SHerbert Xu 
539d902eee4SHerbert Xu static int set_querier_interval(struct net_bridge *br, unsigned long val)
540d902eee4SHerbert Xu {
541d902eee4SHerbert Xu 	br->multicast_querier_interval = clock_t_to_jiffies(val);
542d902eee4SHerbert Xu 	return 0;
543d902eee4SHerbert Xu }
544d902eee4SHerbert Xu 
545fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_querier_interval_store(struct device *d,
546d902eee4SHerbert Xu 						struct device_attribute *attr,
547d902eee4SHerbert Xu 						const char *buf, size_t len)
548d902eee4SHerbert Xu {
549d902eee4SHerbert Xu 	return store_bridge_parm(d, buf, len, set_querier_interval);
550d902eee4SHerbert Xu }
551fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(multicast_querier_interval);
552d902eee4SHerbert Xu 
553fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_query_interval_show(struct device *d,
554d902eee4SHerbert Xu 					     struct device_attribute *attr,
555d902eee4SHerbert Xu 					     char *buf)
556d902eee4SHerbert Xu {
557d902eee4SHerbert Xu 	struct net_bridge *br = to_bridge(d);
558d902eee4SHerbert Xu 	return sprintf(buf, "%lu\n",
559d902eee4SHerbert Xu 		       jiffies_to_clock_t(br->multicast_query_interval));
560d902eee4SHerbert Xu }
561d902eee4SHerbert Xu 
562d902eee4SHerbert Xu static int set_query_interval(struct net_bridge *br, unsigned long val)
563d902eee4SHerbert Xu {
564d902eee4SHerbert Xu 	br->multicast_query_interval = clock_t_to_jiffies(val);
565d902eee4SHerbert Xu 	return 0;
566d902eee4SHerbert Xu }
567d902eee4SHerbert Xu 
568fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_query_interval_store(struct device *d,
569d902eee4SHerbert Xu 					      struct device_attribute *attr,
570d902eee4SHerbert Xu 					      const char *buf, size_t len)
571d902eee4SHerbert Xu {
572d902eee4SHerbert Xu 	return store_bridge_parm(d, buf, len, set_query_interval);
573d902eee4SHerbert Xu }
574fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(multicast_query_interval);
575d902eee4SHerbert Xu 
576fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_query_response_interval_show(
577d902eee4SHerbert Xu 	struct device *d, struct device_attribute *attr, char *buf)
578d902eee4SHerbert Xu {
579d902eee4SHerbert Xu 	struct net_bridge *br = to_bridge(d);
580d902eee4SHerbert Xu 	return sprintf(
581d902eee4SHerbert Xu 		buf, "%lu\n",
582d902eee4SHerbert Xu 		jiffies_to_clock_t(br->multicast_query_response_interval));
583d902eee4SHerbert Xu }
584d902eee4SHerbert Xu 
585d902eee4SHerbert Xu static int set_query_response_interval(struct net_bridge *br, unsigned long val)
586d902eee4SHerbert Xu {
587d902eee4SHerbert Xu 	br->multicast_query_response_interval = clock_t_to_jiffies(val);
588d902eee4SHerbert Xu 	return 0;
589d902eee4SHerbert Xu }
590d902eee4SHerbert Xu 
591fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_query_response_interval_store(
592d902eee4SHerbert Xu 	struct device *d, struct device_attribute *attr, const char *buf,
593d902eee4SHerbert Xu 	size_t len)
594d902eee4SHerbert Xu {
595d902eee4SHerbert Xu 	return store_bridge_parm(d, buf, len, set_query_response_interval);
596d902eee4SHerbert Xu }
597fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(multicast_query_response_interval);
598d902eee4SHerbert Xu 
599fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_startup_query_interval_show(
600d902eee4SHerbert Xu 	struct device *d, struct device_attribute *attr, char *buf)
601d902eee4SHerbert Xu {
602d902eee4SHerbert Xu 	struct net_bridge *br = to_bridge(d);
603d902eee4SHerbert Xu 	return sprintf(
604d902eee4SHerbert Xu 		buf, "%lu\n",
605d902eee4SHerbert Xu 		jiffies_to_clock_t(br->multicast_startup_query_interval));
606d902eee4SHerbert Xu }
607d902eee4SHerbert Xu 
608d902eee4SHerbert Xu static int set_startup_query_interval(struct net_bridge *br, unsigned long val)
609d902eee4SHerbert Xu {
610d902eee4SHerbert Xu 	br->multicast_startup_query_interval = clock_t_to_jiffies(val);
611d902eee4SHerbert Xu 	return 0;
612d902eee4SHerbert Xu }
613d902eee4SHerbert Xu 
614fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_startup_query_interval_store(
615d902eee4SHerbert Xu 	struct device *d, struct device_attribute *attr, const char *buf,
616d902eee4SHerbert Xu 	size_t len)
617d902eee4SHerbert Xu {
618d902eee4SHerbert Xu 	return store_bridge_parm(d, buf, len, set_startup_query_interval);
619d902eee4SHerbert Xu }
620fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(multicast_startup_query_interval);
621*1080ab95SNikolay Aleksandrov 
622*1080ab95SNikolay Aleksandrov static ssize_t multicast_stats_enabled_show(struct device *d,
623*1080ab95SNikolay Aleksandrov 					    struct device_attribute *attr,
624*1080ab95SNikolay Aleksandrov 					    char *buf)
625*1080ab95SNikolay Aleksandrov {
626*1080ab95SNikolay Aleksandrov 	struct net_bridge *br = to_bridge(d);
627*1080ab95SNikolay Aleksandrov 
628*1080ab95SNikolay Aleksandrov 	return sprintf(buf, "%u\n", br->multicast_stats_enabled);
629*1080ab95SNikolay Aleksandrov }
630*1080ab95SNikolay Aleksandrov 
631*1080ab95SNikolay Aleksandrov static int set_stats_enabled(struct net_bridge *br, unsigned long val)
632*1080ab95SNikolay Aleksandrov {
633*1080ab95SNikolay Aleksandrov 	br->multicast_stats_enabled = !!val;
634*1080ab95SNikolay Aleksandrov 	return 0;
635*1080ab95SNikolay Aleksandrov }
636*1080ab95SNikolay Aleksandrov 
637*1080ab95SNikolay Aleksandrov static ssize_t multicast_stats_enabled_store(struct device *d,
638*1080ab95SNikolay Aleksandrov 					     struct device_attribute *attr,
639*1080ab95SNikolay Aleksandrov 					     const char *buf,
640*1080ab95SNikolay Aleksandrov 					     size_t len)
641*1080ab95SNikolay Aleksandrov {
642*1080ab95SNikolay Aleksandrov 	return store_bridge_parm(d, buf, len, set_stats_enabled);
643*1080ab95SNikolay Aleksandrov }
644*1080ab95SNikolay Aleksandrov static DEVICE_ATTR_RW(multicast_stats_enabled);
6450909e117SHerbert Xu #endif
64634666d46SPablo Neira Ayuso #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
647fbf2671bSsfeldma@cumulusnetworks.com static ssize_t nf_call_iptables_show(
6484df53d8bSPatrick McHardy 	struct device *d, struct device_attribute *attr, char *buf)
6494df53d8bSPatrick McHardy {
6504df53d8bSPatrick McHardy 	struct net_bridge *br = to_bridge(d);
6514df53d8bSPatrick McHardy 	return sprintf(buf, "%u\n", br->nf_call_iptables);
6524df53d8bSPatrick McHardy }
6534df53d8bSPatrick McHardy 
6544df53d8bSPatrick McHardy static int set_nf_call_iptables(struct net_bridge *br, unsigned long val)
6554df53d8bSPatrick McHardy {
6564df53d8bSPatrick McHardy 	br->nf_call_iptables = val ? true : false;
6574df53d8bSPatrick McHardy 	return 0;
6584df53d8bSPatrick McHardy }
6594df53d8bSPatrick McHardy 
660fbf2671bSsfeldma@cumulusnetworks.com static ssize_t nf_call_iptables_store(
6614df53d8bSPatrick McHardy 	struct device *d, struct device_attribute *attr, const char *buf,
6624df53d8bSPatrick McHardy 	size_t len)
6634df53d8bSPatrick McHardy {
6644df53d8bSPatrick McHardy 	return store_bridge_parm(d, buf, len, set_nf_call_iptables);
6654df53d8bSPatrick McHardy }
666fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(nf_call_iptables);
6674df53d8bSPatrick McHardy 
668fbf2671bSsfeldma@cumulusnetworks.com static ssize_t nf_call_ip6tables_show(
6694df53d8bSPatrick McHardy 	struct device *d, struct device_attribute *attr, char *buf)
6704df53d8bSPatrick McHardy {
6714df53d8bSPatrick McHardy 	struct net_bridge *br = to_bridge(d);
6724df53d8bSPatrick McHardy 	return sprintf(buf, "%u\n", br->nf_call_ip6tables);
6734df53d8bSPatrick McHardy }
6744df53d8bSPatrick McHardy 
6754df53d8bSPatrick McHardy static int set_nf_call_ip6tables(struct net_bridge *br, unsigned long val)
6764df53d8bSPatrick McHardy {
6774df53d8bSPatrick McHardy 	br->nf_call_ip6tables = val ? true : false;
6784df53d8bSPatrick McHardy 	return 0;
6794df53d8bSPatrick McHardy }
6804df53d8bSPatrick McHardy 
681fbf2671bSsfeldma@cumulusnetworks.com static ssize_t nf_call_ip6tables_store(
6824df53d8bSPatrick McHardy 	struct device *d, struct device_attribute *attr, const char *buf,
6834df53d8bSPatrick McHardy 	size_t len)
6844df53d8bSPatrick McHardy {
6854df53d8bSPatrick McHardy 	return store_bridge_parm(d, buf, len, set_nf_call_ip6tables);
6864df53d8bSPatrick McHardy }
687fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(nf_call_ip6tables);
6884df53d8bSPatrick McHardy 
689fbf2671bSsfeldma@cumulusnetworks.com static ssize_t nf_call_arptables_show(
6904df53d8bSPatrick McHardy 	struct device *d, struct device_attribute *attr, char *buf)
6914df53d8bSPatrick McHardy {
6924df53d8bSPatrick McHardy 	struct net_bridge *br = to_bridge(d);
6934df53d8bSPatrick McHardy 	return sprintf(buf, "%u\n", br->nf_call_arptables);
6944df53d8bSPatrick McHardy }
6954df53d8bSPatrick McHardy 
6964df53d8bSPatrick McHardy static int set_nf_call_arptables(struct net_bridge *br, unsigned long val)
6974df53d8bSPatrick McHardy {
6984df53d8bSPatrick McHardy 	br->nf_call_arptables = val ? true : false;
6994df53d8bSPatrick McHardy 	return 0;
7004df53d8bSPatrick McHardy }
7014df53d8bSPatrick McHardy 
702fbf2671bSsfeldma@cumulusnetworks.com static ssize_t nf_call_arptables_store(
7034df53d8bSPatrick McHardy 	struct device *d, struct device_attribute *attr, const char *buf,
7044df53d8bSPatrick McHardy 	size_t len)
7054df53d8bSPatrick McHardy {
7064df53d8bSPatrick McHardy 	return store_bridge_parm(d, buf, len, set_nf_call_arptables);
7074df53d8bSPatrick McHardy }
708fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(nf_call_arptables);
7094df53d8bSPatrick McHardy #endif
710243a2e63SVlad Yasevich #ifdef CONFIG_BRIDGE_VLAN_FILTERING
711fbf2671bSsfeldma@cumulusnetworks.com static ssize_t vlan_filtering_show(struct device *d,
712243a2e63SVlad Yasevich 				   struct device_attribute *attr,
713243a2e63SVlad Yasevich 				   char *buf)
714243a2e63SVlad Yasevich {
715243a2e63SVlad Yasevich 	struct net_bridge *br = to_bridge(d);
716243a2e63SVlad Yasevich 	return sprintf(buf, "%d\n", br->vlan_enabled);
717243a2e63SVlad Yasevich }
718243a2e63SVlad Yasevich 
719fbf2671bSsfeldma@cumulusnetworks.com static ssize_t vlan_filtering_store(struct device *d,
720243a2e63SVlad Yasevich 				    struct device_attribute *attr,
721243a2e63SVlad Yasevich 				    const char *buf, size_t len)
722243a2e63SVlad Yasevich {
723243a2e63SVlad Yasevich 	return store_bridge_parm(d, buf, len, br_vlan_filter_toggle);
724243a2e63SVlad Yasevich }
725fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(vlan_filtering);
726204177f3SToshiaki Makita 
727204177f3SToshiaki Makita static ssize_t vlan_protocol_show(struct device *d,
728204177f3SToshiaki Makita 				  struct device_attribute *attr,
729204177f3SToshiaki Makita 				  char *buf)
730204177f3SToshiaki Makita {
731204177f3SToshiaki Makita 	struct net_bridge *br = to_bridge(d);
732204177f3SToshiaki Makita 	return sprintf(buf, "%#06x\n", ntohs(br->vlan_proto));
733204177f3SToshiaki Makita }
734204177f3SToshiaki Makita 
735204177f3SToshiaki Makita static ssize_t vlan_protocol_store(struct device *d,
736204177f3SToshiaki Makita 				   struct device_attribute *attr,
737204177f3SToshiaki Makita 				   const char *buf, size_t len)
738204177f3SToshiaki Makita {
739204177f3SToshiaki Makita 	return store_bridge_parm(d, buf, len, br_vlan_set_proto);
740204177f3SToshiaki Makita }
741204177f3SToshiaki Makita static DEVICE_ATTR_RW(vlan_protocol);
74296a20d9dSVlad Yasevich 
74396a20d9dSVlad Yasevich static ssize_t default_pvid_show(struct device *d,
74496a20d9dSVlad Yasevich 				 struct device_attribute *attr,
74596a20d9dSVlad Yasevich 				 char *buf)
74696a20d9dSVlad Yasevich {
74796a20d9dSVlad Yasevich 	struct net_bridge *br = to_bridge(d);
74896a20d9dSVlad Yasevich 	return sprintf(buf, "%d\n", br->default_pvid);
74996a20d9dSVlad Yasevich }
75096a20d9dSVlad Yasevich 
75196a20d9dSVlad Yasevich static ssize_t default_pvid_store(struct device *d,
75296a20d9dSVlad Yasevich 				  struct device_attribute *attr,
75396a20d9dSVlad Yasevich 				  const char *buf, size_t len)
75496a20d9dSVlad Yasevich {
75596a20d9dSVlad Yasevich 	return store_bridge_parm(d, buf, len, br_vlan_set_default_pvid);
75696a20d9dSVlad Yasevich }
75796a20d9dSVlad Yasevich static DEVICE_ATTR_RW(default_pvid);
7586dada9b1SNikolay Aleksandrov 
7596dada9b1SNikolay Aleksandrov static ssize_t vlan_stats_enabled_show(struct device *d,
7606dada9b1SNikolay Aleksandrov 				       struct device_attribute *attr,
7616dada9b1SNikolay Aleksandrov 				       char *buf)
7626dada9b1SNikolay Aleksandrov {
7636dada9b1SNikolay Aleksandrov 	struct net_bridge *br = to_bridge(d);
7646dada9b1SNikolay Aleksandrov 	return sprintf(buf, "%u\n", br->vlan_stats_enabled);
7656dada9b1SNikolay Aleksandrov }
7666dada9b1SNikolay Aleksandrov 
7676dada9b1SNikolay Aleksandrov static ssize_t vlan_stats_enabled_store(struct device *d,
7686dada9b1SNikolay Aleksandrov 					struct device_attribute *attr,
7696dada9b1SNikolay Aleksandrov 					const char *buf, size_t len)
7706dada9b1SNikolay Aleksandrov {
7716dada9b1SNikolay Aleksandrov 	return store_bridge_parm(d, buf, len, br_vlan_set_stats);
7726dada9b1SNikolay Aleksandrov }
7736dada9b1SNikolay Aleksandrov static DEVICE_ATTR_RW(vlan_stats_enabled);
774243a2e63SVlad Yasevich #endif
7750909e117SHerbert Xu 
7761da177e4SLinus Torvalds static struct attribute *bridge_attrs[] = {
77743cb76d9SGreg Kroah-Hartman 	&dev_attr_forward_delay.attr,
77843cb76d9SGreg Kroah-Hartman 	&dev_attr_hello_time.attr,
77943cb76d9SGreg Kroah-Hartman 	&dev_attr_max_age.attr,
78043cb76d9SGreg Kroah-Hartman 	&dev_attr_ageing_time.attr,
78143cb76d9SGreg Kroah-Hartman 	&dev_attr_stp_state.attr,
782515853ccSstephen hemminger 	&dev_attr_group_fwd_mask.attr,
78343cb76d9SGreg Kroah-Hartman 	&dev_attr_priority.attr,
78443cb76d9SGreg Kroah-Hartman 	&dev_attr_bridge_id.attr,
78543cb76d9SGreg Kroah-Hartman 	&dev_attr_root_id.attr,
78643cb76d9SGreg Kroah-Hartman 	&dev_attr_root_path_cost.attr,
78743cb76d9SGreg Kroah-Hartman 	&dev_attr_root_port.attr,
78843cb76d9SGreg Kroah-Hartman 	&dev_attr_topology_change.attr,
78943cb76d9SGreg Kroah-Hartman 	&dev_attr_topology_change_detected.attr,
79043cb76d9SGreg Kroah-Hartman 	&dev_attr_hello_timer.attr,
79143cb76d9SGreg Kroah-Hartman 	&dev_attr_tcn_timer.attr,
79243cb76d9SGreg Kroah-Hartman 	&dev_attr_topology_change_timer.attr,
79343cb76d9SGreg Kroah-Hartman 	&dev_attr_gc_timer.attr,
79443cb76d9SGreg Kroah-Hartman 	&dev_attr_group_addr.attr,
7959cf63747SStephen Hemminger 	&dev_attr_flush.attr,
7960909e117SHerbert Xu #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
7970909e117SHerbert Xu 	&dev_attr_multicast_router.attr,
798561f1103SHerbert Xu 	&dev_attr_multicast_snooping.attr,
799c5c23260SHerbert Xu 	&dev_attr_multicast_querier.attr,
8001c8ad5bfSCong Wang 	&dev_attr_multicast_query_use_ifaddr.attr,
801b195167fSHerbert Xu 	&dev_attr_hash_elasticity.attr,
802b195167fSHerbert Xu 	&dev_attr_hash_max.attr,
803d902eee4SHerbert Xu 	&dev_attr_multicast_last_member_count.attr,
804d902eee4SHerbert Xu 	&dev_attr_multicast_startup_query_count.attr,
805d902eee4SHerbert Xu 	&dev_attr_multicast_last_member_interval.attr,
806d902eee4SHerbert Xu 	&dev_attr_multicast_membership_interval.attr,
807d902eee4SHerbert Xu 	&dev_attr_multicast_querier_interval.attr,
808d902eee4SHerbert Xu 	&dev_attr_multicast_query_interval.attr,
809d902eee4SHerbert Xu 	&dev_attr_multicast_query_response_interval.attr,
810d902eee4SHerbert Xu 	&dev_attr_multicast_startup_query_interval.attr,
811*1080ab95SNikolay Aleksandrov 	&dev_attr_multicast_stats_enabled.attr,
8120909e117SHerbert Xu #endif
81334666d46SPablo Neira Ayuso #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
8144df53d8bSPatrick McHardy 	&dev_attr_nf_call_iptables.attr,
8154df53d8bSPatrick McHardy 	&dev_attr_nf_call_ip6tables.attr,
8164df53d8bSPatrick McHardy 	&dev_attr_nf_call_arptables.attr,
8174df53d8bSPatrick McHardy #endif
818243a2e63SVlad Yasevich #ifdef CONFIG_BRIDGE_VLAN_FILTERING
819243a2e63SVlad Yasevich 	&dev_attr_vlan_filtering.attr,
820204177f3SToshiaki Makita 	&dev_attr_vlan_protocol.attr,
82196a20d9dSVlad Yasevich 	&dev_attr_default_pvid.attr,
8226dada9b1SNikolay Aleksandrov 	&dev_attr_vlan_stats_enabled.attr,
823243a2e63SVlad Yasevich #endif
8241da177e4SLinus Torvalds 	NULL
8251da177e4SLinus Torvalds };
8261da177e4SLinus Torvalds 
8271da177e4SLinus Torvalds static struct attribute_group bridge_group = {
8281da177e4SLinus Torvalds 	.name = SYSFS_BRIDGE_ATTR,
8291da177e4SLinus Torvalds 	.attrs = bridge_attrs,
8301da177e4SLinus Torvalds };
8311da177e4SLinus Torvalds 
8321da177e4SLinus Torvalds /*
8331da177e4SLinus Torvalds  * Export the forwarding information table as a binary file
8341da177e4SLinus Torvalds  * The records are struct __fdb_entry.
8351da177e4SLinus Torvalds  *
8361da177e4SLinus Torvalds  * Returns the number of bytes read.
8371da177e4SLinus Torvalds  */
8382c3c8beaSChris Wright static ssize_t brforward_read(struct file *filp, struct kobject *kobj,
83991a69029SZhang Rui 			      struct bin_attribute *bin_attr,
84091a69029SZhang Rui 			      char *buf, loff_t off, size_t count)
8411da177e4SLinus Torvalds {
842aeb7ed14SGeliang Tang 	struct device *dev = kobj_to_dev(kobj);
84343cb76d9SGreg Kroah-Hartman 	struct net_bridge *br = to_bridge(dev);
8441da177e4SLinus Torvalds 	int n;
8451da177e4SLinus Torvalds 
8461da177e4SLinus Torvalds 	/* must read whole records */
8471da177e4SLinus Torvalds 	if (off % sizeof(struct __fdb_entry) != 0)
8481da177e4SLinus Torvalds 		return -EINVAL;
8491da177e4SLinus Torvalds 
8501da177e4SLinus Torvalds 	n =  br_fdb_fillbuf(br, buf,
8511da177e4SLinus Torvalds 			    count / sizeof(struct __fdb_entry),
8521da177e4SLinus Torvalds 			    off / sizeof(struct __fdb_entry));
8531da177e4SLinus Torvalds 
8541da177e4SLinus Torvalds 	if (n > 0)
8551da177e4SLinus Torvalds 		n *= sizeof(struct __fdb_entry);
8561da177e4SLinus Torvalds 
8571da177e4SLinus Torvalds 	return n;
8581da177e4SLinus Torvalds }
8591da177e4SLinus Torvalds 
8601da177e4SLinus Torvalds static struct bin_attribute bridge_forward = {
8611da177e4SLinus Torvalds 	.attr = { .name = SYSFS_BRIDGE_FDB,
8627b595756STejun Heo 		  .mode = S_IRUGO, },
8631da177e4SLinus Torvalds 	.read = brforward_read,
8641da177e4SLinus Torvalds };
8651da177e4SLinus Torvalds 
8661da177e4SLinus Torvalds /*
8671da177e4SLinus Torvalds  * Add entries in sysfs onto the existing network class device
8681da177e4SLinus Torvalds  * for the bridge.
8691da177e4SLinus Torvalds  *   Adds a attribute group "bridge" containing tuning parameters.
8701da177e4SLinus Torvalds  *   Binary attribute containing the forward table
8711da177e4SLinus Torvalds  *   Sub directory to hold links to interfaces.
8721da177e4SLinus Torvalds  *
8731da177e4SLinus Torvalds  * Note: the ifobj exists only to be a subdirectory
8741da177e4SLinus Torvalds  *   to hold links.  The ifobj exists in same data structure
8751da177e4SLinus Torvalds  *   as it's parent the bridge so reference counting works.
8761da177e4SLinus Torvalds  */
8771da177e4SLinus Torvalds int br_sysfs_addbr(struct net_device *dev)
8781da177e4SLinus Torvalds {
87943cb76d9SGreg Kroah-Hartman 	struct kobject *brobj = &dev->dev.kobj;
8801da177e4SLinus Torvalds 	struct net_bridge *br = netdev_priv(dev);
8811da177e4SLinus Torvalds 	int err;
8821da177e4SLinus Torvalds 
8831da177e4SLinus Torvalds 	err = sysfs_create_group(brobj, &bridge_group);
8841da177e4SLinus Torvalds 	if (err) {
8851da177e4SLinus Torvalds 		pr_info("%s: can't create group %s/%s\n",
8860dc47877SHarvey Harrison 			__func__, dev->name, bridge_group.name);
8871da177e4SLinus Torvalds 		goto out1;
8881da177e4SLinus Torvalds 	}
8891da177e4SLinus Torvalds 
8901da177e4SLinus Torvalds 	err = sysfs_create_bin_file(brobj, &bridge_forward);
8911da177e4SLinus Torvalds 	if (err) {
8921842c4beSRandy Dunlap 		pr_info("%s: can't create attribute file %s/%s\n",
8930dc47877SHarvey Harrison 			__func__, dev->name, bridge_forward.attr.name);
8941da177e4SLinus Torvalds 		goto out2;
8951da177e4SLinus Torvalds 	}
8961da177e4SLinus Torvalds 
89743b98c4aSGreg Kroah-Hartman 	br->ifobj = kobject_create_and_add(SYSFS_BRIDGE_PORT_SUBDIR, brobj);
89843b98c4aSGreg Kroah-Hartman 	if (!br->ifobj) {
8991da177e4SLinus Torvalds 		pr_info("%s: can't add kobject (directory) %s/%s\n",
9000dc47877SHarvey Harrison 			__func__, dev->name, SYSFS_BRIDGE_PORT_SUBDIR);
9011da177e4SLinus Torvalds 		goto out3;
9021da177e4SLinus Torvalds 	}
9031da177e4SLinus Torvalds 	return 0;
9041da177e4SLinus Torvalds  out3:
90543cb76d9SGreg Kroah-Hartman 	sysfs_remove_bin_file(&dev->dev.kobj, &bridge_forward);
9061da177e4SLinus Torvalds  out2:
90743cb76d9SGreg Kroah-Hartman 	sysfs_remove_group(&dev->dev.kobj, &bridge_group);
9081da177e4SLinus Torvalds  out1:
9091da177e4SLinus Torvalds 	return err;
9101da177e4SLinus Torvalds 
9111da177e4SLinus Torvalds }
9121da177e4SLinus Torvalds 
9131da177e4SLinus Torvalds void br_sysfs_delbr(struct net_device *dev)
9141da177e4SLinus Torvalds {
91543cb76d9SGreg Kroah-Hartman 	struct kobject *kobj = &dev->dev.kobj;
9161da177e4SLinus Torvalds 	struct net_bridge *br = netdev_priv(dev);
9171da177e4SLinus Torvalds 
91878a2d906SGreg Kroah-Hartman 	kobject_put(br->ifobj);
9191da177e4SLinus Torvalds 	sysfs_remove_bin_file(kobj, &bridge_forward);
9201da177e4SLinus Torvalds 	sysfs_remove_group(kobj, &bridge_group);
9211da177e4SLinus Torvalds }
922