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