blob: e120307c6e36ab1173232ee1d4fb1730f5dbae60 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Wang Sheng-Hui15401942013-08-06 08:44:46 +08002 * Sysfs attributes of bridge
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 * Linux ethernet bridge
4 *
5 * Authors:
6 * Stephen Hemminger <shemminger@osdl.org>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version
11 * 2 of the License, or (at your option) any later version.
12 */
13
Randy Dunlap4fc268d2006-01-11 12:17:47 -080014#include <linux/capability.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/kernel.h>
16#include <linux/netdevice.h>
John Fastabendb3343a22012-09-18 00:01:12 +000017#include <linux/etherdevice.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <linux/if_bridge.h>
19#include <linux/rtnetlink.h>
20#include <linux/spinlock.h>
21#include <linux/times.h>
22
23#include "br_private.h"
24
Wang Chen524ad0a2008-11-12 23:39:10 -080025#define to_bridge(cd) ((struct net_bridge *)netdev_priv(to_net_dev(cd)))
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
27/*
28 * Common code for storing bridge parameters.
29 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -070030static ssize_t store_bridge_parm(struct device *d,
Linus Torvalds1da177e2005-04-16 15:20:36 -070031 const char *buf, size_t len,
Stephen Hemminger8d4698f72008-09-08 13:44:40 -070032 int (*set)(struct net_bridge *, unsigned long))
Linus Torvalds1da177e2005-04-16 15:20:36 -070033{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -070034 struct net_bridge *br = to_bridge(d);
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 char *endp;
36 unsigned long val;
Stephen Hemminger8d4698f72008-09-08 13:44:40 -070037 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
Eric W. Biedermancb990502012-11-16 03:03:08 +000039 if (!ns_capable(dev_net(br->dev)->user_ns, CAP_NET_ADMIN))
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 return -EPERM;
41
42 val = simple_strtoul(buf, &endp, 0);
43 if (endp == buf)
44 return -EINVAL;
45
Xin Long047831a2016-04-09 00:03:31 +080046 if (!rtnl_trylock())
47 return restart_syscall();
48
Stephen Hemminger8d4698f72008-09-08 13:44:40 -070049 err = (*set)(br, val);
Xin Long047831a2016-04-09 00:03:31 +080050 if (!err)
51 netdev_state_change(br->dev);
52 rtnl_unlock();
53
Stephen Hemminger8d4698f72008-09-08 13:44:40 -070054 return err ? err : len;
Linus Torvalds1da177e2005-04-16 15:20:36 -070055}
56
57
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -080058static ssize_t forward_delay_show(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -070059 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -070060{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -070061 struct net_bridge *br = to_bridge(d);
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 return sprintf(buf, "%lu\n", jiffies_to_clock_t(br->forward_delay));
63}
64
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -080065static ssize_t forward_delay_store(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -070066 struct device_attribute *attr,
67 const char *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -070068{
stephen hemminger14f98f22011-04-04 14:03:33 +000069 return store_bridge_parm(d, buf, len, br_set_forward_delay);
Linus Torvalds1da177e2005-04-16 15:20:36 -070070}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -080071static DEVICE_ATTR_RW(forward_delay);
Linus Torvalds1da177e2005-04-16 15:20:36 -070072
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -080073static ssize_t hello_time_show(struct device *d, struct device_attribute *attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -070074 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -070075{
76 return sprintf(buf, "%lu\n",
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -070077 jiffies_to_clock_t(to_bridge(d)->hello_time));
Linus Torvalds1da177e2005-04-16 15:20:36 -070078}
79
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -080080static ssize_t hello_time_store(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -070081 struct device_attribute *attr, const char *buf,
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 size_t len)
83{
stephen hemminger14f98f22011-04-04 14:03:33 +000084 return store_bridge_parm(d, buf, len, br_set_hello_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -070085}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -080086static DEVICE_ATTR_RW(hello_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -080088static ssize_t max_age_show(struct device *d, struct device_attribute *attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -070089 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -070090{
91 return sprintf(buf, "%lu\n",
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -070092 jiffies_to_clock_t(to_bridge(d)->max_age));
Linus Torvalds1da177e2005-04-16 15:20:36 -070093}
94
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -080095static ssize_t max_age_store(struct device *d, struct device_attribute *attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -070096 const char *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -070097{
stephen hemminger14f98f22011-04-04 14:03:33 +000098 return store_bridge_parm(d, buf, len, br_set_max_age);
Linus Torvalds1da177e2005-04-16 15:20:36 -070099}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800100static DEVICE_ATTR_RW(max_age);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800102static ssize_t ageing_time_show(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700103 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700105 struct net_bridge *br = to_bridge(d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 return sprintf(buf, "%lu\n", jiffies_to_clock_t(br->ageing_time));
107}
108
Stephen Hemminger8d4698f72008-09-08 13:44:40 -0700109static int set_ageing_time(struct net_bridge *br, unsigned long val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110{
Xin Long047831a2016-04-09 00:03:31 +0800111 return br_set_ageing_time(br, val);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112}
113
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800114static ssize_t ageing_time_store(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700115 struct device_attribute *attr,
116 const char *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700118 return store_bridge_parm(d, buf, len, set_ageing_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800120static DEVICE_ATTR_RW(ageing_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800122static ssize_t stp_state_show(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700123 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700125 struct net_bridge *br = to_bridge(d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 return sprintf(buf, "%d\n", br->stp_enabled);
127}
128
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129
Xin Long44361562016-04-09 00:03:30 +0800130static int set_stp_state(struct net_bridge *br, unsigned long val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131{
Stephen Hemminger17120882007-08-14 13:21:34 -0700132 br_stp_set_enabled(br, val);
Stephen Hemminger17120882007-08-14 13:21:34 -0700133
Xin Long44361562016-04-09 00:03:30 +0800134 return 0;
135}
136
137static ssize_t stp_state_store(struct device *d,
138 struct device_attribute *attr, const char *buf,
139 size_t len)
140{
141 return store_bridge_parm(d, buf, len, set_stp_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800143static DEVICE_ATTR_RW(stp_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800145static ssize_t group_fwd_mask_show(struct device *d,
146 struct device_attribute *attr,
147 char *buf)
stephen hemminger515853c2011-10-03 18:14:46 +0000148{
149 struct net_bridge *br = to_bridge(d);
150 return sprintf(buf, "%#x\n", br->group_fwd_mask);
151}
152
Xin Long347db6b2016-04-09 00:03:29 +0800153static int set_group_fwd_mask(struct net_bridge *br, unsigned long val)
154{
155 if (val & BR_GROUPFWD_RESTRICTED)
156 return -EINVAL;
157
158 br->group_fwd_mask = val;
159
160 return 0;
161}
stephen hemminger515853c2011-10-03 18:14:46 +0000162
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800163static ssize_t group_fwd_mask_store(struct device *d,
164 struct device_attribute *attr,
165 const char *buf,
166 size_t len)
stephen hemminger515853c2011-10-03 18:14:46 +0000167{
Xin Long347db6b2016-04-09 00:03:29 +0800168 return store_bridge_parm(d, buf, len, set_group_fwd_mask);
stephen hemminger515853c2011-10-03 18:14:46 +0000169}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800170static DEVICE_ATTR_RW(group_fwd_mask);
stephen hemminger515853c2011-10-03 18:14:46 +0000171
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800172static ssize_t priority_show(struct device *d, struct device_attribute *attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700173 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700175 struct net_bridge *br = to_bridge(d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 return sprintf(buf, "%d\n",
177 (br->bridge_id.prio[0] << 8) | br->bridge_id.prio[1]);
178}
179
Stephen Hemminger8d4698f72008-09-08 13:44:40 -0700180static int set_priority(struct net_bridge *br, unsigned long val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181{
182 br_stp_set_bridge_priority(br, (u16) val);
Stephen Hemminger8d4698f72008-09-08 13:44:40 -0700183 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184}
185
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800186static ssize_t priority_store(struct device *d, struct device_attribute *attr,
187 const char *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700189 return store_bridge_parm(d, buf, len, set_priority);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800191static DEVICE_ATTR_RW(priority);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800193static ssize_t root_id_show(struct device *d, struct device_attribute *attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700194 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700196 return br_show_bridge_id(buf, &to_bridge(d)->designated_root);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800198static DEVICE_ATTR_RO(root_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800200static ssize_t bridge_id_show(struct device *d, struct device_attribute *attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700201 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700203 return br_show_bridge_id(buf, &to_bridge(d)->bridge_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800205static DEVICE_ATTR_RO(bridge_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800207static ssize_t root_port_show(struct device *d, struct device_attribute *attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700208 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700210 return sprintf(buf, "%d\n", to_bridge(d)->root_port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800212static DEVICE_ATTR_RO(root_port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800214static ssize_t root_path_cost_show(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700215 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700217 return sprintf(buf, "%d\n", to_bridge(d)->root_path_cost);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800219static DEVICE_ATTR_RO(root_path_cost);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800221static ssize_t topology_change_show(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700222 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700224 return sprintf(buf, "%d\n", to_bridge(d)->topology_change);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800226static DEVICE_ATTR_RO(topology_change);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800228static ssize_t topology_change_detected_show(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700229 struct device_attribute *attr,
230 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700232 struct net_bridge *br = to_bridge(d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 return sprintf(buf, "%d\n", br->topology_change_detected);
234}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800235static DEVICE_ATTR_RO(topology_change_detected);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800237static ssize_t hello_timer_show(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700238 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700240 struct net_bridge *br = to_bridge(d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 return sprintf(buf, "%ld\n", br_timer_value(&br->hello_timer));
242}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800243static DEVICE_ATTR_RO(hello_timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800245static ssize_t tcn_timer_show(struct device *d, struct device_attribute *attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700246 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700248 struct net_bridge *br = to_bridge(d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 return sprintf(buf, "%ld\n", br_timer_value(&br->tcn_timer));
250}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800251static DEVICE_ATTR_RO(tcn_timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800253static ssize_t topology_change_timer_show(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700254 struct device_attribute *attr,
255 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700257 struct net_bridge *br = to_bridge(d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 return sprintf(buf, "%ld\n", br_timer_value(&br->topology_change_timer));
259}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800260static DEVICE_ATTR_RO(topology_change_timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800262static ssize_t gc_timer_show(struct device *d, struct device_attribute *attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700263 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700265 struct net_bridge *br = to_bridge(d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 return sprintf(buf, "%ld\n", br_timer_value(&br->gc_timer));
267}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800268static DEVICE_ATTR_RO(gc_timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800270static ssize_t group_addr_show(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700271 struct device_attribute *attr, char *buf)
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800272{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700273 struct net_bridge *br = to_bridge(d);
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800274 return sprintf(buf, "%x:%x:%x:%x:%x:%x\n",
275 br->group_addr[0], br->group_addr[1],
276 br->group_addr[2], br->group_addr[3],
277 br->group_addr[4], br->group_addr[5]);
278}
279
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800280static ssize_t group_addr_store(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700281 struct device_attribute *attr,
282 const char *buf, size_t len)
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800283{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700284 struct net_bridge *br = to_bridge(d);
Ben Hutchings4197f242012-11-01 09:10:04 +0000285 u8 new_addr[6];
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800286 int i;
287
Eric W. Biedermancb990502012-11-16 03:03:08 +0000288 if (!ns_capable(dev_net(br->dev)->user_ns, CAP_NET_ADMIN))
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800289 return -EPERM;
290
Ben Hutchings4197f242012-11-01 09:10:04 +0000291 if (sscanf(buf, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx",
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800292 &new_addr[0], &new_addr[1], &new_addr[2],
293 &new_addr[3], &new_addr[4], &new_addr[5]) != 6)
294 return -EINVAL;
295
Ben Hutchings46acc462012-11-01 09:11:11 +0000296 if (!is_link_local_ether_addr(new_addr))
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800297 return -EINVAL;
298
Joe Perchesf64f9e72009-11-29 16:55:45 -0800299 if (new_addr[5] == 1 || /* 802.3x Pause address */
300 new_addr[5] == 2 || /* 802.3ad Slow protocols */
301 new_addr[5] == 3) /* 802.1X PAE address */
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800302 return -EINVAL;
303
Toshiaki Makita204177f2014-06-10 20:59:25 +0900304 if (!rtnl_trylock())
305 return restart_syscall();
306
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800307 spin_lock_bh(&br->lock);
308 for (i = 0; i < 6; i++)
309 br->group_addr[i] = new_addr[i];
310 spin_unlock_bh(&br->lock);
Toshiaki Makita204177f2014-06-10 20:59:25 +0900311
312 br->group_addr_set = true;
313 br_recalculate_fwd_mask(br);
Xin Long047831a2016-04-09 00:03:31 +0800314 netdev_state_change(br->dev);
Toshiaki Makita204177f2014-06-10 20:59:25 +0900315
316 rtnl_unlock();
317
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800318 return len;
319}
320
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800321static DEVICE_ATTR_RW(group_addr);
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800322
Xin Long14f31bb2016-04-09 00:03:28 +0800323static int set_flush(struct net_bridge *br, unsigned long val)
324{
325 br_fdb_flush(br);
326 return 0;
327}
328
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800329static ssize_t flush_store(struct device *d,
Stephen Hemminger9cf63742007-04-09 12:57:54 -0700330 struct device_attribute *attr,
331 const char *buf, size_t len)
332{
Xin Long14f31bb2016-04-09 00:03:28 +0800333 return store_bridge_parm(d, buf, len, set_flush);
Stephen Hemminger9cf63742007-04-09 12:57:54 -0700334}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800335static DEVICE_ATTR_WO(flush);
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800336
Herbert Xu0909e112010-02-27 19:41:49 +0000337#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800338static ssize_t multicast_router_show(struct device *d,
Herbert Xu0909e112010-02-27 19:41:49 +0000339 struct device_attribute *attr, char *buf)
340{
341 struct net_bridge *br = to_bridge(d);
342 return sprintf(buf, "%d\n", br->multicast_router);
343}
344
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800345static ssize_t multicast_router_store(struct device *d,
Herbert Xu0909e112010-02-27 19:41:49 +0000346 struct device_attribute *attr,
347 const char *buf, size_t len)
348{
349 return store_bridge_parm(d, buf, len, br_multicast_set_router);
350}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800351static DEVICE_ATTR_RW(multicast_router);
Herbert Xu561f1102010-02-27 19:41:50 +0000352
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800353static ssize_t multicast_snooping_show(struct device *d,
Herbert Xu561f1102010-02-27 19:41:50 +0000354 struct device_attribute *attr,
355 char *buf)
356{
357 struct net_bridge *br = to_bridge(d);
358 return sprintf(buf, "%d\n", !br->multicast_disabled);
359}
360
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800361static ssize_t multicast_snooping_store(struct device *d,
Herbert Xu561f1102010-02-27 19:41:50 +0000362 struct device_attribute *attr,
363 const char *buf, size_t len)
364{
365 return store_bridge_parm(d, buf, len, br_multicast_toggle);
366}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800367static DEVICE_ATTR_RW(multicast_snooping);
Herbert Xub1951672010-02-27 19:41:51 +0000368
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800369static ssize_t multicast_query_use_ifaddr_show(struct device *d,
370 struct device_attribute *attr,
371 char *buf)
Cong Wang1c8ad5b2013-05-21 21:52:54 +0000372{
373 struct net_bridge *br = to_bridge(d);
374 return sprintf(buf, "%d\n", br->multicast_query_use_ifaddr);
375}
376
377static int set_query_use_ifaddr(struct net_bridge *br, unsigned long val)
378{
379 br->multicast_query_use_ifaddr = !!val;
380 return 0;
381}
382
383static ssize_t
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800384multicast_query_use_ifaddr_store(struct device *d,
Cong Wang1c8ad5b2013-05-21 21:52:54 +0000385 struct device_attribute *attr,
386 const char *buf, size_t len)
387{
388 return store_bridge_parm(d, buf, len, set_query_use_ifaddr);
389}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800390static DEVICE_ATTR_RW(multicast_query_use_ifaddr);
Cong Wang1c8ad5b2013-05-21 21:52:54 +0000391
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800392static ssize_t multicast_querier_show(struct device *d,
Herbert Xuc5c23262012-04-13 02:37:42 +0000393 struct device_attribute *attr,
394 char *buf)
395{
396 struct net_bridge *br = to_bridge(d);
397 return sprintf(buf, "%d\n", br->multicast_querier);
398}
399
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800400static ssize_t multicast_querier_store(struct device *d,
Herbert Xuc5c23262012-04-13 02:37:42 +0000401 struct device_attribute *attr,
402 const char *buf, size_t len)
403{
404 return store_bridge_parm(d, buf, len, br_multicast_set_querier);
405}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800406static DEVICE_ATTR_RW(multicast_querier);
Herbert Xuc5c23262012-04-13 02:37:42 +0000407
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800408static ssize_t hash_elasticity_show(struct device *d,
Herbert Xub1951672010-02-27 19:41:51 +0000409 struct device_attribute *attr, char *buf)
410{
411 struct net_bridge *br = to_bridge(d);
412 return sprintf(buf, "%u\n", br->hash_elasticity);
413}
414
415static int set_elasticity(struct net_bridge *br, unsigned long val)
416{
417 br->hash_elasticity = val;
418 return 0;
419}
420
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800421static ssize_t hash_elasticity_store(struct device *d,
Herbert Xub1951672010-02-27 19:41:51 +0000422 struct device_attribute *attr,
423 const char *buf, size_t len)
424{
425 return store_bridge_parm(d, buf, len, set_elasticity);
426}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800427static DEVICE_ATTR_RW(hash_elasticity);
Herbert Xub1951672010-02-27 19:41:51 +0000428
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800429static ssize_t hash_max_show(struct device *d, struct device_attribute *attr,
Herbert Xub1951672010-02-27 19:41:51 +0000430 char *buf)
431{
432 struct net_bridge *br = to_bridge(d);
433 return sprintf(buf, "%u\n", br->hash_max);
434}
435
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800436static ssize_t hash_max_store(struct device *d, struct device_attribute *attr,
Herbert Xub1951672010-02-27 19:41:51 +0000437 const char *buf, size_t len)
438{
439 return store_bridge_parm(d, buf, len, br_multicast_set_hash_max);
440}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800441static DEVICE_ATTR_RW(hash_max);
Herbert Xud902eee2010-02-27 19:41:52 +0000442
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800443static ssize_t multicast_last_member_count_show(struct device *d,
Herbert Xud902eee2010-02-27 19:41:52 +0000444 struct device_attribute *attr,
445 char *buf)
446{
447 struct net_bridge *br = to_bridge(d);
448 return sprintf(buf, "%u\n", br->multicast_last_member_count);
449}
450
451static int set_last_member_count(struct net_bridge *br, unsigned long val)
452{
453 br->multicast_last_member_count = val;
454 return 0;
455}
456
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800457static ssize_t multicast_last_member_count_store(struct device *d,
Herbert Xud902eee2010-02-27 19:41:52 +0000458 struct device_attribute *attr,
459 const char *buf, size_t len)
460{
461 return store_bridge_parm(d, buf, len, set_last_member_count);
462}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800463static DEVICE_ATTR_RW(multicast_last_member_count);
Herbert Xud902eee2010-02-27 19:41:52 +0000464
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800465static ssize_t multicast_startup_query_count_show(
Herbert Xud902eee2010-02-27 19:41:52 +0000466 struct device *d, struct device_attribute *attr, char *buf)
467{
468 struct net_bridge *br = to_bridge(d);
469 return sprintf(buf, "%u\n", br->multicast_startup_query_count);
470}
471
472static int set_startup_query_count(struct net_bridge *br, unsigned long val)
473{
474 br->multicast_startup_query_count = val;
475 return 0;
476}
477
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800478static ssize_t multicast_startup_query_count_store(
Herbert Xud902eee2010-02-27 19:41:52 +0000479 struct device *d, struct device_attribute *attr, const char *buf,
480 size_t len)
481{
482 return store_bridge_parm(d, buf, len, set_startup_query_count);
483}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800484static DEVICE_ATTR_RW(multicast_startup_query_count);
Herbert Xud902eee2010-02-27 19:41:52 +0000485
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800486static ssize_t multicast_last_member_interval_show(
Herbert Xud902eee2010-02-27 19:41:52 +0000487 struct device *d, struct device_attribute *attr, char *buf)
488{
489 struct net_bridge *br = to_bridge(d);
490 return sprintf(buf, "%lu\n",
491 jiffies_to_clock_t(br->multicast_last_member_interval));
492}
493
494static int set_last_member_interval(struct net_bridge *br, unsigned long val)
495{
496 br->multicast_last_member_interval = clock_t_to_jiffies(val);
497 return 0;
498}
499
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800500static ssize_t multicast_last_member_interval_store(
Herbert Xud902eee2010-02-27 19:41:52 +0000501 struct device *d, struct device_attribute *attr, const char *buf,
502 size_t len)
503{
504 return store_bridge_parm(d, buf, len, set_last_member_interval);
505}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800506static DEVICE_ATTR_RW(multicast_last_member_interval);
Herbert Xud902eee2010-02-27 19:41:52 +0000507
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800508static ssize_t multicast_membership_interval_show(
Herbert Xud902eee2010-02-27 19:41:52 +0000509 struct device *d, struct device_attribute *attr, char *buf)
510{
511 struct net_bridge *br = to_bridge(d);
512 return sprintf(buf, "%lu\n",
513 jiffies_to_clock_t(br->multicast_membership_interval));
514}
515
516static int set_membership_interval(struct net_bridge *br, unsigned long val)
517{
518 br->multicast_membership_interval = clock_t_to_jiffies(val);
519 return 0;
520}
521
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800522static ssize_t multicast_membership_interval_store(
Herbert Xud902eee2010-02-27 19:41:52 +0000523 struct device *d, struct device_attribute *attr, const char *buf,
524 size_t len)
525{
526 return store_bridge_parm(d, buf, len, set_membership_interval);
527}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800528static DEVICE_ATTR_RW(multicast_membership_interval);
Herbert Xud902eee2010-02-27 19:41:52 +0000529
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800530static ssize_t multicast_querier_interval_show(struct device *d,
Herbert Xud902eee2010-02-27 19:41:52 +0000531 struct device_attribute *attr,
532 char *buf)
533{
534 struct net_bridge *br = to_bridge(d);
535 return sprintf(buf, "%lu\n",
536 jiffies_to_clock_t(br->multicast_querier_interval));
537}
538
539static int set_querier_interval(struct net_bridge *br, unsigned long val)
540{
541 br->multicast_querier_interval = clock_t_to_jiffies(val);
542 return 0;
543}
544
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800545static ssize_t multicast_querier_interval_store(struct device *d,
Herbert Xud902eee2010-02-27 19:41:52 +0000546 struct device_attribute *attr,
547 const char *buf, size_t len)
548{
549 return store_bridge_parm(d, buf, len, set_querier_interval);
550}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800551static DEVICE_ATTR_RW(multicast_querier_interval);
Herbert Xud902eee2010-02-27 19:41:52 +0000552
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800553static ssize_t multicast_query_interval_show(struct device *d,
Herbert Xud902eee2010-02-27 19:41:52 +0000554 struct device_attribute *attr,
555 char *buf)
556{
557 struct net_bridge *br = to_bridge(d);
558 return sprintf(buf, "%lu\n",
559 jiffies_to_clock_t(br->multicast_query_interval));
560}
561
562static int set_query_interval(struct net_bridge *br, unsigned long val)
563{
564 br->multicast_query_interval = clock_t_to_jiffies(val);
565 return 0;
566}
567
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800568static ssize_t multicast_query_interval_store(struct device *d,
Herbert Xud902eee2010-02-27 19:41:52 +0000569 struct device_attribute *attr,
570 const char *buf, size_t len)
571{
572 return store_bridge_parm(d, buf, len, set_query_interval);
573}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800574static DEVICE_ATTR_RW(multicast_query_interval);
Herbert Xud902eee2010-02-27 19:41:52 +0000575
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800576static ssize_t multicast_query_response_interval_show(
Herbert Xud902eee2010-02-27 19:41:52 +0000577 struct device *d, struct device_attribute *attr, char *buf)
578{
579 struct net_bridge *br = to_bridge(d);
580 return sprintf(
581 buf, "%lu\n",
582 jiffies_to_clock_t(br->multicast_query_response_interval));
583}
584
585static int set_query_response_interval(struct net_bridge *br, unsigned long val)
586{
587 br->multicast_query_response_interval = clock_t_to_jiffies(val);
588 return 0;
589}
590
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800591static ssize_t multicast_query_response_interval_store(
Herbert Xud902eee2010-02-27 19:41:52 +0000592 struct device *d, struct device_attribute *attr, const char *buf,
593 size_t len)
594{
595 return store_bridge_parm(d, buf, len, set_query_response_interval);
596}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800597static DEVICE_ATTR_RW(multicast_query_response_interval);
Herbert Xud902eee2010-02-27 19:41:52 +0000598
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800599static ssize_t multicast_startup_query_interval_show(
Herbert Xud902eee2010-02-27 19:41:52 +0000600 struct device *d, struct device_attribute *attr, char *buf)
601{
602 struct net_bridge *br = to_bridge(d);
603 return sprintf(
604 buf, "%lu\n",
605 jiffies_to_clock_t(br->multicast_startup_query_interval));
606}
607
608static int set_startup_query_interval(struct net_bridge *br, unsigned long val)
609{
610 br->multicast_startup_query_interval = clock_t_to_jiffies(val);
611 return 0;
612}
613
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800614static ssize_t multicast_startup_query_interval_store(
Herbert Xud902eee2010-02-27 19:41:52 +0000615 struct device *d, struct device_attribute *attr, const char *buf,
616 size_t len)
617{
618 return store_bridge_parm(d, buf, len, set_startup_query_interval);
619}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800620static DEVICE_ATTR_RW(multicast_startup_query_interval);
Nikolay Aleksandrov1080ab92016-06-28 16:57:06 +0200621
622static ssize_t multicast_stats_enabled_show(struct device *d,
623 struct device_attribute *attr,
624 char *buf)
625{
626 struct net_bridge *br = to_bridge(d);
627
628 return sprintf(buf, "%u\n", br->multicast_stats_enabled);
629}
630
631static int set_stats_enabled(struct net_bridge *br, unsigned long val)
632{
633 br->multicast_stats_enabled = !!val;
634 return 0;
635}
636
637static ssize_t multicast_stats_enabled_store(struct device *d,
638 struct device_attribute *attr,
639 const char *buf,
640 size_t len)
641{
642 return store_bridge_parm(d, buf, len, set_stats_enabled);
643}
644static DEVICE_ATTR_RW(multicast_stats_enabled);
Herbert Xu0909e112010-02-27 19:41:49 +0000645#endif
Pablo Neira Ayuso34666d42014-09-18 11:29:03 +0200646#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800647static ssize_t nf_call_iptables_show(
Patrick McHardy4df53d82010-07-02 09:32:57 +0200648 struct device *d, struct device_attribute *attr, char *buf)
649{
650 struct net_bridge *br = to_bridge(d);
651 return sprintf(buf, "%u\n", br->nf_call_iptables);
652}
653
654static int set_nf_call_iptables(struct net_bridge *br, unsigned long val)
655{
656 br->nf_call_iptables = val ? true : false;
657 return 0;
658}
659
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800660static ssize_t nf_call_iptables_store(
Patrick McHardy4df53d82010-07-02 09:32:57 +0200661 struct device *d, struct device_attribute *attr, const char *buf,
662 size_t len)
663{
664 return store_bridge_parm(d, buf, len, set_nf_call_iptables);
665}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800666static DEVICE_ATTR_RW(nf_call_iptables);
Patrick McHardy4df53d82010-07-02 09:32:57 +0200667
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800668static ssize_t nf_call_ip6tables_show(
Patrick McHardy4df53d82010-07-02 09:32:57 +0200669 struct device *d, struct device_attribute *attr, char *buf)
670{
671 struct net_bridge *br = to_bridge(d);
672 return sprintf(buf, "%u\n", br->nf_call_ip6tables);
673}
674
675static int set_nf_call_ip6tables(struct net_bridge *br, unsigned long val)
676{
677 br->nf_call_ip6tables = val ? true : false;
678 return 0;
679}
680
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800681static ssize_t nf_call_ip6tables_store(
Patrick McHardy4df53d82010-07-02 09:32:57 +0200682 struct device *d, struct device_attribute *attr, const char *buf,
683 size_t len)
684{
685 return store_bridge_parm(d, buf, len, set_nf_call_ip6tables);
686}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800687static DEVICE_ATTR_RW(nf_call_ip6tables);
Patrick McHardy4df53d82010-07-02 09:32:57 +0200688
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800689static ssize_t nf_call_arptables_show(
Patrick McHardy4df53d82010-07-02 09:32:57 +0200690 struct device *d, struct device_attribute *attr, char *buf)
691{
692 struct net_bridge *br = to_bridge(d);
693 return sprintf(buf, "%u\n", br->nf_call_arptables);
694}
695
696static int set_nf_call_arptables(struct net_bridge *br, unsigned long val)
697{
698 br->nf_call_arptables = val ? true : false;
699 return 0;
700}
701
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800702static ssize_t nf_call_arptables_store(
Patrick McHardy4df53d82010-07-02 09:32:57 +0200703 struct device *d, struct device_attribute *attr, const char *buf,
704 size_t len)
705{
706 return store_bridge_parm(d, buf, len, set_nf_call_arptables);
707}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800708static DEVICE_ATTR_RW(nf_call_arptables);
Patrick McHardy4df53d82010-07-02 09:32:57 +0200709#endif
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000710#ifdef CONFIG_BRIDGE_VLAN_FILTERING
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800711static ssize_t vlan_filtering_show(struct device *d,
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000712 struct device_attribute *attr,
713 char *buf)
714{
715 struct net_bridge *br = to_bridge(d);
716 return sprintf(buf, "%d\n", br->vlan_enabled);
717}
718
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800719static ssize_t vlan_filtering_store(struct device *d,
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000720 struct device_attribute *attr,
721 const char *buf, size_t len)
722{
723 return store_bridge_parm(d, buf, len, br_vlan_filter_toggle);
724}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800725static DEVICE_ATTR_RW(vlan_filtering);
Toshiaki Makita204177f2014-06-10 20:59:25 +0900726
727static ssize_t vlan_protocol_show(struct device *d,
728 struct device_attribute *attr,
729 char *buf)
730{
731 struct net_bridge *br = to_bridge(d);
732 return sprintf(buf, "%#06x\n", ntohs(br->vlan_proto));
733}
734
735static ssize_t vlan_protocol_store(struct device *d,
736 struct device_attribute *attr,
737 const char *buf, size_t len)
738{
739 return store_bridge_parm(d, buf, len, br_vlan_set_proto);
740}
741static DEVICE_ATTR_RW(vlan_protocol);
Vlad Yasevich96a20d92014-10-03 11:29:16 -0400742
743static ssize_t default_pvid_show(struct device *d,
744 struct device_attribute *attr,
745 char *buf)
746{
747 struct net_bridge *br = to_bridge(d);
748 return sprintf(buf, "%d\n", br->default_pvid);
749}
750
751static ssize_t default_pvid_store(struct device *d,
752 struct device_attribute *attr,
753 const char *buf, size_t len)
754{
755 return store_bridge_parm(d, buf, len, br_vlan_set_default_pvid);
756}
757static DEVICE_ATTR_RW(default_pvid);
Nikolay Aleksandrov6dada9b2016-04-30 10:25:28 +0200758
759static ssize_t vlan_stats_enabled_show(struct device *d,
760 struct device_attribute *attr,
761 char *buf)
762{
763 struct net_bridge *br = to_bridge(d);
764 return sprintf(buf, "%u\n", br->vlan_stats_enabled);
765}
766
767static ssize_t vlan_stats_enabled_store(struct device *d,
768 struct device_attribute *attr,
769 const char *buf, size_t len)
770{
771 return store_bridge_parm(d, buf, len, br_vlan_set_stats);
772}
773static DEVICE_ATTR_RW(vlan_stats_enabled);
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000774#endif
Herbert Xu0909e112010-02-27 19:41:49 +0000775
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776static struct attribute *bridge_attrs[] = {
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700777 &dev_attr_forward_delay.attr,
778 &dev_attr_hello_time.attr,
779 &dev_attr_max_age.attr,
780 &dev_attr_ageing_time.attr,
781 &dev_attr_stp_state.attr,
stephen hemminger515853c2011-10-03 18:14:46 +0000782 &dev_attr_group_fwd_mask.attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700783 &dev_attr_priority.attr,
784 &dev_attr_bridge_id.attr,
785 &dev_attr_root_id.attr,
786 &dev_attr_root_path_cost.attr,
787 &dev_attr_root_port.attr,
788 &dev_attr_topology_change.attr,
789 &dev_attr_topology_change_detected.attr,
790 &dev_attr_hello_timer.attr,
791 &dev_attr_tcn_timer.attr,
792 &dev_attr_topology_change_timer.attr,
793 &dev_attr_gc_timer.attr,
794 &dev_attr_group_addr.attr,
Stephen Hemminger9cf63742007-04-09 12:57:54 -0700795 &dev_attr_flush.attr,
Herbert Xu0909e112010-02-27 19:41:49 +0000796#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
797 &dev_attr_multicast_router.attr,
Herbert Xu561f1102010-02-27 19:41:50 +0000798 &dev_attr_multicast_snooping.attr,
Herbert Xuc5c23262012-04-13 02:37:42 +0000799 &dev_attr_multicast_querier.attr,
Cong Wang1c8ad5b2013-05-21 21:52:54 +0000800 &dev_attr_multicast_query_use_ifaddr.attr,
Herbert Xub1951672010-02-27 19:41:51 +0000801 &dev_attr_hash_elasticity.attr,
802 &dev_attr_hash_max.attr,
Herbert Xud902eee2010-02-27 19:41:52 +0000803 &dev_attr_multicast_last_member_count.attr,
804 &dev_attr_multicast_startup_query_count.attr,
805 &dev_attr_multicast_last_member_interval.attr,
806 &dev_attr_multicast_membership_interval.attr,
807 &dev_attr_multicast_querier_interval.attr,
808 &dev_attr_multicast_query_interval.attr,
809 &dev_attr_multicast_query_response_interval.attr,
810 &dev_attr_multicast_startup_query_interval.attr,
Nikolay Aleksandrov1080ab92016-06-28 16:57:06 +0200811 &dev_attr_multicast_stats_enabled.attr,
Herbert Xu0909e112010-02-27 19:41:49 +0000812#endif
Pablo Neira Ayuso34666d42014-09-18 11:29:03 +0200813#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
Patrick McHardy4df53d82010-07-02 09:32:57 +0200814 &dev_attr_nf_call_iptables.attr,
815 &dev_attr_nf_call_ip6tables.attr,
816 &dev_attr_nf_call_arptables.attr,
817#endif
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000818#ifdef CONFIG_BRIDGE_VLAN_FILTERING
819 &dev_attr_vlan_filtering.attr,
Toshiaki Makita204177f2014-06-10 20:59:25 +0900820 &dev_attr_vlan_protocol.attr,
Vlad Yasevich96a20d92014-10-03 11:29:16 -0400821 &dev_attr_default_pvid.attr,
Nikolay Aleksandrov6dada9b2016-04-30 10:25:28 +0200822 &dev_attr_vlan_stats_enabled.attr,
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000823#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 NULL
825};
826
827static struct attribute_group bridge_group = {
828 .name = SYSFS_BRIDGE_ATTR,
829 .attrs = bridge_attrs,
830};
831
832/*
833 * Export the forwarding information table as a binary file
834 * The records are struct __fdb_entry.
835 *
836 * Returns the number of bytes read.
837 */
Chris Wright2c3c8be2010-05-12 18:28:57 -0700838static ssize_t brforward_read(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +0800839 struct bin_attribute *bin_attr,
840 char *buf, loff_t off, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841{
Geliang Tangaeb7ed12015-12-23 20:42:21 +0800842 struct device *dev = kobj_to_dev(kobj);
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700843 struct net_bridge *br = to_bridge(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 int n;
845
846 /* must read whole records */
847 if (off % sizeof(struct __fdb_entry) != 0)
848 return -EINVAL;
849
YOSHIFUJI Hideaki9d6f2292007-02-09 23:24:35 +0900850 n = br_fdb_fillbuf(br, buf,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 count / sizeof(struct __fdb_entry),
852 off / sizeof(struct __fdb_entry));
853
854 if (n > 0)
855 n *= sizeof(struct __fdb_entry);
YOSHIFUJI Hideaki9d6f2292007-02-09 23:24:35 +0900856
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857 return n;
858}
859
860static struct bin_attribute bridge_forward = {
861 .attr = { .name = SYSFS_BRIDGE_FDB,
Tejun Heo7b595752007-06-14 03:45:17 +0900862 .mode = S_IRUGO, },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863 .read = brforward_read,
864};
865
866/*
867 * Add entries in sysfs onto the existing network class device
868 * for the bridge.
869 * Adds a attribute group "bridge" containing tuning parameters.
870 * Binary attribute containing the forward table
871 * Sub directory to hold links to interfaces.
872 *
873 * Note: the ifobj exists only to be a subdirectory
874 * to hold links. The ifobj exists in same data structure
875 * as it's parent the bridge so reference counting works.
876 */
877int br_sysfs_addbr(struct net_device *dev)
878{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700879 struct kobject *brobj = &dev->dev.kobj;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880 struct net_bridge *br = netdev_priv(dev);
881 int err;
882
883 err = sysfs_create_group(brobj, &bridge_group);
884 if (err) {
885 pr_info("%s: can't create group %s/%s\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -0800886 __func__, dev->name, bridge_group.name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887 goto out1;
888 }
889
890 err = sysfs_create_bin_file(brobj, &bridge_forward);
891 if (err) {
Randy Dunlap1842c4b2006-10-25 23:07:37 -0700892 pr_info("%s: can't create attribute file %s/%s\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -0800893 __func__, dev->name, bridge_forward.attr.name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894 goto out2;
895 }
896
Greg Kroah-Hartman43b98c42007-12-17 15:54:39 -0400897 br->ifobj = kobject_create_and_add(SYSFS_BRIDGE_PORT_SUBDIR, brobj);
898 if (!br->ifobj) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899 pr_info("%s: can't add kobject (directory) %s/%s\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -0800900 __func__, dev->name, SYSFS_BRIDGE_PORT_SUBDIR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901 goto out3;
902 }
903 return 0;
904 out3:
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700905 sysfs_remove_bin_file(&dev->dev.kobj, &bridge_forward);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906 out2:
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700907 sysfs_remove_group(&dev->dev.kobj, &bridge_group);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908 out1:
909 return err;
910
911}
912
913void br_sysfs_delbr(struct net_device *dev)
914{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700915 struct kobject *kobj = &dev->dev.kobj;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916 struct net_bridge *br = netdev_priv(dev);
917
Greg Kroah-Hartman78a2d902007-12-20 08:13:05 -0800918 kobject_put(br->ifobj);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919 sysfs_remove_bin_file(kobj, &bridge_forward);
920 sysfs_remove_group(kobj, &bridge_group);
921}