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