blob: 6b8091407ca3126b333c76c5104f5a8ca6803e49 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Wang Sheng-Hui15401942013-08-06 08:44:46 +08002 * Sysfs attributes of bridge
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 * Linux ethernet bridge
4 *
5 * Authors:
6 * Stephen Hemminger <shemminger@osdl.org>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version
11 * 2 of the License, or (at your option) any later version.
12 */
13
Randy Dunlap4fc268d2006-01-11 12:17:47 -080014#include <linux/capability.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/kernel.h>
16#include <linux/netdevice.h>
John Fastabendb3343a22012-09-18 00:01:12 +000017#include <linux/etherdevice.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <linux/if_bridge.h>
19#include <linux/rtnetlink.h>
20#include <linux/spinlock.h>
21#include <linux/times.h>
22
23#include "br_private.h"
24
Wang Chen524ad0a2008-11-12 23:39:10 -080025#define to_bridge(cd) ((struct net_bridge *)netdev_priv(to_net_dev(cd)))
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
27/*
28 * Common code for storing bridge parameters.
29 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -070030static ssize_t store_bridge_parm(struct device *d,
Linus Torvalds1da177e2005-04-16 15:20:36 -070031 const char *buf, size_t len,
Stephen Hemminger8d4698f72008-09-08 13:44:40 -070032 int (*set)(struct net_bridge *, unsigned long))
Linus Torvalds1da177e2005-04-16 15:20:36 -070033{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -070034 struct net_bridge *br = to_bridge(d);
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 char *endp;
36 unsigned long val;
Stephen Hemminger8d4698f72008-09-08 13:44:40 -070037 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
Eric W. Biedermancb990502012-11-16 03:03:08 +000039 if (!ns_capable(dev_net(br->dev)->user_ns, CAP_NET_ADMIN))
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 return -EPERM;
41
42 val = simple_strtoul(buf, &endp, 0);
43 if (endp == buf)
44 return -EINVAL;
45
Stephen Hemminger8d4698f72008-09-08 13:44:40 -070046 err = (*set)(br, val);
Stephen Hemminger8d4698f72008-09-08 13:44:40 -070047 return err ? err : len;
Linus Torvalds1da177e2005-04-16 15:20:36 -070048}
49
50
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -080051static ssize_t forward_delay_show(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -070052 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -070053{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -070054 struct net_bridge *br = to_bridge(d);
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 return sprintf(buf, "%lu\n", jiffies_to_clock_t(br->forward_delay));
56}
57
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -080058static ssize_t forward_delay_store(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -070059 struct device_attribute *attr,
60 const char *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -070061{
stephen hemminger14f98f22011-04-04 14:03:33 +000062 return store_bridge_parm(d, buf, len, br_set_forward_delay);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -080064static DEVICE_ATTR_RW(forward_delay);
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -080066static ssize_t hello_time_show(struct device *d, struct device_attribute *attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -070067 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -070068{
69 return sprintf(buf, "%lu\n",
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -070070 jiffies_to_clock_t(to_bridge(d)->hello_time));
Linus Torvalds1da177e2005-04-16 15:20:36 -070071}
72
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -080073static ssize_t hello_time_store(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -070074 struct device_attribute *attr, const char *buf,
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 size_t len)
76{
stephen hemminger14f98f22011-04-04 14:03:33 +000077 return store_bridge_parm(d, buf, len, br_set_hello_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -070078}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -080079static DEVICE_ATTR_RW(hello_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -070080
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -080081static ssize_t max_age_show(struct device *d, struct device_attribute *attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -070082 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -070083{
84 return sprintf(buf, "%lu\n",
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -070085 jiffies_to_clock_t(to_bridge(d)->max_age));
Linus Torvalds1da177e2005-04-16 15:20:36 -070086}
87
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -080088static ssize_t max_age_store(struct device *d, struct device_attribute *attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -070089 const char *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -070090{
stephen hemminger14f98f22011-04-04 14:03:33 +000091 return store_bridge_parm(d, buf, len, br_set_max_age);
Linus Torvalds1da177e2005-04-16 15:20:36 -070092}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -080093static DEVICE_ATTR_RW(max_age);
Linus Torvalds1da177e2005-04-16 15:20:36 -070094
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -080095static ssize_t ageing_time_show(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -070096 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -070097{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -070098 struct net_bridge *br = to_bridge(d);
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 return sprintf(buf, "%lu\n", jiffies_to_clock_t(br->ageing_time));
100}
101
Stephen Hemminger8d4698f72008-09-08 13:44:40 -0700102static int set_ageing_time(struct net_bridge *br, unsigned long val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103{
Nikolay Aleksandrovaf379392015-10-12 17:55:55 +0200104 int ret;
105
106 if (!rtnl_trylock())
107 return restart_syscall();
108
109 ret = br_set_ageing_time(br, val);
110 rtnl_unlock();
111
112 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113}
114
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800115static ssize_t ageing_time_store(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700116 struct device_attribute *attr,
117 const char *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700119 return store_bridge_parm(d, buf, len, set_ageing_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800121static DEVICE_ATTR_RW(ageing_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800123static ssize_t stp_state_show(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700124 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700126 struct net_bridge *br = to_bridge(d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 return sprintf(buf, "%d\n", br->stp_enabled);
128}
129
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800131static ssize_t stp_state_store(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700132 struct device_attribute *attr, const char *buf,
133 size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134{
Stephen Hemminger17120882007-08-14 13:21:34 -0700135 struct net_bridge *br = to_bridge(d);
136 char *endp;
137 unsigned long val;
138
Eric W. Biedermancb990502012-11-16 03:03:08 +0000139 if (!ns_capable(dev_net(br->dev)->user_ns, CAP_NET_ADMIN))
Stephen Hemminger17120882007-08-14 13:21:34 -0700140 return -EPERM;
141
142 val = simple_strtoul(buf, &endp, 0);
143 if (endp == buf)
144 return -EINVAL;
145
Eric W. Biedermanaf38f292009-05-13 17:00:41 +0000146 if (!rtnl_trylock())
147 return restart_syscall();
Stephen Hemminger17120882007-08-14 13:21:34 -0700148 br_stp_set_enabled(br, val);
149 rtnl_unlock();
150
Al Viro35b426c2007-08-19 04:51:26 +0100151 return len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800153static DEVICE_ATTR_RW(stp_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800155static ssize_t group_fwd_mask_show(struct device *d,
156 struct device_attribute *attr,
157 char *buf)
stephen hemminger515853c2011-10-03 18:14:46 +0000158{
159 struct net_bridge *br = to_bridge(d);
160 return sprintf(buf, "%#x\n", br->group_fwd_mask);
161}
162
163
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800164static ssize_t group_fwd_mask_store(struct device *d,
165 struct device_attribute *attr,
166 const char *buf,
167 size_t len)
stephen hemminger515853c2011-10-03 18:14:46 +0000168{
169 struct net_bridge *br = to_bridge(d);
170 char *endp;
171 unsigned long val;
172
Eric W. Biedermancb990502012-11-16 03:03:08 +0000173 if (!ns_capable(dev_net(br->dev)->user_ns, CAP_NET_ADMIN))
stephen hemminger515853c2011-10-03 18:14:46 +0000174 return -EPERM;
175
176 val = simple_strtoul(buf, &endp, 0);
177 if (endp == buf)
178 return -EINVAL;
179
180 if (val & BR_GROUPFWD_RESTRICTED)
181 return -EINVAL;
182
183 br->group_fwd_mask = val;
184
185 return len;
186}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800187static DEVICE_ATTR_RW(group_fwd_mask);
stephen hemminger515853c2011-10-03 18:14:46 +0000188
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800189static ssize_t priority_show(struct device *d, struct device_attribute *attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700190 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700192 struct net_bridge *br = to_bridge(d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 return sprintf(buf, "%d\n",
194 (br->bridge_id.prio[0] << 8) | br->bridge_id.prio[1]);
195}
196
Stephen Hemminger8d4698f72008-09-08 13:44:40 -0700197static int set_priority(struct net_bridge *br, unsigned long val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198{
199 br_stp_set_bridge_priority(br, (u16) val);
Stephen Hemminger8d4698f72008-09-08 13:44:40 -0700200 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201}
202
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800203static ssize_t priority_store(struct device *d, struct device_attribute *attr,
204 const char *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700206 return store_bridge_parm(d, buf, len, set_priority);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800208static DEVICE_ATTR_RW(priority);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800210static ssize_t root_id_show(struct device *d, struct device_attribute *attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700211 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700213 return br_show_bridge_id(buf, &to_bridge(d)->designated_root);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800215static DEVICE_ATTR_RO(root_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800217static ssize_t bridge_id_show(struct device *d, struct device_attribute *attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700218 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700220 return br_show_bridge_id(buf, &to_bridge(d)->bridge_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800222static DEVICE_ATTR_RO(bridge_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800224static ssize_t root_port_show(struct device *d, struct device_attribute *attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700225 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700227 return sprintf(buf, "%d\n", to_bridge(d)->root_port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800229static DEVICE_ATTR_RO(root_port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800231static ssize_t root_path_cost_show(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700232 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700234 return sprintf(buf, "%d\n", to_bridge(d)->root_path_cost);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800236static DEVICE_ATTR_RO(root_path_cost);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800238static ssize_t topology_change_show(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700239 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700241 return sprintf(buf, "%d\n", to_bridge(d)->topology_change);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800243static DEVICE_ATTR_RO(topology_change);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800245static ssize_t topology_change_detected_show(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700246 struct device_attribute *attr,
247 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700249 struct net_bridge *br = to_bridge(d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 return sprintf(buf, "%d\n", br->topology_change_detected);
251}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800252static DEVICE_ATTR_RO(topology_change_detected);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800254static ssize_t hello_timer_show(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700255 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700257 struct net_bridge *br = to_bridge(d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 return sprintf(buf, "%ld\n", br_timer_value(&br->hello_timer));
259}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800260static DEVICE_ATTR_RO(hello_timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800262static ssize_t tcn_timer_show(struct device *d, struct device_attribute *attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700263 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700265 struct net_bridge *br = to_bridge(d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 return sprintf(buf, "%ld\n", br_timer_value(&br->tcn_timer));
267}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800268static DEVICE_ATTR_RO(tcn_timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800270static ssize_t topology_change_timer_show(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700271 struct device_attribute *attr,
272 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700274 struct net_bridge *br = to_bridge(d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 return sprintf(buf, "%ld\n", br_timer_value(&br->topology_change_timer));
276}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800277static DEVICE_ATTR_RO(topology_change_timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800279static ssize_t gc_timer_show(struct device *d, struct device_attribute *attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700280 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700282 struct net_bridge *br = to_bridge(d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 return sprintf(buf, "%ld\n", br_timer_value(&br->gc_timer));
284}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800285static DEVICE_ATTR_RO(gc_timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800287static ssize_t group_addr_show(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700288 struct device_attribute *attr, char *buf)
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800289{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700290 struct net_bridge *br = to_bridge(d);
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800291 return sprintf(buf, "%x:%x:%x:%x:%x:%x\n",
292 br->group_addr[0], br->group_addr[1],
293 br->group_addr[2], br->group_addr[3],
294 br->group_addr[4], br->group_addr[5]);
295}
296
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800297static ssize_t group_addr_store(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700298 struct device_attribute *attr,
299 const char *buf, size_t len)
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800300{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700301 struct net_bridge *br = to_bridge(d);
Ben Hutchings4197f242012-11-01 09:10:04 +0000302 u8 new_addr[6];
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800303 int i;
304
Eric W. Biedermancb990502012-11-16 03:03:08 +0000305 if (!ns_capable(dev_net(br->dev)->user_ns, CAP_NET_ADMIN))
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800306 return -EPERM;
307
Ben Hutchings4197f242012-11-01 09:10:04 +0000308 if (sscanf(buf, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx",
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800309 &new_addr[0], &new_addr[1], &new_addr[2],
310 &new_addr[3], &new_addr[4], &new_addr[5]) != 6)
311 return -EINVAL;
312
Ben Hutchings46acc462012-11-01 09:11:11 +0000313 if (!is_link_local_ether_addr(new_addr))
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800314 return -EINVAL;
315
Joe Perchesf64f9e72009-11-29 16:55:45 -0800316 if (new_addr[5] == 1 || /* 802.3x Pause address */
317 new_addr[5] == 2 || /* 802.3ad Slow protocols */
318 new_addr[5] == 3) /* 802.1X PAE address */
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800319 return -EINVAL;
320
Toshiaki Makita204177f2014-06-10 20:59:25 +0900321 if (!rtnl_trylock())
322 return restart_syscall();
323
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800324 spin_lock_bh(&br->lock);
325 for (i = 0; i < 6; i++)
326 br->group_addr[i] = new_addr[i];
327 spin_unlock_bh(&br->lock);
Toshiaki Makita204177f2014-06-10 20:59:25 +0900328
329 br->group_addr_set = true;
330 br_recalculate_fwd_mask(br);
331
332 rtnl_unlock();
333
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800334 return len;
335}
336
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800337static DEVICE_ATTR_RW(group_addr);
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800338
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800339static ssize_t flush_store(struct device *d,
Stephen Hemminger9cf63742007-04-09 12:57:54 -0700340 struct device_attribute *attr,
341 const char *buf, size_t len)
342{
343 struct net_bridge *br = to_bridge(d);
344
Eric W. Biedermancb990502012-11-16 03:03:08 +0000345 if (!ns_capable(dev_net(br->dev)->user_ns, CAP_NET_ADMIN))
Stephen Hemminger9cf63742007-04-09 12:57:54 -0700346 return -EPERM;
347
348 br_fdb_flush(br);
349 return len;
350}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800351static DEVICE_ATTR_WO(flush);
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800352
Herbert Xu0909e112010-02-27 19:41:49 +0000353#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800354static ssize_t multicast_router_show(struct device *d,
Herbert Xu0909e112010-02-27 19:41:49 +0000355 struct device_attribute *attr, char *buf)
356{
357 struct net_bridge *br = to_bridge(d);
358 return sprintf(buf, "%d\n", br->multicast_router);
359}
360
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800361static ssize_t multicast_router_store(struct device *d,
Herbert Xu0909e112010-02-27 19:41:49 +0000362 struct device_attribute *attr,
363 const char *buf, size_t len)
364{
365 return store_bridge_parm(d, buf, len, br_multicast_set_router);
366}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800367static DEVICE_ATTR_RW(multicast_router);
Herbert Xu561f1102010-02-27 19:41:50 +0000368
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800369static ssize_t multicast_snooping_show(struct device *d,
Herbert Xu561f1102010-02-27 19:41:50 +0000370 struct device_attribute *attr,
371 char *buf)
372{
373 struct net_bridge *br = to_bridge(d);
374 return sprintf(buf, "%d\n", !br->multicast_disabled);
375}
376
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800377static ssize_t multicast_snooping_store(struct device *d,
Herbert Xu561f1102010-02-27 19:41:50 +0000378 struct device_attribute *attr,
379 const char *buf, size_t len)
380{
381 return store_bridge_parm(d, buf, len, br_multicast_toggle);
382}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800383static DEVICE_ATTR_RW(multicast_snooping);
Herbert Xub1951672010-02-27 19:41:51 +0000384
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800385static ssize_t multicast_query_use_ifaddr_show(struct device *d,
386 struct device_attribute *attr,
387 char *buf)
Cong Wang1c8ad5b2013-05-21 21:52:54 +0000388{
389 struct net_bridge *br = to_bridge(d);
390 return sprintf(buf, "%d\n", br->multicast_query_use_ifaddr);
391}
392
393static int set_query_use_ifaddr(struct net_bridge *br, unsigned long val)
394{
395 br->multicast_query_use_ifaddr = !!val;
396 return 0;
397}
398
399static ssize_t
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800400multicast_query_use_ifaddr_store(struct device *d,
Cong Wang1c8ad5b2013-05-21 21:52:54 +0000401 struct device_attribute *attr,
402 const char *buf, size_t len)
403{
404 return store_bridge_parm(d, buf, len, set_query_use_ifaddr);
405}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800406static DEVICE_ATTR_RW(multicast_query_use_ifaddr);
Cong Wang1c8ad5b2013-05-21 21:52:54 +0000407
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800408static ssize_t multicast_querier_show(struct device *d,
Herbert Xuc5c23262012-04-13 02:37:42 +0000409 struct device_attribute *attr,
410 char *buf)
411{
412 struct net_bridge *br = to_bridge(d);
413 return sprintf(buf, "%d\n", br->multicast_querier);
414}
415
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800416static ssize_t multicast_querier_store(struct device *d,
Herbert Xuc5c23262012-04-13 02:37:42 +0000417 struct device_attribute *attr,
418 const char *buf, size_t len)
419{
420 return store_bridge_parm(d, buf, len, br_multicast_set_querier);
421}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800422static DEVICE_ATTR_RW(multicast_querier);
Herbert Xuc5c23262012-04-13 02:37:42 +0000423
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800424static ssize_t hash_elasticity_show(struct device *d,
Herbert Xub1951672010-02-27 19:41:51 +0000425 struct device_attribute *attr, char *buf)
426{
427 struct net_bridge *br = to_bridge(d);
428 return sprintf(buf, "%u\n", br->hash_elasticity);
429}
430
431static int set_elasticity(struct net_bridge *br, unsigned long val)
432{
433 br->hash_elasticity = val;
434 return 0;
435}
436
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800437static ssize_t hash_elasticity_store(struct device *d,
Herbert Xub1951672010-02-27 19:41:51 +0000438 struct device_attribute *attr,
439 const char *buf, size_t len)
440{
441 return store_bridge_parm(d, buf, len, set_elasticity);
442}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800443static DEVICE_ATTR_RW(hash_elasticity);
Herbert Xub1951672010-02-27 19:41:51 +0000444
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800445static ssize_t hash_max_show(struct device *d, struct device_attribute *attr,
Herbert Xub1951672010-02-27 19:41:51 +0000446 char *buf)
447{
448 struct net_bridge *br = to_bridge(d);
449 return sprintf(buf, "%u\n", br->hash_max);
450}
451
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800452static ssize_t hash_max_store(struct device *d, struct device_attribute *attr,
Herbert Xub1951672010-02-27 19:41:51 +0000453 const char *buf, size_t len)
454{
455 return store_bridge_parm(d, buf, len, br_multicast_set_hash_max);
456}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800457static DEVICE_ATTR_RW(hash_max);
Herbert Xud902eee2010-02-27 19:41:52 +0000458
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800459static ssize_t multicast_last_member_count_show(struct device *d,
Herbert Xud902eee2010-02-27 19:41:52 +0000460 struct device_attribute *attr,
461 char *buf)
462{
463 struct net_bridge *br = to_bridge(d);
464 return sprintf(buf, "%u\n", br->multicast_last_member_count);
465}
466
467static int set_last_member_count(struct net_bridge *br, unsigned long val)
468{
469 br->multicast_last_member_count = val;
470 return 0;
471}
472
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800473static ssize_t multicast_last_member_count_store(struct device *d,
Herbert Xud902eee2010-02-27 19:41:52 +0000474 struct device_attribute *attr,
475 const char *buf, size_t len)
476{
477 return store_bridge_parm(d, buf, len, set_last_member_count);
478}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800479static DEVICE_ATTR_RW(multicast_last_member_count);
Herbert Xud902eee2010-02-27 19:41:52 +0000480
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800481static ssize_t multicast_startup_query_count_show(
Herbert Xud902eee2010-02-27 19:41:52 +0000482 struct device *d, struct device_attribute *attr, char *buf)
483{
484 struct net_bridge *br = to_bridge(d);
485 return sprintf(buf, "%u\n", br->multicast_startup_query_count);
486}
487
488static int set_startup_query_count(struct net_bridge *br, unsigned long val)
489{
490 br->multicast_startup_query_count = val;
491 return 0;
492}
493
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800494static ssize_t multicast_startup_query_count_store(
Herbert Xud902eee2010-02-27 19:41:52 +0000495 struct device *d, struct device_attribute *attr, const char *buf,
496 size_t len)
497{
498 return store_bridge_parm(d, buf, len, set_startup_query_count);
499}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800500static DEVICE_ATTR_RW(multicast_startup_query_count);
Herbert Xud902eee2010-02-27 19:41:52 +0000501
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800502static ssize_t multicast_last_member_interval_show(
Herbert Xud902eee2010-02-27 19:41:52 +0000503 struct device *d, struct device_attribute *attr, char *buf)
504{
505 struct net_bridge *br = to_bridge(d);
506 return sprintf(buf, "%lu\n",
507 jiffies_to_clock_t(br->multicast_last_member_interval));
508}
509
510static int set_last_member_interval(struct net_bridge *br, unsigned long val)
511{
512 br->multicast_last_member_interval = clock_t_to_jiffies(val);
513 return 0;
514}
515
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800516static ssize_t multicast_last_member_interval_store(
Herbert Xud902eee2010-02-27 19:41:52 +0000517 struct device *d, struct device_attribute *attr, const char *buf,
518 size_t len)
519{
520 return store_bridge_parm(d, buf, len, set_last_member_interval);
521}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800522static DEVICE_ATTR_RW(multicast_last_member_interval);
Herbert Xud902eee2010-02-27 19:41:52 +0000523
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800524static ssize_t multicast_membership_interval_show(
Herbert Xud902eee2010-02-27 19:41:52 +0000525 struct device *d, struct device_attribute *attr, char *buf)
526{
527 struct net_bridge *br = to_bridge(d);
528 return sprintf(buf, "%lu\n",
529 jiffies_to_clock_t(br->multicast_membership_interval));
530}
531
532static int set_membership_interval(struct net_bridge *br, unsigned long val)
533{
534 br->multicast_membership_interval = clock_t_to_jiffies(val);
535 return 0;
536}
537
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800538static ssize_t multicast_membership_interval_store(
Herbert Xud902eee2010-02-27 19:41:52 +0000539 struct device *d, struct device_attribute *attr, const char *buf,
540 size_t len)
541{
542 return store_bridge_parm(d, buf, len, set_membership_interval);
543}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800544static DEVICE_ATTR_RW(multicast_membership_interval);
Herbert Xud902eee2010-02-27 19:41:52 +0000545
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800546static ssize_t multicast_querier_interval_show(struct device *d,
Herbert Xud902eee2010-02-27 19:41:52 +0000547 struct device_attribute *attr,
548 char *buf)
549{
550 struct net_bridge *br = to_bridge(d);
551 return sprintf(buf, "%lu\n",
552 jiffies_to_clock_t(br->multicast_querier_interval));
553}
554
555static int set_querier_interval(struct net_bridge *br, unsigned long val)
556{
557 br->multicast_querier_interval = clock_t_to_jiffies(val);
558 return 0;
559}
560
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800561static ssize_t multicast_querier_interval_store(struct device *d,
Herbert Xud902eee2010-02-27 19:41:52 +0000562 struct device_attribute *attr,
563 const char *buf, size_t len)
564{
565 return store_bridge_parm(d, buf, len, set_querier_interval);
566}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800567static DEVICE_ATTR_RW(multicast_querier_interval);
Herbert Xud902eee2010-02-27 19:41:52 +0000568
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800569static ssize_t multicast_query_interval_show(struct device *d,
Herbert Xud902eee2010-02-27 19:41:52 +0000570 struct device_attribute *attr,
571 char *buf)
572{
573 struct net_bridge *br = to_bridge(d);
574 return sprintf(buf, "%lu\n",
575 jiffies_to_clock_t(br->multicast_query_interval));
576}
577
578static int set_query_interval(struct net_bridge *br, unsigned long val)
579{
580 br->multicast_query_interval = clock_t_to_jiffies(val);
581 return 0;
582}
583
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800584static ssize_t multicast_query_interval_store(struct device *d,
Herbert Xud902eee2010-02-27 19:41:52 +0000585 struct device_attribute *attr,
586 const char *buf, size_t len)
587{
588 return store_bridge_parm(d, buf, len, set_query_interval);
589}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800590static DEVICE_ATTR_RW(multicast_query_interval);
Herbert Xud902eee2010-02-27 19:41:52 +0000591
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800592static ssize_t multicast_query_response_interval_show(
Herbert Xud902eee2010-02-27 19:41:52 +0000593 struct device *d, struct device_attribute *attr, char *buf)
594{
595 struct net_bridge *br = to_bridge(d);
596 return sprintf(
597 buf, "%lu\n",
598 jiffies_to_clock_t(br->multicast_query_response_interval));
599}
600
601static int set_query_response_interval(struct net_bridge *br, unsigned long val)
602{
603 br->multicast_query_response_interval = clock_t_to_jiffies(val);
604 return 0;
605}
606
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800607static ssize_t multicast_query_response_interval_store(
Herbert Xud902eee2010-02-27 19:41:52 +0000608 struct device *d, struct device_attribute *attr, const char *buf,
609 size_t len)
610{
611 return store_bridge_parm(d, buf, len, set_query_response_interval);
612}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800613static DEVICE_ATTR_RW(multicast_query_response_interval);
Herbert Xud902eee2010-02-27 19:41:52 +0000614
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800615static ssize_t multicast_startup_query_interval_show(
Herbert Xud902eee2010-02-27 19:41:52 +0000616 struct device *d, struct device_attribute *attr, char *buf)
617{
618 struct net_bridge *br = to_bridge(d);
619 return sprintf(
620 buf, "%lu\n",
621 jiffies_to_clock_t(br->multicast_startup_query_interval));
622}
623
624static int set_startup_query_interval(struct net_bridge *br, unsigned long val)
625{
626 br->multicast_startup_query_interval = clock_t_to_jiffies(val);
627 return 0;
628}
629
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800630static ssize_t multicast_startup_query_interval_store(
Herbert Xud902eee2010-02-27 19:41:52 +0000631 struct device *d, struct device_attribute *attr, const char *buf,
632 size_t len)
633{
634 return store_bridge_parm(d, buf, len, set_startup_query_interval);
635}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800636static DEVICE_ATTR_RW(multicast_startup_query_interval);
Herbert Xu0909e112010-02-27 19:41:49 +0000637#endif
Pablo Neira Ayuso34666d42014-09-18 11:29:03 +0200638#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800639static ssize_t nf_call_iptables_show(
Patrick McHardy4df53d82010-07-02 09:32:57 +0200640 struct device *d, struct device_attribute *attr, char *buf)
641{
642 struct net_bridge *br = to_bridge(d);
643 return sprintf(buf, "%u\n", br->nf_call_iptables);
644}
645
646static int set_nf_call_iptables(struct net_bridge *br, unsigned long val)
647{
648 br->nf_call_iptables = val ? true : false;
649 return 0;
650}
651
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800652static ssize_t nf_call_iptables_store(
Patrick McHardy4df53d82010-07-02 09:32:57 +0200653 struct device *d, struct device_attribute *attr, const char *buf,
654 size_t len)
655{
656 return store_bridge_parm(d, buf, len, set_nf_call_iptables);
657}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800658static DEVICE_ATTR_RW(nf_call_iptables);
Patrick McHardy4df53d82010-07-02 09:32:57 +0200659
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800660static ssize_t nf_call_ip6tables_show(
Patrick McHardy4df53d82010-07-02 09:32:57 +0200661 struct device *d, struct device_attribute *attr, char *buf)
662{
663 struct net_bridge *br = to_bridge(d);
664 return sprintf(buf, "%u\n", br->nf_call_ip6tables);
665}
666
667static int set_nf_call_ip6tables(struct net_bridge *br, unsigned long val)
668{
669 br->nf_call_ip6tables = val ? true : false;
670 return 0;
671}
672
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800673static ssize_t nf_call_ip6tables_store(
Patrick McHardy4df53d82010-07-02 09:32:57 +0200674 struct device *d, struct device_attribute *attr, const char *buf,
675 size_t len)
676{
677 return store_bridge_parm(d, buf, len, set_nf_call_ip6tables);
678}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800679static DEVICE_ATTR_RW(nf_call_ip6tables);
Patrick McHardy4df53d82010-07-02 09:32:57 +0200680
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800681static ssize_t nf_call_arptables_show(
Patrick McHardy4df53d82010-07-02 09:32:57 +0200682 struct device *d, struct device_attribute *attr, char *buf)
683{
684 struct net_bridge *br = to_bridge(d);
685 return sprintf(buf, "%u\n", br->nf_call_arptables);
686}
687
688static int set_nf_call_arptables(struct net_bridge *br, unsigned long val)
689{
690 br->nf_call_arptables = val ? true : false;
691 return 0;
692}
693
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800694static ssize_t nf_call_arptables_store(
Patrick McHardy4df53d82010-07-02 09:32:57 +0200695 struct device *d, struct device_attribute *attr, const char *buf,
696 size_t len)
697{
698 return store_bridge_parm(d, buf, len, set_nf_call_arptables);
699}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800700static DEVICE_ATTR_RW(nf_call_arptables);
Patrick McHardy4df53d82010-07-02 09:32:57 +0200701#endif
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000702#ifdef CONFIG_BRIDGE_VLAN_FILTERING
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800703static ssize_t vlan_filtering_show(struct device *d,
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000704 struct device_attribute *attr,
705 char *buf)
706{
707 struct net_bridge *br = to_bridge(d);
708 return sprintf(buf, "%d\n", br->vlan_enabled);
709}
710
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800711static ssize_t vlan_filtering_store(struct device *d,
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000712 struct device_attribute *attr,
713 const char *buf, size_t len)
714{
715 return store_bridge_parm(d, buf, len, br_vlan_filter_toggle);
716}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800717static DEVICE_ATTR_RW(vlan_filtering);
Toshiaki Makita204177f2014-06-10 20:59:25 +0900718
719static ssize_t vlan_protocol_show(struct device *d,
720 struct device_attribute *attr,
721 char *buf)
722{
723 struct net_bridge *br = to_bridge(d);
724 return sprintf(buf, "%#06x\n", ntohs(br->vlan_proto));
725}
726
727static ssize_t vlan_protocol_store(struct device *d,
728 struct device_attribute *attr,
729 const char *buf, size_t len)
730{
731 return store_bridge_parm(d, buf, len, br_vlan_set_proto);
732}
733static DEVICE_ATTR_RW(vlan_protocol);
Vlad Yasevich96a20d92014-10-03 11:29:16 -0400734
735static ssize_t default_pvid_show(struct device *d,
736 struct device_attribute *attr,
737 char *buf)
738{
739 struct net_bridge *br = to_bridge(d);
740 return sprintf(buf, "%d\n", br->default_pvid);
741}
742
743static ssize_t default_pvid_store(struct device *d,
744 struct device_attribute *attr,
745 const char *buf, size_t len)
746{
747 return store_bridge_parm(d, buf, len, br_vlan_set_default_pvid);
748}
749static DEVICE_ATTR_RW(default_pvid);
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000750#endif
Herbert Xu0909e112010-02-27 19:41:49 +0000751
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752static struct attribute *bridge_attrs[] = {
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700753 &dev_attr_forward_delay.attr,
754 &dev_attr_hello_time.attr,
755 &dev_attr_max_age.attr,
756 &dev_attr_ageing_time.attr,
757 &dev_attr_stp_state.attr,
stephen hemminger515853c2011-10-03 18:14:46 +0000758 &dev_attr_group_fwd_mask.attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700759 &dev_attr_priority.attr,
760 &dev_attr_bridge_id.attr,
761 &dev_attr_root_id.attr,
762 &dev_attr_root_path_cost.attr,
763 &dev_attr_root_port.attr,
764 &dev_attr_topology_change.attr,
765 &dev_attr_topology_change_detected.attr,
766 &dev_attr_hello_timer.attr,
767 &dev_attr_tcn_timer.attr,
768 &dev_attr_topology_change_timer.attr,
769 &dev_attr_gc_timer.attr,
770 &dev_attr_group_addr.attr,
Stephen Hemminger9cf63742007-04-09 12:57:54 -0700771 &dev_attr_flush.attr,
Herbert Xu0909e112010-02-27 19:41:49 +0000772#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
773 &dev_attr_multicast_router.attr,
Herbert Xu561f1102010-02-27 19:41:50 +0000774 &dev_attr_multicast_snooping.attr,
Herbert Xuc5c23262012-04-13 02:37:42 +0000775 &dev_attr_multicast_querier.attr,
Cong Wang1c8ad5b2013-05-21 21:52:54 +0000776 &dev_attr_multicast_query_use_ifaddr.attr,
Herbert Xub1951672010-02-27 19:41:51 +0000777 &dev_attr_hash_elasticity.attr,
778 &dev_attr_hash_max.attr,
Herbert Xud902eee2010-02-27 19:41:52 +0000779 &dev_attr_multicast_last_member_count.attr,
780 &dev_attr_multicast_startup_query_count.attr,
781 &dev_attr_multicast_last_member_interval.attr,
782 &dev_attr_multicast_membership_interval.attr,
783 &dev_attr_multicast_querier_interval.attr,
784 &dev_attr_multicast_query_interval.attr,
785 &dev_attr_multicast_query_response_interval.attr,
786 &dev_attr_multicast_startup_query_interval.attr,
Herbert Xu0909e112010-02-27 19:41:49 +0000787#endif
Pablo Neira Ayuso34666d42014-09-18 11:29:03 +0200788#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
Patrick McHardy4df53d82010-07-02 09:32:57 +0200789 &dev_attr_nf_call_iptables.attr,
790 &dev_attr_nf_call_ip6tables.attr,
791 &dev_attr_nf_call_arptables.attr,
792#endif
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000793#ifdef CONFIG_BRIDGE_VLAN_FILTERING
794 &dev_attr_vlan_filtering.attr,
Toshiaki Makita204177f2014-06-10 20:59:25 +0900795 &dev_attr_vlan_protocol.attr,
Vlad Yasevich96a20d92014-10-03 11:29:16 -0400796 &dev_attr_default_pvid.attr,
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000797#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 NULL
799};
800
801static struct attribute_group bridge_group = {
802 .name = SYSFS_BRIDGE_ATTR,
803 .attrs = bridge_attrs,
804};
805
806/*
807 * Export the forwarding information table as a binary file
808 * The records are struct __fdb_entry.
809 *
810 * Returns the number of bytes read.
811 */
Chris Wright2c3c8be2010-05-12 18:28:57 -0700812static ssize_t brforward_read(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +0800813 struct bin_attribute *bin_attr,
814 char *buf, loff_t off, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815{
Geliang Tangaeb7ed12015-12-23 20:42:21 +0800816 struct device *dev = kobj_to_dev(kobj);
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700817 struct net_bridge *br = to_bridge(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 int n;
819
820 /* must read whole records */
821 if (off % sizeof(struct __fdb_entry) != 0)
822 return -EINVAL;
823
YOSHIFUJI Hideaki9d6f2292007-02-09 23:24:35 +0900824 n = br_fdb_fillbuf(br, buf,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825 count / sizeof(struct __fdb_entry),
826 off / sizeof(struct __fdb_entry));
827
828 if (n > 0)
829 n *= sizeof(struct __fdb_entry);
YOSHIFUJI Hideaki9d6f2292007-02-09 23:24:35 +0900830
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831 return n;
832}
833
834static struct bin_attribute bridge_forward = {
835 .attr = { .name = SYSFS_BRIDGE_FDB,
Tejun Heo7b595752007-06-14 03:45:17 +0900836 .mode = S_IRUGO, },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837 .read = brforward_read,
838};
839
840/*
841 * Add entries in sysfs onto the existing network class device
842 * for the bridge.
843 * Adds a attribute group "bridge" containing tuning parameters.
844 * Binary attribute containing the forward table
845 * Sub directory to hold links to interfaces.
846 *
847 * Note: the ifobj exists only to be a subdirectory
848 * to hold links. The ifobj exists in same data structure
849 * as it's parent the bridge so reference counting works.
850 */
851int br_sysfs_addbr(struct net_device *dev)
852{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700853 struct kobject *brobj = &dev->dev.kobj;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854 struct net_bridge *br = netdev_priv(dev);
855 int err;
856
857 err = sysfs_create_group(brobj, &bridge_group);
858 if (err) {
859 pr_info("%s: can't create group %s/%s\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -0800860 __func__, dev->name, bridge_group.name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861 goto out1;
862 }
863
864 err = sysfs_create_bin_file(brobj, &bridge_forward);
865 if (err) {
Randy Dunlap1842c4b2006-10-25 23:07:37 -0700866 pr_info("%s: can't create attribute file %s/%s\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -0800867 __func__, dev->name, bridge_forward.attr.name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868 goto out2;
869 }
870
Greg Kroah-Hartman43b98c42007-12-17 15:54:39 -0400871 br->ifobj = kobject_create_and_add(SYSFS_BRIDGE_PORT_SUBDIR, brobj);
872 if (!br->ifobj) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873 pr_info("%s: can't add kobject (directory) %s/%s\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -0800874 __func__, dev->name, SYSFS_BRIDGE_PORT_SUBDIR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875 goto out3;
876 }
877 return 0;
878 out3:
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700879 sysfs_remove_bin_file(&dev->dev.kobj, &bridge_forward);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880 out2:
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700881 sysfs_remove_group(&dev->dev.kobj, &bridge_group);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882 out1:
883 return err;
884
885}
886
887void br_sysfs_delbr(struct net_device *dev)
888{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700889 struct kobject *kobj = &dev->dev.kobj;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890 struct net_bridge *br = netdev_priv(dev);
891
Greg Kroah-Hartman78a2d902007-12-20 08:13:05 -0800892 kobject_put(br->ifobj);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893 sysfs_remove_bin_file(kobj, &bridge_forward);
894 sysfs_remove_group(kobj, &bridge_group);
895}