bond_procfs.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. #include <linux/proc_fs.h>
  2. #include <linux/export.h>
  3. #include <net/net_namespace.h>
  4. #include <net/netns/generic.h>
  5. #include "bonding.h"
  6. static void *bond_info_seq_start(struct seq_file *seq, loff_t *pos)
  7. __acquires(RCU)
  8. __acquires(&bond->lock)
  9. {
  10. struct bonding *bond = seq->private;
  11. loff_t off = 0;
  12. struct slave *slave;
  13. int i;
  14. /* make sure the bond won't be taken away */
  15. rcu_read_lock();
  16. read_lock(&bond->lock);
  17. if (*pos == 0)
  18. return SEQ_START_TOKEN;
  19. bond_for_each_slave(bond, slave, i) {
  20. if (++off == *pos)
  21. return slave;
  22. }
  23. return NULL;
  24. }
  25. static void *bond_info_seq_next(struct seq_file *seq, void *v, loff_t *pos)
  26. {
  27. struct bonding *bond = seq->private;
  28. struct slave *slave = v;
  29. ++*pos;
  30. if (v == SEQ_START_TOKEN)
  31. return bond->first_slave;
  32. slave = slave->next;
  33. return (slave == bond->first_slave) ? NULL : slave;
  34. }
  35. static void bond_info_seq_stop(struct seq_file *seq, void *v)
  36. __releases(&bond->lock)
  37. __releases(RCU)
  38. {
  39. struct bonding *bond = seq->private;
  40. read_unlock(&bond->lock);
  41. rcu_read_unlock();
  42. }
  43. static void bond_info_show_master(struct seq_file *seq)
  44. {
  45. struct bonding *bond = seq->private;
  46. struct slave *curr;
  47. int i;
  48. read_lock(&bond->curr_slave_lock);
  49. curr = bond->curr_active_slave;
  50. read_unlock(&bond->curr_slave_lock);
  51. seq_printf(seq, "Bonding Mode: %s",
  52. bond_mode_name(bond->params.mode));
  53. if (bond->params.mode == BOND_MODE_ACTIVEBACKUP &&
  54. bond->params.fail_over_mac)
  55. seq_printf(seq, " (fail_over_mac %s)",
  56. fail_over_mac_tbl[bond->params.fail_over_mac].modename);
  57. seq_printf(seq, "\n");
  58. if (bond->params.mode == BOND_MODE_XOR ||
  59. bond->params.mode == BOND_MODE_8023AD) {
  60. seq_printf(seq, "Transmit Hash Policy: %s (%d)\n",
  61. xmit_hashtype_tbl[bond->params.xmit_policy].modename,
  62. bond->params.xmit_policy);
  63. }
  64. if (USES_PRIMARY(bond->params.mode)) {
  65. seq_printf(seq, "Primary Slave: %s",
  66. (bond->primary_slave) ?
  67. bond->primary_slave->dev->name : "None");
  68. if (bond->primary_slave)
  69. seq_printf(seq, " (primary_reselect %s)",
  70. pri_reselect_tbl[bond->params.primary_reselect].modename);
  71. seq_printf(seq, "\nCurrently Active Slave: %s\n",
  72. (curr) ? curr->dev->name : "None");
  73. }
  74. seq_printf(seq, "MII Status: %s\n", netif_carrier_ok(bond->dev) ?
  75. "up" : "down");
  76. seq_printf(seq, "MII Polling Interval (ms): %d\n", bond->params.miimon);
  77. seq_printf(seq, "Up Delay (ms): %d\n",
  78. bond->params.updelay * bond->params.miimon);
  79. seq_printf(seq, "Down Delay (ms): %d\n",
  80. bond->params.downdelay * bond->params.miimon);
  81. /* ARP information */
  82. if (bond->params.arp_interval > 0) {
  83. int printed = 0;
  84. seq_printf(seq, "ARP Polling Interval (ms): %d\n",
  85. bond->params.arp_interval);
  86. seq_printf(seq, "ARP IP target/s (n.n.n.n form):");
  87. for (i = 0; (i < BOND_MAX_ARP_TARGETS); i++) {
  88. if (!bond->params.arp_targets[i])
  89. break;
  90. if (printed)
  91. seq_printf(seq, ",");
  92. seq_printf(seq, " %pI4", &bond->params.arp_targets[i]);
  93. printed = 1;
  94. }
  95. seq_printf(seq, "\n");
  96. }
  97. if (bond->params.mode == BOND_MODE_8023AD) {
  98. struct ad_info ad_info;
  99. seq_puts(seq, "\n802.3ad info\n");
  100. seq_printf(seq, "LACP rate: %s\n",
  101. (bond->params.lacp_fast) ? "fast" : "slow");
  102. seq_printf(seq, "Min links: %d\n", bond->params.min_links);
  103. seq_printf(seq, "Aggregator selection policy (ad_select): %s\n",
  104. ad_select_tbl[bond->params.ad_select].modename);
  105. if (bond_3ad_get_active_agg_info(bond, &ad_info)) {
  106. seq_printf(seq, "bond %s has no active aggregator\n",
  107. bond->dev->name);
  108. } else {
  109. seq_printf(seq, "Active Aggregator Info:\n");
  110. seq_printf(seq, "\tAggregator ID: %d\n",
  111. ad_info.aggregator_id);
  112. seq_printf(seq, "\tNumber of ports: %d\n",
  113. ad_info.ports);
  114. seq_printf(seq, "\tActor Key: %d\n",
  115. ad_info.actor_key);
  116. seq_printf(seq, "\tPartner Key: %d\n",
  117. ad_info.partner_key);
  118. seq_printf(seq, "\tPartner Mac Address: %pM\n",
  119. ad_info.partner_system);
  120. }
  121. }
  122. }
  123. static const char *bond_slave_link_status(s8 link)
  124. {
  125. static const char * const status[] = {
  126. [BOND_LINK_UP] = "up",
  127. [BOND_LINK_FAIL] = "going down",
  128. [BOND_LINK_DOWN] = "down",
  129. [BOND_LINK_BACK] = "going back",
  130. };
  131. return status[link];
  132. }
  133. static void bond_info_show_slave(struct seq_file *seq,
  134. const struct slave *slave)
  135. {
  136. struct bonding *bond = seq->private;
  137. seq_printf(seq, "\nSlave Interface: %s\n", slave->dev->name);
  138. seq_printf(seq, "MII Status: %s\n", bond_slave_link_status(slave->link));
  139. if (slave->speed == SPEED_UNKNOWN)
  140. seq_printf(seq, "Speed: %s\n", "Unknown");
  141. else
  142. seq_printf(seq, "Speed: %d Mbps\n", slave->speed);
  143. if (slave->duplex == DUPLEX_UNKNOWN)
  144. seq_printf(seq, "Duplex: %s\n", "Unknown");
  145. else
  146. seq_printf(seq, "Duplex: %s\n", slave->duplex ? "full" : "half");
  147. seq_printf(seq, "Link Failure Count: %u\n",
  148. slave->link_failure_count);
  149. seq_printf(seq, "Permanent HW addr: %pM\n", slave->perm_hwaddr);
  150. if (bond->params.mode == BOND_MODE_8023AD) {
  151. const struct aggregator *agg
  152. = SLAVE_AD_INFO(slave).port.aggregator;
  153. if (agg)
  154. seq_printf(seq, "Aggregator ID: %d\n",
  155. agg->aggregator_identifier);
  156. else
  157. seq_puts(seq, "Aggregator ID: N/A\n");
  158. }
  159. seq_printf(seq, "Slave queue ID: %d\n", slave->queue_id);
  160. }
  161. static int bond_info_seq_show(struct seq_file *seq, void *v)
  162. {
  163. if (v == SEQ_START_TOKEN) {
  164. seq_printf(seq, "%s\n", bond_version);
  165. bond_info_show_master(seq);
  166. } else
  167. bond_info_show_slave(seq, v);
  168. return 0;
  169. }
  170. static const struct seq_operations bond_info_seq_ops = {
  171. .start = bond_info_seq_start,
  172. .next = bond_info_seq_next,
  173. .stop = bond_info_seq_stop,
  174. .show = bond_info_seq_show,
  175. };
  176. static int bond_info_open(struct inode *inode, struct file *file)
  177. {
  178. struct seq_file *seq;
  179. struct proc_dir_entry *proc;
  180. int res;
  181. res = seq_open(file, &bond_info_seq_ops);
  182. if (!res) {
  183. /* recover the pointer buried in proc_dir_entry data */
  184. seq = file->private_data;
  185. proc = PDE(inode);
  186. seq->private = proc->data;
  187. }
  188. return res;
  189. }
  190. static const struct file_operations bond_info_fops = {
  191. .owner = THIS_MODULE,
  192. .open = bond_info_open,
  193. .read = seq_read,
  194. .llseek = seq_lseek,
  195. .release = seq_release,
  196. };
  197. void bond_create_proc_entry(struct bonding *bond)
  198. {
  199. struct net_device *bond_dev = bond->dev;
  200. struct bond_net *bn = net_generic(dev_net(bond_dev), bond_net_id);
  201. if (bn->proc_dir) {
  202. bond->proc_entry = proc_create_data(bond_dev->name,
  203. S_IRUGO, bn->proc_dir,
  204. &bond_info_fops, bond);
  205. if (bond->proc_entry == NULL)
  206. pr_warning("Warning: Cannot create /proc/net/%s/%s\n",
  207. DRV_NAME, bond_dev->name);
  208. else
  209. memcpy(bond->proc_file_name, bond_dev->name, IFNAMSIZ);
  210. }
  211. }
  212. void bond_remove_proc_entry(struct bonding *bond)
  213. {
  214. struct net_device *bond_dev = bond->dev;
  215. struct bond_net *bn = net_generic(dev_net(bond_dev), bond_net_id);
  216. if (bn->proc_dir && bond->proc_entry) {
  217. remove_proc_entry(bond->proc_file_name, bn->proc_dir);
  218. memset(bond->proc_file_name, 0, IFNAMSIZ);
  219. bond->proc_entry = NULL;
  220. }
  221. }
  222. /* Create the bonding directory under /proc/net, if doesn't exist yet.
  223. * Caller must hold rtnl_lock.
  224. */
  225. void __net_init bond_create_proc_dir(struct bond_net *bn)
  226. {
  227. if (!bn->proc_dir) {
  228. bn->proc_dir = proc_mkdir(DRV_NAME, bn->net->proc_net);
  229. if (!bn->proc_dir)
  230. pr_warning("Warning: cannot create /proc/net/%s\n",
  231. DRV_NAME);
  232. }
  233. }
  234. /* Destroy the bonding directory under /proc/net, if empty.
  235. * Caller must hold rtnl_lock.
  236. */
  237. void __net_exit bond_destroy_proc_dir(struct bond_net *bn)
  238. {
  239. if (bn->proc_dir) {
  240. remove_proc_entry(DRV_NAME, bn->net->proc_net);
  241. bn->proc_dir = NULL;
  242. }
  243. }