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