]>
Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
15401946 | 2 | * Sysfs attributes of bridge |
1da177e4 LT |
3 | * 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 | ||
4fc268d2 | 14 | #include <linux/capability.h> |
1da177e4 LT |
15 | #include <linux/kernel.h> |
16 | #include <linux/netdevice.h> | |
b3343a2a | 17 | #include <linux/etherdevice.h> |
1da177e4 LT |
18 | #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 | ||
524ad0a7 | 25 | #define to_bridge(cd) ((struct net_bridge *)netdev_priv(to_net_dev(cd))) |
1da177e4 LT |
26 | |
27 | /* | |
28 | * Common code for storing bridge parameters. | |
29 | */ | |
43cb76d9 | 30 | static ssize_t store_bridge_parm(struct device *d, |
1da177e4 | 31 | const char *buf, size_t len, |
8d4698f7 | 32 | int (*set)(struct net_bridge *, unsigned long)) |
1da177e4 | 33 | { |
43cb76d9 | 34 | struct net_bridge *br = to_bridge(d); |
1da177e4 LT |
35 | char *endp; |
36 | unsigned long val; | |
8d4698f7 | 37 | int err; |
1da177e4 | 38 | |
cb990503 | 39 | if (!ns_capable(dev_net(br->dev)->user_ns, CAP_NET_ADMIN)) |
1da177e4 LT |
40 | return -EPERM; |
41 | ||
42 | val = simple_strtoul(buf, &endp, 0); | |
43 | if (endp == buf) | |
44 | return -EINVAL; | |
45 | ||
047831a9 XL |
46 | if (!rtnl_trylock()) |
47 | return restart_syscall(); | |
48 | ||
8d4698f7 | 49 | err = (*set)(br, val); |
047831a9 XL |
50 | if (!err) |
51 | netdev_state_change(br->dev); | |
52 | rtnl_unlock(); | |
53 | ||
8d4698f7 | 54 | return err ? err : len; |
1da177e4 LT |
55 | } |
56 | ||
57 | ||
fbf2671b | 58 | static ssize_t forward_delay_show(struct device *d, |
43cb76d9 | 59 | struct device_attribute *attr, char *buf) |
1da177e4 | 60 | { |
43cb76d9 | 61 | struct net_bridge *br = to_bridge(d); |
1da177e4 LT |
62 | return sprintf(buf, "%lu\n", jiffies_to_clock_t(br->forward_delay)); |
63 | } | |
64 | ||
fbf2671b | 65 | static ssize_t forward_delay_store(struct device *d, |
43cb76d9 GKH |
66 | struct device_attribute *attr, |
67 | const char *buf, size_t len) | |
1da177e4 | 68 | { |
14f98f25 | 69 | return store_bridge_parm(d, buf, len, br_set_forward_delay); |
1da177e4 | 70 | } |
fbf2671b | 71 | static DEVICE_ATTR_RW(forward_delay); |
1da177e4 | 72 | |
fbf2671b | 73 | static ssize_t hello_time_show(struct device *d, struct device_attribute *attr, |
43cb76d9 | 74 | char *buf) |
1da177e4 LT |
75 | { |
76 | return sprintf(buf, "%lu\n", | |
43cb76d9 | 77 | jiffies_to_clock_t(to_bridge(d)->hello_time)); |
1da177e4 LT |
78 | } |
79 | ||
fbf2671b | 80 | static ssize_t hello_time_store(struct device *d, |
43cb76d9 | 81 | struct device_attribute *attr, const char *buf, |
1da177e4 LT |
82 | size_t len) |
83 | { | |
14f98f25 | 84 | return store_bridge_parm(d, buf, len, br_set_hello_time); |
1da177e4 | 85 | } |
fbf2671b | 86 | static DEVICE_ATTR_RW(hello_time); |
1da177e4 | 87 | |
fbf2671b | 88 | static ssize_t max_age_show(struct device *d, struct device_attribute *attr, |
43cb76d9 | 89 | char *buf) |
1da177e4 LT |
90 | { |
91 | return sprintf(buf, "%lu\n", | |
43cb76d9 | 92 | jiffies_to_clock_t(to_bridge(d)->max_age)); |
1da177e4 LT |
93 | } |
94 | ||
fbf2671b | 95 | static ssize_t max_age_store(struct device *d, struct device_attribute *attr, |
43cb76d9 | 96 | const char *buf, size_t len) |
1da177e4 | 97 | { |
14f98f25 | 98 | return store_bridge_parm(d, buf, len, br_set_max_age); |
1da177e4 | 99 | } |
fbf2671b | 100 | static DEVICE_ATTR_RW(max_age); |
1da177e4 | 101 | |
fbf2671b | 102 | static ssize_t ageing_time_show(struct device *d, |
43cb76d9 | 103 | struct device_attribute *attr, char *buf) |
1da177e4 | 104 | { |
43cb76d9 | 105 | struct net_bridge *br = to_bridge(d); |
1da177e4 LT |
106 | return sprintf(buf, "%lu\n", jiffies_to_clock_t(br->ageing_time)); |
107 | } | |
108 | ||
8d4698f7 | 109 | static int set_ageing_time(struct net_bridge *br, unsigned long val) |
1da177e4 | 110 | { |
047831a9 | 111 | return br_set_ageing_time(br, val); |
1da177e4 LT |
112 | } |
113 | ||
fbf2671b | 114 | static ssize_t ageing_time_store(struct device *d, |
43cb76d9 GKH |
115 | struct device_attribute *attr, |
116 | const char *buf, size_t len) | |
1da177e4 | 117 | { |
43cb76d9 | 118 | return store_bridge_parm(d, buf, len, set_ageing_time); |
1da177e4 | 119 | } |
fbf2671b | 120 | static DEVICE_ATTR_RW(ageing_time); |
1da177e4 | 121 | |
fbf2671b | 122 | static ssize_t stp_state_show(struct device *d, |
43cb76d9 | 123 | struct device_attribute *attr, char *buf) |
1da177e4 | 124 | { |
43cb76d9 | 125 | struct net_bridge *br = to_bridge(d); |
1da177e4 LT |
126 | return sprintf(buf, "%d\n", br->stp_enabled); |
127 | } | |
128 | ||
1da177e4 | 129 | |
4436156b | 130 | static int set_stp_state(struct net_bridge *br, unsigned long val) |
1da177e4 | 131 | { |
17120889 | 132 | br_stp_set_enabled(br, val); |
17120889 | 133 | |
4436156b XL |
134 | return 0; |
135 | } | |
136 | ||
137 | static ssize_t stp_state_store(struct device *d, | |
138 | struct device_attribute *attr, const char *buf, | |
139 | size_t len) | |
140 | { | |
141 | return store_bridge_parm(d, buf, len, set_stp_state); | |
1da177e4 | 142 | } |
fbf2671b | 143 | static DEVICE_ATTR_RW(stp_state); |
1da177e4 | 144 | |
fbf2671b | 145 | static ssize_t group_fwd_mask_show(struct device *d, |
146 | struct device_attribute *attr, | |
147 | char *buf) | |
515853cc | 148 | { |
149 | struct net_bridge *br = to_bridge(d); | |
150 | return sprintf(buf, "%#x\n", br->group_fwd_mask); | |
151 | } | |
152 | ||
347db6b4 | 153 | static int set_group_fwd_mask(struct net_bridge *br, unsigned long val) |
515853cc | 154 | { |
515853cc | 155 | if (val & BR_GROUPFWD_RESTRICTED) |
156 | return -EINVAL; | |
157 | ||
158 | br->group_fwd_mask = val; | |
159 | ||
347db6b4 XL |
160 | return 0; |
161 | } | |
162 | ||
163 | static ssize_t group_fwd_mask_store(struct device *d, | |
164 | struct device_attribute *attr, | |
165 | const char *buf, | |
166 | size_t len) | |
167 | { | |
168 | return store_bridge_parm(d, buf, len, set_group_fwd_mask); | |
515853cc | 169 | } |
fbf2671b | 170 | static DEVICE_ATTR_RW(group_fwd_mask); |
515853cc | 171 | |
fbf2671b | 172 | static ssize_t priority_show(struct device *d, struct device_attribute *attr, |
43cb76d9 | 173 | char *buf) |
1da177e4 | 174 | { |
43cb76d9 | 175 | struct net_bridge *br = to_bridge(d); |
1da177e4 LT |
176 | return sprintf(buf, "%d\n", |
177 | (br->bridge_id.prio[0] << 8) | br->bridge_id.prio[1]); | |
178 | } | |
179 | ||
8d4698f7 | 180 | static int set_priority(struct net_bridge *br, unsigned long val) |
1da177e4 LT |
181 | { |
182 | br_stp_set_bridge_priority(br, (u16) val); | |
8d4698f7 | 183 | return 0; |
1da177e4 LT |
184 | } |
185 | ||
fbf2671b | 186 | static ssize_t priority_store(struct device *d, struct device_attribute *attr, |
187 | const char *buf, size_t len) | |
1da177e4 | 188 | { |
43cb76d9 | 189 | return store_bridge_parm(d, buf, len, set_priority); |
1da177e4 | 190 | } |
fbf2671b | 191 | static DEVICE_ATTR_RW(priority); |
1da177e4 | 192 | |
fbf2671b | 193 | static ssize_t root_id_show(struct device *d, struct device_attribute *attr, |
43cb76d9 | 194 | char *buf) |
1da177e4 | 195 | { |
43cb76d9 | 196 | return br_show_bridge_id(buf, &to_bridge(d)->designated_root); |
1da177e4 | 197 | } |
fbf2671b | 198 | static DEVICE_ATTR_RO(root_id); |
1da177e4 | 199 | |
fbf2671b | 200 | static ssize_t bridge_id_show(struct device *d, struct device_attribute *attr, |
43cb76d9 | 201 | char *buf) |
1da177e4 | 202 | { |
43cb76d9 | 203 | return br_show_bridge_id(buf, &to_bridge(d)->bridge_id); |
1da177e4 | 204 | } |
fbf2671b | 205 | static DEVICE_ATTR_RO(bridge_id); |
1da177e4 | 206 | |
fbf2671b | 207 | static ssize_t root_port_show(struct device *d, struct device_attribute *attr, |
43cb76d9 | 208 | char *buf) |
1da177e4 | 209 | { |
43cb76d9 | 210 | return sprintf(buf, "%d\n", to_bridge(d)->root_port); |
1da177e4 | 211 | } |
fbf2671b | 212 | static DEVICE_ATTR_RO(root_port); |
1da177e4 | 213 | |
fbf2671b | 214 | static ssize_t root_path_cost_show(struct device *d, |
43cb76d9 | 215 | struct device_attribute *attr, char *buf) |
1da177e4 | 216 | { |
43cb76d9 | 217 | return sprintf(buf, "%d\n", to_bridge(d)->root_path_cost); |
1da177e4 | 218 | } |
fbf2671b | 219 | static DEVICE_ATTR_RO(root_path_cost); |
1da177e4 | 220 | |
fbf2671b | 221 | static ssize_t topology_change_show(struct device *d, |
43cb76d9 | 222 | struct device_attribute *attr, char *buf) |
1da177e4 | 223 | { |
43cb76d9 | 224 | return sprintf(buf, "%d\n", to_bridge(d)->topology_change); |
1da177e4 | 225 | } |
fbf2671b | 226 | static DEVICE_ATTR_RO(topology_change); |
1da177e4 | 227 | |
fbf2671b | 228 | static ssize_t topology_change_detected_show(struct device *d, |
43cb76d9 GKH |
229 | struct device_attribute *attr, |
230 | char *buf) | |
1da177e4 | 231 | { |
43cb76d9 | 232 | struct net_bridge *br = to_bridge(d); |
1da177e4 LT |
233 | return sprintf(buf, "%d\n", br->topology_change_detected); |
234 | } | |
fbf2671b | 235 | static DEVICE_ATTR_RO(topology_change_detected); |
1da177e4 | 236 | |
fbf2671b | 237 | static ssize_t hello_timer_show(struct device *d, |
43cb76d9 | 238 | struct device_attribute *attr, char *buf) |
1da177e4 | 239 | { |
43cb76d9 | 240 | struct net_bridge *br = to_bridge(d); |
1da177e4 LT |
241 | return sprintf(buf, "%ld\n", br_timer_value(&br->hello_timer)); |
242 | } | |
fbf2671b | 243 | static DEVICE_ATTR_RO(hello_timer); |
1da177e4 | 244 | |
fbf2671b | 245 | static ssize_t tcn_timer_show(struct device *d, struct device_attribute *attr, |
43cb76d9 | 246 | char *buf) |
1da177e4 | 247 | { |
43cb76d9 | 248 | struct net_bridge *br = to_bridge(d); |
1da177e4 LT |
249 | return sprintf(buf, "%ld\n", br_timer_value(&br->tcn_timer)); |
250 | } | |
fbf2671b | 251 | static DEVICE_ATTR_RO(tcn_timer); |
1da177e4 | 252 | |
fbf2671b | 253 | static ssize_t topology_change_timer_show(struct device *d, |
43cb76d9 GKH |
254 | struct device_attribute *attr, |
255 | char *buf) | |
1da177e4 | 256 | { |
43cb76d9 | 257 | struct net_bridge *br = to_bridge(d); |
1da177e4 LT |
258 | return sprintf(buf, "%ld\n", br_timer_value(&br->topology_change_timer)); |
259 | } | |
fbf2671b | 260 | static DEVICE_ATTR_RO(topology_change_timer); |
1da177e4 | 261 | |
fbf2671b | 262 | static ssize_t gc_timer_show(struct device *d, struct device_attribute *attr, |
43cb76d9 | 263 | char *buf) |
1da177e4 | 264 | { |
43cb76d9 | 265 | struct net_bridge *br = to_bridge(d); |
1da177e4 LT |
266 | return sprintf(buf, "%ld\n", br_timer_value(&br->gc_timer)); |
267 | } | |
fbf2671b | 268 | static DEVICE_ATTR_RO(gc_timer); |
1da177e4 | 269 | |
fbf2671b | 270 | static ssize_t group_addr_show(struct device *d, |
43cb76d9 | 271 | struct device_attribute *attr, char *buf) |
fda93d92 | 272 | { |
43cb76d9 | 273 | struct net_bridge *br = to_bridge(d); |
fda93d92 SH |
274 | return sprintf(buf, "%x:%x:%x:%x:%x:%x\n", |
275 | br->group_addr[0], br->group_addr[1], | |
276 | br->group_addr[2], br->group_addr[3], | |
277 | br->group_addr[4], br->group_addr[5]); | |
278 | } | |
279 | ||
fbf2671b | 280 | static ssize_t group_addr_store(struct device *d, |
43cb76d9 GKH |
281 | struct device_attribute *attr, |
282 | const char *buf, size_t len) | |
fda93d92 | 283 | { |
43cb76d9 | 284 | struct net_bridge *br = to_bridge(d); |
4197f24b | 285 | u8 new_addr[6]; |
fda93d92 SH |
286 | int i; |
287 | ||
cb990503 | 288 | if (!ns_capable(dev_net(br->dev)->user_ns, CAP_NET_ADMIN)) |
fda93d92 SH |
289 | return -EPERM; |
290 | ||
4197f24b | 291 | if (sscanf(buf, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", |
fda93d92 SH |
292 | &new_addr[0], &new_addr[1], &new_addr[2], |
293 | &new_addr[3], &new_addr[4], &new_addr[5]) != 6) | |
294 | return -EINVAL; | |
295 | ||
46acc460 | 296 | if (!is_link_local_ether_addr(new_addr)) |
fda93d92 SH |
297 | return -EINVAL; |
298 | ||
f64f9e71 JP |
299 | if (new_addr[5] == 1 || /* 802.3x Pause address */ |
300 | new_addr[5] == 2 || /* 802.3ad Slow protocols */ | |
301 | new_addr[5] == 3) /* 802.1X PAE address */ | |
fda93d92 SH |
302 | return -EINVAL; |
303 | ||
204177f3 TM |
304 | if (!rtnl_trylock()) |
305 | return restart_syscall(); | |
306 | ||
fda93d92 SH |
307 | spin_lock_bh(&br->lock); |
308 | for (i = 0; i < 6; i++) | |
309 | br->group_addr[i] = new_addr[i]; | |
310 | spin_unlock_bh(&br->lock); | |
204177f3 TM |
311 | |
312 | br->group_addr_set = true; | |
313 | br_recalculate_fwd_mask(br); | |
047831a9 | 314 | netdev_state_change(br->dev); |
204177f3 TM |
315 | |
316 | rtnl_unlock(); | |
317 | ||
fda93d92 SH |
318 | return len; |
319 | } | |
320 | ||
fbf2671b | 321 | static DEVICE_ATTR_RW(group_addr); |
fda93d92 | 322 | |
14f31bb3 XL |
323 | static int set_flush(struct net_bridge *br, unsigned long val) |
324 | { | |
325 | br_fdb_flush(br); | |
326 | return 0; | |
327 | } | |
328 | ||
fbf2671b | 329 | static ssize_t flush_store(struct device *d, |
9cf63747 SH |
330 | struct device_attribute *attr, |
331 | const char *buf, size_t len) | |
332 | { | |
14f31bb3 | 333 | return store_bridge_parm(d, buf, len, set_flush); |
9cf63747 | 334 | } |
fbf2671b | 335 | static DEVICE_ATTR_WO(flush); |
fda93d92 | 336 | |
0909e117 | 337 | #ifdef CONFIG_BRIDGE_IGMP_SNOOPING |
fbf2671b | 338 | static ssize_t multicast_router_show(struct device *d, |
0909e117 HX |
339 | struct device_attribute *attr, char *buf) |
340 | { | |
341 | struct net_bridge *br = to_bridge(d); | |
342 | return sprintf(buf, "%d\n", br->multicast_router); | |
343 | } | |
344 | ||
fbf2671b | 345 | static ssize_t multicast_router_store(struct device *d, |
0909e117 HX |
346 | struct device_attribute *attr, |
347 | const char *buf, size_t len) | |
348 | { | |
349 | return store_bridge_parm(d, buf, len, br_multicast_set_router); | |
350 | } | |
fbf2671b | 351 | static DEVICE_ATTR_RW(multicast_router); |
561f1103 | 352 | |
fbf2671b | 353 | static ssize_t multicast_snooping_show(struct device *d, |
561f1103 HX |
354 | struct device_attribute *attr, |
355 | char *buf) | |
356 | { | |
357 | struct net_bridge *br = to_bridge(d); | |
358 | return sprintf(buf, "%d\n", !br->multicast_disabled); | |
359 | } | |
360 | ||
fbf2671b | 361 | static ssize_t multicast_snooping_store(struct device *d, |
561f1103 HX |
362 | struct device_attribute *attr, |
363 | const char *buf, size_t len) | |
364 | { | |
365 | return store_bridge_parm(d, buf, len, br_multicast_toggle); | |
366 | } | |
fbf2671b | 367 | static DEVICE_ATTR_RW(multicast_snooping); |
b195167f | 368 | |
fbf2671b | 369 | static ssize_t multicast_query_use_ifaddr_show(struct device *d, |
370 | struct device_attribute *attr, | |
371 | char *buf) | |
1c8ad5bf CW |
372 | { |
373 | struct net_bridge *br = to_bridge(d); | |
374 | return sprintf(buf, "%d\n", br->multicast_query_use_ifaddr); | |
375 | } | |
376 | ||
377 | static int set_query_use_ifaddr(struct net_bridge *br, unsigned long val) | |
378 | { | |
379 | br->multicast_query_use_ifaddr = !!val; | |
380 | return 0; | |
381 | } | |
382 | ||
383 | static ssize_t | |
fbf2671b | 384 | multicast_query_use_ifaddr_store(struct device *d, |
1c8ad5bf CW |
385 | struct device_attribute *attr, |
386 | const char *buf, size_t len) | |
387 | { | |
388 | return store_bridge_parm(d, buf, len, set_query_use_ifaddr); | |
389 | } | |
fbf2671b | 390 | static DEVICE_ATTR_RW(multicast_query_use_ifaddr); |
1c8ad5bf | 391 | |
fbf2671b | 392 | static ssize_t multicast_querier_show(struct device *d, |
c5c23260 HX |
393 | struct device_attribute *attr, |
394 | char *buf) | |
395 | { | |
396 | struct net_bridge *br = to_bridge(d); | |
397 | return sprintf(buf, "%d\n", br->multicast_querier); | |
398 | } | |
399 | ||
fbf2671b | 400 | static ssize_t multicast_querier_store(struct device *d, |
c5c23260 HX |
401 | struct device_attribute *attr, |
402 | const char *buf, size_t len) | |
403 | { | |
404 | return store_bridge_parm(d, buf, len, br_multicast_set_querier); | |
405 | } | |
fbf2671b | 406 | static DEVICE_ATTR_RW(multicast_querier); |
c5c23260 | 407 | |
fbf2671b | 408 | static ssize_t hash_elasticity_show(struct device *d, |
b195167f HX |
409 | struct device_attribute *attr, char *buf) |
410 | { | |
411 | struct net_bridge *br = to_bridge(d); | |
412 | return sprintf(buf, "%u\n", br->hash_elasticity); | |
413 | } | |
414 | ||
415 | static int set_elasticity(struct net_bridge *br, unsigned long val) | |
416 | { | |
417 | br->hash_elasticity = val; | |
418 | return 0; | |
419 | } | |
420 | ||
fbf2671b | 421 | static ssize_t hash_elasticity_store(struct device *d, |
b195167f HX |
422 | struct device_attribute *attr, |
423 | const char *buf, size_t len) | |
424 | { | |
425 | return store_bridge_parm(d, buf, len, set_elasticity); | |
426 | } | |
fbf2671b | 427 | static DEVICE_ATTR_RW(hash_elasticity); |
b195167f | 428 | |
fbf2671b | 429 | static ssize_t hash_max_show(struct device *d, struct device_attribute *attr, |
b195167f HX |
430 | char *buf) |
431 | { | |
432 | struct net_bridge *br = to_bridge(d); | |
433 | return sprintf(buf, "%u\n", br->hash_max); | |
434 | } | |
435 | ||
fbf2671b | 436 | static ssize_t hash_max_store(struct device *d, struct device_attribute *attr, |
b195167f HX |
437 | const char *buf, size_t len) |
438 | { | |
439 | return store_bridge_parm(d, buf, len, br_multicast_set_hash_max); | |
440 | } | |
fbf2671b | 441 | static DEVICE_ATTR_RW(hash_max); |
d902eee4 | 442 | |
5e923585 NA |
443 | static ssize_t multicast_igmp_version_show(struct device *d, |
444 | struct device_attribute *attr, | |
445 | char *buf) | |
446 | { | |
447 | struct net_bridge *br = to_bridge(d); | |
448 | ||
449 | return sprintf(buf, "%u\n", br->multicast_igmp_version); | |
450 | } | |
451 | ||
452 | static ssize_t multicast_igmp_version_store(struct device *d, | |
453 | struct device_attribute *attr, | |
454 | const char *buf, size_t len) | |
455 | { | |
456 | return store_bridge_parm(d, buf, len, br_multicast_set_igmp_version); | |
457 | } | |
458 | static DEVICE_ATTR_RW(multicast_igmp_version); | |
459 | ||
fbf2671b | 460 | static ssize_t multicast_last_member_count_show(struct device *d, |
d902eee4 HX |
461 | 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 | ||
468 | static 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 | ||
fbf2671b | 474 | static ssize_t multicast_last_member_count_store(struct device *d, |
d902eee4 HX |
475 | 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 | } | |
fbf2671b | 480 | static DEVICE_ATTR_RW(multicast_last_member_count); |
d902eee4 | 481 | |
fbf2671b | 482 | static ssize_t multicast_startup_query_count_show( |
d902eee4 HX |
483 | 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 | ||
489 | static 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 | ||
fbf2671b | 495 | static ssize_t multicast_startup_query_count_store( |
d902eee4 HX |
496 | 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 | } | |
fbf2671b | 501 | static DEVICE_ATTR_RW(multicast_startup_query_count); |
d902eee4 | 502 | |
fbf2671b | 503 | static ssize_t multicast_last_member_interval_show( |
d902eee4 HX |
504 | 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 | ||
511 | static 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 | ||
fbf2671b | 517 | static ssize_t multicast_last_member_interval_store( |
d902eee4 HX |
518 | 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 | } | |
fbf2671b | 523 | static DEVICE_ATTR_RW(multicast_last_member_interval); |
d902eee4 | 524 | |
fbf2671b | 525 | static ssize_t multicast_membership_interval_show( |
d902eee4 HX |
526 | 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 | ||
533 | static 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 | ||
fbf2671b | 539 | static ssize_t multicast_membership_interval_store( |
d902eee4 HX |
540 | 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 | } | |
fbf2671b | 545 | static DEVICE_ATTR_RW(multicast_membership_interval); |
d902eee4 | 546 | |
fbf2671b | 547 | static ssize_t multicast_querier_interval_show(struct device *d, |
d902eee4 HX |
548 | 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 | ||
556 | static 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 | ||
fbf2671b | 562 | static ssize_t multicast_querier_interval_store(struct device *d, |
d902eee4 HX |
563 | struct device_attribute *attr, |
564 | const char *buf, size_t len) | |
565 | { | |
566 | return store_bridge_parm(d, buf, len, set_querier_interval); | |
567 | } | |
fbf2671b | 568 | static DEVICE_ATTR_RW(multicast_querier_interval); |
d902eee4 | 569 | |
fbf2671b | 570 | static ssize_t multicast_query_interval_show(struct device *d, |
d902eee4 HX |
571 | 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 | ||
579 | static 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 | ||
fbf2671b | 585 | static ssize_t multicast_query_interval_store(struct device *d, |
d902eee4 HX |
586 | struct device_attribute *attr, |
587 | const char *buf, size_t len) | |
588 | { | |
589 | return store_bridge_parm(d, buf, len, set_query_interval); | |
590 | } | |
fbf2671b | 591 | static DEVICE_ATTR_RW(multicast_query_interval); |
d902eee4 | 592 | |
fbf2671b | 593 | static ssize_t multicast_query_response_interval_show( |
d902eee4 HX |
594 | 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 | ||
602 | static 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 | ||
fbf2671b | 608 | static ssize_t multicast_query_response_interval_store( |
d902eee4 HX |
609 | 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 | } | |
fbf2671b | 614 | static DEVICE_ATTR_RW(multicast_query_response_interval); |
d902eee4 | 615 | |
fbf2671b | 616 | static ssize_t multicast_startup_query_interval_show( |
d902eee4 HX |
617 | 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 | ||
625 | static 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 | ||
fbf2671b | 631 | static ssize_t multicast_startup_query_interval_store( |
d902eee4 HX |
632 | 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 | } | |
fbf2671b | 637 | static DEVICE_ATTR_RW(multicast_startup_query_interval); |
1080ab95 NA |
638 | |
639 | static ssize_t multicast_stats_enabled_show(struct device *d, | |
640 | struct device_attribute *attr, | |
641 | char *buf) | |
642 | { | |
643 | struct net_bridge *br = to_bridge(d); | |
644 | ||
645 | return sprintf(buf, "%u\n", br->multicast_stats_enabled); | |
646 | } | |
647 | ||
648 | static int set_stats_enabled(struct net_bridge *br, unsigned long val) | |
649 | { | |
650 | br->multicast_stats_enabled = !!val; | |
651 | return 0; | |
652 | } | |
653 | ||
654 | static ssize_t multicast_stats_enabled_store(struct device *d, | |
655 | struct device_attribute *attr, | |
656 | const char *buf, | |
657 | size_t len) | |
658 | { | |
659 | return store_bridge_parm(d, buf, len, set_stats_enabled); | |
660 | } | |
661 | static DEVICE_ATTR_RW(multicast_stats_enabled); | |
aa2ae3e7 NA |
662 | |
663 | #if IS_ENABLED(CONFIG_IPV6) | |
664 | static ssize_t multicast_mld_version_show(struct device *d, | |
665 | struct device_attribute *attr, | |
666 | char *buf) | |
667 | { | |
668 | struct net_bridge *br = to_bridge(d); | |
669 | ||
670 | return sprintf(buf, "%u\n", br->multicast_mld_version); | |
671 | } | |
672 | ||
673 | static ssize_t multicast_mld_version_store(struct device *d, | |
674 | struct device_attribute *attr, | |
675 | const char *buf, size_t len) | |
676 | { | |
677 | return store_bridge_parm(d, buf, len, br_multicast_set_mld_version); | |
678 | } | |
679 | static DEVICE_ATTR_RW(multicast_mld_version); | |
680 | #endif | |
0909e117 | 681 | #endif |
34666d46 | 682 | #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER) |
fbf2671b | 683 | static ssize_t nf_call_iptables_show( |
4df53d8b PM |
684 | struct device *d, struct device_attribute *attr, char *buf) |
685 | { | |
686 | struct net_bridge *br = to_bridge(d); | |
687 | return sprintf(buf, "%u\n", br->nf_call_iptables); | |
688 | } | |
689 | ||
690 | static int set_nf_call_iptables(struct net_bridge *br, unsigned long val) | |
691 | { | |
692 | br->nf_call_iptables = val ? true : false; | |
693 | return 0; | |
694 | } | |
695 | ||
fbf2671b | 696 | static ssize_t nf_call_iptables_store( |
4df53d8b PM |
697 | struct device *d, struct device_attribute *attr, const char *buf, |
698 | size_t len) | |
699 | { | |
700 | return store_bridge_parm(d, buf, len, set_nf_call_iptables); | |
701 | } | |
fbf2671b | 702 | static DEVICE_ATTR_RW(nf_call_iptables); |
4df53d8b | 703 | |
fbf2671b | 704 | static ssize_t nf_call_ip6tables_show( |
4df53d8b PM |
705 | struct device *d, struct device_attribute *attr, char *buf) |
706 | { | |
707 | struct net_bridge *br = to_bridge(d); | |
708 | return sprintf(buf, "%u\n", br->nf_call_ip6tables); | |
709 | } | |
710 | ||
711 | static int set_nf_call_ip6tables(struct net_bridge *br, unsigned long val) | |
712 | { | |
713 | br->nf_call_ip6tables = val ? true : false; | |
714 | return 0; | |
715 | } | |
716 | ||
fbf2671b | 717 | static ssize_t nf_call_ip6tables_store( |
4df53d8b PM |
718 | struct device *d, struct device_attribute *attr, const char *buf, |
719 | size_t len) | |
720 | { | |
721 | return store_bridge_parm(d, buf, len, set_nf_call_ip6tables); | |
722 | } | |
fbf2671b | 723 | static DEVICE_ATTR_RW(nf_call_ip6tables); |
4df53d8b | 724 | |
fbf2671b | 725 | static ssize_t nf_call_arptables_show( |
4df53d8b PM |
726 | struct device *d, struct device_attribute *attr, char *buf) |
727 | { | |
728 | struct net_bridge *br = to_bridge(d); | |
729 | return sprintf(buf, "%u\n", br->nf_call_arptables); | |
730 | } | |
731 | ||
732 | static int set_nf_call_arptables(struct net_bridge *br, unsigned long val) | |
733 | { | |
734 | br->nf_call_arptables = val ? true : false; | |
735 | return 0; | |
736 | } | |
737 | ||
fbf2671b | 738 | static ssize_t nf_call_arptables_store( |
4df53d8b PM |
739 | struct device *d, struct device_attribute *attr, const char *buf, |
740 | size_t len) | |
741 | { | |
742 | return store_bridge_parm(d, buf, len, set_nf_call_arptables); | |
743 | } | |
fbf2671b | 744 | static DEVICE_ATTR_RW(nf_call_arptables); |
4df53d8b | 745 | #endif |
243a2e63 | 746 | #ifdef CONFIG_BRIDGE_VLAN_FILTERING |
fbf2671b | 747 | static ssize_t vlan_filtering_show(struct device *d, |
243a2e63 VY |
748 | struct device_attribute *attr, |
749 | char *buf) | |
750 | { | |
751 | struct net_bridge *br = to_bridge(d); | |
752 | return sprintf(buf, "%d\n", br->vlan_enabled); | |
753 | } | |
754 | ||
fbf2671b | 755 | static ssize_t vlan_filtering_store(struct device *d, |
243a2e63 VY |
756 | struct device_attribute *attr, |
757 | const char *buf, size_t len) | |
758 | { | |
759 | return store_bridge_parm(d, buf, len, br_vlan_filter_toggle); | |
760 | } | |
fbf2671b | 761 | static DEVICE_ATTR_RW(vlan_filtering); |
204177f3 TM |
762 | |
763 | static ssize_t vlan_protocol_show(struct device *d, | |
764 | struct device_attribute *attr, | |
765 | char *buf) | |
766 | { | |
767 | struct net_bridge *br = to_bridge(d); | |
768 | return sprintf(buf, "%#06x\n", ntohs(br->vlan_proto)); | |
769 | } | |
770 | ||
771 | static ssize_t vlan_protocol_store(struct device *d, | |
772 | struct device_attribute *attr, | |
773 | const char *buf, size_t len) | |
774 | { | |
775 | return store_bridge_parm(d, buf, len, br_vlan_set_proto); | |
776 | } | |
777 | static DEVICE_ATTR_RW(vlan_protocol); | |
96a20d9d VY |
778 | |
779 | static ssize_t default_pvid_show(struct device *d, | |
780 | struct device_attribute *attr, | |
781 | char *buf) | |
782 | { | |
783 | struct net_bridge *br = to_bridge(d); | |
784 | return sprintf(buf, "%d\n", br->default_pvid); | |
785 | } | |
786 | ||
787 | static ssize_t default_pvid_store(struct device *d, | |
788 | struct device_attribute *attr, | |
789 | const char *buf, size_t len) | |
790 | { | |
791 | return store_bridge_parm(d, buf, len, br_vlan_set_default_pvid); | |
792 | } | |
793 | static DEVICE_ATTR_RW(default_pvid); | |
6dada9b1 NA |
794 | |
795 | static ssize_t vlan_stats_enabled_show(struct device *d, | |
796 | struct device_attribute *attr, | |
797 | char *buf) | |
798 | { | |
799 | struct net_bridge *br = to_bridge(d); | |
800 | return sprintf(buf, "%u\n", br->vlan_stats_enabled); | |
801 | } | |
802 | ||
803 | static ssize_t vlan_stats_enabled_store(struct device *d, | |
804 | struct device_attribute *attr, | |
805 | const char *buf, size_t len) | |
806 | { | |
807 | return store_bridge_parm(d, buf, len, br_vlan_set_stats); | |
808 | } | |
809 | static DEVICE_ATTR_RW(vlan_stats_enabled); | |
243a2e63 | 810 | #endif |
0909e117 | 811 | |
1da177e4 | 812 | static struct attribute *bridge_attrs[] = { |
43cb76d9 GKH |
813 | &dev_attr_forward_delay.attr, |
814 | &dev_attr_hello_time.attr, | |
815 | &dev_attr_max_age.attr, | |
816 | &dev_attr_ageing_time.attr, | |
817 | &dev_attr_stp_state.attr, | |
515853cc | 818 | &dev_attr_group_fwd_mask.attr, |
43cb76d9 GKH |
819 | &dev_attr_priority.attr, |
820 | &dev_attr_bridge_id.attr, | |
821 | &dev_attr_root_id.attr, | |
822 | &dev_attr_root_path_cost.attr, | |
823 | &dev_attr_root_port.attr, | |
824 | &dev_attr_topology_change.attr, | |
825 | &dev_attr_topology_change_detected.attr, | |
826 | &dev_attr_hello_timer.attr, | |
827 | &dev_attr_tcn_timer.attr, | |
828 | &dev_attr_topology_change_timer.attr, | |
829 | &dev_attr_gc_timer.attr, | |
830 | &dev_attr_group_addr.attr, | |
9cf63747 | 831 | &dev_attr_flush.attr, |
0909e117 HX |
832 | #ifdef CONFIG_BRIDGE_IGMP_SNOOPING |
833 | &dev_attr_multicast_router.attr, | |
561f1103 | 834 | &dev_attr_multicast_snooping.attr, |
c5c23260 | 835 | &dev_attr_multicast_querier.attr, |
1c8ad5bf | 836 | &dev_attr_multicast_query_use_ifaddr.attr, |
b195167f HX |
837 | &dev_attr_hash_elasticity.attr, |
838 | &dev_attr_hash_max.attr, | |
d902eee4 HX |
839 | &dev_attr_multicast_last_member_count.attr, |
840 | &dev_attr_multicast_startup_query_count.attr, | |
841 | &dev_attr_multicast_last_member_interval.attr, | |
842 | &dev_attr_multicast_membership_interval.attr, | |
843 | &dev_attr_multicast_querier_interval.attr, | |
844 | &dev_attr_multicast_query_interval.attr, | |
845 | &dev_attr_multicast_query_response_interval.attr, | |
846 | &dev_attr_multicast_startup_query_interval.attr, | |
1080ab95 | 847 | &dev_attr_multicast_stats_enabled.attr, |
5e923585 | 848 | &dev_attr_multicast_igmp_version.attr, |
aa2ae3e7 NA |
849 | #if IS_ENABLED(CONFIG_IPV6) |
850 | &dev_attr_multicast_mld_version.attr, | |
851 | #endif | |
4df53d8b | 852 | #endif |
34666d46 | 853 | #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER) |
4df53d8b PM |
854 | &dev_attr_nf_call_iptables.attr, |
855 | &dev_attr_nf_call_ip6tables.attr, | |
856 | &dev_attr_nf_call_arptables.attr, | |
243a2e63 VY |
857 | #endif |
858 | #ifdef CONFIG_BRIDGE_VLAN_FILTERING | |
859 | &dev_attr_vlan_filtering.attr, | |
204177f3 | 860 | &dev_attr_vlan_protocol.attr, |
96a20d9d | 861 | &dev_attr_default_pvid.attr, |
6dada9b1 | 862 | &dev_attr_vlan_stats_enabled.attr, |
0909e117 | 863 | #endif |
1da177e4 LT |
864 | NULL |
865 | }; | |
866 | ||
867 | static struct attribute_group bridge_group = { | |
868 | .name = SYSFS_BRIDGE_ATTR, | |
869 | .attrs = bridge_attrs, | |
870 | }; | |
871 | ||
872 | /* | |
873 | * Export the forwarding information table as a binary file | |
874 | * The records are struct __fdb_entry. | |
875 | * | |
876 | * Returns the number of bytes read. | |
877 | */ | |
2c3c8bea | 878 | static ssize_t brforward_read(struct file *filp, struct kobject *kobj, |
91a69029 ZR |
879 | struct bin_attribute *bin_attr, |
880 | char *buf, loff_t off, size_t count) | |
1da177e4 | 881 | { |
aeb7ed14 | 882 | struct device *dev = kobj_to_dev(kobj); |
43cb76d9 | 883 | struct net_bridge *br = to_bridge(dev); |
1da177e4 LT |
884 | int n; |
885 | ||
886 | /* must read whole records */ | |
887 | if (off % sizeof(struct __fdb_entry) != 0) | |
888 | return -EINVAL; | |
889 | ||
9d6f229f | 890 | n = br_fdb_fillbuf(br, buf, |
1da177e4 LT |
891 | count / sizeof(struct __fdb_entry), |
892 | off / sizeof(struct __fdb_entry)); | |
893 | ||
894 | if (n > 0) | |
895 | n *= sizeof(struct __fdb_entry); | |
9d6f229f | 896 | |
1da177e4 LT |
897 | return n; |
898 | } | |
899 | ||
900 | static struct bin_attribute bridge_forward = { | |
901 | .attr = { .name = SYSFS_BRIDGE_FDB, | |
7b595756 | 902 | .mode = S_IRUGO, }, |
1da177e4 LT |
903 | .read = brforward_read, |
904 | }; | |
905 | ||
906 | /* | |
907 | * Add entries in sysfs onto the existing network class device | |
908 | * for the bridge. | |
909 | * Adds a attribute group "bridge" containing tuning parameters. | |
910 | * Binary attribute containing the forward table | |
911 | * Sub directory to hold links to interfaces. | |
912 | * | |
913 | * Note: the ifobj exists only to be a subdirectory | |
914 | * to hold links. The ifobj exists in same data structure | |
915 | * as it's parent the bridge so reference counting works. | |
916 | */ | |
917 | int br_sysfs_addbr(struct net_device *dev) | |
918 | { | |
43cb76d9 | 919 | struct kobject *brobj = &dev->dev.kobj; |
1da177e4 LT |
920 | struct net_bridge *br = netdev_priv(dev); |
921 | int err; | |
922 | ||
923 | err = sysfs_create_group(brobj, &bridge_group); | |
924 | if (err) { | |
925 | pr_info("%s: can't create group %s/%s\n", | |
0dc47877 | 926 | __func__, dev->name, bridge_group.name); |
1da177e4 LT |
927 | goto out1; |
928 | } | |
929 | ||
930 | err = sysfs_create_bin_file(brobj, &bridge_forward); | |
931 | if (err) { | |
1842c4be | 932 | pr_info("%s: can't create attribute file %s/%s\n", |
0dc47877 | 933 | __func__, dev->name, bridge_forward.attr.name); |
1da177e4 LT |
934 | goto out2; |
935 | } | |
936 | ||
43b98c4a GKH |
937 | br->ifobj = kobject_create_and_add(SYSFS_BRIDGE_PORT_SUBDIR, brobj); |
938 | if (!br->ifobj) { | |
1da177e4 | 939 | pr_info("%s: can't add kobject (directory) %s/%s\n", |
0dc47877 | 940 | __func__, dev->name, SYSFS_BRIDGE_PORT_SUBDIR); |
b5958963 | 941 | err = -ENOMEM; |
1da177e4 LT |
942 | goto out3; |
943 | } | |
944 | return 0; | |
945 | out3: | |
43cb76d9 | 946 | sysfs_remove_bin_file(&dev->dev.kobj, &bridge_forward); |
1da177e4 | 947 | out2: |
43cb76d9 | 948 | sysfs_remove_group(&dev->dev.kobj, &bridge_group); |
1da177e4 LT |
949 | out1: |
950 | return err; | |
951 | ||
952 | } | |
953 | ||
954 | void br_sysfs_delbr(struct net_device *dev) | |
955 | { | |
43cb76d9 | 956 | struct kobject *kobj = &dev->dev.kobj; |
1da177e4 LT |
957 | struct net_bridge *br = netdev_priv(dev); |
958 | ||
78a2d906 | 959 | kobject_put(br->ifobj); |
1da177e4 LT |
960 | sysfs_remove_bin_file(kobj, &bridge_forward); |
961 | sysfs_remove_group(kobj, &bridge_group); | |
962 | } |