/drivers/net/bonding/bond_sysfs.c

http://github.com/mirrors/linux · C · 816 lines · 621 code · 132 blank · 63 comment · 58 complexity · c2329a9fed9a577fcb70f61d67de2786 MD5 · raw file

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