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 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 425 | if (!bond->params.arp_validate && new_value) |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 426 | bond_register_arp(bond); |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 427 | else if (bond->params.arp_validate && !new_value) |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 428 | bond_unregister_arp(bond); |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 429 | |
| 430 | bond->params.arp_validate = new_value; |
| 431 | |
| 432 | return count; |
| 433 | } |
| 434 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 435 | static DEVICE_ATTR(arp_validate, S_IRUGO | S_IWUSR, bonding_show_arp_validate, |
| 436 | bonding_store_arp_validate); |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 437 | |
| 438 | /* |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 439 | * Show and store fail_over_mac. User only allowed to change the |
| 440 | * value when there are no slaves. |
| 441 | */ |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 442 | static ssize_t bonding_show_fail_over_mac(struct device *d, |
| 443 | struct device_attribute *attr, |
| 444 | char *buf) |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 445 | { |
| 446 | struct bonding *bond = to_bond(d); |
| 447 | |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 448 | return sprintf(buf, "%s %d\n", |
| 449 | fail_over_mac_tbl[bond->params.fail_over_mac].modename, |
| 450 | bond->params.fail_over_mac); |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 451 | } |
| 452 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 453 | static ssize_t bonding_store_fail_over_mac(struct device *d, |
| 454 | struct device_attribute *attr, |
| 455 | const char *buf, size_t count) |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 456 | { |
| 457 | int new_value; |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 458 | struct bonding *bond = to_bond(d); |
| 459 | |
| 460 | if (bond->slave_cnt != 0) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 461 | 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] | 462 | bond->dev->name); |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 463 | return -EPERM; |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 464 | } |
| 465 | |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 466 | new_value = bond_parse_parm(buf, fail_over_mac_tbl); |
| 467 | if (new_value < 0) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 468 | pr_err("%s: Ignoring invalid fail_over_mac value %s.\n", |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 469 | bond->dev->name, buf); |
| 470 | return -EINVAL; |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 471 | } |
| 472 | |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 473 | bond->params.fail_over_mac = new_value; |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 474 | pr_info("%s: Setting fail_over_mac to %s (%d).\n", |
| 475 | bond->dev->name, fail_over_mac_tbl[new_value].modename, |
| 476 | new_value); |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 477 | |
| 478 | return count; |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 479 | } |
| 480 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 481 | static DEVICE_ATTR(fail_over_mac, S_IRUGO | S_IWUSR, |
| 482 | bonding_show_fail_over_mac, bonding_store_fail_over_mac); |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 483 | |
| 484 | /* |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 485 | * Show and set the arp timer interval. There are two tricky bits |
| 486 | * here. First, if ARP monitoring is activated, then we must disable |
| 487 | * MII monitoring. Second, if the ARP timer isn't running, we must |
| 488 | * start it. |
| 489 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 490 | static ssize_t bonding_show_arp_interval(struct device *d, |
| 491 | struct device_attribute *attr, |
| 492 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 493 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 494 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 495 | |
Wagner Ferenc | 7bd4650 | 2007-12-06 23:40:28 -0800 | [diff] [blame] | 496 | return sprintf(buf, "%d\n", bond->params.arp_interval); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 497 | } |
| 498 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 499 | static ssize_t bonding_store_arp_interval(struct device *d, |
| 500 | struct device_attribute *attr, |
| 501 | const char *buf, size_t count) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 502 | { |
| 503 | int new_value, ret = count; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 504 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 505 | |
| 506 | if (sscanf(buf, "%d", &new_value) != 1) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 507 | pr_err("%s: no arp_interval value specified.\n", |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 508 | bond->dev->name); |
| 509 | ret = -EINVAL; |
| 510 | goto out; |
| 511 | } |
| 512 | if (new_value < 0) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 513 | 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] | 514 | bond->dev->name, new_value, INT_MAX); |
| 515 | ret = -EINVAL; |
| 516 | goto out; |
| 517 | } |
Andy Gospodarek | c5cb002 | 2010-07-28 15:13:56 +0000 | [diff] [blame] | 518 | if (bond->params.mode == BOND_MODE_ALB || |
| 519 | bond->params.mode == BOND_MODE_TLB) { |
| 520 | pr_info("%s: ARP monitoring cannot be used with ALB/TLB. Only MII monitoring is supported on %s.\n", |
| 521 | bond->dev->name, bond->dev->name); |
| 522 | ret = -EINVAL; |
| 523 | goto out; |
| 524 | } |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 525 | pr_info("%s: Setting ARP monitoring interval to %d.\n", |
| 526 | bond->dev->name, new_value); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 527 | bond->params.arp_interval = new_value; |
| 528 | if (bond->params.miimon) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 529 | pr_info("%s: ARP monitoring cannot be used with MII monitoring. %s Disabling MII monitoring.\n", |
| 530 | bond->dev->name, bond->dev->name); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 531 | bond->params.miimon = 0; |
Jay Vosburgh | 1b76b31 | 2007-10-17 17:37:45 -0700 | [diff] [blame] | 532 | if (delayed_work_pending(&bond->mii_work)) { |
| 533 | cancel_delayed_work(&bond->mii_work); |
| 534 | flush_workqueue(bond->wq); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 535 | } |
| 536 | } |
| 537 | if (!bond->params.arp_targets[0]) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 538 | pr_info("%s: ARP monitoring has been set up, but no ARP targets have been specified.\n", |
| 539 | bond->dev->name); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 540 | } |
| 541 | if (bond->dev->flags & IFF_UP) { |
| 542 | /* If the interface is up, we may need to fire off |
| 543 | * the ARP timer. If the interface is down, the |
| 544 | * timer will get fired off when the open function |
| 545 | * is called. |
| 546 | */ |
Jay Vosburgh | 1b76b31 | 2007-10-17 17:37:45 -0700 | [diff] [blame] | 547 | if (!delayed_work_pending(&bond->arp_work)) { |
| 548 | if (bond->params.mode == BOND_MODE_ACTIVEBACKUP) |
| 549 | INIT_DELAYED_WORK(&bond->arp_work, |
| 550 | bond_activebackup_arp_mon); |
| 551 | else |
| 552 | INIT_DELAYED_WORK(&bond->arp_work, |
| 553 | bond_loadbalance_arp_mon); |
| 554 | |
| 555 | queue_delayed_work(bond->wq, &bond->arp_work, 0); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 556 | } |
| 557 | } |
| 558 | |
| 559 | out: |
| 560 | return ret; |
| 561 | } |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 562 | static DEVICE_ATTR(arp_interval, S_IRUGO | S_IWUSR, |
| 563 | bonding_show_arp_interval, bonding_store_arp_interval); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 564 | |
| 565 | /* |
| 566 | * Show and set the arp targets. |
| 567 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 568 | static ssize_t bonding_show_arp_targets(struct device *d, |
| 569 | struct device_attribute *attr, |
| 570 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 571 | { |
| 572 | int i, res = 0; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 573 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 574 | |
| 575 | for (i = 0; i < BOND_MAX_ARP_TARGETS; i++) { |
| 576 | if (bond->params.arp_targets[i]) |
Harvey Harrison | 6377943 | 2008-10-31 00:56:00 -0700 | [diff] [blame] | 577 | res += sprintf(buf + res, "%pI4 ", |
| 578 | &bond->params.arp_targets[i]); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 579 | } |
Wagner Ferenc | 1dcdcd6 | 2007-12-06 23:40:31 -0800 | [diff] [blame] | 580 | if (res) |
| 581 | buf[res-1] = '\n'; /* eat the leftover space */ |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 582 | return res; |
| 583 | } |
| 584 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 585 | static ssize_t bonding_store_arp_targets(struct device *d, |
| 586 | struct device_attribute *attr, |
| 587 | const char *buf, size_t count) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 588 | { |
Al Viro | d3bb52b | 2007-08-22 20:06:58 -0400 | [diff] [blame] | 589 | __be32 newtarget; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 590 | int i = 0, done = 0, ret = count; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 591 | struct bonding *bond = to_bond(d); |
Al Viro | d3bb52b | 2007-08-22 20:06:58 -0400 | [diff] [blame] | 592 | __be32 *targets; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 593 | |
| 594 | targets = bond->params.arp_targets; |
| 595 | newtarget = in_aton(buf + 1); |
| 596 | /* look for adds */ |
| 597 | if (buf[0] == '+') { |
Al Viro | d3bb52b | 2007-08-22 20:06:58 -0400 | [diff] [blame] | 598 | if ((newtarget == 0) || (newtarget == htonl(INADDR_BROADCAST))) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 599 | pr_err("%s: invalid ARP target %pI4 specified for addition\n", |
Harvey Harrison | 6377943 | 2008-10-31 00:56:00 -0700 | [diff] [blame] | 600 | bond->dev->name, &newtarget); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 601 | ret = -EINVAL; |
| 602 | goto out; |
| 603 | } |
| 604 | /* 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] | 605 | for (i = 0; (i < BOND_MAX_ARP_TARGETS) && !done; i++) { |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 606 | if (targets[i] == newtarget) { /* duplicate */ |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 607 | pr_err("%s: ARP target %pI4 is already present\n", |
Harvey Harrison | 6377943 | 2008-10-31 00:56:00 -0700 | [diff] [blame] | 608 | bond->dev->name, &newtarget); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 609 | ret = -EINVAL; |
| 610 | goto out; |
| 611 | } |
Brian Haley | 5a31bec | 2009-04-13 00:11:30 -0700 | [diff] [blame] | 612 | if (targets[i] == 0) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 613 | pr_info("%s: adding ARP target %pI4.\n", |
| 614 | bond->dev->name, &newtarget); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 615 | done = 1; |
| 616 | targets[i] = newtarget; |
| 617 | } |
| 618 | } |
| 619 | if (!done) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 620 | pr_err("%s: ARP target table is full!\n", |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 621 | bond->dev->name); |
| 622 | ret = -EINVAL; |
| 623 | goto out; |
| 624 | } |
| 625 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 626 | } else if (buf[0] == '-') { |
Al Viro | d3bb52b | 2007-08-22 20:06:58 -0400 | [diff] [blame] | 627 | if ((newtarget == 0) || (newtarget == htonl(INADDR_BROADCAST))) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 628 | pr_err("%s: invalid ARP target %pI4 specified for removal\n", |
Harvey Harrison | 6377943 | 2008-10-31 00:56:00 -0700 | [diff] [blame] | 629 | bond->dev->name, &newtarget); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 630 | ret = -EINVAL; |
| 631 | goto out; |
| 632 | } |
| 633 | |
Brian Haley | 5a31bec | 2009-04-13 00:11:30 -0700 | [diff] [blame] | 634 | for (i = 0; (i < BOND_MAX_ARP_TARGETS) && !done; i++) { |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 635 | if (targets[i] == newtarget) { |
Brian Haley | 5a31bec | 2009-04-13 00:11:30 -0700 | [diff] [blame] | 636 | int j; |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 637 | pr_info("%s: removing ARP target %pI4.\n", |
| 638 | bond->dev->name, &newtarget); |
Brian Haley | 5a31bec | 2009-04-13 00:11:30 -0700 | [diff] [blame] | 639 | for (j = i; (j < (BOND_MAX_ARP_TARGETS-1)) && targets[j+1]; j++) |
| 640 | targets[j] = targets[j+1]; |
| 641 | |
| 642 | targets[j] = 0; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 643 | done = 1; |
| 644 | } |
| 645 | } |
| 646 | if (!done) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 647 | pr_info("%s: unable to remove nonexistent ARP target %pI4.\n", |
| 648 | bond->dev->name, &newtarget); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 649 | ret = -EINVAL; |
| 650 | goto out; |
| 651 | } |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 652 | } else { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 653 | pr_err("no command found in arp_ip_targets file for bond %s. Use +<addr> or -<addr>.\n", |
| 654 | bond->dev->name); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 655 | ret = -EPERM; |
| 656 | goto out; |
| 657 | } |
| 658 | |
| 659 | out: |
| 660 | return ret; |
| 661 | } |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 662 | 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] | 663 | |
| 664 | /* |
| 665 | * Show and set the up and down delays. These must be multiples of the |
| 666 | * MII monitoring value, and are stored internally as the multiplier. |
| 667 | * Thus, we must translate to MS for the real world. |
| 668 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 669 | static ssize_t bonding_show_downdelay(struct device *d, |
| 670 | struct device_attribute *attr, |
| 671 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 672 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 673 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 674 | |
Wagner Ferenc | 7bd4650 | 2007-12-06 23:40:28 -0800 | [diff] [blame] | 675 | return sprintf(buf, "%d\n", bond->params.downdelay * bond->params.miimon); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 676 | } |
| 677 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 678 | static ssize_t bonding_store_downdelay(struct device *d, |
| 679 | struct device_attribute *attr, |
| 680 | const char *buf, size_t count) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 681 | { |
| 682 | int new_value, ret = count; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 683 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 684 | |
| 685 | if (!(bond->params.miimon)) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 686 | 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] | 687 | bond->dev->name); |
| 688 | ret = -EPERM; |
| 689 | goto out; |
| 690 | } |
| 691 | |
| 692 | if (sscanf(buf, "%d", &new_value) != 1) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 693 | pr_err("%s: no down delay value specified.\n", bond->dev->name); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 694 | ret = -EINVAL; |
| 695 | goto out; |
| 696 | } |
| 697 | if (new_value < 0) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 698 | 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] | 699 | bond->dev->name, new_value, 1, INT_MAX); |
| 700 | ret = -EINVAL; |
| 701 | goto out; |
| 702 | } else { |
| 703 | if ((new_value % bond->params.miimon) != 0) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 704 | 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] | 705 | bond->dev->name, new_value, |
| 706 | bond->params.miimon, |
| 707 | (new_value / bond->params.miimon) * |
| 708 | bond->params.miimon); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 709 | } |
| 710 | bond->params.downdelay = new_value / bond->params.miimon; |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 711 | pr_info("%s: Setting down delay to %d.\n", |
| 712 | bond->dev->name, |
| 713 | bond->params.downdelay * bond->params.miimon); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 714 | |
| 715 | } |
| 716 | |
| 717 | out: |
| 718 | return ret; |
| 719 | } |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 720 | static DEVICE_ATTR(downdelay, S_IRUGO | S_IWUSR, |
| 721 | bonding_show_downdelay, bonding_store_downdelay); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 722 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 723 | static ssize_t bonding_show_updelay(struct device *d, |
| 724 | struct device_attribute *attr, |
| 725 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 726 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 727 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 728 | |
Wagner Ferenc | 7bd4650 | 2007-12-06 23:40:28 -0800 | [diff] [blame] | 729 | return sprintf(buf, "%d\n", bond->params.updelay * bond->params.miimon); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 730 | |
| 731 | } |
| 732 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 733 | static ssize_t bonding_store_updelay(struct device *d, |
| 734 | struct device_attribute *attr, |
| 735 | const char *buf, size_t count) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 736 | { |
| 737 | int new_value, ret = count; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 738 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 739 | |
| 740 | if (!(bond->params.miimon)) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 741 | 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] | 742 | bond->dev->name); |
| 743 | ret = -EPERM; |
| 744 | goto out; |
| 745 | } |
| 746 | |
| 747 | if (sscanf(buf, "%d", &new_value) != 1) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 748 | pr_err("%s: no up delay value specified.\n", |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 749 | bond->dev->name); |
| 750 | ret = -EINVAL; |
| 751 | goto out; |
| 752 | } |
| 753 | if (new_value < 0) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 754 | 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] | 755 | bond->dev->name, new_value, 1, INT_MAX); |
| 756 | ret = -EINVAL; |
| 757 | goto out; |
| 758 | } else { |
| 759 | if ((new_value % bond->params.miimon) != 0) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 760 | 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] | 761 | bond->dev->name, new_value, |
| 762 | bond->params.miimon, |
| 763 | (new_value / bond->params.miimon) * |
| 764 | bond->params.miimon); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 765 | } |
| 766 | bond->params.updelay = new_value / bond->params.miimon; |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 767 | pr_info("%s: Setting up delay to %d.\n", |
| 768 | bond->dev->name, |
| 769 | bond->params.updelay * bond->params.miimon); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 770 | } |
| 771 | |
| 772 | out: |
| 773 | return ret; |
| 774 | } |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 775 | static DEVICE_ATTR(updelay, S_IRUGO | S_IWUSR, |
| 776 | bonding_show_updelay, bonding_store_updelay); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 777 | |
| 778 | /* |
| 779 | * Show and set the LACP interval. Interface must be down, and the mode |
| 780 | * must be set to 802.3ad mode. |
| 781 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 782 | static ssize_t bonding_show_lacp(struct device *d, |
| 783 | struct device_attribute *attr, |
| 784 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 785 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 786 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 787 | |
| 788 | return sprintf(buf, "%s %d\n", |
| 789 | bond_lacp_tbl[bond->params.lacp_fast].modename, |
Wagner Ferenc | 7bd4650 | 2007-12-06 23:40:28 -0800 | [diff] [blame] | 790 | bond->params.lacp_fast); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 791 | } |
| 792 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 793 | static ssize_t bonding_store_lacp(struct device *d, |
| 794 | struct device_attribute *attr, |
| 795 | const char *buf, size_t count) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 796 | { |
| 797 | int new_value, ret = count; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 798 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 799 | |
| 800 | if (bond->dev->flags & IFF_UP) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 801 | 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] | 802 | bond->dev->name); |
| 803 | ret = -EPERM; |
| 804 | goto out; |
| 805 | } |
| 806 | |
| 807 | if (bond->params.mode != BOND_MODE_8023AD) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 808 | 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] | 809 | bond->dev->name); |
| 810 | ret = -EPERM; |
| 811 | goto out; |
| 812 | } |
| 813 | |
Jay Vosburgh | ece95f7 | 2008-01-17 16:25:01 -0800 | [diff] [blame] | 814 | new_value = bond_parse_parm(buf, bond_lacp_tbl); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 815 | |
| 816 | if ((new_value == 1) || (new_value == 0)) { |
| 817 | bond->params.lacp_fast = new_value; |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 818 | pr_info("%s: Setting LACP rate to %s (%d).\n", |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 819 | bond->dev->name, bond_lacp_tbl[new_value].modename, |
| 820 | new_value); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 821 | } else { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 822 | pr_err("%s: Ignoring invalid LACP rate value %.*s.\n", |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 823 | bond->dev->name, (int)strlen(buf) - 1, buf); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 824 | ret = -EINVAL; |
| 825 | } |
| 826 | out: |
| 827 | return ret; |
| 828 | } |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 829 | static DEVICE_ATTR(lacp_rate, S_IRUGO | S_IWUSR, |
| 830 | bonding_show_lacp, bonding_store_lacp); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 831 | |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 832 | static ssize_t bonding_show_ad_select(struct device *d, |
| 833 | struct device_attribute *attr, |
| 834 | char *buf) |
| 835 | { |
| 836 | struct bonding *bond = to_bond(d); |
| 837 | |
| 838 | return sprintf(buf, "%s %d\n", |
| 839 | ad_select_tbl[bond->params.ad_select].modename, |
| 840 | bond->params.ad_select); |
| 841 | } |
| 842 | |
| 843 | |
| 844 | static ssize_t bonding_store_ad_select(struct device *d, |
| 845 | struct device_attribute *attr, |
| 846 | const char *buf, size_t count) |
| 847 | { |
| 848 | int new_value, ret = count; |
| 849 | struct bonding *bond = to_bond(d); |
| 850 | |
| 851 | if (bond->dev->flags & IFF_UP) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 852 | pr_err("%s: Unable to update ad_select because interface is up.\n", |
| 853 | bond->dev->name); |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 854 | ret = -EPERM; |
| 855 | goto out; |
| 856 | } |
| 857 | |
| 858 | new_value = bond_parse_parm(buf, ad_select_tbl); |
| 859 | |
| 860 | if (new_value != -1) { |
| 861 | bond->params.ad_select = new_value; |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 862 | pr_info("%s: Setting ad_select to %s (%d).\n", |
| 863 | bond->dev->name, ad_select_tbl[new_value].modename, |
| 864 | new_value); |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 865 | } else { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 866 | pr_err("%s: Ignoring invalid ad_select value %.*s.\n", |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 867 | bond->dev->name, (int)strlen(buf) - 1, buf); |
| 868 | ret = -EINVAL; |
| 869 | } |
| 870 | out: |
| 871 | return ret; |
| 872 | } |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 873 | static DEVICE_ATTR(ad_select, S_IRUGO | S_IWUSR, |
| 874 | bonding_show_ad_select, bonding_store_ad_select); |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 875 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 876 | /* |
Moni Shoua | 7893b24 | 2008-05-17 21:10:12 -0700 | [diff] [blame] | 877 | * Show and set the number of grat ARP to send after a failover event. |
| 878 | */ |
| 879 | static ssize_t bonding_show_n_grat_arp(struct device *d, |
| 880 | struct device_attribute *attr, |
| 881 | char *buf) |
| 882 | { |
| 883 | struct bonding *bond = to_bond(d); |
| 884 | |
| 885 | return sprintf(buf, "%d\n", bond->params.num_grat_arp); |
| 886 | } |
| 887 | |
| 888 | static ssize_t bonding_store_n_grat_arp(struct device *d, |
| 889 | struct device_attribute *attr, |
| 890 | const char *buf, size_t count) |
| 891 | { |
| 892 | int new_value, ret = count; |
| 893 | struct bonding *bond = to_bond(d); |
| 894 | |
| 895 | if (sscanf(buf, "%d", &new_value) != 1) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 896 | pr_err("%s: no num_grat_arp value specified.\n", |
Moni Shoua | 7893b24 | 2008-05-17 21:10:12 -0700 | [diff] [blame] | 897 | bond->dev->name); |
| 898 | ret = -EINVAL; |
| 899 | goto out; |
| 900 | } |
| 901 | if (new_value < 0 || new_value > 255) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 902 | pr_err("%s: Invalid num_grat_arp value %d not in range 0-255; rejected.\n", |
Moni Shoua | 7893b24 | 2008-05-17 21:10:12 -0700 | [diff] [blame] | 903 | bond->dev->name, new_value); |
| 904 | ret = -EINVAL; |
| 905 | goto out; |
| 906 | } else { |
| 907 | bond->params.num_grat_arp = new_value; |
| 908 | } |
| 909 | out: |
| 910 | return ret; |
| 911 | } |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 912 | static DEVICE_ATTR(num_grat_arp, S_IRUGO | S_IWUSR, |
| 913 | bonding_show_n_grat_arp, bonding_store_n_grat_arp); |
Brian Haley | 305d552 | 2008-11-04 17:51:14 -0800 | [diff] [blame] | 914 | |
| 915 | /* |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 916 | * Show and set the number of unsolicited NA's to send after a failover event. |
Brian Haley | 305d552 | 2008-11-04 17:51:14 -0800 | [diff] [blame] | 917 | */ |
| 918 | static ssize_t bonding_show_n_unsol_na(struct device *d, |
| 919 | struct device_attribute *attr, |
| 920 | char *buf) |
| 921 | { |
| 922 | struct bonding *bond = to_bond(d); |
| 923 | |
| 924 | return sprintf(buf, "%d\n", bond->params.num_unsol_na); |
| 925 | } |
| 926 | |
| 927 | static ssize_t bonding_store_n_unsol_na(struct device *d, |
| 928 | struct device_attribute *attr, |
| 929 | const char *buf, size_t count) |
| 930 | { |
| 931 | int new_value, ret = count; |
| 932 | struct bonding *bond = to_bond(d); |
| 933 | |
| 934 | if (sscanf(buf, "%d", &new_value) != 1) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 935 | pr_err("%s: no num_unsol_na value specified.\n", |
Brian Haley | 305d552 | 2008-11-04 17:51:14 -0800 | [diff] [blame] | 936 | bond->dev->name); |
| 937 | ret = -EINVAL; |
| 938 | goto out; |
| 939 | } |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 940 | |
Brian Haley | 305d552 | 2008-11-04 17:51:14 -0800 | [diff] [blame] | 941 | if (new_value < 0 || new_value > 255) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 942 | pr_err("%s: Invalid num_unsol_na value %d not in range 0-255; rejected.\n", |
Brian Haley | 305d552 | 2008-11-04 17:51:14 -0800 | [diff] [blame] | 943 | bond->dev->name, new_value); |
| 944 | ret = -EINVAL; |
| 945 | goto out; |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 946 | } else |
Brian Haley | 305d552 | 2008-11-04 17:51:14 -0800 | [diff] [blame] | 947 | bond->params.num_unsol_na = new_value; |
Brian Haley | 305d552 | 2008-11-04 17:51:14 -0800 | [diff] [blame] | 948 | out: |
| 949 | return ret; |
| 950 | } |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 951 | static DEVICE_ATTR(num_unsol_na, S_IRUGO | S_IWUSR, |
| 952 | bonding_show_n_unsol_na, bonding_store_n_unsol_na); |
Brian Haley | 305d552 | 2008-11-04 17:51:14 -0800 | [diff] [blame] | 953 | |
Moni Shoua | 7893b24 | 2008-05-17 21:10:12 -0700 | [diff] [blame] | 954 | /* |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 955 | * Show and set the MII monitor interval. There are two tricky bits |
| 956 | * here. First, if MII monitoring is activated, then we must disable |
| 957 | * ARP monitoring. Second, if the timer isn't running, we must |
| 958 | * start it. |
| 959 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 960 | static ssize_t bonding_show_miimon(struct device *d, |
| 961 | struct device_attribute *attr, |
| 962 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 963 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 964 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 965 | |
Wagner Ferenc | 7bd4650 | 2007-12-06 23:40:28 -0800 | [diff] [blame] | 966 | return sprintf(buf, "%d\n", bond->params.miimon); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 967 | } |
| 968 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 969 | static ssize_t bonding_store_miimon(struct device *d, |
| 970 | struct device_attribute *attr, |
| 971 | const char *buf, size_t count) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 972 | { |
| 973 | int new_value, ret = count; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 974 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 975 | |
| 976 | if (sscanf(buf, "%d", &new_value) != 1) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 977 | pr_err("%s: no miimon value specified.\n", |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 978 | bond->dev->name); |
| 979 | ret = -EINVAL; |
| 980 | goto out; |
| 981 | } |
| 982 | if (new_value < 0) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 983 | 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] | 984 | bond->dev->name, new_value, 1, INT_MAX); |
| 985 | ret = -EINVAL; |
| 986 | goto out; |
| 987 | } else { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 988 | pr_info("%s: Setting MII monitoring interval to %d.\n", |
| 989 | bond->dev->name, new_value); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 990 | bond->params.miimon = new_value; |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 991 | if (bond->params.updelay) |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 992 | pr_info("%s: Note: Updating updelay (to %d) since it is a multiple of the miimon value.\n", |
| 993 | bond->dev->name, |
| 994 | bond->params.updelay * bond->params.miimon); |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 995 | if (bond->params.downdelay) |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 996 | pr_info("%s: Note: Updating downdelay (to %d) since it is a multiple of the miimon value.\n", |
| 997 | bond->dev->name, |
| 998 | bond->params.downdelay * bond->params.miimon); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 999 | if (bond->params.arp_interval) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1000 | pr_info("%s: MII monitoring cannot be used with ARP monitoring. Disabling ARP monitoring...\n", |
| 1001 | bond->dev->name); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1002 | bond->params.arp_interval = 0; |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 1003 | if (bond->params.arp_validate) { |
| 1004 | bond_unregister_arp(bond); |
| 1005 | bond->params.arp_validate = |
| 1006 | BOND_ARP_VALIDATE_NONE; |
| 1007 | } |
Jay Vosburgh | 1b76b31 | 2007-10-17 17:37:45 -0700 | [diff] [blame] | 1008 | if (delayed_work_pending(&bond->arp_work)) { |
| 1009 | cancel_delayed_work(&bond->arp_work); |
| 1010 | flush_workqueue(bond->wq); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1011 | } |
| 1012 | } |
| 1013 | |
| 1014 | if (bond->dev->flags & IFF_UP) { |
| 1015 | /* If the interface is up, we may need to fire off |
| 1016 | * the MII timer. If the interface is down, the |
| 1017 | * timer will get fired off when the open function |
| 1018 | * is called. |
| 1019 | */ |
Jay Vosburgh | 1b76b31 | 2007-10-17 17:37:45 -0700 | [diff] [blame] | 1020 | if (!delayed_work_pending(&bond->mii_work)) { |
| 1021 | INIT_DELAYED_WORK(&bond->mii_work, |
| 1022 | bond_mii_monitor); |
| 1023 | queue_delayed_work(bond->wq, |
| 1024 | &bond->mii_work, 0); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1025 | } |
| 1026 | } |
| 1027 | } |
| 1028 | out: |
| 1029 | return ret; |
| 1030 | } |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1031 | static DEVICE_ATTR(miimon, S_IRUGO | S_IWUSR, |
| 1032 | bonding_show_miimon, bonding_store_miimon); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1033 | |
| 1034 | /* |
| 1035 | * Show and set the primary slave. The store function is much |
| 1036 | * simpler than bonding_store_slaves function because it only needs to |
| 1037 | * handle one interface name. |
| 1038 | * The bond must be a mode that supports a primary for this be |
| 1039 | * set. |
| 1040 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1041 | static ssize_t bonding_show_primary(struct device *d, |
| 1042 | struct device_attribute *attr, |
| 1043 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1044 | { |
| 1045 | int count = 0; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1046 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1047 | |
| 1048 | if (bond->primary_slave) |
Wagner Ferenc | 7bd4650 | 2007-12-06 23:40:28 -0800 | [diff] [blame] | 1049 | count = sprintf(buf, "%s\n", bond->primary_slave->dev->name); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1050 | |
| 1051 | return count; |
| 1052 | } |
| 1053 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1054 | static ssize_t bonding_store_primary(struct device *d, |
| 1055 | struct device_attribute *attr, |
| 1056 | const char *buf, size_t count) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1057 | { |
| 1058 | int i; |
| 1059 | struct slave *slave; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1060 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1061 | |
Eric W. Biederman | 496a60c | 2009-05-13 17:02:50 +0000 | [diff] [blame] | 1062 | if (!rtnl_trylock()) |
| 1063 | return restart_syscall(); |
Neil Horman | e843fa5 | 2010-10-13 16:01:50 +0000 | [diff] [blame] | 1064 | block_netpoll_tx(); |
Jay Vosburgh | e934dd7 | 2008-01-17 16:24:57 -0800 | [diff] [blame] | 1065 | read_lock(&bond->lock); |
| 1066 | write_lock_bh(&bond->curr_slave_lock); |
| 1067 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1068 | if (!USES_PRIMARY(bond->params.mode)) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1069 | pr_info("%s: Unable to set primary slave; %s is in mode %d\n", |
| 1070 | bond->dev->name, bond->dev->name, bond->params.mode); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1071 | } else { |
| 1072 | bond_for_each_slave(bond, slave, i) { |
| 1073 | if (strnicmp |
| 1074 | (slave->dev->name, buf, |
| 1075 | strlen(slave->dev->name)) == 0) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1076 | pr_info("%s: Setting %s as primary slave.\n", |
| 1077 | bond->dev->name, slave->dev->name); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1078 | bond->primary_slave = slave; |
Jiri Pirko | ce501ca | 2009-09-18 02:13:22 +0000 | [diff] [blame] | 1079 | strcpy(bond->params.primary, slave->dev->name); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1080 | bond_select_active_slave(bond); |
| 1081 | goto out; |
| 1082 | } |
| 1083 | } |
| 1084 | |
| 1085 | /* if we got here, then we didn't match the name of any slave */ |
| 1086 | |
| 1087 | if (strlen(buf) == 0 || buf[0] == '\n') { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1088 | pr_info("%s: Setting primary slave to None.\n", |
| 1089 | bond->dev->name); |
Luiz Fernando Capitulino | 3418db7 | 2006-02-01 00:54:34 -0800 | [diff] [blame] | 1090 | bond->primary_slave = NULL; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1091 | bond_select_active_slave(bond); |
| 1092 | } else { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1093 | pr_info("%s: Unable to set %.*s as primary slave as it is not a slave.\n", |
| 1094 | bond->dev->name, (int)strlen(buf) - 1, buf); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1095 | } |
| 1096 | } |
| 1097 | out: |
Jay Vosburgh | e934dd7 | 2008-01-17 16:24:57 -0800 | [diff] [blame] | 1098 | write_unlock_bh(&bond->curr_slave_lock); |
| 1099 | read_unlock(&bond->lock); |
Neil Horman | e843fa5 | 2010-10-13 16:01:50 +0000 | [diff] [blame] | 1100 | unblock_netpoll_tx(); |
Jay Vosburgh | 6603a6f | 2007-10-17 17:37:50 -0700 | [diff] [blame] | 1101 | rtnl_unlock(); |
| 1102 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1103 | return count; |
| 1104 | } |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1105 | static DEVICE_ATTR(primary, S_IRUGO | S_IWUSR, |
| 1106 | bonding_show_primary, bonding_store_primary); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1107 | |
| 1108 | /* |
Jiri Pirko | a549952 | 2009-09-25 03:28:09 +0000 | [diff] [blame] | 1109 | * Show and set the primary_reselect flag. |
| 1110 | */ |
| 1111 | static ssize_t bonding_show_primary_reselect(struct device *d, |
| 1112 | struct device_attribute *attr, |
| 1113 | char *buf) |
| 1114 | { |
| 1115 | struct bonding *bond = to_bond(d); |
| 1116 | |
| 1117 | return sprintf(buf, "%s %d\n", |
| 1118 | pri_reselect_tbl[bond->params.primary_reselect].modename, |
| 1119 | bond->params.primary_reselect); |
| 1120 | } |
| 1121 | |
| 1122 | static ssize_t bonding_store_primary_reselect(struct device *d, |
| 1123 | struct device_attribute *attr, |
| 1124 | const char *buf, size_t count) |
| 1125 | { |
| 1126 | int new_value, ret = count; |
| 1127 | struct bonding *bond = to_bond(d); |
| 1128 | |
| 1129 | if (!rtnl_trylock()) |
| 1130 | return restart_syscall(); |
| 1131 | |
| 1132 | new_value = bond_parse_parm(buf, pri_reselect_tbl); |
| 1133 | if (new_value < 0) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1134 | pr_err("%s: Ignoring invalid primary_reselect value %.*s.\n", |
Jiri Pirko | a549952 | 2009-09-25 03:28:09 +0000 | [diff] [blame] | 1135 | bond->dev->name, |
| 1136 | (int) strlen(buf) - 1, buf); |
| 1137 | ret = -EINVAL; |
| 1138 | goto out; |
| 1139 | } |
| 1140 | |
| 1141 | bond->params.primary_reselect = new_value; |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1142 | pr_info("%s: setting primary_reselect to %s (%d).\n", |
Jiri Pirko | a549952 | 2009-09-25 03:28:09 +0000 | [diff] [blame] | 1143 | bond->dev->name, pri_reselect_tbl[new_value].modename, |
| 1144 | new_value); |
| 1145 | |
Neil Horman | e843fa5 | 2010-10-13 16:01:50 +0000 | [diff] [blame] | 1146 | block_netpoll_tx(); |
Jiri Pirko | a549952 | 2009-09-25 03:28:09 +0000 | [diff] [blame] | 1147 | read_lock(&bond->lock); |
| 1148 | write_lock_bh(&bond->curr_slave_lock); |
| 1149 | bond_select_active_slave(bond); |
| 1150 | write_unlock_bh(&bond->curr_slave_lock); |
| 1151 | read_unlock(&bond->lock); |
Neil Horman | e843fa5 | 2010-10-13 16:01:50 +0000 | [diff] [blame] | 1152 | unblock_netpoll_tx(); |
Jiri Pirko | a549952 | 2009-09-25 03:28:09 +0000 | [diff] [blame] | 1153 | out: |
| 1154 | rtnl_unlock(); |
| 1155 | return ret; |
| 1156 | } |
| 1157 | static DEVICE_ATTR(primary_reselect, S_IRUGO | S_IWUSR, |
| 1158 | bonding_show_primary_reselect, |
| 1159 | bonding_store_primary_reselect); |
| 1160 | |
| 1161 | /* |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1162 | * Show and set the use_carrier flag. |
| 1163 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1164 | static ssize_t bonding_show_carrier(struct device *d, |
| 1165 | struct device_attribute *attr, |
| 1166 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1167 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1168 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1169 | |
Wagner Ferenc | 7bd4650 | 2007-12-06 23:40:28 -0800 | [diff] [blame] | 1170 | return sprintf(buf, "%d\n", bond->params.use_carrier); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1171 | } |
| 1172 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1173 | static ssize_t bonding_store_carrier(struct device *d, |
| 1174 | struct device_attribute *attr, |
| 1175 | const char *buf, size_t count) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1176 | { |
| 1177 | int new_value, ret = count; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1178 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1179 | |
| 1180 | |
| 1181 | if (sscanf(buf, "%d", &new_value) != 1) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1182 | pr_err("%s: no use_carrier value specified.\n", |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1183 | bond->dev->name); |
| 1184 | ret = -EINVAL; |
| 1185 | goto out; |
| 1186 | } |
| 1187 | if ((new_value == 0) || (new_value == 1)) { |
| 1188 | bond->params.use_carrier = new_value; |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1189 | pr_info("%s: Setting use_carrier to %d.\n", |
| 1190 | bond->dev->name, new_value); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1191 | } else { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1192 | pr_info("%s: Ignoring invalid use_carrier value %d.\n", |
| 1193 | bond->dev->name, new_value); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1194 | } |
| 1195 | out: |
Jiri Pirko | 672bda3 | 2011-01-25 11:03:25 +0000 | [diff] [blame] | 1196 | return ret; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1197 | } |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1198 | static DEVICE_ATTR(use_carrier, S_IRUGO | S_IWUSR, |
| 1199 | bonding_show_carrier, bonding_store_carrier); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1200 | |
| 1201 | |
| 1202 | /* |
| 1203 | * Show and set currently active_slave. |
| 1204 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1205 | static ssize_t bonding_show_active_slave(struct device *d, |
| 1206 | struct device_attribute *attr, |
| 1207 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1208 | { |
| 1209 | struct slave *curr; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1210 | struct bonding *bond = to_bond(d); |
Wagner Ferenc | 16cd016 | 2007-12-06 23:40:29 -0800 | [diff] [blame] | 1211 | int count = 0; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1212 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1213 | read_lock(&bond->curr_slave_lock); |
| 1214 | curr = bond->curr_active_slave; |
| 1215 | read_unlock(&bond->curr_slave_lock); |
| 1216 | |
| 1217 | if (USES_PRIMARY(bond->params.mode) && curr) |
Wagner Ferenc | 7bd4650 | 2007-12-06 23:40:28 -0800 | [diff] [blame] | 1218 | count = sprintf(buf, "%s\n", curr->dev->name); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1219 | return count; |
| 1220 | } |
| 1221 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1222 | static ssize_t bonding_store_active_slave(struct device *d, |
| 1223 | struct device_attribute *attr, |
| 1224 | const char *buf, size_t count) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1225 | { |
| 1226 | int i; |
| 1227 | struct slave *slave; |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1228 | struct slave *old_active = NULL; |
| 1229 | struct slave *new_active = NULL; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1230 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1231 | |
Eric W. Biederman | 496a60c | 2009-05-13 17:02:50 +0000 | [diff] [blame] | 1232 | if (!rtnl_trylock()) |
| 1233 | return restart_syscall(); |
Neil Horman | e843fa5 | 2010-10-13 16:01:50 +0000 | [diff] [blame] | 1234 | |
| 1235 | block_netpoll_tx(); |
Jay Vosburgh | e934dd7 | 2008-01-17 16:24:57 -0800 | [diff] [blame] | 1236 | read_lock(&bond->lock); |
| 1237 | write_lock_bh(&bond->curr_slave_lock); |
Jay Vosburgh | 1466a21 | 2007-11-06 13:33:28 -0800 | [diff] [blame] | 1238 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1239 | if (!USES_PRIMARY(bond->params.mode)) |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1240 | 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] | 1241 | bond->dev->name, bond->dev->name, bond->params.mode); |
| 1242 | else { |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1243 | bond_for_each_slave(bond, slave, i) { |
| 1244 | if (strnicmp |
| 1245 | (slave->dev->name, buf, |
| 1246 | strlen(slave->dev->name)) == 0) { |
| 1247 | old_active = bond->curr_active_slave; |
| 1248 | new_active = slave; |
Jay Vosburgh | a50d8de | 2006-09-22 21:53:25 -0700 | [diff] [blame] | 1249 | if (new_active == old_active) { |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1250 | /* do nothing */ |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1251 | pr_info("%s: %s is already the current active slave.\n", |
| 1252 | bond->dev->name, |
| 1253 | slave->dev->name); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1254 | goto out; |
| 1255 | } |
| 1256 | else { |
| 1257 | if ((new_active) && |
| 1258 | (old_active) && |
| 1259 | (new_active->link == BOND_LINK_UP) && |
| 1260 | IS_UP(new_active->dev)) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1261 | pr_info("%s: Setting %s as active slave.\n", |
| 1262 | bond->dev->name, |
| 1263 | slave->dev->name); |
Jiri Pirko | e5e2a8f | 2009-08-13 04:11:52 +0000 | [diff] [blame] | 1264 | bond_change_active_slave(bond, new_active); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1265 | } |
| 1266 | else { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1267 | pr_info("%s: Could not set %s as active slave; either %s is down or the link is down.\n", |
| 1268 | bond->dev->name, |
| 1269 | slave->dev->name, |
Jiri Pirko | e5e2a8f | 2009-08-13 04:11:52 +0000 | [diff] [blame] | 1270 | slave->dev->name); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1271 | } |
| 1272 | goto out; |
| 1273 | } |
| 1274 | } |
| 1275 | } |
| 1276 | |
| 1277 | /* if we got here, then we didn't match the name of any slave */ |
| 1278 | |
| 1279 | if (strlen(buf) == 0 || buf[0] == '\n') { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1280 | pr_info("%s: Setting active slave to None.\n", |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1281 | bond->dev->name); |
Luiz Fernando Capitulino | 3418db7 | 2006-02-01 00:54:34 -0800 | [diff] [blame] | 1282 | bond->primary_slave = NULL; |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1283 | bond_select_active_slave(bond); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1284 | } else { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1285 | 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] | 1286 | bond->dev->name, (int)strlen(buf) - 1, buf); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1287 | } |
| 1288 | } |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1289 | out: |
Jay Vosburgh | e934dd7 | 2008-01-17 16:24:57 -0800 | [diff] [blame] | 1290 | write_unlock_bh(&bond->curr_slave_lock); |
| 1291 | read_unlock(&bond->lock); |
Neil Horman | e843fa5 | 2010-10-13 16:01:50 +0000 | [diff] [blame] | 1292 | unblock_netpoll_tx(); |
| 1293 | |
Jay Vosburgh | 6603a6f | 2007-10-17 17:37:50 -0700 | [diff] [blame] | 1294 | rtnl_unlock(); |
| 1295 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1296 | return count; |
| 1297 | |
| 1298 | } |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1299 | static DEVICE_ATTR(active_slave, S_IRUGO | S_IWUSR, |
| 1300 | bonding_show_active_slave, bonding_store_active_slave); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1301 | |
| 1302 | |
| 1303 | /* |
| 1304 | * Show link status of the bond interface. |
| 1305 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1306 | static ssize_t bonding_show_mii_status(struct device *d, |
| 1307 | struct device_attribute *attr, |
| 1308 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1309 | { |
| 1310 | struct slave *curr; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1311 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1312 | |
| 1313 | read_lock(&bond->curr_slave_lock); |
| 1314 | curr = bond->curr_active_slave; |
| 1315 | read_unlock(&bond->curr_slave_lock); |
| 1316 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1317 | return sprintf(buf, "%s\n", curr ? "up" : "down"); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1318 | } |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1319 | static DEVICE_ATTR(mii_status, S_IRUGO, bonding_show_mii_status, NULL); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1320 | |
| 1321 | |
| 1322 | /* |
| 1323 | * Show current 802.3ad aggregator ID. |
| 1324 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1325 | static ssize_t bonding_show_ad_aggregator(struct device *d, |
| 1326 | struct device_attribute *attr, |
| 1327 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1328 | { |
| 1329 | int count = 0; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1330 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1331 | |
| 1332 | if (bond->params.mode == BOND_MODE_8023AD) { |
| 1333 | struct ad_info ad_info; |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1334 | count = sprintf(buf, "%d\n", |
| 1335 | (bond_3ad_get_active_agg_info(bond, &ad_info)) |
| 1336 | ? 0 : ad_info.aggregator_id); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1337 | } |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1338 | |
| 1339 | return count; |
| 1340 | } |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1341 | static DEVICE_ATTR(ad_aggregator, S_IRUGO, bonding_show_ad_aggregator, NULL); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1342 | |
| 1343 | |
| 1344 | /* |
| 1345 | * Show number of active 802.3ad ports. |
| 1346 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1347 | static ssize_t bonding_show_ad_num_ports(struct device *d, |
| 1348 | struct device_attribute *attr, |
| 1349 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1350 | { |
| 1351 | int count = 0; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1352 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1353 | |
| 1354 | if (bond->params.mode == BOND_MODE_8023AD) { |
| 1355 | struct ad_info ad_info; |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1356 | count = sprintf(buf, "%d\n", |
| 1357 | (bond_3ad_get_active_agg_info(bond, &ad_info)) |
| 1358 | ? 0 : ad_info.ports); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1359 | } |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1360 | |
| 1361 | return count; |
| 1362 | } |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1363 | 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] | 1364 | |
| 1365 | |
| 1366 | /* |
| 1367 | * Show current 802.3ad actor key. |
| 1368 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1369 | static ssize_t bonding_show_ad_actor_key(struct device *d, |
| 1370 | struct device_attribute *attr, |
| 1371 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1372 | { |
| 1373 | int count = 0; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1374 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1375 | |
| 1376 | if (bond->params.mode == BOND_MODE_8023AD) { |
| 1377 | struct ad_info ad_info; |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1378 | count = sprintf(buf, "%d\n", |
| 1379 | (bond_3ad_get_active_agg_info(bond, &ad_info)) |
| 1380 | ? 0 : ad_info.actor_key); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1381 | } |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1382 | |
| 1383 | return count; |
| 1384 | } |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1385 | 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] | 1386 | |
| 1387 | |
| 1388 | /* |
| 1389 | * Show current 802.3ad partner key. |
| 1390 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1391 | static ssize_t bonding_show_ad_partner_key(struct device *d, |
| 1392 | struct device_attribute *attr, |
| 1393 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1394 | { |
| 1395 | int count = 0; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1396 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1397 | |
| 1398 | if (bond->params.mode == BOND_MODE_8023AD) { |
| 1399 | struct ad_info ad_info; |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1400 | count = sprintf(buf, "%d\n", |
| 1401 | (bond_3ad_get_active_agg_info(bond, &ad_info)) |
| 1402 | ? 0 : ad_info.partner_key); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1403 | } |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1404 | |
| 1405 | return count; |
| 1406 | } |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1407 | 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] | 1408 | |
| 1409 | |
| 1410 | /* |
| 1411 | * Show current 802.3ad partner mac. |
| 1412 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1413 | static ssize_t bonding_show_ad_partner_mac(struct device *d, |
| 1414 | struct device_attribute *attr, |
| 1415 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1416 | { |
| 1417 | int count = 0; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1418 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1419 | |
| 1420 | if (bond->params.mode == BOND_MODE_8023AD) { |
| 1421 | struct ad_info ad_info; |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1422 | if (!bond_3ad_get_active_agg_info(bond, &ad_info)) |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 1423 | count = sprintf(buf, "%pM\n", ad_info.partner_system); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1424 | } |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1425 | |
| 1426 | return count; |
| 1427 | } |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1428 | 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] | 1429 | |
Andy Gospodarek | ebd8e49 | 2010-06-02 08:39:21 +0000 | [diff] [blame] | 1430 | /* |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 1431 | * Show the queue_ids of the slaves in the current bond. |
| 1432 | */ |
| 1433 | static ssize_t bonding_show_queue_id(struct device *d, |
| 1434 | struct device_attribute *attr, |
| 1435 | char *buf) |
| 1436 | { |
| 1437 | struct slave *slave; |
| 1438 | int i, res = 0; |
| 1439 | struct bonding *bond = to_bond(d); |
| 1440 | |
| 1441 | if (!rtnl_trylock()) |
| 1442 | return restart_syscall(); |
| 1443 | |
| 1444 | read_lock(&bond->lock); |
| 1445 | bond_for_each_slave(bond, slave, i) { |
Nicolas de Pesloüan | 7923668 | 2010-07-14 18:24:54 -0700 | [diff] [blame] | 1446 | if (res > (PAGE_SIZE - IFNAMSIZ - 6)) { |
| 1447 | /* not enough space for another interface_name:queue_id pair */ |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 1448 | if ((PAGE_SIZE - res) > 10) |
| 1449 | res = PAGE_SIZE - 10; |
| 1450 | res += sprintf(buf + res, "++more++ "); |
| 1451 | break; |
| 1452 | } |
| 1453 | res += sprintf(buf + res, "%s:%d ", |
| 1454 | slave->dev->name, slave->queue_id); |
| 1455 | } |
| 1456 | read_unlock(&bond->lock); |
| 1457 | if (res) |
| 1458 | buf[res-1] = '\n'; /* eat the leftover space */ |
| 1459 | rtnl_unlock(); |
| 1460 | return res; |
| 1461 | } |
| 1462 | |
| 1463 | /* |
| 1464 | * Set the queue_ids of the slaves in the current bond. The bond |
| 1465 | * interface must be enslaved for this to work. |
| 1466 | */ |
| 1467 | static ssize_t bonding_store_queue_id(struct device *d, |
| 1468 | struct device_attribute *attr, |
| 1469 | const char *buffer, size_t count) |
| 1470 | { |
| 1471 | struct slave *slave, *update_slave; |
| 1472 | struct bonding *bond = to_bond(d); |
| 1473 | u16 qid; |
| 1474 | int i, ret = count; |
| 1475 | char *delim; |
| 1476 | struct net_device *sdev = NULL; |
| 1477 | |
| 1478 | if (!rtnl_trylock()) |
| 1479 | return restart_syscall(); |
| 1480 | |
| 1481 | /* delim will point to queue id if successful */ |
| 1482 | delim = strchr(buffer, ':'); |
| 1483 | if (!delim) |
| 1484 | goto err_no_cmd; |
| 1485 | |
| 1486 | /* |
| 1487 | * Terminate string that points to device name and bump it |
| 1488 | * up one, so we can read the queue id there. |
| 1489 | */ |
| 1490 | *delim = '\0'; |
| 1491 | if (sscanf(++delim, "%hd\n", &qid) != 1) |
| 1492 | goto err_no_cmd; |
| 1493 | |
| 1494 | /* Check buffer length, valid ifname and queue id */ |
| 1495 | if (strlen(buffer) > IFNAMSIZ || |
| 1496 | !dev_valid_name(buffer) || |
| 1497 | qid > bond->params.tx_queues) |
| 1498 | goto err_no_cmd; |
| 1499 | |
| 1500 | /* Get the pointer to that interface if it exists */ |
| 1501 | sdev = __dev_get_by_name(dev_net(bond->dev), buffer); |
| 1502 | if (!sdev) |
| 1503 | goto err_no_cmd; |
| 1504 | |
| 1505 | read_lock(&bond->lock); |
| 1506 | |
| 1507 | /* Search for thes slave and check for duplicate qids */ |
| 1508 | update_slave = NULL; |
| 1509 | bond_for_each_slave(bond, slave, i) { |
| 1510 | if (sdev == slave->dev) |
| 1511 | /* |
| 1512 | * We don't need to check the matching |
| 1513 | * slave for dups, since we're overwriting it |
| 1514 | */ |
| 1515 | update_slave = slave; |
| 1516 | else if (qid && qid == slave->queue_id) { |
| 1517 | goto err_no_cmd_unlock; |
| 1518 | } |
| 1519 | } |
| 1520 | |
| 1521 | if (!update_slave) |
| 1522 | goto err_no_cmd_unlock; |
| 1523 | |
| 1524 | /* Actually set the qids for the slave */ |
| 1525 | update_slave->queue_id = qid; |
| 1526 | |
| 1527 | read_unlock(&bond->lock); |
| 1528 | out: |
| 1529 | rtnl_unlock(); |
| 1530 | return ret; |
| 1531 | |
| 1532 | err_no_cmd_unlock: |
| 1533 | read_unlock(&bond->lock); |
| 1534 | err_no_cmd: |
| 1535 | pr_info("invalid input for queue_id set for %s.\n", |
| 1536 | bond->dev->name); |
| 1537 | ret = -EPERM; |
| 1538 | goto out; |
| 1539 | } |
| 1540 | |
| 1541 | static DEVICE_ATTR(queue_id, S_IRUGO | S_IWUSR, bonding_show_queue_id, |
| 1542 | bonding_store_queue_id); |
| 1543 | |
| 1544 | |
| 1545 | /* |
Andy Gospodarek | ebd8e49 | 2010-06-02 08:39:21 +0000 | [diff] [blame] | 1546 | * Show and set the all_slaves_active flag. |
| 1547 | */ |
| 1548 | static ssize_t bonding_show_slaves_active(struct device *d, |
| 1549 | struct device_attribute *attr, |
| 1550 | char *buf) |
| 1551 | { |
| 1552 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1553 | |
Andy Gospodarek | ebd8e49 | 2010-06-02 08:39:21 +0000 | [diff] [blame] | 1554 | return sprintf(buf, "%d\n", bond->params.all_slaves_active); |
| 1555 | } |
| 1556 | |
| 1557 | static ssize_t bonding_store_slaves_active(struct device *d, |
| 1558 | struct device_attribute *attr, |
| 1559 | const char *buf, size_t count) |
| 1560 | { |
| 1561 | int i, new_value, ret = count; |
| 1562 | struct bonding *bond = to_bond(d); |
| 1563 | struct slave *slave; |
| 1564 | |
| 1565 | if (sscanf(buf, "%d", &new_value) != 1) { |
| 1566 | pr_err("%s: no all_slaves_active value specified.\n", |
| 1567 | bond->dev->name); |
| 1568 | ret = -EINVAL; |
| 1569 | goto out; |
| 1570 | } |
| 1571 | |
| 1572 | if (new_value == bond->params.all_slaves_active) |
| 1573 | goto out; |
| 1574 | |
| 1575 | if ((new_value == 0) || (new_value == 1)) { |
| 1576 | bond->params.all_slaves_active = new_value; |
| 1577 | } else { |
| 1578 | pr_info("%s: Ignoring invalid all_slaves_active value %d.\n", |
| 1579 | bond->dev->name, new_value); |
| 1580 | ret = -EINVAL; |
| 1581 | goto out; |
| 1582 | } |
| 1583 | |
| 1584 | bond_for_each_slave(bond, slave, i) { |
Jiri Pirko | e30bc06 | 2011-03-12 03:14:37 +0000 | [diff] [blame] | 1585 | if (!bond_is_active_slave(slave)) { |
Andy Gospodarek | ebd8e49 | 2010-06-02 08:39:21 +0000 | [diff] [blame] | 1586 | if (new_value) |
Jiri Pirko | 2d7011c | 2011-03-16 08:46:43 +0000 | [diff] [blame] | 1587 | slave->inactive = 0; |
Andy Gospodarek | ebd8e49 | 2010-06-02 08:39:21 +0000 | [diff] [blame] | 1588 | else |
Jiri Pirko | 2d7011c | 2011-03-16 08:46:43 +0000 | [diff] [blame] | 1589 | slave->inactive = 1; |
Andy Gospodarek | ebd8e49 | 2010-06-02 08:39:21 +0000 | [diff] [blame] | 1590 | } |
| 1591 | } |
| 1592 | out: |
Jiri Pirko | 672bda3 | 2011-01-25 11:03:25 +0000 | [diff] [blame] | 1593 | return ret; |
Andy Gospodarek | ebd8e49 | 2010-06-02 08:39:21 +0000 | [diff] [blame] | 1594 | } |
| 1595 | static DEVICE_ATTR(all_slaves_active, S_IRUGO | S_IWUSR, |
| 1596 | bonding_show_slaves_active, bonding_store_slaves_active); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1597 | |
Flavio Leitner | c2952c3 | 2010-10-05 14:23:59 +0000 | [diff] [blame] | 1598 | /* |
| 1599 | * Show and set the number of IGMP membership reports to send on link failure |
| 1600 | */ |
| 1601 | static ssize_t bonding_show_resend_igmp(struct device *d, |
| 1602 | struct device_attribute *attr, |
| 1603 | char *buf) |
| 1604 | { |
| 1605 | struct bonding *bond = to_bond(d); |
| 1606 | |
| 1607 | return sprintf(buf, "%d\n", bond->params.resend_igmp); |
| 1608 | } |
| 1609 | |
| 1610 | static ssize_t bonding_store_resend_igmp(struct device *d, |
| 1611 | struct device_attribute *attr, |
| 1612 | const char *buf, size_t count) |
| 1613 | { |
| 1614 | int new_value, ret = count; |
| 1615 | struct bonding *bond = to_bond(d); |
| 1616 | |
| 1617 | if (sscanf(buf, "%d", &new_value) != 1) { |
| 1618 | pr_err("%s: no resend_igmp value specified.\n", |
| 1619 | bond->dev->name); |
| 1620 | ret = -EINVAL; |
| 1621 | goto out; |
| 1622 | } |
| 1623 | |
| 1624 | if (new_value < 0) { |
| 1625 | pr_err("%s: Invalid resend_igmp value %d not in range 0-255; rejected.\n", |
| 1626 | bond->dev->name, new_value); |
| 1627 | ret = -EINVAL; |
| 1628 | goto out; |
| 1629 | } |
| 1630 | |
| 1631 | pr_info("%s: Setting resend_igmp to %d.\n", |
| 1632 | bond->dev->name, new_value); |
| 1633 | bond->params.resend_igmp = new_value; |
| 1634 | out: |
| 1635 | return ret; |
| 1636 | } |
| 1637 | |
| 1638 | static DEVICE_ATTR(resend_igmp, S_IRUGO | S_IWUSR, |
| 1639 | bonding_show_resend_igmp, bonding_store_resend_igmp); |
| 1640 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1641 | static struct attribute *per_bond_attrs[] = { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1642 | &dev_attr_slaves.attr, |
| 1643 | &dev_attr_mode.attr, |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 1644 | &dev_attr_fail_over_mac.attr, |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1645 | &dev_attr_arp_validate.attr, |
| 1646 | &dev_attr_arp_interval.attr, |
| 1647 | &dev_attr_arp_ip_target.attr, |
| 1648 | &dev_attr_downdelay.attr, |
| 1649 | &dev_attr_updelay.attr, |
| 1650 | &dev_attr_lacp_rate.attr, |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 1651 | &dev_attr_ad_select.attr, |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1652 | &dev_attr_xmit_hash_policy.attr, |
Moni Shoua | 7893b24 | 2008-05-17 21:10:12 -0700 | [diff] [blame] | 1653 | &dev_attr_num_grat_arp.attr, |
Brian Haley | 305d552 | 2008-11-04 17:51:14 -0800 | [diff] [blame] | 1654 | &dev_attr_num_unsol_na.attr, |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1655 | &dev_attr_miimon.attr, |
| 1656 | &dev_attr_primary.attr, |
Jiri Pirko | a549952 | 2009-09-25 03:28:09 +0000 | [diff] [blame] | 1657 | &dev_attr_primary_reselect.attr, |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1658 | &dev_attr_use_carrier.attr, |
| 1659 | &dev_attr_active_slave.attr, |
| 1660 | &dev_attr_mii_status.attr, |
| 1661 | &dev_attr_ad_aggregator.attr, |
| 1662 | &dev_attr_ad_num_ports.attr, |
| 1663 | &dev_attr_ad_actor_key.attr, |
| 1664 | &dev_attr_ad_partner_key.attr, |
| 1665 | &dev_attr_ad_partner_mac.attr, |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 1666 | &dev_attr_queue_id.attr, |
Andy Gospodarek | ebd8e49 | 2010-06-02 08:39:21 +0000 | [diff] [blame] | 1667 | &dev_attr_all_slaves_active.attr, |
Flavio Leitner | c2952c3 | 2010-10-05 14:23:59 +0000 | [diff] [blame] | 1668 | &dev_attr_resend_igmp.attr, |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1669 | NULL, |
| 1670 | }; |
| 1671 | |
| 1672 | static struct attribute_group bonding_group = { |
| 1673 | .name = "bonding", |
| 1674 | .attrs = per_bond_attrs, |
| 1675 | }; |
| 1676 | |
| 1677 | /* |
| 1678 | * Initialize sysfs. This sets up the bonding_masters file in |
| 1679 | * /sys/class/net. |
| 1680 | */ |
| 1681 | int bond_create_sysfs(void) |
| 1682 | { |
Jay Vosburgh | b8a9787 | 2008-06-13 18:12:04 -0700 | [diff] [blame] | 1683 | int ret; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1684 | |
Jay Vosburgh | b8a9787 | 2008-06-13 18:12:04 -0700 | [diff] [blame] | 1685 | ret = netdev_class_create_file(&class_attr_bonding_masters); |
Jay Vosburgh | 877cbd3 | 2007-01-19 18:15:47 -0800 | [diff] [blame] | 1686 | /* |
| 1687 | * Permit multiple loads of the module by ignoring failures to |
| 1688 | * create the bonding_masters sysfs file. Bonding devices |
| 1689 | * created by second or subsequent loads of the module will |
| 1690 | * not be listed in, or controllable by, bonding_masters, but |
| 1691 | * will have the usual "bonding" sysfs directory. |
| 1692 | * |
| 1693 | * This is done to preserve backwards compatibility for |
| 1694 | * initscripts/sysconfig, which load bonding multiple times to |
| 1695 | * configure multiple bonding devices. |
| 1696 | */ |
| 1697 | if (ret == -EEXIST) { |
Stephen Hemminger | 38d2f38 | 2008-05-14 22:35:04 -0700 | [diff] [blame] | 1698 | /* Is someone being kinky and naming a device bonding_master? */ |
| 1699 | if (__dev_get_by_name(&init_net, |
| 1700 | class_attr_bonding_masters.attr.name)) |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1701 | pr_err("network device named %s already exists in sysfs", |
Stephen Hemminger | 38d2f38 | 2008-05-14 22:35:04 -0700 | [diff] [blame] | 1702 | class_attr_bonding_masters.attr.name); |
Stephen Hemminger | 130aa61 | 2009-06-11 05:46:04 -0700 | [diff] [blame] | 1703 | ret = 0; |
Jay Vosburgh | 877cbd3 | 2007-01-19 18:15:47 -0800 | [diff] [blame] | 1704 | } |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1705 | |
| 1706 | return ret; |
| 1707 | |
| 1708 | } |
| 1709 | |
| 1710 | /* |
| 1711 | * Remove /sys/class/net/bonding_masters. |
| 1712 | */ |
| 1713 | void bond_destroy_sysfs(void) |
| 1714 | { |
Jay Vosburgh | b8a9787 | 2008-06-13 18:12:04 -0700 | [diff] [blame] | 1715 | netdev_class_remove_file(&class_attr_bonding_masters); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1716 | } |
| 1717 | |
| 1718 | /* |
| 1719 | * Initialize sysfs for each bond. This sets up and registers |
| 1720 | * the 'bondctl' directory for each individual bond under /sys/class/net. |
| 1721 | */ |
Eric W. Biederman | 6151b3d | 2009-10-29 14:18:22 +0000 | [diff] [blame] | 1722 | void bond_prepare_sysfs_group(struct bonding *bond) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1723 | { |
Eric W. Biederman | 6151b3d | 2009-10-29 14:18:22 +0000 | [diff] [blame] | 1724 | bond->dev->sysfs_groups[0] = &bonding_group; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1725 | } |
| 1726 | |