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