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