blob: 0b5dd607444c71fd2e7c5200d219977aa526c190 [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>
Ingo Molnar174cd4b2017-02-02 19:15:33 +010022#include <linux/sched/signal.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
24#include "br_private.h"
25
Wang Chen524ad0a2008-11-12 23:39:10 -080026#define to_bridge(cd) ((struct net_bridge *)netdev_priv(to_net_dev(cd)))
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
28/*
29 * Common code for storing bridge parameters.
30 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -070031static ssize_t store_bridge_parm(struct device *d,
Linus Torvalds1da177e2005-04-16 15:20:36 -070032 const char *buf, size_t len,
Stephen Hemminger8d4698f72008-09-08 13:44:40 -070033 int (*set)(struct net_bridge *, unsigned long))
Linus Torvalds1da177e2005-04-16 15:20:36 -070034{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -070035 struct net_bridge *br = to_bridge(d);
Linus Torvalds1da177e2005-04-16 15:20:36 -070036 char *endp;
37 unsigned long val;
Stephen Hemminger8d4698f72008-09-08 13:44:40 -070038 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
Eric W. Biedermancb990502012-11-16 03:03:08 +000040 if (!ns_capable(dev_net(br->dev)->user_ns, CAP_NET_ADMIN))
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 return -EPERM;
42
43 val = simple_strtoul(buf, &endp, 0);
44 if (endp == buf)
45 return -EINVAL;
46
Xin Long047831a2016-04-09 00:03:31 +080047 if (!rtnl_trylock())
48 return restart_syscall();
49
Stephen Hemminger8d4698f72008-09-08 13:44:40 -070050 err = (*set)(br, val);
Xin Long047831a2016-04-09 00:03:31 +080051 if (!err)
52 netdev_state_change(br->dev);
53 rtnl_unlock();
54
Stephen Hemminger8d4698f72008-09-08 13:44:40 -070055 return err ? err : len;
Linus Torvalds1da177e2005-04-16 15:20:36 -070056}
57
58
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -080059static ssize_t forward_delay_show(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -070060 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -070061{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -070062 struct net_bridge *br = to_bridge(d);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 return sprintf(buf, "%lu\n", jiffies_to_clock_t(br->forward_delay));
64}
65
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -080066static ssize_t forward_delay_store(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -070067 struct device_attribute *attr,
68 const char *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -070069{
stephen hemminger14f98f22011-04-04 14:03:33 +000070 return store_bridge_parm(d, buf, len, br_set_forward_delay);
Linus Torvalds1da177e2005-04-16 15:20:36 -070071}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -080072static DEVICE_ATTR_RW(forward_delay);
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -080074static ssize_t hello_time_show(struct device *d, struct device_attribute *attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -070075 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -070076{
77 return sprintf(buf, "%lu\n",
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -070078 jiffies_to_clock_t(to_bridge(d)->hello_time));
Linus Torvalds1da177e2005-04-16 15:20:36 -070079}
80
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -080081static ssize_t hello_time_store(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -070082 struct device_attribute *attr, const char *buf,
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 size_t len)
84{
stephen hemminger14f98f22011-04-04 14:03:33 +000085 return store_bridge_parm(d, buf, len, br_set_hello_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -070086}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -080087static DEVICE_ATTR_RW(hello_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -080089static ssize_t max_age_show(struct device *d, struct device_attribute *attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -070090 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -070091{
92 return sprintf(buf, "%lu\n",
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -070093 jiffies_to_clock_t(to_bridge(d)->max_age));
Linus Torvalds1da177e2005-04-16 15:20:36 -070094}
95
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -080096static ssize_t max_age_store(struct device *d, struct device_attribute *attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -070097 const char *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -070098{
stephen hemminger14f98f22011-04-04 14:03:33 +000099 return store_bridge_parm(d, buf, len, br_set_max_age);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800101static DEVICE_ATTR_RW(max_age);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800103static ssize_t ageing_time_show(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700104 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700106 struct net_bridge *br = to_bridge(d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 return sprintf(buf, "%lu\n", jiffies_to_clock_t(br->ageing_time));
108}
109
Stephen Hemminger8d4698f72008-09-08 13:44:40 -0700110static int set_ageing_time(struct net_bridge *br, unsigned long val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111{
Xin Long047831a2016-04-09 00:03:31 +0800112 return br_set_ageing_time(br, val);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113}
114
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800115static ssize_t ageing_time_store(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700116 struct device_attribute *attr,
117 const char *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700119 return store_bridge_parm(d, buf, len, set_ageing_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800121static DEVICE_ATTR_RW(ageing_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800123static ssize_t stp_state_show(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700124 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700126 struct net_bridge *br = to_bridge(d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 return sprintf(buf, "%d\n", br->stp_enabled);
128}
129
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130
Xin Long44361562016-04-09 00:03:30 +0800131static int set_stp_state(struct net_bridge *br, unsigned long val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132{
Stephen Hemminger17120882007-08-14 13:21:34 -0700133 br_stp_set_enabled(br, val);
Stephen Hemminger17120882007-08-14 13:21:34 -0700134
Xin Long44361562016-04-09 00:03:30 +0800135 return 0;
136}
137
138static ssize_t stp_state_store(struct device *d,
139 struct device_attribute *attr, const char *buf,
140 size_t len)
141{
142 return store_bridge_parm(d, buf, len, set_stp_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800144static DEVICE_ATTR_RW(stp_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800146static ssize_t group_fwd_mask_show(struct device *d,
147 struct device_attribute *attr,
148 char *buf)
stephen hemminger515853c2011-10-03 18:14:46 +0000149{
150 struct net_bridge *br = to_bridge(d);
151 return sprintf(buf, "%#x\n", br->group_fwd_mask);
152}
153
Xin Long347db6b2016-04-09 00:03:29 +0800154static int set_group_fwd_mask(struct net_bridge *br, unsigned long val)
155{
156 if (val & BR_GROUPFWD_RESTRICTED)
157 return -EINVAL;
158
159 br->group_fwd_mask = val;
160
161 return 0;
162}
stephen hemminger515853c2011-10-03 18:14:46 +0000163
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800164static ssize_t group_fwd_mask_store(struct device *d,
165 struct device_attribute *attr,
166 const char *buf,
167 size_t len)
stephen hemminger515853c2011-10-03 18:14:46 +0000168{
Xin Long347db6b2016-04-09 00:03:29 +0800169 return store_bridge_parm(d, buf, len, set_group_fwd_mask);
stephen hemminger515853c2011-10-03 18:14:46 +0000170}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800171static DEVICE_ATTR_RW(group_fwd_mask);
stephen hemminger515853c2011-10-03 18:14:46 +0000172
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800173static ssize_t priority_show(struct device *d, struct device_attribute *attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700174 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700176 struct net_bridge *br = to_bridge(d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 return sprintf(buf, "%d\n",
178 (br->bridge_id.prio[0] << 8) | br->bridge_id.prio[1]);
179}
180
Stephen Hemminger8d4698f72008-09-08 13:44:40 -0700181static int set_priority(struct net_bridge *br, unsigned long val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182{
183 br_stp_set_bridge_priority(br, (u16) val);
Stephen Hemminger8d4698f72008-09-08 13:44:40 -0700184 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185}
186
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800187static ssize_t priority_store(struct device *d, struct device_attribute *attr,
188 const char *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700190 return store_bridge_parm(d, buf, len, set_priority);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800192static DEVICE_ATTR_RW(priority);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800194static ssize_t root_id_show(struct device *d, struct device_attribute *attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700195 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700197 return br_show_bridge_id(buf, &to_bridge(d)->designated_root);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800199static DEVICE_ATTR_RO(root_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800201static ssize_t bridge_id_show(struct device *d, struct device_attribute *attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700202 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700204 return br_show_bridge_id(buf, &to_bridge(d)->bridge_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800206static DEVICE_ATTR_RO(bridge_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800208static ssize_t root_port_show(struct device *d, struct device_attribute *attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700209 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700211 return sprintf(buf, "%d\n", to_bridge(d)->root_port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800213static DEVICE_ATTR_RO(root_port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800215static ssize_t root_path_cost_show(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700216 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700218 return sprintf(buf, "%d\n", to_bridge(d)->root_path_cost);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800220static DEVICE_ATTR_RO(root_path_cost);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800222static ssize_t topology_change_show(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700223 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700225 return sprintf(buf, "%d\n", to_bridge(d)->topology_change);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800227static DEVICE_ATTR_RO(topology_change);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800229static ssize_t topology_change_detected_show(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700230 struct device_attribute *attr,
231 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700233 struct net_bridge *br = to_bridge(d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 return sprintf(buf, "%d\n", br->topology_change_detected);
235}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800236static DEVICE_ATTR_RO(topology_change_detected);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800238static ssize_t hello_timer_show(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700239 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700241 struct net_bridge *br = to_bridge(d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 return sprintf(buf, "%ld\n", br_timer_value(&br->hello_timer));
243}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800244static DEVICE_ATTR_RO(hello_timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800246static ssize_t tcn_timer_show(struct device *d, struct device_attribute *attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700247 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700249 struct net_bridge *br = to_bridge(d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 return sprintf(buf, "%ld\n", br_timer_value(&br->tcn_timer));
251}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800252static DEVICE_ATTR_RO(tcn_timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800254static ssize_t topology_change_timer_show(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700255 struct device_attribute *attr,
256 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700258 struct net_bridge *br = to_bridge(d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 return sprintf(buf, "%ld\n", br_timer_value(&br->topology_change_timer));
260}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800261static DEVICE_ATTR_RO(topology_change_timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800263static ssize_t gc_timer_show(struct device *d, struct device_attribute *attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700264 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700266 struct net_bridge *br = to_bridge(d);
Nikolay Aleksandrovf7cdee82017-02-04 18:05:07 +0100267 return sprintf(buf, "%ld\n", br_timer_value(&br->gc_work.timer));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800269static DEVICE_ATTR_RO(gc_timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800271static ssize_t group_addr_show(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700272 struct device_attribute *attr, char *buf)
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800273{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700274 struct net_bridge *br = to_bridge(d);
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800275 return sprintf(buf, "%x:%x:%x:%x:%x:%x\n",
276 br->group_addr[0], br->group_addr[1],
277 br->group_addr[2], br->group_addr[3],
278 br->group_addr[4], br->group_addr[5]);
279}
280
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800281static ssize_t group_addr_store(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700282 struct device_attribute *attr,
283 const char *buf, size_t len)
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800284{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700285 struct net_bridge *br = to_bridge(d);
Ben Hutchings4197f242012-11-01 09:10:04 +0000286 u8 new_addr[6];
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800287 int i;
288
Eric W. Biedermancb990502012-11-16 03:03:08 +0000289 if (!ns_capable(dev_net(br->dev)->user_ns, CAP_NET_ADMIN))
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800290 return -EPERM;
291
Ben Hutchings4197f242012-11-01 09:10:04 +0000292 if (sscanf(buf, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx",
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800293 &new_addr[0], &new_addr[1], &new_addr[2],
294 &new_addr[3], &new_addr[4], &new_addr[5]) != 6)
295 return -EINVAL;
296
Ben Hutchings46acc462012-11-01 09:11:11 +0000297 if (!is_link_local_ether_addr(new_addr))
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800298 return -EINVAL;
299
Joe Perchesf64f9e72009-11-29 16:55:45 -0800300 if (new_addr[5] == 1 || /* 802.3x Pause address */
301 new_addr[5] == 2 || /* 802.3ad Slow protocols */
302 new_addr[5] == 3) /* 802.1X PAE address */
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800303 return -EINVAL;
304
Toshiaki Makita204177f2014-06-10 20:59:25 +0900305 if (!rtnl_trylock())
306 return restart_syscall();
307
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800308 spin_lock_bh(&br->lock);
309 for (i = 0; i < 6; i++)
310 br->group_addr[i] = new_addr[i];
311 spin_unlock_bh(&br->lock);
Toshiaki Makita204177f2014-06-10 20:59:25 +0900312
313 br->group_addr_set = true;
314 br_recalculate_fwd_mask(br);
Xin Long047831a2016-04-09 00:03:31 +0800315 netdev_state_change(br->dev);
Toshiaki Makita204177f2014-06-10 20:59:25 +0900316
317 rtnl_unlock();
318
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800319 return len;
320}
321
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800322static DEVICE_ATTR_RW(group_addr);
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800323
Xin Long14f31bb2016-04-09 00:03:28 +0800324static int set_flush(struct net_bridge *br, unsigned long val)
325{
326 br_fdb_flush(br);
327 return 0;
328}
329
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800330static ssize_t flush_store(struct device *d,
Stephen Hemminger9cf63742007-04-09 12:57:54 -0700331 struct device_attribute *attr,
332 const char *buf, size_t len)
333{
Xin Long14f31bb2016-04-09 00:03:28 +0800334 return store_bridge_parm(d, buf, len, set_flush);
Stephen Hemminger9cf63742007-04-09 12:57:54 -0700335}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800336static DEVICE_ATTR_WO(flush);
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800337
Herbert Xu0909e112010-02-27 19:41:49 +0000338#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800339static ssize_t multicast_router_show(struct device *d,
Herbert Xu0909e112010-02-27 19:41:49 +0000340 struct device_attribute *attr, char *buf)
341{
342 struct net_bridge *br = to_bridge(d);
343 return sprintf(buf, "%d\n", br->multicast_router);
344}
345
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800346static ssize_t multicast_router_store(struct device *d,
Herbert Xu0909e112010-02-27 19:41:49 +0000347 struct device_attribute *attr,
348 const char *buf, size_t len)
349{
350 return store_bridge_parm(d, buf, len, br_multicast_set_router);
351}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800352static DEVICE_ATTR_RW(multicast_router);
Herbert Xu561f1102010-02-27 19:41:50 +0000353
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800354static ssize_t multicast_snooping_show(struct device *d,
Herbert Xu561f1102010-02-27 19:41:50 +0000355 struct device_attribute *attr,
356 char *buf)
357{
358 struct net_bridge *br = to_bridge(d);
359 return sprintf(buf, "%d\n", !br->multicast_disabled);
360}
361
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800362static ssize_t multicast_snooping_store(struct device *d,
Herbert Xu561f1102010-02-27 19:41:50 +0000363 struct device_attribute *attr,
364 const char *buf, size_t len)
365{
366 return store_bridge_parm(d, buf, len, br_multicast_toggle);
367}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800368static DEVICE_ATTR_RW(multicast_snooping);
Herbert Xub1951672010-02-27 19:41:51 +0000369
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800370static ssize_t multicast_query_use_ifaddr_show(struct device *d,
371 struct device_attribute *attr,
372 char *buf)
Cong Wang1c8ad5b2013-05-21 21:52:54 +0000373{
374 struct net_bridge *br = to_bridge(d);
375 return sprintf(buf, "%d\n", br->multicast_query_use_ifaddr);
376}
377
378static int set_query_use_ifaddr(struct net_bridge *br, unsigned long val)
379{
380 br->multicast_query_use_ifaddr = !!val;
381 return 0;
382}
383
384static ssize_t
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800385multicast_query_use_ifaddr_store(struct device *d,
Cong Wang1c8ad5b2013-05-21 21:52:54 +0000386 struct device_attribute *attr,
387 const char *buf, size_t len)
388{
389 return store_bridge_parm(d, buf, len, set_query_use_ifaddr);
390}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800391static DEVICE_ATTR_RW(multicast_query_use_ifaddr);
Cong Wang1c8ad5b2013-05-21 21:52:54 +0000392
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800393static ssize_t multicast_querier_show(struct device *d,
Herbert Xuc5c23262012-04-13 02:37:42 +0000394 struct device_attribute *attr,
395 char *buf)
396{
397 struct net_bridge *br = to_bridge(d);
398 return sprintf(buf, "%d\n", br->multicast_querier);
399}
400
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800401static ssize_t multicast_querier_store(struct device *d,
Herbert Xuc5c23262012-04-13 02:37:42 +0000402 struct device_attribute *attr,
403 const char *buf, size_t len)
404{
405 return store_bridge_parm(d, buf, len, br_multicast_set_querier);
406}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800407static DEVICE_ATTR_RW(multicast_querier);
Herbert Xuc5c23262012-04-13 02:37:42 +0000408
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800409static ssize_t hash_elasticity_show(struct device *d,
Herbert Xub1951672010-02-27 19:41:51 +0000410 struct device_attribute *attr, char *buf)
411{
412 struct net_bridge *br = to_bridge(d);
413 return sprintf(buf, "%u\n", br->hash_elasticity);
414}
415
416static int set_elasticity(struct net_bridge *br, unsigned long val)
417{
418 br->hash_elasticity = val;
419 return 0;
420}
421
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800422static ssize_t hash_elasticity_store(struct device *d,
Herbert Xub1951672010-02-27 19:41:51 +0000423 struct device_attribute *attr,
424 const char *buf, size_t len)
425{
426 return store_bridge_parm(d, buf, len, set_elasticity);
427}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800428static DEVICE_ATTR_RW(hash_elasticity);
Herbert Xub1951672010-02-27 19:41:51 +0000429
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800430static ssize_t hash_max_show(struct device *d, struct device_attribute *attr,
Herbert Xub1951672010-02-27 19:41:51 +0000431 char *buf)
432{
433 struct net_bridge *br = to_bridge(d);
434 return sprintf(buf, "%u\n", br->hash_max);
435}
436
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800437static ssize_t hash_max_store(struct device *d, struct device_attribute *attr,
Herbert Xub1951672010-02-27 19:41:51 +0000438 const char *buf, size_t len)
439{
440 return store_bridge_parm(d, buf, len, br_multicast_set_hash_max);
441}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800442static DEVICE_ATTR_RW(hash_max);
Herbert Xud902eee2010-02-27 19:41:52 +0000443
Nikolay Aleksandrov5e923582016-11-21 13:03:24 +0100444static ssize_t multicast_igmp_version_show(struct device *d,
445 struct device_attribute *attr,
446 char *buf)
447{
448 struct net_bridge *br = to_bridge(d);
449
450 return sprintf(buf, "%u\n", br->multicast_igmp_version);
451}
452
453static ssize_t multicast_igmp_version_store(struct device *d,
454 struct device_attribute *attr,
455 const char *buf, size_t len)
456{
457 return store_bridge_parm(d, buf, len, br_multicast_set_igmp_version);
458}
459static DEVICE_ATTR_RW(multicast_igmp_version);
460
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800461static ssize_t multicast_last_member_count_show(struct device *d,
Herbert Xud902eee2010-02-27 19:41:52 +0000462 struct device_attribute *attr,
463 char *buf)
464{
465 struct net_bridge *br = to_bridge(d);
466 return sprintf(buf, "%u\n", br->multicast_last_member_count);
467}
468
469static int set_last_member_count(struct net_bridge *br, unsigned long val)
470{
471 br->multicast_last_member_count = val;
472 return 0;
473}
474
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800475static ssize_t multicast_last_member_count_store(struct device *d,
Herbert Xud902eee2010-02-27 19:41:52 +0000476 struct device_attribute *attr,
477 const char *buf, size_t len)
478{
479 return store_bridge_parm(d, buf, len, set_last_member_count);
480}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800481static DEVICE_ATTR_RW(multicast_last_member_count);
Herbert Xud902eee2010-02-27 19:41:52 +0000482
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800483static ssize_t multicast_startup_query_count_show(
Herbert Xud902eee2010-02-27 19:41:52 +0000484 struct device *d, struct device_attribute *attr, char *buf)
485{
486 struct net_bridge *br = to_bridge(d);
487 return sprintf(buf, "%u\n", br->multicast_startup_query_count);
488}
489
490static int set_startup_query_count(struct net_bridge *br, unsigned long val)
491{
492 br->multicast_startup_query_count = val;
493 return 0;
494}
495
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800496static ssize_t multicast_startup_query_count_store(
Herbert Xud902eee2010-02-27 19:41:52 +0000497 struct device *d, struct device_attribute *attr, const char *buf,
498 size_t len)
499{
500 return store_bridge_parm(d, buf, len, set_startup_query_count);
501}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800502static DEVICE_ATTR_RW(multicast_startup_query_count);
Herbert Xud902eee2010-02-27 19:41:52 +0000503
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800504static ssize_t multicast_last_member_interval_show(
Herbert Xud902eee2010-02-27 19:41:52 +0000505 struct device *d, struct device_attribute *attr, char *buf)
506{
507 struct net_bridge *br = to_bridge(d);
508 return sprintf(buf, "%lu\n",
509 jiffies_to_clock_t(br->multicast_last_member_interval));
510}
511
512static int set_last_member_interval(struct net_bridge *br, unsigned long val)
513{
514 br->multicast_last_member_interval = clock_t_to_jiffies(val);
515 return 0;
516}
517
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800518static ssize_t multicast_last_member_interval_store(
Herbert Xud902eee2010-02-27 19:41:52 +0000519 struct device *d, struct device_attribute *attr, const char *buf,
520 size_t len)
521{
522 return store_bridge_parm(d, buf, len, set_last_member_interval);
523}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800524static DEVICE_ATTR_RW(multicast_last_member_interval);
Herbert Xud902eee2010-02-27 19:41:52 +0000525
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800526static ssize_t multicast_membership_interval_show(
Herbert Xud902eee2010-02-27 19:41:52 +0000527 struct device *d, struct device_attribute *attr, char *buf)
528{
529 struct net_bridge *br = to_bridge(d);
530 return sprintf(buf, "%lu\n",
531 jiffies_to_clock_t(br->multicast_membership_interval));
532}
533
534static int set_membership_interval(struct net_bridge *br, unsigned long val)
535{
536 br->multicast_membership_interval = clock_t_to_jiffies(val);
537 return 0;
538}
539
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800540static ssize_t multicast_membership_interval_store(
Herbert Xud902eee2010-02-27 19:41:52 +0000541 struct device *d, struct device_attribute *attr, const char *buf,
542 size_t len)
543{
544 return store_bridge_parm(d, buf, len, set_membership_interval);
545}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800546static DEVICE_ATTR_RW(multicast_membership_interval);
Herbert Xud902eee2010-02-27 19:41:52 +0000547
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800548static ssize_t multicast_querier_interval_show(struct device *d,
Herbert Xud902eee2010-02-27 19:41:52 +0000549 struct device_attribute *attr,
550 char *buf)
551{
552 struct net_bridge *br = to_bridge(d);
553 return sprintf(buf, "%lu\n",
554 jiffies_to_clock_t(br->multicast_querier_interval));
555}
556
557static int set_querier_interval(struct net_bridge *br, unsigned long val)
558{
559 br->multicast_querier_interval = clock_t_to_jiffies(val);
560 return 0;
561}
562
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800563static ssize_t multicast_querier_interval_store(struct device *d,
Herbert Xud902eee2010-02-27 19:41:52 +0000564 struct device_attribute *attr,
565 const char *buf, size_t len)
566{
567 return store_bridge_parm(d, buf, len, set_querier_interval);
568}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800569static DEVICE_ATTR_RW(multicast_querier_interval);
Herbert Xud902eee2010-02-27 19:41:52 +0000570
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800571static ssize_t multicast_query_interval_show(struct device *d,
Herbert Xud902eee2010-02-27 19:41:52 +0000572 struct device_attribute *attr,
573 char *buf)
574{
575 struct net_bridge *br = to_bridge(d);
576 return sprintf(buf, "%lu\n",
577 jiffies_to_clock_t(br->multicast_query_interval));
578}
579
580static int set_query_interval(struct net_bridge *br, unsigned long val)
581{
582 br->multicast_query_interval = clock_t_to_jiffies(val);
583 return 0;
584}
585
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800586static ssize_t multicast_query_interval_store(struct device *d,
Herbert Xud902eee2010-02-27 19:41:52 +0000587 struct device_attribute *attr,
588 const char *buf, size_t len)
589{
590 return store_bridge_parm(d, buf, len, set_query_interval);
591}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800592static DEVICE_ATTR_RW(multicast_query_interval);
Herbert Xud902eee2010-02-27 19:41:52 +0000593
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800594static ssize_t multicast_query_response_interval_show(
Herbert Xud902eee2010-02-27 19:41:52 +0000595 struct device *d, struct device_attribute *attr, char *buf)
596{
597 struct net_bridge *br = to_bridge(d);
598 return sprintf(
599 buf, "%lu\n",
600 jiffies_to_clock_t(br->multicast_query_response_interval));
601}
602
603static int set_query_response_interval(struct net_bridge *br, unsigned long val)
604{
605 br->multicast_query_response_interval = clock_t_to_jiffies(val);
606 return 0;
607}
608
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800609static ssize_t multicast_query_response_interval_store(
Herbert Xud902eee2010-02-27 19:41:52 +0000610 struct device *d, struct device_attribute *attr, const char *buf,
611 size_t len)
612{
613 return store_bridge_parm(d, buf, len, set_query_response_interval);
614}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800615static DEVICE_ATTR_RW(multicast_query_response_interval);
Herbert Xud902eee2010-02-27 19:41:52 +0000616
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800617static ssize_t multicast_startup_query_interval_show(
Herbert Xud902eee2010-02-27 19:41:52 +0000618 struct device *d, struct device_attribute *attr, char *buf)
619{
620 struct net_bridge *br = to_bridge(d);
621 return sprintf(
622 buf, "%lu\n",
623 jiffies_to_clock_t(br->multicast_startup_query_interval));
624}
625
626static int set_startup_query_interval(struct net_bridge *br, unsigned long val)
627{
628 br->multicast_startup_query_interval = clock_t_to_jiffies(val);
629 return 0;
630}
631
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800632static ssize_t multicast_startup_query_interval_store(
Herbert Xud902eee2010-02-27 19:41:52 +0000633 struct device *d, struct device_attribute *attr, const char *buf,
634 size_t len)
635{
636 return store_bridge_parm(d, buf, len, set_startup_query_interval);
637}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800638static DEVICE_ATTR_RW(multicast_startup_query_interval);
Nikolay Aleksandrov1080ab92016-06-28 16:57:06 +0200639
640static ssize_t multicast_stats_enabled_show(struct device *d,
641 struct device_attribute *attr,
642 char *buf)
643{
644 struct net_bridge *br = to_bridge(d);
645
646 return sprintf(buf, "%u\n", br->multicast_stats_enabled);
647}
648
649static int set_stats_enabled(struct net_bridge *br, unsigned long val)
650{
651 br->multicast_stats_enabled = !!val;
652 return 0;
653}
654
655static ssize_t multicast_stats_enabled_store(struct device *d,
656 struct device_attribute *attr,
657 const char *buf,
658 size_t len)
659{
660 return store_bridge_parm(d, buf, len, set_stats_enabled);
661}
662static DEVICE_ATTR_RW(multicast_stats_enabled);
Nikolay Aleksandrovaa2ae3e2016-11-21 13:03:25 +0100663
664#if IS_ENABLED(CONFIG_IPV6)
665static ssize_t multicast_mld_version_show(struct device *d,
666 struct device_attribute *attr,
667 char *buf)
668{
669 struct net_bridge *br = to_bridge(d);
670
671 return sprintf(buf, "%u\n", br->multicast_mld_version);
672}
673
674static ssize_t multicast_mld_version_store(struct device *d,
675 struct device_attribute *attr,
676 const char *buf, size_t len)
677{
678 return store_bridge_parm(d, buf, len, br_multicast_set_mld_version);
679}
680static DEVICE_ATTR_RW(multicast_mld_version);
681#endif
Herbert Xu0909e112010-02-27 19:41:49 +0000682#endif
Pablo Neira Ayuso34666d42014-09-18 11:29:03 +0200683#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800684static ssize_t nf_call_iptables_show(
Patrick McHardy4df53d82010-07-02 09:32:57 +0200685 struct device *d, struct device_attribute *attr, char *buf)
686{
687 struct net_bridge *br = to_bridge(d);
688 return sprintf(buf, "%u\n", br->nf_call_iptables);
689}
690
691static int set_nf_call_iptables(struct net_bridge *br, unsigned long val)
692{
693 br->nf_call_iptables = val ? true : false;
694 return 0;
695}
696
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800697static ssize_t nf_call_iptables_store(
Patrick McHardy4df53d82010-07-02 09:32:57 +0200698 struct device *d, struct device_attribute *attr, const char *buf,
699 size_t len)
700{
701 return store_bridge_parm(d, buf, len, set_nf_call_iptables);
702}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800703static DEVICE_ATTR_RW(nf_call_iptables);
Patrick McHardy4df53d82010-07-02 09:32:57 +0200704
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800705static ssize_t nf_call_ip6tables_show(
Patrick McHardy4df53d82010-07-02 09:32:57 +0200706 struct device *d, struct device_attribute *attr, char *buf)
707{
708 struct net_bridge *br = to_bridge(d);
709 return sprintf(buf, "%u\n", br->nf_call_ip6tables);
710}
711
712static int set_nf_call_ip6tables(struct net_bridge *br, unsigned long val)
713{
714 br->nf_call_ip6tables = val ? true : false;
715 return 0;
716}
717
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800718static ssize_t nf_call_ip6tables_store(
Patrick McHardy4df53d82010-07-02 09:32:57 +0200719 struct device *d, struct device_attribute *attr, const char *buf,
720 size_t len)
721{
722 return store_bridge_parm(d, buf, len, set_nf_call_ip6tables);
723}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800724static DEVICE_ATTR_RW(nf_call_ip6tables);
Patrick McHardy4df53d82010-07-02 09:32:57 +0200725
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800726static ssize_t nf_call_arptables_show(
Patrick McHardy4df53d82010-07-02 09:32:57 +0200727 struct device *d, struct device_attribute *attr, char *buf)
728{
729 struct net_bridge *br = to_bridge(d);
730 return sprintf(buf, "%u\n", br->nf_call_arptables);
731}
732
733static int set_nf_call_arptables(struct net_bridge *br, unsigned long val)
734{
735 br->nf_call_arptables = val ? true : false;
736 return 0;
737}
738
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800739static ssize_t nf_call_arptables_store(
Patrick McHardy4df53d82010-07-02 09:32:57 +0200740 struct device *d, struct device_attribute *attr, const char *buf,
741 size_t len)
742{
743 return store_bridge_parm(d, buf, len, set_nf_call_arptables);
744}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800745static DEVICE_ATTR_RW(nf_call_arptables);
Patrick McHardy4df53d82010-07-02 09:32:57 +0200746#endif
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000747#ifdef CONFIG_BRIDGE_VLAN_FILTERING
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800748static ssize_t vlan_filtering_show(struct device *d,
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000749 struct device_attribute *attr,
750 char *buf)
751{
752 struct net_bridge *br = to_bridge(d);
753 return sprintf(buf, "%d\n", br->vlan_enabled);
754}
755
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800756static ssize_t vlan_filtering_store(struct device *d,
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000757 struct device_attribute *attr,
758 const char *buf, size_t len)
759{
760 return store_bridge_parm(d, buf, len, br_vlan_filter_toggle);
761}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800762static DEVICE_ATTR_RW(vlan_filtering);
Toshiaki Makita204177f2014-06-10 20:59:25 +0900763
764static ssize_t vlan_protocol_show(struct device *d,
765 struct device_attribute *attr,
766 char *buf)
767{
768 struct net_bridge *br = to_bridge(d);
769 return sprintf(buf, "%#06x\n", ntohs(br->vlan_proto));
770}
771
772static ssize_t vlan_protocol_store(struct device *d,
773 struct device_attribute *attr,
774 const char *buf, size_t len)
775{
776 return store_bridge_parm(d, buf, len, br_vlan_set_proto);
777}
778static DEVICE_ATTR_RW(vlan_protocol);
Vlad Yasevich96a20d92014-10-03 11:29:16 -0400779
780static ssize_t default_pvid_show(struct device *d,
781 struct device_attribute *attr,
782 char *buf)
783{
784 struct net_bridge *br = to_bridge(d);
785 return sprintf(buf, "%d\n", br->default_pvid);
786}
787
788static ssize_t default_pvid_store(struct device *d,
789 struct device_attribute *attr,
790 const char *buf, size_t len)
791{
792 return store_bridge_parm(d, buf, len, br_vlan_set_default_pvid);
793}
794static DEVICE_ATTR_RW(default_pvid);
Nikolay Aleksandrov6dada9b2016-04-30 10:25:28 +0200795
796static ssize_t vlan_stats_enabled_show(struct device *d,
797 struct device_attribute *attr,
798 char *buf)
799{
800 struct net_bridge *br = to_bridge(d);
801 return sprintf(buf, "%u\n", br->vlan_stats_enabled);
802}
803
804static ssize_t vlan_stats_enabled_store(struct device *d,
805 struct device_attribute *attr,
806 const char *buf, size_t len)
807{
808 return store_bridge_parm(d, buf, len, br_vlan_set_stats);
809}
810static DEVICE_ATTR_RW(vlan_stats_enabled);
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000811#endif
Herbert Xu0909e112010-02-27 19:41:49 +0000812
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813static struct attribute *bridge_attrs[] = {
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700814 &dev_attr_forward_delay.attr,
815 &dev_attr_hello_time.attr,
816 &dev_attr_max_age.attr,
817 &dev_attr_ageing_time.attr,
818 &dev_attr_stp_state.attr,
stephen hemminger515853c2011-10-03 18:14:46 +0000819 &dev_attr_group_fwd_mask.attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700820 &dev_attr_priority.attr,
821 &dev_attr_bridge_id.attr,
822 &dev_attr_root_id.attr,
823 &dev_attr_root_path_cost.attr,
824 &dev_attr_root_port.attr,
825 &dev_attr_topology_change.attr,
826 &dev_attr_topology_change_detected.attr,
827 &dev_attr_hello_timer.attr,
828 &dev_attr_tcn_timer.attr,
829 &dev_attr_topology_change_timer.attr,
830 &dev_attr_gc_timer.attr,
831 &dev_attr_group_addr.attr,
Stephen Hemminger9cf63742007-04-09 12:57:54 -0700832 &dev_attr_flush.attr,
Herbert Xu0909e112010-02-27 19:41:49 +0000833#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
834 &dev_attr_multicast_router.attr,
Herbert Xu561f1102010-02-27 19:41:50 +0000835 &dev_attr_multicast_snooping.attr,
Herbert Xuc5c23262012-04-13 02:37:42 +0000836 &dev_attr_multicast_querier.attr,
Cong Wang1c8ad5b2013-05-21 21:52:54 +0000837 &dev_attr_multicast_query_use_ifaddr.attr,
Herbert Xub1951672010-02-27 19:41:51 +0000838 &dev_attr_hash_elasticity.attr,
839 &dev_attr_hash_max.attr,
Herbert Xud902eee2010-02-27 19:41:52 +0000840 &dev_attr_multicast_last_member_count.attr,
841 &dev_attr_multicast_startup_query_count.attr,
842 &dev_attr_multicast_last_member_interval.attr,
843 &dev_attr_multicast_membership_interval.attr,
844 &dev_attr_multicast_querier_interval.attr,
845 &dev_attr_multicast_query_interval.attr,
846 &dev_attr_multicast_query_response_interval.attr,
847 &dev_attr_multicast_startup_query_interval.attr,
Nikolay Aleksandrov1080ab92016-06-28 16:57:06 +0200848 &dev_attr_multicast_stats_enabled.attr,
Nikolay Aleksandrov5e923582016-11-21 13:03:24 +0100849 &dev_attr_multicast_igmp_version.attr,
Nikolay Aleksandrovaa2ae3e2016-11-21 13:03:25 +0100850#if IS_ENABLED(CONFIG_IPV6)
851 &dev_attr_multicast_mld_version.attr,
852#endif
Herbert Xu0909e112010-02-27 19:41:49 +0000853#endif
Pablo Neira Ayuso34666d42014-09-18 11:29:03 +0200854#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
Patrick McHardy4df53d82010-07-02 09:32:57 +0200855 &dev_attr_nf_call_iptables.attr,
856 &dev_attr_nf_call_ip6tables.attr,
857 &dev_attr_nf_call_arptables.attr,
858#endif
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000859#ifdef CONFIG_BRIDGE_VLAN_FILTERING
860 &dev_attr_vlan_filtering.attr,
Toshiaki Makita204177f2014-06-10 20:59:25 +0900861 &dev_attr_vlan_protocol.attr,
Vlad Yasevich96a20d92014-10-03 11:29:16 -0400862 &dev_attr_default_pvid.attr,
Nikolay Aleksandrov6dada9b2016-04-30 10:25:28 +0200863 &dev_attr_vlan_stats_enabled.attr,
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000864#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865 NULL
866};
867
868static struct attribute_group bridge_group = {
869 .name = SYSFS_BRIDGE_ATTR,
870 .attrs = bridge_attrs,
871};
872
873/*
874 * Export the forwarding information table as a binary file
875 * The records are struct __fdb_entry.
876 *
877 * Returns the number of bytes read.
878 */
Chris Wright2c3c8be2010-05-12 18:28:57 -0700879static ssize_t brforward_read(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +0800880 struct bin_attribute *bin_attr,
881 char *buf, loff_t off, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882{
Geliang Tangaeb7ed12015-12-23 20:42:21 +0800883 struct device *dev = kobj_to_dev(kobj);
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700884 struct net_bridge *br = to_bridge(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885 int n;
886
887 /* must read whole records */
888 if (off % sizeof(struct __fdb_entry) != 0)
889 return -EINVAL;
890
YOSHIFUJI Hideaki9d6f2292007-02-09 23:24:35 +0900891 n = br_fdb_fillbuf(br, buf,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892 count / sizeof(struct __fdb_entry),
893 off / sizeof(struct __fdb_entry));
894
895 if (n > 0)
896 n *= sizeof(struct __fdb_entry);
YOSHIFUJI Hideaki9d6f2292007-02-09 23:24:35 +0900897
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 return n;
899}
900
901static struct bin_attribute bridge_forward = {
902 .attr = { .name = SYSFS_BRIDGE_FDB,
Tejun Heo7b595752007-06-14 03:45:17 +0900903 .mode = S_IRUGO, },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904 .read = brforward_read,
905};
906
907/*
908 * Add entries in sysfs onto the existing network class device
909 * for the bridge.
910 * Adds a attribute group "bridge" containing tuning parameters.
911 * Binary attribute containing the forward table
912 * Sub directory to hold links to interfaces.
913 *
914 * Note: the ifobj exists only to be a subdirectory
915 * to hold links. The ifobj exists in same data structure
916 * as it's parent the bridge so reference counting works.
917 */
918int br_sysfs_addbr(struct net_device *dev)
919{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700920 struct kobject *brobj = &dev->dev.kobj;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921 struct net_bridge *br = netdev_priv(dev);
922 int err;
923
924 err = sysfs_create_group(brobj, &bridge_group);
925 if (err) {
926 pr_info("%s: can't create group %s/%s\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -0800927 __func__, dev->name, bridge_group.name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928 goto out1;
929 }
930
931 err = sysfs_create_bin_file(brobj, &bridge_forward);
932 if (err) {
Randy Dunlap1842c4b2006-10-25 23:07:37 -0700933 pr_info("%s: can't create attribute file %s/%s\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -0800934 __func__, dev->name, bridge_forward.attr.name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935 goto out2;
936 }
937
Greg Kroah-Hartman43b98c42007-12-17 15:54:39 -0400938 br->ifobj = kobject_create_and_add(SYSFS_BRIDGE_PORT_SUBDIR, brobj);
939 if (!br->ifobj) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940 pr_info("%s: can't add kobject (directory) %s/%s\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -0800941 __func__, dev->name, SYSFS_BRIDGE_PORT_SUBDIR);
Pan Bianb5958962016-12-03 19:33:23 +0800942 err = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943 goto out3;
944 }
945 return 0;
946 out3:
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700947 sysfs_remove_bin_file(&dev->dev.kobj, &bridge_forward);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948 out2:
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700949 sysfs_remove_group(&dev->dev.kobj, &bridge_group);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950 out1:
951 return err;
952
953}
954
955void br_sysfs_delbr(struct net_device *dev)
956{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700957 struct kobject *kobj = &dev->dev.kobj;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958 struct net_bridge *br = netdev_priv(dev);
959
Greg Kroah-Hartman78a2d902007-12-20 08:13:05 -0800960 kobject_put(br->ifobj);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961 sysfs_remove_bin_file(kobj, &bridge_forward);
962 sysfs_remove_group(kobj, &bridge_group);
963}