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