bonding: convert downdelay to use the new option API
[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
adf8d3ff 15 * with this program; if not, see <http://www.gnu.org/licenses/>.
b76cdba9
MW
16 *
17 * The full GNU General Public License is included in this distribution in the
18 * file called LICENSE.
19 *
b76cdba9 20 */
a4aee5c8
JP
21
22#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
23
b76cdba9
MW
24#include <linux/kernel.h>
25#include <linux/module.h>
b76cdba9 26#include <linux/device.h>
d43c36dc 27#include <linux/sched.h>
b76cdba9
MW
28#include <linux/fs.h>
29#include <linux/types.h>
30#include <linux/string.h>
31#include <linux/netdevice.h>
32#include <linux/inetdevice.h>
33#include <linux/in.h>
34#include <linux/sysfs.h>
b76cdba9
MW
35#include <linux/ctype.h>
36#include <linux/inet.h>
37#include <linux/rtnetlink.h>
5c5129b5 38#include <linux/etherdevice.h>
881d966b 39#include <net/net_namespace.h>
ec87fd3b
EB
40#include <net/netns/generic.h>
41#include <linux/nsproxy.h>
b76cdba9 42
b76cdba9 43#include "bonding.h"
5a03cdb7 44
3d632c3f 45#define to_dev(obj) container_of(obj, struct device, kobj)
454d7c9b 46#define to_bond(cd) ((struct bonding *)(netdev_priv(to_net_dev(cd))))
b76cdba9 47
b76cdba9
MW
48/*
49 * "show" function for the bond_masters attribute.
50 * The class parameter is ignored.
51 */
28812fe1
AK
52static ssize_t bonding_show_bonds(struct class *cls,
53 struct class_attribute *attr,
54 char *buf)
b76cdba9 55{
4c22400a
EB
56 struct bond_net *bn =
57 container_of(attr, struct bond_net, class_attr_bonding_masters);
b76cdba9
MW
58 int res = 0;
59 struct bonding *bond;
60
7e083840 61 rtnl_lock();
b76cdba9 62
ec87fd3b 63 list_for_each_entry(bond, &bn->dev_list, bond_list) {
b76cdba9
MW
64 if (res > (PAGE_SIZE - IFNAMSIZ)) {
65 /* not enough space for another interface name */
66 if ((PAGE_SIZE - res) > 10)
67 res = PAGE_SIZE - 10;
b8843665 68 res += sprintf(buf + res, "++more++ ");
b76cdba9
MW
69 break;
70 }
b8843665 71 res += sprintf(buf + res, "%s ", bond->dev->name);
b76cdba9 72 }
1dcdcd69
WF
73 if (res)
74 buf[res-1] = '\n'; /* eat the leftover space */
7e083840
SH
75
76 rtnl_unlock();
b76cdba9
MW
77 return res;
78}
79
4c22400a 80static struct net_device *bond_get_by_name(struct bond_net *bn, const char *ifname)
373500db
SH
81{
82 struct bonding *bond;
83
ec87fd3b 84 list_for_each_entry(bond, &bn->dev_list, bond_list) {
373500db
SH
85 if (strncmp(bond->dev->name, ifname, IFNAMSIZ) == 0)
86 return bond->dev;
87 }
88 return NULL;
89}
90
b76cdba9
MW
91/*
92 * "store" function for the bond_masters attribute. This is what
93 * creates and deletes entire bonds.
94 *
95 * The class parameter is ignored.
96 *
97 */
98
3d632c3f 99static ssize_t bonding_store_bonds(struct class *cls,
28812fe1 100 struct class_attribute *attr,
3d632c3f 101 const char *buffer, size_t count)
b76cdba9 102{
4c22400a
EB
103 struct bond_net *bn =
104 container_of(attr, struct bond_net, class_attr_bonding_masters);
b76cdba9
MW
105 char command[IFNAMSIZ + 1] = {0, };
106 char *ifname;
027ea041 107 int rv, res = count;
b76cdba9 108
b76cdba9
MW
109 sscanf(buffer, "%16s", command); /* IFNAMSIZ*/
110 ifname = command + 1;
111 if ((strlen(command) <= 1) ||
112 !dev_valid_name(ifname))
113 goto err_no_cmd;
114
115 if (command[0] == '+') {
a4aee5c8 116 pr_info("%s is being created...\n", ifname);
4c22400a 117 rv = bond_create(bn->net, ifname);
027ea041 118 if (rv) {
5f86cad1
PO
119 if (rv == -EEXIST)
120 pr_info("%s already exists.\n", ifname);
121 else
122 pr_info("%s creation failed.\n", ifname);
027ea041 123 res = rv;
b76cdba9 124 }
373500db
SH
125 } else if (command[0] == '-') {
126 struct net_device *bond_dev;
b76cdba9 127
027ea041 128 rtnl_lock();
4c22400a 129 bond_dev = bond_get_by_name(bn, ifname);
373500db 130 if (bond_dev) {
a4aee5c8 131 pr_info("%s is being deleted...\n", ifname);
373500db
SH
132 unregister_netdevice(bond_dev);
133 } else {
a4aee5c8 134 pr_err("unable to delete non-existent %s\n", ifname);
373500db
SH
135 res = -ENODEV;
136 }
137 rtnl_unlock();
138 } else
139 goto err_no_cmd;
027ea041 140
373500db
SH
141 /* Always return either count or an error. If you return 0, you'll
142 * get called forever, which is bad.
143 */
144 return res;
b76cdba9
MW
145
146err_no_cmd:
a4aee5c8 147 pr_err("no command found in bonding_masters. Use +ifname or -ifname.\n");
c4ebc66a 148 return -EPERM;
b76cdba9 149}
373500db 150
b76cdba9 151/* class attribute for bond_masters file. This ends up in /sys/class/net */
4c22400a
EB
152static const struct class_attribute class_attr_bonding_masters = {
153 .attr = {
154 .name = "bonding_masters",
155 .mode = S_IWUSR | S_IRUGO,
156 },
157 .show = bonding_show_bonds,
158 .store = bonding_store_bonds,
4c22400a 159};
b76cdba9 160
b76cdba9
MW
161/*
162 * Show the slaves in the current bond.
163 */
43cb76d9
GKH
164static ssize_t bonding_show_slaves(struct device *d,
165 struct device_attribute *attr, char *buf)
b76cdba9 166{
43cb76d9 167 struct bonding *bond = to_bond(d);
9caff1e7 168 struct list_head *iter;
dec1e90e 169 struct slave *slave;
170 int res = 0;
b76cdba9 171
4d1ae5fb 172 if (!rtnl_trylock())
173 return restart_syscall();
174
9caff1e7 175 bond_for_each_slave(bond, slave, iter) {
b76cdba9
MW
176 if (res > (PAGE_SIZE - IFNAMSIZ)) {
177 /* not enough space for another interface name */
178 if ((PAGE_SIZE - res) > 10)
179 res = PAGE_SIZE - 10;
7bd46508 180 res += sprintf(buf + res, "++more++ ");
b76cdba9
MW
181 break;
182 }
183 res += sprintf(buf + res, "%s ", slave->dev->name);
184 }
4d1ae5fb 185
186 rtnl_unlock();
187
1dcdcd69
WF
188 if (res)
189 buf[res-1] = '\n'; /* eat the leftover space */
dec1e90e 190
b76cdba9
MW
191 return res;
192}
193
194/*
d6641ccf 195 * Set the slaves in the current bond.
f9f3545e
JP
196 * This is supposed to be only thin wrapper for bond_enslave and bond_release.
197 * All hard work should be done there.
b76cdba9 198 */
43cb76d9
GKH
199static ssize_t bonding_store_slaves(struct device *d,
200 struct device_attribute *attr,
201 const char *buffer, size_t count)
b76cdba9
MW
202{
203 char command[IFNAMSIZ + 1] = { 0, };
204 char *ifname;
f9f3545e
JP
205 int res, ret = count;
206 struct net_device *dev;
43cb76d9 207 struct bonding *bond = to_bond(d);
b76cdba9 208
496a60cd
EB
209 if (!rtnl_trylock())
210 return restart_syscall();
027ea041 211
b76cdba9
MW
212 sscanf(buffer, "%16s", command); /* IFNAMSIZ*/
213 ifname = command + 1;
214 if ((strlen(command) <= 1) ||
215 !dev_valid_name(ifname))
216 goto err_no_cmd;
217
f9f3545e
JP
218 dev = __dev_get_by_name(dev_net(bond->dev), ifname);
219 if (!dev) {
220 pr_info("%s: Interface %s does not exist!\n",
221 bond->dev->name, ifname);
222 ret = -ENODEV;
223 goto out;
224 }
b76cdba9 225
f9f3545e
JP
226 switch (command[0]) {
227 case '+':
228 pr_info("%s: Adding slave %s.\n", bond->dev->name, dev->name);
b76cdba9 229 res = bond_enslave(bond->dev, dev);
f9f3545e 230 break;
3d632c3f 231
f9f3545e
JP
232 case '-':
233 pr_info("%s: Removing slave %s.\n", bond->dev->name, dev->name);
234 res = bond_release(bond->dev, dev);
235 break;
b76cdba9 236
f9f3545e
JP
237 default:
238 goto err_no_cmd;
b76cdba9
MW
239 }
240
f9f3545e
JP
241 if (res)
242 ret = res;
243 goto out;
244
b76cdba9 245err_no_cmd:
a4aee5c8
JP
246 pr_err("no command found in slaves file for bond %s. Use +ifname or -ifname.\n",
247 bond->dev->name);
b76cdba9
MW
248 ret = -EPERM;
249
250out:
027ea041 251 rtnl_unlock();
b76cdba9
MW
252 return ret;
253}
254
3d632c3f
SH
255static DEVICE_ATTR(slaves, S_IRUGO | S_IWUSR, bonding_show_slaves,
256 bonding_store_slaves);
b76cdba9
MW
257
258/*
259 * Show and set the bonding mode. The bond interface must be down to
260 * change the mode.
261 */
43cb76d9
GKH
262static ssize_t bonding_show_mode(struct device *d,
263 struct device_attribute *attr, char *buf)
b76cdba9 264{
43cb76d9 265 struct bonding *bond = to_bond(d);
2b3798d5 266 struct bond_opt_value *val;
b76cdba9 267
2b3798d5
NA
268 val = bond_opt_get_val(BOND_OPT_MODE, bond->params.mode);
269
270 return sprintf(buf, "%s %d\n", val->string, bond->params.mode);
b76cdba9
MW
271}
272
43cb76d9
GKH
273static ssize_t bonding_store_mode(struct device *d,
274 struct device_attribute *attr,
275 const char *buf, size_t count)
b76cdba9 276{
43cb76d9 277 struct bonding *bond = to_bond(d);
2b3798d5 278 int ret;
b76cdba9 279
2b3798d5
NA
280 ret = bond_opt_tryset_rtnl(bond, BOND_OPT_MODE, (char *)buf);
281 if (!ret)
72be35fe 282 ret = count;
8f903c70 283
b76cdba9
MW
284 return ret;
285}
3d632c3f
SH
286static DEVICE_ATTR(mode, S_IRUGO | S_IWUSR,
287 bonding_show_mode, bonding_store_mode);
b76cdba9
MW
288
289/*
3d632c3f 290 * Show and set the bonding transmit hash method.
b76cdba9 291 */
43cb76d9
GKH
292static ssize_t bonding_show_xmit_hash(struct device *d,
293 struct device_attribute *attr,
294 char *buf)
b76cdba9 295{
43cb76d9 296 struct bonding *bond = to_bond(d);
a4b32ce7
NA
297 struct bond_opt_value *val;
298
299 val = bond_opt_get_val(BOND_OPT_XMIT_HASH, bond->params.xmit_policy);
b76cdba9 300
a4b32ce7 301 return sprintf(buf, "%s %d\n", val->string, bond->params.xmit_policy);
b76cdba9
MW
302}
303
43cb76d9
GKH
304static ssize_t bonding_store_xmit_hash(struct device *d,
305 struct device_attribute *attr,
306 const char *buf, size_t count)
b76cdba9 307{
43cb76d9 308 struct bonding *bond = to_bond(d);
a4b32ce7 309 int ret;
b76cdba9 310
a4b32ce7 311 ret = bond_opt_tryset_rtnl(bond, BOND_OPT_XMIT_HASH, (char *)buf);
f70161c6 312 if (!ret)
313 ret = count;
314
b76cdba9
MW
315 return ret;
316}
3d632c3f
SH
317static DEVICE_ATTR(xmit_hash_policy, S_IRUGO | S_IWUSR,
318 bonding_show_xmit_hash, bonding_store_xmit_hash);
b76cdba9 319
f5b2b966
JV
320/*
321 * Show and set arp_validate.
322 */
43cb76d9
GKH
323static ssize_t bonding_show_arp_validate(struct device *d,
324 struct device_attribute *attr,
325 char *buf)
f5b2b966 326{
43cb76d9 327 struct bonding *bond = to_bond(d);
16228881
NA
328 struct bond_opt_value *val;
329
330 val = bond_opt_get_val(BOND_OPT_ARP_VALIDATE,
331 bond->params.arp_validate);
f5b2b966 332
16228881 333 return sprintf(buf, "%s %d\n", val->string, bond->params.arp_validate);
f5b2b966
JV
334}
335
43cb76d9
GKH
336static ssize_t bonding_store_arp_validate(struct device *d,
337 struct device_attribute *attr,
338 const char *buf, size_t count)
f5b2b966 339{
43cb76d9 340 struct bonding *bond = to_bond(d);
16228881 341 int ret;
29c49482 342
16228881 343 ret = bond_opt_tryset_rtnl(bond, BOND_OPT_ARP_VALIDATE, (char *)buf);
29c49482 344 if (!ret)
345 ret = count;
346
5c5038dc 347 return ret;
f5b2b966
JV
348}
349
3d632c3f
SH
350static DEVICE_ATTR(arp_validate, S_IRUGO | S_IWUSR, bonding_show_arp_validate,
351 bonding_store_arp_validate);
8599b52e
VF
352/*
353 * Show and set arp_all_targets.
354 */
355static ssize_t bonding_show_arp_all_targets(struct device *d,
356 struct device_attribute *attr,
357 char *buf)
358{
359 struct bonding *bond = to_bond(d);
edf36b24 360 struct bond_opt_value *val;
8599b52e 361
edf36b24
NA
362 val = bond_opt_get_val(BOND_OPT_ARP_ALL_TARGETS,
363 bond->params.arp_all_targets);
364 return sprintf(buf, "%s %d\n",
365 val->string, bond->params.arp_all_targets);
8599b52e
VF
366}
367
368static ssize_t bonding_store_arp_all_targets(struct device *d,
369 struct device_attribute *attr,
370 const char *buf, size_t count)
371{
372 struct bonding *bond = to_bond(d);
edf36b24 373 int ret;
8599b52e 374
edf36b24 375 ret = bond_opt_tryset_rtnl(bond, BOND_OPT_ARP_ALL_TARGETS, (char *)buf);
d5c84254 376 if (!ret)
377 ret = count;
378
d5c84254 379 return ret;
8599b52e
VF
380}
381
382static DEVICE_ATTR(arp_all_targets, S_IRUGO | S_IWUSR,
383 bonding_show_arp_all_targets, bonding_store_arp_all_targets);
f5b2b966 384
dd957c57
JV
385/*
386 * Show and store fail_over_mac. User only allowed to change the
387 * value when there are no slaves.
388 */
3d632c3f
SH
389static ssize_t bonding_show_fail_over_mac(struct device *d,
390 struct device_attribute *attr,
391 char *buf)
dd957c57
JV
392{
393 struct bonding *bond = to_bond(d);
1df6b6aa 394 struct bond_opt_value *val;
dd957c57 395
1df6b6aa
NA
396 val = bond_opt_get_val(BOND_OPT_FAIL_OVER_MAC,
397 bond->params.fail_over_mac);
398
399 return sprintf(buf, "%s %d\n", val->string, bond->params.fail_over_mac);
dd957c57
JV
400}
401
3d632c3f
SH
402static ssize_t bonding_store_fail_over_mac(struct device *d,
403 struct device_attribute *attr,
404 const char *buf, size_t count)
dd957c57 405{
dd957c57 406 struct bonding *bond = to_bond(d);
1df6b6aa 407 int ret;
dd957c57 408
1df6b6aa 409 ret = bond_opt_tryset_rtnl(bond, BOND_OPT_FAIL_OVER_MAC, (char *)buf);
89901972 410 if (!ret)
411 ret = count;
3915c1e8 412
9402b746 413 return ret;
dd957c57
JV
414}
415
3d632c3f
SH
416static DEVICE_ATTR(fail_over_mac, S_IRUGO | S_IWUSR,
417 bonding_show_fail_over_mac, bonding_store_fail_over_mac);
dd957c57 418
b76cdba9
MW
419/*
420 * Show and set the arp timer interval. There are two tricky bits
421 * here. First, if ARP monitoring is activated, then we must disable
422 * MII monitoring. Second, if the ARP timer isn't running, we must
423 * start it.
424 */
43cb76d9
GKH
425static ssize_t bonding_show_arp_interval(struct device *d,
426 struct device_attribute *attr,
427 char *buf)
b76cdba9 428{
43cb76d9 429 struct bonding *bond = to_bond(d);
b76cdba9 430
7bd46508 431 return sprintf(buf, "%d\n", bond->params.arp_interval);
b76cdba9
MW
432}
433
43cb76d9
GKH
434static ssize_t bonding_store_arp_interval(struct device *d,
435 struct device_attribute *attr,
436 const char *buf, size_t count)
b76cdba9 437{
43cb76d9 438 struct bonding *bond = to_bond(d);
7bdb04ed 439 int ret;
06151dbc 440
7bdb04ed 441 ret = bond_opt_tryset_rtnl(bond, BOND_OPT_ARP_INTERVAL, (char *)buf);
06151dbc 442 if (!ret)
443 ret = count;
444
b76cdba9
MW
445 return ret;
446}
3d632c3f
SH
447static DEVICE_ATTR(arp_interval, S_IRUGO | S_IWUSR,
448 bonding_show_arp_interval, bonding_store_arp_interval);
b76cdba9
MW
449
450/*
451 * Show and set the arp targets.
452 */
43cb76d9
GKH
453static ssize_t bonding_show_arp_targets(struct device *d,
454 struct device_attribute *attr,
455 char *buf)
b76cdba9 456{
43cb76d9 457 struct bonding *bond = to_bond(d);
4fb0ef58 458 int i, res = 0;
b76cdba9
MW
459
460 for (i = 0; i < BOND_MAX_ARP_TARGETS; i++) {
461 if (bond->params.arp_targets[i])
63779436
HH
462 res += sprintf(buf + res, "%pI4 ",
463 &bond->params.arp_targets[i]);
b76cdba9 464 }
1dcdcd69
WF
465 if (res)
466 buf[res-1] = '\n'; /* eat the leftover space */
4fb0ef58 467
b76cdba9
MW
468 return res;
469}
470
43cb76d9
GKH
471static ssize_t bonding_store_arp_targets(struct device *d,
472 struct device_attribute *attr,
473 const char *buf, size_t count)
b76cdba9 474{
43cb76d9 475 struct bonding *bond = to_bond(d);
4fb0ef58 476 int ret;
b76cdba9 477
4fb0ef58 478 ret = bond_opt_tryset_rtnl(bond, BOND_OPT_ARP_TARGETS, (char *)buf);
7f28fa10 479 if (!ret)
480 ret = count;
481
b76cdba9
MW
482 return ret;
483}
43cb76d9 484static DEVICE_ATTR(arp_ip_target, S_IRUGO | S_IWUSR , bonding_show_arp_targets, bonding_store_arp_targets);
b76cdba9
MW
485
486/*
487 * Show and set the up and down delays. These must be multiples of the
488 * MII monitoring value, and are stored internally as the multiplier.
489 * Thus, we must translate to MS for the real world.
490 */
43cb76d9
GKH
491static ssize_t bonding_show_downdelay(struct device *d,
492 struct device_attribute *attr,
493 char *buf)
b76cdba9 494{
43cb76d9 495 struct bonding *bond = to_bond(d);
b76cdba9 496
7bd46508 497 return sprintf(buf, "%d\n", bond->params.downdelay * bond->params.miimon);
b76cdba9
MW
498}
499
43cb76d9
GKH
500static ssize_t bonding_store_downdelay(struct device *d,
501 struct device_attribute *attr,
502 const char *buf, size_t count)
b76cdba9 503{
43cb76d9 504 struct bonding *bond = to_bond(d);
25a9b54a 505 int ret;
b76cdba9 506
25a9b54a 507 ret = bond_opt_tryset_rtnl(bond, BOND_OPT_DOWNDELAY, (char *)buf);
c7461f9b 508 if (!ret)
509 ret = count;
b76cdba9 510
b76cdba9
MW
511 return ret;
512}
3d632c3f
SH
513static DEVICE_ATTR(downdelay, S_IRUGO | S_IWUSR,
514 bonding_show_downdelay, bonding_store_downdelay);
b76cdba9 515
43cb76d9
GKH
516static ssize_t bonding_show_updelay(struct device *d,
517 struct device_attribute *attr,
518 char *buf)
b76cdba9 519{
43cb76d9 520 struct bonding *bond = to_bond(d);
b76cdba9 521
7bd46508 522 return sprintf(buf, "%d\n", bond->params.updelay * bond->params.miimon);
b76cdba9
MW
523
524}
525
43cb76d9
GKH
526static ssize_t bonding_store_updelay(struct device *d,
527 struct device_attribute *attr,
528 const char *buf, size_t count)
b76cdba9 529{
25852e29 530 int new_value, ret;
43cb76d9 531 struct bonding *bond = to_bond(d);
b76cdba9 532
b76cdba9 533 if (sscanf(buf, "%d", &new_value) != 1) {
a4aee5c8 534 pr_err("%s: no up delay value specified.\n",
25852e29 535 bond->dev->name);
536 return -EINVAL;
b76cdba9
MW
537 }
538
25852e29 539 if (!rtnl_trylock())
540 return restart_syscall();
541
542 ret = bond_option_updelay_set(bond, new_value);
543 if (!ret)
544 ret = count;
545
b869ccfa 546 rtnl_unlock();
b76cdba9
MW
547 return ret;
548}
3d632c3f
SH
549static DEVICE_ATTR(updelay, S_IRUGO | S_IWUSR,
550 bonding_show_updelay, bonding_store_updelay);
b76cdba9
MW
551
552/*
553 * Show and set the LACP interval. Interface must be down, and the mode
554 * must be set to 802.3ad mode.
555 */
43cb76d9
GKH
556static ssize_t bonding_show_lacp(struct device *d,
557 struct device_attribute *attr,
558 char *buf)
b76cdba9 559{
43cb76d9 560 struct bonding *bond = to_bond(d);
b76cdba9
MW
561
562 return sprintf(buf, "%s %d\n",
563 bond_lacp_tbl[bond->params.lacp_fast].modename,
7bd46508 564 bond->params.lacp_fast);
b76cdba9
MW
565}
566
43cb76d9
GKH
567static ssize_t bonding_store_lacp(struct device *d,
568 struct device_attribute *attr,
569 const char *buf, size_t count)
b76cdba9 570{
43cb76d9 571 struct bonding *bond = to_bond(d);
998e40bb 572 int new_value, ret;
b76cdba9 573
ece95f7f 574 new_value = bond_parse_parm(buf, bond_lacp_tbl);
998e40bb 575 if (new_value < 0) {
a4aee5c8 576 pr_err("%s: Ignoring invalid LACP rate value %.*s.\n",
3d632c3f 577 bond->dev->name, (int)strlen(buf) - 1, buf);
998e40bb 578 return -EINVAL;
b76cdba9 579 }
c509316b 580
998e40bb 581 if (!rtnl_trylock())
582 return restart_syscall();
583
584 ret = bond_option_lacp_rate_set(bond, new_value);
585 if (!ret)
586 ret = count;
587
588 rtnl_unlock();
b76cdba9
MW
589 return ret;
590}
3d632c3f
SH
591static DEVICE_ATTR(lacp_rate, S_IRUGO | S_IWUSR,
592 bonding_show_lacp, bonding_store_lacp);
b76cdba9 593
655f8919 594static ssize_t bonding_show_min_links(struct device *d,
595 struct device_attribute *attr,
596 char *buf)
597{
598 struct bonding *bond = to_bond(d);
599
600 return sprintf(buf, "%d\n", bond->params.min_links);
601}
602
603static ssize_t bonding_store_min_links(struct device *d,
604 struct device_attribute *attr,
605 const char *buf, size_t count)
606{
607 struct bonding *bond = to_bond(d);
608 int ret;
609 unsigned int new_value;
610
611 ret = kstrtouint(buf, 0, &new_value);
612 if (ret < 0) {
613 pr_err("%s: Ignoring invalid min links value %s.\n",
614 bond->dev->name, buf);
615 return ret;
616 }
617
7d101008 618 if (!rtnl_trylock())
619 return restart_syscall();
620
621 ret = bond_option_min_links_set(bond, new_value);
622 if (!ret)
623 ret = count;
624
625 rtnl_unlock();
626 return ret;
655f8919 627}
628static DEVICE_ATTR(min_links, S_IRUGO | S_IWUSR,
629 bonding_show_min_links, bonding_store_min_links);
630
fd989c83
JV
631static ssize_t bonding_show_ad_select(struct device *d,
632 struct device_attribute *attr,
633 char *buf)
634{
635 struct bonding *bond = to_bond(d);
636
637 return sprintf(buf, "%s %d\n",
638 ad_select_tbl[bond->params.ad_select].modename,
639 bond->params.ad_select);
640}
641
642
643static ssize_t bonding_store_ad_select(struct device *d,
644 struct device_attribute *attr,
645 const char *buf, size_t count)
646{
ec029fac 647 int new_value, ret;
fd989c83
JV
648 struct bonding *bond = to_bond(d);
649
fd989c83 650 new_value = bond_parse_parm(buf, ad_select_tbl);
ec029fac 651 if (new_value < 0) {
a4aee5c8 652 pr_err("%s: Ignoring invalid ad_select value %.*s.\n",
fd989c83 653 bond->dev->name, (int)strlen(buf) - 1, buf);
ec029fac 654 return -EINVAL;
fd989c83 655 }
ec029fac 656
657 if (!rtnl_trylock())
658 return restart_syscall();
659
660 ret = bond_option_ad_select_set(bond, new_value);
661 if (!ret)
662 ret = count;
663
664 rtnl_unlock();
fd989c83
JV
665 return ret;
666}
3d632c3f
SH
667static DEVICE_ATTR(ad_select, S_IRUGO | S_IWUSR,
668 bonding_show_ad_select, bonding_store_ad_select);
fd989c83 669
ad246c99
BH
670/*
671 * Show and set the number of peer notifications to send after a failover event.
672 */
673static ssize_t bonding_show_num_peer_notif(struct device *d,
674 struct device_attribute *attr,
675 char *buf)
676{
677 struct bonding *bond = to_bond(d);
678 return sprintf(buf, "%d\n", bond->params.num_peer_notif);
679}
680
681static ssize_t bonding_store_num_peer_notif(struct device *d,
682 struct device_attribute *attr,
683 const char *buf, size_t count)
684{
685 struct bonding *bond = to_bond(d);
2c9839c1 686 u8 new_value;
687 int ret;
688
689 ret = kstrtou8(buf, 10, &new_value);
0b23810d 690 if (ret) {
2c9839c1 691 pr_err("%s: invalid value %s specified.\n",
692 bond->dev->name, buf);
693 return ret;
694 }
695
696 if (!rtnl_trylock())
697 return restart_syscall();
698
699 ret = bond_option_num_peer_notif_set(bond, new_value);
700 if (!ret)
701 ret = count;
702
703 rtnl_unlock();
704 return ret;
ad246c99
BH
705}
706static DEVICE_ATTR(num_grat_arp, S_IRUGO | S_IWUSR,
707 bonding_show_num_peer_notif, bonding_store_num_peer_notif);
708static DEVICE_ATTR(num_unsol_na, S_IRUGO | S_IWUSR,
709 bonding_show_num_peer_notif, bonding_store_num_peer_notif);
710
b76cdba9
MW
711/*
712 * Show and set the MII monitor interval. There are two tricky bits
713 * here. First, if MII monitoring is activated, then we must disable
714 * ARP monitoring. Second, if the timer isn't running, we must
715 * start it.
716 */
43cb76d9
GKH
717static ssize_t bonding_show_miimon(struct device *d,
718 struct device_attribute *attr,
719 char *buf)
b76cdba9 720{
43cb76d9 721 struct bonding *bond = to_bond(d);
b76cdba9 722
7bd46508 723 return sprintf(buf, "%d\n", bond->params.miimon);
b76cdba9
MW
724}
725
43cb76d9
GKH
726static ssize_t bonding_store_miimon(struct device *d,
727 struct device_attribute *attr,
728 const char *buf, size_t count)
b76cdba9 729{
eecdaa6e 730 int new_value, ret;
43cb76d9 731 struct bonding *bond = to_bond(d);
b76cdba9
MW
732
733 if (sscanf(buf, "%d", &new_value) != 1) {
a4aee5c8 734 pr_err("%s: no miimon value specified.\n",
b76cdba9 735 bond->dev->name);
eecdaa6e 736 return -EINVAL;
b76cdba9 737 }
eecdaa6e 738
739 if (!rtnl_trylock())
740 return restart_syscall();
741
742 ret = bond_option_miimon_set(bond, new_value);
743 if (!ret)
744 ret = count;
745
fbb0c41b 746 rtnl_unlock();
b76cdba9
MW
747 return ret;
748}
3d632c3f
SH
749static DEVICE_ATTR(miimon, S_IRUGO | S_IWUSR,
750 bonding_show_miimon, bonding_store_miimon);
b76cdba9
MW
751
752/*
753 * Show and set the primary slave. The store function is much
754 * simpler than bonding_store_slaves function because it only needs to
755 * handle one interface name.
756 * The bond must be a mode that supports a primary for this be
757 * set.
758 */
43cb76d9
GKH
759static ssize_t bonding_show_primary(struct device *d,
760 struct device_attribute *attr,
761 char *buf)
b76cdba9
MW
762{
763 int count = 0;
43cb76d9 764 struct bonding *bond = to_bond(d);
b76cdba9
MW
765
766 if (bond->primary_slave)
7bd46508 767 count = sprintf(buf, "%s\n", bond->primary_slave->dev->name);
b76cdba9
MW
768
769 return count;
770}
771
43cb76d9
GKH
772static ssize_t bonding_store_primary(struct device *d,
773 struct device_attribute *attr,
774 const char *buf, size_t count)
b76cdba9 775{
43cb76d9 776 struct bonding *bond = to_bond(d);
f4bb2e9c 777 char ifname[IFNAMSIZ];
0a98a0d1 778 int ret;
b76cdba9 779
eb6e98a1 780 sscanf(buf, "%15s", ifname); /* IFNAMSIZ */
0a98a0d1 781 if (ifname[0] == '\n')
782 ifname[0] = '\0';
b76cdba9 783
0a98a0d1 784 if (!rtnl_trylock())
785 return restart_syscall();
f4bb2e9c 786
0a98a0d1 787 ret = bond_option_primary_set(bond, ifname);
788 if (!ret)
789 ret = count;
8a93664d 790
6603a6f2 791 rtnl_unlock();
0a98a0d1 792 return ret;
b76cdba9 793}
3d632c3f
SH
794static DEVICE_ATTR(primary, S_IRUGO | S_IWUSR,
795 bonding_show_primary, bonding_store_primary);
b76cdba9 796
a549952a
JP
797/*
798 * Show and set the primary_reselect flag.
799 */
800static ssize_t bonding_show_primary_reselect(struct device *d,
801 struct device_attribute *attr,
802 char *buf)
803{
804 struct bonding *bond = to_bond(d);
805
806 return sprintf(buf, "%s %d\n",
807 pri_reselect_tbl[bond->params.primary_reselect].modename,
808 bond->params.primary_reselect);
809}
810
811static ssize_t bonding_store_primary_reselect(struct device *d,
812 struct device_attribute *attr,
813 const char *buf, size_t count)
814{
8a41ae44 815 int new_value, ret;
a549952a
JP
816 struct bonding *bond = to_bond(d);
817
a549952a
JP
818 new_value = bond_parse_parm(buf, pri_reselect_tbl);
819 if (new_value < 0) {
a4aee5c8 820 pr_err("%s: Ignoring invalid primary_reselect value %.*s.\n",
a549952a
JP
821 bond->dev->name,
822 (int) strlen(buf) - 1, buf);
8a41ae44 823 return -EINVAL;
a549952a
JP
824 }
825
8a41ae44 826 if (!rtnl_trylock())
827 return restart_syscall();
828
829 ret = bond_option_primary_reselect_set(bond, new_value);
830 if (!ret)
831 ret = count;
a549952a 832
a549952a
JP
833 rtnl_unlock();
834 return ret;
835}
836static DEVICE_ATTR(primary_reselect, S_IRUGO | S_IWUSR,
837 bonding_show_primary_reselect,
838 bonding_store_primary_reselect);
839
b76cdba9
MW
840/*
841 * Show and set the use_carrier flag.
842 */
43cb76d9
GKH
843static ssize_t bonding_show_carrier(struct device *d,
844 struct device_attribute *attr,
845 char *buf)
b76cdba9 846{
43cb76d9 847 struct bonding *bond = to_bond(d);
b76cdba9 848
7bd46508 849 return sprintf(buf, "%d\n", bond->params.use_carrier);
b76cdba9
MW
850}
851
43cb76d9
GKH
852static ssize_t bonding_store_carrier(struct device *d,
853 struct device_attribute *attr,
854 const char *buf, size_t count)
b76cdba9 855{
9f53e14e 856 int new_value, ret;
43cb76d9 857 struct bonding *bond = to_bond(d);
b76cdba9 858
b76cdba9 859 if (sscanf(buf, "%d", &new_value) != 1) {
a4aee5c8 860 pr_err("%s: no use_carrier value specified.\n",
b76cdba9 861 bond->dev->name);
9f53e14e 862 return -EINVAL;
b76cdba9 863 }
9f53e14e 864
865 if (!rtnl_trylock())
866 return restart_syscall();
867
868 ret = bond_option_use_carrier_set(bond, new_value);
869 if (!ret)
870 ret = count;
871
872 rtnl_unlock();
672bda33 873 return ret;
b76cdba9 874}
3d632c3f
SH
875static DEVICE_ATTR(use_carrier, S_IRUGO | S_IWUSR,
876 bonding_show_carrier, bonding_store_carrier);
b76cdba9
MW
877
878
879/*
880 * Show and set currently active_slave.
881 */
43cb76d9
GKH
882static ssize_t bonding_show_active_slave(struct device *d,
883 struct device_attribute *attr,
884 char *buf)
b76cdba9 885{
43cb76d9 886 struct bonding *bond = to_bond(d);
752d48b5 887 struct net_device *slave_dev;
16cd0160 888 int count = 0;
b76cdba9 889
278b2083 890 rcu_read_lock();
752d48b5
JP
891 slave_dev = bond_option_active_slave_get_rcu(bond);
892 if (slave_dev)
893 count = sprintf(buf, "%s\n", slave_dev->name);
278b2083 894 rcu_read_unlock();
895
b76cdba9
MW
896 return count;
897}
898
43cb76d9
GKH
899static ssize_t bonding_store_active_slave(struct device *d,
900 struct device_attribute *attr,
901 const char *buf, size_t count)
b76cdba9 902{
d9e32b21 903 int ret;
43cb76d9 904 struct bonding *bond = to_bond(d);
f4bb2e9c 905 char ifname[IFNAMSIZ];
d9e32b21 906 struct net_device *dev;
b76cdba9 907
496a60cd
EB
908 if (!rtnl_trylock())
909 return restart_syscall();
e843fa50 910
c84e1590 911 sscanf(buf, "%15s", ifname); /* IFNAMSIZ */
f4bb2e9c 912 if (!strlen(ifname) || buf[0] == '\n') {
d9e32b21
JP
913 dev = NULL;
914 } else {
915 dev = __dev_get_by_name(dev_net(bond->dev), ifname);
916 if (!dev) {
917 ret = -ENODEV;
918 goto out;
b76cdba9 919 }
b76cdba9 920 }
f4bb2e9c 921
d9e32b21
JP
922 ret = bond_option_active_slave_set(bond, dev);
923 if (!ret)
924 ret = count;
e843fa50 925
d9e32b21 926 out:
6603a6f2
JV
927 rtnl_unlock();
928
d9e32b21 929 return ret;
b76cdba9
MW
930
931}
3d632c3f
SH
932static DEVICE_ATTR(active_slave, S_IRUGO | S_IWUSR,
933 bonding_show_active_slave, bonding_store_active_slave);
b76cdba9
MW
934
935
936/*
937 * Show link status of the bond interface.
938 */
43cb76d9
GKH
939static ssize_t bonding_show_mii_status(struct device *d,
940 struct device_attribute *attr,
941 char *buf)
b76cdba9 942{
43cb76d9 943 struct bonding *bond = to_bond(d);
b76cdba9 944
278b2083 945 return sprintf(buf, "%s\n", bond->curr_active_slave ? "up" : "down");
b76cdba9 946}
43cb76d9 947static DEVICE_ATTR(mii_status, S_IRUGO, bonding_show_mii_status, NULL);
b76cdba9 948
b76cdba9
MW
949/*
950 * Show current 802.3ad aggregator ID.
951 */
43cb76d9
GKH
952static ssize_t bonding_show_ad_aggregator(struct device *d,
953 struct device_attribute *attr,
954 char *buf)
b76cdba9
MW
955{
956 int count = 0;
43cb76d9 957 struct bonding *bond = to_bond(d);
b76cdba9
MW
958
959 if (bond->params.mode == BOND_MODE_8023AD) {
960 struct ad_info ad_info;
3d632c3f 961 count = sprintf(buf, "%d\n",
318debd8 962 bond_3ad_get_active_agg_info(bond, &ad_info)
3d632c3f 963 ? 0 : ad_info.aggregator_id);
b76cdba9 964 }
b76cdba9
MW
965
966 return count;
967}
43cb76d9 968static DEVICE_ATTR(ad_aggregator, S_IRUGO, bonding_show_ad_aggregator, NULL);
b76cdba9
MW
969
970
971/*
972 * Show number of active 802.3ad ports.
973 */
43cb76d9
GKH
974static ssize_t bonding_show_ad_num_ports(struct device *d,
975 struct device_attribute *attr,
976 char *buf)
b76cdba9
MW
977{
978 int count = 0;
43cb76d9 979 struct bonding *bond = to_bond(d);
b76cdba9
MW
980
981 if (bond->params.mode == BOND_MODE_8023AD) {
982 struct ad_info ad_info;
3d632c3f 983 count = sprintf(buf, "%d\n",
318debd8 984 bond_3ad_get_active_agg_info(bond, &ad_info)
3d632c3f 985 ? 0 : ad_info.ports);
b76cdba9 986 }
b76cdba9
MW
987
988 return count;
989}
43cb76d9 990static DEVICE_ATTR(ad_num_ports, S_IRUGO, bonding_show_ad_num_ports, NULL);
b76cdba9
MW
991
992
993/*
994 * Show current 802.3ad actor key.
995 */
43cb76d9
GKH
996static ssize_t bonding_show_ad_actor_key(struct device *d,
997 struct device_attribute *attr,
998 char *buf)
b76cdba9
MW
999{
1000 int count = 0;
43cb76d9 1001 struct bonding *bond = to_bond(d);
b76cdba9
MW
1002
1003 if (bond->params.mode == BOND_MODE_8023AD) {
1004 struct ad_info ad_info;
3d632c3f 1005 count = sprintf(buf, "%d\n",
318debd8 1006 bond_3ad_get_active_agg_info(bond, &ad_info)
3d632c3f 1007 ? 0 : ad_info.actor_key);
b76cdba9 1008 }
b76cdba9
MW
1009
1010 return count;
1011}
43cb76d9 1012static DEVICE_ATTR(ad_actor_key, S_IRUGO, bonding_show_ad_actor_key, NULL);
b76cdba9
MW
1013
1014
1015/*
1016 * Show current 802.3ad partner key.
1017 */
43cb76d9
GKH
1018static ssize_t bonding_show_ad_partner_key(struct device *d,
1019 struct device_attribute *attr,
1020 char *buf)
b76cdba9
MW
1021{
1022 int count = 0;
43cb76d9 1023 struct bonding *bond = to_bond(d);
b76cdba9
MW
1024
1025 if (bond->params.mode == BOND_MODE_8023AD) {
1026 struct ad_info ad_info;
3d632c3f 1027 count = sprintf(buf, "%d\n",
318debd8 1028 bond_3ad_get_active_agg_info(bond, &ad_info)
3d632c3f 1029 ? 0 : ad_info.partner_key);
b76cdba9 1030 }
b76cdba9
MW
1031
1032 return count;
1033}
43cb76d9 1034static DEVICE_ATTR(ad_partner_key, S_IRUGO, bonding_show_ad_partner_key, NULL);
b76cdba9
MW
1035
1036
1037/*
1038 * Show current 802.3ad partner mac.
1039 */
43cb76d9
GKH
1040static ssize_t bonding_show_ad_partner_mac(struct device *d,
1041 struct device_attribute *attr,
1042 char *buf)
b76cdba9
MW
1043{
1044 int count = 0;
43cb76d9 1045 struct bonding *bond = to_bond(d);
b76cdba9
MW
1046
1047 if (bond->params.mode == BOND_MODE_8023AD) {
1048 struct ad_info ad_info;
3d632c3f 1049 if (!bond_3ad_get_active_agg_info(bond, &ad_info))
e174961c 1050 count = sprintf(buf, "%pM\n", ad_info.partner_system);
b76cdba9 1051 }
b76cdba9
MW
1052
1053 return count;
1054}
43cb76d9 1055static DEVICE_ATTR(ad_partner_mac, S_IRUGO, bonding_show_ad_partner_mac, NULL);
b76cdba9 1056
bb1d9123
AG
1057/*
1058 * Show the queue_ids of the slaves in the current bond.
1059 */
1060static ssize_t bonding_show_queue_id(struct device *d,
1061 struct device_attribute *attr,
1062 char *buf)
1063{
bb1d9123 1064 struct bonding *bond = to_bond(d);
9caff1e7 1065 struct list_head *iter;
dec1e90e 1066 struct slave *slave;
1067 int res = 0;
bb1d9123
AG
1068
1069 if (!rtnl_trylock())
1070 return restart_syscall();
1071
9caff1e7 1072 bond_for_each_slave(bond, slave, iter) {
79236680
NP
1073 if (res > (PAGE_SIZE - IFNAMSIZ - 6)) {
1074 /* not enough space for another interface_name:queue_id pair */
bb1d9123
AG
1075 if ((PAGE_SIZE - res) > 10)
1076 res = PAGE_SIZE - 10;
1077 res += sprintf(buf + res, "++more++ ");
1078 break;
1079 }
1080 res += sprintf(buf + res, "%s:%d ",
1081 slave->dev->name, slave->queue_id);
1082 }
bb1d9123
AG
1083 if (res)
1084 buf[res-1] = '\n'; /* eat the leftover space */
4d1ae5fb 1085
bb1d9123 1086 rtnl_unlock();
dec1e90e 1087
bb1d9123
AG
1088 return res;
1089}
1090
1091/*
1092 * Set the queue_ids of the slaves in the current bond. The bond
1093 * interface must be enslaved for this to work.
1094 */
1095static ssize_t bonding_store_queue_id(struct device *d,
1096 struct device_attribute *attr,
1097 const char *buffer, size_t count)
1098{
1099 struct slave *slave, *update_slave;
1100 struct bonding *bond = to_bond(d);
9caff1e7 1101 struct list_head *iter;
bb1d9123 1102 u16 qid;
dec1e90e 1103 int ret = count;
bb1d9123
AG
1104 char *delim;
1105 struct net_device *sdev = NULL;
1106
1107 if (!rtnl_trylock())
1108 return restart_syscall();
1109
1110 /* delim will point to queue id if successful */
1111 delim = strchr(buffer, ':');
1112 if (!delim)
1113 goto err_no_cmd;
1114
1115 /*
1116 * Terminate string that points to device name and bump it
1117 * up one, so we can read the queue id there.
1118 */
1119 *delim = '\0';
1120 if (sscanf(++delim, "%hd\n", &qid) != 1)
1121 goto err_no_cmd;
1122
1123 /* Check buffer length, valid ifname and queue id */
1124 if (strlen(buffer) > IFNAMSIZ ||
1125 !dev_valid_name(buffer) ||
8a540ff9 1126 qid > bond->dev->real_num_tx_queues)
bb1d9123
AG
1127 goto err_no_cmd;
1128
1129 /* Get the pointer to that interface if it exists */
1130 sdev = __dev_get_by_name(dev_net(bond->dev), buffer);
1131 if (!sdev)
1132 goto err_no_cmd;
1133
bb1d9123
AG
1134 /* Search for thes slave and check for duplicate qids */
1135 update_slave = NULL;
9caff1e7 1136 bond_for_each_slave(bond, slave, iter) {
bb1d9123
AG
1137 if (sdev == slave->dev)
1138 /*
1139 * We don't need to check the matching
1140 * slave for dups, since we're overwriting it
1141 */
1142 update_slave = slave;
1143 else if (qid && qid == slave->queue_id) {
4d1ae5fb 1144 goto err_no_cmd;
bb1d9123
AG
1145 }
1146 }
1147
1148 if (!update_slave)
4d1ae5fb 1149 goto err_no_cmd;
bb1d9123
AG
1150
1151 /* Actually set the qids for the slave */
1152 update_slave->queue_id = qid;
1153
bb1d9123
AG
1154out:
1155 rtnl_unlock();
1156 return ret;
1157
bb1d9123
AG
1158err_no_cmd:
1159 pr_info("invalid input for queue_id set for %s.\n",
1160 bond->dev->name);
1161 ret = -EPERM;
1162 goto out;
1163}
1164
1165static DEVICE_ATTR(queue_id, S_IRUGO | S_IWUSR, bonding_show_queue_id,
1166 bonding_store_queue_id);
1167
1168
ebd8e497
AG
1169/*
1170 * Show and set the all_slaves_active flag.
1171 */
1172static ssize_t bonding_show_slaves_active(struct device *d,
1173 struct device_attribute *attr,
1174 char *buf)
1175{
1176 struct bonding *bond = to_bond(d);
1177
1178 return sprintf(buf, "%d\n", bond->params.all_slaves_active);
1179}
1180
1181static ssize_t bonding_store_slaves_active(struct device *d,
1182 struct device_attribute *attr,
1183 const char *buf, size_t count)
1184{
ebd8e497 1185 struct bonding *bond = to_bond(d);
1cc0b1e3 1186 int new_value, ret;
4d1ae5fb 1187
ebd8e497
AG
1188 if (sscanf(buf, "%d", &new_value) != 1) {
1189 pr_err("%s: no all_slaves_active value specified.\n",
1190 bond->dev->name);
1cc0b1e3 1191 return -EINVAL;
ebd8e497
AG
1192 }
1193
1cc0b1e3 1194 if (!rtnl_trylock())
1195 return restart_syscall();
ebd8e497 1196
1cc0b1e3 1197 ret = bond_option_all_slaves_active_set(bond, new_value);
1198 if (!ret)
1199 ret = count;
b76cdba9 1200
4d1ae5fb 1201 rtnl_unlock();
672bda33 1202 return ret;
ebd8e497
AG
1203}
1204static DEVICE_ATTR(all_slaves_active, S_IRUGO | S_IWUSR,
1205 bonding_show_slaves_active, bonding_store_slaves_active);
b76cdba9 1206
c2952c31
FL
1207/*
1208 * Show and set the number of IGMP membership reports to send on link failure
1209 */
1210static ssize_t bonding_show_resend_igmp(struct device *d,
94265cf5
FL
1211 struct device_attribute *attr,
1212 char *buf)
c2952c31
FL
1213{
1214 struct bonding *bond = to_bond(d);
1215
1216 return sprintf(buf, "%d\n", bond->params.resend_igmp);
1217}
1218
1219static ssize_t bonding_store_resend_igmp(struct device *d,
94265cf5
FL
1220 struct device_attribute *attr,
1221 const char *buf, size_t count)
c2952c31
FL
1222{
1223 int new_value, ret = count;
1224 struct bonding *bond = to_bond(d);
1225
1226 if (sscanf(buf, "%d", &new_value) != 1) {
1227 pr_err("%s: no resend_igmp value specified.\n",
1228 bond->dev->name);
d8838de7 1229 return -EINVAL;
c2952c31
FL
1230 }
1231
d8838de7 1232 if (!rtnl_trylock())
1233 return restart_syscall();
c2952c31 1234
d8838de7 1235 ret = bond_option_resend_igmp_set(bond, new_value);
1236 if (!ret)
1237 ret = count;
1238
1239 rtnl_unlock();
c2952c31
FL
1240 return ret;
1241}
1242
1243static DEVICE_ATTR(resend_igmp, S_IRUGO | S_IWUSR,
1244 bonding_show_resend_igmp, bonding_store_resend_igmp);
1245
7eacd038
NH
1246
1247static ssize_t bonding_show_lp_interval(struct device *d,
1248 struct device_attribute *attr,
1249 char *buf)
1250{
1251 struct bonding *bond = to_bond(d);
1252 return sprintf(buf, "%d\n", bond->params.lp_interval);
1253}
1254
1255static ssize_t bonding_store_lp_interval(struct device *d,
1256 struct device_attribute *attr,
1257 const char *buf, size_t count)
1258{
1259 struct bonding *bond = to_bond(d);
8d836d09 1260 int new_value, ret;
7eacd038
NH
1261
1262 if (sscanf(buf, "%d", &new_value) != 1) {
1263 pr_err("%s: no lp interval value specified.\n",
1264 bond->dev->name);
8d836d09 1265 return -EINVAL;
7eacd038
NH
1266 }
1267
8d836d09 1268 if (!rtnl_trylock())
1269 return restart_syscall();
7eacd038 1270
8d836d09 1271 ret = bond_option_lp_interval_set(bond, new_value);
1272 if (!ret)
1273 ret = count;
1274
1275 rtnl_unlock();
7eacd038
NH
1276 return ret;
1277}
1278
1279static DEVICE_ATTR(lp_interval, S_IRUGO | S_IWUSR,
1280 bonding_show_lp_interval, bonding_store_lp_interval);
1281
73958329
NA
1282static ssize_t bonding_show_packets_per_slave(struct device *d,
1283 struct device_attribute *attr,
1284 char *buf)
1285{
1286 struct bonding *bond = to_bond(d);
a752a8b9 1287 unsigned int packets_per_slave = bond->params.packets_per_slave;
a752a8b9 1288 return sprintf(buf, "%u\n", packets_per_slave);
73958329
NA
1289}
1290
1291static ssize_t bonding_store_packets_per_slave(struct device *d,
1292 struct device_attribute *attr,
1293 const char *buf, size_t count)
1294{
1295 struct bonding *bond = to_bond(d);
aa59d851 1296 int ret;
c13ab3ff 1297
aa59d851
NA
1298 ret = bond_opt_tryset_rtnl(bond, BOND_OPT_PACKETS_PER_SLAVE,
1299 (char *)buf);
c13ab3ff 1300 if (!ret)
1301 ret = count;
1302
73958329
NA
1303 return ret;
1304}
1305
1306static DEVICE_ATTR(packets_per_slave, S_IRUGO | S_IWUSR,
1307 bonding_show_packets_per_slave,
1308 bonding_store_packets_per_slave);
1309
b76cdba9 1310static struct attribute *per_bond_attrs[] = {
43cb76d9
GKH
1311 &dev_attr_slaves.attr,
1312 &dev_attr_mode.attr,
dd957c57 1313 &dev_attr_fail_over_mac.attr,
43cb76d9 1314 &dev_attr_arp_validate.attr,
8599b52e 1315 &dev_attr_arp_all_targets.attr,
43cb76d9
GKH
1316 &dev_attr_arp_interval.attr,
1317 &dev_attr_arp_ip_target.attr,
1318 &dev_attr_downdelay.attr,
1319 &dev_attr_updelay.attr,
1320 &dev_attr_lacp_rate.attr,
fd989c83 1321 &dev_attr_ad_select.attr,
43cb76d9 1322 &dev_attr_xmit_hash_policy.attr,
ad246c99
BH
1323 &dev_attr_num_grat_arp.attr,
1324 &dev_attr_num_unsol_na.attr,
43cb76d9
GKH
1325 &dev_attr_miimon.attr,
1326 &dev_attr_primary.attr,
a549952a 1327 &dev_attr_primary_reselect.attr,
43cb76d9
GKH
1328 &dev_attr_use_carrier.attr,
1329 &dev_attr_active_slave.attr,
1330 &dev_attr_mii_status.attr,
1331 &dev_attr_ad_aggregator.attr,
1332 &dev_attr_ad_num_ports.attr,
1333 &dev_attr_ad_actor_key.attr,
1334 &dev_attr_ad_partner_key.attr,
1335 &dev_attr_ad_partner_mac.attr,
bb1d9123 1336 &dev_attr_queue_id.attr,
ebd8e497 1337 &dev_attr_all_slaves_active.attr,
c2952c31 1338 &dev_attr_resend_igmp.attr,
655f8919 1339 &dev_attr_min_links.attr,
7eacd038 1340 &dev_attr_lp_interval.attr,
73958329 1341 &dev_attr_packets_per_slave.attr,
b76cdba9
MW
1342 NULL,
1343};
1344
1345static struct attribute_group bonding_group = {
1346 .name = "bonding",
1347 .attrs = per_bond_attrs,
1348};
1349
1350/*
1351 * Initialize sysfs. This sets up the bonding_masters file in
1352 * /sys/class/net.
1353 */
4c22400a 1354int bond_create_sysfs(struct bond_net *bn)
b76cdba9 1355{
b8a9787e 1356 int ret;
b76cdba9 1357
4c22400a 1358 bn->class_attr_bonding_masters = class_attr_bonding_masters;
01718e36 1359 sysfs_attr_init(&bn->class_attr_bonding_masters.attr);
4c22400a 1360
58292cbe
TH
1361 ret = netdev_class_create_file_ns(&bn->class_attr_bonding_masters,
1362 bn->net);
877cbd36
JV
1363 /*
1364 * Permit multiple loads of the module by ignoring failures to
1365 * create the bonding_masters sysfs file. Bonding devices
1366 * created by second or subsequent loads of the module will
1367 * not be listed in, or controllable by, bonding_masters, but
1368 * will have the usual "bonding" sysfs directory.
1369 *
1370 * This is done to preserve backwards compatibility for
1371 * initscripts/sysconfig, which load bonding multiple times to
1372 * configure multiple bonding devices.
1373 */
1374 if (ret == -EEXIST) {
38d2f38b 1375 /* Is someone being kinky and naming a device bonding_master? */
4c22400a 1376 if (__dev_get_by_name(bn->net,
38d2f38b 1377 class_attr_bonding_masters.attr.name))
a4aee5c8 1378 pr_err("network device named %s already exists in sysfs",
38d2f38b 1379 class_attr_bonding_masters.attr.name);
130aa61a 1380 ret = 0;
877cbd36 1381 }
b76cdba9
MW
1382
1383 return ret;
1384
1385}
1386
1387/*
1388 * Remove /sys/class/net/bonding_masters.
1389 */
4c22400a 1390void bond_destroy_sysfs(struct bond_net *bn)
b76cdba9 1391{
58292cbe 1392 netdev_class_remove_file_ns(&bn->class_attr_bonding_masters, bn->net);
b76cdba9
MW
1393}
1394
1395/*
1396 * Initialize sysfs for each bond. This sets up and registers
1397 * the 'bondctl' directory for each individual bond under /sys/class/net.
1398 */
6151b3d4 1399void bond_prepare_sysfs_group(struct bonding *bond)
b76cdba9 1400{
6151b3d4 1401 bond->dev->sysfs_groups[0] = &bonding_group;
b76cdba9
MW
1402}
1403