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