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