Commit | Line | Data |
---|---|---|
2874c5fd | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
1da177e4 | 2 | /* |
15401946 | 3 | * Sysfs attributes of bridge |
1da177e4 LT |
4 | * Linux ethernet bridge |
5 | * | |
6 | * Authors: | |
7 | * Stephen Hemminger <shemminger@osdl.org> | |
1da177e4 LT |
8 | */ |
9 | ||
4fc268d2 | 10 | #include <linux/capability.h> |
1da177e4 LT |
11 | #include <linux/kernel.h> |
12 | #include <linux/netdevice.h> | |
b3343a2a | 13 | #include <linux/etherdevice.h> |
1da177e4 LT |
14 | #include <linux/if_bridge.h> |
15 | #include <linux/rtnetlink.h> | |
16 | #include <linux/spinlock.h> | |
17 | #include <linux/times.h> | |
174cd4b1 | 18 | #include <linux/sched/signal.h> |
1da177e4 LT |
19 | |
20 | #include "br_private.h" | |
21 | ||
1e16f382 NA |
22 | /* IMPORTANT: new bridge options must be added with netlink support only |
23 | * please do not add new sysfs entries | |
24 | */ | |
25 | ||
524ad0a7 | 26 | #define to_bridge(cd) ((struct net_bridge *)netdev_priv(to_net_dev(cd))) |
1da177e4 LT |
27 | |
28 | /* | |
29 | * Common code for storing bridge parameters. | |
30 | */ | |
43cb76d9 | 31 | static ssize_t store_bridge_parm(struct device *d, |
1da177e4 | 32 | const char *buf, size_t len, |
9e781401 VO |
33 | int (*set)(struct net_bridge *br, unsigned long val, |
34 | struct netlink_ext_ack *extack)) | |
1da177e4 | 35 | { |
43cb76d9 | 36 | struct net_bridge *br = to_bridge(d); |
9e781401 | 37 | struct netlink_ext_ack extack = {0}; |
1da177e4 | 38 | unsigned long val; |
8d4698f7 | 39 | int err; |
1da177e4 | 40 | |
cb990503 | 41 | if (!ns_capable(dev_net(br->dev)->user_ns, CAP_NET_ADMIN)) |
1da177e4 LT |
42 | return -EPERM; |
43 | ||
520fbdf7 BZ |
44 | err = kstrtoul(buf, 10, &val); |
45 | if (err != 0) | |
46 | return err; | |
1da177e4 | 47 | |
047831a9 XL |
48 | if (!rtnl_trylock()) |
49 | return restart_syscall(); | |
50 | ||
9e781401 | 51 | err = (*set)(br, val, &extack); |
047831a9 XL |
52 | if (!err) |
53 | netdev_state_change(br->dev); | |
9e781401 VO |
54 | if (extack._msg) { |
55 | if (err) | |
56 | br_err(br, "%s\n", extack._msg); | |
57 | else | |
58 | br_warn(br, "%s\n", extack._msg); | |
59 | } | |
047831a9 XL |
60 | rtnl_unlock(); |
61 | ||
8d4698f7 | 62 | return err ? err : len; |
1da177e4 LT |
63 | } |
64 | ||
65 | ||
fbf2671b | 66 | static ssize_t forward_delay_show(struct device *d, |
43cb76d9 | 67 | struct device_attribute *attr, char *buf) |
1da177e4 | 68 | { |
43cb76d9 | 69 | struct net_bridge *br = to_bridge(d); |
1da177e4 LT |
70 | return sprintf(buf, "%lu\n", jiffies_to_clock_t(br->forward_delay)); |
71 | } | |
72 | ||
9e781401 VO |
73 | static int set_forward_delay(struct net_bridge *br, unsigned long val, |
74 | struct netlink_ext_ack *extack) | |
75 | { | |
76 | return br_set_forward_delay(br, val); | |
77 | } | |
78 | ||
fbf2671b | 79 | static ssize_t forward_delay_store(struct device *d, |
43cb76d9 GKH |
80 | struct device_attribute *attr, |
81 | const char *buf, size_t len) | |
1da177e4 | 82 | { |
9e781401 | 83 | return store_bridge_parm(d, buf, len, set_forward_delay); |
1da177e4 | 84 | } |
fbf2671b | 85 | static DEVICE_ATTR_RW(forward_delay); |
1da177e4 | 86 | |
fbf2671b | 87 | static ssize_t hello_time_show(struct device *d, struct device_attribute *attr, |
43cb76d9 | 88 | char *buf) |
1da177e4 LT |
89 | { |
90 | return sprintf(buf, "%lu\n", | |
43cb76d9 | 91 | jiffies_to_clock_t(to_bridge(d)->hello_time)); |
1da177e4 LT |
92 | } |
93 | ||
9e781401 VO |
94 | static int set_hello_time(struct net_bridge *br, unsigned long val, |
95 | struct netlink_ext_ack *extack) | |
96 | { | |
97 | return br_set_hello_time(br, val); | |
98 | } | |
99 | ||
fbf2671b | 100 | static ssize_t hello_time_store(struct device *d, |
43cb76d9 | 101 | struct device_attribute *attr, const char *buf, |
1da177e4 LT |
102 | size_t len) |
103 | { | |
9e781401 | 104 | return store_bridge_parm(d, buf, len, set_hello_time); |
1da177e4 | 105 | } |
fbf2671b | 106 | static DEVICE_ATTR_RW(hello_time); |
1da177e4 | 107 | |
fbf2671b | 108 | static ssize_t max_age_show(struct device *d, struct device_attribute *attr, |
43cb76d9 | 109 | char *buf) |
1da177e4 LT |
110 | { |
111 | return sprintf(buf, "%lu\n", | |
43cb76d9 | 112 | jiffies_to_clock_t(to_bridge(d)->max_age)); |
1da177e4 LT |
113 | } |
114 | ||
9e781401 VO |
115 | static int set_max_age(struct net_bridge *br, unsigned long val, |
116 | struct netlink_ext_ack *extack) | |
117 | { | |
118 | return br_set_max_age(br, val); | |
119 | } | |
120 | ||
fbf2671b | 121 | static ssize_t max_age_store(struct device *d, struct device_attribute *attr, |
43cb76d9 | 122 | const char *buf, size_t len) |
1da177e4 | 123 | { |
9e781401 | 124 | return store_bridge_parm(d, buf, len, set_max_age); |
1da177e4 | 125 | } |
fbf2671b | 126 | static DEVICE_ATTR_RW(max_age); |
1da177e4 | 127 | |
fbf2671b | 128 | static ssize_t ageing_time_show(struct device *d, |
43cb76d9 | 129 | struct device_attribute *attr, char *buf) |
1da177e4 | 130 | { |
43cb76d9 | 131 | struct net_bridge *br = to_bridge(d); |
1da177e4 LT |
132 | return sprintf(buf, "%lu\n", jiffies_to_clock_t(br->ageing_time)); |
133 | } | |
134 | ||
9e781401 VO |
135 | static int set_ageing_time(struct net_bridge *br, unsigned long val, |
136 | struct netlink_ext_ack *extack) | |
1da177e4 | 137 | { |
047831a9 | 138 | return br_set_ageing_time(br, val); |
1da177e4 LT |
139 | } |
140 | ||
fbf2671b | 141 | static ssize_t ageing_time_store(struct device *d, |
43cb76d9 GKH |
142 | struct device_attribute *attr, |
143 | const char *buf, size_t len) | |
1da177e4 | 144 | { |
43cb76d9 | 145 | return store_bridge_parm(d, buf, len, set_ageing_time); |
1da177e4 | 146 | } |
fbf2671b | 147 | static DEVICE_ATTR_RW(ageing_time); |
1da177e4 | 148 | |
fbf2671b | 149 | static ssize_t stp_state_show(struct device *d, |
43cb76d9 | 150 | struct device_attribute *attr, char *buf) |
1da177e4 | 151 | { |
43cb76d9 | 152 | struct net_bridge *br = to_bridge(d); |
1da177e4 LT |
153 | return sprintf(buf, "%d\n", br->stp_enabled); |
154 | } | |
155 | ||
1da177e4 | 156 | |
9e781401 VO |
157 | static int set_stp_state(struct net_bridge *br, unsigned long val, |
158 | struct netlink_ext_ack *extack) | |
1da177e4 | 159 | { |
9e781401 | 160 | return br_stp_set_enabled(br, val, extack); |
4436156b XL |
161 | } |
162 | ||
163 | static ssize_t stp_state_store(struct device *d, | |
164 | struct device_attribute *attr, const char *buf, | |
165 | size_t len) | |
166 | { | |
167 | return store_bridge_parm(d, buf, len, set_stp_state); | |
1da177e4 | 168 | } |
fbf2671b | 169 | static DEVICE_ATTR_RW(stp_state); |
1da177e4 | 170 | |
fbf2671b | 171 | static ssize_t group_fwd_mask_show(struct device *d, |
172 | struct device_attribute *attr, | |
173 | char *buf) | |
515853cc | 174 | { |
175 | struct net_bridge *br = to_bridge(d); | |
176 | return sprintf(buf, "%#x\n", br->group_fwd_mask); | |
177 | } | |
178 | ||
9e781401 VO |
179 | static int set_group_fwd_mask(struct net_bridge *br, unsigned long val, |
180 | struct netlink_ext_ack *extack) | |
515853cc | 181 | { |
515853cc | 182 | if (val & BR_GROUPFWD_RESTRICTED) |
183 | return -EINVAL; | |
184 | ||
185 | br->group_fwd_mask = val; | |
186 | ||
347db6b4 XL |
187 | return 0; |
188 | } | |
189 | ||
190 | static ssize_t group_fwd_mask_store(struct device *d, | |
191 | struct device_attribute *attr, | |
192 | const char *buf, | |
193 | size_t len) | |
194 | { | |
195 | return store_bridge_parm(d, buf, len, set_group_fwd_mask); | |
515853cc | 196 | } |
fbf2671b | 197 | static DEVICE_ATTR_RW(group_fwd_mask); |
515853cc | 198 | |
fbf2671b | 199 | static ssize_t priority_show(struct device *d, struct device_attribute *attr, |
43cb76d9 | 200 | char *buf) |
1da177e4 | 201 | { |
43cb76d9 | 202 | struct net_bridge *br = to_bridge(d); |
1da177e4 LT |
203 | return sprintf(buf, "%d\n", |
204 | (br->bridge_id.prio[0] << 8) | br->bridge_id.prio[1]); | |
205 | } | |
206 | ||
9e781401 VO |
207 | static int set_priority(struct net_bridge *br, unsigned long val, |
208 | struct netlink_ext_ack *extack) | |
1da177e4 LT |
209 | { |
210 | br_stp_set_bridge_priority(br, (u16) val); | |
8d4698f7 | 211 | return 0; |
1da177e4 LT |
212 | } |
213 | ||
fbf2671b | 214 | static ssize_t priority_store(struct device *d, struct device_attribute *attr, |
215 | const char *buf, size_t len) | |
1da177e4 | 216 | { |
43cb76d9 | 217 | return store_bridge_parm(d, buf, len, set_priority); |
1da177e4 | 218 | } |
fbf2671b | 219 | static DEVICE_ATTR_RW(priority); |
1da177e4 | 220 | |
fbf2671b | 221 | static ssize_t root_id_show(struct device *d, struct device_attribute *attr, |
43cb76d9 | 222 | char *buf) |
1da177e4 | 223 | { |
43cb76d9 | 224 | return br_show_bridge_id(buf, &to_bridge(d)->designated_root); |
1da177e4 | 225 | } |
fbf2671b | 226 | static DEVICE_ATTR_RO(root_id); |
1da177e4 | 227 | |
fbf2671b | 228 | static ssize_t bridge_id_show(struct device *d, struct device_attribute *attr, |
43cb76d9 | 229 | char *buf) |
1da177e4 | 230 | { |
43cb76d9 | 231 | return br_show_bridge_id(buf, &to_bridge(d)->bridge_id); |
1da177e4 | 232 | } |
fbf2671b | 233 | static DEVICE_ATTR_RO(bridge_id); |
1da177e4 | 234 | |
fbf2671b | 235 | static ssize_t root_port_show(struct device *d, struct device_attribute *attr, |
43cb76d9 | 236 | char *buf) |
1da177e4 | 237 | { |
43cb76d9 | 238 | return sprintf(buf, "%d\n", to_bridge(d)->root_port); |
1da177e4 | 239 | } |
fbf2671b | 240 | static DEVICE_ATTR_RO(root_port); |
1da177e4 | 241 | |
fbf2671b | 242 | static ssize_t root_path_cost_show(struct device *d, |
43cb76d9 | 243 | struct device_attribute *attr, char *buf) |
1da177e4 | 244 | { |
43cb76d9 | 245 | return sprintf(buf, "%d\n", to_bridge(d)->root_path_cost); |
1da177e4 | 246 | } |
fbf2671b | 247 | static DEVICE_ATTR_RO(root_path_cost); |
1da177e4 | 248 | |
fbf2671b | 249 | static ssize_t topology_change_show(struct device *d, |
43cb76d9 | 250 | struct device_attribute *attr, char *buf) |
1da177e4 | 251 | { |
43cb76d9 | 252 | return sprintf(buf, "%d\n", to_bridge(d)->topology_change); |
1da177e4 | 253 | } |
fbf2671b | 254 | static DEVICE_ATTR_RO(topology_change); |
1da177e4 | 255 | |
fbf2671b | 256 | static ssize_t topology_change_detected_show(struct device *d, |
43cb76d9 GKH |
257 | struct device_attribute *attr, |
258 | char *buf) | |
1da177e4 | 259 | { |
43cb76d9 | 260 | struct net_bridge *br = to_bridge(d); |
1da177e4 LT |
261 | return sprintf(buf, "%d\n", br->topology_change_detected); |
262 | } | |
fbf2671b | 263 | static DEVICE_ATTR_RO(topology_change_detected); |
1da177e4 | 264 | |
fbf2671b | 265 | static ssize_t hello_timer_show(struct device *d, |
43cb76d9 | 266 | struct device_attribute *attr, char *buf) |
1da177e4 | 267 | { |
43cb76d9 | 268 | struct net_bridge *br = to_bridge(d); |
1da177e4 LT |
269 | return sprintf(buf, "%ld\n", br_timer_value(&br->hello_timer)); |
270 | } | |
fbf2671b | 271 | static DEVICE_ATTR_RO(hello_timer); |
1da177e4 | 272 | |
fbf2671b | 273 | static ssize_t tcn_timer_show(struct device *d, struct device_attribute *attr, |
43cb76d9 | 274 | char *buf) |
1da177e4 | 275 | { |
43cb76d9 | 276 | struct net_bridge *br = to_bridge(d); |
1da177e4 LT |
277 | return sprintf(buf, "%ld\n", br_timer_value(&br->tcn_timer)); |
278 | } | |
fbf2671b | 279 | static DEVICE_ATTR_RO(tcn_timer); |
1da177e4 | 280 | |
fbf2671b | 281 | static ssize_t topology_change_timer_show(struct device *d, |
43cb76d9 GKH |
282 | struct device_attribute *attr, |
283 | char *buf) | |
1da177e4 | 284 | { |
43cb76d9 | 285 | struct net_bridge *br = to_bridge(d); |
1da177e4 LT |
286 | return sprintf(buf, "%ld\n", br_timer_value(&br->topology_change_timer)); |
287 | } | |
fbf2671b | 288 | static DEVICE_ATTR_RO(topology_change_timer); |
1da177e4 | 289 | |
fbf2671b | 290 | static ssize_t gc_timer_show(struct device *d, struct device_attribute *attr, |
43cb76d9 | 291 | char *buf) |
1da177e4 | 292 | { |
43cb76d9 | 293 | struct net_bridge *br = to_bridge(d); |
f7cdee8a | 294 | return sprintf(buf, "%ld\n", br_timer_value(&br->gc_work.timer)); |
1da177e4 | 295 | } |
fbf2671b | 296 | static DEVICE_ATTR_RO(gc_timer); |
1da177e4 | 297 | |
fbf2671b | 298 | static ssize_t group_addr_show(struct device *d, |
43cb76d9 | 299 | struct device_attribute *attr, char *buf) |
fda93d92 | 300 | { |
43cb76d9 | 301 | struct net_bridge *br = to_bridge(d); |
223b229b | 302 | return sprintf(buf, "%pM\n", br->group_addr); |
fda93d92 SH |
303 | } |
304 | ||
fbf2671b | 305 | static ssize_t group_addr_store(struct device *d, |
43cb76d9 GKH |
306 | struct device_attribute *attr, |
307 | const char *buf, size_t len) | |
fda93d92 | 308 | { |
43cb76d9 | 309 | struct net_bridge *br = to_bridge(d); |
4197f24b | 310 | u8 new_addr[6]; |
fda93d92 | 311 | |
cb990503 | 312 | if (!ns_capable(dev_net(br->dev)->user_ns, CAP_NET_ADMIN)) |
fda93d92 SH |
313 | return -EPERM; |
314 | ||
223b229b | 315 | if (!mac_pton(buf, new_addr)) |
fda93d92 SH |
316 | return -EINVAL; |
317 | ||
46acc460 | 318 | if (!is_link_local_ether_addr(new_addr)) |
fda93d92 SH |
319 | return -EINVAL; |
320 | ||
f64f9e71 JP |
321 | if (new_addr[5] == 1 || /* 802.3x Pause address */ |
322 | new_addr[5] == 2 || /* 802.3ad Slow protocols */ | |
323 | new_addr[5] == 3) /* 802.1X PAE address */ | |
fda93d92 SH |
324 | return -EINVAL; |
325 | ||
204177f3 TM |
326 | if (!rtnl_trylock()) |
327 | return restart_syscall(); | |
328 | ||
fda93d92 | 329 | spin_lock_bh(&br->lock); |
223b229b | 330 | ether_addr_copy(br->group_addr, new_addr); |
fda93d92 | 331 | spin_unlock_bh(&br->lock); |
204177f3 | 332 | |
be3664a0 | 333 | br_opt_toggle(br, BROPT_GROUP_ADDR_SET, true); |
204177f3 | 334 | br_recalculate_fwd_mask(br); |
047831a9 | 335 | netdev_state_change(br->dev); |
204177f3 TM |
336 | |
337 | rtnl_unlock(); | |
338 | ||
fda93d92 SH |
339 | return len; |
340 | } | |
341 | ||
fbf2671b | 342 | static DEVICE_ATTR_RW(group_addr); |
fda93d92 | 343 | |
9e781401 VO |
344 | static int set_flush(struct net_bridge *br, unsigned long val, |
345 | struct netlink_ext_ack *extack) | |
14f31bb3 XL |
346 | { |
347 | br_fdb_flush(br); | |
348 | return 0; | |
349 | } | |
350 | ||
fbf2671b | 351 | static ssize_t flush_store(struct device *d, |
9cf63747 SH |
352 | struct device_attribute *attr, |
353 | const char *buf, size_t len) | |
354 | { | |
14f31bb3 | 355 | return store_bridge_parm(d, buf, len, set_flush); |
9cf63747 | 356 | } |
fbf2671b | 357 | static DEVICE_ATTR_WO(flush); |
fda93d92 | 358 | |
70e4272b NA |
359 | static ssize_t no_linklocal_learn_show(struct device *d, |
360 | struct device_attribute *attr, | |
361 | char *buf) | |
362 | { | |
363 | struct net_bridge *br = to_bridge(d); | |
364 | return sprintf(buf, "%d\n", br_boolopt_get(br, BR_BOOLOPT_NO_LL_LEARN)); | |
365 | } | |
366 | ||
9e781401 VO |
367 | static int set_no_linklocal_learn(struct net_bridge *br, unsigned long val, |
368 | struct netlink_ext_ack *extack) | |
70e4272b | 369 | { |
9e781401 | 370 | return br_boolopt_toggle(br, BR_BOOLOPT_NO_LL_LEARN, !!val, extack); |
70e4272b NA |
371 | } |
372 | ||
373 | static ssize_t no_linklocal_learn_store(struct device *d, | |
374 | struct device_attribute *attr, | |
375 | const char *buf, size_t len) | |
376 | { | |
377 | return store_bridge_parm(d, buf, len, set_no_linklocal_learn); | |
378 | } | |
379 | static DEVICE_ATTR_RW(no_linklocal_learn); | |
380 | ||
0909e117 | 381 | #ifdef CONFIG_BRIDGE_IGMP_SNOOPING |
fbf2671b | 382 | static ssize_t multicast_router_show(struct device *d, |
0909e117 HX |
383 | struct device_attribute *attr, char *buf) |
384 | { | |
385 | struct net_bridge *br = to_bridge(d); | |
d3d065c0 | 386 | return sprintf(buf, "%d\n", br->multicast_ctx.multicast_router); |
0909e117 HX |
387 | } |
388 | ||
9e781401 VO |
389 | static int set_multicast_router(struct net_bridge *br, unsigned long val, |
390 | struct netlink_ext_ack *extack) | |
391 | { | |
a97df080 | 392 | return br_multicast_set_router(&br->multicast_ctx, val); |
9e781401 VO |
393 | } |
394 | ||
fbf2671b | 395 | static ssize_t multicast_router_store(struct device *d, |
0909e117 HX |
396 | struct device_attribute *attr, |
397 | const char *buf, size_t len) | |
398 | { | |
9e781401 | 399 | return store_bridge_parm(d, buf, len, set_multicast_router); |
0909e117 | 400 | } |
fbf2671b | 401 | static DEVICE_ATTR_RW(multicast_router); |
561f1103 | 402 | |
fbf2671b | 403 | static ssize_t multicast_snooping_show(struct device *d, |
561f1103 HX |
404 | struct device_attribute *attr, |
405 | char *buf) | |
406 | { | |
407 | struct net_bridge *br = to_bridge(d); | |
13cefad2 | 408 | return sprintf(buf, "%d\n", br_opt_get(br, BROPT_MULTICAST_ENABLED)); |
561f1103 HX |
409 | } |
410 | ||
fbf2671b | 411 | static ssize_t multicast_snooping_store(struct device *d, |
561f1103 HX |
412 | struct device_attribute *attr, |
413 | const char *buf, size_t len) | |
414 | { | |
ae1ea84b | 415 | return store_bridge_parm(d, buf, len, br_multicast_toggle); |
561f1103 | 416 | } |
fbf2671b | 417 | static DEVICE_ATTR_RW(multicast_snooping); |
b195167f | 418 | |
fbf2671b | 419 | static ssize_t multicast_query_use_ifaddr_show(struct device *d, |
420 | struct device_attribute *attr, | |
421 | char *buf) | |
1c8ad5bf CW |
422 | { |
423 | struct net_bridge *br = to_bridge(d); | |
675779ad NA |
424 | return sprintf(buf, "%d\n", |
425 | br_opt_get(br, BROPT_MULTICAST_QUERY_USE_IFADDR)); | |
1c8ad5bf CW |
426 | } |
427 | ||
9e781401 VO |
428 | static int set_query_use_ifaddr(struct net_bridge *br, unsigned long val, |
429 | struct netlink_ext_ack *extack) | |
1c8ad5bf | 430 | { |
675779ad | 431 | br_opt_toggle(br, BROPT_MULTICAST_QUERY_USE_IFADDR, !!val); |
1c8ad5bf CW |
432 | return 0; |
433 | } | |
434 | ||
435 | static ssize_t | |
fbf2671b | 436 | multicast_query_use_ifaddr_store(struct device *d, |
1c8ad5bf CW |
437 | struct device_attribute *attr, |
438 | const char *buf, size_t len) | |
439 | { | |
440 | return store_bridge_parm(d, buf, len, set_query_use_ifaddr); | |
441 | } | |
fbf2671b | 442 | static DEVICE_ATTR_RW(multicast_query_use_ifaddr); |
1c8ad5bf | 443 | |
fbf2671b | 444 | static ssize_t multicast_querier_show(struct device *d, |
c5c23260 HX |
445 | struct device_attribute *attr, |
446 | char *buf) | |
447 | { | |
448 | struct net_bridge *br = to_bridge(d); | |
62938182 | 449 | return sprintf(buf, "%d\n", br->multicast_ctx.multicast_querier); |
c5c23260 HX |
450 | } |
451 | ||
9e781401 VO |
452 | static int set_multicast_querier(struct net_bridge *br, unsigned long val, |
453 | struct netlink_ext_ack *extack) | |
454 | { | |
62938182 | 455 | return br_multicast_set_querier(&br->multicast_ctx, val); |
9e781401 VO |
456 | } |
457 | ||
fbf2671b | 458 | static ssize_t multicast_querier_store(struct device *d, |
c5c23260 HX |
459 | struct device_attribute *attr, |
460 | const char *buf, size_t len) | |
461 | { | |
9e781401 | 462 | return store_bridge_parm(d, buf, len, set_multicast_querier); |
c5c23260 | 463 | } |
fbf2671b | 464 | static DEVICE_ATTR_RW(multicast_querier); |
c5c23260 | 465 | |
fbf2671b | 466 | static ssize_t hash_elasticity_show(struct device *d, |
b195167f HX |
467 | struct device_attribute *attr, char *buf) |
468 | { | |
cf332bca | 469 | return sprintf(buf, "%u\n", RHT_ELASTICITY); |
b195167f HX |
470 | } |
471 | ||
9e781401 VO |
472 | static int set_elasticity(struct net_bridge *br, unsigned long val, |
473 | struct netlink_ext_ack *extack) | |
b195167f | 474 | { |
9e781401 VO |
475 | /* 16 is RHT_ELASTICITY */ |
476 | NL_SET_ERR_MSG_MOD(extack, | |
477 | "the hash_elasticity option has been deprecated and is always 16"); | |
b195167f HX |
478 | return 0; |
479 | } | |
480 | ||
fbf2671b | 481 | static ssize_t hash_elasticity_store(struct device *d, |
b195167f HX |
482 | struct device_attribute *attr, |
483 | const char *buf, size_t len) | |
484 | { | |
485 | return store_bridge_parm(d, buf, len, set_elasticity); | |
486 | } | |
fbf2671b | 487 | static DEVICE_ATTR_RW(hash_elasticity); |
b195167f | 488 | |
fbf2671b | 489 | static ssize_t hash_max_show(struct device *d, struct device_attribute *attr, |
b195167f HX |
490 | char *buf) |
491 | { | |
492 | struct net_bridge *br = to_bridge(d); | |
493 | return sprintf(buf, "%u\n", br->hash_max); | |
494 | } | |
495 | ||
9e781401 VO |
496 | static int set_hash_max(struct net_bridge *br, unsigned long val, |
497 | struct netlink_ext_ack *extack) | |
19e3a9c9 NA |
498 | { |
499 | br->hash_max = val; | |
500 | return 0; | |
501 | } | |
502 | ||
fbf2671b | 503 | static ssize_t hash_max_store(struct device *d, struct device_attribute *attr, |
b195167f HX |
504 | const char *buf, size_t len) |
505 | { | |
19e3a9c9 | 506 | return store_bridge_parm(d, buf, len, set_hash_max); |
b195167f | 507 | } |
fbf2671b | 508 | static DEVICE_ATTR_RW(hash_max); |
d902eee4 | 509 | |
5e923585 NA |
510 | static ssize_t multicast_igmp_version_show(struct device *d, |
511 | struct device_attribute *attr, | |
512 | char *buf) | |
513 | { | |
514 | struct net_bridge *br = to_bridge(d); | |
515 | ||
d3d065c0 | 516 | return sprintf(buf, "%u\n", br->multicast_ctx.multicast_igmp_version); |
5e923585 NA |
517 | } |
518 | ||
9e781401 VO |
519 | static int set_multicast_igmp_version(struct net_bridge *br, unsigned long val, |
520 | struct netlink_ext_ack *extack) | |
521 | { | |
df271cd6 | 522 | return br_multicast_set_igmp_version(&br->multicast_ctx, val); |
9e781401 VO |
523 | } |
524 | ||
5e923585 NA |
525 | static ssize_t multicast_igmp_version_store(struct device *d, |
526 | struct device_attribute *attr, | |
527 | const char *buf, size_t len) | |
528 | { | |
9e781401 | 529 | return store_bridge_parm(d, buf, len, set_multicast_igmp_version); |
5e923585 NA |
530 | } |
531 | static DEVICE_ATTR_RW(multicast_igmp_version); | |
532 | ||
fbf2671b | 533 | static ssize_t multicast_last_member_count_show(struct device *d, |
d902eee4 HX |
534 | struct device_attribute *attr, |
535 | char *buf) | |
536 | { | |
537 | struct net_bridge *br = to_bridge(d); | |
d3d065c0 | 538 | return sprintf(buf, "%u\n", br->multicast_ctx.multicast_last_member_count); |
d902eee4 HX |
539 | } |
540 | ||
9e781401 VO |
541 | static int set_last_member_count(struct net_bridge *br, unsigned long val, |
542 | struct netlink_ext_ack *extack) | |
d902eee4 | 543 | { |
d3d065c0 | 544 | br->multicast_ctx.multicast_last_member_count = val; |
d902eee4 HX |
545 | return 0; |
546 | } | |
547 | ||
fbf2671b | 548 | static ssize_t multicast_last_member_count_store(struct device *d, |
d902eee4 HX |
549 | struct device_attribute *attr, |
550 | const char *buf, size_t len) | |
551 | { | |
552 | return store_bridge_parm(d, buf, len, set_last_member_count); | |
553 | } | |
fbf2671b | 554 | static DEVICE_ATTR_RW(multicast_last_member_count); |
d902eee4 | 555 | |
fbf2671b | 556 | static ssize_t multicast_startup_query_count_show( |
d902eee4 HX |
557 | struct device *d, struct device_attribute *attr, char *buf) |
558 | { | |
559 | struct net_bridge *br = to_bridge(d); | |
d3d065c0 | 560 | return sprintf(buf, "%u\n", br->multicast_ctx.multicast_startup_query_count); |
d902eee4 HX |
561 | } |
562 | ||
9e781401 VO |
563 | static int set_startup_query_count(struct net_bridge *br, unsigned long val, |
564 | struct netlink_ext_ack *extack) | |
d902eee4 | 565 | { |
d3d065c0 | 566 | br->multicast_ctx.multicast_startup_query_count = val; |
d902eee4 HX |
567 | return 0; |
568 | } | |
569 | ||
fbf2671b | 570 | static ssize_t multicast_startup_query_count_store( |
d902eee4 HX |
571 | struct device *d, struct device_attribute *attr, const char *buf, |
572 | size_t len) | |
573 | { | |
574 | return store_bridge_parm(d, buf, len, set_startup_query_count); | |
575 | } | |
fbf2671b | 576 | static DEVICE_ATTR_RW(multicast_startup_query_count); |
d902eee4 | 577 | |
fbf2671b | 578 | static ssize_t multicast_last_member_interval_show( |
d902eee4 HX |
579 | struct device *d, struct device_attribute *attr, char *buf) |
580 | { | |
581 | struct net_bridge *br = to_bridge(d); | |
582 | return sprintf(buf, "%lu\n", | |
d3d065c0 | 583 | jiffies_to_clock_t(br->multicast_ctx.multicast_last_member_interval)); |
d902eee4 HX |
584 | } |
585 | ||
9e781401 VO |
586 | static int set_last_member_interval(struct net_bridge *br, unsigned long val, |
587 | struct netlink_ext_ack *extack) | |
d902eee4 | 588 | { |
d3d065c0 | 589 | br->multicast_ctx.multicast_last_member_interval = clock_t_to_jiffies(val); |
d902eee4 HX |
590 | return 0; |
591 | } | |
592 | ||
fbf2671b | 593 | static ssize_t multicast_last_member_interval_store( |
d902eee4 HX |
594 | struct device *d, struct device_attribute *attr, const char *buf, |
595 | size_t len) | |
596 | { | |
597 | return store_bridge_parm(d, buf, len, set_last_member_interval); | |
598 | } | |
fbf2671b | 599 | static DEVICE_ATTR_RW(multicast_last_member_interval); |
d902eee4 | 600 | |
fbf2671b | 601 | static ssize_t multicast_membership_interval_show( |
d902eee4 HX |
602 | struct device *d, struct device_attribute *attr, char *buf) |
603 | { | |
604 | struct net_bridge *br = to_bridge(d); | |
605 | return sprintf(buf, "%lu\n", | |
d3d065c0 | 606 | jiffies_to_clock_t(br->multicast_ctx.multicast_membership_interval)); |
d902eee4 HX |
607 | } |
608 | ||
9e781401 VO |
609 | static int set_membership_interval(struct net_bridge *br, unsigned long val, |
610 | struct netlink_ext_ack *extack) | |
d902eee4 | 611 | { |
d3d065c0 | 612 | br->multicast_ctx.multicast_membership_interval = clock_t_to_jiffies(val); |
d902eee4 HX |
613 | return 0; |
614 | } | |
615 | ||
fbf2671b | 616 | static ssize_t multicast_membership_interval_store( |
d902eee4 HX |
617 | struct device *d, struct device_attribute *attr, const char *buf, |
618 | size_t len) | |
619 | { | |
620 | return store_bridge_parm(d, buf, len, set_membership_interval); | |
621 | } | |
fbf2671b | 622 | static DEVICE_ATTR_RW(multicast_membership_interval); |
d902eee4 | 623 | |
fbf2671b | 624 | static ssize_t multicast_querier_interval_show(struct device *d, |
d902eee4 HX |
625 | struct device_attribute *attr, |
626 | char *buf) | |
627 | { | |
628 | struct net_bridge *br = to_bridge(d); | |
629 | return sprintf(buf, "%lu\n", | |
d3d065c0 | 630 | jiffies_to_clock_t(br->multicast_ctx.multicast_querier_interval)); |
d902eee4 HX |
631 | } |
632 | ||
9e781401 VO |
633 | static int set_querier_interval(struct net_bridge *br, unsigned long val, |
634 | struct netlink_ext_ack *extack) | |
d902eee4 | 635 | { |
d3d065c0 | 636 | br->multicast_ctx.multicast_querier_interval = clock_t_to_jiffies(val); |
d902eee4 HX |
637 | return 0; |
638 | } | |
639 | ||
fbf2671b | 640 | static ssize_t multicast_querier_interval_store(struct device *d, |
d902eee4 HX |
641 | struct device_attribute *attr, |
642 | const char *buf, size_t len) | |
643 | { | |
644 | return store_bridge_parm(d, buf, len, set_querier_interval); | |
645 | } | |
fbf2671b | 646 | static DEVICE_ATTR_RW(multicast_querier_interval); |
d902eee4 | 647 | |
fbf2671b | 648 | static ssize_t multicast_query_interval_show(struct device *d, |
d902eee4 HX |
649 | struct device_attribute *attr, |
650 | char *buf) | |
651 | { | |
652 | struct net_bridge *br = to_bridge(d); | |
653 | return sprintf(buf, "%lu\n", | |
d3d065c0 | 654 | jiffies_to_clock_t(br->multicast_ctx.multicast_query_interval)); |
d902eee4 HX |
655 | } |
656 | ||
9e781401 VO |
657 | static int set_query_interval(struct net_bridge *br, unsigned long val, |
658 | struct netlink_ext_ack *extack) | |
d902eee4 | 659 | { |
d3d065c0 | 660 | br->multicast_ctx.multicast_query_interval = clock_t_to_jiffies(val); |
d902eee4 HX |
661 | return 0; |
662 | } | |
663 | ||
fbf2671b | 664 | static ssize_t multicast_query_interval_store(struct device *d, |
d902eee4 HX |
665 | struct device_attribute *attr, |
666 | const char *buf, size_t len) | |
667 | { | |
668 | return store_bridge_parm(d, buf, len, set_query_interval); | |
669 | } | |
fbf2671b | 670 | static DEVICE_ATTR_RW(multicast_query_interval); |
d902eee4 | 671 | |
fbf2671b | 672 | static ssize_t multicast_query_response_interval_show( |
d902eee4 HX |
673 | struct device *d, struct device_attribute *attr, char *buf) |
674 | { | |
675 | struct net_bridge *br = to_bridge(d); | |
676 | return sprintf( | |
677 | buf, "%lu\n", | |
d3d065c0 | 678 | jiffies_to_clock_t(br->multicast_ctx.multicast_query_response_interval)); |
d902eee4 HX |
679 | } |
680 | ||
9e781401 VO |
681 | static int set_query_response_interval(struct net_bridge *br, unsigned long val, |
682 | struct netlink_ext_ack *extack) | |
d902eee4 | 683 | { |
d3d065c0 | 684 | br->multicast_ctx.multicast_query_response_interval = clock_t_to_jiffies(val); |
d902eee4 HX |
685 | return 0; |
686 | } | |
687 | ||
fbf2671b | 688 | static ssize_t multicast_query_response_interval_store( |
d902eee4 HX |
689 | struct device *d, struct device_attribute *attr, const char *buf, |
690 | size_t len) | |
691 | { | |
692 | return store_bridge_parm(d, buf, len, set_query_response_interval); | |
693 | } | |
fbf2671b | 694 | static DEVICE_ATTR_RW(multicast_query_response_interval); |
d902eee4 | 695 | |
fbf2671b | 696 | static ssize_t multicast_startup_query_interval_show( |
d902eee4 HX |
697 | struct device *d, struct device_attribute *attr, char *buf) |
698 | { | |
699 | struct net_bridge *br = to_bridge(d); | |
700 | return sprintf( | |
701 | buf, "%lu\n", | |
d3d065c0 | 702 | jiffies_to_clock_t(br->multicast_ctx.multicast_startup_query_interval)); |
d902eee4 HX |
703 | } |
704 | ||
9e781401 VO |
705 | static int set_startup_query_interval(struct net_bridge *br, unsigned long val, |
706 | struct netlink_ext_ack *extack) | |
d902eee4 | 707 | { |
d3d065c0 | 708 | br->multicast_ctx.multicast_startup_query_interval = clock_t_to_jiffies(val); |
d902eee4 HX |
709 | return 0; |
710 | } | |
711 | ||
fbf2671b | 712 | static ssize_t multicast_startup_query_interval_store( |
d902eee4 HX |
713 | struct device *d, struct device_attribute *attr, const char *buf, |
714 | size_t len) | |
715 | { | |
716 | return store_bridge_parm(d, buf, len, set_startup_query_interval); | |
717 | } | |
fbf2671b | 718 | static DEVICE_ATTR_RW(multicast_startup_query_interval); |
1080ab95 NA |
719 | |
720 | static ssize_t multicast_stats_enabled_show(struct device *d, | |
721 | struct device_attribute *attr, | |
722 | char *buf) | |
723 | { | |
724 | struct net_bridge *br = to_bridge(d); | |
725 | ||
675779ad NA |
726 | return sprintf(buf, "%d\n", |
727 | br_opt_get(br, BROPT_MULTICAST_STATS_ENABLED)); | |
1080ab95 NA |
728 | } |
729 | ||
9e781401 VO |
730 | static int set_stats_enabled(struct net_bridge *br, unsigned long val, |
731 | struct netlink_ext_ack *extack) | |
1080ab95 | 732 | { |
675779ad | 733 | br_opt_toggle(br, BROPT_MULTICAST_STATS_ENABLED, !!val); |
1080ab95 NA |
734 | return 0; |
735 | } | |
736 | ||
737 | static ssize_t multicast_stats_enabled_store(struct device *d, | |
738 | struct device_attribute *attr, | |
739 | const char *buf, | |
740 | size_t len) | |
741 | { | |
742 | return store_bridge_parm(d, buf, len, set_stats_enabled); | |
743 | } | |
744 | static DEVICE_ATTR_RW(multicast_stats_enabled); | |
aa2ae3e7 NA |
745 | |
746 | #if IS_ENABLED(CONFIG_IPV6) | |
747 | static ssize_t multicast_mld_version_show(struct device *d, | |
748 | struct device_attribute *attr, | |
749 | char *buf) | |
750 | { | |
751 | struct net_bridge *br = to_bridge(d); | |
752 | ||
d3d065c0 | 753 | return sprintf(buf, "%u\n", br->multicast_ctx.multicast_mld_version); |
aa2ae3e7 NA |
754 | } |
755 | ||
9e781401 VO |
756 | static int set_multicast_mld_version(struct net_bridge *br, unsigned long val, |
757 | struct netlink_ext_ack *extack) | |
758 | { | |
df271cd6 | 759 | return br_multicast_set_mld_version(&br->multicast_ctx, val); |
9e781401 VO |
760 | } |
761 | ||
aa2ae3e7 NA |
762 | static ssize_t multicast_mld_version_store(struct device *d, |
763 | struct device_attribute *attr, | |
764 | const char *buf, size_t len) | |
765 | { | |
9e781401 | 766 | return store_bridge_parm(d, buf, len, set_multicast_mld_version); |
aa2ae3e7 NA |
767 | } |
768 | static DEVICE_ATTR_RW(multicast_mld_version); | |
769 | #endif | |
0909e117 | 770 | #endif |
34666d46 | 771 | #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER) |
fbf2671b | 772 | static ssize_t nf_call_iptables_show( |
4df53d8b PM |
773 | struct device *d, struct device_attribute *attr, char *buf) |
774 | { | |
775 | struct net_bridge *br = to_bridge(d); | |
8df3510f | 776 | return sprintf(buf, "%u\n", br_opt_get(br, BROPT_NF_CALL_IPTABLES)); |
4df53d8b PM |
777 | } |
778 | ||
9e781401 VO |
779 | static int set_nf_call_iptables(struct net_bridge *br, unsigned long val, |
780 | struct netlink_ext_ack *extack) | |
4df53d8b | 781 | { |
8df3510f | 782 | br_opt_toggle(br, BROPT_NF_CALL_IPTABLES, !!val); |
4df53d8b PM |
783 | return 0; |
784 | } | |
785 | ||
fbf2671b | 786 | static ssize_t nf_call_iptables_store( |
4df53d8b PM |
787 | struct device *d, struct device_attribute *attr, const char *buf, |
788 | size_t len) | |
789 | { | |
790 | return store_bridge_parm(d, buf, len, set_nf_call_iptables); | |
791 | } | |
fbf2671b | 792 | static DEVICE_ATTR_RW(nf_call_iptables); |
4df53d8b | 793 | |
fbf2671b | 794 | static ssize_t nf_call_ip6tables_show( |
4df53d8b PM |
795 | struct device *d, struct device_attribute *attr, char *buf) |
796 | { | |
797 | struct net_bridge *br = to_bridge(d); | |
8df3510f | 798 | return sprintf(buf, "%u\n", br_opt_get(br, BROPT_NF_CALL_IP6TABLES)); |
4df53d8b PM |
799 | } |
800 | ||
9e781401 VO |
801 | static int set_nf_call_ip6tables(struct net_bridge *br, unsigned long val, |
802 | struct netlink_ext_ack *extack) | |
4df53d8b | 803 | { |
8df3510f | 804 | br_opt_toggle(br, BROPT_NF_CALL_IP6TABLES, !!val); |
4df53d8b PM |
805 | return 0; |
806 | } | |
807 | ||
fbf2671b | 808 | static ssize_t nf_call_ip6tables_store( |
4df53d8b PM |
809 | struct device *d, struct device_attribute *attr, const char *buf, |
810 | size_t len) | |
811 | { | |
812 | return store_bridge_parm(d, buf, len, set_nf_call_ip6tables); | |
813 | } | |
fbf2671b | 814 | static DEVICE_ATTR_RW(nf_call_ip6tables); |
4df53d8b | 815 | |
fbf2671b | 816 | static ssize_t nf_call_arptables_show( |
4df53d8b PM |
817 | struct device *d, struct device_attribute *attr, char *buf) |
818 | { | |
819 | struct net_bridge *br = to_bridge(d); | |
8df3510f | 820 | return sprintf(buf, "%u\n", br_opt_get(br, BROPT_NF_CALL_ARPTABLES)); |
4df53d8b PM |
821 | } |
822 | ||
9e781401 VO |
823 | static int set_nf_call_arptables(struct net_bridge *br, unsigned long val, |
824 | struct netlink_ext_ack *extack) | |
4df53d8b | 825 | { |
8df3510f | 826 | br_opt_toggle(br, BROPT_NF_CALL_ARPTABLES, !!val); |
4df53d8b PM |
827 | return 0; |
828 | } | |
829 | ||
fbf2671b | 830 | static ssize_t nf_call_arptables_store( |
4df53d8b PM |
831 | struct device *d, struct device_attribute *attr, const char *buf, |
832 | size_t len) | |
833 | { | |
834 | return store_bridge_parm(d, buf, len, set_nf_call_arptables); | |
835 | } | |
fbf2671b | 836 | static DEVICE_ATTR_RW(nf_call_arptables); |
4df53d8b | 837 | #endif |
243a2e63 | 838 | #ifdef CONFIG_BRIDGE_VLAN_FILTERING |
fbf2671b | 839 | static ssize_t vlan_filtering_show(struct device *d, |
243a2e63 VY |
840 | struct device_attribute *attr, |
841 | char *buf) | |
842 | { | |
843 | struct net_bridge *br = to_bridge(d); | |
ae75767e | 844 | return sprintf(buf, "%d\n", br_opt_get(br, BROPT_VLAN_ENABLED)); |
243a2e63 VY |
845 | } |
846 | ||
fbf2671b | 847 | static ssize_t vlan_filtering_store(struct device *d, |
243a2e63 VY |
848 | struct device_attribute *attr, |
849 | const char *buf, size_t len) | |
850 | { | |
851 | return store_bridge_parm(d, buf, len, br_vlan_filter_toggle); | |
852 | } | |
fbf2671b | 853 | static DEVICE_ATTR_RW(vlan_filtering); |
204177f3 TM |
854 | |
855 | static ssize_t vlan_protocol_show(struct device *d, | |
856 | struct device_attribute *attr, | |
857 | char *buf) | |
858 | { | |
859 | struct net_bridge *br = to_bridge(d); | |
860 | return sprintf(buf, "%#06x\n", ntohs(br->vlan_proto)); | |
861 | } | |
862 | ||
863 | static ssize_t vlan_protocol_store(struct device *d, | |
864 | struct device_attribute *attr, | |
865 | const char *buf, size_t len) | |
866 | { | |
867 | return store_bridge_parm(d, buf, len, br_vlan_set_proto); | |
868 | } | |
869 | static DEVICE_ATTR_RW(vlan_protocol); | |
96a20d9d VY |
870 | |
871 | static ssize_t default_pvid_show(struct device *d, | |
872 | struct device_attribute *attr, | |
873 | char *buf) | |
874 | { | |
875 | struct net_bridge *br = to_bridge(d); | |
876 | return sprintf(buf, "%d\n", br->default_pvid); | |
877 | } | |
878 | ||
879 | static ssize_t default_pvid_store(struct device *d, | |
880 | struct device_attribute *attr, | |
881 | const char *buf, size_t len) | |
882 | { | |
883 | return store_bridge_parm(d, buf, len, br_vlan_set_default_pvid); | |
884 | } | |
885 | static DEVICE_ATTR_RW(default_pvid); | |
6dada9b1 NA |
886 | |
887 | static ssize_t vlan_stats_enabled_show(struct device *d, | |
888 | struct device_attribute *attr, | |
889 | char *buf) | |
890 | { | |
891 | struct net_bridge *br = to_bridge(d); | |
ae75767e | 892 | return sprintf(buf, "%u\n", br_opt_get(br, BROPT_VLAN_STATS_ENABLED)); |
6dada9b1 NA |
893 | } |
894 | ||
9e781401 VO |
895 | static int set_vlan_stats_enabled(struct net_bridge *br, unsigned long val, |
896 | struct netlink_ext_ack *extack) | |
897 | { | |
898 | return br_vlan_set_stats(br, val); | |
899 | } | |
900 | ||
6dada9b1 NA |
901 | static ssize_t vlan_stats_enabled_store(struct device *d, |
902 | struct device_attribute *attr, | |
903 | const char *buf, size_t len) | |
904 | { | |
9e781401 | 905 | return store_bridge_parm(d, buf, len, set_vlan_stats_enabled); |
6dada9b1 NA |
906 | } |
907 | static DEVICE_ATTR_RW(vlan_stats_enabled); | |
9163a0fc NA |
908 | |
909 | static ssize_t vlan_stats_per_port_show(struct device *d, | |
910 | struct device_attribute *attr, | |
911 | char *buf) | |
912 | { | |
913 | struct net_bridge *br = to_bridge(d); | |
914 | return sprintf(buf, "%u\n", br_opt_get(br, BROPT_VLAN_STATS_PER_PORT)); | |
915 | } | |
916 | ||
9e781401 VO |
917 | static int set_vlan_stats_per_port(struct net_bridge *br, unsigned long val, |
918 | struct netlink_ext_ack *extack) | |
919 | { | |
920 | return br_vlan_set_stats_per_port(br, val); | |
921 | } | |
922 | ||
9163a0fc NA |
923 | static ssize_t vlan_stats_per_port_store(struct device *d, |
924 | struct device_attribute *attr, | |
925 | const char *buf, size_t len) | |
926 | { | |
9e781401 | 927 | return store_bridge_parm(d, buf, len, set_vlan_stats_per_port); |
9163a0fc NA |
928 | } |
929 | static DEVICE_ATTR_RW(vlan_stats_per_port); | |
243a2e63 | 930 | #endif |
0909e117 | 931 | |
1da177e4 | 932 | static struct attribute *bridge_attrs[] = { |
43cb76d9 GKH |
933 | &dev_attr_forward_delay.attr, |
934 | &dev_attr_hello_time.attr, | |
935 | &dev_attr_max_age.attr, | |
936 | &dev_attr_ageing_time.attr, | |
937 | &dev_attr_stp_state.attr, | |
515853cc | 938 | &dev_attr_group_fwd_mask.attr, |
43cb76d9 GKH |
939 | &dev_attr_priority.attr, |
940 | &dev_attr_bridge_id.attr, | |
941 | &dev_attr_root_id.attr, | |
942 | &dev_attr_root_path_cost.attr, | |
943 | &dev_attr_root_port.attr, | |
944 | &dev_attr_topology_change.attr, | |
945 | &dev_attr_topology_change_detected.attr, | |
946 | &dev_attr_hello_timer.attr, | |
947 | &dev_attr_tcn_timer.attr, | |
948 | &dev_attr_topology_change_timer.attr, | |
949 | &dev_attr_gc_timer.attr, | |
950 | &dev_attr_group_addr.attr, | |
9cf63747 | 951 | &dev_attr_flush.attr, |
70e4272b | 952 | &dev_attr_no_linklocal_learn.attr, |
0909e117 HX |
953 | #ifdef CONFIG_BRIDGE_IGMP_SNOOPING |
954 | &dev_attr_multicast_router.attr, | |
561f1103 | 955 | &dev_attr_multicast_snooping.attr, |
c5c23260 | 956 | &dev_attr_multicast_querier.attr, |
1c8ad5bf | 957 | &dev_attr_multicast_query_use_ifaddr.attr, |
b195167f HX |
958 | &dev_attr_hash_elasticity.attr, |
959 | &dev_attr_hash_max.attr, | |
d902eee4 HX |
960 | &dev_attr_multicast_last_member_count.attr, |
961 | &dev_attr_multicast_startup_query_count.attr, | |
962 | &dev_attr_multicast_last_member_interval.attr, | |
963 | &dev_attr_multicast_membership_interval.attr, | |
964 | &dev_attr_multicast_querier_interval.attr, | |
965 | &dev_attr_multicast_query_interval.attr, | |
966 | &dev_attr_multicast_query_response_interval.attr, | |
967 | &dev_attr_multicast_startup_query_interval.attr, | |
1080ab95 | 968 | &dev_attr_multicast_stats_enabled.attr, |
5e923585 | 969 | &dev_attr_multicast_igmp_version.attr, |
aa2ae3e7 NA |
970 | #if IS_ENABLED(CONFIG_IPV6) |
971 | &dev_attr_multicast_mld_version.attr, | |
972 | #endif | |
4df53d8b | 973 | #endif |
34666d46 | 974 | #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER) |
4df53d8b PM |
975 | &dev_attr_nf_call_iptables.attr, |
976 | &dev_attr_nf_call_ip6tables.attr, | |
977 | &dev_attr_nf_call_arptables.attr, | |
243a2e63 VY |
978 | #endif |
979 | #ifdef CONFIG_BRIDGE_VLAN_FILTERING | |
980 | &dev_attr_vlan_filtering.attr, | |
204177f3 | 981 | &dev_attr_vlan_protocol.attr, |
96a20d9d | 982 | &dev_attr_default_pvid.attr, |
6dada9b1 | 983 | &dev_attr_vlan_stats_enabled.attr, |
9163a0fc | 984 | &dev_attr_vlan_stats_per_port.attr, |
0909e117 | 985 | #endif |
1da177e4 LT |
986 | NULL |
987 | }; | |
988 | ||
cddbb79f | 989 | static const struct attribute_group bridge_group = { |
1da177e4 LT |
990 | .name = SYSFS_BRIDGE_ATTR, |
991 | .attrs = bridge_attrs, | |
992 | }; | |
993 | ||
994 | /* | |
995 | * Export the forwarding information table as a binary file | |
996 | * The records are struct __fdb_entry. | |
997 | * | |
998 | * Returns the number of bytes read. | |
999 | */ | |
2c3c8bea | 1000 | static ssize_t brforward_read(struct file *filp, struct kobject *kobj, |
91a69029 ZR |
1001 | struct bin_attribute *bin_attr, |
1002 | char *buf, loff_t off, size_t count) | |
1da177e4 | 1003 | { |
aeb7ed14 | 1004 | struct device *dev = kobj_to_dev(kobj); |
43cb76d9 | 1005 | struct net_bridge *br = to_bridge(dev); |
1da177e4 LT |
1006 | int n; |
1007 | ||
1008 | /* must read whole records */ | |
1009 | if (off % sizeof(struct __fdb_entry) != 0) | |
1010 | return -EINVAL; | |
1011 | ||
9d6f229f | 1012 | n = br_fdb_fillbuf(br, buf, |
1da177e4 LT |
1013 | count / sizeof(struct __fdb_entry), |
1014 | off / sizeof(struct __fdb_entry)); | |
1015 | ||
1016 | if (n > 0) | |
1017 | n *= sizeof(struct __fdb_entry); | |
9d6f229f | 1018 | |
1da177e4 LT |
1019 | return n; |
1020 | } | |
1021 | ||
1022 | static struct bin_attribute bridge_forward = { | |
1023 | .attr = { .name = SYSFS_BRIDGE_FDB, | |
d6444062 | 1024 | .mode = 0444, }, |
1da177e4 LT |
1025 | .read = brforward_read, |
1026 | }; | |
1027 | ||
1028 | /* | |
1029 | * Add entries in sysfs onto the existing network class device | |
1030 | * for the bridge. | |
1031 | * Adds a attribute group "bridge" containing tuning parameters. | |
1032 | * Binary attribute containing the forward table | |
1033 | * Sub directory to hold links to interfaces. | |
1034 | * | |
1035 | * Note: the ifobj exists only to be a subdirectory | |
1036 | * to hold links. The ifobj exists in same data structure | |
1037 | * as it's parent the bridge so reference counting works. | |
1038 | */ | |
1039 | int br_sysfs_addbr(struct net_device *dev) | |
1040 | { | |
43cb76d9 | 1041 | struct kobject *brobj = &dev->dev.kobj; |
1da177e4 LT |
1042 | struct net_bridge *br = netdev_priv(dev); |
1043 | int err; | |
1044 | ||
1045 | err = sysfs_create_group(brobj, &bridge_group); | |
1046 | if (err) { | |
1047 | pr_info("%s: can't create group %s/%s\n", | |
0dc47877 | 1048 | __func__, dev->name, bridge_group.name); |
1da177e4 LT |
1049 | goto out1; |
1050 | } | |
1051 | ||
1052 | err = sysfs_create_bin_file(brobj, &bridge_forward); | |
1053 | if (err) { | |
1842c4be | 1054 | pr_info("%s: can't create attribute file %s/%s\n", |
0dc47877 | 1055 | __func__, dev->name, bridge_forward.attr.name); |
1da177e4 LT |
1056 | goto out2; |
1057 | } | |
1058 | ||
43b98c4a GKH |
1059 | br->ifobj = kobject_create_and_add(SYSFS_BRIDGE_PORT_SUBDIR, brobj); |
1060 | if (!br->ifobj) { | |
1da177e4 | 1061 | pr_info("%s: can't add kobject (directory) %s/%s\n", |
0dc47877 | 1062 | __func__, dev->name, SYSFS_BRIDGE_PORT_SUBDIR); |
b5958963 | 1063 | err = -ENOMEM; |
1da177e4 LT |
1064 | goto out3; |
1065 | } | |
1066 | return 0; | |
1067 | out3: | |
43cb76d9 | 1068 | sysfs_remove_bin_file(&dev->dev.kobj, &bridge_forward); |
1da177e4 | 1069 | out2: |
43cb76d9 | 1070 | sysfs_remove_group(&dev->dev.kobj, &bridge_group); |
1da177e4 LT |
1071 | out1: |
1072 | return err; | |
1073 | ||
1074 | } | |
1075 | ||
1076 | void br_sysfs_delbr(struct net_device *dev) | |
1077 | { | |
43cb76d9 | 1078 | struct kobject *kobj = &dev->dev.kobj; |
1da177e4 LT |
1079 | struct net_bridge *br = netdev_priv(dev); |
1080 | ||
78a2d906 | 1081 | kobject_put(br->ifobj); |
1da177e4 LT |
1082 | sysfs_remove_bin_file(kobj, &bridge_forward); |
1083 | sysfs_remove_group(kobj, &bridge_group); | |
1084 | } |