Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright(c) 2004-2005 Intel Corporation. All rights reserved. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify it |
| 5 | * under the terms of the GNU General Public License as published by the |
| 6 | * Free Software Foundation; either version 2 of the License, or |
| 7 | * (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, but |
| 10 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 11 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 | * for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License along |
Jeff Kirsher | adf8d3f | 2013-12-06 06:28:47 -0800 | [diff] [blame] | 15 | * with this program; if not, see <http://www.gnu.org/licenses/>. |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 16 | * |
| 17 | * The full GNU General Public License is included in this distribution in the |
| 18 | * file called LICENSE. |
| 19 | * |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 20 | */ |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 21 | |
| 22 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 23 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 24 | #include <linux/kernel.h> |
| 25 | #include <linux/module.h> |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 26 | #include <linux/device.h> |
Alexey Dobriyan | d43c36d | 2009-10-07 17:09:06 +0400 | [diff] [blame] | 27 | #include <linux/sched.h> |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 28 | #include <linux/fs.h> |
| 29 | #include <linux/types.h> |
| 30 | #include <linux/string.h> |
| 31 | #include <linux/netdevice.h> |
| 32 | #include <linux/inetdevice.h> |
| 33 | #include <linux/in.h> |
| 34 | #include <linux/sysfs.h> |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 35 | #include <linux/ctype.h> |
| 36 | #include <linux/inet.h> |
| 37 | #include <linux/rtnetlink.h> |
Stephen Hemminger | 5c5129b | 2009-06-12 19:02:51 +0000 | [diff] [blame] | 38 | #include <linux/etherdevice.h> |
Eric W. Biederman | 881d966 | 2007-09-17 11:56:21 -0700 | [diff] [blame] | 39 | #include <net/net_namespace.h> |
Eric W. Biederman | ec87fd3 | 2009-10-29 14:18:26 +0000 | [diff] [blame] | 40 | #include <net/netns/generic.h> |
| 41 | #include <linux/nsproxy.h> |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 42 | |
David S. Miller | 1ef8019 | 2014-11-10 13:27:49 -0500 | [diff] [blame] | 43 | #include <net/bonding.h> |
Holger Eitzenberger | 5a03cdb | 2008-12-09 23:09:22 -0800 | [diff] [blame] | 44 | |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 45 | #define to_bond(cd) ((struct bonding *)(netdev_priv(to_net_dev(cd)))) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 46 | |
Nikolay Aleksandrov | dc3e5d1 | 2014-05-08 14:23:54 +0200 | [diff] [blame] | 47 | /* "show" function for the bond_masters attribute. |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 48 | * The class parameter is ignored. |
| 49 | */ |
Andi Kleen | 28812fe | 2010-01-05 12:48:07 +0100 | [diff] [blame] | 50 | static ssize_t bonding_show_bonds(struct class *cls, |
| 51 | struct class_attribute *attr, |
| 52 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 53 | { |
Eric W. Biederman | 4c22400 | 2011-10-12 21:56:25 +0000 | [diff] [blame] | 54 | struct bond_net *bn = |
| 55 | container_of(attr, struct bond_net, class_attr_bonding_masters); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 56 | int res = 0; |
| 57 | struct bonding *bond; |
| 58 | |
Stephen Hemminger | 7e08384 | 2009-06-12 19:02:46 +0000 | [diff] [blame] | 59 | rtnl_lock(); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 60 | |
Eric W. Biederman | ec87fd3 | 2009-10-29 14:18:26 +0000 | [diff] [blame] | 61 | list_for_each_entry(bond, &bn->dev_list, bond_list) { |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 62 | if (res > (PAGE_SIZE - IFNAMSIZ)) { |
| 63 | /* not enough space for another interface name */ |
| 64 | if ((PAGE_SIZE - res) > 10) |
| 65 | res = PAGE_SIZE - 10; |
Wagner Ferenc | b884366 | 2007-12-06 23:40:30 -0800 | [diff] [blame] | 66 | res += sprintf(buf + res, "++more++ "); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 67 | break; |
| 68 | } |
Wagner Ferenc | b884366 | 2007-12-06 23:40:30 -0800 | [diff] [blame] | 69 | res += sprintf(buf + res, "%s ", bond->dev->name); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 70 | } |
Wagner Ferenc | 1dcdcd6 | 2007-12-06 23:40:31 -0800 | [diff] [blame] | 71 | if (res) |
| 72 | buf[res-1] = '\n'; /* eat the leftover space */ |
Stephen Hemminger | 7e08384 | 2009-06-12 19:02:46 +0000 | [diff] [blame] | 73 | |
| 74 | rtnl_unlock(); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 75 | return res; |
| 76 | } |
| 77 | |
Eric W. Biederman | 4c22400 | 2011-10-12 21:56:25 +0000 | [diff] [blame] | 78 | static struct net_device *bond_get_by_name(struct bond_net *bn, const char *ifname) |
Stephen Hemminger | 373500d | 2009-06-12 19:02:50 +0000 | [diff] [blame] | 79 | { |
| 80 | struct bonding *bond; |
| 81 | |
Eric W. Biederman | ec87fd3 | 2009-10-29 14:18:26 +0000 | [diff] [blame] | 82 | list_for_each_entry(bond, &bn->dev_list, bond_list) { |
Stephen Hemminger | 373500d | 2009-06-12 19:02:50 +0000 | [diff] [blame] | 83 | if (strncmp(bond->dev->name, ifname, IFNAMSIZ) == 0) |
| 84 | return bond->dev; |
| 85 | } |
| 86 | return NULL; |
| 87 | } |
| 88 | |
Nikolay Aleksandrov | dc3e5d1 | 2014-05-08 14:23:54 +0200 | [diff] [blame] | 89 | /* "store" function for the bond_masters attribute. This is what |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 90 | * creates and deletes entire bonds. |
| 91 | * |
| 92 | * The class parameter is ignored. |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 93 | */ |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 94 | static ssize_t bonding_store_bonds(struct class *cls, |
Andi Kleen | 28812fe | 2010-01-05 12:48:07 +0100 | [diff] [blame] | 95 | struct class_attribute *attr, |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 96 | const char *buffer, size_t count) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 97 | { |
Eric W. Biederman | 4c22400 | 2011-10-12 21:56:25 +0000 | [diff] [blame] | 98 | struct bond_net *bn = |
| 99 | container_of(attr, struct bond_net, class_attr_bonding_masters); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 100 | char command[IFNAMSIZ + 1] = {0, }; |
| 101 | char *ifname; |
Jay Vosburgh | 027ea04 | 2008-01-17 16:25:02 -0800 | [diff] [blame] | 102 | int rv, res = count; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 103 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 104 | sscanf(buffer, "%16s", command); /* IFNAMSIZ*/ |
| 105 | ifname = command + 1; |
| 106 | if ((strlen(command) <= 1) || |
| 107 | !dev_valid_name(ifname)) |
| 108 | goto err_no_cmd; |
| 109 | |
| 110 | if (command[0] == '+') { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 111 | pr_info("%s is being created...\n", ifname); |
Eric W. Biederman | 4c22400 | 2011-10-12 21:56:25 +0000 | [diff] [blame] | 112 | rv = bond_create(bn->net, ifname); |
Jay Vosburgh | 027ea04 | 2008-01-17 16:25:02 -0800 | [diff] [blame] | 113 | if (rv) { |
Phil Oester | 5f86cad1 | 2011-03-14 06:22:06 +0000 | [diff] [blame] | 114 | if (rv == -EEXIST) |
Joe Perches | 9019426 | 2014-02-15 16:01:45 -0800 | [diff] [blame] | 115 | pr_info("%s already exists\n", ifname); |
Phil Oester | 5f86cad1 | 2011-03-14 06:22:06 +0000 | [diff] [blame] | 116 | else |
Joe Perches | 9019426 | 2014-02-15 16:01:45 -0800 | [diff] [blame] | 117 | pr_info("%s creation failed\n", ifname); |
Jay Vosburgh | 027ea04 | 2008-01-17 16:25:02 -0800 | [diff] [blame] | 118 | res = rv; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 119 | } |
Stephen Hemminger | 373500d | 2009-06-12 19:02:50 +0000 | [diff] [blame] | 120 | } else if (command[0] == '-') { |
| 121 | struct net_device *bond_dev; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 122 | |
Jay Vosburgh | 027ea04 | 2008-01-17 16:25:02 -0800 | [diff] [blame] | 123 | rtnl_lock(); |
Eric W. Biederman | 4c22400 | 2011-10-12 21:56:25 +0000 | [diff] [blame] | 124 | bond_dev = bond_get_by_name(bn, ifname); |
Stephen Hemminger | 373500d | 2009-06-12 19:02:50 +0000 | [diff] [blame] | 125 | if (bond_dev) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 126 | pr_info("%s is being deleted...\n", ifname); |
Stephen Hemminger | 373500d | 2009-06-12 19:02:50 +0000 | [diff] [blame] | 127 | unregister_netdevice(bond_dev); |
| 128 | } else { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 129 | pr_err("unable to delete non-existent %s\n", ifname); |
Stephen Hemminger | 373500d | 2009-06-12 19:02:50 +0000 | [diff] [blame] | 130 | res = -ENODEV; |
| 131 | } |
| 132 | rtnl_unlock(); |
| 133 | } else |
| 134 | goto err_no_cmd; |
Jay Vosburgh | 027ea04 | 2008-01-17 16:25:02 -0800 | [diff] [blame] | 135 | |
Stephen Hemminger | 373500d | 2009-06-12 19:02:50 +0000 | [diff] [blame] | 136 | /* Always return either count or an error. If you return 0, you'll |
| 137 | * get called forever, which is bad. |
| 138 | */ |
| 139 | return res; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 140 | |
| 141 | err_no_cmd: |
Joe Perches | 9019426 | 2014-02-15 16:01:45 -0800 | [diff] [blame] | 142 | pr_err("no command found in bonding_masters - use +ifname or -ifname\n"); |
Jay Vosburgh | c4ebc66 | 2008-05-02 17:49:38 -0700 | [diff] [blame] | 143 | return -EPERM; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 144 | } |
Stephen Hemminger | 373500d | 2009-06-12 19:02:50 +0000 | [diff] [blame] | 145 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 146 | /* class attribute for bond_masters file. This ends up in /sys/class/net */ |
Eric W. Biederman | 4c22400 | 2011-10-12 21:56:25 +0000 | [diff] [blame] | 147 | static const struct class_attribute class_attr_bonding_masters = { |
| 148 | .attr = { |
| 149 | .name = "bonding_masters", |
| 150 | .mode = S_IWUSR | S_IRUGO, |
| 151 | }, |
| 152 | .show = bonding_show_bonds, |
| 153 | .store = bonding_store_bonds, |
Eric W. Biederman | 4c22400 | 2011-10-12 21:56:25 +0000 | [diff] [blame] | 154 | }; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 155 | |
Nikolay Aleksandrov | dc3e5d1 | 2014-05-08 14:23:54 +0200 | [diff] [blame] | 156 | /* Generic "store" method for bonding sysfs option setting */ |
| 157 | static ssize_t bonding_sysfs_store_option(struct device *d, |
| 158 | struct device_attribute *attr, |
| 159 | const char *buffer, size_t count) |
| 160 | { |
| 161 | struct bonding *bond = to_bond(d); |
| 162 | const struct bond_option *opt; |
| 163 | int ret; |
| 164 | |
| 165 | opt = bond_opt_get_by_name(attr->attr.name); |
| 166 | if (WARN_ON(!opt)) |
| 167 | return -ENOENT; |
| 168 | ret = bond_opt_tryset_rtnl(bond, opt->id, (char *)buffer); |
| 169 | if (!ret) |
| 170 | ret = count; |
| 171 | |
| 172 | return ret; |
| 173 | } |
| 174 | |
| 175 | /* Show the slaves in the current bond. */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 176 | static ssize_t bonding_show_slaves(struct device *d, |
| 177 | struct device_attribute *attr, char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 178 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 179 | struct bonding *bond = to_bond(d); |
Veaceslav Falico | 9caff1e7 | 2013-09-25 09:20:14 +0200 | [diff] [blame] | 180 | struct list_head *iter; |
nikolay@redhat.com | dec1e90 | 2013-08-01 16:54:47 +0200 | [diff] [blame] | 181 | struct slave *slave; |
| 182 | int res = 0; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 183 | |
dingtianhong | 4d1ae5f | 2013-10-15 16:28:42 +0800 | [diff] [blame] | 184 | if (!rtnl_trylock()) |
| 185 | return restart_syscall(); |
| 186 | |
Veaceslav Falico | 9caff1e7 | 2013-09-25 09:20:14 +0200 | [diff] [blame] | 187 | bond_for_each_slave(bond, slave, iter) { |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 188 | if (res > (PAGE_SIZE - IFNAMSIZ)) { |
| 189 | /* not enough space for another interface name */ |
| 190 | if ((PAGE_SIZE - res) > 10) |
| 191 | res = PAGE_SIZE - 10; |
Wagner Ferenc | 7bd4650 | 2007-12-06 23:40:28 -0800 | [diff] [blame] | 192 | res += sprintf(buf + res, "++more++ "); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 193 | break; |
| 194 | } |
| 195 | res += sprintf(buf + res, "%s ", slave->dev->name); |
| 196 | } |
dingtianhong | 4d1ae5f | 2013-10-15 16:28:42 +0800 | [diff] [blame] | 197 | |
| 198 | rtnl_unlock(); |
| 199 | |
Wagner Ferenc | 1dcdcd6 | 2007-12-06 23:40:31 -0800 | [diff] [blame] | 200 | if (res) |
| 201 | buf[res-1] = '\n'; /* eat the leftover space */ |
nikolay@redhat.com | dec1e90 | 2013-08-01 16:54:47 +0200 | [diff] [blame] | 202 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 203 | return res; |
| 204 | } |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 205 | static DEVICE_ATTR(slaves, S_IRUGO | S_IWUSR, bonding_show_slaves, |
Nikolay Aleksandrov | dc3e5d1 | 2014-05-08 14:23:54 +0200 | [diff] [blame] | 206 | bonding_sysfs_store_option); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 207 | |
Nikolay Aleksandrov | dc3e5d1 | 2014-05-08 14:23:54 +0200 | [diff] [blame] | 208 | /* Show the bonding mode. */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 209 | static ssize_t bonding_show_mode(struct device *d, |
| 210 | struct device_attribute *attr, char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 211 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 212 | struct bonding *bond = to_bond(d); |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 213 | const struct bond_opt_value *val; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 214 | |
Veaceslav Falico | 0184409 | 2014-05-15 21:39:55 +0200 | [diff] [blame] | 215 | val = bond_opt_get_val(BOND_OPT_MODE, BOND_MODE(bond)); |
Nikolay Aleksandrov | 2b3798d | 2014-01-22 14:53:17 +0100 | [diff] [blame] | 216 | |
Veaceslav Falico | 0184409 | 2014-05-15 21:39:55 +0200 | [diff] [blame] | 217 | return sprintf(buf, "%s %d\n", val->string, BOND_MODE(bond)); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 218 | } |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 219 | static DEVICE_ATTR(mode, S_IRUGO | S_IWUSR, |
Nikolay Aleksandrov | dc3e5d1 | 2014-05-08 14:23:54 +0200 | [diff] [blame] | 220 | bonding_show_mode, bonding_sysfs_store_option); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 221 | |
Nikolay Aleksandrov | dc3e5d1 | 2014-05-08 14:23:54 +0200 | [diff] [blame] | 222 | /* Show the bonding transmit hash method. */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 223 | static ssize_t bonding_show_xmit_hash(struct device *d, |
| 224 | struct device_attribute *attr, |
| 225 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 226 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 227 | struct bonding *bond = to_bond(d); |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 228 | const struct bond_opt_value *val; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 229 | |
Nikolay Aleksandrov | a4b32ce | 2014-01-22 14:53:19 +0100 | [diff] [blame] | 230 | val = bond_opt_get_val(BOND_OPT_XMIT_HASH, bond->params.xmit_policy); |
| 231 | |
| 232 | return sprintf(buf, "%s %d\n", val->string, bond->params.xmit_policy); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 233 | } |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 234 | static DEVICE_ATTR(xmit_hash_policy, S_IRUGO | S_IWUSR, |
Nikolay Aleksandrov | dc3e5d1 | 2014-05-08 14:23:54 +0200 | [diff] [blame] | 235 | bonding_show_xmit_hash, bonding_sysfs_store_option); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 236 | |
Nikolay Aleksandrov | dc3e5d1 | 2014-05-08 14:23:54 +0200 | [diff] [blame] | 237 | /* Show arp_validate. */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 238 | static ssize_t bonding_show_arp_validate(struct device *d, |
| 239 | struct device_attribute *attr, |
| 240 | char *buf) |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 241 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 242 | struct bonding *bond = to_bond(d); |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 243 | const struct bond_opt_value *val; |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 244 | |
Nikolay Aleksandrov | 1622888 | 2014-01-22 14:53:20 +0100 | [diff] [blame] | 245 | val = bond_opt_get_val(BOND_OPT_ARP_VALIDATE, |
| 246 | bond->params.arp_validate); |
| 247 | |
| 248 | return sprintf(buf, "%s %d\n", val->string, bond->params.arp_validate); |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 249 | } |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 250 | static DEVICE_ATTR(arp_validate, S_IRUGO | S_IWUSR, bonding_show_arp_validate, |
Nikolay Aleksandrov | dc3e5d1 | 2014-05-08 14:23:54 +0200 | [diff] [blame] | 251 | bonding_sysfs_store_option); |
| 252 | |
| 253 | /* Show arp_all_targets. */ |
Veaceslav Falico | 8599b52 | 2013-06-24 11:49:34 +0200 | [diff] [blame] | 254 | static ssize_t bonding_show_arp_all_targets(struct device *d, |
| 255 | struct device_attribute *attr, |
| 256 | char *buf) |
| 257 | { |
| 258 | struct bonding *bond = to_bond(d); |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 259 | const struct bond_opt_value *val; |
Veaceslav Falico | 8599b52 | 2013-06-24 11:49:34 +0200 | [diff] [blame] | 260 | |
Nikolay Aleksandrov | edf36b2 | 2014-01-22 14:53:21 +0100 | [diff] [blame] | 261 | val = bond_opt_get_val(BOND_OPT_ARP_ALL_TARGETS, |
| 262 | bond->params.arp_all_targets); |
| 263 | return sprintf(buf, "%s %d\n", |
| 264 | val->string, bond->params.arp_all_targets); |
Veaceslav Falico | 8599b52 | 2013-06-24 11:49:34 +0200 | [diff] [blame] | 265 | } |
Veaceslav Falico | 8599b52 | 2013-06-24 11:49:34 +0200 | [diff] [blame] | 266 | static DEVICE_ATTR(arp_all_targets, S_IRUGO | S_IWUSR, |
Nikolay Aleksandrov | dc3e5d1 | 2014-05-08 14:23:54 +0200 | [diff] [blame] | 267 | bonding_show_arp_all_targets, bonding_sysfs_store_option); |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 268 | |
Nikolay Aleksandrov | dc3e5d1 | 2014-05-08 14:23:54 +0200 | [diff] [blame] | 269 | /* Show fail_over_mac. */ |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 270 | static ssize_t bonding_show_fail_over_mac(struct device *d, |
| 271 | struct device_attribute *attr, |
| 272 | char *buf) |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 273 | { |
| 274 | struct bonding *bond = to_bond(d); |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 275 | const struct bond_opt_value *val; |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 276 | |
Nikolay Aleksandrov | 1df6b6a | 2014-01-22 14:53:22 +0100 | [diff] [blame] | 277 | val = bond_opt_get_val(BOND_OPT_FAIL_OVER_MAC, |
| 278 | bond->params.fail_over_mac); |
| 279 | |
| 280 | return sprintf(buf, "%s %d\n", val->string, bond->params.fail_over_mac); |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 281 | } |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 282 | static DEVICE_ATTR(fail_over_mac, S_IRUGO | S_IWUSR, |
Nikolay Aleksandrov | dc3e5d1 | 2014-05-08 14:23:54 +0200 | [diff] [blame] | 283 | bonding_show_fail_over_mac, bonding_sysfs_store_option); |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 284 | |
Nikolay Aleksandrov | dc3e5d1 | 2014-05-08 14:23:54 +0200 | [diff] [blame] | 285 | /* Show the arp timer interval. */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 286 | static ssize_t bonding_show_arp_interval(struct device *d, |
| 287 | struct device_attribute *attr, |
| 288 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 289 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 290 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 291 | |
Wagner Ferenc | 7bd4650 | 2007-12-06 23:40:28 -0800 | [diff] [blame] | 292 | return sprintf(buf, "%d\n", bond->params.arp_interval); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 293 | } |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 294 | static DEVICE_ATTR(arp_interval, S_IRUGO | S_IWUSR, |
Nikolay Aleksandrov | dc3e5d1 | 2014-05-08 14:23:54 +0200 | [diff] [blame] | 295 | bonding_show_arp_interval, bonding_sysfs_store_option); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 296 | |
Nikolay Aleksandrov | dc3e5d1 | 2014-05-08 14:23:54 +0200 | [diff] [blame] | 297 | /* Show the arp targets. */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 298 | static ssize_t bonding_show_arp_targets(struct device *d, |
| 299 | struct device_attribute *attr, |
| 300 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 301 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 302 | struct bonding *bond = to_bond(d); |
Nikolay Aleksandrov | 4fb0ef58 | 2014-01-22 14:53:24 +0100 | [diff] [blame] | 303 | int i, res = 0; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 304 | |
| 305 | for (i = 0; i < BOND_MAX_ARP_TARGETS; i++) { |
| 306 | if (bond->params.arp_targets[i]) |
Harvey Harrison | 6377943 | 2008-10-31 00:56:00 -0700 | [diff] [blame] | 307 | res += sprintf(buf + res, "%pI4 ", |
| 308 | &bond->params.arp_targets[i]); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 309 | } |
Wagner Ferenc | 1dcdcd6 | 2007-12-06 23:40:31 -0800 | [diff] [blame] | 310 | if (res) |
| 311 | buf[res-1] = '\n'; /* eat the leftover space */ |
Nikolay Aleksandrov | 4fb0ef58 | 2014-01-22 14:53:24 +0100 | [diff] [blame] | 312 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 313 | return res; |
| 314 | } |
Nikolay Aleksandrov | dc3e5d1 | 2014-05-08 14:23:54 +0200 | [diff] [blame] | 315 | static DEVICE_ATTR(arp_ip_target, S_IRUGO | S_IWUSR, |
| 316 | bonding_show_arp_targets, bonding_sysfs_store_option); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 317 | |
Nikolay Aleksandrov | dc3e5d1 | 2014-05-08 14:23:54 +0200 | [diff] [blame] | 318 | /* Show the up and down delays. */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 319 | static ssize_t bonding_show_downdelay(struct device *d, |
| 320 | struct device_attribute *attr, |
| 321 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 322 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 323 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 324 | |
Wagner Ferenc | 7bd4650 | 2007-12-06 23:40:28 -0800 | [diff] [blame] | 325 | return sprintf(buf, "%d\n", bond->params.downdelay * bond->params.miimon); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 326 | } |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 327 | static DEVICE_ATTR(downdelay, S_IRUGO | S_IWUSR, |
Nikolay Aleksandrov | dc3e5d1 | 2014-05-08 14:23:54 +0200 | [diff] [blame] | 328 | bonding_show_downdelay, bonding_sysfs_store_option); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 329 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 330 | static ssize_t bonding_show_updelay(struct device *d, |
| 331 | struct device_attribute *attr, |
| 332 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 333 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 334 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 335 | |
Wagner Ferenc | 7bd4650 | 2007-12-06 23:40:28 -0800 | [diff] [blame] | 336 | return sprintf(buf, "%d\n", bond->params.updelay * bond->params.miimon); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 337 | |
| 338 | } |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 339 | static DEVICE_ATTR(updelay, S_IRUGO | S_IWUSR, |
Nikolay Aleksandrov | dc3e5d1 | 2014-05-08 14:23:54 +0200 | [diff] [blame] | 340 | bonding_show_updelay, bonding_sysfs_store_option); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 341 | |
Nikolay Aleksandrov | dc3e5d1 | 2014-05-08 14:23:54 +0200 | [diff] [blame] | 342 | /* Show the LACP interval. */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 343 | static ssize_t bonding_show_lacp(struct device *d, |
| 344 | struct device_attribute *attr, |
| 345 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 346 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 347 | struct bonding *bond = to_bond(d); |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 348 | const struct bond_opt_value *val; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 349 | |
Nikolay Aleksandrov | d3131de | 2014-01-22 14:53:27 +0100 | [diff] [blame] | 350 | val = bond_opt_get_val(BOND_OPT_LACP_RATE, bond->params.lacp_fast); |
| 351 | |
| 352 | return sprintf(buf, "%s %d\n", val->string, bond->params.lacp_fast); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 353 | } |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 354 | static DEVICE_ATTR(lacp_rate, S_IRUGO | S_IWUSR, |
Nikolay Aleksandrov | dc3e5d1 | 2014-05-08 14:23:54 +0200 | [diff] [blame] | 355 | bonding_show_lacp, bonding_sysfs_store_option); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 356 | |
stephen hemminger | 655f891 | 2011-06-22 09:54:39 +0000 | [diff] [blame] | 357 | static ssize_t bonding_show_min_links(struct device *d, |
| 358 | struct device_attribute *attr, |
| 359 | char *buf) |
| 360 | { |
| 361 | struct bonding *bond = to_bond(d); |
| 362 | |
Masanari Iida | 014f1b2 | 2014-04-29 00:41:21 +0900 | [diff] [blame] | 363 | return sprintf(buf, "%u\n", bond->params.min_links); |
stephen hemminger | 655f891 | 2011-06-22 09:54:39 +0000 | [diff] [blame] | 364 | } |
stephen hemminger | 655f891 | 2011-06-22 09:54:39 +0000 | [diff] [blame] | 365 | static DEVICE_ATTR(min_links, S_IRUGO | S_IWUSR, |
Nikolay Aleksandrov | dc3e5d1 | 2014-05-08 14:23:54 +0200 | [diff] [blame] | 366 | bonding_show_min_links, bonding_sysfs_store_option); |
stephen hemminger | 655f891 | 2011-06-22 09:54:39 +0000 | [diff] [blame] | 367 | |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 368 | static ssize_t bonding_show_ad_select(struct device *d, |
| 369 | struct device_attribute *attr, |
| 370 | char *buf) |
| 371 | { |
| 372 | struct bonding *bond = to_bond(d); |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 373 | const struct bond_opt_value *val; |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 374 | |
Nikolay Aleksandrov | 9e5f5ee | 2014-01-22 14:53:29 +0100 | [diff] [blame] | 375 | val = bond_opt_get_val(BOND_OPT_AD_SELECT, bond->params.ad_select); |
| 376 | |
| 377 | return sprintf(buf, "%s %d\n", val->string, bond->params.ad_select); |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 378 | } |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 379 | static DEVICE_ATTR(ad_select, S_IRUGO | S_IWUSR, |
Nikolay Aleksandrov | dc3e5d1 | 2014-05-08 14:23:54 +0200 | [diff] [blame] | 380 | bonding_show_ad_select, bonding_sysfs_store_option); |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 381 | |
Nikolay Aleksandrov | 205845a | 2015-07-24 15:50:31 +0200 | [diff] [blame] | 382 | /* Show the number of peer notifications to send after a failover event. */ |
Ben Hutchings | ad246c9 | 2011-04-26 15:25:52 +0000 | [diff] [blame] | 383 | static ssize_t bonding_show_num_peer_notif(struct device *d, |
| 384 | struct device_attribute *attr, |
| 385 | char *buf) |
| 386 | { |
| 387 | struct bonding *bond = to_bond(d); |
| 388 | return sprintf(buf, "%d\n", bond->params.num_peer_notif); |
| 389 | } |
Ben Hutchings | ad246c9 | 2011-04-26 15:25:52 +0000 | [diff] [blame] | 390 | static DEVICE_ATTR(num_grat_arp, S_IRUGO | S_IWUSR, |
Nikolay Aleksandrov | 205845a | 2015-07-24 15:50:31 +0200 | [diff] [blame] | 391 | bonding_show_num_peer_notif, bonding_sysfs_store_option); |
Ben Hutchings | ad246c9 | 2011-04-26 15:25:52 +0000 | [diff] [blame] | 392 | static DEVICE_ATTR(num_unsol_na, S_IRUGO | S_IWUSR, |
Nikolay Aleksandrov | 205845a | 2015-07-24 15:50:31 +0200 | [diff] [blame] | 393 | bonding_show_num_peer_notif, bonding_sysfs_store_option); |
Ben Hutchings | ad246c9 | 2011-04-26 15:25:52 +0000 | [diff] [blame] | 394 | |
Nikolay Aleksandrov | dc3e5d1 | 2014-05-08 14:23:54 +0200 | [diff] [blame] | 395 | /* Show the MII monitor interval. */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 396 | static ssize_t bonding_show_miimon(struct device *d, |
| 397 | struct device_attribute *attr, |
| 398 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 399 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 400 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 401 | |
Wagner Ferenc | 7bd4650 | 2007-12-06 23:40:28 -0800 | [diff] [blame] | 402 | return sprintf(buf, "%d\n", bond->params.miimon); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 403 | } |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 404 | static DEVICE_ATTR(miimon, S_IRUGO | S_IWUSR, |
Nikolay Aleksandrov | dc3e5d1 | 2014-05-08 14:23:54 +0200 | [diff] [blame] | 405 | bonding_show_miimon, bonding_sysfs_store_option); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 406 | |
Nikolay Aleksandrov | dc3e5d1 | 2014-05-08 14:23:54 +0200 | [diff] [blame] | 407 | /* Show the primary slave. */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 408 | static ssize_t bonding_show_primary(struct device *d, |
| 409 | struct device_attribute *attr, |
| 410 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 411 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 412 | struct bonding *bond = to_bond(d); |
Nikolay Aleksandrov | 059b47e | 2014-09-09 23:17:00 +0200 | [diff] [blame] | 413 | struct slave *primary; |
| 414 | int count = 0; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 415 | |
Nikolay Aleksandrov | 059b47e | 2014-09-09 23:17:00 +0200 | [diff] [blame] | 416 | rcu_read_lock(); |
| 417 | primary = rcu_dereference(bond->primary_slave); |
| 418 | if (primary) |
| 419 | count = sprintf(buf, "%s\n", primary->dev->name); |
| 420 | rcu_read_unlock(); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 421 | |
| 422 | return count; |
| 423 | } |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 424 | static DEVICE_ATTR(primary, S_IRUGO | S_IWUSR, |
Nikolay Aleksandrov | dc3e5d1 | 2014-05-08 14:23:54 +0200 | [diff] [blame] | 425 | bonding_show_primary, bonding_sysfs_store_option); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 426 | |
Nikolay Aleksandrov | dc3e5d1 | 2014-05-08 14:23:54 +0200 | [diff] [blame] | 427 | /* Show the primary_reselect flag. */ |
Jiri Pirko | a549952 | 2009-09-25 03:28:09 +0000 | [diff] [blame] | 428 | static ssize_t bonding_show_primary_reselect(struct device *d, |
| 429 | struct device_attribute *attr, |
| 430 | char *buf) |
| 431 | { |
| 432 | struct bonding *bond = to_bond(d); |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 433 | const struct bond_opt_value *val; |
Nikolay Aleksandrov | 388d3a6 | 2014-01-22 14:53:33 +0100 | [diff] [blame] | 434 | |
| 435 | val = bond_opt_get_val(BOND_OPT_PRIMARY_RESELECT, |
| 436 | bond->params.primary_reselect); |
Jiri Pirko | a549952 | 2009-09-25 03:28:09 +0000 | [diff] [blame] | 437 | |
| 438 | return sprintf(buf, "%s %d\n", |
Nikolay Aleksandrov | 388d3a6 | 2014-01-22 14:53:33 +0100 | [diff] [blame] | 439 | val->string, bond->params.primary_reselect); |
Jiri Pirko | a549952 | 2009-09-25 03:28:09 +0000 | [diff] [blame] | 440 | } |
Jiri Pirko | a549952 | 2009-09-25 03:28:09 +0000 | [diff] [blame] | 441 | static DEVICE_ATTR(primary_reselect, S_IRUGO | S_IWUSR, |
Nikolay Aleksandrov | dc3e5d1 | 2014-05-08 14:23:54 +0200 | [diff] [blame] | 442 | bonding_show_primary_reselect, bonding_sysfs_store_option); |
Jiri Pirko | a549952 | 2009-09-25 03:28:09 +0000 | [diff] [blame] | 443 | |
Nikolay Aleksandrov | dc3e5d1 | 2014-05-08 14:23:54 +0200 | [diff] [blame] | 444 | /* Show the use_carrier flag. */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 445 | static ssize_t bonding_show_carrier(struct device *d, |
| 446 | struct device_attribute *attr, |
| 447 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 448 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 449 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 450 | |
Wagner Ferenc | 7bd4650 | 2007-12-06 23:40:28 -0800 | [diff] [blame] | 451 | return sprintf(buf, "%d\n", bond->params.use_carrier); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 452 | } |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 453 | static DEVICE_ATTR(use_carrier, S_IRUGO | S_IWUSR, |
Nikolay Aleksandrov | dc3e5d1 | 2014-05-08 14:23:54 +0200 | [diff] [blame] | 454 | bonding_show_carrier, bonding_sysfs_store_option); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 455 | |
| 456 | |
Nikolay Aleksandrov | dc3e5d1 | 2014-05-08 14:23:54 +0200 | [diff] [blame] | 457 | /* Show currently active_slave. */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 458 | static ssize_t bonding_show_active_slave(struct device *d, |
| 459 | struct device_attribute *attr, |
| 460 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 461 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 462 | struct bonding *bond = to_bond(d); |
Jiri Pirko | 752d48b | 2013-10-18 17:43:37 +0200 | [diff] [blame] | 463 | struct net_device *slave_dev; |
Wagner Ferenc | 16cd016 | 2007-12-06 23:40:29 -0800 | [diff] [blame] | 464 | int count = 0; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 465 | |
nikolay@redhat.com | 278b208 | 2013-08-01 16:54:51 +0200 | [diff] [blame] | 466 | rcu_read_lock(); |
Jiri Pirko | 752d48b | 2013-10-18 17:43:37 +0200 | [diff] [blame] | 467 | slave_dev = bond_option_active_slave_get_rcu(bond); |
| 468 | if (slave_dev) |
| 469 | count = sprintf(buf, "%s\n", slave_dev->name); |
nikolay@redhat.com | 278b208 | 2013-08-01 16:54:51 +0200 | [diff] [blame] | 470 | rcu_read_unlock(); |
| 471 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 472 | return count; |
| 473 | } |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 474 | static DEVICE_ATTR(active_slave, S_IRUGO | S_IWUSR, |
Nikolay Aleksandrov | dc3e5d1 | 2014-05-08 14:23:54 +0200 | [diff] [blame] | 475 | bonding_show_active_slave, bonding_sysfs_store_option); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 476 | |
Nikolay Aleksandrov | dc3e5d1 | 2014-05-08 14:23:54 +0200 | [diff] [blame] | 477 | /* Show link status of the bond interface. */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 478 | static ssize_t bonding_show_mii_status(struct device *d, |
| 479 | struct device_attribute *attr, |
| 480 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 481 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 482 | struct bonding *bond = to_bond(d); |
Jarod Wilson | c8086f6 | 2016-01-08 20:35:36 -0500 | [diff] [blame] | 483 | bool active = netif_carrier_ok(bond->dev); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 484 | |
Eric Dumazet | c2646b5 | 2014-07-15 06:56:54 -0700 | [diff] [blame] | 485 | return sprintf(buf, "%s\n", active ? "up" : "down"); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 486 | } |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 487 | static DEVICE_ATTR(mii_status, S_IRUGO, bonding_show_mii_status, NULL); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 488 | |
Nikolay Aleksandrov | dc3e5d1 | 2014-05-08 14:23:54 +0200 | [diff] [blame] | 489 | /* Show current 802.3ad aggregator ID. */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 490 | static ssize_t bonding_show_ad_aggregator(struct device *d, |
| 491 | struct device_attribute *attr, |
| 492 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 493 | { |
| 494 | int count = 0; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 495 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 496 | |
Veaceslav Falico | 0184409 | 2014-05-15 21:39:55 +0200 | [diff] [blame] | 497 | if (BOND_MODE(bond) == BOND_MODE_8023AD) { |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 498 | struct ad_info ad_info; |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 499 | count = sprintf(buf, "%d\n", |
nikolay@redhat.com | 318debd | 2013-05-18 01:18:31 +0000 | [diff] [blame] | 500 | bond_3ad_get_active_agg_info(bond, &ad_info) |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 501 | ? 0 : ad_info.aggregator_id); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 502 | } |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 503 | |
| 504 | return count; |
| 505 | } |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 506 | static DEVICE_ATTR(ad_aggregator, S_IRUGO, bonding_show_ad_aggregator, NULL); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 507 | |
| 508 | |
Nikolay Aleksandrov | dc3e5d1 | 2014-05-08 14:23:54 +0200 | [diff] [blame] | 509 | /* Show number of active 802.3ad ports. */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 510 | static ssize_t bonding_show_ad_num_ports(struct device *d, |
| 511 | struct device_attribute *attr, |
| 512 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 513 | { |
| 514 | int count = 0; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 515 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 516 | |
Veaceslav Falico | 0184409 | 2014-05-15 21:39:55 +0200 | [diff] [blame] | 517 | if (BOND_MODE(bond) == BOND_MODE_8023AD) { |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 518 | struct ad_info ad_info; |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 519 | count = sprintf(buf, "%d\n", |
nikolay@redhat.com | 318debd | 2013-05-18 01:18:31 +0000 | [diff] [blame] | 520 | bond_3ad_get_active_agg_info(bond, &ad_info) |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 521 | ? 0 : ad_info.ports); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 522 | } |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 523 | |
| 524 | return count; |
| 525 | } |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 526 | static DEVICE_ATTR(ad_num_ports, S_IRUGO, bonding_show_ad_num_ports, NULL); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 527 | |
| 528 | |
Nikolay Aleksandrov | dc3e5d1 | 2014-05-08 14:23:54 +0200 | [diff] [blame] | 529 | /* Show current 802.3ad actor key. */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 530 | static ssize_t bonding_show_ad_actor_key(struct device *d, |
| 531 | struct device_attribute *attr, |
| 532 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 533 | { |
| 534 | int count = 0; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 535 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 536 | |
Mahesh Bandewar | 4cd6b47 | 2015-06-18 11:30:54 -0700 | [diff] [blame] | 537 | if (BOND_MODE(bond) == BOND_MODE_8023AD && capable(CAP_NET_ADMIN)) { |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 538 | struct ad_info ad_info; |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 539 | count = sprintf(buf, "%d\n", |
nikolay@redhat.com | 318debd | 2013-05-18 01:18:31 +0000 | [diff] [blame] | 540 | bond_3ad_get_active_agg_info(bond, &ad_info) |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 541 | ? 0 : ad_info.actor_key); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 542 | } |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 543 | |
| 544 | return count; |
| 545 | } |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 546 | static DEVICE_ATTR(ad_actor_key, S_IRUGO, bonding_show_ad_actor_key, NULL); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 547 | |
| 548 | |
Nikolay Aleksandrov | dc3e5d1 | 2014-05-08 14:23:54 +0200 | [diff] [blame] | 549 | /* Show current 802.3ad partner key. */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 550 | static ssize_t bonding_show_ad_partner_key(struct device *d, |
| 551 | struct device_attribute *attr, |
| 552 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 553 | { |
| 554 | int count = 0; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 555 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 556 | |
Mahesh Bandewar | 4cd6b47 | 2015-06-18 11:30:54 -0700 | [diff] [blame] | 557 | if (BOND_MODE(bond) == BOND_MODE_8023AD && capable(CAP_NET_ADMIN)) { |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 558 | struct ad_info ad_info; |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 559 | count = sprintf(buf, "%d\n", |
nikolay@redhat.com | 318debd | 2013-05-18 01:18:31 +0000 | [diff] [blame] | 560 | bond_3ad_get_active_agg_info(bond, &ad_info) |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 561 | ? 0 : ad_info.partner_key); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 562 | } |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 563 | |
| 564 | return count; |
| 565 | } |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 566 | static DEVICE_ATTR(ad_partner_key, S_IRUGO, bonding_show_ad_partner_key, NULL); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 567 | |
| 568 | |
Nikolay Aleksandrov | dc3e5d1 | 2014-05-08 14:23:54 +0200 | [diff] [blame] | 569 | /* Show current 802.3ad partner mac. */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 570 | static ssize_t bonding_show_ad_partner_mac(struct device *d, |
| 571 | struct device_attribute *attr, |
| 572 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 573 | { |
| 574 | int count = 0; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 575 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 576 | |
Mahesh Bandewar | 4cd6b47 | 2015-06-18 11:30:54 -0700 | [diff] [blame] | 577 | if (BOND_MODE(bond) == BOND_MODE_8023AD && capable(CAP_NET_ADMIN)) { |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 578 | struct ad_info ad_info; |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 579 | if (!bond_3ad_get_active_agg_info(bond, &ad_info)) |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 580 | count = sprintf(buf, "%pM\n", ad_info.partner_system); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 581 | } |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 582 | |
| 583 | return count; |
| 584 | } |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 585 | static DEVICE_ATTR(ad_partner_mac, S_IRUGO, bonding_show_ad_partner_mac, NULL); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 586 | |
Nikolay Aleksandrov | dc3e5d1 | 2014-05-08 14:23:54 +0200 | [diff] [blame] | 587 | /* Show the queue_ids of the slaves in the current bond. */ |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 588 | static ssize_t bonding_show_queue_id(struct device *d, |
| 589 | struct device_attribute *attr, |
| 590 | char *buf) |
| 591 | { |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 592 | struct bonding *bond = to_bond(d); |
Veaceslav Falico | 9caff1e7 | 2013-09-25 09:20:14 +0200 | [diff] [blame] | 593 | struct list_head *iter; |
nikolay@redhat.com | dec1e90 | 2013-08-01 16:54:47 +0200 | [diff] [blame] | 594 | struct slave *slave; |
| 595 | int res = 0; |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 596 | |
| 597 | if (!rtnl_trylock()) |
| 598 | return restart_syscall(); |
| 599 | |
Veaceslav Falico | 9caff1e7 | 2013-09-25 09:20:14 +0200 | [diff] [blame] | 600 | bond_for_each_slave(bond, slave, iter) { |
Nicolas de Pesloüan | 7923668 | 2010-07-14 18:24:54 -0700 | [diff] [blame] | 601 | if (res > (PAGE_SIZE - IFNAMSIZ - 6)) { |
| 602 | /* not enough space for another interface_name:queue_id pair */ |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 603 | if ((PAGE_SIZE - res) > 10) |
| 604 | res = PAGE_SIZE - 10; |
| 605 | res += sprintf(buf + res, "++more++ "); |
| 606 | break; |
| 607 | } |
| 608 | res += sprintf(buf + res, "%s:%d ", |
| 609 | slave->dev->name, slave->queue_id); |
| 610 | } |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 611 | if (res) |
| 612 | buf[res-1] = '\n'; /* eat the leftover space */ |
dingtianhong | 4d1ae5f | 2013-10-15 16:28:42 +0800 | [diff] [blame] | 613 | |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 614 | rtnl_unlock(); |
nikolay@redhat.com | dec1e90 | 2013-08-01 16:54:47 +0200 | [diff] [blame] | 615 | |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 616 | return res; |
| 617 | } |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 618 | static DEVICE_ATTR(queue_id, S_IRUGO | S_IWUSR, bonding_show_queue_id, |
Nikolay Aleksandrov | dc3e5d1 | 2014-05-08 14:23:54 +0200 | [diff] [blame] | 619 | bonding_sysfs_store_option); |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 620 | |
| 621 | |
Nikolay Aleksandrov | dc3e5d1 | 2014-05-08 14:23:54 +0200 | [diff] [blame] | 622 | /* Show the all_slaves_active flag. */ |
Andy Gospodarek | ebd8e49 | 2010-06-02 08:39:21 +0000 | [diff] [blame] | 623 | static ssize_t bonding_show_slaves_active(struct device *d, |
| 624 | struct device_attribute *attr, |
| 625 | char *buf) |
| 626 | { |
| 627 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 628 | |
Andy Gospodarek | ebd8e49 | 2010-06-02 08:39:21 +0000 | [diff] [blame] | 629 | return sprintf(buf, "%d\n", bond->params.all_slaves_active); |
| 630 | } |
Andy Gospodarek | ebd8e49 | 2010-06-02 08:39:21 +0000 | [diff] [blame] | 631 | static DEVICE_ATTR(all_slaves_active, S_IRUGO | S_IWUSR, |
Nikolay Aleksandrov | dc3e5d1 | 2014-05-08 14:23:54 +0200 | [diff] [blame] | 632 | bonding_show_slaves_active, bonding_sysfs_store_option); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 633 | |
Nikolay Aleksandrov | dc3e5d1 | 2014-05-08 14:23:54 +0200 | [diff] [blame] | 634 | /* Show the number of IGMP membership reports to send on link failure */ |
Flavio Leitner | c2952c3 | 2010-10-05 14:23:59 +0000 | [diff] [blame] | 635 | static ssize_t bonding_show_resend_igmp(struct device *d, |
Flavio Leitner | 94265cf | 2011-05-25 08:38:58 +0000 | [diff] [blame] | 636 | struct device_attribute *attr, |
| 637 | char *buf) |
Flavio Leitner | c2952c3 | 2010-10-05 14:23:59 +0000 | [diff] [blame] | 638 | { |
| 639 | struct bonding *bond = to_bond(d); |
| 640 | |
| 641 | return sprintf(buf, "%d\n", bond->params.resend_igmp); |
| 642 | } |
Flavio Leitner | c2952c3 | 2010-10-05 14:23:59 +0000 | [diff] [blame] | 643 | static DEVICE_ATTR(resend_igmp, S_IRUGO | S_IWUSR, |
Nikolay Aleksandrov | dc3e5d1 | 2014-05-08 14:23:54 +0200 | [diff] [blame] | 644 | bonding_show_resend_igmp, bonding_sysfs_store_option); |
Flavio Leitner | c2952c3 | 2010-10-05 14:23:59 +0000 | [diff] [blame] | 645 | |
Neil Horman | 7eacd03 | 2013-09-13 11:05:33 -0400 | [diff] [blame] | 646 | |
| 647 | static ssize_t bonding_show_lp_interval(struct device *d, |
| 648 | struct device_attribute *attr, |
| 649 | char *buf) |
| 650 | { |
| 651 | struct bonding *bond = to_bond(d); |
Nikolay Aleksandrov | dc3e5d1 | 2014-05-08 14:23:54 +0200 | [diff] [blame] | 652 | |
Neil Horman | 7eacd03 | 2013-09-13 11:05:33 -0400 | [diff] [blame] | 653 | return sprintf(buf, "%d\n", bond->params.lp_interval); |
| 654 | } |
Neil Horman | 7eacd03 | 2013-09-13 11:05:33 -0400 | [diff] [blame] | 655 | static DEVICE_ATTR(lp_interval, S_IRUGO | S_IWUSR, |
Nikolay Aleksandrov | dc3e5d1 | 2014-05-08 14:23:54 +0200 | [diff] [blame] | 656 | bonding_show_lp_interval, bonding_sysfs_store_option); |
Neil Horman | 7eacd03 | 2013-09-13 11:05:33 -0400 | [diff] [blame] | 657 | |
Mahesh Bandewar | e9f0fb8 | 2014-04-22 16:30:22 -0700 | [diff] [blame] | 658 | static ssize_t bonding_show_tlb_dynamic_lb(struct device *d, |
| 659 | struct device_attribute *attr, |
| 660 | char *buf) |
| 661 | { |
| 662 | struct bonding *bond = to_bond(d); |
| 663 | return sprintf(buf, "%d\n", bond->params.tlb_dynamic_lb); |
| 664 | } |
Mahesh Bandewar | e9f0fb8 | 2014-04-22 16:30:22 -0700 | [diff] [blame] | 665 | static DEVICE_ATTR(tlb_dynamic_lb, S_IRUGO | S_IWUSR, |
Nikolay Aleksandrov | dc3e5d1 | 2014-05-08 14:23:54 +0200 | [diff] [blame] | 666 | bonding_show_tlb_dynamic_lb, bonding_sysfs_store_option); |
Mahesh Bandewar | e9f0fb8 | 2014-04-22 16:30:22 -0700 | [diff] [blame] | 667 | |
Nikolay Aleksandrov | 7395832 | 2013-11-05 13:51:41 +0100 | [diff] [blame] | 668 | static ssize_t bonding_show_packets_per_slave(struct device *d, |
| 669 | struct device_attribute *attr, |
| 670 | char *buf) |
| 671 | { |
| 672 | struct bonding *bond = to_bond(d); |
Nikolay Aleksandrov | a752a8b | 2013-12-05 11:36:58 +0100 | [diff] [blame] | 673 | unsigned int packets_per_slave = bond->params.packets_per_slave; |
Nikolay Aleksandrov | dc3e5d1 | 2014-05-08 14:23:54 +0200 | [diff] [blame] | 674 | |
Nikolay Aleksandrov | a752a8b | 2013-12-05 11:36:58 +0100 | [diff] [blame] | 675 | return sprintf(buf, "%u\n", packets_per_slave); |
Nikolay Aleksandrov | 7395832 | 2013-11-05 13:51:41 +0100 | [diff] [blame] | 676 | } |
Nikolay Aleksandrov | 7395832 | 2013-11-05 13:51:41 +0100 | [diff] [blame] | 677 | static DEVICE_ATTR(packets_per_slave, S_IRUGO | S_IWUSR, |
Nikolay Aleksandrov | dc3e5d1 | 2014-05-08 14:23:54 +0200 | [diff] [blame] | 678 | bonding_show_packets_per_slave, bonding_sysfs_store_option); |
Nikolay Aleksandrov | 7395832 | 2013-11-05 13:51:41 +0100 | [diff] [blame] | 679 | |
Mahesh Bandewar | 6791e46 | 2015-05-09 00:01:55 -0700 | [diff] [blame] | 680 | static ssize_t bonding_show_ad_actor_sys_prio(struct device *d, |
| 681 | struct device_attribute *attr, |
| 682 | char *buf) |
| 683 | { |
| 684 | struct bonding *bond = to_bond(d); |
| 685 | |
Mahesh Bandewar | 4cd6b47 | 2015-06-18 11:30:54 -0700 | [diff] [blame] | 686 | if (BOND_MODE(bond) == BOND_MODE_8023AD && capable(CAP_NET_ADMIN)) |
Mahesh Bandewar | 6791e46 | 2015-05-09 00:01:55 -0700 | [diff] [blame] | 687 | return sprintf(buf, "%hu\n", bond->params.ad_actor_sys_prio); |
| 688 | |
| 689 | return 0; |
| 690 | } |
| 691 | static DEVICE_ATTR(ad_actor_sys_prio, S_IRUGO | S_IWUSR, |
| 692 | bonding_show_ad_actor_sys_prio, bonding_sysfs_store_option); |
| 693 | |
Mahesh Bandewar | 7451495 | 2015-05-09 00:01:56 -0700 | [diff] [blame] | 694 | static ssize_t bonding_show_ad_actor_system(struct device *d, |
| 695 | struct device_attribute *attr, |
| 696 | char *buf) |
| 697 | { |
| 698 | struct bonding *bond = to_bond(d); |
| 699 | |
Mahesh Bandewar | 4cd6b47 | 2015-06-18 11:30:54 -0700 | [diff] [blame] | 700 | if (BOND_MODE(bond) == BOND_MODE_8023AD && capable(CAP_NET_ADMIN)) |
Mahesh Bandewar | 7451495 | 2015-05-09 00:01:56 -0700 | [diff] [blame] | 701 | return sprintf(buf, "%pM\n", bond->params.ad_actor_system); |
| 702 | |
| 703 | return 0; |
| 704 | } |
| 705 | |
| 706 | static DEVICE_ATTR(ad_actor_system, S_IRUGO | S_IWUSR, |
| 707 | bonding_show_ad_actor_system, bonding_sysfs_store_option); |
| 708 | |
Mahesh Bandewar | d22a5fc | 2015-05-09 00:01:57 -0700 | [diff] [blame] | 709 | static ssize_t bonding_show_ad_user_port_key(struct device *d, |
| 710 | struct device_attribute *attr, |
| 711 | char *buf) |
| 712 | { |
| 713 | struct bonding *bond = to_bond(d); |
| 714 | |
Mahesh Bandewar | 4cd6b47 | 2015-06-18 11:30:54 -0700 | [diff] [blame] | 715 | if (BOND_MODE(bond) == BOND_MODE_8023AD && capable(CAP_NET_ADMIN)) |
Mahesh Bandewar | d22a5fc | 2015-05-09 00:01:57 -0700 | [diff] [blame] | 716 | return sprintf(buf, "%hu\n", bond->params.ad_user_port_key); |
| 717 | |
| 718 | return 0; |
| 719 | } |
| 720 | static DEVICE_ATTR(ad_user_port_key, S_IRUGO | S_IWUSR, |
| 721 | bonding_show_ad_user_port_key, bonding_sysfs_store_option); |
| 722 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 723 | static struct attribute *per_bond_attrs[] = { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 724 | &dev_attr_slaves.attr, |
| 725 | &dev_attr_mode.attr, |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 726 | &dev_attr_fail_over_mac.attr, |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 727 | &dev_attr_arp_validate.attr, |
Veaceslav Falico | 8599b52 | 2013-06-24 11:49:34 +0200 | [diff] [blame] | 728 | &dev_attr_arp_all_targets.attr, |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 729 | &dev_attr_arp_interval.attr, |
| 730 | &dev_attr_arp_ip_target.attr, |
| 731 | &dev_attr_downdelay.attr, |
| 732 | &dev_attr_updelay.attr, |
| 733 | &dev_attr_lacp_rate.attr, |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 734 | &dev_attr_ad_select.attr, |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 735 | &dev_attr_xmit_hash_policy.attr, |
Ben Hutchings | ad246c9 | 2011-04-26 15:25:52 +0000 | [diff] [blame] | 736 | &dev_attr_num_grat_arp.attr, |
| 737 | &dev_attr_num_unsol_na.attr, |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 738 | &dev_attr_miimon.attr, |
| 739 | &dev_attr_primary.attr, |
Jiri Pirko | a549952 | 2009-09-25 03:28:09 +0000 | [diff] [blame] | 740 | &dev_attr_primary_reselect.attr, |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 741 | &dev_attr_use_carrier.attr, |
| 742 | &dev_attr_active_slave.attr, |
| 743 | &dev_attr_mii_status.attr, |
| 744 | &dev_attr_ad_aggregator.attr, |
| 745 | &dev_attr_ad_num_ports.attr, |
| 746 | &dev_attr_ad_actor_key.attr, |
| 747 | &dev_attr_ad_partner_key.attr, |
| 748 | &dev_attr_ad_partner_mac.attr, |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 749 | &dev_attr_queue_id.attr, |
Andy Gospodarek | ebd8e49 | 2010-06-02 08:39:21 +0000 | [diff] [blame] | 750 | &dev_attr_all_slaves_active.attr, |
Flavio Leitner | c2952c3 | 2010-10-05 14:23:59 +0000 | [diff] [blame] | 751 | &dev_attr_resend_igmp.attr, |
stephen hemminger | 655f891 | 2011-06-22 09:54:39 +0000 | [diff] [blame] | 752 | &dev_attr_min_links.attr, |
Neil Horman | 7eacd03 | 2013-09-13 11:05:33 -0400 | [diff] [blame] | 753 | &dev_attr_lp_interval.attr, |
Nikolay Aleksandrov | 7395832 | 2013-11-05 13:51:41 +0100 | [diff] [blame] | 754 | &dev_attr_packets_per_slave.attr, |
Mahesh Bandewar | e9f0fb8 | 2014-04-22 16:30:22 -0700 | [diff] [blame] | 755 | &dev_attr_tlb_dynamic_lb.attr, |
Mahesh Bandewar | 6791e46 | 2015-05-09 00:01:55 -0700 | [diff] [blame] | 756 | &dev_attr_ad_actor_sys_prio.attr, |
Mahesh Bandewar | 7451495 | 2015-05-09 00:01:56 -0700 | [diff] [blame] | 757 | &dev_attr_ad_actor_system.attr, |
Mahesh Bandewar | d22a5fc | 2015-05-09 00:01:57 -0700 | [diff] [blame] | 758 | &dev_attr_ad_user_port_key.attr, |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 759 | NULL, |
| 760 | }; |
| 761 | |
| 762 | static struct attribute_group bonding_group = { |
| 763 | .name = "bonding", |
| 764 | .attrs = per_bond_attrs, |
| 765 | }; |
| 766 | |
Nikolay Aleksandrov | dc3e5d1 | 2014-05-08 14:23:54 +0200 | [diff] [blame] | 767 | /* Initialize sysfs. This sets up the bonding_masters file in |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 768 | * /sys/class/net. |
| 769 | */ |
Eric W. Biederman | 4c22400 | 2011-10-12 21:56:25 +0000 | [diff] [blame] | 770 | int bond_create_sysfs(struct bond_net *bn) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 771 | { |
Jay Vosburgh | b8a9787 | 2008-06-13 18:12:04 -0700 | [diff] [blame] | 772 | int ret; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 773 | |
Eric W. Biederman | 4c22400 | 2011-10-12 21:56:25 +0000 | [diff] [blame] | 774 | bn->class_attr_bonding_masters = class_attr_bonding_masters; |
Eric W. Biederman | 01718e3 | 2011-10-21 22:43:07 +0000 | [diff] [blame] | 775 | sysfs_attr_init(&bn->class_attr_bonding_masters.attr); |
Eric W. Biederman | 4c22400 | 2011-10-12 21:56:25 +0000 | [diff] [blame] | 776 | |
Tejun Heo | 58292cbe | 2013-09-11 22:29:04 -0400 | [diff] [blame] | 777 | ret = netdev_class_create_file_ns(&bn->class_attr_bonding_masters, |
| 778 | bn->net); |
Nikolay Aleksandrov | dc3e5d1 | 2014-05-08 14:23:54 +0200 | [diff] [blame] | 779 | /* Permit multiple loads of the module by ignoring failures to |
Jay Vosburgh | 877cbd3 | 2007-01-19 18:15:47 -0800 | [diff] [blame] | 780 | * create the bonding_masters sysfs file. Bonding devices |
| 781 | * created by second or subsequent loads of the module will |
| 782 | * not be listed in, or controllable by, bonding_masters, but |
| 783 | * will have the usual "bonding" sysfs directory. |
| 784 | * |
| 785 | * This is done to preserve backwards compatibility for |
| 786 | * initscripts/sysconfig, which load bonding multiple times to |
| 787 | * configure multiple bonding devices. |
| 788 | */ |
| 789 | if (ret == -EEXIST) { |
Stephen Hemminger | 38d2f38 | 2008-05-14 22:35:04 -0700 | [diff] [blame] | 790 | /* Is someone being kinky and naming a device bonding_master? */ |
Eric W. Biederman | 4c22400 | 2011-10-12 21:56:25 +0000 | [diff] [blame] | 791 | if (__dev_get_by_name(bn->net, |
Stephen Hemminger | 38d2f38 | 2008-05-14 22:35:04 -0700 | [diff] [blame] | 792 | class_attr_bonding_masters.attr.name)) |
Joe Perches | 9019426 | 2014-02-15 16:01:45 -0800 | [diff] [blame] | 793 | pr_err("network device named %s already exists in sysfs\n", |
Stephen Hemminger | 38d2f38 | 2008-05-14 22:35:04 -0700 | [diff] [blame] | 794 | class_attr_bonding_masters.attr.name); |
Stephen Hemminger | 130aa61 | 2009-06-11 05:46:04 -0700 | [diff] [blame] | 795 | ret = 0; |
Jay Vosburgh | 877cbd3 | 2007-01-19 18:15:47 -0800 | [diff] [blame] | 796 | } |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 797 | |
| 798 | return ret; |
| 799 | |
| 800 | } |
| 801 | |
Nikolay Aleksandrov | dc3e5d1 | 2014-05-08 14:23:54 +0200 | [diff] [blame] | 802 | /* Remove /sys/class/net/bonding_masters. */ |
Eric W. Biederman | 4c22400 | 2011-10-12 21:56:25 +0000 | [diff] [blame] | 803 | void bond_destroy_sysfs(struct bond_net *bn) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 804 | { |
Tejun Heo | 58292cbe | 2013-09-11 22:29:04 -0400 | [diff] [blame] | 805 | netdev_class_remove_file_ns(&bn->class_attr_bonding_masters, bn->net); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 806 | } |
| 807 | |
Nikolay Aleksandrov | dc3e5d1 | 2014-05-08 14:23:54 +0200 | [diff] [blame] | 808 | /* Initialize sysfs for each bond. This sets up and registers |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 809 | * the 'bondctl' directory for each individual bond under /sys/class/net. |
| 810 | */ |
Eric W. Biederman | 6151b3d | 2009-10-29 14:18:22 +0000 | [diff] [blame] | 811 | void bond_prepare_sysfs_group(struct bonding *bond) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 812 | { |
Eric W. Biederman | 6151b3d | 2009-10-29 14:18:22 +0000 | [diff] [blame] | 813 | bond->dev->sysfs_groups[0] = &bonding_group; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 814 | } |
| 815 | |