bonding: convert miimon to use the new option API
[deliverable/linux.git] / drivers / net / bonding / bond_sysfs.c
CommitLineData
b76cdba9
MW
1/*
2 * Copyright(c) 2004-2005 Intel Corporation. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
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{
43cb76d9 530 struct bonding *bond = to_bond(d);
e4994612 531 int ret;
b76cdba9 532
e4994612 533 ret = bond_opt_tryset_rtnl(bond, BOND_OPT_UPDELAY, (char *)buf);
25852e29 534 if (!ret)
535 ret = count;
536
b76cdba9
MW
537 return ret;
538}
3d632c3f
SH
539static DEVICE_ATTR(updelay, S_IRUGO | S_IWUSR,
540 bonding_show_updelay, bonding_store_updelay);
b76cdba9
MW
541
542/*
543 * Show and set the LACP interval. Interface must be down, and the mode
544 * must be set to 802.3ad mode.
545 */
43cb76d9
GKH
546static ssize_t bonding_show_lacp(struct device *d,
547 struct device_attribute *attr,
548 char *buf)
b76cdba9 549{
43cb76d9 550 struct bonding *bond = to_bond(d);
d3131de7 551 struct bond_opt_value *val;
b76cdba9 552
d3131de7
NA
553 val = bond_opt_get_val(BOND_OPT_LACP_RATE, bond->params.lacp_fast);
554
555 return sprintf(buf, "%s %d\n", val->string, bond->params.lacp_fast);
b76cdba9
MW
556}
557
43cb76d9
GKH
558static ssize_t bonding_store_lacp(struct device *d,
559 struct device_attribute *attr,
560 const char *buf, size_t count)
b76cdba9 561{
43cb76d9 562 struct bonding *bond = to_bond(d);
d3131de7 563 int ret;
998e40bb 564
d3131de7 565 ret = bond_opt_tryset_rtnl(bond, BOND_OPT_LACP_RATE, (char *)buf);
998e40bb 566 if (!ret)
567 ret = count;
568
b76cdba9
MW
569 return ret;
570}
3d632c3f
SH
571static DEVICE_ATTR(lacp_rate, S_IRUGO | S_IWUSR,
572 bonding_show_lacp, bonding_store_lacp);
b76cdba9 573
655f8919 574static ssize_t bonding_show_min_links(struct device *d,
575 struct device_attribute *attr,
576 char *buf)
577{
578 struct bonding *bond = to_bond(d);
579
580 return sprintf(buf, "%d\n", bond->params.min_links);
581}
582
583static ssize_t bonding_store_min_links(struct device *d,
584 struct device_attribute *attr,
585 const char *buf, size_t count)
586{
587 struct bonding *bond = to_bond(d);
588 int ret;
655f8919 589
633ddc9e 590 ret = bond_opt_tryset_rtnl(bond, BOND_OPT_MINLINKS, (char *)buf);
7d101008 591 if (!ret)
592 ret = count;
593
7d101008 594 return ret;
655f8919 595}
596static DEVICE_ATTR(min_links, S_IRUGO | S_IWUSR,
597 bonding_show_min_links, bonding_store_min_links);
598
fd989c83
JV
599static ssize_t bonding_show_ad_select(struct device *d,
600 struct device_attribute *attr,
601 char *buf)
602{
603 struct bonding *bond = to_bond(d);
9e5f5eeb 604 struct bond_opt_value *val;
fd989c83 605
9e5f5eeb
NA
606 val = bond_opt_get_val(BOND_OPT_AD_SELECT, bond->params.ad_select);
607
608 return sprintf(buf, "%s %d\n", val->string, bond->params.ad_select);
fd989c83
JV
609}
610
611
612static ssize_t bonding_store_ad_select(struct device *d,
613 struct device_attribute *attr,
614 const char *buf, size_t count)
615{
fd989c83 616 struct bonding *bond = to_bond(d);
9e5f5eeb 617 int ret;
fd989c83 618
9e5f5eeb 619 ret = bond_opt_tryset_rtnl(bond, BOND_OPT_AD_SELECT, (char *)buf);
ec029fac 620 if (!ret)
621 ret = count;
622
fd989c83
JV
623 return ret;
624}
3d632c3f
SH
625static DEVICE_ATTR(ad_select, S_IRUGO | S_IWUSR,
626 bonding_show_ad_select, bonding_store_ad_select);
fd989c83 627
ad246c99
BH
628/*
629 * Show and set the number of peer notifications to send after a failover event.
630 */
631static ssize_t bonding_show_num_peer_notif(struct device *d,
632 struct device_attribute *attr,
633 char *buf)
634{
635 struct bonding *bond = to_bond(d);
636 return sprintf(buf, "%d\n", bond->params.num_peer_notif);
637}
638
639static ssize_t bonding_store_num_peer_notif(struct device *d,
640 struct device_attribute *attr,
641 const char *buf, size_t count)
642{
643 struct bonding *bond = to_bond(d);
2c9839c1 644 int ret;
645
ef56becb 646 ret = bond_opt_tryset_rtnl(bond, BOND_OPT_NUM_PEER_NOTIF, (char *)buf);
2c9839c1 647 if (!ret)
648 ret = count;
649
2c9839c1 650 return ret;
ad246c99
BH
651}
652static DEVICE_ATTR(num_grat_arp, S_IRUGO | S_IWUSR,
653 bonding_show_num_peer_notif, bonding_store_num_peer_notif);
654static DEVICE_ATTR(num_unsol_na, S_IRUGO | S_IWUSR,
655 bonding_show_num_peer_notif, bonding_store_num_peer_notif);
656
b76cdba9
MW
657/*
658 * Show and set the MII monitor interval. There are two tricky bits
659 * here. First, if MII monitoring is activated, then we must disable
660 * ARP monitoring. Second, if the timer isn't running, we must
661 * start it.
662 */
43cb76d9
GKH
663static ssize_t bonding_show_miimon(struct device *d,
664 struct device_attribute *attr,
665 char *buf)
b76cdba9 666{
43cb76d9 667 struct bonding *bond = to_bond(d);
b76cdba9 668
7bd46508 669 return sprintf(buf, "%d\n", bond->params.miimon);
b76cdba9
MW
670}
671
43cb76d9
GKH
672static ssize_t bonding_store_miimon(struct device *d,
673 struct device_attribute *attr,
674 const char *buf, size_t count)
b76cdba9 675{
43cb76d9 676 struct bonding *bond = to_bond(d);
b98d9c66 677 int ret;
b76cdba9 678
b98d9c66 679 ret = bond_opt_tryset_rtnl(bond, BOND_OPT_MIIMON, (char *)buf);
eecdaa6e 680 if (!ret)
681 ret = count;
682
b76cdba9
MW
683 return ret;
684}
3d632c3f
SH
685static DEVICE_ATTR(miimon, S_IRUGO | S_IWUSR,
686 bonding_show_miimon, bonding_store_miimon);
b76cdba9
MW
687
688/*
689 * Show and set the primary slave. The store function is much
690 * simpler than bonding_store_slaves function because it only needs to
691 * handle one interface name.
692 * The bond must be a mode that supports a primary for this be
693 * set.
694 */
43cb76d9
GKH
695static ssize_t bonding_show_primary(struct device *d,
696 struct device_attribute *attr,
697 char *buf)
b76cdba9
MW
698{
699 int count = 0;
43cb76d9 700 struct bonding *bond = to_bond(d);
b76cdba9
MW
701
702 if (bond->primary_slave)
7bd46508 703 count = sprintf(buf, "%s\n", bond->primary_slave->dev->name);
b76cdba9
MW
704
705 return count;
706}
707
43cb76d9
GKH
708static ssize_t bonding_store_primary(struct device *d,
709 struct device_attribute *attr,
710 const char *buf, size_t count)
b76cdba9 711{
43cb76d9 712 struct bonding *bond = to_bond(d);
f4bb2e9c 713 char ifname[IFNAMSIZ];
0a98a0d1 714 int ret;
b76cdba9 715
eb6e98a1 716 sscanf(buf, "%15s", ifname); /* IFNAMSIZ */
0a98a0d1 717 if (ifname[0] == '\n')
718 ifname[0] = '\0';
b76cdba9 719
0a98a0d1 720 if (!rtnl_trylock())
721 return restart_syscall();
f4bb2e9c 722
0a98a0d1 723 ret = bond_option_primary_set(bond, ifname);
724 if (!ret)
725 ret = count;
8a93664d 726
6603a6f2 727 rtnl_unlock();
0a98a0d1 728 return ret;
b76cdba9 729}
3d632c3f
SH
730static DEVICE_ATTR(primary, S_IRUGO | S_IWUSR,
731 bonding_show_primary, bonding_store_primary);
b76cdba9 732
a549952a
JP
733/*
734 * Show and set the primary_reselect flag.
735 */
736static ssize_t bonding_show_primary_reselect(struct device *d,
737 struct device_attribute *attr,
738 char *buf)
739{
740 struct bonding *bond = to_bond(d);
741
742 return sprintf(buf, "%s %d\n",
743 pri_reselect_tbl[bond->params.primary_reselect].modename,
744 bond->params.primary_reselect);
745}
746
747static ssize_t bonding_store_primary_reselect(struct device *d,
748 struct device_attribute *attr,
749 const char *buf, size_t count)
750{
8a41ae44 751 int new_value, ret;
a549952a
JP
752 struct bonding *bond = to_bond(d);
753
a549952a
JP
754 new_value = bond_parse_parm(buf, pri_reselect_tbl);
755 if (new_value < 0) {
a4aee5c8 756 pr_err("%s: Ignoring invalid primary_reselect value %.*s.\n",
a549952a
JP
757 bond->dev->name,
758 (int) strlen(buf) - 1, buf);
8a41ae44 759 return -EINVAL;
a549952a
JP
760 }
761
8a41ae44 762 if (!rtnl_trylock())
763 return restart_syscall();
764
765 ret = bond_option_primary_reselect_set(bond, new_value);
766 if (!ret)
767 ret = count;
a549952a 768
a549952a
JP
769 rtnl_unlock();
770 return ret;
771}
772static DEVICE_ATTR(primary_reselect, S_IRUGO | S_IWUSR,
773 bonding_show_primary_reselect,
774 bonding_store_primary_reselect);
775
b76cdba9
MW
776/*
777 * Show and set the use_carrier flag.
778 */
43cb76d9
GKH
779static ssize_t bonding_show_carrier(struct device *d,
780 struct device_attribute *attr,
781 char *buf)
b76cdba9 782{
43cb76d9 783 struct bonding *bond = to_bond(d);
b76cdba9 784
7bd46508 785 return sprintf(buf, "%d\n", bond->params.use_carrier);
b76cdba9
MW
786}
787
43cb76d9
GKH
788static ssize_t bonding_store_carrier(struct device *d,
789 struct device_attribute *attr,
790 const char *buf, size_t count)
b76cdba9 791{
9f53e14e 792 int new_value, ret;
43cb76d9 793 struct bonding *bond = to_bond(d);
b76cdba9 794
b76cdba9 795 if (sscanf(buf, "%d", &new_value) != 1) {
a4aee5c8 796 pr_err("%s: no use_carrier value specified.\n",
b76cdba9 797 bond->dev->name);
9f53e14e 798 return -EINVAL;
b76cdba9 799 }
9f53e14e 800
801 if (!rtnl_trylock())
802 return restart_syscall();
803
804 ret = bond_option_use_carrier_set(bond, new_value);
805 if (!ret)
806 ret = count;
807
808 rtnl_unlock();
672bda33 809 return ret;
b76cdba9 810}
3d632c3f
SH
811static DEVICE_ATTR(use_carrier, S_IRUGO | S_IWUSR,
812 bonding_show_carrier, bonding_store_carrier);
b76cdba9
MW
813
814
815/*
816 * Show and set currently active_slave.
817 */
43cb76d9
GKH
818static ssize_t bonding_show_active_slave(struct device *d,
819 struct device_attribute *attr,
820 char *buf)
b76cdba9 821{
43cb76d9 822 struct bonding *bond = to_bond(d);
752d48b5 823 struct net_device *slave_dev;
16cd0160 824 int count = 0;
b76cdba9 825
278b2083 826 rcu_read_lock();
752d48b5
JP
827 slave_dev = bond_option_active_slave_get_rcu(bond);
828 if (slave_dev)
829 count = sprintf(buf, "%s\n", slave_dev->name);
278b2083 830 rcu_read_unlock();
831
b76cdba9
MW
832 return count;
833}
834
43cb76d9
GKH
835static ssize_t bonding_store_active_slave(struct device *d,
836 struct device_attribute *attr,
837 const char *buf, size_t count)
b76cdba9 838{
d9e32b21 839 int ret;
43cb76d9 840 struct bonding *bond = to_bond(d);
f4bb2e9c 841 char ifname[IFNAMSIZ];
d9e32b21 842 struct net_device *dev;
b76cdba9 843
496a60cd
EB
844 if (!rtnl_trylock())
845 return restart_syscall();
e843fa50 846
c84e1590 847 sscanf(buf, "%15s", ifname); /* IFNAMSIZ */
f4bb2e9c 848 if (!strlen(ifname) || buf[0] == '\n') {
d9e32b21
JP
849 dev = NULL;
850 } else {
851 dev = __dev_get_by_name(dev_net(bond->dev), ifname);
852 if (!dev) {
853 ret = -ENODEV;
854 goto out;
b76cdba9 855 }
b76cdba9 856 }
f4bb2e9c 857
d9e32b21
JP
858 ret = bond_option_active_slave_set(bond, dev);
859 if (!ret)
860 ret = count;
e843fa50 861
d9e32b21 862 out:
6603a6f2
JV
863 rtnl_unlock();
864
d9e32b21 865 return ret;
b76cdba9
MW
866
867}
3d632c3f
SH
868static DEVICE_ATTR(active_slave, S_IRUGO | S_IWUSR,
869 bonding_show_active_slave, bonding_store_active_slave);
b76cdba9
MW
870
871
872/*
873 * Show link status of the bond interface.
874 */
43cb76d9
GKH
875static ssize_t bonding_show_mii_status(struct device *d,
876 struct device_attribute *attr,
877 char *buf)
b76cdba9 878{
43cb76d9 879 struct bonding *bond = to_bond(d);
b76cdba9 880
278b2083 881 return sprintf(buf, "%s\n", bond->curr_active_slave ? "up" : "down");
b76cdba9 882}
43cb76d9 883static DEVICE_ATTR(mii_status, S_IRUGO, bonding_show_mii_status, NULL);
b76cdba9 884
b76cdba9
MW
885/*
886 * Show current 802.3ad aggregator ID.
887 */
43cb76d9
GKH
888static ssize_t bonding_show_ad_aggregator(struct device *d,
889 struct device_attribute *attr,
890 char *buf)
b76cdba9
MW
891{
892 int count = 0;
43cb76d9 893 struct bonding *bond = to_bond(d);
b76cdba9
MW
894
895 if (bond->params.mode == BOND_MODE_8023AD) {
896 struct ad_info ad_info;
3d632c3f 897 count = sprintf(buf, "%d\n",
318debd8 898 bond_3ad_get_active_agg_info(bond, &ad_info)
3d632c3f 899 ? 0 : ad_info.aggregator_id);
b76cdba9 900 }
b76cdba9
MW
901
902 return count;
903}
43cb76d9 904static DEVICE_ATTR(ad_aggregator, S_IRUGO, bonding_show_ad_aggregator, NULL);
b76cdba9
MW
905
906
907/*
908 * Show number of active 802.3ad ports.
909 */
43cb76d9
GKH
910static ssize_t bonding_show_ad_num_ports(struct device *d,
911 struct device_attribute *attr,
912 char *buf)
b76cdba9
MW
913{
914 int count = 0;
43cb76d9 915 struct bonding *bond = to_bond(d);
b76cdba9
MW
916
917 if (bond->params.mode == BOND_MODE_8023AD) {
918 struct ad_info ad_info;
3d632c3f 919 count = sprintf(buf, "%d\n",
318debd8 920 bond_3ad_get_active_agg_info(bond, &ad_info)
3d632c3f 921 ? 0 : ad_info.ports);
b76cdba9 922 }
b76cdba9
MW
923
924 return count;
925}
43cb76d9 926static DEVICE_ATTR(ad_num_ports, S_IRUGO, bonding_show_ad_num_ports, NULL);
b76cdba9
MW
927
928
929/*
930 * Show current 802.3ad actor key.
931 */
43cb76d9
GKH
932static ssize_t bonding_show_ad_actor_key(struct device *d,
933 struct device_attribute *attr,
934 char *buf)
b76cdba9
MW
935{
936 int count = 0;
43cb76d9 937 struct bonding *bond = to_bond(d);
b76cdba9
MW
938
939 if (bond->params.mode == BOND_MODE_8023AD) {
940 struct ad_info ad_info;
3d632c3f 941 count = sprintf(buf, "%d\n",
318debd8 942 bond_3ad_get_active_agg_info(bond, &ad_info)
3d632c3f 943 ? 0 : ad_info.actor_key);
b76cdba9 944 }
b76cdba9
MW
945
946 return count;
947}
43cb76d9 948static DEVICE_ATTR(ad_actor_key, S_IRUGO, bonding_show_ad_actor_key, NULL);
b76cdba9
MW
949
950
951/*
952 * Show current 802.3ad partner key.
953 */
43cb76d9
GKH
954static ssize_t bonding_show_ad_partner_key(struct device *d,
955 struct device_attribute *attr,
956 char *buf)
b76cdba9
MW
957{
958 int count = 0;
43cb76d9 959 struct bonding *bond = to_bond(d);
b76cdba9
MW
960
961 if (bond->params.mode == BOND_MODE_8023AD) {
962 struct ad_info ad_info;
3d632c3f 963 count = sprintf(buf, "%d\n",
318debd8 964 bond_3ad_get_active_agg_info(bond, &ad_info)
3d632c3f 965 ? 0 : ad_info.partner_key);
b76cdba9 966 }
b76cdba9
MW
967
968 return count;
969}
43cb76d9 970static DEVICE_ATTR(ad_partner_key, S_IRUGO, bonding_show_ad_partner_key, NULL);
b76cdba9
MW
971
972
973/*
974 * Show current 802.3ad partner mac.
975 */
43cb76d9
GKH
976static ssize_t bonding_show_ad_partner_mac(struct device *d,
977 struct device_attribute *attr,
978 char *buf)
b76cdba9
MW
979{
980 int count = 0;
43cb76d9 981 struct bonding *bond = to_bond(d);
b76cdba9
MW
982
983 if (bond->params.mode == BOND_MODE_8023AD) {
984 struct ad_info ad_info;
3d632c3f 985 if (!bond_3ad_get_active_agg_info(bond, &ad_info))
e174961c 986 count = sprintf(buf, "%pM\n", ad_info.partner_system);
b76cdba9 987 }
b76cdba9
MW
988
989 return count;
990}
43cb76d9 991static DEVICE_ATTR(ad_partner_mac, S_IRUGO, bonding_show_ad_partner_mac, NULL);
b76cdba9 992
bb1d9123
AG
993/*
994 * Show the queue_ids of the slaves in the current bond.
995 */
996static ssize_t bonding_show_queue_id(struct device *d,
997 struct device_attribute *attr,
998 char *buf)
999{
bb1d9123 1000 struct bonding *bond = to_bond(d);
9caff1e7 1001 struct list_head *iter;
dec1e90e 1002 struct slave *slave;
1003 int res = 0;
bb1d9123
AG
1004
1005 if (!rtnl_trylock())
1006 return restart_syscall();
1007
9caff1e7 1008 bond_for_each_slave(bond, slave, iter) {
79236680
NP
1009 if (res > (PAGE_SIZE - IFNAMSIZ - 6)) {
1010 /* not enough space for another interface_name:queue_id pair */
bb1d9123
AG
1011 if ((PAGE_SIZE - res) > 10)
1012 res = PAGE_SIZE - 10;
1013 res += sprintf(buf + res, "++more++ ");
1014 break;
1015 }
1016 res += sprintf(buf + res, "%s:%d ",
1017 slave->dev->name, slave->queue_id);
1018 }
bb1d9123
AG
1019 if (res)
1020 buf[res-1] = '\n'; /* eat the leftover space */
4d1ae5fb 1021
bb1d9123 1022 rtnl_unlock();
dec1e90e 1023
bb1d9123
AG
1024 return res;
1025}
1026
1027/*
1028 * Set the queue_ids of the slaves in the current bond. The bond
1029 * interface must be enslaved for this to work.
1030 */
1031static ssize_t bonding_store_queue_id(struct device *d,
1032 struct device_attribute *attr,
1033 const char *buffer, size_t count)
1034{
1035 struct slave *slave, *update_slave;
1036 struct bonding *bond = to_bond(d);
9caff1e7 1037 struct list_head *iter;
bb1d9123 1038 u16 qid;
dec1e90e 1039 int ret = count;
bb1d9123
AG
1040 char *delim;
1041 struct net_device *sdev = NULL;
1042
1043 if (!rtnl_trylock())
1044 return restart_syscall();
1045
1046 /* delim will point to queue id if successful */
1047 delim = strchr(buffer, ':');
1048 if (!delim)
1049 goto err_no_cmd;
1050
1051 /*
1052 * Terminate string that points to device name and bump it
1053 * up one, so we can read the queue id there.
1054 */
1055 *delim = '\0';
1056 if (sscanf(++delim, "%hd\n", &qid) != 1)
1057 goto err_no_cmd;
1058
1059 /* Check buffer length, valid ifname and queue id */
1060 if (strlen(buffer) > IFNAMSIZ ||
1061 !dev_valid_name(buffer) ||
8a540ff9 1062 qid > bond->dev->real_num_tx_queues)
bb1d9123
AG
1063 goto err_no_cmd;
1064
1065 /* Get the pointer to that interface if it exists */
1066 sdev = __dev_get_by_name(dev_net(bond->dev), buffer);
1067 if (!sdev)
1068 goto err_no_cmd;
1069
bb1d9123
AG
1070 /* Search for thes slave and check for duplicate qids */
1071 update_slave = NULL;
9caff1e7 1072 bond_for_each_slave(bond, slave, iter) {
bb1d9123
AG
1073 if (sdev == slave->dev)
1074 /*
1075 * We don't need to check the matching
1076 * slave for dups, since we're overwriting it
1077 */
1078 update_slave = slave;
1079 else if (qid && qid == slave->queue_id) {
4d1ae5fb 1080 goto err_no_cmd;
bb1d9123
AG
1081 }
1082 }
1083
1084 if (!update_slave)
4d1ae5fb 1085 goto err_no_cmd;
bb1d9123
AG
1086
1087 /* Actually set the qids for the slave */
1088 update_slave->queue_id = qid;
1089
bb1d9123
AG
1090out:
1091 rtnl_unlock();
1092 return ret;
1093
bb1d9123
AG
1094err_no_cmd:
1095 pr_info("invalid input for queue_id set for %s.\n",
1096 bond->dev->name);
1097 ret = -EPERM;
1098 goto out;
1099}
1100
1101static DEVICE_ATTR(queue_id, S_IRUGO | S_IWUSR, bonding_show_queue_id,
1102 bonding_store_queue_id);
1103
1104
ebd8e497
AG
1105/*
1106 * Show and set the all_slaves_active flag.
1107 */
1108static ssize_t bonding_show_slaves_active(struct device *d,
1109 struct device_attribute *attr,
1110 char *buf)
1111{
1112 struct bonding *bond = to_bond(d);
1113
1114 return sprintf(buf, "%d\n", bond->params.all_slaves_active);
1115}
1116
1117static ssize_t bonding_store_slaves_active(struct device *d,
1118 struct device_attribute *attr,
1119 const char *buf, size_t count)
1120{
ebd8e497 1121 struct bonding *bond = to_bond(d);
1cc0b1e3 1122 int new_value, ret;
4d1ae5fb 1123
ebd8e497
AG
1124 if (sscanf(buf, "%d", &new_value) != 1) {
1125 pr_err("%s: no all_slaves_active value specified.\n",
1126 bond->dev->name);
1cc0b1e3 1127 return -EINVAL;
ebd8e497
AG
1128 }
1129
1cc0b1e3 1130 if (!rtnl_trylock())
1131 return restart_syscall();
ebd8e497 1132
1cc0b1e3 1133 ret = bond_option_all_slaves_active_set(bond, new_value);
1134 if (!ret)
1135 ret = count;
b76cdba9 1136
4d1ae5fb 1137 rtnl_unlock();
672bda33 1138 return ret;
ebd8e497
AG
1139}
1140static DEVICE_ATTR(all_slaves_active, S_IRUGO | S_IWUSR,
1141 bonding_show_slaves_active, bonding_store_slaves_active);
b76cdba9 1142
c2952c31
FL
1143/*
1144 * Show and set the number of IGMP membership reports to send on link failure
1145 */
1146static ssize_t bonding_show_resend_igmp(struct device *d,
94265cf5
FL
1147 struct device_attribute *attr,
1148 char *buf)
c2952c31
FL
1149{
1150 struct bonding *bond = to_bond(d);
1151
1152 return sprintf(buf, "%d\n", bond->params.resend_igmp);
1153}
1154
1155static ssize_t bonding_store_resend_igmp(struct device *d,
94265cf5
FL
1156 struct device_attribute *attr,
1157 const char *buf, size_t count)
c2952c31
FL
1158{
1159 int new_value, ret = count;
1160 struct bonding *bond = to_bond(d);
1161
1162 if (sscanf(buf, "%d", &new_value) != 1) {
1163 pr_err("%s: no resend_igmp value specified.\n",
1164 bond->dev->name);
d8838de7 1165 return -EINVAL;
c2952c31
FL
1166 }
1167
d8838de7 1168 if (!rtnl_trylock())
1169 return restart_syscall();
c2952c31 1170
d8838de7 1171 ret = bond_option_resend_igmp_set(bond, new_value);
1172 if (!ret)
1173 ret = count;
1174
1175 rtnl_unlock();
c2952c31
FL
1176 return ret;
1177}
1178
1179static DEVICE_ATTR(resend_igmp, S_IRUGO | S_IWUSR,
1180 bonding_show_resend_igmp, bonding_store_resend_igmp);
1181
7eacd038
NH
1182
1183static ssize_t bonding_show_lp_interval(struct device *d,
1184 struct device_attribute *attr,
1185 char *buf)
1186{
1187 struct bonding *bond = to_bond(d);
1188 return sprintf(buf, "%d\n", bond->params.lp_interval);
1189}
1190
1191static ssize_t bonding_store_lp_interval(struct device *d,
1192 struct device_attribute *attr,
1193 const char *buf, size_t count)
1194{
1195 struct bonding *bond = to_bond(d);
8d836d09 1196 int new_value, ret;
7eacd038
NH
1197
1198 if (sscanf(buf, "%d", &new_value) != 1) {
1199 pr_err("%s: no lp interval value specified.\n",
1200 bond->dev->name);
8d836d09 1201 return -EINVAL;
7eacd038
NH
1202 }
1203
8d836d09 1204 if (!rtnl_trylock())
1205 return restart_syscall();
7eacd038 1206
8d836d09 1207 ret = bond_option_lp_interval_set(bond, new_value);
1208 if (!ret)
1209 ret = count;
1210
1211 rtnl_unlock();
7eacd038
NH
1212 return ret;
1213}
1214
1215static DEVICE_ATTR(lp_interval, S_IRUGO | S_IWUSR,
1216 bonding_show_lp_interval, bonding_store_lp_interval);
1217
73958329
NA
1218static ssize_t bonding_show_packets_per_slave(struct device *d,
1219 struct device_attribute *attr,
1220 char *buf)
1221{
1222 struct bonding *bond = to_bond(d);
a752a8b9 1223 unsigned int packets_per_slave = bond->params.packets_per_slave;
a752a8b9 1224 return sprintf(buf, "%u\n", packets_per_slave);
73958329
NA
1225}
1226
1227static ssize_t bonding_store_packets_per_slave(struct device *d,
1228 struct device_attribute *attr,
1229 const char *buf, size_t count)
1230{
1231 struct bonding *bond = to_bond(d);
aa59d851 1232 int ret;
c13ab3ff 1233
aa59d851
NA
1234 ret = bond_opt_tryset_rtnl(bond, BOND_OPT_PACKETS_PER_SLAVE,
1235 (char *)buf);
c13ab3ff 1236 if (!ret)
1237 ret = count;
1238
73958329
NA
1239 return ret;
1240}
1241
1242static DEVICE_ATTR(packets_per_slave, S_IRUGO | S_IWUSR,
1243 bonding_show_packets_per_slave,
1244 bonding_store_packets_per_slave);
1245
b76cdba9 1246static struct attribute *per_bond_attrs[] = {
43cb76d9
GKH
1247 &dev_attr_slaves.attr,
1248 &dev_attr_mode.attr,
dd957c57 1249 &dev_attr_fail_over_mac.attr,
43cb76d9 1250 &dev_attr_arp_validate.attr,
8599b52e 1251 &dev_attr_arp_all_targets.attr,
43cb76d9
GKH
1252 &dev_attr_arp_interval.attr,
1253 &dev_attr_arp_ip_target.attr,
1254 &dev_attr_downdelay.attr,
1255 &dev_attr_updelay.attr,
1256 &dev_attr_lacp_rate.attr,
fd989c83 1257 &dev_attr_ad_select.attr,
43cb76d9 1258 &dev_attr_xmit_hash_policy.attr,
ad246c99
BH
1259 &dev_attr_num_grat_arp.attr,
1260 &dev_attr_num_unsol_na.attr,
43cb76d9
GKH
1261 &dev_attr_miimon.attr,
1262 &dev_attr_primary.attr,
a549952a 1263 &dev_attr_primary_reselect.attr,
43cb76d9
GKH
1264 &dev_attr_use_carrier.attr,
1265 &dev_attr_active_slave.attr,
1266 &dev_attr_mii_status.attr,
1267 &dev_attr_ad_aggregator.attr,
1268 &dev_attr_ad_num_ports.attr,
1269 &dev_attr_ad_actor_key.attr,
1270 &dev_attr_ad_partner_key.attr,
1271 &dev_attr_ad_partner_mac.attr,
bb1d9123 1272 &dev_attr_queue_id.attr,
ebd8e497 1273 &dev_attr_all_slaves_active.attr,
c2952c31 1274 &dev_attr_resend_igmp.attr,
655f8919 1275 &dev_attr_min_links.attr,
7eacd038 1276 &dev_attr_lp_interval.attr,
73958329 1277 &dev_attr_packets_per_slave.attr,
b76cdba9
MW
1278 NULL,
1279};
1280
1281static struct attribute_group bonding_group = {
1282 .name = "bonding",
1283 .attrs = per_bond_attrs,
1284};
1285
1286/*
1287 * Initialize sysfs. This sets up the bonding_masters file in
1288 * /sys/class/net.
1289 */
4c22400a 1290int bond_create_sysfs(struct bond_net *bn)
b76cdba9 1291{
b8a9787e 1292 int ret;
b76cdba9 1293
4c22400a 1294 bn->class_attr_bonding_masters = class_attr_bonding_masters;
01718e36 1295 sysfs_attr_init(&bn->class_attr_bonding_masters.attr);
4c22400a 1296
58292cbe
TH
1297 ret = netdev_class_create_file_ns(&bn->class_attr_bonding_masters,
1298 bn->net);
877cbd36
JV
1299 /*
1300 * Permit multiple loads of the module by ignoring failures to
1301 * create the bonding_masters sysfs file. Bonding devices
1302 * created by second or subsequent loads of the module will
1303 * not be listed in, or controllable by, bonding_masters, but
1304 * will have the usual "bonding" sysfs directory.
1305 *
1306 * This is done to preserve backwards compatibility for
1307 * initscripts/sysconfig, which load bonding multiple times to
1308 * configure multiple bonding devices.
1309 */
1310 if (ret == -EEXIST) {
38d2f38b 1311 /* Is someone being kinky and naming a device bonding_master? */
4c22400a 1312 if (__dev_get_by_name(bn->net,
38d2f38b 1313 class_attr_bonding_masters.attr.name))
a4aee5c8 1314 pr_err("network device named %s already exists in sysfs",
38d2f38b 1315 class_attr_bonding_masters.attr.name);
130aa61a 1316 ret = 0;
877cbd36 1317 }
b76cdba9
MW
1318
1319 return ret;
1320
1321}
1322
1323/*
1324 * Remove /sys/class/net/bonding_masters.
1325 */
4c22400a 1326void bond_destroy_sysfs(struct bond_net *bn)
b76cdba9 1327{
58292cbe 1328 netdev_class_remove_file_ns(&bn->class_attr_bonding_masters, bn->net);
b76cdba9
MW
1329}
1330
1331/*
1332 * Initialize sysfs for each bond. This sets up and registers
1333 * the 'bondctl' directory for each individual bond under /sys/class/net.
1334 */
6151b3d4 1335void bond_prepare_sysfs_group(struct bonding *bond)
b76cdba9 1336{
6151b3d4 1337 bond->dev->sysfs_groups[0] = &bonding_group;
b76cdba9
MW
1338}
1339
This page took 0.912979 seconds and 5 git commands to generate.