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