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