blob: 72bb0f6cc9bf39289ec7b9c0185f9d3ded6a4af8 [file] [log] [blame]
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001/*
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 Williamsb76cdba2005-11-09 10:36:41 -080021 */
Joe Perchesa4aee5c2009-12-13 20:06:07 -080022
23#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
24
Mitch Williamsb76cdba2005-11-09 10:36:41 -080025#include <linux/kernel.h>
26#include <linux/module.h>
Mitch Williamsb76cdba2005-11-09 10:36:41 -080027#include <linux/device.h>
Alexey Dobriyand43c36d2009-10-07 17:09:06 +040028#include <linux/sched.h>
Mitch Williamsb76cdba2005-11-09 10:36:41 -080029#include <linux/sysdev.h>
30#include <linux/fs.h>
31#include <linux/types.h>
32#include <linux/string.h>
33#include <linux/netdevice.h>
34#include <linux/inetdevice.h>
35#include <linux/in.h>
36#include <linux/sysfs.h>
Mitch Williamsb76cdba2005-11-09 10:36:41 -080037#include <linux/ctype.h>
38#include <linux/inet.h>
39#include <linux/rtnetlink.h>
Stephen Hemminger5c5129b2009-06-12 19:02:51 +000040#include <linux/etherdevice.h>
Eric W. Biederman881d9662007-09-17 11:56:21 -070041#include <net/net_namespace.h>
Eric W. Biedermanec87fd32009-10-29 14:18:26 +000042#include <net/netns/generic.h>
43#include <linux/nsproxy.h>
Mitch Williamsb76cdba2005-11-09 10:36:41 -080044
Mitch Williamsb76cdba2005-11-09 10:36:41 -080045#include "bonding.h"
Holger Eitzenberger5a03cdb2008-12-09 23:09:22 -080046
Stephen Hemminger3d632c32009-06-12 19:02:48 +000047#define to_dev(obj) container_of(obj, struct device, kobj)
Wang Chen454d7c92008-11-12 23:37:49 -080048#define to_bond(cd) ((struct bonding *)(netdev_priv(to_net_dev(cd))))
Mitch Williamsb76cdba2005-11-09 10:36:41 -080049
Mitch Williamsb76cdba2005-11-09 10:36:41 -080050/*
51 * "show" function for the bond_masters attribute.
52 * The class parameter is ignored.
53 */
Andi Kleen28812fe2010-01-05 12:48:07 +010054static ssize_t bonding_show_bonds(struct class *cls,
55 struct class_attribute *attr,
56 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -080057{
Eric W. Biedermanec87fd32009-10-29 14:18:26 +000058 struct net *net = current->nsproxy->net_ns;
59 struct bond_net *bn = net_generic(net, bond_net_id);
Mitch Williamsb76cdba2005-11-09 10:36:41 -080060 int res = 0;
61 struct bonding *bond;
62
Stephen Hemminger7e083842009-06-12 19:02:46 +000063 rtnl_lock();
Mitch Williamsb76cdba2005-11-09 10:36:41 -080064
Eric W. Biedermanec87fd32009-10-29 14:18:26 +000065 list_for_each_entry(bond, &bn->dev_list, bond_list) {
Mitch Williamsb76cdba2005-11-09 10:36:41 -080066 if (res > (PAGE_SIZE - IFNAMSIZ)) {
67 /* not enough space for another interface name */
68 if ((PAGE_SIZE - res) > 10)
69 res = PAGE_SIZE - 10;
Wagner Ferencb8843662007-12-06 23:40:30 -080070 res += sprintf(buf + res, "++more++ ");
Mitch Williamsb76cdba2005-11-09 10:36:41 -080071 break;
72 }
Wagner Ferencb8843662007-12-06 23:40:30 -080073 res += sprintf(buf + res, "%s ", bond->dev->name);
Mitch Williamsb76cdba2005-11-09 10:36:41 -080074 }
Wagner Ferenc1dcdcd62007-12-06 23:40:31 -080075 if (res)
76 buf[res-1] = '\n'; /* eat the leftover space */
Stephen Hemminger7e083842009-06-12 19:02:46 +000077
78 rtnl_unlock();
Mitch Williamsb76cdba2005-11-09 10:36:41 -080079 return res;
80}
81
Eric W. Biedermanec87fd32009-10-29 14:18:26 +000082static struct net_device *bond_get_by_name(struct net *net, const char *ifname)
Stephen Hemminger373500d2009-06-12 19:02:50 +000083{
Eric W. Biedermanec87fd32009-10-29 14:18:26 +000084 struct bond_net *bn = net_generic(net, bond_net_id);
Stephen Hemminger373500d2009-06-12 19:02:50 +000085 struct bonding *bond;
86
Eric W. Biedermanec87fd32009-10-29 14:18:26 +000087 list_for_each_entry(bond, &bn->dev_list, bond_list) {
Stephen Hemminger373500d2009-06-12 19:02:50 +000088 if (strncmp(bond->dev->name, ifname, IFNAMSIZ) == 0)
89 return bond->dev;
90 }
91 return NULL;
92}
93
Mitch Williamsb76cdba2005-11-09 10:36:41 -080094/*
95 * "store" function for the bond_masters attribute. This is what
96 * creates and deletes entire bonds.
97 *
98 * The class parameter is ignored.
99 *
100 */
101
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000102static ssize_t bonding_store_bonds(struct class *cls,
Andi Kleen28812fe2010-01-05 12:48:07 +0100103 struct class_attribute *attr,
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000104 const char *buffer, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800105{
Eric W. Biedermanec87fd32009-10-29 14:18:26 +0000106 struct net *net = current->nsproxy->net_ns;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800107 char command[IFNAMSIZ + 1] = {0, };
108 char *ifname;
Jay Vosburgh027ea042008-01-17 16:25:02 -0800109 int rv, res = count;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800110
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800111 sscanf(buffer, "%16s", command); /* IFNAMSIZ*/
112 ifname = command + 1;
113 if ((strlen(command) <= 1) ||
114 !dev_valid_name(ifname))
115 goto err_no_cmd;
116
117 if (command[0] == '+') {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800118 pr_info("%s is being created...\n", ifname);
Eric W. Biedermanec87fd32009-10-29 14:18:26 +0000119 rv = bond_create(net, ifname);
Jay Vosburgh027ea042008-01-17 16:25:02 -0800120 if (rv) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800121 pr_info("Bond creation failed.\n");
Jay Vosburgh027ea042008-01-17 16:25:02 -0800122 res = rv;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800123 }
Stephen Hemminger373500d2009-06-12 19:02:50 +0000124 } else if (command[0] == '-') {
125 struct net_device *bond_dev;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800126
Jay Vosburgh027ea042008-01-17 16:25:02 -0800127 rtnl_lock();
Eric W. Biedermanec87fd32009-10-29 14:18:26 +0000128 bond_dev = bond_get_by_name(net, ifname);
Stephen Hemminger373500d2009-06-12 19:02:50 +0000129 if (bond_dev) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800130 pr_info("%s is being deleted...\n", ifname);
Stephen Hemminger373500d2009-06-12 19:02:50 +0000131 unregister_netdevice(bond_dev);
132 } else {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800133 pr_err("unable to delete non-existent %s\n", ifname);
Stephen Hemminger373500d2009-06-12 19:02:50 +0000134 res = -ENODEV;
135 }
136 rtnl_unlock();
137 } else
138 goto err_no_cmd;
Jay Vosburgh027ea042008-01-17 16:25:02 -0800139
Stephen Hemminger373500d2009-06-12 19:02:50 +0000140 /* Always return either count or an error. If you return 0, you'll
141 * get called forever, which is bad.
142 */
143 return res;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800144
145err_no_cmd:
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800146 pr_err("no command found in bonding_masters. Use +ifname or -ifname.\n");
Jay Vosburghc4ebc662008-05-02 17:49:38 -0700147 return -EPERM;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800148}
Stephen Hemminger373500d2009-06-12 19:02:50 +0000149
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800150/* class attribute for bond_masters file. This ends up in /sys/class/net */
151static CLASS_ATTR(bonding_masters, S_IWUSR | S_IRUGO,
152 bonding_show_bonds, bonding_store_bonds);
153
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000154int bond_create_slave_symlinks(struct net_device *master,
155 struct net_device *slave)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800156{
157 char linkname[IFNAMSIZ+7];
158 int ret = 0;
159
160 /* first, create a link from the slave back to the master */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700161 ret = sysfs_create_link(&(slave->dev.kobj), &(master->dev.kobj),
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800162 "master");
163 if (ret)
164 return ret;
165 /* next, create a link from the master to the slave */
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000166 sprintf(linkname, "slave_%s", slave->name);
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700167 ret = sysfs_create_link(&(master->dev.kobj), &(slave->dev.kobj),
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800168 linkname);
169 return ret;
170
171}
172
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000173void bond_destroy_slave_symlinks(struct net_device *master,
174 struct net_device *slave)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800175{
176 char linkname[IFNAMSIZ+7];
177
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700178 sysfs_remove_link(&(slave->dev.kobj), "master");
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000179 sprintf(linkname, "slave_%s", slave->name);
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700180 sysfs_remove_link(&(master->dev.kobj), linkname);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800181}
182
183
184/*
185 * Show the slaves in the current bond.
186 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700187static ssize_t bonding_show_slaves(struct device *d,
188 struct device_attribute *attr, char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800189{
190 struct slave *slave;
191 int i, res = 0;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700192 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800193
Jay Vosburgh6603a6f2007-10-17 17:37:50 -0700194 read_lock(&bond->lock);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800195 bond_for_each_slave(bond, slave, i) {
196 if (res > (PAGE_SIZE - IFNAMSIZ)) {
197 /* not enough space for another interface name */
198 if ((PAGE_SIZE - res) > 10)
199 res = PAGE_SIZE - 10;
Wagner Ferenc7bd46502007-12-06 23:40:28 -0800200 res += sprintf(buf + res, "++more++ ");
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800201 break;
202 }
203 res += sprintf(buf + res, "%s ", slave->dev->name);
204 }
Jay Vosburgh6603a6f2007-10-17 17:37:50 -0700205 read_unlock(&bond->lock);
Wagner Ferenc1dcdcd62007-12-06 23:40:31 -0800206 if (res)
207 buf[res-1] = '\n'; /* eat the leftover space */
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800208 return res;
209}
210
211/*
212 * Set the slaves in the current bond. The bond interface must be
213 * up for this to succeed.
Jiri Pirkof9f35452010-05-18 05:46:39 +0000214 * This is supposed to be only thin wrapper for bond_enslave and bond_release.
215 * All hard work should be done there.
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800216 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700217static ssize_t bonding_store_slaves(struct device *d,
218 struct device_attribute *attr,
219 const char *buffer, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800220{
221 char command[IFNAMSIZ + 1] = { 0, };
222 char *ifname;
Jiri Pirkof9f35452010-05-18 05:46:39 +0000223 int res, ret = count;
224 struct net_device *dev;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700225 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800226
227 /* Quick sanity check -- is the bond interface up? */
228 if (!(bond->dev->flags & IFF_UP)) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800229 pr_warning("%s: doing slave updates when interface is down.\n",
230 bond->dev->name);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800231 }
232
Eric W. Biederman496a60c2009-05-13 17:02:50 +0000233 if (!rtnl_trylock())
234 return restart_syscall();
Jay Vosburgh027ea042008-01-17 16:25:02 -0800235
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800236 sscanf(buffer, "%16s", command); /* IFNAMSIZ*/
237 ifname = command + 1;
238 if ((strlen(command) <= 1) ||
239 !dev_valid_name(ifname))
240 goto err_no_cmd;
241
Jiri Pirkof9f35452010-05-18 05:46:39 +0000242 dev = __dev_get_by_name(dev_net(bond->dev), ifname);
243 if (!dev) {
244 pr_info("%s: Interface %s does not exist!\n",
245 bond->dev->name, ifname);
246 ret = -ENODEV;
247 goto out;
248 }
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800249
Jiri Pirkof9f35452010-05-18 05:46:39 +0000250 switch (command[0]) {
251 case '+':
252 pr_info("%s: Adding slave %s.\n", bond->dev->name, dev->name);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800253 res = bond_enslave(bond->dev, dev);
Jiri Pirkof9f35452010-05-18 05:46:39 +0000254 break;
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000255
Jiri Pirkof9f35452010-05-18 05:46:39 +0000256 case '-':
257 pr_info("%s: Removing slave %s.\n", bond->dev->name, dev->name);
258 res = bond_release(bond->dev, dev);
259 break;
260
261 default:
262 goto err_no_cmd;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800263 }
264
Jiri Pirkof9f35452010-05-18 05:46:39 +0000265 if (res)
266 ret = res;
267 goto out;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800268
269err_no_cmd:
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800270 pr_err("no command found in slaves file for bond %s. Use +ifname or -ifname.\n",
271 bond->dev->name);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800272 ret = -EPERM;
273
274out:
Jay Vosburgh027ea042008-01-17 16:25:02 -0800275 rtnl_unlock();
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800276 return ret;
277}
278
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000279static DEVICE_ATTR(slaves, S_IRUGO | S_IWUSR, bonding_show_slaves,
280 bonding_store_slaves);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800281
282/*
283 * Show and set the bonding mode. The bond interface must be down to
284 * change the mode.
285 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700286static ssize_t bonding_show_mode(struct device *d,
287 struct device_attribute *attr, char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800288{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700289 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800290
291 return sprintf(buf, "%s %d\n",
292 bond_mode_tbl[bond->params.mode].modename,
Wagner Ferenc7bd46502007-12-06 23:40:28 -0800293 bond->params.mode);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800294}
295
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700296static ssize_t bonding_store_mode(struct device *d,
297 struct device_attribute *attr,
298 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800299{
300 int new_value, ret = count;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700301 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800302
303 if (bond->dev->flags & IFF_UP) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800304 pr_err("unable to update mode of %s because interface is up.\n",
305 bond->dev->name);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800306 ret = -EPERM;
307 goto out;
308 }
309
Jay Vosburghece95f72008-01-17 16:25:01 -0800310 new_value = bond_parse_parm(buf, bond_mode_tbl);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800311 if (new_value < 0) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800312 pr_err("%s: Ignoring invalid mode value %.*s.\n",
313 bond->dev->name, (int)strlen(buf) - 1, buf);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800314 ret = -EINVAL;
315 goto out;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800316 }
Andy Gospodarekc5cb0022010-07-28 15:13:56 +0000317 if ((new_value == BOND_MODE_ALB ||
318 new_value == BOND_MODE_TLB) &&
319 bond->params.arp_interval) {
320 pr_err("%s: %s mode is incompatible with arp monitoring.\n",
321 bond->dev->name, bond_mode_tbl[new_value].modename);
322 ret = -EINVAL;
323 goto out;
324 }
325 if (bond->params.mode == BOND_MODE_8023AD)
326 bond_unset_master_3ad_flags(bond);
327
328 if (bond->params.mode == BOND_MODE_ALB)
329 bond_unset_master_alb_flags(bond);
330
331 bond->params.mode = new_value;
332 bond_set_mode_ops(bond, bond->params.mode);
333 pr_info("%s: setting mode to %s (%d).\n",
334 bond->dev->name, bond_mode_tbl[new_value].modename,
335 new_value);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800336out:
337 return ret;
338}
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000339static DEVICE_ATTR(mode, S_IRUGO | S_IWUSR,
340 bonding_show_mode, bonding_store_mode);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800341
342/*
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000343 * Show and set the bonding transmit hash method.
344 * The bond interface must be down to change the xmit hash policy.
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800345 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700346static ssize_t bonding_show_xmit_hash(struct device *d,
347 struct device_attribute *attr,
348 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800349{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700350 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800351
Wagner Ferenc8e4b9322007-12-06 23:40:32 -0800352 return sprintf(buf, "%s %d\n",
353 xmit_hashtype_tbl[bond->params.xmit_policy].modename,
354 bond->params.xmit_policy);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800355}
356
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700357static ssize_t bonding_store_xmit_hash(struct device *d,
358 struct device_attribute *attr,
359 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800360{
361 int new_value, ret = count;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700362 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800363
364 if (bond->dev->flags & IFF_UP) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800365 pr_err("%s: Interface is up. Unable to update xmit policy.\n",
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800366 bond->dev->name);
367 ret = -EPERM;
368 goto out;
369 }
370
Jay Vosburghece95f72008-01-17 16:25:01 -0800371 new_value = bond_parse_parm(buf, xmit_hashtype_tbl);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800372 if (new_value < 0) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800373 pr_err("%s: Ignoring invalid xmit hash policy value %.*s.\n",
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800374 bond->dev->name,
375 (int)strlen(buf) - 1, buf);
376 ret = -EINVAL;
377 goto out;
378 } else {
379 bond->params.xmit_policy = new_value;
380 bond_set_mode_ops(bond, bond->params.mode);
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800381 pr_info("%s: setting xmit hash policy to %s (%d).\n",
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000382 bond->dev->name,
383 xmit_hashtype_tbl[new_value].modename, new_value);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800384 }
385out:
386 return ret;
387}
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000388static DEVICE_ATTR(xmit_hash_policy, S_IRUGO | S_IWUSR,
389 bonding_show_xmit_hash, bonding_store_xmit_hash);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800390
391/*
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700392 * Show and set arp_validate.
393 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700394static ssize_t bonding_show_arp_validate(struct device *d,
395 struct device_attribute *attr,
396 char *buf)
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700397{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700398 struct bonding *bond = to_bond(d);
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700399
400 return sprintf(buf, "%s %d\n",
401 arp_validate_tbl[bond->params.arp_validate].modename,
Wagner Ferenc7bd46502007-12-06 23:40:28 -0800402 bond->params.arp_validate);
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700403}
404
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700405static ssize_t bonding_store_arp_validate(struct device *d,
406 struct device_attribute *attr,
407 const char *buf, size_t count)
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700408{
409 int new_value;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700410 struct bonding *bond = to_bond(d);
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700411
Jay Vosburghece95f72008-01-17 16:25:01 -0800412 new_value = bond_parse_parm(buf, arp_validate_tbl);
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700413 if (new_value < 0) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800414 pr_err("%s: Ignoring invalid arp_validate value %s\n",
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700415 bond->dev->name, buf);
416 return -EINVAL;
417 }
418 if (new_value && (bond->params.mode != BOND_MODE_ACTIVEBACKUP)) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800419 pr_err("%s: arp_validate only supported in active-backup mode.\n",
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700420 bond->dev->name);
421 return -EINVAL;
422 }
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800423 pr_info("%s: setting arp_validate to %s (%d).\n",
424 bond->dev->name, arp_validate_tbl[new_value].modename,
425 new_value);
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700426
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000427 if (!bond->params.arp_validate && new_value)
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700428 bond_register_arp(bond);
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000429 else if (bond->params.arp_validate && !new_value)
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700430 bond_unregister_arp(bond);
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700431
432 bond->params.arp_validate = new_value;
433
434 return count;
435}
436
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000437static DEVICE_ATTR(arp_validate, S_IRUGO | S_IWUSR, bonding_show_arp_validate,
438 bonding_store_arp_validate);
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700439
440/*
Jay Vosburghdd957c52007-10-09 19:57:24 -0700441 * Show and store fail_over_mac. User only allowed to change the
442 * value when there are no slaves.
443 */
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000444static ssize_t bonding_show_fail_over_mac(struct device *d,
445 struct device_attribute *attr,
446 char *buf)
Jay Vosburghdd957c52007-10-09 19:57:24 -0700447{
448 struct bonding *bond = to_bond(d);
449
Jay Vosburgh3915c1e82008-05-17 21:10:14 -0700450 return sprintf(buf, "%s %d\n",
451 fail_over_mac_tbl[bond->params.fail_over_mac].modename,
452 bond->params.fail_over_mac);
Jay Vosburghdd957c52007-10-09 19:57:24 -0700453}
454
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000455static ssize_t bonding_store_fail_over_mac(struct device *d,
456 struct device_attribute *attr,
457 const char *buf, size_t count)
Jay Vosburghdd957c52007-10-09 19:57:24 -0700458{
459 int new_value;
Jay Vosburghdd957c52007-10-09 19:57:24 -0700460 struct bonding *bond = to_bond(d);
461
462 if (bond->slave_cnt != 0) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800463 pr_err("%s: Can't alter fail_over_mac with slaves in bond.\n",
Jay Vosburghdd957c52007-10-09 19:57:24 -0700464 bond->dev->name);
Jay Vosburgh3915c1e82008-05-17 21:10:14 -0700465 return -EPERM;
Jay Vosburghdd957c52007-10-09 19:57:24 -0700466 }
467
Jay Vosburgh3915c1e82008-05-17 21:10:14 -0700468 new_value = bond_parse_parm(buf, fail_over_mac_tbl);
469 if (new_value < 0) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800470 pr_err("%s: Ignoring invalid fail_over_mac value %s.\n",
Jay Vosburgh3915c1e82008-05-17 21:10:14 -0700471 bond->dev->name, buf);
472 return -EINVAL;
Jay Vosburghdd957c52007-10-09 19:57:24 -0700473 }
474
Jay Vosburgh3915c1e82008-05-17 21:10:14 -0700475 bond->params.fail_over_mac = new_value;
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800476 pr_info("%s: Setting fail_over_mac to %s (%d).\n",
477 bond->dev->name, fail_over_mac_tbl[new_value].modename,
478 new_value);
Jay Vosburgh3915c1e82008-05-17 21:10:14 -0700479
480 return count;
Jay Vosburghdd957c52007-10-09 19:57:24 -0700481}
482
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000483static DEVICE_ATTR(fail_over_mac, S_IRUGO | S_IWUSR,
484 bonding_show_fail_over_mac, bonding_store_fail_over_mac);
Jay Vosburghdd957c52007-10-09 19:57:24 -0700485
486/*
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800487 * Show and set the arp timer interval. There are two tricky bits
488 * here. First, if ARP monitoring is activated, then we must disable
489 * MII monitoring. Second, if the ARP timer isn't running, we must
490 * start it.
491 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700492static ssize_t bonding_show_arp_interval(struct device *d,
493 struct device_attribute *attr,
494 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800495{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700496 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800497
Wagner Ferenc7bd46502007-12-06 23:40:28 -0800498 return sprintf(buf, "%d\n", bond->params.arp_interval);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800499}
500
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700501static ssize_t bonding_store_arp_interval(struct device *d,
502 struct device_attribute *attr,
503 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800504{
505 int new_value, ret = count;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700506 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800507
508 if (sscanf(buf, "%d", &new_value) != 1) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800509 pr_err("%s: no arp_interval value specified.\n",
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800510 bond->dev->name);
511 ret = -EINVAL;
512 goto out;
513 }
514 if (new_value < 0) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800515 pr_err("%s: Invalid arp_interval value %d not in range 1-%d; rejected.\n",
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800516 bond->dev->name, new_value, INT_MAX);
517 ret = -EINVAL;
518 goto out;
519 }
Andy Gospodarekc5cb0022010-07-28 15:13:56 +0000520 if (bond->params.mode == BOND_MODE_ALB ||
521 bond->params.mode == BOND_MODE_TLB) {
522 pr_info("%s: ARP monitoring cannot be used with ALB/TLB. Only MII monitoring is supported on %s.\n",
523 bond->dev->name, bond->dev->name);
524 ret = -EINVAL;
525 goto out;
526 }
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800527 pr_info("%s: Setting ARP monitoring interval to %d.\n",
528 bond->dev->name, new_value);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800529 bond->params.arp_interval = new_value;
Jay Vosburgh6cf3f412008-11-03 18:16:50 -0800530 if (bond->params.arp_interval)
531 bond->dev->priv_flags |= IFF_MASTER_ARPMON;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800532 if (bond->params.miimon) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800533 pr_info("%s: ARP monitoring cannot be used with MII monitoring. %s Disabling MII monitoring.\n",
534 bond->dev->name, bond->dev->name);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800535 bond->params.miimon = 0;
Jay Vosburgh1b76b312007-10-17 17:37:45 -0700536 if (delayed_work_pending(&bond->mii_work)) {
537 cancel_delayed_work(&bond->mii_work);
538 flush_workqueue(bond->wq);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800539 }
540 }
541 if (!bond->params.arp_targets[0]) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800542 pr_info("%s: ARP monitoring has been set up, but no ARP targets have been specified.\n",
543 bond->dev->name);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800544 }
545 if (bond->dev->flags & IFF_UP) {
546 /* If the interface is up, we may need to fire off
547 * the ARP timer. If the interface is down, the
548 * timer will get fired off when the open function
549 * is called.
550 */
Jay Vosburgh1b76b312007-10-17 17:37:45 -0700551 if (!delayed_work_pending(&bond->arp_work)) {
552 if (bond->params.mode == BOND_MODE_ACTIVEBACKUP)
553 INIT_DELAYED_WORK(&bond->arp_work,
554 bond_activebackup_arp_mon);
555 else
556 INIT_DELAYED_WORK(&bond->arp_work,
557 bond_loadbalance_arp_mon);
558
559 queue_delayed_work(bond->wq, &bond->arp_work, 0);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800560 }
561 }
562
563out:
564 return ret;
565}
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000566static DEVICE_ATTR(arp_interval, S_IRUGO | S_IWUSR,
567 bonding_show_arp_interval, bonding_store_arp_interval);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800568
569/*
570 * Show and set the arp targets.
571 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700572static ssize_t bonding_show_arp_targets(struct device *d,
573 struct device_attribute *attr,
574 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800575{
576 int i, res = 0;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700577 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800578
579 for (i = 0; i < BOND_MAX_ARP_TARGETS; i++) {
580 if (bond->params.arp_targets[i])
Harvey Harrison63779432008-10-31 00:56:00 -0700581 res += sprintf(buf + res, "%pI4 ",
582 &bond->params.arp_targets[i]);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800583 }
Wagner Ferenc1dcdcd62007-12-06 23:40:31 -0800584 if (res)
585 buf[res-1] = '\n'; /* eat the leftover space */
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800586 return res;
587}
588
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700589static ssize_t bonding_store_arp_targets(struct device *d,
590 struct device_attribute *attr,
591 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800592{
Al Virod3bb52b2007-08-22 20:06:58 -0400593 __be32 newtarget;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800594 int i = 0, done = 0, ret = count;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700595 struct bonding *bond = to_bond(d);
Al Virod3bb52b2007-08-22 20:06:58 -0400596 __be32 *targets;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800597
598 targets = bond->params.arp_targets;
599 newtarget = in_aton(buf + 1);
600 /* look for adds */
601 if (buf[0] == '+') {
Al Virod3bb52b2007-08-22 20:06:58 -0400602 if ((newtarget == 0) || (newtarget == htonl(INADDR_BROADCAST))) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800603 pr_err("%s: invalid ARP target %pI4 specified for addition\n",
Harvey Harrison63779432008-10-31 00:56:00 -0700604 bond->dev->name, &newtarget);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800605 ret = -EINVAL;
606 goto out;
607 }
608 /* look for an empty slot to put the target in, and check for dupes */
Brian Haley5a31bec2009-04-13 00:11:30 -0700609 for (i = 0; (i < BOND_MAX_ARP_TARGETS) && !done; i++) {
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800610 if (targets[i] == newtarget) { /* duplicate */
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800611 pr_err("%s: ARP target %pI4 is already present\n",
Harvey Harrison63779432008-10-31 00:56:00 -0700612 bond->dev->name, &newtarget);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800613 ret = -EINVAL;
614 goto out;
615 }
Brian Haley5a31bec2009-04-13 00:11:30 -0700616 if (targets[i] == 0) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800617 pr_info("%s: adding ARP target %pI4.\n",
618 bond->dev->name, &newtarget);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800619 done = 1;
620 targets[i] = newtarget;
621 }
622 }
623 if (!done) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800624 pr_err("%s: ARP target table is full!\n",
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800625 bond->dev->name);
626 ret = -EINVAL;
627 goto out;
628 }
629
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000630 } else if (buf[0] == '-') {
Al Virod3bb52b2007-08-22 20:06:58 -0400631 if ((newtarget == 0) || (newtarget == htonl(INADDR_BROADCAST))) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800632 pr_err("%s: invalid ARP target %pI4 specified for removal\n",
Harvey Harrison63779432008-10-31 00:56:00 -0700633 bond->dev->name, &newtarget);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800634 ret = -EINVAL;
635 goto out;
636 }
637
Brian Haley5a31bec2009-04-13 00:11:30 -0700638 for (i = 0; (i < BOND_MAX_ARP_TARGETS) && !done; i++) {
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800639 if (targets[i] == newtarget) {
Brian Haley5a31bec2009-04-13 00:11:30 -0700640 int j;
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800641 pr_info("%s: removing ARP target %pI4.\n",
642 bond->dev->name, &newtarget);
Brian Haley5a31bec2009-04-13 00:11:30 -0700643 for (j = i; (j < (BOND_MAX_ARP_TARGETS-1)) && targets[j+1]; j++)
644 targets[j] = targets[j+1];
645
646 targets[j] = 0;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800647 done = 1;
648 }
649 }
650 if (!done) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800651 pr_info("%s: unable to remove nonexistent ARP target %pI4.\n",
652 bond->dev->name, &newtarget);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800653 ret = -EINVAL;
654 goto out;
655 }
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000656 } else {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800657 pr_err("no command found in arp_ip_targets file for bond %s. Use +<addr> or -<addr>.\n",
658 bond->dev->name);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800659 ret = -EPERM;
660 goto out;
661 }
662
663out:
664 return ret;
665}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700666static DEVICE_ATTR(arp_ip_target, S_IRUGO | S_IWUSR , bonding_show_arp_targets, bonding_store_arp_targets);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800667
668/*
669 * Show and set the up and down delays. These must be multiples of the
670 * MII monitoring value, and are stored internally as the multiplier.
671 * Thus, we must translate to MS for the real world.
672 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700673static ssize_t bonding_show_downdelay(struct device *d,
674 struct device_attribute *attr,
675 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800676{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700677 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800678
Wagner Ferenc7bd46502007-12-06 23:40:28 -0800679 return sprintf(buf, "%d\n", bond->params.downdelay * bond->params.miimon);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800680}
681
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700682static ssize_t bonding_store_downdelay(struct device *d,
683 struct device_attribute *attr,
684 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800685{
686 int new_value, ret = count;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700687 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800688
689 if (!(bond->params.miimon)) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800690 pr_err("%s: Unable to set down delay as MII monitoring is disabled\n",
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800691 bond->dev->name);
692 ret = -EPERM;
693 goto out;
694 }
695
696 if (sscanf(buf, "%d", &new_value) != 1) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800697 pr_err("%s: no down delay value specified.\n", bond->dev->name);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800698 ret = -EINVAL;
699 goto out;
700 }
701 if (new_value < 0) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800702 pr_err("%s: Invalid down delay value %d not in range %d-%d; rejected.\n",
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800703 bond->dev->name, new_value, 1, INT_MAX);
704 ret = -EINVAL;
705 goto out;
706 } else {
707 if ((new_value % bond->params.miimon) != 0) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800708 pr_warning("%s: Warning: down delay (%d) is not a multiple of miimon (%d), delay rounded to %d ms\n",
Jiri Pirkoe5e2a8f2009-08-13 04:11:52 +0000709 bond->dev->name, new_value,
710 bond->params.miimon,
711 (new_value / bond->params.miimon) *
712 bond->params.miimon);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800713 }
714 bond->params.downdelay = new_value / bond->params.miimon;
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800715 pr_info("%s: Setting down delay to %d.\n",
716 bond->dev->name,
717 bond->params.downdelay * bond->params.miimon);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800718
719 }
720
721out:
722 return ret;
723}
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000724static DEVICE_ATTR(downdelay, S_IRUGO | S_IWUSR,
725 bonding_show_downdelay, bonding_store_downdelay);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800726
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700727static ssize_t bonding_show_updelay(struct device *d,
728 struct device_attribute *attr,
729 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800730{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700731 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800732
Wagner Ferenc7bd46502007-12-06 23:40:28 -0800733 return sprintf(buf, "%d\n", bond->params.updelay * bond->params.miimon);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800734
735}
736
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700737static ssize_t bonding_store_updelay(struct device *d,
738 struct device_attribute *attr,
739 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800740{
741 int new_value, ret = count;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700742 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800743
744 if (!(bond->params.miimon)) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800745 pr_err("%s: Unable to set up delay as MII monitoring is disabled\n",
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800746 bond->dev->name);
747 ret = -EPERM;
748 goto out;
749 }
750
751 if (sscanf(buf, "%d", &new_value) != 1) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800752 pr_err("%s: no up delay value specified.\n",
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800753 bond->dev->name);
754 ret = -EINVAL;
755 goto out;
756 }
757 if (new_value < 0) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800758 pr_err("%s: Invalid down delay value %d not in range %d-%d; rejected.\n",
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800759 bond->dev->name, new_value, 1, INT_MAX);
760 ret = -EINVAL;
761 goto out;
762 } else {
763 if ((new_value % bond->params.miimon) != 0) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800764 pr_warning("%s: Warning: up delay (%d) is not a multiple of miimon (%d), updelay rounded to %d ms\n",
Jiri Pirkoe5e2a8f2009-08-13 04:11:52 +0000765 bond->dev->name, new_value,
766 bond->params.miimon,
767 (new_value / bond->params.miimon) *
768 bond->params.miimon);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800769 }
770 bond->params.updelay = new_value / bond->params.miimon;
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800771 pr_info("%s: Setting up delay to %d.\n",
772 bond->dev->name,
773 bond->params.updelay * bond->params.miimon);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800774 }
775
776out:
777 return ret;
778}
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000779static DEVICE_ATTR(updelay, S_IRUGO | S_IWUSR,
780 bonding_show_updelay, bonding_store_updelay);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800781
782/*
783 * Show and set the LACP interval. Interface must be down, and the mode
784 * must be set to 802.3ad mode.
785 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700786static ssize_t bonding_show_lacp(struct device *d,
787 struct device_attribute *attr,
788 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800789{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700790 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800791
792 return sprintf(buf, "%s %d\n",
793 bond_lacp_tbl[bond->params.lacp_fast].modename,
Wagner Ferenc7bd46502007-12-06 23:40:28 -0800794 bond->params.lacp_fast);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800795}
796
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700797static ssize_t bonding_store_lacp(struct device *d,
798 struct device_attribute *attr,
799 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800800{
801 int new_value, ret = count;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700802 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800803
804 if (bond->dev->flags & IFF_UP) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800805 pr_err("%s: Unable to update LACP rate because interface is up.\n",
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800806 bond->dev->name);
807 ret = -EPERM;
808 goto out;
809 }
810
811 if (bond->params.mode != BOND_MODE_8023AD) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800812 pr_err("%s: Unable to update LACP rate because bond is not in 802.3ad mode.\n",
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800813 bond->dev->name);
814 ret = -EPERM;
815 goto out;
816 }
817
Jay Vosburghece95f72008-01-17 16:25:01 -0800818 new_value = bond_parse_parm(buf, bond_lacp_tbl);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800819
820 if ((new_value == 1) || (new_value == 0)) {
821 bond->params.lacp_fast = new_value;
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800822 pr_info("%s: Setting LACP rate to %s (%d).\n",
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000823 bond->dev->name, bond_lacp_tbl[new_value].modename,
824 new_value);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800825 } else {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800826 pr_err("%s: Ignoring invalid LACP rate value %.*s.\n",
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000827 bond->dev->name, (int)strlen(buf) - 1, buf);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800828 ret = -EINVAL;
829 }
830out:
831 return ret;
832}
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000833static DEVICE_ATTR(lacp_rate, S_IRUGO | S_IWUSR,
834 bonding_show_lacp, bonding_store_lacp);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800835
Jay Vosburghfd989c82008-11-04 17:51:16 -0800836static ssize_t bonding_show_ad_select(struct device *d,
837 struct device_attribute *attr,
838 char *buf)
839{
840 struct bonding *bond = to_bond(d);
841
842 return sprintf(buf, "%s %d\n",
843 ad_select_tbl[bond->params.ad_select].modename,
844 bond->params.ad_select);
845}
846
847
848static ssize_t bonding_store_ad_select(struct device *d,
849 struct device_attribute *attr,
850 const char *buf, size_t count)
851{
852 int new_value, ret = count;
853 struct bonding *bond = to_bond(d);
854
855 if (bond->dev->flags & IFF_UP) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800856 pr_err("%s: Unable to update ad_select because interface is up.\n",
857 bond->dev->name);
Jay Vosburghfd989c82008-11-04 17:51:16 -0800858 ret = -EPERM;
859 goto out;
860 }
861
862 new_value = bond_parse_parm(buf, ad_select_tbl);
863
864 if (new_value != -1) {
865 bond->params.ad_select = new_value;
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800866 pr_info("%s: Setting ad_select to %s (%d).\n",
867 bond->dev->name, ad_select_tbl[new_value].modename,
868 new_value);
Jay Vosburghfd989c82008-11-04 17:51:16 -0800869 } else {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800870 pr_err("%s: Ignoring invalid ad_select value %.*s.\n",
Jay Vosburghfd989c82008-11-04 17:51:16 -0800871 bond->dev->name, (int)strlen(buf) - 1, buf);
872 ret = -EINVAL;
873 }
874out:
875 return ret;
876}
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000877static DEVICE_ATTR(ad_select, S_IRUGO | S_IWUSR,
878 bonding_show_ad_select, bonding_store_ad_select);
Jay Vosburghfd989c82008-11-04 17:51:16 -0800879
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800880/*
Moni Shoua7893b242008-05-17 21:10:12 -0700881 * Show and set the number of grat ARP to send after a failover event.
882 */
883static ssize_t bonding_show_n_grat_arp(struct device *d,
884 struct device_attribute *attr,
885 char *buf)
886{
887 struct bonding *bond = to_bond(d);
888
889 return sprintf(buf, "%d\n", bond->params.num_grat_arp);
890}
891
892static ssize_t bonding_store_n_grat_arp(struct device *d,
893 struct device_attribute *attr,
894 const char *buf, size_t count)
895{
896 int new_value, ret = count;
897 struct bonding *bond = to_bond(d);
898
899 if (sscanf(buf, "%d", &new_value) != 1) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800900 pr_err("%s: no num_grat_arp value specified.\n",
Moni Shoua7893b242008-05-17 21:10:12 -0700901 bond->dev->name);
902 ret = -EINVAL;
903 goto out;
904 }
905 if (new_value < 0 || new_value > 255) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800906 pr_err("%s: Invalid num_grat_arp value %d not in range 0-255; rejected.\n",
Moni Shoua7893b242008-05-17 21:10:12 -0700907 bond->dev->name, new_value);
908 ret = -EINVAL;
909 goto out;
910 } else {
911 bond->params.num_grat_arp = new_value;
912 }
913out:
914 return ret;
915}
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000916static DEVICE_ATTR(num_grat_arp, S_IRUGO | S_IWUSR,
917 bonding_show_n_grat_arp, bonding_store_n_grat_arp);
Brian Haley305d5522008-11-04 17:51:14 -0800918
919/*
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000920 * Show and set the number of unsolicited NA's to send after a failover event.
Brian Haley305d5522008-11-04 17:51:14 -0800921 */
922static ssize_t bonding_show_n_unsol_na(struct device *d,
923 struct device_attribute *attr,
924 char *buf)
925{
926 struct bonding *bond = to_bond(d);
927
928 return sprintf(buf, "%d\n", bond->params.num_unsol_na);
929}
930
931static ssize_t bonding_store_n_unsol_na(struct device *d,
932 struct device_attribute *attr,
933 const char *buf, size_t count)
934{
935 int new_value, ret = count;
936 struct bonding *bond = to_bond(d);
937
938 if (sscanf(buf, "%d", &new_value) != 1) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800939 pr_err("%s: no num_unsol_na value specified.\n",
Brian Haley305d5522008-11-04 17:51:14 -0800940 bond->dev->name);
941 ret = -EINVAL;
942 goto out;
943 }
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000944
Brian Haley305d5522008-11-04 17:51:14 -0800945 if (new_value < 0 || new_value > 255) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800946 pr_err("%s: Invalid num_unsol_na value %d not in range 0-255; rejected.\n",
Brian Haley305d5522008-11-04 17:51:14 -0800947 bond->dev->name, new_value);
948 ret = -EINVAL;
949 goto out;
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000950 } else
Brian Haley305d5522008-11-04 17:51:14 -0800951 bond->params.num_unsol_na = new_value;
Brian Haley305d5522008-11-04 17:51:14 -0800952out:
953 return ret;
954}
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000955static DEVICE_ATTR(num_unsol_na, S_IRUGO | S_IWUSR,
956 bonding_show_n_unsol_na, bonding_store_n_unsol_na);
Brian Haley305d5522008-11-04 17:51:14 -0800957
Moni Shoua7893b242008-05-17 21:10:12 -0700958/*
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800959 * Show and set the MII monitor interval. There are two tricky bits
960 * here. First, if MII monitoring is activated, then we must disable
961 * ARP monitoring. Second, if the timer isn't running, we must
962 * start it.
963 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700964static ssize_t bonding_show_miimon(struct device *d,
965 struct device_attribute *attr,
966 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800967{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700968 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800969
Wagner Ferenc7bd46502007-12-06 23:40:28 -0800970 return sprintf(buf, "%d\n", bond->params.miimon);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800971}
972
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700973static ssize_t bonding_store_miimon(struct device *d,
974 struct device_attribute *attr,
975 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800976{
977 int new_value, ret = count;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700978 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800979
980 if (sscanf(buf, "%d", &new_value) != 1) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800981 pr_err("%s: no miimon value specified.\n",
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800982 bond->dev->name);
983 ret = -EINVAL;
984 goto out;
985 }
986 if (new_value < 0) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800987 pr_err("%s: Invalid miimon value %d not in range %d-%d; rejected.\n",
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800988 bond->dev->name, new_value, 1, INT_MAX);
989 ret = -EINVAL;
990 goto out;
991 } else {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800992 pr_info("%s: Setting MII monitoring interval to %d.\n",
993 bond->dev->name, new_value);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800994 bond->params.miimon = new_value;
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000995 if (bond->params.updelay)
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800996 pr_info("%s: Note: Updating updelay (to %d) since it is a multiple of the miimon value.\n",
997 bond->dev->name,
998 bond->params.updelay * bond->params.miimon);
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000999 if (bond->params.downdelay)
Joe Perchesa4aee5c2009-12-13 20:06:07 -08001000 pr_info("%s: Note: Updating downdelay (to %d) since it is a multiple of the miimon value.\n",
1001 bond->dev->name,
1002 bond->params.downdelay * bond->params.miimon);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001003 if (bond->params.arp_interval) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -08001004 pr_info("%s: MII monitoring cannot be used with ARP monitoring. Disabling ARP monitoring...\n",
1005 bond->dev->name);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001006 bond->params.arp_interval = 0;
Jay Vosburgh6cf3f412008-11-03 18:16:50 -08001007 bond->dev->priv_flags &= ~IFF_MASTER_ARPMON;
Jay Vosburghf5b2b962006-09-22 21:54:53 -07001008 if (bond->params.arp_validate) {
1009 bond_unregister_arp(bond);
1010 bond->params.arp_validate =
1011 BOND_ARP_VALIDATE_NONE;
1012 }
Jay Vosburgh1b76b312007-10-17 17:37:45 -07001013 if (delayed_work_pending(&bond->arp_work)) {
1014 cancel_delayed_work(&bond->arp_work);
1015 flush_workqueue(bond->wq);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001016 }
1017 }
1018
1019 if (bond->dev->flags & IFF_UP) {
1020 /* If the interface is up, we may need to fire off
1021 * the MII timer. If the interface is down, the
1022 * timer will get fired off when the open function
1023 * is called.
1024 */
Jay Vosburgh1b76b312007-10-17 17:37:45 -07001025 if (!delayed_work_pending(&bond->mii_work)) {
1026 INIT_DELAYED_WORK(&bond->mii_work,
1027 bond_mii_monitor);
1028 queue_delayed_work(bond->wq,
1029 &bond->mii_work, 0);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001030 }
1031 }
1032 }
1033out:
1034 return ret;
1035}
Stephen Hemminger3d632c32009-06-12 19:02:48 +00001036static DEVICE_ATTR(miimon, S_IRUGO | S_IWUSR,
1037 bonding_show_miimon, bonding_store_miimon);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001038
1039/*
1040 * Show and set the primary slave. The store function is much
1041 * simpler than bonding_store_slaves function because it only needs to
1042 * handle one interface name.
1043 * The bond must be a mode that supports a primary for this be
1044 * set.
1045 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001046static ssize_t bonding_show_primary(struct device *d,
1047 struct device_attribute *attr,
1048 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001049{
1050 int count = 0;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001051 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001052
1053 if (bond->primary_slave)
Wagner Ferenc7bd46502007-12-06 23:40:28 -08001054 count = sprintf(buf, "%s\n", bond->primary_slave->dev->name);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001055
1056 return count;
1057}
1058
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001059static ssize_t bonding_store_primary(struct device *d,
1060 struct device_attribute *attr,
1061 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001062{
1063 int i;
1064 struct slave *slave;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001065 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001066
Eric W. Biederman496a60c2009-05-13 17:02:50 +00001067 if (!rtnl_trylock())
1068 return restart_syscall();
Neil Hormane843fa52010-10-13 16:01:50 +00001069 block_netpoll_tx();
Jay Vosburghe934dd72008-01-17 16:24:57 -08001070 read_lock(&bond->lock);
1071 write_lock_bh(&bond->curr_slave_lock);
1072
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001073 if (!USES_PRIMARY(bond->params.mode)) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -08001074 pr_info("%s: Unable to set primary slave; %s is in mode %d\n",
1075 bond->dev->name, bond->dev->name, bond->params.mode);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001076 } else {
1077 bond_for_each_slave(bond, slave, i) {
1078 if (strnicmp
1079 (slave->dev->name, buf,
1080 strlen(slave->dev->name)) == 0) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -08001081 pr_info("%s: Setting %s as primary slave.\n",
1082 bond->dev->name, slave->dev->name);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001083 bond->primary_slave = slave;
Jiri Pirkoce501ca2009-09-18 02:13:22 +00001084 strcpy(bond->params.primary, slave->dev->name);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001085 bond_select_active_slave(bond);
1086 goto out;
1087 }
1088 }
1089
1090 /* if we got here, then we didn't match the name of any slave */
1091
1092 if (strlen(buf) == 0 || buf[0] == '\n') {
Joe Perchesa4aee5c2009-12-13 20:06:07 -08001093 pr_info("%s: Setting primary slave to None.\n",
1094 bond->dev->name);
Luiz Fernando Capitulino3418db72006-02-01 00:54:34 -08001095 bond->primary_slave = NULL;
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001096 bond_select_active_slave(bond);
1097 } else {
Joe Perchesa4aee5c2009-12-13 20:06:07 -08001098 pr_info("%s: Unable to set %.*s as primary slave as it is not a slave.\n",
1099 bond->dev->name, (int)strlen(buf) - 1, buf);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001100 }
1101 }
1102out:
Jay Vosburghe934dd72008-01-17 16:24:57 -08001103 write_unlock_bh(&bond->curr_slave_lock);
1104 read_unlock(&bond->lock);
Neil Hormane843fa52010-10-13 16:01:50 +00001105 unblock_netpoll_tx();
Jay Vosburgh6603a6f2007-10-17 17:37:50 -07001106 rtnl_unlock();
1107
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001108 return count;
1109}
Stephen Hemminger3d632c32009-06-12 19:02:48 +00001110static DEVICE_ATTR(primary, S_IRUGO | S_IWUSR,
1111 bonding_show_primary, bonding_store_primary);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001112
1113/*
Jiri Pirkoa5499522009-09-25 03:28:09 +00001114 * Show and set the primary_reselect flag.
1115 */
1116static ssize_t bonding_show_primary_reselect(struct device *d,
1117 struct device_attribute *attr,
1118 char *buf)
1119{
1120 struct bonding *bond = to_bond(d);
1121
1122 return sprintf(buf, "%s %d\n",
1123 pri_reselect_tbl[bond->params.primary_reselect].modename,
1124 bond->params.primary_reselect);
1125}
1126
1127static ssize_t bonding_store_primary_reselect(struct device *d,
1128 struct device_attribute *attr,
1129 const char *buf, size_t count)
1130{
1131 int new_value, ret = count;
1132 struct bonding *bond = to_bond(d);
1133
1134 if (!rtnl_trylock())
1135 return restart_syscall();
1136
1137 new_value = bond_parse_parm(buf, pri_reselect_tbl);
1138 if (new_value < 0) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -08001139 pr_err("%s: Ignoring invalid primary_reselect value %.*s.\n",
Jiri Pirkoa5499522009-09-25 03:28:09 +00001140 bond->dev->name,
1141 (int) strlen(buf) - 1, buf);
1142 ret = -EINVAL;
1143 goto out;
1144 }
1145
1146 bond->params.primary_reselect = new_value;
Joe Perchesa4aee5c2009-12-13 20:06:07 -08001147 pr_info("%s: setting primary_reselect to %s (%d).\n",
Jiri Pirkoa5499522009-09-25 03:28:09 +00001148 bond->dev->name, pri_reselect_tbl[new_value].modename,
1149 new_value);
1150
Neil Hormane843fa52010-10-13 16:01:50 +00001151 block_netpoll_tx();
Jiri Pirkoa5499522009-09-25 03:28:09 +00001152 read_lock(&bond->lock);
1153 write_lock_bh(&bond->curr_slave_lock);
1154 bond_select_active_slave(bond);
1155 write_unlock_bh(&bond->curr_slave_lock);
1156 read_unlock(&bond->lock);
Neil Hormane843fa52010-10-13 16:01:50 +00001157 unblock_netpoll_tx();
Jiri Pirkoa5499522009-09-25 03:28:09 +00001158out:
1159 rtnl_unlock();
1160 return ret;
1161}
1162static DEVICE_ATTR(primary_reselect, S_IRUGO | S_IWUSR,
1163 bonding_show_primary_reselect,
1164 bonding_store_primary_reselect);
1165
1166/*
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001167 * Show and set the use_carrier flag.
1168 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001169static ssize_t bonding_show_carrier(struct device *d,
1170 struct device_attribute *attr,
1171 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001172{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001173 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001174
Wagner Ferenc7bd46502007-12-06 23:40:28 -08001175 return sprintf(buf, "%d\n", bond->params.use_carrier);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001176}
1177
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001178static ssize_t bonding_store_carrier(struct device *d,
1179 struct device_attribute *attr,
1180 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001181{
1182 int new_value, ret = count;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001183 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001184
1185
1186 if (sscanf(buf, "%d", &new_value) != 1) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -08001187 pr_err("%s: no use_carrier value specified.\n",
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001188 bond->dev->name);
1189 ret = -EINVAL;
1190 goto out;
1191 }
1192 if ((new_value == 0) || (new_value == 1)) {
1193 bond->params.use_carrier = new_value;
Joe Perchesa4aee5c2009-12-13 20:06:07 -08001194 pr_info("%s: Setting use_carrier to %d.\n",
1195 bond->dev->name, new_value);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001196 } else {
Joe Perchesa4aee5c2009-12-13 20:06:07 -08001197 pr_info("%s: Ignoring invalid use_carrier value %d.\n",
1198 bond->dev->name, new_value);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001199 }
1200out:
Jiri Pirko672bda32011-01-25 11:03:25 +00001201 return ret;
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001202}
Stephen Hemminger3d632c32009-06-12 19:02:48 +00001203static DEVICE_ATTR(use_carrier, S_IRUGO | S_IWUSR,
1204 bonding_show_carrier, bonding_store_carrier);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001205
1206
1207/*
1208 * Show and set currently active_slave.
1209 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001210static ssize_t bonding_show_active_slave(struct device *d,
1211 struct device_attribute *attr,
1212 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001213{
1214 struct slave *curr;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001215 struct bonding *bond = to_bond(d);
Wagner Ferenc16cd0162007-12-06 23:40:29 -08001216 int count = 0;
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001217
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001218 read_lock(&bond->curr_slave_lock);
1219 curr = bond->curr_active_slave;
1220 read_unlock(&bond->curr_slave_lock);
1221
1222 if (USES_PRIMARY(bond->params.mode) && curr)
Wagner Ferenc7bd46502007-12-06 23:40:28 -08001223 count = sprintf(buf, "%s\n", curr->dev->name);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001224 return count;
1225}
1226
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001227static ssize_t bonding_store_active_slave(struct device *d,
1228 struct device_attribute *attr,
1229 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001230{
1231 int i;
1232 struct slave *slave;
Stephen Hemminger3d632c32009-06-12 19:02:48 +00001233 struct slave *old_active = NULL;
1234 struct slave *new_active = NULL;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001235 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001236
Eric W. Biederman496a60c2009-05-13 17:02:50 +00001237 if (!rtnl_trylock())
1238 return restart_syscall();
Neil Hormane843fa52010-10-13 16:01:50 +00001239
1240 block_netpoll_tx();
Jay Vosburghe934dd72008-01-17 16:24:57 -08001241 read_lock(&bond->lock);
1242 write_lock_bh(&bond->curr_slave_lock);
Jay Vosburgh1466a212007-11-06 13:33:28 -08001243
Stephen Hemminger3d632c32009-06-12 19:02:48 +00001244 if (!USES_PRIMARY(bond->params.mode))
Joe Perchesa4aee5c2009-12-13 20:06:07 -08001245 pr_info("%s: Unable to change active slave; %s is in mode %d\n",
Stephen Hemminger3d632c32009-06-12 19:02:48 +00001246 bond->dev->name, bond->dev->name, bond->params.mode);
1247 else {
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001248 bond_for_each_slave(bond, slave, i) {
1249 if (strnicmp
1250 (slave->dev->name, buf,
1251 strlen(slave->dev->name)) == 0) {
1252 old_active = bond->curr_active_slave;
1253 new_active = slave;
Jay Vosburgha50d8de2006-09-22 21:53:25 -07001254 if (new_active == old_active) {
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001255 /* do nothing */
Joe Perchesa4aee5c2009-12-13 20:06:07 -08001256 pr_info("%s: %s is already the current active slave.\n",
1257 bond->dev->name,
1258 slave->dev->name);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001259 goto out;
1260 }
1261 else {
1262 if ((new_active) &&
1263 (old_active) &&
1264 (new_active->link == BOND_LINK_UP) &&
1265 IS_UP(new_active->dev)) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -08001266 pr_info("%s: Setting %s as active slave.\n",
1267 bond->dev->name,
1268 slave->dev->name);
Jiri Pirkoe5e2a8f2009-08-13 04:11:52 +00001269 bond_change_active_slave(bond, new_active);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001270 }
1271 else {
Joe Perchesa4aee5c2009-12-13 20:06:07 -08001272 pr_info("%s: Could not set %s as active slave; either %s is down or the link is down.\n",
1273 bond->dev->name,
1274 slave->dev->name,
Jiri Pirkoe5e2a8f2009-08-13 04:11:52 +00001275 slave->dev->name);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001276 }
1277 goto out;
1278 }
1279 }
1280 }
1281
1282 /* if we got here, then we didn't match the name of any slave */
1283
1284 if (strlen(buf) == 0 || buf[0] == '\n') {
Joe Perchesa4aee5c2009-12-13 20:06:07 -08001285 pr_info("%s: Setting active slave to None.\n",
Stephen Hemminger3d632c32009-06-12 19:02:48 +00001286 bond->dev->name);
Luiz Fernando Capitulino3418db72006-02-01 00:54:34 -08001287 bond->primary_slave = NULL;
Stephen Hemminger3d632c32009-06-12 19:02:48 +00001288 bond_select_active_slave(bond);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001289 } else {
Joe Perchesa4aee5c2009-12-13 20:06:07 -08001290 pr_info("%s: Unable to set %.*s as active slave as it is not a slave.\n",
Stephen Hemminger3d632c32009-06-12 19:02:48 +00001291 bond->dev->name, (int)strlen(buf) - 1, buf);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001292 }
1293 }
Stephen Hemminger3d632c32009-06-12 19:02:48 +00001294 out:
Jay Vosburghe934dd72008-01-17 16:24:57 -08001295 write_unlock_bh(&bond->curr_slave_lock);
1296 read_unlock(&bond->lock);
Neil Hormane843fa52010-10-13 16:01:50 +00001297 unblock_netpoll_tx();
1298
Jay Vosburgh6603a6f2007-10-17 17:37:50 -07001299 rtnl_unlock();
1300
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001301 return count;
1302
1303}
Stephen Hemminger3d632c32009-06-12 19:02:48 +00001304static DEVICE_ATTR(active_slave, S_IRUGO | S_IWUSR,
1305 bonding_show_active_slave, bonding_store_active_slave);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001306
1307
1308/*
1309 * Show link status of the bond interface.
1310 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001311static ssize_t bonding_show_mii_status(struct device *d,
1312 struct device_attribute *attr,
1313 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001314{
1315 struct slave *curr;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001316 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001317
1318 read_lock(&bond->curr_slave_lock);
1319 curr = bond->curr_active_slave;
1320 read_unlock(&bond->curr_slave_lock);
1321
Stephen Hemminger3d632c32009-06-12 19:02:48 +00001322 return sprintf(buf, "%s\n", curr ? "up" : "down");
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001323}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001324static DEVICE_ATTR(mii_status, S_IRUGO, bonding_show_mii_status, NULL);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001325
1326
1327/*
1328 * Show current 802.3ad aggregator ID.
1329 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001330static ssize_t bonding_show_ad_aggregator(struct device *d,
1331 struct device_attribute *attr,
1332 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001333{
1334 int count = 0;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001335 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001336
1337 if (bond->params.mode == BOND_MODE_8023AD) {
1338 struct ad_info ad_info;
Stephen Hemminger3d632c32009-06-12 19:02:48 +00001339 count = sprintf(buf, "%d\n",
1340 (bond_3ad_get_active_agg_info(bond, &ad_info))
1341 ? 0 : ad_info.aggregator_id);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001342 }
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001343
1344 return count;
1345}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001346static DEVICE_ATTR(ad_aggregator, S_IRUGO, bonding_show_ad_aggregator, NULL);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001347
1348
1349/*
1350 * Show number of active 802.3ad ports.
1351 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001352static ssize_t bonding_show_ad_num_ports(struct device *d,
1353 struct device_attribute *attr,
1354 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001355{
1356 int count = 0;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001357 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001358
1359 if (bond->params.mode == BOND_MODE_8023AD) {
1360 struct ad_info ad_info;
Stephen Hemminger3d632c32009-06-12 19:02:48 +00001361 count = sprintf(buf, "%d\n",
1362 (bond_3ad_get_active_agg_info(bond, &ad_info))
1363 ? 0 : ad_info.ports);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001364 }
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001365
1366 return count;
1367}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001368static DEVICE_ATTR(ad_num_ports, S_IRUGO, bonding_show_ad_num_ports, NULL);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001369
1370
1371/*
1372 * Show current 802.3ad actor key.
1373 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001374static ssize_t bonding_show_ad_actor_key(struct device *d,
1375 struct device_attribute *attr,
1376 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001377{
1378 int count = 0;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001379 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001380
1381 if (bond->params.mode == BOND_MODE_8023AD) {
1382 struct ad_info ad_info;
Stephen Hemminger3d632c32009-06-12 19:02:48 +00001383 count = sprintf(buf, "%d\n",
1384 (bond_3ad_get_active_agg_info(bond, &ad_info))
1385 ? 0 : ad_info.actor_key);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001386 }
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001387
1388 return count;
1389}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001390static DEVICE_ATTR(ad_actor_key, S_IRUGO, bonding_show_ad_actor_key, NULL);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001391
1392
1393/*
1394 * Show current 802.3ad partner key.
1395 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001396static ssize_t bonding_show_ad_partner_key(struct device *d,
1397 struct device_attribute *attr,
1398 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001399{
1400 int count = 0;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001401 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001402
1403 if (bond->params.mode == BOND_MODE_8023AD) {
1404 struct ad_info ad_info;
Stephen Hemminger3d632c32009-06-12 19:02:48 +00001405 count = sprintf(buf, "%d\n",
1406 (bond_3ad_get_active_agg_info(bond, &ad_info))
1407 ? 0 : ad_info.partner_key);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001408 }
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001409
1410 return count;
1411}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001412static DEVICE_ATTR(ad_partner_key, S_IRUGO, bonding_show_ad_partner_key, NULL);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001413
1414
1415/*
1416 * Show current 802.3ad partner mac.
1417 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001418static ssize_t bonding_show_ad_partner_mac(struct device *d,
1419 struct device_attribute *attr,
1420 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001421{
1422 int count = 0;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001423 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001424
1425 if (bond->params.mode == BOND_MODE_8023AD) {
1426 struct ad_info ad_info;
Stephen Hemminger3d632c32009-06-12 19:02:48 +00001427 if (!bond_3ad_get_active_agg_info(bond, &ad_info))
Johannes Berge1749612008-10-27 15:59:26 -07001428 count = sprintf(buf, "%pM\n", ad_info.partner_system);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001429 }
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001430
1431 return count;
1432}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001433static DEVICE_ATTR(ad_partner_mac, S_IRUGO, bonding_show_ad_partner_mac, NULL);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001434
Andy Gospodarekebd8e492010-06-02 08:39:21 +00001435/*
Andy Gospodarekbb1d9122010-06-02 08:40:18 +00001436 * Show the queue_ids of the slaves in the current bond.
1437 */
1438static ssize_t bonding_show_queue_id(struct device *d,
1439 struct device_attribute *attr,
1440 char *buf)
1441{
1442 struct slave *slave;
1443 int i, res = 0;
1444 struct bonding *bond = to_bond(d);
1445
1446 if (!rtnl_trylock())
1447 return restart_syscall();
1448
1449 read_lock(&bond->lock);
1450 bond_for_each_slave(bond, slave, i) {
Nicolas de Pesloüan79236682010-07-14 18:24:54 -07001451 if (res > (PAGE_SIZE - IFNAMSIZ - 6)) {
1452 /* not enough space for another interface_name:queue_id pair */
Andy Gospodarekbb1d9122010-06-02 08:40:18 +00001453 if ((PAGE_SIZE - res) > 10)
1454 res = PAGE_SIZE - 10;
1455 res += sprintf(buf + res, "++more++ ");
1456 break;
1457 }
1458 res += sprintf(buf + res, "%s:%d ",
1459 slave->dev->name, slave->queue_id);
1460 }
1461 read_unlock(&bond->lock);
1462 if (res)
1463 buf[res-1] = '\n'; /* eat the leftover space */
1464 rtnl_unlock();
1465 return res;
1466}
1467
1468/*
1469 * Set the queue_ids of the slaves in the current bond. The bond
1470 * interface must be enslaved for this to work.
1471 */
1472static ssize_t bonding_store_queue_id(struct device *d,
1473 struct device_attribute *attr,
1474 const char *buffer, size_t count)
1475{
1476 struct slave *slave, *update_slave;
1477 struct bonding *bond = to_bond(d);
1478 u16 qid;
1479 int i, ret = count;
1480 char *delim;
1481 struct net_device *sdev = NULL;
1482
1483 if (!rtnl_trylock())
1484 return restart_syscall();
1485
1486 /* delim will point to queue id if successful */
1487 delim = strchr(buffer, ':');
1488 if (!delim)
1489 goto err_no_cmd;
1490
1491 /*
1492 * Terminate string that points to device name and bump it
1493 * up one, so we can read the queue id there.
1494 */
1495 *delim = '\0';
1496 if (sscanf(++delim, "%hd\n", &qid) != 1)
1497 goto err_no_cmd;
1498
1499 /* Check buffer length, valid ifname and queue id */
1500 if (strlen(buffer) > IFNAMSIZ ||
1501 !dev_valid_name(buffer) ||
1502 qid > bond->params.tx_queues)
1503 goto err_no_cmd;
1504
1505 /* Get the pointer to that interface if it exists */
1506 sdev = __dev_get_by_name(dev_net(bond->dev), buffer);
1507 if (!sdev)
1508 goto err_no_cmd;
1509
1510 read_lock(&bond->lock);
1511
1512 /* Search for thes slave and check for duplicate qids */
1513 update_slave = NULL;
1514 bond_for_each_slave(bond, slave, i) {
1515 if (sdev == slave->dev)
1516 /*
1517 * We don't need to check the matching
1518 * slave for dups, since we're overwriting it
1519 */
1520 update_slave = slave;
1521 else if (qid && qid == slave->queue_id) {
1522 goto err_no_cmd_unlock;
1523 }
1524 }
1525
1526 if (!update_slave)
1527 goto err_no_cmd_unlock;
1528
1529 /* Actually set the qids for the slave */
1530 update_slave->queue_id = qid;
1531
1532 read_unlock(&bond->lock);
1533out:
1534 rtnl_unlock();
1535 return ret;
1536
1537err_no_cmd_unlock:
1538 read_unlock(&bond->lock);
1539err_no_cmd:
1540 pr_info("invalid input for queue_id set for %s.\n",
1541 bond->dev->name);
1542 ret = -EPERM;
1543 goto out;
1544}
1545
1546static DEVICE_ATTR(queue_id, S_IRUGO | S_IWUSR, bonding_show_queue_id,
1547 bonding_store_queue_id);
1548
1549
1550/*
Andy Gospodarekebd8e492010-06-02 08:39:21 +00001551 * Show and set the all_slaves_active flag.
1552 */
1553static ssize_t bonding_show_slaves_active(struct device *d,
1554 struct device_attribute *attr,
1555 char *buf)
1556{
1557 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001558
Andy Gospodarekebd8e492010-06-02 08:39:21 +00001559 return sprintf(buf, "%d\n", bond->params.all_slaves_active);
1560}
1561
1562static ssize_t bonding_store_slaves_active(struct device *d,
1563 struct device_attribute *attr,
1564 const char *buf, size_t count)
1565{
1566 int i, new_value, ret = count;
1567 struct bonding *bond = to_bond(d);
1568 struct slave *slave;
1569
1570 if (sscanf(buf, "%d", &new_value) != 1) {
1571 pr_err("%s: no all_slaves_active value specified.\n",
1572 bond->dev->name);
1573 ret = -EINVAL;
1574 goto out;
1575 }
1576
1577 if (new_value == bond->params.all_slaves_active)
1578 goto out;
1579
1580 if ((new_value == 0) || (new_value == 1)) {
1581 bond->params.all_slaves_active = new_value;
1582 } else {
1583 pr_info("%s: Ignoring invalid all_slaves_active value %d.\n",
1584 bond->dev->name, new_value);
1585 ret = -EINVAL;
1586 goto out;
1587 }
1588
1589 bond_for_each_slave(bond, slave, i) {
1590 if (slave->state == BOND_STATE_BACKUP) {
1591 if (new_value)
1592 slave->dev->priv_flags &= ~IFF_SLAVE_INACTIVE;
1593 else
1594 slave->dev->priv_flags |= IFF_SLAVE_INACTIVE;
1595 }
1596 }
1597out:
Jiri Pirko672bda32011-01-25 11:03:25 +00001598 return ret;
Andy Gospodarekebd8e492010-06-02 08:39:21 +00001599}
1600static DEVICE_ATTR(all_slaves_active, S_IRUGO | S_IWUSR,
1601 bonding_show_slaves_active, bonding_store_slaves_active);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001602
Flavio Leitnerc2952c32010-10-05 14:23:59 +00001603/*
1604 * Show and set the number of IGMP membership reports to send on link failure
1605 */
1606static ssize_t bonding_show_resend_igmp(struct device *d,
1607 struct device_attribute *attr,
1608 char *buf)
1609{
1610 struct bonding *bond = to_bond(d);
1611
1612 return sprintf(buf, "%d\n", bond->params.resend_igmp);
1613}
1614
1615static ssize_t bonding_store_resend_igmp(struct device *d,
1616 struct device_attribute *attr,
1617 const char *buf, size_t count)
1618{
1619 int new_value, ret = count;
1620 struct bonding *bond = to_bond(d);
1621
1622 if (sscanf(buf, "%d", &new_value) != 1) {
1623 pr_err("%s: no resend_igmp value specified.\n",
1624 bond->dev->name);
1625 ret = -EINVAL;
1626 goto out;
1627 }
1628
1629 if (new_value < 0) {
1630 pr_err("%s: Invalid resend_igmp value %d not in range 0-255; rejected.\n",
1631 bond->dev->name, new_value);
1632 ret = -EINVAL;
1633 goto out;
1634 }
1635
1636 pr_info("%s: Setting resend_igmp to %d.\n",
1637 bond->dev->name, new_value);
1638 bond->params.resend_igmp = new_value;
1639out:
1640 return ret;
1641}
1642
1643static DEVICE_ATTR(resend_igmp, S_IRUGO | S_IWUSR,
1644 bonding_show_resend_igmp, bonding_store_resend_igmp);
1645
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001646static struct attribute *per_bond_attrs[] = {
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001647 &dev_attr_slaves.attr,
1648 &dev_attr_mode.attr,
Jay Vosburghdd957c52007-10-09 19:57:24 -07001649 &dev_attr_fail_over_mac.attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001650 &dev_attr_arp_validate.attr,
1651 &dev_attr_arp_interval.attr,
1652 &dev_attr_arp_ip_target.attr,
1653 &dev_attr_downdelay.attr,
1654 &dev_attr_updelay.attr,
1655 &dev_attr_lacp_rate.attr,
Jay Vosburghfd989c82008-11-04 17:51:16 -08001656 &dev_attr_ad_select.attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001657 &dev_attr_xmit_hash_policy.attr,
Moni Shoua7893b242008-05-17 21:10:12 -07001658 &dev_attr_num_grat_arp.attr,
Brian Haley305d5522008-11-04 17:51:14 -08001659 &dev_attr_num_unsol_na.attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001660 &dev_attr_miimon.attr,
1661 &dev_attr_primary.attr,
Jiri Pirkoa5499522009-09-25 03:28:09 +00001662 &dev_attr_primary_reselect.attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001663 &dev_attr_use_carrier.attr,
1664 &dev_attr_active_slave.attr,
1665 &dev_attr_mii_status.attr,
1666 &dev_attr_ad_aggregator.attr,
1667 &dev_attr_ad_num_ports.attr,
1668 &dev_attr_ad_actor_key.attr,
1669 &dev_attr_ad_partner_key.attr,
1670 &dev_attr_ad_partner_mac.attr,
Andy Gospodarekbb1d9122010-06-02 08:40:18 +00001671 &dev_attr_queue_id.attr,
Andy Gospodarekebd8e492010-06-02 08:39:21 +00001672 &dev_attr_all_slaves_active.attr,
Flavio Leitnerc2952c32010-10-05 14:23:59 +00001673 &dev_attr_resend_igmp.attr,
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001674 NULL,
1675};
1676
1677static struct attribute_group bonding_group = {
1678 .name = "bonding",
1679 .attrs = per_bond_attrs,
1680};
1681
1682/*
1683 * Initialize sysfs. This sets up the bonding_masters file in
1684 * /sys/class/net.
1685 */
1686int bond_create_sysfs(void)
1687{
Jay Vosburghb8a97872008-06-13 18:12:04 -07001688 int ret;
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001689
Jay Vosburghb8a97872008-06-13 18:12:04 -07001690 ret = netdev_class_create_file(&class_attr_bonding_masters);
Jay Vosburgh877cbd32007-01-19 18:15:47 -08001691 /*
1692 * Permit multiple loads of the module by ignoring failures to
1693 * create the bonding_masters sysfs file. Bonding devices
1694 * created by second or subsequent loads of the module will
1695 * not be listed in, or controllable by, bonding_masters, but
1696 * will have the usual "bonding" sysfs directory.
1697 *
1698 * This is done to preserve backwards compatibility for
1699 * initscripts/sysconfig, which load bonding multiple times to
1700 * configure multiple bonding devices.
1701 */
1702 if (ret == -EEXIST) {
Stephen Hemminger38d2f382008-05-14 22:35:04 -07001703 /* Is someone being kinky and naming a device bonding_master? */
1704 if (__dev_get_by_name(&init_net,
1705 class_attr_bonding_masters.attr.name))
Joe Perchesa4aee5c2009-12-13 20:06:07 -08001706 pr_err("network device named %s already exists in sysfs",
Stephen Hemminger38d2f382008-05-14 22:35:04 -07001707 class_attr_bonding_masters.attr.name);
Stephen Hemminger130aa612009-06-11 05:46:04 -07001708 ret = 0;
Jay Vosburgh877cbd32007-01-19 18:15:47 -08001709 }
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001710
1711 return ret;
1712
1713}
1714
1715/*
1716 * Remove /sys/class/net/bonding_masters.
1717 */
1718void bond_destroy_sysfs(void)
1719{
Jay Vosburghb8a97872008-06-13 18:12:04 -07001720 netdev_class_remove_file(&class_attr_bonding_masters);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001721}
1722
1723/*
1724 * Initialize sysfs for each bond. This sets up and registers
1725 * the 'bondctl' directory for each individual bond under /sys/class/net.
1726 */
Eric W. Biederman6151b3d2009-10-29 14:18:22 +00001727void bond_prepare_sysfs_group(struct bonding *bond)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001728{
Eric W. Biederman6151b3d2009-10-29 14:18:22 +00001729 bond->dev->sysfs_groups[0] = &bonding_group;
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001730}
1731