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