bond_sysfs.c 21 KB

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