bond_procfs.c 8.7 KB

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