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