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