blob: 159590d5c2afd39e9c2fc7560b0d64ed502023c6 [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;
Stephen Hemminger8d4698f72008-09-08 13:44:40 -070039 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
Eric W. Biedermancb990502012-11-16 03:03:08 +000041 if (!ns_capable(dev_net(br->dev)->user_ns, CAP_NET_ADMIN))
Linus Torvalds1da177e2005-04-16 15:20:36 -070042 return -EPERM;
43
Ido Schimmel5a45ab32021-11-24 12:11:22 +020044 err = kstrtoul(buf, 0, &val);
Bernard Zhao520fbdf2021-11-18 18:06:42 -080045 if (err != 0)
46 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
Xin Long047831a2016-04-09 00:03:31 +080048 if (!rtnl_trylock())
49 return restart_syscall();
50
Vladimir Oltean9e781402021-02-13 22:43:16 +020051 err = (*set)(br, val, &extack);
Xin Long047831a2016-04-09 00:03:31 +080052 if (!err)
53 netdev_state_change(br->dev);
Vladimir Oltean9e781402021-02-13 22:43:16 +020054 if (extack._msg) {
55 if (err)
56 br_err(br, "%s\n", extack._msg);
57 else
58 br_warn(br, "%s\n", extack._msg);
59 }
Xin Long047831a2016-04-09 00:03:31 +080060 rtnl_unlock();
61
Stephen Hemminger8d4698f72008-09-08 13:44:40 -070062 return err ? err : len;
Linus Torvalds1da177e2005-04-16 15:20:36 -070063}
64
65
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -080066static ssize_t forward_delay_show(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -070067 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -070068{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -070069 struct net_bridge *br = to_bridge(d);
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 return sprintf(buf, "%lu\n", jiffies_to_clock_t(br->forward_delay));
71}
72
Vladimir Oltean9e781402021-02-13 22:43:16 +020073static int set_forward_delay(struct net_bridge *br, unsigned long val,
74 struct netlink_ext_ack *extack)
75{
76 return br_set_forward_delay(br, val);
77}
78
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -080079static ssize_t forward_delay_store(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -070080 struct device_attribute *attr,
81 const char *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -070082{
Vladimir Oltean9e781402021-02-13 22:43:16 +020083 return store_bridge_parm(d, buf, len, set_forward_delay);
Linus Torvalds1da177e2005-04-16 15:20:36 -070084}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -080085static DEVICE_ATTR_RW(forward_delay);
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -080087static ssize_t hello_time_show(struct device *d, struct device_attribute *attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -070088 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -070089{
90 return sprintf(buf, "%lu\n",
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -070091 jiffies_to_clock_t(to_bridge(d)->hello_time));
Linus Torvalds1da177e2005-04-16 15:20:36 -070092}
93
Vladimir Oltean9e781402021-02-13 22:43:16 +020094static int set_hello_time(struct net_bridge *br, unsigned long val,
95 struct netlink_ext_ack *extack)
96{
97 return br_set_hello_time(br, val);
98}
99
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800100static ssize_t hello_time_store(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700101 struct device_attribute *attr, const char *buf,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 size_t len)
103{
Vladimir Oltean9e781402021-02-13 22:43:16 +0200104 return store_bridge_parm(d, buf, len, set_hello_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800106static DEVICE_ATTR_RW(hello_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800108static ssize_t max_age_show(struct device *d, struct device_attribute *attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700109 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110{
111 return sprintf(buf, "%lu\n",
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700112 jiffies_to_clock_t(to_bridge(d)->max_age));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113}
114
Vladimir Oltean9e781402021-02-13 22:43:16 +0200115static int set_max_age(struct net_bridge *br, unsigned long val,
116 struct netlink_ext_ack *extack)
117{
118 return br_set_max_age(br, val);
119}
120
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800121static ssize_t max_age_store(struct device *d, struct device_attribute *attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700122 const char *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123{
Vladimir Oltean9e781402021-02-13 22:43:16 +0200124 return store_bridge_parm(d, buf, len, set_max_age);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800126static DEVICE_ATTR_RW(max_age);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800128static ssize_t ageing_time_show(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700129 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700131 struct net_bridge *br = to_bridge(d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 return sprintf(buf, "%lu\n", jiffies_to_clock_t(br->ageing_time));
133}
134
Vladimir Oltean9e781402021-02-13 22:43:16 +0200135static int set_ageing_time(struct net_bridge *br, unsigned long val,
136 struct netlink_ext_ack *extack)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137{
Xin Long047831a2016-04-09 00:03:31 +0800138 return br_set_ageing_time(br, val);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139}
140
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800141static ssize_t ageing_time_store(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700142 struct device_attribute *attr,
143 const char *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700145 return store_bridge_parm(d, buf, len, set_ageing_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800147static DEVICE_ATTR_RW(ageing_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800149static ssize_t stp_state_show(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700150 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700152 struct net_bridge *br = to_bridge(d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 return sprintf(buf, "%d\n", br->stp_enabled);
154}
155
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156
Vladimir Oltean9e781402021-02-13 22:43:16 +0200157static int set_stp_state(struct net_bridge *br, unsigned long val,
158 struct netlink_ext_ack *extack)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159{
Vladimir Oltean9e781402021-02-13 22:43:16 +0200160 return br_stp_set_enabled(br, val, extack);
Xin Long44361562016-04-09 00:03:30 +0800161}
162
163static ssize_t stp_state_store(struct device *d,
164 struct device_attribute *attr, const char *buf,
165 size_t len)
166{
167 return store_bridge_parm(d, buf, len, set_stp_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800169static DEVICE_ATTR_RW(stp_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800171static ssize_t group_fwd_mask_show(struct device *d,
172 struct device_attribute *attr,
173 char *buf)
stephen hemminger515853c2011-10-03 18:14:46 +0000174{
175 struct net_bridge *br = to_bridge(d);
176 return sprintf(buf, "%#x\n", br->group_fwd_mask);
177}
178
Vladimir Oltean9e781402021-02-13 22:43:16 +0200179static int set_group_fwd_mask(struct net_bridge *br, unsigned long val,
180 struct netlink_ext_ack *extack)
Xin Long347db6b2016-04-09 00:03:29 +0800181{
182 if (val & BR_GROUPFWD_RESTRICTED)
183 return -EINVAL;
184
185 br->group_fwd_mask = val;
186
187 return 0;
188}
stephen hemminger515853c2011-10-03 18:14:46 +0000189
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800190static ssize_t group_fwd_mask_store(struct device *d,
191 struct device_attribute *attr,
192 const char *buf,
193 size_t len)
stephen hemminger515853c2011-10-03 18:14:46 +0000194{
Xin Long347db6b2016-04-09 00:03:29 +0800195 return store_bridge_parm(d, buf, len, set_group_fwd_mask);
stephen hemminger515853c2011-10-03 18:14:46 +0000196}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800197static DEVICE_ATTR_RW(group_fwd_mask);
stephen hemminger515853c2011-10-03 18:14:46 +0000198
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800199static ssize_t priority_show(struct device *d, struct device_attribute *attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700200 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700202 struct net_bridge *br = to_bridge(d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 return sprintf(buf, "%d\n",
204 (br->bridge_id.prio[0] << 8) | br->bridge_id.prio[1]);
205}
206
Vladimir Oltean9e781402021-02-13 22:43:16 +0200207static int set_priority(struct net_bridge *br, unsigned long val,
208 struct netlink_ext_ack *extack)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209{
210 br_stp_set_bridge_priority(br, (u16) val);
Stephen Hemminger8d4698f72008-09-08 13:44:40 -0700211 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212}
213
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800214static ssize_t priority_store(struct device *d, struct device_attribute *attr,
215 const char *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700217 return store_bridge_parm(d, buf, len, set_priority);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800219static DEVICE_ATTR_RW(priority);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800221static ssize_t root_id_show(struct device *d, struct device_attribute *attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700222 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700224 return br_show_bridge_id(buf, &to_bridge(d)->designated_root);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800226static DEVICE_ATTR_RO(root_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800228static ssize_t bridge_id_show(struct device *d, struct device_attribute *attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700229 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700231 return br_show_bridge_id(buf, &to_bridge(d)->bridge_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800233static DEVICE_ATTR_RO(bridge_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800235static ssize_t root_port_show(struct device *d, struct device_attribute *attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700236 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700238 return sprintf(buf, "%d\n", to_bridge(d)->root_port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800240static DEVICE_ATTR_RO(root_port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800242static ssize_t root_path_cost_show(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700243 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700245 return sprintf(buf, "%d\n", to_bridge(d)->root_path_cost);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800247static DEVICE_ATTR_RO(root_path_cost);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800249static ssize_t topology_change_show(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700250 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700252 return sprintf(buf, "%d\n", to_bridge(d)->topology_change);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800254static DEVICE_ATTR_RO(topology_change);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800256static ssize_t topology_change_detected_show(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700257 struct device_attribute *attr,
258 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700260 struct net_bridge *br = to_bridge(d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 return sprintf(buf, "%d\n", br->topology_change_detected);
262}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800263static DEVICE_ATTR_RO(topology_change_detected);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800265static ssize_t hello_timer_show(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700266 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700268 struct net_bridge *br = to_bridge(d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 return sprintf(buf, "%ld\n", br_timer_value(&br->hello_timer));
270}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800271static DEVICE_ATTR_RO(hello_timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800273static ssize_t tcn_timer_show(struct device *d, struct device_attribute *attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700274 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700276 struct net_bridge *br = to_bridge(d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 return sprintf(buf, "%ld\n", br_timer_value(&br->tcn_timer));
278}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800279static DEVICE_ATTR_RO(tcn_timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800281static ssize_t topology_change_timer_show(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700282 struct device_attribute *attr,
283 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700285 struct net_bridge *br = to_bridge(d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 return sprintf(buf, "%ld\n", br_timer_value(&br->topology_change_timer));
287}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800288static DEVICE_ATTR_RO(topology_change_timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800290static ssize_t gc_timer_show(struct device *d, struct device_attribute *attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700291 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700293 struct net_bridge *br = to_bridge(d);
Nikolay Aleksandrovf7cdee82017-02-04 18:05:07 +0100294 return sprintf(buf, "%ld\n", br_timer_value(&br->gc_work.timer));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800296static DEVICE_ATTR_RO(gc_timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800298static ssize_t group_addr_show(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700299 struct device_attribute *attr, char *buf)
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800300{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700301 struct net_bridge *br = to_bridge(d);
Andy Shevchenko223b2292017-12-19 20:10:53 +0200302 return sprintf(buf, "%pM\n", br->group_addr);
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800303}
304
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800305static ssize_t group_addr_store(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700306 struct device_attribute *attr,
307 const char *buf, size_t len)
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800308{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700309 struct net_bridge *br = to_bridge(d);
Ben Hutchings4197f242012-11-01 09:10:04 +0000310 u8 new_addr[6];
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800311
Eric W. Biedermancb990502012-11-16 03:03:08 +0000312 if (!ns_capable(dev_net(br->dev)->user_ns, CAP_NET_ADMIN))
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800313 return -EPERM;
314
Andy Shevchenko223b2292017-12-19 20:10:53 +0200315 if (!mac_pton(buf, new_addr))
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800316 return -EINVAL;
317
Ben Hutchings46acc462012-11-01 09:11:11 +0000318 if (!is_link_local_ether_addr(new_addr))
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800319 return -EINVAL;
320
Joe Perchesf64f9e72009-11-29 16:55:45 -0800321 if (new_addr[5] == 1 || /* 802.3x Pause address */
322 new_addr[5] == 2 || /* 802.3ad Slow protocols */
323 new_addr[5] == 3) /* 802.1X PAE address */
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800324 return -EINVAL;
325
Toshiaki Makita204177f2014-06-10 20:59:25 +0900326 if (!rtnl_trylock())
327 return restart_syscall();
328
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800329 spin_lock_bh(&br->lock);
Andy Shevchenko223b2292017-12-19 20:10:53 +0200330 ether_addr_copy(br->group_addr, new_addr);
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800331 spin_unlock_bh(&br->lock);
Toshiaki Makita204177f2014-06-10 20:59:25 +0900332
Nikolay Aleksandrovbe3664a2018-09-26 17:01:02 +0300333 br_opt_toggle(br, BROPT_GROUP_ADDR_SET, true);
Toshiaki Makita204177f2014-06-10 20:59:25 +0900334 br_recalculate_fwd_mask(br);
Xin Long047831a2016-04-09 00:03:31 +0800335 netdev_state_change(br->dev);
Toshiaki Makita204177f2014-06-10 20:59:25 +0900336
337 rtnl_unlock();
338
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800339 return len;
340}
341
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800342static DEVICE_ATTR_RW(group_addr);
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800343
Vladimir Oltean9e781402021-02-13 22:43:16 +0200344static int set_flush(struct net_bridge *br, unsigned long val,
345 struct netlink_ext_ack *extack)
Xin Long14f31bb2016-04-09 00:03:28 +0800346{
347 br_fdb_flush(br);
348 return 0;
349}
350
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800351static ssize_t flush_store(struct device *d,
Stephen Hemminger9cf63742007-04-09 12:57:54 -0700352 struct device_attribute *attr,
353 const char *buf, size_t len)
354{
Xin Long14f31bb2016-04-09 00:03:28 +0800355 return store_bridge_parm(d, buf, len, set_flush);
Stephen Hemminger9cf63742007-04-09 12:57:54 -0700356}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800357static DEVICE_ATTR_WO(flush);
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800358
Nikolay Aleksandrov70e42722018-11-24 04:34:21 +0200359static ssize_t no_linklocal_learn_show(struct device *d,
360 struct device_attribute *attr,
361 char *buf)
362{
363 struct net_bridge *br = to_bridge(d);
364 return sprintf(buf, "%d\n", br_boolopt_get(br, BR_BOOLOPT_NO_LL_LEARN));
365}
366
Vladimir Oltean9e781402021-02-13 22:43:16 +0200367static int set_no_linklocal_learn(struct net_bridge *br, unsigned long val,
368 struct netlink_ext_ack *extack)
Nikolay Aleksandrov70e42722018-11-24 04:34:21 +0200369{
Vladimir Oltean9e781402021-02-13 22:43:16 +0200370 return br_boolopt_toggle(br, BR_BOOLOPT_NO_LL_LEARN, !!val, extack);
Nikolay Aleksandrov70e42722018-11-24 04:34:21 +0200371}
372
373static ssize_t no_linklocal_learn_store(struct device *d,
374 struct device_attribute *attr,
375 const char *buf, size_t len)
376{
377 return store_bridge_parm(d, buf, len, set_no_linklocal_learn);
378}
379static DEVICE_ATTR_RW(no_linklocal_learn);
380
Herbert Xu0909e112010-02-27 19:41:49 +0000381#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800382static ssize_t multicast_router_show(struct device *d,
Herbert Xu0909e112010-02-27 19:41:49 +0000383 struct device_attribute *attr, char *buf)
384{
385 struct net_bridge *br = to_bridge(d);
Nikolay Aleksandrovd3d065c2021-07-19 20:06:24 +0300386 return sprintf(buf, "%d\n", br->multicast_ctx.multicast_router);
Herbert Xu0909e112010-02-27 19:41:49 +0000387}
388
Vladimir Oltean9e781402021-02-13 22:43:16 +0200389static int set_multicast_router(struct net_bridge *br, unsigned long val,
390 struct netlink_ext_ack *extack)
391{
Nikolay Aleksandrova97df082021-08-10 18:29:31 +0300392 return br_multicast_set_router(&br->multicast_ctx, val);
Vladimir Oltean9e781402021-02-13 22:43:16 +0200393}
394
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800395static ssize_t multicast_router_store(struct device *d,
Herbert Xu0909e112010-02-27 19:41:49 +0000396 struct device_attribute *attr,
397 const char *buf, size_t len)
398{
Vladimir Oltean9e781402021-02-13 22:43:16 +0200399 return store_bridge_parm(d, buf, len, set_multicast_router);
Herbert Xu0909e112010-02-27 19:41:49 +0000400}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800401static DEVICE_ATTR_RW(multicast_router);
Herbert Xu561f1102010-02-27 19:41:50 +0000402
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800403static ssize_t multicast_snooping_show(struct device *d,
Herbert Xu561f1102010-02-27 19:41:50 +0000404 struct device_attribute *attr,
405 char *buf)
406{
407 struct net_bridge *br = to_bridge(d);
Nikolay Aleksandrov13cefad2018-09-26 17:01:03 +0300408 return sprintf(buf, "%d\n", br_opt_get(br, BROPT_MULTICAST_ENABLED));
Herbert Xu561f1102010-02-27 19:41:50 +0000409}
410
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800411static ssize_t multicast_snooping_store(struct device *d,
Herbert Xu561f1102010-02-27 19:41:50 +0000412 struct device_attribute *attr,
413 const char *buf, size_t len)
414{
Florian Fainelliae1ea842021-04-14 22:22:57 +0300415 return store_bridge_parm(d, buf, len, br_multicast_toggle);
Herbert Xu561f1102010-02-27 19:41:50 +0000416}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800417static DEVICE_ATTR_RW(multicast_snooping);
Herbert Xub1951672010-02-27 19:41:51 +0000418
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800419static ssize_t multicast_query_use_ifaddr_show(struct device *d,
420 struct device_attribute *attr,
421 char *buf)
Cong Wang1c8ad5b2013-05-21 21:52:54 +0000422{
423 struct net_bridge *br = to_bridge(d);
Nikolay Aleksandrov675779a2018-09-26 17:01:04 +0300424 return sprintf(buf, "%d\n",
425 br_opt_get(br, BROPT_MULTICAST_QUERY_USE_IFADDR));
Cong Wang1c8ad5b2013-05-21 21:52:54 +0000426}
427
Vladimir Oltean9e781402021-02-13 22:43:16 +0200428static int set_query_use_ifaddr(struct net_bridge *br, unsigned long val,
429 struct netlink_ext_ack *extack)
Cong Wang1c8ad5b2013-05-21 21:52:54 +0000430{
Nikolay Aleksandrov675779a2018-09-26 17:01:04 +0300431 br_opt_toggle(br, BROPT_MULTICAST_QUERY_USE_IFADDR, !!val);
Cong Wang1c8ad5b2013-05-21 21:52:54 +0000432 return 0;
433}
434
435static ssize_t
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800436multicast_query_use_ifaddr_store(struct device *d,
Cong Wang1c8ad5b2013-05-21 21:52:54 +0000437 struct device_attribute *attr,
438 const char *buf, size_t len)
439{
440 return store_bridge_parm(d, buf, len, set_query_use_ifaddr);
441}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800442static DEVICE_ATTR_RW(multicast_query_use_ifaddr);
Cong Wang1c8ad5b2013-05-21 21:52:54 +0000443
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800444static ssize_t multicast_querier_show(struct device *d,
Herbert Xuc5c23262012-04-13 02:37:42 +0000445 struct device_attribute *attr,
446 char *buf)
447{
448 struct net_bridge *br = to_bridge(d);
Nikolay Aleksandrov62938182021-08-10 18:29:30 +0300449 return sprintf(buf, "%d\n", br->multicast_ctx.multicast_querier);
Herbert Xuc5c23262012-04-13 02:37:42 +0000450}
451
Vladimir Oltean9e781402021-02-13 22:43:16 +0200452static int set_multicast_querier(struct net_bridge *br, unsigned long val,
453 struct netlink_ext_ack *extack)
454{
Nikolay Aleksandrov62938182021-08-10 18:29:30 +0300455 return br_multicast_set_querier(&br->multicast_ctx, val);
Vladimir Oltean9e781402021-02-13 22:43:16 +0200456}
457
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800458static ssize_t multicast_querier_store(struct device *d,
Herbert Xuc5c23262012-04-13 02:37:42 +0000459 struct device_attribute *attr,
460 const char *buf, size_t len)
461{
Vladimir Oltean9e781402021-02-13 22:43:16 +0200462 return store_bridge_parm(d, buf, len, set_multicast_querier);
Herbert Xuc5c23262012-04-13 02:37:42 +0000463}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800464static DEVICE_ATTR_RW(multicast_querier);
Herbert Xuc5c23262012-04-13 02:37:42 +0000465
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800466static ssize_t hash_elasticity_show(struct device *d,
Herbert Xub1951672010-02-27 19:41:51 +0000467 struct device_attribute *attr, char *buf)
468{
Nikolay Aleksandrovcf332bca2018-12-05 15:14:26 +0200469 return sprintf(buf, "%u\n", RHT_ELASTICITY);
Herbert Xub1951672010-02-27 19:41:51 +0000470}
471
Vladimir Oltean9e781402021-02-13 22:43:16 +0200472static int set_elasticity(struct net_bridge *br, unsigned long val,
473 struct netlink_ext_ack *extack)
Herbert Xub1951672010-02-27 19:41:51 +0000474{
Vladimir Oltean9e781402021-02-13 22:43:16 +0200475 /* 16 is RHT_ELASTICITY */
476 NL_SET_ERR_MSG_MOD(extack,
477 "the hash_elasticity option has been deprecated and is always 16");
Herbert Xub1951672010-02-27 19:41:51 +0000478 return 0;
479}
480
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800481static ssize_t hash_elasticity_store(struct device *d,
Herbert Xub1951672010-02-27 19:41:51 +0000482 struct device_attribute *attr,
483 const char *buf, size_t len)
484{
485 return store_bridge_parm(d, buf, len, set_elasticity);
486}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800487static DEVICE_ATTR_RW(hash_elasticity);
Herbert Xub1951672010-02-27 19:41:51 +0000488
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800489static ssize_t hash_max_show(struct device *d, struct device_attribute *attr,
Herbert Xub1951672010-02-27 19:41:51 +0000490 char *buf)
491{
492 struct net_bridge *br = to_bridge(d);
493 return sprintf(buf, "%u\n", br->hash_max);
494}
495
Vladimir Oltean9e781402021-02-13 22:43:16 +0200496static int set_hash_max(struct net_bridge *br, unsigned long val,
497 struct netlink_ext_ack *extack)
Nikolay Aleksandrov19e3a9c2018-12-05 15:14:24 +0200498{
499 br->hash_max = val;
500 return 0;
501}
502
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800503static ssize_t hash_max_store(struct device *d, struct device_attribute *attr,
Herbert Xub1951672010-02-27 19:41:51 +0000504 const char *buf, size_t len)
505{
Nikolay Aleksandrov19e3a9c2018-12-05 15:14:24 +0200506 return store_bridge_parm(d, buf, len, set_hash_max);
Herbert Xub1951672010-02-27 19:41:51 +0000507}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800508static DEVICE_ATTR_RW(hash_max);
Herbert Xud902eee2010-02-27 19:41:52 +0000509
Nikolay Aleksandrov5e923582016-11-21 13:03:24 +0100510static ssize_t multicast_igmp_version_show(struct device *d,
511 struct device_attribute *attr,
512 char *buf)
513{
514 struct net_bridge *br = to_bridge(d);
515
Nikolay Aleksandrovd3d065c2021-07-19 20:06:24 +0300516 return sprintf(buf, "%u\n", br->multicast_ctx.multicast_igmp_version);
Nikolay Aleksandrov5e923582016-11-21 13:03:24 +0100517}
518
Vladimir Oltean9e781402021-02-13 22:43:16 +0200519static int set_multicast_igmp_version(struct net_bridge *br, unsigned long val,
520 struct netlink_ext_ack *extack)
521{
Nikolay Aleksandrovdf271cd2021-08-10 18:29:19 +0300522 return br_multicast_set_igmp_version(&br->multicast_ctx, val);
Vladimir Oltean9e781402021-02-13 22:43:16 +0200523}
524
Nikolay Aleksandrov5e923582016-11-21 13:03:24 +0100525static ssize_t multicast_igmp_version_store(struct device *d,
526 struct device_attribute *attr,
527 const char *buf, size_t len)
528{
Vladimir Oltean9e781402021-02-13 22:43:16 +0200529 return store_bridge_parm(d, buf, len, set_multicast_igmp_version);
Nikolay Aleksandrov5e923582016-11-21 13:03:24 +0100530}
531static DEVICE_ATTR_RW(multicast_igmp_version);
532
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800533static ssize_t multicast_last_member_count_show(struct device *d,
Herbert Xud902eee2010-02-27 19:41:52 +0000534 struct device_attribute *attr,
535 char *buf)
536{
537 struct net_bridge *br = to_bridge(d);
Nikolay Aleksandrovd3d065c2021-07-19 20:06:24 +0300538 return sprintf(buf, "%u\n", br->multicast_ctx.multicast_last_member_count);
Herbert Xud902eee2010-02-27 19:41:52 +0000539}
540
Vladimir Oltean9e781402021-02-13 22:43:16 +0200541static int set_last_member_count(struct net_bridge *br, unsigned long val,
542 struct netlink_ext_ack *extack)
Herbert Xud902eee2010-02-27 19:41:52 +0000543{
Nikolay Aleksandrovd3d065c2021-07-19 20:06:24 +0300544 br->multicast_ctx.multicast_last_member_count = val;
Herbert Xud902eee2010-02-27 19:41:52 +0000545 return 0;
546}
547
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800548static ssize_t multicast_last_member_count_store(struct device *d,
Herbert Xud902eee2010-02-27 19:41:52 +0000549 struct device_attribute *attr,
550 const char *buf, size_t len)
551{
552 return store_bridge_parm(d, buf, len, set_last_member_count);
553}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800554static DEVICE_ATTR_RW(multicast_last_member_count);
Herbert Xud902eee2010-02-27 19:41:52 +0000555
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800556static ssize_t multicast_startup_query_count_show(
Herbert Xud902eee2010-02-27 19:41:52 +0000557 struct device *d, struct device_attribute *attr, char *buf)
558{
559 struct net_bridge *br = to_bridge(d);
Nikolay Aleksandrovd3d065c2021-07-19 20:06:24 +0300560 return sprintf(buf, "%u\n", br->multicast_ctx.multicast_startup_query_count);
Herbert Xud902eee2010-02-27 19:41:52 +0000561}
562
Vladimir Oltean9e781402021-02-13 22:43:16 +0200563static int set_startup_query_count(struct net_bridge *br, unsigned long val,
564 struct netlink_ext_ack *extack)
Herbert Xud902eee2010-02-27 19:41:52 +0000565{
Nikolay Aleksandrovd3d065c2021-07-19 20:06:24 +0300566 br->multicast_ctx.multicast_startup_query_count = val;
Herbert Xud902eee2010-02-27 19:41:52 +0000567 return 0;
568}
569
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800570static ssize_t multicast_startup_query_count_store(
Herbert Xud902eee2010-02-27 19:41:52 +0000571 struct device *d, struct device_attribute *attr, const char *buf,
572 size_t len)
573{
574 return store_bridge_parm(d, buf, len, set_startup_query_count);
575}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800576static DEVICE_ATTR_RW(multicast_startup_query_count);
Herbert Xud902eee2010-02-27 19:41:52 +0000577
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800578static ssize_t multicast_last_member_interval_show(
Herbert Xud902eee2010-02-27 19:41:52 +0000579 struct device *d, struct device_attribute *attr, char *buf)
580{
581 struct net_bridge *br = to_bridge(d);
582 return sprintf(buf, "%lu\n",
Nikolay Aleksandrovd3d065c2021-07-19 20:06:24 +0300583 jiffies_to_clock_t(br->multicast_ctx.multicast_last_member_interval));
Herbert Xud902eee2010-02-27 19:41:52 +0000584}
585
Vladimir Oltean9e781402021-02-13 22:43:16 +0200586static int set_last_member_interval(struct net_bridge *br, unsigned long val,
587 struct netlink_ext_ack *extack)
Herbert Xud902eee2010-02-27 19:41:52 +0000588{
Nikolay Aleksandrovd3d065c2021-07-19 20:06:24 +0300589 br->multicast_ctx.multicast_last_member_interval = clock_t_to_jiffies(val);
Herbert Xud902eee2010-02-27 19:41:52 +0000590 return 0;
591}
592
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800593static ssize_t multicast_last_member_interval_store(
Herbert Xud902eee2010-02-27 19:41:52 +0000594 struct device *d, struct device_attribute *attr, const char *buf,
595 size_t len)
596{
597 return store_bridge_parm(d, buf, len, set_last_member_interval);
598}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800599static DEVICE_ATTR_RW(multicast_last_member_interval);
Herbert Xud902eee2010-02-27 19:41:52 +0000600
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800601static ssize_t multicast_membership_interval_show(
Herbert Xud902eee2010-02-27 19:41:52 +0000602 struct device *d, struct device_attribute *attr, char *buf)
603{
604 struct net_bridge *br = to_bridge(d);
605 return sprintf(buf, "%lu\n",
Nikolay Aleksandrovd3d065c2021-07-19 20:06:24 +0300606 jiffies_to_clock_t(br->multicast_ctx.multicast_membership_interval));
Herbert Xud902eee2010-02-27 19:41:52 +0000607}
608
Vladimir Oltean9e781402021-02-13 22:43:16 +0200609static int set_membership_interval(struct net_bridge *br, unsigned long val,
610 struct netlink_ext_ack *extack)
Herbert Xud902eee2010-02-27 19:41:52 +0000611{
Nikolay Aleksandrovd3d065c2021-07-19 20:06:24 +0300612 br->multicast_ctx.multicast_membership_interval = clock_t_to_jiffies(val);
Herbert Xud902eee2010-02-27 19:41:52 +0000613 return 0;
614}
615
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800616static ssize_t multicast_membership_interval_store(
Herbert Xud902eee2010-02-27 19:41:52 +0000617 struct device *d, struct device_attribute *attr, const char *buf,
618 size_t len)
619{
620 return store_bridge_parm(d, buf, len, set_membership_interval);
621}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800622static DEVICE_ATTR_RW(multicast_membership_interval);
Herbert Xud902eee2010-02-27 19:41:52 +0000623
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800624static ssize_t multicast_querier_interval_show(struct device *d,
Herbert Xud902eee2010-02-27 19:41:52 +0000625 struct device_attribute *attr,
626 char *buf)
627{
628 struct net_bridge *br = to_bridge(d);
629 return sprintf(buf, "%lu\n",
Nikolay Aleksandrovd3d065c2021-07-19 20:06:24 +0300630 jiffies_to_clock_t(br->multicast_ctx.multicast_querier_interval));
Herbert Xud902eee2010-02-27 19:41:52 +0000631}
632
Vladimir Oltean9e781402021-02-13 22:43:16 +0200633static int set_querier_interval(struct net_bridge *br, unsigned long val,
634 struct netlink_ext_ack *extack)
Herbert Xud902eee2010-02-27 19:41:52 +0000635{
Nikolay Aleksandrovd3d065c2021-07-19 20:06:24 +0300636 br->multicast_ctx.multicast_querier_interval = clock_t_to_jiffies(val);
Herbert Xud902eee2010-02-27 19:41:52 +0000637 return 0;
638}
639
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800640static ssize_t multicast_querier_interval_store(struct device *d,
Herbert Xud902eee2010-02-27 19:41:52 +0000641 struct device_attribute *attr,
642 const char *buf, size_t len)
643{
644 return store_bridge_parm(d, buf, len, set_querier_interval);
645}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800646static DEVICE_ATTR_RW(multicast_querier_interval);
Herbert Xud902eee2010-02-27 19:41:52 +0000647
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800648static ssize_t multicast_query_interval_show(struct device *d,
Herbert Xud902eee2010-02-27 19:41:52 +0000649 struct device_attribute *attr,
650 char *buf)
651{
652 struct net_bridge *br = to_bridge(d);
653 return sprintf(buf, "%lu\n",
Nikolay Aleksandrovd3d065c2021-07-19 20:06:24 +0300654 jiffies_to_clock_t(br->multicast_ctx.multicast_query_interval));
Herbert Xud902eee2010-02-27 19:41:52 +0000655}
656
Vladimir Oltean9e781402021-02-13 22:43:16 +0200657static int set_query_interval(struct net_bridge *br, unsigned long val,
658 struct netlink_ext_ack *extack)
Herbert Xud902eee2010-02-27 19:41:52 +0000659{
Nikolay Aleksandrovd3d065c2021-07-19 20:06:24 +0300660 br->multicast_ctx.multicast_query_interval = clock_t_to_jiffies(val);
Herbert Xud902eee2010-02-27 19:41:52 +0000661 return 0;
662}
663
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800664static ssize_t multicast_query_interval_store(struct device *d,
Herbert Xud902eee2010-02-27 19:41:52 +0000665 struct device_attribute *attr,
666 const char *buf, size_t len)
667{
668 return store_bridge_parm(d, buf, len, set_query_interval);
669}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800670static DEVICE_ATTR_RW(multicast_query_interval);
Herbert Xud902eee2010-02-27 19:41:52 +0000671
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800672static ssize_t multicast_query_response_interval_show(
Herbert Xud902eee2010-02-27 19:41:52 +0000673 struct device *d, struct device_attribute *attr, char *buf)
674{
675 struct net_bridge *br = to_bridge(d);
676 return sprintf(
677 buf, "%lu\n",
Nikolay Aleksandrovd3d065c2021-07-19 20:06:24 +0300678 jiffies_to_clock_t(br->multicast_ctx.multicast_query_response_interval));
Herbert Xud902eee2010-02-27 19:41:52 +0000679}
680
Vladimir Oltean9e781402021-02-13 22:43:16 +0200681static int set_query_response_interval(struct net_bridge *br, unsigned long val,
682 struct netlink_ext_ack *extack)
Herbert Xud902eee2010-02-27 19:41:52 +0000683{
Nikolay Aleksandrovd3d065c2021-07-19 20:06:24 +0300684 br->multicast_ctx.multicast_query_response_interval = clock_t_to_jiffies(val);
Herbert Xud902eee2010-02-27 19:41:52 +0000685 return 0;
686}
687
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800688static ssize_t multicast_query_response_interval_store(
Herbert Xud902eee2010-02-27 19:41:52 +0000689 struct device *d, struct device_attribute *attr, const char *buf,
690 size_t len)
691{
692 return store_bridge_parm(d, buf, len, set_query_response_interval);
693}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800694static DEVICE_ATTR_RW(multicast_query_response_interval);
Herbert Xud902eee2010-02-27 19:41:52 +0000695
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800696static ssize_t multicast_startup_query_interval_show(
Herbert Xud902eee2010-02-27 19:41:52 +0000697 struct device *d, struct device_attribute *attr, char *buf)
698{
699 struct net_bridge *br = to_bridge(d);
700 return sprintf(
701 buf, "%lu\n",
Nikolay Aleksandrovd3d065c2021-07-19 20:06:24 +0300702 jiffies_to_clock_t(br->multicast_ctx.multicast_startup_query_interval));
Herbert Xud902eee2010-02-27 19:41:52 +0000703}
704
Vladimir Oltean9e781402021-02-13 22:43:16 +0200705static int set_startup_query_interval(struct net_bridge *br, unsigned long val,
706 struct netlink_ext_ack *extack)
Herbert Xud902eee2010-02-27 19:41:52 +0000707{
Nikolay Aleksandrovd3d065c2021-07-19 20:06:24 +0300708 br->multicast_ctx.multicast_startup_query_interval = clock_t_to_jiffies(val);
Herbert Xud902eee2010-02-27 19:41:52 +0000709 return 0;
710}
711
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800712static ssize_t multicast_startup_query_interval_store(
Herbert Xud902eee2010-02-27 19:41:52 +0000713 struct device *d, struct device_attribute *attr, const char *buf,
714 size_t len)
715{
716 return store_bridge_parm(d, buf, len, set_startup_query_interval);
717}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800718static DEVICE_ATTR_RW(multicast_startup_query_interval);
Nikolay Aleksandrov1080ab92016-06-28 16:57:06 +0200719
720static ssize_t multicast_stats_enabled_show(struct device *d,
721 struct device_attribute *attr,
722 char *buf)
723{
724 struct net_bridge *br = to_bridge(d);
725
Nikolay Aleksandrov675779a2018-09-26 17:01:04 +0300726 return sprintf(buf, "%d\n",
727 br_opt_get(br, BROPT_MULTICAST_STATS_ENABLED));
Nikolay Aleksandrov1080ab92016-06-28 16:57:06 +0200728}
729
Vladimir Oltean9e781402021-02-13 22:43:16 +0200730static int set_stats_enabled(struct net_bridge *br, unsigned long val,
731 struct netlink_ext_ack *extack)
Nikolay Aleksandrov1080ab92016-06-28 16:57:06 +0200732{
Nikolay Aleksandrov675779a2018-09-26 17:01:04 +0300733 br_opt_toggle(br, BROPT_MULTICAST_STATS_ENABLED, !!val);
Nikolay Aleksandrov1080ab92016-06-28 16:57:06 +0200734 return 0;
735}
736
737static ssize_t multicast_stats_enabled_store(struct device *d,
738 struct device_attribute *attr,
739 const char *buf,
740 size_t len)
741{
742 return store_bridge_parm(d, buf, len, set_stats_enabled);
743}
744static DEVICE_ATTR_RW(multicast_stats_enabled);
Nikolay Aleksandrovaa2ae3e2016-11-21 13:03:25 +0100745
746#if IS_ENABLED(CONFIG_IPV6)
747static ssize_t multicast_mld_version_show(struct device *d,
748 struct device_attribute *attr,
749 char *buf)
750{
751 struct net_bridge *br = to_bridge(d);
752
Nikolay Aleksandrovd3d065c2021-07-19 20:06:24 +0300753 return sprintf(buf, "%u\n", br->multicast_ctx.multicast_mld_version);
Nikolay Aleksandrovaa2ae3e2016-11-21 13:03:25 +0100754}
755
Vladimir Oltean9e781402021-02-13 22:43:16 +0200756static int set_multicast_mld_version(struct net_bridge *br, unsigned long val,
757 struct netlink_ext_ack *extack)
758{
Nikolay Aleksandrovdf271cd2021-08-10 18:29:19 +0300759 return br_multicast_set_mld_version(&br->multicast_ctx, val);
Vladimir Oltean9e781402021-02-13 22:43:16 +0200760}
761
Nikolay Aleksandrovaa2ae3e2016-11-21 13:03:25 +0100762static ssize_t multicast_mld_version_store(struct device *d,
763 struct device_attribute *attr,
764 const char *buf, size_t len)
765{
Vladimir Oltean9e781402021-02-13 22:43:16 +0200766 return store_bridge_parm(d, buf, len, set_multicast_mld_version);
Nikolay Aleksandrovaa2ae3e2016-11-21 13:03:25 +0100767}
768static DEVICE_ATTR_RW(multicast_mld_version);
769#endif
Herbert Xu0909e112010-02-27 19:41:49 +0000770#endif
Pablo Neira Ayuso34666d42014-09-18 11:29:03 +0200771#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800772static ssize_t nf_call_iptables_show(
Patrick McHardy4df53d82010-07-02 09:32:57 +0200773 struct device *d, struct device_attribute *attr, char *buf)
774{
775 struct net_bridge *br = to_bridge(d);
Nikolay Aleksandrov8df35102018-09-26 17:01:01 +0300776 return sprintf(buf, "%u\n", br_opt_get(br, BROPT_NF_CALL_IPTABLES));
Patrick McHardy4df53d82010-07-02 09:32:57 +0200777}
778
Vladimir Oltean9e781402021-02-13 22:43:16 +0200779static int set_nf_call_iptables(struct net_bridge *br, unsigned long val,
780 struct netlink_ext_ack *extack)
Patrick McHardy4df53d82010-07-02 09:32:57 +0200781{
Nikolay Aleksandrov8df35102018-09-26 17:01:01 +0300782 br_opt_toggle(br, BROPT_NF_CALL_IPTABLES, !!val);
Patrick McHardy4df53d82010-07-02 09:32:57 +0200783 return 0;
784}
785
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800786static ssize_t nf_call_iptables_store(
Patrick McHardy4df53d82010-07-02 09:32:57 +0200787 struct device *d, struct device_attribute *attr, const char *buf,
788 size_t len)
789{
790 return store_bridge_parm(d, buf, len, set_nf_call_iptables);
791}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800792static DEVICE_ATTR_RW(nf_call_iptables);
Patrick McHardy4df53d82010-07-02 09:32:57 +0200793
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800794static ssize_t nf_call_ip6tables_show(
Patrick McHardy4df53d82010-07-02 09:32:57 +0200795 struct device *d, struct device_attribute *attr, char *buf)
796{
797 struct net_bridge *br = to_bridge(d);
Nikolay Aleksandrov8df35102018-09-26 17:01:01 +0300798 return sprintf(buf, "%u\n", br_opt_get(br, BROPT_NF_CALL_IP6TABLES));
Patrick McHardy4df53d82010-07-02 09:32:57 +0200799}
800
Vladimir Oltean9e781402021-02-13 22:43:16 +0200801static int set_nf_call_ip6tables(struct net_bridge *br, unsigned long val,
802 struct netlink_ext_ack *extack)
Patrick McHardy4df53d82010-07-02 09:32:57 +0200803{
Nikolay Aleksandrov8df35102018-09-26 17:01:01 +0300804 br_opt_toggle(br, BROPT_NF_CALL_IP6TABLES, !!val);
Patrick McHardy4df53d82010-07-02 09:32:57 +0200805 return 0;
806}
807
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800808static ssize_t nf_call_ip6tables_store(
Patrick McHardy4df53d82010-07-02 09:32:57 +0200809 struct device *d, struct device_attribute *attr, const char *buf,
810 size_t len)
811{
812 return store_bridge_parm(d, buf, len, set_nf_call_ip6tables);
813}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800814static DEVICE_ATTR_RW(nf_call_ip6tables);
Patrick McHardy4df53d82010-07-02 09:32:57 +0200815
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800816static ssize_t nf_call_arptables_show(
Patrick McHardy4df53d82010-07-02 09:32:57 +0200817 struct device *d, struct device_attribute *attr, char *buf)
818{
819 struct net_bridge *br = to_bridge(d);
Nikolay Aleksandrov8df35102018-09-26 17:01:01 +0300820 return sprintf(buf, "%u\n", br_opt_get(br, BROPT_NF_CALL_ARPTABLES));
Patrick McHardy4df53d82010-07-02 09:32:57 +0200821}
822
Vladimir Oltean9e781402021-02-13 22:43:16 +0200823static int set_nf_call_arptables(struct net_bridge *br, unsigned long val,
824 struct netlink_ext_ack *extack)
Patrick McHardy4df53d82010-07-02 09:32:57 +0200825{
Nikolay Aleksandrov8df35102018-09-26 17:01:01 +0300826 br_opt_toggle(br, BROPT_NF_CALL_ARPTABLES, !!val);
Patrick McHardy4df53d82010-07-02 09:32:57 +0200827 return 0;
828}
829
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800830static ssize_t nf_call_arptables_store(
Patrick McHardy4df53d82010-07-02 09:32:57 +0200831 struct device *d, struct device_attribute *attr, const char *buf,
832 size_t len)
833{
834 return store_bridge_parm(d, buf, len, set_nf_call_arptables);
835}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800836static DEVICE_ATTR_RW(nf_call_arptables);
Patrick McHardy4df53d82010-07-02 09:32:57 +0200837#endif
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000838#ifdef CONFIG_BRIDGE_VLAN_FILTERING
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800839static ssize_t vlan_filtering_show(struct device *d,
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000840 struct device_attribute *attr,
841 char *buf)
842{
843 struct net_bridge *br = to_bridge(d);
Nikolay Aleksandrovae757672018-09-26 17:01:00 +0300844 return sprintf(buf, "%d\n", br_opt_get(br, BROPT_VLAN_ENABLED));
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000845}
846
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800847static ssize_t vlan_filtering_store(struct device *d,
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000848 struct device_attribute *attr,
849 const char *buf, size_t len)
850{
851 return store_bridge_parm(d, buf, len, br_vlan_filter_toggle);
852}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800853static DEVICE_ATTR_RW(vlan_filtering);
Toshiaki Makita204177f2014-06-10 20:59:25 +0900854
855static ssize_t vlan_protocol_show(struct device *d,
856 struct device_attribute *attr,
857 char *buf)
858{
859 struct net_bridge *br = to_bridge(d);
860 return sprintf(buf, "%#06x\n", ntohs(br->vlan_proto));
861}
862
863static ssize_t vlan_protocol_store(struct device *d,
864 struct device_attribute *attr,
865 const char *buf, size_t len)
866{
867 return store_bridge_parm(d, buf, len, br_vlan_set_proto);
868}
869static DEVICE_ATTR_RW(vlan_protocol);
Vlad Yasevich96a20d92014-10-03 11:29:16 -0400870
871static ssize_t default_pvid_show(struct device *d,
872 struct device_attribute *attr,
873 char *buf)
874{
875 struct net_bridge *br = to_bridge(d);
876 return sprintf(buf, "%d\n", br->default_pvid);
877}
878
879static ssize_t default_pvid_store(struct device *d,
880 struct device_attribute *attr,
881 const char *buf, size_t len)
882{
883 return store_bridge_parm(d, buf, len, br_vlan_set_default_pvid);
884}
885static DEVICE_ATTR_RW(default_pvid);
Nikolay Aleksandrov6dada9b2016-04-30 10:25:28 +0200886
887static ssize_t vlan_stats_enabled_show(struct device *d,
888 struct device_attribute *attr,
889 char *buf)
890{
891 struct net_bridge *br = to_bridge(d);
Nikolay Aleksandrovae757672018-09-26 17:01:00 +0300892 return sprintf(buf, "%u\n", br_opt_get(br, BROPT_VLAN_STATS_ENABLED));
Nikolay Aleksandrov6dada9b2016-04-30 10:25:28 +0200893}
894
Vladimir Oltean9e781402021-02-13 22:43:16 +0200895static int set_vlan_stats_enabled(struct net_bridge *br, unsigned long val,
896 struct netlink_ext_ack *extack)
897{
898 return br_vlan_set_stats(br, val);
899}
900
Nikolay Aleksandrov6dada9b2016-04-30 10:25:28 +0200901static ssize_t vlan_stats_enabled_store(struct device *d,
902 struct device_attribute *attr,
903 const char *buf, size_t len)
904{
Vladimir Oltean9e781402021-02-13 22:43:16 +0200905 return store_bridge_parm(d, buf, len, set_vlan_stats_enabled);
Nikolay Aleksandrov6dada9b2016-04-30 10:25:28 +0200906}
907static DEVICE_ATTR_RW(vlan_stats_enabled);
Nikolay Aleksandrov9163a0f2018-10-12 13:41:16 +0300908
909static ssize_t vlan_stats_per_port_show(struct device *d,
910 struct device_attribute *attr,
911 char *buf)
912{
913 struct net_bridge *br = to_bridge(d);
914 return sprintf(buf, "%u\n", br_opt_get(br, BROPT_VLAN_STATS_PER_PORT));
915}
916
Vladimir Oltean9e781402021-02-13 22:43:16 +0200917static int set_vlan_stats_per_port(struct net_bridge *br, unsigned long val,
918 struct netlink_ext_ack *extack)
919{
920 return br_vlan_set_stats_per_port(br, val);
921}
922
Nikolay Aleksandrov9163a0f2018-10-12 13:41:16 +0300923static ssize_t vlan_stats_per_port_store(struct device *d,
924 struct device_attribute *attr,
925 const char *buf, size_t len)
926{
Vladimir Oltean9e781402021-02-13 22:43:16 +0200927 return store_bridge_parm(d, buf, len, set_vlan_stats_per_port);
Nikolay Aleksandrov9163a0f2018-10-12 13:41:16 +0300928}
929static DEVICE_ATTR_RW(vlan_stats_per_port);
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000930#endif
Herbert Xu0909e112010-02-27 19:41:49 +0000931
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932static struct attribute *bridge_attrs[] = {
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700933 &dev_attr_forward_delay.attr,
934 &dev_attr_hello_time.attr,
935 &dev_attr_max_age.attr,
936 &dev_attr_ageing_time.attr,
937 &dev_attr_stp_state.attr,
stephen hemminger515853c2011-10-03 18:14:46 +0000938 &dev_attr_group_fwd_mask.attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700939 &dev_attr_priority.attr,
940 &dev_attr_bridge_id.attr,
941 &dev_attr_root_id.attr,
942 &dev_attr_root_path_cost.attr,
943 &dev_attr_root_port.attr,
944 &dev_attr_topology_change.attr,
945 &dev_attr_topology_change_detected.attr,
946 &dev_attr_hello_timer.attr,
947 &dev_attr_tcn_timer.attr,
948 &dev_attr_topology_change_timer.attr,
949 &dev_attr_gc_timer.attr,
950 &dev_attr_group_addr.attr,
Stephen Hemminger9cf63742007-04-09 12:57:54 -0700951 &dev_attr_flush.attr,
Nikolay Aleksandrov70e42722018-11-24 04:34:21 +0200952 &dev_attr_no_linklocal_learn.attr,
Herbert Xu0909e112010-02-27 19:41:49 +0000953#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
954 &dev_attr_multicast_router.attr,
Herbert Xu561f1102010-02-27 19:41:50 +0000955 &dev_attr_multicast_snooping.attr,
Herbert Xuc5c23262012-04-13 02:37:42 +0000956 &dev_attr_multicast_querier.attr,
Cong Wang1c8ad5b2013-05-21 21:52:54 +0000957 &dev_attr_multicast_query_use_ifaddr.attr,
Herbert Xub1951672010-02-27 19:41:51 +0000958 &dev_attr_hash_elasticity.attr,
959 &dev_attr_hash_max.attr,
Herbert Xud902eee2010-02-27 19:41:52 +0000960 &dev_attr_multicast_last_member_count.attr,
961 &dev_attr_multicast_startup_query_count.attr,
962 &dev_attr_multicast_last_member_interval.attr,
963 &dev_attr_multicast_membership_interval.attr,
964 &dev_attr_multicast_querier_interval.attr,
965 &dev_attr_multicast_query_interval.attr,
966 &dev_attr_multicast_query_response_interval.attr,
967 &dev_attr_multicast_startup_query_interval.attr,
Nikolay Aleksandrov1080ab92016-06-28 16:57:06 +0200968 &dev_attr_multicast_stats_enabled.attr,
Nikolay Aleksandrov5e923582016-11-21 13:03:24 +0100969 &dev_attr_multicast_igmp_version.attr,
Nikolay Aleksandrovaa2ae3e2016-11-21 13:03:25 +0100970#if IS_ENABLED(CONFIG_IPV6)
971 &dev_attr_multicast_mld_version.attr,
972#endif
Herbert Xu0909e112010-02-27 19:41:49 +0000973#endif
Pablo Neira Ayuso34666d42014-09-18 11:29:03 +0200974#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
Patrick McHardy4df53d82010-07-02 09:32:57 +0200975 &dev_attr_nf_call_iptables.attr,
976 &dev_attr_nf_call_ip6tables.attr,
977 &dev_attr_nf_call_arptables.attr,
978#endif
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000979#ifdef CONFIG_BRIDGE_VLAN_FILTERING
980 &dev_attr_vlan_filtering.attr,
Toshiaki Makita204177f2014-06-10 20:59:25 +0900981 &dev_attr_vlan_protocol.attr,
Vlad Yasevich96a20d92014-10-03 11:29:16 -0400982 &dev_attr_default_pvid.attr,
Nikolay Aleksandrov6dada9b2016-04-30 10:25:28 +0200983 &dev_attr_vlan_stats_enabled.attr,
Nikolay Aleksandrov9163a0f2018-10-12 13:41:16 +0300984 &dev_attr_vlan_stats_per_port.attr,
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000985#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986 NULL
987};
988
Arvind Yadavcddbb792017-06-29 16:39:38 +0530989static const struct attribute_group bridge_group = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990 .name = SYSFS_BRIDGE_ATTR,
991 .attrs = bridge_attrs,
992};
993
994/*
995 * Export the forwarding information table as a binary file
996 * The records are struct __fdb_entry.
997 *
998 * Returns the number of bytes read.
999 */
Chris Wright2c3c8be2010-05-12 18:28:57 -07001000static ssize_t brforward_read(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +08001001 struct bin_attribute *bin_attr,
1002 char *buf, loff_t off, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003{
Geliang Tangaeb7ed12015-12-23 20:42:21 +08001004 struct device *dev = kobj_to_dev(kobj);
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001005 struct net_bridge *br = to_bridge(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006 int n;
1007
1008 /* must read whole records */
1009 if (off % sizeof(struct __fdb_entry) != 0)
1010 return -EINVAL;
1011
YOSHIFUJI Hideaki9d6f2292007-02-09 23:24:35 +09001012 n = br_fdb_fillbuf(br, buf,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013 count / sizeof(struct __fdb_entry),
1014 off / sizeof(struct __fdb_entry));
1015
1016 if (n > 0)
1017 n *= sizeof(struct __fdb_entry);
YOSHIFUJI Hideaki9d6f2292007-02-09 23:24:35 +09001018
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019 return n;
1020}
1021
1022static struct bin_attribute bridge_forward = {
1023 .attr = { .name = SYSFS_BRIDGE_FDB,
Joe Perchesd6444062018-03-23 15:54:38 -07001024 .mode = 0444, },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025 .read = brforward_read,
1026};
1027
1028/*
1029 * Add entries in sysfs onto the existing network class device
1030 * for the bridge.
1031 * Adds a attribute group "bridge" containing tuning parameters.
1032 * Binary attribute containing the forward table
1033 * Sub directory to hold links to interfaces.
1034 *
1035 * Note: the ifobj exists only to be a subdirectory
1036 * to hold links. The ifobj exists in same data structure
1037 * as it's parent the bridge so reference counting works.
1038 */
1039int br_sysfs_addbr(struct net_device *dev)
1040{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001041 struct kobject *brobj = &dev->dev.kobj;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042 struct net_bridge *br = netdev_priv(dev);
1043 int err;
1044
1045 err = sysfs_create_group(brobj, &bridge_group);
1046 if (err) {
1047 pr_info("%s: can't create group %s/%s\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -08001048 __func__, dev->name, bridge_group.name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049 goto out1;
1050 }
1051
1052 err = sysfs_create_bin_file(brobj, &bridge_forward);
1053 if (err) {
Randy Dunlap1842c4b2006-10-25 23:07:37 -07001054 pr_info("%s: can't create attribute file %s/%s\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -08001055 __func__, dev->name, bridge_forward.attr.name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056 goto out2;
1057 }
1058
Greg Kroah-Hartman43b98c42007-12-17 15:54:39 -04001059 br->ifobj = kobject_create_and_add(SYSFS_BRIDGE_PORT_SUBDIR, brobj);
1060 if (!br->ifobj) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061 pr_info("%s: can't add kobject (directory) %s/%s\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -08001062 __func__, dev->name, SYSFS_BRIDGE_PORT_SUBDIR);
Pan Bianb5958962016-12-03 19:33:23 +08001063 err = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064 goto out3;
1065 }
1066 return 0;
1067 out3:
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001068 sysfs_remove_bin_file(&dev->dev.kobj, &bridge_forward);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069 out2:
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001070 sysfs_remove_group(&dev->dev.kobj, &bridge_group);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071 out1:
1072 return err;
1073
1074}
1075
1076void br_sysfs_delbr(struct net_device *dev)
1077{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001078 struct kobject *kobj = &dev->dev.kobj;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079 struct net_bridge *br = netdev_priv(dev);
1080
Greg Kroah-Hartman78a2d902007-12-20 08:13:05 -08001081 kobject_put(br->ifobj);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082 sysfs_remove_bin_file(kobj, &bridge_forward);
1083 sysfs_remove_group(kobj, &bridge_group);
1084}