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