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