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/signal.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 43 #include <net/bonding.h> 44 45 #define to_bond(cd) ((struct bonding *)(netdev_priv(to_net_dev(cd)))) 46 47 /* "show" function for the bond_masters attribute. 48 * The class parameter is ignored. 49 */ 50 static ssize_t bonding_show_bonds(struct class *cls, 51 struct class_attribute *attr, 52 char *buf) 53 { 54 struct bond_net *bn = 55 container_of(attr, struct bond_net, class_attr_bonding_masters); 56 int res = 0; 57 struct bonding *bond; 58 59 rtnl_lock(); 60 61 list_for_each_entry(bond, &bn->dev_list, bond_list) { 62 if (res > (PAGE_SIZE - IFNAMSIZ)) { 63 /* not enough space for another interface name */ 64 if ((PAGE_SIZE - res) > 10) 65 res = PAGE_SIZE - 10; 66 res += sprintf(buf + res, "++more++ "); 67 break; 68 } 69 res += sprintf(buf + res, "%s ", bond->dev->name); 70 } 71 if (res) 72 buf[res-1] = '\n'; /* eat the leftover space */ 73 74 rtnl_unlock(); 75 return res; 76 } 77 78 static struct net_device *bond_get_by_name(struct bond_net *bn, const char *ifname) 79 { 80 struct bonding *bond; 81 82 list_for_each_entry(bond, &bn->dev_list, bond_list) { 83 if (strncmp(bond->dev->name, ifname, IFNAMSIZ) == 0) 84 return bond->dev; 85 } 86 return NULL; 87 } 88 89 /* "store" function for the bond_masters attribute. This is what 90 * creates and deletes entire bonds. 91 * 92 * The class parameter is ignored. 93 */ 94 static ssize_t bonding_store_bonds(struct class *cls, 95 struct class_attribute *attr, 96 const char *buffer, size_t count) 97 { 98 struct bond_net *bn = 99 container_of(attr, struct bond_net, class_attr_bonding_masters); 100 char command[IFNAMSIZ + 1] = {0, }; 101 char *ifname; 102 int rv, res = count; 103 104 sscanf(buffer, "%16s", command); /* IFNAMSIZ*/ 105 ifname = command + 1; 106 if ((strlen(command) <= 1) || 107 !dev_valid_name(ifname)) 108 goto err_no_cmd; 109 110 if (command[0] == '+') { 111 pr_info("%s is being created...\n", ifname); 112 rv = bond_create(bn->net, ifname); 113 if (rv) { 114 if (rv == -EEXIST) 115 pr_info("%s already exists\n", ifname); 116 else 117 pr_info("%s creation failed\n", ifname); 118 res = rv; 119 } 120 } else if (command[0] == '-') { 121 struct net_device *bond_dev; 122 123 rtnl_lock(); 124 bond_dev = bond_get_by_name(bn, ifname); 125 if (bond_dev) { 126 pr_info("%s is being deleted...\n", ifname); 127 unregister_netdevice(bond_dev); 128 } else { 129 pr_err("unable to delete non-existent %s\n", ifname); 130 res = -ENODEV; 131 } 132 rtnl_unlock(); 133 } else 134 goto err_no_cmd; 135 136 /* Always return either count or an error. If you return 0, you'll 137 * get called forever, which is bad. 138 */ 139 return res; 140 141 err_no_cmd: 142 pr_err("no command found in bonding_masters - use +ifname or -ifname\n"); 143 return -EPERM; 144 } 145 146 /* class attribute for bond_masters file. This ends up in /sys/class/net */ 147 static const struct class_attribute class_attr_bonding_masters = { 148 .attr = { 149 .name = "bonding_masters", 150 .mode = 0644, 151 }, 152 .show = bonding_show_bonds, 153 .store = bonding_store_bonds, 154 }; 155 156 /* Generic "store" method for bonding sysfs option setting */ 157 static ssize_t bonding_sysfs_store_option(struct device *d, 158 struct device_attribute *attr, 159 const char *buffer, size_t count) 160 { 161 struct bonding *bond = to_bond(d); 162 const struct bond_option *opt; 163 int ret; 164 165 opt = bond_opt_get_by_name(attr->attr.name); 166 if (WARN_ON(!opt)) 167 return -ENOENT; 168 ret = bond_opt_tryset_rtnl(bond, opt->id, (char *)buffer); 169 if (!ret) 170 ret = count; 171 172 return ret; 173 } 174 175 /* Show the slaves in the current bond. */ 176 static ssize_t bonding_show_slaves(struct device *d, 177 struct device_attribute *attr, char *buf) 178 { 179 struct bonding *bond = to_bond(d); 180 struct list_head *iter; 181 struct slave *slave; 182 int res = 0; 183 184 if (!rtnl_trylock()) 185 return restart_syscall(); 186 187 bond_for_each_slave(bond, slave, iter) { 188 if (res > (PAGE_SIZE - IFNAMSIZ)) { 189 /* not enough space for another interface name */ 190 if ((PAGE_SIZE - res) > 10) 191 res = PAGE_SIZE - 10; 192 res += sprintf(buf + res, "++more++ "); 193 break; 194 } 195 res += sprintf(buf + res, "%s ", slave->dev->name); 196 } 197 198 rtnl_unlock(); 199 200 if (res) 201 buf[res-1] = '\n'; /* eat the leftover space */ 202 203 return res; 204 } 205 static DEVICE_ATTR(slaves, 0644, bonding_show_slaves, 206 bonding_sysfs_store_option); 207 208 /* Show the bonding mode. */ 209 static ssize_t bonding_show_mode(struct device *d, 210 struct device_attribute *attr, char *buf) 211 { 212 struct bonding *bond = to_bond(d); 213 const struct bond_opt_value *val; 214 215 val = bond_opt_get_val(BOND_OPT_MODE, BOND_MODE(bond)); 216 217 return sprintf(buf, "%s %d\n", val->string, BOND_MODE(bond)); 218 } 219 static DEVICE_ATTR(mode, 0644, bonding_show_mode, bonding_sysfs_store_option); 220 221 /* Show the bonding transmit hash method. */ 222 static ssize_t bonding_show_xmit_hash(struct device *d, 223 struct device_attribute *attr, 224 char *buf) 225 { 226 struct bonding *bond = to_bond(d); 227 const struct bond_opt_value *val; 228 229 val = bond_opt_get_val(BOND_OPT_XMIT_HASH, bond->params.xmit_policy); 230 231 return sprintf(buf, "%s %d\n", val->string, bond->params.xmit_policy); 232 } 233 static DEVICE_ATTR(xmit_hash_policy, 0644, 234 bonding_show_xmit_hash, bonding_sysfs_store_option); 235 236 /* Show arp_validate. */ 237 static ssize_t bonding_show_arp_validate(struct device *d, 238 struct device_attribute *attr, 239 char *buf) 240 { 241 struct bonding *bond = to_bond(d); 242 const struct bond_opt_value *val; 243 244 val = bond_opt_get_val(BOND_OPT_ARP_VALIDATE, 245 bond->params.arp_validate); 246 247 return sprintf(buf, "%s %d\n", val->string, bond->params.arp_validate); 248 } 249 static DEVICE_ATTR(arp_validate, 0644, bonding_show_arp_validate, 250 bonding_sysfs_store_option); 251 252 /* Show arp_all_targets. */ 253 static ssize_t bonding_show_arp_all_targets(struct device *d, 254 struct device_attribute *attr, 255 char *buf) 256 { 257 struct bonding *bond = to_bond(d); 258 const struct bond_opt_value *val; 259 260 val = bond_opt_get_val(BOND_OPT_ARP_ALL_TARGETS, 261 bond->params.arp_all_targets); 262 return sprintf(buf, "%s %d\n", 263 val->string, bond->params.arp_all_targets); 264 } 265 static DEVICE_ATTR(arp_all_targets, 0644, 266 bonding_show_arp_all_targets, bonding_sysfs_store_option); 267 268 /* Show fail_over_mac. */ 269 static ssize_t bonding_show_fail_over_mac(struct device *d, 270 struct device_attribute *attr, 271 char *buf) 272 { 273 struct bonding *bond = to_bond(d); 274 const struct bond_opt_value *val; 275 276 val = bond_opt_get_val(BOND_OPT_FAIL_OVER_MAC, 277 bond->params.fail_over_mac); 278 279 return sprintf(buf, "%s %d\n", val->string, bond->params.fail_over_mac); 280 } 281 static DEVICE_ATTR(fail_over_mac, 0644, 282 bonding_show_fail_over_mac, bonding_sysfs_store_option); 283 284 /* Show the arp timer interval. */ 285 static ssize_t bonding_show_arp_interval(struct device *d, 286 struct device_attribute *attr, 287 char *buf) 288 { 289 struct bonding *bond = to_bond(d); 290 291 return sprintf(buf, "%d\n", bond->params.arp_interval); 292 } 293 static DEVICE_ATTR(arp_interval, 0644, 294 bonding_show_arp_interval, bonding_sysfs_store_option); 295 296 /* Show the arp targets. */ 297 static ssize_t bonding_show_arp_targets(struct device *d, 298 struct device_attribute *attr, 299 char *buf) 300 { 301 struct bonding *bond = to_bond(d); 302 int i, res = 0; 303 304 for (i = 0; i < BOND_MAX_ARP_TARGETS; i++) { 305 if (bond->params.arp_targets[i]) 306 res += sprintf(buf + res, "%pI4 ", 307 &bond->params.arp_targets[i]); 308 } 309 if (res) 310 buf[res-1] = '\n'; /* eat the leftover space */ 311 312 return res; 313 } 314 static DEVICE_ATTR(arp_ip_target, 0644, 315 bonding_show_arp_targets, bonding_sysfs_store_option); 316 317 /* Show the up and down delays. */ 318 static ssize_t bonding_show_downdelay(struct device *d, 319 struct device_attribute *attr, 320 char *buf) 321 { 322 struct bonding *bond = to_bond(d); 323 324 return sprintf(buf, "%d\n", bond->params.downdelay * bond->params.miimon); 325 } 326 static DEVICE_ATTR(downdelay, 0644, 327 bonding_show_downdelay, bonding_sysfs_store_option); 328 329 static ssize_t bonding_show_updelay(struct device *d, 330 struct device_attribute *attr, 331 char *buf) 332 { 333 struct bonding *bond = to_bond(d); 334 335 return sprintf(buf, "%d\n", bond->params.updelay * bond->params.miimon); 336 337 } 338 static DEVICE_ATTR(updelay, 0644, 339 bonding_show_updelay, bonding_sysfs_store_option); 340 341 /* Show the LACP interval. */ 342 static ssize_t bonding_show_lacp(struct device *d, 343 struct device_attribute *attr, 344 char *buf) 345 { 346 struct bonding *bond = to_bond(d); 347 const struct bond_opt_value *val; 348 349 val = bond_opt_get_val(BOND_OPT_LACP_RATE, bond->params.lacp_fast); 350 351 return sprintf(buf, "%s %d\n", val->string, bond->params.lacp_fast); 352 } 353 static DEVICE_ATTR(lacp_rate, 0644, 354 bonding_show_lacp, bonding_sysfs_store_option); 355 356 static ssize_t bonding_show_min_links(struct device *d, 357 struct device_attribute *attr, 358 char *buf) 359 { 360 struct bonding *bond = to_bond(d); 361 362 return sprintf(buf, "%u\n", bond->params.min_links); 363 } 364 static DEVICE_ATTR(min_links, 0644, 365 bonding_show_min_links, bonding_sysfs_store_option); 366 367 static ssize_t bonding_show_ad_select(struct device *d, 368 struct device_attribute *attr, 369 char *buf) 370 { 371 struct bonding *bond = to_bond(d); 372 const struct bond_opt_value *val; 373 374 val = bond_opt_get_val(BOND_OPT_AD_SELECT, bond->params.ad_select); 375 376 return sprintf(buf, "%s %d\n", val->string, bond->params.ad_select); 377 } 378 static DEVICE_ATTR(ad_select, 0644, 379 bonding_show_ad_select, bonding_sysfs_store_option); 380 381 /* Show the number of peer notifications to send after a failover event. */ 382 static ssize_t bonding_show_num_peer_notif(struct device *d, 383 struct device_attribute *attr, 384 char *buf) 385 { 386 struct bonding *bond = to_bond(d); 387 return sprintf(buf, "%d\n", bond->params.num_peer_notif); 388 } 389 static DEVICE_ATTR(num_grat_arp, 0644, 390 bonding_show_num_peer_notif, bonding_sysfs_store_option); 391 static DEVICE_ATTR(num_unsol_na, 0644, 392 bonding_show_num_peer_notif, bonding_sysfs_store_option); 393 394 /* Show the MII monitor interval. */ 395 static ssize_t bonding_show_miimon(struct device *d, 396 struct device_attribute *attr, 397 char *buf) 398 { 399 struct bonding *bond = to_bond(d); 400 401 return sprintf(buf, "%d\n", bond->params.miimon); 402 } 403 static DEVICE_ATTR(miimon, 0644, 404 bonding_show_miimon, bonding_sysfs_store_option); 405 406 /* Show the primary slave. */ 407 static ssize_t bonding_show_primary(struct device *d, 408 struct device_attribute *attr, 409 char *buf) 410 { 411 struct bonding *bond = to_bond(d); 412 struct slave *primary; 413 int count = 0; 414 415 rcu_read_lock(); 416 primary = rcu_dereference(bond->primary_slave); 417 if (primary) 418 count = sprintf(buf, "%s\n", primary->dev->name); 419 rcu_read_unlock(); 420 421 return count; 422 } 423 static DEVICE_ATTR(primary, 0644, 424 bonding_show_primary, bonding_sysfs_store_option); 425 426 /* Show the primary_reselect flag. */ 427 static ssize_t bonding_show_primary_reselect(struct device *d, 428 struct device_attribute *attr, 429 char *buf) 430 { 431 struct bonding *bond = to_bond(d); 432 const struct bond_opt_value *val; 433 434 val = bond_opt_get_val(BOND_OPT_PRIMARY_RESELECT, 435 bond->params.primary_reselect); 436 437 return sprintf(buf, "%s %d\n", 438 val->string, bond->params.primary_reselect); 439 } 440 static DEVICE_ATTR(primary_reselect, 0644, 441 bonding_show_primary_reselect, bonding_sysfs_store_option); 442 443 /* Show the use_carrier flag. */ 444 static ssize_t bonding_show_carrier(struct device *d, 445 struct device_attribute *attr, 446 char *buf) 447 { 448 struct bonding *bond = to_bond(d); 449 450 return sprintf(buf, "%d\n", bond->params.use_carrier); 451 } 452 static DEVICE_ATTR(use_carrier, 0644, 453 bonding_show_carrier, bonding_sysfs_store_option); 454 455 456 /* Show currently active_slave. */ 457 static ssize_t bonding_show_active_slave(struct device *d, 458 struct device_attribute *attr, 459 char *buf) 460 { 461 struct bonding *bond = to_bond(d); 462 struct net_device *slave_dev; 463 int count = 0; 464 465 rcu_read_lock(); 466 slave_dev = bond_option_active_slave_get_rcu(bond); 467 if (slave_dev) 468 count = sprintf(buf, "%s\n", slave_dev->name); 469 rcu_read_unlock(); 470 471 return count; 472 } 473 static DEVICE_ATTR(active_slave, 0644, 474 bonding_show_active_slave, bonding_sysfs_store_option); 475 476 /* Show link status of the bond interface. */ 477 static ssize_t bonding_show_mii_status(struct device *d, 478 struct device_attribute *attr, 479 char *buf) 480 { 481 struct bonding *bond = to_bond(d); 482 bool active = netif_carrier_ok(bond->dev); 483 484 return sprintf(buf, "%s\n", active ? "up" : "down"); 485 } 486 static DEVICE_ATTR(mii_status, 0444, bonding_show_mii_status, NULL); 487 488 /* Show current 802.3ad aggregator ID. */ 489 static ssize_t bonding_show_ad_aggregator(struct device *d, 490 struct device_attribute *attr, 491 char *buf) 492 { 493 int count = 0; 494 struct bonding *bond = to_bond(d); 495 496 if (BOND_MODE(bond) == BOND_MODE_8023AD) { 497 struct ad_info ad_info; 498 count = sprintf(buf, "%d\n", 499 bond_3ad_get_active_agg_info(bond, &ad_info) 500 ? 0 : ad_info.aggregator_id); 501 } 502 503 return count; 504 } 505 static DEVICE_ATTR(ad_aggregator, 0444, bonding_show_ad_aggregator, NULL); 506 507 508 /* Show number of active 802.3ad ports. */ 509 static ssize_t bonding_show_ad_num_ports(struct device *d, 510 struct device_attribute *attr, 511 char *buf) 512 { 513 int count = 0; 514 struct bonding *bond = to_bond(d); 515 516 if (BOND_MODE(bond) == BOND_MODE_8023AD) { 517 struct ad_info ad_info; 518 count = sprintf(buf, "%d\n", 519 bond_3ad_get_active_agg_info(bond, &ad_info) 520 ? 0 : ad_info.ports); 521 } 522 523 return count; 524 } 525 static DEVICE_ATTR(ad_num_ports, 0444, bonding_show_ad_num_ports, NULL); 526 527 528 /* Show current 802.3ad actor key. */ 529 static ssize_t bonding_show_ad_actor_key(struct device *d, 530 struct device_attribute *attr, 531 char *buf) 532 { 533 int count = 0; 534 struct bonding *bond = to_bond(d); 535 536 if (BOND_MODE(bond) == BOND_MODE_8023AD && capable(CAP_NET_ADMIN)) { 537 struct ad_info ad_info; 538 count = sprintf(buf, "%d\n", 539 bond_3ad_get_active_agg_info(bond, &ad_info) 540 ? 0 : ad_info.actor_key); 541 } 542 543 return count; 544 } 545 static DEVICE_ATTR(ad_actor_key, 0444, bonding_show_ad_actor_key, NULL); 546 547 548 /* Show current 802.3ad partner key. */ 549 static ssize_t bonding_show_ad_partner_key(struct device *d, 550 struct device_attribute *attr, 551 char *buf) 552 { 553 int count = 0; 554 struct bonding *bond = to_bond(d); 555 556 if (BOND_MODE(bond) == BOND_MODE_8023AD && capable(CAP_NET_ADMIN)) { 557 struct ad_info ad_info; 558 count = sprintf(buf, "%d\n", 559 bond_3ad_get_active_agg_info(bond, &ad_info) 560 ? 0 : ad_info.partner_key); 561 } 562 563 return count; 564 } 565 static DEVICE_ATTR(ad_partner_key, 0444, bonding_show_ad_partner_key, NULL); 566 567 568 /* Show current 802.3ad partner mac. */ 569 static ssize_t bonding_show_ad_partner_mac(struct device *d, 570 struct device_attribute *attr, 571 char *buf) 572 { 573 int count = 0; 574 struct bonding *bond = to_bond(d); 575 576 if (BOND_MODE(bond) == BOND_MODE_8023AD && capable(CAP_NET_ADMIN)) { 577 struct ad_info ad_info; 578 if (!bond_3ad_get_active_agg_info(bond, &ad_info)) 579 count = sprintf(buf, "%pM\n", ad_info.partner_system); 580 } 581 582 return count; 583 } 584 static DEVICE_ATTR(ad_partner_mac, 0444, bonding_show_ad_partner_mac, NULL); 585 586 /* Show the queue_ids of the slaves in the current bond. */ 587 static ssize_t bonding_show_queue_id(struct device *d, 588 struct device_attribute *attr, 589 char *buf) 590 { 591 struct bonding *bond = to_bond(d); 592 struct list_head *iter; 593 struct slave *slave; 594 int res = 0; 595 596 if (!rtnl_trylock()) 597 return restart_syscall(); 598 599 bond_for_each_slave(bond, slave, iter) { 600 if (res > (PAGE_SIZE - IFNAMSIZ - 6)) { 601 /* not enough space for another interface_name:queue_id pair */ 602 if ((PAGE_SIZE - res) > 10) 603 res = PAGE_SIZE - 10; 604 res += sprintf(buf + res, "++more++ "); 605 break; 606 } 607 res += sprintf(buf + res, "%s:%d ", 608 slave->dev->name, slave->queue_id); 609 } 610 if (res) 611 buf[res-1] = '\n'; /* eat the leftover space */ 612 613 rtnl_unlock(); 614 615 return res; 616 } 617 static DEVICE_ATTR(queue_id, 0644, bonding_show_queue_id, 618 bonding_sysfs_store_option); 619 620 621 /* Show the all_slaves_active flag. */ 622 static ssize_t bonding_show_slaves_active(struct device *d, 623 struct device_attribute *attr, 624 char *buf) 625 { 626 struct bonding *bond = to_bond(d); 627 628 return sprintf(buf, "%d\n", bond->params.all_slaves_active); 629 } 630 static DEVICE_ATTR(all_slaves_active, 0644, 631 bonding_show_slaves_active, bonding_sysfs_store_option); 632 633 /* Show the number of IGMP membership reports to send on link failure */ 634 static ssize_t bonding_show_resend_igmp(struct device *d, 635 struct device_attribute *attr, 636 char *buf) 637 { 638 struct bonding *bond = to_bond(d); 639 640 return sprintf(buf, "%d\n", bond->params.resend_igmp); 641 } 642 static DEVICE_ATTR(resend_igmp, 0644, 643 bonding_show_resend_igmp, bonding_sysfs_store_option); 644 645 646 static ssize_t bonding_show_lp_interval(struct device *d, 647 struct device_attribute *attr, 648 char *buf) 649 { 650 struct bonding *bond = to_bond(d); 651 652 return sprintf(buf, "%d\n", bond->params.lp_interval); 653 } 654 static DEVICE_ATTR(lp_interval, 0644, 655 bonding_show_lp_interval, bonding_sysfs_store_option); 656 657 static ssize_t bonding_show_tlb_dynamic_lb(struct device *d, 658 struct device_attribute *attr, 659 char *buf) 660 { 661 struct bonding *bond = to_bond(d); 662 return sprintf(buf, "%d\n", bond->params.tlb_dynamic_lb); 663 } 664 static DEVICE_ATTR(tlb_dynamic_lb, 0644, 665 bonding_show_tlb_dynamic_lb, bonding_sysfs_store_option); 666 667 static ssize_t bonding_show_packets_per_slave(struct device *d, 668 struct device_attribute *attr, 669 char *buf) 670 { 671 struct bonding *bond = to_bond(d); 672 unsigned int packets_per_slave = bond->params.packets_per_slave; 673 674 return sprintf(buf, "%u\n", packets_per_slave); 675 } 676 static DEVICE_ATTR(packets_per_slave, 0644, 677 bonding_show_packets_per_slave, bonding_sysfs_store_option); 678 679 static ssize_t bonding_show_ad_actor_sys_prio(struct device *d, 680 struct device_attribute *attr, 681 char *buf) 682 { 683 struct bonding *bond = to_bond(d); 684 685 if (BOND_MODE(bond) == BOND_MODE_8023AD && capable(CAP_NET_ADMIN)) 686 return sprintf(buf, "%hu\n", bond->params.ad_actor_sys_prio); 687 688 return 0; 689 } 690 static DEVICE_ATTR(ad_actor_sys_prio, 0644, 691 bonding_show_ad_actor_sys_prio, bonding_sysfs_store_option); 692 693 static ssize_t bonding_show_ad_actor_system(struct device *d, 694 struct device_attribute *attr, 695 char *buf) 696 { 697 struct bonding *bond = to_bond(d); 698 699 if (BOND_MODE(bond) == BOND_MODE_8023AD && capable(CAP_NET_ADMIN)) 700 return sprintf(buf, "%pM\n", bond->params.ad_actor_system); 701 702 return 0; 703 } 704 705 static DEVICE_ATTR(ad_actor_system, 0644, 706 bonding_show_ad_actor_system, bonding_sysfs_store_option); 707 708 static ssize_t bonding_show_ad_user_port_key(struct device *d, 709 struct device_attribute *attr, 710 char *buf) 711 { 712 struct bonding *bond = to_bond(d); 713 714 if (BOND_MODE(bond) == BOND_MODE_8023AD && capable(CAP_NET_ADMIN)) 715 return sprintf(buf, "%hu\n", bond->params.ad_user_port_key); 716 717 return 0; 718 } 719 static DEVICE_ATTR(ad_user_port_key, 0644, 720 bonding_show_ad_user_port_key, bonding_sysfs_store_option); 721 722 static struct attribute *per_bond_attrs[] = { 723 &dev_attr_slaves.attr, 724 &dev_attr_mode.attr, 725 &dev_attr_fail_over_mac.attr, 726 &dev_attr_arp_validate.attr, 727 &dev_attr_arp_all_targets.attr, 728 &dev_attr_arp_interval.attr, 729 &dev_attr_arp_ip_target.attr, 730 &dev_attr_downdelay.attr, 731 &dev_attr_updelay.attr, 732 &dev_attr_lacp_rate.attr, 733 &dev_attr_ad_select.attr, 734 &dev_attr_xmit_hash_policy.attr, 735 &dev_attr_num_grat_arp.attr, 736 &dev_attr_num_unsol_na.attr, 737 &dev_attr_miimon.attr, 738 &dev_attr_primary.attr, 739 &dev_attr_primary_reselect.attr, 740 &dev_attr_use_carrier.attr, 741 &dev_attr_active_slave.attr, 742 &dev_attr_mii_status.attr, 743 &dev_attr_ad_aggregator.attr, 744 &dev_attr_ad_num_ports.attr, 745 &dev_attr_ad_actor_key.attr, 746 &dev_attr_ad_partner_key.attr, 747 &dev_attr_ad_partner_mac.attr, 748 &dev_attr_queue_id.attr, 749 &dev_attr_all_slaves_active.attr, 750 &dev_attr_resend_igmp.attr, 751 &dev_attr_min_links.attr, 752 &dev_attr_lp_interval.attr, 753 &dev_attr_packets_per_slave.attr, 754 &dev_attr_tlb_dynamic_lb.attr, 755 &dev_attr_ad_actor_sys_prio.attr, 756 &dev_attr_ad_actor_system.attr, 757 &dev_attr_ad_user_port_key.attr, 758 NULL, 759 }; 760 761 static const struct attribute_group bonding_group = { 762 .name = "bonding", 763 .attrs = per_bond_attrs, 764 }; 765 766 /* Initialize sysfs. This sets up the bonding_masters file in 767 * /sys/class/net. 768 */ 769 int bond_create_sysfs(struct bond_net *bn) 770 { 771 int ret; 772 773 bn->class_attr_bonding_masters = class_attr_bonding_masters; 774 sysfs_attr_init(&bn->class_attr_bonding_masters.attr); 775 776 ret = netdev_class_create_file_ns(&bn->class_attr_bonding_masters, 777 bn->net); 778 /* Permit multiple loads of the module by ignoring failures to 779 * create the bonding_masters sysfs file. Bonding devices 780 * created by second or subsequent loads of the module will 781 * not be listed in, or controllable by, bonding_masters, but 782 * will have the usual "bonding" sysfs directory. 783 * 784 * This is done to preserve backwards compatibility for 785 * initscripts/sysconfig, which load bonding multiple times to 786 * configure multiple bonding devices. 787 */ 788 if (ret == -EEXIST) { 789 /* Is someone being kinky and naming a device bonding_master? */ 790 if (__dev_get_by_name(bn->net, 791 class_attr_bonding_masters.attr.name)) 792 pr_err("network device named %s already exists in sysfs\n", 793 class_attr_bonding_masters.attr.name); 794 ret = 0; 795 } 796 797 return ret; 798 799 } 800 801 /* Remove /sys/class/net/bonding_masters. */ 802 void bond_destroy_sysfs(struct bond_net *bn) 803 { 804 netdev_class_remove_file_ns(&bn->class_attr_bonding_masters, bn->net); 805 } 806 807 /* Initialize sysfs for each bond. This sets up and registers 808 * the 'bondctl' directory for each individual bond under /sys/class/net. 809 */ 810 void bond_prepare_sysfs_group(struct bonding *bond) 811 { 812 bond->dev->sysfs_groups[0] = &bonding_group; 813 } 814 815