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