Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Wang Sheng-Hui | 1540194 | 2013-08-06 08:44:46 +0800 | [diff] [blame] | 2 | * Sysfs attributes of bridge |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Randy Dunlap | 4fc268d | 2006-01-11 12:17:47 -0800 | [diff] [blame] | 14 | #include <linux/capability.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/kernel.h> |
| 16 | #include <linux/netdevice.h> |
John Fastabend | b3343a2 | 2012-09-18 00:01:12 +0000 | [diff] [blame] | 17 | #include <linux/etherdevice.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 25 | #define to_dev(obj) container_of(obj, struct device, kobj) |
Wang Chen | 524ad0a | 2008-11-12 23:39:10 -0800 | [diff] [blame] | 26 | #define to_bridge(cd) ((struct net_bridge *)netdev_priv(to_net_dev(cd))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | |
| 28 | /* |
| 29 | * Common code for storing bridge parameters. |
| 30 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 31 | static ssize_t store_bridge_parm(struct device *d, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | const char *buf, size_t len, |
Stephen Hemminger | 8d4698f7 | 2008-09-08 13:44:40 -0700 | [diff] [blame] | 33 | int (*set)(struct net_bridge *, unsigned long)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 35 | struct net_bridge *br = to_bridge(d); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | char *endp; |
| 37 | unsigned long val; |
Stephen Hemminger | 8d4698f7 | 2008-09-08 13:44:40 -0700 | [diff] [blame] | 38 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | |
Eric W. Biederman | cb99050 | 2012-11-16 03:03:08 +0000 | [diff] [blame] | 40 | if (!ns_capable(dev_net(br->dev)->user_ns, CAP_NET_ADMIN)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | return -EPERM; |
| 42 | |
| 43 | val = simple_strtoul(buf, &endp, 0); |
| 44 | if (endp == buf) |
| 45 | return -EINVAL; |
| 46 | |
Stephen Hemminger | 8d4698f7 | 2008-09-08 13:44:40 -0700 | [diff] [blame] | 47 | err = (*set)(br, val); |
Stephen Hemminger | 8d4698f7 | 2008-09-08 13:44:40 -0700 | [diff] [blame] | 48 | return err ? err : len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 52 | static ssize_t show_forward_delay(struct device *d, |
| 53 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 55 | struct net_bridge *br = to_bridge(d); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | return sprintf(buf, "%lu\n", jiffies_to_clock_t(br->forward_delay)); |
| 57 | } |
| 58 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 59 | static ssize_t store_forward_delay(struct device *d, |
| 60 | struct device_attribute *attr, |
| 61 | const char *buf, size_t len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | { |
stephen hemminger | 14f98f2 | 2011-04-04 14:03:33 +0000 | [diff] [blame] | 63 | return store_bridge_parm(d, buf, len, br_set_forward_delay); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | } |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 65 | static DEVICE_ATTR(forward_delay, S_IRUGO | S_IWUSR, |
| 66 | show_forward_delay, store_forward_delay); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 68 | static ssize_t show_hello_time(struct device *d, struct device_attribute *attr, |
| 69 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | { |
| 71 | return sprintf(buf, "%lu\n", |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 72 | jiffies_to_clock_t(to_bridge(d)->hello_time)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | } |
| 74 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 75 | static ssize_t store_hello_time(struct device *d, |
| 76 | struct device_attribute *attr, const char *buf, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | size_t len) |
| 78 | { |
stephen hemminger | 14f98f2 | 2011-04-04 14:03:33 +0000 | [diff] [blame] | 79 | return store_bridge_parm(d, buf, len, br_set_hello_time); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | } |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 81 | static DEVICE_ATTR(hello_time, S_IRUGO | S_IWUSR, show_hello_time, |
| 82 | store_hello_time); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 84 | static ssize_t show_max_age(struct device *d, struct device_attribute *attr, |
| 85 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | { |
| 87 | return sprintf(buf, "%lu\n", |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 88 | jiffies_to_clock_t(to_bridge(d)->max_age)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | } |
| 90 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 91 | static ssize_t store_max_age(struct device *d, struct device_attribute *attr, |
| 92 | const char *buf, size_t len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | { |
stephen hemminger | 14f98f2 | 2011-04-04 14:03:33 +0000 | [diff] [blame] | 94 | return store_bridge_parm(d, buf, len, br_set_max_age); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | } |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 96 | static DEVICE_ATTR(max_age, S_IRUGO | S_IWUSR, show_max_age, store_max_age); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 98 | static ssize_t show_ageing_time(struct device *d, |
| 99 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 101 | struct net_bridge *br = to_bridge(d); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | return sprintf(buf, "%lu\n", jiffies_to_clock_t(br->ageing_time)); |
| 103 | } |
| 104 | |
Stephen Hemminger | 8d4698f7 | 2008-09-08 13:44:40 -0700 | [diff] [blame] | 105 | static int set_ageing_time(struct net_bridge *br, unsigned long val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | { |
| 107 | br->ageing_time = clock_t_to_jiffies(val); |
Stephen Hemminger | 8d4698f7 | 2008-09-08 13:44:40 -0700 | [diff] [blame] | 108 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | } |
| 110 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 111 | static ssize_t store_ageing_time(struct device *d, |
| 112 | struct device_attribute *attr, |
| 113 | const char *buf, size_t len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 115 | return store_bridge_parm(d, buf, len, set_ageing_time); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | } |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 117 | static DEVICE_ATTR(ageing_time, S_IRUGO | S_IWUSR, show_ageing_time, |
| 118 | store_ageing_time); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 120 | static ssize_t show_stp_state(struct device *d, |
| 121 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 123 | struct net_bridge *br = to_bridge(d); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | return sprintf(buf, "%d\n", br->stp_enabled); |
| 125 | } |
| 126 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 128 | static ssize_t store_stp_state(struct device *d, |
| 129 | struct device_attribute *attr, const char *buf, |
| 130 | size_t len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | { |
Stephen Hemminger | 1712088 | 2007-08-14 13:21:34 -0700 | [diff] [blame] | 132 | struct net_bridge *br = to_bridge(d); |
| 133 | char *endp; |
| 134 | unsigned long val; |
| 135 | |
Eric W. Biederman | cb99050 | 2012-11-16 03:03:08 +0000 | [diff] [blame] | 136 | if (!ns_capable(dev_net(br->dev)->user_ns, CAP_NET_ADMIN)) |
Stephen Hemminger | 1712088 | 2007-08-14 13:21:34 -0700 | [diff] [blame] | 137 | return -EPERM; |
| 138 | |
| 139 | val = simple_strtoul(buf, &endp, 0); |
| 140 | if (endp == buf) |
| 141 | return -EINVAL; |
| 142 | |
Eric W. Biederman | af38f29 | 2009-05-13 17:00:41 +0000 | [diff] [blame] | 143 | if (!rtnl_trylock()) |
| 144 | return restart_syscall(); |
Stephen Hemminger | 1712088 | 2007-08-14 13:21:34 -0700 | [diff] [blame] | 145 | br_stp_set_enabled(br, val); |
| 146 | rtnl_unlock(); |
| 147 | |
Al Viro | 35b426c | 2007-08-19 04:51:26 +0100 | [diff] [blame] | 148 | return len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | } |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 150 | static DEVICE_ATTR(stp_state, S_IRUGO | S_IWUSR, show_stp_state, |
| 151 | store_stp_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | |
stephen hemminger | 515853c | 2011-10-03 18:14:46 +0000 | [diff] [blame] | 153 | static ssize_t show_group_fwd_mask(struct device *d, |
| 154 | struct device_attribute *attr, char *buf) |
| 155 | { |
| 156 | struct net_bridge *br = to_bridge(d); |
| 157 | return sprintf(buf, "%#x\n", br->group_fwd_mask); |
| 158 | } |
| 159 | |
| 160 | |
| 161 | static ssize_t store_group_fwd_mask(struct device *d, |
| 162 | struct device_attribute *attr, const char *buf, |
| 163 | size_t len) |
| 164 | { |
| 165 | struct net_bridge *br = to_bridge(d); |
| 166 | char *endp; |
| 167 | unsigned long val; |
| 168 | |
Eric W. Biederman | cb99050 | 2012-11-16 03:03:08 +0000 | [diff] [blame] | 169 | if (!ns_capable(dev_net(br->dev)->user_ns, CAP_NET_ADMIN)) |
stephen hemminger | 515853c | 2011-10-03 18:14:46 +0000 | [diff] [blame] | 170 | return -EPERM; |
| 171 | |
| 172 | val = simple_strtoul(buf, &endp, 0); |
| 173 | if (endp == buf) |
| 174 | return -EINVAL; |
| 175 | |
| 176 | if (val & BR_GROUPFWD_RESTRICTED) |
| 177 | return -EINVAL; |
| 178 | |
| 179 | br->group_fwd_mask = val; |
| 180 | |
| 181 | return len; |
| 182 | } |
| 183 | static DEVICE_ATTR(group_fwd_mask, S_IRUGO | S_IWUSR, show_group_fwd_mask, |
| 184 | store_group_fwd_mask); |
| 185 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 186 | static ssize_t show_priority(struct device *d, struct device_attribute *attr, |
| 187 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 189 | struct net_bridge *br = to_bridge(d); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | return sprintf(buf, "%d\n", |
| 191 | (br->bridge_id.prio[0] << 8) | br->bridge_id.prio[1]); |
| 192 | } |
| 193 | |
Stephen Hemminger | 8d4698f7 | 2008-09-08 13:44:40 -0700 | [diff] [blame] | 194 | static int set_priority(struct net_bridge *br, unsigned long val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | { |
| 196 | br_stp_set_bridge_priority(br, (u16) val); |
Stephen Hemminger | 8d4698f7 | 2008-09-08 13:44:40 -0700 | [diff] [blame] | 197 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | } |
| 199 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 200 | static ssize_t store_priority(struct device *d, struct device_attribute *attr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | const char *buf, size_t len) |
| 202 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 203 | return store_bridge_parm(d, buf, len, set_priority); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | } |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 205 | static DEVICE_ATTR(priority, S_IRUGO | S_IWUSR, show_priority, store_priority); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 207 | static ssize_t show_root_id(struct device *d, struct device_attribute *attr, |
| 208 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 210 | return br_show_bridge_id(buf, &to_bridge(d)->designated_root); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | } |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 212 | static DEVICE_ATTR(root_id, S_IRUGO, show_root_id, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 214 | static ssize_t show_bridge_id(struct device *d, struct device_attribute *attr, |
| 215 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 217 | return br_show_bridge_id(buf, &to_bridge(d)->bridge_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | } |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 219 | static DEVICE_ATTR(bridge_id, S_IRUGO, show_bridge_id, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 221 | static ssize_t show_root_port(struct device *d, struct device_attribute *attr, |
| 222 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 224 | return sprintf(buf, "%d\n", to_bridge(d)->root_port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | } |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 226 | static DEVICE_ATTR(root_port, S_IRUGO, show_root_port, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 228 | static ssize_t show_root_path_cost(struct device *d, |
| 229 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 231 | return sprintf(buf, "%d\n", to_bridge(d)->root_path_cost); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | } |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 233 | static DEVICE_ATTR(root_path_cost, S_IRUGO, show_root_path_cost, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 235 | static ssize_t show_topology_change(struct device *d, |
| 236 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 238 | return sprintf(buf, "%d\n", to_bridge(d)->topology_change); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | } |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 240 | static DEVICE_ATTR(topology_change, S_IRUGO, show_topology_change, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 242 | static ssize_t show_topology_change_detected(struct device *d, |
| 243 | struct device_attribute *attr, |
| 244 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 246 | struct net_bridge *br = to_bridge(d); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | return sprintf(buf, "%d\n", br->topology_change_detected); |
| 248 | } |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 249 | static DEVICE_ATTR(topology_change_detected, S_IRUGO, |
| 250 | show_topology_change_detected, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 252 | static ssize_t show_hello_timer(struct device *d, |
| 253 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 255 | struct net_bridge *br = to_bridge(d); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | return sprintf(buf, "%ld\n", br_timer_value(&br->hello_timer)); |
| 257 | } |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 258 | static DEVICE_ATTR(hello_timer, S_IRUGO, show_hello_timer, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 260 | static ssize_t show_tcn_timer(struct device *d, struct device_attribute *attr, |
| 261 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 263 | struct net_bridge *br = to_bridge(d); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | return sprintf(buf, "%ld\n", br_timer_value(&br->tcn_timer)); |
| 265 | } |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 266 | static DEVICE_ATTR(tcn_timer, S_IRUGO, show_tcn_timer, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 268 | static ssize_t show_topology_change_timer(struct device *d, |
| 269 | struct device_attribute *attr, |
| 270 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 272 | struct net_bridge *br = to_bridge(d); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | return sprintf(buf, "%ld\n", br_timer_value(&br->topology_change_timer)); |
| 274 | } |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 275 | static DEVICE_ATTR(topology_change_timer, S_IRUGO, show_topology_change_timer, |
| 276 | NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 278 | static ssize_t show_gc_timer(struct device *d, struct device_attribute *attr, |
| 279 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 281 | struct net_bridge *br = to_bridge(d); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | return sprintf(buf, "%ld\n", br_timer_value(&br->gc_timer)); |
| 283 | } |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 284 | static DEVICE_ATTR(gc_timer, S_IRUGO, show_gc_timer, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 286 | static ssize_t show_group_addr(struct device *d, |
| 287 | struct device_attribute *attr, char *buf) |
Stephen Hemminger | fda93d9 | 2006-03-20 22:59:21 -0800 | [diff] [blame] | 288 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 289 | struct net_bridge *br = to_bridge(d); |
Stephen Hemminger | fda93d9 | 2006-03-20 22:59:21 -0800 | [diff] [blame] | 290 | return sprintf(buf, "%x:%x:%x:%x:%x:%x\n", |
| 291 | br->group_addr[0], br->group_addr[1], |
| 292 | br->group_addr[2], br->group_addr[3], |
| 293 | br->group_addr[4], br->group_addr[5]); |
| 294 | } |
| 295 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 296 | static ssize_t store_group_addr(struct device *d, |
| 297 | struct device_attribute *attr, |
| 298 | const char *buf, size_t len) |
Stephen Hemminger | fda93d9 | 2006-03-20 22:59:21 -0800 | [diff] [blame] | 299 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 300 | struct net_bridge *br = to_bridge(d); |
Ben Hutchings | 4197f24 | 2012-11-01 09:10:04 +0000 | [diff] [blame] | 301 | u8 new_addr[6]; |
Stephen Hemminger | fda93d9 | 2006-03-20 22:59:21 -0800 | [diff] [blame] | 302 | int i; |
| 303 | |
Eric W. Biederman | cb99050 | 2012-11-16 03:03:08 +0000 | [diff] [blame] | 304 | if (!ns_capable(dev_net(br->dev)->user_ns, CAP_NET_ADMIN)) |
Stephen Hemminger | fda93d9 | 2006-03-20 22:59:21 -0800 | [diff] [blame] | 305 | return -EPERM; |
| 306 | |
Ben Hutchings | 4197f24 | 2012-11-01 09:10:04 +0000 | [diff] [blame] | 307 | if (sscanf(buf, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", |
Stephen Hemminger | fda93d9 | 2006-03-20 22:59:21 -0800 | [diff] [blame] | 308 | &new_addr[0], &new_addr[1], &new_addr[2], |
| 309 | &new_addr[3], &new_addr[4], &new_addr[5]) != 6) |
| 310 | return -EINVAL; |
| 311 | |
Ben Hutchings | 46acc46 | 2012-11-01 09:11:11 +0000 | [diff] [blame] | 312 | if (!is_link_local_ether_addr(new_addr)) |
Stephen Hemminger | fda93d9 | 2006-03-20 22:59:21 -0800 | [diff] [blame] | 313 | return -EINVAL; |
| 314 | |
Joe Perches | f64f9e7 | 2009-11-29 16:55:45 -0800 | [diff] [blame] | 315 | if (new_addr[5] == 1 || /* 802.3x Pause address */ |
| 316 | new_addr[5] == 2 || /* 802.3ad Slow protocols */ |
| 317 | new_addr[5] == 3) /* 802.1X PAE address */ |
Stephen Hemminger | fda93d9 | 2006-03-20 22:59:21 -0800 | [diff] [blame] | 318 | return -EINVAL; |
| 319 | |
| 320 | spin_lock_bh(&br->lock); |
| 321 | for (i = 0; i < 6; i++) |
| 322 | br->group_addr[i] = new_addr[i]; |
| 323 | spin_unlock_bh(&br->lock); |
| 324 | return len; |
| 325 | } |
| 326 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 327 | static DEVICE_ATTR(group_addr, S_IRUGO | S_IWUSR, |
| 328 | show_group_addr, store_group_addr); |
Stephen Hemminger | fda93d9 | 2006-03-20 22:59:21 -0800 | [diff] [blame] | 329 | |
Stephen Hemminger | 9cf6374 | 2007-04-09 12:57:54 -0700 | [diff] [blame] | 330 | static ssize_t store_flush(struct device *d, |
| 331 | struct device_attribute *attr, |
| 332 | const char *buf, size_t len) |
| 333 | { |
| 334 | struct net_bridge *br = to_bridge(d); |
| 335 | |
Eric W. Biederman | cb99050 | 2012-11-16 03:03:08 +0000 | [diff] [blame] | 336 | if (!ns_capable(dev_net(br->dev)->user_ns, CAP_NET_ADMIN)) |
Stephen Hemminger | 9cf6374 | 2007-04-09 12:57:54 -0700 | [diff] [blame] | 337 | return -EPERM; |
| 338 | |
| 339 | br_fdb_flush(br); |
| 340 | return len; |
| 341 | } |
| 342 | static DEVICE_ATTR(flush, S_IWUSR, NULL, store_flush); |
Stephen Hemminger | fda93d9 | 2006-03-20 22:59:21 -0800 | [diff] [blame] | 343 | |
Herbert Xu | 0909e11 | 2010-02-27 19:41:49 +0000 | [diff] [blame] | 344 | #ifdef CONFIG_BRIDGE_IGMP_SNOOPING |
| 345 | static ssize_t show_multicast_router(struct device *d, |
| 346 | struct device_attribute *attr, char *buf) |
| 347 | { |
| 348 | struct net_bridge *br = to_bridge(d); |
| 349 | return sprintf(buf, "%d\n", br->multicast_router); |
| 350 | } |
| 351 | |
| 352 | static ssize_t store_multicast_router(struct device *d, |
| 353 | struct device_attribute *attr, |
| 354 | const char *buf, size_t len) |
| 355 | { |
| 356 | return store_bridge_parm(d, buf, len, br_multicast_set_router); |
| 357 | } |
| 358 | static DEVICE_ATTR(multicast_router, S_IRUGO | S_IWUSR, show_multicast_router, |
| 359 | store_multicast_router); |
Herbert Xu | 561f110 | 2010-02-27 19:41:50 +0000 | [diff] [blame] | 360 | |
| 361 | static ssize_t show_multicast_snooping(struct device *d, |
| 362 | struct device_attribute *attr, |
| 363 | char *buf) |
| 364 | { |
| 365 | struct net_bridge *br = to_bridge(d); |
| 366 | return sprintf(buf, "%d\n", !br->multicast_disabled); |
| 367 | } |
| 368 | |
| 369 | static ssize_t store_multicast_snooping(struct device *d, |
| 370 | struct device_attribute *attr, |
| 371 | const char *buf, size_t len) |
| 372 | { |
| 373 | return store_bridge_parm(d, buf, len, br_multicast_toggle); |
| 374 | } |
| 375 | static DEVICE_ATTR(multicast_snooping, S_IRUGO | S_IWUSR, |
| 376 | show_multicast_snooping, store_multicast_snooping); |
Herbert Xu | b195167 | 2010-02-27 19:41:51 +0000 | [diff] [blame] | 377 | |
Cong Wang | 1c8ad5b | 2013-05-21 21:52:54 +0000 | [diff] [blame] | 378 | static ssize_t show_multicast_query_use_ifaddr(struct device *d, |
| 379 | struct device_attribute *attr, |
| 380 | char *buf) |
| 381 | { |
| 382 | struct net_bridge *br = to_bridge(d); |
| 383 | return sprintf(buf, "%d\n", br->multicast_query_use_ifaddr); |
| 384 | } |
| 385 | |
| 386 | static int set_query_use_ifaddr(struct net_bridge *br, unsigned long val) |
| 387 | { |
| 388 | br->multicast_query_use_ifaddr = !!val; |
| 389 | return 0; |
| 390 | } |
| 391 | |
| 392 | static ssize_t |
| 393 | store_multicast_query_use_ifaddr(struct device *d, |
| 394 | struct device_attribute *attr, |
| 395 | const char *buf, size_t len) |
| 396 | { |
| 397 | return store_bridge_parm(d, buf, len, set_query_use_ifaddr); |
| 398 | } |
| 399 | static DEVICE_ATTR(multicast_query_use_ifaddr, S_IRUGO | S_IWUSR, |
| 400 | show_multicast_query_use_ifaddr, |
| 401 | store_multicast_query_use_ifaddr); |
| 402 | |
Herbert Xu | c5c2326 | 2012-04-13 02:37:42 +0000 | [diff] [blame] | 403 | static ssize_t show_multicast_querier(struct device *d, |
| 404 | struct device_attribute *attr, |
| 405 | char *buf) |
| 406 | { |
| 407 | struct net_bridge *br = to_bridge(d); |
| 408 | return sprintf(buf, "%d\n", br->multicast_querier); |
| 409 | } |
| 410 | |
| 411 | static ssize_t store_multicast_querier(struct device *d, |
| 412 | struct device_attribute *attr, |
| 413 | const char *buf, size_t len) |
| 414 | { |
| 415 | return store_bridge_parm(d, buf, len, br_multicast_set_querier); |
| 416 | } |
| 417 | static DEVICE_ATTR(multicast_querier, S_IRUGO | S_IWUSR, |
| 418 | show_multicast_querier, store_multicast_querier); |
| 419 | |
Herbert Xu | b195167 | 2010-02-27 19:41:51 +0000 | [diff] [blame] | 420 | static ssize_t show_hash_elasticity(struct device *d, |
| 421 | struct device_attribute *attr, char *buf) |
| 422 | { |
| 423 | struct net_bridge *br = to_bridge(d); |
| 424 | return sprintf(buf, "%u\n", br->hash_elasticity); |
| 425 | } |
| 426 | |
| 427 | static int set_elasticity(struct net_bridge *br, unsigned long val) |
| 428 | { |
| 429 | br->hash_elasticity = val; |
| 430 | return 0; |
| 431 | } |
| 432 | |
| 433 | static ssize_t store_hash_elasticity(struct device *d, |
| 434 | struct device_attribute *attr, |
| 435 | const char *buf, size_t len) |
| 436 | { |
| 437 | return store_bridge_parm(d, buf, len, set_elasticity); |
| 438 | } |
| 439 | static DEVICE_ATTR(hash_elasticity, S_IRUGO | S_IWUSR, show_hash_elasticity, |
| 440 | store_hash_elasticity); |
| 441 | |
| 442 | static ssize_t show_hash_max(struct device *d, struct device_attribute *attr, |
| 443 | char *buf) |
| 444 | { |
| 445 | struct net_bridge *br = to_bridge(d); |
| 446 | return sprintf(buf, "%u\n", br->hash_max); |
| 447 | } |
| 448 | |
| 449 | static ssize_t store_hash_max(struct device *d, struct device_attribute *attr, |
| 450 | const char *buf, size_t len) |
| 451 | { |
| 452 | return store_bridge_parm(d, buf, len, br_multicast_set_hash_max); |
| 453 | } |
| 454 | static DEVICE_ATTR(hash_max, S_IRUGO | S_IWUSR, show_hash_max, |
| 455 | store_hash_max); |
Herbert Xu | d902eee | 2010-02-27 19:41:52 +0000 | [diff] [blame] | 456 | |
| 457 | static ssize_t show_multicast_last_member_count(struct device *d, |
| 458 | struct device_attribute *attr, |
| 459 | char *buf) |
| 460 | { |
| 461 | struct net_bridge *br = to_bridge(d); |
| 462 | return sprintf(buf, "%u\n", br->multicast_last_member_count); |
| 463 | } |
| 464 | |
| 465 | static int set_last_member_count(struct net_bridge *br, unsigned long val) |
| 466 | { |
| 467 | br->multicast_last_member_count = val; |
| 468 | return 0; |
| 469 | } |
| 470 | |
| 471 | static ssize_t store_multicast_last_member_count(struct device *d, |
| 472 | struct device_attribute *attr, |
| 473 | const char *buf, size_t len) |
| 474 | { |
| 475 | return store_bridge_parm(d, buf, len, set_last_member_count); |
| 476 | } |
| 477 | static DEVICE_ATTR(multicast_last_member_count, S_IRUGO | S_IWUSR, |
| 478 | show_multicast_last_member_count, |
| 479 | store_multicast_last_member_count); |
| 480 | |
| 481 | static ssize_t show_multicast_startup_query_count( |
| 482 | struct device *d, struct device_attribute *attr, char *buf) |
| 483 | { |
| 484 | struct net_bridge *br = to_bridge(d); |
| 485 | return sprintf(buf, "%u\n", br->multicast_startup_query_count); |
| 486 | } |
| 487 | |
| 488 | static int set_startup_query_count(struct net_bridge *br, unsigned long val) |
| 489 | { |
| 490 | br->multicast_startup_query_count = val; |
| 491 | return 0; |
| 492 | } |
| 493 | |
| 494 | static ssize_t store_multicast_startup_query_count( |
| 495 | struct device *d, struct device_attribute *attr, const char *buf, |
| 496 | size_t len) |
| 497 | { |
| 498 | return store_bridge_parm(d, buf, len, set_startup_query_count); |
| 499 | } |
| 500 | static DEVICE_ATTR(multicast_startup_query_count, S_IRUGO | S_IWUSR, |
| 501 | show_multicast_startup_query_count, |
| 502 | store_multicast_startup_query_count); |
| 503 | |
| 504 | static ssize_t show_multicast_last_member_interval( |
| 505 | struct device *d, struct device_attribute *attr, char *buf) |
| 506 | { |
| 507 | struct net_bridge *br = to_bridge(d); |
| 508 | return sprintf(buf, "%lu\n", |
| 509 | jiffies_to_clock_t(br->multicast_last_member_interval)); |
| 510 | } |
| 511 | |
| 512 | static int set_last_member_interval(struct net_bridge *br, unsigned long val) |
| 513 | { |
| 514 | br->multicast_last_member_interval = clock_t_to_jiffies(val); |
| 515 | return 0; |
| 516 | } |
| 517 | |
| 518 | static ssize_t store_multicast_last_member_interval( |
| 519 | struct device *d, struct device_attribute *attr, const char *buf, |
| 520 | size_t len) |
| 521 | { |
| 522 | return store_bridge_parm(d, buf, len, set_last_member_interval); |
| 523 | } |
| 524 | static DEVICE_ATTR(multicast_last_member_interval, S_IRUGO | S_IWUSR, |
| 525 | show_multicast_last_member_interval, |
| 526 | store_multicast_last_member_interval); |
| 527 | |
| 528 | static ssize_t show_multicast_membership_interval( |
| 529 | struct device *d, struct device_attribute *attr, char *buf) |
| 530 | { |
| 531 | struct net_bridge *br = to_bridge(d); |
| 532 | return sprintf(buf, "%lu\n", |
| 533 | jiffies_to_clock_t(br->multicast_membership_interval)); |
| 534 | } |
| 535 | |
| 536 | static int set_membership_interval(struct net_bridge *br, unsigned long val) |
| 537 | { |
| 538 | br->multicast_membership_interval = clock_t_to_jiffies(val); |
| 539 | return 0; |
| 540 | } |
| 541 | |
| 542 | static ssize_t store_multicast_membership_interval( |
| 543 | struct device *d, struct device_attribute *attr, const char *buf, |
| 544 | size_t len) |
| 545 | { |
| 546 | return store_bridge_parm(d, buf, len, set_membership_interval); |
| 547 | } |
| 548 | static DEVICE_ATTR(multicast_membership_interval, S_IRUGO | S_IWUSR, |
| 549 | show_multicast_membership_interval, |
| 550 | store_multicast_membership_interval); |
| 551 | |
| 552 | static ssize_t show_multicast_querier_interval(struct device *d, |
| 553 | struct device_attribute *attr, |
| 554 | char *buf) |
| 555 | { |
| 556 | struct net_bridge *br = to_bridge(d); |
| 557 | return sprintf(buf, "%lu\n", |
| 558 | jiffies_to_clock_t(br->multicast_querier_interval)); |
| 559 | } |
| 560 | |
| 561 | static int set_querier_interval(struct net_bridge *br, unsigned long val) |
| 562 | { |
| 563 | br->multicast_querier_interval = clock_t_to_jiffies(val); |
| 564 | return 0; |
| 565 | } |
| 566 | |
| 567 | static ssize_t store_multicast_querier_interval(struct device *d, |
| 568 | struct device_attribute *attr, |
| 569 | const char *buf, size_t len) |
| 570 | { |
| 571 | return store_bridge_parm(d, buf, len, set_querier_interval); |
| 572 | } |
| 573 | static DEVICE_ATTR(multicast_querier_interval, S_IRUGO | S_IWUSR, |
| 574 | show_multicast_querier_interval, |
| 575 | store_multicast_querier_interval); |
| 576 | |
| 577 | static ssize_t show_multicast_query_interval(struct device *d, |
| 578 | struct device_attribute *attr, |
| 579 | char *buf) |
| 580 | { |
| 581 | struct net_bridge *br = to_bridge(d); |
| 582 | return sprintf(buf, "%lu\n", |
| 583 | jiffies_to_clock_t(br->multicast_query_interval)); |
| 584 | } |
| 585 | |
| 586 | static int set_query_interval(struct net_bridge *br, unsigned long val) |
| 587 | { |
| 588 | br->multicast_query_interval = clock_t_to_jiffies(val); |
| 589 | return 0; |
| 590 | } |
| 591 | |
| 592 | static ssize_t store_multicast_query_interval(struct device *d, |
| 593 | struct device_attribute *attr, |
| 594 | const char *buf, size_t len) |
| 595 | { |
| 596 | return store_bridge_parm(d, buf, len, set_query_interval); |
| 597 | } |
| 598 | static DEVICE_ATTR(multicast_query_interval, S_IRUGO | S_IWUSR, |
| 599 | show_multicast_query_interval, |
| 600 | store_multicast_query_interval); |
| 601 | |
| 602 | static ssize_t show_multicast_query_response_interval( |
| 603 | struct device *d, struct device_attribute *attr, char *buf) |
| 604 | { |
| 605 | struct net_bridge *br = to_bridge(d); |
| 606 | return sprintf( |
| 607 | buf, "%lu\n", |
| 608 | jiffies_to_clock_t(br->multicast_query_response_interval)); |
| 609 | } |
| 610 | |
| 611 | static int set_query_response_interval(struct net_bridge *br, unsigned long val) |
| 612 | { |
| 613 | br->multicast_query_response_interval = clock_t_to_jiffies(val); |
| 614 | return 0; |
| 615 | } |
| 616 | |
| 617 | static ssize_t store_multicast_query_response_interval( |
| 618 | struct device *d, struct device_attribute *attr, const char *buf, |
| 619 | size_t len) |
| 620 | { |
| 621 | return store_bridge_parm(d, buf, len, set_query_response_interval); |
| 622 | } |
| 623 | static DEVICE_ATTR(multicast_query_response_interval, S_IRUGO | S_IWUSR, |
| 624 | show_multicast_query_response_interval, |
| 625 | store_multicast_query_response_interval); |
| 626 | |
| 627 | static ssize_t show_multicast_startup_query_interval( |
| 628 | struct device *d, struct device_attribute *attr, char *buf) |
| 629 | { |
| 630 | struct net_bridge *br = to_bridge(d); |
| 631 | return sprintf( |
| 632 | buf, "%lu\n", |
| 633 | jiffies_to_clock_t(br->multicast_startup_query_interval)); |
| 634 | } |
| 635 | |
| 636 | static int set_startup_query_interval(struct net_bridge *br, unsigned long val) |
| 637 | { |
| 638 | br->multicast_startup_query_interval = clock_t_to_jiffies(val); |
| 639 | return 0; |
| 640 | } |
| 641 | |
| 642 | static ssize_t store_multicast_startup_query_interval( |
| 643 | struct device *d, struct device_attribute *attr, const char *buf, |
| 644 | size_t len) |
| 645 | { |
| 646 | return store_bridge_parm(d, buf, len, set_startup_query_interval); |
| 647 | } |
| 648 | static DEVICE_ATTR(multicast_startup_query_interval, S_IRUGO | S_IWUSR, |
| 649 | show_multicast_startup_query_interval, |
| 650 | store_multicast_startup_query_interval); |
Herbert Xu | 0909e11 | 2010-02-27 19:41:49 +0000 | [diff] [blame] | 651 | #endif |
Patrick McHardy | 4df53d8 | 2010-07-02 09:32:57 +0200 | [diff] [blame] | 652 | #ifdef CONFIG_BRIDGE_NETFILTER |
| 653 | static ssize_t show_nf_call_iptables( |
| 654 | struct device *d, struct device_attribute *attr, char *buf) |
| 655 | { |
| 656 | struct net_bridge *br = to_bridge(d); |
| 657 | return sprintf(buf, "%u\n", br->nf_call_iptables); |
| 658 | } |
| 659 | |
| 660 | static int set_nf_call_iptables(struct net_bridge *br, unsigned long val) |
| 661 | { |
| 662 | br->nf_call_iptables = val ? true : false; |
| 663 | return 0; |
| 664 | } |
| 665 | |
| 666 | static ssize_t store_nf_call_iptables( |
| 667 | struct device *d, struct device_attribute *attr, const char *buf, |
| 668 | size_t len) |
| 669 | { |
| 670 | return store_bridge_parm(d, buf, len, set_nf_call_iptables); |
| 671 | } |
| 672 | static DEVICE_ATTR(nf_call_iptables, S_IRUGO | S_IWUSR, |
| 673 | show_nf_call_iptables, store_nf_call_iptables); |
| 674 | |
| 675 | static ssize_t show_nf_call_ip6tables( |
| 676 | struct device *d, struct device_attribute *attr, char *buf) |
| 677 | { |
| 678 | struct net_bridge *br = to_bridge(d); |
| 679 | return sprintf(buf, "%u\n", br->nf_call_ip6tables); |
| 680 | } |
| 681 | |
| 682 | static int set_nf_call_ip6tables(struct net_bridge *br, unsigned long val) |
| 683 | { |
| 684 | br->nf_call_ip6tables = val ? true : false; |
| 685 | return 0; |
| 686 | } |
| 687 | |
| 688 | static ssize_t store_nf_call_ip6tables( |
| 689 | struct device *d, struct device_attribute *attr, const char *buf, |
| 690 | size_t len) |
| 691 | { |
| 692 | return store_bridge_parm(d, buf, len, set_nf_call_ip6tables); |
| 693 | } |
| 694 | static DEVICE_ATTR(nf_call_ip6tables, S_IRUGO | S_IWUSR, |
| 695 | show_nf_call_ip6tables, store_nf_call_ip6tables); |
| 696 | |
| 697 | static ssize_t show_nf_call_arptables( |
| 698 | struct device *d, struct device_attribute *attr, char *buf) |
| 699 | { |
| 700 | struct net_bridge *br = to_bridge(d); |
| 701 | return sprintf(buf, "%u\n", br->nf_call_arptables); |
| 702 | } |
| 703 | |
| 704 | static int set_nf_call_arptables(struct net_bridge *br, unsigned long val) |
| 705 | { |
| 706 | br->nf_call_arptables = val ? true : false; |
| 707 | return 0; |
| 708 | } |
| 709 | |
| 710 | static ssize_t store_nf_call_arptables( |
| 711 | struct device *d, struct device_attribute *attr, const char *buf, |
| 712 | size_t len) |
| 713 | { |
| 714 | return store_bridge_parm(d, buf, len, set_nf_call_arptables); |
| 715 | } |
| 716 | static DEVICE_ATTR(nf_call_arptables, S_IRUGO | S_IWUSR, |
| 717 | show_nf_call_arptables, store_nf_call_arptables); |
| 718 | #endif |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 719 | #ifdef CONFIG_BRIDGE_VLAN_FILTERING |
| 720 | static ssize_t show_vlan_filtering(struct device *d, |
| 721 | struct device_attribute *attr, |
| 722 | char *buf) |
| 723 | { |
| 724 | struct net_bridge *br = to_bridge(d); |
| 725 | return sprintf(buf, "%d\n", br->vlan_enabled); |
| 726 | } |
| 727 | |
| 728 | static ssize_t store_vlan_filtering(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_filter_toggle); |
| 733 | } |
| 734 | static DEVICE_ATTR(vlan_filtering, S_IRUGO | S_IWUSR, |
| 735 | show_vlan_filtering, store_vlan_filtering); |
| 736 | #endif |
Herbert Xu | 0909e11 | 2010-02-27 19:41:49 +0000 | [diff] [blame] | 737 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | static struct attribute *bridge_attrs[] = { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 739 | &dev_attr_forward_delay.attr, |
| 740 | &dev_attr_hello_time.attr, |
| 741 | &dev_attr_max_age.attr, |
| 742 | &dev_attr_ageing_time.attr, |
| 743 | &dev_attr_stp_state.attr, |
stephen hemminger | 515853c | 2011-10-03 18:14:46 +0000 | [diff] [blame] | 744 | &dev_attr_group_fwd_mask.attr, |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 745 | &dev_attr_priority.attr, |
| 746 | &dev_attr_bridge_id.attr, |
| 747 | &dev_attr_root_id.attr, |
| 748 | &dev_attr_root_path_cost.attr, |
| 749 | &dev_attr_root_port.attr, |
| 750 | &dev_attr_topology_change.attr, |
| 751 | &dev_attr_topology_change_detected.attr, |
| 752 | &dev_attr_hello_timer.attr, |
| 753 | &dev_attr_tcn_timer.attr, |
| 754 | &dev_attr_topology_change_timer.attr, |
| 755 | &dev_attr_gc_timer.attr, |
| 756 | &dev_attr_group_addr.attr, |
Stephen Hemminger | 9cf6374 | 2007-04-09 12:57:54 -0700 | [diff] [blame] | 757 | &dev_attr_flush.attr, |
Herbert Xu | 0909e11 | 2010-02-27 19:41:49 +0000 | [diff] [blame] | 758 | #ifdef CONFIG_BRIDGE_IGMP_SNOOPING |
| 759 | &dev_attr_multicast_router.attr, |
Herbert Xu | 561f110 | 2010-02-27 19:41:50 +0000 | [diff] [blame] | 760 | &dev_attr_multicast_snooping.attr, |
Herbert Xu | c5c2326 | 2012-04-13 02:37:42 +0000 | [diff] [blame] | 761 | &dev_attr_multicast_querier.attr, |
Cong Wang | 1c8ad5b | 2013-05-21 21:52:54 +0000 | [diff] [blame] | 762 | &dev_attr_multicast_query_use_ifaddr.attr, |
Herbert Xu | b195167 | 2010-02-27 19:41:51 +0000 | [diff] [blame] | 763 | &dev_attr_hash_elasticity.attr, |
| 764 | &dev_attr_hash_max.attr, |
Herbert Xu | d902eee | 2010-02-27 19:41:52 +0000 | [diff] [blame] | 765 | &dev_attr_multicast_last_member_count.attr, |
| 766 | &dev_attr_multicast_startup_query_count.attr, |
| 767 | &dev_attr_multicast_last_member_interval.attr, |
| 768 | &dev_attr_multicast_membership_interval.attr, |
| 769 | &dev_attr_multicast_querier_interval.attr, |
| 770 | &dev_attr_multicast_query_interval.attr, |
| 771 | &dev_attr_multicast_query_response_interval.attr, |
| 772 | &dev_attr_multicast_startup_query_interval.attr, |
Herbert Xu | 0909e11 | 2010-02-27 19:41:49 +0000 | [diff] [blame] | 773 | #endif |
Patrick McHardy | 4df53d8 | 2010-07-02 09:32:57 +0200 | [diff] [blame] | 774 | #ifdef CONFIG_BRIDGE_NETFILTER |
| 775 | &dev_attr_nf_call_iptables.attr, |
| 776 | &dev_attr_nf_call_ip6tables.attr, |
| 777 | &dev_attr_nf_call_arptables.attr, |
| 778 | #endif |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 779 | #ifdef CONFIG_BRIDGE_VLAN_FILTERING |
| 780 | &dev_attr_vlan_filtering.attr, |
| 781 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 | NULL |
| 783 | }; |
| 784 | |
| 785 | static struct attribute_group bridge_group = { |
| 786 | .name = SYSFS_BRIDGE_ATTR, |
| 787 | .attrs = bridge_attrs, |
| 788 | }; |
| 789 | |
| 790 | /* |
| 791 | * Export the forwarding information table as a binary file |
| 792 | * The records are struct __fdb_entry. |
| 793 | * |
| 794 | * Returns the number of bytes read. |
| 795 | */ |
Chris Wright | 2c3c8be | 2010-05-12 18:28:57 -0700 | [diff] [blame] | 796 | static ssize_t brforward_read(struct file *filp, struct kobject *kobj, |
Zhang Rui | 91a6902 | 2007-06-09 13:57:22 +0800 | [diff] [blame] | 797 | struct bin_attribute *bin_attr, |
| 798 | char *buf, loff_t off, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 800 | struct device *dev = to_dev(kobj); |
| 801 | struct net_bridge *br = to_bridge(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 802 | int n; |
| 803 | |
| 804 | /* must read whole records */ |
| 805 | if (off % sizeof(struct __fdb_entry) != 0) |
| 806 | return -EINVAL; |
| 807 | |
YOSHIFUJI Hideaki | 9d6f229 | 2007-02-09 23:24:35 +0900 | [diff] [blame] | 808 | n = br_fdb_fillbuf(br, buf, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | count / sizeof(struct __fdb_entry), |
| 810 | off / sizeof(struct __fdb_entry)); |
| 811 | |
| 812 | if (n > 0) |
| 813 | n *= sizeof(struct __fdb_entry); |
YOSHIFUJI Hideaki | 9d6f229 | 2007-02-09 23:24:35 +0900 | [diff] [blame] | 814 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | return n; |
| 816 | } |
| 817 | |
| 818 | static struct bin_attribute bridge_forward = { |
| 819 | .attr = { .name = SYSFS_BRIDGE_FDB, |
Tejun Heo | 7b59575 | 2007-06-14 03:45:17 +0900 | [diff] [blame] | 820 | .mode = S_IRUGO, }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | .read = brforward_read, |
| 822 | }; |
| 823 | |
| 824 | /* |
| 825 | * Add entries in sysfs onto the existing network class device |
| 826 | * for the bridge. |
| 827 | * Adds a attribute group "bridge" containing tuning parameters. |
| 828 | * Binary attribute containing the forward table |
| 829 | * Sub directory to hold links to interfaces. |
| 830 | * |
| 831 | * Note: the ifobj exists only to be a subdirectory |
| 832 | * to hold links. The ifobj exists in same data structure |
| 833 | * as it's parent the bridge so reference counting works. |
| 834 | */ |
| 835 | int br_sysfs_addbr(struct net_device *dev) |
| 836 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 837 | struct kobject *brobj = &dev->dev.kobj; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 838 | struct net_bridge *br = netdev_priv(dev); |
| 839 | int err; |
| 840 | |
| 841 | err = sysfs_create_group(brobj, &bridge_group); |
| 842 | if (err) { |
| 843 | pr_info("%s: can't create group %s/%s\n", |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 844 | __func__, dev->name, bridge_group.name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 845 | goto out1; |
| 846 | } |
| 847 | |
| 848 | err = sysfs_create_bin_file(brobj, &bridge_forward); |
| 849 | if (err) { |
Randy Dunlap | 1842c4b | 2006-10-25 23:07:37 -0700 | [diff] [blame] | 850 | pr_info("%s: can't create attribute file %s/%s\n", |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 851 | __func__, dev->name, bridge_forward.attr.name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 852 | goto out2; |
| 853 | } |
| 854 | |
Greg Kroah-Hartman | 43b98c4 | 2007-12-17 15:54:39 -0400 | [diff] [blame] | 855 | br->ifobj = kobject_create_and_add(SYSFS_BRIDGE_PORT_SUBDIR, brobj); |
| 856 | if (!br->ifobj) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 857 | pr_info("%s: can't add kobject (directory) %s/%s\n", |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 858 | __func__, dev->name, SYSFS_BRIDGE_PORT_SUBDIR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 859 | goto out3; |
| 860 | } |
| 861 | return 0; |
| 862 | out3: |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 863 | sysfs_remove_bin_file(&dev->dev.kobj, &bridge_forward); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 | out2: |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 865 | sysfs_remove_group(&dev->dev.kobj, &bridge_group); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 866 | out1: |
| 867 | return err; |
| 868 | |
| 869 | } |
| 870 | |
| 871 | void br_sysfs_delbr(struct net_device *dev) |
| 872 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 873 | struct kobject *kobj = &dev->dev.kobj; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 874 | struct net_bridge *br = netdev_priv(dev); |
| 875 | |
Greg Kroah-Hartman | 78a2d90 | 2007-12-20 08:13:05 -0800 | [diff] [blame] | 876 | kobject_put(br->ifobj); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 877 | sysfs_remove_bin_file(kobj, &bridge_forward); |
| 878 | sysfs_remove_group(kobj, &bridge_group); |
| 879 | } |