bonding: remove unused bond_for_each_slave_from()
[deliverable/linux.git] / drivers / net / bonding / bond_sysfs.c
CommitLineData
b76cdba9
MW
1/*
2 * Copyright(c) 2004-2005 Intel Corporation. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 *
18 * The full GNU General Public License is included in this distribution in the
19 * file called LICENSE.
20 *
b76cdba9 21 */
a4aee5c8
JP
22
23#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
24
b76cdba9
MW
25#include <linux/kernel.h>
26#include <linux/module.h>
b76cdba9 27#include <linux/device.h>
d43c36dc 28#include <linux/sched.h>
b76cdba9
MW
29#include <linux/fs.h>
30#include <linux/types.h>
31#include <linux/string.h>
32#include <linux/netdevice.h>
33#include <linux/inetdevice.h>
34#include <linux/in.h>
35#include <linux/sysfs.h>
b76cdba9
MW
36#include <linux/ctype.h>
37#include <linux/inet.h>
38#include <linux/rtnetlink.h>
5c5129b5 39#include <linux/etherdevice.h>
881d966b 40#include <net/net_namespace.h>
ec87fd3b
EB
41#include <net/netns/generic.h>
42#include <linux/nsproxy.h>
b76cdba9 43
b76cdba9 44#include "bonding.h"
5a03cdb7 45
3d632c3f 46#define to_dev(obj) container_of(obj, struct device, kobj)
454d7c9b 47#define to_bond(cd) ((struct bonding *)(netdev_priv(to_net_dev(cd))))
b76cdba9 48
b76cdba9
MW
49/*
50 * "show" function for the bond_masters attribute.
51 * The class parameter is ignored.
52 */
28812fe1
AK
53static ssize_t bonding_show_bonds(struct class *cls,
54 struct class_attribute *attr,
55 char *buf)
b76cdba9 56{
4c22400a
EB
57 struct bond_net *bn =
58 container_of(attr, struct bond_net, class_attr_bonding_masters);
b76cdba9
MW
59 int res = 0;
60 struct bonding *bond;
61
7e083840 62 rtnl_lock();
b76cdba9 63
ec87fd3b 64 list_for_each_entry(bond, &bn->dev_list, bond_list) {
b76cdba9
MW
65 if (res > (PAGE_SIZE - IFNAMSIZ)) {
66 /* not enough space for another interface name */
67 if ((PAGE_SIZE - res) > 10)
68 res = PAGE_SIZE - 10;
b8843665 69 res += sprintf(buf + res, "++more++ ");
b76cdba9
MW
70 break;
71 }
b8843665 72 res += sprintf(buf + res, "%s ", bond->dev->name);
b76cdba9 73 }
1dcdcd69
WF
74 if (res)
75 buf[res-1] = '\n'; /* eat the leftover space */
7e083840
SH
76
77 rtnl_unlock();
b76cdba9
MW
78 return res;
79}
80
4c22400a 81static struct net_device *bond_get_by_name(struct bond_net *bn, const char *ifname)
373500db
SH
82{
83 struct bonding *bond;
84
ec87fd3b 85 list_for_each_entry(bond, &bn->dev_list, bond_list) {
373500db
SH
86 if (strncmp(bond->dev->name, ifname, IFNAMSIZ) == 0)
87 return bond->dev;
88 }
89 return NULL;
90}
91
b76cdba9
MW
92/*
93 * "store" function for the bond_masters attribute. This is what
94 * creates and deletes entire bonds.
95 *
96 * The class parameter is ignored.
97 *
98 */
99
3d632c3f 100static ssize_t bonding_store_bonds(struct class *cls,
28812fe1 101 struct class_attribute *attr,
3d632c3f 102 const char *buffer, size_t count)
b76cdba9 103{
4c22400a
EB
104 struct bond_net *bn =
105 container_of(attr, struct bond_net, class_attr_bonding_masters);
b76cdba9
MW
106 char command[IFNAMSIZ + 1] = {0, };
107 char *ifname;
027ea041 108 int rv, res = count;
b76cdba9 109
b76cdba9
MW
110 sscanf(buffer, "%16s", command); /* IFNAMSIZ*/
111 ifname = command + 1;
112 if ((strlen(command) <= 1) ||
113 !dev_valid_name(ifname))
114 goto err_no_cmd;
115
116 if (command[0] == '+') {
a4aee5c8 117 pr_info("%s is being created...\n", ifname);
4c22400a 118 rv = bond_create(bn->net, ifname);
027ea041 119 if (rv) {
5f86cad1
PO
120 if (rv == -EEXIST)
121 pr_info("%s already exists.\n", ifname);
122 else
123 pr_info("%s creation failed.\n", ifname);
027ea041 124 res = rv;
b76cdba9 125 }
373500db
SH
126 } else if (command[0] == '-') {
127 struct net_device *bond_dev;
b76cdba9 128
027ea041 129 rtnl_lock();
4c22400a 130 bond_dev = bond_get_by_name(bn, ifname);
373500db 131 if (bond_dev) {
a4aee5c8 132 pr_info("%s is being deleted...\n", ifname);
373500db
SH
133 unregister_netdevice(bond_dev);
134 } else {
a4aee5c8 135 pr_err("unable to delete non-existent %s\n", ifname);
373500db
SH
136 res = -ENODEV;
137 }
138 rtnl_unlock();
139 } else
140 goto err_no_cmd;
027ea041 141
373500db
SH
142 /* Always return either count or an error. If you return 0, you'll
143 * get called forever, which is bad.
144 */
145 return res;
b76cdba9
MW
146
147err_no_cmd:
a4aee5c8 148 pr_err("no command found in bonding_masters. Use +ifname or -ifname.\n");
c4ebc66a 149 return -EPERM;
b76cdba9 150}
373500db 151
4c22400a
EB
152static const void *bonding_namespace(struct class *cls,
153 const struct class_attribute *attr)
154{
155 const struct bond_net *bn =
156 container_of(attr, struct bond_net, class_attr_bonding_masters);
157 return bn->net;
158}
159
b76cdba9 160/* class attribute for bond_masters file. This ends up in /sys/class/net */
4c22400a
EB
161static const struct class_attribute class_attr_bonding_masters = {
162 .attr = {
163 .name = "bonding_masters",
164 .mode = S_IWUSR | S_IRUGO,
165 },
166 .show = bonding_show_bonds,
167 .store = bonding_store_bonds,
168 .namespace = bonding_namespace,
169};
b76cdba9 170
3d632c3f
SH
171int bond_create_slave_symlinks(struct net_device *master,
172 struct net_device *slave)
b76cdba9
MW
173{
174 char linkname[IFNAMSIZ+7];
175 int ret = 0;
176
177 /* first, create a link from the slave back to the master */
43cb76d9 178 ret = sysfs_create_link(&(slave->dev.kobj), &(master->dev.kobj),
b76cdba9
MW
179 "master");
180 if (ret)
181 return ret;
182 /* next, create a link from the master to the slave */
3d632c3f 183 sprintf(linkname, "slave_%s", slave->name);
43cb76d9 184 ret = sysfs_create_link(&(master->dev.kobj), &(slave->dev.kobj),
b76cdba9 185 linkname);
9fe16b78
VF
186
187 /* free the master link created earlier in case of error */
188 if (ret)
189 sysfs_remove_link(&(slave->dev.kobj), "master");
190
b76cdba9
MW
191 return ret;
192
193}
194
3d632c3f
SH
195void bond_destroy_slave_symlinks(struct net_device *master,
196 struct net_device *slave)
b76cdba9
MW
197{
198 char linkname[IFNAMSIZ+7];
199
43cb76d9 200 sysfs_remove_link(&(slave->dev.kobj), "master");
3d632c3f 201 sprintf(linkname, "slave_%s", slave->name);
43cb76d9 202 sysfs_remove_link(&(master->dev.kobj), linkname);
b76cdba9
MW
203}
204
205
206/*
207 * Show the slaves in the current bond.
208 */
43cb76d9
GKH
209static ssize_t bonding_show_slaves(struct device *d,
210 struct device_attribute *attr, char *buf)
b76cdba9 211{
43cb76d9 212 struct bonding *bond = to_bond(d);
9caff1e7 213 struct list_head *iter;
dec1e90e 214 struct slave *slave;
215 int res = 0;
b76cdba9 216
6603a6f2 217 read_lock(&bond->lock);
9caff1e7 218 bond_for_each_slave(bond, slave, iter) {
b76cdba9
MW
219 if (res > (PAGE_SIZE - IFNAMSIZ)) {
220 /* not enough space for another interface name */
221 if ((PAGE_SIZE - res) > 10)
222 res = PAGE_SIZE - 10;
7bd46508 223 res += sprintf(buf + res, "++more++ ");
b76cdba9
MW
224 break;
225 }
226 res += sprintf(buf + res, "%s ", slave->dev->name);
227 }
6603a6f2 228 read_unlock(&bond->lock);
1dcdcd69
WF
229 if (res)
230 buf[res-1] = '\n'; /* eat the leftover space */
dec1e90e 231
b76cdba9
MW
232 return res;
233}
234
235/*
d6641ccf 236 * Set the slaves in the current bond.
f9f3545e
JP
237 * This is supposed to be only thin wrapper for bond_enslave and bond_release.
238 * All hard work should be done there.
b76cdba9 239 */
43cb76d9
GKH
240static ssize_t bonding_store_slaves(struct device *d,
241 struct device_attribute *attr,
242 const char *buffer, size_t count)
b76cdba9
MW
243{
244 char command[IFNAMSIZ + 1] = { 0, };
245 char *ifname;
f9f3545e
JP
246 int res, ret = count;
247 struct net_device *dev;
43cb76d9 248 struct bonding *bond = to_bond(d);
b76cdba9 249
496a60cd
EB
250 if (!rtnl_trylock())
251 return restart_syscall();
027ea041 252
b76cdba9
MW
253 sscanf(buffer, "%16s", command); /* IFNAMSIZ*/
254 ifname = command + 1;
255 if ((strlen(command) <= 1) ||
256 !dev_valid_name(ifname))
257 goto err_no_cmd;
258
f9f3545e
JP
259 dev = __dev_get_by_name(dev_net(bond->dev), ifname);
260 if (!dev) {
261 pr_info("%s: Interface %s does not exist!\n",
262 bond->dev->name, ifname);
263 ret = -ENODEV;
264 goto out;
265 }
b76cdba9 266
f9f3545e
JP
267 switch (command[0]) {
268 case '+':
269 pr_info("%s: Adding slave %s.\n", bond->dev->name, dev->name);
b76cdba9 270 res = bond_enslave(bond->dev, dev);
f9f3545e 271 break;
3d632c3f 272
f9f3545e
JP
273 case '-':
274 pr_info("%s: Removing slave %s.\n", bond->dev->name, dev->name);
275 res = bond_release(bond->dev, dev);
276 break;
b76cdba9 277
f9f3545e
JP
278 default:
279 goto err_no_cmd;
b76cdba9
MW
280 }
281
f9f3545e
JP
282 if (res)
283 ret = res;
284 goto out;
285
b76cdba9 286err_no_cmd:
a4aee5c8
JP
287 pr_err("no command found in slaves file for bond %s. Use +ifname or -ifname.\n",
288 bond->dev->name);
b76cdba9
MW
289 ret = -EPERM;
290
291out:
027ea041 292 rtnl_unlock();
b76cdba9
MW
293 return ret;
294}
295
3d632c3f
SH
296static DEVICE_ATTR(slaves, S_IRUGO | S_IWUSR, bonding_show_slaves,
297 bonding_store_slaves);
b76cdba9
MW
298
299/*
300 * Show and set the bonding mode. The bond interface must be down to
301 * change the mode.
302 */
43cb76d9
GKH
303static ssize_t bonding_show_mode(struct device *d,
304 struct device_attribute *attr, char *buf)
b76cdba9 305{
43cb76d9 306 struct bonding *bond = to_bond(d);
b76cdba9
MW
307
308 return sprintf(buf, "%s %d\n",
309 bond_mode_tbl[bond->params.mode].modename,
7bd46508 310 bond->params.mode);
b76cdba9
MW
311}
312
43cb76d9
GKH
313static ssize_t bonding_store_mode(struct device *d,
314 struct device_attribute *attr,
315 const char *buf, size_t count)
b76cdba9
MW
316{
317 int new_value, ret = count;
43cb76d9 318 struct bonding *bond = to_bond(d);
b76cdba9 319
ea6836dd 320 if (!rtnl_trylock())
321 return restart_syscall();
322
b76cdba9 323 if (bond->dev->flags & IFF_UP) {
a4aee5c8
JP
324 pr_err("unable to update mode of %s because interface is up.\n",
325 bond->dev->name);
b76cdba9
MW
326 ret = -EPERM;
327 goto out;
328 }
329
dec1e90e 330 if (!list_empty(&bond->slave_list)) {
4a8bb7e2
VF
331 pr_err("unable to update mode of %s because it has slaves.\n",
332 bond->dev->name);
333 ret = -EPERM;
334 goto out;
335 }
336
ece95f7f 337 new_value = bond_parse_parm(buf, bond_mode_tbl);
b76cdba9 338 if (new_value < 0) {
a4aee5c8
JP
339 pr_err("%s: Ignoring invalid mode value %.*s.\n",
340 bond->dev->name, (int)strlen(buf) - 1, buf);
b76cdba9
MW
341 ret = -EINVAL;
342 goto out;
c5cb002f
AG
343 }
344 if ((new_value == BOND_MODE_ALB ||
345 new_value == BOND_MODE_TLB) &&
346 bond->params.arp_interval) {
347 pr_err("%s: %s mode is incompatible with arp monitoring.\n",
348 bond->dev->name, bond_mode_tbl[new_value].modename);
349 ret = -EINVAL;
350 goto out;
351 }
8f903c70 352
5bb9e0b5 353 /* don't cache arp_validate between modes */
354 bond->params.arp_validate = BOND_ARP_VALIDATE_NONE;
c5cb002f
AG
355 bond->params.mode = new_value;
356 bond_set_mode_ops(bond, bond->params.mode);
357 pr_info("%s: setting mode to %s (%d).\n",
358 bond->dev->name, bond_mode_tbl[new_value].modename,
359 new_value);
b76cdba9 360out:
ea6836dd 361 rtnl_unlock();
b76cdba9
MW
362 return ret;
363}
3d632c3f
SH
364static DEVICE_ATTR(mode, S_IRUGO | S_IWUSR,
365 bonding_show_mode, bonding_store_mode);
b76cdba9
MW
366
367/*
3d632c3f 368 * Show and set the bonding transmit hash method.
b76cdba9 369 */
43cb76d9
GKH
370static ssize_t bonding_show_xmit_hash(struct device *d,
371 struct device_attribute *attr,
372 char *buf)
b76cdba9 373{
43cb76d9 374 struct bonding *bond = to_bond(d);
b76cdba9 375
8e4b9329
WF
376 return sprintf(buf, "%s %d\n",
377 xmit_hashtype_tbl[bond->params.xmit_policy].modename,
378 bond->params.xmit_policy);
b76cdba9
MW
379}
380
43cb76d9
GKH
381static ssize_t bonding_store_xmit_hash(struct device *d,
382 struct device_attribute *attr,
383 const char *buf, size_t count)
b76cdba9
MW
384{
385 int new_value, ret = count;
43cb76d9 386 struct bonding *bond = to_bond(d);
b76cdba9 387
ece95f7f 388 new_value = bond_parse_parm(buf, xmit_hashtype_tbl);
b76cdba9 389 if (new_value < 0) {
a4aee5c8 390 pr_err("%s: Ignoring invalid xmit hash policy value %.*s.\n",
b76cdba9
MW
391 bond->dev->name,
392 (int)strlen(buf) - 1, buf);
393 ret = -EINVAL;
b76cdba9
MW
394 } else {
395 bond->params.xmit_policy = new_value;
396 bond_set_mode_ops(bond, bond->params.mode);
a4aee5c8 397 pr_info("%s: setting xmit hash policy to %s (%d).\n",
3d632c3f
SH
398 bond->dev->name,
399 xmit_hashtype_tbl[new_value].modename, new_value);
b76cdba9 400 }
53edee2c 401
b76cdba9
MW
402 return ret;
403}
3d632c3f
SH
404static DEVICE_ATTR(xmit_hash_policy, S_IRUGO | S_IWUSR,
405 bonding_show_xmit_hash, bonding_store_xmit_hash);
b76cdba9 406
f5b2b966
JV
407/*
408 * Show and set arp_validate.
409 */
43cb76d9
GKH
410static ssize_t bonding_show_arp_validate(struct device *d,
411 struct device_attribute *attr,
412 char *buf)
f5b2b966 413{
43cb76d9 414 struct bonding *bond = to_bond(d);
f5b2b966
JV
415
416 return sprintf(buf, "%s %d\n",
417 arp_validate_tbl[bond->params.arp_validate].modename,
7bd46508 418 bond->params.arp_validate);
f5b2b966
JV
419}
420
43cb76d9
GKH
421static ssize_t bonding_store_arp_validate(struct device *d,
422 struct device_attribute *attr,
423 const char *buf, size_t count)
f5b2b966 424{
43cb76d9 425 struct bonding *bond = to_bond(d);
5bb9e0b5 426 int new_value, ret = count;
f5b2b966 427
5c5038dc 428 if (!rtnl_trylock())
429 return restart_syscall();
ece95f7f 430 new_value = bond_parse_parm(buf, arp_validate_tbl);
f5b2b966 431 if (new_value < 0) {
a4aee5c8 432 pr_err("%s: Ignoring invalid arp_validate value %s\n",
f5b2b966 433 bond->dev->name, buf);
5c5038dc 434 ret = -EINVAL;
435 goto out;
f5b2b966 436 }
5bb9e0b5 437 if (bond->params.mode != BOND_MODE_ACTIVEBACKUP) {
a4aee5c8 438 pr_err("%s: arp_validate only supported in active-backup mode.\n",
f5b2b966 439 bond->dev->name);
5c5038dc 440 ret = -EINVAL;
441 goto out;
f5b2b966 442 }
a4aee5c8
JP
443 pr_info("%s: setting arp_validate to %s (%d).\n",
444 bond->dev->name, arp_validate_tbl[new_value].modename,
445 new_value);
f5b2b966 446
5bb9e0b5 447 if (bond->dev->flags & IFF_UP) {
448 if (!new_value)
449 bond->recv_probe = NULL;
450 else if (bond->params.arp_interval)
451 bond->recv_probe = bond_arp_rcv;
452 }
f5b2b966 453 bond->params.arp_validate = new_value;
5c5038dc 454out:
455 rtnl_unlock();
f5b2b966 456
5c5038dc 457 return ret;
f5b2b966
JV
458}
459
3d632c3f
SH
460static DEVICE_ATTR(arp_validate, S_IRUGO | S_IWUSR, bonding_show_arp_validate,
461 bonding_store_arp_validate);
8599b52e
VF
462/*
463 * Show and set arp_all_targets.
464 */
465static ssize_t bonding_show_arp_all_targets(struct device *d,
466 struct device_attribute *attr,
467 char *buf)
468{
469 struct bonding *bond = to_bond(d);
470 int value = bond->params.arp_all_targets;
471
472 return sprintf(buf, "%s %d\n", arp_all_targets_tbl[value].modename,
473 value);
474}
475
476static ssize_t bonding_store_arp_all_targets(struct device *d,
477 struct device_attribute *attr,
478 const char *buf, size_t count)
479{
480 struct bonding *bond = to_bond(d);
481 int new_value;
482
483 new_value = bond_parse_parm(buf, arp_all_targets_tbl);
484 if (new_value < 0) {
485 pr_err("%s: Ignoring invalid arp_all_targets value %s\n",
486 bond->dev->name, buf);
487 return -EINVAL;
488 }
489 pr_info("%s: setting arp_all_targets to %s (%d).\n",
490 bond->dev->name, arp_all_targets_tbl[new_value].modename,
491 new_value);
492
493 bond->params.arp_all_targets = new_value;
494
495 return count;
496}
497
498static DEVICE_ATTR(arp_all_targets, S_IRUGO | S_IWUSR,
499 bonding_show_arp_all_targets, bonding_store_arp_all_targets);
f5b2b966 500
dd957c57
JV
501/*
502 * Show and store fail_over_mac. User only allowed to change the
503 * value when there are no slaves.
504 */
3d632c3f
SH
505static ssize_t bonding_show_fail_over_mac(struct device *d,
506 struct device_attribute *attr,
507 char *buf)
dd957c57
JV
508{
509 struct bonding *bond = to_bond(d);
510
3915c1e8
JV
511 return sprintf(buf, "%s %d\n",
512 fail_over_mac_tbl[bond->params.fail_over_mac].modename,
513 bond->params.fail_over_mac);
dd957c57
JV
514}
515
3d632c3f
SH
516static ssize_t bonding_store_fail_over_mac(struct device *d,
517 struct device_attribute *attr,
518 const char *buf, size_t count)
dd957c57 519{
9402b746 520 int new_value, ret = count;
dd957c57
JV
521 struct bonding *bond = to_bond(d);
522
9402b746 523 if (!rtnl_trylock())
524 return restart_syscall();
525
dec1e90e 526 if (!list_empty(&bond->slave_list)) {
a4aee5c8 527 pr_err("%s: Can't alter fail_over_mac with slaves in bond.\n",
dd957c57 528 bond->dev->name);
9402b746 529 ret = -EPERM;
530 goto out;
dd957c57
JV
531 }
532
3915c1e8
JV
533 new_value = bond_parse_parm(buf, fail_over_mac_tbl);
534 if (new_value < 0) {
a4aee5c8 535 pr_err("%s: Ignoring invalid fail_over_mac value %s.\n",
3915c1e8 536 bond->dev->name, buf);
9402b746 537 ret = -EINVAL;
538 goto out;
dd957c57
JV
539 }
540
3915c1e8 541 bond->params.fail_over_mac = new_value;
a4aee5c8
JP
542 pr_info("%s: Setting fail_over_mac to %s (%d).\n",
543 bond->dev->name, fail_over_mac_tbl[new_value].modename,
544 new_value);
3915c1e8 545
9402b746 546out:
547 rtnl_unlock();
548 return ret;
dd957c57
JV
549}
550
3d632c3f
SH
551static DEVICE_ATTR(fail_over_mac, S_IRUGO | S_IWUSR,
552 bonding_show_fail_over_mac, bonding_store_fail_over_mac);
dd957c57 553
b76cdba9
MW
554/*
555 * Show and set the arp timer interval. There are two tricky bits
556 * here. First, if ARP monitoring is activated, then we must disable
557 * MII monitoring. Second, if the ARP timer isn't running, we must
558 * start it.
559 */
43cb76d9
GKH
560static ssize_t bonding_show_arp_interval(struct device *d,
561 struct device_attribute *attr,
562 char *buf)
b76cdba9 563{
43cb76d9 564 struct bonding *bond = to_bond(d);
b76cdba9 565
7bd46508 566 return sprintf(buf, "%d\n", bond->params.arp_interval);
b76cdba9
MW
567}
568
43cb76d9
GKH
569static ssize_t bonding_store_arp_interval(struct device *d,
570 struct device_attribute *attr,
571 const char *buf, size_t count)
b76cdba9 572{
43cb76d9 573 struct bonding *bond = to_bond(d);
5bb9e0b5 574 int new_value, ret = count;
b76cdba9 575
fbb0c41b 576 if (!rtnl_trylock())
577 return restart_syscall();
b76cdba9 578 if (sscanf(buf, "%d", &new_value) != 1) {
a4aee5c8 579 pr_err("%s: no arp_interval value specified.\n",
b76cdba9
MW
580 bond->dev->name);
581 ret = -EINVAL;
582 goto out;
583 }
584 if (new_value < 0) {
1bc7db16 585 pr_err("%s: Invalid arp_interval value %d not in range 0-%d; rejected.\n",
b76cdba9
MW
586 bond->dev->name, new_value, INT_MAX);
587 ret = -EINVAL;
588 goto out;
589 }
c5cb002f
AG
590 if (bond->params.mode == BOND_MODE_ALB ||
591 bond->params.mode == BOND_MODE_TLB) {
592 pr_info("%s: ARP monitoring cannot be used with ALB/TLB. Only MII monitoring is supported on %s.\n",
593 bond->dev->name, bond->dev->name);
594 ret = -EINVAL;
595 goto out;
596 }
a4aee5c8
JP
597 pr_info("%s: Setting ARP monitoring interval to %d.\n",
598 bond->dev->name, new_value);
b76cdba9 599 bond->params.arp_interval = new_value;
1bc7db16 600 if (new_value) {
601 if (bond->params.miimon) {
602 pr_info("%s: ARP monitoring cannot be used with MII monitoring. %s Disabling MII monitoring.\n",
603 bond->dev->name, bond->dev->name);
604 bond->params.miimon = 0;
605 }
606 if (!bond->params.arp_targets[0])
607 pr_info("%s: ARP monitoring has been set up, but no ARP targets have been specified.\n",
608 bond->dev->name);
b76cdba9
MW
609 }
610 if (bond->dev->flags & IFF_UP) {
611 /* If the interface is up, we may need to fire off
612 * the ARP timer. If the interface is down, the
613 * timer will get fired off when the open function
614 * is called.
615 */
1bc7db16 616 if (!new_value) {
5bb9e0b5 617 if (bond->params.arp_validate)
618 bond->recv_probe = NULL;
1bc7db16 619 cancel_delayed_work_sync(&bond->arp_work);
620 } else {
5bb9e0b5 621 /* arp_validate can be set only in active-backup mode */
622 if (bond->params.arp_validate)
623 bond->recv_probe = bond_arp_rcv;
1bc7db16 624 cancel_delayed_work_sync(&bond->mii_work);
625 queue_delayed_work(bond->wq, &bond->arp_work, 0);
626 }
b76cdba9 627 }
b76cdba9 628out:
fbb0c41b 629 rtnl_unlock();
b76cdba9
MW
630 return ret;
631}
3d632c3f
SH
632static DEVICE_ATTR(arp_interval, S_IRUGO | S_IWUSR,
633 bonding_show_arp_interval, bonding_store_arp_interval);
b76cdba9
MW
634
635/*
636 * Show and set the arp targets.
637 */
43cb76d9
GKH
638static ssize_t bonding_show_arp_targets(struct device *d,
639 struct device_attribute *attr,
640 char *buf)
b76cdba9
MW
641{
642 int i, res = 0;
43cb76d9 643 struct bonding *bond = to_bond(d);
b76cdba9
MW
644
645 for (i = 0; i < BOND_MAX_ARP_TARGETS; i++) {
646 if (bond->params.arp_targets[i])
63779436
HH
647 res += sprintf(buf + res, "%pI4 ",
648 &bond->params.arp_targets[i]);
b76cdba9 649 }
1dcdcd69
WF
650 if (res)
651 buf[res-1] = '\n'; /* eat the leftover space */
b76cdba9
MW
652 return res;
653}
654
43cb76d9
GKH
655static ssize_t bonding_store_arp_targets(struct device *d,
656 struct device_attribute *attr,
657 const char *buf, size_t count)
b76cdba9 658{
43cb76d9 659 struct bonding *bond = to_bond(d);
9caff1e7 660 struct list_head *iter;
8599b52e
VF
661 struct slave *slave;
662 __be32 newtarget, *targets;
663 unsigned long *targets_rx;
664 int ind, i, j, ret = -EINVAL;
b76cdba9
MW
665
666 targets = bond->params.arp_targets;
667 newtarget = in_aton(buf + 1);
668 /* look for adds */
669 if (buf[0] == '+') {
d3bb52b0 670 if ((newtarget == 0) || (newtarget == htonl(INADDR_BROADCAST))) {
a4aee5c8 671 pr_err("%s: invalid ARP target %pI4 specified for addition\n",
63779436 672 bond->dev->name, &newtarget);
b76cdba9
MW
673 goto out;
674 }
87a7b84b
VF
675
676 if (bond_get_targets_ip(targets, newtarget) != -1) { /* dup */
677 pr_err("%s: ARP target %pI4 is already present\n",
678 bond->dev->name, &newtarget);
679 goto out;
b76cdba9 680 }
87a7b84b 681
8599b52e
VF
682 ind = bond_get_targets_ip(targets, 0); /* first free slot */
683 if (ind == -1) {
a4aee5c8 684 pr_err("%s: ARP target table is full!\n",
b76cdba9 685 bond->dev->name);
b76cdba9
MW
686 goto out;
687 }
688
87a7b84b
VF
689 pr_info("%s: adding ARP target %pI4.\n", bond->dev->name,
690 &newtarget);
8599b52e
VF
691 /* not to race with bond_arp_rcv */
692 write_lock_bh(&bond->lock);
9caff1e7 693 bond_for_each_slave(bond, slave, iter)
8599b52e
VF
694 slave->target_last_arp_rx[ind] = jiffies;
695 targets[ind] = newtarget;
696 write_unlock_bh(&bond->lock);
3d632c3f 697 } else if (buf[0] == '-') {
d3bb52b0 698 if ((newtarget == 0) || (newtarget == htonl(INADDR_BROADCAST))) {
a4aee5c8 699 pr_err("%s: invalid ARP target %pI4 specified for removal\n",
63779436 700 bond->dev->name, &newtarget);
b76cdba9
MW
701 goto out;
702 }
703
8599b52e
VF
704 ind = bond_get_targets_ip(targets, newtarget);
705 if (ind == -1) {
706 pr_err("%s: unable to remove nonexistent ARP target %pI4.\n",
a4aee5c8 707 bond->dev->name, &newtarget);
b76cdba9
MW
708 goto out;
709 }
87a7b84b 710
8599b52e
VF
711 if (ind == 0 && !targets[1] && bond->params.arp_interval)
712 pr_warn("%s: removing last arp target with arp_interval on\n",
713 bond->dev->name);
714
87a7b84b
VF
715 pr_info("%s: removing ARP target %pI4.\n", bond->dev->name,
716 &newtarget);
8599b52e
VF
717
718 write_lock_bh(&bond->lock);
9caff1e7 719 bond_for_each_slave(bond, slave, iter) {
8599b52e
VF
720 targets_rx = slave->target_last_arp_rx;
721 j = ind;
722 for (; (j < BOND_MAX_ARP_TARGETS-1) && targets[j+1]; j++)
723 targets_rx[j] = targets_rx[j+1];
724 targets_rx[j] = 0;
725 }
726 for (i = ind; (i < BOND_MAX_ARP_TARGETS-1) && targets[i+1]; i++)
87a7b84b
VF
727 targets[i] = targets[i+1];
728 targets[i] = 0;
8599b52e 729 write_unlock_bh(&bond->lock);
3d632c3f 730 } else {
a4aee5c8
JP
731 pr_err("no command found in arp_ip_targets file for bond %s. Use +<addr> or -<addr>.\n",
732 bond->dev->name);
b76cdba9
MW
733 ret = -EPERM;
734 goto out;
735 }
736
87a7b84b 737 ret = count;
b76cdba9
MW
738out:
739 return ret;
740}
43cb76d9 741static DEVICE_ATTR(arp_ip_target, S_IRUGO | S_IWUSR , bonding_show_arp_targets, bonding_store_arp_targets);
b76cdba9
MW
742
743/*
744 * Show and set the up and down delays. These must be multiples of the
745 * MII monitoring value, and are stored internally as the multiplier.
746 * Thus, we must translate to MS for the real world.
747 */
43cb76d9
GKH
748static ssize_t bonding_show_downdelay(struct device *d,
749 struct device_attribute *attr,
750 char *buf)
b76cdba9 751{
43cb76d9 752 struct bonding *bond = to_bond(d);
b76cdba9 753
7bd46508 754 return sprintf(buf, "%d\n", bond->params.downdelay * bond->params.miimon);
b76cdba9
MW
755}
756
43cb76d9
GKH
757static ssize_t bonding_store_downdelay(struct device *d,
758 struct device_attribute *attr,
759 const char *buf, size_t count)
b76cdba9
MW
760{
761 int new_value, ret = count;
43cb76d9 762 struct bonding *bond = to_bond(d);
b76cdba9
MW
763
764 if (!(bond->params.miimon)) {
a4aee5c8 765 pr_err("%s: Unable to set down delay as MII monitoring is disabled\n",
b76cdba9
MW
766 bond->dev->name);
767 ret = -EPERM;
768 goto out;
769 }
770
771 if (sscanf(buf, "%d", &new_value) != 1) {
a4aee5c8 772 pr_err("%s: no down delay value specified.\n", bond->dev->name);
b76cdba9
MW
773 ret = -EINVAL;
774 goto out;
775 }
776 if (new_value < 0) {
a4aee5c8 777 pr_err("%s: Invalid down delay value %d not in range %d-%d; rejected.\n",
1bc7db16 778 bond->dev->name, new_value, 0, INT_MAX);
b76cdba9
MW
779 ret = -EINVAL;
780 goto out;
781 } else {
782 if ((new_value % bond->params.miimon) != 0) {
a4aee5c8 783 pr_warning("%s: Warning: down delay (%d) is not a multiple of miimon (%d), delay rounded to %d ms\n",
e5e2a8fd
JP
784 bond->dev->name, new_value,
785 bond->params.miimon,
786 (new_value / bond->params.miimon) *
787 bond->params.miimon);
b76cdba9
MW
788 }
789 bond->params.downdelay = new_value / bond->params.miimon;
a4aee5c8
JP
790 pr_info("%s: Setting down delay to %d.\n",
791 bond->dev->name,
792 bond->params.downdelay * bond->params.miimon);
b76cdba9
MW
793
794 }
795
796out:
797 return ret;
798}
3d632c3f
SH
799static DEVICE_ATTR(downdelay, S_IRUGO | S_IWUSR,
800 bonding_show_downdelay, bonding_store_downdelay);
b76cdba9 801
43cb76d9
GKH
802static ssize_t bonding_show_updelay(struct device *d,
803 struct device_attribute *attr,
804 char *buf)
b76cdba9 805{
43cb76d9 806 struct bonding *bond = to_bond(d);
b76cdba9 807
7bd46508 808 return sprintf(buf, "%d\n", bond->params.updelay * bond->params.miimon);
b76cdba9
MW
809
810}
811
43cb76d9
GKH
812static ssize_t bonding_store_updelay(struct device *d,
813 struct device_attribute *attr,
814 const char *buf, size_t count)
b76cdba9
MW
815{
816 int new_value, ret = count;
43cb76d9 817 struct bonding *bond = to_bond(d);
b76cdba9
MW
818
819 if (!(bond->params.miimon)) {
a4aee5c8 820 pr_err("%s: Unable to set up delay as MII monitoring is disabled\n",
b76cdba9
MW
821 bond->dev->name);
822 ret = -EPERM;
823 goto out;
824 }
825
826 if (sscanf(buf, "%d", &new_value) != 1) {
a4aee5c8 827 pr_err("%s: no up delay value specified.\n",
b76cdba9
MW
828 bond->dev->name);
829 ret = -EINVAL;
830 goto out;
831 }
832 if (new_value < 0) {
1bc7db16 833 pr_err("%s: Invalid up delay value %d not in range %d-%d; rejected.\n",
834 bond->dev->name, new_value, 0, INT_MAX);
b76cdba9
MW
835 ret = -EINVAL;
836 goto out;
837 } else {
838 if ((new_value % bond->params.miimon) != 0) {
a4aee5c8 839 pr_warning("%s: Warning: up delay (%d) is not a multiple of miimon (%d), updelay rounded to %d ms\n",
e5e2a8fd
JP
840 bond->dev->name, new_value,
841 bond->params.miimon,
842 (new_value / bond->params.miimon) *
843 bond->params.miimon);
b76cdba9
MW
844 }
845 bond->params.updelay = new_value / bond->params.miimon;
a4aee5c8
JP
846 pr_info("%s: Setting up delay to %d.\n",
847 bond->dev->name,
848 bond->params.updelay * bond->params.miimon);
b76cdba9
MW
849 }
850
851out:
852 return ret;
853}
3d632c3f
SH
854static DEVICE_ATTR(updelay, S_IRUGO | S_IWUSR,
855 bonding_show_updelay, bonding_store_updelay);
b76cdba9
MW
856
857/*
858 * Show and set the LACP interval. Interface must be down, and the mode
859 * must be set to 802.3ad mode.
860 */
43cb76d9
GKH
861static ssize_t bonding_show_lacp(struct device *d,
862 struct device_attribute *attr,
863 char *buf)
b76cdba9 864{
43cb76d9 865 struct bonding *bond = to_bond(d);
b76cdba9
MW
866
867 return sprintf(buf, "%s %d\n",
868 bond_lacp_tbl[bond->params.lacp_fast].modename,
7bd46508 869 bond->params.lacp_fast);
b76cdba9
MW
870}
871
43cb76d9
GKH
872static ssize_t bonding_store_lacp(struct device *d,
873 struct device_attribute *attr,
874 const char *buf, size_t count)
b76cdba9 875{
43cb76d9 876 struct bonding *bond = to_bond(d);
c509316b 877 int new_value, ret = count;
878
879 if (!rtnl_trylock())
880 return restart_syscall();
b76cdba9
MW
881
882 if (bond->dev->flags & IFF_UP) {
a4aee5c8 883 pr_err("%s: Unable to update LACP rate because interface is up.\n",
b76cdba9
MW
884 bond->dev->name);
885 ret = -EPERM;
886 goto out;
887 }
888
889 if (bond->params.mode != BOND_MODE_8023AD) {
a4aee5c8 890 pr_err("%s: Unable to update LACP rate because bond is not in 802.3ad mode.\n",
b76cdba9
MW
891 bond->dev->name);
892 ret = -EPERM;
893 goto out;
894 }
895
ece95f7f 896 new_value = bond_parse_parm(buf, bond_lacp_tbl);
b76cdba9
MW
897
898 if ((new_value == 1) || (new_value == 0)) {
899 bond->params.lacp_fast = new_value;
ba824a8b 900 bond_3ad_update_lacp_rate(bond);
a4aee5c8 901 pr_info("%s: Setting LACP rate to %s (%d).\n",
3d632c3f
SH
902 bond->dev->name, bond_lacp_tbl[new_value].modename,
903 new_value);
b76cdba9 904 } else {
a4aee5c8 905 pr_err("%s: Ignoring invalid LACP rate value %.*s.\n",
3d632c3f 906 bond->dev->name, (int)strlen(buf) - 1, buf);
b76cdba9
MW
907 ret = -EINVAL;
908 }
909out:
c509316b 910 rtnl_unlock();
911
b76cdba9
MW
912 return ret;
913}
3d632c3f
SH
914static DEVICE_ATTR(lacp_rate, S_IRUGO | S_IWUSR,
915 bonding_show_lacp, bonding_store_lacp);
b76cdba9 916
655f8919 917static ssize_t bonding_show_min_links(struct device *d,
918 struct device_attribute *attr,
919 char *buf)
920{
921 struct bonding *bond = to_bond(d);
922
923 return sprintf(buf, "%d\n", bond->params.min_links);
924}
925
926static ssize_t bonding_store_min_links(struct device *d,
927 struct device_attribute *attr,
928 const char *buf, size_t count)
929{
930 struct bonding *bond = to_bond(d);
931 int ret;
932 unsigned int new_value;
933
934 ret = kstrtouint(buf, 0, &new_value);
935 if (ret < 0) {
936 pr_err("%s: Ignoring invalid min links value %s.\n",
937 bond->dev->name, buf);
938 return ret;
939 }
940
941 pr_info("%s: Setting min links value to %u\n",
942 bond->dev->name, new_value);
943 bond->params.min_links = new_value;
944 return count;
945}
946static DEVICE_ATTR(min_links, S_IRUGO | S_IWUSR,
947 bonding_show_min_links, bonding_store_min_links);
948
fd989c83
JV
949static ssize_t bonding_show_ad_select(struct device *d,
950 struct device_attribute *attr,
951 char *buf)
952{
953 struct bonding *bond = to_bond(d);
954
955 return sprintf(buf, "%s %d\n",
956 ad_select_tbl[bond->params.ad_select].modename,
957 bond->params.ad_select);
958}
959
960
961static ssize_t bonding_store_ad_select(struct device *d,
962 struct device_attribute *attr,
963 const char *buf, size_t count)
964{
965 int new_value, ret = count;
966 struct bonding *bond = to_bond(d);
967
968 if (bond->dev->flags & IFF_UP) {
a4aee5c8
JP
969 pr_err("%s: Unable to update ad_select because interface is up.\n",
970 bond->dev->name);
fd989c83
JV
971 ret = -EPERM;
972 goto out;
973 }
974
975 new_value = bond_parse_parm(buf, ad_select_tbl);
976
977 if (new_value != -1) {
978 bond->params.ad_select = new_value;
a4aee5c8
JP
979 pr_info("%s: Setting ad_select to %s (%d).\n",
980 bond->dev->name, ad_select_tbl[new_value].modename,
981 new_value);
fd989c83 982 } else {
a4aee5c8 983 pr_err("%s: Ignoring invalid ad_select value %.*s.\n",
fd989c83
JV
984 bond->dev->name, (int)strlen(buf) - 1, buf);
985 ret = -EINVAL;
986 }
987out:
988 return ret;
989}
3d632c3f
SH
990static DEVICE_ATTR(ad_select, S_IRUGO | S_IWUSR,
991 bonding_show_ad_select, bonding_store_ad_select);
fd989c83 992
ad246c99
BH
993/*
994 * Show and set the number of peer notifications to send after a failover event.
995 */
996static ssize_t bonding_show_num_peer_notif(struct device *d,
997 struct device_attribute *attr,
998 char *buf)
999{
1000 struct bonding *bond = to_bond(d);
1001 return sprintf(buf, "%d\n", bond->params.num_peer_notif);
1002}
1003
1004static ssize_t bonding_store_num_peer_notif(struct device *d,
1005 struct device_attribute *attr,
1006 const char *buf, size_t count)
1007{
1008 struct bonding *bond = to_bond(d);
1009 int err = kstrtou8(buf, 10, &bond->params.num_peer_notif);
1010 return err ? err : count;
1011}
1012static DEVICE_ATTR(num_grat_arp, S_IRUGO | S_IWUSR,
1013 bonding_show_num_peer_notif, bonding_store_num_peer_notif);
1014static DEVICE_ATTR(num_unsol_na, S_IRUGO | S_IWUSR,
1015 bonding_show_num_peer_notif, bonding_store_num_peer_notif);
1016
b76cdba9
MW
1017/*
1018 * Show and set the MII monitor interval. There are two tricky bits
1019 * here. First, if MII monitoring is activated, then we must disable
1020 * ARP monitoring. Second, if the timer isn't running, we must
1021 * start it.
1022 */
43cb76d9
GKH
1023static ssize_t bonding_show_miimon(struct device *d,
1024 struct device_attribute *attr,
1025 char *buf)
b76cdba9 1026{
43cb76d9 1027 struct bonding *bond = to_bond(d);
b76cdba9 1028
7bd46508 1029 return sprintf(buf, "%d\n", bond->params.miimon);
b76cdba9
MW
1030}
1031
43cb76d9
GKH
1032static ssize_t bonding_store_miimon(struct device *d,
1033 struct device_attribute *attr,
1034 const char *buf, size_t count)
b76cdba9
MW
1035{
1036 int new_value, ret = count;
43cb76d9 1037 struct bonding *bond = to_bond(d);
b76cdba9 1038
fbb0c41b 1039 if (!rtnl_trylock())
1040 return restart_syscall();
b76cdba9 1041 if (sscanf(buf, "%d", &new_value) != 1) {
a4aee5c8 1042 pr_err("%s: no miimon value specified.\n",
b76cdba9
MW
1043 bond->dev->name);
1044 ret = -EINVAL;
1045 goto out;
1046 }
1047 if (new_value < 0) {
a4aee5c8 1048 pr_err("%s: Invalid miimon value %d not in range %d-%d; rejected.\n",
1bc7db16 1049 bond->dev->name, new_value, 0, INT_MAX);
b76cdba9
MW
1050 ret = -EINVAL;
1051 goto out;
1bc7db16 1052 }
1053 pr_info("%s: Setting MII monitoring interval to %d.\n",
1054 bond->dev->name, new_value);
1055 bond->params.miimon = new_value;
1056 if (bond->params.updelay)
1057 pr_info("%s: Note: Updating updelay (to %d) since it is a multiple of the miimon value.\n",
1058 bond->dev->name,
1059 bond->params.updelay * bond->params.miimon);
1060 if (bond->params.downdelay)
1061 pr_info("%s: Note: Updating downdelay (to %d) since it is a multiple of the miimon value.\n",
1062 bond->dev->name,
1063 bond->params.downdelay * bond->params.miimon);
1064 if (new_value && bond->params.arp_interval) {
1065 pr_info("%s: MII monitoring cannot be used with ARP monitoring. Disabling ARP monitoring...\n",
1066 bond->dev->name);
1067 bond->params.arp_interval = 0;
1068 if (bond->params.arp_validate)
1069 bond->params.arp_validate = BOND_ARP_VALIDATE_NONE;
1070 }
1071 if (bond->dev->flags & IFF_UP) {
1072 /* If the interface is up, we may need to fire off
1073 * the MII timer. If the interface is down, the
1074 * timer will get fired off when the open function
1075 * is called.
1076 */
1077 if (!new_value) {
1078 cancel_delayed_work_sync(&bond->mii_work);
1079 } else {
fbb0c41b 1080 cancel_delayed_work_sync(&bond->arp_work);
1081 queue_delayed_work(bond->wq, &bond->mii_work, 0);
b76cdba9
MW
1082 }
1083 }
1084out:
fbb0c41b 1085 rtnl_unlock();
b76cdba9
MW
1086 return ret;
1087}
3d632c3f
SH
1088static DEVICE_ATTR(miimon, S_IRUGO | S_IWUSR,
1089 bonding_show_miimon, bonding_store_miimon);
b76cdba9
MW
1090
1091/*
1092 * Show and set the primary slave. The store function is much
1093 * simpler than bonding_store_slaves function because it only needs to
1094 * handle one interface name.
1095 * The bond must be a mode that supports a primary for this be
1096 * set.
1097 */
43cb76d9
GKH
1098static ssize_t bonding_show_primary(struct device *d,
1099 struct device_attribute *attr,
1100 char *buf)
b76cdba9
MW
1101{
1102 int count = 0;
43cb76d9 1103 struct bonding *bond = to_bond(d);
b76cdba9
MW
1104
1105 if (bond->primary_slave)
7bd46508 1106 count = sprintf(buf, "%s\n", bond->primary_slave->dev->name);
b76cdba9
MW
1107
1108 return count;
1109}
1110
43cb76d9
GKH
1111static ssize_t bonding_store_primary(struct device *d,
1112 struct device_attribute *attr,
1113 const char *buf, size_t count)
b76cdba9 1114{
43cb76d9 1115 struct bonding *bond = to_bond(d);
9caff1e7 1116 struct list_head *iter;
f4bb2e9c 1117 char ifname[IFNAMSIZ];
dec1e90e 1118 struct slave *slave;
b76cdba9 1119
496a60cd
EB
1120 if (!rtnl_trylock())
1121 return restart_syscall();
e843fa50 1122 block_netpoll_tx();
e934dd78
JV
1123 read_lock(&bond->lock);
1124 write_lock_bh(&bond->curr_slave_lock);
1125
b76cdba9 1126 if (!USES_PRIMARY(bond->params.mode)) {
a4aee5c8
JP
1127 pr_info("%s: Unable to set primary slave; %s is in mode %d\n",
1128 bond->dev->name, bond->dev->name, bond->params.mode);
f4bb2e9c
AG
1129 goto out;
1130 }
b76cdba9 1131
eb6e98a1 1132 sscanf(buf, "%15s", ifname); /* IFNAMSIZ */
b76cdba9 1133
f4bb2e9c
AG
1134 /* check to see if we are clearing primary */
1135 if (!strlen(ifname) || buf[0] == '\n') {
1136 pr_info("%s: Setting primary slave to None.\n",
1137 bond->dev->name);
1138 bond->primary_slave = NULL;
eb492f74 1139 memset(bond->params.primary, 0, sizeof(bond->params.primary));
f4bb2e9c
AG
1140 bond_select_active_slave(bond);
1141 goto out;
1142 }
1143
9caff1e7 1144 bond_for_each_slave(bond, slave, iter) {
f4bb2e9c
AG
1145 if (strncmp(slave->dev->name, ifname, IFNAMSIZ) == 0) {
1146 pr_info("%s: Setting %s as primary slave.\n",
1147 bond->dev->name, slave->dev->name);
1148 bond->primary_slave = slave;
1149 strcpy(bond->params.primary, slave->dev->name);
1150 bond_select_active_slave(bond);
1151 goto out;
b76cdba9
MW
1152 }
1153 }
f4bb2e9c 1154
8a93664d
WP
1155 strncpy(bond->params.primary, ifname, IFNAMSIZ);
1156 bond->params.primary[IFNAMSIZ - 1] = 0;
1157
1158 pr_info("%s: Recording %s as primary, "
1159 "but it has not been enslaved to %s yet.\n",
1160 bond->dev->name, ifname, bond->dev->name);
b76cdba9 1161out:
e934dd78
JV
1162 write_unlock_bh(&bond->curr_slave_lock);
1163 read_unlock(&bond->lock);
e843fa50 1164 unblock_netpoll_tx();
6603a6f2
JV
1165 rtnl_unlock();
1166
b76cdba9
MW
1167 return count;
1168}
3d632c3f
SH
1169static DEVICE_ATTR(primary, S_IRUGO | S_IWUSR,
1170 bonding_show_primary, bonding_store_primary);
b76cdba9 1171
a549952a
JP
1172/*
1173 * Show and set the primary_reselect flag.
1174 */
1175static ssize_t bonding_show_primary_reselect(struct device *d,
1176 struct device_attribute *attr,
1177 char *buf)
1178{
1179 struct bonding *bond = to_bond(d);
1180
1181 return sprintf(buf, "%s %d\n",
1182 pri_reselect_tbl[bond->params.primary_reselect].modename,
1183 bond->params.primary_reselect);
1184}
1185
1186static ssize_t bonding_store_primary_reselect(struct device *d,
1187 struct device_attribute *attr,
1188 const char *buf, size_t count)
1189{
1190 int new_value, ret = count;
1191 struct bonding *bond = to_bond(d);
1192
1193 if (!rtnl_trylock())
1194 return restart_syscall();
1195
1196 new_value = bond_parse_parm(buf, pri_reselect_tbl);
1197 if (new_value < 0) {
a4aee5c8 1198 pr_err("%s: Ignoring invalid primary_reselect value %.*s.\n",
a549952a
JP
1199 bond->dev->name,
1200 (int) strlen(buf) - 1, buf);
1201 ret = -EINVAL;
1202 goto out;
1203 }
1204
1205 bond->params.primary_reselect = new_value;
a4aee5c8 1206 pr_info("%s: setting primary_reselect to %s (%d).\n",
a549952a
JP
1207 bond->dev->name, pri_reselect_tbl[new_value].modename,
1208 new_value);
1209
e843fa50 1210 block_netpoll_tx();
a549952a
JP
1211 read_lock(&bond->lock);
1212 write_lock_bh(&bond->curr_slave_lock);
1213 bond_select_active_slave(bond);
1214 write_unlock_bh(&bond->curr_slave_lock);
1215 read_unlock(&bond->lock);
e843fa50 1216 unblock_netpoll_tx();
a549952a
JP
1217out:
1218 rtnl_unlock();
1219 return ret;
1220}
1221static DEVICE_ATTR(primary_reselect, S_IRUGO | S_IWUSR,
1222 bonding_show_primary_reselect,
1223 bonding_store_primary_reselect);
1224
b76cdba9
MW
1225/*
1226 * Show and set the use_carrier flag.
1227 */
43cb76d9
GKH
1228static ssize_t bonding_show_carrier(struct device *d,
1229 struct device_attribute *attr,
1230 char *buf)
b76cdba9 1231{
43cb76d9 1232 struct bonding *bond = to_bond(d);
b76cdba9 1233
7bd46508 1234 return sprintf(buf, "%d\n", bond->params.use_carrier);
b76cdba9
MW
1235}
1236
43cb76d9
GKH
1237static ssize_t bonding_store_carrier(struct device *d,
1238 struct device_attribute *attr,
1239 const char *buf, size_t count)
b76cdba9
MW
1240{
1241 int new_value, ret = count;
43cb76d9 1242 struct bonding *bond = to_bond(d);
b76cdba9
MW
1243
1244
1245 if (sscanf(buf, "%d", &new_value) != 1) {
a4aee5c8 1246 pr_err("%s: no use_carrier value specified.\n",
b76cdba9
MW
1247 bond->dev->name);
1248 ret = -EINVAL;
1249 goto out;
1250 }
1251 if ((new_value == 0) || (new_value == 1)) {
1252 bond->params.use_carrier = new_value;
a4aee5c8
JP
1253 pr_info("%s: Setting use_carrier to %d.\n",
1254 bond->dev->name, new_value);
b76cdba9 1255 } else {
a4aee5c8
JP
1256 pr_info("%s: Ignoring invalid use_carrier value %d.\n",
1257 bond->dev->name, new_value);
b76cdba9
MW
1258 }
1259out:
672bda33 1260 return ret;
b76cdba9 1261}
3d632c3f
SH
1262static DEVICE_ATTR(use_carrier, S_IRUGO | S_IWUSR,
1263 bonding_show_carrier, bonding_store_carrier);
b76cdba9
MW
1264
1265
1266/*
1267 * Show and set currently active_slave.
1268 */
43cb76d9
GKH
1269static ssize_t bonding_show_active_slave(struct device *d,
1270 struct device_attribute *attr,
1271 char *buf)
b76cdba9 1272{
43cb76d9 1273 struct bonding *bond = to_bond(d);
278b2083 1274 struct slave *curr;
16cd0160 1275 int count = 0;
b76cdba9 1276
278b2083 1277 rcu_read_lock();
1278 curr = rcu_dereference(bond->curr_active_slave);
b76cdba9 1279 if (USES_PRIMARY(bond->params.mode) && curr)
7bd46508 1280 count = sprintf(buf, "%s\n", curr->dev->name);
278b2083 1281 rcu_read_unlock();
1282
b76cdba9
MW
1283 return count;
1284}
1285
43cb76d9
GKH
1286static ssize_t bonding_store_active_slave(struct device *d,
1287 struct device_attribute *attr,
1288 const char *buf, size_t count)
b76cdba9 1289{
dec1e90e 1290 struct slave *slave, *old_active, *new_active;
43cb76d9 1291 struct bonding *bond = to_bond(d);
9caff1e7 1292 struct list_head *iter;
f4bb2e9c 1293 char ifname[IFNAMSIZ];
b76cdba9 1294
496a60cd
EB
1295 if (!rtnl_trylock())
1296 return restart_syscall();
e843fa50 1297
dec1e90e 1298 old_active = new_active = NULL;
e843fa50 1299 block_netpoll_tx();
e934dd78
JV
1300 read_lock(&bond->lock);
1301 write_lock_bh(&bond->curr_slave_lock);
1466a219 1302
f4bb2e9c 1303 if (!USES_PRIMARY(bond->params.mode)) {
a4aee5c8 1304 pr_info("%s: Unable to change active slave; %s is in mode %d\n",
3d632c3f 1305 bond->dev->name, bond->dev->name, bond->params.mode);
f4bb2e9c
AG
1306 goto out;
1307 }
1308
c84e1590 1309 sscanf(buf, "%15s", ifname); /* IFNAMSIZ */
f4bb2e9c
AG
1310
1311 /* check to see if we are clearing active */
1312 if (!strlen(ifname) || buf[0] == '\n') {
1313 pr_info("%s: Clearing current active slave.\n",
1314 bond->dev->name);
278b2083 1315 rcu_assign_pointer(bond->curr_active_slave, NULL);
f4bb2e9c
AG
1316 bond_select_active_slave(bond);
1317 goto out;
1318 }
1319
9caff1e7 1320 bond_for_each_slave(bond, slave, iter) {
f4bb2e9c
AG
1321 if (strncmp(slave->dev->name, ifname, IFNAMSIZ) == 0) {
1322 old_active = bond->curr_active_slave;
1323 new_active = slave;
1324 if (new_active == old_active) {
1325 /* do nothing */
1326 pr_info("%s: %s is already the current"
1327 " active slave.\n",
1328 bond->dev->name,
1329 slave->dev->name);
1330 goto out;
38c4916a 1331 } else {
f4bb2e9c
AG
1332 if ((new_active) &&
1333 (old_active) &&
1334 (new_active->link == BOND_LINK_UP) &&
1335 IS_UP(new_active->dev)) {
1336 pr_info("%s: Setting %s as active"
1337 " slave.\n",
a4aee5c8
JP
1338 bond->dev->name,
1339 slave->dev->name);
f4bb2e9c
AG
1340 bond_change_active_slave(bond,
1341 new_active);
38c4916a 1342 } else {
f4bb2e9c
AG
1343 pr_info("%s: Could not set %s as"
1344 " active slave; either %s is"
1345 " down or the link is down.\n",
1346 bond->dev->name,
1347 slave->dev->name,
1348 slave->dev->name);
b76cdba9 1349 }
f4bb2e9c 1350 goto out;
b76cdba9
MW
1351 }
1352 }
b76cdba9 1353 }
f4bb2e9c
AG
1354
1355 pr_info("%s: Unable to set %.*s as active slave.\n",
1356 bond->dev->name, (int)strlen(buf) - 1, buf);
3d632c3f 1357 out:
e934dd78
JV
1358 write_unlock_bh(&bond->curr_slave_lock);
1359 read_unlock(&bond->lock);
e843fa50
NH
1360 unblock_netpoll_tx();
1361
6603a6f2
JV
1362 rtnl_unlock();
1363
b76cdba9
MW
1364 return count;
1365
1366}
3d632c3f
SH
1367static DEVICE_ATTR(active_slave, S_IRUGO | S_IWUSR,
1368 bonding_show_active_slave, bonding_store_active_slave);
b76cdba9
MW
1369
1370
1371/*
1372 * Show link status of the bond interface.
1373 */
43cb76d9
GKH
1374static ssize_t bonding_show_mii_status(struct device *d,
1375 struct device_attribute *attr,
1376 char *buf)
b76cdba9 1377{
43cb76d9 1378 struct bonding *bond = to_bond(d);
b76cdba9 1379
278b2083 1380 return sprintf(buf, "%s\n", bond->curr_active_slave ? "up" : "down");
b76cdba9 1381}
43cb76d9 1382static DEVICE_ATTR(mii_status, S_IRUGO, bonding_show_mii_status, NULL);
b76cdba9 1383
b76cdba9
MW
1384/*
1385 * Show current 802.3ad aggregator ID.
1386 */
43cb76d9
GKH
1387static ssize_t bonding_show_ad_aggregator(struct device *d,
1388 struct device_attribute *attr,
1389 char *buf)
b76cdba9
MW
1390{
1391 int count = 0;
43cb76d9 1392 struct bonding *bond = to_bond(d);
b76cdba9
MW
1393
1394 if (bond->params.mode == BOND_MODE_8023AD) {
1395 struct ad_info ad_info;
3d632c3f 1396 count = sprintf(buf, "%d\n",
318debd8 1397 bond_3ad_get_active_agg_info(bond, &ad_info)
3d632c3f 1398 ? 0 : ad_info.aggregator_id);
b76cdba9 1399 }
b76cdba9
MW
1400
1401 return count;
1402}
43cb76d9 1403static DEVICE_ATTR(ad_aggregator, S_IRUGO, bonding_show_ad_aggregator, NULL);
b76cdba9
MW
1404
1405
1406/*
1407 * Show number of active 802.3ad ports.
1408 */
43cb76d9
GKH
1409static ssize_t bonding_show_ad_num_ports(struct device *d,
1410 struct device_attribute *attr,
1411 char *buf)
b76cdba9
MW
1412{
1413 int count = 0;
43cb76d9 1414 struct bonding *bond = to_bond(d);
b76cdba9
MW
1415
1416 if (bond->params.mode == BOND_MODE_8023AD) {
1417 struct ad_info ad_info;
3d632c3f 1418 count = sprintf(buf, "%d\n",
318debd8 1419 bond_3ad_get_active_agg_info(bond, &ad_info)
3d632c3f 1420 ? 0 : ad_info.ports);
b76cdba9 1421 }
b76cdba9
MW
1422
1423 return count;
1424}
43cb76d9 1425static DEVICE_ATTR(ad_num_ports, S_IRUGO, bonding_show_ad_num_ports, NULL);
b76cdba9
MW
1426
1427
1428/*
1429 * Show current 802.3ad actor key.
1430 */
43cb76d9
GKH
1431static ssize_t bonding_show_ad_actor_key(struct device *d,
1432 struct device_attribute *attr,
1433 char *buf)
b76cdba9
MW
1434{
1435 int count = 0;
43cb76d9 1436 struct bonding *bond = to_bond(d);
b76cdba9
MW
1437
1438 if (bond->params.mode == BOND_MODE_8023AD) {
1439 struct ad_info ad_info;
3d632c3f 1440 count = sprintf(buf, "%d\n",
318debd8 1441 bond_3ad_get_active_agg_info(bond, &ad_info)
3d632c3f 1442 ? 0 : ad_info.actor_key);
b76cdba9 1443 }
b76cdba9
MW
1444
1445 return count;
1446}
43cb76d9 1447static DEVICE_ATTR(ad_actor_key, S_IRUGO, bonding_show_ad_actor_key, NULL);
b76cdba9
MW
1448
1449
1450/*
1451 * Show current 802.3ad partner key.
1452 */
43cb76d9
GKH
1453static ssize_t bonding_show_ad_partner_key(struct device *d,
1454 struct device_attribute *attr,
1455 char *buf)
b76cdba9
MW
1456{
1457 int count = 0;
43cb76d9 1458 struct bonding *bond = to_bond(d);
b76cdba9
MW
1459
1460 if (bond->params.mode == BOND_MODE_8023AD) {
1461 struct ad_info ad_info;
3d632c3f 1462 count = sprintf(buf, "%d\n",
318debd8 1463 bond_3ad_get_active_agg_info(bond, &ad_info)
3d632c3f 1464 ? 0 : ad_info.partner_key);
b76cdba9 1465 }
b76cdba9
MW
1466
1467 return count;
1468}
43cb76d9 1469static DEVICE_ATTR(ad_partner_key, S_IRUGO, bonding_show_ad_partner_key, NULL);
b76cdba9
MW
1470
1471
1472/*
1473 * Show current 802.3ad partner mac.
1474 */
43cb76d9
GKH
1475static ssize_t bonding_show_ad_partner_mac(struct device *d,
1476 struct device_attribute *attr,
1477 char *buf)
b76cdba9
MW
1478{
1479 int count = 0;
43cb76d9 1480 struct bonding *bond = to_bond(d);
b76cdba9
MW
1481
1482 if (bond->params.mode == BOND_MODE_8023AD) {
1483 struct ad_info ad_info;
3d632c3f 1484 if (!bond_3ad_get_active_agg_info(bond, &ad_info))
e174961c 1485 count = sprintf(buf, "%pM\n", ad_info.partner_system);
b76cdba9 1486 }
b76cdba9
MW
1487
1488 return count;
1489}
43cb76d9 1490static DEVICE_ATTR(ad_partner_mac, S_IRUGO, bonding_show_ad_partner_mac, NULL);
b76cdba9 1491
bb1d9123
AG
1492/*
1493 * Show the queue_ids of the slaves in the current bond.
1494 */
1495static ssize_t bonding_show_queue_id(struct device *d,
1496 struct device_attribute *attr,
1497 char *buf)
1498{
bb1d9123 1499 struct bonding *bond = to_bond(d);
9caff1e7 1500 struct list_head *iter;
dec1e90e 1501 struct slave *slave;
1502 int res = 0;
bb1d9123
AG
1503
1504 if (!rtnl_trylock())
1505 return restart_syscall();
1506
1507 read_lock(&bond->lock);
9caff1e7 1508 bond_for_each_slave(bond, slave, iter) {
79236680
NP
1509 if (res > (PAGE_SIZE - IFNAMSIZ - 6)) {
1510 /* not enough space for another interface_name:queue_id pair */
bb1d9123
AG
1511 if ((PAGE_SIZE - res) > 10)
1512 res = PAGE_SIZE - 10;
1513 res += sprintf(buf + res, "++more++ ");
1514 break;
1515 }
1516 res += sprintf(buf + res, "%s:%d ",
1517 slave->dev->name, slave->queue_id);
1518 }
1519 read_unlock(&bond->lock);
1520 if (res)
1521 buf[res-1] = '\n'; /* eat the leftover space */
1522 rtnl_unlock();
dec1e90e 1523
bb1d9123
AG
1524 return res;
1525}
1526
1527/*
1528 * Set the queue_ids of the slaves in the current bond. The bond
1529 * interface must be enslaved for this to work.
1530 */
1531static ssize_t bonding_store_queue_id(struct device *d,
1532 struct device_attribute *attr,
1533 const char *buffer, size_t count)
1534{
1535 struct slave *slave, *update_slave;
1536 struct bonding *bond = to_bond(d);
9caff1e7 1537 struct list_head *iter;
bb1d9123 1538 u16 qid;
dec1e90e 1539 int ret = count;
bb1d9123
AG
1540 char *delim;
1541 struct net_device *sdev = NULL;
1542
1543 if (!rtnl_trylock())
1544 return restart_syscall();
1545
1546 /* delim will point to queue id if successful */
1547 delim = strchr(buffer, ':');
1548 if (!delim)
1549 goto err_no_cmd;
1550
1551 /*
1552 * Terminate string that points to device name and bump it
1553 * up one, so we can read the queue id there.
1554 */
1555 *delim = '\0';
1556 if (sscanf(++delim, "%hd\n", &qid) != 1)
1557 goto err_no_cmd;
1558
1559 /* Check buffer length, valid ifname and queue id */
1560 if (strlen(buffer) > IFNAMSIZ ||
1561 !dev_valid_name(buffer) ||
8a540ff9 1562 qid > bond->dev->real_num_tx_queues)
bb1d9123
AG
1563 goto err_no_cmd;
1564
1565 /* Get the pointer to that interface if it exists */
1566 sdev = __dev_get_by_name(dev_net(bond->dev), buffer);
1567 if (!sdev)
1568 goto err_no_cmd;
1569
1570 read_lock(&bond->lock);
1571
1572 /* Search for thes slave and check for duplicate qids */
1573 update_slave = NULL;
9caff1e7 1574 bond_for_each_slave(bond, slave, iter) {
bb1d9123
AG
1575 if (sdev == slave->dev)
1576 /*
1577 * We don't need to check the matching
1578 * slave for dups, since we're overwriting it
1579 */
1580 update_slave = slave;
1581 else if (qid && qid == slave->queue_id) {
1582 goto err_no_cmd_unlock;
1583 }
1584 }
1585
1586 if (!update_slave)
1587 goto err_no_cmd_unlock;
1588
1589 /* Actually set the qids for the slave */
1590 update_slave->queue_id = qid;
1591
1592 read_unlock(&bond->lock);
1593out:
1594 rtnl_unlock();
1595 return ret;
1596
1597err_no_cmd_unlock:
1598 read_unlock(&bond->lock);
1599err_no_cmd:
1600 pr_info("invalid input for queue_id set for %s.\n",
1601 bond->dev->name);
1602 ret = -EPERM;
1603 goto out;
1604}
1605
1606static DEVICE_ATTR(queue_id, S_IRUGO | S_IWUSR, bonding_show_queue_id,
1607 bonding_store_queue_id);
1608
1609
ebd8e497
AG
1610/*
1611 * Show and set the all_slaves_active flag.
1612 */
1613static ssize_t bonding_show_slaves_active(struct device *d,
1614 struct device_attribute *attr,
1615 char *buf)
1616{
1617 struct bonding *bond = to_bond(d);
1618
1619 return sprintf(buf, "%d\n", bond->params.all_slaves_active);
1620}
1621
1622static ssize_t bonding_store_slaves_active(struct device *d,
1623 struct device_attribute *attr,
1624 const char *buf, size_t count)
1625{
ebd8e497 1626 struct bonding *bond = to_bond(d);
dec1e90e 1627 int new_value, ret = count;
9caff1e7 1628 struct list_head *iter;
ebd8e497
AG
1629 struct slave *slave;
1630
1631 if (sscanf(buf, "%d", &new_value) != 1) {
1632 pr_err("%s: no all_slaves_active value specified.\n",
1633 bond->dev->name);
1634 ret = -EINVAL;
1635 goto out;
1636 }
1637
1638 if (new_value == bond->params.all_slaves_active)
1639 goto out;
1640
1641 if ((new_value == 0) || (new_value == 1)) {
1642 bond->params.all_slaves_active = new_value;
1643 } else {
1644 pr_info("%s: Ignoring invalid all_slaves_active value %d.\n",
1645 bond->dev->name, new_value);
1646 ret = -EINVAL;
1647 goto out;
1648 }
b76cdba9 1649
e196c0e5 1650 read_lock(&bond->lock);
9caff1e7 1651 bond_for_each_slave(bond, slave, iter) {
e30bc066 1652 if (!bond_is_active_slave(slave)) {
ebd8e497 1653 if (new_value)
2d7011ca 1654 slave->inactive = 0;
ebd8e497 1655 else
2d7011ca 1656 slave->inactive = 1;
ebd8e497
AG
1657 }
1658 }
e196c0e5 1659 read_unlock(&bond->lock);
ebd8e497 1660out:
672bda33 1661 return ret;
ebd8e497
AG
1662}
1663static DEVICE_ATTR(all_slaves_active, S_IRUGO | S_IWUSR,
1664 bonding_show_slaves_active, bonding_store_slaves_active);
b76cdba9 1665
c2952c31
FL
1666/*
1667 * Show and set the number of IGMP membership reports to send on link failure
1668 */
1669static ssize_t bonding_show_resend_igmp(struct device *d,
94265cf5
FL
1670 struct device_attribute *attr,
1671 char *buf)
c2952c31
FL
1672{
1673 struct bonding *bond = to_bond(d);
1674
1675 return sprintf(buf, "%d\n", bond->params.resend_igmp);
1676}
1677
1678static ssize_t bonding_store_resend_igmp(struct device *d,
94265cf5
FL
1679 struct device_attribute *attr,
1680 const char *buf, size_t count)
c2952c31
FL
1681{
1682 int new_value, ret = count;
1683 struct bonding *bond = to_bond(d);
1684
1685 if (sscanf(buf, "%d", &new_value) != 1) {
1686 pr_err("%s: no resend_igmp value specified.\n",
1687 bond->dev->name);
1688 ret = -EINVAL;
1689 goto out;
1690 }
1691
94265cf5 1692 if (new_value < 0 || new_value > 255) {
c2952c31
FL
1693 pr_err("%s: Invalid resend_igmp value %d not in range 0-255; rejected.\n",
1694 bond->dev->name, new_value);
1695 ret = -EINVAL;
1696 goto out;
1697 }
1698
1699 pr_info("%s: Setting resend_igmp to %d.\n",
1700 bond->dev->name, new_value);
1701 bond->params.resend_igmp = new_value;
1702out:
1703 return ret;
1704}
1705
1706static DEVICE_ATTR(resend_igmp, S_IRUGO | S_IWUSR,
1707 bonding_show_resend_igmp, bonding_store_resend_igmp);
1708
7eacd038
NH
1709
1710static ssize_t bonding_show_lp_interval(struct device *d,
1711 struct device_attribute *attr,
1712 char *buf)
1713{
1714 struct bonding *bond = to_bond(d);
1715 return sprintf(buf, "%d\n", bond->params.lp_interval);
1716}
1717
1718static ssize_t bonding_store_lp_interval(struct device *d,
1719 struct device_attribute *attr,
1720 const char *buf, size_t count)
1721{
1722 struct bonding *bond = to_bond(d);
1723 int new_value, ret = count;
1724
1725 if (sscanf(buf, "%d", &new_value) != 1) {
1726 pr_err("%s: no lp interval value specified.\n",
1727 bond->dev->name);
1728 ret = -EINVAL;
1729 goto out;
1730 }
1731
1732 if (new_value <= 0) {
1733 pr_err ("%s: lp_interval must be between 1 and %d\n",
1734 bond->dev->name, INT_MAX);
1735 ret = -EINVAL;
1736 goto out;
1737 }
1738
1739 bond->params.lp_interval = new_value;
1740out:
1741 return ret;
1742}
1743
1744static DEVICE_ATTR(lp_interval, S_IRUGO | S_IWUSR,
1745 bonding_show_lp_interval, bonding_store_lp_interval);
1746
b76cdba9 1747static struct attribute *per_bond_attrs[] = {
43cb76d9
GKH
1748 &dev_attr_slaves.attr,
1749 &dev_attr_mode.attr,
dd957c57 1750 &dev_attr_fail_over_mac.attr,
43cb76d9 1751 &dev_attr_arp_validate.attr,
8599b52e 1752 &dev_attr_arp_all_targets.attr,
43cb76d9
GKH
1753 &dev_attr_arp_interval.attr,
1754 &dev_attr_arp_ip_target.attr,
1755 &dev_attr_downdelay.attr,
1756 &dev_attr_updelay.attr,
1757 &dev_attr_lacp_rate.attr,
fd989c83 1758 &dev_attr_ad_select.attr,
43cb76d9 1759 &dev_attr_xmit_hash_policy.attr,
ad246c99
BH
1760 &dev_attr_num_grat_arp.attr,
1761 &dev_attr_num_unsol_na.attr,
43cb76d9
GKH
1762 &dev_attr_miimon.attr,
1763 &dev_attr_primary.attr,
a549952a 1764 &dev_attr_primary_reselect.attr,
43cb76d9
GKH
1765 &dev_attr_use_carrier.attr,
1766 &dev_attr_active_slave.attr,
1767 &dev_attr_mii_status.attr,
1768 &dev_attr_ad_aggregator.attr,
1769 &dev_attr_ad_num_ports.attr,
1770 &dev_attr_ad_actor_key.attr,
1771 &dev_attr_ad_partner_key.attr,
1772 &dev_attr_ad_partner_mac.attr,
bb1d9123 1773 &dev_attr_queue_id.attr,
ebd8e497 1774 &dev_attr_all_slaves_active.attr,
c2952c31 1775 &dev_attr_resend_igmp.attr,
655f8919 1776 &dev_attr_min_links.attr,
7eacd038 1777 &dev_attr_lp_interval.attr,
b76cdba9
MW
1778 NULL,
1779};
1780
1781static struct attribute_group bonding_group = {
1782 .name = "bonding",
1783 .attrs = per_bond_attrs,
1784};
1785
1786/*
1787 * Initialize sysfs. This sets up the bonding_masters file in
1788 * /sys/class/net.
1789 */
4c22400a 1790int bond_create_sysfs(struct bond_net *bn)
b76cdba9 1791{
b8a9787e 1792 int ret;
b76cdba9 1793
4c22400a 1794 bn->class_attr_bonding_masters = class_attr_bonding_masters;
01718e36 1795 sysfs_attr_init(&bn->class_attr_bonding_masters.attr);
4c22400a
EB
1796
1797 ret = netdev_class_create_file(&bn->class_attr_bonding_masters);
877cbd36
JV
1798 /*
1799 * Permit multiple loads of the module by ignoring failures to
1800 * create the bonding_masters sysfs file. Bonding devices
1801 * created by second or subsequent loads of the module will
1802 * not be listed in, or controllable by, bonding_masters, but
1803 * will have the usual "bonding" sysfs directory.
1804 *
1805 * This is done to preserve backwards compatibility for
1806 * initscripts/sysconfig, which load bonding multiple times to
1807 * configure multiple bonding devices.
1808 */
1809 if (ret == -EEXIST) {
38d2f38b 1810 /* Is someone being kinky and naming a device bonding_master? */
4c22400a 1811 if (__dev_get_by_name(bn->net,
38d2f38b 1812 class_attr_bonding_masters.attr.name))
a4aee5c8 1813 pr_err("network device named %s already exists in sysfs",
38d2f38b 1814 class_attr_bonding_masters.attr.name);
130aa61a 1815 ret = 0;
877cbd36 1816 }
b76cdba9
MW
1817
1818 return ret;
1819
1820}
1821
1822/*
1823 * Remove /sys/class/net/bonding_masters.
1824 */
4c22400a 1825void bond_destroy_sysfs(struct bond_net *bn)
b76cdba9 1826{
4c22400a 1827 netdev_class_remove_file(&bn->class_attr_bonding_masters);
b76cdba9
MW
1828}
1829
1830/*
1831 * Initialize sysfs for each bond. This sets up and registers
1832 * the 'bondctl' directory for each individual bond under /sys/class/net.
1833 */
6151b3d4 1834void bond_prepare_sysfs_group(struct bonding *bond)
b76cdba9 1835{
6151b3d4 1836 bond->dev->sysfs_groups[0] = &bonding_group;
b76cdba9
MW
1837}
1838
This page took 0.876831 seconds and 5 git commands to generate.