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