blob: e718144c5cfa774a6777e1540c608a36bac1d813 [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) {
Phil Oester5f86cad12011-03-14 06:22:06 +0000121 if (rv == -EEXIST)
122 pr_info("%s already exists.\n", ifname);
123 else
124 pr_info("%s creation failed.\n", ifname);
Jay Vosburgh027ea042008-01-17 16:25:02 -0800125 res = rv;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800126 }
Stephen Hemminger373500d2009-06-12 19:02:50 +0000127 } else if (command[0] == '-') {
128 struct net_device *bond_dev;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800129
Jay Vosburgh027ea042008-01-17 16:25:02 -0800130 rtnl_lock();
Eric W. Biedermanec87fd32009-10-29 14:18:26 +0000131 bond_dev = bond_get_by_name(net, ifname);
Stephen Hemminger373500d2009-06-12 19:02:50 +0000132 if (bond_dev) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800133 pr_info("%s is being deleted...\n", ifname);
Stephen Hemminger373500d2009-06-12 19:02:50 +0000134 unregister_netdevice(bond_dev);
135 } else {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800136 pr_err("unable to delete non-existent %s\n", ifname);
Stephen Hemminger373500d2009-06-12 19:02:50 +0000137 res = -ENODEV;
138 }
139 rtnl_unlock();
140 } else
141 goto err_no_cmd;
Jay Vosburgh027ea042008-01-17 16:25:02 -0800142
Stephen Hemminger373500d2009-06-12 19:02:50 +0000143 /* Always return either count or an error. If you return 0, you'll
144 * get called forever, which is bad.
145 */
146 return res;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800147
148err_no_cmd:
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800149 pr_err("no command found in bonding_masters. Use +ifname or -ifname.\n");
Jay Vosburghc4ebc662008-05-02 17:49:38 -0700150 return -EPERM;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800151}
Stephen Hemminger373500d2009-06-12 19:02:50 +0000152
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800153/* class attribute for bond_masters file. This ends up in /sys/class/net */
154static CLASS_ATTR(bonding_masters, S_IWUSR | S_IRUGO,
155 bonding_show_bonds, bonding_store_bonds);
156
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000157int bond_create_slave_symlinks(struct net_device *master,
158 struct net_device *slave)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800159{
160 char linkname[IFNAMSIZ+7];
161 int ret = 0;
162
163 /* first, create a link from the slave back to the master */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700164 ret = sysfs_create_link(&(slave->dev.kobj), &(master->dev.kobj),
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800165 "master");
166 if (ret)
167 return ret;
168 /* next, create a link from the master to the slave */
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000169 sprintf(linkname, "slave_%s", slave->name);
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700170 ret = sysfs_create_link(&(master->dev.kobj), &(slave->dev.kobj),
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800171 linkname);
172 return ret;
173
174}
175
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000176void bond_destroy_slave_symlinks(struct net_device *master,
177 struct net_device *slave)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800178{
179 char linkname[IFNAMSIZ+7];
180
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700181 sysfs_remove_link(&(slave->dev.kobj), "master");
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000182 sprintf(linkname, "slave_%s", slave->name);
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700183 sysfs_remove_link(&(master->dev.kobj), linkname);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800184}
185
186
187/*
188 * Show the slaves in the current bond.
189 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700190static ssize_t bonding_show_slaves(struct device *d,
191 struct device_attribute *attr, char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800192{
193 struct slave *slave;
194 int i, res = 0;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700195 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800196
Jay Vosburgh6603a6f2007-10-17 17:37:50 -0700197 read_lock(&bond->lock);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800198 bond_for_each_slave(bond, slave, i) {
199 if (res > (PAGE_SIZE - IFNAMSIZ)) {
200 /* not enough space for another interface name */
201 if ((PAGE_SIZE - res) > 10)
202 res = PAGE_SIZE - 10;
Wagner Ferenc7bd46502007-12-06 23:40:28 -0800203 res += sprintf(buf + res, "++more++ ");
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800204 break;
205 }
206 res += sprintf(buf + res, "%s ", slave->dev->name);
207 }
Jay Vosburgh6603a6f2007-10-17 17:37:50 -0700208 read_unlock(&bond->lock);
Wagner Ferenc1dcdcd62007-12-06 23:40:31 -0800209 if (res)
210 buf[res-1] = '\n'; /* eat the leftover space */
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800211 return res;
212}
213
214/*
215 * Set the slaves in the current bond. The bond interface must be
216 * up for this to succeed.
Jiri Pirkof9f35452010-05-18 05:46:39 +0000217 * This is supposed to be only thin wrapper for bond_enslave and bond_release.
218 * All hard work should be done there.
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800219 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700220static ssize_t bonding_store_slaves(struct device *d,
221 struct device_attribute *attr,
222 const char *buffer, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800223{
224 char command[IFNAMSIZ + 1] = { 0, };
225 char *ifname;
Jiri Pirkof9f35452010-05-18 05:46:39 +0000226 int res, ret = count;
227 struct net_device *dev;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700228 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800229
230 /* Quick sanity check -- is the bond interface up? */
231 if (!(bond->dev->flags & IFF_UP)) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800232 pr_warning("%s: doing slave updates when interface is down.\n",
233 bond->dev->name);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800234 }
235
Eric W. Biederman496a60c2009-05-13 17:02:50 +0000236 if (!rtnl_trylock())
237 return restart_syscall();
Jay Vosburgh027ea042008-01-17 16:25:02 -0800238
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800239 sscanf(buffer, "%16s", command); /* IFNAMSIZ*/
240 ifname = command + 1;
241 if ((strlen(command) <= 1) ||
242 !dev_valid_name(ifname))
243 goto err_no_cmd;
244
Jiri Pirkof9f35452010-05-18 05:46:39 +0000245 dev = __dev_get_by_name(dev_net(bond->dev), ifname);
246 if (!dev) {
247 pr_info("%s: Interface %s does not exist!\n",
248 bond->dev->name, ifname);
249 ret = -ENODEV;
250 goto out;
251 }
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800252
Jiri Pirkof9f35452010-05-18 05:46:39 +0000253 switch (command[0]) {
254 case '+':
255 pr_info("%s: Adding slave %s.\n", bond->dev->name, dev->name);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800256 res = bond_enslave(bond->dev, dev);
Jiri Pirkof9f35452010-05-18 05:46:39 +0000257 break;
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000258
Jiri Pirkof9f35452010-05-18 05:46:39 +0000259 case '-':
260 pr_info("%s: Removing slave %s.\n", bond->dev->name, dev->name);
261 res = bond_release(bond->dev, dev);
262 break;
263
264 default:
265 goto err_no_cmd;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800266 }
267
Jiri Pirkof9f35452010-05-18 05:46:39 +0000268 if (res)
269 ret = res;
270 goto out;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800271
272err_no_cmd:
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800273 pr_err("no command found in slaves file for bond %s. Use +ifname or -ifname.\n",
274 bond->dev->name);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800275 ret = -EPERM;
276
277out:
Jay Vosburgh027ea042008-01-17 16:25:02 -0800278 rtnl_unlock();
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800279 return ret;
280}
281
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000282static DEVICE_ATTR(slaves, S_IRUGO | S_IWUSR, bonding_show_slaves,
283 bonding_store_slaves);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800284
285/*
286 * Show and set the bonding mode. The bond interface must be down to
287 * change the mode.
288 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700289static ssize_t bonding_show_mode(struct device *d,
290 struct device_attribute *attr, char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800291{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700292 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800293
294 return sprintf(buf, "%s %d\n",
295 bond_mode_tbl[bond->params.mode].modename,
Wagner Ferenc7bd46502007-12-06 23:40:28 -0800296 bond->params.mode);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800297}
298
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700299static ssize_t bonding_store_mode(struct device *d,
300 struct device_attribute *attr,
301 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800302{
303 int new_value, ret = count;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700304 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800305
306 if (bond->dev->flags & IFF_UP) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800307 pr_err("unable to update mode of %s because interface is up.\n",
308 bond->dev->name);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800309 ret = -EPERM;
310 goto out;
311 }
312
Jay Vosburghece95f72008-01-17 16:25:01 -0800313 new_value = bond_parse_parm(buf, bond_mode_tbl);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800314 if (new_value < 0) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800315 pr_err("%s: Ignoring invalid mode value %.*s.\n",
316 bond->dev->name, (int)strlen(buf) - 1, buf);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800317 ret = -EINVAL;
318 goto out;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800319 }
Andy Gospodarekc5cb0022010-07-28 15:13:56 +0000320 if ((new_value == BOND_MODE_ALB ||
321 new_value == BOND_MODE_TLB) &&
322 bond->params.arp_interval) {
323 pr_err("%s: %s mode is incompatible with arp monitoring.\n",
324 bond->dev->name, bond_mode_tbl[new_value].modename);
325 ret = -EINVAL;
326 goto out;
327 }
328 if (bond->params.mode == BOND_MODE_8023AD)
329 bond_unset_master_3ad_flags(bond);
330
331 if (bond->params.mode == BOND_MODE_ALB)
332 bond_unset_master_alb_flags(bond);
333
334 bond->params.mode = new_value;
335 bond_set_mode_ops(bond, bond->params.mode);
336 pr_info("%s: setting mode to %s (%d).\n",
337 bond->dev->name, bond_mode_tbl[new_value].modename,
338 new_value);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800339out:
340 return ret;
341}
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000342static DEVICE_ATTR(mode, S_IRUGO | S_IWUSR,
343 bonding_show_mode, bonding_store_mode);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800344
345/*
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000346 * Show and set the bonding transmit hash method.
347 * The bond interface must be down to change the xmit hash policy.
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800348 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700349static ssize_t bonding_show_xmit_hash(struct device *d,
350 struct device_attribute *attr,
351 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800352{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700353 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800354
Wagner Ferenc8e4b9322007-12-06 23:40:32 -0800355 return sprintf(buf, "%s %d\n",
356 xmit_hashtype_tbl[bond->params.xmit_policy].modename,
357 bond->params.xmit_policy);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800358}
359
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700360static ssize_t bonding_store_xmit_hash(struct device *d,
361 struct device_attribute *attr,
362 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800363{
364 int new_value, ret = count;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700365 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800366
367 if (bond->dev->flags & IFF_UP) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800368 pr_err("%s: Interface is up. Unable to update xmit policy.\n",
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800369 bond->dev->name);
370 ret = -EPERM;
371 goto out;
372 }
373
Jay Vosburghece95f72008-01-17 16:25:01 -0800374 new_value = bond_parse_parm(buf, xmit_hashtype_tbl);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800375 if (new_value < 0) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800376 pr_err("%s: Ignoring invalid xmit hash policy value %.*s.\n",
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800377 bond->dev->name,
378 (int)strlen(buf) - 1, buf);
379 ret = -EINVAL;
380 goto out;
381 } else {
382 bond->params.xmit_policy = new_value;
383 bond_set_mode_ops(bond, bond->params.mode);
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800384 pr_info("%s: setting xmit hash policy to %s (%d).\n",
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000385 bond->dev->name,
386 xmit_hashtype_tbl[new_value].modename, new_value);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800387 }
388out:
389 return ret;
390}
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000391static DEVICE_ATTR(xmit_hash_policy, S_IRUGO | S_IWUSR,
392 bonding_show_xmit_hash, bonding_store_xmit_hash);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800393
394/*
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700395 * Show and set arp_validate.
396 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700397static ssize_t bonding_show_arp_validate(struct device *d,
398 struct device_attribute *attr,
399 char *buf)
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700400{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700401 struct bonding *bond = to_bond(d);
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700402
403 return sprintf(buf, "%s %d\n",
404 arp_validate_tbl[bond->params.arp_validate].modename,
Wagner Ferenc7bd46502007-12-06 23:40:28 -0800405 bond->params.arp_validate);
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700406}
407
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700408static ssize_t bonding_store_arp_validate(struct device *d,
409 struct device_attribute *attr,
410 const char *buf, size_t count)
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700411{
412 int new_value;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700413 struct bonding *bond = to_bond(d);
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700414
Jay Vosburghece95f72008-01-17 16:25:01 -0800415 new_value = bond_parse_parm(buf, arp_validate_tbl);
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700416 if (new_value < 0) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800417 pr_err("%s: Ignoring invalid arp_validate value %s\n",
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700418 bond->dev->name, buf);
419 return -EINVAL;
420 }
421 if (new_value && (bond->params.mode != BOND_MODE_ACTIVEBACKUP)) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800422 pr_err("%s: arp_validate only supported in active-backup mode.\n",
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700423 bond->dev->name);
424 return -EINVAL;
425 }
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800426 pr_info("%s: setting arp_validate to %s (%d).\n",
427 bond->dev->name, arp_validate_tbl[new_value].modename,
428 new_value);
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700429
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000430 if (!bond->params.arp_validate && new_value)
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700431 bond_register_arp(bond);
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000432 else if (bond->params.arp_validate && !new_value)
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700433 bond_unregister_arp(bond);
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700434
435 bond->params.arp_validate = new_value;
436
437 return count;
438}
439
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000440static DEVICE_ATTR(arp_validate, S_IRUGO | S_IWUSR, bonding_show_arp_validate,
441 bonding_store_arp_validate);
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700442
443/*
Jay Vosburghdd957c52007-10-09 19:57:24 -0700444 * Show and store fail_over_mac. User only allowed to change the
445 * value when there are no slaves.
446 */
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000447static ssize_t bonding_show_fail_over_mac(struct device *d,
448 struct device_attribute *attr,
449 char *buf)
Jay Vosburghdd957c52007-10-09 19:57:24 -0700450{
451 struct bonding *bond = to_bond(d);
452
Jay Vosburgh3915c1e82008-05-17 21:10:14 -0700453 return sprintf(buf, "%s %d\n",
454 fail_over_mac_tbl[bond->params.fail_over_mac].modename,
455 bond->params.fail_over_mac);
Jay Vosburghdd957c52007-10-09 19:57:24 -0700456}
457
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000458static ssize_t bonding_store_fail_over_mac(struct device *d,
459 struct device_attribute *attr,
460 const char *buf, size_t count)
Jay Vosburghdd957c52007-10-09 19:57:24 -0700461{
462 int new_value;
Jay Vosburghdd957c52007-10-09 19:57:24 -0700463 struct bonding *bond = to_bond(d);
464
465 if (bond->slave_cnt != 0) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800466 pr_err("%s: Can't alter fail_over_mac with slaves in bond.\n",
Jay Vosburghdd957c52007-10-09 19:57:24 -0700467 bond->dev->name);
Jay Vosburgh3915c1e82008-05-17 21:10:14 -0700468 return -EPERM;
Jay Vosburghdd957c52007-10-09 19:57:24 -0700469 }
470
Jay Vosburgh3915c1e82008-05-17 21:10:14 -0700471 new_value = bond_parse_parm(buf, fail_over_mac_tbl);
472 if (new_value < 0) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800473 pr_err("%s: Ignoring invalid fail_over_mac value %s.\n",
Jay Vosburgh3915c1e82008-05-17 21:10:14 -0700474 bond->dev->name, buf);
475 return -EINVAL;
Jay Vosburghdd957c52007-10-09 19:57:24 -0700476 }
477
Jay Vosburgh3915c1e82008-05-17 21:10:14 -0700478 bond->params.fail_over_mac = new_value;
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800479 pr_info("%s: Setting fail_over_mac to %s (%d).\n",
480 bond->dev->name, fail_over_mac_tbl[new_value].modename,
481 new_value);
Jay Vosburgh3915c1e82008-05-17 21:10:14 -0700482
483 return count;
Jay Vosburghdd957c52007-10-09 19:57:24 -0700484}
485
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000486static DEVICE_ATTR(fail_over_mac, S_IRUGO | S_IWUSR,
487 bonding_show_fail_over_mac, bonding_store_fail_over_mac);
Jay Vosburghdd957c52007-10-09 19:57:24 -0700488
489/*
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800490 * Show and set the arp timer interval. There are two tricky bits
491 * here. First, if ARP monitoring is activated, then we must disable
492 * MII monitoring. Second, if the ARP timer isn't running, we must
493 * start it.
494 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700495static ssize_t bonding_show_arp_interval(struct device *d,
496 struct device_attribute *attr,
497 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800498{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700499 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800500
Wagner Ferenc7bd46502007-12-06 23:40:28 -0800501 return sprintf(buf, "%d\n", bond->params.arp_interval);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800502}
503
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700504static ssize_t bonding_store_arp_interval(struct device *d,
505 struct device_attribute *attr,
506 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800507{
508 int new_value, ret = count;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700509 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800510
511 if (sscanf(buf, "%d", &new_value) != 1) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800512 pr_err("%s: no arp_interval value specified.\n",
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800513 bond->dev->name);
514 ret = -EINVAL;
515 goto out;
516 }
517 if (new_value < 0) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800518 pr_err("%s: Invalid arp_interval value %d not in range 1-%d; rejected.\n",
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800519 bond->dev->name, new_value, INT_MAX);
520 ret = -EINVAL;
521 goto out;
522 }
Andy Gospodarekc5cb0022010-07-28 15:13:56 +0000523 if (bond->params.mode == BOND_MODE_ALB ||
524 bond->params.mode == BOND_MODE_TLB) {
525 pr_info("%s: ARP monitoring cannot be used with ALB/TLB. Only MII monitoring is supported on %s.\n",
526 bond->dev->name, bond->dev->name);
527 ret = -EINVAL;
528 goto out;
529 }
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800530 pr_info("%s: Setting ARP monitoring interval to %d.\n",
531 bond->dev->name, new_value);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800532 bond->params.arp_interval = new_value;
Jay Vosburgh6cf3f412008-11-03 18:16:50 -0800533 if (bond->params.arp_interval)
534 bond->dev->priv_flags |= IFF_MASTER_ARPMON;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800535 if (bond->params.miimon) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800536 pr_info("%s: ARP monitoring cannot be used with MII monitoring. %s Disabling MII monitoring.\n",
537 bond->dev->name, bond->dev->name);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800538 bond->params.miimon = 0;
Jay Vosburgh1b76b312007-10-17 17:37:45 -0700539 if (delayed_work_pending(&bond->mii_work)) {
540 cancel_delayed_work(&bond->mii_work);
541 flush_workqueue(bond->wq);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800542 }
543 }
544 if (!bond->params.arp_targets[0]) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800545 pr_info("%s: ARP monitoring has been set up, but no ARP targets have been specified.\n",
546 bond->dev->name);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800547 }
548 if (bond->dev->flags & IFF_UP) {
549 /* If the interface is up, we may need to fire off
550 * the ARP timer. If the interface is down, the
551 * timer will get fired off when the open function
552 * is called.
553 */
Jay Vosburgh1b76b312007-10-17 17:37:45 -0700554 if (!delayed_work_pending(&bond->arp_work)) {
555 if (bond->params.mode == BOND_MODE_ACTIVEBACKUP)
556 INIT_DELAYED_WORK(&bond->arp_work,
557 bond_activebackup_arp_mon);
558 else
559 INIT_DELAYED_WORK(&bond->arp_work,
560 bond_loadbalance_arp_mon);
561
562 queue_delayed_work(bond->wq, &bond->arp_work, 0);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800563 }
564 }
565
566out:
567 return ret;
568}
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000569static DEVICE_ATTR(arp_interval, S_IRUGO | S_IWUSR,
570 bonding_show_arp_interval, bonding_store_arp_interval);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800571
572/*
573 * Show and set the arp targets.
574 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700575static ssize_t bonding_show_arp_targets(struct device *d,
576 struct device_attribute *attr,
577 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800578{
579 int i, res = 0;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700580 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800581
582 for (i = 0; i < BOND_MAX_ARP_TARGETS; i++) {
583 if (bond->params.arp_targets[i])
Harvey Harrison63779432008-10-31 00:56:00 -0700584 res += sprintf(buf + res, "%pI4 ",
585 &bond->params.arp_targets[i]);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800586 }
Wagner Ferenc1dcdcd62007-12-06 23:40:31 -0800587 if (res)
588 buf[res-1] = '\n'; /* eat the leftover space */
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800589 return res;
590}
591
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700592static ssize_t bonding_store_arp_targets(struct device *d,
593 struct device_attribute *attr,
594 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800595{
Al Virod3bb52b2007-08-22 20:06:58 -0400596 __be32 newtarget;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800597 int i = 0, done = 0, ret = count;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700598 struct bonding *bond = to_bond(d);
Al Virod3bb52b2007-08-22 20:06:58 -0400599 __be32 *targets;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800600
601 targets = bond->params.arp_targets;
602 newtarget = in_aton(buf + 1);
603 /* look for adds */
604 if (buf[0] == '+') {
Al Virod3bb52b2007-08-22 20:06:58 -0400605 if ((newtarget == 0) || (newtarget == htonl(INADDR_BROADCAST))) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800606 pr_err("%s: invalid ARP target %pI4 specified for addition\n",
Harvey Harrison63779432008-10-31 00:56:00 -0700607 bond->dev->name, &newtarget);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800608 ret = -EINVAL;
609 goto out;
610 }
611 /* look for an empty slot to put the target in, and check for dupes */
Brian Haley5a31bec2009-04-13 00:11:30 -0700612 for (i = 0; (i < BOND_MAX_ARP_TARGETS) && !done; i++) {
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800613 if (targets[i] == newtarget) { /* duplicate */
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800614 pr_err("%s: ARP target %pI4 is already present\n",
Harvey Harrison63779432008-10-31 00:56:00 -0700615 bond->dev->name, &newtarget);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800616 ret = -EINVAL;
617 goto out;
618 }
Brian Haley5a31bec2009-04-13 00:11:30 -0700619 if (targets[i] == 0) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800620 pr_info("%s: adding ARP target %pI4.\n",
621 bond->dev->name, &newtarget);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800622 done = 1;
623 targets[i] = newtarget;
624 }
625 }
626 if (!done) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800627 pr_err("%s: ARP target table is full!\n",
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800628 bond->dev->name);
629 ret = -EINVAL;
630 goto out;
631 }
632
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000633 } else if (buf[0] == '-') {
Al Virod3bb52b2007-08-22 20:06:58 -0400634 if ((newtarget == 0) || (newtarget == htonl(INADDR_BROADCAST))) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800635 pr_err("%s: invalid ARP target %pI4 specified for removal\n",
Harvey Harrison63779432008-10-31 00:56:00 -0700636 bond->dev->name, &newtarget);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800637 ret = -EINVAL;
638 goto out;
639 }
640
Brian Haley5a31bec2009-04-13 00:11:30 -0700641 for (i = 0; (i < BOND_MAX_ARP_TARGETS) && !done; i++) {
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800642 if (targets[i] == newtarget) {
Brian Haley5a31bec2009-04-13 00:11:30 -0700643 int j;
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800644 pr_info("%s: removing ARP target %pI4.\n",
645 bond->dev->name, &newtarget);
Brian Haley5a31bec2009-04-13 00:11:30 -0700646 for (j = i; (j < (BOND_MAX_ARP_TARGETS-1)) && targets[j+1]; j++)
647 targets[j] = targets[j+1];
648
649 targets[j] = 0;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800650 done = 1;
651 }
652 }
653 if (!done) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800654 pr_info("%s: unable to remove nonexistent ARP target %pI4.\n",
655 bond->dev->name, &newtarget);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800656 ret = -EINVAL;
657 goto out;
658 }
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000659 } else {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800660 pr_err("no command found in arp_ip_targets file for bond %s. Use +<addr> or -<addr>.\n",
661 bond->dev->name);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800662 ret = -EPERM;
663 goto out;
664 }
665
666out:
667 return ret;
668}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700669static DEVICE_ATTR(arp_ip_target, S_IRUGO | S_IWUSR , bonding_show_arp_targets, bonding_store_arp_targets);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800670
671/*
672 * Show and set the up and down delays. These must be multiples of the
673 * MII monitoring value, and are stored internally as the multiplier.
674 * Thus, we must translate to MS for the real world.
675 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700676static ssize_t bonding_show_downdelay(struct device *d,
677 struct device_attribute *attr,
678 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800679{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700680 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800681
Wagner Ferenc7bd46502007-12-06 23:40:28 -0800682 return sprintf(buf, "%d\n", bond->params.downdelay * bond->params.miimon);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800683}
684
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700685static ssize_t bonding_store_downdelay(struct device *d,
686 struct device_attribute *attr,
687 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800688{
689 int new_value, ret = count;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700690 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800691
692 if (!(bond->params.miimon)) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800693 pr_err("%s: Unable to set down delay as MII monitoring is disabled\n",
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800694 bond->dev->name);
695 ret = -EPERM;
696 goto out;
697 }
698
699 if (sscanf(buf, "%d", &new_value) != 1) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800700 pr_err("%s: no down delay value specified.\n", bond->dev->name);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800701 ret = -EINVAL;
702 goto out;
703 }
704 if (new_value < 0) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800705 pr_err("%s: Invalid down delay value %d not in range %d-%d; rejected.\n",
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800706 bond->dev->name, new_value, 1, INT_MAX);
707 ret = -EINVAL;
708 goto out;
709 } else {
710 if ((new_value % bond->params.miimon) != 0) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800711 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 +0000712 bond->dev->name, new_value,
713 bond->params.miimon,
714 (new_value / bond->params.miimon) *
715 bond->params.miimon);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800716 }
717 bond->params.downdelay = new_value / bond->params.miimon;
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800718 pr_info("%s: Setting down delay to %d.\n",
719 bond->dev->name,
720 bond->params.downdelay * bond->params.miimon);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800721
722 }
723
724out:
725 return ret;
726}
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000727static DEVICE_ATTR(downdelay, S_IRUGO | S_IWUSR,
728 bonding_show_downdelay, bonding_store_downdelay);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800729
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700730static ssize_t bonding_show_updelay(struct device *d,
731 struct device_attribute *attr,
732 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800733{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700734 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800735
Wagner Ferenc7bd46502007-12-06 23:40:28 -0800736 return sprintf(buf, "%d\n", bond->params.updelay * bond->params.miimon);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800737
738}
739
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700740static ssize_t bonding_store_updelay(struct device *d,
741 struct device_attribute *attr,
742 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800743{
744 int new_value, ret = count;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700745 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800746
747 if (!(bond->params.miimon)) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800748 pr_err("%s: Unable to set up delay as MII monitoring is disabled\n",
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800749 bond->dev->name);
750 ret = -EPERM;
751 goto out;
752 }
753
754 if (sscanf(buf, "%d", &new_value) != 1) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800755 pr_err("%s: no up delay value specified.\n",
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800756 bond->dev->name);
757 ret = -EINVAL;
758 goto out;
759 }
760 if (new_value < 0) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800761 pr_err("%s: Invalid down delay value %d not in range %d-%d; rejected.\n",
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800762 bond->dev->name, new_value, 1, INT_MAX);
763 ret = -EINVAL;
764 goto out;
765 } else {
766 if ((new_value % bond->params.miimon) != 0) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800767 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 +0000768 bond->dev->name, new_value,
769 bond->params.miimon,
770 (new_value / bond->params.miimon) *
771 bond->params.miimon);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800772 }
773 bond->params.updelay = new_value / bond->params.miimon;
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800774 pr_info("%s: Setting up delay to %d.\n",
775 bond->dev->name,
776 bond->params.updelay * bond->params.miimon);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800777 }
778
779out:
780 return ret;
781}
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000782static DEVICE_ATTR(updelay, S_IRUGO | S_IWUSR,
783 bonding_show_updelay, bonding_store_updelay);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800784
785/*
786 * Show and set the LACP interval. Interface must be down, and the mode
787 * must be set to 802.3ad mode.
788 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700789static ssize_t bonding_show_lacp(struct device *d,
790 struct device_attribute *attr,
791 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800792{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700793 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800794
795 return sprintf(buf, "%s %d\n",
796 bond_lacp_tbl[bond->params.lacp_fast].modename,
Wagner Ferenc7bd46502007-12-06 23:40:28 -0800797 bond->params.lacp_fast);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800798}
799
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700800static ssize_t bonding_store_lacp(struct device *d,
801 struct device_attribute *attr,
802 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800803{
804 int new_value, ret = count;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700805 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800806
807 if (bond->dev->flags & IFF_UP) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800808 pr_err("%s: Unable to update LACP rate because interface is up.\n",
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800809 bond->dev->name);
810 ret = -EPERM;
811 goto out;
812 }
813
814 if (bond->params.mode != BOND_MODE_8023AD) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800815 pr_err("%s: Unable to update LACP rate because bond is not in 802.3ad mode.\n",
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800816 bond->dev->name);
817 ret = -EPERM;
818 goto out;
819 }
820
Jay Vosburghece95f72008-01-17 16:25:01 -0800821 new_value = bond_parse_parm(buf, bond_lacp_tbl);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800822
823 if ((new_value == 1) || (new_value == 0)) {
824 bond->params.lacp_fast = new_value;
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800825 pr_info("%s: Setting LACP rate to %s (%d).\n",
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000826 bond->dev->name, bond_lacp_tbl[new_value].modename,
827 new_value);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800828 } else {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800829 pr_err("%s: Ignoring invalid LACP rate value %.*s.\n",
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000830 bond->dev->name, (int)strlen(buf) - 1, buf);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800831 ret = -EINVAL;
832 }
833out:
834 return ret;
835}
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000836static DEVICE_ATTR(lacp_rate, S_IRUGO | S_IWUSR,
837 bonding_show_lacp, bonding_store_lacp);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800838
Jay Vosburghfd989c82008-11-04 17:51:16 -0800839static ssize_t bonding_show_ad_select(struct device *d,
840 struct device_attribute *attr,
841 char *buf)
842{
843 struct bonding *bond = to_bond(d);
844
845 return sprintf(buf, "%s %d\n",
846 ad_select_tbl[bond->params.ad_select].modename,
847 bond->params.ad_select);
848}
849
850
851static ssize_t bonding_store_ad_select(struct device *d,
852 struct device_attribute *attr,
853 const char *buf, size_t count)
854{
855 int new_value, ret = count;
856 struct bonding *bond = to_bond(d);
857
858 if (bond->dev->flags & IFF_UP) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800859 pr_err("%s: Unable to update ad_select because interface is up.\n",
860 bond->dev->name);
Jay Vosburghfd989c82008-11-04 17:51:16 -0800861 ret = -EPERM;
862 goto out;
863 }
864
865 new_value = bond_parse_parm(buf, ad_select_tbl);
866
867 if (new_value != -1) {
868 bond->params.ad_select = new_value;
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800869 pr_info("%s: Setting ad_select to %s (%d).\n",
870 bond->dev->name, ad_select_tbl[new_value].modename,
871 new_value);
Jay Vosburghfd989c82008-11-04 17:51:16 -0800872 } else {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800873 pr_err("%s: Ignoring invalid ad_select value %.*s.\n",
Jay Vosburghfd989c82008-11-04 17:51:16 -0800874 bond->dev->name, (int)strlen(buf) - 1, buf);
875 ret = -EINVAL;
876 }
877out:
878 return ret;
879}
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000880static DEVICE_ATTR(ad_select, S_IRUGO | S_IWUSR,
881 bonding_show_ad_select, bonding_store_ad_select);
Jay Vosburghfd989c82008-11-04 17:51:16 -0800882
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800883/*
Moni Shoua7893b242008-05-17 21:10:12 -0700884 * Show and set the number of grat ARP to send after a failover event.
885 */
886static ssize_t bonding_show_n_grat_arp(struct device *d,
887 struct device_attribute *attr,
888 char *buf)
889{
890 struct bonding *bond = to_bond(d);
891
892 return sprintf(buf, "%d\n", bond->params.num_grat_arp);
893}
894
895static ssize_t bonding_store_n_grat_arp(struct device *d,
896 struct device_attribute *attr,
897 const char *buf, size_t count)
898{
899 int new_value, ret = count;
900 struct bonding *bond = to_bond(d);
901
902 if (sscanf(buf, "%d", &new_value) != 1) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800903 pr_err("%s: no num_grat_arp value specified.\n",
Moni Shoua7893b242008-05-17 21:10:12 -0700904 bond->dev->name);
905 ret = -EINVAL;
906 goto out;
907 }
908 if (new_value < 0 || new_value > 255) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800909 pr_err("%s: Invalid num_grat_arp value %d not in range 0-255; rejected.\n",
Moni Shoua7893b242008-05-17 21:10:12 -0700910 bond->dev->name, new_value);
911 ret = -EINVAL;
912 goto out;
913 } else {
914 bond->params.num_grat_arp = new_value;
915 }
916out:
917 return ret;
918}
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000919static DEVICE_ATTR(num_grat_arp, S_IRUGO | S_IWUSR,
920 bonding_show_n_grat_arp, bonding_store_n_grat_arp);
Brian Haley305d5522008-11-04 17:51:14 -0800921
922/*
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000923 * Show and set the number of unsolicited NA's to send after a failover event.
Brian Haley305d5522008-11-04 17:51:14 -0800924 */
925static ssize_t bonding_show_n_unsol_na(struct device *d,
926 struct device_attribute *attr,
927 char *buf)
928{
929 struct bonding *bond = to_bond(d);
930
931 return sprintf(buf, "%d\n", bond->params.num_unsol_na);
932}
933
934static ssize_t bonding_store_n_unsol_na(struct device *d,
935 struct device_attribute *attr,
936 const char *buf, size_t count)
937{
938 int new_value, ret = count;
939 struct bonding *bond = to_bond(d);
940
941 if (sscanf(buf, "%d", &new_value) != 1) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800942 pr_err("%s: no num_unsol_na value specified.\n",
Brian Haley305d5522008-11-04 17:51:14 -0800943 bond->dev->name);
944 ret = -EINVAL;
945 goto out;
946 }
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000947
Brian Haley305d5522008-11-04 17:51:14 -0800948 if (new_value < 0 || new_value > 255) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800949 pr_err("%s: Invalid num_unsol_na value %d not in range 0-255; rejected.\n",
Brian Haley305d5522008-11-04 17:51:14 -0800950 bond->dev->name, new_value);
951 ret = -EINVAL;
952 goto out;
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000953 } else
Brian Haley305d5522008-11-04 17:51:14 -0800954 bond->params.num_unsol_na = new_value;
Brian Haley305d5522008-11-04 17:51:14 -0800955out:
956 return ret;
957}
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000958static DEVICE_ATTR(num_unsol_na, S_IRUGO | S_IWUSR,
959 bonding_show_n_unsol_na, bonding_store_n_unsol_na);
Brian Haley305d5522008-11-04 17:51:14 -0800960
Moni Shoua7893b242008-05-17 21:10:12 -0700961/*
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800962 * Show and set the MII monitor interval. There are two tricky bits
963 * here. First, if MII monitoring is activated, then we must disable
964 * ARP monitoring. Second, if the timer isn't running, we must
965 * start it.
966 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700967static ssize_t bonding_show_miimon(struct device *d,
968 struct device_attribute *attr,
969 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800970{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700971 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800972
Wagner Ferenc7bd46502007-12-06 23:40:28 -0800973 return sprintf(buf, "%d\n", bond->params.miimon);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800974}
975
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700976static ssize_t bonding_store_miimon(struct device *d,
977 struct device_attribute *attr,
978 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800979{
980 int new_value, ret = count;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700981 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800982
983 if (sscanf(buf, "%d", &new_value) != 1) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800984 pr_err("%s: no miimon value specified.\n",
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800985 bond->dev->name);
986 ret = -EINVAL;
987 goto out;
988 }
989 if (new_value < 0) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800990 pr_err("%s: Invalid miimon value %d not in range %d-%d; rejected.\n",
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800991 bond->dev->name, new_value, 1, INT_MAX);
992 ret = -EINVAL;
993 goto out;
994 } else {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800995 pr_info("%s: Setting MII monitoring interval to %d.\n",
996 bond->dev->name, new_value);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800997 bond->params.miimon = new_value;
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000998 if (bond->params.updelay)
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800999 pr_info("%s: Note: Updating updelay (to %d) since it is a multiple of the miimon value.\n",
1000 bond->dev->name,
1001 bond->params.updelay * bond->params.miimon);
Stephen Hemminger3d632c32009-06-12 19:02:48 +00001002 if (bond->params.downdelay)
Joe Perchesa4aee5c2009-12-13 20:06:07 -08001003 pr_info("%s: Note: Updating downdelay (to %d) since it is a multiple of the miimon value.\n",
1004 bond->dev->name,
1005 bond->params.downdelay * bond->params.miimon);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001006 if (bond->params.arp_interval) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -08001007 pr_info("%s: MII monitoring cannot be used with ARP monitoring. Disabling ARP monitoring...\n",
1008 bond->dev->name);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001009 bond->params.arp_interval = 0;
Jay Vosburgh6cf3f412008-11-03 18:16:50 -08001010 bond->dev->priv_flags &= ~IFF_MASTER_ARPMON;
Jay Vosburghf5b2b962006-09-22 21:54:53 -07001011 if (bond->params.arp_validate) {
1012 bond_unregister_arp(bond);
1013 bond->params.arp_validate =
1014 BOND_ARP_VALIDATE_NONE;
1015 }
Jay Vosburgh1b76b312007-10-17 17:37:45 -07001016 if (delayed_work_pending(&bond->arp_work)) {
1017 cancel_delayed_work(&bond->arp_work);
1018 flush_workqueue(bond->wq);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001019 }
1020 }
1021
1022 if (bond->dev->flags & IFF_UP) {
1023 /* If the interface is up, we may need to fire off
1024 * the MII timer. If the interface is down, the
1025 * timer will get fired off when the open function
1026 * is called.
1027 */
Jay Vosburgh1b76b312007-10-17 17:37:45 -07001028 if (!delayed_work_pending(&bond->mii_work)) {
1029 INIT_DELAYED_WORK(&bond->mii_work,
1030 bond_mii_monitor);
1031 queue_delayed_work(bond->wq,
1032 &bond->mii_work, 0);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001033 }
1034 }
1035 }
1036out:
1037 return ret;
1038}
Stephen Hemminger3d632c32009-06-12 19:02:48 +00001039static DEVICE_ATTR(miimon, S_IRUGO | S_IWUSR,
1040 bonding_show_miimon, bonding_store_miimon);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001041
1042/*
1043 * Show and set the primary slave. The store function is much
1044 * simpler than bonding_store_slaves function because it only needs to
1045 * handle one interface name.
1046 * The bond must be a mode that supports a primary for this be
1047 * set.
1048 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001049static ssize_t bonding_show_primary(struct device *d,
1050 struct device_attribute *attr,
1051 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001052{
1053 int count = 0;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001054 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001055
1056 if (bond->primary_slave)
Wagner Ferenc7bd46502007-12-06 23:40:28 -08001057 count = sprintf(buf, "%s\n", bond->primary_slave->dev->name);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001058
1059 return count;
1060}
1061
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001062static ssize_t bonding_store_primary(struct device *d,
1063 struct device_attribute *attr,
1064 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001065{
1066 int i;
1067 struct slave *slave;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001068 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001069
Eric W. Biederman496a60c2009-05-13 17:02:50 +00001070 if (!rtnl_trylock())
1071 return restart_syscall();
Neil Hormane843fa52010-10-13 16:01:50 +00001072 block_netpoll_tx();
Jay Vosburghe934dd72008-01-17 16:24:57 -08001073 read_lock(&bond->lock);
1074 write_lock_bh(&bond->curr_slave_lock);
1075
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001076 if (!USES_PRIMARY(bond->params.mode)) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -08001077 pr_info("%s: Unable to set primary slave; %s is in mode %d\n",
1078 bond->dev->name, bond->dev->name, bond->params.mode);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001079 } else {
1080 bond_for_each_slave(bond, slave, i) {
1081 if (strnicmp
1082 (slave->dev->name, buf,
1083 strlen(slave->dev->name)) == 0) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -08001084 pr_info("%s: Setting %s as primary slave.\n",
1085 bond->dev->name, slave->dev->name);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001086 bond->primary_slave = slave;
Jiri Pirkoce501ca2009-09-18 02:13:22 +00001087 strcpy(bond->params.primary, slave->dev->name);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001088 bond_select_active_slave(bond);
1089 goto out;
1090 }
1091 }
1092
1093 /* if we got here, then we didn't match the name of any slave */
1094
1095 if (strlen(buf) == 0 || buf[0] == '\n') {
Joe Perchesa4aee5c2009-12-13 20:06:07 -08001096 pr_info("%s: Setting primary slave to None.\n",
1097 bond->dev->name);
Luiz Fernando Capitulino3418db72006-02-01 00:54:34 -08001098 bond->primary_slave = NULL;
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001099 bond_select_active_slave(bond);
1100 } else {
Joe Perchesa4aee5c2009-12-13 20:06:07 -08001101 pr_info("%s: Unable to set %.*s as primary slave as it is not a slave.\n",
1102 bond->dev->name, (int)strlen(buf) - 1, buf);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001103 }
1104 }
1105out:
Jay Vosburghe934dd72008-01-17 16:24:57 -08001106 write_unlock_bh(&bond->curr_slave_lock);
1107 read_unlock(&bond->lock);
Neil Hormane843fa52010-10-13 16:01:50 +00001108 unblock_netpoll_tx();
Jay Vosburgh6603a6f2007-10-17 17:37:50 -07001109 rtnl_unlock();
1110
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001111 return count;
1112}
Stephen Hemminger3d632c32009-06-12 19:02:48 +00001113static DEVICE_ATTR(primary, S_IRUGO | S_IWUSR,
1114 bonding_show_primary, bonding_store_primary);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001115
1116/*
Jiri Pirkoa5499522009-09-25 03:28:09 +00001117 * Show and set the primary_reselect flag.
1118 */
1119static ssize_t bonding_show_primary_reselect(struct device *d,
1120 struct device_attribute *attr,
1121 char *buf)
1122{
1123 struct bonding *bond = to_bond(d);
1124
1125 return sprintf(buf, "%s %d\n",
1126 pri_reselect_tbl[bond->params.primary_reselect].modename,
1127 bond->params.primary_reselect);
1128}
1129
1130static ssize_t bonding_store_primary_reselect(struct device *d,
1131 struct device_attribute *attr,
1132 const char *buf, size_t count)
1133{
1134 int new_value, ret = count;
1135 struct bonding *bond = to_bond(d);
1136
1137 if (!rtnl_trylock())
1138 return restart_syscall();
1139
1140 new_value = bond_parse_parm(buf, pri_reselect_tbl);
1141 if (new_value < 0) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -08001142 pr_err("%s: Ignoring invalid primary_reselect value %.*s.\n",
Jiri Pirkoa5499522009-09-25 03:28:09 +00001143 bond->dev->name,
1144 (int) strlen(buf) - 1, buf);
1145 ret = -EINVAL;
1146 goto out;
1147 }
1148
1149 bond->params.primary_reselect = new_value;
Joe Perchesa4aee5c2009-12-13 20:06:07 -08001150 pr_info("%s: setting primary_reselect to %s (%d).\n",
Jiri Pirkoa5499522009-09-25 03:28:09 +00001151 bond->dev->name, pri_reselect_tbl[new_value].modename,
1152 new_value);
1153
Neil Hormane843fa52010-10-13 16:01:50 +00001154 block_netpoll_tx();
Jiri Pirkoa5499522009-09-25 03:28:09 +00001155 read_lock(&bond->lock);
1156 write_lock_bh(&bond->curr_slave_lock);
1157 bond_select_active_slave(bond);
1158 write_unlock_bh(&bond->curr_slave_lock);
1159 read_unlock(&bond->lock);
Neil Hormane843fa52010-10-13 16:01:50 +00001160 unblock_netpoll_tx();
Jiri Pirkoa5499522009-09-25 03:28:09 +00001161out:
1162 rtnl_unlock();
1163 return ret;
1164}
1165static DEVICE_ATTR(primary_reselect, S_IRUGO | S_IWUSR,
1166 bonding_show_primary_reselect,
1167 bonding_store_primary_reselect);
1168
1169/*
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001170 * Show and set the use_carrier flag.
1171 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001172static ssize_t bonding_show_carrier(struct device *d,
1173 struct device_attribute *attr,
1174 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001175{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001176 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001177
Wagner Ferenc7bd46502007-12-06 23:40:28 -08001178 return sprintf(buf, "%d\n", bond->params.use_carrier);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001179}
1180
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001181static ssize_t bonding_store_carrier(struct device *d,
1182 struct device_attribute *attr,
1183 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001184{
1185 int new_value, ret = count;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001186 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001187
1188
1189 if (sscanf(buf, "%d", &new_value) != 1) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -08001190 pr_err("%s: no use_carrier value specified.\n",
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001191 bond->dev->name);
1192 ret = -EINVAL;
1193 goto out;
1194 }
1195 if ((new_value == 0) || (new_value == 1)) {
1196 bond->params.use_carrier = new_value;
Joe Perchesa4aee5c2009-12-13 20:06:07 -08001197 pr_info("%s: Setting use_carrier to %d.\n",
1198 bond->dev->name, new_value);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001199 } else {
Joe Perchesa4aee5c2009-12-13 20:06:07 -08001200 pr_info("%s: Ignoring invalid use_carrier value %d.\n",
1201 bond->dev->name, new_value);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001202 }
1203out:
Jiri Pirko672bda32011-01-25 11:03:25 +00001204 return ret;
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001205}
Stephen Hemminger3d632c32009-06-12 19:02:48 +00001206static DEVICE_ATTR(use_carrier, S_IRUGO | S_IWUSR,
1207 bonding_show_carrier, bonding_store_carrier);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001208
1209
1210/*
1211 * Show and set currently active_slave.
1212 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001213static ssize_t bonding_show_active_slave(struct device *d,
1214 struct device_attribute *attr,
1215 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001216{
1217 struct slave *curr;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001218 struct bonding *bond = to_bond(d);
Wagner Ferenc16cd0162007-12-06 23:40:29 -08001219 int count = 0;
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001220
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001221 read_lock(&bond->curr_slave_lock);
1222 curr = bond->curr_active_slave;
1223 read_unlock(&bond->curr_slave_lock);
1224
1225 if (USES_PRIMARY(bond->params.mode) && curr)
Wagner Ferenc7bd46502007-12-06 23:40:28 -08001226 count = sprintf(buf, "%s\n", curr->dev->name);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001227 return count;
1228}
1229
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001230static ssize_t bonding_store_active_slave(struct device *d,
1231 struct device_attribute *attr,
1232 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001233{
1234 int i;
1235 struct slave *slave;
Stephen Hemminger3d632c32009-06-12 19:02:48 +00001236 struct slave *old_active = NULL;
1237 struct slave *new_active = NULL;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001238 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001239
Eric W. Biederman496a60c2009-05-13 17:02:50 +00001240 if (!rtnl_trylock())
1241 return restart_syscall();
Neil Hormane843fa52010-10-13 16:01:50 +00001242
1243 block_netpoll_tx();
Jay Vosburghe934dd72008-01-17 16:24:57 -08001244 read_lock(&bond->lock);
1245 write_lock_bh(&bond->curr_slave_lock);
Jay Vosburgh1466a212007-11-06 13:33:28 -08001246
Stephen Hemminger3d632c32009-06-12 19:02:48 +00001247 if (!USES_PRIMARY(bond->params.mode))
Joe Perchesa4aee5c2009-12-13 20:06:07 -08001248 pr_info("%s: Unable to change active slave; %s is in mode %d\n",
Stephen Hemminger3d632c32009-06-12 19:02:48 +00001249 bond->dev->name, bond->dev->name, bond->params.mode);
1250 else {
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001251 bond_for_each_slave(bond, slave, i) {
1252 if (strnicmp
1253 (slave->dev->name, buf,
1254 strlen(slave->dev->name)) == 0) {
1255 old_active = bond->curr_active_slave;
1256 new_active = slave;
Jay Vosburgha50d8de2006-09-22 21:53:25 -07001257 if (new_active == old_active) {
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001258 /* do nothing */
Joe Perchesa4aee5c2009-12-13 20:06:07 -08001259 pr_info("%s: %s is already the current active slave.\n",
1260 bond->dev->name,
1261 slave->dev->name);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001262 goto out;
1263 }
1264 else {
1265 if ((new_active) &&
1266 (old_active) &&
1267 (new_active->link == BOND_LINK_UP) &&
1268 IS_UP(new_active->dev)) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -08001269 pr_info("%s: Setting %s as active slave.\n",
1270 bond->dev->name,
1271 slave->dev->name);
Jiri Pirkoe5e2a8f2009-08-13 04:11:52 +00001272 bond_change_active_slave(bond, new_active);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001273 }
1274 else {
Joe Perchesa4aee5c2009-12-13 20:06:07 -08001275 pr_info("%s: Could not set %s as active slave; either %s is down or the link is down.\n",
1276 bond->dev->name,
1277 slave->dev->name,
Jiri Pirkoe5e2a8f2009-08-13 04:11:52 +00001278 slave->dev->name);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001279 }
1280 goto out;
1281 }
1282 }
1283 }
1284
1285 /* if we got here, then we didn't match the name of any slave */
1286
1287 if (strlen(buf) == 0 || buf[0] == '\n') {
Joe Perchesa4aee5c2009-12-13 20:06:07 -08001288 pr_info("%s: Setting active slave to None.\n",
Stephen Hemminger3d632c32009-06-12 19:02:48 +00001289 bond->dev->name);
Luiz Fernando Capitulino3418db72006-02-01 00:54:34 -08001290 bond->primary_slave = NULL;
Stephen Hemminger3d632c32009-06-12 19:02:48 +00001291 bond_select_active_slave(bond);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001292 } else {
Joe Perchesa4aee5c2009-12-13 20:06:07 -08001293 pr_info("%s: Unable to set %.*s as active slave as it is not a slave.\n",
Stephen Hemminger3d632c32009-06-12 19:02:48 +00001294 bond->dev->name, (int)strlen(buf) - 1, buf);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001295 }
1296 }
Stephen Hemminger3d632c32009-06-12 19:02:48 +00001297 out:
Jay Vosburghe934dd72008-01-17 16:24:57 -08001298 write_unlock_bh(&bond->curr_slave_lock);
1299 read_unlock(&bond->lock);
Neil Hormane843fa52010-10-13 16:01:50 +00001300 unblock_netpoll_tx();
1301
Jay Vosburgh6603a6f2007-10-17 17:37:50 -07001302 rtnl_unlock();
1303
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001304 return count;
1305
1306}
Stephen Hemminger3d632c32009-06-12 19:02:48 +00001307static DEVICE_ATTR(active_slave, S_IRUGO | S_IWUSR,
1308 bonding_show_active_slave, bonding_store_active_slave);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001309
1310
1311/*
1312 * Show link status of the bond interface.
1313 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001314static ssize_t bonding_show_mii_status(struct device *d,
1315 struct device_attribute *attr,
1316 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001317{
1318 struct slave *curr;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001319 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001320
1321 read_lock(&bond->curr_slave_lock);
1322 curr = bond->curr_active_slave;
1323 read_unlock(&bond->curr_slave_lock);
1324
Stephen Hemminger3d632c32009-06-12 19:02:48 +00001325 return sprintf(buf, "%s\n", curr ? "up" : "down");
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001326}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001327static DEVICE_ATTR(mii_status, S_IRUGO, bonding_show_mii_status, NULL);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001328
1329
1330/*
1331 * Show current 802.3ad aggregator ID.
1332 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001333static ssize_t bonding_show_ad_aggregator(struct device *d,
1334 struct device_attribute *attr,
1335 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001336{
1337 int count = 0;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001338 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001339
1340 if (bond->params.mode == BOND_MODE_8023AD) {
1341 struct ad_info ad_info;
Stephen Hemminger3d632c32009-06-12 19:02:48 +00001342 count = sprintf(buf, "%d\n",
1343 (bond_3ad_get_active_agg_info(bond, &ad_info))
1344 ? 0 : ad_info.aggregator_id);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001345 }
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001346
1347 return count;
1348}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001349static DEVICE_ATTR(ad_aggregator, S_IRUGO, bonding_show_ad_aggregator, NULL);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001350
1351
1352/*
1353 * Show number of active 802.3ad ports.
1354 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001355static ssize_t bonding_show_ad_num_ports(struct device *d,
1356 struct device_attribute *attr,
1357 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001358{
1359 int count = 0;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001360 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001361
1362 if (bond->params.mode == BOND_MODE_8023AD) {
1363 struct ad_info ad_info;
Stephen Hemminger3d632c32009-06-12 19:02:48 +00001364 count = sprintf(buf, "%d\n",
1365 (bond_3ad_get_active_agg_info(bond, &ad_info))
1366 ? 0 : ad_info.ports);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001367 }
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001368
1369 return count;
1370}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001371static DEVICE_ATTR(ad_num_ports, S_IRUGO, bonding_show_ad_num_ports, NULL);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001372
1373
1374/*
1375 * Show current 802.3ad actor key.
1376 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001377static ssize_t bonding_show_ad_actor_key(struct device *d,
1378 struct device_attribute *attr,
1379 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001380{
1381 int count = 0;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001382 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001383
1384 if (bond->params.mode == BOND_MODE_8023AD) {
1385 struct ad_info ad_info;
Stephen Hemminger3d632c32009-06-12 19:02:48 +00001386 count = sprintf(buf, "%d\n",
1387 (bond_3ad_get_active_agg_info(bond, &ad_info))
1388 ? 0 : ad_info.actor_key);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001389 }
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001390
1391 return count;
1392}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001393static DEVICE_ATTR(ad_actor_key, S_IRUGO, bonding_show_ad_actor_key, NULL);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001394
1395
1396/*
1397 * Show current 802.3ad partner key.
1398 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001399static ssize_t bonding_show_ad_partner_key(struct device *d,
1400 struct device_attribute *attr,
1401 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001402{
1403 int count = 0;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001404 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001405
1406 if (bond->params.mode == BOND_MODE_8023AD) {
1407 struct ad_info ad_info;
Stephen Hemminger3d632c32009-06-12 19:02:48 +00001408 count = sprintf(buf, "%d\n",
1409 (bond_3ad_get_active_agg_info(bond, &ad_info))
1410 ? 0 : ad_info.partner_key);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001411 }
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001412
1413 return count;
1414}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001415static DEVICE_ATTR(ad_partner_key, S_IRUGO, bonding_show_ad_partner_key, NULL);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001416
1417
1418/*
1419 * Show current 802.3ad partner mac.
1420 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001421static ssize_t bonding_show_ad_partner_mac(struct device *d,
1422 struct device_attribute *attr,
1423 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001424{
1425 int count = 0;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001426 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001427
1428 if (bond->params.mode == BOND_MODE_8023AD) {
1429 struct ad_info ad_info;
Stephen Hemminger3d632c32009-06-12 19:02:48 +00001430 if (!bond_3ad_get_active_agg_info(bond, &ad_info))
Johannes Berge1749612008-10-27 15:59:26 -07001431 count = sprintf(buf, "%pM\n", ad_info.partner_system);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001432 }
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001433
1434 return count;
1435}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001436static DEVICE_ATTR(ad_partner_mac, S_IRUGO, bonding_show_ad_partner_mac, NULL);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001437
Andy Gospodarekebd8e492010-06-02 08:39:21 +00001438/*
Andy Gospodarekbb1d9122010-06-02 08:40:18 +00001439 * Show the queue_ids of the slaves in the current bond.
1440 */
1441static ssize_t bonding_show_queue_id(struct device *d,
1442 struct device_attribute *attr,
1443 char *buf)
1444{
1445 struct slave *slave;
1446 int i, res = 0;
1447 struct bonding *bond = to_bond(d);
1448
1449 if (!rtnl_trylock())
1450 return restart_syscall();
1451
1452 read_lock(&bond->lock);
1453 bond_for_each_slave(bond, slave, i) {
Nicolas de Pesloüan79236682010-07-14 18:24:54 -07001454 if (res > (PAGE_SIZE - IFNAMSIZ - 6)) {
1455 /* not enough space for another interface_name:queue_id pair */
Andy Gospodarekbb1d9122010-06-02 08:40:18 +00001456 if ((PAGE_SIZE - res) > 10)
1457 res = PAGE_SIZE - 10;
1458 res += sprintf(buf + res, "++more++ ");
1459 break;
1460 }
1461 res += sprintf(buf + res, "%s:%d ",
1462 slave->dev->name, slave->queue_id);
1463 }
1464 read_unlock(&bond->lock);
1465 if (res)
1466 buf[res-1] = '\n'; /* eat the leftover space */
1467 rtnl_unlock();
1468 return res;
1469}
1470
1471/*
1472 * Set the queue_ids of the slaves in the current bond. The bond
1473 * interface must be enslaved for this to work.
1474 */
1475static ssize_t bonding_store_queue_id(struct device *d,
1476 struct device_attribute *attr,
1477 const char *buffer, size_t count)
1478{
1479 struct slave *slave, *update_slave;
1480 struct bonding *bond = to_bond(d);
1481 u16 qid;
1482 int i, ret = count;
1483 char *delim;
1484 struct net_device *sdev = NULL;
1485
1486 if (!rtnl_trylock())
1487 return restart_syscall();
1488
1489 /* delim will point to queue id if successful */
1490 delim = strchr(buffer, ':');
1491 if (!delim)
1492 goto err_no_cmd;
1493
1494 /*
1495 * Terminate string that points to device name and bump it
1496 * up one, so we can read the queue id there.
1497 */
1498 *delim = '\0';
1499 if (sscanf(++delim, "%hd\n", &qid) != 1)
1500 goto err_no_cmd;
1501
1502 /* Check buffer length, valid ifname and queue id */
1503 if (strlen(buffer) > IFNAMSIZ ||
1504 !dev_valid_name(buffer) ||
1505 qid > bond->params.tx_queues)
1506 goto err_no_cmd;
1507
1508 /* Get the pointer to that interface if it exists */
1509 sdev = __dev_get_by_name(dev_net(bond->dev), buffer);
1510 if (!sdev)
1511 goto err_no_cmd;
1512
1513 read_lock(&bond->lock);
1514
1515 /* Search for thes slave and check for duplicate qids */
1516 update_slave = NULL;
1517 bond_for_each_slave(bond, slave, i) {
1518 if (sdev == slave->dev)
1519 /*
1520 * We don't need to check the matching
1521 * slave for dups, since we're overwriting it
1522 */
1523 update_slave = slave;
1524 else if (qid && qid == slave->queue_id) {
1525 goto err_no_cmd_unlock;
1526 }
1527 }
1528
1529 if (!update_slave)
1530 goto err_no_cmd_unlock;
1531
1532 /* Actually set the qids for the slave */
1533 update_slave->queue_id = qid;
1534
1535 read_unlock(&bond->lock);
1536out:
1537 rtnl_unlock();
1538 return ret;
1539
1540err_no_cmd_unlock:
1541 read_unlock(&bond->lock);
1542err_no_cmd:
1543 pr_info("invalid input for queue_id set for %s.\n",
1544 bond->dev->name);
1545 ret = -EPERM;
1546 goto out;
1547}
1548
1549static DEVICE_ATTR(queue_id, S_IRUGO | S_IWUSR, bonding_show_queue_id,
1550 bonding_store_queue_id);
1551
1552
1553/*
Andy Gospodarekebd8e492010-06-02 08:39:21 +00001554 * Show and set the all_slaves_active flag.
1555 */
1556static ssize_t bonding_show_slaves_active(struct device *d,
1557 struct device_attribute *attr,
1558 char *buf)
1559{
1560 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001561
Andy Gospodarekebd8e492010-06-02 08:39:21 +00001562 return sprintf(buf, "%d\n", bond->params.all_slaves_active);
1563}
1564
1565static ssize_t bonding_store_slaves_active(struct device *d,
1566 struct device_attribute *attr,
1567 const char *buf, size_t count)
1568{
1569 int i, new_value, ret = count;
1570 struct bonding *bond = to_bond(d);
1571 struct slave *slave;
1572
1573 if (sscanf(buf, "%d", &new_value) != 1) {
1574 pr_err("%s: no all_slaves_active value specified.\n",
1575 bond->dev->name);
1576 ret = -EINVAL;
1577 goto out;
1578 }
1579
1580 if (new_value == bond->params.all_slaves_active)
1581 goto out;
1582
1583 if ((new_value == 0) || (new_value == 1)) {
1584 bond->params.all_slaves_active = new_value;
1585 } else {
1586 pr_info("%s: Ignoring invalid all_slaves_active value %d.\n",
1587 bond->dev->name, new_value);
1588 ret = -EINVAL;
1589 goto out;
1590 }
1591
1592 bond_for_each_slave(bond, slave, i) {
1593 if (slave->state == BOND_STATE_BACKUP) {
1594 if (new_value)
1595 slave->dev->priv_flags &= ~IFF_SLAVE_INACTIVE;
1596 else
1597 slave->dev->priv_flags |= IFF_SLAVE_INACTIVE;
1598 }
1599 }
1600out:
Jiri Pirko672bda32011-01-25 11:03:25 +00001601 return ret;
Andy Gospodarekebd8e492010-06-02 08:39:21 +00001602}
1603static DEVICE_ATTR(all_slaves_active, S_IRUGO | S_IWUSR,
1604 bonding_show_slaves_active, bonding_store_slaves_active);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001605
Flavio Leitnerc2952c32010-10-05 14:23:59 +00001606/*
1607 * Show and set the number of IGMP membership reports to send on link failure
1608 */
1609static ssize_t bonding_show_resend_igmp(struct device *d,
1610 struct device_attribute *attr,
1611 char *buf)
1612{
1613 struct bonding *bond = to_bond(d);
1614
1615 return sprintf(buf, "%d\n", bond->params.resend_igmp);
1616}
1617
1618static ssize_t bonding_store_resend_igmp(struct device *d,
1619 struct device_attribute *attr,
1620 const char *buf, size_t count)
1621{
1622 int new_value, ret = count;
1623 struct bonding *bond = to_bond(d);
1624
1625 if (sscanf(buf, "%d", &new_value) != 1) {
1626 pr_err("%s: no resend_igmp value specified.\n",
1627 bond->dev->name);
1628 ret = -EINVAL;
1629 goto out;
1630 }
1631
1632 if (new_value < 0) {
1633 pr_err("%s: Invalid resend_igmp value %d not in range 0-255; rejected.\n",
1634 bond->dev->name, new_value);
1635 ret = -EINVAL;
1636 goto out;
1637 }
1638
1639 pr_info("%s: Setting resend_igmp to %d.\n",
1640 bond->dev->name, new_value);
1641 bond->params.resend_igmp = new_value;
1642out:
1643 return ret;
1644}
1645
1646static DEVICE_ATTR(resend_igmp, S_IRUGO | S_IWUSR,
1647 bonding_show_resend_igmp, bonding_store_resend_igmp);
1648
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001649static struct attribute *per_bond_attrs[] = {
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001650 &dev_attr_slaves.attr,
1651 &dev_attr_mode.attr,
Jay Vosburghdd957c52007-10-09 19:57:24 -07001652 &dev_attr_fail_over_mac.attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001653 &dev_attr_arp_validate.attr,
1654 &dev_attr_arp_interval.attr,
1655 &dev_attr_arp_ip_target.attr,
1656 &dev_attr_downdelay.attr,
1657 &dev_attr_updelay.attr,
1658 &dev_attr_lacp_rate.attr,
Jay Vosburghfd989c82008-11-04 17:51:16 -08001659 &dev_attr_ad_select.attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001660 &dev_attr_xmit_hash_policy.attr,
Moni Shoua7893b242008-05-17 21:10:12 -07001661 &dev_attr_num_grat_arp.attr,
Brian Haley305d5522008-11-04 17:51:14 -08001662 &dev_attr_num_unsol_na.attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001663 &dev_attr_miimon.attr,
1664 &dev_attr_primary.attr,
Jiri Pirkoa5499522009-09-25 03:28:09 +00001665 &dev_attr_primary_reselect.attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001666 &dev_attr_use_carrier.attr,
1667 &dev_attr_active_slave.attr,
1668 &dev_attr_mii_status.attr,
1669 &dev_attr_ad_aggregator.attr,
1670 &dev_attr_ad_num_ports.attr,
1671 &dev_attr_ad_actor_key.attr,
1672 &dev_attr_ad_partner_key.attr,
1673 &dev_attr_ad_partner_mac.attr,
Andy Gospodarekbb1d9122010-06-02 08:40:18 +00001674 &dev_attr_queue_id.attr,
Andy Gospodarekebd8e492010-06-02 08:39:21 +00001675 &dev_attr_all_slaves_active.attr,
Flavio Leitnerc2952c32010-10-05 14:23:59 +00001676 &dev_attr_resend_igmp.attr,
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001677 NULL,
1678};
1679
1680static struct attribute_group bonding_group = {
1681 .name = "bonding",
1682 .attrs = per_bond_attrs,
1683};
1684
1685/*
1686 * Initialize sysfs. This sets up the bonding_masters file in
1687 * /sys/class/net.
1688 */
1689int bond_create_sysfs(void)
1690{
Jay Vosburghb8a97872008-06-13 18:12:04 -07001691 int ret;
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001692
Jay Vosburghb8a97872008-06-13 18:12:04 -07001693 ret = netdev_class_create_file(&class_attr_bonding_masters);
Jay Vosburgh877cbd32007-01-19 18:15:47 -08001694 /*
1695 * Permit multiple loads of the module by ignoring failures to
1696 * create the bonding_masters sysfs file. Bonding devices
1697 * created by second or subsequent loads of the module will
1698 * not be listed in, or controllable by, bonding_masters, but
1699 * will have the usual "bonding" sysfs directory.
1700 *
1701 * This is done to preserve backwards compatibility for
1702 * initscripts/sysconfig, which load bonding multiple times to
1703 * configure multiple bonding devices.
1704 */
1705 if (ret == -EEXIST) {
Stephen Hemminger38d2f382008-05-14 22:35:04 -07001706 /* Is someone being kinky and naming a device bonding_master? */
1707 if (__dev_get_by_name(&init_net,
1708 class_attr_bonding_masters.attr.name))
Joe Perchesa4aee5c2009-12-13 20:06:07 -08001709 pr_err("network device named %s already exists in sysfs",
Stephen Hemminger38d2f382008-05-14 22:35:04 -07001710 class_attr_bonding_masters.attr.name);
Stephen Hemminger130aa612009-06-11 05:46:04 -07001711 ret = 0;
Jay Vosburgh877cbd32007-01-19 18:15:47 -08001712 }
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001713
1714 return ret;
1715
1716}
1717
1718/*
1719 * Remove /sys/class/net/bonding_masters.
1720 */
1721void bond_destroy_sysfs(void)
1722{
Jay Vosburghb8a97872008-06-13 18:12:04 -07001723 netdev_class_remove_file(&class_attr_bonding_masters);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001724}
1725
1726/*
1727 * Initialize sysfs for each bond. This sets up and registers
1728 * the 'bondctl' directory for each individual bond under /sys/class/net.
1729 */
Eric W. Biederman6151b3d2009-10-29 14:18:22 +00001730void bond_prepare_sysfs_group(struct bonding *bond)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001731{
Eric W. Biederman6151b3d2009-10-29 14:18:22 +00001732 bond->dev->sysfs_groups[0] = &bonding_group;
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001733}
1734