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