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