ar-proc.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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 *rxrpc_conn_states[] = {
  16. [RXRPC_CONN_UNUSED] = "Unused ",
  17. [RXRPC_CONN_CLIENT] = "Client ",
  18. [RXRPC_CONN_SERVER_UNSECURED] = "SvUnsec ",
  19. [RXRPC_CONN_SERVER_CHALLENGING] = "SvChall ",
  20. [RXRPC_CONN_SERVER] = "SvSecure",
  21. [RXRPC_CONN_REMOTELY_ABORTED] = "RmtAbort",
  22. [RXRPC_CONN_LOCALLY_ABORTED] = "LocAbort",
  23. [RXRPC_CONN_NETWORK_ERROR] = "NetError",
  24. };
  25. const char *rxrpc_call_states[] = {
  26. [RXRPC_CALL_CLIENT_SEND_REQUEST] = "ClSndReq",
  27. [RXRPC_CALL_CLIENT_AWAIT_REPLY] = "ClAwtRpl",
  28. [RXRPC_CALL_CLIENT_RECV_REPLY] = "ClRcvRpl",
  29. [RXRPC_CALL_CLIENT_FINAL_ACK] = "ClFnlACK",
  30. [RXRPC_CALL_SERVER_SECURING] = "SvSecure",
  31. [RXRPC_CALL_SERVER_ACCEPTING] = "SvAccept",
  32. [RXRPC_CALL_SERVER_RECV_REQUEST] = "SvRcvReq",
  33. [RXRPC_CALL_SERVER_ACK_REQUEST] = "SvAckReq",
  34. [RXRPC_CALL_SERVER_SEND_REPLY] = "SvSndRpl",
  35. [RXRPC_CALL_SERVER_AWAIT_ACK] = "SvAwtACK",
  36. [RXRPC_CALL_COMPLETE] = "Complete",
  37. [RXRPC_CALL_SERVER_BUSY] = "SvBusy ",
  38. [RXRPC_CALL_REMOTELY_ABORTED] = "RmtAbort",
  39. [RXRPC_CALL_LOCALLY_ABORTED] = "LocAbort",
  40. [RXRPC_CALL_NETWORK_ERROR] = "NetError",
  41. [RXRPC_CALL_DEAD] = "Dead ",
  42. };
  43. /*
  44. * generate a list of extant and dead calls in /proc/net/rxrpc_calls
  45. */
  46. static void *rxrpc_call_seq_start(struct seq_file *seq, loff_t *_pos)
  47. {
  48. struct list_head *_p;
  49. loff_t pos = *_pos;
  50. read_lock(&rxrpc_call_lock);
  51. if (!pos)
  52. return SEQ_START_TOKEN;
  53. pos--;
  54. list_for_each(_p, &rxrpc_calls)
  55. if (!pos--)
  56. break;
  57. return _p != &rxrpc_calls ? _p : NULL;
  58. }
  59. static void *rxrpc_call_seq_next(struct seq_file *seq, void *v, loff_t *pos)
  60. {
  61. struct list_head *_p;
  62. (*pos)++;
  63. _p = v;
  64. _p = (v == SEQ_START_TOKEN) ? rxrpc_calls.next : _p->next;
  65. return _p != &rxrpc_calls ? _p : NULL;
  66. }
  67. static void rxrpc_call_seq_stop(struct seq_file *seq, void *v)
  68. {
  69. read_unlock(&rxrpc_call_lock);
  70. }
  71. static int rxrpc_call_seq_show(struct seq_file *seq, void *v)
  72. {
  73. struct rxrpc_transport *trans;
  74. struct rxrpc_call *call;
  75. char lbuff[4 + 4 + 4 + 4 + 5 + 1], rbuff[4 + 4 + 4 + 4 + 5 + 1];
  76. if (v == SEQ_START_TOKEN) {
  77. seq_puts(seq,
  78. "Proto Local Remote "
  79. " SvID ConnID CallID End Use State Abort "
  80. " UserID\n");
  81. return 0;
  82. }
  83. call = list_entry(v, struct rxrpc_call, link);
  84. trans = call->conn->trans;
  85. sprintf(lbuff, NIPQUAD_FMT":%u",
  86. NIPQUAD(trans->local->srx.transport.sin.sin_addr),
  87. ntohs(trans->local->srx.transport.sin.sin_port));
  88. sprintf(rbuff, NIPQUAD_FMT":%u",
  89. NIPQUAD(trans->peer->srx.transport.sin.sin_addr),
  90. ntohs(trans->peer->srx.transport.sin.sin_port));
  91. seq_printf(seq,
  92. "UDP %-22.22s %-22.22s %4x %08x %08x %s %3u"
  93. " %-8.8s %08x %lx\n",
  94. lbuff,
  95. rbuff,
  96. ntohs(call->conn->service_id),
  97. ntohl(call->conn->cid),
  98. ntohl(call->call_id),
  99. call->conn->in_clientflag ? "Svc" : "Clt",
  100. atomic_read(&call->usage),
  101. rxrpc_call_states[call->state],
  102. call->abort_code,
  103. call->user_call_ID);
  104. return 0;
  105. }
  106. static struct seq_operations rxrpc_call_seq_ops = {
  107. .start = rxrpc_call_seq_start,
  108. .next = rxrpc_call_seq_next,
  109. .stop = rxrpc_call_seq_stop,
  110. .show = rxrpc_call_seq_show,
  111. };
  112. static int rxrpc_call_seq_open(struct inode *inode, struct file *file)
  113. {
  114. return seq_open(file, &rxrpc_call_seq_ops);
  115. }
  116. struct file_operations rxrpc_call_seq_fops = {
  117. .owner = THIS_MODULE,
  118. .open = rxrpc_call_seq_open,
  119. .read = seq_read,
  120. .llseek = seq_lseek,
  121. .release = seq_release_private,
  122. };
  123. /*
  124. * generate a list of extant virtual connections in /proc/net/rxrpc_conns
  125. */
  126. static void *rxrpc_connection_seq_start(struct seq_file *seq, loff_t *_pos)
  127. {
  128. struct list_head *_p;
  129. loff_t pos = *_pos;
  130. read_lock(&rxrpc_connection_lock);
  131. if (!pos)
  132. return SEQ_START_TOKEN;
  133. pos--;
  134. list_for_each(_p, &rxrpc_connections)
  135. if (!pos--)
  136. break;
  137. return _p != &rxrpc_connections ? _p : NULL;
  138. }
  139. static void *rxrpc_connection_seq_next(struct seq_file *seq, void *v,
  140. loff_t *pos)
  141. {
  142. struct list_head *_p;
  143. (*pos)++;
  144. _p = v;
  145. _p = (v == SEQ_START_TOKEN) ? rxrpc_connections.next : _p->next;
  146. return _p != &rxrpc_connections ? _p : NULL;
  147. }
  148. static void rxrpc_connection_seq_stop(struct seq_file *seq, void *v)
  149. {
  150. read_unlock(&rxrpc_connection_lock);
  151. }
  152. static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
  153. {
  154. struct rxrpc_connection *conn;
  155. struct rxrpc_transport *trans;
  156. char lbuff[4 + 4 + 4 + 4 + 5 + 1], rbuff[4 + 4 + 4 + 4 + 5 + 1];
  157. if (v == SEQ_START_TOKEN) {
  158. seq_puts(seq,
  159. "Proto Local Remote "
  160. " SvID ConnID Calls End Use State Key "
  161. " Serial ISerial\n"
  162. );
  163. return 0;
  164. }
  165. conn = list_entry(v, struct rxrpc_connection, link);
  166. trans = conn->trans;
  167. sprintf(lbuff, NIPQUAD_FMT":%u",
  168. NIPQUAD(trans->local->srx.transport.sin.sin_addr),
  169. ntohs(trans->local->srx.transport.sin.sin_port));
  170. sprintf(rbuff, NIPQUAD_FMT":%u",
  171. NIPQUAD(trans->peer->srx.transport.sin.sin_addr),
  172. ntohs(trans->peer->srx.transport.sin.sin_port));
  173. seq_printf(seq,
  174. "UDP %-22.22s %-22.22s %4x %08x %08x %s %3u"
  175. " %s %08x %08x %08x\n",
  176. lbuff,
  177. rbuff,
  178. ntohs(conn->service_id),
  179. ntohl(conn->cid),
  180. conn->call_counter,
  181. conn->in_clientflag ? "Svc" : "Clt",
  182. atomic_read(&conn->usage),
  183. rxrpc_conn_states[conn->state],
  184. key_serial(conn->key),
  185. atomic_read(&conn->serial),
  186. atomic_read(&conn->hi_serial));
  187. return 0;
  188. }
  189. static struct seq_operations rxrpc_connection_seq_ops = {
  190. .start = rxrpc_connection_seq_start,
  191. .next = rxrpc_connection_seq_next,
  192. .stop = rxrpc_connection_seq_stop,
  193. .show = rxrpc_connection_seq_show,
  194. };
  195. static int rxrpc_connection_seq_open(struct inode *inode, struct file *file)
  196. {
  197. return seq_open(file, &rxrpc_connection_seq_ops);
  198. }
  199. struct file_operations rxrpc_connection_seq_fops = {
  200. .owner = THIS_MODULE,
  201. .open = rxrpc_connection_seq_open,
  202. .read = seq_read,
  203. .llseek = seq_lseek,
  204. .release = seq_release_private,
  205. };