blob: 03d1196b844da619bea8f9f218e8da8580fbff73 [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
Eric W. Biederman496a60c2009-05-13 17:02:50 +0000230 if (!rtnl_trylock())
231 return restart_syscall();
Jay Vosburgh027ea042008-01-17 16:25:02 -0800232
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800233 sscanf(buffer, "%16s", command); /* IFNAMSIZ*/
234 ifname = command + 1;
235 if ((strlen(command) <= 1) ||
236 !dev_valid_name(ifname))
237 goto err_no_cmd;
238
Jiri Pirkof9f35452010-05-18 05:46:39 +0000239 dev = __dev_get_by_name(dev_net(bond->dev), ifname);
240 if (!dev) {
241 pr_info("%s: Interface %s does not exist!\n",
242 bond->dev->name, ifname);
243 ret = -ENODEV;
244 goto out;
245 }
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800246
Jiri Pirkof9f35452010-05-18 05:46:39 +0000247 switch (command[0]) {
248 case '+':
249 pr_info("%s: Adding slave %s.\n", bond->dev->name, dev->name);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800250 res = bond_enslave(bond->dev, dev);
Jiri Pirkof9f35452010-05-18 05:46:39 +0000251 break;
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000252
Jiri Pirkof9f35452010-05-18 05:46:39 +0000253 case '-':
254 pr_info("%s: Removing slave %s.\n", bond->dev->name, dev->name);
255 res = bond_release(bond->dev, dev);
256 break;
257
258 default:
259 goto err_no_cmd;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800260 }
261
Jiri Pirkof9f35452010-05-18 05:46:39 +0000262 if (res)
263 ret = res;
264 goto out;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800265
266err_no_cmd:
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800267 pr_err("no command found in slaves file for bond %s. Use +ifname or -ifname.\n",
268 bond->dev->name);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800269 ret = -EPERM;
270
271out:
Jay Vosburgh027ea042008-01-17 16:25:02 -0800272 rtnl_unlock();
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800273 return ret;
274}
275
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000276static DEVICE_ATTR(slaves, S_IRUGO | S_IWUSR, bonding_show_slaves,
277 bonding_store_slaves);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800278
279/*
280 * Show and set the bonding mode. The bond interface must be down to
281 * change the mode.
282 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700283static ssize_t bonding_show_mode(struct device *d,
284 struct device_attribute *attr, char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800285{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700286 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800287
288 return sprintf(buf, "%s %d\n",
289 bond_mode_tbl[bond->params.mode].modename,
Wagner Ferenc7bd46502007-12-06 23:40:28 -0800290 bond->params.mode);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800291}
292
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700293static ssize_t bonding_store_mode(struct device *d,
294 struct device_attribute *attr,
295 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800296{
297 int new_value, ret = count;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700298 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800299
300 if (bond->dev->flags & IFF_UP) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800301 pr_err("unable to update mode of %s because interface is up.\n",
302 bond->dev->name);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800303 ret = -EPERM;
304 goto out;
305 }
306
Jay Vosburghece95f72008-01-17 16:25:01 -0800307 new_value = bond_parse_parm(buf, bond_mode_tbl);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800308 if (new_value < 0) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800309 pr_err("%s: Ignoring invalid mode value %.*s.\n",
310 bond->dev->name, (int)strlen(buf) - 1, buf);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800311 ret = -EINVAL;
312 goto out;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800313 }
Andy Gospodarekc5cb0022010-07-28 15:13:56 +0000314 if ((new_value == BOND_MODE_ALB ||
315 new_value == BOND_MODE_TLB) &&
316 bond->params.arp_interval) {
317 pr_err("%s: %s mode is incompatible with arp monitoring.\n",
318 bond->dev->name, bond_mode_tbl[new_value].modename);
319 ret = -EINVAL;
320 goto out;
321 }
Andy Gospodarekc5cb0022010-07-28 15:13:56 +0000322
323 bond->params.mode = new_value;
324 bond_set_mode_ops(bond, bond->params.mode);
325 pr_info("%s: setting mode to %s (%d).\n",
326 bond->dev->name, bond_mode_tbl[new_value].modename,
327 new_value);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800328out:
329 return ret;
330}
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000331static DEVICE_ATTR(mode, S_IRUGO | S_IWUSR,
332 bonding_show_mode, bonding_store_mode);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800333
334/*
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000335 * Show and set the bonding transmit hash method.
336 * The bond interface must be down to change the xmit hash policy.
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800337 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700338static ssize_t bonding_show_xmit_hash(struct device *d,
339 struct device_attribute *attr,
340 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800341{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700342 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800343
Wagner Ferenc8e4b9322007-12-06 23:40:32 -0800344 return sprintf(buf, "%s %d\n",
345 xmit_hashtype_tbl[bond->params.xmit_policy].modename,
346 bond->params.xmit_policy);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800347}
348
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700349static ssize_t bonding_store_xmit_hash(struct device *d,
350 struct device_attribute *attr,
351 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800352{
353 int new_value, ret = count;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700354 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800355
356 if (bond->dev->flags & IFF_UP) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800357 pr_err("%s: Interface is up. Unable to update xmit policy.\n",
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800358 bond->dev->name);
359 ret = -EPERM;
360 goto out;
361 }
362
Jay Vosburghece95f72008-01-17 16:25:01 -0800363 new_value = bond_parse_parm(buf, xmit_hashtype_tbl);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800364 if (new_value < 0) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800365 pr_err("%s: Ignoring invalid xmit hash policy value %.*s.\n",
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800366 bond->dev->name,
367 (int)strlen(buf) - 1, buf);
368 ret = -EINVAL;
369 goto out;
370 } else {
371 bond->params.xmit_policy = new_value;
372 bond_set_mode_ops(bond, bond->params.mode);
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800373 pr_info("%s: setting xmit hash policy to %s (%d).\n",
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000374 bond->dev->name,
375 xmit_hashtype_tbl[new_value].modename, new_value);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800376 }
377out:
378 return ret;
379}
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000380static DEVICE_ATTR(xmit_hash_policy, S_IRUGO | S_IWUSR,
381 bonding_show_xmit_hash, bonding_store_xmit_hash);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800382
383/*
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700384 * Show and set arp_validate.
385 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700386static ssize_t bonding_show_arp_validate(struct device *d,
387 struct device_attribute *attr,
388 char *buf)
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700389{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700390 struct bonding *bond = to_bond(d);
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700391
392 return sprintf(buf, "%s %d\n",
393 arp_validate_tbl[bond->params.arp_validate].modename,
Wagner Ferenc7bd46502007-12-06 23:40:28 -0800394 bond->params.arp_validate);
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700395}
396
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700397static ssize_t bonding_store_arp_validate(struct device *d,
398 struct device_attribute *attr,
399 const char *buf, size_t count)
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700400{
401 int new_value;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700402 struct bonding *bond = to_bond(d);
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700403
Jay Vosburghece95f72008-01-17 16:25:01 -0800404 new_value = bond_parse_parm(buf, arp_validate_tbl);
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700405 if (new_value < 0) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800406 pr_err("%s: Ignoring invalid arp_validate value %s\n",
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700407 bond->dev->name, buf);
408 return -EINVAL;
409 }
410 if (new_value && (bond->params.mode != BOND_MODE_ACTIVEBACKUP)) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800411 pr_err("%s: arp_validate only supported in active-backup mode.\n",
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700412 bond->dev->name);
413 return -EINVAL;
414 }
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800415 pr_info("%s: setting arp_validate to %s (%d).\n",
416 bond->dev->name, arp_validate_tbl[new_value].modename,
417 new_value);
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700418
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700419 bond->params.arp_validate = new_value;
420
421 return count;
422}
423
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000424static DEVICE_ATTR(arp_validate, S_IRUGO | S_IWUSR, bonding_show_arp_validate,
425 bonding_store_arp_validate);
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700426
427/*
Jay Vosburghdd957c52007-10-09 19:57:24 -0700428 * Show and store fail_over_mac. User only allowed to change the
429 * value when there are no slaves.
430 */
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000431static ssize_t bonding_show_fail_over_mac(struct device *d,
432 struct device_attribute *attr,
433 char *buf)
Jay Vosburghdd957c52007-10-09 19:57:24 -0700434{
435 struct bonding *bond = to_bond(d);
436
Jay Vosburgh3915c1e82008-05-17 21:10:14 -0700437 return sprintf(buf, "%s %d\n",
438 fail_over_mac_tbl[bond->params.fail_over_mac].modename,
439 bond->params.fail_over_mac);
Jay Vosburghdd957c52007-10-09 19:57:24 -0700440}
441
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000442static ssize_t bonding_store_fail_over_mac(struct device *d,
443 struct device_attribute *attr,
444 const char *buf, size_t count)
Jay Vosburghdd957c52007-10-09 19:57:24 -0700445{
446 int new_value;
Jay Vosburghdd957c52007-10-09 19:57:24 -0700447 struct bonding *bond = to_bond(d);
448
449 if (bond->slave_cnt != 0) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800450 pr_err("%s: Can't alter fail_over_mac with slaves in bond.\n",
Jay Vosburghdd957c52007-10-09 19:57:24 -0700451 bond->dev->name);
Jay Vosburgh3915c1e82008-05-17 21:10:14 -0700452 return -EPERM;
Jay Vosburghdd957c52007-10-09 19:57:24 -0700453 }
454
Jay Vosburgh3915c1e82008-05-17 21:10:14 -0700455 new_value = bond_parse_parm(buf, fail_over_mac_tbl);
456 if (new_value < 0) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800457 pr_err("%s: Ignoring invalid fail_over_mac value %s.\n",
Jay Vosburgh3915c1e82008-05-17 21:10:14 -0700458 bond->dev->name, buf);
459 return -EINVAL;
Jay Vosburghdd957c52007-10-09 19:57:24 -0700460 }
461
Jay Vosburgh3915c1e82008-05-17 21:10:14 -0700462 bond->params.fail_over_mac = new_value;
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800463 pr_info("%s: Setting fail_over_mac to %s (%d).\n",
464 bond->dev->name, fail_over_mac_tbl[new_value].modename,
465 new_value);
Jay Vosburgh3915c1e82008-05-17 21:10:14 -0700466
467 return count;
Jay Vosburghdd957c52007-10-09 19:57:24 -0700468}
469
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000470static DEVICE_ATTR(fail_over_mac, S_IRUGO | S_IWUSR,
471 bonding_show_fail_over_mac, bonding_store_fail_over_mac);
Jay Vosburghdd957c52007-10-09 19:57:24 -0700472
473/*
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800474 * Show and set the arp timer interval. There are two tricky bits
475 * here. First, if ARP monitoring is activated, then we must disable
476 * MII monitoring. Second, if the ARP timer isn't running, we must
477 * start it.
478 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700479static ssize_t bonding_show_arp_interval(struct device *d,
480 struct device_attribute *attr,
481 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800482{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700483 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800484
Wagner Ferenc7bd46502007-12-06 23:40:28 -0800485 return sprintf(buf, "%d\n", bond->params.arp_interval);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800486}
487
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700488static ssize_t bonding_store_arp_interval(struct device *d,
489 struct device_attribute *attr,
490 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800491{
492 int new_value, ret = count;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700493 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800494
495 if (sscanf(buf, "%d", &new_value) != 1) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800496 pr_err("%s: no arp_interval value specified.\n",
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800497 bond->dev->name);
498 ret = -EINVAL;
499 goto out;
500 }
501 if (new_value < 0) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800502 pr_err("%s: Invalid arp_interval value %d not in range 1-%d; rejected.\n",
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800503 bond->dev->name, new_value, INT_MAX);
504 ret = -EINVAL;
505 goto out;
506 }
Andy Gospodarekc5cb0022010-07-28 15:13:56 +0000507 if (bond->params.mode == BOND_MODE_ALB ||
508 bond->params.mode == BOND_MODE_TLB) {
509 pr_info("%s: ARP monitoring cannot be used with ALB/TLB. Only MII monitoring is supported on %s.\n",
510 bond->dev->name, bond->dev->name);
511 ret = -EINVAL;
512 goto out;
513 }
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800514 pr_info("%s: Setting ARP monitoring interval to %d.\n",
515 bond->dev->name, new_value);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800516 bond->params.arp_interval = new_value;
517 if (bond->params.miimon) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800518 pr_info("%s: ARP monitoring cannot be used with MII monitoring. %s Disabling MII monitoring.\n",
519 bond->dev->name, bond->dev->name);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800520 bond->params.miimon = 0;
Jay Vosburgh1b76b312007-10-17 17:37:45 -0700521 if (delayed_work_pending(&bond->mii_work)) {
522 cancel_delayed_work(&bond->mii_work);
523 flush_workqueue(bond->wq);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800524 }
525 }
526 if (!bond->params.arp_targets[0]) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800527 pr_info("%s: ARP monitoring has been set up, but no ARP targets have been specified.\n",
528 bond->dev->name);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800529 }
530 if (bond->dev->flags & IFF_UP) {
531 /* If the interface is up, we may need to fire off
532 * the ARP timer. If the interface is down, the
533 * timer will get fired off when the open function
534 * is called.
535 */
Jay Vosburgh1b76b312007-10-17 17:37:45 -0700536 if (!delayed_work_pending(&bond->arp_work)) {
537 if (bond->params.mode == BOND_MODE_ACTIVEBACKUP)
538 INIT_DELAYED_WORK(&bond->arp_work,
539 bond_activebackup_arp_mon);
540 else
541 INIT_DELAYED_WORK(&bond->arp_work,
542 bond_loadbalance_arp_mon);
543
544 queue_delayed_work(bond->wq, &bond->arp_work, 0);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800545 }
546 }
547
548out:
549 return ret;
550}
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000551static DEVICE_ATTR(arp_interval, S_IRUGO | S_IWUSR,
552 bonding_show_arp_interval, bonding_store_arp_interval);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800553
554/*
555 * Show and set the arp targets.
556 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700557static ssize_t bonding_show_arp_targets(struct device *d,
558 struct device_attribute *attr,
559 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800560{
561 int i, res = 0;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700562 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800563
564 for (i = 0; i < BOND_MAX_ARP_TARGETS; i++) {
565 if (bond->params.arp_targets[i])
Harvey Harrison63779432008-10-31 00:56:00 -0700566 res += sprintf(buf + res, "%pI4 ",
567 &bond->params.arp_targets[i]);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800568 }
Wagner Ferenc1dcdcd62007-12-06 23:40:31 -0800569 if (res)
570 buf[res-1] = '\n'; /* eat the leftover space */
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800571 return res;
572}
573
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700574static ssize_t bonding_store_arp_targets(struct device *d,
575 struct device_attribute *attr,
576 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800577{
Al Virod3bb52b2007-08-22 20:06:58 -0400578 __be32 newtarget;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800579 int i = 0, done = 0, ret = count;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700580 struct bonding *bond = to_bond(d);
Al Virod3bb52b2007-08-22 20:06:58 -0400581 __be32 *targets;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800582
583 targets = bond->params.arp_targets;
584 newtarget = in_aton(buf + 1);
585 /* look for adds */
586 if (buf[0] == '+') {
Al Virod3bb52b2007-08-22 20:06:58 -0400587 if ((newtarget == 0) || (newtarget == htonl(INADDR_BROADCAST))) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800588 pr_err("%s: invalid ARP target %pI4 specified for addition\n",
Harvey Harrison63779432008-10-31 00:56:00 -0700589 bond->dev->name, &newtarget);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800590 ret = -EINVAL;
591 goto out;
592 }
593 /* look for an empty slot to put the target in, and check for dupes */
Brian Haley5a31bec2009-04-13 00:11:30 -0700594 for (i = 0; (i < BOND_MAX_ARP_TARGETS) && !done; i++) {
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800595 if (targets[i] == newtarget) { /* duplicate */
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800596 pr_err("%s: ARP target %pI4 is already present\n",
Harvey Harrison63779432008-10-31 00:56:00 -0700597 bond->dev->name, &newtarget);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800598 ret = -EINVAL;
599 goto out;
600 }
Brian Haley5a31bec2009-04-13 00:11:30 -0700601 if (targets[i] == 0) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800602 pr_info("%s: adding ARP target %pI4.\n",
603 bond->dev->name, &newtarget);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800604 done = 1;
605 targets[i] = newtarget;
606 }
607 }
608 if (!done) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800609 pr_err("%s: ARP target table is full!\n",
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800610 bond->dev->name);
611 ret = -EINVAL;
612 goto out;
613 }
614
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000615 } else if (buf[0] == '-') {
Al Virod3bb52b2007-08-22 20:06:58 -0400616 if ((newtarget == 0) || (newtarget == htonl(INADDR_BROADCAST))) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800617 pr_err("%s: invalid ARP target %pI4 specified for removal\n",
Harvey Harrison63779432008-10-31 00:56:00 -0700618 bond->dev->name, &newtarget);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800619 ret = -EINVAL;
620 goto out;
621 }
622
Brian Haley5a31bec2009-04-13 00:11:30 -0700623 for (i = 0; (i < BOND_MAX_ARP_TARGETS) && !done; i++) {
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800624 if (targets[i] == newtarget) {
Brian Haley5a31bec2009-04-13 00:11:30 -0700625 int j;
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800626 pr_info("%s: removing ARP target %pI4.\n",
627 bond->dev->name, &newtarget);
Brian Haley5a31bec2009-04-13 00:11:30 -0700628 for (j = i; (j < (BOND_MAX_ARP_TARGETS-1)) && targets[j+1]; j++)
629 targets[j] = targets[j+1];
630
631 targets[j] = 0;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800632 done = 1;
633 }
634 }
635 if (!done) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800636 pr_info("%s: unable to remove nonexistent ARP target %pI4.\n",
637 bond->dev->name, &newtarget);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800638 ret = -EINVAL;
639 goto out;
640 }
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000641 } else {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800642 pr_err("no command found in arp_ip_targets file for bond %s. Use +<addr> or -<addr>.\n",
643 bond->dev->name);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800644 ret = -EPERM;
645 goto out;
646 }
647
648out:
649 return ret;
650}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700651static DEVICE_ATTR(arp_ip_target, S_IRUGO | S_IWUSR , bonding_show_arp_targets, bonding_store_arp_targets);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800652
653/*
654 * Show and set the up and down delays. These must be multiples of the
655 * MII monitoring value, and are stored internally as the multiplier.
656 * Thus, we must translate to MS for the real world.
657 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700658static ssize_t bonding_show_downdelay(struct device *d,
659 struct device_attribute *attr,
660 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800661{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700662 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800663
Wagner Ferenc7bd46502007-12-06 23:40:28 -0800664 return sprintf(buf, "%d\n", bond->params.downdelay * bond->params.miimon);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800665}
666
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700667static ssize_t bonding_store_downdelay(struct device *d,
668 struct device_attribute *attr,
669 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800670{
671 int new_value, ret = count;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700672 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800673
674 if (!(bond->params.miimon)) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800675 pr_err("%s: Unable to set down delay as MII monitoring is disabled\n",
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800676 bond->dev->name);
677 ret = -EPERM;
678 goto out;
679 }
680
681 if (sscanf(buf, "%d", &new_value) != 1) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800682 pr_err("%s: no down delay value specified.\n", bond->dev->name);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800683 ret = -EINVAL;
684 goto out;
685 }
686 if (new_value < 0) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800687 pr_err("%s: Invalid down delay value %d not in range %d-%d; rejected.\n",
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800688 bond->dev->name, new_value, 1, INT_MAX);
689 ret = -EINVAL;
690 goto out;
691 } else {
692 if ((new_value % bond->params.miimon) != 0) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800693 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 +0000694 bond->dev->name, new_value,
695 bond->params.miimon,
696 (new_value / bond->params.miimon) *
697 bond->params.miimon);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800698 }
699 bond->params.downdelay = new_value / bond->params.miimon;
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800700 pr_info("%s: Setting down delay to %d.\n",
701 bond->dev->name,
702 bond->params.downdelay * bond->params.miimon);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800703
704 }
705
706out:
707 return ret;
708}
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000709static DEVICE_ATTR(downdelay, S_IRUGO | S_IWUSR,
710 bonding_show_downdelay, bonding_store_downdelay);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800711
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700712static ssize_t bonding_show_updelay(struct device *d,
713 struct device_attribute *attr,
714 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800715{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700716 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800717
Wagner Ferenc7bd46502007-12-06 23:40:28 -0800718 return sprintf(buf, "%d\n", bond->params.updelay * bond->params.miimon);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800719
720}
721
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700722static ssize_t bonding_store_updelay(struct device *d,
723 struct device_attribute *attr,
724 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800725{
726 int new_value, ret = count;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700727 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800728
729 if (!(bond->params.miimon)) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800730 pr_err("%s: Unable to set up delay as MII monitoring is disabled\n",
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800731 bond->dev->name);
732 ret = -EPERM;
733 goto out;
734 }
735
736 if (sscanf(buf, "%d", &new_value) != 1) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800737 pr_err("%s: no up delay value specified.\n",
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800738 bond->dev->name);
739 ret = -EINVAL;
740 goto out;
741 }
742 if (new_value < 0) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800743 pr_err("%s: Invalid down delay value %d not in range %d-%d; rejected.\n",
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800744 bond->dev->name, new_value, 1, INT_MAX);
745 ret = -EINVAL;
746 goto out;
747 } else {
748 if ((new_value % bond->params.miimon) != 0) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800749 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 +0000750 bond->dev->name, new_value,
751 bond->params.miimon,
752 (new_value / bond->params.miimon) *
753 bond->params.miimon);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800754 }
755 bond->params.updelay = new_value / bond->params.miimon;
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800756 pr_info("%s: Setting up delay to %d.\n",
757 bond->dev->name,
758 bond->params.updelay * bond->params.miimon);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800759 }
760
761out:
762 return ret;
763}
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000764static DEVICE_ATTR(updelay, S_IRUGO | S_IWUSR,
765 bonding_show_updelay, bonding_store_updelay);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800766
767/*
768 * Show and set the LACP interval. Interface must be down, and the mode
769 * must be set to 802.3ad mode.
770 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700771static ssize_t bonding_show_lacp(struct device *d,
772 struct device_attribute *attr,
773 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800774{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700775 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800776
777 return sprintf(buf, "%s %d\n",
778 bond_lacp_tbl[bond->params.lacp_fast].modename,
Wagner Ferenc7bd46502007-12-06 23:40:28 -0800779 bond->params.lacp_fast);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800780}
781
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700782static ssize_t bonding_store_lacp(struct device *d,
783 struct device_attribute *attr,
784 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800785{
786 int new_value, ret = count;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700787 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800788
789 if (bond->dev->flags & IFF_UP) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800790 pr_err("%s: Unable to update LACP rate because interface is up.\n",
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800791 bond->dev->name);
792 ret = -EPERM;
793 goto out;
794 }
795
796 if (bond->params.mode != BOND_MODE_8023AD) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800797 pr_err("%s: Unable to update LACP rate because bond is not in 802.3ad mode.\n",
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800798 bond->dev->name);
799 ret = -EPERM;
800 goto out;
801 }
802
Jay Vosburghece95f72008-01-17 16:25:01 -0800803 new_value = bond_parse_parm(buf, bond_lacp_tbl);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800804
805 if ((new_value == 1) || (new_value == 0)) {
806 bond->params.lacp_fast = new_value;
Peter Pan(潘卫平)ba824a82011-06-08 21:19:01 +0000807 bond_3ad_update_lacp_rate(bond);
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800808 pr_info("%s: Setting LACP rate to %s (%d).\n",
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000809 bond->dev->name, bond_lacp_tbl[new_value].modename,
810 new_value);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800811 } else {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800812 pr_err("%s: Ignoring invalid LACP rate value %.*s.\n",
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000813 bond->dev->name, (int)strlen(buf) - 1, buf);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800814 ret = -EINVAL;
815 }
816out:
817 return ret;
818}
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000819static DEVICE_ATTR(lacp_rate, S_IRUGO | S_IWUSR,
820 bonding_show_lacp, bonding_store_lacp);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800821
Jay Vosburghfd989c82008-11-04 17:51:16 -0800822static ssize_t bonding_show_ad_select(struct device *d,
823 struct device_attribute *attr,
824 char *buf)
825{
826 struct bonding *bond = to_bond(d);
827
828 return sprintf(buf, "%s %d\n",
829 ad_select_tbl[bond->params.ad_select].modename,
830 bond->params.ad_select);
831}
832
833
834static ssize_t bonding_store_ad_select(struct device *d,
835 struct device_attribute *attr,
836 const char *buf, size_t count)
837{
838 int new_value, ret = count;
839 struct bonding *bond = to_bond(d);
840
841 if (bond->dev->flags & IFF_UP) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800842 pr_err("%s: Unable to update ad_select because interface is up.\n",
843 bond->dev->name);
Jay Vosburghfd989c82008-11-04 17:51:16 -0800844 ret = -EPERM;
845 goto out;
846 }
847
848 new_value = bond_parse_parm(buf, ad_select_tbl);
849
850 if (new_value != -1) {
851 bond->params.ad_select = new_value;
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800852 pr_info("%s: Setting ad_select to %s (%d).\n",
853 bond->dev->name, ad_select_tbl[new_value].modename,
854 new_value);
Jay Vosburghfd989c82008-11-04 17:51:16 -0800855 } else {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800856 pr_err("%s: Ignoring invalid ad_select value %.*s.\n",
Jay Vosburghfd989c82008-11-04 17:51:16 -0800857 bond->dev->name, (int)strlen(buf) - 1, buf);
858 ret = -EINVAL;
859 }
860out:
861 return ret;
862}
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000863static DEVICE_ATTR(ad_select, S_IRUGO | S_IWUSR,
864 bonding_show_ad_select, bonding_store_ad_select);
Jay Vosburghfd989c82008-11-04 17:51:16 -0800865
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800866/*
Ben Hutchingsad246c92011-04-26 15:25:52 +0000867 * Show and set the number of peer notifications to send after a failover event.
868 */
869static ssize_t bonding_show_num_peer_notif(struct device *d,
870 struct device_attribute *attr,
871 char *buf)
872{
873 struct bonding *bond = to_bond(d);
874 return sprintf(buf, "%d\n", bond->params.num_peer_notif);
875}
876
877static ssize_t bonding_store_num_peer_notif(struct device *d,
878 struct device_attribute *attr,
879 const char *buf, size_t count)
880{
881 struct bonding *bond = to_bond(d);
882 int err = kstrtou8(buf, 10, &bond->params.num_peer_notif);
883 return err ? err : count;
884}
885static DEVICE_ATTR(num_grat_arp, S_IRUGO | S_IWUSR,
886 bonding_show_num_peer_notif, bonding_store_num_peer_notif);
887static DEVICE_ATTR(num_unsol_na, S_IRUGO | S_IWUSR,
888 bonding_show_num_peer_notif, bonding_store_num_peer_notif);
889
890/*
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800891 * Show and set the MII monitor interval. There are two tricky bits
892 * here. First, if MII monitoring is activated, then we must disable
893 * ARP monitoring. Second, if the timer isn't running, we must
894 * start it.
895 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700896static ssize_t bonding_show_miimon(struct device *d,
897 struct device_attribute *attr,
898 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800899{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700900 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800901
Wagner Ferenc7bd46502007-12-06 23:40:28 -0800902 return sprintf(buf, "%d\n", bond->params.miimon);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800903}
904
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700905static ssize_t bonding_store_miimon(struct device *d,
906 struct device_attribute *attr,
907 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800908{
909 int new_value, ret = count;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700910 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800911
912 if (sscanf(buf, "%d", &new_value) != 1) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800913 pr_err("%s: no miimon value specified.\n",
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800914 bond->dev->name);
915 ret = -EINVAL;
916 goto out;
917 }
918 if (new_value < 0) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800919 pr_err("%s: Invalid miimon value %d not in range %d-%d; rejected.\n",
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800920 bond->dev->name, new_value, 1, INT_MAX);
921 ret = -EINVAL;
922 goto out;
923 } else {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800924 pr_info("%s: Setting MII monitoring interval to %d.\n",
925 bond->dev->name, new_value);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800926 bond->params.miimon = new_value;
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000927 if (bond->params.updelay)
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800928 pr_info("%s: Note: Updating updelay (to %d) since it is a multiple of the miimon value.\n",
929 bond->dev->name,
930 bond->params.updelay * bond->params.miimon);
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000931 if (bond->params.downdelay)
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800932 pr_info("%s: Note: Updating downdelay (to %d) since it is a multiple of the miimon value.\n",
933 bond->dev->name,
934 bond->params.downdelay * bond->params.miimon);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800935 if (bond->params.arp_interval) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800936 pr_info("%s: MII monitoring cannot be used with ARP monitoring. Disabling ARP monitoring...\n",
937 bond->dev->name);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800938 bond->params.arp_interval = 0;
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700939 if (bond->params.arp_validate) {
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700940 bond->params.arp_validate =
941 BOND_ARP_VALIDATE_NONE;
942 }
Jay Vosburgh1b76b312007-10-17 17:37:45 -0700943 if (delayed_work_pending(&bond->arp_work)) {
944 cancel_delayed_work(&bond->arp_work);
945 flush_workqueue(bond->wq);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800946 }
947 }
948
949 if (bond->dev->flags & IFF_UP) {
950 /* If the interface is up, we may need to fire off
951 * the MII timer. If the interface is down, the
952 * timer will get fired off when the open function
953 * is called.
954 */
Jay Vosburgh1b76b312007-10-17 17:37:45 -0700955 if (!delayed_work_pending(&bond->mii_work)) {
956 INIT_DELAYED_WORK(&bond->mii_work,
957 bond_mii_monitor);
958 queue_delayed_work(bond->wq,
959 &bond->mii_work, 0);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800960 }
961 }
962 }
963out:
964 return ret;
965}
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000966static DEVICE_ATTR(miimon, S_IRUGO | S_IWUSR,
967 bonding_show_miimon, bonding_store_miimon);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800968
969/*
970 * Show and set the primary slave. The store function is much
971 * simpler than bonding_store_slaves function because it only needs to
972 * handle one interface name.
973 * The bond must be a mode that supports a primary for this be
974 * set.
975 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700976static ssize_t bonding_show_primary(struct device *d,
977 struct device_attribute *attr,
978 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800979{
980 int count = 0;
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 (bond->primary_slave)
Wagner Ferenc7bd46502007-12-06 23:40:28 -0800984 count = sprintf(buf, "%s\n", bond->primary_slave->dev->name);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800985
986 return count;
987}
988
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700989static ssize_t bonding_store_primary(struct device *d,
990 struct device_attribute *attr,
991 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800992{
993 int i;
994 struct slave *slave;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700995 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800996
Eric W. Biederman496a60c2009-05-13 17:02:50 +0000997 if (!rtnl_trylock())
998 return restart_syscall();
Neil Hormane843fa52010-10-13 16:01:50 +0000999 block_netpoll_tx();
Jay Vosburghe934dd72008-01-17 16:24:57 -08001000 read_lock(&bond->lock);
1001 write_lock_bh(&bond->curr_slave_lock);
1002
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001003 if (!USES_PRIMARY(bond->params.mode)) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -08001004 pr_info("%s: Unable to set primary slave; %s is in mode %d\n",
1005 bond->dev->name, bond->dev->name, bond->params.mode);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001006 } else {
1007 bond_for_each_slave(bond, slave, i) {
1008 if (strnicmp
1009 (slave->dev->name, buf,
1010 strlen(slave->dev->name)) == 0) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -08001011 pr_info("%s: Setting %s as primary slave.\n",
1012 bond->dev->name, slave->dev->name);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001013 bond->primary_slave = slave;
Jiri Pirkoce501ca2009-09-18 02:13:22 +00001014 strcpy(bond->params.primary, slave->dev->name);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001015 bond_select_active_slave(bond);
1016 goto out;
1017 }
1018 }
1019
1020 /* if we got here, then we didn't match the name of any slave */
1021
1022 if (strlen(buf) == 0 || buf[0] == '\n') {
Joe Perchesa4aee5c2009-12-13 20:06:07 -08001023 pr_info("%s: Setting primary slave to None.\n",
1024 bond->dev->name);
Luiz Fernando Capitulino3418db72006-02-01 00:54:34 -08001025 bond->primary_slave = NULL;
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001026 bond_select_active_slave(bond);
1027 } else {
Joe Perchesa4aee5c2009-12-13 20:06:07 -08001028 pr_info("%s: Unable to set %.*s as primary slave as it is not a slave.\n",
1029 bond->dev->name, (int)strlen(buf) - 1, buf);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001030 }
1031 }
1032out:
Jay Vosburghe934dd72008-01-17 16:24:57 -08001033 write_unlock_bh(&bond->curr_slave_lock);
1034 read_unlock(&bond->lock);
Neil Hormane843fa52010-10-13 16:01:50 +00001035 unblock_netpoll_tx();
Jay Vosburgh6603a6f2007-10-17 17:37:50 -07001036 rtnl_unlock();
1037
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001038 return count;
1039}
Stephen Hemminger3d632c32009-06-12 19:02:48 +00001040static DEVICE_ATTR(primary, S_IRUGO | S_IWUSR,
1041 bonding_show_primary, bonding_store_primary);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001042
1043/*
Jiri Pirkoa5499522009-09-25 03:28:09 +00001044 * Show and set the primary_reselect flag.
1045 */
1046static ssize_t bonding_show_primary_reselect(struct device *d,
1047 struct device_attribute *attr,
1048 char *buf)
1049{
1050 struct bonding *bond = to_bond(d);
1051
1052 return sprintf(buf, "%s %d\n",
1053 pri_reselect_tbl[bond->params.primary_reselect].modename,
1054 bond->params.primary_reselect);
1055}
1056
1057static ssize_t bonding_store_primary_reselect(struct device *d,
1058 struct device_attribute *attr,
1059 const char *buf, size_t count)
1060{
1061 int new_value, ret = count;
1062 struct bonding *bond = to_bond(d);
1063
1064 if (!rtnl_trylock())
1065 return restart_syscall();
1066
1067 new_value = bond_parse_parm(buf, pri_reselect_tbl);
1068 if (new_value < 0) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -08001069 pr_err("%s: Ignoring invalid primary_reselect value %.*s.\n",
Jiri Pirkoa5499522009-09-25 03:28:09 +00001070 bond->dev->name,
1071 (int) strlen(buf) - 1, buf);
1072 ret = -EINVAL;
1073 goto out;
1074 }
1075
1076 bond->params.primary_reselect = new_value;
Joe Perchesa4aee5c2009-12-13 20:06:07 -08001077 pr_info("%s: setting primary_reselect to %s (%d).\n",
Jiri Pirkoa5499522009-09-25 03:28:09 +00001078 bond->dev->name, pri_reselect_tbl[new_value].modename,
1079 new_value);
1080
Neil Hormane843fa52010-10-13 16:01:50 +00001081 block_netpoll_tx();
Jiri Pirkoa5499522009-09-25 03:28:09 +00001082 read_lock(&bond->lock);
1083 write_lock_bh(&bond->curr_slave_lock);
1084 bond_select_active_slave(bond);
1085 write_unlock_bh(&bond->curr_slave_lock);
1086 read_unlock(&bond->lock);
Neil Hormane843fa52010-10-13 16:01:50 +00001087 unblock_netpoll_tx();
Jiri Pirkoa5499522009-09-25 03:28:09 +00001088out:
1089 rtnl_unlock();
1090 return ret;
1091}
1092static DEVICE_ATTR(primary_reselect, S_IRUGO | S_IWUSR,
1093 bonding_show_primary_reselect,
1094 bonding_store_primary_reselect);
1095
1096/*
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001097 * Show and set the use_carrier flag.
1098 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001099static ssize_t bonding_show_carrier(struct device *d,
1100 struct device_attribute *attr,
1101 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001102{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001103 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001104
Wagner Ferenc7bd46502007-12-06 23:40:28 -08001105 return sprintf(buf, "%d\n", bond->params.use_carrier);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001106}
1107
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001108static ssize_t bonding_store_carrier(struct device *d,
1109 struct device_attribute *attr,
1110 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001111{
1112 int new_value, ret = count;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001113 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001114
1115
1116 if (sscanf(buf, "%d", &new_value) != 1) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -08001117 pr_err("%s: no use_carrier value specified.\n",
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001118 bond->dev->name);
1119 ret = -EINVAL;
1120 goto out;
1121 }
1122 if ((new_value == 0) || (new_value == 1)) {
1123 bond->params.use_carrier = new_value;
Joe Perchesa4aee5c2009-12-13 20:06:07 -08001124 pr_info("%s: Setting use_carrier to %d.\n",
1125 bond->dev->name, new_value);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001126 } else {
Joe Perchesa4aee5c2009-12-13 20:06:07 -08001127 pr_info("%s: Ignoring invalid use_carrier value %d.\n",
1128 bond->dev->name, new_value);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001129 }
1130out:
Jiri Pirko672bda32011-01-25 11:03:25 +00001131 return ret;
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001132}
Stephen Hemminger3d632c32009-06-12 19:02:48 +00001133static DEVICE_ATTR(use_carrier, S_IRUGO | S_IWUSR,
1134 bonding_show_carrier, bonding_store_carrier);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001135
1136
1137/*
1138 * Show and set currently active_slave.
1139 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001140static ssize_t bonding_show_active_slave(struct device *d,
1141 struct device_attribute *attr,
1142 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001143{
1144 struct slave *curr;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001145 struct bonding *bond = to_bond(d);
Wagner Ferenc16cd0162007-12-06 23:40:29 -08001146 int count = 0;
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001147
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001148 read_lock(&bond->curr_slave_lock);
1149 curr = bond->curr_active_slave;
1150 read_unlock(&bond->curr_slave_lock);
1151
1152 if (USES_PRIMARY(bond->params.mode) && curr)
Wagner Ferenc7bd46502007-12-06 23:40:28 -08001153 count = sprintf(buf, "%s\n", curr->dev->name);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001154 return count;
1155}
1156
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001157static ssize_t bonding_store_active_slave(struct device *d,
1158 struct device_attribute *attr,
1159 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001160{
1161 int i;
1162 struct slave *slave;
Stephen Hemminger3d632c32009-06-12 19:02:48 +00001163 struct slave *old_active = NULL;
1164 struct slave *new_active = NULL;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001165 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001166
Eric W. Biederman496a60c2009-05-13 17:02:50 +00001167 if (!rtnl_trylock())
1168 return restart_syscall();
Neil Hormane843fa52010-10-13 16:01:50 +00001169
1170 block_netpoll_tx();
Jay Vosburghe934dd72008-01-17 16:24:57 -08001171 read_lock(&bond->lock);
1172 write_lock_bh(&bond->curr_slave_lock);
Jay Vosburgh1466a212007-11-06 13:33:28 -08001173
Stephen Hemminger3d632c32009-06-12 19:02:48 +00001174 if (!USES_PRIMARY(bond->params.mode))
Joe Perchesa4aee5c2009-12-13 20:06:07 -08001175 pr_info("%s: Unable to change active slave; %s is in mode %d\n",
Stephen Hemminger3d632c32009-06-12 19:02:48 +00001176 bond->dev->name, bond->dev->name, bond->params.mode);
1177 else {
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001178 bond_for_each_slave(bond, slave, i) {
1179 if (strnicmp
1180 (slave->dev->name, buf,
1181 strlen(slave->dev->name)) == 0) {
1182 old_active = bond->curr_active_slave;
1183 new_active = slave;
Jay Vosburgha50d8de2006-09-22 21:53:25 -07001184 if (new_active == old_active) {
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001185 /* do nothing */
Joe Perchesa4aee5c2009-12-13 20:06:07 -08001186 pr_info("%s: %s is already the current active slave.\n",
1187 bond->dev->name,
1188 slave->dev->name);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001189 goto out;
1190 }
1191 else {
1192 if ((new_active) &&
1193 (old_active) &&
1194 (new_active->link == BOND_LINK_UP) &&
1195 IS_UP(new_active->dev)) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -08001196 pr_info("%s: Setting %s as active slave.\n",
1197 bond->dev->name,
1198 slave->dev->name);
Jiri Pirkoe5e2a8f2009-08-13 04:11:52 +00001199 bond_change_active_slave(bond, new_active);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001200 }
1201 else {
Joe Perchesa4aee5c2009-12-13 20:06:07 -08001202 pr_info("%s: Could not set %s as active slave; either %s is down or the link is down.\n",
1203 bond->dev->name,
1204 slave->dev->name,
Jiri Pirkoe5e2a8f2009-08-13 04:11:52 +00001205 slave->dev->name);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001206 }
1207 goto out;
1208 }
1209 }
1210 }
1211
1212 /* if we got here, then we didn't match the name of any slave */
1213
1214 if (strlen(buf) == 0 || buf[0] == '\n') {
Joe Perchesa4aee5c2009-12-13 20:06:07 -08001215 pr_info("%s: Setting active slave to None.\n",
Stephen Hemminger3d632c32009-06-12 19:02:48 +00001216 bond->dev->name);
Luiz Fernando Capitulino3418db72006-02-01 00:54:34 -08001217 bond->primary_slave = NULL;
Stephen Hemminger3d632c32009-06-12 19:02:48 +00001218 bond_select_active_slave(bond);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001219 } else {
Joe Perchesa4aee5c2009-12-13 20:06:07 -08001220 pr_info("%s: Unable to set %.*s as active slave as it is not a slave.\n",
Stephen Hemminger3d632c32009-06-12 19:02:48 +00001221 bond->dev->name, (int)strlen(buf) - 1, buf);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001222 }
1223 }
Stephen Hemminger3d632c32009-06-12 19:02:48 +00001224 out:
Jay Vosburghe934dd72008-01-17 16:24:57 -08001225 write_unlock_bh(&bond->curr_slave_lock);
1226 read_unlock(&bond->lock);
Neil Hormane843fa52010-10-13 16:01:50 +00001227 unblock_netpoll_tx();
1228
Jay Vosburgh6603a6f2007-10-17 17:37:50 -07001229 rtnl_unlock();
1230
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001231 return count;
1232
1233}
Stephen Hemminger3d632c32009-06-12 19:02:48 +00001234static DEVICE_ATTR(active_slave, S_IRUGO | S_IWUSR,
1235 bonding_show_active_slave, bonding_store_active_slave);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001236
1237
1238/*
1239 * Show link status of the bond interface.
1240 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001241static ssize_t bonding_show_mii_status(struct device *d,
1242 struct device_attribute *attr,
1243 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001244{
1245 struct slave *curr;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001246 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001247
1248 read_lock(&bond->curr_slave_lock);
1249 curr = bond->curr_active_slave;
1250 read_unlock(&bond->curr_slave_lock);
1251
Stephen Hemminger3d632c32009-06-12 19:02:48 +00001252 return sprintf(buf, "%s\n", curr ? "up" : "down");
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001253}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001254static DEVICE_ATTR(mii_status, S_IRUGO, bonding_show_mii_status, NULL);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001255
1256
1257/*
1258 * Show current 802.3ad aggregator ID.
1259 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001260static ssize_t bonding_show_ad_aggregator(struct device *d,
1261 struct device_attribute *attr,
1262 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001263{
1264 int count = 0;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001265 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001266
1267 if (bond->params.mode == BOND_MODE_8023AD) {
1268 struct ad_info ad_info;
Stephen Hemminger3d632c32009-06-12 19:02:48 +00001269 count = sprintf(buf, "%d\n",
1270 (bond_3ad_get_active_agg_info(bond, &ad_info))
1271 ? 0 : ad_info.aggregator_id);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001272 }
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001273
1274 return count;
1275}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001276static DEVICE_ATTR(ad_aggregator, S_IRUGO, bonding_show_ad_aggregator, NULL);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001277
1278
1279/*
1280 * Show number of active 802.3ad ports.
1281 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001282static ssize_t bonding_show_ad_num_ports(struct device *d,
1283 struct device_attribute *attr,
1284 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001285{
1286 int count = 0;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001287 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001288
1289 if (bond->params.mode == BOND_MODE_8023AD) {
1290 struct ad_info ad_info;
Stephen Hemminger3d632c32009-06-12 19:02:48 +00001291 count = sprintf(buf, "%d\n",
1292 (bond_3ad_get_active_agg_info(bond, &ad_info))
1293 ? 0 : ad_info.ports);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001294 }
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001295
1296 return count;
1297}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001298static DEVICE_ATTR(ad_num_ports, S_IRUGO, bonding_show_ad_num_ports, NULL);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001299
1300
1301/*
1302 * Show current 802.3ad actor key.
1303 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001304static ssize_t bonding_show_ad_actor_key(struct device *d,
1305 struct device_attribute *attr,
1306 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001307{
1308 int count = 0;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001309 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001310
1311 if (bond->params.mode == BOND_MODE_8023AD) {
1312 struct ad_info ad_info;
Stephen Hemminger3d632c32009-06-12 19:02:48 +00001313 count = sprintf(buf, "%d\n",
1314 (bond_3ad_get_active_agg_info(bond, &ad_info))
1315 ? 0 : ad_info.actor_key);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001316 }
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001317
1318 return count;
1319}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001320static DEVICE_ATTR(ad_actor_key, S_IRUGO, bonding_show_ad_actor_key, NULL);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001321
1322
1323/*
1324 * Show current 802.3ad partner key.
1325 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001326static ssize_t bonding_show_ad_partner_key(struct device *d,
1327 struct device_attribute *attr,
1328 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001329{
1330 int count = 0;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001331 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001332
1333 if (bond->params.mode == BOND_MODE_8023AD) {
1334 struct ad_info ad_info;
Stephen Hemminger3d632c32009-06-12 19:02:48 +00001335 count = sprintf(buf, "%d\n",
1336 (bond_3ad_get_active_agg_info(bond, &ad_info))
1337 ? 0 : ad_info.partner_key);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001338 }
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001339
1340 return count;
1341}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001342static DEVICE_ATTR(ad_partner_key, S_IRUGO, bonding_show_ad_partner_key, NULL);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001343
1344
1345/*
1346 * Show current 802.3ad partner mac.
1347 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001348static ssize_t bonding_show_ad_partner_mac(struct device *d,
1349 struct device_attribute *attr,
1350 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001351{
1352 int count = 0;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001353 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001354
1355 if (bond->params.mode == BOND_MODE_8023AD) {
1356 struct ad_info ad_info;
Stephen Hemminger3d632c32009-06-12 19:02:48 +00001357 if (!bond_3ad_get_active_agg_info(bond, &ad_info))
Johannes Berge1749612008-10-27 15:59:26 -07001358 count = sprintf(buf, "%pM\n", ad_info.partner_system);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001359 }
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001360
1361 return count;
1362}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001363static DEVICE_ATTR(ad_partner_mac, S_IRUGO, bonding_show_ad_partner_mac, NULL);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001364
Andy Gospodarekebd8e492010-06-02 08:39:21 +00001365/*
Andy Gospodarekbb1d9122010-06-02 08:40:18 +00001366 * Show the queue_ids of the slaves in the current bond.
1367 */
1368static ssize_t bonding_show_queue_id(struct device *d,
1369 struct device_attribute *attr,
1370 char *buf)
1371{
1372 struct slave *slave;
1373 int i, res = 0;
1374 struct bonding *bond = to_bond(d);
1375
1376 if (!rtnl_trylock())
1377 return restart_syscall();
1378
1379 read_lock(&bond->lock);
1380 bond_for_each_slave(bond, slave, i) {
Nicolas de Pesloüan79236682010-07-14 18:24:54 -07001381 if (res > (PAGE_SIZE - IFNAMSIZ - 6)) {
1382 /* not enough space for another interface_name:queue_id pair */
Andy Gospodarekbb1d9122010-06-02 08:40:18 +00001383 if ((PAGE_SIZE - res) > 10)
1384 res = PAGE_SIZE - 10;
1385 res += sprintf(buf + res, "++more++ ");
1386 break;
1387 }
1388 res += sprintf(buf + res, "%s:%d ",
1389 slave->dev->name, slave->queue_id);
1390 }
1391 read_unlock(&bond->lock);
1392 if (res)
1393 buf[res-1] = '\n'; /* eat the leftover space */
1394 rtnl_unlock();
1395 return res;
1396}
1397
1398/*
1399 * Set the queue_ids of the slaves in the current bond. The bond
1400 * interface must be enslaved for this to work.
1401 */
1402static ssize_t bonding_store_queue_id(struct device *d,
1403 struct device_attribute *attr,
1404 const char *buffer, size_t count)
1405{
1406 struct slave *slave, *update_slave;
1407 struct bonding *bond = to_bond(d);
1408 u16 qid;
1409 int i, ret = count;
1410 char *delim;
1411 struct net_device *sdev = NULL;
1412
1413 if (!rtnl_trylock())
1414 return restart_syscall();
1415
1416 /* delim will point to queue id if successful */
1417 delim = strchr(buffer, ':');
1418 if (!delim)
1419 goto err_no_cmd;
1420
1421 /*
1422 * Terminate string that points to device name and bump it
1423 * up one, so we can read the queue id there.
1424 */
1425 *delim = '\0';
1426 if (sscanf(++delim, "%hd\n", &qid) != 1)
1427 goto err_no_cmd;
1428
1429 /* Check buffer length, valid ifname and queue id */
1430 if (strlen(buffer) > IFNAMSIZ ||
1431 !dev_valid_name(buffer) ||
1432 qid > bond->params.tx_queues)
1433 goto err_no_cmd;
1434
1435 /* Get the pointer to that interface if it exists */
1436 sdev = __dev_get_by_name(dev_net(bond->dev), buffer);
1437 if (!sdev)
1438 goto err_no_cmd;
1439
1440 read_lock(&bond->lock);
1441
1442 /* Search for thes slave and check for duplicate qids */
1443 update_slave = NULL;
1444 bond_for_each_slave(bond, slave, i) {
1445 if (sdev == slave->dev)
1446 /*
1447 * We don't need to check the matching
1448 * slave for dups, since we're overwriting it
1449 */
1450 update_slave = slave;
1451 else if (qid && qid == slave->queue_id) {
1452 goto err_no_cmd_unlock;
1453 }
1454 }
1455
1456 if (!update_slave)
1457 goto err_no_cmd_unlock;
1458
1459 /* Actually set the qids for the slave */
1460 update_slave->queue_id = qid;
1461
1462 read_unlock(&bond->lock);
1463out:
1464 rtnl_unlock();
1465 return ret;
1466
1467err_no_cmd_unlock:
1468 read_unlock(&bond->lock);
1469err_no_cmd:
1470 pr_info("invalid input for queue_id set for %s.\n",
1471 bond->dev->name);
1472 ret = -EPERM;
1473 goto out;
1474}
1475
1476static DEVICE_ATTR(queue_id, S_IRUGO | S_IWUSR, bonding_show_queue_id,
1477 bonding_store_queue_id);
1478
1479
1480/*
Andy Gospodarekebd8e492010-06-02 08:39:21 +00001481 * Show and set the all_slaves_active flag.
1482 */
1483static ssize_t bonding_show_slaves_active(struct device *d,
1484 struct device_attribute *attr,
1485 char *buf)
1486{
1487 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001488
Andy Gospodarekebd8e492010-06-02 08:39:21 +00001489 return sprintf(buf, "%d\n", bond->params.all_slaves_active);
1490}
1491
1492static ssize_t bonding_store_slaves_active(struct device *d,
1493 struct device_attribute *attr,
1494 const char *buf, size_t count)
1495{
1496 int i, new_value, ret = count;
1497 struct bonding *bond = to_bond(d);
1498 struct slave *slave;
1499
1500 if (sscanf(buf, "%d", &new_value) != 1) {
1501 pr_err("%s: no all_slaves_active value specified.\n",
1502 bond->dev->name);
1503 ret = -EINVAL;
1504 goto out;
1505 }
1506
1507 if (new_value == bond->params.all_slaves_active)
1508 goto out;
1509
1510 if ((new_value == 0) || (new_value == 1)) {
1511 bond->params.all_slaves_active = new_value;
1512 } else {
1513 pr_info("%s: Ignoring invalid all_slaves_active value %d.\n",
1514 bond->dev->name, new_value);
1515 ret = -EINVAL;
1516 goto out;
1517 }
1518
1519 bond_for_each_slave(bond, slave, i) {
Jiri Pirkoe30bc062011-03-12 03:14:37 +00001520 if (!bond_is_active_slave(slave)) {
Andy Gospodarekebd8e492010-06-02 08:39:21 +00001521 if (new_value)
Jiri Pirko2d7011c2011-03-16 08:46:43 +00001522 slave->inactive = 0;
Andy Gospodarekebd8e492010-06-02 08:39:21 +00001523 else
Jiri Pirko2d7011c2011-03-16 08:46:43 +00001524 slave->inactive = 1;
Andy Gospodarekebd8e492010-06-02 08:39:21 +00001525 }
1526 }
1527out:
Jiri Pirko672bda32011-01-25 11:03:25 +00001528 return ret;
Andy Gospodarekebd8e492010-06-02 08:39:21 +00001529}
1530static DEVICE_ATTR(all_slaves_active, S_IRUGO | S_IWUSR,
1531 bonding_show_slaves_active, bonding_store_slaves_active);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001532
Flavio Leitnerc2952c32010-10-05 14:23:59 +00001533/*
1534 * Show and set the number of IGMP membership reports to send on link failure
1535 */
1536static ssize_t bonding_show_resend_igmp(struct device *d,
Flavio Leitner94265cf2011-05-25 08:38:58 +00001537 struct device_attribute *attr,
1538 char *buf)
Flavio Leitnerc2952c32010-10-05 14:23:59 +00001539{
1540 struct bonding *bond = to_bond(d);
1541
1542 return sprintf(buf, "%d\n", bond->params.resend_igmp);
1543}
1544
1545static ssize_t bonding_store_resend_igmp(struct device *d,
Flavio Leitner94265cf2011-05-25 08:38:58 +00001546 struct device_attribute *attr,
1547 const char *buf, size_t count)
Flavio Leitnerc2952c32010-10-05 14:23:59 +00001548{
1549 int new_value, ret = count;
1550 struct bonding *bond = to_bond(d);
1551
1552 if (sscanf(buf, "%d", &new_value) != 1) {
1553 pr_err("%s: no resend_igmp value specified.\n",
1554 bond->dev->name);
1555 ret = -EINVAL;
1556 goto out;
1557 }
1558
Flavio Leitner94265cf2011-05-25 08:38:58 +00001559 if (new_value < 0 || new_value > 255) {
Flavio Leitnerc2952c32010-10-05 14:23:59 +00001560 pr_err("%s: Invalid resend_igmp value %d not in range 0-255; rejected.\n",
1561 bond->dev->name, new_value);
1562 ret = -EINVAL;
1563 goto out;
1564 }
1565
1566 pr_info("%s: Setting resend_igmp to %d.\n",
1567 bond->dev->name, new_value);
1568 bond->params.resend_igmp = new_value;
1569out:
1570 return ret;
1571}
1572
1573static DEVICE_ATTR(resend_igmp, S_IRUGO | S_IWUSR,
1574 bonding_show_resend_igmp, bonding_store_resend_igmp);
1575
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001576static struct attribute *per_bond_attrs[] = {
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001577 &dev_attr_slaves.attr,
1578 &dev_attr_mode.attr,
Jay Vosburghdd957c52007-10-09 19:57:24 -07001579 &dev_attr_fail_over_mac.attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001580 &dev_attr_arp_validate.attr,
1581 &dev_attr_arp_interval.attr,
1582 &dev_attr_arp_ip_target.attr,
1583 &dev_attr_downdelay.attr,
1584 &dev_attr_updelay.attr,
1585 &dev_attr_lacp_rate.attr,
Jay Vosburghfd989c82008-11-04 17:51:16 -08001586 &dev_attr_ad_select.attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001587 &dev_attr_xmit_hash_policy.attr,
Ben Hutchingsad246c92011-04-26 15:25:52 +00001588 &dev_attr_num_grat_arp.attr,
1589 &dev_attr_num_unsol_na.attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001590 &dev_attr_miimon.attr,
1591 &dev_attr_primary.attr,
Jiri Pirkoa5499522009-09-25 03:28:09 +00001592 &dev_attr_primary_reselect.attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001593 &dev_attr_use_carrier.attr,
1594 &dev_attr_active_slave.attr,
1595 &dev_attr_mii_status.attr,
1596 &dev_attr_ad_aggregator.attr,
1597 &dev_attr_ad_num_ports.attr,
1598 &dev_attr_ad_actor_key.attr,
1599 &dev_attr_ad_partner_key.attr,
1600 &dev_attr_ad_partner_mac.attr,
Andy Gospodarekbb1d9122010-06-02 08:40:18 +00001601 &dev_attr_queue_id.attr,
Andy Gospodarekebd8e492010-06-02 08:39:21 +00001602 &dev_attr_all_slaves_active.attr,
Flavio Leitnerc2952c32010-10-05 14:23:59 +00001603 &dev_attr_resend_igmp.attr,
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001604 NULL,
1605};
1606
1607static struct attribute_group bonding_group = {
1608 .name = "bonding",
1609 .attrs = per_bond_attrs,
1610};
1611
1612/*
1613 * Initialize sysfs. This sets up the bonding_masters file in
1614 * /sys/class/net.
1615 */
1616int bond_create_sysfs(void)
1617{
Jay Vosburghb8a97872008-06-13 18:12:04 -07001618 int ret;
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001619
Jay Vosburghb8a97872008-06-13 18:12:04 -07001620 ret = netdev_class_create_file(&class_attr_bonding_masters);
Jay Vosburgh877cbd32007-01-19 18:15:47 -08001621 /*
1622 * Permit multiple loads of the module by ignoring failures to
1623 * create the bonding_masters sysfs file. Bonding devices
1624 * created by second or subsequent loads of the module will
1625 * not be listed in, or controllable by, bonding_masters, but
1626 * will have the usual "bonding" sysfs directory.
1627 *
1628 * This is done to preserve backwards compatibility for
1629 * initscripts/sysconfig, which load bonding multiple times to
1630 * configure multiple bonding devices.
1631 */
1632 if (ret == -EEXIST) {
Stephen Hemminger38d2f382008-05-14 22:35:04 -07001633 /* Is someone being kinky and naming a device bonding_master? */
1634 if (__dev_get_by_name(&init_net,
1635 class_attr_bonding_masters.attr.name))
Joe Perchesa4aee5c2009-12-13 20:06:07 -08001636 pr_err("network device named %s already exists in sysfs",
Stephen Hemminger38d2f382008-05-14 22:35:04 -07001637 class_attr_bonding_masters.attr.name);
Stephen Hemminger130aa612009-06-11 05:46:04 -07001638 ret = 0;
Jay Vosburgh877cbd32007-01-19 18:15:47 -08001639 }
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001640
1641 return ret;
1642
1643}
1644
1645/*
1646 * Remove /sys/class/net/bonding_masters.
1647 */
1648void bond_destroy_sysfs(void)
1649{
Jay Vosburghb8a97872008-06-13 18:12:04 -07001650 netdev_class_remove_file(&class_attr_bonding_masters);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001651}
1652
1653/*
1654 * Initialize sysfs for each bond. This sets up and registers
1655 * the 'bondctl' directory for each individual bond under /sys/class/net.
1656 */
Eric W. Biederman6151b3d2009-10-29 14:18:22 +00001657void bond_prepare_sysfs_group(struct bonding *bond)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001658{
Eric W. Biederman6151b3d2009-10-29 14:18:22 +00001659 bond->dev->sysfs_groups[0] = &bonding_group;
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001660}
1661