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