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