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