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