blob: 08e31debd6f2f0ddb1a598cefa64c69942e88d0f [file] [log] [blame]
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
Wang Sheng-Hui15401942013-08-06 08:44:46 +08003 * Sysfs attributes of bridge
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * Linux ethernet bridge
5 *
6 * Authors:
7 * Stephen Hemminger <shemminger@osdl.org>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 */
9
Randy Dunlap4fc268d2006-01-11 12:17:47 -080010#include <linux/capability.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#include <linux/kernel.h>
12#include <linux/netdevice.h>
John Fastabendb3343a22012-09-18 00:01:12 +000013#include <linux/etherdevice.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/if_bridge.h>
15#include <linux/rtnetlink.h>
16#include <linux/spinlock.h>
17#include <linux/times.h>
Ingo Molnar174cd4b2017-02-02 19:15:33 +010018#include <linux/sched/signal.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019
20#include "br_private.h"
21
Nikolay Aleksandrov1e16f382021-01-29 13:51:42 +020022/* IMPORTANT: new bridge options must be added with netlink support only
23 * please do not add new sysfs entries
24 */
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,
Vladimir Oltean9e781402021-02-13 22:43:16 +020033 int (*set)(struct net_bridge *br, unsigned long val,
34 struct netlink_ext_ack *extack))
Linus Torvalds1da177e2005-04-16 15:20:36 -070035{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -070036 struct net_bridge *br = to_bridge(d);
Vladimir Oltean9e781402021-02-13 22:43:16 +020037 struct netlink_ext_ack extack = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 unsigned long val;
Vladimir Oltean9e781402021-02-13 22:43:16 +020039 char *endp;
Stephen Hemminger8d4698f72008-09-08 13:44:40 -070040 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
Eric W. Biedermancb990502012-11-16 03:03:08 +000042 if (!ns_capable(dev_net(br->dev)->user_ns, CAP_NET_ADMIN))
Linus Torvalds1da177e2005-04-16 15:20:36 -070043 return -EPERM;
44
45 val = simple_strtoul(buf, &endp, 0);
46 if (endp == buf)
47 return -EINVAL;
48
Xin Long047831a2016-04-09 00:03:31 +080049 if (!rtnl_trylock())
50 return restart_syscall();
51
Vladimir Oltean9e781402021-02-13 22:43:16 +020052 err = (*set)(br, val, &extack);
Xin Long047831a2016-04-09 00:03:31 +080053 if (!err)
54 netdev_state_change(br->dev);
Vladimir Oltean9e781402021-02-13 22:43:16 +020055 if (extack._msg) {
56 if (err)
57 br_err(br, "%s\n", extack._msg);
58 else
59 br_warn(br, "%s\n", extack._msg);
60 }
Xin Long047831a2016-04-09 00:03:31 +080061 rtnl_unlock();
62
Stephen Hemminger8d4698f72008-09-08 13:44:40 -070063 return err ? err : len;
Linus Torvalds1da177e2005-04-16 15:20:36 -070064}
65
66
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -080067static ssize_t forward_delay_show(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -070068 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -070069{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -070070 struct net_bridge *br = to_bridge(d);
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 return sprintf(buf, "%lu\n", jiffies_to_clock_t(br->forward_delay));
72}
73
Vladimir Oltean9e781402021-02-13 22:43:16 +020074static int set_forward_delay(struct net_bridge *br, unsigned long val,
75 struct netlink_ext_ack *extack)
76{
77 return br_set_forward_delay(br, val);
78}
79
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -080080static ssize_t forward_delay_store(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -070081 struct device_attribute *attr,
82 const char *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -070083{
Vladimir Oltean9e781402021-02-13 22:43:16 +020084 return store_bridge_parm(d, buf, len, set_forward_delay);
Linus Torvalds1da177e2005-04-16 15:20:36 -070085}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -080086static DEVICE_ATTR_RW(forward_delay);
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -080088static ssize_t hello_time_show(struct device *d, struct device_attribute *attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -070089 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -070090{
91 return sprintf(buf, "%lu\n",
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -070092 jiffies_to_clock_t(to_bridge(d)->hello_time));
Linus Torvalds1da177e2005-04-16 15:20:36 -070093}
94
Vladimir Oltean9e781402021-02-13 22:43:16 +020095static int set_hello_time(struct net_bridge *br, unsigned long val,
96 struct netlink_ext_ack *extack)
97{
98 return br_set_hello_time(br, val);
99}
100
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800101static ssize_t hello_time_store(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700102 struct device_attribute *attr, const char *buf,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 size_t len)
104{
Vladimir Oltean9e781402021-02-13 22:43:16 +0200105 return store_bridge_parm(d, buf, len, set_hello_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800107static DEVICE_ATTR_RW(hello_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800109static ssize_t max_age_show(struct device *d, struct device_attribute *attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700110 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111{
112 return sprintf(buf, "%lu\n",
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700113 jiffies_to_clock_t(to_bridge(d)->max_age));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114}
115
Vladimir Oltean9e781402021-02-13 22:43:16 +0200116static int set_max_age(struct net_bridge *br, unsigned long val,
117 struct netlink_ext_ack *extack)
118{
119 return br_set_max_age(br, val);
120}
121
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800122static ssize_t max_age_store(struct device *d, struct device_attribute *attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700123 const char *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124{
Vladimir Oltean9e781402021-02-13 22:43:16 +0200125 return store_bridge_parm(d, buf, len, set_max_age);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800127static DEVICE_ATTR_RW(max_age);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800129static ssize_t ageing_time_show(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700130 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700132 struct net_bridge *br = to_bridge(d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 return sprintf(buf, "%lu\n", jiffies_to_clock_t(br->ageing_time));
134}
135
Vladimir Oltean9e781402021-02-13 22:43:16 +0200136static int set_ageing_time(struct net_bridge *br, unsigned long val,
137 struct netlink_ext_ack *extack)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138{
Xin Long047831a2016-04-09 00:03:31 +0800139 return br_set_ageing_time(br, val);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140}
141
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800142static ssize_t ageing_time_store(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700143 struct device_attribute *attr,
144 const char *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700146 return store_bridge_parm(d, buf, len, set_ageing_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800148static DEVICE_ATTR_RW(ageing_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800150static ssize_t stp_state_show(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700151 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700153 struct net_bridge *br = to_bridge(d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 return sprintf(buf, "%d\n", br->stp_enabled);
155}
156
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157
Vladimir Oltean9e781402021-02-13 22:43:16 +0200158static int set_stp_state(struct net_bridge *br, unsigned long val,
159 struct netlink_ext_ack *extack)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160{
Vladimir Oltean9e781402021-02-13 22:43:16 +0200161 return br_stp_set_enabled(br, val, extack);
Xin Long44361562016-04-09 00:03:30 +0800162}
163
164static ssize_t stp_state_store(struct device *d,
165 struct device_attribute *attr, const char *buf,
166 size_t len)
167{
168 return store_bridge_parm(d, buf, len, set_stp_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800170static DEVICE_ATTR_RW(stp_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800172static ssize_t group_fwd_mask_show(struct device *d,
173 struct device_attribute *attr,
174 char *buf)
stephen hemminger515853c2011-10-03 18:14:46 +0000175{
176 struct net_bridge *br = to_bridge(d);
177 return sprintf(buf, "%#x\n", br->group_fwd_mask);
178}
179
Vladimir Oltean9e781402021-02-13 22:43:16 +0200180static int set_group_fwd_mask(struct net_bridge *br, unsigned long val,
181 struct netlink_ext_ack *extack)
Xin Long347db6b2016-04-09 00:03:29 +0800182{
183 if (val & BR_GROUPFWD_RESTRICTED)
184 return -EINVAL;
185
186 br->group_fwd_mask = val;
187
188 return 0;
189}
stephen hemminger515853c2011-10-03 18:14:46 +0000190
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800191static ssize_t group_fwd_mask_store(struct device *d,
192 struct device_attribute *attr,
193 const char *buf,
194 size_t len)
stephen hemminger515853c2011-10-03 18:14:46 +0000195{
Xin Long347db6b2016-04-09 00:03:29 +0800196 return store_bridge_parm(d, buf, len, set_group_fwd_mask);
stephen hemminger515853c2011-10-03 18:14:46 +0000197}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800198static DEVICE_ATTR_RW(group_fwd_mask);
stephen hemminger515853c2011-10-03 18:14:46 +0000199
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800200static ssize_t priority_show(struct device *d, struct device_attribute *attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700201 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700203 struct net_bridge *br = to_bridge(d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 return sprintf(buf, "%d\n",
205 (br->bridge_id.prio[0] << 8) | br->bridge_id.prio[1]);
206}
207
Vladimir Oltean9e781402021-02-13 22:43:16 +0200208static int set_priority(struct net_bridge *br, unsigned long val,
209 struct netlink_ext_ack *extack)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210{
211 br_stp_set_bridge_priority(br, (u16) val);
Stephen Hemminger8d4698f72008-09-08 13:44:40 -0700212 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213}
214
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800215static ssize_t priority_store(struct device *d, struct device_attribute *attr,
216 const char *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700218 return store_bridge_parm(d, buf, len, set_priority);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800220static DEVICE_ATTR_RW(priority);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800222static ssize_t root_id_show(struct device *d, struct device_attribute *attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700223 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700225 return br_show_bridge_id(buf, &to_bridge(d)->designated_root);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800227static DEVICE_ATTR_RO(root_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800229static ssize_t bridge_id_show(struct device *d, struct device_attribute *attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700230 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700232 return br_show_bridge_id(buf, &to_bridge(d)->bridge_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800234static DEVICE_ATTR_RO(bridge_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800236static ssize_t root_port_show(struct device *d, struct device_attribute *attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700237 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700239 return sprintf(buf, "%d\n", to_bridge(d)->root_port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800241static DEVICE_ATTR_RO(root_port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800243static ssize_t root_path_cost_show(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700244 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700246 return sprintf(buf, "%d\n", to_bridge(d)->root_path_cost);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800248static DEVICE_ATTR_RO(root_path_cost);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800250static ssize_t topology_change_show(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700251 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700253 return sprintf(buf, "%d\n", to_bridge(d)->topology_change);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800255static DEVICE_ATTR_RO(topology_change);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800257static ssize_t topology_change_detected_show(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700258 struct device_attribute *attr,
259 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700261 struct net_bridge *br = to_bridge(d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 return sprintf(buf, "%d\n", br->topology_change_detected);
263}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800264static DEVICE_ATTR_RO(topology_change_detected);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800266static ssize_t hello_timer_show(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700267 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700269 struct net_bridge *br = to_bridge(d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 return sprintf(buf, "%ld\n", br_timer_value(&br->hello_timer));
271}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800272static DEVICE_ATTR_RO(hello_timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800274static ssize_t tcn_timer_show(struct device *d, struct device_attribute *attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700275 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700277 struct net_bridge *br = to_bridge(d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 return sprintf(buf, "%ld\n", br_timer_value(&br->tcn_timer));
279}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800280static DEVICE_ATTR_RO(tcn_timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800282static ssize_t topology_change_timer_show(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700283 struct device_attribute *attr,
284 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700286 struct net_bridge *br = to_bridge(d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 return sprintf(buf, "%ld\n", br_timer_value(&br->topology_change_timer));
288}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800289static DEVICE_ATTR_RO(topology_change_timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800291static ssize_t gc_timer_show(struct device *d, struct device_attribute *attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700292 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700294 struct net_bridge *br = to_bridge(d);
Nikolay Aleksandrovf7cdee82017-02-04 18:05:07 +0100295 return sprintf(buf, "%ld\n", br_timer_value(&br->gc_work.timer));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800297static DEVICE_ATTR_RO(gc_timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800299static ssize_t group_addr_show(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700300 struct device_attribute *attr, char *buf)
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800301{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700302 struct net_bridge *br = to_bridge(d);
Andy Shevchenko223b2292017-12-19 20:10:53 +0200303 return sprintf(buf, "%pM\n", br->group_addr);
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800304}
305
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800306static ssize_t group_addr_store(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700307 struct device_attribute *attr,
308 const char *buf, size_t len)
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800309{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700310 struct net_bridge *br = to_bridge(d);
Ben Hutchings4197f242012-11-01 09:10:04 +0000311 u8 new_addr[6];
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800312
Eric W. Biedermancb990502012-11-16 03:03:08 +0000313 if (!ns_capable(dev_net(br->dev)->user_ns, CAP_NET_ADMIN))
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800314 return -EPERM;
315
Andy Shevchenko223b2292017-12-19 20:10:53 +0200316 if (!mac_pton(buf, new_addr))
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800317 return -EINVAL;
318
Ben Hutchings46acc462012-11-01 09:11:11 +0000319 if (!is_link_local_ether_addr(new_addr))
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800320 return -EINVAL;
321
Joe Perchesf64f9e72009-11-29 16:55:45 -0800322 if (new_addr[5] == 1 || /* 802.3x Pause address */
323 new_addr[5] == 2 || /* 802.3ad Slow protocols */
324 new_addr[5] == 3) /* 802.1X PAE address */
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800325 return -EINVAL;
326
Toshiaki Makita204177f2014-06-10 20:59:25 +0900327 if (!rtnl_trylock())
328 return restart_syscall();
329
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800330 spin_lock_bh(&br->lock);
Andy Shevchenko223b2292017-12-19 20:10:53 +0200331 ether_addr_copy(br->group_addr, new_addr);
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800332 spin_unlock_bh(&br->lock);
Toshiaki Makita204177f2014-06-10 20:59:25 +0900333
Nikolay Aleksandrovbe3664a2018-09-26 17:01:02 +0300334 br_opt_toggle(br, BROPT_GROUP_ADDR_SET, true);
Toshiaki Makita204177f2014-06-10 20:59:25 +0900335 br_recalculate_fwd_mask(br);
Xin Long047831a2016-04-09 00:03:31 +0800336 netdev_state_change(br->dev);
Toshiaki Makita204177f2014-06-10 20:59:25 +0900337
338 rtnl_unlock();
339
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800340 return len;
341}
342
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800343static DEVICE_ATTR_RW(group_addr);
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800344
Vladimir Oltean9e781402021-02-13 22:43:16 +0200345static int set_flush(struct net_bridge *br, unsigned long val,
346 struct netlink_ext_ack *extack)
Xin Long14f31bb2016-04-09 00:03:28 +0800347{
348 br_fdb_flush(br);
349 return 0;
350}
351
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800352static ssize_t flush_store(struct device *d,
Stephen Hemminger9cf63742007-04-09 12:57:54 -0700353 struct device_attribute *attr,
354 const char *buf, size_t len)
355{
Xin Long14f31bb2016-04-09 00:03:28 +0800356 return store_bridge_parm(d, buf, len, set_flush);
Stephen Hemminger9cf63742007-04-09 12:57:54 -0700357}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800358static DEVICE_ATTR_WO(flush);
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800359
Nikolay Aleksandrov70e42722018-11-24 04:34:21 +0200360static ssize_t no_linklocal_learn_show(struct device *d,
361 struct device_attribute *attr,
362 char *buf)
363{
364 struct net_bridge *br = to_bridge(d);
365 return sprintf(buf, "%d\n", br_boolopt_get(br, BR_BOOLOPT_NO_LL_LEARN));
366}
367
Vladimir Oltean9e781402021-02-13 22:43:16 +0200368static int set_no_linklocal_learn(struct net_bridge *br, unsigned long val,
369 struct netlink_ext_ack *extack)
Nikolay Aleksandrov70e42722018-11-24 04:34:21 +0200370{
Vladimir Oltean9e781402021-02-13 22:43:16 +0200371 return br_boolopt_toggle(br, BR_BOOLOPT_NO_LL_LEARN, !!val, extack);
Nikolay Aleksandrov70e42722018-11-24 04:34:21 +0200372}
373
374static ssize_t no_linklocal_learn_store(struct device *d,
375 struct device_attribute *attr,
376 const char *buf, size_t len)
377{
378 return store_bridge_parm(d, buf, len, set_no_linklocal_learn);
379}
380static DEVICE_ATTR_RW(no_linklocal_learn);
381
Herbert Xu0909e112010-02-27 19:41:49 +0000382#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800383static ssize_t multicast_router_show(struct device *d,
Herbert Xu0909e112010-02-27 19:41:49 +0000384 struct device_attribute *attr, char *buf)
385{
386 struct net_bridge *br = to_bridge(d);
Nikolay Aleksandrovd3d065c2021-07-19 20:06:24 +0300387 return sprintf(buf, "%d\n", br->multicast_ctx.multicast_router);
Herbert Xu0909e112010-02-27 19:41:49 +0000388}
389
Vladimir Oltean9e781402021-02-13 22:43:16 +0200390static int set_multicast_router(struct net_bridge *br, unsigned long val,
391 struct netlink_ext_ack *extack)
392{
393 return br_multicast_set_router(br, val);
394}
395
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800396static ssize_t multicast_router_store(struct device *d,
Herbert Xu0909e112010-02-27 19:41:49 +0000397 struct device_attribute *attr,
398 const char *buf, size_t len)
399{
Vladimir Oltean9e781402021-02-13 22:43:16 +0200400 return store_bridge_parm(d, buf, len, set_multicast_router);
Herbert Xu0909e112010-02-27 19:41:49 +0000401}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800402static DEVICE_ATTR_RW(multicast_router);
Herbert Xu561f1102010-02-27 19:41:50 +0000403
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800404static ssize_t multicast_snooping_show(struct device *d,
Herbert Xu561f1102010-02-27 19:41:50 +0000405 struct device_attribute *attr,
406 char *buf)
407{
408 struct net_bridge *br = to_bridge(d);
Nikolay Aleksandrov13cefad2018-09-26 17:01:03 +0300409 return sprintf(buf, "%d\n", br_opt_get(br, BROPT_MULTICAST_ENABLED));
Herbert Xu561f1102010-02-27 19:41:50 +0000410}
411
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800412static ssize_t multicast_snooping_store(struct device *d,
Herbert Xu561f1102010-02-27 19:41:50 +0000413 struct device_attribute *attr,
414 const char *buf, size_t len)
415{
Florian Fainelliae1ea842021-04-14 22:22:57 +0300416 return store_bridge_parm(d, buf, len, br_multicast_toggle);
Herbert Xu561f1102010-02-27 19:41:50 +0000417}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800418static DEVICE_ATTR_RW(multicast_snooping);
Herbert Xub1951672010-02-27 19:41:51 +0000419
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800420static ssize_t multicast_query_use_ifaddr_show(struct device *d,
421 struct device_attribute *attr,
422 char *buf)
Cong Wang1c8ad5b2013-05-21 21:52:54 +0000423{
424 struct net_bridge *br = to_bridge(d);
Nikolay Aleksandrov675779a2018-09-26 17:01:04 +0300425 return sprintf(buf, "%d\n",
426 br_opt_get(br, BROPT_MULTICAST_QUERY_USE_IFADDR));
Cong Wang1c8ad5b2013-05-21 21:52:54 +0000427}
428
Vladimir Oltean9e781402021-02-13 22:43:16 +0200429static int set_query_use_ifaddr(struct net_bridge *br, unsigned long val,
430 struct netlink_ext_ack *extack)
Cong Wang1c8ad5b2013-05-21 21:52:54 +0000431{
Nikolay Aleksandrov675779a2018-09-26 17:01:04 +0300432 br_opt_toggle(br, BROPT_MULTICAST_QUERY_USE_IFADDR, !!val);
Cong Wang1c8ad5b2013-05-21 21:52:54 +0000433 return 0;
434}
435
436static ssize_t
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800437multicast_query_use_ifaddr_store(struct device *d,
Cong Wang1c8ad5b2013-05-21 21:52:54 +0000438 struct device_attribute *attr,
439 const char *buf, size_t len)
440{
441 return store_bridge_parm(d, buf, len, set_query_use_ifaddr);
442}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800443static DEVICE_ATTR_RW(multicast_query_use_ifaddr);
Cong Wang1c8ad5b2013-05-21 21:52:54 +0000444
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800445static ssize_t multicast_querier_show(struct device *d,
Herbert Xuc5c23262012-04-13 02:37:42 +0000446 struct device_attribute *attr,
447 char *buf)
448{
449 struct net_bridge *br = to_bridge(d);
Nikolay Aleksandrov675779a2018-09-26 17:01:04 +0300450 return sprintf(buf, "%d\n", br_opt_get(br, BROPT_MULTICAST_QUERIER));
Herbert Xuc5c23262012-04-13 02:37:42 +0000451}
452
Vladimir Oltean9e781402021-02-13 22:43:16 +0200453static int set_multicast_querier(struct net_bridge *br, unsigned long val,
454 struct netlink_ext_ack *extack)
455{
456 return br_multicast_set_querier(br, val);
457}
458
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800459static ssize_t multicast_querier_store(struct device *d,
Herbert Xuc5c23262012-04-13 02:37:42 +0000460 struct device_attribute *attr,
461 const char *buf, size_t len)
462{
Vladimir Oltean9e781402021-02-13 22:43:16 +0200463 return store_bridge_parm(d, buf, len, set_multicast_querier);
Herbert Xuc5c23262012-04-13 02:37:42 +0000464}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800465static DEVICE_ATTR_RW(multicast_querier);
Herbert Xuc5c23262012-04-13 02:37:42 +0000466
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800467static ssize_t hash_elasticity_show(struct device *d,
Herbert Xub1951672010-02-27 19:41:51 +0000468 struct device_attribute *attr, char *buf)
469{
Nikolay Aleksandrovcf332bca2018-12-05 15:14:26 +0200470 return sprintf(buf, "%u\n", RHT_ELASTICITY);
Herbert Xub1951672010-02-27 19:41:51 +0000471}
472
Vladimir Oltean9e781402021-02-13 22:43:16 +0200473static int set_elasticity(struct net_bridge *br, unsigned long val,
474 struct netlink_ext_ack *extack)
Herbert Xub1951672010-02-27 19:41:51 +0000475{
Vladimir Oltean9e781402021-02-13 22:43:16 +0200476 /* 16 is RHT_ELASTICITY */
477 NL_SET_ERR_MSG_MOD(extack,
478 "the hash_elasticity option has been deprecated and is always 16");
Herbert Xub1951672010-02-27 19:41:51 +0000479 return 0;
480}
481
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800482static ssize_t hash_elasticity_store(struct device *d,
Herbert Xub1951672010-02-27 19:41:51 +0000483 struct device_attribute *attr,
484 const char *buf, size_t len)
485{
486 return store_bridge_parm(d, buf, len, set_elasticity);
487}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800488static DEVICE_ATTR_RW(hash_elasticity);
Herbert Xub1951672010-02-27 19:41:51 +0000489
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800490static ssize_t hash_max_show(struct device *d, struct device_attribute *attr,
Herbert Xub1951672010-02-27 19:41:51 +0000491 char *buf)
492{
493 struct net_bridge *br = to_bridge(d);
494 return sprintf(buf, "%u\n", br->hash_max);
495}
496
Vladimir Oltean9e781402021-02-13 22:43:16 +0200497static int set_hash_max(struct net_bridge *br, unsigned long val,
498 struct netlink_ext_ack *extack)
Nikolay Aleksandrov19e3a9c2018-12-05 15:14:24 +0200499{
500 br->hash_max = val;
501 return 0;
502}
503
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800504static ssize_t hash_max_store(struct device *d, struct device_attribute *attr,
Herbert Xub1951672010-02-27 19:41:51 +0000505 const char *buf, size_t len)
506{
Nikolay Aleksandrov19e3a9c2018-12-05 15:14:24 +0200507 return store_bridge_parm(d, buf, len, set_hash_max);
Herbert Xub1951672010-02-27 19:41:51 +0000508}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800509static DEVICE_ATTR_RW(hash_max);
Herbert Xud902eee2010-02-27 19:41:52 +0000510
Nikolay Aleksandrov5e923582016-11-21 13:03:24 +0100511static ssize_t multicast_igmp_version_show(struct device *d,
512 struct device_attribute *attr,
513 char *buf)
514{
515 struct net_bridge *br = to_bridge(d);
516
Nikolay Aleksandrovd3d065c2021-07-19 20:06:24 +0300517 return sprintf(buf, "%u\n", br->multicast_ctx.multicast_igmp_version);
Nikolay Aleksandrov5e923582016-11-21 13:03:24 +0100518}
519
Vladimir Oltean9e781402021-02-13 22:43:16 +0200520static int set_multicast_igmp_version(struct net_bridge *br, unsigned long val,
521 struct netlink_ext_ack *extack)
522{
Nikolay Aleksandrovdf271cd2021-08-10 18:29:19 +0300523 return br_multicast_set_igmp_version(&br->multicast_ctx, val);
Vladimir Oltean9e781402021-02-13 22:43:16 +0200524}
525
Nikolay Aleksandrov5e923582016-11-21 13:03:24 +0100526static ssize_t multicast_igmp_version_store(struct device *d,
527 struct device_attribute *attr,
528 const char *buf, size_t len)
529{
Vladimir Oltean9e781402021-02-13 22:43:16 +0200530 return store_bridge_parm(d, buf, len, set_multicast_igmp_version);
Nikolay Aleksandrov5e923582016-11-21 13:03:24 +0100531}
532static DEVICE_ATTR_RW(multicast_igmp_version);
533
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800534static ssize_t multicast_last_member_count_show(struct device *d,
Herbert Xud902eee2010-02-27 19:41:52 +0000535 struct device_attribute *attr,
536 char *buf)
537{
538 struct net_bridge *br = to_bridge(d);
Nikolay Aleksandrovd3d065c2021-07-19 20:06:24 +0300539 return sprintf(buf, "%u\n", br->multicast_ctx.multicast_last_member_count);
Herbert Xud902eee2010-02-27 19:41:52 +0000540}
541
Vladimir Oltean9e781402021-02-13 22:43:16 +0200542static int set_last_member_count(struct net_bridge *br, unsigned long val,
543 struct netlink_ext_ack *extack)
Herbert Xud902eee2010-02-27 19:41:52 +0000544{
Nikolay Aleksandrovd3d065c2021-07-19 20:06:24 +0300545 br->multicast_ctx.multicast_last_member_count = val;
Herbert Xud902eee2010-02-27 19:41:52 +0000546 return 0;
547}
548
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800549static ssize_t multicast_last_member_count_store(struct device *d,
Herbert Xud902eee2010-02-27 19:41:52 +0000550 struct device_attribute *attr,
551 const char *buf, size_t len)
552{
553 return store_bridge_parm(d, buf, len, set_last_member_count);
554}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800555static DEVICE_ATTR_RW(multicast_last_member_count);
Herbert Xud902eee2010-02-27 19:41:52 +0000556
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800557static ssize_t multicast_startup_query_count_show(
Herbert Xud902eee2010-02-27 19:41:52 +0000558 struct device *d, struct device_attribute *attr, char *buf)
559{
560 struct net_bridge *br = to_bridge(d);
Nikolay Aleksandrovd3d065c2021-07-19 20:06:24 +0300561 return sprintf(buf, "%u\n", br->multicast_ctx.multicast_startup_query_count);
Herbert Xud902eee2010-02-27 19:41:52 +0000562}
563
Vladimir Oltean9e781402021-02-13 22:43:16 +0200564static int set_startup_query_count(struct net_bridge *br, unsigned long val,
565 struct netlink_ext_ack *extack)
Herbert Xud902eee2010-02-27 19:41:52 +0000566{
Nikolay Aleksandrovd3d065c2021-07-19 20:06:24 +0300567 br->multicast_ctx.multicast_startup_query_count = val;
Herbert Xud902eee2010-02-27 19:41:52 +0000568 return 0;
569}
570
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800571static ssize_t multicast_startup_query_count_store(
Herbert Xud902eee2010-02-27 19:41:52 +0000572 struct device *d, struct device_attribute *attr, const char *buf,
573 size_t len)
574{
575 return store_bridge_parm(d, buf, len, set_startup_query_count);
576}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800577static DEVICE_ATTR_RW(multicast_startup_query_count);
Herbert Xud902eee2010-02-27 19:41:52 +0000578
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800579static ssize_t multicast_last_member_interval_show(
Herbert Xud902eee2010-02-27 19:41:52 +0000580 struct device *d, struct device_attribute *attr, char *buf)
581{
582 struct net_bridge *br = to_bridge(d);
583 return sprintf(buf, "%lu\n",
Nikolay Aleksandrovd3d065c2021-07-19 20:06:24 +0300584 jiffies_to_clock_t(br->multicast_ctx.multicast_last_member_interval));
Herbert Xud902eee2010-02-27 19:41:52 +0000585}
586
Vladimir Oltean9e781402021-02-13 22:43:16 +0200587static int set_last_member_interval(struct net_bridge *br, unsigned long val,
588 struct netlink_ext_ack *extack)
Herbert Xud902eee2010-02-27 19:41:52 +0000589{
Nikolay Aleksandrovd3d065c2021-07-19 20:06:24 +0300590 br->multicast_ctx.multicast_last_member_interval = clock_t_to_jiffies(val);
Herbert Xud902eee2010-02-27 19:41:52 +0000591 return 0;
592}
593
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800594static ssize_t multicast_last_member_interval_store(
Herbert Xud902eee2010-02-27 19:41:52 +0000595 struct device *d, struct device_attribute *attr, const char *buf,
596 size_t len)
597{
598 return store_bridge_parm(d, buf, len, set_last_member_interval);
599}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800600static DEVICE_ATTR_RW(multicast_last_member_interval);
Herbert Xud902eee2010-02-27 19:41:52 +0000601
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800602static ssize_t multicast_membership_interval_show(
Herbert Xud902eee2010-02-27 19:41:52 +0000603 struct device *d, struct device_attribute *attr, char *buf)
604{
605 struct net_bridge *br = to_bridge(d);
606 return sprintf(buf, "%lu\n",
Nikolay Aleksandrovd3d065c2021-07-19 20:06:24 +0300607 jiffies_to_clock_t(br->multicast_ctx.multicast_membership_interval));
Herbert Xud902eee2010-02-27 19:41:52 +0000608}
609
Vladimir Oltean9e781402021-02-13 22:43:16 +0200610static int set_membership_interval(struct net_bridge *br, unsigned long val,
611 struct netlink_ext_ack *extack)
Herbert Xud902eee2010-02-27 19:41:52 +0000612{
Nikolay Aleksandrovd3d065c2021-07-19 20:06:24 +0300613 br->multicast_ctx.multicast_membership_interval = clock_t_to_jiffies(val);
Herbert Xud902eee2010-02-27 19:41:52 +0000614 return 0;
615}
616
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800617static ssize_t multicast_membership_interval_store(
Herbert Xud902eee2010-02-27 19:41:52 +0000618 struct device *d, struct device_attribute *attr, const char *buf,
619 size_t len)
620{
621 return store_bridge_parm(d, buf, len, set_membership_interval);
622}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800623static DEVICE_ATTR_RW(multicast_membership_interval);
Herbert Xud902eee2010-02-27 19:41:52 +0000624
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800625static ssize_t multicast_querier_interval_show(struct device *d,
Herbert Xud902eee2010-02-27 19:41:52 +0000626 struct device_attribute *attr,
627 char *buf)
628{
629 struct net_bridge *br = to_bridge(d);
630 return sprintf(buf, "%lu\n",
Nikolay Aleksandrovd3d065c2021-07-19 20:06:24 +0300631 jiffies_to_clock_t(br->multicast_ctx.multicast_querier_interval));
Herbert Xud902eee2010-02-27 19:41:52 +0000632}
633
Vladimir Oltean9e781402021-02-13 22:43:16 +0200634static int set_querier_interval(struct net_bridge *br, unsigned long val,
635 struct netlink_ext_ack *extack)
Herbert Xud902eee2010-02-27 19:41:52 +0000636{
Nikolay Aleksandrovd3d065c2021-07-19 20:06:24 +0300637 br->multicast_ctx.multicast_querier_interval = clock_t_to_jiffies(val);
Herbert Xud902eee2010-02-27 19:41:52 +0000638 return 0;
639}
640
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800641static ssize_t multicast_querier_interval_store(struct device *d,
Herbert Xud902eee2010-02-27 19:41:52 +0000642 struct device_attribute *attr,
643 const char *buf, size_t len)
644{
645 return store_bridge_parm(d, buf, len, set_querier_interval);
646}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800647static DEVICE_ATTR_RW(multicast_querier_interval);
Herbert Xud902eee2010-02-27 19:41:52 +0000648
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800649static ssize_t multicast_query_interval_show(struct device *d,
Herbert Xud902eee2010-02-27 19:41:52 +0000650 struct device_attribute *attr,
651 char *buf)
652{
653 struct net_bridge *br = to_bridge(d);
654 return sprintf(buf, "%lu\n",
Nikolay Aleksandrovd3d065c2021-07-19 20:06:24 +0300655 jiffies_to_clock_t(br->multicast_ctx.multicast_query_interval));
Herbert Xud902eee2010-02-27 19:41:52 +0000656}
657
Vladimir Oltean9e781402021-02-13 22:43:16 +0200658static int set_query_interval(struct net_bridge *br, unsigned long val,
659 struct netlink_ext_ack *extack)
Herbert Xud902eee2010-02-27 19:41:52 +0000660{
Nikolay Aleksandrovd3d065c2021-07-19 20:06:24 +0300661 br->multicast_ctx.multicast_query_interval = clock_t_to_jiffies(val);
Herbert Xud902eee2010-02-27 19:41:52 +0000662 return 0;
663}
664
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800665static ssize_t multicast_query_interval_store(struct device *d,
Herbert Xud902eee2010-02-27 19:41:52 +0000666 struct device_attribute *attr,
667 const char *buf, size_t len)
668{
669 return store_bridge_parm(d, buf, len, set_query_interval);
670}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800671static DEVICE_ATTR_RW(multicast_query_interval);
Herbert Xud902eee2010-02-27 19:41:52 +0000672
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800673static ssize_t multicast_query_response_interval_show(
Herbert Xud902eee2010-02-27 19:41:52 +0000674 struct device *d, struct device_attribute *attr, char *buf)
675{
676 struct net_bridge *br = to_bridge(d);
677 return sprintf(
678 buf, "%lu\n",
Nikolay Aleksandrovd3d065c2021-07-19 20:06:24 +0300679 jiffies_to_clock_t(br->multicast_ctx.multicast_query_response_interval));
Herbert Xud902eee2010-02-27 19:41:52 +0000680}
681
Vladimir Oltean9e781402021-02-13 22:43:16 +0200682static int set_query_response_interval(struct net_bridge *br, unsigned long val,
683 struct netlink_ext_ack *extack)
Herbert Xud902eee2010-02-27 19:41:52 +0000684{
Nikolay Aleksandrovd3d065c2021-07-19 20:06:24 +0300685 br->multicast_ctx.multicast_query_response_interval = clock_t_to_jiffies(val);
Herbert Xud902eee2010-02-27 19:41:52 +0000686 return 0;
687}
688
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800689static ssize_t multicast_query_response_interval_store(
Herbert Xud902eee2010-02-27 19:41:52 +0000690 struct device *d, struct device_attribute *attr, const char *buf,
691 size_t len)
692{
693 return store_bridge_parm(d, buf, len, set_query_response_interval);
694}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800695static DEVICE_ATTR_RW(multicast_query_response_interval);
Herbert Xud902eee2010-02-27 19:41:52 +0000696
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800697static ssize_t multicast_startup_query_interval_show(
Herbert Xud902eee2010-02-27 19:41:52 +0000698 struct device *d, struct device_attribute *attr, char *buf)
699{
700 struct net_bridge *br = to_bridge(d);
701 return sprintf(
702 buf, "%lu\n",
Nikolay Aleksandrovd3d065c2021-07-19 20:06:24 +0300703 jiffies_to_clock_t(br->multicast_ctx.multicast_startup_query_interval));
Herbert Xud902eee2010-02-27 19:41:52 +0000704}
705
Vladimir Oltean9e781402021-02-13 22:43:16 +0200706static int set_startup_query_interval(struct net_bridge *br, unsigned long val,
707 struct netlink_ext_ack *extack)
Herbert Xud902eee2010-02-27 19:41:52 +0000708{
Nikolay Aleksandrovd3d065c2021-07-19 20:06:24 +0300709 br->multicast_ctx.multicast_startup_query_interval = clock_t_to_jiffies(val);
Herbert Xud902eee2010-02-27 19:41:52 +0000710 return 0;
711}
712
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800713static ssize_t multicast_startup_query_interval_store(
Herbert Xud902eee2010-02-27 19:41:52 +0000714 struct device *d, struct device_attribute *attr, const char *buf,
715 size_t len)
716{
717 return store_bridge_parm(d, buf, len, set_startup_query_interval);
718}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800719static DEVICE_ATTR_RW(multicast_startup_query_interval);
Nikolay Aleksandrov1080ab92016-06-28 16:57:06 +0200720
721static ssize_t multicast_stats_enabled_show(struct device *d,
722 struct device_attribute *attr,
723 char *buf)
724{
725 struct net_bridge *br = to_bridge(d);
726
Nikolay Aleksandrov675779a2018-09-26 17:01:04 +0300727 return sprintf(buf, "%d\n",
728 br_opt_get(br, BROPT_MULTICAST_STATS_ENABLED));
Nikolay Aleksandrov1080ab92016-06-28 16:57:06 +0200729}
730
Vladimir Oltean9e781402021-02-13 22:43:16 +0200731static int set_stats_enabled(struct net_bridge *br, unsigned long val,
732 struct netlink_ext_ack *extack)
Nikolay Aleksandrov1080ab92016-06-28 16:57:06 +0200733{
Nikolay Aleksandrov675779a2018-09-26 17:01:04 +0300734 br_opt_toggle(br, BROPT_MULTICAST_STATS_ENABLED, !!val);
Nikolay Aleksandrov1080ab92016-06-28 16:57:06 +0200735 return 0;
736}
737
738static ssize_t multicast_stats_enabled_store(struct device *d,
739 struct device_attribute *attr,
740 const char *buf,
741 size_t len)
742{
743 return store_bridge_parm(d, buf, len, set_stats_enabled);
744}
745static DEVICE_ATTR_RW(multicast_stats_enabled);
Nikolay Aleksandrovaa2ae3e2016-11-21 13:03:25 +0100746
747#if IS_ENABLED(CONFIG_IPV6)
748static ssize_t multicast_mld_version_show(struct device *d,
749 struct device_attribute *attr,
750 char *buf)
751{
752 struct net_bridge *br = to_bridge(d);
753
Nikolay Aleksandrovd3d065c2021-07-19 20:06:24 +0300754 return sprintf(buf, "%u\n", br->multicast_ctx.multicast_mld_version);
Nikolay Aleksandrovaa2ae3e2016-11-21 13:03:25 +0100755}
756
Vladimir Oltean9e781402021-02-13 22:43:16 +0200757static int set_multicast_mld_version(struct net_bridge *br, unsigned long val,
758 struct netlink_ext_ack *extack)
759{
Nikolay Aleksandrovdf271cd2021-08-10 18:29:19 +0300760 return br_multicast_set_mld_version(&br->multicast_ctx, val);
Vladimir Oltean9e781402021-02-13 22:43:16 +0200761}
762
Nikolay Aleksandrovaa2ae3e2016-11-21 13:03:25 +0100763static ssize_t multicast_mld_version_store(struct device *d,
764 struct device_attribute *attr,
765 const char *buf, size_t len)
766{
Vladimir Oltean9e781402021-02-13 22:43:16 +0200767 return store_bridge_parm(d, buf, len, set_multicast_mld_version);
Nikolay Aleksandrovaa2ae3e2016-11-21 13:03:25 +0100768}
769static DEVICE_ATTR_RW(multicast_mld_version);
770#endif
Herbert Xu0909e112010-02-27 19:41:49 +0000771#endif
Pablo Neira Ayuso34666d42014-09-18 11:29:03 +0200772#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800773static ssize_t nf_call_iptables_show(
Patrick McHardy4df53d82010-07-02 09:32:57 +0200774 struct device *d, struct device_attribute *attr, char *buf)
775{
776 struct net_bridge *br = to_bridge(d);
Nikolay Aleksandrov8df35102018-09-26 17:01:01 +0300777 return sprintf(buf, "%u\n", br_opt_get(br, BROPT_NF_CALL_IPTABLES));
Patrick McHardy4df53d82010-07-02 09:32:57 +0200778}
779
Vladimir Oltean9e781402021-02-13 22:43:16 +0200780static int set_nf_call_iptables(struct net_bridge *br, unsigned long val,
781 struct netlink_ext_ack *extack)
Patrick McHardy4df53d82010-07-02 09:32:57 +0200782{
Nikolay Aleksandrov8df35102018-09-26 17:01:01 +0300783 br_opt_toggle(br, BROPT_NF_CALL_IPTABLES, !!val);
Patrick McHardy4df53d82010-07-02 09:32:57 +0200784 return 0;
785}
786
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800787static ssize_t nf_call_iptables_store(
Patrick McHardy4df53d82010-07-02 09:32:57 +0200788 struct device *d, struct device_attribute *attr, const char *buf,
789 size_t len)
790{
791 return store_bridge_parm(d, buf, len, set_nf_call_iptables);
792}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800793static DEVICE_ATTR_RW(nf_call_iptables);
Patrick McHardy4df53d82010-07-02 09:32:57 +0200794
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800795static ssize_t nf_call_ip6tables_show(
Patrick McHardy4df53d82010-07-02 09:32:57 +0200796 struct device *d, struct device_attribute *attr, char *buf)
797{
798 struct net_bridge *br = to_bridge(d);
Nikolay Aleksandrov8df35102018-09-26 17:01:01 +0300799 return sprintf(buf, "%u\n", br_opt_get(br, BROPT_NF_CALL_IP6TABLES));
Patrick McHardy4df53d82010-07-02 09:32:57 +0200800}
801
Vladimir Oltean9e781402021-02-13 22:43:16 +0200802static int set_nf_call_ip6tables(struct net_bridge *br, unsigned long val,
803 struct netlink_ext_ack *extack)
Patrick McHardy4df53d82010-07-02 09:32:57 +0200804{
Nikolay Aleksandrov8df35102018-09-26 17:01:01 +0300805 br_opt_toggle(br, BROPT_NF_CALL_IP6TABLES, !!val);
Patrick McHardy4df53d82010-07-02 09:32:57 +0200806 return 0;
807}
808
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800809static ssize_t nf_call_ip6tables_store(
Patrick McHardy4df53d82010-07-02 09:32:57 +0200810 struct device *d, struct device_attribute *attr, const char *buf,
811 size_t len)
812{
813 return store_bridge_parm(d, buf, len, set_nf_call_ip6tables);
814}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800815static DEVICE_ATTR_RW(nf_call_ip6tables);
Patrick McHardy4df53d82010-07-02 09:32:57 +0200816
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800817static ssize_t nf_call_arptables_show(
Patrick McHardy4df53d82010-07-02 09:32:57 +0200818 struct device *d, struct device_attribute *attr, char *buf)
819{
820 struct net_bridge *br = to_bridge(d);
Nikolay Aleksandrov8df35102018-09-26 17:01:01 +0300821 return sprintf(buf, "%u\n", br_opt_get(br, BROPT_NF_CALL_ARPTABLES));
Patrick McHardy4df53d82010-07-02 09:32:57 +0200822}
823
Vladimir Oltean9e781402021-02-13 22:43:16 +0200824static int set_nf_call_arptables(struct net_bridge *br, unsigned long val,
825 struct netlink_ext_ack *extack)
Patrick McHardy4df53d82010-07-02 09:32:57 +0200826{
Nikolay Aleksandrov8df35102018-09-26 17:01:01 +0300827 br_opt_toggle(br, BROPT_NF_CALL_ARPTABLES, !!val);
Patrick McHardy4df53d82010-07-02 09:32:57 +0200828 return 0;
829}
830
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800831static ssize_t nf_call_arptables_store(
Patrick McHardy4df53d82010-07-02 09:32:57 +0200832 struct device *d, struct device_attribute *attr, const char *buf,
833 size_t len)
834{
835 return store_bridge_parm(d, buf, len, set_nf_call_arptables);
836}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800837static DEVICE_ATTR_RW(nf_call_arptables);
Patrick McHardy4df53d82010-07-02 09:32:57 +0200838#endif
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000839#ifdef CONFIG_BRIDGE_VLAN_FILTERING
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800840static ssize_t vlan_filtering_show(struct device *d,
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000841 struct device_attribute *attr,
842 char *buf)
843{
844 struct net_bridge *br = to_bridge(d);
Nikolay Aleksandrovae757672018-09-26 17:01:00 +0300845 return sprintf(buf, "%d\n", br_opt_get(br, BROPT_VLAN_ENABLED));
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000846}
847
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800848static ssize_t vlan_filtering_store(struct device *d,
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000849 struct device_attribute *attr,
850 const char *buf, size_t len)
851{
852 return store_bridge_parm(d, buf, len, br_vlan_filter_toggle);
853}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800854static DEVICE_ATTR_RW(vlan_filtering);
Toshiaki Makita204177f2014-06-10 20:59:25 +0900855
856static ssize_t vlan_protocol_show(struct device *d,
857 struct device_attribute *attr,
858 char *buf)
859{
860 struct net_bridge *br = to_bridge(d);
861 return sprintf(buf, "%#06x\n", ntohs(br->vlan_proto));
862}
863
864static ssize_t vlan_protocol_store(struct device *d,
865 struct device_attribute *attr,
866 const char *buf, size_t len)
867{
868 return store_bridge_parm(d, buf, len, br_vlan_set_proto);
869}
870static DEVICE_ATTR_RW(vlan_protocol);
Vlad Yasevich96a20d92014-10-03 11:29:16 -0400871
872static ssize_t default_pvid_show(struct device *d,
873 struct device_attribute *attr,
874 char *buf)
875{
876 struct net_bridge *br = to_bridge(d);
877 return sprintf(buf, "%d\n", br->default_pvid);
878}
879
880static ssize_t default_pvid_store(struct device *d,
881 struct device_attribute *attr,
882 const char *buf, size_t len)
883{
884 return store_bridge_parm(d, buf, len, br_vlan_set_default_pvid);
885}
886static DEVICE_ATTR_RW(default_pvid);
Nikolay Aleksandrov6dada9b2016-04-30 10:25:28 +0200887
888static ssize_t vlan_stats_enabled_show(struct device *d,
889 struct device_attribute *attr,
890 char *buf)
891{
892 struct net_bridge *br = to_bridge(d);
Nikolay Aleksandrovae757672018-09-26 17:01:00 +0300893 return sprintf(buf, "%u\n", br_opt_get(br, BROPT_VLAN_STATS_ENABLED));
Nikolay Aleksandrov6dada9b2016-04-30 10:25:28 +0200894}
895
Vladimir Oltean9e781402021-02-13 22:43:16 +0200896static int set_vlan_stats_enabled(struct net_bridge *br, unsigned long val,
897 struct netlink_ext_ack *extack)
898{
899 return br_vlan_set_stats(br, val);
900}
901
Nikolay Aleksandrov6dada9b2016-04-30 10:25:28 +0200902static ssize_t vlan_stats_enabled_store(struct device *d,
903 struct device_attribute *attr,
904 const char *buf, size_t len)
905{
Vladimir Oltean9e781402021-02-13 22:43:16 +0200906 return store_bridge_parm(d, buf, len, set_vlan_stats_enabled);
Nikolay Aleksandrov6dada9b2016-04-30 10:25:28 +0200907}
908static DEVICE_ATTR_RW(vlan_stats_enabled);
Nikolay Aleksandrov9163a0f2018-10-12 13:41:16 +0300909
910static ssize_t vlan_stats_per_port_show(struct device *d,
911 struct device_attribute *attr,
912 char *buf)
913{
914 struct net_bridge *br = to_bridge(d);
915 return sprintf(buf, "%u\n", br_opt_get(br, BROPT_VLAN_STATS_PER_PORT));
916}
917
Vladimir Oltean9e781402021-02-13 22:43:16 +0200918static int set_vlan_stats_per_port(struct net_bridge *br, unsigned long val,
919 struct netlink_ext_ack *extack)
920{
921 return br_vlan_set_stats_per_port(br, val);
922}
923
Nikolay Aleksandrov9163a0f2018-10-12 13:41:16 +0300924static ssize_t vlan_stats_per_port_store(struct device *d,
925 struct device_attribute *attr,
926 const char *buf, size_t len)
927{
Vladimir Oltean9e781402021-02-13 22:43:16 +0200928 return store_bridge_parm(d, buf, len, set_vlan_stats_per_port);
Nikolay Aleksandrov9163a0f2018-10-12 13:41:16 +0300929}
930static DEVICE_ATTR_RW(vlan_stats_per_port);
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000931#endif
Herbert Xu0909e112010-02-27 19:41:49 +0000932
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933static struct attribute *bridge_attrs[] = {
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700934 &dev_attr_forward_delay.attr,
935 &dev_attr_hello_time.attr,
936 &dev_attr_max_age.attr,
937 &dev_attr_ageing_time.attr,
938 &dev_attr_stp_state.attr,
stephen hemminger515853c2011-10-03 18:14:46 +0000939 &dev_attr_group_fwd_mask.attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700940 &dev_attr_priority.attr,
941 &dev_attr_bridge_id.attr,
942 &dev_attr_root_id.attr,
943 &dev_attr_root_path_cost.attr,
944 &dev_attr_root_port.attr,
945 &dev_attr_topology_change.attr,
946 &dev_attr_topology_change_detected.attr,
947 &dev_attr_hello_timer.attr,
948 &dev_attr_tcn_timer.attr,
949 &dev_attr_topology_change_timer.attr,
950 &dev_attr_gc_timer.attr,
951 &dev_attr_group_addr.attr,
Stephen Hemminger9cf63742007-04-09 12:57:54 -0700952 &dev_attr_flush.attr,
Nikolay Aleksandrov70e42722018-11-24 04:34:21 +0200953 &dev_attr_no_linklocal_learn.attr,
Herbert Xu0909e112010-02-27 19:41:49 +0000954#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
955 &dev_attr_multicast_router.attr,
Herbert Xu561f1102010-02-27 19:41:50 +0000956 &dev_attr_multicast_snooping.attr,
Herbert Xuc5c23262012-04-13 02:37:42 +0000957 &dev_attr_multicast_querier.attr,
Cong Wang1c8ad5b2013-05-21 21:52:54 +0000958 &dev_attr_multicast_query_use_ifaddr.attr,
Herbert Xub1951672010-02-27 19:41:51 +0000959 &dev_attr_hash_elasticity.attr,
960 &dev_attr_hash_max.attr,
Herbert Xud902eee2010-02-27 19:41:52 +0000961 &dev_attr_multicast_last_member_count.attr,
962 &dev_attr_multicast_startup_query_count.attr,
963 &dev_attr_multicast_last_member_interval.attr,
964 &dev_attr_multicast_membership_interval.attr,
965 &dev_attr_multicast_querier_interval.attr,
966 &dev_attr_multicast_query_interval.attr,
967 &dev_attr_multicast_query_response_interval.attr,
968 &dev_attr_multicast_startup_query_interval.attr,
Nikolay Aleksandrov1080ab92016-06-28 16:57:06 +0200969 &dev_attr_multicast_stats_enabled.attr,
Nikolay Aleksandrov5e923582016-11-21 13:03:24 +0100970 &dev_attr_multicast_igmp_version.attr,
Nikolay Aleksandrovaa2ae3e2016-11-21 13:03:25 +0100971#if IS_ENABLED(CONFIG_IPV6)
972 &dev_attr_multicast_mld_version.attr,
973#endif
Herbert Xu0909e112010-02-27 19:41:49 +0000974#endif
Pablo Neira Ayuso34666d42014-09-18 11:29:03 +0200975#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
Patrick McHardy4df53d82010-07-02 09:32:57 +0200976 &dev_attr_nf_call_iptables.attr,
977 &dev_attr_nf_call_ip6tables.attr,
978 &dev_attr_nf_call_arptables.attr,
979#endif
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000980#ifdef CONFIG_BRIDGE_VLAN_FILTERING
981 &dev_attr_vlan_filtering.attr,
Toshiaki Makita204177f2014-06-10 20:59:25 +0900982 &dev_attr_vlan_protocol.attr,
Vlad Yasevich96a20d92014-10-03 11:29:16 -0400983 &dev_attr_default_pvid.attr,
Nikolay Aleksandrov6dada9b2016-04-30 10:25:28 +0200984 &dev_attr_vlan_stats_enabled.attr,
Nikolay Aleksandrov9163a0f2018-10-12 13:41:16 +0300985 &dev_attr_vlan_stats_per_port.attr,
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000986#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987 NULL
988};
989
Arvind Yadavcddbb792017-06-29 16:39:38 +0530990static const struct attribute_group bridge_group = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991 .name = SYSFS_BRIDGE_ATTR,
992 .attrs = bridge_attrs,
993};
994
995/*
996 * Export the forwarding information table as a binary file
997 * The records are struct __fdb_entry.
998 *
999 * Returns the number of bytes read.
1000 */
Chris Wright2c3c8be2010-05-12 18:28:57 -07001001static ssize_t brforward_read(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +08001002 struct bin_attribute *bin_attr,
1003 char *buf, loff_t off, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004{
Geliang Tangaeb7ed12015-12-23 20:42:21 +08001005 struct device *dev = kobj_to_dev(kobj);
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001006 struct net_bridge *br = to_bridge(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007 int n;
1008
1009 /* must read whole records */
1010 if (off % sizeof(struct __fdb_entry) != 0)
1011 return -EINVAL;
1012
YOSHIFUJI Hideaki9d6f2292007-02-09 23:24:35 +09001013 n = br_fdb_fillbuf(br, buf,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014 count / sizeof(struct __fdb_entry),
1015 off / sizeof(struct __fdb_entry));
1016
1017 if (n > 0)
1018 n *= sizeof(struct __fdb_entry);
YOSHIFUJI Hideaki9d6f2292007-02-09 23:24:35 +09001019
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020 return n;
1021}
1022
1023static struct bin_attribute bridge_forward = {
1024 .attr = { .name = SYSFS_BRIDGE_FDB,
Joe Perchesd6444062018-03-23 15:54:38 -07001025 .mode = 0444, },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026 .read = brforward_read,
1027};
1028
1029/*
1030 * Add entries in sysfs onto the existing network class device
1031 * for the bridge.
1032 * Adds a attribute group "bridge" containing tuning parameters.
1033 * Binary attribute containing the forward table
1034 * Sub directory to hold links to interfaces.
1035 *
1036 * Note: the ifobj exists only to be a subdirectory
1037 * to hold links. The ifobj exists in same data structure
1038 * as it's parent the bridge so reference counting works.
1039 */
1040int br_sysfs_addbr(struct net_device *dev)
1041{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001042 struct kobject *brobj = &dev->dev.kobj;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043 struct net_bridge *br = netdev_priv(dev);
1044 int err;
1045
1046 err = sysfs_create_group(brobj, &bridge_group);
1047 if (err) {
1048 pr_info("%s: can't create group %s/%s\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -08001049 __func__, dev->name, bridge_group.name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050 goto out1;
1051 }
1052
1053 err = sysfs_create_bin_file(brobj, &bridge_forward);
1054 if (err) {
Randy Dunlap1842c4b2006-10-25 23:07:37 -07001055 pr_info("%s: can't create attribute file %s/%s\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -08001056 __func__, dev->name, bridge_forward.attr.name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057 goto out2;
1058 }
1059
Greg Kroah-Hartman43b98c42007-12-17 15:54:39 -04001060 br->ifobj = kobject_create_and_add(SYSFS_BRIDGE_PORT_SUBDIR, brobj);
1061 if (!br->ifobj) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062 pr_info("%s: can't add kobject (directory) %s/%s\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -08001063 __func__, dev->name, SYSFS_BRIDGE_PORT_SUBDIR);
Pan Bianb5958962016-12-03 19:33:23 +08001064 err = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065 goto out3;
1066 }
1067 return 0;
1068 out3:
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001069 sysfs_remove_bin_file(&dev->dev.kobj, &bridge_forward);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070 out2:
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001071 sysfs_remove_group(&dev->dev.kobj, &bridge_group);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072 out1:
1073 return err;
1074
1075}
1076
1077void br_sysfs_delbr(struct net_device *dev)
1078{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001079 struct kobject *kobj = &dev->dev.kobj;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080 struct net_bridge *br = netdev_priv(dev);
1081
Greg Kroah-Hartman78a2d902007-12-20 08:13:05 -08001082 kobject_put(br->ifobj);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083 sysfs_remove_bin_file(kobj, &bridge_forward);
1084 sysfs_remove_group(kobj, &bridge_group);
1085}