proc.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. /* /proc/net/ support for AF_RXRPC
  2. *
  3. * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
  4. * Written by David Howells (dhowells@redhat.com)
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. */
  11. #include <linux/module.h>
  12. #include <net/sock.h>
  13. #include <net/af_rxrpc.h>
  14. #include "ar-internal.h"
  15. static const char *const rxrpc_conn_states[RXRPC_CONN__NR_STATES] = {
  16. [RXRPC_CONN_UNUSED] = "Unused ",
  17. [RXRPC_CONN_CLIENT] = "Client ",
  18. [RXRPC_CONN_SERVICE_PREALLOC] = "SvPrealc",
  19. [RXRPC_CONN_SERVICE_UNSECURED] = "SvUnsec ",
  20. [RXRPC_CONN_SERVICE_CHALLENGING] = "SvChall ",
  21. [RXRPC_CONN_SERVICE] = "SvSecure",
  22. [RXRPC_CONN_REMOTELY_ABORTED] = "RmtAbort",
  23. [RXRPC_CONN_LOCALLY_ABORTED] = "LocAbort",
  24. };
  25. /*
  26. * generate a list of extant and dead calls in /proc/net/rxrpc_calls
  27. */
  28. static void *rxrpc_call_seq_start(struct seq_file *seq, loff_t *_pos)
  29. {
  30. struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
  31. rcu_read_lock();
  32. read_lock(&rxnet->call_lock);
  33. return seq_list_start_head(&rxnet->calls, *_pos);
  34. }
  35. static void *rxrpc_call_seq_next(struct seq_file *seq, void *v, loff_t *pos)
  36. {
  37. struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
  38. return seq_list_next(v, &rxnet->calls, pos);
  39. }
  40. static void rxrpc_call_seq_stop(struct seq_file *seq, void *v)
  41. {
  42. struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
  43. read_unlock(&rxnet->call_lock);
  44. rcu_read_unlock();
  45. }
  46. static int rxrpc_call_seq_show(struct seq_file *seq, void *v)
  47. {
  48. struct rxrpc_local *local;
  49. struct rxrpc_sock *rx;
  50. struct rxrpc_peer *peer;
  51. struct rxrpc_call *call;
  52. struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
  53. rxrpc_seq_t tx_hard_ack, rx_hard_ack;
  54. char lbuff[50], rbuff[50];
  55. if (v == &rxnet->calls) {
  56. seq_puts(seq,
  57. "Proto Local "
  58. " Remote "
  59. " SvID ConnID CallID End Use State Abort "
  60. " UserID\n");
  61. return 0;
  62. }
  63. call = list_entry(v, struct rxrpc_call, link);
  64. rx = rcu_dereference(call->socket);
  65. if (rx) {
  66. local = READ_ONCE(rx->local);
  67. if (local)
  68. sprintf(lbuff, "%pISpc", &local->srx.transport);
  69. else
  70. strcpy(lbuff, "no_local");
  71. } else {
  72. strcpy(lbuff, "no_socket");
  73. }
  74. peer = call->peer;
  75. if (peer)
  76. sprintf(rbuff, "%pISpc", &peer->srx.transport);
  77. else
  78. strcpy(rbuff, "no_connection");
  79. tx_hard_ack = READ_ONCE(call->tx_hard_ack);
  80. rx_hard_ack = READ_ONCE(call->rx_hard_ack);
  81. seq_printf(seq,
  82. "UDP %-47.47s %-47.47s %4x %08x %08x %s %3u"
  83. " %-8.8s %08x %lx %08x %02x %08x %02x\n",
  84. lbuff,
  85. rbuff,
  86. call->service_id,
  87. call->cid,
  88. call->call_id,
  89. rxrpc_is_service_call(call) ? "Svc" : "Clt",
  90. atomic_read(&call->usage),
  91. rxrpc_call_states[call->state],
  92. call->abort_code,
  93. call->user_call_ID,
  94. tx_hard_ack, READ_ONCE(call->tx_top) - tx_hard_ack,
  95. rx_hard_ack, READ_ONCE(call->rx_top) - rx_hard_ack);
  96. return 0;
  97. }
  98. static const struct seq_operations rxrpc_call_seq_ops = {
  99. .start = rxrpc_call_seq_start,
  100. .next = rxrpc_call_seq_next,
  101. .stop = rxrpc_call_seq_stop,
  102. .show = rxrpc_call_seq_show,
  103. };
  104. static int rxrpc_call_seq_open(struct inode *inode, struct file *file)
  105. {
  106. return seq_open_net(inode, file, &rxrpc_call_seq_ops,
  107. sizeof(struct seq_net_private));
  108. }
  109. const struct file_operations rxrpc_call_seq_fops = {
  110. .owner = THIS_MODULE,
  111. .open = rxrpc_call_seq_open,
  112. .read = seq_read,
  113. .llseek = seq_lseek,
  114. .release = seq_release,
  115. };
  116. /*
  117. * generate a list of extant virtual connections in /proc/net/rxrpc_conns
  118. */
  119. static void *rxrpc_connection_seq_start(struct seq_file *seq, loff_t *_pos)
  120. {
  121. struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
  122. read_lock(&rxnet->conn_lock);
  123. return seq_list_start_head(&rxnet->conn_proc_list, *_pos);
  124. }
  125. static void *rxrpc_connection_seq_next(struct seq_file *seq, void *v,
  126. loff_t *pos)
  127. {
  128. struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
  129. return seq_list_next(v, &rxnet->conn_proc_list, pos);
  130. }
  131. static void rxrpc_connection_seq_stop(struct seq_file *seq, void *v)
  132. {
  133. struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
  134. read_unlock(&rxnet->conn_lock);
  135. }
  136. static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
  137. {
  138. struct rxrpc_connection *conn;
  139. struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
  140. char lbuff[50], rbuff[50];
  141. if (v == &rxnet->conn_proc_list) {
  142. seq_puts(seq,
  143. "Proto Local "
  144. " Remote "
  145. " SvID ConnID End Use State Key "
  146. " Serial ISerial\n"
  147. );
  148. return 0;
  149. }
  150. conn = list_entry(v, struct rxrpc_connection, proc_link);
  151. if (conn->state == RXRPC_CONN_SERVICE_PREALLOC) {
  152. strcpy(lbuff, "no_local");
  153. strcpy(rbuff, "no_connection");
  154. goto print;
  155. }
  156. sprintf(lbuff, "%pISpc", &conn->params.local->srx.transport);
  157. sprintf(rbuff, "%pISpc", &conn->params.peer->srx.transport);
  158. print:
  159. seq_printf(seq,
  160. "UDP %-47.47s %-47.47s %4x %08x %s %3u"
  161. " %s %08x %08x %08x\n",
  162. lbuff,
  163. rbuff,
  164. conn->service_id,
  165. conn->proto.cid,
  166. rxrpc_conn_is_service(conn) ? "Svc" : "Clt",
  167. atomic_read(&conn->usage),
  168. rxrpc_conn_states[conn->state],
  169. key_serial(conn->params.key),
  170. atomic_read(&conn->serial),
  171. conn->hi_serial);
  172. return 0;
  173. }
  174. static const struct seq_operations rxrpc_connection_seq_ops = {
  175. .start = rxrpc_connection_seq_start,
  176. .next = rxrpc_connection_seq_next,
  177. .stop = rxrpc_connection_seq_stop,
  178. .show = rxrpc_connection_seq_show,
  179. };
  180. static int rxrpc_connection_seq_open(struct inode *inode, struct file *file)
  181. {
  182. return seq_open_net(inode, file, &rxrpc_connection_seq_ops,
  183. sizeof(struct seq_net_private));
  184. }
  185. const struct file_operations rxrpc_connection_seq_fops = {
  186. .owner = THIS_MODULE,
  187. .open = rxrpc_connection_seq_open,
  188. .read = seq_read,
  189. .llseek = seq_lseek,
  190. .release = seq_release,
  191. };