blob: 4c97fc50fb704265bd2f51d96527cf3227a65118 [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
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -070025#define to_dev(obj) container_of(obj, struct device, kobj)
Wang Chen524ad0a2008-11-12 23:39:10 -080026#define to_bridge(cd) ((struct net_bridge *)netdev_priv(to_net_dev(cd)))
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
28/*
29 * Common code for storing bridge parameters.
30 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -070031static ssize_t store_bridge_parm(struct device *d,
Linus Torvalds1da177e2005-04-16 15:20:36 -070032 const char *buf, size_t len,
Stephen Hemminger8d4698f72008-09-08 13:44:40 -070033 int (*set)(struct net_bridge *, unsigned long))
Linus Torvalds1da177e2005-04-16 15:20:36 -070034{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -070035 struct net_bridge *br = to_bridge(d);
Linus Torvalds1da177e2005-04-16 15:20:36 -070036 char *endp;
37 unsigned long val;
Stephen Hemminger8d4698f72008-09-08 13:44:40 -070038 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
Eric W. Biedermancb990502012-11-16 03:03:08 +000040 if (!ns_capable(dev_net(br->dev)->user_ns, CAP_NET_ADMIN))
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 return -EPERM;
42
43 val = simple_strtoul(buf, &endp, 0);
44 if (endp == buf)
45 return -EINVAL;
46
Stephen Hemminger8d4698f72008-09-08 13:44:40 -070047 err = (*set)(br, val);
Stephen Hemminger8d4698f72008-09-08 13:44:40 -070048 return err ? err : len;
Linus Torvalds1da177e2005-04-16 15:20:36 -070049}
50
51
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -080052static ssize_t forward_delay_show(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -070053 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -070054{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -070055 struct net_bridge *br = to_bridge(d);
Linus Torvalds1da177e2005-04-16 15:20:36 -070056 return sprintf(buf, "%lu\n", jiffies_to_clock_t(br->forward_delay));
57}
58
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -080059static ssize_t forward_delay_store(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -070060 struct device_attribute *attr,
61 const char *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -070062{
stephen hemminger14f98f22011-04-04 14:03:33 +000063 return store_bridge_parm(d, buf, len, br_set_forward_delay);
Linus Torvalds1da177e2005-04-16 15:20:36 -070064}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -080065static DEVICE_ATTR_RW(forward_delay);
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -080067static ssize_t hello_time_show(struct device *d, struct device_attribute *attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -070068 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -070069{
70 return sprintf(buf, "%lu\n",
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -070071 jiffies_to_clock_t(to_bridge(d)->hello_time));
Linus Torvalds1da177e2005-04-16 15:20:36 -070072}
73
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -080074static ssize_t hello_time_store(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -070075 struct device_attribute *attr, const char *buf,
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 size_t len)
77{
stephen hemminger14f98f22011-04-04 14:03:33 +000078 return store_bridge_parm(d, buf, len, br_set_hello_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -070079}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -080080static DEVICE_ATTR_RW(hello_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -080082static ssize_t max_age_show(struct device *d, struct device_attribute *attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -070083 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -070084{
85 return sprintf(buf, "%lu\n",
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -070086 jiffies_to_clock_t(to_bridge(d)->max_age));
Linus Torvalds1da177e2005-04-16 15:20:36 -070087}
88
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -080089static ssize_t max_age_store(struct device *d, struct device_attribute *attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -070090 const char *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -070091{
stephen hemminger14f98f22011-04-04 14:03:33 +000092 return store_bridge_parm(d, buf, len, br_set_max_age);
Linus Torvalds1da177e2005-04-16 15:20:36 -070093}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -080094static DEVICE_ATTR_RW(max_age);
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -080096static ssize_t ageing_time_show(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -070097 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -070098{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -070099 struct net_bridge *br = to_bridge(d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 return sprintf(buf, "%lu\n", jiffies_to_clock_t(br->ageing_time));
101}
102
Stephen Hemminger8d4698f72008-09-08 13:44:40 -0700103static int set_ageing_time(struct net_bridge *br, unsigned long val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104{
105 br->ageing_time = clock_t_to_jiffies(val);
Stephen Hemminger8d4698f72008-09-08 13:44:40 -0700106 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107}
108
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800109static ssize_t ageing_time_store(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700110 struct device_attribute *attr,
111 const char *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700113 return store_bridge_parm(d, buf, len, set_ageing_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800115static DEVICE_ATTR_RW(ageing_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800117static ssize_t stp_state_show(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700118 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700120 struct net_bridge *br = to_bridge(d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 return sprintf(buf, "%d\n", br->stp_enabled);
122}
123
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800125static ssize_t stp_state_store(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700126 struct device_attribute *attr, const char *buf,
127 size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128{
Stephen Hemminger17120882007-08-14 13:21:34 -0700129 struct net_bridge *br = to_bridge(d);
130 char *endp;
131 unsigned long val;
132
Eric W. Biedermancb990502012-11-16 03:03:08 +0000133 if (!ns_capable(dev_net(br->dev)->user_ns, CAP_NET_ADMIN))
Stephen Hemminger17120882007-08-14 13:21:34 -0700134 return -EPERM;
135
136 val = simple_strtoul(buf, &endp, 0);
137 if (endp == buf)
138 return -EINVAL;
139
Eric W. Biedermanaf38f292009-05-13 17:00:41 +0000140 if (!rtnl_trylock())
141 return restart_syscall();
Stephen Hemminger17120882007-08-14 13:21:34 -0700142 br_stp_set_enabled(br, val);
143 rtnl_unlock();
144
Al Viro35b426c2007-08-19 04:51:26 +0100145 return len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800147static DEVICE_ATTR_RW(stp_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800149static ssize_t group_fwd_mask_show(struct device *d,
150 struct device_attribute *attr,
151 char *buf)
stephen hemminger515853c2011-10-03 18:14:46 +0000152{
153 struct net_bridge *br = to_bridge(d);
154 return sprintf(buf, "%#x\n", br->group_fwd_mask);
155}
156
157
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800158static ssize_t group_fwd_mask_store(struct device *d,
159 struct device_attribute *attr,
160 const char *buf,
161 size_t len)
stephen hemminger515853c2011-10-03 18:14:46 +0000162{
163 struct net_bridge *br = to_bridge(d);
164 char *endp;
165 unsigned long val;
166
Eric W. Biedermancb990502012-11-16 03:03:08 +0000167 if (!ns_capable(dev_net(br->dev)->user_ns, CAP_NET_ADMIN))
stephen hemminger515853c2011-10-03 18:14:46 +0000168 return -EPERM;
169
170 val = simple_strtoul(buf, &endp, 0);
171 if (endp == buf)
172 return -EINVAL;
173
174 if (val & BR_GROUPFWD_RESTRICTED)
175 return -EINVAL;
176
177 br->group_fwd_mask = val;
178
179 return len;
180}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800181static DEVICE_ATTR_RW(group_fwd_mask);
stephen hemminger515853c2011-10-03 18:14:46 +0000182
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800183static ssize_t priority_show(struct device *d, struct device_attribute *attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700184 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700186 struct net_bridge *br = to_bridge(d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 return sprintf(buf, "%d\n",
188 (br->bridge_id.prio[0] << 8) | br->bridge_id.prio[1]);
189}
190
Stephen Hemminger8d4698f72008-09-08 13:44:40 -0700191static int set_priority(struct net_bridge *br, unsigned long val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192{
193 br_stp_set_bridge_priority(br, (u16) val);
Stephen Hemminger8d4698f72008-09-08 13:44:40 -0700194 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195}
196
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800197static ssize_t priority_store(struct device *d, struct device_attribute *attr,
198 const char *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700200 return store_bridge_parm(d, buf, len, set_priority);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800202static DEVICE_ATTR_RW(priority);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800204static ssize_t root_id_show(struct device *d, struct device_attribute *attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700205 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700207 return br_show_bridge_id(buf, &to_bridge(d)->designated_root);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800209static DEVICE_ATTR_RO(root_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800211static ssize_t bridge_id_show(struct device *d, struct device_attribute *attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700212 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700214 return br_show_bridge_id(buf, &to_bridge(d)->bridge_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800216static DEVICE_ATTR_RO(bridge_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800218static ssize_t root_port_show(struct device *d, struct device_attribute *attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700219 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700221 return sprintf(buf, "%d\n", to_bridge(d)->root_port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800223static DEVICE_ATTR_RO(root_port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800225static ssize_t root_path_cost_show(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700226 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700228 return sprintf(buf, "%d\n", to_bridge(d)->root_path_cost);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800230static DEVICE_ATTR_RO(root_path_cost);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800232static ssize_t topology_change_show(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700233 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700235 return sprintf(buf, "%d\n", to_bridge(d)->topology_change);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800237static DEVICE_ATTR_RO(topology_change);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800239static ssize_t topology_change_detected_show(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700240 struct device_attribute *attr,
241 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700243 struct net_bridge *br = to_bridge(d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 return sprintf(buf, "%d\n", br->topology_change_detected);
245}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800246static DEVICE_ATTR_RO(topology_change_detected);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800248static ssize_t hello_timer_show(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700249 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700251 struct net_bridge *br = to_bridge(d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 return sprintf(buf, "%ld\n", br_timer_value(&br->hello_timer));
253}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800254static DEVICE_ATTR_RO(hello_timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800256static ssize_t tcn_timer_show(struct device *d, struct device_attribute *attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700257 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700259 struct net_bridge *br = to_bridge(d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 return sprintf(buf, "%ld\n", br_timer_value(&br->tcn_timer));
261}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800262static DEVICE_ATTR_RO(tcn_timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800264static ssize_t topology_change_timer_show(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700265 struct device_attribute *attr,
266 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->topology_change_timer));
270}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800271static DEVICE_ATTR_RO(topology_change_timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800273static ssize_t gc_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->gc_timer));
278}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800279static DEVICE_ATTR_RO(gc_timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800281static ssize_t group_addr_show(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700282 struct device_attribute *attr, char *buf)
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800283{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700284 struct net_bridge *br = to_bridge(d);
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800285 return sprintf(buf, "%x:%x:%x:%x:%x:%x\n",
286 br->group_addr[0], br->group_addr[1],
287 br->group_addr[2], br->group_addr[3],
288 br->group_addr[4], br->group_addr[5]);
289}
290
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800291static ssize_t group_addr_store(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700292 struct device_attribute *attr,
293 const char *buf, size_t len)
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800294{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700295 struct net_bridge *br = to_bridge(d);
Ben Hutchings4197f242012-11-01 09:10:04 +0000296 u8 new_addr[6];
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800297 int i;
298
Eric W. Biedermancb990502012-11-16 03:03:08 +0000299 if (!ns_capable(dev_net(br->dev)->user_ns, CAP_NET_ADMIN))
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800300 return -EPERM;
301
Ben Hutchings4197f242012-11-01 09:10:04 +0000302 if (sscanf(buf, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx",
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800303 &new_addr[0], &new_addr[1], &new_addr[2],
304 &new_addr[3], &new_addr[4], &new_addr[5]) != 6)
305 return -EINVAL;
306
Ben Hutchings46acc462012-11-01 09:11:11 +0000307 if (!is_link_local_ether_addr(new_addr))
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800308 return -EINVAL;
309
Joe Perchesf64f9e72009-11-29 16:55:45 -0800310 if (new_addr[5] == 1 || /* 802.3x Pause address */
311 new_addr[5] == 2 || /* 802.3ad Slow protocols */
312 new_addr[5] == 3) /* 802.1X PAE address */
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800313 return -EINVAL;
314
Toshiaki Makita204177f2014-06-10 20:59:25 +0900315 if (!rtnl_trylock())
316 return restart_syscall();
317
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800318 spin_lock_bh(&br->lock);
319 for (i = 0; i < 6; i++)
320 br->group_addr[i] = new_addr[i];
321 spin_unlock_bh(&br->lock);
Toshiaki Makita204177f2014-06-10 20:59:25 +0900322
323 br->group_addr_set = true;
324 br_recalculate_fwd_mask(br);
325
326 rtnl_unlock();
327
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800328 return len;
329}
330
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800331static DEVICE_ATTR_RW(group_addr);
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800332
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800333static ssize_t flush_store(struct device *d,
Stephen Hemminger9cf63742007-04-09 12:57:54 -0700334 struct device_attribute *attr,
335 const char *buf, size_t len)
336{
337 struct net_bridge *br = to_bridge(d);
338
Eric W. Biedermancb990502012-11-16 03:03:08 +0000339 if (!ns_capable(dev_net(br->dev)->user_ns, CAP_NET_ADMIN))
Stephen Hemminger9cf63742007-04-09 12:57:54 -0700340 return -EPERM;
341
342 br_fdb_flush(br);
343 return len;
344}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800345static DEVICE_ATTR_WO(flush);
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800346
Herbert Xu0909e112010-02-27 19:41:49 +0000347#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800348static ssize_t multicast_router_show(struct device *d,
Herbert Xu0909e112010-02-27 19:41:49 +0000349 struct device_attribute *attr, char *buf)
350{
351 struct net_bridge *br = to_bridge(d);
352 return sprintf(buf, "%d\n", br->multicast_router);
353}
354
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800355static ssize_t multicast_router_store(struct device *d,
Herbert Xu0909e112010-02-27 19:41:49 +0000356 struct device_attribute *attr,
357 const char *buf, size_t len)
358{
359 return store_bridge_parm(d, buf, len, br_multicast_set_router);
360}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800361static DEVICE_ATTR_RW(multicast_router);
Herbert Xu561f1102010-02-27 19:41:50 +0000362
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800363static ssize_t multicast_snooping_show(struct device *d,
Herbert Xu561f1102010-02-27 19:41:50 +0000364 struct device_attribute *attr,
365 char *buf)
366{
367 struct net_bridge *br = to_bridge(d);
368 return sprintf(buf, "%d\n", !br->multicast_disabled);
369}
370
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800371static ssize_t multicast_snooping_store(struct device *d,
Herbert Xu561f1102010-02-27 19:41:50 +0000372 struct device_attribute *attr,
373 const char *buf, size_t len)
374{
375 return store_bridge_parm(d, buf, len, br_multicast_toggle);
376}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800377static DEVICE_ATTR_RW(multicast_snooping);
Herbert Xub1951672010-02-27 19:41:51 +0000378
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800379static ssize_t multicast_query_use_ifaddr_show(struct device *d,
380 struct device_attribute *attr,
381 char *buf)
Cong Wang1c8ad5b2013-05-21 21:52:54 +0000382{
383 struct net_bridge *br = to_bridge(d);
384 return sprintf(buf, "%d\n", br->multicast_query_use_ifaddr);
385}
386
387static int set_query_use_ifaddr(struct net_bridge *br, unsigned long val)
388{
389 br->multicast_query_use_ifaddr = !!val;
390 return 0;
391}
392
393static ssize_t
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800394multicast_query_use_ifaddr_store(struct device *d,
Cong Wang1c8ad5b2013-05-21 21:52:54 +0000395 struct device_attribute *attr,
396 const char *buf, size_t len)
397{
398 return store_bridge_parm(d, buf, len, set_query_use_ifaddr);
399}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800400static DEVICE_ATTR_RW(multicast_query_use_ifaddr);
Cong Wang1c8ad5b2013-05-21 21:52:54 +0000401
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800402static ssize_t multicast_querier_show(struct device *d,
Herbert Xuc5c23262012-04-13 02:37:42 +0000403 struct device_attribute *attr,
404 char *buf)
405{
406 struct net_bridge *br = to_bridge(d);
407 return sprintf(buf, "%d\n", br->multicast_querier);
408}
409
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800410static ssize_t multicast_querier_store(struct device *d,
Herbert Xuc5c23262012-04-13 02:37:42 +0000411 struct device_attribute *attr,
412 const char *buf, size_t len)
413{
414 return store_bridge_parm(d, buf, len, br_multicast_set_querier);
415}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800416static DEVICE_ATTR_RW(multicast_querier);
Herbert Xuc5c23262012-04-13 02:37:42 +0000417
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800418static ssize_t hash_elasticity_show(struct device *d,
Herbert Xub1951672010-02-27 19:41:51 +0000419 struct device_attribute *attr, char *buf)
420{
421 struct net_bridge *br = to_bridge(d);
422 return sprintf(buf, "%u\n", br->hash_elasticity);
423}
424
425static int set_elasticity(struct net_bridge *br, unsigned long val)
426{
427 br->hash_elasticity = val;
428 return 0;
429}
430
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800431static ssize_t hash_elasticity_store(struct device *d,
Herbert Xub1951672010-02-27 19:41:51 +0000432 struct device_attribute *attr,
433 const char *buf, size_t len)
434{
435 return store_bridge_parm(d, buf, len, set_elasticity);
436}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800437static DEVICE_ATTR_RW(hash_elasticity);
Herbert Xub1951672010-02-27 19:41:51 +0000438
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800439static ssize_t hash_max_show(struct device *d, struct device_attribute *attr,
Herbert Xub1951672010-02-27 19:41:51 +0000440 char *buf)
441{
442 struct net_bridge *br = to_bridge(d);
443 return sprintf(buf, "%u\n", br->hash_max);
444}
445
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800446static ssize_t hash_max_store(struct device *d, struct device_attribute *attr,
Herbert Xub1951672010-02-27 19:41:51 +0000447 const char *buf, size_t len)
448{
449 return store_bridge_parm(d, buf, len, br_multicast_set_hash_max);
450}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800451static DEVICE_ATTR_RW(hash_max);
Herbert Xud902eee2010-02-27 19:41:52 +0000452
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800453static ssize_t multicast_last_member_count_show(struct device *d,
Herbert Xud902eee2010-02-27 19:41:52 +0000454 struct device_attribute *attr,
455 char *buf)
456{
457 struct net_bridge *br = to_bridge(d);
458 return sprintf(buf, "%u\n", br->multicast_last_member_count);
459}
460
461static int set_last_member_count(struct net_bridge *br, unsigned long val)
462{
463 br->multicast_last_member_count = val;
464 return 0;
465}
466
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800467static ssize_t multicast_last_member_count_store(struct device *d,
Herbert Xud902eee2010-02-27 19:41:52 +0000468 struct device_attribute *attr,
469 const char *buf, size_t len)
470{
471 return store_bridge_parm(d, buf, len, set_last_member_count);
472}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800473static DEVICE_ATTR_RW(multicast_last_member_count);
Herbert Xud902eee2010-02-27 19:41:52 +0000474
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800475static ssize_t multicast_startup_query_count_show(
Herbert Xud902eee2010-02-27 19:41:52 +0000476 struct device *d, struct device_attribute *attr, char *buf)
477{
478 struct net_bridge *br = to_bridge(d);
479 return sprintf(buf, "%u\n", br->multicast_startup_query_count);
480}
481
482static int set_startup_query_count(struct net_bridge *br, unsigned long val)
483{
484 br->multicast_startup_query_count = val;
485 return 0;
486}
487
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800488static ssize_t multicast_startup_query_count_store(
Herbert Xud902eee2010-02-27 19:41:52 +0000489 struct device *d, struct device_attribute *attr, const char *buf,
490 size_t len)
491{
492 return store_bridge_parm(d, buf, len, set_startup_query_count);
493}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800494static DEVICE_ATTR_RW(multicast_startup_query_count);
Herbert Xud902eee2010-02-27 19:41:52 +0000495
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800496static ssize_t multicast_last_member_interval_show(
Herbert Xud902eee2010-02-27 19:41:52 +0000497 struct device *d, struct device_attribute *attr, char *buf)
498{
499 struct net_bridge *br = to_bridge(d);
500 return sprintf(buf, "%lu\n",
501 jiffies_to_clock_t(br->multicast_last_member_interval));
502}
503
504static int set_last_member_interval(struct net_bridge *br, unsigned long val)
505{
506 br->multicast_last_member_interval = clock_t_to_jiffies(val);
507 return 0;
508}
509
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800510static ssize_t multicast_last_member_interval_store(
Herbert Xud902eee2010-02-27 19:41:52 +0000511 struct device *d, struct device_attribute *attr, const char *buf,
512 size_t len)
513{
514 return store_bridge_parm(d, buf, len, set_last_member_interval);
515}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800516static DEVICE_ATTR_RW(multicast_last_member_interval);
Herbert Xud902eee2010-02-27 19:41:52 +0000517
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800518static ssize_t multicast_membership_interval_show(
Herbert Xud902eee2010-02-27 19:41:52 +0000519 struct device *d, struct device_attribute *attr, char *buf)
520{
521 struct net_bridge *br = to_bridge(d);
522 return sprintf(buf, "%lu\n",
523 jiffies_to_clock_t(br->multicast_membership_interval));
524}
525
526static int set_membership_interval(struct net_bridge *br, unsigned long val)
527{
528 br->multicast_membership_interval = clock_t_to_jiffies(val);
529 return 0;
530}
531
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800532static ssize_t multicast_membership_interval_store(
Herbert Xud902eee2010-02-27 19:41:52 +0000533 struct device *d, struct device_attribute *attr, const char *buf,
534 size_t len)
535{
536 return store_bridge_parm(d, buf, len, set_membership_interval);
537}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800538static DEVICE_ATTR_RW(multicast_membership_interval);
Herbert Xud902eee2010-02-27 19:41:52 +0000539
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800540static ssize_t multicast_querier_interval_show(struct device *d,
Herbert Xud902eee2010-02-27 19:41:52 +0000541 struct device_attribute *attr,
542 char *buf)
543{
544 struct net_bridge *br = to_bridge(d);
545 return sprintf(buf, "%lu\n",
546 jiffies_to_clock_t(br->multicast_querier_interval));
547}
548
549static int set_querier_interval(struct net_bridge *br, unsigned long val)
550{
551 br->multicast_querier_interval = clock_t_to_jiffies(val);
552 return 0;
553}
554
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800555static ssize_t multicast_querier_interval_store(struct device *d,
Herbert Xud902eee2010-02-27 19:41:52 +0000556 struct device_attribute *attr,
557 const char *buf, size_t len)
558{
559 return store_bridge_parm(d, buf, len, set_querier_interval);
560}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800561static DEVICE_ATTR_RW(multicast_querier_interval);
Herbert Xud902eee2010-02-27 19:41:52 +0000562
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800563static ssize_t multicast_query_interval_show(struct device *d,
Herbert Xud902eee2010-02-27 19:41:52 +0000564 struct device_attribute *attr,
565 char *buf)
566{
567 struct net_bridge *br = to_bridge(d);
568 return sprintf(buf, "%lu\n",
569 jiffies_to_clock_t(br->multicast_query_interval));
570}
571
572static int set_query_interval(struct net_bridge *br, unsigned long val)
573{
574 br->multicast_query_interval = clock_t_to_jiffies(val);
575 return 0;
576}
577
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800578static ssize_t multicast_query_interval_store(struct device *d,
Herbert Xud902eee2010-02-27 19:41:52 +0000579 struct device_attribute *attr,
580 const char *buf, size_t len)
581{
582 return store_bridge_parm(d, buf, len, set_query_interval);
583}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800584static DEVICE_ATTR_RW(multicast_query_interval);
Herbert Xud902eee2010-02-27 19:41:52 +0000585
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800586static ssize_t multicast_query_response_interval_show(
Herbert Xud902eee2010-02-27 19:41:52 +0000587 struct device *d, struct device_attribute *attr, char *buf)
588{
589 struct net_bridge *br = to_bridge(d);
590 return sprintf(
591 buf, "%lu\n",
592 jiffies_to_clock_t(br->multicast_query_response_interval));
593}
594
595static int set_query_response_interval(struct net_bridge *br, unsigned long val)
596{
597 br->multicast_query_response_interval = clock_t_to_jiffies(val);
598 return 0;
599}
600
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800601static ssize_t multicast_query_response_interval_store(
Herbert Xud902eee2010-02-27 19:41:52 +0000602 struct device *d, struct device_attribute *attr, const char *buf,
603 size_t len)
604{
605 return store_bridge_parm(d, buf, len, set_query_response_interval);
606}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800607static DEVICE_ATTR_RW(multicast_query_response_interval);
Herbert Xud902eee2010-02-27 19:41:52 +0000608
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800609static ssize_t multicast_startup_query_interval_show(
Herbert Xud902eee2010-02-27 19:41:52 +0000610 struct device *d, struct device_attribute *attr, char *buf)
611{
612 struct net_bridge *br = to_bridge(d);
613 return sprintf(
614 buf, "%lu\n",
615 jiffies_to_clock_t(br->multicast_startup_query_interval));
616}
617
618static int set_startup_query_interval(struct net_bridge *br, unsigned long val)
619{
620 br->multicast_startup_query_interval = clock_t_to_jiffies(val);
621 return 0;
622}
623
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800624static ssize_t multicast_startup_query_interval_store(
Herbert Xud902eee2010-02-27 19:41:52 +0000625 struct device *d, struct device_attribute *attr, const char *buf,
626 size_t len)
627{
628 return store_bridge_parm(d, buf, len, set_startup_query_interval);
629}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800630static DEVICE_ATTR_RW(multicast_startup_query_interval);
Herbert Xu0909e112010-02-27 19:41:49 +0000631#endif
Pablo Neira Ayuso34666d42014-09-18 11:29:03 +0200632#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800633static ssize_t nf_call_iptables_show(
Patrick McHardy4df53d82010-07-02 09:32:57 +0200634 struct device *d, struct device_attribute *attr, char *buf)
635{
636 struct net_bridge *br = to_bridge(d);
637 return sprintf(buf, "%u\n", br->nf_call_iptables);
638}
639
640static int set_nf_call_iptables(struct net_bridge *br, unsigned long val)
641{
642 br->nf_call_iptables = val ? true : false;
643 return 0;
644}
645
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800646static ssize_t nf_call_iptables_store(
Patrick McHardy4df53d82010-07-02 09:32:57 +0200647 struct device *d, struct device_attribute *attr, const char *buf,
648 size_t len)
649{
650 return store_bridge_parm(d, buf, len, set_nf_call_iptables);
651}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800652static DEVICE_ATTR_RW(nf_call_iptables);
Patrick McHardy4df53d82010-07-02 09:32:57 +0200653
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800654static ssize_t nf_call_ip6tables_show(
Patrick McHardy4df53d82010-07-02 09:32:57 +0200655 struct device *d, struct device_attribute *attr, char *buf)
656{
657 struct net_bridge *br = to_bridge(d);
658 return sprintf(buf, "%u\n", br->nf_call_ip6tables);
659}
660
661static int set_nf_call_ip6tables(struct net_bridge *br, unsigned long val)
662{
663 br->nf_call_ip6tables = val ? true : false;
664 return 0;
665}
666
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800667static ssize_t nf_call_ip6tables_store(
Patrick McHardy4df53d82010-07-02 09:32:57 +0200668 struct device *d, struct device_attribute *attr, const char *buf,
669 size_t len)
670{
671 return store_bridge_parm(d, buf, len, set_nf_call_ip6tables);
672}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800673static DEVICE_ATTR_RW(nf_call_ip6tables);
Patrick McHardy4df53d82010-07-02 09:32:57 +0200674
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800675static ssize_t nf_call_arptables_show(
Patrick McHardy4df53d82010-07-02 09:32:57 +0200676 struct device *d, struct device_attribute *attr, char *buf)
677{
678 struct net_bridge *br = to_bridge(d);
679 return sprintf(buf, "%u\n", br->nf_call_arptables);
680}
681
682static int set_nf_call_arptables(struct net_bridge *br, unsigned long val)
683{
684 br->nf_call_arptables = val ? true : false;
685 return 0;
686}
687
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800688static ssize_t nf_call_arptables_store(
Patrick McHardy4df53d82010-07-02 09:32:57 +0200689 struct device *d, struct device_attribute *attr, const char *buf,
690 size_t len)
691{
692 return store_bridge_parm(d, buf, len, set_nf_call_arptables);
693}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800694static DEVICE_ATTR_RW(nf_call_arptables);
Patrick McHardy4df53d82010-07-02 09:32:57 +0200695#endif
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000696#ifdef CONFIG_BRIDGE_VLAN_FILTERING
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800697static ssize_t vlan_filtering_show(struct device *d,
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000698 struct device_attribute *attr,
699 char *buf)
700{
701 struct net_bridge *br = to_bridge(d);
702 return sprintf(buf, "%d\n", br->vlan_enabled);
703}
704
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800705static ssize_t vlan_filtering_store(struct device *d,
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000706 struct device_attribute *attr,
707 const char *buf, size_t len)
708{
709 return store_bridge_parm(d, buf, len, br_vlan_filter_toggle);
710}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800711static DEVICE_ATTR_RW(vlan_filtering);
Toshiaki Makita204177f2014-06-10 20:59:25 +0900712
713static ssize_t vlan_protocol_show(struct device *d,
714 struct device_attribute *attr,
715 char *buf)
716{
717 struct net_bridge *br = to_bridge(d);
718 return sprintf(buf, "%#06x\n", ntohs(br->vlan_proto));
719}
720
721static ssize_t vlan_protocol_store(struct device *d,
722 struct device_attribute *attr,
723 const char *buf, size_t len)
724{
725 return store_bridge_parm(d, buf, len, br_vlan_set_proto);
726}
727static DEVICE_ATTR_RW(vlan_protocol);
Vlad Yasevich96a20d92014-10-03 11:29:16 -0400728
729static ssize_t default_pvid_show(struct device *d,
730 struct device_attribute *attr,
731 char *buf)
732{
733 struct net_bridge *br = to_bridge(d);
734 return sprintf(buf, "%d\n", br->default_pvid);
735}
736
737static ssize_t default_pvid_store(struct device *d,
738 struct device_attribute *attr,
739 const char *buf, size_t len)
740{
741 return store_bridge_parm(d, buf, len, br_vlan_set_default_pvid);
742}
743static DEVICE_ATTR_RW(default_pvid);
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000744#endif
Herbert Xu0909e112010-02-27 19:41:49 +0000745
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746static struct attribute *bridge_attrs[] = {
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700747 &dev_attr_forward_delay.attr,
748 &dev_attr_hello_time.attr,
749 &dev_attr_max_age.attr,
750 &dev_attr_ageing_time.attr,
751 &dev_attr_stp_state.attr,
stephen hemminger515853c2011-10-03 18:14:46 +0000752 &dev_attr_group_fwd_mask.attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700753 &dev_attr_priority.attr,
754 &dev_attr_bridge_id.attr,
755 &dev_attr_root_id.attr,
756 &dev_attr_root_path_cost.attr,
757 &dev_attr_root_port.attr,
758 &dev_attr_topology_change.attr,
759 &dev_attr_topology_change_detected.attr,
760 &dev_attr_hello_timer.attr,
761 &dev_attr_tcn_timer.attr,
762 &dev_attr_topology_change_timer.attr,
763 &dev_attr_gc_timer.attr,
764 &dev_attr_group_addr.attr,
Stephen Hemminger9cf63742007-04-09 12:57:54 -0700765 &dev_attr_flush.attr,
Herbert Xu0909e112010-02-27 19:41:49 +0000766#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
767 &dev_attr_multicast_router.attr,
Herbert Xu561f1102010-02-27 19:41:50 +0000768 &dev_attr_multicast_snooping.attr,
Herbert Xuc5c23262012-04-13 02:37:42 +0000769 &dev_attr_multicast_querier.attr,
Cong Wang1c8ad5b2013-05-21 21:52:54 +0000770 &dev_attr_multicast_query_use_ifaddr.attr,
Herbert Xub1951672010-02-27 19:41:51 +0000771 &dev_attr_hash_elasticity.attr,
772 &dev_attr_hash_max.attr,
Herbert Xud902eee2010-02-27 19:41:52 +0000773 &dev_attr_multicast_last_member_count.attr,
774 &dev_attr_multicast_startup_query_count.attr,
775 &dev_attr_multicast_last_member_interval.attr,
776 &dev_attr_multicast_membership_interval.attr,
777 &dev_attr_multicast_querier_interval.attr,
778 &dev_attr_multicast_query_interval.attr,
779 &dev_attr_multicast_query_response_interval.attr,
780 &dev_attr_multicast_startup_query_interval.attr,
Herbert Xu0909e112010-02-27 19:41:49 +0000781#endif
Pablo Neira Ayuso34666d42014-09-18 11:29:03 +0200782#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
Patrick McHardy4df53d82010-07-02 09:32:57 +0200783 &dev_attr_nf_call_iptables.attr,
784 &dev_attr_nf_call_ip6tables.attr,
785 &dev_attr_nf_call_arptables.attr,
786#endif
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000787#ifdef CONFIG_BRIDGE_VLAN_FILTERING
788 &dev_attr_vlan_filtering.attr,
Toshiaki Makita204177f2014-06-10 20:59:25 +0900789 &dev_attr_vlan_protocol.attr,
Vlad Yasevich96a20d92014-10-03 11:29:16 -0400790 &dev_attr_default_pvid.attr,
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000791#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 NULL
793};
794
795static struct attribute_group bridge_group = {
796 .name = SYSFS_BRIDGE_ATTR,
797 .attrs = bridge_attrs,
798};
799
800/*
801 * Export the forwarding information table as a binary file
802 * The records are struct __fdb_entry.
803 *
804 * Returns the number of bytes read.
805 */
Chris Wright2c3c8be2010-05-12 18:28:57 -0700806static ssize_t brforward_read(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +0800807 struct bin_attribute *bin_attr,
808 char *buf, loff_t off, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700810 struct device *dev = to_dev(kobj);
811 struct net_bridge *br = to_bridge(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812 int n;
813
814 /* must read whole records */
815 if (off % sizeof(struct __fdb_entry) != 0)
816 return -EINVAL;
817
YOSHIFUJI Hideaki9d6f2292007-02-09 23:24:35 +0900818 n = br_fdb_fillbuf(br, buf,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 count / sizeof(struct __fdb_entry),
820 off / sizeof(struct __fdb_entry));
821
822 if (n > 0)
823 n *= sizeof(struct __fdb_entry);
YOSHIFUJI Hideaki9d6f2292007-02-09 23:24:35 +0900824
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825 return n;
826}
827
828static struct bin_attribute bridge_forward = {
829 .attr = { .name = SYSFS_BRIDGE_FDB,
Tejun Heo7b595752007-06-14 03:45:17 +0900830 .mode = S_IRUGO, },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831 .read = brforward_read,
832};
833
834/*
835 * Add entries in sysfs onto the existing network class device
836 * for the bridge.
837 * Adds a attribute group "bridge" containing tuning parameters.
838 * Binary attribute containing the forward table
839 * Sub directory to hold links to interfaces.
840 *
841 * Note: the ifobj exists only to be a subdirectory
842 * to hold links. The ifobj exists in same data structure
843 * as it's parent the bridge so reference counting works.
844 */
845int br_sysfs_addbr(struct net_device *dev)
846{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700847 struct kobject *brobj = &dev->dev.kobj;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848 struct net_bridge *br = netdev_priv(dev);
849 int err;
850
851 err = sysfs_create_group(brobj, &bridge_group);
852 if (err) {
853 pr_info("%s: can't create group %s/%s\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -0800854 __func__, dev->name, bridge_group.name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855 goto out1;
856 }
857
858 err = sysfs_create_bin_file(brobj, &bridge_forward);
859 if (err) {
Randy Dunlap1842c4b2006-10-25 23:07:37 -0700860 pr_info("%s: can't create attribute file %s/%s\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -0800861 __func__, dev->name, bridge_forward.attr.name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 goto out2;
863 }
864
Greg Kroah-Hartman43b98c42007-12-17 15:54:39 -0400865 br->ifobj = kobject_create_and_add(SYSFS_BRIDGE_PORT_SUBDIR, brobj);
866 if (!br->ifobj) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867 pr_info("%s: can't add kobject (directory) %s/%s\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -0800868 __func__, dev->name, SYSFS_BRIDGE_PORT_SUBDIR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869 goto out3;
870 }
871 return 0;
872 out3:
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700873 sysfs_remove_bin_file(&dev->dev.kobj, &bridge_forward);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874 out2:
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700875 sysfs_remove_group(&dev->dev.kobj, &bridge_group);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876 out1:
877 return err;
878
879}
880
881void br_sysfs_delbr(struct net_device *dev)
882{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700883 struct kobject *kobj = &dev->dev.kobj;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884 struct net_bridge *br = netdev_priv(dev);
885
Greg Kroah-Hartman78a2d902007-12-20 08:13:05 -0800886 kobject_put(br->ifobj);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887 sysfs_remove_bin_file(kobj, &bridge_forward);
888 sysfs_remove_group(kobj, &bridge_group);
889}