blob: 4059bfc73dbf531d3e7c7df946c6615b611c51a5 [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 }
Andy Gospodarekc5cb0022010-07-28 15:13:56 +0000328
329 bond->params.mode = new_value;
330 bond_set_mode_ops(bond, bond->params.mode);
331 pr_info("%s: setting mode to %s (%d).\n",
332 bond->dev->name, bond_mode_tbl[new_value].modename,
333 new_value);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800334out:
335 return ret;
336}
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000337static DEVICE_ATTR(mode, S_IRUGO | S_IWUSR,
338 bonding_show_mode, bonding_store_mode);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800339
340/*
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000341 * Show and set the bonding transmit hash method.
342 * The bond interface must be down to change the xmit hash policy.
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800343 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700344static ssize_t bonding_show_xmit_hash(struct device *d,
345 struct device_attribute *attr,
346 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800347{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700348 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800349
Wagner Ferenc8e4b9322007-12-06 23:40:32 -0800350 return sprintf(buf, "%s %d\n",
351 xmit_hashtype_tbl[bond->params.xmit_policy].modename,
352 bond->params.xmit_policy);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800353}
354
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700355static ssize_t bonding_store_xmit_hash(struct device *d,
356 struct device_attribute *attr,
357 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800358{
359 int new_value, ret = count;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700360 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800361
362 if (bond->dev->flags & IFF_UP) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800363 pr_err("%s: Interface is up. Unable to update xmit policy.\n",
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800364 bond->dev->name);
365 ret = -EPERM;
366 goto out;
367 }
368
Jay Vosburghece95f72008-01-17 16:25:01 -0800369 new_value = bond_parse_parm(buf, xmit_hashtype_tbl);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800370 if (new_value < 0) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800371 pr_err("%s: Ignoring invalid xmit hash policy value %.*s.\n",
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800372 bond->dev->name,
373 (int)strlen(buf) - 1, buf);
374 ret = -EINVAL;
375 goto out;
376 } else {
377 bond->params.xmit_policy = new_value;
378 bond_set_mode_ops(bond, bond->params.mode);
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800379 pr_info("%s: setting xmit hash policy to %s (%d).\n",
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000380 bond->dev->name,
381 xmit_hashtype_tbl[new_value].modename, new_value);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800382 }
383out:
384 return ret;
385}
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000386static DEVICE_ATTR(xmit_hash_policy, S_IRUGO | S_IWUSR,
387 bonding_show_xmit_hash, bonding_store_xmit_hash);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800388
389/*
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700390 * Show and set arp_validate.
391 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700392static ssize_t bonding_show_arp_validate(struct device *d,
393 struct device_attribute *attr,
394 char *buf)
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700395{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700396 struct bonding *bond = to_bond(d);
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700397
398 return sprintf(buf, "%s %d\n",
399 arp_validate_tbl[bond->params.arp_validate].modename,
Wagner Ferenc7bd46502007-12-06 23:40:28 -0800400 bond->params.arp_validate);
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700401}
402
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700403static ssize_t bonding_store_arp_validate(struct device *d,
404 struct device_attribute *attr,
405 const char *buf, size_t count)
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700406{
407 int new_value;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700408 struct bonding *bond = to_bond(d);
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700409
Jay Vosburghece95f72008-01-17 16:25:01 -0800410 new_value = bond_parse_parm(buf, arp_validate_tbl);
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700411 if (new_value < 0) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800412 pr_err("%s: Ignoring invalid arp_validate value %s\n",
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700413 bond->dev->name, buf);
414 return -EINVAL;
415 }
416 if (new_value && (bond->params.mode != BOND_MODE_ACTIVEBACKUP)) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800417 pr_err("%s: arp_validate only supported in active-backup mode.\n",
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700418 bond->dev->name);
419 return -EINVAL;
420 }
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800421 pr_info("%s: setting arp_validate to %s (%d).\n",
422 bond->dev->name, arp_validate_tbl[new_value].modename,
423 new_value);
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700424
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700425 bond->params.arp_validate = new_value;
426
427 return count;
428}
429
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000430static DEVICE_ATTR(arp_validate, S_IRUGO | S_IWUSR, bonding_show_arp_validate,
431 bonding_store_arp_validate);
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700432
433/*
Jay Vosburghdd957c52007-10-09 19:57:24 -0700434 * Show and store fail_over_mac. User only allowed to change the
435 * value when there are no slaves.
436 */
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000437static ssize_t bonding_show_fail_over_mac(struct device *d,
438 struct device_attribute *attr,
439 char *buf)
Jay Vosburghdd957c52007-10-09 19:57:24 -0700440{
441 struct bonding *bond = to_bond(d);
442
Jay Vosburgh3915c1e82008-05-17 21:10:14 -0700443 return sprintf(buf, "%s %d\n",
444 fail_over_mac_tbl[bond->params.fail_over_mac].modename,
445 bond->params.fail_over_mac);
Jay Vosburghdd957c52007-10-09 19:57:24 -0700446}
447
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000448static ssize_t bonding_store_fail_over_mac(struct device *d,
449 struct device_attribute *attr,
450 const char *buf, size_t count)
Jay Vosburghdd957c52007-10-09 19:57:24 -0700451{
452 int new_value;
Jay Vosburghdd957c52007-10-09 19:57:24 -0700453 struct bonding *bond = to_bond(d);
454
455 if (bond->slave_cnt != 0) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800456 pr_err("%s: Can't alter fail_over_mac with slaves in bond.\n",
Jay Vosburghdd957c52007-10-09 19:57:24 -0700457 bond->dev->name);
Jay Vosburgh3915c1e82008-05-17 21:10:14 -0700458 return -EPERM;
Jay Vosburghdd957c52007-10-09 19:57:24 -0700459 }
460
Jay Vosburgh3915c1e82008-05-17 21:10:14 -0700461 new_value = bond_parse_parm(buf, fail_over_mac_tbl);
462 if (new_value < 0) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800463 pr_err("%s: Ignoring invalid fail_over_mac value %s.\n",
Jay Vosburgh3915c1e82008-05-17 21:10:14 -0700464 bond->dev->name, buf);
465 return -EINVAL;
Jay Vosburghdd957c52007-10-09 19:57:24 -0700466 }
467
Jay Vosburgh3915c1e82008-05-17 21:10:14 -0700468 bond->params.fail_over_mac = new_value;
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800469 pr_info("%s: Setting fail_over_mac to %s (%d).\n",
470 bond->dev->name, fail_over_mac_tbl[new_value].modename,
471 new_value);
Jay Vosburgh3915c1e82008-05-17 21:10:14 -0700472
473 return count;
Jay Vosburghdd957c52007-10-09 19:57:24 -0700474}
475
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000476static DEVICE_ATTR(fail_over_mac, S_IRUGO | S_IWUSR,
477 bonding_show_fail_over_mac, bonding_store_fail_over_mac);
Jay Vosburghdd957c52007-10-09 19:57:24 -0700478
479/*
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800480 * Show and set the arp timer interval. There are two tricky bits
481 * here. First, if ARP monitoring is activated, then we must disable
482 * MII monitoring. Second, if the ARP timer isn't running, we must
483 * start it.
484 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700485static ssize_t bonding_show_arp_interval(struct device *d,
486 struct device_attribute *attr,
487 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800488{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700489 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800490
Wagner Ferenc7bd46502007-12-06 23:40:28 -0800491 return sprintf(buf, "%d\n", bond->params.arp_interval);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800492}
493
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700494static ssize_t bonding_store_arp_interval(struct device *d,
495 struct device_attribute *attr,
496 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800497{
498 int new_value, ret = count;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700499 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800500
501 if (sscanf(buf, "%d", &new_value) != 1) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800502 pr_err("%s: no arp_interval value specified.\n",
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800503 bond->dev->name);
504 ret = -EINVAL;
505 goto out;
506 }
507 if (new_value < 0) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800508 pr_err("%s: Invalid arp_interval value %d not in range 1-%d; rejected.\n",
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800509 bond->dev->name, new_value, INT_MAX);
510 ret = -EINVAL;
511 goto out;
512 }
Andy Gospodarekc5cb0022010-07-28 15:13:56 +0000513 if (bond->params.mode == BOND_MODE_ALB ||
514 bond->params.mode == BOND_MODE_TLB) {
515 pr_info("%s: ARP monitoring cannot be used with ALB/TLB. Only MII monitoring is supported on %s.\n",
516 bond->dev->name, bond->dev->name);
517 ret = -EINVAL;
518 goto out;
519 }
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800520 pr_info("%s: Setting ARP monitoring interval to %d.\n",
521 bond->dev->name, new_value);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800522 bond->params.arp_interval = new_value;
523 if (bond->params.miimon) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800524 pr_info("%s: ARP monitoring cannot be used with MII monitoring. %s Disabling MII monitoring.\n",
525 bond->dev->name, bond->dev->name);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800526 bond->params.miimon = 0;
Jay Vosburgh1b76b312007-10-17 17:37:45 -0700527 if (delayed_work_pending(&bond->mii_work)) {
528 cancel_delayed_work(&bond->mii_work);
529 flush_workqueue(bond->wq);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800530 }
531 }
532 if (!bond->params.arp_targets[0]) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800533 pr_info("%s: ARP monitoring has been set up, but no ARP targets have been specified.\n",
534 bond->dev->name);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800535 }
536 if (bond->dev->flags & IFF_UP) {
537 /* If the interface is up, we may need to fire off
538 * the ARP timer. If the interface is down, the
539 * timer will get fired off when the open function
540 * is called.
541 */
Jay Vosburgh1b76b312007-10-17 17:37:45 -0700542 if (!delayed_work_pending(&bond->arp_work)) {
543 if (bond->params.mode == BOND_MODE_ACTIVEBACKUP)
544 INIT_DELAYED_WORK(&bond->arp_work,
545 bond_activebackup_arp_mon);
546 else
547 INIT_DELAYED_WORK(&bond->arp_work,
548 bond_loadbalance_arp_mon);
549
550 queue_delayed_work(bond->wq, &bond->arp_work, 0);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800551 }
552 }
553
554out:
555 return ret;
556}
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000557static DEVICE_ATTR(arp_interval, S_IRUGO | S_IWUSR,
558 bonding_show_arp_interval, bonding_store_arp_interval);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800559
560/*
561 * Show and set the arp targets.
562 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700563static ssize_t bonding_show_arp_targets(struct device *d,
564 struct device_attribute *attr,
565 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800566{
567 int i, res = 0;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700568 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800569
570 for (i = 0; i < BOND_MAX_ARP_TARGETS; i++) {
571 if (bond->params.arp_targets[i])
Harvey Harrison63779432008-10-31 00:56:00 -0700572 res += sprintf(buf + res, "%pI4 ",
573 &bond->params.arp_targets[i]);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800574 }
Wagner Ferenc1dcdcd62007-12-06 23:40:31 -0800575 if (res)
576 buf[res-1] = '\n'; /* eat the leftover space */
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800577 return res;
578}
579
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700580static ssize_t bonding_store_arp_targets(struct device *d,
581 struct device_attribute *attr,
582 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800583{
Al Virod3bb52b2007-08-22 20:06:58 -0400584 __be32 newtarget;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800585 int i = 0, done = 0, ret = count;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700586 struct bonding *bond = to_bond(d);
Al Virod3bb52b2007-08-22 20:06:58 -0400587 __be32 *targets;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800588
589 targets = bond->params.arp_targets;
590 newtarget = in_aton(buf + 1);
591 /* look for adds */
592 if (buf[0] == '+') {
Al Virod3bb52b2007-08-22 20:06:58 -0400593 if ((newtarget == 0) || (newtarget == htonl(INADDR_BROADCAST))) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800594 pr_err("%s: invalid ARP target %pI4 specified for addition\n",
Harvey Harrison63779432008-10-31 00:56:00 -0700595 bond->dev->name, &newtarget);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800596 ret = -EINVAL;
597 goto out;
598 }
599 /* look for an empty slot to put the target in, and check for dupes */
Brian Haley5a31bec2009-04-13 00:11:30 -0700600 for (i = 0; (i < BOND_MAX_ARP_TARGETS) && !done; i++) {
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800601 if (targets[i] == newtarget) { /* duplicate */
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800602 pr_err("%s: ARP target %pI4 is already present\n",
Harvey Harrison63779432008-10-31 00:56:00 -0700603 bond->dev->name, &newtarget);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800604 ret = -EINVAL;
605 goto out;
606 }
Brian Haley5a31bec2009-04-13 00:11:30 -0700607 if (targets[i] == 0) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800608 pr_info("%s: adding ARP target %pI4.\n",
609 bond->dev->name, &newtarget);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800610 done = 1;
611 targets[i] = newtarget;
612 }
613 }
614 if (!done) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800615 pr_err("%s: ARP target table is full!\n",
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800616 bond->dev->name);
617 ret = -EINVAL;
618 goto out;
619 }
620
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000621 } else if (buf[0] == '-') {
Al Virod3bb52b2007-08-22 20:06:58 -0400622 if ((newtarget == 0) || (newtarget == htonl(INADDR_BROADCAST))) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800623 pr_err("%s: invalid ARP target %pI4 specified for removal\n",
Harvey Harrison63779432008-10-31 00:56:00 -0700624 bond->dev->name, &newtarget);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800625 ret = -EINVAL;
626 goto out;
627 }
628
Brian Haley5a31bec2009-04-13 00:11:30 -0700629 for (i = 0; (i < BOND_MAX_ARP_TARGETS) && !done; i++) {
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800630 if (targets[i] == newtarget) {
Brian Haley5a31bec2009-04-13 00:11:30 -0700631 int j;
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800632 pr_info("%s: removing ARP target %pI4.\n",
633 bond->dev->name, &newtarget);
Brian Haley5a31bec2009-04-13 00:11:30 -0700634 for (j = i; (j < (BOND_MAX_ARP_TARGETS-1)) && targets[j+1]; j++)
635 targets[j] = targets[j+1];
636
637 targets[j] = 0;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800638 done = 1;
639 }
640 }
641 if (!done) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800642 pr_info("%s: unable to remove nonexistent ARP target %pI4.\n",
643 bond->dev->name, &newtarget);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800644 ret = -EINVAL;
645 goto out;
646 }
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000647 } else {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800648 pr_err("no command found in arp_ip_targets file for bond %s. Use +<addr> or -<addr>.\n",
649 bond->dev->name);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800650 ret = -EPERM;
651 goto out;
652 }
653
654out:
655 return ret;
656}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700657static DEVICE_ATTR(arp_ip_target, S_IRUGO | S_IWUSR , bonding_show_arp_targets, bonding_store_arp_targets);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800658
659/*
660 * Show and set the up and down delays. These must be multiples of the
661 * MII monitoring value, and are stored internally as the multiplier.
662 * Thus, we must translate to MS for the real world.
663 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700664static ssize_t bonding_show_downdelay(struct device *d,
665 struct device_attribute *attr,
666 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800667{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700668 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800669
Wagner Ferenc7bd46502007-12-06 23:40:28 -0800670 return sprintf(buf, "%d\n", bond->params.downdelay * bond->params.miimon);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800671}
672
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700673static ssize_t bonding_store_downdelay(struct device *d,
674 struct device_attribute *attr,
675 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800676{
677 int new_value, ret = count;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700678 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800679
680 if (!(bond->params.miimon)) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800681 pr_err("%s: Unable to set down delay as MII monitoring is disabled\n",
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800682 bond->dev->name);
683 ret = -EPERM;
684 goto out;
685 }
686
687 if (sscanf(buf, "%d", &new_value) != 1) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800688 pr_err("%s: no down delay value specified.\n", bond->dev->name);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800689 ret = -EINVAL;
690 goto out;
691 }
692 if (new_value < 0) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800693 pr_err("%s: Invalid down delay value %d not in range %d-%d; rejected.\n",
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800694 bond->dev->name, new_value, 1, INT_MAX);
695 ret = -EINVAL;
696 goto out;
697 } else {
698 if ((new_value % bond->params.miimon) != 0) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800699 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 +0000700 bond->dev->name, new_value,
701 bond->params.miimon,
702 (new_value / bond->params.miimon) *
703 bond->params.miimon);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800704 }
705 bond->params.downdelay = new_value / bond->params.miimon;
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800706 pr_info("%s: Setting down delay to %d.\n",
707 bond->dev->name,
708 bond->params.downdelay * bond->params.miimon);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800709
710 }
711
712out:
713 return ret;
714}
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000715static DEVICE_ATTR(downdelay, S_IRUGO | S_IWUSR,
716 bonding_show_downdelay, bonding_store_downdelay);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800717
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700718static ssize_t bonding_show_updelay(struct device *d,
719 struct device_attribute *attr,
720 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800721{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700722 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800723
Wagner Ferenc7bd46502007-12-06 23:40:28 -0800724 return sprintf(buf, "%d\n", bond->params.updelay * bond->params.miimon);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800725
726}
727
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700728static ssize_t bonding_store_updelay(struct device *d,
729 struct device_attribute *attr,
730 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800731{
732 int new_value, ret = count;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700733 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800734
735 if (!(bond->params.miimon)) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800736 pr_err("%s: Unable to set up delay as MII monitoring is disabled\n",
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800737 bond->dev->name);
738 ret = -EPERM;
739 goto out;
740 }
741
742 if (sscanf(buf, "%d", &new_value) != 1) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800743 pr_err("%s: no up delay value specified.\n",
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800744 bond->dev->name);
745 ret = -EINVAL;
746 goto out;
747 }
748 if (new_value < 0) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800749 pr_err("%s: Invalid down delay value %d not in range %d-%d; rejected.\n",
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800750 bond->dev->name, new_value, 1, INT_MAX);
751 ret = -EINVAL;
752 goto out;
753 } else {
754 if ((new_value % bond->params.miimon) != 0) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800755 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 +0000756 bond->dev->name, new_value,
757 bond->params.miimon,
758 (new_value / bond->params.miimon) *
759 bond->params.miimon);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800760 }
761 bond->params.updelay = new_value / bond->params.miimon;
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800762 pr_info("%s: Setting up delay to %d.\n",
763 bond->dev->name,
764 bond->params.updelay * bond->params.miimon);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800765 }
766
767out:
768 return ret;
769}
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000770static DEVICE_ATTR(updelay, S_IRUGO | S_IWUSR,
771 bonding_show_updelay, bonding_store_updelay);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800772
773/*
774 * Show and set the LACP interval. Interface must be down, and the mode
775 * must be set to 802.3ad mode.
776 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700777static ssize_t bonding_show_lacp(struct device *d,
778 struct device_attribute *attr,
779 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800780{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700781 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800782
783 return sprintf(buf, "%s %d\n",
784 bond_lacp_tbl[bond->params.lacp_fast].modename,
Wagner Ferenc7bd46502007-12-06 23:40:28 -0800785 bond->params.lacp_fast);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800786}
787
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700788static ssize_t bonding_store_lacp(struct device *d,
789 struct device_attribute *attr,
790 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800791{
792 int new_value, ret = count;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700793 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800794
795 if (bond->dev->flags & IFF_UP) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800796 pr_err("%s: Unable to update LACP rate because interface is up.\n",
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800797 bond->dev->name);
798 ret = -EPERM;
799 goto out;
800 }
801
802 if (bond->params.mode != BOND_MODE_8023AD) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800803 pr_err("%s: Unable to update LACP rate because bond is not in 802.3ad mode.\n",
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800804 bond->dev->name);
805 ret = -EPERM;
806 goto out;
807 }
808
Jay Vosburghece95f72008-01-17 16:25:01 -0800809 new_value = bond_parse_parm(buf, bond_lacp_tbl);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800810
811 if ((new_value == 1) || (new_value == 0)) {
812 bond->params.lacp_fast = new_value;
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800813 pr_info("%s: Setting LACP rate to %s (%d).\n",
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000814 bond->dev->name, bond_lacp_tbl[new_value].modename,
815 new_value);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800816 } else {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800817 pr_err("%s: Ignoring invalid LACP rate value %.*s.\n",
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000818 bond->dev->name, (int)strlen(buf) - 1, buf);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800819 ret = -EINVAL;
820 }
821out:
822 return ret;
823}
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000824static DEVICE_ATTR(lacp_rate, S_IRUGO | S_IWUSR,
825 bonding_show_lacp, bonding_store_lacp);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800826
Jay Vosburghfd989c82008-11-04 17:51:16 -0800827static ssize_t bonding_show_ad_select(struct device *d,
828 struct device_attribute *attr,
829 char *buf)
830{
831 struct bonding *bond = to_bond(d);
832
833 return sprintf(buf, "%s %d\n",
834 ad_select_tbl[bond->params.ad_select].modename,
835 bond->params.ad_select);
836}
837
838
839static ssize_t bonding_store_ad_select(struct device *d,
840 struct device_attribute *attr,
841 const char *buf, size_t count)
842{
843 int new_value, ret = count;
844 struct bonding *bond = to_bond(d);
845
846 if (bond->dev->flags & IFF_UP) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800847 pr_err("%s: Unable to update ad_select because interface is up.\n",
848 bond->dev->name);
Jay Vosburghfd989c82008-11-04 17:51:16 -0800849 ret = -EPERM;
850 goto out;
851 }
852
853 new_value = bond_parse_parm(buf, ad_select_tbl);
854
855 if (new_value != -1) {
856 bond->params.ad_select = new_value;
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800857 pr_info("%s: Setting ad_select to %s (%d).\n",
858 bond->dev->name, ad_select_tbl[new_value].modename,
859 new_value);
Jay Vosburghfd989c82008-11-04 17:51:16 -0800860 } else {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800861 pr_err("%s: Ignoring invalid ad_select value %.*s.\n",
Jay Vosburghfd989c82008-11-04 17:51:16 -0800862 bond->dev->name, (int)strlen(buf) - 1, buf);
863 ret = -EINVAL;
864 }
865out:
866 return ret;
867}
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000868static DEVICE_ATTR(ad_select, S_IRUGO | S_IWUSR,
869 bonding_show_ad_select, bonding_store_ad_select);
Jay Vosburghfd989c82008-11-04 17:51:16 -0800870
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800871/*
Ben Hutchingsad246c92011-04-26 15:25:52 +0000872 * Show and set the number of peer notifications to send after a failover event.
873 */
874static ssize_t bonding_show_num_peer_notif(struct device *d,
875 struct device_attribute *attr,
876 char *buf)
877{
878 struct bonding *bond = to_bond(d);
879 return sprintf(buf, "%d\n", bond->params.num_peer_notif);
880}
881
882static ssize_t bonding_store_num_peer_notif(struct device *d,
883 struct device_attribute *attr,
884 const char *buf, size_t count)
885{
886 struct bonding *bond = to_bond(d);
887 int err = kstrtou8(buf, 10, &bond->params.num_peer_notif);
888 return err ? err : count;
889}
890static DEVICE_ATTR(num_grat_arp, S_IRUGO | S_IWUSR,
891 bonding_show_num_peer_notif, bonding_store_num_peer_notif);
892static DEVICE_ATTR(num_unsol_na, S_IRUGO | S_IWUSR,
893 bonding_show_num_peer_notif, bonding_store_num_peer_notif);
894
895/*
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800896 * Show and set the MII monitor interval. There are two tricky bits
897 * here. First, if MII monitoring is activated, then we must disable
898 * ARP monitoring. Second, if the timer isn't running, we must
899 * start it.
900 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700901static ssize_t bonding_show_miimon(struct device *d,
902 struct device_attribute *attr,
903 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800904{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700905 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800906
Wagner Ferenc7bd46502007-12-06 23:40:28 -0800907 return sprintf(buf, "%d\n", bond->params.miimon);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800908}
909
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700910static ssize_t bonding_store_miimon(struct device *d,
911 struct device_attribute *attr,
912 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800913{
914 int new_value, ret = count;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700915 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800916
917 if (sscanf(buf, "%d", &new_value) != 1) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800918 pr_err("%s: no miimon value specified.\n",
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800919 bond->dev->name);
920 ret = -EINVAL;
921 goto out;
922 }
923 if (new_value < 0) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800924 pr_err("%s: Invalid miimon value %d not in range %d-%d; rejected.\n",
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800925 bond->dev->name, new_value, 1, INT_MAX);
926 ret = -EINVAL;
927 goto out;
928 } else {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800929 pr_info("%s: Setting MII monitoring interval to %d.\n",
930 bond->dev->name, new_value);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800931 bond->params.miimon = new_value;
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000932 if (bond->params.updelay)
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800933 pr_info("%s: Note: Updating updelay (to %d) since it is a multiple of the miimon value.\n",
934 bond->dev->name,
935 bond->params.updelay * bond->params.miimon);
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000936 if (bond->params.downdelay)
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800937 pr_info("%s: Note: Updating downdelay (to %d) since it is a multiple of the miimon value.\n",
938 bond->dev->name,
939 bond->params.downdelay * bond->params.miimon);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800940 if (bond->params.arp_interval) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800941 pr_info("%s: MII monitoring cannot be used with ARP monitoring. Disabling ARP monitoring...\n",
942 bond->dev->name);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800943 bond->params.arp_interval = 0;
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700944 if (bond->params.arp_validate) {
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700945 bond->params.arp_validate =
946 BOND_ARP_VALIDATE_NONE;
947 }
Jay Vosburgh1b76b312007-10-17 17:37:45 -0700948 if (delayed_work_pending(&bond->arp_work)) {
949 cancel_delayed_work(&bond->arp_work);
950 flush_workqueue(bond->wq);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800951 }
952 }
953
954 if (bond->dev->flags & IFF_UP) {
955 /* If the interface is up, we may need to fire off
956 * the MII timer. If the interface is down, the
957 * timer will get fired off when the open function
958 * is called.
959 */
Jay Vosburgh1b76b312007-10-17 17:37:45 -0700960 if (!delayed_work_pending(&bond->mii_work)) {
961 INIT_DELAYED_WORK(&bond->mii_work,
962 bond_mii_monitor);
963 queue_delayed_work(bond->wq,
964 &bond->mii_work, 0);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800965 }
966 }
967 }
968out:
969 return ret;
970}
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000971static DEVICE_ATTR(miimon, S_IRUGO | S_IWUSR,
972 bonding_show_miimon, bonding_store_miimon);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800973
974/*
975 * Show and set the primary slave. The store function is much
976 * simpler than bonding_store_slaves function because it only needs to
977 * handle one interface name.
978 * The bond must be a mode that supports a primary for this be
979 * set.
980 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700981static ssize_t bonding_show_primary(struct device *d,
982 struct device_attribute *attr,
983 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800984{
985 int count = 0;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700986 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800987
988 if (bond->primary_slave)
Wagner Ferenc7bd46502007-12-06 23:40:28 -0800989 count = sprintf(buf, "%s\n", bond->primary_slave->dev->name);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800990
991 return count;
992}
993
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700994static ssize_t bonding_store_primary(struct device *d,
995 struct device_attribute *attr,
996 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800997{
998 int i;
999 struct slave *slave;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001000 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001001
Eric W. Biederman496a60c2009-05-13 17:02:50 +00001002 if (!rtnl_trylock())
1003 return restart_syscall();
Neil Hormane843fa52010-10-13 16:01:50 +00001004 block_netpoll_tx();
Jay Vosburghe934dd72008-01-17 16:24:57 -08001005 read_lock(&bond->lock);
1006 write_lock_bh(&bond->curr_slave_lock);
1007
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001008 if (!USES_PRIMARY(bond->params.mode)) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -08001009 pr_info("%s: Unable to set primary slave; %s is in mode %d\n",
1010 bond->dev->name, bond->dev->name, bond->params.mode);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001011 } else {
1012 bond_for_each_slave(bond, slave, i) {
1013 if (strnicmp
1014 (slave->dev->name, buf,
1015 strlen(slave->dev->name)) == 0) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -08001016 pr_info("%s: Setting %s as primary slave.\n",
1017 bond->dev->name, slave->dev->name);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001018 bond->primary_slave = slave;
Jiri Pirkoce501ca2009-09-18 02:13:22 +00001019 strcpy(bond->params.primary, slave->dev->name);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001020 bond_select_active_slave(bond);
1021 goto out;
1022 }
1023 }
1024
1025 /* if we got here, then we didn't match the name of any slave */
1026
1027 if (strlen(buf) == 0 || buf[0] == '\n') {
Joe Perchesa4aee5c2009-12-13 20:06:07 -08001028 pr_info("%s: Setting primary slave to None.\n",
1029 bond->dev->name);
Luiz Fernando Capitulino3418db72006-02-01 00:54:34 -08001030 bond->primary_slave = NULL;
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001031 bond_select_active_slave(bond);
1032 } else {
Joe Perchesa4aee5c2009-12-13 20:06:07 -08001033 pr_info("%s: Unable to set %.*s as primary slave as it is not a slave.\n",
1034 bond->dev->name, (int)strlen(buf) - 1, buf);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001035 }
1036 }
1037out:
Jay Vosburghe934dd72008-01-17 16:24:57 -08001038 write_unlock_bh(&bond->curr_slave_lock);
1039 read_unlock(&bond->lock);
Neil Hormane843fa52010-10-13 16:01:50 +00001040 unblock_netpoll_tx();
Jay Vosburgh6603a6f2007-10-17 17:37:50 -07001041 rtnl_unlock();
1042
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001043 return count;
1044}
Stephen Hemminger3d632c32009-06-12 19:02:48 +00001045static DEVICE_ATTR(primary, S_IRUGO | S_IWUSR,
1046 bonding_show_primary, bonding_store_primary);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001047
1048/*
Jiri Pirkoa5499522009-09-25 03:28:09 +00001049 * Show and set the primary_reselect flag.
1050 */
1051static ssize_t bonding_show_primary_reselect(struct device *d,
1052 struct device_attribute *attr,
1053 char *buf)
1054{
1055 struct bonding *bond = to_bond(d);
1056
1057 return sprintf(buf, "%s %d\n",
1058 pri_reselect_tbl[bond->params.primary_reselect].modename,
1059 bond->params.primary_reselect);
1060}
1061
1062static ssize_t bonding_store_primary_reselect(struct device *d,
1063 struct device_attribute *attr,
1064 const char *buf, size_t count)
1065{
1066 int new_value, ret = count;
1067 struct bonding *bond = to_bond(d);
1068
1069 if (!rtnl_trylock())
1070 return restart_syscall();
1071
1072 new_value = bond_parse_parm(buf, pri_reselect_tbl);
1073 if (new_value < 0) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -08001074 pr_err("%s: Ignoring invalid primary_reselect value %.*s.\n",
Jiri Pirkoa5499522009-09-25 03:28:09 +00001075 bond->dev->name,
1076 (int) strlen(buf) - 1, buf);
1077 ret = -EINVAL;
1078 goto out;
1079 }
1080
1081 bond->params.primary_reselect = new_value;
Joe Perchesa4aee5c2009-12-13 20:06:07 -08001082 pr_info("%s: setting primary_reselect to %s (%d).\n",
Jiri Pirkoa5499522009-09-25 03:28:09 +00001083 bond->dev->name, pri_reselect_tbl[new_value].modename,
1084 new_value);
1085
Neil Hormane843fa52010-10-13 16:01:50 +00001086 block_netpoll_tx();
Jiri Pirkoa5499522009-09-25 03:28:09 +00001087 read_lock(&bond->lock);
1088 write_lock_bh(&bond->curr_slave_lock);
1089 bond_select_active_slave(bond);
1090 write_unlock_bh(&bond->curr_slave_lock);
1091 read_unlock(&bond->lock);
Neil Hormane843fa52010-10-13 16:01:50 +00001092 unblock_netpoll_tx();
Jiri Pirkoa5499522009-09-25 03:28:09 +00001093out:
1094 rtnl_unlock();
1095 return ret;
1096}
1097static DEVICE_ATTR(primary_reselect, S_IRUGO | S_IWUSR,
1098 bonding_show_primary_reselect,
1099 bonding_store_primary_reselect);
1100
1101/*
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001102 * Show and set the use_carrier flag.
1103 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001104static ssize_t bonding_show_carrier(struct device *d,
1105 struct device_attribute *attr,
1106 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001107{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001108 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001109
Wagner Ferenc7bd46502007-12-06 23:40:28 -08001110 return sprintf(buf, "%d\n", bond->params.use_carrier);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001111}
1112
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001113static ssize_t bonding_store_carrier(struct device *d,
1114 struct device_attribute *attr,
1115 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001116{
1117 int new_value, ret = count;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001118 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001119
1120
1121 if (sscanf(buf, "%d", &new_value) != 1) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -08001122 pr_err("%s: no use_carrier value specified.\n",
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001123 bond->dev->name);
1124 ret = -EINVAL;
1125 goto out;
1126 }
1127 if ((new_value == 0) || (new_value == 1)) {
1128 bond->params.use_carrier = new_value;
Joe Perchesa4aee5c2009-12-13 20:06:07 -08001129 pr_info("%s: Setting use_carrier to %d.\n",
1130 bond->dev->name, new_value);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001131 } else {
Joe Perchesa4aee5c2009-12-13 20:06:07 -08001132 pr_info("%s: Ignoring invalid use_carrier value %d.\n",
1133 bond->dev->name, new_value);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001134 }
1135out:
Jiri Pirko672bda32011-01-25 11:03:25 +00001136 return ret;
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001137}
Stephen Hemminger3d632c32009-06-12 19:02:48 +00001138static DEVICE_ATTR(use_carrier, S_IRUGO | S_IWUSR,
1139 bonding_show_carrier, bonding_store_carrier);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001140
1141
1142/*
1143 * Show and set currently active_slave.
1144 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001145static ssize_t bonding_show_active_slave(struct device *d,
1146 struct device_attribute *attr,
1147 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001148{
1149 struct slave *curr;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001150 struct bonding *bond = to_bond(d);
Wagner Ferenc16cd0162007-12-06 23:40:29 -08001151 int count = 0;
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001152
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001153 read_lock(&bond->curr_slave_lock);
1154 curr = bond->curr_active_slave;
1155 read_unlock(&bond->curr_slave_lock);
1156
1157 if (USES_PRIMARY(bond->params.mode) && curr)
Wagner Ferenc7bd46502007-12-06 23:40:28 -08001158 count = sprintf(buf, "%s\n", curr->dev->name);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001159 return count;
1160}
1161
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001162static ssize_t bonding_store_active_slave(struct device *d,
1163 struct device_attribute *attr,
1164 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001165{
1166 int i;
1167 struct slave *slave;
Stephen Hemminger3d632c32009-06-12 19:02:48 +00001168 struct slave *old_active = NULL;
1169 struct slave *new_active = NULL;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001170 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001171
Eric W. Biederman496a60c2009-05-13 17:02:50 +00001172 if (!rtnl_trylock())
1173 return restart_syscall();
Neil Hormane843fa52010-10-13 16:01:50 +00001174
1175 block_netpoll_tx();
Jay Vosburghe934dd72008-01-17 16:24:57 -08001176 read_lock(&bond->lock);
1177 write_lock_bh(&bond->curr_slave_lock);
Jay Vosburgh1466a212007-11-06 13:33:28 -08001178
Stephen Hemminger3d632c32009-06-12 19:02:48 +00001179 if (!USES_PRIMARY(bond->params.mode))
Joe Perchesa4aee5c2009-12-13 20:06:07 -08001180 pr_info("%s: Unable to change active slave; %s is in mode %d\n",
Stephen Hemminger3d632c32009-06-12 19:02:48 +00001181 bond->dev->name, bond->dev->name, bond->params.mode);
1182 else {
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001183 bond_for_each_slave(bond, slave, i) {
1184 if (strnicmp
1185 (slave->dev->name, buf,
1186 strlen(slave->dev->name)) == 0) {
1187 old_active = bond->curr_active_slave;
1188 new_active = slave;
Jay Vosburgha50d8de2006-09-22 21:53:25 -07001189 if (new_active == old_active) {
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001190 /* do nothing */
Joe Perchesa4aee5c2009-12-13 20:06:07 -08001191 pr_info("%s: %s is already the current active slave.\n",
1192 bond->dev->name,
1193 slave->dev->name);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001194 goto out;
1195 }
1196 else {
1197 if ((new_active) &&
1198 (old_active) &&
1199 (new_active->link == BOND_LINK_UP) &&
1200 IS_UP(new_active->dev)) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -08001201 pr_info("%s: Setting %s as active slave.\n",
1202 bond->dev->name,
1203 slave->dev->name);
Jiri Pirkoe5e2a8f2009-08-13 04:11:52 +00001204 bond_change_active_slave(bond, new_active);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001205 }
1206 else {
Joe Perchesa4aee5c2009-12-13 20:06:07 -08001207 pr_info("%s: Could not set %s as active slave; either %s is down or the link is down.\n",
1208 bond->dev->name,
1209 slave->dev->name,
Jiri Pirkoe5e2a8f2009-08-13 04:11:52 +00001210 slave->dev->name);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001211 }
1212 goto out;
1213 }
1214 }
1215 }
1216
1217 /* if we got here, then we didn't match the name of any slave */
1218
1219 if (strlen(buf) == 0 || buf[0] == '\n') {
Joe Perchesa4aee5c2009-12-13 20:06:07 -08001220 pr_info("%s: Setting active slave to None.\n",
Stephen Hemminger3d632c32009-06-12 19:02:48 +00001221 bond->dev->name);
Luiz Fernando Capitulino3418db72006-02-01 00:54:34 -08001222 bond->primary_slave = NULL;
Stephen Hemminger3d632c32009-06-12 19:02:48 +00001223 bond_select_active_slave(bond);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001224 } else {
Joe Perchesa4aee5c2009-12-13 20:06:07 -08001225 pr_info("%s: Unable to set %.*s as active slave as it is not a slave.\n",
Stephen Hemminger3d632c32009-06-12 19:02:48 +00001226 bond->dev->name, (int)strlen(buf) - 1, buf);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001227 }
1228 }
Stephen Hemminger3d632c32009-06-12 19:02:48 +00001229 out:
Jay Vosburghe934dd72008-01-17 16:24:57 -08001230 write_unlock_bh(&bond->curr_slave_lock);
1231 read_unlock(&bond->lock);
Neil Hormane843fa52010-10-13 16:01:50 +00001232 unblock_netpoll_tx();
1233
Jay Vosburgh6603a6f2007-10-17 17:37:50 -07001234 rtnl_unlock();
1235
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001236 return count;
1237
1238}
Stephen Hemminger3d632c32009-06-12 19:02:48 +00001239static DEVICE_ATTR(active_slave, S_IRUGO | S_IWUSR,
1240 bonding_show_active_slave, bonding_store_active_slave);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001241
1242
1243/*
1244 * Show link status of the bond interface.
1245 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001246static ssize_t bonding_show_mii_status(struct device *d,
1247 struct device_attribute *attr,
1248 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001249{
1250 struct slave *curr;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001251 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001252
1253 read_lock(&bond->curr_slave_lock);
1254 curr = bond->curr_active_slave;
1255 read_unlock(&bond->curr_slave_lock);
1256
Stephen Hemminger3d632c32009-06-12 19:02:48 +00001257 return sprintf(buf, "%s\n", curr ? "up" : "down");
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001258}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001259static DEVICE_ATTR(mii_status, S_IRUGO, bonding_show_mii_status, NULL);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001260
1261
1262/*
1263 * Show current 802.3ad aggregator ID.
1264 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001265static ssize_t bonding_show_ad_aggregator(struct device *d,
1266 struct device_attribute *attr,
1267 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001268{
1269 int count = 0;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001270 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001271
1272 if (bond->params.mode == BOND_MODE_8023AD) {
1273 struct ad_info ad_info;
Stephen Hemminger3d632c32009-06-12 19:02:48 +00001274 count = sprintf(buf, "%d\n",
1275 (bond_3ad_get_active_agg_info(bond, &ad_info))
1276 ? 0 : ad_info.aggregator_id);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001277 }
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001278
1279 return count;
1280}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001281static DEVICE_ATTR(ad_aggregator, S_IRUGO, bonding_show_ad_aggregator, NULL);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001282
1283
1284/*
1285 * Show number of active 802.3ad ports.
1286 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001287static ssize_t bonding_show_ad_num_ports(struct device *d,
1288 struct device_attribute *attr,
1289 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001290{
1291 int count = 0;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001292 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001293
1294 if (bond->params.mode == BOND_MODE_8023AD) {
1295 struct ad_info ad_info;
Stephen Hemminger3d632c32009-06-12 19:02:48 +00001296 count = sprintf(buf, "%d\n",
1297 (bond_3ad_get_active_agg_info(bond, &ad_info))
1298 ? 0 : ad_info.ports);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001299 }
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001300
1301 return count;
1302}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001303static DEVICE_ATTR(ad_num_ports, S_IRUGO, bonding_show_ad_num_ports, NULL);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001304
1305
1306/*
1307 * Show current 802.3ad actor key.
1308 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001309static ssize_t bonding_show_ad_actor_key(struct device *d,
1310 struct device_attribute *attr,
1311 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001312{
1313 int count = 0;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001314 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001315
1316 if (bond->params.mode == BOND_MODE_8023AD) {
1317 struct ad_info ad_info;
Stephen Hemminger3d632c32009-06-12 19:02:48 +00001318 count = sprintf(buf, "%d\n",
1319 (bond_3ad_get_active_agg_info(bond, &ad_info))
1320 ? 0 : ad_info.actor_key);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001321 }
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001322
1323 return count;
1324}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001325static DEVICE_ATTR(ad_actor_key, S_IRUGO, bonding_show_ad_actor_key, NULL);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001326
1327
1328/*
1329 * Show current 802.3ad partner key.
1330 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001331static ssize_t bonding_show_ad_partner_key(struct device *d,
1332 struct device_attribute *attr,
1333 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001334{
1335 int count = 0;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001336 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001337
1338 if (bond->params.mode == BOND_MODE_8023AD) {
1339 struct ad_info ad_info;
Stephen Hemminger3d632c32009-06-12 19:02:48 +00001340 count = sprintf(buf, "%d\n",
1341 (bond_3ad_get_active_agg_info(bond, &ad_info))
1342 ? 0 : ad_info.partner_key);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001343 }
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001344
1345 return count;
1346}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001347static DEVICE_ATTR(ad_partner_key, S_IRUGO, bonding_show_ad_partner_key, NULL);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001348
1349
1350/*
1351 * Show current 802.3ad partner mac.
1352 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001353static ssize_t bonding_show_ad_partner_mac(struct device *d,
1354 struct device_attribute *attr,
1355 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001356{
1357 int count = 0;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001358 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001359
1360 if (bond->params.mode == BOND_MODE_8023AD) {
1361 struct ad_info ad_info;
Stephen Hemminger3d632c32009-06-12 19:02:48 +00001362 if (!bond_3ad_get_active_agg_info(bond, &ad_info))
Johannes Berge1749612008-10-27 15:59:26 -07001363 count = sprintf(buf, "%pM\n", ad_info.partner_system);
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_partner_mac, S_IRUGO, bonding_show_ad_partner_mac, NULL);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001369
Andy Gospodarekebd8e492010-06-02 08:39:21 +00001370/*
Andy Gospodarekbb1d9122010-06-02 08:40:18 +00001371 * Show the queue_ids of the slaves in the current bond.
1372 */
1373static ssize_t bonding_show_queue_id(struct device *d,
1374 struct device_attribute *attr,
1375 char *buf)
1376{
1377 struct slave *slave;
1378 int i, res = 0;
1379 struct bonding *bond = to_bond(d);
1380
1381 if (!rtnl_trylock())
1382 return restart_syscall();
1383
1384 read_lock(&bond->lock);
1385 bond_for_each_slave(bond, slave, i) {
Nicolas de Pesloüan79236682010-07-14 18:24:54 -07001386 if (res > (PAGE_SIZE - IFNAMSIZ - 6)) {
1387 /* not enough space for another interface_name:queue_id pair */
Andy Gospodarekbb1d9122010-06-02 08:40:18 +00001388 if ((PAGE_SIZE - res) > 10)
1389 res = PAGE_SIZE - 10;
1390 res += sprintf(buf + res, "++more++ ");
1391 break;
1392 }
1393 res += sprintf(buf + res, "%s:%d ",
1394 slave->dev->name, slave->queue_id);
1395 }
1396 read_unlock(&bond->lock);
1397 if (res)
1398 buf[res-1] = '\n'; /* eat the leftover space */
1399 rtnl_unlock();
1400 return res;
1401}
1402
1403/*
1404 * Set the queue_ids of the slaves in the current bond. The bond
1405 * interface must be enslaved for this to work.
1406 */
1407static ssize_t bonding_store_queue_id(struct device *d,
1408 struct device_attribute *attr,
1409 const char *buffer, size_t count)
1410{
1411 struct slave *slave, *update_slave;
1412 struct bonding *bond = to_bond(d);
1413 u16 qid;
1414 int i, ret = count;
1415 char *delim;
1416 struct net_device *sdev = NULL;
1417
1418 if (!rtnl_trylock())
1419 return restart_syscall();
1420
1421 /* delim will point to queue id if successful */
1422 delim = strchr(buffer, ':');
1423 if (!delim)
1424 goto err_no_cmd;
1425
1426 /*
1427 * Terminate string that points to device name and bump it
1428 * up one, so we can read the queue id there.
1429 */
1430 *delim = '\0';
1431 if (sscanf(++delim, "%hd\n", &qid) != 1)
1432 goto err_no_cmd;
1433
1434 /* Check buffer length, valid ifname and queue id */
1435 if (strlen(buffer) > IFNAMSIZ ||
1436 !dev_valid_name(buffer) ||
1437 qid > bond->params.tx_queues)
1438 goto err_no_cmd;
1439
1440 /* Get the pointer to that interface if it exists */
1441 sdev = __dev_get_by_name(dev_net(bond->dev), buffer);
1442 if (!sdev)
1443 goto err_no_cmd;
1444
1445 read_lock(&bond->lock);
1446
1447 /* Search for thes slave and check for duplicate qids */
1448 update_slave = NULL;
1449 bond_for_each_slave(bond, slave, i) {
1450 if (sdev == slave->dev)
1451 /*
1452 * We don't need to check the matching
1453 * slave for dups, since we're overwriting it
1454 */
1455 update_slave = slave;
1456 else if (qid && qid == slave->queue_id) {
1457 goto err_no_cmd_unlock;
1458 }
1459 }
1460
1461 if (!update_slave)
1462 goto err_no_cmd_unlock;
1463
1464 /* Actually set the qids for the slave */
1465 update_slave->queue_id = qid;
1466
1467 read_unlock(&bond->lock);
1468out:
1469 rtnl_unlock();
1470 return ret;
1471
1472err_no_cmd_unlock:
1473 read_unlock(&bond->lock);
1474err_no_cmd:
1475 pr_info("invalid input for queue_id set for %s.\n",
1476 bond->dev->name);
1477 ret = -EPERM;
1478 goto out;
1479}
1480
1481static DEVICE_ATTR(queue_id, S_IRUGO | S_IWUSR, bonding_show_queue_id,
1482 bonding_store_queue_id);
1483
1484
1485/*
Andy Gospodarekebd8e492010-06-02 08:39:21 +00001486 * Show and set the all_slaves_active flag.
1487 */
1488static ssize_t bonding_show_slaves_active(struct device *d,
1489 struct device_attribute *attr,
1490 char *buf)
1491{
1492 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001493
Andy Gospodarekebd8e492010-06-02 08:39:21 +00001494 return sprintf(buf, "%d\n", bond->params.all_slaves_active);
1495}
1496
1497static ssize_t bonding_store_slaves_active(struct device *d,
1498 struct device_attribute *attr,
1499 const char *buf, size_t count)
1500{
1501 int i, new_value, ret = count;
1502 struct bonding *bond = to_bond(d);
1503 struct slave *slave;
1504
1505 if (sscanf(buf, "%d", &new_value) != 1) {
1506 pr_err("%s: no all_slaves_active value specified.\n",
1507 bond->dev->name);
1508 ret = -EINVAL;
1509 goto out;
1510 }
1511
1512 if (new_value == bond->params.all_slaves_active)
1513 goto out;
1514
1515 if ((new_value == 0) || (new_value == 1)) {
1516 bond->params.all_slaves_active = new_value;
1517 } else {
1518 pr_info("%s: Ignoring invalid all_slaves_active value %d.\n",
1519 bond->dev->name, new_value);
1520 ret = -EINVAL;
1521 goto out;
1522 }
1523
1524 bond_for_each_slave(bond, slave, i) {
Jiri Pirkoe30bc062011-03-12 03:14:37 +00001525 if (!bond_is_active_slave(slave)) {
Andy Gospodarekebd8e492010-06-02 08:39:21 +00001526 if (new_value)
Jiri Pirko2d7011c2011-03-16 08:46:43 +00001527 slave->inactive = 0;
Andy Gospodarekebd8e492010-06-02 08:39:21 +00001528 else
Jiri Pirko2d7011c2011-03-16 08:46:43 +00001529 slave->inactive = 1;
Andy Gospodarekebd8e492010-06-02 08:39:21 +00001530 }
1531 }
1532out:
Jiri Pirko672bda32011-01-25 11:03:25 +00001533 return ret;
Andy Gospodarekebd8e492010-06-02 08:39:21 +00001534}
1535static DEVICE_ATTR(all_slaves_active, S_IRUGO | S_IWUSR,
1536 bonding_show_slaves_active, bonding_store_slaves_active);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001537
Flavio Leitnerc2952c32010-10-05 14:23:59 +00001538/*
1539 * Show and set the number of IGMP membership reports to send on link failure
1540 */
1541static ssize_t bonding_show_resend_igmp(struct device *d,
1542 struct device_attribute *attr,
1543 char *buf)
1544{
1545 struct bonding *bond = to_bond(d);
1546
1547 return sprintf(buf, "%d\n", bond->params.resend_igmp);
1548}
1549
1550static ssize_t bonding_store_resend_igmp(struct device *d,
1551 struct device_attribute *attr,
1552 const char *buf, size_t count)
1553{
1554 int new_value, ret = count;
1555 struct bonding *bond = to_bond(d);
1556
1557 if (sscanf(buf, "%d", &new_value) != 1) {
1558 pr_err("%s: no resend_igmp value specified.\n",
1559 bond->dev->name);
1560 ret = -EINVAL;
1561 goto out;
1562 }
1563
1564 if (new_value < 0) {
1565 pr_err("%s: Invalid resend_igmp value %d not in range 0-255; rejected.\n",
1566 bond->dev->name, new_value);
1567 ret = -EINVAL;
1568 goto out;
1569 }
1570
1571 pr_info("%s: Setting resend_igmp to %d.\n",
1572 bond->dev->name, new_value);
1573 bond->params.resend_igmp = new_value;
1574out:
1575 return ret;
1576}
1577
1578static DEVICE_ATTR(resend_igmp, S_IRUGO | S_IWUSR,
1579 bonding_show_resend_igmp, bonding_store_resend_igmp);
1580
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001581static struct attribute *per_bond_attrs[] = {
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001582 &dev_attr_slaves.attr,
1583 &dev_attr_mode.attr,
Jay Vosburghdd957c52007-10-09 19:57:24 -07001584 &dev_attr_fail_over_mac.attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001585 &dev_attr_arp_validate.attr,
1586 &dev_attr_arp_interval.attr,
1587 &dev_attr_arp_ip_target.attr,
1588 &dev_attr_downdelay.attr,
1589 &dev_attr_updelay.attr,
1590 &dev_attr_lacp_rate.attr,
Jay Vosburghfd989c82008-11-04 17:51:16 -08001591 &dev_attr_ad_select.attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001592 &dev_attr_xmit_hash_policy.attr,
Ben Hutchingsad246c92011-04-26 15:25:52 +00001593 &dev_attr_num_grat_arp.attr,
1594 &dev_attr_num_unsol_na.attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001595 &dev_attr_miimon.attr,
1596 &dev_attr_primary.attr,
Jiri Pirkoa5499522009-09-25 03:28:09 +00001597 &dev_attr_primary_reselect.attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001598 &dev_attr_use_carrier.attr,
1599 &dev_attr_active_slave.attr,
1600 &dev_attr_mii_status.attr,
1601 &dev_attr_ad_aggregator.attr,
1602 &dev_attr_ad_num_ports.attr,
1603 &dev_attr_ad_actor_key.attr,
1604 &dev_attr_ad_partner_key.attr,
1605 &dev_attr_ad_partner_mac.attr,
Andy Gospodarekbb1d9122010-06-02 08:40:18 +00001606 &dev_attr_queue_id.attr,
Andy Gospodarekebd8e492010-06-02 08:39:21 +00001607 &dev_attr_all_slaves_active.attr,
Flavio Leitnerc2952c32010-10-05 14:23:59 +00001608 &dev_attr_resend_igmp.attr,
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001609 NULL,
1610};
1611
1612static struct attribute_group bonding_group = {
1613 .name = "bonding",
1614 .attrs = per_bond_attrs,
1615};
1616
1617/*
1618 * Initialize sysfs. This sets up the bonding_masters file in
1619 * /sys/class/net.
1620 */
1621int bond_create_sysfs(void)
1622{
Jay Vosburghb8a97872008-06-13 18:12:04 -07001623 int ret;
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001624
Jay Vosburghb8a97872008-06-13 18:12:04 -07001625 ret = netdev_class_create_file(&class_attr_bonding_masters);
Jay Vosburgh877cbd32007-01-19 18:15:47 -08001626 /*
1627 * Permit multiple loads of the module by ignoring failures to
1628 * create the bonding_masters sysfs file. Bonding devices
1629 * created by second or subsequent loads of the module will
1630 * not be listed in, or controllable by, bonding_masters, but
1631 * will have the usual "bonding" sysfs directory.
1632 *
1633 * This is done to preserve backwards compatibility for
1634 * initscripts/sysconfig, which load bonding multiple times to
1635 * configure multiple bonding devices.
1636 */
1637 if (ret == -EEXIST) {
Stephen Hemminger38d2f382008-05-14 22:35:04 -07001638 /* Is someone being kinky and naming a device bonding_master? */
1639 if (__dev_get_by_name(&init_net,
1640 class_attr_bonding_masters.attr.name))
Joe Perchesa4aee5c2009-12-13 20:06:07 -08001641 pr_err("network device named %s already exists in sysfs",
Stephen Hemminger38d2f382008-05-14 22:35:04 -07001642 class_attr_bonding_masters.attr.name);
Stephen Hemminger130aa612009-06-11 05:46:04 -07001643 ret = 0;
Jay Vosburgh877cbd32007-01-19 18:15:47 -08001644 }
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001645
1646 return ret;
1647
1648}
1649
1650/*
1651 * Remove /sys/class/net/bonding_masters.
1652 */
1653void bond_destroy_sysfs(void)
1654{
Jay Vosburghb8a97872008-06-13 18:12:04 -07001655 netdev_class_remove_file(&class_attr_bonding_masters);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001656}
1657
1658/*
1659 * Initialize sysfs for each bond. This sets up and registers
1660 * the 'bondctl' directory for each individual bond under /sys/class/net.
1661 */
Eric W. Biederman6151b3d2009-10-29 14:18:22 +00001662void bond_prepare_sysfs_group(struct bonding *bond)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001663{
Eric W. Biederman6151b3d2009-10-29 14:18:22 +00001664 bond->dev->sysfs_groups[0] = &bonding_group;
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001665}
1666