bond_procfs.c 9.0 KB

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