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