]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/net/bonding/bond_sysfs.c
bonding: convert packets_per_slave to use the new option API
[mirror_ubuntu-artful-kernel.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);
b76cdba9 297
8e4b9329
WF
298 return sprintf(buf, "%s %d\n",
299 xmit_hashtype_tbl[bond->params.xmit_policy].modename,
300 bond->params.xmit_policy);
b76cdba9
MW
301}
302
43cb76d9
GKH
303static ssize_t bonding_store_xmit_hash(struct device *d,
304 struct device_attribute *attr,
305 const char *buf, size_t count)
b76cdba9 306{
f70161c6 307 int new_value, ret;
43cb76d9 308 struct bonding *bond = to_bond(d);
b76cdba9 309
ece95f7f 310 new_value = bond_parse_parm(buf, xmit_hashtype_tbl);
b76cdba9 311 if (new_value < 0) {
a4aee5c8 312 pr_err("%s: Ignoring invalid xmit hash policy value %.*s.\n",
b76cdba9
MW
313 bond->dev->name,
314 (int)strlen(buf) - 1, buf);
f70161c6 315 return -EINVAL;
b76cdba9 316 }
53edee2c 317
f70161c6 318 if (!rtnl_trylock())
319 return restart_syscall();
320
321 ret = bond_option_xmit_hash_policy_set(bond, new_value);
322 if (!ret)
323 ret = count;
324
325 rtnl_unlock();
b76cdba9
MW
326 return ret;
327}
3d632c3f
SH
328static DEVICE_ATTR(xmit_hash_policy, S_IRUGO | S_IWUSR,
329 bonding_show_xmit_hash, bonding_store_xmit_hash);
b76cdba9 330
f5b2b966
JV
331/*
332 * Show and set arp_validate.
333 */
43cb76d9
GKH
334static ssize_t bonding_show_arp_validate(struct device *d,
335 struct device_attribute *attr,
336 char *buf)
f5b2b966 337{
43cb76d9 338 struct bonding *bond = to_bond(d);
f5b2b966
JV
339
340 return sprintf(buf, "%s %d\n",
341 arp_validate_tbl[bond->params.arp_validate].modename,
7bd46508 342 bond->params.arp_validate);
f5b2b966
JV
343}
344
43cb76d9
GKH
345static ssize_t bonding_store_arp_validate(struct device *d,
346 struct device_attribute *attr,
347 const char *buf, size_t count)
f5b2b966 348{
43cb76d9 349 struct bonding *bond = to_bond(d);
29c49482 350 int new_value, ret;
f5b2b966 351
ece95f7f 352 new_value = bond_parse_parm(buf, arp_validate_tbl);
f5b2b966 353 if (new_value < 0) {
a4aee5c8 354 pr_err("%s: Ignoring invalid arp_validate value %s\n",
f5b2b966 355 bond->dev->name, buf);
29c49482 356 return -EINVAL;
5bb9e0b5 357 }
29c49482 358 if (!rtnl_trylock())
359 return restart_syscall();
360
361 ret = bond_option_arp_validate_set(bond, new_value);
362 if (!ret)
363 ret = count;
364
5c5038dc 365 rtnl_unlock();
f5b2b966 366
5c5038dc 367 return ret;
f5b2b966
JV
368}
369
3d632c3f
SH
370static DEVICE_ATTR(arp_validate, S_IRUGO | S_IWUSR, bonding_show_arp_validate,
371 bonding_store_arp_validate);
8599b52e
VF
372/*
373 * Show and set arp_all_targets.
374 */
375static ssize_t bonding_show_arp_all_targets(struct device *d,
376 struct device_attribute *attr,
377 char *buf)
378{
379 struct bonding *bond = to_bond(d);
380 int value = bond->params.arp_all_targets;
381
382 return sprintf(buf, "%s %d\n", arp_all_targets_tbl[value].modename,
383 value);
384}
385
386static ssize_t bonding_store_arp_all_targets(struct device *d,
387 struct device_attribute *attr,
388 const char *buf, size_t count)
389{
390 struct bonding *bond = to_bond(d);
d5c84254 391 int new_value, ret;
8599b52e
VF
392
393 new_value = bond_parse_parm(buf, arp_all_targets_tbl);
394 if (new_value < 0) {
395 pr_err("%s: Ignoring invalid arp_all_targets value %s\n",
396 bond->dev->name, buf);
397 return -EINVAL;
398 }
8599b52e 399
d5c84254 400 if (!rtnl_trylock())
401 return restart_syscall();
8599b52e 402
d5c84254 403 ret = bond_option_arp_all_targets_set(bond, new_value);
404 if (!ret)
405 ret = count;
406
407 rtnl_unlock();
408
409 return ret;
8599b52e
VF
410}
411
412static DEVICE_ATTR(arp_all_targets, S_IRUGO | S_IWUSR,
413 bonding_show_arp_all_targets, bonding_store_arp_all_targets);
f5b2b966 414
dd957c57
JV
415/*
416 * Show and store fail_over_mac. User only allowed to change the
417 * value when there are no slaves.
418 */
3d632c3f
SH
419static ssize_t bonding_show_fail_over_mac(struct device *d,
420 struct device_attribute *attr,
421 char *buf)
dd957c57
JV
422{
423 struct bonding *bond = to_bond(d);
424
3915c1e8
JV
425 return sprintf(buf, "%s %d\n",
426 fail_over_mac_tbl[bond->params.fail_over_mac].modename,
427 bond->params.fail_over_mac);
dd957c57
JV
428}
429
3d632c3f
SH
430static ssize_t bonding_store_fail_over_mac(struct device *d,
431 struct device_attribute *attr,
432 const char *buf, size_t count)
dd957c57 433{
89901972 434 int new_value, ret;
dd957c57
JV
435 struct bonding *bond = to_bond(d);
436
3915c1e8
JV
437 new_value = bond_parse_parm(buf, fail_over_mac_tbl);
438 if (new_value < 0) {
a4aee5c8 439 pr_err("%s: Ignoring invalid fail_over_mac value %s.\n",
3915c1e8 440 bond->dev->name, buf);
89901972 441 return -EINVAL;
dd957c57
JV
442 }
443
89901972 444 if (!rtnl_trylock())
445 return restart_syscall();
446
447 ret = bond_option_fail_over_mac_set(bond, new_value);
448 if (!ret)
449 ret = count;
3915c1e8 450
9402b746 451 rtnl_unlock();
452 return ret;
dd957c57
JV
453}
454
3d632c3f
SH
455static DEVICE_ATTR(fail_over_mac, S_IRUGO | S_IWUSR,
456 bonding_show_fail_over_mac, bonding_store_fail_over_mac);
dd957c57 457
b76cdba9
MW
458/*
459 * Show and set the arp timer interval. There are two tricky bits
460 * here. First, if ARP monitoring is activated, then we must disable
461 * MII monitoring. Second, if the ARP timer isn't running, we must
462 * start it.
463 */
43cb76d9
GKH
464static ssize_t bonding_show_arp_interval(struct device *d,
465 struct device_attribute *attr,
466 char *buf)
b76cdba9 467{
43cb76d9 468 struct bonding *bond = to_bond(d);
b76cdba9 469
7bd46508 470 return sprintf(buf, "%d\n", bond->params.arp_interval);
b76cdba9
MW
471}
472
43cb76d9
GKH
473static ssize_t bonding_store_arp_interval(struct device *d,
474 struct device_attribute *attr,
475 const char *buf, size_t count)
b76cdba9 476{
43cb76d9 477 struct bonding *bond = to_bond(d);
06151dbc 478 int new_value, ret;
b76cdba9
MW
479
480 if (sscanf(buf, "%d", &new_value) != 1) {
a4aee5c8 481 pr_err("%s: no arp_interval value specified.\n",
06151dbc 482 bond->dev->name);
483 return -EINVAL;
b76cdba9 484 }
06151dbc 485
486 if (!rtnl_trylock())
487 return restart_syscall();
488
489 ret = bond_option_arp_interval_set(bond, new_value);
490 if (!ret)
491 ret = count;
492
fbb0c41b 493 rtnl_unlock();
b76cdba9
MW
494 return ret;
495}
3d632c3f
SH
496static DEVICE_ATTR(arp_interval, S_IRUGO | S_IWUSR,
497 bonding_show_arp_interval, bonding_store_arp_interval);
b76cdba9
MW
498
499/*
500 * Show and set the arp targets.
501 */
43cb76d9
GKH
502static ssize_t bonding_show_arp_targets(struct device *d,
503 struct device_attribute *attr,
504 char *buf)
b76cdba9
MW
505{
506 int i, res = 0;
43cb76d9 507 struct bonding *bond = to_bond(d);
b76cdba9
MW
508
509 for (i = 0; i < BOND_MAX_ARP_TARGETS; i++) {
510 if (bond->params.arp_targets[i])
63779436
HH
511 res += sprintf(buf + res, "%pI4 ",
512 &bond->params.arp_targets[i]);
b76cdba9 513 }
1dcdcd69
WF
514 if (res)
515 buf[res-1] = '\n'; /* eat the leftover space */
b76cdba9
MW
516 return res;
517}
518
43cb76d9
GKH
519static ssize_t bonding_store_arp_targets(struct device *d,
520 struct device_attribute *attr,
521 const char *buf, size_t count)
b76cdba9 522{
43cb76d9 523 struct bonding *bond = to_bond(d);
7f28fa10 524 __be32 target;
525 int ret = -EPERM;
4d1ae5fb 526
7f28fa10 527 if (!in4_pton(buf + 1, -1, (u8 *)&target, -1, NULL)) {
528 pr_err("%s: invalid ARP target %pI4 specified\n",
529 bond->dev->name, &target);
530 return -EPERM;
f9de11a1 531 }
8599b52e 532
7f28fa10 533 if (!rtnl_trylock())
534 return restart_syscall();
8599b52e 535
7f28fa10 536 if (buf[0] == '+')
537 ret = bond_option_arp_ip_target_add(bond, target);
538 else if (buf[0] == '-')
539 ret = bond_option_arp_ip_target_rem(bond, target);
540 else
a4aee5c8
JP
541 pr_err("no command found in arp_ip_targets file for bond %s. Use +<addr> or -<addr>.\n",
542 bond->dev->name);
b76cdba9 543
7f28fa10 544 if (!ret)
545 ret = count;
546
4d1ae5fb 547 rtnl_unlock();
b76cdba9
MW
548 return ret;
549}
43cb76d9 550static DEVICE_ATTR(arp_ip_target, S_IRUGO | S_IWUSR , bonding_show_arp_targets, bonding_store_arp_targets);
b76cdba9
MW
551
552/*
553 * Show and set the up and down delays. These must be multiples of the
554 * MII monitoring value, and are stored internally as the multiplier.
555 * Thus, we must translate to MS for the real world.
556 */
43cb76d9
GKH
557static ssize_t bonding_show_downdelay(struct device *d,
558 struct device_attribute *attr,
559 char *buf)
b76cdba9 560{
43cb76d9 561 struct bonding *bond = to_bond(d);
b76cdba9 562
7bd46508 563 return sprintf(buf, "%d\n", bond->params.downdelay * bond->params.miimon);
b76cdba9
MW
564}
565
43cb76d9
GKH
566static ssize_t bonding_store_downdelay(struct device *d,
567 struct device_attribute *attr,
568 const char *buf, size_t count)
b76cdba9 569{
c7461f9b 570 int new_value, ret;
43cb76d9 571 struct bonding *bond = to_bond(d);
b76cdba9 572
b76cdba9 573 if (sscanf(buf, "%d", &new_value) != 1) {
a4aee5c8 574 pr_err("%s: no down delay value specified.\n", bond->dev->name);
c7461f9b 575 return -EINVAL;
b76cdba9 576 }
b76cdba9 577
c7461f9b 578 if (!rtnl_trylock())
579 return restart_syscall();
580
581 ret = bond_option_downdelay_set(bond, new_value);
582 if (!ret)
583 ret = count;
b76cdba9 584
b869ccfa 585 rtnl_unlock();
b76cdba9
MW
586 return ret;
587}
3d632c3f
SH
588static DEVICE_ATTR(downdelay, S_IRUGO | S_IWUSR,
589 bonding_show_downdelay, bonding_store_downdelay);
b76cdba9 590
43cb76d9
GKH
591static ssize_t bonding_show_updelay(struct device *d,
592 struct device_attribute *attr,
593 char *buf)
b76cdba9 594{
43cb76d9 595 struct bonding *bond = to_bond(d);
b76cdba9 596
7bd46508 597 return sprintf(buf, "%d\n", bond->params.updelay * bond->params.miimon);
b76cdba9
MW
598
599}
600
43cb76d9
GKH
601static ssize_t bonding_store_updelay(struct device *d,
602 struct device_attribute *attr,
603 const char *buf, size_t count)
b76cdba9 604{
25852e29 605 int new_value, ret;
43cb76d9 606 struct bonding *bond = to_bond(d);
b76cdba9 607
b76cdba9 608 if (sscanf(buf, "%d", &new_value) != 1) {
a4aee5c8 609 pr_err("%s: no up delay value specified.\n",
25852e29 610 bond->dev->name);
611 return -EINVAL;
b76cdba9
MW
612 }
613
25852e29 614 if (!rtnl_trylock())
615 return restart_syscall();
616
617 ret = bond_option_updelay_set(bond, new_value);
618 if (!ret)
619 ret = count;
620
b869ccfa 621 rtnl_unlock();
b76cdba9
MW
622 return ret;
623}
3d632c3f
SH
624static DEVICE_ATTR(updelay, S_IRUGO | S_IWUSR,
625 bonding_show_updelay, bonding_store_updelay);
b76cdba9
MW
626
627/*
628 * Show and set the LACP interval. Interface must be down, and the mode
629 * must be set to 802.3ad mode.
630 */
43cb76d9
GKH
631static ssize_t bonding_show_lacp(struct device *d,
632 struct device_attribute *attr,
633 char *buf)
b76cdba9 634{
43cb76d9 635 struct bonding *bond = to_bond(d);
b76cdba9
MW
636
637 return sprintf(buf, "%s %d\n",
638 bond_lacp_tbl[bond->params.lacp_fast].modename,
7bd46508 639 bond->params.lacp_fast);
b76cdba9
MW
640}
641
43cb76d9
GKH
642static ssize_t bonding_store_lacp(struct device *d,
643 struct device_attribute *attr,
644 const char *buf, size_t count)
b76cdba9 645{
43cb76d9 646 struct bonding *bond = to_bond(d);
998e40bb 647 int new_value, ret;
b76cdba9 648
ece95f7f 649 new_value = bond_parse_parm(buf, bond_lacp_tbl);
998e40bb 650 if (new_value < 0) {
a4aee5c8 651 pr_err("%s: Ignoring invalid LACP rate value %.*s.\n",
3d632c3f 652 bond->dev->name, (int)strlen(buf) - 1, buf);
998e40bb 653 return -EINVAL;
b76cdba9 654 }
c509316b 655
998e40bb 656 if (!rtnl_trylock())
657 return restart_syscall();
658
659 ret = bond_option_lacp_rate_set(bond, new_value);
660 if (!ret)
661 ret = count;
662
663 rtnl_unlock();
b76cdba9
MW
664 return ret;
665}
3d632c3f
SH
666static DEVICE_ATTR(lacp_rate, S_IRUGO | S_IWUSR,
667 bonding_show_lacp, bonding_store_lacp);
b76cdba9 668
655f8919 669static ssize_t bonding_show_min_links(struct device *d,
670 struct device_attribute *attr,
671 char *buf)
672{
673 struct bonding *bond = to_bond(d);
674
675 return sprintf(buf, "%d\n", bond->params.min_links);
676}
677
678static ssize_t bonding_store_min_links(struct device *d,
679 struct device_attribute *attr,
680 const char *buf, size_t count)
681{
682 struct bonding *bond = to_bond(d);
683 int ret;
684 unsigned int new_value;
685
686 ret = kstrtouint(buf, 0, &new_value);
687 if (ret < 0) {
688 pr_err("%s: Ignoring invalid min links value %s.\n",
689 bond->dev->name, buf);
690 return ret;
691 }
692
7d101008 693 if (!rtnl_trylock())
694 return restart_syscall();
695
696 ret = bond_option_min_links_set(bond, new_value);
697 if (!ret)
698 ret = count;
699
700 rtnl_unlock();
701 return ret;
655f8919 702}
703static DEVICE_ATTR(min_links, S_IRUGO | S_IWUSR,
704 bonding_show_min_links, bonding_store_min_links);
705
fd989c83
JV
706static ssize_t bonding_show_ad_select(struct device *d,
707 struct device_attribute *attr,
708 char *buf)
709{
710 struct bonding *bond = to_bond(d);
711
712 return sprintf(buf, "%s %d\n",
713 ad_select_tbl[bond->params.ad_select].modename,
714 bond->params.ad_select);
715}
716
717
718static ssize_t bonding_store_ad_select(struct device *d,
719 struct device_attribute *attr,
720 const char *buf, size_t count)
721{
ec029fac 722 int new_value, ret;
fd989c83
JV
723 struct bonding *bond = to_bond(d);
724
fd989c83 725 new_value = bond_parse_parm(buf, ad_select_tbl);
ec029fac 726 if (new_value < 0) {
a4aee5c8 727 pr_err("%s: Ignoring invalid ad_select value %.*s.\n",
fd989c83 728 bond->dev->name, (int)strlen(buf) - 1, buf);
ec029fac 729 return -EINVAL;
fd989c83 730 }
ec029fac 731
732 if (!rtnl_trylock())
733 return restart_syscall();
734
735 ret = bond_option_ad_select_set(bond, new_value);
736 if (!ret)
737 ret = count;
738
739 rtnl_unlock();
fd989c83
JV
740 return ret;
741}
3d632c3f
SH
742static DEVICE_ATTR(ad_select, S_IRUGO | S_IWUSR,
743 bonding_show_ad_select, bonding_store_ad_select);
fd989c83 744
ad246c99
BH
745/*
746 * Show and set the number of peer notifications to send after a failover event.
747 */
748static ssize_t bonding_show_num_peer_notif(struct device *d,
749 struct device_attribute *attr,
750 char *buf)
751{
752 struct bonding *bond = to_bond(d);
753 return sprintf(buf, "%d\n", bond->params.num_peer_notif);
754}
755
756static ssize_t bonding_store_num_peer_notif(struct device *d,
757 struct device_attribute *attr,
758 const char *buf, size_t count)
759{
760 struct bonding *bond = to_bond(d);
2c9839c1 761 u8 new_value;
762 int ret;
763
764 ret = kstrtou8(buf, 10, &new_value);
0b23810d 765 if (ret) {
2c9839c1 766 pr_err("%s: invalid value %s specified.\n",
767 bond->dev->name, buf);
768 return ret;
769 }
770
771 if (!rtnl_trylock())
772 return restart_syscall();
773
774 ret = bond_option_num_peer_notif_set(bond, new_value);
775 if (!ret)
776 ret = count;
777
778 rtnl_unlock();
779 return ret;
ad246c99
BH
780}
781static DEVICE_ATTR(num_grat_arp, S_IRUGO | S_IWUSR,
782 bonding_show_num_peer_notif, bonding_store_num_peer_notif);
783static DEVICE_ATTR(num_unsol_na, S_IRUGO | S_IWUSR,
784 bonding_show_num_peer_notif, bonding_store_num_peer_notif);
785
b76cdba9
MW
786/*
787 * Show and set the MII monitor interval. There are two tricky bits
788 * here. First, if MII monitoring is activated, then we must disable
789 * ARP monitoring. Second, if the timer isn't running, we must
790 * start it.
791 */
43cb76d9
GKH
792static ssize_t bonding_show_miimon(struct device *d,
793 struct device_attribute *attr,
794 char *buf)
b76cdba9 795{
43cb76d9 796 struct bonding *bond = to_bond(d);
b76cdba9 797
7bd46508 798 return sprintf(buf, "%d\n", bond->params.miimon);
b76cdba9
MW
799}
800
43cb76d9
GKH
801static ssize_t bonding_store_miimon(struct device *d,
802 struct device_attribute *attr,
803 const char *buf, size_t count)
b76cdba9 804{
eecdaa6e 805 int new_value, ret;
43cb76d9 806 struct bonding *bond = to_bond(d);
b76cdba9
MW
807
808 if (sscanf(buf, "%d", &new_value) != 1) {
a4aee5c8 809 pr_err("%s: no miimon value specified.\n",
b76cdba9 810 bond->dev->name);
eecdaa6e 811 return -EINVAL;
b76cdba9 812 }
eecdaa6e 813
814 if (!rtnl_trylock())
815 return restart_syscall();
816
817 ret = bond_option_miimon_set(bond, new_value);
818 if (!ret)
819 ret = count;
820
fbb0c41b 821 rtnl_unlock();
b76cdba9
MW
822 return ret;
823}
3d632c3f
SH
824static DEVICE_ATTR(miimon, S_IRUGO | S_IWUSR,
825 bonding_show_miimon, bonding_store_miimon);
b76cdba9
MW
826
827/*
828 * Show and set the primary slave. The store function is much
829 * simpler than bonding_store_slaves function because it only needs to
830 * handle one interface name.
831 * The bond must be a mode that supports a primary for this be
832 * set.
833 */
43cb76d9
GKH
834static ssize_t bonding_show_primary(struct device *d,
835 struct device_attribute *attr,
836 char *buf)
b76cdba9
MW
837{
838 int count = 0;
43cb76d9 839 struct bonding *bond = to_bond(d);
b76cdba9
MW
840
841 if (bond->primary_slave)
7bd46508 842 count = sprintf(buf, "%s\n", bond->primary_slave->dev->name);
b76cdba9
MW
843
844 return count;
845}
846
43cb76d9
GKH
847static ssize_t bonding_store_primary(struct device *d,
848 struct device_attribute *attr,
849 const char *buf, size_t count)
b76cdba9 850{
43cb76d9 851 struct bonding *bond = to_bond(d);
f4bb2e9c 852 char ifname[IFNAMSIZ];
0a98a0d1 853 int ret;
b76cdba9 854
eb6e98a1 855 sscanf(buf, "%15s", ifname); /* IFNAMSIZ */
0a98a0d1 856 if (ifname[0] == '\n')
857 ifname[0] = '\0';
b76cdba9 858
0a98a0d1 859 if (!rtnl_trylock())
860 return restart_syscall();
f4bb2e9c 861
0a98a0d1 862 ret = bond_option_primary_set(bond, ifname);
863 if (!ret)
864 ret = count;
8a93664d 865
6603a6f2 866 rtnl_unlock();
0a98a0d1 867 return ret;
b76cdba9 868}
3d632c3f
SH
869static DEVICE_ATTR(primary, S_IRUGO | S_IWUSR,
870 bonding_show_primary, bonding_store_primary);
b76cdba9 871
a549952a
JP
872/*
873 * Show and set the primary_reselect flag.
874 */
875static ssize_t bonding_show_primary_reselect(struct device *d,
876 struct device_attribute *attr,
877 char *buf)
878{
879 struct bonding *bond = to_bond(d);
880
881 return sprintf(buf, "%s %d\n",
882 pri_reselect_tbl[bond->params.primary_reselect].modename,
883 bond->params.primary_reselect);
884}
885
886static ssize_t bonding_store_primary_reselect(struct device *d,
887 struct device_attribute *attr,
888 const char *buf, size_t count)
889{
8a41ae44 890 int new_value, ret;
a549952a
JP
891 struct bonding *bond = to_bond(d);
892
a549952a
JP
893 new_value = bond_parse_parm(buf, pri_reselect_tbl);
894 if (new_value < 0) {
a4aee5c8 895 pr_err("%s: Ignoring invalid primary_reselect value %.*s.\n",
a549952a
JP
896 bond->dev->name,
897 (int) strlen(buf) - 1, buf);
8a41ae44 898 return -EINVAL;
a549952a
JP
899 }
900
8a41ae44 901 if (!rtnl_trylock())
902 return restart_syscall();
903
904 ret = bond_option_primary_reselect_set(bond, new_value);
905 if (!ret)
906 ret = count;
a549952a 907
a549952a
JP
908 rtnl_unlock();
909 return ret;
910}
911static DEVICE_ATTR(primary_reselect, S_IRUGO | S_IWUSR,
912 bonding_show_primary_reselect,
913 bonding_store_primary_reselect);
914
b76cdba9
MW
915/*
916 * Show and set the use_carrier flag.
917 */
43cb76d9
GKH
918static ssize_t bonding_show_carrier(struct device *d,
919 struct device_attribute *attr,
920 char *buf)
b76cdba9 921{
43cb76d9 922 struct bonding *bond = to_bond(d);
b76cdba9 923
7bd46508 924 return sprintf(buf, "%d\n", bond->params.use_carrier);
b76cdba9
MW
925}
926
43cb76d9
GKH
927static ssize_t bonding_store_carrier(struct device *d,
928 struct device_attribute *attr,
929 const char *buf, size_t count)
b76cdba9 930{
9f53e14e 931 int new_value, ret;
43cb76d9 932 struct bonding *bond = to_bond(d);
b76cdba9 933
b76cdba9 934 if (sscanf(buf, "%d", &new_value) != 1) {
a4aee5c8 935 pr_err("%s: no use_carrier value specified.\n",
b76cdba9 936 bond->dev->name);
9f53e14e 937 return -EINVAL;
b76cdba9 938 }
9f53e14e 939
940 if (!rtnl_trylock())
941 return restart_syscall();
942
943 ret = bond_option_use_carrier_set(bond, new_value);
944 if (!ret)
945 ret = count;
946
947 rtnl_unlock();
672bda33 948 return ret;
b76cdba9 949}
3d632c3f
SH
950static DEVICE_ATTR(use_carrier, S_IRUGO | S_IWUSR,
951 bonding_show_carrier, bonding_store_carrier);
b76cdba9
MW
952
953
954/*
955 * Show and set currently active_slave.
956 */
43cb76d9
GKH
957static ssize_t bonding_show_active_slave(struct device *d,
958 struct device_attribute *attr,
959 char *buf)
b76cdba9 960{
43cb76d9 961 struct bonding *bond = to_bond(d);
752d48b5 962 struct net_device *slave_dev;
16cd0160 963 int count = 0;
b76cdba9 964
278b2083 965 rcu_read_lock();
752d48b5
JP
966 slave_dev = bond_option_active_slave_get_rcu(bond);
967 if (slave_dev)
968 count = sprintf(buf, "%s\n", slave_dev->name);
278b2083 969 rcu_read_unlock();
970
b76cdba9
MW
971 return count;
972}
973
43cb76d9
GKH
974static ssize_t bonding_store_active_slave(struct device *d,
975 struct device_attribute *attr,
976 const char *buf, size_t count)
b76cdba9 977{
d9e32b21 978 int ret;
43cb76d9 979 struct bonding *bond = to_bond(d);
f4bb2e9c 980 char ifname[IFNAMSIZ];
d9e32b21 981 struct net_device *dev;
b76cdba9 982
496a60cd
EB
983 if (!rtnl_trylock())
984 return restart_syscall();
e843fa50 985
c84e1590 986 sscanf(buf, "%15s", ifname); /* IFNAMSIZ */
f4bb2e9c 987 if (!strlen(ifname) || buf[0] == '\n') {
d9e32b21
JP
988 dev = NULL;
989 } else {
990 dev = __dev_get_by_name(dev_net(bond->dev), ifname);
991 if (!dev) {
992 ret = -ENODEV;
993 goto out;
b76cdba9 994 }
b76cdba9 995 }
f4bb2e9c 996
d9e32b21
JP
997 ret = bond_option_active_slave_set(bond, dev);
998 if (!ret)
999 ret = count;
e843fa50 1000
d9e32b21 1001 out:
6603a6f2
JV
1002 rtnl_unlock();
1003
d9e32b21 1004 return ret;
b76cdba9
MW
1005
1006}
3d632c3f
SH
1007static DEVICE_ATTR(active_slave, S_IRUGO | S_IWUSR,
1008 bonding_show_active_slave, bonding_store_active_slave);
b76cdba9
MW
1009
1010
1011/*
1012 * Show link status of the bond interface.
1013 */
43cb76d9
GKH
1014static ssize_t bonding_show_mii_status(struct device *d,
1015 struct device_attribute *attr,
1016 char *buf)
b76cdba9 1017{
43cb76d9 1018 struct bonding *bond = to_bond(d);
b76cdba9 1019
278b2083 1020 return sprintf(buf, "%s\n", bond->curr_active_slave ? "up" : "down");
b76cdba9 1021}
43cb76d9 1022static DEVICE_ATTR(mii_status, S_IRUGO, bonding_show_mii_status, NULL);
b76cdba9 1023
b76cdba9
MW
1024/*
1025 * Show current 802.3ad aggregator ID.
1026 */
43cb76d9
GKH
1027static ssize_t bonding_show_ad_aggregator(struct device *d,
1028 struct device_attribute *attr,
1029 char *buf)
b76cdba9
MW
1030{
1031 int count = 0;
43cb76d9 1032 struct bonding *bond = to_bond(d);
b76cdba9
MW
1033
1034 if (bond->params.mode == BOND_MODE_8023AD) {
1035 struct ad_info ad_info;
3d632c3f 1036 count = sprintf(buf, "%d\n",
318debd8 1037 bond_3ad_get_active_agg_info(bond, &ad_info)
3d632c3f 1038 ? 0 : ad_info.aggregator_id);
b76cdba9 1039 }
b76cdba9
MW
1040
1041 return count;
1042}
43cb76d9 1043static DEVICE_ATTR(ad_aggregator, S_IRUGO, bonding_show_ad_aggregator, NULL);
b76cdba9
MW
1044
1045
1046/*
1047 * Show number of active 802.3ad ports.
1048 */
43cb76d9
GKH
1049static ssize_t bonding_show_ad_num_ports(struct device *d,
1050 struct device_attribute *attr,
1051 char *buf)
b76cdba9
MW
1052{
1053 int count = 0;
43cb76d9 1054 struct bonding *bond = to_bond(d);
b76cdba9
MW
1055
1056 if (bond->params.mode == BOND_MODE_8023AD) {
1057 struct ad_info ad_info;
3d632c3f 1058 count = sprintf(buf, "%d\n",
318debd8 1059 bond_3ad_get_active_agg_info(bond, &ad_info)
3d632c3f 1060 ? 0 : ad_info.ports);
b76cdba9 1061 }
b76cdba9
MW
1062
1063 return count;
1064}
43cb76d9 1065static DEVICE_ATTR(ad_num_ports, S_IRUGO, bonding_show_ad_num_ports, NULL);
b76cdba9
MW
1066
1067
1068/*
1069 * Show current 802.3ad actor key.
1070 */
43cb76d9
GKH
1071static ssize_t bonding_show_ad_actor_key(struct device *d,
1072 struct device_attribute *attr,
1073 char *buf)
b76cdba9
MW
1074{
1075 int count = 0;
43cb76d9 1076 struct bonding *bond = to_bond(d);
b76cdba9
MW
1077
1078 if (bond->params.mode == BOND_MODE_8023AD) {
1079 struct ad_info ad_info;
3d632c3f 1080 count = sprintf(buf, "%d\n",
318debd8 1081 bond_3ad_get_active_agg_info(bond, &ad_info)
3d632c3f 1082 ? 0 : ad_info.actor_key);
b76cdba9 1083 }
b76cdba9
MW
1084
1085 return count;
1086}
43cb76d9 1087static DEVICE_ATTR(ad_actor_key, S_IRUGO, bonding_show_ad_actor_key, NULL);
b76cdba9
MW
1088
1089
1090/*
1091 * Show current 802.3ad partner key.
1092 */
43cb76d9
GKH
1093static ssize_t bonding_show_ad_partner_key(struct device *d,
1094 struct device_attribute *attr,
1095 char *buf)
b76cdba9
MW
1096{
1097 int count = 0;
43cb76d9 1098 struct bonding *bond = to_bond(d);
b76cdba9
MW
1099
1100 if (bond->params.mode == BOND_MODE_8023AD) {
1101 struct ad_info ad_info;
3d632c3f 1102 count = sprintf(buf, "%d\n",
318debd8 1103 bond_3ad_get_active_agg_info(bond, &ad_info)
3d632c3f 1104 ? 0 : ad_info.partner_key);
b76cdba9 1105 }
b76cdba9
MW
1106
1107 return count;
1108}
43cb76d9 1109static DEVICE_ATTR(ad_partner_key, S_IRUGO, bonding_show_ad_partner_key, NULL);
b76cdba9
MW
1110
1111
1112/*
1113 * Show current 802.3ad partner mac.
1114 */
43cb76d9
GKH
1115static ssize_t bonding_show_ad_partner_mac(struct device *d,
1116 struct device_attribute *attr,
1117 char *buf)
b76cdba9
MW
1118{
1119 int count = 0;
43cb76d9 1120 struct bonding *bond = to_bond(d);
b76cdba9
MW
1121
1122 if (bond->params.mode == BOND_MODE_8023AD) {
1123 struct ad_info ad_info;
3d632c3f 1124 if (!bond_3ad_get_active_agg_info(bond, &ad_info))
e174961c 1125 count = sprintf(buf, "%pM\n", ad_info.partner_system);
b76cdba9 1126 }
b76cdba9
MW
1127
1128 return count;
1129}
43cb76d9 1130static DEVICE_ATTR(ad_partner_mac, S_IRUGO, bonding_show_ad_partner_mac, NULL);
b76cdba9 1131
bb1d9123
AG
1132/*
1133 * Show the queue_ids of the slaves in the current bond.
1134 */
1135static ssize_t bonding_show_queue_id(struct device *d,
1136 struct device_attribute *attr,
1137 char *buf)
1138{
bb1d9123 1139 struct bonding *bond = to_bond(d);
9caff1e7 1140 struct list_head *iter;
dec1e90e 1141 struct slave *slave;
1142 int res = 0;
bb1d9123
AG
1143
1144 if (!rtnl_trylock())
1145 return restart_syscall();
1146
9caff1e7 1147 bond_for_each_slave(bond, slave, iter) {
79236680
NP
1148 if (res > (PAGE_SIZE - IFNAMSIZ - 6)) {
1149 /* not enough space for another interface_name:queue_id pair */
bb1d9123
AG
1150 if ((PAGE_SIZE - res) > 10)
1151 res = PAGE_SIZE - 10;
1152 res += sprintf(buf + res, "++more++ ");
1153 break;
1154 }
1155 res += sprintf(buf + res, "%s:%d ",
1156 slave->dev->name, slave->queue_id);
1157 }
bb1d9123
AG
1158 if (res)
1159 buf[res-1] = '\n'; /* eat the leftover space */
4d1ae5fb 1160
bb1d9123 1161 rtnl_unlock();
dec1e90e 1162
bb1d9123
AG
1163 return res;
1164}
1165
1166/*
1167 * Set the queue_ids of the slaves in the current bond. The bond
1168 * interface must be enslaved for this to work.
1169 */
1170static ssize_t bonding_store_queue_id(struct device *d,
1171 struct device_attribute *attr,
1172 const char *buffer, size_t count)
1173{
1174 struct slave *slave, *update_slave;
1175 struct bonding *bond = to_bond(d);
9caff1e7 1176 struct list_head *iter;
bb1d9123 1177 u16 qid;
dec1e90e 1178 int ret = count;
bb1d9123
AG
1179 char *delim;
1180 struct net_device *sdev = NULL;
1181
1182 if (!rtnl_trylock())
1183 return restart_syscall();
1184
1185 /* delim will point to queue id if successful */
1186 delim = strchr(buffer, ':');
1187 if (!delim)
1188 goto err_no_cmd;
1189
1190 /*
1191 * Terminate string that points to device name and bump it
1192 * up one, so we can read the queue id there.
1193 */
1194 *delim = '\0';
1195 if (sscanf(++delim, "%hd\n", &qid) != 1)
1196 goto err_no_cmd;
1197
1198 /* Check buffer length, valid ifname and queue id */
1199 if (strlen(buffer) > IFNAMSIZ ||
1200 !dev_valid_name(buffer) ||
8a540ff9 1201 qid > bond->dev->real_num_tx_queues)
bb1d9123
AG
1202 goto err_no_cmd;
1203
1204 /* Get the pointer to that interface if it exists */
1205 sdev = __dev_get_by_name(dev_net(bond->dev), buffer);
1206 if (!sdev)
1207 goto err_no_cmd;
1208
bb1d9123
AG
1209 /* Search for thes slave and check for duplicate qids */
1210 update_slave = NULL;
9caff1e7 1211 bond_for_each_slave(bond, slave, iter) {
bb1d9123
AG
1212 if (sdev == slave->dev)
1213 /*
1214 * We don't need to check the matching
1215 * slave for dups, since we're overwriting it
1216 */
1217 update_slave = slave;
1218 else if (qid && qid == slave->queue_id) {
4d1ae5fb 1219 goto err_no_cmd;
bb1d9123
AG
1220 }
1221 }
1222
1223 if (!update_slave)
4d1ae5fb 1224 goto err_no_cmd;
bb1d9123
AG
1225
1226 /* Actually set the qids for the slave */
1227 update_slave->queue_id = qid;
1228
bb1d9123
AG
1229out:
1230 rtnl_unlock();
1231 return ret;
1232
bb1d9123
AG
1233err_no_cmd:
1234 pr_info("invalid input for queue_id set for %s.\n",
1235 bond->dev->name);
1236 ret = -EPERM;
1237 goto out;
1238}
1239
1240static DEVICE_ATTR(queue_id, S_IRUGO | S_IWUSR, bonding_show_queue_id,
1241 bonding_store_queue_id);
1242
1243
ebd8e497
AG
1244/*
1245 * Show and set the all_slaves_active flag.
1246 */
1247static ssize_t bonding_show_slaves_active(struct device *d,
1248 struct device_attribute *attr,
1249 char *buf)
1250{
1251 struct bonding *bond = to_bond(d);
1252
1253 return sprintf(buf, "%d\n", bond->params.all_slaves_active);
1254}
1255
1256static ssize_t bonding_store_slaves_active(struct device *d,
1257 struct device_attribute *attr,
1258 const char *buf, size_t count)
1259{
ebd8e497 1260 struct bonding *bond = to_bond(d);
1cc0b1e3 1261 int new_value, ret;
4d1ae5fb 1262
ebd8e497
AG
1263 if (sscanf(buf, "%d", &new_value) != 1) {
1264 pr_err("%s: no all_slaves_active value specified.\n",
1265 bond->dev->name);
1cc0b1e3 1266 return -EINVAL;
ebd8e497
AG
1267 }
1268
1cc0b1e3 1269 if (!rtnl_trylock())
1270 return restart_syscall();
ebd8e497 1271
1cc0b1e3 1272 ret = bond_option_all_slaves_active_set(bond, new_value);
1273 if (!ret)
1274 ret = count;
b76cdba9 1275
4d1ae5fb 1276 rtnl_unlock();
672bda33 1277 return ret;
ebd8e497
AG
1278}
1279static DEVICE_ATTR(all_slaves_active, S_IRUGO | S_IWUSR,
1280 bonding_show_slaves_active, bonding_store_slaves_active);
b76cdba9 1281
c2952c31
FL
1282/*
1283 * Show and set the number of IGMP membership reports to send on link failure
1284 */
1285static ssize_t bonding_show_resend_igmp(struct device *d,
94265cf5
FL
1286 struct device_attribute *attr,
1287 char *buf)
c2952c31
FL
1288{
1289 struct bonding *bond = to_bond(d);
1290
1291 return sprintf(buf, "%d\n", bond->params.resend_igmp);
1292}
1293
1294static ssize_t bonding_store_resend_igmp(struct device *d,
94265cf5
FL
1295 struct device_attribute *attr,
1296 const char *buf, size_t count)
c2952c31
FL
1297{
1298 int new_value, ret = count;
1299 struct bonding *bond = to_bond(d);
1300
1301 if (sscanf(buf, "%d", &new_value) != 1) {
1302 pr_err("%s: no resend_igmp value specified.\n",
1303 bond->dev->name);
d8838de7 1304 return -EINVAL;
c2952c31
FL
1305 }
1306
d8838de7 1307 if (!rtnl_trylock())
1308 return restart_syscall();
c2952c31 1309
d8838de7 1310 ret = bond_option_resend_igmp_set(bond, new_value);
1311 if (!ret)
1312 ret = count;
1313
1314 rtnl_unlock();
c2952c31
FL
1315 return ret;
1316}
1317
1318static DEVICE_ATTR(resend_igmp, S_IRUGO | S_IWUSR,
1319 bonding_show_resend_igmp, bonding_store_resend_igmp);
1320
7eacd038
NH
1321
1322static ssize_t bonding_show_lp_interval(struct device *d,
1323 struct device_attribute *attr,
1324 char *buf)
1325{
1326 struct bonding *bond = to_bond(d);
1327 return sprintf(buf, "%d\n", bond->params.lp_interval);
1328}
1329
1330static ssize_t bonding_store_lp_interval(struct device *d,
1331 struct device_attribute *attr,
1332 const char *buf, size_t count)
1333{
1334 struct bonding *bond = to_bond(d);
8d836d09 1335 int new_value, ret;
7eacd038
NH
1336
1337 if (sscanf(buf, "%d", &new_value) != 1) {
1338 pr_err("%s: no lp interval value specified.\n",
1339 bond->dev->name);
8d836d09 1340 return -EINVAL;
7eacd038
NH
1341 }
1342
8d836d09 1343 if (!rtnl_trylock())
1344 return restart_syscall();
7eacd038 1345
8d836d09 1346 ret = bond_option_lp_interval_set(bond, new_value);
1347 if (!ret)
1348 ret = count;
1349
1350 rtnl_unlock();
7eacd038
NH
1351 return ret;
1352}
1353
1354static DEVICE_ATTR(lp_interval, S_IRUGO | S_IWUSR,
1355 bonding_show_lp_interval, bonding_store_lp_interval);
1356
73958329
NA
1357static ssize_t bonding_show_packets_per_slave(struct device *d,
1358 struct device_attribute *attr,
1359 char *buf)
1360{
1361 struct bonding *bond = to_bond(d);
a752a8b9 1362 unsigned int packets_per_slave = bond->params.packets_per_slave;
a752a8b9 1363 return sprintf(buf, "%u\n", packets_per_slave);
73958329
NA
1364}
1365
1366static ssize_t bonding_store_packets_per_slave(struct device *d,
1367 struct device_attribute *attr,
1368 const char *buf, size_t count)
1369{
1370 struct bonding *bond = to_bond(d);
aa59d851 1371 int ret;
c13ab3ff 1372
aa59d851
NA
1373 ret = bond_opt_tryset_rtnl(bond, BOND_OPT_PACKETS_PER_SLAVE,
1374 (char *)buf);
c13ab3ff 1375 if (!ret)
1376 ret = count;
1377
73958329
NA
1378 return ret;
1379}
1380
1381static DEVICE_ATTR(packets_per_slave, S_IRUGO | S_IWUSR,
1382 bonding_show_packets_per_slave,
1383 bonding_store_packets_per_slave);
1384
b76cdba9 1385static struct attribute *per_bond_attrs[] = {
43cb76d9
GKH
1386 &dev_attr_slaves.attr,
1387 &dev_attr_mode.attr,
dd957c57 1388 &dev_attr_fail_over_mac.attr,
43cb76d9 1389 &dev_attr_arp_validate.attr,
8599b52e 1390 &dev_attr_arp_all_targets.attr,
43cb76d9
GKH
1391 &dev_attr_arp_interval.attr,
1392 &dev_attr_arp_ip_target.attr,
1393 &dev_attr_downdelay.attr,
1394 &dev_attr_updelay.attr,
1395 &dev_attr_lacp_rate.attr,
fd989c83 1396 &dev_attr_ad_select.attr,
43cb76d9 1397 &dev_attr_xmit_hash_policy.attr,
ad246c99
BH
1398 &dev_attr_num_grat_arp.attr,
1399 &dev_attr_num_unsol_na.attr,
43cb76d9
GKH
1400 &dev_attr_miimon.attr,
1401 &dev_attr_primary.attr,
a549952a 1402 &dev_attr_primary_reselect.attr,
43cb76d9
GKH
1403 &dev_attr_use_carrier.attr,
1404 &dev_attr_active_slave.attr,
1405 &dev_attr_mii_status.attr,
1406 &dev_attr_ad_aggregator.attr,
1407 &dev_attr_ad_num_ports.attr,
1408 &dev_attr_ad_actor_key.attr,
1409 &dev_attr_ad_partner_key.attr,
1410 &dev_attr_ad_partner_mac.attr,
bb1d9123 1411 &dev_attr_queue_id.attr,
ebd8e497 1412 &dev_attr_all_slaves_active.attr,
c2952c31 1413 &dev_attr_resend_igmp.attr,
655f8919 1414 &dev_attr_min_links.attr,
7eacd038 1415 &dev_attr_lp_interval.attr,
73958329 1416 &dev_attr_packets_per_slave.attr,
b76cdba9
MW
1417 NULL,
1418};
1419
1420static struct attribute_group bonding_group = {
1421 .name = "bonding",
1422 .attrs = per_bond_attrs,
1423};
1424
1425/*
1426 * Initialize sysfs. This sets up the bonding_masters file in
1427 * /sys/class/net.
1428 */
4c22400a 1429int bond_create_sysfs(struct bond_net *bn)
b76cdba9 1430{
b8a9787e 1431 int ret;
b76cdba9 1432
4c22400a 1433 bn->class_attr_bonding_masters = class_attr_bonding_masters;
01718e36 1434 sysfs_attr_init(&bn->class_attr_bonding_masters.attr);
4c22400a 1435
58292cbe
TH
1436 ret = netdev_class_create_file_ns(&bn->class_attr_bonding_masters,
1437 bn->net);
877cbd36
JV
1438 /*
1439 * Permit multiple loads of the module by ignoring failures to
1440 * create the bonding_masters sysfs file. Bonding devices
1441 * created by second or subsequent loads of the module will
1442 * not be listed in, or controllable by, bonding_masters, but
1443 * will have the usual "bonding" sysfs directory.
1444 *
1445 * This is done to preserve backwards compatibility for
1446 * initscripts/sysconfig, which load bonding multiple times to
1447 * configure multiple bonding devices.
1448 */
1449 if (ret == -EEXIST) {
38d2f38b 1450 /* Is someone being kinky and naming a device bonding_master? */
4c22400a 1451 if (__dev_get_by_name(bn->net,
38d2f38b 1452 class_attr_bonding_masters.attr.name))
a4aee5c8 1453 pr_err("network device named %s already exists in sysfs",
38d2f38b 1454 class_attr_bonding_masters.attr.name);
130aa61a 1455 ret = 0;
877cbd36 1456 }
b76cdba9
MW
1457
1458 return ret;
1459
1460}
1461
1462/*
1463 * Remove /sys/class/net/bonding_masters.
1464 */
4c22400a 1465void bond_destroy_sysfs(struct bond_net *bn)
b76cdba9 1466{
58292cbe 1467 netdev_class_remove_file_ns(&bn->class_attr_bonding_masters, bn->net);
b76cdba9
MW
1468}
1469
1470/*
1471 * Initialize sysfs for each bond. This sets up and registers
1472 * the 'bondctl' directory for each individual bond under /sys/class/net.
1473 */
6151b3d4 1474void bond_prepare_sysfs_group(struct bonding *bond)
b76cdba9 1475{
6151b3d4 1476 bond->dev->sysfs_groups[0] = &bonding_group;
b76cdba9
MW
1477}
1478