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 |
| 15 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 16 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 17 | * |
| 18 | * The full GNU General Public License is included in this distribution in the |
| 19 | * file called LICENSE. |
| 20 | * |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 21 | */ |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 22 | |
| 23 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 24 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 25 | #include <linux/kernel.h> |
| 26 | #include <linux/module.h> |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 27 | #include <linux/device.h> |
Alexey Dobriyan | d43c36d | 2009-10-07 17:09:06 +0400 | [diff] [blame] | 28 | #include <linux/sched.h> |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 29 | #include <linux/fs.h> |
| 30 | #include <linux/types.h> |
| 31 | #include <linux/string.h> |
| 32 | #include <linux/netdevice.h> |
| 33 | #include <linux/inetdevice.h> |
| 34 | #include <linux/in.h> |
| 35 | #include <linux/sysfs.h> |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 36 | #include <linux/ctype.h> |
| 37 | #include <linux/inet.h> |
| 38 | #include <linux/rtnetlink.h> |
Stephen Hemminger | 5c5129b | 2009-06-12 19:02:51 +0000 | [diff] [blame] | 39 | #include <linux/etherdevice.h> |
Eric W. Biederman | 881d966 | 2007-09-17 11:56:21 -0700 | [diff] [blame] | 40 | #include <net/net_namespace.h> |
Eric W. Biederman | ec87fd3 | 2009-10-29 14:18:26 +0000 | [diff] [blame] | 41 | #include <net/netns/generic.h> |
| 42 | #include <linux/nsproxy.h> |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 43 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 44 | #include "bonding.h" |
Holger Eitzenberger | 5a03cdb | 2008-12-09 23:09:22 -0800 | [diff] [blame] | 45 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 46 | #define to_dev(obj) container_of(obj, struct device, kobj) |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 47 | #define to_bond(cd) ((struct bonding *)(netdev_priv(to_net_dev(cd)))) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 48 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 49 | /* |
| 50 | * "show" function for the bond_masters attribute. |
| 51 | * The class parameter is ignored. |
| 52 | */ |
Andi Kleen | 28812fe | 2010-01-05 12:48:07 +0100 | [diff] [blame] | 53 | static ssize_t bonding_show_bonds(struct class *cls, |
| 54 | struct class_attribute *attr, |
| 55 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 56 | { |
Eric W. Biederman | 4c22400 | 2011-10-12 21:56:25 +0000 | [diff] [blame] | 57 | struct bond_net *bn = |
| 58 | container_of(attr, struct bond_net, class_attr_bonding_masters); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 59 | int res = 0; |
| 60 | struct bonding *bond; |
| 61 | |
Stephen Hemminger | 7e08384 | 2009-06-12 19:02:46 +0000 | [diff] [blame] | 62 | rtnl_lock(); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 63 | |
Eric W. Biederman | ec87fd3 | 2009-10-29 14:18:26 +0000 | [diff] [blame] | 64 | list_for_each_entry(bond, &bn->dev_list, bond_list) { |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 65 | if (res > (PAGE_SIZE - IFNAMSIZ)) { |
| 66 | /* not enough space for another interface name */ |
| 67 | if ((PAGE_SIZE - res) > 10) |
| 68 | res = PAGE_SIZE - 10; |
Wagner Ferenc | b884366 | 2007-12-06 23:40:30 -0800 | [diff] [blame] | 69 | res += sprintf(buf + res, "++more++ "); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 70 | break; |
| 71 | } |
Wagner Ferenc | b884366 | 2007-12-06 23:40:30 -0800 | [diff] [blame] | 72 | res += sprintf(buf + res, "%s ", bond->dev->name); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 73 | } |
Wagner Ferenc | 1dcdcd6 | 2007-12-06 23:40:31 -0800 | [diff] [blame] | 74 | if (res) |
| 75 | buf[res-1] = '\n'; /* eat the leftover space */ |
Stephen Hemminger | 7e08384 | 2009-06-12 19:02:46 +0000 | [diff] [blame] | 76 | |
| 77 | rtnl_unlock(); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 78 | return res; |
| 79 | } |
| 80 | |
Eric W. Biederman | 4c22400 | 2011-10-12 21:56:25 +0000 | [diff] [blame] | 81 | 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] | 82 | { |
| 83 | struct bonding *bond; |
| 84 | |
Eric W. Biederman | ec87fd3 | 2009-10-29 14:18:26 +0000 | [diff] [blame] | 85 | list_for_each_entry(bond, &bn->dev_list, bond_list) { |
Stephen Hemminger | 373500d | 2009-06-12 19:02:50 +0000 | [diff] [blame] | 86 | if (strncmp(bond->dev->name, ifname, IFNAMSIZ) == 0) |
| 87 | return bond->dev; |
| 88 | } |
| 89 | return NULL; |
| 90 | } |
| 91 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 92 | /* |
| 93 | * "store" function for the bond_masters attribute. This is what |
| 94 | * creates and deletes entire bonds. |
| 95 | * |
| 96 | * The class parameter is ignored. |
| 97 | * |
| 98 | */ |
| 99 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 100 | static ssize_t bonding_store_bonds(struct class *cls, |
Andi Kleen | 28812fe | 2010-01-05 12:48:07 +0100 | [diff] [blame] | 101 | struct class_attribute *attr, |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 102 | const char *buffer, size_t count) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 103 | { |
Eric W. Biederman | 4c22400 | 2011-10-12 21:56:25 +0000 | [diff] [blame] | 104 | struct bond_net *bn = |
| 105 | container_of(attr, struct bond_net, class_attr_bonding_masters); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 106 | char command[IFNAMSIZ + 1] = {0, }; |
| 107 | char *ifname; |
Jay Vosburgh | 027ea04 | 2008-01-17 16:25:02 -0800 | [diff] [blame] | 108 | int rv, res = count; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 109 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 110 | sscanf(buffer, "%16s", command); /* IFNAMSIZ*/ |
| 111 | ifname = command + 1; |
| 112 | if ((strlen(command) <= 1) || |
| 113 | !dev_valid_name(ifname)) |
| 114 | goto err_no_cmd; |
| 115 | |
| 116 | if (command[0] == '+') { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 117 | pr_info("%s is being created...\n", ifname); |
Eric W. Biederman | 4c22400 | 2011-10-12 21:56:25 +0000 | [diff] [blame] | 118 | rv = bond_create(bn->net, ifname); |
Jay Vosburgh | 027ea04 | 2008-01-17 16:25:02 -0800 | [diff] [blame] | 119 | if (rv) { |
Phil Oester | 5f86cad1 | 2011-03-14 06:22:06 +0000 | [diff] [blame] | 120 | if (rv == -EEXIST) |
| 121 | pr_info("%s already exists.\n", ifname); |
| 122 | else |
| 123 | pr_info("%s creation failed.\n", ifname); |
Jay Vosburgh | 027ea04 | 2008-01-17 16:25:02 -0800 | [diff] [blame] | 124 | res = rv; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 125 | } |
Stephen Hemminger | 373500d | 2009-06-12 19:02:50 +0000 | [diff] [blame] | 126 | } else if (command[0] == '-') { |
| 127 | struct net_device *bond_dev; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 128 | |
Jay Vosburgh | 027ea04 | 2008-01-17 16:25:02 -0800 | [diff] [blame] | 129 | rtnl_lock(); |
Eric W. Biederman | 4c22400 | 2011-10-12 21:56:25 +0000 | [diff] [blame] | 130 | bond_dev = bond_get_by_name(bn, ifname); |
Stephen Hemminger | 373500d | 2009-06-12 19:02:50 +0000 | [diff] [blame] | 131 | if (bond_dev) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 132 | pr_info("%s is being deleted...\n", ifname); |
Stephen Hemminger | 373500d | 2009-06-12 19:02:50 +0000 | [diff] [blame] | 133 | unregister_netdevice(bond_dev); |
| 134 | } else { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 135 | pr_err("unable to delete non-existent %s\n", ifname); |
Stephen Hemminger | 373500d | 2009-06-12 19:02:50 +0000 | [diff] [blame] | 136 | res = -ENODEV; |
| 137 | } |
| 138 | rtnl_unlock(); |
| 139 | } else |
| 140 | goto err_no_cmd; |
Jay Vosburgh | 027ea04 | 2008-01-17 16:25:02 -0800 | [diff] [blame] | 141 | |
Stephen Hemminger | 373500d | 2009-06-12 19:02:50 +0000 | [diff] [blame] | 142 | /* Always return either count or an error. If you return 0, you'll |
| 143 | * get called forever, which is bad. |
| 144 | */ |
| 145 | return res; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 146 | |
| 147 | err_no_cmd: |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 148 | 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] | 149 | return -EPERM; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 150 | } |
Stephen Hemminger | 373500d | 2009-06-12 19:02:50 +0000 | [diff] [blame] | 151 | |
Eric W. Biederman | 4c22400 | 2011-10-12 21:56:25 +0000 | [diff] [blame] | 152 | static const void *bonding_namespace(struct class *cls, |
| 153 | const struct class_attribute *attr) |
| 154 | { |
| 155 | const struct bond_net *bn = |
| 156 | container_of(attr, struct bond_net, class_attr_bonding_masters); |
| 157 | return bn->net; |
| 158 | } |
| 159 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 160 | /* 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] | 161 | static const struct class_attribute class_attr_bonding_masters = { |
| 162 | .attr = { |
| 163 | .name = "bonding_masters", |
| 164 | .mode = S_IWUSR | S_IRUGO, |
| 165 | }, |
| 166 | .show = bonding_show_bonds, |
| 167 | .store = bonding_store_bonds, |
| 168 | .namespace = bonding_namespace, |
| 169 | }; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 170 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 171 | /* |
| 172 | * Show the slaves in the current bond. |
| 173 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 174 | static ssize_t bonding_show_slaves(struct device *d, |
| 175 | struct device_attribute *attr, char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 176 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 177 | struct bonding *bond = to_bond(d); |
Veaceslav Falico | 9caff1e7 | 2013-09-25 09:20:14 +0200 | [diff] [blame] | 178 | struct list_head *iter; |
nikolay@redhat.com | dec1e90 | 2013-08-01 16:54:47 +0200 | [diff] [blame] | 179 | struct slave *slave; |
| 180 | int res = 0; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 181 | |
dingtianhong | 4d1ae5f | 2013-10-15 16:28:42 +0800 | [diff] [blame^] | 182 | if (!rtnl_trylock()) |
| 183 | return restart_syscall(); |
| 184 | |
Veaceslav Falico | 9caff1e7 | 2013-09-25 09:20:14 +0200 | [diff] [blame] | 185 | bond_for_each_slave(bond, slave, iter) { |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 186 | if (res > (PAGE_SIZE - IFNAMSIZ)) { |
| 187 | /* not enough space for another interface name */ |
| 188 | if ((PAGE_SIZE - res) > 10) |
| 189 | res = PAGE_SIZE - 10; |
Wagner Ferenc | 7bd4650 | 2007-12-06 23:40:28 -0800 | [diff] [blame] | 190 | res += sprintf(buf + res, "++more++ "); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 191 | break; |
| 192 | } |
| 193 | res += sprintf(buf + res, "%s ", slave->dev->name); |
| 194 | } |
dingtianhong | 4d1ae5f | 2013-10-15 16:28:42 +0800 | [diff] [blame^] | 195 | |
| 196 | rtnl_unlock(); |
| 197 | |
Wagner Ferenc | 1dcdcd6 | 2007-12-06 23:40:31 -0800 | [diff] [blame] | 198 | if (res) |
| 199 | buf[res-1] = '\n'; /* eat the leftover space */ |
nikolay@redhat.com | dec1e90 | 2013-08-01 16:54:47 +0200 | [diff] [blame] | 200 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 201 | return res; |
| 202 | } |
| 203 | |
| 204 | /* |
Veaceslav Falico | d6641cc | 2013-05-28 01:26:13 +0000 | [diff] [blame] | 205 | * Set the slaves in the current bond. |
Jiri Pirko | f9f3545 | 2010-05-18 05:46:39 +0000 | [diff] [blame] | 206 | * This is supposed to be only thin wrapper for bond_enslave and bond_release. |
| 207 | * All hard work should be done there. |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 208 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 209 | static ssize_t bonding_store_slaves(struct device *d, |
| 210 | struct device_attribute *attr, |
| 211 | const char *buffer, size_t count) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 212 | { |
| 213 | char command[IFNAMSIZ + 1] = { 0, }; |
| 214 | char *ifname; |
Jiri Pirko | f9f3545 | 2010-05-18 05:46:39 +0000 | [diff] [blame] | 215 | int res, ret = count; |
| 216 | struct net_device *dev; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 217 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 218 | |
Eric W. Biederman | 496a60c | 2009-05-13 17:02:50 +0000 | [diff] [blame] | 219 | if (!rtnl_trylock()) |
| 220 | return restart_syscall(); |
Jay Vosburgh | 027ea04 | 2008-01-17 16:25:02 -0800 | [diff] [blame] | 221 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 222 | sscanf(buffer, "%16s", command); /* IFNAMSIZ*/ |
| 223 | ifname = command + 1; |
| 224 | if ((strlen(command) <= 1) || |
| 225 | !dev_valid_name(ifname)) |
| 226 | goto err_no_cmd; |
| 227 | |
Jiri Pirko | f9f3545 | 2010-05-18 05:46:39 +0000 | [diff] [blame] | 228 | dev = __dev_get_by_name(dev_net(bond->dev), ifname); |
| 229 | if (!dev) { |
| 230 | pr_info("%s: Interface %s does not exist!\n", |
| 231 | bond->dev->name, ifname); |
| 232 | ret = -ENODEV; |
| 233 | goto out; |
| 234 | } |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 235 | |
Jiri Pirko | f9f3545 | 2010-05-18 05:46:39 +0000 | [diff] [blame] | 236 | switch (command[0]) { |
| 237 | case '+': |
| 238 | pr_info("%s: Adding slave %s.\n", bond->dev->name, dev->name); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 239 | res = bond_enslave(bond->dev, dev); |
Jiri Pirko | f9f3545 | 2010-05-18 05:46:39 +0000 | [diff] [blame] | 240 | break; |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 241 | |
Jiri Pirko | f9f3545 | 2010-05-18 05:46:39 +0000 | [diff] [blame] | 242 | case '-': |
| 243 | pr_info("%s: Removing slave %s.\n", bond->dev->name, dev->name); |
| 244 | res = bond_release(bond->dev, dev); |
| 245 | break; |
| 246 | |
| 247 | default: |
| 248 | goto err_no_cmd; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 249 | } |
| 250 | |
Jiri Pirko | f9f3545 | 2010-05-18 05:46:39 +0000 | [diff] [blame] | 251 | if (res) |
| 252 | ret = res; |
| 253 | goto out; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 254 | |
| 255 | err_no_cmd: |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 256 | pr_err("no command found in slaves file for bond %s. Use +ifname or -ifname.\n", |
| 257 | bond->dev->name); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 258 | ret = -EPERM; |
| 259 | |
| 260 | out: |
Jay Vosburgh | 027ea04 | 2008-01-17 16:25:02 -0800 | [diff] [blame] | 261 | rtnl_unlock(); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 262 | return ret; |
| 263 | } |
| 264 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 265 | static DEVICE_ATTR(slaves, S_IRUGO | S_IWUSR, bonding_show_slaves, |
| 266 | bonding_store_slaves); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 267 | |
| 268 | /* |
| 269 | * Show and set the bonding mode. The bond interface must be down to |
| 270 | * change the mode. |
| 271 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 272 | static ssize_t bonding_show_mode(struct device *d, |
| 273 | struct device_attribute *attr, char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 274 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 275 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 276 | |
| 277 | return sprintf(buf, "%s %d\n", |
| 278 | bond_mode_tbl[bond->params.mode].modename, |
Wagner Ferenc | 7bd4650 | 2007-12-06 23:40:28 -0800 | [diff] [blame] | 279 | bond->params.mode); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 280 | } |
| 281 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 282 | static ssize_t bonding_store_mode(struct device *d, |
| 283 | struct device_attribute *attr, |
| 284 | const char *buf, size_t count) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 285 | { |
| 286 | int new_value, ret = count; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 287 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 288 | |
nikolay@redhat.com | ea6836d | 2013-05-18 01:18:28 +0000 | [diff] [blame] | 289 | if (!rtnl_trylock()) |
| 290 | return restart_syscall(); |
| 291 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 292 | if (bond->dev->flags & IFF_UP) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 293 | pr_err("unable to update mode of %s because interface is up.\n", |
| 294 | bond->dev->name); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 295 | ret = -EPERM; |
| 296 | goto out; |
| 297 | } |
| 298 | |
Veaceslav Falico | 0965a1f | 2013-09-25 09:20:21 +0200 | [diff] [blame] | 299 | if (bond_has_slaves(bond)) { |
Veaceslav Falico | 4a8bb7e | 2011-11-15 06:44:42 +0000 | [diff] [blame] | 300 | pr_err("unable to update mode of %s because it has slaves.\n", |
| 301 | bond->dev->name); |
| 302 | ret = -EPERM; |
| 303 | goto out; |
| 304 | } |
| 305 | |
Jay Vosburgh | ece95f7 | 2008-01-17 16:25:01 -0800 | [diff] [blame] | 306 | new_value = bond_parse_parm(buf, bond_mode_tbl); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 307 | if (new_value < 0) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 308 | pr_err("%s: Ignoring invalid mode value %.*s.\n", |
| 309 | bond->dev->name, (int)strlen(buf) - 1, buf); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 310 | ret = -EINVAL; |
| 311 | goto out; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 312 | } |
Andy Gospodarek | c5cb002 | 2010-07-28 15:13:56 +0000 | [diff] [blame] | 313 | if ((new_value == BOND_MODE_ALB || |
| 314 | new_value == BOND_MODE_TLB) && |
| 315 | bond->params.arp_interval) { |
| 316 | pr_err("%s: %s mode is incompatible with arp monitoring.\n", |
| 317 | bond->dev->name, bond_mode_tbl[new_value].modename); |
| 318 | ret = -EINVAL; |
| 319 | goto out; |
| 320 | } |
Andy Gospodarek | c5cb002 | 2010-07-28 15:13:56 +0000 | [diff] [blame] | 321 | |
nikolay@redhat.com | 5bb9e0b | 2013-09-07 00:00:26 +0200 | [diff] [blame] | 322 | /* don't cache arp_validate between modes */ |
| 323 | bond->params.arp_validate = BOND_ARP_VALIDATE_NONE; |
Andy Gospodarek | c5cb002 | 2010-07-28 15:13:56 +0000 | [diff] [blame] | 324 | bond->params.mode = new_value; |
Andy Gospodarek | c5cb002 | 2010-07-28 15:13:56 +0000 | [diff] [blame] | 325 | pr_info("%s: setting mode to %s (%d).\n", |
| 326 | bond->dev->name, bond_mode_tbl[new_value].modename, |
| 327 | new_value); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 328 | out: |
nikolay@redhat.com | ea6836d | 2013-05-18 01:18:28 +0000 | [diff] [blame] | 329 | rtnl_unlock(); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 330 | return ret; |
| 331 | } |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 332 | static DEVICE_ATTR(mode, S_IRUGO | S_IWUSR, |
| 333 | bonding_show_mode, bonding_store_mode); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 334 | |
| 335 | /* |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 336 | * Show and set the bonding transmit hash method. |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 337 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 338 | static ssize_t bonding_show_xmit_hash(struct device *d, |
| 339 | struct device_attribute *attr, |
| 340 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 341 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 342 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 343 | |
Wagner Ferenc | 8e4b932 | 2007-12-06 23:40:32 -0800 | [diff] [blame] | 344 | return sprintf(buf, "%s %d\n", |
| 345 | xmit_hashtype_tbl[bond->params.xmit_policy].modename, |
| 346 | bond->params.xmit_policy); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 347 | } |
| 348 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 349 | static ssize_t bonding_store_xmit_hash(struct device *d, |
| 350 | struct device_attribute *attr, |
| 351 | const char *buf, size_t count) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 352 | { |
| 353 | int new_value, ret = count; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 354 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 355 | |
Jay Vosburgh | ece95f7 | 2008-01-17 16:25:01 -0800 | [diff] [blame] | 356 | new_value = bond_parse_parm(buf, xmit_hashtype_tbl); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 357 | if (new_value < 0) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 358 | pr_err("%s: Ignoring invalid xmit hash policy value %.*s.\n", |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 359 | bond->dev->name, |
| 360 | (int)strlen(buf) - 1, buf); |
| 361 | ret = -EINVAL; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 362 | } else { |
| 363 | bond->params.xmit_policy = new_value; |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 364 | pr_info("%s: setting xmit hash policy to %s (%d).\n", |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 365 | bond->dev->name, |
| 366 | xmit_hashtype_tbl[new_value].modename, new_value); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 367 | } |
Nikolay Aleksandrov | 53edee2 | 2013-05-24 00:59:47 +0000 | [diff] [blame] | 368 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 369 | return ret; |
| 370 | } |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 371 | static DEVICE_ATTR(xmit_hash_policy, S_IRUGO | S_IWUSR, |
| 372 | bonding_show_xmit_hash, bonding_store_xmit_hash); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 373 | |
| 374 | /* |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 375 | * Show and set arp_validate. |
| 376 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 377 | static ssize_t bonding_show_arp_validate(struct device *d, |
| 378 | struct device_attribute *attr, |
| 379 | char *buf) |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 380 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 381 | struct bonding *bond = to_bond(d); |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 382 | |
| 383 | return sprintf(buf, "%s %d\n", |
| 384 | arp_validate_tbl[bond->params.arp_validate].modename, |
Wagner Ferenc | 7bd4650 | 2007-12-06 23:40:28 -0800 | [diff] [blame] | 385 | bond->params.arp_validate); |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 386 | } |
| 387 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 388 | static ssize_t bonding_store_arp_validate(struct device *d, |
| 389 | struct device_attribute *attr, |
| 390 | const char *buf, size_t count) |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 391 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 392 | struct bonding *bond = to_bond(d); |
nikolay@redhat.com | 5bb9e0b | 2013-09-07 00:00:26 +0200 | [diff] [blame] | 393 | int new_value, ret = count; |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 394 | |
nikolay@redhat.com | 5c5038d | 2013-09-07 00:00:25 +0200 | [diff] [blame] | 395 | if (!rtnl_trylock()) |
| 396 | return restart_syscall(); |
Jay Vosburgh | ece95f7 | 2008-01-17 16:25:01 -0800 | [diff] [blame] | 397 | new_value = bond_parse_parm(buf, arp_validate_tbl); |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 398 | if (new_value < 0) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 399 | pr_err("%s: Ignoring invalid arp_validate value %s\n", |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 400 | bond->dev->name, buf); |
nikolay@redhat.com | 5c5038d | 2013-09-07 00:00:25 +0200 | [diff] [blame] | 401 | ret = -EINVAL; |
| 402 | goto out; |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 403 | } |
nikolay@redhat.com | 5bb9e0b | 2013-09-07 00:00:26 +0200 | [diff] [blame] | 404 | if (bond->params.mode != BOND_MODE_ACTIVEBACKUP) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 405 | pr_err("%s: arp_validate only supported in active-backup mode.\n", |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 406 | bond->dev->name); |
nikolay@redhat.com | 5c5038d | 2013-09-07 00:00:25 +0200 | [diff] [blame] | 407 | ret = -EINVAL; |
| 408 | goto out; |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 409 | } |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 410 | pr_info("%s: setting arp_validate to %s (%d).\n", |
| 411 | bond->dev->name, arp_validate_tbl[new_value].modename, |
| 412 | new_value); |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 413 | |
nikolay@redhat.com | 5bb9e0b | 2013-09-07 00:00:26 +0200 | [diff] [blame] | 414 | if (bond->dev->flags & IFF_UP) { |
| 415 | if (!new_value) |
| 416 | bond->recv_probe = NULL; |
| 417 | else if (bond->params.arp_interval) |
| 418 | bond->recv_probe = bond_arp_rcv; |
| 419 | } |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 420 | bond->params.arp_validate = new_value; |
nikolay@redhat.com | 5c5038d | 2013-09-07 00:00:25 +0200 | [diff] [blame] | 421 | out: |
| 422 | rtnl_unlock(); |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 423 | |
nikolay@redhat.com | 5c5038d | 2013-09-07 00:00:25 +0200 | [diff] [blame] | 424 | return ret; |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 425 | } |
| 426 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 427 | static DEVICE_ATTR(arp_validate, S_IRUGO | S_IWUSR, bonding_show_arp_validate, |
| 428 | bonding_store_arp_validate); |
Veaceslav Falico | 8599b52 | 2013-06-24 11:49:34 +0200 | [diff] [blame] | 429 | /* |
| 430 | * Show and set arp_all_targets. |
| 431 | */ |
| 432 | static ssize_t bonding_show_arp_all_targets(struct device *d, |
| 433 | struct device_attribute *attr, |
| 434 | char *buf) |
| 435 | { |
| 436 | struct bonding *bond = to_bond(d); |
| 437 | int value = bond->params.arp_all_targets; |
| 438 | |
| 439 | return sprintf(buf, "%s %d\n", arp_all_targets_tbl[value].modename, |
| 440 | value); |
| 441 | } |
| 442 | |
| 443 | static ssize_t bonding_store_arp_all_targets(struct device *d, |
| 444 | struct device_attribute *attr, |
| 445 | const char *buf, size_t count) |
| 446 | { |
| 447 | struct bonding *bond = to_bond(d); |
| 448 | int new_value; |
| 449 | |
| 450 | new_value = bond_parse_parm(buf, arp_all_targets_tbl); |
| 451 | if (new_value < 0) { |
| 452 | pr_err("%s: Ignoring invalid arp_all_targets value %s\n", |
| 453 | bond->dev->name, buf); |
| 454 | return -EINVAL; |
| 455 | } |
| 456 | pr_info("%s: setting arp_all_targets to %s (%d).\n", |
| 457 | bond->dev->name, arp_all_targets_tbl[new_value].modename, |
| 458 | new_value); |
| 459 | |
| 460 | bond->params.arp_all_targets = new_value; |
| 461 | |
| 462 | return count; |
| 463 | } |
| 464 | |
| 465 | static DEVICE_ATTR(arp_all_targets, S_IRUGO | S_IWUSR, |
| 466 | bonding_show_arp_all_targets, bonding_store_arp_all_targets); |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 467 | |
| 468 | /* |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 469 | * Show and store fail_over_mac. User only allowed to change the |
| 470 | * value when there are no slaves. |
| 471 | */ |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 472 | static ssize_t bonding_show_fail_over_mac(struct device *d, |
| 473 | struct device_attribute *attr, |
| 474 | char *buf) |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 475 | { |
| 476 | struct bonding *bond = to_bond(d); |
| 477 | |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 478 | return sprintf(buf, "%s %d\n", |
| 479 | fail_over_mac_tbl[bond->params.fail_over_mac].modename, |
| 480 | bond->params.fail_over_mac); |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 481 | } |
| 482 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 483 | static ssize_t bonding_store_fail_over_mac(struct device *d, |
| 484 | struct device_attribute *attr, |
| 485 | const char *buf, size_t count) |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 486 | { |
dingtianhong | 9402b74 | 2013-07-23 15:25:39 +0800 | [diff] [blame] | 487 | int new_value, ret = count; |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 488 | struct bonding *bond = to_bond(d); |
| 489 | |
dingtianhong | 9402b74 | 2013-07-23 15:25:39 +0800 | [diff] [blame] | 490 | if (!rtnl_trylock()) |
| 491 | return restart_syscall(); |
| 492 | |
Veaceslav Falico | 0965a1f | 2013-09-25 09:20:21 +0200 | [diff] [blame] | 493 | if (bond_has_slaves(bond)) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 494 | pr_err("%s: Can't alter fail_over_mac with slaves in bond.\n", |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 495 | bond->dev->name); |
dingtianhong | 9402b74 | 2013-07-23 15:25:39 +0800 | [diff] [blame] | 496 | ret = -EPERM; |
| 497 | goto out; |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 498 | } |
| 499 | |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 500 | new_value = bond_parse_parm(buf, fail_over_mac_tbl); |
| 501 | if (new_value < 0) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 502 | pr_err("%s: Ignoring invalid fail_over_mac value %s.\n", |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 503 | bond->dev->name, buf); |
dingtianhong | 9402b74 | 2013-07-23 15:25:39 +0800 | [diff] [blame] | 504 | ret = -EINVAL; |
| 505 | goto out; |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 506 | } |
| 507 | |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 508 | bond->params.fail_over_mac = new_value; |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 509 | pr_info("%s: Setting fail_over_mac to %s (%d).\n", |
| 510 | bond->dev->name, fail_over_mac_tbl[new_value].modename, |
| 511 | new_value); |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 512 | |
dingtianhong | 9402b74 | 2013-07-23 15:25:39 +0800 | [diff] [blame] | 513 | out: |
| 514 | rtnl_unlock(); |
| 515 | return ret; |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 516 | } |
| 517 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 518 | static DEVICE_ATTR(fail_over_mac, S_IRUGO | S_IWUSR, |
| 519 | bonding_show_fail_over_mac, bonding_store_fail_over_mac); |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 520 | |
| 521 | /* |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 522 | * Show and set the arp timer interval. There are two tricky bits |
| 523 | * here. First, if ARP monitoring is activated, then we must disable |
| 524 | * MII monitoring. Second, if the ARP timer isn't running, we must |
| 525 | * start it. |
| 526 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 527 | static ssize_t bonding_show_arp_interval(struct device *d, |
| 528 | struct device_attribute *attr, |
| 529 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 530 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 531 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 532 | |
Wagner Ferenc | 7bd4650 | 2007-12-06 23:40:28 -0800 | [diff] [blame] | 533 | return sprintf(buf, "%d\n", bond->params.arp_interval); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 534 | } |
| 535 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 536 | static ssize_t bonding_store_arp_interval(struct device *d, |
| 537 | struct device_attribute *attr, |
| 538 | const char *buf, size_t count) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 539 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 540 | struct bonding *bond = to_bond(d); |
nikolay@redhat.com | 5bb9e0b | 2013-09-07 00:00:26 +0200 | [diff] [blame] | 541 | int new_value, ret = count; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 542 | |
nikolay@redhat.com | fbb0c41 | 2012-11-29 01:31:31 +0000 | [diff] [blame] | 543 | if (!rtnl_trylock()) |
| 544 | return restart_syscall(); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 545 | if (sscanf(buf, "%d", &new_value) != 1) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 546 | pr_err("%s: no arp_interval value specified.\n", |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 547 | bond->dev->name); |
| 548 | ret = -EINVAL; |
| 549 | goto out; |
| 550 | } |
| 551 | if (new_value < 0) { |
nikolay@redhat.com | 1bc7db1 | 2013-03-27 03:32:41 +0000 | [diff] [blame] | 552 | pr_err("%s: Invalid arp_interval value %d not in range 0-%d; rejected.\n", |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 553 | bond->dev->name, new_value, INT_MAX); |
| 554 | ret = -EINVAL; |
| 555 | goto out; |
| 556 | } |
Andy Gospodarek | c5cb002 | 2010-07-28 15:13:56 +0000 | [diff] [blame] | 557 | if (bond->params.mode == BOND_MODE_ALB || |
| 558 | bond->params.mode == BOND_MODE_TLB) { |
| 559 | pr_info("%s: ARP monitoring cannot be used with ALB/TLB. Only MII monitoring is supported on %s.\n", |
| 560 | bond->dev->name, bond->dev->name); |
| 561 | ret = -EINVAL; |
| 562 | goto out; |
| 563 | } |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 564 | pr_info("%s: Setting ARP monitoring interval to %d.\n", |
| 565 | bond->dev->name, new_value); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 566 | bond->params.arp_interval = new_value; |
nikolay@redhat.com | 1bc7db1 | 2013-03-27 03:32:41 +0000 | [diff] [blame] | 567 | if (new_value) { |
| 568 | if (bond->params.miimon) { |
| 569 | pr_info("%s: ARP monitoring cannot be used with MII monitoring. %s Disabling MII monitoring.\n", |
| 570 | bond->dev->name, bond->dev->name); |
| 571 | bond->params.miimon = 0; |
| 572 | } |
| 573 | if (!bond->params.arp_targets[0]) |
| 574 | pr_info("%s: ARP monitoring has been set up, but no ARP targets have been specified.\n", |
| 575 | bond->dev->name); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 576 | } |
| 577 | if (bond->dev->flags & IFF_UP) { |
| 578 | /* If the interface is up, we may need to fire off |
| 579 | * the ARP timer. If the interface is down, the |
| 580 | * timer will get fired off when the open function |
| 581 | * is called. |
| 582 | */ |
nikolay@redhat.com | 1bc7db1 | 2013-03-27 03:32:41 +0000 | [diff] [blame] | 583 | if (!new_value) { |
nikolay@redhat.com | 5bb9e0b | 2013-09-07 00:00:26 +0200 | [diff] [blame] | 584 | if (bond->params.arp_validate) |
| 585 | bond->recv_probe = NULL; |
nikolay@redhat.com | 1bc7db1 | 2013-03-27 03:32:41 +0000 | [diff] [blame] | 586 | cancel_delayed_work_sync(&bond->arp_work); |
| 587 | } else { |
nikolay@redhat.com | 5bb9e0b | 2013-09-07 00:00:26 +0200 | [diff] [blame] | 588 | /* arp_validate can be set only in active-backup mode */ |
| 589 | if (bond->params.arp_validate) |
| 590 | bond->recv_probe = bond_arp_rcv; |
nikolay@redhat.com | 1bc7db1 | 2013-03-27 03:32:41 +0000 | [diff] [blame] | 591 | cancel_delayed_work_sync(&bond->mii_work); |
| 592 | queue_delayed_work(bond->wq, &bond->arp_work, 0); |
| 593 | } |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 594 | } |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 595 | out: |
nikolay@redhat.com | fbb0c41 | 2012-11-29 01:31:31 +0000 | [diff] [blame] | 596 | rtnl_unlock(); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 597 | return ret; |
| 598 | } |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 599 | static DEVICE_ATTR(arp_interval, S_IRUGO | S_IWUSR, |
| 600 | bonding_show_arp_interval, bonding_store_arp_interval); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 601 | |
| 602 | /* |
| 603 | * Show and set the arp targets. |
| 604 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 605 | static ssize_t bonding_show_arp_targets(struct device *d, |
| 606 | struct device_attribute *attr, |
| 607 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 608 | { |
| 609 | int i, res = 0; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 610 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 611 | |
| 612 | for (i = 0; i < BOND_MAX_ARP_TARGETS; i++) { |
| 613 | if (bond->params.arp_targets[i]) |
Harvey Harrison | 6377943 | 2008-10-31 00:56:00 -0700 | [diff] [blame] | 614 | res += sprintf(buf + res, "%pI4 ", |
| 615 | &bond->params.arp_targets[i]); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 616 | } |
Wagner Ferenc | 1dcdcd6 | 2007-12-06 23:40:31 -0800 | [diff] [blame] | 617 | if (res) |
| 618 | buf[res-1] = '\n'; /* eat the leftover space */ |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 619 | return res; |
| 620 | } |
| 621 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 622 | static ssize_t bonding_store_arp_targets(struct device *d, |
| 623 | struct device_attribute *attr, |
| 624 | const char *buf, size_t count) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 625 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 626 | struct bonding *bond = to_bond(d); |
Veaceslav Falico | 9caff1e7 | 2013-09-25 09:20:14 +0200 | [diff] [blame] | 627 | struct list_head *iter; |
Veaceslav Falico | 8599b52 | 2013-06-24 11:49:34 +0200 | [diff] [blame] | 628 | struct slave *slave; |
| 629 | __be32 newtarget, *targets; |
| 630 | unsigned long *targets_rx; |
| 631 | int ind, i, j, ret = -EINVAL; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 632 | |
dingtianhong | 4d1ae5f | 2013-10-15 16:28:42 +0800 | [diff] [blame^] | 633 | if (!rtnl_trylock()) |
| 634 | return restart_syscall(); |
| 635 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 636 | targets = bond->params.arp_targets; |
| 637 | newtarget = in_aton(buf + 1); |
| 638 | /* look for adds */ |
| 639 | if (buf[0] == '+') { |
Al Viro | d3bb52b | 2007-08-22 20:06:58 -0400 | [diff] [blame] | 640 | if ((newtarget == 0) || (newtarget == htonl(INADDR_BROADCAST))) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 641 | pr_err("%s: invalid ARP target %pI4 specified for addition\n", |
Harvey Harrison | 6377943 | 2008-10-31 00:56:00 -0700 | [diff] [blame] | 642 | bond->dev->name, &newtarget); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 643 | goto out; |
| 644 | } |
| 645 | |
Veaceslav Falico | 87a7b84 | 2013-06-24 11:49:29 +0200 | [diff] [blame] | 646 | if (bond_get_targets_ip(targets, newtarget) != -1) { /* dup */ |
| 647 | pr_err("%s: ARP target %pI4 is already present\n", |
| 648 | bond->dev->name, &newtarget); |
| 649 | goto out; |
| 650 | } |
| 651 | |
Veaceslav Falico | 8599b52 | 2013-06-24 11:49:34 +0200 | [diff] [blame] | 652 | ind = bond_get_targets_ip(targets, 0); /* first free slot */ |
| 653 | if (ind == -1) { |
Veaceslav Falico | 87a7b84 | 2013-06-24 11:49:29 +0200 | [diff] [blame] | 654 | pr_err("%s: ARP target table is full!\n", |
| 655 | bond->dev->name); |
| 656 | goto out; |
| 657 | } |
| 658 | |
| 659 | pr_info("%s: adding ARP target %pI4.\n", bond->dev->name, |
| 660 | &newtarget); |
Veaceslav Falico | 8599b52 | 2013-06-24 11:49:34 +0200 | [diff] [blame] | 661 | /* not to race with bond_arp_rcv */ |
| 662 | write_lock_bh(&bond->lock); |
Veaceslav Falico | 9caff1e7 | 2013-09-25 09:20:14 +0200 | [diff] [blame] | 663 | bond_for_each_slave(bond, slave, iter) |
Veaceslav Falico | 8599b52 | 2013-06-24 11:49:34 +0200 | [diff] [blame] | 664 | slave->target_last_arp_rx[ind] = jiffies; |
| 665 | targets[ind] = newtarget; |
| 666 | write_unlock_bh(&bond->lock); |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 667 | } else if (buf[0] == '-') { |
Al Viro | d3bb52b | 2007-08-22 20:06:58 -0400 | [diff] [blame] | 668 | if ((newtarget == 0) || (newtarget == htonl(INADDR_BROADCAST))) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 669 | pr_err("%s: invalid ARP target %pI4 specified for removal\n", |
Harvey Harrison | 6377943 | 2008-10-31 00:56:00 -0700 | [diff] [blame] | 670 | bond->dev->name, &newtarget); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 671 | goto out; |
| 672 | } |
| 673 | |
Veaceslav Falico | 8599b52 | 2013-06-24 11:49:34 +0200 | [diff] [blame] | 674 | ind = bond_get_targets_ip(targets, newtarget); |
| 675 | if (ind == -1) { |
| 676 | pr_err("%s: unable to remove nonexistent ARP target %pI4.\n", |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 677 | bond->dev->name, &newtarget); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 678 | goto out; |
| 679 | } |
Veaceslav Falico | 87a7b84 | 2013-06-24 11:49:29 +0200 | [diff] [blame] | 680 | |
Veaceslav Falico | 8599b52 | 2013-06-24 11:49:34 +0200 | [diff] [blame] | 681 | if (ind == 0 && !targets[1] && bond->params.arp_interval) |
| 682 | pr_warn("%s: removing last arp target with arp_interval on\n", |
| 683 | bond->dev->name); |
| 684 | |
Veaceslav Falico | 87a7b84 | 2013-06-24 11:49:29 +0200 | [diff] [blame] | 685 | pr_info("%s: removing ARP target %pI4.\n", bond->dev->name, |
| 686 | &newtarget); |
Veaceslav Falico | 8599b52 | 2013-06-24 11:49:34 +0200 | [diff] [blame] | 687 | |
| 688 | write_lock_bh(&bond->lock); |
Veaceslav Falico | 9caff1e7 | 2013-09-25 09:20:14 +0200 | [diff] [blame] | 689 | bond_for_each_slave(bond, slave, iter) { |
Veaceslav Falico | 8599b52 | 2013-06-24 11:49:34 +0200 | [diff] [blame] | 690 | targets_rx = slave->target_last_arp_rx; |
| 691 | j = ind; |
| 692 | for (; (j < BOND_MAX_ARP_TARGETS-1) && targets[j+1]; j++) |
| 693 | targets_rx[j] = targets_rx[j+1]; |
| 694 | targets_rx[j] = 0; |
| 695 | } |
| 696 | for (i = ind; (i < BOND_MAX_ARP_TARGETS-1) && targets[i+1]; i++) |
Veaceslav Falico | 87a7b84 | 2013-06-24 11:49:29 +0200 | [diff] [blame] | 697 | targets[i] = targets[i+1]; |
| 698 | targets[i] = 0; |
Veaceslav Falico | 8599b52 | 2013-06-24 11:49:34 +0200 | [diff] [blame] | 699 | write_unlock_bh(&bond->lock); |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 700 | } else { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 701 | pr_err("no command found in arp_ip_targets file for bond %s. Use +<addr> or -<addr>.\n", |
| 702 | bond->dev->name); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 703 | ret = -EPERM; |
| 704 | goto out; |
| 705 | } |
| 706 | |
Veaceslav Falico | 87a7b84 | 2013-06-24 11:49:29 +0200 | [diff] [blame] | 707 | ret = count; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 708 | out: |
dingtianhong | 4d1ae5f | 2013-10-15 16:28:42 +0800 | [diff] [blame^] | 709 | rtnl_unlock(); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 710 | return ret; |
| 711 | } |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 712 | static DEVICE_ATTR(arp_ip_target, S_IRUGO | S_IWUSR , bonding_show_arp_targets, bonding_store_arp_targets); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 713 | |
| 714 | /* |
| 715 | * Show and set the up and down delays. These must be multiples of the |
| 716 | * MII monitoring value, and are stored internally as the multiplier. |
| 717 | * Thus, we must translate to MS for the real world. |
| 718 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 719 | static ssize_t bonding_show_downdelay(struct device *d, |
| 720 | struct device_attribute *attr, |
| 721 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 722 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 723 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 724 | |
Wagner Ferenc | 7bd4650 | 2007-12-06 23:40:28 -0800 | [diff] [blame] | 725 | return sprintf(buf, "%d\n", bond->params.downdelay * bond->params.miimon); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 726 | } |
| 727 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 728 | static ssize_t bonding_store_downdelay(struct device *d, |
| 729 | struct device_attribute *attr, |
| 730 | const char *buf, size_t count) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 731 | { |
| 732 | int new_value, ret = count; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 733 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 734 | |
| 735 | if (!(bond->params.miimon)) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 736 | pr_err("%s: Unable to set down delay as MII monitoring is disabled\n", |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 737 | bond->dev->name); |
| 738 | ret = -EPERM; |
| 739 | goto out; |
| 740 | } |
| 741 | |
| 742 | if (sscanf(buf, "%d", &new_value) != 1) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 743 | pr_err("%s: no down delay value specified.\n", bond->dev->name); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 744 | ret = -EINVAL; |
| 745 | goto out; |
| 746 | } |
| 747 | if (new_value < 0) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 748 | pr_err("%s: Invalid down delay value %d not in range %d-%d; rejected.\n", |
nikolay@redhat.com | 1bc7db1 | 2013-03-27 03:32:41 +0000 | [diff] [blame] | 749 | bond->dev->name, new_value, 0, INT_MAX); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 750 | ret = -EINVAL; |
| 751 | goto out; |
| 752 | } else { |
| 753 | if ((new_value % bond->params.miimon) != 0) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 754 | pr_warning("%s: Warning: down delay (%d) is not a multiple of miimon (%d), delay rounded to %d ms\n", |
Jiri Pirko | e5e2a8f | 2009-08-13 04:11:52 +0000 | [diff] [blame] | 755 | bond->dev->name, new_value, |
| 756 | bond->params.miimon, |
| 757 | (new_value / bond->params.miimon) * |
| 758 | bond->params.miimon); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 759 | } |
| 760 | bond->params.downdelay = new_value / bond->params.miimon; |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 761 | pr_info("%s: Setting down delay to %d.\n", |
| 762 | bond->dev->name, |
| 763 | bond->params.downdelay * bond->params.miimon); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 764 | |
| 765 | } |
| 766 | |
| 767 | out: |
| 768 | return ret; |
| 769 | } |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 770 | static DEVICE_ATTR(downdelay, S_IRUGO | S_IWUSR, |
| 771 | bonding_show_downdelay, bonding_store_downdelay); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 772 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 773 | static ssize_t bonding_show_updelay(struct device *d, |
| 774 | struct device_attribute *attr, |
| 775 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 776 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 777 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 778 | |
Wagner Ferenc | 7bd4650 | 2007-12-06 23:40:28 -0800 | [diff] [blame] | 779 | return sprintf(buf, "%d\n", bond->params.updelay * bond->params.miimon); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 780 | |
| 781 | } |
| 782 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 783 | static ssize_t bonding_store_updelay(struct device *d, |
| 784 | struct device_attribute *attr, |
| 785 | const char *buf, size_t count) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 786 | { |
| 787 | int new_value, ret = count; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 788 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 789 | |
| 790 | if (!(bond->params.miimon)) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 791 | pr_err("%s: Unable to set up delay as MII monitoring is disabled\n", |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 792 | bond->dev->name); |
| 793 | ret = -EPERM; |
| 794 | goto out; |
| 795 | } |
| 796 | |
| 797 | if (sscanf(buf, "%d", &new_value) != 1) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 798 | pr_err("%s: no up delay value specified.\n", |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 799 | bond->dev->name); |
| 800 | ret = -EINVAL; |
| 801 | goto out; |
| 802 | } |
| 803 | if (new_value < 0) { |
nikolay@redhat.com | 1bc7db1 | 2013-03-27 03:32:41 +0000 | [diff] [blame] | 804 | pr_err("%s: Invalid up delay value %d not in range %d-%d; rejected.\n", |
| 805 | bond->dev->name, new_value, 0, INT_MAX); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 806 | ret = -EINVAL; |
| 807 | goto out; |
| 808 | } else { |
| 809 | if ((new_value % bond->params.miimon) != 0) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 810 | pr_warning("%s: Warning: up delay (%d) is not a multiple of miimon (%d), updelay rounded to %d ms\n", |
Jiri Pirko | e5e2a8f | 2009-08-13 04:11:52 +0000 | [diff] [blame] | 811 | bond->dev->name, new_value, |
| 812 | bond->params.miimon, |
| 813 | (new_value / bond->params.miimon) * |
| 814 | bond->params.miimon); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 815 | } |
| 816 | bond->params.updelay = new_value / bond->params.miimon; |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 817 | pr_info("%s: Setting up delay to %d.\n", |
| 818 | bond->dev->name, |
| 819 | bond->params.updelay * bond->params.miimon); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 820 | } |
| 821 | |
| 822 | out: |
| 823 | return ret; |
| 824 | } |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 825 | static DEVICE_ATTR(updelay, S_IRUGO | S_IWUSR, |
| 826 | bonding_show_updelay, bonding_store_updelay); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 827 | |
| 828 | /* |
| 829 | * Show and set the LACP interval. Interface must be down, and the mode |
| 830 | * must be set to 802.3ad mode. |
| 831 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 832 | static ssize_t bonding_show_lacp(struct device *d, |
| 833 | struct device_attribute *attr, |
| 834 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 835 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 836 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 837 | |
| 838 | return sprintf(buf, "%s %d\n", |
| 839 | bond_lacp_tbl[bond->params.lacp_fast].modename, |
Wagner Ferenc | 7bd4650 | 2007-12-06 23:40:28 -0800 | [diff] [blame] | 840 | bond->params.lacp_fast); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 841 | } |
| 842 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 843 | static ssize_t bonding_store_lacp(struct device *d, |
| 844 | struct device_attribute *attr, |
| 845 | const char *buf, size_t count) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 846 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 847 | struct bonding *bond = to_bond(d); |
nikolay@redhat.com | c509316 | 2013-09-02 13:51:40 +0200 | [diff] [blame] | 848 | int new_value, ret = count; |
| 849 | |
| 850 | if (!rtnl_trylock()) |
| 851 | return restart_syscall(); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 852 | |
| 853 | if (bond->dev->flags & IFF_UP) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 854 | pr_err("%s: Unable to update LACP rate because interface is up.\n", |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 855 | bond->dev->name); |
| 856 | ret = -EPERM; |
| 857 | goto out; |
| 858 | } |
| 859 | |
| 860 | if (bond->params.mode != BOND_MODE_8023AD) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 861 | pr_err("%s: Unable to update LACP rate because bond is not in 802.3ad mode.\n", |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 862 | bond->dev->name); |
| 863 | ret = -EPERM; |
| 864 | goto out; |
| 865 | } |
| 866 | |
Jay Vosburgh | ece95f7 | 2008-01-17 16:25:01 -0800 | [diff] [blame] | 867 | new_value = bond_parse_parm(buf, bond_lacp_tbl); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 868 | |
| 869 | if ((new_value == 1) || (new_value == 0)) { |
| 870 | bond->params.lacp_fast = new_value; |
Peter Pan(潘卫平) | ba824a8 | 2011-06-08 21:19:01 +0000 | [diff] [blame] | 871 | bond_3ad_update_lacp_rate(bond); |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 872 | pr_info("%s: Setting LACP rate to %s (%d).\n", |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 873 | bond->dev->name, bond_lacp_tbl[new_value].modename, |
| 874 | new_value); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 875 | } else { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 876 | pr_err("%s: Ignoring invalid LACP rate value %.*s.\n", |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 877 | bond->dev->name, (int)strlen(buf) - 1, buf); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 878 | ret = -EINVAL; |
| 879 | } |
| 880 | out: |
nikolay@redhat.com | c509316 | 2013-09-02 13:51:40 +0200 | [diff] [blame] | 881 | rtnl_unlock(); |
| 882 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 883 | return ret; |
| 884 | } |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 885 | static DEVICE_ATTR(lacp_rate, S_IRUGO | S_IWUSR, |
| 886 | bonding_show_lacp, bonding_store_lacp); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 887 | |
stephen hemminger | 655f891 | 2011-06-22 09:54:39 +0000 | [diff] [blame] | 888 | static ssize_t bonding_show_min_links(struct device *d, |
| 889 | struct device_attribute *attr, |
| 890 | char *buf) |
| 891 | { |
| 892 | struct bonding *bond = to_bond(d); |
| 893 | |
| 894 | return sprintf(buf, "%d\n", bond->params.min_links); |
| 895 | } |
| 896 | |
| 897 | static ssize_t bonding_store_min_links(struct device *d, |
| 898 | struct device_attribute *attr, |
| 899 | const char *buf, size_t count) |
| 900 | { |
| 901 | struct bonding *bond = to_bond(d); |
| 902 | int ret; |
| 903 | unsigned int new_value; |
| 904 | |
| 905 | ret = kstrtouint(buf, 0, &new_value); |
| 906 | if (ret < 0) { |
| 907 | pr_err("%s: Ignoring invalid min links value %s.\n", |
| 908 | bond->dev->name, buf); |
| 909 | return ret; |
| 910 | } |
| 911 | |
| 912 | pr_info("%s: Setting min links value to %u\n", |
| 913 | bond->dev->name, new_value); |
| 914 | bond->params.min_links = new_value; |
| 915 | return count; |
| 916 | } |
| 917 | static DEVICE_ATTR(min_links, S_IRUGO | S_IWUSR, |
| 918 | bonding_show_min_links, bonding_store_min_links); |
| 919 | |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 920 | static ssize_t bonding_show_ad_select(struct device *d, |
| 921 | struct device_attribute *attr, |
| 922 | char *buf) |
| 923 | { |
| 924 | struct bonding *bond = to_bond(d); |
| 925 | |
| 926 | return sprintf(buf, "%s %d\n", |
| 927 | ad_select_tbl[bond->params.ad_select].modename, |
| 928 | bond->params.ad_select); |
| 929 | } |
| 930 | |
| 931 | |
| 932 | static ssize_t bonding_store_ad_select(struct device *d, |
| 933 | struct device_attribute *attr, |
| 934 | const char *buf, size_t count) |
| 935 | { |
| 936 | int new_value, ret = count; |
| 937 | struct bonding *bond = to_bond(d); |
| 938 | |
| 939 | if (bond->dev->flags & IFF_UP) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 940 | pr_err("%s: Unable to update ad_select because interface is up.\n", |
| 941 | bond->dev->name); |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 942 | ret = -EPERM; |
| 943 | goto out; |
| 944 | } |
| 945 | |
| 946 | new_value = bond_parse_parm(buf, ad_select_tbl); |
| 947 | |
| 948 | if (new_value != -1) { |
| 949 | bond->params.ad_select = new_value; |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 950 | pr_info("%s: Setting ad_select to %s (%d).\n", |
| 951 | bond->dev->name, ad_select_tbl[new_value].modename, |
| 952 | new_value); |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 953 | } else { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 954 | pr_err("%s: Ignoring invalid ad_select value %.*s.\n", |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 955 | bond->dev->name, (int)strlen(buf) - 1, buf); |
| 956 | ret = -EINVAL; |
| 957 | } |
| 958 | out: |
| 959 | return ret; |
| 960 | } |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 961 | static DEVICE_ATTR(ad_select, S_IRUGO | S_IWUSR, |
| 962 | bonding_show_ad_select, bonding_store_ad_select); |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 963 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 964 | /* |
Ben Hutchings | ad246c9 | 2011-04-26 15:25:52 +0000 | [diff] [blame] | 965 | * Show and set the number of peer notifications to send after a failover event. |
| 966 | */ |
| 967 | static ssize_t bonding_show_num_peer_notif(struct device *d, |
| 968 | struct device_attribute *attr, |
| 969 | char *buf) |
| 970 | { |
| 971 | struct bonding *bond = to_bond(d); |
| 972 | return sprintf(buf, "%d\n", bond->params.num_peer_notif); |
| 973 | } |
| 974 | |
| 975 | static ssize_t bonding_store_num_peer_notif(struct device *d, |
| 976 | struct device_attribute *attr, |
| 977 | const char *buf, size_t count) |
| 978 | { |
| 979 | struct bonding *bond = to_bond(d); |
| 980 | int err = kstrtou8(buf, 10, &bond->params.num_peer_notif); |
| 981 | return err ? err : count; |
| 982 | } |
| 983 | static DEVICE_ATTR(num_grat_arp, S_IRUGO | S_IWUSR, |
| 984 | bonding_show_num_peer_notif, bonding_store_num_peer_notif); |
| 985 | static DEVICE_ATTR(num_unsol_na, S_IRUGO | S_IWUSR, |
| 986 | bonding_show_num_peer_notif, bonding_store_num_peer_notif); |
| 987 | |
| 988 | /* |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 989 | * Show and set the MII monitor interval. There are two tricky bits |
| 990 | * here. First, if MII monitoring is activated, then we must disable |
| 991 | * ARP monitoring. Second, if the timer isn't running, we must |
| 992 | * start it. |
| 993 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 994 | static ssize_t bonding_show_miimon(struct device *d, |
| 995 | struct device_attribute *attr, |
| 996 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 997 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 998 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 999 | |
Wagner Ferenc | 7bd4650 | 2007-12-06 23:40:28 -0800 | [diff] [blame] | 1000 | return sprintf(buf, "%d\n", bond->params.miimon); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1001 | } |
| 1002 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1003 | static ssize_t bonding_store_miimon(struct device *d, |
| 1004 | struct device_attribute *attr, |
| 1005 | const char *buf, size_t count) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1006 | { |
| 1007 | int new_value, ret = count; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1008 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1009 | |
nikolay@redhat.com | fbb0c41 | 2012-11-29 01:31:31 +0000 | [diff] [blame] | 1010 | if (!rtnl_trylock()) |
| 1011 | return restart_syscall(); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1012 | if (sscanf(buf, "%d", &new_value) != 1) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1013 | pr_err("%s: no miimon value specified.\n", |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1014 | bond->dev->name); |
| 1015 | ret = -EINVAL; |
| 1016 | goto out; |
| 1017 | } |
| 1018 | if (new_value < 0) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1019 | pr_err("%s: Invalid miimon value %d not in range %d-%d; rejected.\n", |
nikolay@redhat.com | 1bc7db1 | 2013-03-27 03:32:41 +0000 | [diff] [blame] | 1020 | bond->dev->name, new_value, 0, INT_MAX); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1021 | ret = -EINVAL; |
| 1022 | goto out; |
nikolay@redhat.com | 1bc7db1 | 2013-03-27 03:32:41 +0000 | [diff] [blame] | 1023 | } |
| 1024 | pr_info("%s: Setting MII monitoring interval to %d.\n", |
| 1025 | bond->dev->name, new_value); |
| 1026 | bond->params.miimon = new_value; |
| 1027 | if (bond->params.updelay) |
| 1028 | pr_info("%s: Note: Updating updelay (to %d) since it is a multiple of the miimon value.\n", |
| 1029 | bond->dev->name, |
| 1030 | bond->params.updelay * bond->params.miimon); |
| 1031 | if (bond->params.downdelay) |
| 1032 | pr_info("%s: Note: Updating downdelay (to %d) since it is a multiple of the miimon value.\n", |
| 1033 | bond->dev->name, |
| 1034 | bond->params.downdelay * bond->params.miimon); |
| 1035 | if (new_value && bond->params.arp_interval) { |
| 1036 | pr_info("%s: MII monitoring cannot be used with ARP monitoring. Disabling ARP monitoring...\n", |
| 1037 | bond->dev->name); |
| 1038 | bond->params.arp_interval = 0; |
| 1039 | if (bond->params.arp_validate) |
| 1040 | bond->params.arp_validate = BOND_ARP_VALIDATE_NONE; |
| 1041 | } |
| 1042 | if (bond->dev->flags & IFF_UP) { |
| 1043 | /* If the interface is up, we may need to fire off |
| 1044 | * the MII timer. If the interface is down, the |
| 1045 | * timer will get fired off when the open function |
| 1046 | * is called. |
| 1047 | */ |
| 1048 | if (!new_value) { |
| 1049 | cancel_delayed_work_sync(&bond->mii_work); |
| 1050 | } else { |
nikolay@redhat.com | fbb0c41 | 2012-11-29 01:31:31 +0000 | [diff] [blame] | 1051 | cancel_delayed_work_sync(&bond->arp_work); |
| 1052 | queue_delayed_work(bond->wq, &bond->mii_work, 0); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1053 | } |
| 1054 | } |
| 1055 | out: |
nikolay@redhat.com | fbb0c41 | 2012-11-29 01:31:31 +0000 | [diff] [blame] | 1056 | rtnl_unlock(); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1057 | return ret; |
| 1058 | } |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1059 | static DEVICE_ATTR(miimon, S_IRUGO | S_IWUSR, |
| 1060 | bonding_show_miimon, bonding_store_miimon); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1061 | |
| 1062 | /* |
| 1063 | * Show and set the primary slave. The store function is much |
| 1064 | * simpler than bonding_store_slaves function because it only needs to |
| 1065 | * handle one interface name. |
| 1066 | * The bond must be a mode that supports a primary for this be |
| 1067 | * set. |
| 1068 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1069 | static ssize_t bonding_show_primary(struct device *d, |
| 1070 | struct device_attribute *attr, |
| 1071 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1072 | { |
| 1073 | int count = 0; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1074 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1075 | |
| 1076 | if (bond->primary_slave) |
Wagner Ferenc | 7bd4650 | 2007-12-06 23:40:28 -0800 | [diff] [blame] | 1077 | count = sprintf(buf, "%s\n", bond->primary_slave->dev->name); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1078 | |
| 1079 | return count; |
| 1080 | } |
| 1081 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1082 | static ssize_t bonding_store_primary(struct device *d, |
| 1083 | struct device_attribute *attr, |
| 1084 | const char *buf, size_t count) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1085 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1086 | struct bonding *bond = to_bond(d); |
Veaceslav Falico | 9caff1e7 | 2013-09-25 09:20:14 +0200 | [diff] [blame] | 1087 | struct list_head *iter; |
Andy Gospodarek | f4bb2e9 | 2011-07-26 11:12:27 +0000 | [diff] [blame] | 1088 | char ifname[IFNAMSIZ]; |
nikolay@redhat.com | dec1e90 | 2013-08-01 16:54:47 +0200 | [diff] [blame] | 1089 | struct slave *slave; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1090 | |
Eric W. Biederman | 496a60c | 2009-05-13 17:02:50 +0000 | [diff] [blame] | 1091 | if (!rtnl_trylock()) |
| 1092 | return restart_syscall(); |
Neil Horman | e843fa5 | 2010-10-13 16:01:50 +0000 | [diff] [blame] | 1093 | block_netpoll_tx(); |
Jay Vosburgh | e934dd7 | 2008-01-17 16:24:57 -0800 | [diff] [blame] | 1094 | read_lock(&bond->lock); |
| 1095 | write_lock_bh(&bond->curr_slave_lock); |
| 1096 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1097 | if (!USES_PRIMARY(bond->params.mode)) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1098 | pr_info("%s: Unable to set primary slave; %s is in mode %d\n", |
| 1099 | bond->dev->name, bond->dev->name, bond->params.mode); |
Andy Gospodarek | f4bb2e9 | 2011-07-26 11:12:27 +0000 | [diff] [blame] | 1100 | goto out; |
| 1101 | } |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1102 | |
nikolay@redhat.com | eb6e98a | 2012-10-31 04:42:51 +0000 | [diff] [blame] | 1103 | sscanf(buf, "%15s", ifname); /* IFNAMSIZ */ |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1104 | |
Andy Gospodarek | f4bb2e9 | 2011-07-26 11:12:27 +0000 | [diff] [blame] | 1105 | /* check to see if we are clearing primary */ |
| 1106 | if (!strlen(ifname) || buf[0] == '\n') { |
| 1107 | pr_info("%s: Setting primary slave to None.\n", |
| 1108 | bond->dev->name); |
| 1109 | bond->primary_slave = NULL; |
Milos Vyletel | eb492f7 | 2013-01-29 09:59:00 +0000 | [diff] [blame] | 1110 | memset(bond->params.primary, 0, sizeof(bond->params.primary)); |
Andy Gospodarek | f4bb2e9 | 2011-07-26 11:12:27 +0000 | [diff] [blame] | 1111 | bond_select_active_slave(bond); |
| 1112 | goto out; |
| 1113 | } |
| 1114 | |
Veaceslav Falico | 9caff1e7 | 2013-09-25 09:20:14 +0200 | [diff] [blame] | 1115 | bond_for_each_slave(bond, slave, iter) { |
Andy Gospodarek | f4bb2e9 | 2011-07-26 11:12:27 +0000 | [diff] [blame] | 1116 | if (strncmp(slave->dev->name, ifname, IFNAMSIZ) == 0) { |
| 1117 | pr_info("%s: Setting %s as primary slave.\n", |
| 1118 | bond->dev->name, slave->dev->name); |
| 1119 | bond->primary_slave = slave; |
| 1120 | strcpy(bond->params.primary, slave->dev->name); |
| 1121 | bond_select_active_slave(bond); |
| 1122 | goto out; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1123 | } |
| 1124 | } |
Andy Gospodarek | f4bb2e9 | 2011-07-26 11:12:27 +0000 | [diff] [blame] | 1125 | |
Weiping Pan | 8a93664 | 2012-06-10 23:00:20 +0000 | [diff] [blame] | 1126 | strncpy(bond->params.primary, ifname, IFNAMSIZ); |
| 1127 | bond->params.primary[IFNAMSIZ - 1] = 0; |
| 1128 | |
| 1129 | pr_info("%s: Recording %s as primary, " |
| 1130 | "but it has not been enslaved to %s yet.\n", |
| 1131 | bond->dev->name, ifname, bond->dev->name); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1132 | out: |
Jay Vosburgh | e934dd7 | 2008-01-17 16:24:57 -0800 | [diff] [blame] | 1133 | write_unlock_bh(&bond->curr_slave_lock); |
| 1134 | read_unlock(&bond->lock); |
Neil Horman | e843fa5 | 2010-10-13 16:01:50 +0000 | [diff] [blame] | 1135 | unblock_netpoll_tx(); |
Jay Vosburgh | 6603a6f | 2007-10-17 17:37:50 -0700 | [diff] [blame] | 1136 | rtnl_unlock(); |
| 1137 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1138 | return count; |
| 1139 | } |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1140 | static DEVICE_ATTR(primary, S_IRUGO | S_IWUSR, |
| 1141 | bonding_show_primary, bonding_store_primary); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1142 | |
| 1143 | /* |
Jiri Pirko | a549952 | 2009-09-25 03:28:09 +0000 | [diff] [blame] | 1144 | * Show and set the primary_reselect flag. |
| 1145 | */ |
| 1146 | static ssize_t bonding_show_primary_reselect(struct device *d, |
| 1147 | struct device_attribute *attr, |
| 1148 | char *buf) |
| 1149 | { |
| 1150 | struct bonding *bond = to_bond(d); |
| 1151 | |
| 1152 | return sprintf(buf, "%s %d\n", |
| 1153 | pri_reselect_tbl[bond->params.primary_reselect].modename, |
| 1154 | bond->params.primary_reselect); |
| 1155 | } |
| 1156 | |
| 1157 | static ssize_t bonding_store_primary_reselect(struct device *d, |
| 1158 | struct device_attribute *attr, |
| 1159 | const char *buf, size_t count) |
| 1160 | { |
| 1161 | int new_value, ret = count; |
| 1162 | struct bonding *bond = to_bond(d); |
| 1163 | |
| 1164 | if (!rtnl_trylock()) |
| 1165 | return restart_syscall(); |
| 1166 | |
| 1167 | new_value = bond_parse_parm(buf, pri_reselect_tbl); |
| 1168 | if (new_value < 0) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1169 | pr_err("%s: Ignoring invalid primary_reselect value %.*s.\n", |
Jiri Pirko | a549952 | 2009-09-25 03:28:09 +0000 | [diff] [blame] | 1170 | bond->dev->name, |
| 1171 | (int) strlen(buf) - 1, buf); |
| 1172 | ret = -EINVAL; |
| 1173 | goto out; |
| 1174 | } |
| 1175 | |
| 1176 | bond->params.primary_reselect = new_value; |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1177 | pr_info("%s: setting primary_reselect to %s (%d).\n", |
Jiri Pirko | a549952 | 2009-09-25 03:28:09 +0000 | [diff] [blame] | 1178 | bond->dev->name, pri_reselect_tbl[new_value].modename, |
| 1179 | new_value); |
| 1180 | |
Neil Horman | e843fa5 | 2010-10-13 16:01:50 +0000 | [diff] [blame] | 1181 | block_netpoll_tx(); |
Jiri Pirko | a549952 | 2009-09-25 03:28:09 +0000 | [diff] [blame] | 1182 | read_lock(&bond->lock); |
| 1183 | write_lock_bh(&bond->curr_slave_lock); |
| 1184 | bond_select_active_slave(bond); |
| 1185 | write_unlock_bh(&bond->curr_slave_lock); |
| 1186 | read_unlock(&bond->lock); |
Neil Horman | e843fa5 | 2010-10-13 16:01:50 +0000 | [diff] [blame] | 1187 | unblock_netpoll_tx(); |
Jiri Pirko | a549952 | 2009-09-25 03:28:09 +0000 | [diff] [blame] | 1188 | out: |
| 1189 | rtnl_unlock(); |
| 1190 | return ret; |
| 1191 | } |
| 1192 | static DEVICE_ATTR(primary_reselect, S_IRUGO | S_IWUSR, |
| 1193 | bonding_show_primary_reselect, |
| 1194 | bonding_store_primary_reselect); |
| 1195 | |
| 1196 | /* |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1197 | * Show and set the use_carrier flag. |
| 1198 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1199 | static ssize_t bonding_show_carrier(struct device *d, |
| 1200 | struct device_attribute *attr, |
| 1201 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1202 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1203 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1204 | |
Wagner Ferenc | 7bd4650 | 2007-12-06 23:40:28 -0800 | [diff] [blame] | 1205 | return sprintf(buf, "%d\n", bond->params.use_carrier); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1206 | } |
| 1207 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1208 | static ssize_t bonding_store_carrier(struct device *d, |
| 1209 | struct device_attribute *attr, |
| 1210 | const char *buf, size_t count) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1211 | { |
| 1212 | int new_value, ret = count; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1213 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1214 | |
| 1215 | |
| 1216 | if (sscanf(buf, "%d", &new_value) != 1) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1217 | pr_err("%s: no use_carrier value specified.\n", |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1218 | bond->dev->name); |
| 1219 | ret = -EINVAL; |
| 1220 | goto out; |
| 1221 | } |
| 1222 | if ((new_value == 0) || (new_value == 1)) { |
| 1223 | bond->params.use_carrier = new_value; |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1224 | pr_info("%s: Setting use_carrier to %d.\n", |
| 1225 | bond->dev->name, new_value); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1226 | } else { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1227 | pr_info("%s: Ignoring invalid use_carrier value %d.\n", |
| 1228 | bond->dev->name, new_value); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1229 | } |
| 1230 | out: |
Jiri Pirko | 672bda3 | 2011-01-25 11:03:25 +0000 | [diff] [blame] | 1231 | return ret; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1232 | } |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1233 | static DEVICE_ATTR(use_carrier, S_IRUGO | S_IWUSR, |
| 1234 | bonding_show_carrier, bonding_store_carrier); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1235 | |
| 1236 | |
| 1237 | /* |
| 1238 | * Show and set currently active_slave. |
| 1239 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1240 | static ssize_t bonding_show_active_slave(struct device *d, |
| 1241 | struct device_attribute *attr, |
| 1242 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1243 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1244 | struct bonding *bond = to_bond(d); |
nikolay@redhat.com | 278b208 | 2013-08-01 16:54:51 +0200 | [diff] [blame] | 1245 | struct slave *curr; |
Wagner Ferenc | 16cd016 | 2007-12-06 23:40:29 -0800 | [diff] [blame] | 1246 | int count = 0; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1247 | |
nikolay@redhat.com | 278b208 | 2013-08-01 16:54:51 +0200 | [diff] [blame] | 1248 | rcu_read_lock(); |
| 1249 | curr = rcu_dereference(bond->curr_active_slave); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1250 | if (USES_PRIMARY(bond->params.mode) && curr) |
Wagner Ferenc | 7bd4650 | 2007-12-06 23:40:28 -0800 | [diff] [blame] | 1251 | count = sprintf(buf, "%s\n", curr->dev->name); |
nikolay@redhat.com | 278b208 | 2013-08-01 16:54:51 +0200 | [diff] [blame] | 1252 | rcu_read_unlock(); |
| 1253 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1254 | return count; |
| 1255 | } |
| 1256 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1257 | static ssize_t bonding_store_active_slave(struct device *d, |
| 1258 | struct device_attribute *attr, |
| 1259 | const char *buf, size_t count) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1260 | { |
nikolay@redhat.com | dec1e90 | 2013-08-01 16:54:47 +0200 | [diff] [blame] | 1261 | struct slave *slave, *old_active, *new_active; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1262 | struct bonding *bond = to_bond(d); |
Veaceslav Falico | 9caff1e7 | 2013-09-25 09:20:14 +0200 | [diff] [blame] | 1263 | struct list_head *iter; |
Andy Gospodarek | f4bb2e9 | 2011-07-26 11:12:27 +0000 | [diff] [blame] | 1264 | char ifname[IFNAMSIZ]; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1265 | |
Eric W. Biederman | 496a60c | 2009-05-13 17:02:50 +0000 | [diff] [blame] | 1266 | if (!rtnl_trylock()) |
| 1267 | return restart_syscall(); |
Neil Horman | e843fa5 | 2010-10-13 16:01:50 +0000 | [diff] [blame] | 1268 | |
nikolay@redhat.com | dec1e90 | 2013-08-01 16:54:47 +0200 | [diff] [blame] | 1269 | old_active = new_active = NULL; |
Neil Horman | e843fa5 | 2010-10-13 16:01:50 +0000 | [diff] [blame] | 1270 | block_netpoll_tx(); |
Jay Vosburgh | e934dd7 | 2008-01-17 16:24:57 -0800 | [diff] [blame] | 1271 | read_lock(&bond->lock); |
| 1272 | write_lock_bh(&bond->curr_slave_lock); |
Jay Vosburgh | 1466a21 | 2007-11-06 13:33:28 -0800 | [diff] [blame] | 1273 | |
Andy Gospodarek | f4bb2e9 | 2011-07-26 11:12:27 +0000 | [diff] [blame] | 1274 | if (!USES_PRIMARY(bond->params.mode)) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1275 | pr_info("%s: Unable to change active slave; %s is in mode %d\n", |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1276 | bond->dev->name, bond->dev->name, bond->params.mode); |
Andy Gospodarek | f4bb2e9 | 2011-07-26 11:12:27 +0000 | [diff] [blame] | 1277 | goto out; |
| 1278 | } |
| 1279 | |
nikolay@redhat.com | c84e159 | 2012-10-31 06:03:52 +0000 | [diff] [blame] | 1280 | sscanf(buf, "%15s", ifname); /* IFNAMSIZ */ |
Andy Gospodarek | f4bb2e9 | 2011-07-26 11:12:27 +0000 | [diff] [blame] | 1281 | |
| 1282 | /* check to see if we are clearing active */ |
| 1283 | if (!strlen(ifname) || buf[0] == '\n') { |
| 1284 | pr_info("%s: Clearing current active slave.\n", |
| 1285 | bond->dev->name); |
nikolay@redhat.com | 278b208 | 2013-08-01 16:54:51 +0200 | [diff] [blame] | 1286 | rcu_assign_pointer(bond->curr_active_slave, NULL); |
Andy Gospodarek | f4bb2e9 | 2011-07-26 11:12:27 +0000 | [diff] [blame] | 1287 | bond_select_active_slave(bond); |
| 1288 | goto out; |
| 1289 | } |
| 1290 | |
Veaceslav Falico | 9caff1e7 | 2013-09-25 09:20:14 +0200 | [diff] [blame] | 1291 | bond_for_each_slave(bond, slave, iter) { |
Andy Gospodarek | f4bb2e9 | 2011-07-26 11:12:27 +0000 | [diff] [blame] | 1292 | if (strncmp(slave->dev->name, ifname, IFNAMSIZ) == 0) { |
| 1293 | old_active = bond->curr_active_slave; |
| 1294 | new_active = slave; |
| 1295 | if (new_active == old_active) { |
| 1296 | /* do nothing */ |
| 1297 | pr_info("%s: %s is already the current" |
| 1298 | " active slave.\n", |
| 1299 | bond->dev->name, |
| 1300 | slave->dev->name); |
| 1301 | goto out; |
dingtianhong | 38c4916 | 2013-07-23 15:25:32 +0800 | [diff] [blame] | 1302 | } else { |
Andy Gospodarek | f4bb2e9 | 2011-07-26 11:12:27 +0000 | [diff] [blame] | 1303 | if ((new_active) && |
| 1304 | (old_active) && |
| 1305 | (new_active->link == BOND_LINK_UP) && |
| 1306 | IS_UP(new_active->dev)) { |
| 1307 | pr_info("%s: Setting %s as active" |
| 1308 | " slave.\n", |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1309 | bond->dev->name, |
| 1310 | slave->dev->name); |
Andy Gospodarek | f4bb2e9 | 2011-07-26 11:12:27 +0000 | [diff] [blame] | 1311 | bond_change_active_slave(bond, |
| 1312 | new_active); |
dingtianhong | 38c4916 | 2013-07-23 15:25:32 +0800 | [diff] [blame] | 1313 | } else { |
Andy Gospodarek | f4bb2e9 | 2011-07-26 11:12:27 +0000 | [diff] [blame] | 1314 | pr_info("%s: Could not set %s as" |
| 1315 | " active slave; either %s is" |
| 1316 | " down or the link is down.\n", |
| 1317 | bond->dev->name, |
| 1318 | slave->dev->name, |
| 1319 | slave->dev->name); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1320 | } |
Andy Gospodarek | f4bb2e9 | 2011-07-26 11:12:27 +0000 | [diff] [blame] | 1321 | goto out; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1322 | } |
| 1323 | } |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1324 | } |
Andy Gospodarek | f4bb2e9 | 2011-07-26 11:12:27 +0000 | [diff] [blame] | 1325 | |
| 1326 | pr_info("%s: Unable to set %.*s as active slave.\n", |
| 1327 | bond->dev->name, (int)strlen(buf) - 1, buf); |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1328 | out: |
Jay Vosburgh | e934dd7 | 2008-01-17 16:24:57 -0800 | [diff] [blame] | 1329 | write_unlock_bh(&bond->curr_slave_lock); |
| 1330 | read_unlock(&bond->lock); |
Neil Horman | e843fa5 | 2010-10-13 16:01:50 +0000 | [diff] [blame] | 1331 | unblock_netpoll_tx(); |
| 1332 | |
Jay Vosburgh | 6603a6f | 2007-10-17 17:37:50 -0700 | [diff] [blame] | 1333 | rtnl_unlock(); |
| 1334 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1335 | return count; |
| 1336 | |
| 1337 | } |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1338 | static DEVICE_ATTR(active_slave, S_IRUGO | S_IWUSR, |
| 1339 | bonding_show_active_slave, bonding_store_active_slave); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1340 | |
| 1341 | |
| 1342 | /* |
| 1343 | * Show link status of the bond interface. |
| 1344 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1345 | static ssize_t bonding_show_mii_status(struct device *d, |
| 1346 | struct device_attribute *attr, |
| 1347 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1348 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1349 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1350 | |
nikolay@redhat.com | 278b208 | 2013-08-01 16:54:51 +0200 | [diff] [blame] | 1351 | return sprintf(buf, "%s\n", bond->curr_active_slave ? "up" : "down"); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1352 | } |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1353 | static DEVICE_ATTR(mii_status, S_IRUGO, bonding_show_mii_status, NULL); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1354 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1355 | /* |
| 1356 | * Show current 802.3ad aggregator ID. |
| 1357 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1358 | static ssize_t bonding_show_ad_aggregator(struct device *d, |
| 1359 | struct device_attribute *attr, |
| 1360 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1361 | { |
| 1362 | int count = 0; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1363 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1364 | |
| 1365 | if (bond->params.mode == BOND_MODE_8023AD) { |
| 1366 | struct ad_info ad_info; |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1367 | count = sprintf(buf, "%d\n", |
nikolay@redhat.com | 318debd | 2013-05-18 01:18:31 +0000 | [diff] [blame] | 1368 | bond_3ad_get_active_agg_info(bond, &ad_info) |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1369 | ? 0 : ad_info.aggregator_id); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1370 | } |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1371 | |
| 1372 | return count; |
| 1373 | } |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1374 | static DEVICE_ATTR(ad_aggregator, S_IRUGO, bonding_show_ad_aggregator, NULL); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1375 | |
| 1376 | |
| 1377 | /* |
| 1378 | * Show number of active 802.3ad ports. |
| 1379 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1380 | static ssize_t bonding_show_ad_num_ports(struct device *d, |
| 1381 | struct device_attribute *attr, |
| 1382 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1383 | { |
| 1384 | int count = 0; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1385 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1386 | |
| 1387 | if (bond->params.mode == BOND_MODE_8023AD) { |
| 1388 | struct ad_info ad_info; |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1389 | count = sprintf(buf, "%d\n", |
nikolay@redhat.com | 318debd | 2013-05-18 01:18:31 +0000 | [diff] [blame] | 1390 | bond_3ad_get_active_agg_info(bond, &ad_info) |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1391 | ? 0 : ad_info.ports); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1392 | } |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1393 | |
| 1394 | return count; |
| 1395 | } |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1396 | 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] | 1397 | |
| 1398 | |
| 1399 | /* |
| 1400 | * Show current 802.3ad actor key. |
| 1401 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1402 | static ssize_t bonding_show_ad_actor_key(struct device *d, |
| 1403 | struct device_attribute *attr, |
| 1404 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1405 | { |
| 1406 | int count = 0; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1407 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1408 | |
| 1409 | if (bond->params.mode == BOND_MODE_8023AD) { |
| 1410 | struct ad_info ad_info; |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1411 | count = sprintf(buf, "%d\n", |
nikolay@redhat.com | 318debd | 2013-05-18 01:18:31 +0000 | [diff] [blame] | 1412 | bond_3ad_get_active_agg_info(bond, &ad_info) |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1413 | ? 0 : ad_info.actor_key); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1414 | } |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1415 | |
| 1416 | return count; |
| 1417 | } |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1418 | 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] | 1419 | |
| 1420 | |
| 1421 | /* |
| 1422 | * Show current 802.3ad partner key. |
| 1423 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1424 | static ssize_t bonding_show_ad_partner_key(struct device *d, |
| 1425 | struct device_attribute *attr, |
| 1426 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1427 | { |
| 1428 | int count = 0; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1429 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1430 | |
| 1431 | if (bond->params.mode == BOND_MODE_8023AD) { |
| 1432 | struct ad_info ad_info; |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1433 | count = sprintf(buf, "%d\n", |
nikolay@redhat.com | 318debd | 2013-05-18 01:18:31 +0000 | [diff] [blame] | 1434 | bond_3ad_get_active_agg_info(bond, &ad_info) |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1435 | ? 0 : ad_info.partner_key); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1436 | } |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1437 | |
| 1438 | return count; |
| 1439 | } |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1440 | 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] | 1441 | |
| 1442 | |
| 1443 | /* |
| 1444 | * Show current 802.3ad partner mac. |
| 1445 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1446 | static ssize_t bonding_show_ad_partner_mac(struct device *d, |
| 1447 | struct device_attribute *attr, |
| 1448 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1449 | { |
| 1450 | int count = 0; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1451 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1452 | |
| 1453 | if (bond->params.mode == BOND_MODE_8023AD) { |
| 1454 | struct ad_info ad_info; |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1455 | if (!bond_3ad_get_active_agg_info(bond, &ad_info)) |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 1456 | count = sprintf(buf, "%pM\n", ad_info.partner_system); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1457 | } |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1458 | |
| 1459 | return count; |
| 1460 | } |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1461 | 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] | 1462 | |
Andy Gospodarek | ebd8e49 | 2010-06-02 08:39:21 +0000 | [diff] [blame] | 1463 | /* |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 1464 | * Show the queue_ids of the slaves in the current bond. |
| 1465 | */ |
| 1466 | static ssize_t bonding_show_queue_id(struct device *d, |
| 1467 | struct device_attribute *attr, |
| 1468 | char *buf) |
| 1469 | { |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 1470 | struct bonding *bond = to_bond(d); |
Veaceslav Falico | 9caff1e7 | 2013-09-25 09:20:14 +0200 | [diff] [blame] | 1471 | struct list_head *iter; |
nikolay@redhat.com | dec1e90 | 2013-08-01 16:54:47 +0200 | [diff] [blame] | 1472 | struct slave *slave; |
| 1473 | int res = 0; |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 1474 | |
| 1475 | if (!rtnl_trylock()) |
| 1476 | return restart_syscall(); |
| 1477 | |
Veaceslav Falico | 9caff1e7 | 2013-09-25 09:20:14 +0200 | [diff] [blame] | 1478 | bond_for_each_slave(bond, slave, iter) { |
Nicolas de Pesloüan | 7923668 | 2010-07-14 18:24:54 -0700 | [diff] [blame] | 1479 | if (res > (PAGE_SIZE - IFNAMSIZ - 6)) { |
| 1480 | /* not enough space for another interface_name:queue_id pair */ |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 1481 | if ((PAGE_SIZE - res) > 10) |
| 1482 | res = PAGE_SIZE - 10; |
| 1483 | res += sprintf(buf + res, "++more++ "); |
| 1484 | break; |
| 1485 | } |
| 1486 | res += sprintf(buf + res, "%s:%d ", |
| 1487 | slave->dev->name, slave->queue_id); |
| 1488 | } |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 1489 | if (res) |
| 1490 | buf[res-1] = '\n'; /* eat the leftover space */ |
dingtianhong | 4d1ae5f | 2013-10-15 16:28:42 +0800 | [diff] [blame^] | 1491 | |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 1492 | rtnl_unlock(); |
nikolay@redhat.com | dec1e90 | 2013-08-01 16:54:47 +0200 | [diff] [blame] | 1493 | |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 1494 | return res; |
| 1495 | } |
| 1496 | |
| 1497 | /* |
| 1498 | * Set the queue_ids of the slaves in the current bond. The bond |
| 1499 | * interface must be enslaved for this to work. |
| 1500 | */ |
| 1501 | static ssize_t bonding_store_queue_id(struct device *d, |
| 1502 | struct device_attribute *attr, |
| 1503 | const char *buffer, size_t count) |
| 1504 | { |
| 1505 | struct slave *slave, *update_slave; |
| 1506 | struct bonding *bond = to_bond(d); |
Veaceslav Falico | 9caff1e7 | 2013-09-25 09:20:14 +0200 | [diff] [blame] | 1507 | struct list_head *iter; |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 1508 | u16 qid; |
nikolay@redhat.com | dec1e90 | 2013-08-01 16:54:47 +0200 | [diff] [blame] | 1509 | int ret = count; |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 1510 | char *delim; |
| 1511 | struct net_device *sdev = NULL; |
| 1512 | |
| 1513 | if (!rtnl_trylock()) |
| 1514 | return restart_syscall(); |
| 1515 | |
| 1516 | /* delim will point to queue id if successful */ |
| 1517 | delim = strchr(buffer, ':'); |
| 1518 | if (!delim) |
| 1519 | goto err_no_cmd; |
| 1520 | |
| 1521 | /* |
| 1522 | * Terminate string that points to device name and bump it |
| 1523 | * up one, so we can read the queue id there. |
| 1524 | */ |
| 1525 | *delim = '\0'; |
| 1526 | if (sscanf(++delim, "%hd\n", &qid) != 1) |
| 1527 | goto err_no_cmd; |
| 1528 | |
| 1529 | /* Check buffer length, valid ifname and queue id */ |
| 1530 | if (strlen(buffer) > IFNAMSIZ || |
| 1531 | !dev_valid_name(buffer) || |
Jiri Pirko | 8a540ff | 2012-07-20 02:28:50 +0000 | [diff] [blame] | 1532 | qid > bond->dev->real_num_tx_queues) |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 1533 | goto err_no_cmd; |
| 1534 | |
| 1535 | /* Get the pointer to that interface if it exists */ |
| 1536 | sdev = __dev_get_by_name(dev_net(bond->dev), buffer); |
| 1537 | if (!sdev) |
| 1538 | goto err_no_cmd; |
| 1539 | |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 1540 | /* Search for thes slave and check for duplicate qids */ |
| 1541 | update_slave = NULL; |
Veaceslav Falico | 9caff1e7 | 2013-09-25 09:20:14 +0200 | [diff] [blame] | 1542 | bond_for_each_slave(bond, slave, iter) { |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 1543 | if (sdev == slave->dev) |
| 1544 | /* |
| 1545 | * We don't need to check the matching |
| 1546 | * slave for dups, since we're overwriting it |
| 1547 | */ |
| 1548 | update_slave = slave; |
| 1549 | else if (qid && qid == slave->queue_id) { |
dingtianhong | 4d1ae5f | 2013-10-15 16:28:42 +0800 | [diff] [blame^] | 1550 | goto err_no_cmd; |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 1551 | } |
| 1552 | } |
| 1553 | |
| 1554 | if (!update_slave) |
dingtianhong | 4d1ae5f | 2013-10-15 16:28:42 +0800 | [diff] [blame^] | 1555 | goto err_no_cmd; |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 1556 | |
| 1557 | /* Actually set the qids for the slave */ |
| 1558 | update_slave->queue_id = qid; |
| 1559 | |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 1560 | out: |
| 1561 | rtnl_unlock(); |
| 1562 | return ret; |
| 1563 | |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 1564 | err_no_cmd: |
| 1565 | pr_info("invalid input for queue_id set for %s.\n", |
| 1566 | bond->dev->name); |
| 1567 | ret = -EPERM; |
| 1568 | goto out; |
| 1569 | } |
| 1570 | |
| 1571 | static DEVICE_ATTR(queue_id, S_IRUGO | S_IWUSR, bonding_show_queue_id, |
| 1572 | bonding_store_queue_id); |
| 1573 | |
| 1574 | |
| 1575 | /* |
Andy Gospodarek | ebd8e49 | 2010-06-02 08:39:21 +0000 | [diff] [blame] | 1576 | * Show and set the all_slaves_active flag. |
| 1577 | */ |
| 1578 | static ssize_t bonding_show_slaves_active(struct device *d, |
| 1579 | struct device_attribute *attr, |
| 1580 | char *buf) |
| 1581 | { |
| 1582 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1583 | |
Andy Gospodarek | ebd8e49 | 2010-06-02 08:39:21 +0000 | [diff] [blame] | 1584 | return sprintf(buf, "%d\n", bond->params.all_slaves_active); |
| 1585 | } |
| 1586 | |
| 1587 | static ssize_t bonding_store_slaves_active(struct device *d, |
| 1588 | struct device_attribute *attr, |
| 1589 | const char *buf, size_t count) |
| 1590 | { |
Andy Gospodarek | ebd8e49 | 2010-06-02 08:39:21 +0000 | [diff] [blame] | 1591 | struct bonding *bond = to_bond(d); |
nikolay@redhat.com | dec1e90 | 2013-08-01 16:54:47 +0200 | [diff] [blame] | 1592 | int new_value, ret = count; |
Veaceslav Falico | 9caff1e7 | 2013-09-25 09:20:14 +0200 | [diff] [blame] | 1593 | struct list_head *iter; |
Andy Gospodarek | ebd8e49 | 2010-06-02 08:39:21 +0000 | [diff] [blame] | 1594 | struct slave *slave; |
| 1595 | |
dingtianhong | 4d1ae5f | 2013-10-15 16:28:42 +0800 | [diff] [blame^] | 1596 | if (!rtnl_trylock()) |
| 1597 | return restart_syscall(); |
| 1598 | |
Andy Gospodarek | ebd8e49 | 2010-06-02 08:39:21 +0000 | [diff] [blame] | 1599 | if (sscanf(buf, "%d", &new_value) != 1) { |
| 1600 | pr_err("%s: no all_slaves_active value specified.\n", |
| 1601 | bond->dev->name); |
| 1602 | ret = -EINVAL; |
| 1603 | goto out; |
| 1604 | } |
| 1605 | |
| 1606 | if (new_value == bond->params.all_slaves_active) |
| 1607 | goto out; |
| 1608 | |
| 1609 | if ((new_value == 0) || (new_value == 1)) { |
| 1610 | bond->params.all_slaves_active = new_value; |
| 1611 | } else { |
| 1612 | pr_info("%s: Ignoring invalid all_slaves_active value %d.\n", |
| 1613 | bond->dev->name, new_value); |
| 1614 | ret = -EINVAL; |
| 1615 | goto out; |
| 1616 | } |
| 1617 | |
Veaceslav Falico | 9caff1e7 | 2013-09-25 09:20:14 +0200 | [diff] [blame] | 1618 | bond_for_each_slave(bond, slave, iter) { |
Jiri Pirko | e30bc06 | 2011-03-12 03:14:37 +0000 | [diff] [blame] | 1619 | if (!bond_is_active_slave(slave)) { |
Andy Gospodarek | ebd8e49 | 2010-06-02 08:39:21 +0000 | [diff] [blame] | 1620 | if (new_value) |
Jiri Pirko | 2d7011c | 2011-03-16 08:46:43 +0000 | [diff] [blame] | 1621 | slave->inactive = 0; |
Andy Gospodarek | ebd8e49 | 2010-06-02 08:39:21 +0000 | [diff] [blame] | 1622 | else |
Jiri Pirko | 2d7011c | 2011-03-16 08:46:43 +0000 | [diff] [blame] | 1623 | slave->inactive = 1; |
Andy Gospodarek | ebd8e49 | 2010-06-02 08:39:21 +0000 | [diff] [blame] | 1624 | } |
| 1625 | } |
| 1626 | out: |
dingtianhong | 4d1ae5f | 2013-10-15 16:28:42 +0800 | [diff] [blame^] | 1627 | rtnl_unlock(); |
Jiri Pirko | 672bda3 | 2011-01-25 11:03:25 +0000 | [diff] [blame] | 1628 | return ret; |
Andy Gospodarek | ebd8e49 | 2010-06-02 08:39:21 +0000 | [diff] [blame] | 1629 | } |
| 1630 | static DEVICE_ATTR(all_slaves_active, S_IRUGO | S_IWUSR, |
| 1631 | bonding_show_slaves_active, bonding_store_slaves_active); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1632 | |
Flavio Leitner | c2952c3 | 2010-10-05 14:23:59 +0000 | [diff] [blame] | 1633 | /* |
| 1634 | * Show and set the number of IGMP membership reports to send on link failure |
| 1635 | */ |
| 1636 | static ssize_t bonding_show_resend_igmp(struct device *d, |
Flavio Leitner | 94265cf | 2011-05-25 08:38:58 +0000 | [diff] [blame] | 1637 | struct device_attribute *attr, |
| 1638 | char *buf) |
Flavio Leitner | c2952c3 | 2010-10-05 14:23:59 +0000 | [diff] [blame] | 1639 | { |
| 1640 | struct bonding *bond = to_bond(d); |
| 1641 | |
| 1642 | return sprintf(buf, "%d\n", bond->params.resend_igmp); |
| 1643 | } |
| 1644 | |
| 1645 | static ssize_t bonding_store_resend_igmp(struct device *d, |
Flavio Leitner | 94265cf | 2011-05-25 08:38:58 +0000 | [diff] [blame] | 1646 | struct device_attribute *attr, |
| 1647 | const char *buf, size_t count) |
Flavio Leitner | c2952c3 | 2010-10-05 14:23:59 +0000 | [diff] [blame] | 1648 | { |
| 1649 | int new_value, ret = count; |
| 1650 | struct bonding *bond = to_bond(d); |
| 1651 | |
| 1652 | if (sscanf(buf, "%d", &new_value) != 1) { |
| 1653 | pr_err("%s: no resend_igmp value specified.\n", |
| 1654 | bond->dev->name); |
| 1655 | ret = -EINVAL; |
| 1656 | goto out; |
| 1657 | } |
| 1658 | |
Flavio Leitner | 94265cf | 2011-05-25 08:38:58 +0000 | [diff] [blame] | 1659 | if (new_value < 0 || new_value > 255) { |
Flavio Leitner | c2952c3 | 2010-10-05 14:23:59 +0000 | [diff] [blame] | 1660 | pr_err("%s: Invalid resend_igmp value %d not in range 0-255; rejected.\n", |
| 1661 | bond->dev->name, new_value); |
| 1662 | ret = -EINVAL; |
| 1663 | goto out; |
| 1664 | } |
| 1665 | |
| 1666 | pr_info("%s: Setting resend_igmp to %d.\n", |
| 1667 | bond->dev->name, new_value); |
| 1668 | bond->params.resend_igmp = new_value; |
| 1669 | out: |
| 1670 | return ret; |
| 1671 | } |
| 1672 | |
| 1673 | static DEVICE_ATTR(resend_igmp, S_IRUGO | S_IWUSR, |
| 1674 | bonding_show_resend_igmp, bonding_store_resend_igmp); |
| 1675 | |
Neil Horman | 7eacd03 | 2013-09-13 11:05:33 -0400 | [diff] [blame] | 1676 | |
| 1677 | static ssize_t bonding_show_lp_interval(struct device *d, |
| 1678 | struct device_attribute *attr, |
| 1679 | char *buf) |
| 1680 | { |
| 1681 | struct bonding *bond = to_bond(d); |
| 1682 | return sprintf(buf, "%d\n", bond->params.lp_interval); |
| 1683 | } |
| 1684 | |
| 1685 | static ssize_t bonding_store_lp_interval(struct device *d, |
| 1686 | struct device_attribute *attr, |
| 1687 | const char *buf, size_t count) |
| 1688 | { |
| 1689 | struct bonding *bond = to_bond(d); |
| 1690 | int new_value, ret = count; |
| 1691 | |
| 1692 | if (sscanf(buf, "%d", &new_value) != 1) { |
| 1693 | pr_err("%s: no lp interval value specified.\n", |
| 1694 | bond->dev->name); |
| 1695 | ret = -EINVAL; |
| 1696 | goto out; |
| 1697 | } |
| 1698 | |
| 1699 | if (new_value <= 0) { |
| 1700 | pr_err ("%s: lp_interval must be between 1 and %d\n", |
| 1701 | bond->dev->name, INT_MAX); |
| 1702 | ret = -EINVAL; |
| 1703 | goto out; |
| 1704 | } |
| 1705 | |
| 1706 | bond->params.lp_interval = new_value; |
| 1707 | out: |
| 1708 | return ret; |
| 1709 | } |
| 1710 | |
| 1711 | static DEVICE_ATTR(lp_interval, S_IRUGO | S_IWUSR, |
| 1712 | bonding_show_lp_interval, bonding_store_lp_interval); |
| 1713 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1714 | static struct attribute *per_bond_attrs[] = { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1715 | &dev_attr_slaves.attr, |
| 1716 | &dev_attr_mode.attr, |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 1717 | &dev_attr_fail_over_mac.attr, |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1718 | &dev_attr_arp_validate.attr, |
Veaceslav Falico | 8599b52 | 2013-06-24 11:49:34 +0200 | [diff] [blame] | 1719 | &dev_attr_arp_all_targets.attr, |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1720 | &dev_attr_arp_interval.attr, |
| 1721 | &dev_attr_arp_ip_target.attr, |
| 1722 | &dev_attr_downdelay.attr, |
| 1723 | &dev_attr_updelay.attr, |
| 1724 | &dev_attr_lacp_rate.attr, |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 1725 | &dev_attr_ad_select.attr, |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1726 | &dev_attr_xmit_hash_policy.attr, |
Ben Hutchings | ad246c9 | 2011-04-26 15:25:52 +0000 | [diff] [blame] | 1727 | &dev_attr_num_grat_arp.attr, |
| 1728 | &dev_attr_num_unsol_na.attr, |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1729 | &dev_attr_miimon.attr, |
| 1730 | &dev_attr_primary.attr, |
Jiri Pirko | a549952 | 2009-09-25 03:28:09 +0000 | [diff] [blame] | 1731 | &dev_attr_primary_reselect.attr, |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1732 | &dev_attr_use_carrier.attr, |
| 1733 | &dev_attr_active_slave.attr, |
| 1734 | &dev_attr_mii_status.attr, |
| 1735 | &dev_attr_ad_aggregator.attr, |
| 1736 | &dev_attr_ad_num_ports.attr, |
| 1737 | &dev_attr_ad_actor_key.attr, |
| 1738 | &dev_attr_ad_partner_key.attr, |
| 1739 | &dev_attr_ad_partner_mac.attr, |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 1740 | &dev_attr_queue_id.attr, |
Andy Gospodarek | ebd8e49 | 2010-06-02 08:39:21 +0000 | [diff] [blame] | 1741 | &dev_attr_all_slaves_active.attr, |
Flavio Leitner | c2952c3 | 2010-10-05 14:23:59 +0000 | [diff] [blame] | 1742 | &dev_attr_resend_igmp.attr, |
stephen hemminger | 655f891 | 2011-06-22 09:54:39 +0000 | [diff] [blame] | 1743 | &dev_attr_min_links.attr, |
Neil Horman | 7eacd03 | 2013-09-13 11:05:33 -0400 | [diff] [blame] | 1744 | &dev_attr_lp_interval.attr, |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1745 | NULL, |
| 1746 | }; |
| 1747 | |
| 1748 | static struct attribute_group bonding_group = { |
| 1749 | .name = "bonding", |
| 1750 | .attrs = per_bond_attrs, |
| 1751 | }; |
| 1752 | |
| 1753 | /* |
| 1754 | * Initialize sysfs. This sets up the bonding_masters file in |
| 1755 | * /sys/class/net. |
| 1756 | */ |
Eric W. Biederman | 4c22400 | 2011-10-12 21:56:25 +0000 | [diff] [blame] | 1757 | int bond_create_sysfs(struct bond_net *bn) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1758 | { |
Jay Vosburgh | b8a9787 | 2008-06-13 18:12:04 -0700 | [diff] [blame] | 1759 | int ret; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1760 | |
Eric W. Biederman | 4c22400 | 2011-10-12 21:56:25 +0000 | [diff] [blame] | 1761 | bn->class_attr_bonding_masters = class_attr_bonding_masters; |
Eric W. Biederman | 01718e3 | 2011-10-21 22:43:07 +0000 | [diff] [blame] | 1762 | sysfs_attr_init(&bn->class_attr_bonding_masters.attr); |
Eric W. Biederman | 4c22400 | 2011-10-12 21:56:25 +0000 | [diff] [blame] | 1763 | |
| 1764 | ret = netdev_class_create_file(&bn->class_attr_bonding_masters); |
Jay Vosburgh | 877cbd3 | 2007-01-19 18:15:47 -0800 | [diff] [blame] | 1765 | /* |
| 1766 | * Permit multiple loads of the module by ignoring failures to |
| 1767 | * create the bonding_masters sysfs file. Bonding devices |
| 1768 | * created by second or subsequent loads of the module will |
| 1769 | * not be listed in, or controllable by, bonding_masters, but |
| 1770 | * will have the usual "bonding" sysfs directory. |
| 1771 | * |
| 1772 | * This is done to preserve backwards compatibility for |
| 1773 | * initscripts/sysconfig, which load bonding multiple times to |
| 1774 | * configure multiple bonding devices. |
| 1775 | */ |
| 1776 | if (ret == -EEXIST) { |
Stephen Hemminger | 38d2f38 | 2008-05-14 22:35:04 -0700 | [diff] [blame] | 1777 | /* Is someone being kinky and naming a device bonding_master? */ |
Eric W. Biederman | 4c22400 | 2011-10-12 21:56:25 +0000 | [diff] [blame] | 1778 | if (__dev_get_by_name(bn->net, |
Stephen Hemminger | 38d2f38 | 2008-05-14 22:35:04 -0700 | [diff] [blame] | 1779 | class_attr_bonding_masters.attr.name)) |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1780 | pr_err("network device named %s already exists in sysfs", |
Stephen Hemminger | 38d2f38 | 2008-05-14 22:35:04 -0700 | [diff] [blame] | 1781 | class_attr_bonding_masters.attr.name); |
Stephen Hemminger | 130aa61 | 2009-06-11 05:46:04 -0700 | [diff] [blame] | 1782 | ret = 0; |
Jay Vosburgh | 877cbd3 | 2007-01-19 18:15:47 -0800 | [diff] [blame] | 1783 | } |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1784 | |
| 1785 | return ret; |
| 1786 | |
| 1787 | } |
| 1788 | |
| 1789 | /* |
| 1790 | * Remove /sys/class/net/bonding_masters. |
| 1791 | */ |
Eric W. Biederman | 4c22400 | 2011-10-12 21:56:25 +0000 | [diff] [blame] | 1792 | void bond_destroy_sysfs(struct bond_net *bn) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1793 | { |
Eric W. Biederman | 4c22400 | 2011-10-12 21:56:25 +0000 | [diff] [blame] | 1794 | netdev_class_remove_file(&bn->class_attr_bonding_masters); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1795 | } |
| 1796 | |
| 1797 | /* |
| 1798 | * Initialize sysfs for each bond. This sets up and registers |
| 1799 | * the 'bondctl' directory for each individual bond under /sys/class/net. |
| 1800 | */ |
Eric W. Biederman | 6151b3d | 2009-10-29 14:18:22 +0000 | [diff] [blame] | 1801 | void bond_prepare_sysfs_group(struct bonding *bond) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1802 | { |
Eric W. Biederman | 6151b3d | 2009-10-29 14:18:22 +0000 | [diff] [blame] | 1803 | bond->dev->sysfs_groups[0] = &bonding_group; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1804 | } |
| 1805 | |