0001
0002
0003
0004
0005
0006 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
0007
0008 #include <linux/kernel.h>
0009 #include <linux/module.h>
0010 #include <linux/device.h>
0011 #include <linux/sched/signal.h>
0012 #include <linux/fs.h>
0013 #include <linux/types.h>
0014 #include <linux/string.h>
0015 #include <linux/netdevice.h>
0016 #include <linux/inetdevice.h>
0017 #include <linux/in.h>
0018 #include <linux/sysfs.h>
0019 #include <linux/ctype.h>
0020 #include <linux/inet.h>
0021 #include <linux/rtnetlink.h>
0022 #include <linux/etherdevice.h>
0023 #include <net/net_namespace.h>
0024 #include <net/netns/generic.h>
0025 #include <linux/nsproxy.h>
0026
0027 #include <net/bonding.h>
0028
0029 #define to_bond(cd) ((struct bonding *)(netdev_priv(to_net_dev(cd))))
0030
0031
0032
0033
0034 static ssize_t bonding_show_bonds(struct class *cls,
0035 struct class_attribute *attr,
0036 char *buf)
0037 {
0038 struct bond_net *bn =
0039 container_of(attr, struct bond_net, class_attr_bonding_masters);
0040 int res = 0;
0041 struct bonding *bond;
0042
0043 rtnl_lock();
0044
0045 list_for_each_entry(bond, &bn->dev_list, bond_list) {
0046 if (res > (PAGE_SIZE - IFNAMSIZ)) {
0047
0048 if ((PAGE_SIZE - res) > 10)
0049 res = PAGE_SIZE - 10;
0050 res += sprintf(buf + res, "++more++ ");
0051 break;
0052 }
0053 res += sprintf(buf + res, "%s ", bond->dev->name);
0054 }
0055 if (res)
0056 buf[res-1] = '\n';
0057
0058 rtnl_unlock();
0059 return res;
0060 }
0061
0062 static struct net_device *bond_get_by_name(struct bond_net *bn, const char *ifname)
0063 {
0064 struct bonding *bond;
0065
0066 list_for_each_entry(bond, &bn->dev_list, bond_list) {
0067 if (strncmp(bond->dev->name, ifname, IFNAMSIZ) == 0)
0068 return bond->dev;
0069 }
0070 return NULL;
0071 }
0072
0073
0074
0075
0076
0077
0078 static ssize_t bonding_store_bonds(struct class *cls,
0079 struct class_attribute *attr,
0080 const char *buffer, size_t count)
0081 {
0082 struct bond_net *bn =
0083 container_of(attr, struct bond_net, class_attr_bonding_masters);
0084 char command[IFNAMSIZ + 1] = {0, };
0085 char *ifname;
0086 int rv, res = count;
0087
0088 sscanf(buffer, "%16s", command);
0089 ifname = command + 1;
0090 if ((strlen(command) <= 1) ||
0091 !dev_valid_name(ifname))
0092 goto err_no_cmd;
0093
0094 if (command[0] == '+') {
0095 pr_info("%s is being created...\n", ifname);
0096 rv = bond_create(bn->net, ifname);
0097 if (rv) {
0098 if (rv == -EEXIST)
0099 pr_info("%s already exists\n", ifname);
0100 else
0101 pr_info("%s creation failed\n", ifname);
0102 res = rv;
0103 }
0104 } else if (command[0] == '-') {
0105 struct net_device *bond_dev;
0106
0107 rtnl_lock();
0108 bond_dev = bond_get_by_name(bn, ifname);
0109 if (bond_dev) {
0110 pr_info("%s is being deleted...\n", ifname);
0111 unregister_netdevice(bond_dev);
0112 } else {
0113 pr_err("unable to delete non-existent %s\n", ifname);
0114 res = -ENODEV;
0115 }
0116 rtnl_unlock();
0117 } else
0118 goto err_no_cmd;
0119
0120
0121
0122
0123 return res;
0124
0125 err_no_cmd:
0126 pr_err("no command found in bonding_masters - use +ifname or -ifname\n");
0127 return -EPERM;
0128 }
0129
0130
0131 static const struct class_attribute class_attr_bonding_masters = {
0132 .attr = {
0133 .name = "bonding_masters",
0134 .mode = 0644,
0135 },
0136 .show = bonding_show_bonds,
0137 .store = bonding_store_bonds,
0138 };
0139
0140
0141 static ssize_t bonding_sysfs_store_option(struct device *d,
0142 struct device_attribute *attr,
0143 const char *buffer, size_t count)
0144 {
0145 struct bonding *bond = to_bond(d);
0146 const struct bond_option *opt;
0147 char *buffer_clone;
0148 int ret;
0149
0150 opt = bond_opt_get_by_name(attr->attr.name);
0151 if (WARN_ON(!opt))
0152 return -ENOENT;
0153 buffer_clone = kstrndup(buffer, count, GFP_KERNEL);
0154 if (!buffer_clone)
0155 return -ENOMEM;
0156 ret = bond_opt_tryset_rtnl(bond, opt->id, buffer_clone);
0157 if (!ret)
0158 ret = count;
0159 kfree(buffer_clone);
0160
0161 return ret;
0162 }
0163
0164
0165 static ssize_t bonding_show_slaves(struct device *d,
0166 struct device_attribute *attr, char *buf)
0167 {
0168 struct bonding *bond = to_bond(d);
0169 struct list_head *iter;
0170 struct slave *slave;
0171 int res = 0;
0172
0173 if (!rtnl_trylock())
0174 return restart_syscall();
0175
0176 bond_for_each_slave(bond, slave, iter) {
0177 if (res > (PAGE_SIZE - IFNAMSIZ)) {
0178
0179 if ((PAGE_SIZE - res) > 10)
0180 res = PAGE_SIZE - 10;
0181 res += sprintf(buf + res, "++more++ ");
0182 break;
0183 }
0184 res += sprintf(buf + res, "%s ", slave->dev->name);
0185 }
0186
0187 rtnl_unlock();
0188
0189 if (res)
0190 buf[res-1] = '\n';
0191
0192 return res;
0193 }
0194 static DEVICE_ATTR(slaves, 0644, bonding_show_slaves,
0195 bonding_sysfs_store_option);
0196
0197
0198 static ssize_t bonding_show_mode(struct device *d,
0199 struct device_attribute *attr, char *buf)
0200 {
0201 struct bonding *bond = to_bond(d);
0202 const struct bond_opt_value *val;
0203
0204 val = bond_opt_get_val(BOND_OPT_MODE, BOND_MODE(bond));
0205
0206 return sprintf(buf, "%s %d\n", val->string, BOND_MODE(bond));
0207 }
0208 static DEVICE_ATTR(mode, 0644, bonding_show_mode, bonding_sysfs_store_option);
0209
0210
0211 static ssize_t bonding_show_xmit_hash(struct device *d,
0212 struct device_attribute *attr,
0213 char *buf)
0214 {
0215 struct bonding *bond = to_bond(d);
0216 const struct bond_opt_value *val;
0217
0218 val = bond_opt_get_val(BOND_OPT_XMIT_HASH, bond->params.xmit_policy);
0219
0220 return sprintf(buf, "%s %d\n", val->string, bond->params.xmit_policy);
0221 }
0222 static DEVICE_ATTR(xmit_hash_policy, 0644,
0223 bonding_show_xmit_hash, bonding_sysfs_store_option);
0224
0225
0226 static ssize_t bonding_show_arp_validate(struct device *d,
0227 struct device_attribute *attr,
0228 char *buf)
0229 {
0230 struct bonding *bond = to_bond(d);
0231 const struct bond_opt_value *val;
0232
0233 val = bond_opt_get_val(BOND_OPT_ARP_VALIDATE,
0234 bond->params.arp_validate);
0235
0236 return sprintf(buf, "%s %d\n", val->string, bond->params.arp_validate);
0237 }
0238 static DEVICE_ATTR(arp_validate, 0644, bonding_show_arp_validate,
0239 bonding_sysfs_store_option);
0240
0241
0242 static ssize_t bonding_show_arp_all_targets(struct device *d,
0243 struct device_attribute *attr,
0244 char *buf)
0245 {
0246 struct bonding *bond = to_bond(d);
0247 const struct bond_opt_value *val;
0248
0249 val = bond_opt_get_val(BOND_OPT_ARP_ALL_TARGETS,
0250 bond->params.arp_all_targets);
0251 return sprintf(buf, "%s %d\n",
0252 val->string, bond->params.arp_all_targets);
0253 }
0254 static DEVICE_ATTR(arp_all_targets, 0644,
0255 bonding_show_arp_all_targets, bonding_sysfs_store_option);
0256
0257
0258 static ssize_t bonding_show_fail_over_mac(struct device *d,
0259 struct device_attribute *attr,
0260 char *buf)
0261 {
0262 struct bonding *bond = to_bond(d);
0263 const struct bond_opt_value *val;
0264
0265 val = bond_opt_get_val(BOND_OPT_FAIL_OVER_MAC,
0266 bond->params.fail_over_mac);
0267
0268 return sprintf(buf, "%s %d\n", val->string, bond->params.fail_over_mac);
0269 }
0270 static DEVICE_ATTR(fail_over_mac, 0644,
0271 bonding_show_fail_over_mac, bonding_sysfs_store_option);
0272
0273
0274 static ssize_t bonding_show_arp_interval(struct device *d,
0275 struct device_attribute *attr,
0276 char *buf)
0277 {
0278 struct bonding *bond = to_bond(d);
0279
0280 return sprintf(buf, "%d\n", bond->params.arp_interval);
0281 }
0282 static DEVICE_ATTR(arp_interval, 0644,
0283 bonding_show_arp_interval, bonding_sysfs_store_option);
0284
0285
0286 static ssize_t bonding_show_arp_targets(struct device *d,
0287 struct device_attribute *attr,
0288 char *buf)
0289 {
0290 struct bonding *bond = to_bond(d);
0291 int i, res = 0;
0292
0293 for (i = 0; i < BOND_MAX_ARP_TARGETS; i++) {
0294 if (bond->params.arp_targets[i])
0295 res += sprintf(buf + res, "%pI4 ",
0296 &bond->params.arp_targets[i]);
0297 }
0298 if (res)
0299 buf[res-1] = '\n';
0300
0301 return res;
0302 }
0303 static DEVICE_ATTR(arp_ip_target, 0644,
0304 bonding_show_arp_targets, bonding_sysfs_store_option);
0305
0306
0307 static ssize_t bonding_show_missed_max(struct device *d,
0308 struct device_attribute *attr,
0309 char *buf)
0310 {
0311 struct bonding *bond = to_bond(d);
0312
0313 return sprintf(buf, "%u\n", bond->params.missed_max);
0314 }
0315 static DEVICE_ATTR(arp_missed_max, 0644,
0316 bonding_show_missed_max, bonding_sysfs_store_option);
0317
0318
0319 static ssize_t bonding_show_downdelay(struct device *d,
0320 struct device_attribute *attr,
0321 char *buf)
0322 {
0323 struct bonding *bond = to_bond(d);
0324
0325 return sprintf(buf, "%d\n", bond->params.downdelay * bond->params.miimon);
0326 }
0327 static DEVICE_ATTR(downdelay, 0644,
0328 bonding_show_downdelay, bonding_sysfs_store_option);
0329
0330 static ssize_t bonding_show_updelay(struct device *d,
0331 struct device_attribute *attr,
0332 char *buf)
0333 {
0334 struct bonding *bond = to_bond(d);
0335
0336 return sprintf(buf, "%d\n", bond->params.updelay * bond->params.miimon);
0337
0338 }
0339 static DEVICE_ATTR(updelay, 0644,
0340 bonding_show_updelay, bonding_sysfs_store_option);
0341
0342 static ssize_t bonding_show_peer_notif_delay(struct device *d,
0343 struct device_attribute *attr,
0344 char *buf)
0345 {
0346 struct bonding *bond = to_bond(d);
0347
0348 return sprintf(buf, "%d\n",
0349 bond->params.peer_notif_delay * bond->params.miimon);
0350 }
0351 static DEVICE_ATTR(peer_notif_delay, 0644,
0352 bonding_show_peer_notif_delay, bonding_sysfs_store_option);
0353
0354
0355 static ssize_t bonding_show_lacp_active(struct device *d,
0356 struct device_attribute *attr,
0357 char *buf)
0358 {
0359 struct bonding *bond = to_bond(d);
0360 const struct bond_opt_value *val;
0361
0362 val = bond_opt_get_val(BOND_OPT_LACP_ACTIVE, bond->params.lacp_active);
0363
0364 return sprintf(buf, "%s %d\n", val->string, bond->params.lacp_active);
0365 }
0366 static DEVICE_ATTR(lacp_active, 0644,
0367 bonding_show_lacp_active, bonding_sysfs_store_option);
0368
0369 static ssize_t bonding_show_lacp_rate(struct device *d,
0370 struct device_attribute *attr,
0371 char *buf)
0372 {
0373 struct bonding *bond = to_bond(d);
0374 const struct bond_opt_value *val;
0375
0376 val = bond_opt_get_val(BOND_OPT_LACP_RATE, bond->params.lacp_fast);
0377
0378 return sprintf(buf, "%s %d\n", val->string, bond->params.lacp_fast);
0379 }
0380 static DEVICE_ATTR(lacp_rate, 0644,
0381 bonding_show_lacp_rate, bonding_sysfs_store_option);
0382
0383 static ssize_t bonding_show_min_links(struct device *d,
0384 struct device_attribute *attr,
0385 char *buf)
0386 {
0387 struct bonding *bond = to_bond(d);
0388
0389 return sprintf(buf, "%u\n", bond->params.min_links);
0390 }
0391 static DEVICE_ATTR(min_links, 0644,
0392 bonding_show_min_links, bonding_sysfs_store_option);
0393
0394 static ssize_t bonding_show_ad_select(struct device *d,
0395 struct device_attribute *attr,
0396 char *buf)
0397 {
0398 struct bonding *bond = to_bond(d);
0399 const struct bond_opt_value *val;
0400
0401 val = bond_opt_get_val(BOND_OPT_AD_SELECT, bond->params.ad_select);
0402
0403 return sprintf(buf, "%s %d\n", val->string, bond->params.ad_select);
0404 }
0405 static DEVICE_ATTR(ad_select, 0644,
0406 bonding_show_ad_select, bonding_sysfs_store_option);
0407
0408
0409 static ssize_t bonding_show_num_peer_notif(struct device *d,
0410 struct device_attribute *attr,
0411 char *buf)
0412 {
0413 struct bonding *bond = to_bond(d);
0414
0415 return sprintf(buf, "%d\n", bond->params.num_peer_notif);
0416 }
0417 static DEVICE_ATTR(num_grat_arp, 0644,
0418 bonding_show_num_peer_notif, bonding_sysfs_store_option);
0419 static DEVICE_ATTR(num_unsol_na, 0644,
0420 bonding_show_num_peer_notif, bonding_sysfs_store_option);
0421
0422
0423 static ssize_t bonding_show_miimon(struct device *d,
0424 struct device_attribute *attr,
0425 char *buf)
0426 {
0427 struct bonding *bond = to_bond(d);
0428
0429 return sprintf(buf, "%d\n", bond->params.miimon);
0430 }
0431 static DEVICE_ATTR(miimon, 0644,
0432 bonding_show_miimon, bonding_sysfs_store_option);
0433
0434
0435 static ssize_t bonding_show_primary(struct device *d,
0436 struct device_attribute *attr,
0437 char *buf)
0438 {
0439 struct bonding *bond = to_bond(d);
0440 struct slave *primary;
0441 int count = 0;
0442
0443 rcu_read_lock();
0444 primary = rcu_dereference(bond->primary_slave);
0445 if (primary)
0446 count = sprintf(buf, "%s\n", primary->dev->name);
0447 rcu_read_unlock();
0448
0449 return count;
0450 }
0451 static DEVICE_ATTR(primary, 0644,
0452 bonding_show_primary, bonding_sysfs_store_option);
0453
0454
0455 static ssize_t bonding_show_primary_reselect(struct device *d,
0456 struct device_attribute *attr,
0457 char *buf)
0458 {
0459 struct bonding *bond = to_bond(d);
0460 const struct bond_opt_value *val;
0461
0462 val = bond_opt_get_val(BOND_OPT_PRIMARY_RESELECT,
0463 bond->params.primary_reselect);
0464
0465 return sprintf(buf, "%s %d\n",
0466 val->string, bond->params.primary_reselect);
0467 }
0468 static DEVICE_ATTR(primary_reselect, 0644,
0469 bonding_show_primary_reselect, bonding_sysfs_store_option);
0470
0471
0472 static ssize_t bonding_show_carrier(struct device *d,
0473 struct device_attribute *attr,
0474 char *buf)
0475 {
0476 struct bonding *bond = to_bond(d);
0477
0478 return sprintf(buf, "%d\n", bond->params.use_carrier);
0479 }
0480 static DEVICE_ATTR(use_carrier, 0644,
0481 bonding_show_carrier, bonding_sysfs_store_option);
0482
0483
0484
0485 static ssize_t bonding_show_active_slave(struct device *d,
0486 struct device_attribute *attr,
0487 char *buf)
0488 {
0489 struct bonding *bond = to_bond(d);
0490 struct net_device *slave_dev;
0491 int count = 0;
0492
0493 rcu_read_lock();
0494 slave_dev = bond_option_active_slave_get_rcu(bond);
0495 if (slave_dev)
0496 count = sprintf(buf, "%s\n", slave_dev->name);
0497 rcu_read_unlock();
0498
0499 return count;
0500 }
0501 static DEVICE_ATTR(active_slave, 0644,
0502 bonding_show_active_slave, bonding_sysfs_store_option);
0503
0504
0505 static ssize_t bonding_show_mii_status(struct device *d,
0506 struct device_attribute *attr,
0507 char *buf)
0508 {
0509 struct bonding *bond = to_bond(d);
0510 bool active = netif_carrier_ok(bond->dev);
0511
0512 return sprintf(buf, "%s\n", active ? "up" : "down");
0513 }
0514 static DEVICE_ATTR(mii_status, 0444, bonding_show_mii_status, NULL);
0515
0516
0517 static ssize_t bonding_show_ad_aggregator(struct device *d,
0518 struct device_attribute *attr,
0519 char *buf)
0520 {
0521 int count = 0;
0522 struct bonding *bond = to_bond(d);
0523
0524 if (BOND_MODE(bond) == BOND_MODE_8023AD) {
0525 struct ad_info ad_info;
0526
0527 count = sprintf(buf, "%d\n",
0528 bond_3ad_get_active_agg_info(bond, &ad_info)
0529 ? 0 : ad_info.aggregator_id);
0530 }
0531
0532 return count;
0533 }
0534 static DEVICE_ATTR(ad_aggregator, 0444, bonding_show_ad_aggregator, NULL);
0535
0536
0537
0538 static ssize_t bonding_show_ad_num_ports(struct device *d,
0539 struct device_attribute *attr,
0540 char *buf)
0541 {
0542 int count = 0;
0543 struct bonding *bond = to_bond(d);
0544
0545 if (BOND_MODE(bond) == BOND_MODE_8023AD) {
0546 struct ad_info ad_info;
0547
0548 count = sprintf(buf, "%d\n",
0549 bond_3ad_get_active_agg_info(bond, &ad_info)
0550 ? 0 : ad_info.ports);
0551 }
0552
0553 return count;
0554 }
0555 static DEVICE_ATTR(ad_num_ports, 0444, bonding_show_ad_num_ports, NULL);
0556
0557
0558
0559 static ssize_t bonding_show_ad_actor_key(struct device *d,
0560 struct device_attribute *attr,
0561 char *buf)
0562 {
0563 int count = 0;
0564 struct bonding *bond = to_bond(d);
0565
0566 if (BOND_MODE(bond) == BOND_MODE_8023AD && capable(CAP_NET_ADMIN)) {
0567 struct ad_info ad_info;
0568
0569 count = sprintf(buf, "%d\n",
0570 bond_3ad_get_active_agg_info(bond, &ad_info)
0571 ? 0 : ad_info.actor_key);
0572 }
0573
0574 return count;
0575 }
0576 static DEVICE_ATTR(ad_actor_key, 0444, bonding_show_ad_actor_key, NULL);
0577
0578
0579
0580 static ssize_t bonding_show_ad_partner_key(struct device *d,
0581 struct device_attribute *attr,
0582 char *buf)
0583 {
0584 int count = 0;
0585 struct bonding *bond = to_bond(d);
0586
0587 if (BOND_MODE(bond) == BOND_MODE_8023AD && capable(CAP_NET_ADMIN)) {
0588 struct ad_info ad_info;
0589
0590 count = sprintf(buf, "%d\n",
0591 bond_3ad_get_active_agg_info(bond, &ad_info)
0592 ? 0 : ad_info.partner_key);
0593 }
0594
0595 return count;
0596 }
0597 static DEVICE_ATTR(ad_partner_key, 0444, bonding_show_ad_partner_key, NULL);
0598
0599
0600
0601 static ssize_t bonding_show_ad_partner_mac(struct device *d,
0602 struct device_attribute *attr,
0603 char *buf)
0604 {
0605 int count = 0;
0606 struct bonding *bond = to_bond(d);
0607
0608 if (BOND_MODE(bond) == BOND_MODE_8023AD && capable(CAP_NET_ADMIN)) {
0609 struct ad_info ad_info;
0610
0611 if (!bond_3ad_get_active_agg_info(bond, &ad_info))
0612 count = sprintf(buf, "%pM\n", ad_info.partner_system);
0613 }
0614
0615 return count;
0616 }
0617 static DEVICE_ATTR(ad_partner_mac, 0444, bonding_show_ad_partner_mac, NULL);
0618
0619
0620 static ssize_t bonding_show_queue_id(struct device *d,
0621 struct device_attribute *attr,
0622 char *buf)
0623 {
0624 struct bonding *bond = to_bond(d);
0625 struct list_head *iter;
0626 struct slave *slave;
0627 int res = 0;
0628
0629 if (!rtnl_trylock())
0630 return restart_syscall();
0631
0632 bond_for_each_slave(bond, slave, iter) {
0633 if (res > (PAGE_SIZE - IFNAMSIZ - 6)) {
0634
0635 if ((PAGE_SIZE - res) > 10)
0636 res = PAGE_SIZE - 10;
0637 res += sprintf(buf + res, "++more++ ");
0638 break;
0639 }
0640 res += sprintf(buf + res, "%s:%d ",
0641 slave->dev->name, slave->queue_id);
0642 }
0643 if (res)
0644 buf[res-1] = '\n';
0645
0646 rtnl_unlock();
0647
0648 return res;
0649 }
0650 static DEVICE_ATTR(queue_id, 0644, bonding_show_queue_id,
0651 bonding_sysfs_store_option);
0652
0653
0654
0655 static ssize_t bonding_show_slaves_active(struct device *d,
0656 struct device_attribute *attr,
0657 char *buf)
0658 {
0659 struct bonding *bond = to_bond(d);
0660
0661 return sprintf(buf, "%d\n", bond->params.all_slaves_active);
0662 }
0663 static DEVICE_ATTR(all_slaves_active, 0644,
0664 bonding_show_slaves_active, bonding_sysfs_store_option);
0665
0666
0667 static ssize_t bonding_show_resend_igmp(struct device *d,
0668 struct device_attribute *attr,
0669 char *buf)
0670 {
0671 struct bonding *bond = to_bond(d);
0672
0673 return sprintf(buf, "%d\n", bond->params.resend_igmp);
0674 }
0675 static DEVICE_ATTR(resend_igmp, 0644,
0676 bonding_show_resend_igmp, bonding_sysfs_store_option);
0677
0678
0679 static ssize_t bonding_show_lp_interval(struct device *d,
0680 struct device_attribute *attr,
0681 char *buf)
0682 {
0683 struct bonding *bond = to_bond(d);
0684
0685 return sprintf(buf, "%d\n", bond->params.lp_interval);
0686 }
0687 static DEVICE_ATTR(lp_interval, 0644,
0688 bonding_show_lp_interval, bonding_sysfs_store_option);
0689
0690 static ssize_t bonding_show_tlb_dynamic_lb(struct device *d,
0691 struct device_attribute *attr,
0692 char *buf)
0693 {
0694 struct bonding *bond = to_bond(d);
0695
0696 return sprintf(buf, "%d\n", bond->params.tlb_dynamic_lb);
0697 }
0698 static DEVICE_ATTR(tlb_dynamic_lb, 0644,
0699 bonding_show_tlb_dynamic_lb, bonding_sysfs_store_option);
0700
0701 static ssize_t bonding_show_packets_per_slave(struct device *d,
0702 struct device_attribute *attr,
0703 char *buf)
0704 {
0705 struct bonding *bond = to_bond(d);
0706 unsigned int packets_per_slave = bond->params.packets_per_slave;
0707
0708 return sprintf(buf, "%u\n", packets_per_slave);
0709 }
0710 static DEVICE_ATTR(packets_per_slave, 0644,
0711 bonding_show_packets_per_slave, bonding_sysfs_store_option);
0712
0713 static ssize_t bonding_show_ad_actor_sys_prio(struct device *d,
0714 struct device_attribute *attr,
0715 char *buf)
0716 {
0717 struct bonding *bond = to_bond(d);
0718
0719 if (BOND_MODE(bond) == BOND_MODE_8023AD && capable(CAP_NET_ADMIN))
0720 return sprintf(buf, "%hu\n", bond->params.ad_actor_sys_prio);
0721
0722 return 0;
0723 }
0724 static DEVICE_ATTR(ad_actor_sys_prio, 0644,
0725 bonding_show_ad_actor_sys_prio, bonding_sysfs_store_option);
0726
0727 static ssize_t bonding_show_ad_actor_system(struct device *d,
0728 struct device_attribute *attr,
0729 char *buf)
0730 {
0731 struct bonding *bond = to_bond(d);
0732
0733 if (BOND_MODE(bond) == BOND_MODE_8023AD && capable(CAP_NET_ADMIN))
0734 return sprintf(buf, "%pM\n", bond->params.ad_actor_system);
0735
0736 return 0;
0737 }
0738
0739 static DEVICE_ATTR(ad_actor_system, 0644,
0740 bonding_show_ad_actor_system, bonding_sysfs_store_option);
0741
0742 static ssize_t bonding_show_ad_user_port_key(struct device *d,
0743 struct device_attribute *attr,
0744 char *buf)
0745 {
0746 struct bonding *bond = to_bond(d);
0747
0748 if (BOND_MODE(bond) == BOND_MODE_8023AD && capable(CAP_NET_ADMIN))
0749 return sprintf(buf, "%hu\n", bond->params.ad_user_port_key);
0750
0751 return 0;
0752 }
0753 static DEVICE_ATTR(ad_user_port_key, 0644,
0754 bonding_show_ad_user_port_key, bonding_sysfs_store_option);
0755
0756 static struct attribute *per_bond_attrs[] = {
0757 &dev_attr_slaves.attr,
0758 &dev_attr_mode.attr,
0759 &dev_attr_fail_over_mac.attr,
0760 &dev_attr_arp_validate.attr,
0761 &dev_attr_arp_all_targets.attr,
0762 &dev_attr_arp_interval.attr,
0763 &dev_attr_arp_ip_target.attr,
0764 &dev_attr_downdelay.attr,
0765 &dev_attr_updelay.attr,
0766 &dev_attr_peer_notif_delay.attr,
0767 &dev_attr_lacp_active.attr,
0768 &dev_attr_lacp_rate.attr,
0769 &dev_attr_ad_select.attr,
0770 &dev_attr_xmit_hash_policy.attr,
0771 &dev_attr_num_grat_arp.attr,
0772 &dev_attr_num_unsol_na.attr,
0773 &dev_attr_miimon.attr,
0774 &dev_attr_primary.attr,
0775 &dev_attr_primary_reselect.attr,
0776 &dev_attr_use_carrier.attr,
0777 &dev_attr_active_slave.attr,
0778 &dev_attr_mii_status.attr,
0779 &dev_attr_ad_aggregator.attr,
0780 &dev_attr_ad_num_ports.attr,
0781 &dev_attr_ad_actor_key.attr,
0782 &dev_attr_ad_partner_key.attr,
0783 &dev_attr_ad_partner_mac.attr,
0784 &dev_attr_queue_id.attr,
0785 &dev_attr_all_slaves_active.attr,
0786 &dev_attr_resend_igmp.attr,
0787 &dev_attr_min_links.attr,
0788 &dev_attr_lp_interval.attr,
0789 &dev_attr_packets_per_slave.attr,
0790 &dev_attr_tlb_dynamic_lb.attr,
0791 &dev_attr_ad_actor_sys_prio.attr,
0792 &dev_attr_ad_actor_system.attr,
0793 &dev_attr_ad_user_port_key.attr,
0794 &dev_attr_arp_missed_max.attr,
0795 NULL,
0796 };
0797
0798 static const struct attribute_group bonding_group = {
0799 .name = "bonding",
0800 .attrs = per_bond_attrs,
0801 };
0802
0803
0804
0805
0806 int bond_create_sysfs(struct bond_net *bn)
0807 {
0808 int ret;
0809
0810 bn->class_attr_bonding_masters = class_attr_bonding_masters;
0811 sysfs_attr_init(&bn->class_attr_bonding_masters.attr);
0812
0813 ret = netdev_class_create_file_ns(&bn->class_attr_bonding_masters,
0814 bn->net);
0815
0816
0817
0818
0819
0820
0821
0822
0823
0824
0825 if (ret == -EEXIST) {
0826
0827 if (netdev_name_in_use(bn->net,
0828 class_attr_bonding_masters.attr.name))
0829 pr_err("network device named %s already exists in sysfs\n",
0830 class_attr_bonding_masters.attr.name);
0831 ret = 0;
0832 }
0833
0834 return ret;
0835
0836 }
0837
0838
0839 void bond_destroy_sysfs(struct bond_net *bn)
0840 {
0841 netdev_class_remove_file_ns(&bn->class_attr_bonding_masters, bn->net);
0842 }
0843
0844
0845
0846
0847 void bond_prepare_sysfs_group(struct bonding *bond)
0848 {
0849 bond->dev->sysfs_groups[0] = &bonding_group;
0850 }
0851