blob: 6caac0ffb2f2bc575397b650da276b626f51bdd2 [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[];
Jay Vosburgh3915c1e82008-05-17 21:10:14 -070053extern struct bond_parm_tbl fail_over_mac_tbl[];
Mitch Williamsb76cdba2005-11-09 10:36:41 -080054
55static int expected_refcount = -1;
Mitch Williamsb76cdba2005-11-09 10:36:41 -080056/*--------------------------- 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;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800114
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800115 sscanf(buffer, "%16s", command); /* IFNAMSIZ*/
116 ifname = command + 1;
117 if ((strlen(command) <= 1) ||
118 !dev_valid_name(ifname))
119 goto err_no_cmd;
120
121 if (command[0] == '+') {
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800122 printk(KERN_INFO DRV_NAME
123 ": %s is being created...\n", ifname);
Pavel Emelyanov0dd646f2008-05-17 21:10:09 -0700124 rv = bond_create(ifname, &bonding_defaults);
Jay Vosburgh027ea042008-01-17 16:25:02 -0800125 if (rv) {
126 printk(KERN_INFO DRV_NAME ": Bond creation failed.\n");
127 res = rv;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800128 }
129 goto out;
130 }
131
132 if (command[0] == '-') {
Jay Vosburgh027ea042008-01-17 16:25:02 -0800133 rtnl_lock();
134 down_write(&bonding_rwsem);
135
Pavel Emelyanov0883bec2008-05-17 21:10:10 -0700136 list_for_each_entry(bond, &bond_dev_list, bond_list)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800137 if (strnicmp(bond->dev->name, ifname, IFNAMSIZ) == 0) {
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800138 /* check the ref count on the bond's kobject.
139 * If it's > expected, then there's a file open,
140 * and we have to fail.
141 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700142 if (atomic_read(&bond->dev->dev.kobj.kref.refcount)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800143 > expected_refcount){
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800144 printk(KERN_INFO DRV_NAME
145 ": Unable remove bond %s due to open references.\n",
146 ifname);
147 res = -EPERM;
Jay Vosburghc4ebc662008-05-02 17:49:38 -0700148 goto out_unlock;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800149 }
150 printk(KERN_INFO DRV_NAME
151 ": %s is being deleted...\n",
152 bond->dev->name);
Moni Shouad90a1622007-10-09 19:43:43 -0700153 bond_destroy(bond);
Jay Vosburghc4ebc662008-05-02 17:49:38 -0700154 goto out_unlock;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800155 }
156
157 printk(KERN_ERR DRV_NAME
158 ": unable to delete non-existent bond %s\n", ifname);
159 res = -ENODEV;
Jay Vosburghc4ebc662008-05-02 17:49:38 -0700160 goto out_unlock;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800161 }
162
163err_no_cmd:
164 printk(KERN_ERR DRV_NAME
165 ": no command found in bonding_masters. Use +ifname or -ifname.\n");
Jay Vosburghc4ebc662008-05-02 17:49:38 -0700166 return -EPERM;
167
168out_unlock:
169 up_write(&bonding_rwsem);
170 rtnl_unlock();
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800171
172 /* Always return either count or an error. If you return 0, you'll
173 * get called forever, which is bad.
174 */
175out:
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800176 return res;
177}
178/* class attribute for bond_masters file. This ends up in /sys/class/net */
179static CLASS_ATTR(bonding_masters, S_IWUSR | S_IRUGO,
180 bonding_show_bonds, bonding_store_bonds);
181
182int bond_create_slave_symlinks(struct net_device *master, struct net_device *slave)
183{
184 char linkname[IFNAMSIZ+7];
185 int ret = 0;
186
187 /* first, create a link from the slave back to the master */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700188 ret = sysfs_create_link(&(slave->dev.kobj), &(master->dev.kobj),
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800189 "master");
190 if (ret)
191 return ret;
192 /* next, create a link from the master to the slave */
193 sprintf(linkname,"slave_%s",slave->name);
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700194 ret = sysfs_create_link(&(master->dev.kobj), &(slave->dev.kobj),
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800195 linkname);
196 return ret;
197
198}
199
200void bond_destroy_slave_symlinks(struct net_device *master, struct net_device *slave)
201{
202 char linkname[IFNAMSIZ+7];
203
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700204 sysfs_remove_link(&(slave->dev.kobj), "master");
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800205 sprintf(linkname,"slave_%s",slave->name);
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700206 sysfs_remove_link(&(master->dev.kobj), linkname);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800207}
208
209
210/*
211 * Show the slaves in the current bond.
212 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700213static ssize_t bonding_show_slaves(struct device *d,
214 struct device_attribute *attr, char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800215{
216 struct slave *slave;
217 int i, res = 0;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700218 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800219
Jay Vosburgh6603a6f2007-10-17 17:37:50 -0700220 read_lock(&bond->lock);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800221 bond_for_each_slave(bond, slave, i) {
222 if (res > (PAGE_SIZE - IFNAMSIZ)) {
223 /* not enough space for another interface name */
224 if ((PAGE_SIZE - res) > 10)
225 res = PAGE_SIZE - 10;
Wagner Ferenc7bd46502007-12-06 23:40:28 -0800226 res += sprintf(buf + res, "++more++ ");
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800227 break;
228 }
229 res += sprintf(buf + res, "%s ", slave->dev->name);
230 }
Jay Vosburgh6603a6f2007-10-17 17:37:50 -0700231 read_unlock(&bond->lock);
Wagner Ferenc1dcdcd62007-12-06 23:40:31 -0800232 if (res)
233 buf[res-1] = '\n'; /* eat the leftover space */
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800234 return res;
235}
236
237/*
238 * Set the slaves in the current bond. The bond interface must be
239 * up for this to succeed.
240 * This function is largely the same flow as bonding_update_bonds().
241 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700242static ssize_t bonding_store_slaves(struct device *d,
243 struct device_attribute *attr,
244 const char *buffer, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800245{
246 char command[IFNAMSIZ + 1] = { 0, };
247 char *ifname;
248 int i, res, found, ret = count;
Moni Shoua3158bf72007-10-09 19:43:41 -0700249 u32 original_mtu;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800250 struct slave *slave;
Luiz Fernando Capitulino3418db72006-02-01 00:54:34 -0800251 struct net_device *dev = NULL;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700252 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800253
254 /* Quick sanity check -- is the bond interface up? */
255 if (!(bond->dev->flags & IFF_UP)) {
Moni Shoua6b1bf092007-10-09 19:43:40 -0700256 printk(KERN_WARNING DRV_NAME
257 ": %s: doing slave updates when interface is down.\n",
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800258 bond->dev->name);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800259 }
260
261 /* Note: We can't hold bond->lock here, as bond_create grabs it. */
262
Jay Vosburgh027ea042008-01-17 16:25:02 -0800263 rtnl_lock();
264 down_write(&(bonding_rwsem));
265
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800266 sscanf(buffer, "%16s", command); /* IFNAMSIZ*/
267 ifname = command + 1;
268 if ((strlen(command) <= 1) ||
269 !dev_valid_name(ifname))
270 goto err_no_cmd;
271
272 if (command[0] == '+') {
273
274 /* Got a slave name in ifname. Is it already in the list? */
275 found = 0;
Jay Vosburgh6603a6f2007-10-17 17:37:50 -0700276 read_lock(&bond->lock);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800277 bond_for_each_slave(bond, slave, i)
278 if (strnicmp(slave->dev->name, ifname, IFNAMSIZ) == 0) {
279 printk(KERN_ERR DRV_NAME
280 ": %s: Interface %s is already enslaved!\n",
281 bond->dev->name, ifname);
282 ret = -EPERM;
Jay Vosburgh6603a6f2007-10-17 17:37:50 -0700283 read_unlock(&bond->lock);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800284 goto out;
285 }
286
Jay Vosburgh6603a6f2007-10-17 17:37:50 -0700287 read_unlock(&bond->lock);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800288 printk(KERN_INFO DRV_NAME ": %s: Adding slave %s.\n",
289 bond->dev->name, ifname);
Eric W. Biederman881d9662007-09-17 11:56:21 -0700290 dev = dev_get_by_name(&init_net, ifname);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800291 if (!dev) {
292 printk(KERN_INFO DRV_NAME
293 ": %s: Interface %s does not exist!\n",
294 bond->dev->name, ifname);
295 ret = -EPERM;
296 goto out;
297 }
298 else
299 dev_put(dev);
300
301 if (dev->flags & IFF_UP) {
302 printk(KERN_ERR DRV_NAME
303 ": %s: Error: Unable to enslave %s "
304 "because it is already up.\n",
305 bond->dev->name, dev->name);
306 ret = -EPERM;
307 goto out;
308 }
309 /* If this is the first slave, then we need to set
310 the master's hardware address to be the same as the
311 slave's. */
312 if (!(*((u32 *) & (bond->dev->dev_addr[0])))) {
313 memcpy(bond->dev->dev_addr, dev->dev_addr,
314 dev->addr_len);
315 }
316
317 /* Set the slave's MTU to match the bond */
Moni Shoua3158bf72007-10-09 19:43:41 -0700318 original_mtu = dev->mtu;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800319 if (dev->mtu != bond->dev->mtu) {
320 if (dev->change_mtu) {
321 res = dev->change_mtu(dev,
322 bond->dev->mtu);
323 if (res) {
324 ret = res;
325 goto out;
326 }
327 } else {
328 dev->mtu = bond->dev->mtu;
329 }
330 }
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800331 res = bond_enslave(bond->dev, dev);
Moni Shoua3158bf72007-10-09 19:43:41 -0700332 bond_for_each_slave(bond, slave, i)
333 if (strnicmp(slave->dev->name, ifname, IFNAMSIZ) == 0)
334 slave->original_mtu = original_mtu;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800335 if (res) {
336 ret = res;
337 }
338 goto out;
339 }
340
341 if (command[0] == '-') {
342 dev = NULL;
David S. Miller6952d8922008-03-28 16:15:38 -0700343 original_mtu = 0;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800344 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
Jay Vosburgh3915c1e82008-05-17 21:10:14 -0700550 return sprintf(buf, "%s %d\n",
551 fail_over_mac_tbl[bond->params.fail_over_mac].modename,
552 bond->params.fail_over_mac);
Jay Vosburghdd957c52007-10-09 19:57:24 -0700553}
554
555static ssize_t bonding_store_fail_over_mac(struct device *d, struct device_attribute *attr, const char *buf, size_t count)
556{
557 int new_value;
Jay Vosburghdd957c52007-10-09 19:57:24 -0700558 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);
Jay Vosburgh3915c1e82008-05-17 21:10:14 -0700564 return -EPERM;
Jay Vosburghdd957c52007-10-09 19:57:24 -0700565 }
566
Jay Vosburgh3915c1e82008-05-17 21:10:14 -0700567 new_value = bond_parse_parm(buf, fail_over_mac_tbl);
568 if (new_value < 0) {
Jay Vosburghdd957c52007-10-09 19:57:24 -0700569 printk(KERN_ERR DRV_NAME
Jay Vosburgh3915c1e82008-05-17 21:10:14 -0700570 ": %s: Ignoring invalid fail_over_mac value %s.\n",
571 bond->dev->name, buf);
572 return -EINVAL;
Jay Vosburghdd957c52007-10-09 19:57:24 -0700573 }
574
Jay Vosburgh3915c1e82008-05-17 21:10:14 -0700575 bond->params.fail_over_mac = new_value;
576 printk(KERN_INFO DRV_NAME ": %s: Setting fail_over_mac to %s (%d).\n",
577 bond->dev->name, fail_over_mac_tbl[new_value].modename,
578 new_value);
579
580 return count;
Jay Vosburghdd957c52007-10-09 19:57:24 -0700581}
582
583static DEVICE_ATTR(fail_over_mac, S_IRUGO | S_IWUSR, bonding_show_fail_over_mac, bonding_store_fail_over_mac);
584
585/*
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800586 * Show and set the arp timer interval. There are two tricky bits
587 * here. First, if ARP monitoring is activated, then we must disable
588 * MII monitoring. Second, if the ARP timer isn't running, we must
589 * start it.
590 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700591static ssize_t bonding_show_arp_interval(struct device *d,
592 struct device_attribute *attr,
593 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800594{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700595 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800596
Wagner Ferenc7bd46502007-12-06 23:40:28 -0800597 return sprintf(buf, "%d\n", bond->params.arp_interval);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800598}
599
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700600static ssize_t bonding_store_arp_interval(struct device *d,
601 struct device_attribute *attr,
602 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800603{
604 int new_value, ret = count;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700605 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800606
607 if (sscanf(buf, "%d", &new_value) != 1) {
608 printk(KERN_ERR DRV_NAME
609 ": %s: no arp_interval value specified.\n",
610 bond->dev->name);
611 ret = -EINVAL;
612 goto out;
613 }
614 if (new_value < 0) {
615 printk(KERN_ERR DRV_NAME
616 ": %s: Invalid arp_interval value %d not in range 1-%d; rejected.\n",
617 bond->dev->name, new_value, INT_MAX);
618 ret = -EINVAL;
619 goto out;
620 }
621
622 printk(KERN_INFO DRV_NAME
623 ": %s: Setting ARP monitoring interval to %d.\n",
624 bond->dev->name, new_value);
625 bond->params.arp_interval = new_value;
626 if (bond->params.miimon) {
627 printk(KERN_INFO DRV_NAME
628 ": %s: ARP monitoring cannot be used with MII monitoring. "
629 "%s Disabling MII monitoring.\n",
630 bond->dev->name, bond->dev->name);
631 bond->params.miimon = 0;
Jay Vosburgh1b76b312007-10-17 17:37:45 -0700632 if (delayed_work_pending(&bond->mii_work)) {
633 cancel_delayed_work(&bond->mii_work);
634 flush_workqueue(bond->wq);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800635 }
636 }
637 if (!bond->params.arp_targets[0]) {
638 printk(KERN_INFO DRV_NAME
639 ": %s: ARP monitoring has been set up, "
640 "but no ARP targets have been specified.\n",
641 bond->dev->name);
642 }
643 if (bond->dev->flags & IFF_UP) {
644 /* If the interface is up, we may need to fire off
645 * the ARP timer. If the interface is down, the
646 * timer will get fired off when the open function
647 * is called.
648 */
Jay Vosburgh1b76b312007-10-17 17:37:45 -0700649 if (!delayed_work_pending(&bond->arp_work)) {
650 if (bond->params.mode == BOND_MODE_ACTIVEBACKUP)
651 INIT_DELAYED_WORK(&bond->arp_work,
652 bond_activebackup_arp_mon);
653 else
654 INIT_DELAYED_WORK(&bond->arp_work,
655 bond_loadbalance_arp_mon);
656
657 queue_delayed_work(bond->wq, &bond->arp_work, 0);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800658 }
659 }
660
661out:
662 return ret;
663}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700664static DEVICE_ATTR(arp_interval, S_IRUGO | S_IWUSR , bonding_show_arp_interval, bonding_store_arp_interval);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800665
666/*
667 * Show and set the arp targets.
668 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700669static ssize_t bonding_show_arp_targets(struct device *d,
670 struct device_attribute *attr,
671 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800672{
673 int i, res = 0;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700674 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800675
676 for (i = 0; i < BOND_MAX_ARP_TARGETS; i++) {
677 if (bond->params.arp_targets[i])
678 res += sprintf(buf + res, "%u.%u.%u.%u ",
679 NIPQUAD(bond->params.arp_targets[i]));
680 }
Wagner Ferenc1dcdcd62007-12-06 23:40:31 -0800681 if (res)
682 buf[res-1] = '\n'; /* eat the leftover space */
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800683 return res;
684}
685
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700686static ssize_t bonding_store_arp_targets(struct device *d,
687 struct device_attribute *attr,
688 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800689{
Al Virod3bb52b2007-08-22 20:06:58 -0400690 __be32 newtarget;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800691 int i = 0, done = 0, ret = count;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700692 struct bonding *bond = to_bond(d);
Al Virod3bb52b2007-08-22 20:06:58 -0400693 __be32 *targets;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800694
695 targets = bond->params.arp_targets;
696 newtarget = in_aton(buf + 1);
697 /* look for adds */
698 if (buf[0] == '+') {
Al Virod3bb52b2007-08-22 20:06:58 -0400699 if ((newtarget == 0) || (newtarget == htonl(INADDR_BROADCAST))) {
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800700 printk(KERN_ERR DRV_NAME
701 ": %s: invalid ARP target %u.%u.%u.%u specified for addition\n",
702 bond->dev->name, NIPQUAD(newtarget));
703 ret = -EINVAL;
704 goto out;
705 }
706 /* look for an empty slot to put the target in, and check for dupes */
707 for (i = 0; (i < BOND_MAX_ARP_TARGETS); i++) {
708 if (targets[i] == newtarget) { /* duplicate */
709 printk(KERN_ERR DRV_NAME
710 ": %s: ARP target %u.%u.%u.%u is already present\n",
711 bond->dev->name, NIPQUAD(newtarget));
712 if (done)
713 targets[i] = 0;
714 ret = -EINVAL;
715 goto out;
716 }
717 if (targets[i] == 0 && !done) {
718 printk(KERN_INFO DRV_NAME
719 ": %s: adding ARP target %d.%d.%d.%d.\n",
720 bond->dev->name, NIPQUAD(newtarget));
721 done = 1;
722 targets[i] = newtarget;
723 }
724 }
725 if (!done) {
726 printk(KERN_ERR DRV_NAME
727 ": %s: ARP target table is full!\n",
728 bond->dev->name);
729 ret = -EINVAL;
730 goto out;
731 }
732
733 }
734 else if (buf[0] == '-') {
Al Virod3bb52b2007-08-22 20:06:58 -0400735 if ((newtarget == 0) || (newtarget == htonl(INADDR_BROADCAST))) {
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800736 printk(KERN_ERR DRV_NAME
737 ": %s: invalid ARP target %d.%d.%d.%d specified for removal\n",
738 bond->dev->name, NIPQUAD(newtarget));
739 ret = -EINVAL;
740 goto out;
741 }
742
743 for (i = 0; (i < BOND_MAX_ARP_TARGETS); i++) {
744 if (targets[i] == newtarget) {
745 printk(KERN_INFO DRV_NAME
746 ": %s: removing ARP target %d.%d.%d.%d.\n",
747 bond->dev->name, NIPQUAD(newtarget));
748 targets[i] = 0;
749 done = 1;
750 }
751 }
752 if (!done) {
753 printk(KERN_INFO DRV_NAME
754 ": %s: unable to remove nonexistent ARP target %d.%d.%d.%d.\n",
755 bond->dev->name, NIPQUAD(newtarget));
756 ret = -EINVAL;
757 goto out;
758 }
759 }
760 else {
761 printk(KERN_ERR DRV_NAME ": no command found in arp_ip_targets file for bond %s. Use +<addr> or -<addr>.\n",
762 bond->dev->name);
763 ret = -EPERM;
764 goto out;
765 }
766
767out:
768 return ret;
769}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700770static DEVICE_ATTR(arp_ip_target, S_IRUGO | S_IWUSR , bonding_show_arp_targets, bonding_store_arp_targets);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800771
772/*
773 * Show and set the up and down delays. These must be multiples of the
774 * MII monitoring value, and are stored internally as the multiplier.
775 * Thus, we must translate to MS for the real world.
776 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700777static ssize_t bonding_show_downdelay(struct device *d,
778 struct device_attribute *attr,
779 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800780{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700781 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800782
Wagner Ferenc7bd46502007-12-06 23:40:28 -0800783 return sprintf(buf, "%d\n", bond->params.downdelay * bond->params.miimon);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800784}
785
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700786static ssize_t bonding_store_downdelay(struct device *d,
787 struct device_attribute *attr,
788 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800789{
790 int new_value, ret = count;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700791 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800792
793 if (!(bond->params.miimon)) {
794 printk(KERN_ERR DRV_NAME
795 ": %s: Unable to set down delay as MII monitoring is disabled\n",
796 bond->dev->name);
797 ret = -EPERM;
798 goto out;
799 }
800
801 if (sscanf(buf, "%d", &new_value) != 1) {
802 printk(KERN_ERR DRV_NAME
803 ": %s: no down delay value specified.\n",
804 bond->dev->name);
805 ret = -EINVAL;
806 goto out;
807 }
808 if (new_value < 0) {
809 printk(KERN_ERR DRV_NAME
810 ": %s: Invalid down delay value %d not in range %d-%d; rejected.\n",
811 bond->dev->name, new_value, 1, INT_MAX);
812 ret = -EINVAL;
813 goto out;
814 } else {
815 if ((new_value % bond->params.miimon) != 0) {
816 printk(KERN_WARNING DRV_NAME
817 ": %s: Warning: down delay (%d) is not a multiple "
818 "of miimon (%d), delay rounded to %d ms\n",
819 bond->dev->name, new_value, bond->params.miimon,
820 (new_value / bond->params.miimon) *
821 bond->params.miimon);
822 }
823 bond->params.downdelay = new_value / bond->params.miimon;
824 printk(KERN_INFO DRV_NAME ": %s: Setting down delay to %d.\n",
825 bond->dev->name, bond->params.downdelay * bond->params.miimon);
826
827 }
828
829out:
830 return ret;
831}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700832static DEVICE_ATTR(downdelay, S_IRUGO | S_IWUSR , bonding_show_downdelay, bonding_store_downdelay);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800833
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700834static ssize_t bonding_show_updelay(struct device *d,
835 struct device_attribute *attr,
836 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800837{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700838 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800839
Wagner Ferenc7bd46502007-12-06 23:40:28 -0800840 return sprintf(buf, "%d\n", bond->params.updelay * bond->params.miimon);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800841
842}
843
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700844static ssize_t bonding_store_updelay(struct device *d,
845 struct device_attribute *attr,
846 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800847{
848 int new_value, ret = count;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700849 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800850
851 if (!(bond->params.miimon)) {
852 printk(KERN_ERR DRV_NAME
853 ": %s: Unable to set up delay as MII monitoring is disabled\n",
854 bond->dev->name);
855 ret = -EPERM;
856 goto out;
857 }
858
859 if (sscanf(buf, "%d", &new_value) != 1) {
860 printk(KERN_ERR DRV_NAME
861 ": %s: no up delay value specified.\n",
862 bond->dev->name);
863 ret = -EINVAL;
864 goto out;
865 }
866 if (new_value < 0) {
867 printk(KERN_ERR DRV_NAME
868 ": %s: Invalid down delay value %d not in range %d-%d; rejected.\n",
869 bond->dev->name, new_value, 1, INT_MAX);
870 ret = -EINVAL;
871 goto out;
872 } else {
873 if ((new_value % bond->params.miimon) != 0) {
874 printk(KERN_WARNING DRV_NAME
875 ": %s: Warning: up delay (%d) is not a multiple "
876 "of miimon (%d), updelay rounded to %d ms\n",
877 bond->dev->name, new_value, bond->params.miimon,
878 (new_value / bond->params.miimon) *
879 bond->params.miimon);
880 }
881 bond->params.updelay = new_value / bond->params.miimon;
882 printk(KERN_INFO DRV_NAME ": %s: Setting up delay to %d.\n",
883 bond->dev->name, bond->params.updelay * bond->params.miimon);
884
885 }
886
887out:
888 return ret;
889}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700890static DEVICE_ATTR(updelay, S_IRUGO | S_IWUSR , bonding_show_updelay, bonding_store_updelay);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800891
892/*
893 * Show and set the LACP interval. Interface must be down, and the mode
894 * must be set to 802.3ad mode.
895 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700896static ssize_t bonding_show_lacp(struct device *d,
897 struct device_attribute *attr,
898 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800899{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700900 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800901
902 return sprintf(buf, "%s %d\n",
903 bond_lacp_tbl[bond->params.lacp_fast].modename,
Wagner Ferenc7bd46502007-12-06 23:40:28 -0800904 bond->params.lacp_fast);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800905}
906
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700907static ssize_t bonding_store_lacp(struct device *d,
908 struct device_attribute *attr,
909 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800910{
911 int new_value, ret = count;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700912 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800913
914 if (bond->dev->flags & IFF_UP) {
915 printk(KERN_ERR DRV_NAME
916 ": %s: Unable to update LACP rate because interface is up.\n",
917 bond->dev->name);
918 ret = -EPERM;
919 goto out;
920 }
921
922 if (bond->params.mode != BOND_MODE_8023AD) {
923 printk(KERN_ERR DRV_NAME
924 ": %s: Unable to update LACP rate because bond is not in 802.3ad mode.\n",
925 bond->dev->name);
926 ret = -EPERM;
927 goto out;
928 }
929
Jay Vosburghece95f72008-01-17 16:25:01 -0800930 new_value = bond_parse_parm(buf, bond_lacp_tbl);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800931
932 if ((new_value == 1) || (new_value == 0)) {
933 bond->params.lacp_fast = new_value;
934 printk(KERN_INFO DRV_NAME
935 ": %s: Setting LACP rate to %s (%d).\n",
936 bond->dev->name, bond_lacp_tbl[new_value].modename, new_value);
937 } else {
938 printk(KERN_ERR DRV_NAME
939 ": %s: Ignoring invalid LACP rate value %.*s.\n",
940 bond->dev->name, (int)strlen(buf) - 1, buf);
941 ret = -EINVAL;
942 }
943out:
944 return ret;
945}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700946static DEVICE_ATTR(lacp_rate, S_IRUGO | S_IWUSR, bonding_show_lacp, bonding_store_lacp);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800947
948/*
Moni Shoua7893b242008-05-17 21:10:12 -0700949 * Show and set the number of grat ARP to send after a failover event.
950 */
951static ssize_t bonding_show_n_grat_arp(struct device *d,
952 struct device_attribute *attr,
953 char *buf)
954{
955 struct bonding *bond = to_bond(d);
956
957 return sprintf(buf, "%d\n", bond->params.num_grat_arp);
958}
959
960static ssize_t bonding_store_n_grat_arp(struct device *d,
961 struct device_attribute *attr,
962 const char *buf, size_t count)
963{
964 int new_value, ret = count;
965 struct bonding *bond = to_bond(d);
966
967 if (sscanf(buf, "%d", &new_value) != 1) {
968 printk(KERN_ERR DRV_NAME
969 ": %s: no num_grat_arp value specified.\n",
970 bond->dev->name);
971 ret = -EINVAL;
972 goto out;
973 }
974 if (new_value < 0 || new_value > 255) {
975 printk(KERN_ERR DRV_NAME
976 ": %s: Invalid num_grat_arp value %d not in range 0-255; rejected.\n",
977 bond->dev->name, new_value);
978 ret = -EINVAL;
979 goto out;
980 } else {
981 bond->params.num_grat_arp = new_value;
982 }
983out:
984 return ret;
985}
986static DEVICE_ATTR(num_grat_arp, S_IRUGO | S_IWUSR, bonding_show_n_grat_arp, bonding_store_n_grat_arp);
987/*
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800988 * Show and set the MII monitor interval. There are two tricky bits
989 * here. First, if MII monitoring is activated, then we must disable
990 * ARP monitoring. Second, if the timer isn't running, we must
991 * start it.
992 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700993static ssize_t bonding_show_miimon(struct device *d,
994 struct device_attribute *attr,
995 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800996{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700997 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800998
Wagner Ferenc7bd46502007-12-06 23:40:28 -0800999 return sprintf(buf, "%d\n", bond->params.miimon);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001000}
1001
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001002static ssize_t bonding_store_miimon(struct device *d,
1003 struct device_attribute *attr,
1004 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001005{
1006 int new_value, ret = count;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001007 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001008
1009 if (sscanf(buf, "%d", &new_value) != 1) {
1010 printk(KERN_ERR DRV_NAME
1011 ": %s: no miimon value specified.\n",
1012 bond->dev->name);
1013 ret = -EINVAL;
1014 goto out;
1015 }
1016 if (new_value < 0) {
1017 printk(KERN_ERR DRV_NAME
1018 ": %s: Invalid miimon value %d not in range %d-%d; rejected.\n",
1019 bond->dev->name, new_value, 1, INT_MAX);
1020 ret = -EINVAL;
1021 goto out;
1022 } else {
1023 printk(KERN_INFO DRV_NAME
1024 ": %s: Setting MII monitoring interval to %d.\n",
1025 bond->dev->name, new_value);
1026 bond->params.miimon = new_value;
1027 if(bond->params.updelay)
1028 printk(KERN_INFO DRV_NAME
1029 ": %s: Note: Updating updelay (to %d) "
1030 "since it is a multiple of the miimon value.\n",
1031 bond->dev->name,
1032 bond->params.updelay * bond->params.miimon);
1033 if(bond->params.downdelay)
1034 printk(KERN_INFO DRV_NAME
1035 ": %s: Note: Updating downdelay (to %d) "
1036 "since it is a multiple of the miimon value.\n",
1037 bond->dev->name,
1038 bond->params.downdelay * bond->params.miimon);
1039 if (bond->params.arp_interval) {
1040 printk(KERN_INFO DRV_NAME
1041 ": %s: MII monitoring cannot be used with "
1042 "ARP monitoring. Disabling ARP monitoring...\n",
1043 bond->dev->name);
1044 bond->params.arp_interval = 0;
Jay Vosburghf5b2b962006-09-22 21:54:53 -07001045 if (bond->params.arp_validate) {
1046 bond_unregister_arp(bond);
1047 bond->params.arp_validate =
1048 BOND_ARP_VALIDATE_NONE;
1049 }
Jay Vosburgh1b76b312007-10-17 17:37:45 -07001050 if (delayed_work_pending(&bond->arp_work)) {
1051 cancel_delayed_work(&bond->arp_work);
1052 flush_workqueue(bond->wq);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001053 }
1054 }
1055
1056 if (bond->dev->flags & IFF_UP) {
1057 /* If the interface is up, we may need to fire off
1058 * the MII timer. If the interface is down, the
1059 * timer will get fired off when the open function
1060 * is called.
1061 */
Jay Vosburgh1b76b312007-10-17 17:37:45 -07001062 if (!delayed_work_pending(&bond->mii_work)) {
1063 INIT_DELAYED_WORK(&bond->mii_work,
1064 bond_mii_monitor);
1065 queue_delayed_work(bond->wq,
1066 &bond->mii_work, 0);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001067 }
1068 }
1069 }
1070out:
1071 return ret;
1072}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001073static DEVICE_ATTR(miimon, S_IRUGO | S_IWUSR, bonding_show_miimon, bonding_store_miimon);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001074
1075/*
1076 * Show and set the primary slave. The store function is much
1077 * simpler than bonding_store_slaves function because it only needs to
1078 * handle one interface name.
1079 * The bond must be a mode that supports a primary for this be
1080 * set.
1081 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001082static ssize_t bonding_show_primary(struct device *d,
1083 struct device_attribute *attr,
1084 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001085{
1086 int count = 0;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001087 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001088
1089 if (bond->primary_slave)
Wagner Ferenc7bd46502007-12-06 23:40:28 -08001090 count = sprintf(buf, "%s\n", bond->primary_slave->dev->name);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001091
1092 return count;
1093}
1094
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001095static ssize_t bonding_store_primary(struct device *d,
1096 struct device_attribute *attr,
1097 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001098{
1099 int i;
1100 struct slave *slave;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001101 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001102
Jay Vosburghe934dd72008-01-17 16:24:57 -08001103 rtnl_lock();
1104 read_lock(&bond->lock);
1105 write_lock_bh(&bond->curr_slave_lock);
1106
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001107 if (!USES_PRIMARY(bond->params.mode)) {
1108 printk(KERN_INFO DRV_NAME
1109 ": %s: Unable to set primary slave; %s is in mode %d\n",
1110 bond->dev->name, bond->dev->name, bond->params.mode);
1111 } else {
1112 bond_for_each_slave(bond, slave, i) {
1113 if (strnicmp
1114 (slave->dev->name, buf,
1115 strlen(slave->dev->name)) == 0) {
1116 printk(KERN_INFO DRV_NAME
1117 ": %s: Setting %s as primary slave.\n",
1118 bond->dev->name, slave->dev->name);
1119 bond->primary_slave = slave;
1120 bond_select_active_slave(bond);
1121 goto out;
1122 }
1123 }
1124
1125 /* if we got here, then we didn't match the name of any slave */
1126
1127 if (strlen(buf) == 0 || buf[0] == '\n') {
1128 printk(KERN_INFO DRV_NAME
1129 ": %s: Setting primary slave to None.\n",
1130 bond->dev->name);
Luiz Fernando Capitulino3418db72006-02-01 00:54:34 -08001131 bond->primary_slave = NULL;
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001132 bond_select_active_slave(bond);
1133 } else {
1134 printk(KERN_INFO DRV_NAME
1135 ": %s: Unable to set %.*s as primary slave as it is not a slave.\n",
1136 bond->dev->name, (int)strlen(buf) - 1, buf);
1137 }
1138 }
1139out:
Jay Vosburghe934dd72008-01-17 16:24:57 -08001140 write_unlock_bh(&bond->curr_slave_lock);
1141 read_unlock(&bond->lock);
Jay Vosburgh6603a6f2007-10-17 17:37:50 -07001142 rtnl_unlock();
1143
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001144 return count;
1145}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001146static DEVICE_ATTR(primary, S_IRUGO | S_IWUSR, bonding_show_primary, bonding_store_primary);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001147
1148/*
1149 * Show and set the use_carrier flag.
1150 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001151static ssize_t bonding_show_carrier(struct device *d,
1152 struct device_attribute *attr,
1153 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001154{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001155 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001156
Wagner Ferenc7bd46502007-12-06 23:40:28 -08001157 return sprintf(buf, "%d\n", bond->params.use_carrier);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001158}
1159
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001160static ssize_t bonding_store_carrier(struct device *d,
1161 struct device_attribute *attr,
1162 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001163{
1164 int new_value, ret = count;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001165 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001166
1167
1168 if (sscanf(buf, "%d", &new_value) != 1) {
1169 printk(KERN_ERR DRV_NAME
1170 ": %s: no use_carrier value specified.\n",
1171 bond->dev->name);
1172 ret = -EINVAL;
1173 goto out;
1174 }
1175 if ((new_value == 0) || (new_value == 1)) {
1176 bond->params.use_carrier = new_value;
1177 printk(KERN_INFO DRV_NAME ": %s: Setting use_carrier to %d.\n",
1178 bond->dev->name, new_value);
1179 } else {
1180 printk(KERN_INFO DRV_NAME
1181 ": %s: Ignoring invalid use_carrier value %d.\n",
1182 bond->dev->name, new_value);
1183 }
1184out:
1185 return count;
1186}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001187static DEVICE_ATTR(use_carrier, S_IRUGO | S_IWUSR, bonding_show_carrier, bonding_store_carrier);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001188
1189
1190/*
1191 * Show and set currently active_slave.
1192 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001193static ssize_t bonding_show_active_slave(struct device *d,
1194 struct device_attribute *attr,
1195 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001196{
1197 struct slave *curr;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001198 struct bonding *bond = to_bond(d);
Wagner Ferenc16cd0162007-12-06 23:40:29 -08001199 int count = 0;
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001200
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001201 read_lock(&bond->curr_slave_lock);
1202 curr = bond->curr_active_slave;
1203 read_unlock(&bond->curr_slave_lock);
1204
1205 if (USES_PRIMARY(bond->params.mode) && curr)
Wagner Ferenc7bd46502007-12-06 23:40:28 -08001206 count = sprintf(buf, "%s\n", curr->dev->name);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001207 return count;
1208}
1209
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001210static ssize_t bonding_store_active_slave(struct device *d,
1211 struct device_attribute *attr,
1212 const char *buf, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001213{
1214 int i;
1215 struct slave *slave;
1216 struct slave *old_active = NULL;
1217 struct slave *new_active = NULL;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001218 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001219
Jay Vosburgh1466a212007-11-06 13:33:28 -08001220 rtnl_lock();
Jay Vosburghe934dd72008-01-17 16:24:57 -08001221 read_lock(&bond->lock);
1222 write_lock_bh(&bond->curr_slave_lock);
Jay Vosburgh1466a212007-11-06 13:33:28 -08001223
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001224 if (!USES_PRIMARY(bond->params.mode)) {
1225 printk(KERN_INFO DRV_NAME
1226 ": %s: Unable to change active slave; %s is in mode %d\n",
1227 bond->dev->name, bond->dev->name, bond->params.mode);
1228 } else {
1229 bond_for_each_slave(bond, slave, i) {
1230 if (strnicmp
1231 (slave->dev->name, buf,
1232 strlen(slave->dev->name)) == 0) {
1233 old_active = bond->curr_active_slave;
1234 new_active = slave;
Jay Vosburgha50d8de2006-09-22 21:53:25 -07001235 if (new_active == old_active) {
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001236 /* do nothing */
1237 printk(KERN_INFO DRV_NAME
1238 ": %s: %s is already the current active slave.\n",
1239 bond->dev->name, slave->dev->name);
1240 goto out;
1241 }
1242 else {
1243 if ((new_active) &&
1244 (old_active) &&
1245 (new_active->link == BOND_LINK_UP) &&
1246 IS_UP(new_active->dev)) {
1247 printk(KERN_INFO DRV_NAME
1248 ": %s: Setting %s as active slave.\n",
1249 bond->dev->name, slave->dev->name);
1250 bond_change_active_slave(bond, new_active);
1251 }
1252 else {
1253 printk(KERN_INFO DRV_NAME
1254 ": %s: Could not set %s as active slave; "
1255 "either %s is down or the link is down.\n",
1256 bond->dev->name, slave->dev->name,
1257 slave->dev->name);
1258 }
1259 goto out;
1260 }
1261 }
1262 }
1263
1264 /* if we got here, then we didn't match the name of any slave */
1265
1266 if (strlen(buf) == 0 || buf[0] == '\n') {
1267 printk(KERN_INFO DRV_NAME
1268 ": %s: Setting active slave to None.\n",
1269 bond->dev->name);
Luiz Fernando Capitulino3418db72006-02-01 00:54:34 -08001270 bond->primary_slave = NULL;
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001271 bond_select_active_slave(bond);
1272 } else {
1273 printk(KERN_INFO DRV_NAME
1274 ": %s: Unable to set %.*s as active slave as it is not a slave.\n",
1275 bond->dev->name, (int)strlen(buf) - 1, buf);
1276 }
1277 }
1278out:
Jay Vosburghe934dd72008-01-17 16:24:57 -08001279 write_unlock_bh(&bond->curr_slave_lock);
1280 read_unlock(&bond->lock);
Jay Vosburgh6603a6f2007-10-17 17:37:50 -07001281 rtnl_unlock();
1282
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001283 return count;
1284
1285}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001286static DEVICE_ATTR(active_slave, S_IRUGO | S_IWUSR, bonding_show_active_slave, bonding_store_active_slave);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001287
1288
1289/*
1290 * Show link status of the bond interface.
1291 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001292static ssize_t bonding_show_mii_status(struct device *d,
1293 struct device_attribute *attr,
1294 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001295{
1296 struct slave *curr;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001297 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001298
1299 read_lock(&bond->curr_slave_lock);
1300 curr = bond->curr_active_slave;
1301 read_unlock(&bond->curr_slave_lock);
1302
Wagner Ferenc7bd46502007-12-06 23:40:28 -08001303 return sprintf(buf, "%s\n", (curr) ? "up" : "down");
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001304}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001305static DEVICE_ATTR(mii_status, S_IRUGO, bonding_show_mii_status, NULL);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001306
1307
1308/*
1309 * Show current 802.3ad aggregator ID.
1310 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001311static ssize_t bonding_show_ad_aggregator(struct device *d,
1312 struct device_attribute *attr,
1313 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001314{
1315 int count = 0;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001316 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001317
1318 if (bond->params.mode == BOND_MODE_8023AD) {
1319 struct ad_info ad_info;
Wagner Ferenc7bd46502007-12-06 23:40:28 -08001320 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 -08001321 }
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001322
1323 return count;
1324}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001325static DEVICE_ATTR(ad_aggregator, S_IRUGO, bonding_show_ad_aggregator, NULL);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001326
1327
1328/*
1329 * Show number of active 802.3ad ports.
1330 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001331static ssize_t bonding_show_ad_num_ports(struct device *d,
1332 struct device_attribute *attr,
1333 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001334{
1335 int count = 0;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001336 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001337
1338 if (bond->params.mode == BOND_MODE_8023AD) {
1339 struct ad_info ad_info;
Wagner Ferenc7bd46502007-12-06 23:40:28 -08001340 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 -08001341 }
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001342
1343 return count;
1344}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001345static DEVICE_ATTR(ad_num_ports, S_IRUGO, bonding_show_ad_num_ports, NULL);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001346
1347
1348/*
1349 * Show current 802.3ad actor key.
1350 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001351static ssize_t bonding_show_ad_actor_key(struct device *d,
1352 struct device_attribute *attr,
1353 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001354{
1355 int count = 0;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001356 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001357
1358 if (bond->params.mode == BOND_MODE_8023AD) {
1359 struct ad_info ad_info;
Wagner Ferenc7bd46502007-12-06 23:40:28 -08001360 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 -08001361 }
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001362
1363 return count;
1364}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001365static DEVICE_ATTR(ad_actor_key, S_IRUGO, bonding_show_ad_actor_key, NULL);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001366
1367
1368/*
1369 * Show current 802.3ad partner key.
1370 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001371static ssize_t bonding_show_ad_partner_key(struct device *d,
1372 struct device_attribute *attr,
1373 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001374{
1375 int count = 0;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001376 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001377
1378 if (bond->params.mode == BOND_MODE_8023AD) {
1379 struct ad_info ad_info;
Wagner Ferenc7bd46502007-12-06 23:40:28 -08001380 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 -08001381 }
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001382
1383 return count;
1384}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001385static DEVICE_ATTR(ad_partner_key, S_IRUGO, bonding_show_ad_partner_key, NULL);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001386
1387
1388/*
1389 * Show current 802.3ad partner mac.
1390 */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001391static ssize_t bonding_show_ad_partner_mac(struct device *d,
1392 struct device_attribute *attr,
1393 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001394{
1395 int count = 0;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001396 struct bonding *bond = to_bond(d);
Joe Perches0795af52007-10-03 17:59:30 -07001397 DECLARE_MAC_BUF(mac);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001398
1399 if (bond->params.mode == BOND_MODE_8023AD) {
1400 struct ad_info ad_info;
1401 if (!bond_3ad_get_active_agg_info(bond, &ad_info)) {
Joe Perches0795af52007-10-03 17:59:30 -07001402 count = sprintf(buf,"%s\n",
Wagner Ferenc7bd46502007-12-06 23:40:28 -08001403 print_mac(mac, ad_info.partner_system));
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001404 }
1405 }
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001406
1407 return count;
1408}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001409static DEVICE_ATTR(ad_partner_mac, S_IRUGO, bonding_show_ad_partner_mac, NULL);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001410
1411
1412
1413static struct attribute *per_bond_attrs[] = {
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001414 &dev_attr_slaves.attr,
1415 &dev_attr_mode.attr,
Jay Vosburghdd957c52007-10-09 19:57:24 -07001416 &dev_attr_fail_over_mac.attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001417 &dev_attr_arp_validate.attr,
1418 &dev_attr_arp_interval.attr,
1419 &dev_attr_arp_ip_target.attr,
1420 &dev_attr_downdelay.attr,
1421 &dev_attr_updelay.attr,
1422 &dev_attr_lacp_rate.attr,
1423 &dev_attr_xmit_hash_policy.attr,
Moni Shoua7893b242008-05-17 21:10:12 -07001424 &dev_attr_num_grat_arp.attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001425 &dev_attr_miimon.attr,
1426 &dev_attr_primary.attr,
1427 &dev_attr_use_carrier.attr,
1428 &dev_attr_active_slave.attr,
1429 &dev_attr_mii_status.attr,
1430 &dev_attr_ad_aggregator.attr,
1431 &dev_attr_ad_num_ports.attr,
1432 &dev_attr_ad_actor_key.attr,
1433 &dev_attr_ad_partner_key.attr,
1434 &dev_attr_ad_partner_mac.attr,
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001435 NULL,
1436};
1437
1438static struct attribute_group bonding_group = {
1439 .name = "bonding",
1440 .attrs = per_bond_attrs,
1441};
1442
1443/*
1444 * Initialize sysfs. This sets up the bonding_masters file in
1445 * /sys/class/net.
1446 */
1447int bond_create_sysfs(void)
1448{
Jay Vosburghb8a97872008-06-13 18:12:04 -07001449 int ret;
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001450
Jay Vosburghb8a97872008-06-13 18:12:04 -07001451 ret = netdev_class_create_file(&class_attr_bonding_masters);
Jay Vosburgh877cbd32007-01-19 18:15:47 -08001452 /*
1453 * Permit multiple loads of the module by ignoring failures to
1454 * create the bonding_masters sysfs file. Bonding devices
1455 * created by second or subsequent loads of the module will
1456 * not be listed in, or controllable by, bonding_masters, but
1457 * will have the usual "bonding" sysfs directory.
1458 *
1459 * This is done to preserve backwards compatibility for
1460 * initscripts/sysconfig, which load bonding multiple times to
1461 * configure multiple bonding devices.
1462 */
1463 if (ret == -EEXIST) {
Stephen Hemminger38d2f382008-05-14 22:35:04 -07001464 /* Is someone being kinky and naming a device bonding_master? */
1465 if (__dev_get_by_name(&init_net,
1466 class_attr_bonding_masters.attr.name))
1467 printk(KERN_ERR
1468 "network device named %s already exists in sysfs",
1469 class_attr_bonding_masters.attr.name);
Jay Vosburgh877cbd32007-01-19 18:15:47 -08001470 }
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001471
1472 return ret;
1473
1474}
1475
1476/*
1477 * Remove /sys/class/net/bonding_masters.
1478 */
1479void bond_destroy_sysfs(void)
1480{
Jay Vosburghb8a97872008-06-13 18:12:04 -07001481 netdev_class_remove_file(&class_attr_bonding_masters);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001482}
1483
1484/*
1485 * Initialize sysfs for each bond. This sets up and registers
1486 * the 'bondctl' directory for each individual bond under /sys/class/net.
1487 */
1488int bond_create_sysfs_entry(struct bonding *bond)
1489{
1490 struct net_device *dev = bond->dev;
1491 int err;
1492
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001493 err = sysfs_create_group(&(dev->dev.kobj), &bonding_group);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001494 if (err) {
1495 printk(KERN_EMERG "eek! didn't create group!\n");
1496 }
1497
1498 if (expected_refcount < 1)
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001499 expected_refcount = atomic_read(&bond->dev->dev.kobj.kref.refcount);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001500
1501 return err;
1502}
1503/*
1504 * Remove sysfs entries for each bond.
1505 */
1506void bond_destroy_sysfs_entry(struct bonding *bond)
1507{
1508 struct net_device *dev = bond->dev;
1509
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07001510 sysfs_remove_group(&(dev->dev.kobj), &bonding_group);
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001511}
1512