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