blob: 979c2d05ff9c91c19ab7dbee9964cfc608afc299 [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;
Jay Vosburgh027ea042008-01-17 16:25:02 -0800112 int rv, res = count;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800113 struct bonding *bond;
114 struct bonding *nxt;
115
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800116 sscanf(buffer, "%16s", command); /* IFNAMSIZ*/
117 ifname = command + 1;
118 if ((strlen(command) <= 1) ||
119 !dev_valid_name(ifname))
120 goto err_no_cmd;
121
122 if (command[0] == '+') {
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800123 printk(KERN_INFO DRV_NAME
124 ": %s is being created...\n", ifname);
Jay Vosburgh027ea042008-01-17 16:25:02 -0800125 rv = bond_create(ifname, &bonding_defaults, &bond);
126 if (rv) {
127 printk(KERN_INFO DRV_NAME ": Bond creation failed.\n");
128 res = rv;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800129 }
130 goto out;
131 }
132
133 if (command[0] == '-') {
Jay Vosburgh027ea042008-01-17 16:25:02 -0800134 rtnl_lock();
135 down_write(&bonding_rwsem);
136
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800137 list_for_each_entry_safe(bond, nxt, &bond_dev_list, bond_list)
138 if (strnicmp(bond->dev->name, ifname, IFNAMSIZ) == 0) {
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800139 /* check the ref count on the bond's kobject.
140 * If it's > expected, then there's a file open,
141 * and we have to fail.
142 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700143 if (atomic_read(&bond->dev->dev.kobj.kref.refcount)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800144 > expected_refcount){
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800145 printk(KERN_INFO DRV_NAME
146 ": Unable remove bond %s due to open references.\n",
147 ifname);
148 res = -EPERM;
149 goto out;
150 }
151 printk(KERN_INFO DRV_NAME
152 ": %s is being deleted...\n",
153 bond->dev->name);
Moni Shouad90a1622007-10-09 19:43:43 -0700154 bond_destroy(bond);
Jay Vosburgh027ea042008-01-17 16:25:02 -0800155 up_write(&bonding_rwsem);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800156 rtnl_unlock();
157 goto out;
158 }
159
160 printk(KERN_ERR DRV_NAME
161 ": unable to delete non-existent bond %s\n", ifname);
162 res = -ENODEV;
Jay Vosburgh027ea042008-01-17 16:25:02 -0800163 up_write(&bonding_rwsem);
164 rtnl_unlock();
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800165 goto out;
166 }
167
168err_no_cmd:
169 printk(KERN_ERR DRV_NAME
170 ": no command found in bonding_masters. Use +ifname or -ifname.\n");
171 res = -EPERM;
172
173 /* Always return either count or an error. If you return 0, you'll
174 * get called forever, which is bad.
175 */
176out:
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800177 return res;
178}
179/* class attribute for bond_masters file. This ends up in /sys/class/net */
180static CLASS_ATTR(bonding_masters, S_IWUSR | S_IRUGO,
181 bonding_show_bonds, bonding_store_bonds);
182
183int bond_create_slave_symlinks(struct net_device *master, struct net_device *slave)
184{
185 char linkname[IFNAMSIZ+7];
186 int ret = 0;
187
188 /* first, create a link from the slave back to the master */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700189 ret = sysfs_create_link(&(slave->dev.kobj), &(master->dev.kobj),
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800190 "master");
191 if (ret)
192 return ret;
193 /* next, create a link from the master to the slave */
194 sprintf(linkname,"slave_%s",slave->name);
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700195 ret = sysfs_create_link(&(master->dev.kobj), &(slave->dev.kobj),
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800196 linkname);
197 return ret;
198
199}
200
201void bond_destroy_slave_symlinks(struct net_device *master, struct net_device *slave)
202{
203 char linkname[IFNAMSIZ+7];
204
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700205 sysfs_remove_link(&(slave->dev.kobj), "master");
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800206 sprintf(linkname,"slave_%s",slave->name);
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700207 sysfs_remove_link(&(master->dev.kobj), linkname);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800208}
209
210
211/*
212 * Show the slaves in the current bond.
213 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700214static ssize_t bonding_show_slaves(struct device *d,
215 struct device_attribute *attr, char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800216{
217 struct slave *slave;
218 int i, res = 0;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700219 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800220
Jay Vosburgh6603a6f2007-10-17 17:37:50 -0700221 read_lock(&bond->lock);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800222 bond_for_each_slave(bond, slave, i) {
223 if (res > (PAGE_SIZE - IFNAMSIZ)) {
224 /* not enough space for another interface name */
225 if ((PAGE_SIZE - res) > 10)
226 res = PAGE_SIZE - 10;
Wagner Ferenc7bd46502007-12-06 23:40:28 -0800227 res += sprintf(buf + res, "++more++ ");
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800228 break;
229 }
230 res += sprintf(buf + res, "%s ", slave->dev->name);
231 }
Jay Vosburgh6603a6f2007-10-17 17:37:50 -0700232 read_unlock(&bond->lock);
Wagner Ferenc1dcdcd62007-12-06 23:40:31 -0800233 if (res)
234 buf[res-1] = '\n'; /* eat the leftover space */
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800235 return res;
236}
237
238/*
239 * Set the slaves in the current bond. The bond interface must be
240 * up for this to succeed.
241 * This function is largely the same flow as bonding_update_bonds().
242 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700243static ssize_t bonding_store_slaves(struct device *d,
244 struct device_attribute *attr,
245 const char *buffer, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800246{
247 char command[IFNAMSIZ + 1] = { 0, };
248 char *ifname;
249 int i, res, found, ret = count;
Moni Shoua3158bf72007-10-09 19:43:41 -0700250 u32 original_mtu;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800251 struct slave *slave;
Luiz Fernando Capitulino3418db72006-02-01 00:54:34 -0800252 struct net_device *dev = NULL;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700253 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800254
255 /* Quick sanity check -- is the bond interface up? */
256 if (!(bond->dev->flags & IFF_UP)) {
Moni Shoua6b1bf092007-10-09 19:43:40 -0700257 printk(KERN_WARNING DRV_NAME
258 ": %s: doing slave updates when interface is down.\n",
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800259 bond->dev->name);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800260 }
261
262 /* Note: We can't hold bond->lock here, as bond_create grabs it. */
263
Jay Vosburgh027ea042008-01-17 16:25:02 -0800264 rtnl_lock();
265 down_write(&(bonding_rwsem));
266
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800267 sscanf(buffer, "%16s", command); /* IFNAMSIZ*/
268 ifname = command + 1;
269 if ((strlen(command) <= 1) ||
270 !dev_valid_name(ifname))
271 goto err_no_cmd;
272
273 if (command[0] == '+') {
274
275 /* Got a slave name in ifname. Is it already in the list? */
276 found = 0;
Jay Vosburgh6603a6f2007-10-17 17:37:50 -0700277 read_lock(&bond->lock);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800278 bond_for_each_slave(bond, slave, i)
279 if (strnicmp(slave->dev->name, ifname, IFNAMSIZ) == 0) {
280 printk(KERN_ERR DRV_NAME
281 ": %s: Interface %s is already enslaved!\n",
282 bond->dev->name, ifname);
283 ret = -EPERM;
Jay Vosburgh6603a6f2007-10-17 17:37:50 -0700284 read_unlock(&bond->lock);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800285 goto out;
286 }
287
Jay Vosburgh6603a6f2007-10-17 17:37:50 -0700288 read_unlock(&bond->lock);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800289 printk(KERN_INFO DRV_NAME ": %s: Adding slave %s.\n",
290 bond->dev->name, ifname);
Eric W. Biederman881d9662007-09-17 11:56:21 -0700291 dev = dev_get_by_name(&init_net, ifname);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800292 if (!dev) {
293 printk(KERN_INFO DRV_NAME
294 ": %s: Interface %s does not exist!\n",
295 bond->dev->name, ifname);
296 ret = -EPERM;
297 goto out;
298 }
299 else
300 dev_put(dev);
301
302 if (dev->flags & IFF_UP) {
303 printk(KERN_ERR DRV_NAME
304 ": %s: Error: Unable to enslave %s "
305 "because it is already up.\n",
306 bond->dev->name, dev->name);
307 ret = -EPERM;
308 goto out;
309 }
310 /* If this is the first slave, then we need to set
311 the master's hardware address to be the same as the
312 slave's. */
313 if (!(*((u32 *) & (bond->dev->dev_addr[0])))) {
314 memcpy(bond->dev->dev_addr, dev->dev_addr,
315 dev->addr_len);
316 }
317
318 /* Set the slave's MTU to match the bond */
Moni Shoua3158bf72007-10-09 19:43:41 -0700319 original_mtu = dev->mtu;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800320 if (dev->mtu != bond->dev->mtu) {
321 if (dev->change_mtu) {
322 res = dev->change_mtu(dev,
323 bond->dev->mtu);
324 if (res) {
325 ret = res;
326 goto out;
327 }
328 } else {
329 dev->mtu = bond->dev->mtu;
330 }
331 }
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800332 res = bond_enslave(bond->dev, dev);
Moni Shoua3158bf72007-10-09 19:43:41 -0700333 bond_for_each_slave(bond, slave, i)
334 if (strnicmp(slave->dev->name, ifname, IFNAMSIZ) == 0)
335 slave->original_mtu = original_mtu;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800336 if (res) {
337 ret = res;
338 }
339 goto out;
340 }
341
342 if (command[0] == '-') {
343 dev = NULL;
David S. Miller6952d892008-03-28 16:15:38 -0700344 original_mtu = 0;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800345 bond_for_each_slave(bond, slave, i)
346 if (strnicmp(slave->dev->name, ifname, IFNAMSIZ) == 0) {
347 dev = slave->dev;
Moni Shoua3158bf72007-10-09 19:43:41 -0700348 original_mtu = slave->original_mtu;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800349 break;
350 }
351 if (dev) {
352 printk(KERN_INFO DRV_NAME ": %s: Removing slave %s\n",
353 bond->dev->name, dev->name);
Moni Shouad90a1622007-10-09 19:43:43 -0700354 if (bond->setup_by_slave)
355 res = bond_release_and_destroy(bond->dev, dev);
356 else
357 res = bond_release(bond->dev, dev);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800358 if (res) {
359 ret = res;
360 goto out;
361 }
362 /* set the slave MTU to the default */
363 if (dev->change_mtu) {
Moni Shoua3158bf72007-10-09 19:43:41 -0700364 dev->change_mtu(dev, original_mtu);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800365 } else {
Moni Shoua3158bf72007-10-09 19:43:41 -0700366 dev->mtu = original_mtu;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800367 }
368 }
369 else {
370 printk(KERN_ERR DRV_NAME ": unable to remove non-existent slave %s for bond %s.\n",
371 ifname, bond->dev->name);
372 ret = -ENODEV;
373 }
374 goto out;
375 }
376
377err_no_cmd:
378 printk(KERN_ERR DRV_NAME ": no command found in slaves file for bond %s. Use +ifname or -ifname.\n", bond->dev->name);
379 ret = -EPERM;
380
381out:
Jay Vosburgh027ea042008-01-17 16:25:02 -0800382 up_write(&(bonding_rwsem));
383 rtnl_unlock();
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800384 return ret;
385}
386
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700387static DEVICE_ATTR(slaves, S_IRUGO | S_IWUSR, bonding_show_slaves, bonding_store_slaves);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800388
389/*
390 * Show and set the bonding mode. The bond interface must be down to
391 * change the mode.
392 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700393static ssize_t bonding_show_mode(struct device *d,
394 struct device_attribute *attr, char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800395{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700396 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800397
398 return sprintf(buf, "%s %d\n",
399 bond_mode_tbl[bond->params.mode].modename,
Wagner Ferenc7bd46502007-12-06 23:40:28 -0800400 bond->params.mode);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800401}
402
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700403static ssize_t bonding_store_mode(struct device *d,
404 struct device_attribute *attr,
405 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800406{
407 int new_value, ret = count;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700408 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800409
410 if (bond->dev->flags & IFF_UP) {
411 printk(KERN_ERR DRV_NAME
412 ": unable to update mode of %s because interface is up.\n",
413 bond->dev->name);
414 ret = -EPERM;
415 goto out;
416 }
417
Jay Vosburghece95f72008-01-17 16:25:01 -0800418 new_value = bond_parse_parm(buf, bond_mode_tbl);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800419 if (new_value < 0) {
420 printk(KERN_ERR DRV_NAME
421 ": %s: Ignoring invalid mode value %.*s.\n",
422 bond->dev->name,
423 (int)strlen(buf) - 1, buf);
424 ret = -EINVAL;
425 goto out;
426 } else {
Jay Vosburgh8f903c72006-02-21 16:36:44 -0800427 if (bond->params.mode == BOND_MODE_8023AD)
428 bond_unset_master_3ad_flags(bond);
429
430 if (bond->params.mode == BOND_MODE_ALB)
431 bond_unset_master_alb_flags(bond);
432
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800433 bond->params.mode = new_value;
434 bond_set_mode_ops(bond, bond->params.mode);
435 printk(KERN_INFO DRV_NAME ": %s: setting mode to %s (%d).\n",
436 bond->dev->name, bond_mode_tbl[new_value].modename, new_value);
437 }
438out:
439 return ret;
440}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700441static DEVICE_ATTR(mode, S_IRUGO | S_IWUSR, bonding_show_mode, bonding_store_mode);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800442
443/*
444 * Show and set the bonding transmit hash method. The bond interface must be down to
445 * change the xmit hash policy.
446 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700447static ssize_t bonding_show_xmit_hash(struct device *d,
448 struct device_attribute *attr,
449 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800450{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700451 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800452
Wagner Ferenc8e4b9322007-12-06 23:40:32 -0800453 return sprintf(buf, "%s %d\n",
454 xmit_hashtype_tbl[bond->params.xmit_policy].modename,
455 bond->params.xmit_policy);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800456}
457
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700458static ssize_t bonding_store_xmit_hash(struct device *d,
459 struct device_attribute *attr,
460 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800461{
462 int new_value, ret = count;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700463 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800464
465 if (bond->dev->flags & IFF_UP) {
466 printk(KERN_ERR DRV_NAME
467 "%s: Interface is up. Unable to update xmit policy.\n",
468 bond->dev->name);
469 ret = -EPERM;
470 goto out;
471 }
472
Jay Vosburghece95f72008-01-17 16:25:01 -0800473 new_value = bond_parse_parm(buf, xmit_hashtype_tbl);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800474 if (new_value < 0) {
475 printk(KERN_ERR DRV_NAME
476 ": %s: Ignoring invalid xmit hash policy value %.*s.\n",
477 bond->dev->name,
478 (int)strlen(buf) - 1, buf);
479 ret = -EINVAL;
480 goto out;
481 } else {
482 bond->params.xmit_policy = new_value;
483 bond_set_mode_ops(bond, bond->params.mode);
484 printk(KERN_INFO DRV_NAME ": %s: setting xmit hash policy to %s (%d).\n",
485 bond->dev->name, xmit_hashtype_tbl[new_value].modename, new_value);
486 }
487out:
488 return ret;
489}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700490static DEVICE_ATTR(xmit_hash_policy, S_IRUGO | S_IWUSR, bonding_show_xmit_hash, bonding_store_xmit_hash);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800491
492/*
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700493 * Show and set arp_validate.
494 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700495static ssize_t bonding_show_arp_validate(struct device *d,
496 struct device_attribute *attr,
497 char *buf)
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700498{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700499 struct bonding *bond = to_bond(d);
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700500
501 return sprintf(buf, "%s %d\n",
502 arp_validate_tbl[bond->params.arp_validate].modename,
Wagner Ferenc7bd46502007-12-06 23:40:28 -0800503 bond->params.arp_validate);
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700504}
505
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700506static ssize_t bonding_store_arp_validate(struct device *d,
507 struct device_attribute *attr,
508 const char *buf, size_t count)
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700509{
510 int new_value;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700511 struct bonding *bond = to_bond(d);
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700512
Jay Vosburghece95f72008-01-17 16:25:01 -0800513 new_value = bond_parse_parm(buf, arp_validate_tbl);
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700514 if (new_value < 0) {
515 printk(KERN_ERR DRV_NAME
516 ": %s: Ignoring invalid arp_validate value %s\n",
517 bond->dev->name, buf);
518 return -EINVAL;
519 }
520 if (new_value && (bond->params.mode != BOND_MODE_ACTIVEBACKUP)) {
521 printk(KERN_ERR DRV_NAME
522 ": %s: arp_validate only supported in active-backup mode.\n",
523 bond->dev->name);
524 return -EINVAL;
525 }
526 printk(KERN_INFO DRV_NAME ": %s: setting arp_validate to %s (%d).\n",
527 bond->dev->name, arp_validate_tbl[new_value].modename,
528 new_value);
529
530 if (!bond->params.arp_validate && new_value) {
531 bond_register_arp(bond);
532 } else if (bond->params.arp_validate && !new_value) {
533 bond_unregister_arp(bond);
534 }
535
536 bond->params.arp_validate = new_value;
537
538 return count;
539}
540
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700541static DEVICE_ATTR(arp_validate, S_IRUGO | S_IWUSR, bonding_show_arp_validate, bonding_store_arp_validate);
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700542
543/*
Jay Vosburghdd957c52007-10-09 19:57:24 -0700544 * Show and store fail_over_mac. User only allowed to change the
545 * value when there are no slaves.
546 */
547static ssize_t bonding_show_fail_over_mac(struct device *d, struct device_attribute *attr, char *buf)
548{
549 struct bonding *bond = to_bond(d);
550
551 return sprintf(buf, "%d\n", bond->params.fail_over_mac) + 1;
552}
553
554static ssize_t bonding_store_fail_over_mac(struct device *d, struct device_attribute *attr, const char *buf, size_t count)
555{
556 int new_value;
557 int ret = count;
558 struct bonding *bond = to_bond(d);
559
560 if (bond->slave_cnt != 0) {
561 printk(KERN_ERR DRV_NAME
562 ": %s: Can't alter fail_over_mac with slaves in bond.\n",
563 bond->dev->name);
564 ret = -EPERM;
565 goto out;
566 }
567
568 if (sscanf(buf, "%d", &new_value) != 1) {
569 printk(KERN_ERR DRV_NAME
570 ": %s: no fail_over_mac value specified.\n",
571 bond->dev->name);
572 ret = -EINVAL;
573 goto out;
574 }
575
576 if ((new_value == 0) || (new_value == 1)) {
577 bond->params.fail_over_mac = new_value;
578 printk(KERN_INFO DRV_NAME ": %s: Setting fail_over_mac to %d.\n",
579 bond->dev->name, new_value);
580 } else {
581 printk(KERN_INFO DRV_NAME
582 ": %s: Ignoring invalid fail_over_mac value %d.\n",
583 bond->dev->name, new_value);
584 }
585out:
586 return ret;
587}
588
589static DEVICE_ATTR(fail_over_mac, S_IRUGO | S_IWUSR, bonding_show_fail_over_mac, bonding_store_fail_over_mac);
590
591/*
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800592 * Show and set the arp timer interval. There are two tricky bits
593 * here. First, if ARP monitoring is activated, then we must disable
594 * MII monitoring. Second, if the ARP timer isn't running, we must
595 * start it.
596 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700597static ssize_t bonding_show_arp_interval(struct device *d,
598 struct device_attribute *attr,
599 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800600{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700601 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800602
Wagner Ferenc7bd46502007-12-06 23:40:28 -0800603 return sprintf(buf, "%d\n", bond->params.arp_interval);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800604}
605
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700606static ssize_t bonding_store_arp_interval(struct device *d,
607 struct device_attribute *attr,
608 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800609{
610 int new_value, ret = count;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700611 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800612
613 if (sscanf(buf, "%d", &new_value) != 1) {
614 printk(KERN_ERR DRV_NAME
615 ": %s: no arp_interval value specified.\n",
616 bond->dev->name);
617 ret = -EINVAL;
618 goto out;
619 }
620 if (new_value < 0) {
621 printk(KERN_ERR DRV_NAME
622 ": %s: Invalid arp_interval value %d not in range 1-%d; rejected.\n",
623 bond->dev->name, new_value, INT_MAX);
624 ret = -EINVAL;
625 goto out;
626 }
627
628 printk(KERN_INFO DRV_NAME
629 ": %s: Setting ARP monitoring interval to %d.\n",
630 bond->dev->name, new_value);
631 bond->params.arp_interval = new_value;
632 if (bond->params.miimon) {
633 printk(KERN_INFO DRV_NAME
634 ": %s: ARP monitoring cannot be used with MII monitoring. "
635 "%s Disabling MII monitoring.\n",
636 bond->dev->name, bond->dev->name);
637 bond->params.miimon = 0;
Jay Vosburgh1b76b312007-10-17 17:37:45 -0700638 if (delayed_work_pending(&bond->mii_work)) {
639 cancel_delayed_work(&bond->mii_work);
640 flush_workqueue(bond->wq);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800641 }
642 }
643 if (!bond->params.arp_targets[0]) {
644 printk(KERN_INFO DRV_NAME
645 ": %s: ARP monitoring has been set up, "
646 "but no ARP targets have been specified.\n",
647 bond->dev->name);
648 }
649 if (bond->dev->flags & IFF_UP) {
650 /* If the interface is up, we may need to fire off
651 * the ARP timer. If the interface is down, the
652 * timer will get fired off when the open function
653 * is called.
654 */
Jay Vosburgh1b76b312007-10-17 17:37:45 -0700655 if (!delayed_work_pending(&bond->arp_work)) {
656 if (bond->params.mode == BOND_MODE_ACTIVEBACKUP)
657 INIT_DELAYED_WORK(&bond->arp_work,
658 bond_activebackup_arp_mon);
659 else
660 INIT_DELAYED_WORK(&bond->arp_work,
661 bond_loadbalance_arp_mon);
662
663 queue_delayed_work(bond->wq, &bond->arp_work, 0);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800664 }
665 }
666
667out:
668 return ret;
669}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700670static DEVICE_ATTR(arp_interval, S_IRUGO | S_IWUSR , bonding_show_arp_interval, bonding_store_arp_interval);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800671
672/*
673 * Show and set the arp targets.
674 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700675static ssize_t bonding_show_arp_targets(struct device *d,
676 struct device_attribute *attr,
677 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800678{
679 int i, res = 0;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700680 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800681
682 for (i = 0; i < BOND_MAX_ARP_TARGETS; i++) {
683 if (bond->params.arp_targets[i])
684 res += sprintf(buf + res, "%u.%u.%u.%u ",
685 NIPQUAD(bond->params.arp_targets[i]));
686 }
Wagner Ferenc1dcdcd62007-12-06 23:40:31 -0800687 if (res)
688 buf[res-1] = '\n'; /* eat the leftover space */
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800689 return res;
690}
691
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700692static ssize_t bonding_store_arp_targets(struct device *d,
693 struct device_attribute *attr,
694 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800695{
Al Virod3bb52b2007-08-22 20:06:58 -0400696 __be32 newtarget;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800697 int i = 0, done = 0, ret = count;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700698 struct bonding *bond = to_bond(d);
Al Virod3bb52b2007-08-22 20:06:58 -0400699 __be32 *targets;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800700
701 targets = bond->params.arp_targets;
702 newtarget = in_aton(buf + 1);
703 /* look for adds */
704 if (buf[0] == '+') {
Al Virod3bb52b2007-08-22 20:06:58 -0400705 if ((newtarget == 0) || (newtarget == htonl(INADDR_BROADCAST))) {
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800706 printk(KERN_ERR DRV_NAME
707 ": %s: invalid ARP target %u.%u.%u.%u specified for addition\n",
708 bond->dev->name, NIPQUAD(newtarget));
709 ret = -EINVAL;
710 goto out;
711 }
712 /* look for an empty slot to put the target in, and check for dupes */
713 for (i = 0; (i < BOND_MAX_ARP_TARGETS); i++) {
714 if (targets[i] == newtarget) { /* duplicate */
715 printk(KERN_ERR DRV_NAME
716 ": %s: ARP target %u.%u.%u.%u is already present\n",
717 bond->dev->name, NIPQUAD(newtarget));
718 if (done)
719 targets[i] = 0;
720 ret = -EINVAL;
721 goto out;
722 }
723 if (targets[i] == 0 && !done) {
724 printk(KERN_INFO DRV_NAME
725 ": %s: adding ARP target %d.%d.%d.%d.\n",
726 bond->dev->name, NIPQUAD(newtarget));
727 done = 1;
728 targets[i] = newtarget;
729 }
730 }
731 if (!done) {
732 printk(KERN_ERR DRV_NAME
733 ": %s: ARP target table is full!\n",
734 bond->dev->name);
735 ret = -EINVAL;
736 goto out;
737 }
738
739 }
740 else if (buf[0] == '-') {
Al Virod3bb52b2007-08-22 20:06:58 -0400741 if ((newtarget == 0) || (newtarget == htonl(INADDR_BROADCAST))) {
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800742 printk(KERN_ERR DRV_NAME
743 ": %s: invalid ARP target %d.%d.%d.%d specified for removal\n",
744 bond->dev->name, NIPQUAD(newtarget));
745 ret = -EINVAL;
746 goto out;
747 }
748
749 for (i = 0; (i < BOND_MAX_ARP_TARGETS); i++) {
750 if (targets[i] == newtarget) {
751 printk(KERN_INFO DRV_NAME
752 ": %s: removing ARP target %d.%d.%d.%d.\n",
753 bond->dev->name, NIPQUAD(newtarget));
754 targets[i] = 0;
755 done = 1;
756 }
757 }
758 if (!done) {
759 printk(KERN_INFO DRV_NAME
760 ": %s: unable to remove nonexistent ARP target %d.%d.%d.%d.\n",
761 bond->dev->name, NIPQUAD(newtarget));
762 ret = -EINVAL;
763 goto out;
764 }
765 }
766 else {
767 printk(KERN_ERR DRV_NAME ": no command found in arp_ip_targets file for bond %s. Use +<addr> or -<addr>.\n",
768 bond->dev->name);
769 ret = -EPERM;
770 goto out;
771 }
772
773out:
774 return ret;
775}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700776static DEVICE_ATTR(arp_ip_target, S_IRUGO | S_IWUSR , bonding_show_arp_targets, bonding_store_arp_targets);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800777
778/*
779 * Show and set the up and down delays. These must be multiples of the
780 * MII monitoring value, and are stored internally as the multiplier.
781 * Thus, we must translate to MS for the real world.
782 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700783static ssize_t bonding_show_downdelay(struct device *d,
784 struct device_attribute *attr,
785 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800786{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700787 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800788
Wagner Ferenc7bd46502007-12-06 23:40:28 -0800789 return sprintf(buf, "%d\n", bond->params.downdelay * bond->params.miimon);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800790}
791
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700792static ssize_t bonding_store_downdelay(struct device *d,
793 struct device_attribute *attr,
794 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800795{
796 int new_value, ret = count;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700797 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800798
799 if (!(bond->params.miimon)) {
800 printk(KERN_ERR DRV_NAME
801 ": %s: Unable to set down delay as MII monitoring is disabled\n",
802 bond->dev->name);
803 ret = -EPERM;
804 goto out;
805 }
806
807 if (sscanf(buf, "%d", &new_value) != 1) {
808 printk(KERN_ERR DRV_NAME
809 ": %s: no down delay value specified.\n",
810 bond->dev->name);
811 ret = -EINVAL;
812 goto out;
813 }
814 if (new_value < 0) {
815 printk(KERN_ERR DRV_NAME
816 ": %s: Invalid down delay value %d not in range %d-%d; rejected.\n",
817 bond->dev->name, new_value, 1, INT_MAX);
818 ret = -EINVAL;
819 goto out;
820 } else {
821 if ((new_value % bond->params.miimon) != 0) {
822 printk(KERN_WARNING DRV_NAME
823 ": %s: Warning: down delay (%d) is not a multiple "
824 "of miimon (%d), delay rounded to %d ms\n",
825 bond->dev->name, new_value, bond->params.miimon,
826 (new_value / bond->params.miimon) *
827 bond->params.miimon);
828 }
829 bond->params.downdelay = new_value / bond->params.miimon;
830 printk(KERN_INFO DRV_NAME ": %s: Setting down delay to %d.\n",
831 bond->dev->name, bond->params.downdelay * bond->params.miimon);
832
833 }
834
835out:
836 return ret;
837}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700838static DEVICE_ATTR(downdelay, S_IRUGO | S_IWUSR , bonding_show_downdelay, bonding_store_downdelay);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800839
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700840static ssize_t bonding_show_updelay(struct device *d,
841 struct device_attribute *attr,
842 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800843{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700844 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800845
Wagner Ferenc7bd46502007-12-06 23:40:28 -0800846 return sprintf(buf, "%d\n", bond->params.updelay * bond->params.miimon);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800847
848}
849
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700850static ssize_t bonding_store_updelay(struct device *d,
851 struct device_attribute *attr,
852 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800853{
854 int new_value, ret = count;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700855 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800856
857 if (!(bond->params.miimon)) {
858 printk(KERN_ERR DRV_NAME
859 ": %s: Unable to set up delay as MII monitoring is disabled\n",
860 bond->dev->name);
861 ret = -EPERM;
862 goto out;
863 }
864
865 if (sscanf(buf, "%d", &new_value) != 1) {
866 printk(KERN_ERR DRV_NAME
867 ": %s: no up delay value specified.\n",
868 bond->dev->name);
869 ret = -EINVAL;
870 goto out;
871 }
872 if (new_value < 0) {
873 printk(KERN_ERR DRV_NAME
874 ": %s: Invalid down delay value %d not in range %d-%d; rejected.\n",
875 bond->dev->name, new_value, 1, INT_MAX);
876 ret = -EINVAL;
877 goto out;
878 } else {
879 if ((new_value % bond->params.miimon) != 0) {
880 printk(KERN_WARNING DRV_NAME
881 ": %s: Warning: up delay (%d) is not a multiple "
882 "of miimon (%d), updelay rounded to %d ms\n",
883 bond->dev->name, new_value, bond->params.miimon,
884 (new_value / bond->params.miimon) *
885 bond->params.miimon);
886 }
887 bond->params.updelay = new_value / bond->params.miimon;
888 printk(KERN_INFO DRV_NAME ": %s: Setting up delay to %d.\n",
889 bond->dev->name, bond->params.updelay * bond->params.miimon);
890
891 }
892
893out:
894 return ret;
895}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700896static DEVICE_ATTR(updelay, S_IRUGO | S_IWUSR , bonding_show_updelay, bonding_store_updelay);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800897
898/*
899 * Show and set the LACP interval. Interface must be down, and the mode
900 * must be set to 802.3ad mode.
901 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700902static ssize_t bonding_show_lacp(struct device *d,
903 struct device_attribute *attr,
904 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800905{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700906 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800907
908 return sprintf(buf, "%s %d\n",
909 bond_lacp_tbl[bond->params.lacp_fast].modename,
Wagner Ferenc7bd46502007-12-06 23:40:28 -0800910 bond->params.lacp_fast);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800911}
912
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700913static ssize_t bonding_store_lacp(struct device *d,
914 struct device_attribute *attr,
915 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800916{
917 int new_value, ret = count;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700918 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800919
920 if (bond->dev->flags & IFF_UP) {
921 printk(KERN_ERR DRV_NAME
922 ": %s: Unable to update LACP rate because interface is up.\n",
923 bond->dev->name);
924 ret = -EPERM;
925 goto out;
926 }
927
928 if (bond->params.mode != BOND_MODE_8023AD) {
929 printk(KERN_ERR DRV_NAME
930 ": %s: Unable to update LACP rate because bond is not in 802.3ad mode.\n",
931 bond->dev->name);
932 ret = -EPERM;
933 goto out;
934 }
935
Jay Vosburghece95f72008-01-17 16:25:01 -0800936 new_value = bond_parse_parm(buf, bond_lacp_tbl);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800937
938 if ((new_value == 1) || (new_value == 0)) {
939 bond->params.lacp_fast = new_value;
940 printk(KERN_INFO DRV_NAME
941 ": %s: Setting LACP rate to %s (%d).\n",
942 bond->dev->name, bond_lacp_tbl[new_value].modename, new_value);
943 } else {
944 printk(KERN_ERR DRV_NAME
945 ": %s: Ignoring invalid LACP rate value %.*s.\n",
946 bond->dev->name, (int)strlen(buf) - 1, buf);
947 ret = -EINVAL;
948 }
949out:
950 return ret;
951}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700952static DEVICE_ATTR(lacp_rate, S_IRUGO | S_IWUSR, bonding_show_lacp, bonding_store_lacp);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800953
954/*
955 * Show and set the MII monitor interval. There are two tricky bits
956 * here. First, if MII monitoring is activated, then we must disable
957 * ARP monitoring. Second, if the timer isn't running, we must
958 * start it.
959 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700960static ssize_t bonding_show_miimon(struct device *d,
961 struct device_attribute *attr,
962 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800963{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700964 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800965
Wagner Ferenc7bd46502007-12-06 23:40:28 -0800966 return sprintf(buf, "%d\n", bond->params.miimon);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800967}
968
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700969static ssize_t bonding_store_miimon(struct device *d,
970 struct device_attribute *attr,
971 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800972{
973 int new_value, ret = count;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700974 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800975
976 if (sscanf(buf, "%d", &new_value) != 1) {
977 printk(KERN_ERR DRV_NAME
978 ": %s: no miimon value specified.\n",
979 bond->dev->name);
980 ret = -EINVAL;
981 goto out;
982 }
983 if (new_value < 0) {
984 printk(KERN_ERR DRV_NAME
985 ": %s: Invalid miimon value %d not in range %d-%d; rejected.\n",
986 bond->dev->name, new_value, 1, INT_MAX);
987 ret = -EINVAL;
988 goto out;
989 } else {
990 printk(KERN_INFO DRV_NAME
991 ": %s: Setting MII monitoring interval to %d.\n",
992 bond->dev->name, new_value);
993 bond->params.miimon = new_value;
994 if(bond->params.updelay)
995 printk(KERN_INFO DRV_NAME
996 ": %s: Note: Updating updelay (to %d) "
997 "since it is a multiple of the miimon value.\n",
998 bond->dev->name,
999 bond->params.updelay * bond->params.miimon);
1000 if(bond->params.downdelay)
1001 printk(KERN_INFO DRV_NAME
1002 ": %s: Note: Updating downdelay (to %d) "
1003 "since it is a multiple of the miimon value.\n",
1004 bond->dev->name,
1005 bond->params.downdelay * bond->params.miimon);
1006 if (bond->params.arp_interval) {
1007 printk(KERN_INFO DRV_NAME
1008 ": %s: MII monitoring cannot be used with "
1009 "ARP monitoring. Disabling ARP monitoring...\n",
1010 bond->dev->name);
1011 bond->params.arp_interval = 0;
Jay Vosburghf5b2b962006-09-22 21:54:53 -07001012 if (bond->params.arp_validate) {
1013 bond_unregister_arp(bond);
1014 bond->params.arp_validate =
1015 BOND_ARP_VALIDATE_NONE;
1016 }
Jay Vosburgh1b76b312007-10-17 17:37:45 -07001017 if (delayed_work_pending(&bond->arp_work)) {
1018 cancel_delayed_work(&bond->arp_work);
1019 flush_workqueue(bond->wq);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001020 }
1021 }
1022
1023 if (bond->dev->flags & IFF_UP) {
1024 /* If the interface is up, we may need to fire off
1025 * the MII timer. If the interface is down, the
1026 * timer will get fired off when the open function
1027 * is called.
1028 */
Jay Vosburgh1b76b312007-10-17 17:37:45 -07001029 if (!delayed_work_pending(&bond->mii_work)) {
1030 INIT_DELAYED_WORK(&bond->mii_work,
1031 bond_mii_monitor);
1032 queue_delayed_work(bond->wq,
1033 &bond->mii_work, 0);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001034 }
1035 }
1036 }
1037out:
1038 return ret;
1039}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001040static DEVICE_ATTR(miimon, S_IRUGO | S_IWUSR, bonding_show_miimon, bonding_store_miimon);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001041
1042/*
1043 * Show and set the primary slave. The store function is much
1044 * simpler than bonding_store_slaves function because it only needs to
1045 * handle one interface name.
1046 * The bond must be a mode that supports a primary for this be
1047 * set.
1048 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001049static ssize_t bonding_show_primary(struct device *d,
1050 struct device_attribute *attr,
1051 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001052{
1053 int count = 0;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001054 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001055
1056 if (bond->primary_slave)
Wagner Ferenc7bd46502007-12-06 23:40:28 -08001057 count = sprintf(buf, "%s\n", bond->primary_slave->dev->name);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001058
1059 return count;
1060}
1061
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001062static ssize_t bonding_store_primary(struct device *d,
1063 struct device_attribute *attr,
1064 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001065{
1066 int i;
1067 struct slave *slave;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001068 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001069
Jay Vosburghe934dd72008-01-17 16:24:57 -08001070 rtnl_lock();
1071 read_lock(&bond->lock);
1072 write_lock_bh(&bond->curr_slave_lock);
1073
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001074 if (!USES_PRIMARY(bond->params.mode)) {
1075 printk(KERN_INFO DRV_NAME
1076 ": %s: Unable to set primary slave; %s is in mode %d\n",
1077 bond->dev->name, bond->dev->name, bond->params.mode);
1078 } else {
1079 bond_for_each_slave(bond, slave, i) {
1080 if (strnicmp
1081 (slave->dev->name, buf,
1082 strlen(slave->dev->name)) == 0) {
1083 printk(KERN_INFO DRV_NAME
1084 ": %s: Setting %s as primary slave.\n",
1085 bond->dev->name, slave->dev->name);
1086 bond->primary_slave = slave;
1087 bond_select_active_slave(bond);
1088 goto out;
1089 }
1090 }
1091
1092 /* if we got here, then we didn't match the name of any slave */
1093
1094 if (strlen(buf) == 0 || buf[0] == '\n') {
1095 printk(KERN_INFO DRV_NAME
1096 ": %s: Setting primary slave to None.\n",
1097 bond->dev->name);
Luiz Fernando Capitulino3418db72006-02-01 00:54:34 -08001098 bond->primary_slave = NULL;
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001099 bond_select_active_slave(bond);
1100 } else {
1101 printk(KERN_INFO DRV_NAME
1102 ": %s: Unable to set %.*s as primary slave as it is not a slave.\n",
1103 bond->dev->name, (int)strlen(buf) - 1, buf);
1104 }
1105 }
1106out:
Jay Vosburghe934dd72008-01-17 16:24:57 -08001107 write_unlock_bh(&bond->curr_slave_lock);
1108 read_unlock(&bond->lock);
Jay Vosburgh6603a6f2007-10-17 17:37:50 -07001109 rtnl_unlock();
1110
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001111 return count;
1112}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001113static DEVICE_ATTR(primary, S_IRUGO | S_IWUSR, bonding_show_primary, bonding_store_primary);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001114
1115/*
1116 * Show and set the use_carrier flag.
1117 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001118static ssize_t bonding_show_carrier(struct device *d,
1119 struct device_attribute *attr,
1120 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001121{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001122 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001123
Wagner Ferenc7bd46502007-12-06 23:40:28 -08001124 return sprintf(buf, "%d\n", bond->params.use_carrier);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001125}
1126
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001127static ssize_t bonding_store_carrier(struct device *d,
1128 struct device_attribute *attr,
1129 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001130{
1131 int new_value, ret = count;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001132 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001133
1134
1135 if (sscanf(buf, "%d", &new_value) != 1) {
1136 printk(KERN_ERR DRV_NAME
1137 ": %s: no use_carrier value specified.\n",
1138 bond->dev->name);
1139 ret = -EINVAL;
1140 goto out;
1141 }
1142 if ((new_value == 0) || (new_value == 1)) {
1143 bond->params.use_carrier = new_value;
1144 printk(KERN_INFO DRV_NAME ": %s: Setting use_carrier to %d.\n",
1145 bond->dev->name, new_value);
1146 } else {
1147 printk(KERN_INFO DRV_NAME
1148 ": %s: Ignoring invalid use_carrier value %d.\n",
1149 bond->dev->name, new_value);
1150 }
1151out:
1152 return count;
1153}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001154static DEVICE_ATTR(use_carrier, S_IRUGO | S_IWUSR, bonding_show_carrier, bonding_store_carrier);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001155
1156
1157/*
1158 * Show and set currently active_slave.
1159 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001160static ssize_t bonding_show_active_slave(struct device *d,
1161 struct device_attribute *attr,
1162 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001163{
1164 struct slave *curr;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001165 struct bonding *bond = to_bond(d);
Wagner Ferenc16cd0162007-12-06 23:40:29 -08001166 int count = 0;
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001167
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001168 read_lock(&bond->curr_slave_lock);
1169 curr = bond->curr_active_slave;
1170 read_unlock(&bond->curr_slave_lock);
1171
1172 if (USES_PRIMARY(bond->params.mode) && curr)
Wagner Ferenc7bd46502007-12-06 23:40:28 -08001173 count = sprintf(buf, "%s\n", curr->dev->name);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001174 return count;
1175}
1176
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001177static ssize_t bonding_store_active_slave(struct device *d,
1178 struct device_attribute *attr,
1179 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001180{
1181 int i;
1182 struct slave *slave;
1183 struct slave *old_active = NULL;
1184 struct slave *new_active = NULL;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001185 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001186
Jay Vosburgh1466a212007-11-06 13:33:28 -08001187 rtnl_lock();
Jay Vosburghe934dd72008-01-17 16:24:57 -08001188 read_lock(&bond->lock);
1189 write_lock_bh(&bond->curr_slave_lock);
Jay Vosburgh1466a212007-11-06 13:33:28 -08001190
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001191 if (!USES_PRIMARY(bond->params.mode)) {
1192 printk(KERN_INFO DRV_NAME
1193 ": %s: Unable to change active slave; %s is in mode %d\n",
1194 bond->dev->name, bond->dev->name, bond->params.mode);
1195 } else {
1196 bond_for_each_slave(bond, slave, i) {
1197 if (strnicmp
1198 (slave->dev->name, buf,
1199 strlen(slave->dev->name)) == 0) {
1200 old_active = bond->curr_active_slave;
1201 new_active = slave;
Jay Vosburgha50d8de2006-09-22 21:53:25 -07001202 if (new_active == old_active) {
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001203 /* do nothing */
1204 printk(KERN_INFO DRV_NAME
1205 ": %s: %s is already the current active slave.\n",
1206 bond->dev->name, slave->dev->name);
1207 goto out;
1208 }
1209 else {
1210 if ((new_active) &&
1211 (old_active) &&
1212 (new_active->link == BOND_LINK_UP) &&
1213 IS_UP(new_active->dev)) {
1214 printk(KERN_INFO DRV_NAME
1215 ": %s: Setting %s as active slave.\n",
1216 bond->dev->name, slave->dev->name);
1217 bond_change_active_slave(bond, new_active);
1218 }
1219 else {
1220 printk(KERN_INFO DRV_NAME
1221 ": %s: Could not set %s as active slave; "
1222 "either %s is down or the link is down.\n",
1223 bond->dev->name, slave->dev->name,
1224 slave->dev->name);
1225 }
1226 goto out;
1227 }
1228 }
1229 }
1230
1231 /* if we got here, then we didn't match the name of any slave */
1232
1233 if (strlen(buf) == 0 || buf[0] == '\n') {
1234 printk(KERN_INFO DRV_NAME
1235 ": %s: Setting active slave to None.\n",
1236 bond->dev->name);
Luiz Fernando Capitulino3418db72006-02-01 00:54:34 -08001237 bond->primary_slave = NULL;
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001238 bond_select_active_slave(bond);
1239 } else {
1240 printk(KERN_INFO DRV_NAME
1241 ": %s: Unable to set %.*s as active slave as it is not a slave.\n",
1242 bond->dev->name, (int)strlen(buf) - 1, buf);
1243 }
1244 }
1245out:
Jay Vosburghe934dd72008-01-17 16:24:57 -08001246 write_unlock_bh(&bond->curr_slave_lock);
1247 read_unlock(&bond->lock);
Jay Vosburgh6603a6f2007-10-17 17:37:50 -07001248 rtnl_unlock();
1249
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001250 return count;
1251
1252}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001253static DEVICE_ATTR(active_slave, S_IRUGO | S_IWUSR, bonding_show_active_slave, bonding_store_active_slave);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001254
1255
1256/*
1257 * Show link status of the bond interface.
1258 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001259static ssize_t bonding_show_mii_status(struct device *d,
1260 struct device_attribute *attr,
1261 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001262{
1263 struct slave *curr;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001264 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001265
1266 read_lock(&bond->curr_slave_lock);
1267 curr = bond->curr_active_slave;
1268 read_unlock(&bond->curr_slave_lock);
1269
Wagner Ferenc7bd46502007-12-06 23:40:28 -08001270 return sprintf(buf, "%s\n", (curr) ? "up" : "down");
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001271}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001272static DEVICE_ATTR(mii_status, S_IRUGO, bonding_show_mii_status, NULL);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001273
1274
1275/*
1276 * Show current 802.3ad aggregator ID.
1277 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001278static ssize_t bonding_show_ad_aggregator(struct device *d,
1279 struct device_attribute *attr,
1280 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001281{
1282 int count = 0;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001283 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001284
1285 if (bond->params.mode == BOND_MODE_8023AD) {
1286 struct ad_info ad_info;
Wagner Ferenc7bd46502007-12-06 23:40:28 -08001287 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 -08001288 }
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001289
1290 return count;
1291}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001292static DEVICE_ATTR(ad_aggregator, S_IRUGO, bonding_show_ad_aggregator, NULL);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001293
1294
1295/*
1296 * Show number of active 802.3ad ports.
1297 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001298static ssize_t bonding_show_ad_num_ports(struct device *d,
1299 struct device_attribute *attr,
1300 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001301{
1302 int count = 0;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001303 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001304
1305 if (bond->params.mode == BOND_MODE_8023AD) {
1306 struct ad_info ad_info;
Wagner Ferenc7bd46502007-12-06 23:40:28 -08001307 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 -08001308 }
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001309
1310 return count;
1311}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001312static DEVICE_ATTR(ad_num_ports, S_IRUGO, bonding_show_ad_num_ports, NULL);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001313
1314
1315/*
1316 * Show current 802.3ad actor key.
1317 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001318static ssize_t bonding_show_ad_actor_key(struct device *d,
1319 struct device_attribute *attr,
1320 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001321{
1322 int count = 0;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001323 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001324
1325 if (bond->params.mode == BOND_MODE_8023AD) {
1326 struct ad_info ad_info;
Wagner Ferenc7bd46502007-12-06 23:40:28 -08001327 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 -08001328 }
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001329
1330 return count;
1331}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001332static DEVICE_ATTR(ad_actor_key, S_IRUGO, bonding_show_ad_actor_key, NULL);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001333
1334
1335/*
1336 * Show current 802.3ad partner key.
1337 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001338static ssize_t bonding_show_ad_partner_key(struct device *d,
1339 struct device_attribute *attr,
1340 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001341{
1342 int count = 0;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001343 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001344
1345 if (bond->params.mode == BOND_MODE_8023AD) {
1346 struct ad_info ad_info;
Wagner Ferenc7bd46502007-12-06 23:40:28 -08001347 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 -08001348 }
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001349
1350 return count;
1351}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001352static DEVICE_ATTR(ad_partner_key, S_IRUGO, bonding_show_ad_partner_key, NULL);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001353
1354
1355/*
1356 * Show current 802.3ad partner mac.
1357 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001358static ssize_t bonding_show_ad_partner_mac(struct device *d,
1359 struct device_attribute *attr,
1360 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001361{
1362 int count = 0;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001363 struct bonding *bond = to_bond(d);
Joe Perches0795af52007-10-03 17:59:30 -07001364 DECLARE_MAC_BUF(mac);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001365
1366 if (bond->params.mode == BOND_MODE_8023AD) {
1367 struct ad_info ad_info;
1368 if (!bond_3ad_get_active_agg_info(bond, &ad_info)) {
Joe Perches0795af52007-10-03 17:59:30 -07001369 count = sprintf(buf,"%s\n",
Wagner Ferenc7bd46502007-12-06 23:40:28 -08001370 print_mac(mac, ad_info.partner_system));
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001371 }
1372 }
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001373
1374 return count;
1375}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001376static DEVICE_ATTR(ad_partner_mac, S_IRUGO, bonding_show_ad_partner_mac, NULL);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001377
1378
1379
1380static struct attribute *per_bond_attrs[] = {
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001381 &dev_attr_slaves.attr,
1382 &dev_attr_mode.attr,
Jay Vosburghdd957c52007-10-09 19:57:24 -07001383 &dev_attr_fail_over_mac.attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001384 &dev_attr_arp_validate.attr,
1385 &dev_attr_arp_interval.attr,
1386 &dev_attr_arp_ip_target.attr,
1387 &dev_attr_downdelay.attr,
1388 &dev_attr_updelay.attr,
1389 &dev_attr_lacp_rate.attr,
1390 &dev_attr_xmit_hash_policy.attr,
1391 &dev_attr_miimon.attr,
1392 &dev_attr_primary.attr,
1393 &dev_attr_use_carrier.attr,
1394 &dev_attr_active_slave.attr,
1395 &dev_attr_mii_status.attr,
1396 &dev_attr_ad_aggregator.attr,
1397 &dev_attr_ad_num_ports.attr,
1398 &dev_attr_ad_actor_key.attr,
1399 &dev_attr_ad_partner_key.attr,
1400 &dev_attr_ad_partner_mac.attr,
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001401 NULL,
1402};
1403
1404static struct attribute_group bonding_group = {
1405 .name = "bonding",
1406 .attrs = per_bond_attrs,
1407};
1408
1409/*
1410 * Initialize sysfs. This sets up the bonding_masters file in
1411 * /sys/class/net.
1412 */
1413int bond_create_sysfs(void)
1414{
1415 int ret = 0;
1416 struct bonding *firstbond;
1417
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001418 /* get the netdev class pointer */
1419 firstbond = container_of(bond_dev_list.next, struct bonding, bond_list);
1420 if (!firstbond)
1421 return -ENODEV;
1422
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001423 netdev_class = firstbond->dev->dev.class;
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001424 if (!netdev_class)
1425 return -ENODEV;
1426
1427 ret = class_create_file(netdev_class, &class_attr_bonding_masters);
Jay Vosburgh877cbd32007-01-19 18:15:47 -08001428 /*
1429 * Permit multiple loads of the module by ignoring failures to
1430 * create the bonding_masters sysfs file. Bonding devices
1431 * created by second or subsequent loads of the module will
1432 * not be listed in, or controllable by, bonding_masters, but
1433 * will have the usual "bonding" sysfs directory.
1434 *
1435 * This is done to preserve backwards compatibility for
1436 * initscripts/sysconfig, which load bonding multiple times to
1437 * configure multiple bonding devices.
1438 */
1439 if (ret == -EEXIST) {
1440 netdev_class = NULL;
1441 return 0;
1442 }
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001443
1444 return ret;
1445
1446}
1447
1448/*
1449 * Remove /sys/class/net/bonding_masters.
1450 */
1451void bond_destroy_sysfs(void)
1452{
1453 if (netdev_class)
1454 class_remove_file(netdev_class, &class_attr_bonding_masters);
1455}
1456
1457/*
1458 * Initialize sysfs for each bond. This sets up and registers
1459 * the 'bondctl' directory for each individual bond under /sys/class/net.
1460 */
1461int bond_create_sysfs_entry(struct bonding *bond)
1462{
1463 struct net_device *dev = bond->dev;
1464 int err;
1465
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001466 err = sysfs_create_group(&(dev->dev.kobj), &bonding_group);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001467 if (err) {
1468 printk(KERN_EMERG "eek! didn't create group!\n");
1469 }
1470
1471 if (expected_refcount < 1)
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001472 expected_refcount = atomic_read(&bond->dev->dev.kobj.kref.refcount);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001473
1474 return err;
1475}
1476/*
1477 * Remove sysfs entries for each bond.
1478 */
1479void bond_destroy_sysfs_entry(struct bonding *bond)
1480{
1481 struct net_device *dev = bond->dev;
1482
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001483 sysfs_remove_group(&(dev->dev.kobj), &bonding_group);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001484}
1485