]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/net/bonding/bond_sysfs.c
bonding: convert primary 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);
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);
0a98a0d1 713 int ret;
b76cdba9 714
180222f0 715 ret = bond_opt_tryset_rtnl(bond, BOND_OPT_PRIMARY, (char *)buf);
0a98a0d1 716 if (!ret)
717 ret = count;
8a93664d 718
0a98a0d1 719 return ret;
b76cdba9 720}
3d632c3f
SH
721static DEVICE_ATTR(primary, S_IRUGO | S_IWUSR,
722 bonding_show_primary, bonding_store_primary);
b76cdba9 723
a549952a
JP
724/*
725 * Show and set the primary_reselect flag.
726 */
727static ssize_t bonding_show_primary_reselect(struct device *d,
728 struct device_attribute *attr,
729 char *buf)
730{
731 struct bonding *bond = to_bond(d);
732
733 return sprintf(buf, "%s %d\n",
734 pri_reselect_tbl[bond->params.primary_reselect].modename,
735 bond->params.primary_reselect);
736}
737
738static ssize_t bonding_store_primary_reselect(struct device *d,
739 struct device_attribute *attr,
740 const char *buf, size_t count)
741{
8a41ae44 742 int new_value, ret;
a549952a
JP
743 struct bonding *bond = to_bond(d);
744
a549952a
JP
745 new_value = bond_parse_parm(buf, pri_reselect_tbl);
746 if (new_value < 0) {
a4aee5c8 747 pr_err("%s: Ignoring invalid primary_reselect value %.*s.\n",
a549952a
JP
748 bond->dev->name,
749 (int) strlen(buf) - 1, buf);
8a41ae44 750 return -EINVAL;
a549952a
JP
751 }
752
8a41ae44 753 if (!rtnl_trylock())
754 return restart_syscall();
755
756 ret = bond_option_primary_reselect_set(bond, new_value);
757 if (!ret)
758 ret = count;
a549952a 759
a549952a
JP
760 rtnl_unlock();
761 return ret;
762}
763static DEVICE_ATTR(primary_reselect, S_IRUGO | S_IWUSR,
764 bonding_show_primary_reselect,
765 bonding_store_primary_reselect);
766
b76cdba9
MW
767/*
768 * Show and set the use_carrier flag.
769 */
43cb76d9
GKH
770static ssize_t bonding_show_carrier(struct device *d,
771 struct device_attribute *attr,
772 char *buf)
b76cdba9 773{
43cb76d9 774 struct bonding *bond = to_bond(d);
b76cdba9 775
7bd46508 776 return sprintf(buf, "%d\n", bond->params.use_carrier);
b76cdba9
MW
777}
778
43cb76d9
GKH
779static ssize_t bonding_store_carrier(struct device *d,
780 struct device_attribute *attr,
781 const char *buf, size_t count)
b76cdba9 782{
9f53e14e 783 int new_value, ret;
43cb76d9 784 struct bonding *bond = to_bond(d);
b76cdba9 785
b76cdba9 786 if (sscanf(buf, "%d", &new_value) != 1) {
a4aee5c8 787 pr_err("%s: no use_carrier value specified.\n",
b76cdba9 788 bond->dev->name);
9f53e14e 789 return -EINVAL;
b76cdba9 790 }
9f53e14e 791
792 if (!rtnl_trylock())
793 return restart_syscall();
794
795 ret = bond_option_use_carrier_set(bond, new_value);
796 if (!ret)
797 ret = count;
798
799 rtnl_unlock();
672bda33 800 return ret;
b76cdba9 801}
3d632c3f
SH
802static DEVICE_ATTR(use_carrier, S_IRUGO | S_IWUSR,
803 bonding_show_carrier, bonding_store_carrier);
b76cdba9
MW
804
805
806/*
807 * Show and set currently active_slave.
808 */
43cb76d9
GKH
809static ssize_t bonding_show_active_slave(struct device *d,
810 struct device_attribute *attr,
811 char *buf)
b76cdba9 812{
43cb76d9 813 struct bonding *bond = to_bond(d);
752d48b5 814 struct net_device *slave_dev;
16cd0160 815 int count = 0;
b76cdba9 816
278b2083 817 rcu_read_lock();
752d48b5
JP
818 slave_dev = bond_option_active_slave_get_rcu(bond);
819 if (slave_dev)
820 count = sprintf(buf, "%s\n", slave_dev->name);
278b2083 821 rcu_read_unlock();
822
b76cdba9
MW
823 return count;
824}
825
43cb76d9
GKH
826static ssize_t bonding_store_active_slave(struct device *d,
827 struct device_attribute *attr,
828 const char *buf, size_t count)
b76cdba9 829{
d9e32b21 830 int ret;
43cb76d9 831 struct bonding *bond = to_bond(d);
f4bb2e9c 832 char ifname[IFNAMSIZ];
d9e32b21 833 struct net_device *dev;
b76cdba9 834
496a60cd
EB
835 if (!rtnl_trylock())
836 return restart_syscall();
e843fa50 837
c84e1590 838 sscanf(buf, "%15s", ifname); /* IFNAMSIZ */
f4bb2e9c 839 if (!strlen(ifname) || buf[0] == '\n') {
d9e32b21
JP
840 dev = NULL;
841 } else {
842 dev = __dev_get_by_name(dev_net(bond->dev), ifname);
843 if (!dev) {
844 ret = -ENODEV;
845 goto out;
b76cdba9 846 }
b76cdba9 847 }
f4bb2e9c 848
d9e32b21
JP
849 ret = bond_option_active_slave_set(bond, dev);
850 if (!ret)
851 ret = count;
e843fa50 852
d9e32b21 853 out:
6603a6f2
JV
854 rtnl_unlock();
855
d9e32b21 856 return ret;
b76cdba9
MW
857
858}
3d632c3f
SH
859static DEVICE_ATTR(active_slave, S_IRUGO | S_IWUSR,
860 bonding_show_active_slave, bonding_store_active_slave);
b76cdba9
MW
861
862
863/*
864 * Show link status of the bond interface.
865 */
43cb76d9
GKH
866static ssize_t bonding_show_mii_status(struct device *d,
867 struct device_attribute *attr,
868 char *buf)
b76cdba9 869{
43cb76d9 870 struct bonding *bond = to_bond(d);
b76cdba9 871
278b2083 872 return sprintf(buf, "%s\n", bond->curr_active_slave ? "up" : "down");
b76cdba9 873}
43cb76d9 874static DEVICE_ATTR(mii_status, S_IRUGO, bonding_show_mii_status, NULL);
b76cdba9 875
b76cdba9
MW
876/*
877 * Show current 802.3ad aggregator ID.
878 */
43cb76d9
GKH
879static ssize_t bonding_show_ad_aggregator(struct device *d,
880 struct device_attribute *attr,
881 char *buf)
b76cdba9
MW
882{
883 int count = 0;
43cb76d9 884 struct bonding *bond = to_bond(d);
b76cdba9
MW
885
886 if (bond->params.mode == BOND_MODE_8023AD) {
887 struct ad_info ad_info;
3d632c3f 888 count = sprintf(buf, "%d\n",
318debd8 889 bond_3ad_get_active_agg_info(bond, &ad_info)
3d632c3f 890 ? 0 : ad_info.aggregator_id);
b76cdba9 891 }
b76cdba9
MW
892
893 return count;
894}
43cb76d9 895static DEVICE_ATTR(ad_aggregator, S_IRUGO, bonding_show_ad_aggregator, NULL);
b76cdba9
MW
896
897
898/*
899 * Show number of active 802.3ad ports.
900 */
43cb76d9
GKH
901static ssize_t bonding_show_ad_num_ports(struct device *d,
902 struct device_attribute *attr,
903 char *buf)
b76cdba9
MW
904{
905 int count = 0;
43cb76d9 906 struct bonding *bond = to_bond(d);
b76cdba9
MW
907
908 if (bond->params.mode == BOND_MODE_8023AD) {
909 struct ad_info ad_info;
3d632c3f 910 count = sprintf(buf, "%d\n",
318debd8 911 bond_3ad_get_active_agg_info(bond, &ad_info)
3d632c3f 912 ? 0 : ad_info.ports);
b76cdba9 913 }
b76cdba9
MW
914
915 return count;
916}
43cb76d9 917static DEVICE_ATTR(ad_num_ports, S_IRUGO, bonding_show_ad_num_ports, NULL);
b76cdba9
MW
918
919
920/*
921 * Show current 802.3ad actor key.
922 */
43cb76d9
GKH
923static ssize_t bonding_show_ad_actor_key(struct device *d,
924 struct device_attribute *attr,
925 char *buf)
b76cdba9
MW
926{
927 int count = 0;
43cb76d9 928 struct bonding *bond = to_bond(d);
b76cdba9
MW
929
930 if (bond->params.mode == BOND_MODE_8023AD) {
931 struct ad_info ad_info;
3d632c3f 932 count = sprintf(buf, "%d\n",
318debd8 933 bond_3ad_get_active_agg_info(bond, &ad_info)
3d632c3f 934 ? 0 : ad_info.actor_key);
b76cdba9 935 }
b76cdba9
MW
936
937 return count;
938}
43cb76d9 939static DEVICE_ATTR(ad_actor_key, S_IRUGO, bonding_show_ad_actor_key, NULL);
b76cdba9
MW
940
941
942/*
943 * Show current 802.3ad partner key.
944 */
43cb76d9
GKH
945static ssize_t bonding_show_ad_partner_key(struct device *d,
946 struct device_attribute *attr,
947 char *buf)
b76cdba9
MW
948{
949 int count = 0;
43cb76d9 950 struct bonding *bond = to_bond(d);
b76cdba9
MW
951
952 if (bond->params.mode == BOND_MODE_8023AD) {
953 struct ad_info ad_info;
3d632c3f 954 count = sprintf(buf, "%d\n",
318debd8 955 bond_3ad_get_active_agg_info(bond, &ad_info)
3d632c3f 956 ? 0 : ad_info.partner_key);
b76cdba9 957 }
b76cdba9
MW
958
959 return count;
960}
43cb76d9 961static DEVICE_ATTR(ad_partner_key, S_IRUGO, bonding_show_ad_partner_key, NULL);
b76cdba9
MW
962
963
964/*
965 * Show current 802.3ad partner mac.
966 */
43cb76d9
GKH
967static ssize_t bonding_show_ad_partner_mac(struct device *d,
968 struct device_attribute *attr,
969 char *buf)
b76cdba9
MW
970{
971 int count = 0;
43cb76d9 972 struct bonding *bond = to_bond(d);
b76cdba9
MW
973
974 if (bond->params.mode == BOND_MODE_8023AD) {
975 struct ad_info ad_info;
3d632c3f 976 if (!bond_3ad_get_active_agg_info(bond, &ad_info))
e174961c 977 count = sprintf(buf, "%pM\n", ad_info.partner_system);
b76cdba9 978 }
b76cdba9
MW
979
980 return count;
981}
43cb76d9 982static DEVICE_ATTR(ad_partner_mac, S_IRUGO, bonding_show_ad_partner_mac, NULL);
b76cdba9 983
bb1d9123
AG
984/*
985 * Show the queue_ids of the slaves in the current bond.
986 */
987static ssize_t bonding_show_queue_id(struct device *d,
988 struct device_attribute *attr,
989 char *buf)
990{
bb1d9123 991 struct bonding *bond = to_bond(d);
9caff1e7 992 struct list_head *iter;
dec1e90e 993 struct slave *slave;
994 int res = 0;
bb1d9123
AG
995
996 if (!rtnl_trylock())
997 return restart_syscall();
998
9caff1e7 999 bond_for_each_slave(bond, slave, iter) {
79236680
NP
1000 if (res > (PAGE_SIZE - IFNAMSIZ - 6)) {
1001 /* not enough space for another interface_name:queue_id pair */
bb1d9123
AG
1002 if ((PAGE_SIZE - res) > 10)
1003 res = PAGE_SIZE - 10;
1004 res += sprintf(buf + res, "++more++ ");
1005 break;
1006 }
1007 res += sprintf(buf + res, "%s:%d ",
1008 slave->dev->name, slave->queue_id);
1009 }
bb1d9123
AG
1010 if (res)
1011 buf[res-1] = '\n'; /* eat the leftover space */
4d1ae5fb 1012
bb1d9123 1013 rtnl_unlock();
dec1e90e 1014
bb1d9123
AG
1015 return res;
1016}
1017
1018/*
1019 * Set the queue_ids of the slaves in the current bond. The bond
1020 * interface must be enslaved for this to work.
1021 */
1022static ssize_t bonding_store_queue_id(struct device *d,
1023 struct device_attribute *attr,
1024 const char *buffer, size_t count)
1025{
1026 struct slave *slave, *update_slave;
1027 struct bonding *bond = to_bond(d);
9caff1e7 1028 struct list_head *iter;
bb1d9123 1029 u16 qid;
dec1e90e 1030 int ret = count;
bb1d9123
AG
1031 char *delim;
1032 struct net_device *sdev = NULL;
1033
1034 if (!rtnl_trylock())
1035 return restart_syscall();
1036
1037 /* delim will point to queue id if successful */
1038 delim = strchr(buffer, ':');
1039 if (!delim)
1040 goto err_no_cmd;
1041
1042 /*
1043 * Terminate string that points to device name and bump it
1044 * up one, so we can read the queue id there.
1045 */
1046 *delim = '\0';
1047 if (sscanf(++delim, "%hd\n", &qid) != 1)
1048 goto err_no_cmd;
1049
1050 /* Check buffer length, valid ifname and queue id */
1051 if (strlen(buffer) > IFNAMSIZ ||
1052 !dev_valid_name(buffer) ||
8a540ff9 1053 qid > bond->dev->real_num_tx_queues)
bb1d9123
AG
1054 goto err_no_cmd;
1055
1056 /* Get the pointer to that interface if it exists */
1057 sdev = __dev_get_by_name(dev_net(bond->dev), buffer);
1058 if (!sdev)
1059 goto err_no_cmd;
1060
bb1d9123
AG
1061 /* Search for thes slave and check for duplicate qids */
1062 update_slave = NULL;
9caff1e7 1063 bond_for_each_slave(bond, slave, iter) {
bb1d9123
AG
1064 if (sdev == slave->dev)
1065 /*
1066 * We don't need to check the matching
1067 * slave for dups, since we're overwriting it
1068 */
1069 update_slave = slave;
1070 else if (qid && qid == slave->queue_id) {
4d1ae5fb 1071 goto err_no_cmd;
bb1d9123
AG
1072 }
1073 }
1074
1075 if (!update_slave)
4d1ae5fb 1076 goto err_no_cmd;
bb1d9123
AG
1077
1078 /* Actually set the qids for the slave */
1079 update_slave->queue_id = qid;
1080
bb1d9123
AG
1081out:
1082 rtnl_unlock();
1083 return ret;
1084
bb1d9123
AG
1085err_no_cmd:
1086 pr_info("invalid input for queue_id set for %s.\n",
1087 bond->dev->name);
1088 ret = -EPERM;
1089 goto out;
1090}
1091
1092static DEVICE_ATTR(queue_id, S_IRUGO | S_IWUSR, bonding_show_queue_id,
1093 bonding_store_queue_id);
1094
1095
ebd8e497
AG
1096/*
1097 * Show and set the all_slaves_active flag.
1098 */
1099static ssize_t bonding_show_slaves_active(struct device *d,
1100 struct device_attribute *attr,
1101 char *buf)
1102{
1103 struct bonding *bond = to_bond(d);
1104
1105 return sprintf(buf, "%d\n", bond->params.all_slaves_active);
1106}
1107
1108static ssize_t bonding_store_slaves_active(struct device *d,
1109 struct device_attribute *attr,
1110 const char *buf, size_t count)
1111{
ebd8e497 1112 struct bonding *bond = to_bond(d);
1cc0b1e3 1113 int new_value, ret;
4d1ae5fb 1114
ebd8e497
AG
1115 if (sscanf(buf, "%d", &new_value) != 1) {
1116 pr_err("%s: no all_slaves_active value specified.\n",
1117 bond->dev->name);
1cc0b1e3 1118 return -EINVAL;
ebd8e497
AG
1119 }
1120
1cc0b1e3 1121 if (!rtnl_trylock())
1122 return restart_syscall();
ebd8e497 1123
1cc0b1e3 1124 ret = bond_option_all_slaves_active_set(bond, new_value);
1125 if (!ret)
1126 ret = count;
b76cdba9 1127
4d1ae5fb 1128 rtnl_unlock();
672bda33 1129 return ret;
ebd8e497
AG
1130}
1131static DEVICE_ATTR(all_slaves_active, S_IRUGO | S_IWUSR,
1132 bonding_show_slaves_active, bonding_store_slaves_active);
b76cdba9 1133
c2952c31
FL
1134/*
1135 * Show and set the number of IGMP membership reports to send on link failure
1136 */
1137static ssize_t bonding_show_resend_igmp(struct device *d,
94265cf5
FL
1138 struct device_attribute *attr,
1139 char *buf)
c2952c31
FL
1140{
1141 struct bonding *bond = to_bond(d);
1142
1143 return sprintf(buf, "%d\n", bond->params.resend_igmp);
1144}
1145
1146static ssize_t bonding_store_resend_igmp(struct device *d,
94265cf5
FL
1147 struct device_attribute *attr,
1148 const char *buf, size_t count)
c2952c31
FL
1149{
1150 int new_value, ret = count;
1151 struct bonding *bond = to_bond(d);
1152
1153 if (sscanf(buf, "%d", &new_value) != 1) {
1154 pr_err("%s: no resend_igmp value specified.\n",
1155 bond->dev->name);
d8838de7 1156 return -EINVAL;
c2952c31
FL
1157 }
1158
d8838de7 1159 if (!rtnl_trylock())
1160 return restart_syscall();
c2952c31 1161
d8838de7 1162 ret = bond_option_resend_igmp_set(bond, new_value);
1163 if (!ret)
1164 ret = count;
1165
1166 rtnl_unlock();
c2952c31
FL
1167 return ret;
1168}
1169
1170static DEVICE_ATTR(resend_igmp, S_IRUGO | S_IWUSR,
1171 bonding_show_resend_igmp, bonding_store_resend_igmp);
1172
7eacd038
NH
1173
1174static ssize_t bonding_show_lp_interval(struct device *d,
1175 struct device_attribute *attr,
1176 char *buf)
1177{
1178 struct bonding *bond = to_bond(d);
1179 return sprintf(buf, "%d\n", bond->params.lp_interval);
1180}
1181
1182static ssize_t bonding_store_lp_interval(struct device *d,
1183 struct device_attribute *attr,
1184 const char *buf, size_t count)
1185{
1186 struct bonding *bond = to_bond(d);
8d836d09 1187 int new_value, ret;
7eacd038
NH
1188
1189 if (sscanf(buf, "%d", &new_value) != 1) {
1190 pr_err("%s: no lp interval value specified.\n",
1191 bond->dev->name);
8d836d09 1192 return -EINVAL;
7eacd038
NH
1193 }
1194
8d836d09 1195 if (!rtnl_trylock())
1196 return restart_syscall();
7eacd038 1197
8d836d09 1198 ret = bond_option_lp_interval_set(bond, new_value);
1199 if (!ret)
1200 ret = count;
1201
1202 rtnl_unlock();
7eacd038
NH
1203 return ret;
1204}
1205
1206static DEVICE_ATTR(lp_interval, S_IRUGO | S_IWUSR,
1207 bonding_show_lp_interval, bonding_store_lp_interval);
1208
73958329
NA
1209static ssize_t bonding_show_packets_per_slave(struct device *d,
1210 struct device_attribute *attr,
1211 char *buf)
1212{
1213 struct bonding *bond = to_bond(d);
a752a8b9 1214 unsigned int packets_per_slave = bond->params.packets_per_slave;
a752a8b9 1215 return sprintf(buf, "%u\n", packets_per_slave);
73958329
NA
1216}
1217
1218static ssize_t bonding_store_packets_per_slave(struct device *d,
1219 struct device_attribute *attr,
1220 const char *buf, size_t count)
1221{
1222 struct bonding *bond = to_bond(d);
aa59d851 1223 int ret;
c13ab3ff 1224
aa59d851
NA
1225 ret = bond_opt_tryset_rtnl(bond, BOND_OPT_PACKETS_PER_SLAVE,
1226 (char *)buf);
c13ab3ff 1227 if (!ret)
1228 ret = count;
1229
73958329
NA
1230 return ret;
1231}
1232
1233static DEVICE_ATTR(packets_per_slave, S_IRUGO | S_IWUSR,
1234 bonding_show_packets_per_slave,
1235 bonding_store_packets_per_slave);
1236
b76cdba9 1237static struct attribute *per_bond_attrs[] = {
43cb76d9
GKH
1238 &dev_attr_slaves.attr,
1239 &dev_attr_mode.attr,
dd957c57 1240 &dev_attr_fail_over_mac.attr,
43cb76d9 1241 &dev_attr_arp_validate.attr,
8599b52e 1242 &dev_attr_arp_all_targets.attr,
43cb76d9
GKH
1243 &dev_attr_arp_interval.attr,
1244 &dev_attr_arp_ip_target.attr,
1245 &dev_attr_downdelay.attr,
1246 &dev_attr_updelay.attr,
1247 &dev_attr_lacp_rate.attr,
fd989c83 1248 &dev_attr_ad_select.attr,
43cb76d9 1249 &dev_attr_xmit_hash_policy.attr,
ad246c99
BH
1250 &dev_attr_num_grat_arp.attr,
1251 &dev_attr_num_unsol_na.attr,
43cb76d9
GKH
1252 &dev_attr_miimon.attr,
1253 &dev_attr_primary.attr,
a549952a 1254 &dev_attr_primary_reselect.attr,
43cb76d9
GKH
1255 &dev_attr_use_carrier.attr,
1256 &dev_attr_active_slave.attr,
1257 &dev_attr_mii_status.attr,
1258 &dev_attr_ad_aggregator.attr,
1259 &dev_attr_ad_num_ports.attr,
1260 &dev_attr_ad_actor_key.attr,
1261 &dev_attr_ad_partner_key.attr,
1262 &dev_attr_ad_partner_mac.attr,
bb1d9123 1263 &dev_attr_queue_id.attr,
ebd8e497 1264 &dev_attr_all_slaves_active.attr,
c2952c31 1265 &dev_attr_resend_igmp.attr,
655f8919 1266 &dev_attr_min_links.attr,
7eacd038 1267 &dev_attr_lp_interval.attr,
73958329 1268 &dev_attr_packets_per_slave.attr,
b76cdba9
MW
1269 NULL,
1270};
1271
1272static struct attribute_group bonding_group = {
1273 .name = "bonding",
1274 .attrs = per_bond_attrs,
1275};
1276
1277/*
1278 * Initialize sysfs. This sets up the bonding_masters file in
1279 * /sys/class/net.
1280 */
4c22400a 1281int bond_create_sysfs(struct bond_net *bn)
b76cdba9 1282{
b8a9787e 1283 int ret;
b76cdba9 1284
4c22400a 1285 bn->class_attr_bonding_masters = class_attr_bonding_masters;
01718e36 1286 sysfs_attr_init(&bn->class_attr_bonding_masters.attr);
4c22400a 1287
58292cbe
TH
1288 ret = netdev_class_create_file_ns(&bn->class_attr_bonding_masters,
1289 bn->net);
877cbd36
JV
1290 /*
1291 * Permit multiple loads of the module by ignoring failures to
1292 * create the bonding_masters sysfs file. Bonding devices
1293 * created by second or subsequent loads of the module will
1294 * not be listed in, or controllable by, bonding_masters, but
1295 * will have the usual "bonding" sysfs directory.
1296 *
1297 * This is done to preserve backwards compatibility for
1298 * initscripts/sysconfig, which load bonding multiple times to
1299 * configure multiple bonding devices.
1300 */
1301 if (ret == -EEXIST) {
38d2f38b 1302 /* Is someone being kinky and naming a device bonding_master? */
4c22400a 1303 if (__dev_get_by_name(bn->net,
38d2f38b 1304 class_attr_bonding_masters.attr.name))
a4aee5c8 1305 pr_err("network device named %s already exists in sysfs",
38d2f38b 1306 class_attr_bonding_masters.attr.name);
130aa61a 1307 ret = 0;
877cbd36 1308 }
b76cdba9
MW
1309
1310 return ret;
1311
1312}
1313
1314/*
1315 * Remove /sys/class/net/bonding_masters.
1316 */
4c22400a 1317void bond_destroy_sysfs(struct bond_net *bn)
b76cdba9 1318{
58292cbe 1319 netdev_class_remove_file_ns(&bn->class_attr_bonding_masters, bn->net);
b76cdba9
MW
1320}
1321
1322/*
1323 * Initialize sysfs for each bond. This sets up and registers
1324 * the 'bondctl' directory for each individual bond under /sys/class/net.
1325 */
6151b3d4 1326void bond_prepare_sysfs_group(struct bonding *bond)
b76cdba9 1327{
6151b3d4 1328 bond->dev->sysfs_groups[0] = &bonding_group;
b76cdba9
MW
1329}
1330