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