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