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