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