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