blob: 11b76b352415f6dedad302133b97e952728032dd [file] [log] [blame]
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001
2/*
3 * Copyright(c) 2004-2005 Intel Corporation. All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 *
19 * The full GNU General Public License is included in this distribution in the
20 * file called LICENSE.
21 *
Mitch Williamsb76cdba2005-11-09 10:36:41 -080022 */
Mitch Williamsb76cdba2005-11-09 10:36:41 -080023#include <linux/kernel.h>
24#include <linux/module.h>
Mitch Williamsb76cdba2005-11-09 10:36:41 -080025#include <linux/device.h>
26#include <linux/sysdev.h>
27#include <linux/fs.h>
28#include <linux/types.h>
29#include <linux/string.h>
30#include <linux/netdevice.h>
31#include <linux/inetdevice.h>
32#include <linux/in.h>
33#include <linux/sysfs.h>
Mitch Williamsb76cdba2005-11-09 10:36:41 -080034#include <linux/ctype.h>
35#include <linux/inet.h>
36#include <linux/rtnetlink.h>
Eric W. Biederman881d9662007-09-17 11:56:21 -070037#include <net/net_namespace.h>
Mitch Williamsb76cdba2005-11-09 10:36:41 -080038
39/* #define BONDING_DEBUG 1 */
40#include "bonding.h"
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -070041#define to_dev(obj) container_of(obj,struct device,kobj)
Mitch Williamsb76cdba2005-11-09 10:36:41 -080042#define to_bond(cd) ((struct bonding *)(to_net_dev(cd)->priv))
43
44/*---------------------------- Declarations -------------------------------*/
45
46
47extern struct list_head bond_dev_list;
48extern struct bond_params bonding_defaults;
49extern struct bond_parm_tbl bond_mode_tbl[];
50extern struct bond_parm_tbl bond_lacp_tbl[];
51extern struct bond_parm_tbl xmit_hashtype_tbl[];
Jay Vosburghf5b2b962006-09-22 21:54:53 -070052extern struct bond_parm_tbl arp_validate_tbl[];
Mitch Williamsb76cdba2005-11-09 10:36:41 -080053
54static int expected_refcount = -1;
55static struct class *netdev_class;
56/*--------------------------- Data Structures -----------------------------*/
57
Robert P. J. Day3a4fa0a2007-10-19 23:10:43 +020058/* Bonding sysfs lock. Why can't we just use the subsystem lock?
Mitch Williamsb76cdba2005-11-09 10:36:41 -080059 * Because kobject_register tries to acquire the subsystem lock. If
60 * we already hold the lock (which we would if the user was creating
61 * a new bond through the sysfs interface), we deadlock.
62 * This lock is only needed when deleting a bond - we need to make sure
63 * that we don't collide with an ongoing ioctl.
64 */
65
66struct rw_semaphore bonding_rwsem;
67
68
69
70
71/*------------------------------ Functions --------------------------------*/
72
73/*
74 * "show" function for the bond_masters attribute.
75 * The class parameter is ignored.
76 */
Wagner Ferencb8843662007-12-06 23:40:30 -080077static ssize_t bonding_show_bonds(struct class *cls, char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -080078{
79 int res = 0;
80 struct bonding *bond;
81
82 down_read(&(bonding_rwsem));
83
84 list_for_each_entry(bond, &bond_dev_list, bond_list) {
85 if (res > (PAGE_SIZE - IFNAMSIZ)) {
86 /* not enough space for another interface name */
87 if ((PAGE_SIZE - res) > 10)
88 res = PAGE_SIZE - 10;
Wagner Ferencb8843662007-12-06 23:40:30 -080089 res += sprintf(buf + res, "++more++ ");
Mitch Williamsb76cdba2005-11-09 10:36:41 -080090 break;
91 }
Wagner Ferencb8843662007-12-06 23:40:30 -080092 res += sprintf(buf + res, "%s ", bond->dev->name);
Mitch Williamsb76cdba2005-11-09 10:36:41 -080093 }
Wagner Ferenc1dcdcd62007-12-06 23:40:31 -080094 if (res)
95 buf[res-1] = '\n'; /* eat the leftover space */
Mitch Williamsb76cdba2005-11-09 10:36:41 -080096 up_read(&(bonding_rwsem));
97 return res;
98}
99
100/*
101 * "store" function for the bond_masters attribute. This is what
102 * creates and deletes entire bonds.
103 *
104 * The class parameter is ignored.
105 *
106 */
107
108static ssize_t bonding_store_bonds(struct class *cls, const char *buffer, size_t count)
109{
110 char command[IFNAMSIZ + 1] = {0, };
111 char *ifname;
112 int res = count;
113 struct bonding *bond;
114 struct bonding *nxt;
115
116 down_write(&(bonding_rwsem));
117 sscanf(buffer, "%16s", command); /* IFNAMSIZ*/
118 ifname = command + 1;
119 if ((strlen(command) <= 1) ||
120 !dev_valid_name(ifname))
121 goto err_no_cmd;
122
123 if (command[0] == '+') {
124
125 /* Check to see if the bond already exists. */
126 list_for_each_entry_safe(bond, nxt, &bond_dev_list, bond_list)
127 if (strnicmp(bond->dev->name, ifname, IFNAMSIZ) == 0) {
128 printk(KERN_ERR DRV_NAME
129 ": cannot add bond %s; it already exists\n",
130 ifname);
131 res = -EPERM;
132 goto out;
133 }
134
135 printk(KERN_INFO DRV_NAME
136 ": %s is being created...\n", ifname);
137 if (bond_create(ifname, &bonding_defaults, &bond)) {
138 printk(KERN_INFO DRV_NAME
139 ": %s interface already exists. Bond creation failed.\n",
140 ifname);
141 res = -EPERM;
142 }
143 goto out;
144 }
145
146 if (command[0] == '-') {
147 list_for_each_entry_safe(bond, nxt, &bond_dev_list, bond_list)
148 if (strnicmp(bond->dev->name, ifname, IFNAMSIZ) == 0) {
149 rtnl_lock();
150 /* check the ref count on the bond's kobject.
151 * If it's > expected, then there's a file open,
152 * and we have to fail.
153 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700154 if (atomic_read(&bond->dev->dev.kobj.kref.refcount)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800155 > expected_refcount){
156 rtnl_unlock();
157 printk(KERN_INFO DRV_NAME
158 ": Unable remove bond %s due to open references.\n",
159 ifname);
160 res = -EPERM;
161 goto out;
162 }
163 printk(KERN_INFO DRV_NAME
164 ": %s is being deleted...\n",
165 bond->dev->name);
Moni Shouad90a1622007-10-09 19:43:43 -0700166 bond_destroy(bond);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800167 rtnl_unlock();
168 goto out;
169 }
170
171 printk(KERN_ERR DRV_NAME
172 ": unable to delete non-existent bond %s\n", ifname);
173 res = -ENODEV;
174 goto out;
175 }
176
177err_no_cmd:
178 printk(KERN_ERR DRV_NAME
179 ": no command found in bonding_masters. Use +ifname or -ifname.\n");
180 res = -EPERM;
181
182 /* Always return either count or an error. If you return 0, you'll
183 * get called forever, which is bad.
184 */
185out:
186 up_write(&(bonding_rwsem));
187 return res;
188}
189/* class attribute for bond_masters file. This ends up in /sys/class/net */
190static CLASS_ATTR(bonding_masters, S_IWUSR | S_IRUGO,
191 bonding_show_bonds, bonding_store_bonds);
192
193int bond_create_slave_symlinks(struct net_device *master, struct net_device *slave)
194{
195 char linkname[IFNAMSIZ+7];
196 int ret = 0;
197
198 /* first, create a link from the slave back to the master */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700199 ret = sysfs_create_link(&(slave->dev.kobj), &(master->dev.kobj),
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800200 "master");
201 if (ret)
202 return ret;
203 /* next, create a link from the master to the slave */
204 sprintf(linkname,"slave_%s",slave->name);
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700205 ret = sysfs_create_link(&(master->dev.kobj), &(slave->dev.kobj),
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800206 linkname);
207 return ret;
208
209}
210
211void bond_destroy_slave_symlinks(struct net_device *master, struct net_device *slave)
212{
213 char linkname[IFNAMSIZ+7];
214
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700215 sysfs_remove_link(&(slave->dev.kobj), "master");
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800216 sprintf(linkname,"slave_%s",slave->name);
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700217 sysfs_remove_link(&(master->dev.kobj), linkname);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800218}
219
220
221/*
222 * Show the slaves in the current bond.
223 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700224static ssize_t bonding_show_slaves(struct device *d,
225 struct device_attribute *attr, char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800226{
227 struct slave *slave;
228 int i, res = 0;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700229 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800230
Jay Vosburgh6603a6f2007-10-17 17:37:50 -0700231 read_lock(&bond->lock);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800232 bond_for_each_slave(bond, slave, i) {
233 if (res > (PAGE_SIZE - IFNAMSIZ)) {
234 /* not enough space for another interface name */
235 if ((PAGE_SIZE - res) > 10)
236 res = PAGE_SIZE - 10;
Wagner Ferenc7bd46502007-12-06 23:40:28 -0800237 res += sprintf(buf + res, "++more++ ");
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800238 break;
239 }
240 res += sprintf(buf + res, "%s ", slave->dev->name);
241 }
Jay Vosburgh6603a6f2007-10-17 17:37:50 -0700242 read_unlock(&bond->lock);
Wagner Ferenc1dcdcd62007-12-06 23:40:31 -0800243 if (res)
244 buf[res-1] = '\n'; /* eat the leftover space */
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800245 return res;
246}
247
248/*
249 * Set the slaves in the current bond. The bond interface must be
250 * up for this to succeed.
251 * This function is largely the same flow as bonding_update_bonds().
252 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700253static ssize_t bonding_store_slaves(struct device *d,
254 struct device_attribute *attr,
255 const char *buffer, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800256{
257 char command[IFNAMSIZ + 1] = { 0, };
258 char *ifname;
259 int i, res, found, ret = count;
Moni Shoua3158bf72007-10-09 19:43:41 -0700260 u32 original_mtu;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800261 struct slave *slave;
Luiz Fernando Capitulino3418db72006-02-01 00:54:34 -0800262 struct net_device *dev = NULL;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700263 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800264
265 /* Quick sanity check -- is the bond interface up? */
266 if (!(bond->dev->flags & IFF_UP)) {
Moni Shoua6b1bf092007-10-09 19:43:40 -0700267 printk(KERN_WARNING DRV_NAME
268 ": %s: doing slave updates when interface is down.\n",
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800269 bond->dev->name);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800270 }
271
272 /* Note: We can't hold bond->lock here, as bond_create grabs it. */
273
274 sscanf(buffer, "%16s", command); /* IFNAMSIZ*/
275 ifname = command + 1;
276 if ((strlen(command) <= 1) ||
277 !dev_valid_name(ifname))
278 goto err_no_cmd;
279
280 if (command[0] == '+') {
281
282 /* Got a slave name in ifname. Is it already in the list? */
283 found = 0;
Jay Vosburgh6603a6f2007-10-17 17:37:50 -0700284 read_lock(&bond->lock);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800285 bond_for_each_slave(bond, slave, i)
286 if (strnicmp(slave->dev->name, ifname, IFNAMSIZ) == 0) {
287 printk(KERN_ERR DRV_NAME
288 ": %s: Interface %s is already enslaved!\n",
289 bond->dev->name, ifname);
290 ret = -EPERM;
Jay Vosburgh6603a6f2007-10-17 17:37:50 -0700291 read_unlock(&bond->lock);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800292 goto out;
293 }
294
Jay Vosburgh6603a6f2007-10-17 17:37:50 -0700295 read_unlock(&bond->lock);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800296 printk(KERN_INFO DRV_NAME ": %s: Adding slave %s.\n",
297 bond->dev->name, ifname);
Eric W. Biederman881d9662007-09-17 11:56:21 -0700298 dev = dev_get_by_name(&init_net, ifname);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800299 if (!dev) {
300 printk(KERN_INFO DRV_NAME
301 ": %s: Interface %s does not exist!\n",
302 bond->dev->name, ifname);
303 ret = -EPERM;
304 goto out;
305 }
306 else
307 dev_put(dev);
308
309 if (dev->flags & IFF_UP) {
310 printk(KERN_ERR DRV_NAME
311 ": %s: Error: Unable to enslave %s "
312 "because it is already up.\n",
313 bond->dev->name, dev->name);
314 ret = -EPERM;
315 goto out;
316 }
317 /* If this is the first slave, then we need to set
318 the master's hardware address to be the same as the
319 slave's. */
320 if (!(*((u32 *) & (bond->dev->dev_addr[0])))) {
321 memcpy(bond->dev->dev_addr, dev->dev_addr,
322 dev->addr_len);
323 }
324
325 /* Set the slave's MTU to match the bond */
Moni Shoua3158bf72007-10-09 19:43:41 -0700326 original_mtu = dev->mtu;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800327 if (dev->mtu != bond->dev->mtu) {
328 if (dev->change_mtu) {
329 res = dev->change_mtu(dev,
330 bond->dev->mtu);
331 if (res) {
332 ret = res;
333 goto out;
334 }
335 } else {
336 dev->mtu = bond->dev->mtu;
337 }
338 }
339 rtnl_lock();
340 res = bond_enslave(bond->dev, dev);
Moni Shoua3158bf72007-10-09 19:43:41 -0700341 bond_for_each_slave(bond, slave, i)
342 if (strnicmp(slave->dev->name, ifname, IFNAMSIZ) == 0)
343 slave->original_mtu = original_mtu;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800344 rtnl_unlock();
345 if (res) {
346 ret = res;
347 }
348 goto out;
349 }
350
351 if (command[0] == '-') {
352 dev = NULL;
353 bond_for_each_slave(bond, slave, i)
354 if (strnicmp(slave->dev->name, ifname, IFNAMSIZ) == 0) {
355 dev = slave->dev;
Moni Shoua3158bf72007-10-09 19:43:41 -0700356 original_mtu = slave->original_mtu;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800357 break;
358 }
359 if (dev) {
360 printk(KERN_INFO DRV_NAME ": %s: Removing slave %s\n",
361 bond->dev->name, dev->name);
362 rtnl_lock();
Moni Shouad90a1622007-10-09 19:43:43 -0700363 if (bond->setup_by_slave)
364 res = bond_release_and_destroy(bond->dev, dev);
365 else
366 res = bond_release(bond->dev, dev);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800367 rtnl_unlock();
368 if (res) {
369 ret = res;
370 goto out;
371 }
372 /* set the slave MTU to the default */
373 if (dev->change_mtu) {
Moni Shoua3158bf72007-10-09 19:43:41 -0700374 dev->change_mtu(dev, original_mtu);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800375 } else {
Moni Shoua3158bf72007-10-09 19:43:41 -0700376 dev->mtu = original_mtu;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800377 }
378 }
379 else {
380 printk(KERN_ERR DRV_NAME ": unable to remove non-existent slave %s for bond %s.\n",
381 ifname, bond->dev->name);
382 ret = -ENODEV;
383 }
384 goto out;
385 }
386
387err_no_cmd:
388 printk(KERN_ERR DRV_NAME ": no command found in slaves file for bond %s. Use +ifname or -ifname.\n", bond->dev->name);
389 ret = -EPERM;
390
391out:
392 return ret;
393}
394
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700395static DEVICE_ATTR(slaves, S_IRUGO | S_IWUSR, bonding_show_slaves, bonding_store_slaves);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800396
397/*
398 * Show and set the bonding mode. The bond interface must be down to
399 * change the mode.
400 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700401static ssize_t bonding_show_mode(struct device *d,
402 struct device_attribute *attr, char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800403{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700404 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800405
406 return sprintf(buf, "%s %d\n",
407 bond_mode_tbl[bond->params.mode].modename,
Wagner Ferenc7bd46502007-12-06 23:40:28 -0800408 bond->params.mode);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800409}
410
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700411static ssize_t bonding_store_mode(struct device *d,
412 struct device_attribute *attr,
413 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800414{
415 int new_value, ret = count;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700416 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800417
418 if (bond->dev->flags & IFF_UP) {
419 printk(KERN_ERR DRV_NAME
420 ": unable to update mode of %s because interface is up.\n",
421 bond->dev->name);
422 ret = -EPERM;
423 goto out;
424 }
425
426 new_value = bond_parse_parm((char *)buf, bond_mode_tbl);
427 if (new_value < 0) {
428 printk(KERN_ERR DRV_NAME
429 ": %s: Ignoring invalid mode value %.*s.\n",
430 bond->dev->name,
431 (int)strlen(buf) - 1, buf);
432 ret = -EINVAL;
433 goto out;
434 } else {
Jay Vosburgh8f903c72006-02-21 16:36:44 -0800435 if (bond->params.mode == BOND_MODE_8023AD)
436 bond_unset_master_3ad_flags(bond);
437
438 if (bond->params.mode == BOND_MODE_ALB)
439 bond_unset_master_alb_flags(bond);
440
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800441 bond->params.mode = new_value;
442 bond_set_mode_ops(bond, bond->params.mode);
443 printk(KERN_INFO DRV_NAME ": %s: setting mode to %s (%d).\n",
444 bond->dev->name, bond_mode_tbl[new_value].modename, new_value);
445 }
446out:
447 return ret;
448}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700449static DEVICE_ATTR(mode, S_IRUGO | S_IWUSR, bonding_show_mode, bonding_store_mode);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800450
451/*
452 * Show and set the bonding transmit hash method. The bond interface must be down to
453 * change the xmit hash policy.
454 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700455static ssize_t bonding_show_xmit_hash(struct device *d,
456 struct device_attribute *attr,
457 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800458{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700459 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800460
Wagner Ferenc8e4b9322007-12-06 23:40:32 -0800461 return sprintf(buf, "%s %d\n",
462 xmit_hashtype_tbl[bond->params.xmit_policy].modename,
463 bond->params.xmit_policy);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800464}
465
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700466static ssize_t bonding_store_xmit_hash(struct device *d,
467 struct device_attribute *attr,
468 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800469{
470 int new_value, ret = count;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700471 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800472
473 if (bond->dev->flags & IFF_UP) {
474 printk(KERN_ERR DRV_NAME
475 "%s: Interface is up. Unable to update xmit policy.\n",
476 bond->dev->name);
477 ret = -EPERM;
478 goto out;
479 }
480
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800481 new_value = bond_parse_parm((char *)buf, xmit_hashtype_tbl);
482 if (new_value < 0) {
483 printk(KERN_ERR DRV_NAME
484 ": %s: Ignoring invalid xmit hash policy value %.*s.\n",
485 bond->dev->name,
486 (int)strlen(buf) - 1, buf);
487 ret = -EINVAL;
488 goto out;
489 } else {
490 bond->params.xmit_policy = new_value;
491 bond_set_mode_ops(bond, bond->params.mode);
492 printk(KERN_INFO DRV_NAME ": %s: setting xmit hash policy to %s (%d).\n",
493 bond->dev->name, xmit_hashtype_tbl[new_value].modename, new_value);
494 }
495out:
496 return ret;
497}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700498static DEVICE_ATTR(xmit_hash_policy, S_IRUGO | S_IWUSR, bonding_show_xmit_hash, bonding_store_xmit_hash);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800499
500/*
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700501 * Show and set arp_validate.
502 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700503static ssize_t bonding_show_arp_validate(struct device *d,
504 struct device_attribute *attr,
505 char *buf)
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700506{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700507 struct bonding *bond = to_bond(d);
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700508
509 return sprintf(buf, "%s %d\n",
510 arp_validate_tbl[bond->params.arp_validate].modename,
Wagner Ferenc7bd46502007-12-06 23:40:28 -0800511 bond->params.arp_validate);
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700512}
513
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700514static ssize_t bonding_store_arp_validate(struct device *d,
515 struct device_attribute *attr,
516 const char *buf, size_t count)
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700517{
518 int new_value;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700519 struct bonding *bond = to_bond(d);
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700520
521 new_value = bond_parse_parm((char *)buf, arp_validate_tbl);
522 if (new_value < 0) {
523 printk(KERN_ERR DRV_NAME
524 ": %s: Ignoring invalid arp_validate value %s\n",
525 bond->dev->name, buf);
526 return -EINVAL;
527 }
528 if (new_value && (bond->params.mode != BOND_MODE_ACTIVEBACKUP)) {
529 printk(KERN_ERR DRV_NAME
530 ": %s: arp_validate only supported in active-backup mode.\n",
531 bond->dev->name);
532 return -EINVAL;
533 }
534 printk(KERN_INFO DRV_NAME ": %s: setting arp_validate to %s (%d).\n",
535 bond->dev->name, arp_validate_tbl[new_value].modename,
536 new_value);
537
538 if (!bond->params.arp_validate && new_value) {
539 bond_register_arp(bond);
540 } else if (bond->params.arp_validate && !new_value) {
541 bond_unregister_arp(bond);
542 }
543
544 bond->params.arp_validate = new_value;
545
546 return count;
547}
548
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700549static DEVICE_ATTR(arp_validate, S_IRUGO | S_IWUSR, bonding_show_arp_validate, bonding_store_arp_validate);
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700550
551/*
Jay Vosburghdd957c52007-10-09 19:57:24 -0700552 * Show and store fail_over_mac. User only allowed to change the
553 * value when there are no slaves.
554 */
555static ssize_t bonding_show_fail_over_mac(struct device *d, struct device_attribute *attr, char *buf)
556{
557 struct bonding *bond = to_bond(d);
558
559 return sprintf(buf, "%d\n", bond->params.fail_over_mac) + 1;
560}
561
562static ssize_t bonding_store_fail_over_mac(struct device *d, struct device_attribute *attr, const char *buf, size_t count)
563{
564 int new_value;
565 int ret = count;
566 struct bonding *bond = to_bond(d);
567
568 if (bond->slave_cnt != 0) {
569 printk(KERN_ERR DRV_NAME
570 ": %s: Can't alter fail_over_mac with slaves in bond.\n",
571 bond->dev->name);
572 ret = -EPERM;
573 goto out;
574 }
575
576 if (sscanf(buf, "%d", &new_value) != 1) {
577 printk(KERN_ERR DRV_NAME
578 ": %s: no fail_over_mac value specified.\n",
579 bond->dev->name);
580 ret = -EINVAL;
581 goto out;
582 }
583
584 if ((new_value == 0) || (new_value == 1)) {
585 bond->params.fail_over_mac = new_value;
586 printk(KERN_INFO DRV_NAME ": %s: Setting fail_over_mac to %d.\n",
587 bond->dev->name, new_value);
588 } else {
589 printk(KERN_INFO DRV_NAME
590 ": %s: Ignoring invalid fail_over_mac value %d.\n",
591 bond->dev->name, new_value);
592 }
593out:
594 return ret;
595}
596
597static DEVICE_ATTR(fail_over_mac, S_IRUGO | S_IWUSR, bonding_show_fail_over_mac, bonding_store_fail_over_mac);
598
599/*
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800600 * Show and set the arp timer interval. There are two tricky bits
601 * here. First, if ARP monitoring is activated, then we must disable
602 * MII monitoring. Second, if the ARP timer isn't running, we must
603 * start it.
604 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700605static ssize_t bonding_show_arp_interval(struct device *d,
606 struct device_attribute *attr,
607 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800608{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700609 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800610
Wagner Ferenc7bd46502007-12-06 23:40:28 -0800611 return sprintf(buf, "%d\n", bond->params.arp_interval);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800612}
613
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700614static ssize_t bonding_store_arp_interval(struct device *d,
615 struct device_attribute *attr,
616 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800617{
618 int new_value, ret = count;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700619 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800620
621 if (sscanf(buf, "%d", &new_value) != 1) {
622 printk(KERN_ERR DRV_NAME
623 ": %s: no arp_interval value specified.\n",
624 bond->dev->name);
625 ret = -EINVAL;
626 goto out;
627 }
628 if (new_value < 0) {
629 printk(KERN_ERR DRV_NAME
630 ": %s: Invalid arp_interval value %d not in range 1-%d; rejected.\n",
631 bond->dev->name, new_value, INT_MAX);
632 ret = -EINVAL;
633 goto out;
634 }
635
636 printk(KERN_INFO DRV_NAME
637 ": %s: Setting ARP monitoring interval to %d.\n",
638 bond->dev->name, new_value);
639 bond->params.arp_interval = new_value;
640 if (bond->params.miimon) {
641 printk(KERN_INFO DRV_NAME
642 ": %s: ARP monitoring cannot be used with MII monitoring. "
643 "%s Disabling MII monitoring.\n",
644 bond->dev->name, bond->dev->name);
645 bond->params.miimon = 0;
Jay Vosburgh1b76b312007-10-17 17:37:45 -0700646 if (delayed_work_pending(&bond->mii_work)) {
647 cancel_delayed_work(&bond->mii_work);
648 flush_workqueue(bond->wq);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800649 }
650 }
651 if (!bond->params.arp_targets[0]) {
652 printk(KERN_INFO DRV_NAME
653 ": %s: ARP monitoring has been set up, "
654 "but no ARP targets have been specified.\n",
655 bond->dev->name);
656 }
657 if (bond->dev->flags & IFF_UP) {
658 /* If the interface is up, we may need to fire off
659 * the ARP timer. If the interface is down, the
660 * timer will get fired off when the open function
661 * is called.
662 */
Jay Vosburgh1b76b312007-10-17 17:37:45 -0700663 if (!delayed_work_pending(&bond->arp_work)) {
664 if (bond->params.mode == BOND_MODE_ACTIVEBACKUP)
665 INIT_DELAYED_WORK(&bond->arp_work,
666 bond_activebackup_arp_mon);
667 else
668 INIT_DELAYED_WORK(&bond->arp_work,
669 bond_loadbalance_arp_mon);
670
671 queue_delayed_work(bond->wq, &bond->arp_work, 0);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800672 }
673 }
674
675out:
676 return ret;
677}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700678static DEVICE_ATTR(arp_interval, S_IRUGO | S_IWUSR , bonding_show_arp_interval, bonding_store_arp_interval);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800679
680/*
681 * Show and set the arp targets.
682 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700683static ssize_t bonding_show_arp_targets(struct device *d,
684 struct device_attribute *attr,
685 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800686{
687 int i, res = 0;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700688 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800689
690 for (i = 0; i < BOND_MAX_ARP_TARGETS; i++) {
691 if (bond->params.arp_targets[i])
692 res += sprintf(buf + res, "%u.%u.%u.%u ",
693 NIPQUAD(bond->params.arp_targets[i]));
694 }
Wagner Ferenc1dcdcd62007-12-06 23:40:31 -0800695 if (res)
696 buf[res-1] = '\n'; /* eat the leftover space */
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800697 return res;
698}
699
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700700static ssize_t bonding_store_arp_targets(struct device *d,
701 struct device_attribute *attr,
702 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800703{
Al Virod3bb52b2007-08-22 20:06:58 -0400704 __be32 newtarget;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800705 int i = 0, done = 0, ret = count;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700706 struct bonding *bond = to_bond(d);
Al Virod3bb52b2007-08-22 20:06:58 -0400707 __be32 *targets;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800708
709 targets = bond->params.arp_targets;
710 newtarget = in_aton(buf + 1);
711 /* look for adds */
712 if (buf[0] == '+') {
Al Virod3bb52b2007-08-22 20:06:58 -0400713 if ((newtarget == 0) || (newtarget == htonl(INADDR_BROADCAST))) {
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800714 printk(KERN_ERR DRV_NAME
715 ": %s: invalid ARP target %u.%u.%u.%u specified for addition\n",
716 bond->dev->name, NIPQUAD(newtarget));
717 ret = -EINVAL;
718 goto out;
719 }
720 /* look for an empty slot to put the target in, and check for dupes */
721 for (i = 0; (i < BOND_MAX_ARP_TARGETS); i++) {
722 if (targets[i] == newtarget) { /* duplicate */
723 printk(KERN_ERR DRV_NAME
724 ": %s: ARP target %u.%u.%u.%u is already present\n",
725 bond->dev->name, NIPQUAD(newtarget));
726 if (done)
727 targets[i] = 0;
728 ret = -EINVAL;
729 goto out;
730 }
731 if (targets[i] == 0 && !done) {
732 printk(KERN_INFO DRV_NAME
733 ": %s: adding ARP target %d.%d.%d.%d.\n",
734 bond->dev->name, NIPQUAD(newtarget));
735 done = 1;
736 targets[i] = newtarget;
737 }
738 }
739 if (!done) {
740 printk(KERN_ERR DRV_NAME
741 ": %s: ARP target table is full!\n",
742 bond->dev->name);
743 ret = -EINVAL;
744 goto out;
745 }
746
747 }
748 else if (buf[0] == '-') {
Al Virod3bb52b2007-08-22 20:06:58 -0400749 if ((newtarget == 0) || (newtarget == htonl(INADDR_BROADCAST))) {
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800750 printk(KERN_ERR DRV_NAME
751 ": %s: invalid ARP target %d.%d.%d.%d specified for removal\n",
752 bond->dev->name, NIPQUAD(newtarget));
753 ret = -EINVAL;
754 goto out;
755 }
756
757 for (i = 0; (i < BOND_MAX_ARP_TARGETS); i++) {
758 if (targets[i] == newtarget) {
759 printk(KERN_INFO DRV_NAME
760 ": %s: removing ARP target %d.%d.%d.%d.\n",
761 bond->dev->name, NIPQUAD(newtarget));
762 targets[i] = 0;
763 done = 1;
764 }
765 }
766 if (!done) {
767 printk(KERN_INFO DRV_NAME
768 ": %s: unable to remove nonexistent ARP target %d.%d.%d.%d.\n",
769 bond->dev->name, NIPQUAD(newtarget));
770 ret = -EINVAL;
771 goto out;
772 }
773 }
774 else {
775 printk(KERN_ERR DRV_NAME ": no command found in arp_ip_targets file for bond %s. Use +<addr> or -<addr>.\n",
776 bond->dev->name);
777 ret = -EPERM;
778 goto out;
779 }
780
781out:
782 return ret;
783}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700784static DEVICE_ATTR(arp_ip_target, S_IRUGO | S_IWUSR , bonding_show_arp_targets, bonding_store_arp_targets);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800785
786/*
787 * Show and set the up and down delays. These must be multiples of the
788 * MII monitoring value, and are stored internally as the multiplier.
789 * Thus, we must translate to MS for the real world.
790 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700791static ssize_t bonding_show_downdelay(struct device *d,
792 struct device_attribute *attr,
793 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800794{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700795 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800796
Wagner Ferenc7bd46502007-12-06 23:40:28 -0800797 return sprintf(buf, "%d\n", bond->params.downdelay * bond->params.miimon);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800798}
799
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700800static ssize_t bonding_store_downdelay(struct device *d,
801 struct device_attribute *attr,
802 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800803{
804 int new_value, ret = count;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700805 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800806
807 if (!(bond->params.miimon)) {
808 printk(KERN_ERR DRV_NAME
809 ": %s: Unable to set down delay as MII monitoring is disabled\n",
810 bond->dev->name);
811 ret = -EPERM;
812 goto out;
813 }
814
815 if (sscanf(buf, "%d", &new_value) != 1) {
816 printk(KERN_ERR DRV_NAME
817 ": %s: no down delay value specified.\n",
818 bond->dev->name);
819 ret = -EINVAL;
820 goto out;
821 }
822 if (new_value < 0) {
823 printk(KERN_ERR DRV_NAME
824 ": %s: Invalid down delay value %d not in range %d-%d; rejected.\n",
825 bond->dev->name, new_value, 1, INT_MAX);
826 ret = -EINVAL;
827 goto out;
828 } else {
829 if ((new_value % bond->params.miimon) != 0) {
830 printk(KERN_WARNING DRV_NAME
831 ": %s: Warning: down delay (%d) is not a multiple "
832 "of miimon (%d), delay rounded to %d ms\n",
833 bond->dev->name, new_value, bond->params.miimon,
834 (new_value / bond->params.miimon) *
835 bond->params.miimon);
836 }
837 bond->params.downdelay = new_value / bond->params.miimon;
838 printk(KERN_INFO DRV_NAME ": %s: Setting down delay to %d.\n",
839 bond->dev->name, bond->params.downdelay * bond->params.miimon);
840
841 }
842
843out:
844 return ret;
845}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700846static DEVICE_ATTR(downdelay, S_IRUGO | S_IWUSR , bonding_show_downdelay, bonding_store_downdelay);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800847
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700848static ssize_t bonding_show_updelay(struct device *d,
849 struct device_attribute *attr,
850 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800851{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700852 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800853
Wagner Ferenc7bd46502007-12-06 23:40:28 -0800854 return sprintf(buf, "%d\n", bond->params.updelay * bond->params.miimon);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800855
856}
857
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700858static ssize_t bonding_store_updelay(struct device *d,
859 struct device_attribute *attr,
860 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800861{
862 int new_value, ret = count;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700863 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800864
865 if (!(bond->params.miimon)) {
866 printk(KERN_ERR DRV_NAME
867 ": %s: Unable to set up delay as MII monitoring is disabled\n",
868 bond->dev->name);
869 ret = -EPERM;
870 goto out;
871 }
872
873 if (sscanf(buf, "%d", &new_value) != 1) {
874 printk(KERN_ERR DRV_NAME
875 ": %s: no up delay value specified.\n",
876 bond->dev->name);
877 ret = -EINVAL;
878 goto out;
879 }
880 if (new_value < 0) {
881 printk(KERN_ERR DRV_NAME
882 ": %s: Invalid down delay value %d not in range %d-%d; rejected.\n",
883 bond->dev->name, new_value, 1, INT_MAX);
884 ret = -EINVAL;
885 goto out;
886 } else {
887 if ((new_value % bond->params.miimon) != 0) {
888 printk(KERN_WARNING DRV_NAME
889 ": %s: Warning: up delay (%d) is not a multiple "
890 "of miimon (%d), updelay rounded to %d ms\n",
891 bond->dev->name, new_value, bond->params.miimon,
892 (new_value / bond->params.miimon) *
893 bond->params.miimon);
894 }
895 bond->params.updelay = new_value / bond->params.miimon;
896 printk(KERN_INFO DRV_NAME ": %s: Setting up delay to %d.\n",
897 bond->dev->name, bond->params.updelay * bond->params.miimon);
898
899 }
900
901out:
902 return ret;
903}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700904static DEVICE_ATTR(updelay, S_IRUGO | S_IWUSR , bonding_show_updelay, bonding_store_updelay);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800905
906/*
907 * Show and set the LACP interval. Interface must be down, and the mode
908 * must be set to 802.3ad mode.
909 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700910static ssize_t bonding_show_lacp(struct device *d,
911 struct device_attribute *attr,
912 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800913{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700914 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800915
916 return sprintf(buf, "%s %d\n",
917 bond_lacp_tbl[bond->params.lacp_fast].modename,
Wagner Ferenc7bd46502007-12-06 23:40:28 -0800918 bond->params.lacp_fast);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800919}
920
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700921static ssize_t bonding_store_lacp(struct device *d,
922 struct device_attribute *attr,
923 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800924{
925 int new_value, ret = count;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700926 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800927
928 if (bond->dev->flags & IFF_UP) {
929 printk(KERN_ERR DRV_NAME
930 ": %s: Unable to update LACP rate because interface is up.\n",
931 bond->dev->name);
932 ret = -EPERM;
933 goto out;
934 }
935
936 if (bond->params.mode != BOND_MODE_8023AD) {
937 printk(KERN_ERR DRV_NAME
938 ": %s: Unable to update LACP rate because bond is not in 802.3ad mode.\n",
939 bond->dev->name);
940 ret = -EPERM;
941 goto out;
942 }
943
944 new_value = bond_parse_parm((char *)buf, bond_lacp_tbl);
945
946 if ((new_value == 1) || (new_value == 0)) {
947 bond->params.lacp_fast = new_value;
948 printk(KERN_INFO DRV_NAME
949 ": %s: Setting LACP rate to %s (%d).\n",
950 bond->dev->name, bond_lacp_tbl[new_value].modename, new_value);
951 } else {
952 printk(KERN_ERR DRV_NAME
953 ": %s: Ignoring invalid LACP rate value %.*s.\n",
954 bond->dev->name, (int)strlen(buf) - 1, buf);
955 ret = -EINVAL;
956 }
957out:
958 return ret;
959}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700960static DEVICE_ATTR(lacp_rate, S_IRUGO | S_IWUSR, bonding_show_lacp, bonding_store_lacp);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800961
962/*
963 * Show and set the MII monitor interval. There are two tricky bits
964 * here. First, if MII monitoring is activated, then we must disable
965 * ARP monitoring. Second, if the timer isn't running, we must
966 * start it.
967 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700968static ssize_t bonding_show_miimon(struct device *d,
969 struct device_attribute *attr,
970 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800971{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700972 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800973
Wagner Ferenc7bd46502007-12-06 23:40:28 -0800974 return sprintf(buf, "%d\n", bond->params.miimon);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800975}
976
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700977static ssize_t bonding_store_miimon(struct device *d,
978 struct device_attribute *attr,
979 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800980{
981 int new_value, ret = count;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700982 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800983
984 if (sscanf(buf, "%d", &new_value) != 1) {
985 printk(KERN_ERR DRV_NAME
986 ": %s: no miimon value specified.\n",
987 bond->dev->name);
988 ret = -EINVAL;
989 goto out;
990 }
991 if (new_value < 0) {
992 printk(KERN_ERR DRV_NAME
993 ": %s: Invalid miimon value %d not in range %d-%d; rejected.\n",
994 bond->dev->name, new_value, 1, INT_MAX);
995 ret = -EINVAL;
996 goto out;
997 } else {
998 printk(KERN_INFO DRV_NAME
999 ": %s: Setting MII monitoring interval to %d.\n",
1000 bond->dev->name, new_value);
1001 bond->params.miimon = new_value;
1002 if(bond->params.updelay)
1003 printk(KERN_INFO DRV_NAME
1004 ": %s: Note: Updating updelay (to %d) "
1005 "since it is a multiple of the miimon value.\n",
1006 bond->dev->name,
1007 bond->params.updelay * bond->params.miimon);
1008 if(bond->params.downdelay)
1009 printk(KERN_INFO DRV_NAME
1010 ": %s: Note: Updating downdelay (to %d) "
1011 "since it is a multiple of the miimon value.\n",
1012 bond->dev->name,
1013 bond->params.downdelay * bond->params.miimon);
1014 if (bond->params.arp_interval) {
1015 printk(KERN_INFO DRV_NAME
1016 ": %s: MII monitoring cannot be used with "
1017 "ARP monitoring. Disabling ARP monitoring...\n",
1018 bond->dev->name);
1019 bond->params.arp_interval = 0;
Jay Vosburghf5b2b962006-09-22 21:54:53 -07001020 if (bond->params.arp_validate) {
1021 bond_unregister_arp(bond);
1022 bond->params.arp_validate =
1023 BOND_ARP_VALIDATE_NONE;
1024 }
Jay Vosburgh1b76b312007-10-17 17:37:45 -07001025 if (delayed_work_pending(&bond->arp_work)) {
1026 cancel_delayed_work(&bond->arp_work);
1027 flush_workqueue(bond->wq);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001028 }
1029 }
1030
1031 if (bond->dev->flags & IFF_UP) {
1032 /* If the interface is up, we may need to fire off
1033 * the MII timer. If the interface is down, the
1034 * timer will get fired off when the open function
1035 * is called.
1036 */
Jay Vosburgh1b76b312007-10-17 17:37:45 -07001037 if (!delayed_work_pending(&bond->mii_work)) {
1038 INIT_DELAYED_WORK(&bond->mii_work,
1039 bond_mii_monitor);
1040 queue_delayed_work(bond->wq,
1041 &bond->mii_work, 0);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001042 }
1043 }
1044 }
1045out:
1046 return ret;
1047}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001048static DEVICE_ATTR(miimon, S_IRUGO | S_IWUSR, bonding_show_miimon, bonding_store_miimon);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001049
1050/*
1051 * Show and set the primary slave. The store function is much
1052 * simpler than bonding_store_slaves function because it only needs to
1053 * handle one interface name.
1054 * The bond must be a mode that supports a primary for this be
1055 * set.
1056 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001057static ssize_t bonding_show_primary(struct device *d,
1058 struct device_attribute *attr,
1059 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001060{
1061 int count = 0;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001062 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001063
1064 if (bond->primary_slave)
Wagner Ferenc7bd46502007-12-06 23:40:28 -08001065 count = sprintf(buf, "%s\n", bond->primary_slave->dev->name);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001066
1067 return count;
1068}
1069
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001070static ssize_t bonding_store_primary(struct device *d,
1071 struct device_attribute *attr,
1072 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001073{
1074 int i;
1075 struct slave *slave;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001076 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001077
1078 write_lock_bh(&bond->lock);
1079 if (!USES_PRIMARY(bond->params.mode)) {
1080 printk(KERN_INFO DRV_NAME
1081 ": %s: Unable to set primary slave; %s is in mode %d\n",
1082 bond->dev->name, bond->dev->name, bond->params.mode);
1083 } else {
1084 bond_for_each_slave(bond, slave, i) {
1085 if (strnicmp
1086 (slave->dev->name, buf,
1087 strlen(slave->dev->name)) == 0) {
1088 printk(KERN_INFO DRV_NAME
1089 ": %s: Setting %s as primary slave.\n",
1090 bond->dev->name, slave->dev->name);
1091 bond->primary_slave = slave;
1092 bond_select_active_slave(bond);
1093 goto out;
1094 }
1095 }
1096
1097 /* if we got here, then we didn't match the name of any slave */
1098
1099 if (strlen(buf) == 0 || buf[0] == '\n') {
1100 printk(KERN_INFO DRV_NAME
1101 ": %s: Setting primary slave to None.\n",
1102 bond->dev->name);
Luiz Fernando Capitulino3418db72006-02-01 00:54:34 -08001103 bond->primary_slave = NULL;
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001104 bond_select_active_slave(bond);
1105 } else {
1106 printk(KERN_INFO DRV_NAME
1107 ": %s: Unable to set %.*s as primary slave as it is not a slave.\n",
1108 bond->dev->name, (int)strlen(buf) - 1, buf);
1109 }
1110 }
1111out:
1112 write_unlock_bh(&bond->lock);
Jay Vosburgh6603a6f2007-10-17 17:37:50 -07001113
1114 rtnl_unlock();
1115
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001116 return count;
1117}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001118static DEVICE_ATTR(primary, S_IRUGO | S_IWUSR, bonding_show_primary, bonding_store_primary);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001119
1120/*
1121 * Show and set the use_carrier flag.
1122 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001123static ssize_t bonding_show_carrier(struct device *d,
1124 struct device_attribute *attr,
1125 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001126{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001127 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001128
Wagner Ferenc7bd46502007-12-06 23:40:28 -08001129 return sprintf(buf, "%d\n", bond->params.use_carrier);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001130}
1131
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001132static ssize_t bonding_store_carrier(struct device *d,
1133 struct device_attribute *attr,
1134 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001135{
1136 int new_value, ret = count;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001137 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001138
1139
1140 if (sscanf(buf, "%d", &new_value) != 1) {
1141 printk(KERN_ERR DRV_NAME
1142 ": %s: no use_carrier value specified.\n",
1143 bond->dev->name);
1144 ret = -EINVAL;
1145 goto out;
1146 }
1147 if ((new_value == 0) || (new_value == 1)) {
1148 bond->params.use_carrier = new_value;
1149 printk(KERN_INFO DRV_NAME ": %s: Setting use_carrier to %d.\n",
1150 bond->dev->name, new_value);
1151 } else {
1152 printk(KERN_INFO DRV_NAME
1153 ": %s: Ignoring invalid use_carrier value %d.\n",
1154 bond->dev->name, new_value);
1155 }
1156out:
1157 return count;
1158}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001159static DEVICE_ATTR(use_carrier, S_IRUGO | S_IWUSR, bonding_show_carrier, bonding_store_carrier);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001160
1161
1162/*
1163 * Show and set currently active_slave.
1164 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001165static ssize_t bonding_show_active_slave(struct device *d,
1166 struct device_attribute *attr,
1167 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001168{
1169 struct slave *curr;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001170 struct bonding *bond = to_bond(d);
Wagner Ferenc16cd0162007-12-06 23:40:29 -08001171 int count = 0;
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001172
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001173 read_lock(&bond->curr_slave_lock);
1174 curr = bond->curr_active_slave;
1175 read_unlock(&bond->curr_slave_lock);
1176
1177 if (USES_PRIMARY(bond->params.mode) && curr)
Wagner Ferenc7bd46502007-12-06 23:40:28 -08001178 count = sprintf(buf, "%s\n", curr->dev->name);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001179 return count;
1180}
1181
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001182static ssize_t bonding_store_active_slave(struct device *d,
1183 struct device_attribute *attr,
1184 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001185{
1186 int i;
1187 struct slave *slave;
1188 struct slave *old_active = NULL;
1189 struct slave *new_active = NULL;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001190 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001191
Jay Vosburgh1466a212007-11-06 13:33:28 -08001192 rtnl_lock();
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001193 write_lock_bh(&bond->lock);
Jay Vosburgh1466a212007-11-06 13:33:28 -08001194
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001195 if (!USES_PRIMARY(bond->params.mode)) {
1196 printk(KERN_INFO DRV_NAME
1197 ": %s: Unable to change active slave; %s is in mode %d\n",
1198 bond->dev->name, bond->dev->name, bond->params.mode);
1199 } else {
1200 bond_for_each_slave(bond, slave, i) {
1201 if (strnicmp
1202 (slave->dev->name, buf,
1203 strlen(slave->dev->name)) == 0) {
1204 old_active = bond->curr_active_slave;
1205 new_active = slave;
Jay Vosburgha50d8de2006-09-22 21:53:25 -07001206 if (new_active == old_active) {
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001207 /* do nothing */
1208 printk(KERN_INFO DRV_NAME
1209 ": %s: %s is already the current active slave.\n",
1210 bond->dev->name, slave->dev->name);
1211 goto out;
1212 }
1213 else {
1214 if ((new_active) &&
1215 (old_active) &&
1216 (new_active->link == BOND_LINK_UP) &&
1217 IS_UP(new_active->dev)) {
1218 printk(KERN_INFO DRV_NAME
1219 ": %s: Setting %s as active slave.\n",
1220 bond->dev->name, slave->dev->name);
1221 bond_change_active_slave(bond, new_active);
1222 }
1223 else {
1224 printk(KERN_INFO DRV_NAME
1225 ": %s: Could not set %s as active slave; "
1226 "either %s is down or the link is down.\n",
1227 bond->dev->name, slave->dev->name,
1228 slave->dev->name);
1229 }
1230 goto out;
1231 }
1232 }
1233 }
1234
1235 /* if we got here, then we didn't match the name of any slave */
1236
1237 if (strlen(buf) == 0 || buf[0] == '\n') {
1238 printk(KERN_INFO DRV_NAME
1239 ": %s: Setting active slave to None.\n",
1240 bond->dev->name);
Luiz Fernando Capitulino3418db72006-02-01 00:54:34 -08001241 bond->primary_slave = NULL;
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001242 bond_select_active_slave(bond);
1243 } else {
1244 printk(KERN_INFO DRV_NAME
1245 ": %s: Unable to set %.*s as active slave as it is not a slave.\n",
1246 bond->dev->name, (int)strlen(buf) - 1, buf);
1247 }
1248 }
1249out:
1250 write_unlock_bh(&bond->lock);
Jay Vosburgh6603a6f2007-10-17 17:37:50 -07001251 rtnl_unlock();
1252
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001253 return count;
1254
1255}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001256static DEVICE_ATTR(active_slave, S_IRUGO | S_IWUSR, bonding_show_active_slave, bonding_store_active_slave);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001257
1258
1259/*
1260 * Show link status of the bond interface.
1261 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001262static ssize_t bonding_show_mii_status(struct device *d,
1263 struct device_attribute *attr,
1264 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001265{
1266 struct slave *curr;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001267 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001268
1269 read_lock(&bond->curr_slave_lock);
1270 curr = bond->curr_active_slave;
1271 read_unlock(&bond->curr_slave_lock);
1272
Wagner Ferenc7bd46502007-12-06 23:40:28 -08001273 return sprintf(buf, "%s\n", (curr) ? "up" : "down");
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001274}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001275static DEVICE_ATTR(mii_status, S_IRUGO, bonding_show_mii_status, NULL);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001276
1277
1278/*
1279 * Show current 802.3ad aggregator ID.
1280 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001281static ssize_t bonding_show_ad_aggregator(struct device *d,
1282 struct device_attribute *attr,
1283 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001284{
1285 int count = 0;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001286 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001287
1288 if (bond->params.mode == BOND_MODE_8023AD) {
1289 struct ad_info ad_info;
Wagner Ferenc7bd46502007-12-06 23:40:28 -08001290 count = sprintf(buf, "%d\n", (bond_3ad_get_active_agg_info(bond, &ad_info)) ? 0 : ad_info.aggregator_id);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001291 }
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001292
1293 return count;
1294}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001295static DEVICE_ATTR(ad_aggregator, S_IRUGO, bonding_show_ad_aggregator, NULL);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001296
1297
1298/*
1299 * Show number of active 802.3ad ports.
1300 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001301static ssize_t bonding_show_ad_num_ports(struct device *d,
1302 struct device_attribute *attr,
1303 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001304{
1305 int count = 0;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001306 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001307
1308 if (bond->params.mode == BOND_MODE_8023AD) {
1309 struct ad_info ad_info;
Wagner Ferenc7bd46502007-12-06 23:40:28 -08001310 count = sprintf(buf, "%d\n", (bond_3ad_get_active_agg_info(bond, &ad_info)) ? 0: ad_info.ports);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001311 }
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001312
1313 return count;
1314}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001315static DEVICE_ATTR(ad_num_ports, S_IRUGO, bonding_show_ad_num_ports, NULL);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001316
1317
1318/*
1319 * Show current 802.3ad actor key.
1320 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001321static ssize_t bonding_show_ad_actor_key(struct device *d,
1322 struct device_attribute *attr,
1323 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001324{
1325 int count = 0;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001326 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001327
1328 if (bond->params.mode == BOND_MODE_8023AD) {
1329 struct ad_info ad_info;
Wagner Ferenc7bd46502007-12-06 23:40:28 -08001330 count = sprintf(buf, "%d\n", (bond_3ad_get_active_agg_info(bond, &ad_info)) ? 0 : ad_info.actor_key);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001331 }
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001332
1333 return count;
1334}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001335static DEVICE_ATTR(ad_actor_key, S_IRUGO, bonding_show_ad_actor_key, NULL);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001336
1337
1338/*
1339 * Show current 802.3ad partner key.
1340 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001341static ssize_t bonding_show_ad_partner_key(struct device *d,
1342 struct device_attribute *attr,
1343 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001344{
1345 int count = 0;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001346 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001347
1348 if (bond->params.mode == BOND_MODE_8023AD) {
1349 struct ad_info ad_info;
Wagner Ferenc7bd46502007-12-06 23:40:28 -08001350 count = sprintf(buf, "%d\n", (bond_3ad_get_active_agg_info(bond, &ad_info)) ? 0 : ad_info.partner_key);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001351 }
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001352
1353 return count;
1354}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001355static DEVICE_ATTR(ad_partner_key, S_IRUGO, bonding_show_ad_partner_key, NULL);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001356
1357
1358/*
1359 * Show current 802.3ad partner mac.
1360 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001361static ssize_t bonding_show_ad_partner_mac(struct device *d,
1362 struct device_attribute *attr,
1363 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001364{
1365 int count = 0;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001366 struct bonding *bond = to_bond(d);
Joe Perches0795af52007-10-03 17:59:30 -07001367 DECLARE_MAC_BUF(mac);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001368
1369 if (bond->params.mode == BOND_MODE_8023AD) {
1370 struct ad_info ad_info;
1371 if (!bond_3ad_get_active_agg_info(bond, &ad_info)) {
Joe Perches0795af52007-10-03 17:59:30 -07001372 count = sprintf(buf,"%s\n",
Wagner Ferenc7bd46502007-12-06 23:40:28 -08001373 print_mac(mac, ad_info.partner_system));
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001374 }
1375 }
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001376
1377 return count;
1378}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001379static DEVICE_ATTR(ad_partner_mac, S_IRUGO, bonding_show_ad_partner_mac, NULL);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001380
1381
1382
1383static struct attribute *per_bond_attrs[] = {
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001384 &dev_attr_slaves.attr,
1385 &dev_attr_mode.attr,
Jay Vosburghdd957c52007-10-09 19:57:24 -07001386 &dev_attr_fail_over_mac.attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001387 &dev_attr_arp_validate.attr,
1388 &dev_attr_arp_interval.attr,
1389 &dev_attr_arp_ip_target.attr,
1390 &dev_attr_downdelay.attr,
1391 &dev_attr_updelay.attr,
1392 &dev_attr_lacp_rate.attr,
1393 &dev_attr_xmit_hash_policy.attr,
1394 &dev_attr_miimon.attr,
1395 &dev_attr_primary.attr,
1396 &dev_attr_use_carrier.attr,
1397 &dev_attr_active_slave.attr,
1398 &dev_attr_mii_status.attr,
1399 &dev_attr_ad_aggregator.attr,
1400 &dev_attr_ad_num_ports.attr,
1401 &dev_attr_ad_actor_key.attr,
1402 &dev_attr_ad_partner_key.attr,
1403 &dev_attr_ad_partner_mac.attr,
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001404 NULL,
1405};
1406
1407static struct attribute_group bonding_group = {
1408 .name = "bonding",
1409 .attrs = per_bond_attrs,
1410};
1411
1412/*
1413 * Initialize sysfs. This sets up the bonding_masters file in
1414 * /sys/class/net.
1415 */
1416int bond_create_sysfs(void)
1417{
1418 int ret = 0;
1419 struct bonding *firstbond;
1420
1421 init_rwsem(&bonding_rwsem);
1422
1423 /* get the netdev class pointer */
1424 firstbond = container_of(bond_dev_list.next, struct bonding, bond_list);
1425 if (!firstbond)
1426 return -ENODEV;
1427
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001428 netdev_class = firstbond->dev->dev.class;
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001429 if (!netdev_class)
1430 return -ENODEV;
1431
1432 ret = class_create_file(netdev_class, &class_attr_bonding_masters);
Jay Vosburgh877cbd32007-01-19 18:15:47 -08001433 /*
1434 * Permit multiple loads of the module by ignoring failures to
1435 * create the bonding_masters sysfs file. Bonding devices
1436 * created by second or subsequent loads of the module will
1437 * not be listed in, or controllable by, bonding_masters, but
1438 * will have the usual "bonding" sysfs directory.
1439 *
1440 * This is done to preserve backwards compatibility for
1441 * initscripts/sysconfig, which load bonding multiple times to
1442 * configure multiple bonding devices.
1443 */
1444 if (ret == -EEXIST) {
1445 netdev_class = NULL;
1446 return 0;
1447 }
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001448
1449 return ret;
1450
1451}
1452
1453/*
1454 * Remove /sys/class/net/bonding_masters.
1455 */
1456void bond_destroy_sysfs(void)
1457{
1458 if (netdev_class)
1459 class_remove_file(netdev_class, &class_attr_bonding_masters);
1460}
1461
1462/*
1463 * Initialize sysfs for each bond. This sets up and registers
1464 * the 'bondctl' directory for each individual bond under /sys/class/net.
1465 */
1466int bond_create_sysfs_entry(struct bonding *bond)
1467{
1468 struct net_device *dev = bond->dev;
1469 int err;
1470
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001471 err = sysfs_create_group(&(dev->dev.kobj), &bonding_group);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001472 if (err) {
1473 printk(KERN_EMERG "eek! didn't create group!\n");
1474 }
1475
1476 if (expected_refcount < 1)
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001477 expected_refcount = atomic_read(&bond->dev->dev.kobj.kref.refcount);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001478
1479 return err;
1480}
1481/*
1482 * Remove sysfs entries for each bond.
1483 */
1484void bond_destroy_sysfs_entry(struct bonding *bond)
1485{
1486 struct net_device *dev = bond->dev;
1487
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001488 sysfs_remove_group(&(dev->dev.kobj), &bonding_group);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001489}
1490