bond_procfs.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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 void bond_info_show_slave(struct seq_file *seq,
  124. const struct slave *slave)
  125. {
  126. struct bonding *bond = seq->private;
  127. seq_printf(seq, "\nSlave Interface: %s\n", slave->dev->name);
  128. seq_printf(seq, "MII Status: %s\n",
  129. (slave->link == BOND_LINK_UP) ? "up" : "down");
  130. if (slave->speed == SPEED_UNKNOWN)
  131. seq_printf(seq, "Speed: %s\n", "Unknown");
  132. else
  133. seq_printf(seq, "Speed: %d Mbps\n", slave->speed);
  134. if (slave->duplex == DUPLEX_UNKNOWN)
  135. seq_printf(seq, "Duplex: %s\n", "Unknown");
  136. else
  137. seq_printf(seq, "Duplex: %s\n", slave->duplex ? "full" : "half");
  138. seq_printf(seq, "Link Failure Count: %u\n",
  139. slave->link_failure_count);
  140. seq_printf(seq, "Permanent HW addr: %pM\n", slave->perm_hwaddr);
  141. if (bond->params.mode == BOND_MODE_8023AD) {
  142. const struct aggregator *agg
  143. = SLAVE_AD_INFO(slave).port.aggregator;
  144. if (agg)
  145. seq_printf(seq, "Aggregator ID: %d\n",
  146. agg->aggregator_identifier);
  147. else
  148. seq_puts(seq, "Aggregator ID: N/A\n");
  149. }
  150. seq_printf(seq, "Slave queue ID: %d\n", slave->queue_id);
  151. }
  152. static int bond_info_seq_show(struct seq_file *seq, void *v)
  153. {
  154. if (v == SEQ_START_TOKEN) {
  155. seq_printf(seq, "%s\n", bond_version);
  156. bond_info_show_master(seq);
  157. } else
  158. bond_info_show_slave(seq, v);
  159. return 0;
  160. }
  161. static const struct seq_operations bond_info_seq_ops = {
  162. .start = bond_info_seq_start,
  163. .next = bond_info_seq_next,
  164. .stop = bond_info_seq_stop,
  165. .show = bond_info_seq_show,
  166. };
  167. static int bond_info_open(struct inode *inode, struct file *file)
  168. {
  169. struct seq_file *seq;
  170. struct proc_dir_entry *proc;
  171. int res;
  172. res = seq_open(file, &bond_info_seq_ops);
  173. if (!res) {
  174. /* recover the pointer buried in proc_dir_entry data */
  175. seq = file->private_data;
  176. proc = PDE(inode);
  177. seq->private = proc->data;
  178. }
  179. return res;
  180. }
  181. static const struct file_operations bond_info_fops = {
  182. .owner = THIS_MODULE,
  183. .open = bond_info_open,
  184. .read = seq_read,
  185. .llseek = seq_lseek,
  186. .release = seq_release,
  187. };
  188. void bond_create_proc_entry(struct bonding *bond)
  189. {
  190. struct net_device *bond_dev = bond->dev;
  191. struct bond_net *bn = net_generic(dev_net(bond_dev), bond_net_id);
  192. if (bn->proc_dir) {
  193. bond->proc_entry = proc_create_data(bond_dev->name,
  194. S_IRUGO, bn->proc_dir,
  195. &bond_info_fops, bond);
  196. if (bond->proc_entry == NULL)
  197. pr_warning("Warning: Cannot create /proc/net/%s/%s\n",
  198. DRV_NAME, bond_dev->name);
  199. else
  200. memcpy(bond->proc_file_name, bond_dev->name, IFNAMSIZ);
  201. }
  202. }
  203. void bond_remove_proc_entry(struct bonding *bond)
  204. {
  205. struct net_device *bond_dev = bond->dev;
  206. struct bond_net *bn = net_generic(dev_net(bond_dev), bond_net_id);
  207. if (bn->proc_dir && bond->proc_entry) {
  208. remove_proc_entry(bond->proc_file_name, bn->proc_dir);
  209. memset(bond->proc_file_name, 0, IFNAMSIZ);
  210. bond->proc_entry = NULL;
  211. }
  212. }
  213. /* Create the bonding directory under /proc/net, if doesn't exist yet.
  214. * Caller must hold rtnl_lock.
  215. */
  216. void __net_init bond_create_proc_dir(struct bond_net *bn)
  217. {
  218. if (!bn->proc_dir) {
  219. bn->proc_dir = proc_mkdir(DRV_NAME, bn->net->proc_net);
  220. if (!bn->proc_dir)
  221. pr_warning("Warning: cannot create /proc/net/%s\n",
  222. DRV_NAME);
  223. }
  224. }
  225. /* Destroy the bonding directory under /proc/net, if empty.
  226. * Caller must hold rtnl_lock.
  227. */
  228. void __net_exit bond_destroy_proc_dir(struct bond_net *bn)
  229. {
  230. if (bn->proc_dir) {
  231. remove_proc_entry(DRV_NAME, bn->net->proc_net);
  232. bn->proc_dir = NULL;
  233. }
  234. }