blob: 60182bef634158ec1e61346cf7d0d9284d925e8a [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);
Andy Shevchenko223b2292017-12-19 20:10:53 +0200275 return sprintf(buf, "%pM\n", br->group_addr);
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800276}
277
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800278static ssize_t group_addr_store(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700279 struct device_attribute *attr,
280 const char *buf, size_t len)
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800281{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700282 struct net_bridge *br = to_bridge(d);
Ben Hutchings4197f242012-11-01 09:10:04 +0000283 u8 new_addr[6];
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800284
Eric W. Biedermancb990502012-11-16 03:03:08 +0000285 if (!ns_capable(dev_net(br->dev)->user_ns, CAP_NET_ADMIN))
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800286 return -EPERM;
287
Andy Shevchenko223b2292017-12-19 20:10:53 +0200288 if (!mac_pton(buf, new_addr))
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800289 return -EINVAL;
290
Ben Hutchings46acc462012-11-01 09:11:11 +0000291 if (!is_link_local_ether_addr(new_addr))
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800292 return -EINVAL;
293
Joe Perchesf64f9e72009-11-29 16:55:45 -0800294 if (new_addr[5] == 1 || /* 802.3x Pause address */
295 new_addr[5] == 2 || /* 802.3ad Slow protocols */
296 new_addr[5] == 3) /* 802.1X PAE address */
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800297 return -EINVAL;
298
Toshiaki Makita204177f2014-06-10 20:59:25 +0900299 if (!rtnl_trylock())
300 return restart_syscall();
301
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800302 spin_lock_bh(&br->lock);
Andy Shevchenko223b2292017-12-19 20:10:53 +0200303 ether_addr_copy(br->group_addr, new_addr);
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800304 spin_unlock_bh(&br->lock);
Toshiaki Makita204177f2014-06-10 20:59:25 +0900305
Nikolay Aleksandrovbe3664a2018-09-26 17:01:02 +0300306 br_opt_toggle(br, BROPT_GROUP_ADDR_SET, true);
Toshiaki Makita204177f2014-06-10 20:59:25 +0900307 br_recalculate_fwd_mask(br);
Xin Long047831a2016-04-09 00:03:31 +0800308 netdev_state_change(br->dev);
Toshiaki Makita204177f2014-06-10 20:59:25 +0900309
310 rtnl_unlock();
311
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800312 return len;
313}
314
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800315static DEVICE_ATTR_RW(group_addr);
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800316
Xin Long14f31bb2016-04-09 00:03:28 +0800317static int set_flush(struct net_bridge *br, unsigned long val)
318{
319 br_fdb_flush(br);
320 return 0;
321}
322
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800323static ssize_t flush_store(struct device *d,
Stephen Hemminger9cf63742007-04-09 12:57:54 -0700324 struct device_attribute *attr,
325 const char *buf, size_t len)
326{
Xin Long14f31bb2016-04-09 00:03:28 +0800327 return store_bridge_parm(d, buf, len, set_flush);
Stephen Hemminger9cf63742007-04-09 12:57:54 -0700328}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800329static DEVICE_ATTR_WO(flush);
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800330
Herbert Xu0909e112010-02-27 19:41:49 +0000331#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800332static ssize_t multicast_router_show(struct device *d,
Herbert Xu0909e112010-02-27 19:41:49 +0000333 struct device_attribute *attr, char *buf)
334{
335 struct net_bridge *br = to_bridge(d);
336 return sprintf(buf, "%d\n", br->multicast_router);
337}
338
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800339static ssize_t multicast_router_store(struct device *d,
Herbert Xu0909e112010-02-27 19:41:49 +0000340 struct device_attribute *attr,
341 const char *buf, size_t len)
342{
343 return store_bridge_parm(d, buf, len, br_multicast_set_router);
344}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800345static DEVICE_ATTR_RW(multicast_router);
Herbert Xu561f1102010-02-27 19:41:50 +0000346
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800347static ssize_t multicast_snooping_show(struct device *d,
Herbert Xu561f1102010-02-27 19:41:50 +0000348 struct device_attribute *attr,
349 char *buf)
350{
351 struct net_bridge *br = to_bridge(d);
Nikolay Aleksandrov13cefad2018-09-26 17:01:03 +0300352 return sprintf(buf, "%d\n", br_opt_get(br, BROPT_MULTICAST_ENABLED));
Herbert Xu561f1102010-02-27 19:41:50 +0000353}
354
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800355static ssize_t multicast_snooping_store(struct device *d,
Herbert Xu561f1102010-02-27 19:41:50 +0000356 struct device_attribute *attr,
357 const char *buf, size_t len)
358{
359 return store_bridge_parm(d, buf, len, br_multicast_toggle);
360}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800361static DEVICE_ATTR_RW(multicast_snooping);
Herbert Xub1951672010-02-27 19:41:51 +0000362
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800363static ssize_t multicast_query_use_ifaddr_show(struct device *d,
364 struct device_attribute *attr,
365 char *buf)
Cong Wang1c8ad5b2013-05-21 21:52:54 +0000366{
367 struct net_bridge *br = to_bridge(d);
Nikolay Aleksandrov675779a2018-09-26 17:01:04 +0300368 return sprintf(buf, "%d\n",
369 br_opt_get(br, BROPT_MULTICAST_QUERY_USE_IFADDR));
Cong Wang1c8ad5b2013-05-21 21:52:54 +0000370}
371
372static int set_query_use_ifaddr(struct net_bridge *br, unsigned long val)
373{
Nikolay Aleksandrov675779a2018-09-26 17:01:04 +0300374 br_opt_toggle(br, BROPT_MULTICAST_QUERY_USE_IFADDR, !!val);
Cong Wang1c8ad5b2013-05-21 21:52:54 +0000375 return 0;
376}
377
378static ssize_t
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800379multicast_query_use_ifaddr_store(struct device *d,
Cong Wang1c8ad5b2013-05-21 21:52:54 +0000380 struct device_attribute *attr,
381 const char *buf, size_t len)
382{
383 return store_bridge_parm(d, buf, len, set_query_use_ifaddr);
384}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800385static DEVICE_ATTR_RW(multicast_query_use_ifaddr);
Cong Wang1c8ad5b2013-05-21 21:52:54 +0000386
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800387static ssize_t multicast_querier_show(struct device *d,
Herbert Xuc5c23262012-04-13 02:37:42 +0000388 struct device_attribute *attr,
389 char *buf)
390{
391 struct net_bridge *br = to_bridge(d);
Nikolay Aleksandrov675779a2018-09-26 17:01:04 +0300392 return sprintf(buf, "%d\n", br_opt_get(br, BROPT_MULTICAST_QUERIER));
Herbert Xuc5c23262012-04-13 02:37:42 +0000393}
394
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800395static ssize_t multicast_querier_store(struct device *d,
Herbert Xuc5c23262012-04-13 02:37:42 +0000396 struct device_attribute *attr,
397 const char *buf, size_t len)
398{
399 return store_bridge_parm(d, buf, len, br_multicast_set_querier);
400}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800401static DEVICE_ATTR_RW(multicast_querier);
Herbert Xuc5c23262012-04-13 02:37:42 +0000402
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800403static ssize_t hash_elasticity_show(struct device *d,
Herbert Xub1951672010-02-27 19:41:51 +0000404 struct device_attribute *attr, char *buf)
405{
406 struct net_bridge *br = to_bridge(d);
407 return sprintf(buf, "%u\n", br->hash_elasticity);
408}
409
410static int set_elasticity(struct net_bridge *br, unsigned long val)
411{
412 br->hash_elasticity = val;
413 return 0;
414}
415
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800416static ssize_t hash_elasticity_store(struct device *d,
Herbert Xub1951672010-02-27 19:41:51 +0000417 struct device_attribute *attr,
418 const char *buf, size_t len)
419{
420 return store_bridge_parm(d, buf, len, set_elasticity);
421}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800422static DEVICE_ATTR_RW(hash_elasticity);
Herbert Xub1951672010-02-27 19:41:51 +0000423
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800424static ssize_t hash_max_show(struct device *d, struct device_attribute *attr,
Herbert Xub1951672010-02-27 19:41:51 +0000425 char *buf)
426{
427 struct net_bridge *br = to_bridge(d);
428 return sprintf(buf, "%u\n", br->hash_max);
429}
430
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800431static ssize_t hash_max_store(struct device *d, struct device_attribute *attr,
Herbert Xub1951672010-02-27 19:41:51 +0000432 const char *buf, size_t len)
433{
434 return store_bridge_parm(d, buf, len, br_multicast_set_hash_max);
435}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800436static DEVICE_ATTR_RW(hash_max);
Herbert Xud902eee2010-02-27 19:41:52 +0000437
Nikolay Aleksandrov5e923582016-11-21 13:03:24 +0100438static ssize_t multicast_igmp_version_show(struct device *d,
439 struct device_attribute *attr,
440 char *buf)
441{
442 struct net_bridge *br = to_bridge(d);
443
444 return sprintf(buf, "%u\n", br->multicast_igmp_version);
445}
446
447static ssize_t multicast_igmp_version_store(struct device *d,
448 struct device_attribute *attr,
449 const char *buf, size_t len)
450{
451 return store_bridge_parm(d, buf, len, br_multicast_set_igmp_version);
452}
453static DEVICE_ATTR_RW(multicast_igmp_version);
454
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800455static ssize_t multicast_last_member_count_show(struct device *d,
Herbert Xud902eee2010-02-27 19:41:52 +0000456 struct device_attribute *attr,
457 char *buf)
458{
459 struct net_bridge *br = to_bridge(d);
460 return sprintf(buf, "%u\n", br->multicast_last_member_count);
461}
462
463static int set_last_member_count(struct net_bridge *br, unsigned long val)
464{
465 br->multicast_last_member_count = val;
466 return 0;
467}
468
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800469static ssize_t multicast_last_member_count_store(struct device *d,
Herbert Xud902eee2010-02-27 19:41:52 +0000470 struct device_attribute *attr,
471 const char *buf, size_t len)
472{
473 return store_bridge_parm(d, buf, len, set_last_member_count);
474}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800475static DEVICE_ATTR_RW(multicast_last_member_count);
Herbert Xud902eee2010-02-27 19:41:52 +0000476
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800477static ssize_t multicast_startup_query_count_show(
Herbert Xud902eee2010-02-27 19:41:52 +0000478 struct device *d, struct device_attribute *attr, char *buf)
479{
480 struct net_bridge *br = to_bridge(d);
481 return sprintf(buf, "%u\n", br->multicast_startup_query_count);
482}
483
484static int set_startup_query_count(struct net_bridge *br, unsigned long val)
485{
486 br->multicast_startup_query_count = val;
487 return 0;
488}
489
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800490static ssize_t multicast_startup_query_count_store(
Herbert Xud902eee2010-02-27 19:41:52 +0000491 struct device *d, struct device_attribute *attr, const char *buf,
492 size_t len)
493{
494 return store_bridge_parm(d, buf, len, set_startup_query_count);
495}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800496static DEVICE_ATTR_RW(multicast_startup_query_count);
Herbert Xud902eee2010-02-27 19:41:52 +0000497
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800498static ssize_t multicast_last_member_interval_show(
Herbert Xud902eee2010-02-27 19:41:52 +0000499 struct device *d, struct device_attribute *attr, char *buf)
500{
501 struct net_bridge *br = to_bridge(d);
502 return sprintf(buf, "%lu\n",
503 jiffies_to_clock_t(br->multicast_last_member_interval));
504}
505
506static int set_last_member_interval(struct net_bridge *br, unsigned long val)
507{
508 br->multicast_last_member_interval = clock_t_to_jiffies(val);
509 return 0;
510}
511
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800512static ssize_t multicast_last_member_interval_store(
Herbert Xud902eee2010-02-27 19:41:52 +0000513 struct device *d, struct device_attribute *attr, const char *buf,
514 size_t len)
515{
516 return store_bridge_parm(d, buf, len, set_last_member_interval);
517}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800518static DEVICE_ATTR_RW(multicast_last_member_interval);
Herbert Xud902eee2010-02-27 19:41:52 +0000519
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800520static ssize_t multicast_membership_interval_show(
Herbert Xud902eee2010-02-27 19:41:52 +0000521 struct device *d, struct device_attribute *attr, char *buf)
522{
523 struct net_bridge *br = to_bridge(d);
524 return sprintf(buf, "%lu\n",
525 jiffies_to_clock_t(br->multicast_membership_interval));
526}
527
528static int set_membership_interval(struct net_bridge *br, unsigned long val)
529{
530 br->multicast_membership_interval = clock_t_to_jiffies(val);
531 return 0;
532}
533
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800534static ssize_t multicast_membership_interval_store(
Herbert Xud902eee2010-02-27 19:41:52 +0000535 struct device *d, struct device_attribute *attr, const char *buf,
536 size_t len)
537{
538 return store_bridge_parm(d, buf, len, set_membership_interval);
539}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800540static DEVICE_ATTR_RW(multicast_membership_interval);
Herbert Xud902eee2010-02-27 19:41:52 +0000541
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800542static ssize_t multicast_querier_interval_show(struct device *d,
Herbert Xud902eee2010-02-27 19:41:52 +0000543 struct device_attribute *attr,
544 char *buf)
545{
546 struct net_bridge *br = to_bridge(d);
547 return sprintf(buf, "%lu\n",
548 jiffies_to_clock_t(br->multicast_querier_interval));
549}
550
551static int set_querier_interval(struct net_bridge *br, unsigned long val)
552{
553 br->multicast_querier_interval = clock_t_to_jiffies(val);
554 return 0;
555}
556
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800557static ssize_t multicast_querier_interval_store(struct device *d,
Herbert Xud902eee2010-02-27 19:41:52 +0000558 struct device_attribute *attr,
559 const char *buf, size_t len)
560{
561 return store_bridge_parm(d, buf, len, set_querier_interval);
562}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800563static DEVICE_ATTR_RW(multicast_querier_interval);
Herbert Xud902eee2010-02-27 19:41:52 +0000564
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800565static ssize_t multicast_query_interval_show(struct device *d,
Herbert Xud902eee2010-02-27 19:41:52 +0000566 struct device_attribute *attr,
567 char *buf)
568{
569 struct net_bridge *br = to_bridge(d);
570 return sprintf(buf, "%lu\n",
571 jiffies_to_clock_t(br->multicast_query_interval));
572}
573
574static int set_query_interval(struct net_bridge *br, unsigned long val)
575{
576 br->multicast_query_interval = clock_t_to_jiffies(val);
577 return 0;
578}
579
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800580static ssize_t multicast_query_interval_store(struct device *d,
Herbert Xud902eee2010-02-27 19:41:52 +0000581 struct device_attribute *attr,
582 const char *buf, size_t len)
583{
584 return store_bridge_parm(d, buf, len, set_query_interval);
585}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800586static DEVICE_ATTR_RW(multicast_query_interval);
Herbert Xud902eee2010-02-27 19:41:52 +0000587
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800588static ssize_t multicast_query_response_interval_show(
Herbert Xud902eee2010-02-27 19:41:52 +0000589 struct device *d, struct device_attribute *attr, char *buf)
590{
591 struct net_bridge *br = to_bridge(d);
592 return sprintf(
593 buf, "%lu\n",
594 jiffies_to_clock_t(br->multicast_query_response_interval));
595}
596
597static int set_query_response_interval(struct net_bridge *br, unsigned long val)
598{
599 br->multicast_query_response_interval = clock_t_to_jiffies(val);
600 return 0;
601}
602
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800603static ssize_t multicast_query_response_interval_store(
Herbert Xud902eee2010-02-27 19:41:52 +0000604 struct device *d, struct device_attribute *attr, const char *buf,
605 size_t len)
606{
607 return store_bridge_parm(d, buf, len, set_query_response_interval);
608}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800609static DEVICE_ATTR_RW(multicast_query_response_interval);
Herbert Xud902eee2010-02-27 19:41:52 +0000610
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800611static ssize_t multicast_startup_query_interval_show(
Herbert Xud902eee2010-02-27 19:41:52 +0000612 struct device *d, struct device_attribute *attr, char *buf)
613{
614 struct net_bridge *br = to_bridge(d);
615 return sprintf(
616 buf, "%lu\n",
617 jiffies_to_clock_t(br->multicast_startup_query_interval));
618}
619
620static int set_startup_query_interval(struct net_bridge *br, unsigned long val)
621{
622 br->multicast_startup_query_interval = clock_t_to_jiffies(val);
623 return 0;
624}
625
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800626static ssize_t multicast_startup_query_interval_store(
Herbert Xud902eee2010-02-27 19:41:52 +0000627 struct device *d, struct device_attribute *attr, const char *buf,
628 size_t len)
629{
630 return store_bridge_parm(d, buf, len, set_startup_query_interval);
631}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800632static DEVICE_ATTR_RW(multicast_startup_query_interval);
Nikolay Aleksandrov1080ab92016-06-28 16:57:06 +0200633
634static ssize_t multicast_stats_enabled_show(struct device *d,
635 struct device_attribute *attr,
636 char *buf)
637{
638 struct net_bridge *br = to_bridge(d);
639
Nikolay Aleksandrov675779a2018-09-26 17:01:04 +0300640 return sprintf(buf, "%d\n",
641 br_opt_get(br, BROPT_MULTICAST_STATS_ENABLED));
Nikolay Aleksandrov1080ab92016-06-28 16:57:06 +0200642}
643
644static int set_stats_enabled(struct net_bridge *br, unsigned long val)
645{
Nikolay Aleksandrov675779a2018-09-26 17:01:04 +0300646 br_opt_toggle(br, BROPT_MULTICAST_STATS_ENABLED, !!val);
Nikolay Aleksandrov1080ab92016-06-28 16:57:06 +0200647 return 0;
648}
649
650static ssize_t multicast_stats_enabled_store(struct device *d,
651 struct device_attribute *attr,
652 const char *buf,
653 size_t len)
654{
655 return store_bridge_parm(d, buf, len, set_stats_enabled);
656}
657static DEVICE_ATTR_RW(multicast_stats_enabled);
Nikolay Aleksandrovaa2ae3e2016-11-21 13:03:25 +0100658
659#if IS_ENABLED(CONFIG_IPV6)
660static ssize_t multicast_mld_version_show(struct device *d,
661 struct device_attribute *attr,
662 char *buf)
663{
664 struct net_bridge *br = to_bridge(d);
665
666 return sprintf(buf, "%u\n", br->multicast_mld_version);
667}
668
669static ssize_t multicast_mld_version_store(struct device *d,
670 struct device_attribute *attr,
671 const char *buf, size_t len)
672{
673 return store_bridge_parm(d, buf, len, br_multicast_set_mld_version);
674}
675static DEVICE_ATTR_RW(multicast_mld_version);
676#endif
Herbert Xu0909e112010-02-27 19:41:49 +0000677#endif
Pablo Neira Ayuso34666d42014-09-18 11:29:03 +0200678#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800679static ssize_t nf_call_iptables_show(
Patrick McHardy4df53d82010-07-02 09:32:57 +0200680 struct device *d, struct device_attribute *attr, char *buf)
681{
682 struct net_bridge *br = to_bridge(d);
Nikolay Aleksandrov8df35102018-09-26 17:01:01 +0300683 return sprintf(buf, "%u\n", br_opt_get(br, BROPT_NF_CALL_IPTABLES));
Patrick McHardy4df53d82010-07-02 09:32:57 +0200684}
685
686static int set_nf_call_iptables(struct net_bridge *br, unsigned long val)
687{
Nikolay Aleksandrov8df35102018-09-26 17:01:01 +0300688 br_opt_toggle(br, BROPT_NF_CALL_IPTABLES, !!val);
Patrick McHardy4df53d82010-07-02 09:32:57 +0200689 return 0;
690}
691
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800692static ssize_t nf_call_iptables_store(
Patrick McHardy4df53d82010-07-02 09:32:57 +0200693 struct device *d, struct device_attribute *attr, const char *buf,
694 size_t len)
695{
696 return store_bridge_parm(d, buf, len, set_nf_call_iptables);
697}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800698static DEVICE_ATTR_RW(nf_call_iptables);
Patrick McHardy4df53d82010-07-02 09:32:57 +0200699
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800700static ssize_t nf_call_ip6tables_show(
Patrick McHardy4df53d82010-07-02 09:32:57 +0200701 struct device *d, struct device_attribute *attr, char *buf)
702{
703 struct net_bridge *br = to_bridge(d);
Nikolay Aleksandrov8df35102018-09-26 17:01:01 +0300704 return sprintf(buf, "%u\n", br_opt_get(br, BROPT_NF_CALL_IP6TABLES));
Patrick McHardy4df53d82010-07-02 09:32:57 +0200705}
706
707static int set_nf_call_ip6tables(struct net_bridge *br, unsigned long val)
708{
Nikolay Aleksandrov8df35102018-09-26 17:01:01 +0300709 br_opt_toggle(br, BROPT_NF_CALL_IP6TABLES, !!val);
Patrick McHardy4df53d82010-07-02 09:32:57 +0200710 return 0;
711}
712
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800713static ssize_t nf_call_ip6tables_store(
Patrick McHardy4df53d82010-07-02 09:32:57 +0200714 struct device *d, struct device_attribute *attr, const char *buf,
715 size_t len)
716{
717 return store_bridge_parm(d, buf, len, set_nf_call_ip6tables);
718}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800719static DEVICE_ATTR_RW(nf_call_ip6tables);
Patrick McHardy4df53d82010-07-02 09:32:57 +0200720
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800721static ssize_t nf_call_arptables_show(
Patrick McHardy4df53d82010-07-02 09:32:57 +0200722 struct device *d, struct device_attribute *attr, char *buf)
723{
724 struct net_bridge *br = to_bridge(d);
Nikolay Aleksandrov8df35102018-09-26 17:01:01 +0300725 return sprintf(buf, "%u\n", br_opt_get(br, BROPT_NF_CALL_ARPTABLES));
Patrick McHardy4df53d82010-07-02 09:32:57 +0200726}
727
728static int set_nf_call_arptables(struct net_bridge *br, unsigned long val)
729{
Nikolay Aleksandrov8df35102018-09-26 17:01:01 +0300730 br_opt_toggle(br, BROPT_NF_CALL_ARPTABLES, !!val);
Patrick McHardy4df53d82010-07-02 09:32:57 +0200731 return 0;
732}
733
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800734static ssize_t nf_call_arptables_store(
Patrick McHardy4df53d82010-07-02 09:32:57 +0200735 struct device *d, struct device_attribute *attr, const char *buf,
736 size_t len)
737{
738 return store_bridge_parm(d, buf, len, set_nf_call_arptables);
739}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800740static DEVICE_ATTR_RW(nf_call_arptables);
Patrick McHardy4df53d82010-07-02 09:32:57 +0200741#endif
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000742#ifdef CONFIG_BRIDGE_VLAN_FILTERING
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800743static ssize_t vlan_filtering_show(struct device *d,
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000744 struct device_attribute *attr,
745 char *buf)
746{
747 struct net_bridge *br = to_bridge(d);
Nikolay Aleksandrovae757672018-09-26 17:01:00 +0300748 return sprintf(buf, "%d\n", br_opt_get(br, BROPT_VLAN_ENABLED));
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000749}
750
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800751static ssize_t vlan_filtering_store(struct device *d,
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000752 struct device_attribute *attr,
753 const char *buf, size_t len)
754{
755 return store_bridge_parm(d, buf, len, br_vlan_filter_toggle);
756}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800757static DEVICE_ATTR_RW(vlan_filtering);
Toshiaki Makita204177f2014-06-10 20:59:25 +0900758
759static ssize_t vlan_protocol_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, "%#06x\n", ntohs(br->vlan_proto));
765}
766
767static ssize_t vlan_protocol_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_proto);
772}
773static DEVICE_ATTR_RW(vlan_protocol);
Vlad Yasevich96a20d92014-10-03 11:29:16 -0400774
775static ssize_t default_pvid_show(struct device *d,
776 struct device_attribute *attr,
777 char *buf)
778{
779 struct net_bridge *br = to_bridge(d);
780 return sprintf(buf, "%d\n", br->default_pvid);
781}
782
783static ssize_t default_pvid_store(struct device *d,
784 struct device_attribute *attr,
785 const char *buf, size_t len)
786{
787 return store_bridge_parm(d, buf, len, br_vlan_set_default_pvid);
788}
789static DEVICE_ATTR_RW(default_pvid);
Nikolay Aleksandrov6dada9b2016-04-30 10:25:28 +0200790
791static ssize_t vlan_stats_enabled_show(struct device *d,
792 struct device_attribute *attr,
793 char *buf)
794{
795 struct net_bridge *br = to_bridge(d);
Nikolay Aleksandrovae757672018-09-26 17:01:00 +0300796 return sprintf(buf, "%u\n", br_opt_get(br, BROPT_VLAN_STATS_ENABLED));
Nikolay Aleksandrov6dada9b2016-04-30 10:25:28 +0200797}
798
799static ssize_t vlan_stats_enabled_store(struct device *d,
800 struct device_attribute *attr,
801 const char *buf, size_t len)
802{
803 return store_bridge_parm(d, buf, len, br_vlan_set_stats);
804}
805static DEVICE_ATTR_RW(vlan_stats_enabled);
Nikolay Aleksandrov9163a0f2018-10-12 13:41:16 +0300806
807static ssize_t vlan_stats_per_port_show(struct device *d,
808 struct device_attribute *attr,
809 char *buf)
810{
811 struct net_bridge *br = to_bridge(d);
812 return sprintf(buf, "%u\n", br_opt_get(br, BROPT_VLAN_STATS_PER_PORT));
813}
814
815static ssize_t vlan_stats_per_port_store(struct device *d,
816 struct device_attribute *attr,
817 const char *buf, size_t len)
818{
819 return store_bridge_parm(d, buf, len, br_vlan_set_stats_per_port);
820}
821static DEVICE_ATTR_RW(vlan_stats_per_port);
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000822#endif
Herbert Xu0909e112010-02-27 19:41:49 +0000823
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824static struct attribute *bridge_attrs[] = {
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700825 &dev_attr_forward_delay.attr,
826 &dev_attr_hello_time.attr,
827 &dev_attr_max_age.attr,
828 &dev_attr_ageing_time.attr,
829 &dev_attr_stp_state.attr,
stephen hemminger515853c2011-10-03 18:14:46 +0000830 &dev_attr_group_fwd_mask.attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700831 &dev_attr_priority.attr,
832 &dev_attr_bridge_id.attr,
833 &dev_attr_root_id.attr,
834 &dev_attr_root_path_cost.attr,
835 &dev_attr_root_port.attr,
836 &dev_attr_topology_change.attr,
837 &dev_attr_topology_change_detected.attr,
838 &dev_attr_hello_timer.attr,
839 &dev_attr_tcn_timer.attr,
840 &dev_attr_topology_change_timer.attr,
841 &dev_attr_gc_timer.attr,
842 &dev_attr_group_addr.attr,
Stephen Hemminger9cf63742007-04-09 12:57:54 -0700843 &dev_attr_flush.attr,
Herbert Xu0909e112010-02-27 19:41:49 +0000844#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
845 &dev_attr_multicast_router.attr,
Herbert Xu561f1102010-02-27 19:41:50 +0000846 &dev_attr_multicast_snooping.attr,
Herbert Xuc5c23262012-04-13 02:37:42 +0000847 &dev_attr_multicast_querier.attr,
Cong Wang1c8ad5b2013-05-21 21:52:54 +0000848 &dev_attr_multicast_query_use_ifaddr.attr,
Herbert Xub1951672010-02-27 19:41:51 +0000849 &dev_attr_hash_elasticity.attr,
850 &dev_attr_hash_max.attr,
Herbert Xud902eee2010-02-27 19:41:52 +0000851 &dev_attr_multicast_last_member_count.attr,
852 &dev_attr_multicast_startup_query_count.attr,
853 &dev_attr_multicast_last_member_interval.attr,
854 &dev_attr_multicast_membership_interval.attr,
855 &dev_attr_multicast_querier_interval.attr,
856 &dev_attr_multicast_query_interval.attr,
857 &dev_attr_multicast_query_response_interval.attr,
858 &dev_attr_multicast_startup_query_interval.attr,
Nikolay Aleksandrov1080ab92016-06-28 16:57:06 +0200859 &dev_attr_multicast_stats_enabled.attr,
Nikolay Aleksandrov5e923582016-11-21 13:03:24 +0100860 &dev_attr_multicast_igmp_version.attr,
Nikolay Aleksandrovaa2ae3e2016-11-21 13:03:25 +0100861#if IS_ENABLED(CONFIG_IPV6)
862 &dev_attr_multicast_mld_version.attr,
863#endif
Herbert Xu0909e112010-02-27 19:41:49 +0000864#endif
Pablo Neira Ayuso34666d42014-09-18 11:29:03 +0200865#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
Patrick McHardy4df53d82010-07-02 09:32:57 +0200866 &dev_attr_nf_call_iptables.attr,
867 &dev_attr_nf_call_ip6tables.attr,
868 &dev_attr_nf_call_arptables.attr,
869#endif
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000870#ifdef CONFIG_BRIDGE_VLAN_FILTERING
871 &dev_attr_vlan_filtering.attr,
Toshiaki Makita204177f2014-06-10 20:59:25 +0900872 &dev_attr_vlan_protocol.attr,
Vlad Yasevich96a20d92014-10-03 11:29:16 -0400873 &dev_attr_default_pvid.attr,
Nikolay Aleksandrov6dada9b2016-04-30 10:25:28 +0200874 &dev_attr_vlan_stats_enabled.attr,
Nikolay Aleksandrov9163a0f2018-10-12 13:41:16 +0300875 &dev_attr_vlan_stats_per_port.attr,
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000876#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877 NULL
878};
879
Arvind Yadavcddbb792017-06-29 16:39:38 +0530880static const struct attribute_group bridge_group = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881 .name = SYSFS_BRIDGE_ATTR,
882 .attrs = bridge_attrs,
883};
884
885/*
886 * Export the forwarding information table as a binary file
887 * The records are struct __fdb_entry.
888 *
889 * Returns the number of bytes read.
890 */
Chris Wright2c3c8be2010-05-12 18:28:57 -0700891static ssize_t brforward_read(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +0800892 struct bin_attribute *bin_attr,
893 char *buf, loff_t off, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894{
Geliang Tangaeb7ed12015-12-23 20:42:21 +0800895 struct device *dev = kobj_to_dev(kobj);
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700896 struct net_bridge *br = to_bridge(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897 int n;
898
899 /* must read whole records */
900 if (off % sizeof(struct __fdb_entry) != 0)
901 return -EINVAL;
902
YOSHIFUJI Hideaki9d6f2292007-02-09 23:24:35 +0900903 n = br_fdb_fillbuf(br, buf,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904 count / sizeof(struct __fdb_entry),
905 off / sizeof(struct __fdb_entry));
906
907 if (n > 0)
908 n *= sizeof(struct __fdb_entry);
YOSHIFUJI Hideaki9d6f2292007-02-09 23:24:35 +0900909
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910 return n;
911}
912
913static struct bin_attribute bridge_forward = {
914 .attr = { .name = SYSFS_BRIDGE_FDB,
Joe Perchesd6444062018-03-23 15:54:38 -0700915 .mode = 0444, },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916 .read = brforward_read,
917};
918
919/*
920 * Add entries in sysfs onto the existing network class device
921 * for the bridge.
922 * Adds a attribute group "bridge" containing tuning parameters.
923 * Binary attribute containing the forward table
924 * Sub directory to hold links to interfaces.
925 *
926 * Note: the ifobj exists only to be a subdirectory
927 * to hold links. The ifobj exists in same data structure
928 * as it's parent the bridge so reference counting works.
929 */
930int br_sysfs_addbr(struct net_device *dev)
931{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700932 struct kobject *brobj = &dev->dev.kobj;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933 struct net_bridge *br = netdev_priv(dev);
934 int err;
935
936 err = sysfs_create_group(brobj, &bridge_group);
937 if (err) {
938 pr_info("%s: can't create group %s/%s\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -0800939 __func__, dev->name, bridge_group.name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940 goto out1;
941 }
942
943 err = sysfs_create_bin_file(brobj, &bridge_forward);
944 if (err) {
Randy Dunlap1842c4b2006-10-25 23:07:37 -0700945 pr_info("%s: can't create attribute file %s/%s\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -0800946 __func__, dev->name, bridge_forward.attr.name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947 goto out2;
948 }
949
Greg Kroah-Hartman43b98c42007-12-17 15:54:39 -0400950 br->ifobj = kobject_create_and_add(SYSFS_BRIDGE_PORT_SUBDIR, brobj);
951 if (!br->ifobj) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952 pr_info("%s: can't add kobject (directory) %s/%s\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -0800953 __func__, dev->name, SYSFS_BRIDGE_PORT_SUBDIR);
Pan Bianb5958962016-12-03 19:33:23 +0800954 err = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955 goto out3;
956 }
957 return 0;
958 out3:
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700959 sysfs_remove_bin_file(&dev->dev.kobj, &bridge_forward);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960 out2:
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700961 sysfs_remove_group(&dev->dev.kobj, &bridge_group);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962 out1:
963 return err;
964
965}
966
967void br_sysfs_delbr(struct net_device *dev)
968{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700969 struct kobject *kobj = &dev->dev.kobj;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970 struct net_bridge *br = netdev_priv(dev);
971
Greg Kroah-Hartman78a2d902007-12-20 08:13:05 -0800972 kobject_put(br->ifobj);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973 sysfs_remove_bin_file(kobj, &bridge_forward);
974 sysfs_remove_group(kobj, &bridge_group);
975}