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