bond_procfs.c 7.5 KB

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