blob: 90a1f31e8e637bd104a09490b8d05db80b0b5acc [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;
344 bond_for_each_slave(bond, slave, i)
345 if (strnicmp(slave->dev->name, ifname, IFNAMSIZ) == 0) {
346 dev = slave->dev;
Moni Shoua3158bf72007-10-09 19:43:41 -0700347 original_mtu = slave->original_mtu;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800348 break;
349 }
350 if (dev) {
351 printk(KERN_INFO DRV_NAME ": %s: Removing slave %s\n",
352 bond->dev->name, dev->name);
Moni Shouad90a1622007-10-09 19:43:43 -0700353 if (bond->setup_by_slave)
354 res = bond_release_and_destroy(bond->dev, dev);
355 else
356 res = bond_release(bond->dev, dev);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800357 if (res) {
358 ret = res;
359 goto out;
360 }
361 /* set the slave MTU to the default */
362 if (dev->change_mtu) {
Moni Shoua3158bf72007-10-09 19:43:41 -0700363 dev->change_mtu(dev, original_mtu);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800364 } else {
Moni Shoua3158bf72007-10-09 19:43:41 -0700365 dev->mtu = original_mtu;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800366 }
367 }
368 else {
369 printk(KERN_ERR DRV_NAME ": unable to remove non-existent slave %s for bond %s.\n",
370 ifname, bond->dev->name);
371 ret = -ENODEV;
372 }
373 goto out;
374 }
375
376err_no_cmd:
377 printk(KERN_ERR DRV_NAME ": no command found in slaves file for bond %s. Use +ifname or -ifname.\n", bond->dev->name);
378 ret = -EPERM;
379
380out:
Jay Vosburgh027ea042008-01-17 16:25:02 -0800381 up_write(&(bonding_rwsem));
382 rtnl_unlock();
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800383 return ret;
384}
385
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700386static DEVICE_ATTR(slaves, S_IRUGO | S_IWUSR, bonding_show_slaves, bonding_store_slaves);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800387
388/*
389 * Show and set the bonding mode. The bond interface must be down to
390 * change the mode.
391 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700392static ssize_t bonding_show_mode(struct device *d,
393 struct device_attribute *attr, char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800394{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700395 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800396
397 return sprintf(buf, "%s %d\n",
398 bond_mode_tbl[bond->params.mode].modename,
Wagner Ferenc7bd46502007-12-06 23:40:28 -0800399 bond->params.mode);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800400}
401
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700402static ssize_t bonding_store_mode(struct device *d,
403 struct device_attribute *attr,
404 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800405{
406 int new_value, ret = count;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700407 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800408
409 if (bond->dev->flags & IFF_UP) {
410 printk(KERN_ERR DRV_NAME
411 ": unable to update mode of %s because interface is up.\n",
412 bond->dev->name);
413 ret = -EPERM;
414 goto out;
415 }
416
Jay Vosburghece95f72008-01-17 16:25:01 -0800417 new_value = bond_parse_parm(buf, bond_mode_tbl);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800418 if (new_value < 0) {
419 printk(KERN_ERR DRV_NAME
420 ": %s: Ignoring invalid mode value %.*s.\n",
421 bond->dev->name,
422 (int)strlen(buf) - 1, buf);
423 ret = -EINVAL;
424 goto out;
425 } else {
Jay Vosburgh8f903c72006-02-21 16:36:44 -0800426 if (bond->params.mode == BOND_MODE_8023AD)
427 bond_unset_master_3ad_flags(bond);
428
429 if (bond->params.mode == BOND_MODE_ALB)
430 bond_unset_master_alb_flags(bond);
431
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800432 bond->params.mode = new_value;
433 bond_set_mode_ops(bond, bond->params.mode);
434 printk(KERN_INFO DRV_NAME ": %s: setting mode to %s (%d).\n",
435 bond->dev->name, bond_mode_tbl[new_value].modename, new_value);
436 }
437out:
438 return ret;
439}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700440static DEVICE_ATTR(mode, S_IRUGO | S_IWUSR, bonding_show_mode, bonding_store_mode);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800441
442/*
443 * Show and set the bonding transmit hash method. The bond interface must be down to
444 * change the xmit hash policy.
445 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700446static ssize_t bonding_show_xmit_hash(struct device *d,
447 struct device_attribute *attr,
448 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800449{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700450 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800451
Wagner Ferenc8e4b9322007-12-06 23:40:32 -0800452 return sprintf(buf, "%s %d\n",
453 xmit_hashtype_tbl[bond->params.xmit_policy].modename,
454 bond->params.xmit_policy);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800455}
456
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700457static ssize_t bonding_store_xmit_hash(struct device *d,
458 struct device_attribute *attr,
459 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800460{
461 int new_value, ret = count;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700462 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800463
464 if (bond->dev->flags & IFF_UP) {
465 printk(KERN_ERR DRV_NAME
466 "%s: Interface is up. Unable to update xmit policy.\n",
467 bond->dev->name);
468 ret = -EPERM;
469 goto out;
470 }
471
Jay Vosburghece95f72008-01-17 16:25:01 -0800472 new_value = bond_parse_parm(buf, xmit_hashtype_tbl);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800473 if (new_value < 0) {
474 printk(KERN_ERR DRV_NAME
475 ": %s: Ignoring invalid xmit hash policy value %.*s.\n",
476 bond->dev->name,
477 (int)strlen(buf) - 1, buf);
478 ret = -EINVAL;
479 goto out;
480 } else {
481 bond->params.xmit_policy = new_value;
482 bond_set_mode_ops(bond, bond->params.mode);
483 printk(KERN_INFO DRV_NAME ": %s: setting xmit hash policy to %s (%d).\n",
484 bond->dev->name, xmit_hashtype_tbl[new_value].modename, new_value);
485 }
486out:
487 return ret;
488}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700489static DEVICE_ATTR(xmit_hash_policy, S_IRUGO | S_IWUSR, bonding_show_xmit_hash, bonding_store_xmit_hash);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800490
491/*
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700492 * Show and set arp_validate.
493 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700494static ssize_t bonding_show_arp_validate(struct device *d,
495 struct device_attribute *attr,
496 char *buf)
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700497{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700498 struct bonding *bond = to_bond(d);
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700499
500 return sprintf(buf, "%s %d\n",
501 arp_validate_tbl[bond->params.arp_validate].modename,
Wagner Ferenc7bd46502007-12-06 23:40:28 -0800502 bond->params.arp_validate);
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700503}
504
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700505static ssize_t bonding_store_arp_validate(struct device *d,
506 struct device_attribute *attr,
507 const char *buf, size_t count)
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700508{
509 int new_value;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700510 struct bonding *bond = to_bond(d);
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700511
Jay Vosburghece95f72008-01-17 16:25:01 -0800512 new_value = bond_parse_parm(buf, arp_validate_tbl);
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700513 if (new_value < 0) {
514 printk(KERN_ERR DRV_NAME
515 ": %s: Ignoring invalid arp_validate value %s\n",
516 bond->dev->name, buf);
517 return -EINVAL;
518 }
519 if (new_value && (bond->params.mode != BOND_MODE_ACTIVEBACKUP)) {
520 printk(KERN_ERR DRV_NAME
521 ": %s: arp_validate only supported in active-backup mode.\n",
522 bond->dev->name);
523 return -EINVAL;
524 }
525 printk(KERN_INFO DRV_NAME ": %s: setting arp_validate to %s (%d).\n",
526 bond->dev->name, arp_validate_tbl[new_value].modename,
527 new_value);
528
529 if (!bond->params.arp_validate && new_value) {
530 bond_register_arp(bond);
531 } else if (bond->params.arp_validate && !new_value) {
532 bond_unregister_arp(bond);
533 }
534
535 bond->params.arp_validate = new_value;
536
537 return count;
538}
539
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700540static DEVICE_ATTR(arp_validate, S_IRUGO | S_IWUSR, bonding_show_arp_validate, bonding_store_arp_validate);
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700541
542/*
Jay Vosburghdd957c52007-10-09 19:57:24 -0700543 * Show and store fail_over_mac. User only allowed to change the
544 * value when there are no slaves.
545 */
546static ssize_t bonding_show_fail_over_mac(struct device *d, struct device_attribute *attr, char *buf)
547{
548 struct bonding *bond = to_bond(d);
549
550 return sprintf(buf, "%d\n", bond->params.fail_over_mac) + 1;
551}
552
553static ssize_t bonding_store_fail_over_mac(struct device *d, struct device_attribute *attr, const char *buf, size_t count)
554{
555 int new_value;
556 int ret = count;
557 struct bonding *bond = to_bond(d);
558
559 if (bond->slave_cnt != 0) {
560 printk(KERN_ERR DRV_NAME
561 ": %s: Can't alter fail_over_mac with slaves in bond.\n",
562 bond->dev->name);
563 ret = -EPERM;
564 goto out;
565 }
566
567 if (sscanf(buf, "%d", &new_value) != 1) {
568 printk(KERN_ERR DRV_NAME
569 ": %s: no fail_over_mac value specified.\n",
570 bond->dev->name);
571 ret = -EINVAL;
572 goto out;
573 }
574
575 if ((new_value == 0) || (new_value == 1)) {
576 bond->params.fail_over_mac = new_value;
577 printk(KERN_INFO DRV_NAME ": %s: Setting fail_over_mac to %d.\n",
578 bond->dev->name, new_value);
579 } else {
580 printk(KERN_INFO DRV_NAME
581 ": %s: Ignoring invalid fail_over_mac value %d.\n",
582 bond->dev->name, new_value);
583 }
584out:
585 return ret;
586}
587
588static DEVICE_ATTR(fail_over_mac, S_IRUGO | S_IWUSR, bonding_show_fail_over_mac, bonding_store_fail_over_mac);
589
590/*
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800591 * Show and set the arp timer interval. There are two tricky bits
592 * here. First, if ARP monitoring is activated, then we must disable
593 * MII monitoring. Second, if the ARP timer isn't running, we must
594 * start it.
595 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700596static ssize_t bonding_show_arp_interval(struct device *d,
597 struct device_attribute *attr,
598 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800599{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700600 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800601
Wagner Ferenc7bd46502007-12-06 23:40:28 -0800602 return sprintf(buf, "%d\n", bond->params.arp_interval);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800603}
604
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700605static ssize_t bonding_store_arp_interval(struct device *d,
606 struct device_attribute *attr,
607 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800608{
609 int new_value, ret = count;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700610 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800611
612 if (sscanf(buf, "%d", &new_value) != 1) {
613 printk(KERN_ERR DRV_NAME
614 ": %s: no arp_interval value specified.\n",
615 bond->dev->name);
616 ret = -EINVAL;
617 goto out;
618 }
619 if (new_value < 0) {
620 printk(KERN_ERR DRV_NAME
621 ": %s: Invalid arp_interval value %d not in range 1-%d; rejected.\n",
622 bond->dev->name, new_value, INT_MAX);
623 ret = -EINVAL;
624 goto out;
625 }
626
627 printk(KERN_INFO DRV_NAME
628 ": %s: Setting ARP monitoring interval to %d.\n",
629 bond->dev->name, new_value);
630 bond->params.arp_interval = new_value;
631 if (bond->params.miimon) {
632 printk(KERN_INFO DRV_NAME
633 ": %s: ARP monitoring cannot be used with MII monitoring. "
634 "%s Disabling MII monitoring.\n",
635 bond->dev->name, bond->dev->name);
636 bond->params.miimon = 0;
Jay Vosburgh1b76b312007-10-17 17:37:45 -0700637 if (delayed_work_pending(&bond->mii_work)) {
638 cancel_delayed_work(&bond->mii_work);
639 flush_workqueue(bond->wq);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800640 }
641 }
642 if (!bond->params.arp_targets[0]) {
643 printk(KERN_INFO DRV_NAME
644 ": %s: ARP monitoring has been set up, "
645 "but no ARP targets have been specified.\n",
646 bond->dev->name);
647 }
648 if (bond->dev->flags & IFF_UP) {
649 /* If the interface is up, we may need to fire off
650 * the ARP timer. If the interface is down, the
651 * timer will get fired off when the open function
652 * is called.
653 */
Jay Vosburgh1b76b312007-10-17 17:37:45 -0700654 if (!delayed_work_pending(&bond->arp_work)) {
655 if (bond->params.mode == BOND_MODE_ACTIVEBACKUP)
656 INIT_DELAYED_WORK(&bond->arp_work,
657 bond_activebackup_arp_mon);
658 else
659 INIT_DELAYED_WORK(&bond->arp_work,
660 bond_loadbalance_arp_mon);
661
662 queue_delayed_work(bond->wq, &bond->arp_work, 0);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800663 }
664 }
665
666out:
667 return ret;
668}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700669static DEVICE_ATTR(arp_interval, S_IRUGO | S_IWUSR , bonding_show_arp_interval, bonding_store_arp_interval);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800670
671/*
672 * Show and set the arp targets.
673 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700674static ssize_t bonding_show_arp_targets(struct device *d,
675 struct device_attribute *attr,
676 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800677{
678 int i, res = 0;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700679 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800680
681 for (i = 0; i < BOND_MAX_ARP_TARGETS; i++) {
682 if (bond->params.arp_targets[i])
683 res += sprintf(buf + res, "%u.%u.%u.%u ",
684 NIPQUAD(bond->params.arp_targets[i]));
685 }
Wagner Ferenc1dcdcd62007-12-06 23:40:31 -0800686 if (res)
687 buf[res-1] = '\n'; /* eat the leftover space */
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800688 return res;
689}
690
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700691static ssize_t bonding_store_arp_targets(struct device *d,
692 struct device_attribute *attr,
693 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800694{
Al Virod3bb52b2007-08-22 20:06:58 -0400695 __be32 newtarget;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800696 int i = 0, done = 0, ret = count;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700697 struct bonding *bond = to_bond(d);
Al Virod3bb52b2007-08-22 20:06:58 -0400698 __be32 *targets;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800699
700 targets = bond->params.arp_targets;
701 newtarget = in_aton(buf + 1);
702 /* look for adds */
703 if (buf[0] == '+') {
Al Virod3bb52b2007-08-22 20:06:58 -0400704 if ((newtarget == 0) || (newtarget == htonl(INADDR_BROADCAST))) {
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800705 printk(KERN_ERR DRV_NAME
706 ": %s: invalid ARP target %u.%u.%u.%u specified for addition\n",
707 bond->dev->name, NIPQUAD(newtarget));
708 ret = -EINVAL;
709 goto out;
710 }
711 /* look for an empty slot to put the target in, and check for dupes */
712 for (i = 0; (i < BOND_MAX_ARP_TARGETS); i++) {
713 if (targets[i] == newtarget) { /* duplicate */
714 printk(KERN_ERR DRV_NAME
715 ": %s: ARP target %u.%u.%u.%u is already present\n",
716 bond->dev->name, NIPQUAD(newtarget));
717 if (done)
718 targets[i] = 0;
719 ret = -EINVAL;
720 goto out;
721 }
722 if (targets[i] == 0 && !done) {
723 printk(KERN_INFO DRV_NAME
724 ": %s: adding ARP target %d.%d.%d.%d.\n",
725 bond->dev->name, NIPQUAD(newtarget));
726 done = 1;
727 targets[i] = newtarget;
728 }
729 }
730 if (!done) {
731 printk(KERN_ERR DRV_NAME
732 ": %s: ARP target table is full!\n",
733 bond->dev->name);
734 ret = -EINVAL;
735 goto out;
736 }
737
738 }
739 else if (buf[0] == '-') {
Al Virod3bb52b2007-08-22 20:06:58 -0400740 if ((newtarget == 0) || (newtarget == htonl(INADDR_BROADCAST))) {
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800741 printk(KERN_ERR DRV_NAME
742 ": %s: invalid ARP target %d.%d.%d.%d specified for removal\n",
743 bond->dev->name, NIPQUAD(newtarget));
744 ret = -EINVAL;
745 goto out;
746 }
747
748 for (i = 0; (i < BOND_MAX_ARP_TARGETS); i++) {
749 if (targets[i] == newtarget) {
750 printk(KERN_INFO DRV_NAME
751 ": %s: removing ARP target %d.%d.%d.%d.\n",
752 bond->dev->name, NIPQUAD(newtarget));
753 targets[i] = 0;
754 done = 1;
755 }
756 }
757 if (!done) {
758 printk(KERN_INFO DRV_NAME
759 ": %s: unable to remove nonexistent ARP target %d.%d.%d.%d.\n",
760 bond->dev->name, NIPQUAD(newtarget));
761 ret = -EINVAL;
762 goto out;
763 }
764 }
765 else {
766 printk(KERN_ERR DRV_NAME ": no command found in arp_ip_targets file for bond %s. Use +<addr> or -<addr>.\n",
767 bond->dev->name);
768 ret = -EPERM;
769 goto out;
770 }
771
772out:
773 return ret;
774}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700775static DEVICE_ATTR(arp_ip_target, S_IRUGO | S_IWUSR , bonding_show_arp_targets, bonding_store_arp_targets);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800776
777/*
778 * Show and set the up and down delays. These must be multiples of the
779 * MII monitoring value, and are stored internally as the multiplier.
780 * Thus, we must translate to MS for the real world.
781 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700782static ssize_t bonding_show_downdelay(struct device *d,
783 struct device_attribute *attr,
784 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800785{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700786 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800787
Wagner Ferenc7bd46502007-12-06 23:40:28 -0800788 return sprintf(buf, "%d\n", bond->params.downdelay * bond->params.miimon);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800789}
790
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700791static ssize_t bonding_store_downdelay(struct device *d,
792 struct device_attribute *attr,
793 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800794{
795 int new_value, ret = count;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700796 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800797
798 if (!(bond->params.miimon)) {
799 printk(KERN_ERR DRV_NAME
800 ": %s: Unable to set down delay as MII monitoring is disabled\n",
801 bond->dev->name);
802 ret = -EPERM;
803 goto out;
804 }
805
806 if (sscanf(buf, "%d", &new_value) != 1) {
807 printk(KERN_ERR DRV_NAME
808 ": %s: no down delay value specified.\n",
809 bond->dev->name);
810 ret = -EINVAL;
811 goto out;
812 }
813 if (new_value < 0) {
814 printk(KERN_ERR DRV_NAME
815 ": %s: Invalid down delay value %d not in range %d-%d; rejected.\n",
816 bond->dev->name, new_value, 1, INT_MAX);
817 ret = -EINVAL;
818 goto out;
819 } else {
820 if ((new_value % bond->params.miimon) != 0) {
821 printk(KERN_WARNING DRV_NAME
822 ": %s: Warning: down delay (%d) is not a multiple "
823 "of miimon (%d), delay rounded to %d ms\n",
824 bond->dev->name, new_value, bond->params.miimon,
825 (new_value / bond->params.miimon) *
826 bond->params.miimon);
827 }
828 bond->params.downdelay = new_value / bond->params.miimon;
829 printk(KERN_INFO DRV_NAME ": %s: Setting down delay to %d.\n",
830 bond->dev->name, bond->params.downdelay * bond->params.miimon);
831
832 }
833
834out:
835 return ret;
836}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700837static DEVICE_ATTR(downdelay, S_IRUGO | S_IWUSR , bonding_show_downdelay, bonding_store_downdelay);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800838
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700839static ssize_t bonding_show_updelay(struct device *d,
840 struct device_attribute *attr,
841 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800842{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700843 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800844
Wagner Ferenc7bd46502007-12-06 23:40:28 -0800845 return sprintf(buf, "%d\n", bond->params.updelay * bond->params.miimon);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800846
847}
848
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700849static ssize_t bonding_store_updelay(struct device *d,
850 struct device_attribute *attr,
851 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800852{
853 int new_value, ret = count;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700854 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800855
856 if (!(bond->params.miimon)) {
857 printk(KERN_ERR DRV_NAME
858 ": %s: Unable to set up delay as MII monitoring is disabled\n",
859 bond->dev->name);
860 ret = -EPERM;
861 goto out;
862 }
863
864 if (sscanf(buf, "%d", &new_value) != 1) {
865 printk(KERN_ERR DRV_NAME
866 ": %s: no up delay value specified.\n",
867 bond->dev->name);
868 ret = -EINVAL;
869 goto out;
870 }
871 if (new_value < 0) {
872 printk(KERN_ERR DRV_NAME
873 ": %s: Invalid down delay value %d not in range %d-%d; rejected.\n",
874 bond->dev->name, new_value, 1, INT_MAX);
875 ret = -EINVAL;
876 goto out;
877 } else {
878 if ((new_value % bond->params.miimon) != 0) {
879 printk(KERN_WARNING DRV_NAME
880 ": %s: Warning: up delay (%d) is not a multiple "
881 "of miimon (%d), updelay rounded to %d ms\n",
882 bond->dev->name, new_value, bond->params.miimon,
883 (new_value / bond->params.miimon) *
884 bond->params.miimon);
885 }
886 bond->params.updelay = new_value / bond->params.miimon;
887 printk(KERN_INFO DRV_NAME ": %s: Setting up delay to %d.\n",
888 bond->dev->name, bond->params.updelay * bond->params.miimon);
889
890 }
891
892out:
893 return ret;
894}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700895static DEVICE_ATTR(updelay, S_IRUGO | S_IWUSR , bonding_show_updelay, bonding_store_updelay);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800896
897/*
898 * Show and set the LACP interval. Interface must be down, and the mode
899 * must be set to 802.3ad mode.
900 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700901static ssize_t bonding_show_lacp(struct device *d,
902 struct device_attribute *attr,
903 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800904{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700905 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800906
907 return sprintf(buf, "%s %d\n",
908 bond_lacp_tbl[bond->params.lacp_fast].modename,
Wagner Ferenc7bd46502007-12-06 23:40:28 -0800909 bond->params.lacp_fast);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800910}
911
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700912static ssize_t bonding_store_lacp(struct device *d,
913 struct device_attribute *attr,
914 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800915{
916 int new_value, ret = count;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700917 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800918
919 if (bond->dev->flags & IFF_UP) {
920 printk(KERN_ERR DRV_NAME
921 ": %s: Unable to update LACP rate because interface is up.\n",
922 bond->dev->name);
923 ret = -EPERM;
924 goto out;
925 }
926
927 if (bond->params.mode != BOND_MODE_8023AD) {
928 printk(KERN_ERR DRV_NAME
929 ": %s: Unable to update LACP rate because bond is not in 802.3ad mode.\n",
930 bond->dev->name);
931 ret = -EPERM;
932 goto out;
933 }
934
Jay Vosburghece95f72008-01-17 16:25:01 -0800935 new_value = bond_parse_parm(buf, bond_lacp_tbl);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800936
937 if ((new_value == 1) || (new_value == 0)) {
938 bond->params.lacp_fast = new_value;
939 printk(KERN_INFO DRV_NAME
940 ": %s: Setting LACP rate to %s (%d).\n",
941 bond->dev->name, bond_lacp_tbl[new_value].modename, new_value);
942 } else {
943 printk(KERN_ERR DRV_NAME
944 ": %s: Ignoring invalid LACP rate value %.*s.\n",
945 bond->dev->name, (int)strlen(buf) - 1, buf);
946 ret = -EINVAL;
947 }
948out:
949 return ret;
950}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700951static DEVICE_ATTR(lacp_rate, S_IRUGO | S_IWUSR, bonding_show_lacp, bonding_store_lacp);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800952
953/*
954 * Show and set the MII monitor interval. There are two tricky bits
955 * here. First, if MII monitoring is activated, then we must disable
956 * ARP monitoring. Second, if the timer isn't running, we must
957 * start it.
958 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700959static ssize_t bonding_show_miimon(struct device *d,
960 struct device_attribute *attr,
961 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800962{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700963 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800964
Wagner Ferenc7bd46502007-12-06 23:40:28 -0800965 return sprintf(buf, "%d\n", bond->params.miimon);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800966}
967
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700968static ssize_t bonding_store_miimon(struct device *d,
969 struct device_attribute *attr,
970 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800971{
972 int new_value, ret = count;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700973 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800974
975 if (sscanf(buf, "%d", &new_value) != 1) {
976 printk(KERN_ERR DRV_NAME
977 ": %s: no miimon value specified.\n",
978 bond->dev->name);
979 ret = -EINVAL;
980 goto out;
981 }
982 if (new_value < 0) {
983 printk(KERN_ERR DRV_NAME
984 ": %s: Invalid miimon value %d not in range %d-%d; rejected.\n",
985 bond->dev->name, new_value, 1, INT_MAX);
986 ret = -EINVAL;
987 goto out;
988 } else {
989 printk(KERN_INFO DRV_NAME
990 ": %s: Setting MII monitoring interval to %d.\n",
991 bond->dev->name, new_value);
992 bond->params.miimon = new_value;
993 if(bond->params.updelay)
994 printk(KERN_INFO DRV_NAME
995 ": %s: Note: Updating updelay (to %d) "
996 "since it is a multiple of the miimon value.\n",
997 bond->dev->name,
998 bond->params.updelay * bond->params.miimon);
999 if(bond->params.downdelay)
1000 printk(KERN_INFO DRV_NAME
1001 ": %s: Note: Updating downdelay (to %d) "
1002 "since it is a multiple of the miimon value.\n",
1003 bond->dev->name,
1004 bond->params.downdelay * bond->params.miimon);
1005 if (bond->params.arp_interval) {
1006 printk(KERN_INFO DRV_NAME
1007 ": %s: MII monitoring cannot be used with "
1008 "ARP monitoring. Disabling ARP monitoring...\n",
1009 bond->dev->name);
1010 bond->params.arp_interval = 0;
Jay Vosburghf5b2b962006-09-22 21:54:53 -07001011 if (bond->params.arp_validate) {
1012 bond_unregister_arp(bond);
1013 bond->params.arp_validate =
1014 BOND_ARP_VALIDATE_NONE;
1015 }
Jay Vosburgh1b76b312007-10-17 17:37:45 -07001016 if (delayed_work_pending(&bond->arp_work)) {
1017 cancel_delayed_work(&bond->arp_work);
1018 flush_workqueue(bond->wq);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001019 }
1020 }
1021
1022 if (bond->dev->flags & IFF_UP) {
1023 /* If the interface is up, we may need to fire off
1024 * the MII timer. If the interface is down, the
1025 * timer will get fired off when the open function
1026 * is called.
1027 */
Jay Vosburgh1b76b312007-10-17 17:37:45 -07001028 if (!delayed_work_pending(&bond->mii_work)) {
1029 INIT_DELAYED_WORK(&bond->mii_work,
1030 bond_mii_monitor);
1031 queue_delayed_work(bond->wq,
1032 &bond->mii_work, 0);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001033 }
1034 }
1035 }
1036out:
1037 return ret;
1038}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001039static DEVICE_ATTR(miimon, S_IRUGO | S_IWUSR, bonding_show_miimon, bonding_store_miimon);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001040
1041/*
1042 * Show and set the primary slave. The store function is much
1043 * simpler than bonding_store_slaves function because it only needs to
1044 * handle one interface name.
1045 * The bond must be a mode that supports a primary for this be
1046 * set.
1047 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001048static ssize_t bonding_show_primary(struct device *d,
1049 struct device_attribute *attr,
1050 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001051{
1052 int count = 0;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001053 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001054
1055 if (bond->primary_slave)
Wagner Ferenc7bd46502007-12-06 23:40:28 -08001056 count = sprintf(buf, "%s\n", bond->primary_slave->dev->name);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001057
1058 return count;
1059}
1060
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001061static ssize_t bonding_store_primary(struct device *d,
1062 struct device_attribute *attr,
1063 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001064{
1065 int i;
1066 struct slave *slave;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001067 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001068
Jay Vosburghe934dd72008-01-17 16:24:57 -08001069 rtnl_lock();
1070 read_lock(&bond->lock);
1071 write_lock_bh(&bond->curr_slave_lock);
1072
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001073 if (!USES_PRIMARY(bond->params.mode)) {
1074 printk(KERN_INFO DRV_NAME
1075 ": %s: Unable to set primary slave; %s is in mode %d\n",
1076 bond->dev->name, bond->dev->name, bond->params.mode);
1077 } else {
1078 bond_for_each_slave(bond, slave, i) {
1079 if (strnicmp
1080 (slave->dev->name, buf,
1081 strlen(slave->dev->name)) == 0) {
1082 printk(KERN_INFO DRV_NAME
1083 ": %s: Setting %s as primary slave.\n",
1084 bond->dev->name, slave->dev->name);
1085 bond->primary_slave = slave;
1086 bond_select_active_slave(bond);
1087 goto out;
1088 }
1089 }
1090
1091 /* if we got here, then we didn't match the name of any slave */
1092
1093 if (strlen(buf) == 0 || buf[0] == '\n') {
1094 printk(KERN_INFO DRV_NAME
1095 ": %s: Setting primary slave to None.\n",
1096 bond->dev->name);
Luiz Fernando Capitulino3418db72006-02-01 00:54:34 -08001097 bond->primary_slave = NULL;
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001098 bond_select_active_slave(bond);
1099 } else {
1100 printk(KERN_INFO DRV_NAME
1101 ": %s: Unable to set %.*s as primary slave as it is not a slave.\n",
1102 bond->dev->name, (int)strlen(buf) - 1, buf);
1103 }
1104 }
1105out:
Jay Vosburghe934dd72008-01-17 16:24:57 -08001106 write_unlock_bh(&bond->curr_slave_lock);
1107 read_unlock(&bond->lock);
Jay Vosburgh6603a6f2007-10-17 17:37:50 -07001108 rtnl_unlock();
1109
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001110 return count;
1111}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001112static DEVICE_ATTR(primary, S_IRUGO | S_IWUSR, bonding_show_primary, bonding_store_primary);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001113
1114/*
1115 * Show and set the use_carrier flag.
1116 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001117static ssize_t bonding_show_carrier(struct device *d,
1118 struct device_attribute *attr,
1119 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001120{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001121 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001122
Wagner Ferenc7bd46502007-12-06 23:40:28 -08001123 return sprintf(buf, "%d\n", bond->params.use_carrier);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001124}
1125
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001126static ssize_t bonding_store_carrier(struct device *d,
1127 struct device_attribute *attr,
1128 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001129{
1130 int new_value, ret = count;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001131 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001132
1133
1134 if (sscanf(buf, "%d", &new_value) != 1) {
1135 printk(KERN_ERR DRV_NAME
1136 ": %s: no use_carrier value specified.\n",
1137 bond->dev->name);
1138 ret = -EINVAL;
1139 goto out;
1140 }
1141 if ((new_value == 0) || (new_value == 1)) {
1142 bond->params.use_carrier = new_value;
1143 printk(KERN_INFO DRV_NAME ": %s: Setting use_carrier to %d.\n",
1144 bond->dev->name, new_value);
1145 } else {
1146 printk(KERN_INFO DRV_NAME
1147 ": %s: Ignoring invalid use_carrier value %d.\n",
1148 bond->dev->name, new_value);
1149 }
1150out:
1151 return count;
1152}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001153static DEVICE_ATTR(use_carrier, S_IRUGO | S_IWUSR, bonding_show_carrier, bonding_store_carrier);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001154
1155
1156/*
1157 * Show and set currently active_slave.
1158 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001159static ssize_t bonding_show_active_slave(struct device *d,
1160 struct device_attribute *attr,
1161 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001162{
1163 struct slave *curr;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001164 struct bonding *bond = to_bond(d);
Wagner Ferenc16cd0162007-12-06 23:40:29 -08001165 int count = 0;
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001166
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001167 read_lock(&bond->curr_slave_lock);
1168 curr = bond->curr_active_slave;
1169 read_unlock(&bond->curr_slave_lock);
1170
1171 if (USES_PRIMARY(bond->params.mode) && curr)
Wagner Ferenc7bd46502007-12-06 23:40:28 -08001172 count = sprintf(buf, "%s\n", curr->dev->name);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001173 return count;
1174}
1175
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001176static ssize_t bonding_store_active_slave(struct device *d,
1177 struct device_attribute *attr,
1178 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001179{
1180 int i;
1181 struct slave *slave;
1182 struct slave *old_active = NULL;
1183 struct slave *new_active = NULL;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001184 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001185
Jay Vosburgh1466a212007-11-06 13:33:28 -08001186 rtnl_lock();
Jay Vosburghe934dd72008-01-17 16:24:57 -08001187 read_lock(&bond->lock);
1188 write_lock_bh(&bond->curr_slave_lock);
Jay Vosburgh1466a212007-11-06 13:33:28 -08001189
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001190 if (!USES_PRIMARY(bond->params.mode)) {
1191 printk(KERN_INFO DRV_NAME
1192 ": %s: Unable to change active slave; %s is in mode %d\n",
1193 bond->dev->name, bond->dev->name, bond->params.mode);
1194 } else {
1195 bond_for_each_slave(bond, slave, i) {
1196 if (strnicmp
1197 (slave->dev->name, buf,
1198 strlen(slave->dev->name)) == 0) {
1199 old_active = bond->curr_active_slave;
1200 new_active = slave;
Jay Vosburgha50d8de2006-09-22 21:53:25 -07001201 if (new_active == old_active) {
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001202 /* do nothing */
1203 printk(KERN_INFO DRV_NAME
1204 ": %s: %s is already the current active slave.\n",
1205 bond->dev->name, slave->dev->name);
1206 goto out;
1207 }
1208 else {
1209 if ((new_active) &&
1210 (old_active) &&
1211 (new_active->link == BOND_LINK_UP) &&
1212 IS_UP(new_active->dev)) {
1213 printk(KERN_INFO DRV_NAME
1214 ": %s: Setting %s as active slave.\n",
1215 bond->dev->name, slave->dev->name);
1216 bond_change_active_slave(bond, new_active);
1217 }
1218 else {
1219 printk(KERN_INFO DRV_NAME
1220 ": %s: Could not set %s as active slave; "
1221 "either %s is down or the link is down.\n",
1222 bond->dev->name, slave->dev->name,
1223 slave->dev->name);
1224 }
1225 goto out;
1226 }
1227 }
1228 }
1229
1230 /* if we got here, then we didn't match the name of any slave */
1231
1232 if (strlen(buf) == 0 || buf[0] == '\n') {
1233 printk(KERN_INFO DRV_NAME
1234 ": %s: Setting active slave to None.\n",
1235 bond->dev->name);
Luiz Fernando Capitulino3418db72006-02-01 00:54:34 -08001236 bond->primary_slave = NULL;
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001237 bond_select_active_slave(bond);
1238 } else {
1239 printk(KERN_INFO DRV_NAME
1240 ": %s: Unable to set %.*s as active slave as it is not a slave.\n",
1241 bond->dev->name, (int)strlen(buf) - 1, buf);
1242 }
1243 }
1244out:
Jay Vosburghe934dd72008-01-17 16:24:57 -08001245 write_unlock_bh(&bond->curr_slave_lock);
1246 read_unlock(&bond->lock);
Jay Vosburgh6603a6f2007-10-17 17:37:50 -07001247 rtnl_unlock();
1248
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001249 return count;
1250
1251}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001252static DEVICE_ATTR(active_slave, S_IRUGO | S_IWUSR, bonding_show_active_slave, bonding_store_active_slave);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001253
1254
1255/*
1256 * Show link status of the bond interface.
1257 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001258static ssize_t bonding_show_mii_status(struct device *d,
1259 struct device_attribute *attr,
1260 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001261{
1262 struct slave *curr;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001263 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001264
1265 read_lock(&bond->curr_slave_lock);
1266 curr = bond->curr_active_slave;
1267 read_unlock(&bond->curr_slave_lock);
1268
Wagner Ferenc7bd46502007-12-06 23:40:28 -08001269 return sprintf(buf, "%s\n", (curr) ? "up" : "down");
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001270}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001271static DEVICE_ATTR(mii_status, S_IRUGO, bonding_show_mii_status, NULL);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001272
1273
1274/*
1275 * Show current 802.3ad aggregator ID.
1276 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001277static ssize_t bonding_show_ad_aggregator(struct device *d,
1278 struct device_attribute *attr,
1279 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001280{
1281 int count = 0;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001282 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001283
1284 if (bond->params.mode == BOND_MODE_8023AD) {
1285 struct ad_info ad_info;
Wagner Ferenc7bd46502007-12-06 23:40:28 -08001286 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 -08001287 }
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001288
1289 return count;
1290}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001291static DEVICE_ATTR(ad_aggregator, S_IRUGO, bonding_show_ad_aggregator, NULL);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001292
1293
1294/*
1295 * Show number of active 802.3ad ports.
1296 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001297static ssize_t bonding_show_ad_num_ports(struct device *d,
1298 struct device_attribute *attr,
1299 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001300{
1301 int count = 0;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001302 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001303
1304 if (bond->params.mode == BOND_MODE_8023AD) {
1305 struct ad_info ad_info;
Wagner Ferenc7bd46502007-12-06 23:40:28 -08001306 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 -08001307 }
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001308
1309 return count;
1310}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001311static DEVICE_ATTR(ad_num_ports, S_IRUGO, bonding_show_ad_num_ports, NULL);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001312
1313
1314/*
1315 * Show current 802.3ad actor key.
1316 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001317static ssize_t bonding_show_ad_actor_key(struct device *d,
1318 struct device_attribute *attr,
1319 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001320{
1321 int count = 0;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001322 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001323
1324 if (bond->params.mode == BOND_MODE_8023AD) {
1325 struct ad_info ad_info;
Wagner Ferenc7bd46502007-12-06 23:40:28 -08001326 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 -08001327 }
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001328
1329 return count;
1330}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001331static DEVICE_ATTR(ad_actor_key, S_IRUGO, bonding_show_ad_actor_key, NULL);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001332
1333
1334/*
1335 * Show current 802.3ad partner key.
1336 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001337static ssize_t bonding_show_ad_partner_key(struct device *d,
1338 struct device_attribute *attr,
1339 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001340{
1341 int count = 0;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001342 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001343
1344 if (bond->params.mode == BOND_MODE_8023AD) {
1345 struct ad_info ad_info;
Wagner Ferenc7bd46502007-12-06 23:40:28 -08001346 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 -08001347 }
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001348
1349 return count;
1350}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001351static DEVICE_ATTR(ad_partner_key, S_IRUGO, bonding_show_ad_partner_key, NULL);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001352
1353
1354/*
1355 * Show current 802.3ad partner mac.
1356 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001357static ssize_t bonding_show_ad_partner_mac(struct device *d,
1358 struct device_attribute *attr,
1359 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001360{
1361 int count = 0;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001362 struct bonding *bond = to_bond(d);
Joe Perches0795af52007-10-03 17:59:30 -07001363 DECLARE_MAC_BUF(mac);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001364
1365 if (bond->params.mode == BOND_MODE_8023AD) {
1366 struct ad_info ad_info;
1367 if (!bond_3ad_get_active_agg_info(bond, &ad_info)) {
Joe Perches0795af52007-10-03 17:59:30 -07001368 count = sprintf(buf,"%s\n",
Wagner Ferenc7bd46502007-12-06 23:40:28 -08001369 print_mac(mac, ad_info.partner_system));
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001370 }
1371 }
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001372
1373 return count;
1374}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001375static DEVICE_ATTR(ad_partner_mac, S_IRUGO, bonding_show_ad_partner_mac, NULL);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001376
1377
1378
1379static struct attribute *per_bond_attrs[] = {
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001380 &dev_attr_slaves.attr,
1381 &dev_attr_mode.attr,
Jay Vosburghdd957c52007-10-09 19:57:24 -07001382 &dev_attr_fail_over_mac.attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001383 &dev_attr_arp_validate.attr,
1384 &dev_attr_arp_interval.attr,
1385 &dev_attr_arp_ip_target.attr,
1386 &dev_attr_downdelay.attr,
1387 &dev_attr_updelay.attr,
1388 &dev_attr_lacp_rate.attr,
1389 &dev_attr_xmit_hash_policy.attr,
1390 &dev_attr_miimon.attr,
1391 &dev_attr_primary.attr,
1392 &dev_attr_use_carrier.attr,
1393 &dev_attr_active_slave.attr,
1394 &dev_attr_mii_status.attr,
1395 &dev_attr_ad_aggregator.attr,
1396 &dev_attr_ad_num_ports.attr,
1397 &dev_attr_ad_actor_key.attr,
1398 &dev_attr_ad_partner_key.attr,
1399 &dev_attr_ad_partner_mac.attr,
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001400 NULL,
1401};
1402
1403static struct attribute_group bonding_group = {
1404 .name = "bonding",
1405 .attrs = per_bond_attrs,
1406};
1407
1408/*
1409 * Initialize sysfs. This sets up the bonding_masters file in
1410 * /sys/class/net.
1411 */
1412int bond_create_sysfs(void)
1413{
1414 int ret = 0;
1415 struct bonding *firstbond;
1416
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001417 /* get the netdev class pointer */
1418 firstbond = container_of(bond_dev_list.next, struct bonding, bond_list);
1419 if (!firstbond)
1420 return -ENODEV;
1421
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001422 netdev_class = firstbond->dev->dev.class;
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001423 if (!netdev_class)
1424 return -ENODEV;
1425
1426 ret = class_create_file(netdev_class, &class_attr_bonding_masters);
Jay Vosburgh877cbd32007-01-19 18:15:47 -08001427 /*
1428 * Permit multiple loads of the module by ignoring failures to
1429 * create the bonding_masters sysfs file. Bonding devices
1430 * created by second or subsequent loads of the module will
1431 * not be listed in, or controllable by, bonding_masters, but
1432 * will have the usual "bonding" sysfs directory.
1433 *
1434 * This is done to preserve backwards compatibility for
1435 * initscripts/sysconfig, which load bonding multiple times to
1436 * configure multiple bonding devices.
1437 */
1438 if (ret == -EEXIST) {
1439 netdev_class = NULL;
1440 return 0;
1441 }
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001442
1443 return ret;
1444
1445}
1446
1447/*
1448 * Remove /sys/class/net/bonding_masters.
1449 */
1450void bond_destroy_sysfs(void)
1451{
1452 if (netdev_class)
1453 class_remove_file(netdev_class, &class_attr_bonding_masters);
1454}
1455
1456/*
1457 * Initialize sysfs for each bond. This sets up and registers
1458 * the 'bondctl' directory for each individual bond under /sys/class/net.
1459 */
1460int bond_create_sysfs_entry(struct bonding *bond)
1461{
1462 struct net_device *dev = bond->dev;
1463 int err;
1464
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001465 err = sysfs_create_group(&(dev->dev.kobj), &bonding_group);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001466 if (err) {
1467 printk(KERN_EMERG "eek! didn't create group!\n");
1468 }
1469
1470 if (expected_refcount < 1)
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001471 expected_refcount = atomic_read(&bond->dev->dev.kobj.kref.refcount);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001472
1473 return err;
1474}
1475/*
1476 * Remove sysfs entries for each bond.
1477 */
1478void bond_destroy_sysfs_entry(struct bonding *bond)
1479{
1480 struct net_device *dev = bond->dev;
1481
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001482 sysfs_remove_group(&(dev->dev.kobj), &bonding_group);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001483}
1484