blob: 8365bd53c42179dec15314fa99bf2346f729899f [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{
Nikolay Aleksandrovaf379392015-10-12 17:55:55 +0200105 int ret;
106
107 if (!rtnl_trylock())
108 return restart_syscall();
109
110 ret = br_set_ageing_time(br, val);
111 rtnl_unlock();
112
113 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114}
115
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800116static ssize_t ageing_time_store(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700117 struct device_attribute *attr,
118 const char *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700120 return store_bridge_parm(d, buf, len, set_ageing_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800122static DEVICE_ATTR_RW(ageing_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800124static ssize_t stp_state_show(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700125 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700127 struct net_bridge *br = to_bridge(d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 return sprintf(buf, "%d\n", br->stp_enabled);
129}
130
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800132static ssize_t stp_state_store(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700133 struct device_attribute *attr, const char *buf,
134 size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135{
Stephen Hemminger17120882007-08-14 13:21:34 -0700136 struct net_bridge *br = to_bridge(d);
137 char *endp;
138 unsigned long val;
139
Eric W. Biedermancb990502012-11-16 03:03:08 +0000140 if (!ns_capable(dev_net(br->dev)->user_ns, CAP_NET_ADMIN))
Stephen Hemminger17120882007-08-14 13:21:34 -0700141 return -EPERM;
142
143 val = simple_strtoul(buf, &endp, 0);
144 if (endp == buf)
145 return -EINVAL;
146
Eric W. Biedermanaf38f292009-05-13 17:00:41 +0000147 if (!rtnl_trylock())
148 return restart_syscall();
Stephen Hemminger17120882007-08-14 13:21:34 -0700149 br_stp_set_enabled(br, val);
150 rtnl_unlock();
151
Al Viro35b426c2007-08-19 04:51:26 +0100152 return len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800154static DEVICE_ATTR_RW(stp_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800156static ssize_t group_fwd_mask_show(struct device *d,
157 struct device_attribute *attr,
158 char *buf)
stephen hemminger515853c2011-10-03 18:14:46 +0000159{
160 struct net_bridge *br = to_bridge(d);
161 return sprintf(buf, "%#x\n", br->group_fwd_mask);
162}
163
164
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800165static ssize_t group_fwd_mask_store(struct device *d,
166 struct device_attribute *attr,
167 const char *buf,
168 size_t len)
stephen hemminger515853c2011-10-03 18:14:46 +0000169{
170 struct net_bridge *br = to_bridge(d);
171 char *endp;
172 unsigned long val;
173
Eric W. Biedermancb990502012-11-16 03:03:08 +0000174 if (!ns_capable(dev_net(br->dev)->user_ns, CAP_NET_ADMIN))
stephen hemminger515853c2011-10-03 18:14:46 +0000175 return -EPERM;
176
177 val = simple_strtoul(buf, &endp, 0);
178 if (endp == buf)
179 return -EINVAL;
180
181 if (val & BR_GROUPFWD_RESTRICTED)
182 return -EINVAL;
183
184 br->group_fwd_mask = val;
185
186 return len;
187}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800188static DEVICE_ATTR_RW(group_fwd_mask);
stephen hemminger515853c2011-10-03 18:14:46 +0000189
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800190static ssize_t priority_show(struct device *d, struct device_attribute *attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700191 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700193 struct net_bridge *br = to_bridge(d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 return sprintf(buf, "%d\n",
195 (br->bridge_id.prio[0] << 8) | br->bridge_id.prio[1]);
196}
197
Stephen Hemminger8d4698f72008-09-08 13:44:40 -0700198static int set_priority(struct net_bridge *br, unsigned long val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199{
200 br_stp_set_bridge_priority(br, (u16) val);
Stephen Hemminger8d4698f72008-09-08 13:44:40 -0700201 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202}
203
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800204static ssize_t priority_store(struct device *d, struct device_attribute *attr,
205 const char *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700207 return store_bridge_parm(d, buf, len, set_priority);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800209static DEVICE_ATTR_RW(priority);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800211static ssize_t root_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)->designated_root);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800216static DEVICE_ATTR_RO(root_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800218static ssize_t bridge_id_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 br_show_bridge_id(buf, &to_bridge(d)->bridge_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800223static DEVICE_ATTR_RO(bridge_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800225static ssize_t root_port_show(struct device *d, struct device_attribute *attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700226 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_port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800230static DEVICE_ATTR_RO(root_port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800232static ssize_t root_path_cost_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)->root_path_cost);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800237static DEVICE_ATTR_RO(root_path_cost);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800239static ssize_t topology_change_show(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700240 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700242 return sprintf(buf, "%d\n", to_bridge(d)->topology_change);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800244static DEVICE_ATTR_RO(topology_change);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800246static ssize_t topology_change_detected_show(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700247 struct device_attribute *attr,
248 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700250 struct net_bridge *br = to_bridge(d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 return sprintf(buf, "%d\n", br->topology_change_detected);
252}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800253static DEVICE_ATTR_RO(topology_change_detected);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800255static ssize_t hello_timer_show(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700256 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700258 struct net_bridge *br = to_bridge(d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 return sprintf(buf, "%ld\n", br_timer_value(&br->hello_timer));
260}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800261static DEVICE_ATTR_RO(hello_timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800263static ssize_t tcn_timer_show(struct device *d, struct device_attribute *attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700264 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700266 struct net_bridge *br = to_bridge(d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 return sprintf(buf, "%ld\n", br_timer_value(&br->tcn_timer));
268}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800269static DEVICE_ATTR_RO(tcn_timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800271static ssize_t topology_change_timer_show(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700272 struct device_attribute *attr,
273 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700275 struct net_bridge *br = to_bridge(d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 return sprintf(buf, "%ld\n", br_timer_value(&br->topology_change_timer));
277}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800278static DEVICE_ATTR_RO(topology_change_timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800280static ssize_t gc_timer_show(struct device *d, struct device_attribute *attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700281 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700283 struct net_bridge *br = to_bridge(d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 return sprintf(buf, "%ld\n", br_timer_value(&br->gc_timer));
285}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800286static DEVICE_ATTR_RO(gc_timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800288static ssize_t group_addr_show(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700289 struct device_attribute *attr, char *buf)
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800290{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700291 struct net_bridge *br = to_bridge(d);
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800292 return sprintf(buf, "%x:%x:%x:%x:%x:%x\n",
293 br->group_addr[0], br->group_addr[1],
294 br->group_addr[2], br->group_addr[3],
295 br->group_addr[4], br->group_addr[5]);
296}
297
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800298static ssize_t group_addr_store(struct device *d,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700299 struct device_attribute *attr,
300 const char *buf, size_t len)
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800301{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700302 struct net_bridge *br = to_bridge(d);
Ben Hutchings4197f242012-11-01 09:10:04 +0000303 u8 new_addr[6];
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800304 int i;
305
Eric W. Biedermancb990502012-11-16 03:03:08 +0000306 if (!ns_capable(dev_net(br->dev)->user_ns, CAP_NET_ADMIN))
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800307 return -EPERM;
308
Ben Hutchings4197f242012-11-01 09:10:04 +0000309 if (sscanf(buf, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx",
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800310 &new_addr[0], &new_addr[1], &new_addr[2],
311 &new_addr[3], &new_addr[4], &new_addr[5]) != 6)
312 return -EINVAL;
313
Ben Hutchings46acc462012-11-01 09:11:11 +0000314 if (!is_link_local_ether_addr(new_addr))
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800315 return -EINVAL;
316
Joe Perchesf64f9e72009-11-29 16:55:45 -0800317 if (new_addr[5] == 1 || /* 802.3x Pause address */
318 new_addr[5] == 2 || /* 802.3ad Slow protocols */
319 new_addr[5] == 3) /* 802.1X PAE address */
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800320 return -EINVAL;
321
Toshiaki Makita204177f2014-06-10 20:59:25 +0900322 if (!rtnl_trylock())
323 return restart_syscall();
324
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800325 spin_lock_bh(&br->lock);
326 for (i = 0; i < 6; i++)
327 br->group_addr[i] = new_addr[i];
328 spin_unlock_bh(&br->lock);
Toshiaki Makita204177f2014-06-10 20:59:25 +0900329
330 br->group_addr_set = true;
331 br_recalculate_fwd_mask(br);
332
333 rtnl_unlock();
334
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800335 return len;
336}
337
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800338static DEVICE_ATTR_RW(group_addr);
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800339
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800340static ssize_t flush_store(struct device *d,
Stephen Hemminger9cf63742007-04-09 12:57:54 -0700341 struct device_attribute *attr,
342 const char *buf, size_t len)
343{
344 struct net_bridge *br = to_bridge(d);
345
Eric W. Biedermancb990502012-11-16 03:03:08 +0000346 if (!ns_capable(dev_net(br->dev)->user_ns, CAP_NET_ADMIN))
Stephen Hemminger9cf63742007-04-09 12:57:54 -0700347 return -EPERM;
348
349 br_fdb_flush(br);
350 return len;
351}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800352static DEVICE_ATTR_WO(flush);
Stephen Hemmingerfda93d92006-03-20 22:59:21 -0800353
Herbert Xu0909e112010-02-27 19:41:49 +0000354#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800355static ssize_t multicast_router_show(struct device *d,
Herbert Xu0909e112010-02-27 19:41:49 +0000356 struct device_attribute *attr, char *buf)
357{
358 struct net_bridge *br = to_bridge(d);
359 return sprintf(buf, "%d\n", br->multicast_router);
360}
361
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800362static ssize_t multicast_router_store(struct device *d,
Herbert Xu0909e112010-02-27 19:41:49 +0000363 struct device_attribute *attr,
364 const char *buf, size_t len)
365{
366 return store_bridge_parm(d, buf, len, br_multicast_set_router);
367}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800368static DEVICE_ATTR_RW(multicast_router);
Herbert Xu561f1102010-02-27 19:41:50 +0000369
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800370static ssize_t multicast_snooping_show(struct device *d,
Herbert Xu561f1102010-02-27 19:41:50 +0000371 struct device_attribute *attr,
372 char *buf)
373{
374 struct net_bridge *br = to_bridge(d);
375 return sprintf(buf, "%d\n", !br->multicast_disabled);
376}
377
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800378static ssize_t multicast_snooping_store(struct device *d,
Herbert Xu561f1102010-02-27 19:41:50 +0000379 struct device_attribute *attr,
380 const char *buf, size_t len)
381{
382 return store_bridge_parm(d, buf, len, br_multicast_toggle);
383}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800384static DEVICE_ATTR_RW(multicast_snooping);
Herbert Xub1951672010-02-27 19:41:51 +0000385
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800386static ssize_t multicast_query_use_ifaddr_show(struct device *d,
387 struct device_attribute *attr,
388 char *buf)
Cong Wang1c8ad5b2013-05-21 21:52:54 +0000389{
390 struct net_bridge *br = to_bridge(d);
391 return sprintf(buf, "%d\n", br->multicast_query_use_ifaddr);
392}
393
394static int set_query_use_ifaddr(struct net_bridge *br, unsigned long val)
395{
396 br->multicast_query_use_ifaddr = !!val;
397 return 0;
398}
399
400static ssize_t
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800401multicast_query_use_ifaddr_store(struct device *d,
Cong Wang1c8ad5b2013-05-21 21:52:54 +0000402 struct device_attribute *attr,
403 const char *buf, size_t len)
404{
405 return store_bridge_parm(d, buf, len, set_query_use_ifaddr);
406}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800407static DEVICE_ATTR_RW(multicast_query_use_ifaddr);
Cong Wang1c8ad5b2013-05-21 21:52:54 +0000408
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800409static ssize_t multicast_querier_show(struct device *d,
Herbert Xuc5c23262012-04-13 02:37:42 +0000410 struct device_attribute *attr,
411 char *buf)
412{
413 struct net_bridge *br = to_bridge(d);
414 return sprintf(buf, "%d\n", br->multicast_querier);
415}
416
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800417static ssize_t multicast_querier_store(struct device *d,
Herbert Xuc5c23262012-04-13 02:37:42 +0000418 struct device_attribute *attr,
419 const char *buf, size_t len)
420{
421 return store_bridge_parm(d, buf, len, br_multicast_set_querier);
422}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800423static DEVICE_ATTR_RW(multicast_querier);
Herbert Xuc5c23262012-04-13 02:37:42 +0000424
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800425static ssize_t hash_elasticity_show(struct device *d,
Herbert Xub1951672010-02-27 19:41:51 +0000426 struct device_attribute *attr, char *buf)
427{
428 struct net_bridge *br = to_bridge(d);
429 return sprintf(buf, "%u\n", br->hash_elasticity);
430}
431
432static int set_elasticity(struct net_bridge *br, unsigned long val)
433{
434 br->hash_elasticity = val;
435 return 0;
436}
437
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800438static ssize_t hash_elasticity_store(struct device *d,
Herbert Xub1951672010-02-27 19:41:51 +0000439 struct device_attribute *attr,
440 const char *buf, size_t len)
441{
442 return store_bridge_parm(d, buf, len, set_elasticity);
443}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800444static DEVICE_ATTR_RW(hash_elasticity);
Herbert Xub1951672010-02-27 19:41:51 +0000445
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800446static ssize_t hash_max_show(struct device *d, struct device_attribute *attr,
Herbert Xub1951672010-02-27 19:41:51 +0000447 char *buf)
448{
449 struct net_bridge *br = to_bridge(d);
450 return sprintf(buf, "%u\n", br->hash_max);
451}
452
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800453static ssize_t hash_max_store(struct device *d, struct device_attribute *attr,
Herbert Xub1951672010-02-27 19:41:51 +0000454 const char *buf, size_t len)
455{
456 return store_bridge_parm(d, buf, len, br_multicast_set_hash_max);
457}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800458static DEVICE_ATTR_RW(hash_max);
Herbert Xud902eee2010-02-27 19:41:52 +0000459
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800460static ssize_t multicast_last_member_count_show(struct device *d,
Herbert Xud902eee2010-02-27 19:41:52 +0000461 struct device_attribute *attr,
462 char *buf)
463{
464 struct net_bridge *br = to_bridge(d);
465 return sprintf(buf, "%u\n", br->multicast_last_member_count);
466}
467
468static int set_last_member_count(struct net_bridge *br, unsigned long val)
469{
470 br->multicast_last_member_count = val;
471 return 0;
472}
473
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800474static ssize_t multicast_last_member_count_store(struct device *d,
Herbert Xud902eee2010-02-27 19:41:52 +0000475 struct device_attribute *attr,
476 const char *buf, size_t len)
477{
478 return store_bridge_parm(d, buf, len, set_last_member_count);
479}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800480static DEVICE_ATTR_RW(multicast_last_member_count);
Herbert Xud902eee2010-02-27 19:41:52 +0000481
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800482static ssize_t multicast_startup_query_count_show(
Herbert Xud902eee2010-02-27 19:41:52 +0000483 struct device *d, struct device_attribute *attr, char *buf)
484{
485 struct net_bridge *br = to_bridge(d);
486 return sprintf(buf, "%u\n", br->multicast_startup_query_count);
487}
488
489static int set_startup_query_count(struct net_bridge *br, unsigned long val)
490{
491 br->multicast_startup_query_count = val;
492 return 0;
493}
494
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800495static ssize_t multicast_startup_query_count_store(
Herbert Xud902eee2010-02-27 19:41:52 +0000496 struct device *d, struct device_attribute *attr, const char *buf,
497 size_t len)
498{
499 return store_bridge_parm(d, buf, len, set_startup_query_count);
500}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800501static DEVICE_ATTR_RW(multicast_startup_query_count);
Herbert Xud902eee2010-02-27 19:41:52 +0000502
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800503static ssize_t multicast_last_member_interval_show(
Herbert Xud902eee2010-02-27 19:41:52 +0000504 struct device *d, struct device_attribute *attr, char *buf)
505{
506 struct net_bridge *br = to_bridge(d);
507 return sprintf(buf, "%lu\n",
508 jiffies_to_clock_t(br->multicast_last_member_interval));
509}
510
511static int set_last_member_interval(struct net_bridge *br, unsigned long val)
512{
513 br->multicast_last_member_interval = clock_t_to_jiffies(val);
514 return 0;
515}
516
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800517static ssize_t multicast_last_member_interval_store(
Herbert Xud902eee2010-02-27 19:41:52 +0000518 struct device *d, struct device_attribute *attr, const char *buf,
519 size_t len)
520{
521 return store_bridge_parm(d, buf, len, set_last_member_interval);
522}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800523static DEVICE_ATTR_RW(multicast_last_member_interval);
Herbert Xud902eee2010-02-27 19:41:52 +0000524
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800525static ssize_t multicast_membership_interval_show(
Herbert Xud902eee2010-02-27 19:41:52 +0000526 struct device *d, struct device_attribute *attr, char *buf)
527{
528 struct net_bridge *br = to_bridge(d);
529 return sprintf(buf, "%lu\n",
530 jiffies_to_clock_t(br->multicast_membership_interval));
531}
532
533static int set_membership_interval(struct net_bridge *br, unsigned long val)
534{
535 br->multicast_membership_interval = clock_t_to_jiffies(val);
536 return 0;
537}
538
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800539static ssize_t multicast_membership_interval_store(
Herbert Xud902eee2010-02-27 19:41:52 +0000540 struct device *d, struct device_attribute *attr, const char *buf,
541 size_t len)
542{
543 return store_bridge_parm(d, buf, len, set_membership_interval);
544}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800545static DEVICE_ATTR_RW(multicast_membership_interval);
Herbert Xud902eee2010-02-27 19:41:52 +0000546
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800547static ssize_t multicast_querier_interval_show(struct device *d,
Herbert Xud902eee2010-02-27 19:41:52 +0000548 struct device_attribute *attr,
549 char *buf)
550{
551 struct net_bridge *br = to_bridge(d);
552 return sprintf(buf, "%lu\n",
553 jiffies_to_clock_t(br->multicast_querier_interval));
554}
555
556static int set_querier_interval(struct net_bridge *br, unsigned long val)
557{
558 br->multicast_querier_interval = clock_t_to_jiffies(val);
559 return 0;
560}
561
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800562static ssize_t multicast_querier_interval_store(struct device *d,
Herbert Xud902eee2010-02-27 19:41:52 +0000563 struct device_attribute *attr,
564 const char *buf, size_t len)
565{
566 return store_bridge_parm(d, buf, len, set_querier_interval);
567}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800568static DEVICE_ATTR_RW(multicast_querier_interval);
Herbert Xud902eee2010-02-27 19:41:52 +0000569
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800570static ssize_t multicast_query_interval_show(struct device *d,
Herbert Xud902eee2010-02-27 19:41:52 +0000571 struct device_attribute *attr,
572 char *buf)
573{
574 struct net_bridge *br = to_bridge(d);
575 return sprintf(buf, "%lu\n",
576 jiffies_to_clock_t(br->multicast_query_interval));
577}
578
579static int set_query_interval(struct net_bridge *br, unsigned long val)
580{
581 br->multicast_query_interval = clock_t_to_jiffies(val);
582 return 0;
583}
584
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800585static ssize_t multicast_query_interval_store(struct device *d,
Herbert Xud902eee2010-02-27 19:41:52 +0000586 struct device_attribute *attr,
587 const char *buf, size_t len)
588{
589 return store_bridge_parm(d, buf, len, set_query_interval);
590}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800591static DEVICE_ATTR_RW(multicast_query_interval);
Herbert Xud902eee2010-02-27 19:41:52 +0000592
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800593static ssize_t multicast_query_response_interval_show(
Herbert Xud902eee2010-02-27 19:41:52 +0000594 struct device *d, struct device_attribute *attr, char *buf)
595{
596 struct net_bridge *br = to_bridge(d);
597 return sprintf(
598 buf, "%lu\n",
599 jiffies_to_clock_t(br->multicast_query_response_interval));
600}
601
602static int set_query_response_interval(struct net_bridge *br, unsigned long val)
603{
604 br->multicast_query_response_interval = clock_t_to_jiffies(val);
605 return 0;
606}
607
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800608static ssize_t multicast_query_response_interval_store(
Herbert Xud902eee2010-02-27 19:41:52 +0000609 struct device *d, struct device_attribute *attr, const char *buf,
610 size_t len)
611{
612 return store_bridge_parm(d, buf, len, set_query_response_interval);
613}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800614static DEVICE_ATTR_RW(multicast_query_response_interval);
Herbert Xud902eee2010-02-27 19:41:52 +0000615
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800616static ssize_t multicast_startup_query_interval_show(
Herbert Xud902eee2010-02-27 19:41:52 +0000617 struct device *d, struct device_attribute *attr, char *buf)
618{
619 struct net_bridge *br = to_bridge(d);
620 return sprintf(
621 buf, "%lu\n",
622 jiffies_to_clock_t(br->multicast_startup_query_interval));
623}
624
625static int set_startup_query_interval(struct net_bridge *br, unsigned long val)
626{
627 br->multicast_startup_query_interval = clock_t_to_jiffies(val);
628 return 0;
629}
630
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800631static ssize_t multicast_startup_query_interval_store(
Herbert Xud902eee2010-02-27 19:41:52 +0000632 struct device *d, struct device_attribute *attr, const char *buf,
633 size_t len)
634{
635 return store_bridge_parm(d, buf, len, set_startup_query_interval);
636}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800637static DEVICE_ATTR_RW(multicast_startup_query_interval);
Herbert Xu0909e112010-02-27 19:41:49 +0000638#endif
Pablo Neira Ayuso34666d42014-09-18 11:29:03 +0200639#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800640static ssize_t nf_call_iptables_show(
Patrick McHardy4df53d82010-07-02 09:32:57 +0200641 struct device *d, struct device_attribute *attr, char *buf)
642{
643 struct net_bridge *br = to_bridge(d);
644 return sprintf(buf, "%u\n", br->nf_call_iptables);
645}
646
647static int set_nf_call_iptables(struct net_bridge *br, unsigned long val)
648{
649 br->nf_call_iptables = val ? true : false;
650 return 0;
651}
652
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800653static ssize_t nf_call_iptables_store(
Patrick McHardy4df53d82010-07-02 09:32:57 +0200654 struct device *d, struct device_attribute *attr, const char *buf,
655 size_t len)
656{
657 return store_bridge_parm(d, buf, len, set_nf_call_iptables);
658}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800659static DEVICE_ATTR_RW(nf_call_iptables);
Patrick McHardy4df53d82010-07-02 09:32:57 +0200660
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800661static ssize_t nf_call_ip6tables_show(
Patrick McHardy4df53d82010-07-02 09:32:57 +0200662 struct device *d, struct device_attribute *attr, char *buf)
663{
664 struct net_bridge *br = to_bridge(d);
665 return sprintf(buf, "%u\n", br->nf_call_ip6tables);
666}
667
668static int set_nf_call_ip6tables(struct net_bridge *br, unsigned long val)
669{
670 br->nf_call_ip6tables = val ? true : false;
671 return 0;
672}
673
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800674static ssize_t nf_call_ip6tables_store(
Patrick McHardy4df53d82010-07-02 09:32:57 +0200675 struct device *d, struct device_attribute *attr, const char *buf,
676 size_t len)
677{
678 return store_bridge_parm(d, buf, len, set_nf_call_ip6tables);
679}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800680static DEVICE_ATTR_RW(nf_call_ip6tables);
Patrick McHardy4df53d82010-07-02 09:32:57 +0200681
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800682static ssize_t nf_call_arptables_show(
Patrick McHardy4df53d82010-07-02 09:32:57 +0200683 struct device *d, struct device_attribute *attr, char *buf)
684{
685 struct net_bridge *br = to_bridge(d);
686 return sprintf(buf, "%u\n", br->nf_call_arptables);
687}
688
689static int set_nf_call_arptables(struct net_bridge *br, unsigned long val)
690{
691 br->nf_call_arptables = val ? true : false;
692 return 0;
693}
694
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800695static ssize_t nf_call_arptables_store(
Patrick McHardy4df53d82010-07-02 09:32:57 +0200696 struct device *d, struct device_attribute *attr, const char *buf,
697 size_t len)
698{
699 return store_bridge_parm(d, buf, len, set_nf_call_arptables);
700}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800701static DEVICE_ATTR_RW(nf_call_arptables);
Patrick McHardy4df53d82010-07-02 09:32:57 +0200702#endif
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000703#ifdef CONFIG_BRIDGE_VLAN_FILTERING
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800704static ssize_t vlan_filtering_show(struct device *d,
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000705 struct device_attribute *attr,
706 char *buf)
707{
708 struct net_bridge *br = to_bridge(d);
709 return sprintf(buf, "%d\n", br->vlan_enabled);
710}
711
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800712static ssize_t vlan_filtering_store(struct device *d,
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000713 struct device_attribute *attr,
714 const char *buf, size_t len)
715{
716 return store_bridge_parm(d, buf, len, br_vlan_filter_toggle);
717}
sfeldma@cumulusnetworks.comfbf26712014-01-06 11:00:44 -0800718static DEVICE_ATTR_RW(vlan_filtering);
Toshiaki Makita204177f2014-06-10 20:59:25 +0900719
720static ssize_t vlan_protocol_show(struct device *d,
721 struct device_attribute *attr,
722 char *buf)
723{
724 struct net_bridge *br = to_bridge(d);
725 return sprintf(buf, "%#06x\n", ntohs(br->vlan_proto));
726}
727
728static ssize_t vlan_protocol_store(struct device *d,
729 struct device_attribute *attr,
730 const char *buf, size_t len)
731{
732 return store_bridge_parm(d, buf, len, br_vlan_set_proto);
733}
734static DEVICE_ATTR_RW(vlan_protocol);
Vlad Yasevich96a20d92014-10-03 11:29:16 -0400735
736static ssize_t default_pvid_show(struct device *d,
737 struct device_attribute *attr,
738 char *buf)
739{
740 struct net_bridge *br = to_bridge(d);
741 return sprintf(buf, "%d\n", br->default_pvid);
742}
743
744static ssize_t default_pvid_store(struct device *d,
745 struct device_attribute *attr,
746 const char *buf, size_t len)
747{
748 return store_bridge_parm(d, buf, len, br_vlan_set_default_pvid);
749}
750static DEVICE_ATTR_RW(default_pvid);
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000751#endif
Herbert Xu0909e112010-02-27 19:41:49 +0000752
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753static struct attribute *bridge_attrs[] = {
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700754 &dev_attr_forward_delay.attr,
755 &dev_attr_hello_time.attr,
756 &dev_attr_max_age.attr,
757 &dev_attr_ageing_time.attr,
758 &dev_attr_stp_state.attr,
stephen hemminger515853c2011-10-03 18:14:46 +0000759 &dev_attr_group_fwd_mask.attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700760 &dev_attr_priority.attr,
761 &dev_attr_bridge_id.attr,
762 &dev_attr_root_id.attr,
763 &dev_attr_root_path_cost.attr,
764 &dev_attr_root_port.attr,
765 &dev_attr_topology_change.attr,
766 &dev_attr_topology_change_detected.attr,
767 &dev_attr_hello_timer.attr,
768 &dev_attr_tcn_timer.attr,
769 &dev_attr_topology_change_timer.attr,
770 &dev_attr_gc_timer.attr,
771 &dev_attr_group_addr.attr,
Stephen Hemminger9cf63742007-04-09 12:57:54 -0700772 &dev_attr_flush.attr,
Herbert Xu0909e112010-02-27 19:41:49 +0000773#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
774 &dev_attr_multicast_router.attr,
Herbert Xu561f1102010-02-27 19:41:50 +0000775 &dev_attr_multicast_snooping.attr,
Herbert Xuc5c23262012-04-13 02:37:42 +0000776 &dev_attr_multicast_querier.attr,
Cong Wang1c8ad5b2013-05-21 21:52:54 +0000777 &dev_attr_multicast_query_use_ifaddr.attr,
Herbert Xub1951672010-02-27 19:41:51 +0000778 &dev_attr_hash_elasticity.attr,
779 &dev_attr_hash_max.attr,
Herbert Xud902eee2010-02-27 19:41:52 +0000780 &dev_attr_multicast_last_member_count.attr,
781 &dev_attr_multicast_startup_query_count.attr,
782 &dev_attr_multicast_last_member_interval.attr,
783 &dev_attr_multicast_membership_interval.attr,
784 &dev_attr_multicast_querier_interval.attr,
785 &dev_attr_multicast_query_interval.attr,
786 &dev_attr_multicast_query_response_interval.attr,
787 &dev_attr_multicast_startup_query_interval.attr,
Herbert Xu0909e112010-02-27 19:41:49 +0000788#endif
Pablo Neira Ayuso34666d42014-09-18 11:29:03 +0200789#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
Patrick McHardy4df53d82010-07-02 09:32:57 +0200790 &dev_attr_nf_call_iptables.attr,
791 &dev_attr_nf_call_ip6tables.attr,
792 &dev_attr_nf_call_arptables.attr,
793#endif
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000794#ifdef CONFIG_BRIDGE_VLAN_FILTERING
795 &dev_attr_vlan_filtering.attr,
Toshiaki Makita204177f2014-06-10 20:59:25 +0900796 &dev_attr_vlan_protocol.attr,
Vlad Yasevich96a20d92014-10-03 11:29:16 -0400797 &dev_attr_default_pvid.attr,
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000798#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 NULL
800};
801
802static struct attribute_group bridge_group = {
803 .name = SYSFS_BRIDGE_ATTR,
804 .attrs = bridge_attrs,
805};
806
807/*
808 * Export the forwarding information table as a binary file
809 * The records are struct __fdb_entry.
810 *
811 * Returns the number of bytes read.
812 */
Chris Wright2c3c8be2010-05-12 18:28:57 -0700813static ssize_t brforward_read(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +0800814 struct bin_attribute *bin_attr,
815 char *buf, loff_t off, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700817 struct device *dev = to_dev(kobj);
818 struct net_bridge *br = to_bridge(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 int n;
820
821 /* must read whole records */
822 if (off % sizeof(struct __fdb_entry) != 0)
823 return -EINVAL;
824
YOSHIFUJI Hideaki9d6f2292007-02-09 23:24:35 +0900825 n = br_fdb_fillbuf(br, buf,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826 count / sizeof(struct __fdb_entry),
827 off / sizeof(struct __fdb_entry));
828
829 if (n > 0)
830 n *= sizeof(struct __fdb_entry);
YOSHIFUJI Hideaki9d6f2292007-02-09 23:24:35 +0900831
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 return n;
833}
834
835static struct bin_attribute bridge_forward = {
836 .attr = { .name = SYSFS_BRIDGE_FDB,
Tejun Heo7b595752007-06-14 03:45:17 +0900837 .mode = S_IRUGO, },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 .read = brforward_read,
839};
840
841/*
842 * Add entries in sysfs onto the existing network class device
843 * for the bridge.
844 * Adds a attribute group "bridge" containing tuning parameters.
845 * Binary attribute containing the forward table
846 * Sub directory to hold links to interfaces.
847 *
848 * Note: the ifobj exists only to be a subdirectory
849 * to hold links. The ifobj exists in same data structure
850 * as it's parent the bridge so reference counting works.
851 */
852int br_sysfs_addbr(struct net_device *dev)
853{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700854 struct kobject *brobj = &dev->dev.kobj;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855 struct net_bridge *br = netdev_priv(dev);
856 int err;
857
858 err = sysfs_create_group(brobj, &bridge_group);
859 if (err) {
860 pr_info("%s: can't create group %s/%s\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -0800861 __func__, dev->name, bridge_group.name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 goto out1;
863 }
864
865 err = sysfs_create_bin_file(brobj, &bridge_forward);
866 if (err) {
Randy Dunlap1842c4b2006-10-25 23:07:37 -0700867 pr_info("%s: can't create attribute file %s/%s\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -0800868 __func__, dev->name, bridge_forward.attr.name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869 goto out2;
870 }
871
Greg Kroah-Hartman43b98c42007-12-17 15:54:39 -0400872 br->ifobj = kobject_create_and_add(SYSFS_BRIDGE_PORT_SUBDIR, brobj);
873 if (!br->ifobj) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874 pr_info("%s: can't add kobject (directory) %s/%s\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -0800875 __func__, dev->name, SYSFS_BRIDGE_PORT_SUBDIR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876 goto out3;
877 }
878 return 0;
879 out3:
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700880 sysfs_remove_bin_file(&dev->dev.kobj, &bridge_forward);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881 out2:
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700882 sysfs_remove_group(&dev->dev.kobj, &bridge_group);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883 out1:
884 return err;
885
886}
887
888void br_sysfs_delbr(struct net_device *dev)
889{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700890 struct kobject *kobj = &dev->dev.kobj;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891 struct net_bridge *br = netdev_priv(dev);
892
Greg Kroah-Hartman78a2d902007-12-20 08:13:05 -0800893 kobject_put(br->ifobj);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894 sysfs_remove_bin_file(kobj, &bridge_forward);
895 sysfs_remove_group(kobj, &bridge_group);
896}