ar-proc.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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. /*
  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 list_head *_p;
  31. loff_t pos = *_pos;
  32. read_lock(&rxrpc_call_lock);
  33. if (!pos)
  34. return SEQ_START_TOKEN;
  35. pos--;
  36. list_for_each(_p, &rxrpc_calls)
  37. if (!pos--)
  38. break;
  39. return _p != &rxrpc_calls ? _p : NULL;
  40. }
  41. static void *rxrpc_call_seq_next(struct seq_file *seq, void *v, loff_t *pos)
  42. {
  43. struct list_head *_p;
  44. (*pos)++;
  45. _p = v;
  46. _p = (v == SEQ_START_TOKEN) ? rxrpc_calls.next : _p->next;
  47. return _p != &rxrpc_calls ? _p : NULL;
  48. }
  49. static void rxrpc_call_seq_stop(struct seq_file *seq, void *v)
  50. {
  51. read_unlock(&rxrpc_call_lock);
  52. }
  53. static int rxrpc_call_seq_show(struct seq_file *seq, void *v)
  54. {
  55. struct rxrpc_transport *trans;
  56. struct rxrpc_call *call;
  57. char lbuff[4 + 4 + 4 + 4 + 5 + 1], rbuff[4 + 4 + 4 + 4 + 5 + 1];
  58. if (v == SEQ_START_TOKEN) {
  59. seq_puts(seq,
  60. "Proto Local Remote "
  61. " SvID ConnID CallID End Use State Abort "
  62. " UserID\n");
  63. return 0;
  64. }
  65. call = list_entry(v, struct rxrpc_call, link);
  66. trans = call->conn->trans;
  67. sprintf(lbuff, NIPQUAD_FMT":%u",
  68. NIPQUAD(trans->local->srx.transport.sin.sin_addr),
  69. ntohs(trans->local->srx.transport.sin.sin_port));
  70. sprintf(rbuff, NIPQUAD_FMT":%u",
  71. NIPQUAD(trans->peer->srx.transport.sin.sin_addr),
  72. ntohs(trans->peer->srx.transport.sin.sin_port));
  73. seq_printf(seq,
  74. "UDP %-22.22s %-22.22s %4x %08x %08x %s %3u"
  75. " %-8.8s %08x %lx\n",
  76. lbuff,
  77. rbuff,
  78. ntohs(call->conn->service_id),
  79. ntohl(call->conn->cid),
  80. ntohl(call->call_id),
  81. call->conn->in_clientflag ? "Svc" : "Clt",
  82. atomic_read(&call->usage),
  83. rxrpc_call_states[call->state],
  84. call->abort_code,
  85. call->user_call_ID);
  86. return 0;
  87. }
  88. static struct seq_operations rxrpc_call_seq_ops = {
  89. .start = rxrpc_call_seq_start,
  90. .next = rxrpc_call_seq_next,
  91. .stop = rxrpc_call_seq_stop,
  92. .show = rxrpc_call_seq_show,
  93. };
  94. static int rxrpc_call_seq_open(struct inode *inode, struct file *file)
  95. {
  96. return seq_open(file, &rxrpc_call_seq_ops);
  97. }
  98. struct file_operations rxrpc_call_seq_fops = {
  99. .owner = THIS_MODULE,
  100. .open = rxrpc_call_seq_open,
  101. .read = seq_read,
  102. .llseek = seq_lseek,
  103. .release = seq_release_private,
  104. };
  105. /*
  106. * generate a list of extant virtual connections in /proc/net/rxrpc_conns
  107. */
  108. static void *rxrpc_connection_seq_start(struct seq_file *seq, loff_t *_pos)
  109. {
  110. struct list_head *_p;
  111. loff_t pos = *_pos;
  112. read_lock(&rxrpc_connection_lock);
  113. if (!pos)
  114. return SEQ_START_TOKEN;
  115. pos--;
  116. list_for_each(_p, &rxrpc_connections)
  117. if (!pos--)
  118. break;
  119. return _p != &rxrpc_connections ? _p : NULL;
  120. }
  121. static void *rxrpc_connection_seq_next(struct seq_file *seq, void *v,
  122. loff_t *pos)
  123. {
  124. struct list_head *_p;
  125. (*pos)++;
  126. _p = v;
  127. _p = (v == SEQ_START_TOKEN) ? rxrpc_connections.next : _p->next;
  128. return _p != &rxrpc_connections ? _p : NULL;
  129. }
  130. static void rxrpc_connection_seq_stop(struct seq_file *seq, void *v)
  131. {
  132. read_unlock(&rxrpc_connection_lock);
  133. }
  134. static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
  135. {
  136. struct rxrpc_connection *conn;
  137. struct rxrpc_transport *trans;
  138. char lbuff[4 + 4 + 4 + 4 + 5 + 1], rbuff[4 + 4 + 4 + 4 + 5 + 1];
  139. if (v == SEQ_START_TOKEN) {
  140. seq_puts(seq,
  141. "Proto Local Remote "
  142. " SvID ConnID Calls End Use State Key "
  143. " Serial ISerial\n"
  144. );
  145. return 0;
  146. }
  147. conn = list_entry(v, struct rxrpc_connection, link);
  148. trans = conn->trans;
  149. sprintf(lbuff, NIPQUAD_FMT":%u",
  150. NIPQUAD(trans->local->srx.transport.sin.sin_addr),
  151. ntohs(trans->local->srx.transport.sin.sin_port));
  152. sprintf(rbuff, NIPQUAD_FMT":%u",
  153. NIPQUAD(trans->peer->srx.transport.sin.sin_addr),
  154. ntohs(trans->peer->srx.transport.sin.sin_port));
  155. seq_printf(seq,
  156. "UDP %-22.22s %-22.22s %4x %08x %08x %s %3u"
  157. " %s %08x %08x %08x\n",
  158. lbuff,
  159. rbuff,
  160. ntohs(conn->service_id),
  161. ntohl(conn->cid),
  162. conn->call_counter,
  163. conn->in_clientflag ? "Svc" : "Clt",
  164. atomic_read(&conn->usage),
  165. rxrpc_conn_states[conn->state],
  166. key_serial(conn->key),
  167. atomic_read(&conn->serial),
  168. atomic_read(&conn->hi_serial));
  169. return 0;
  170. }
  171. static struct seq_operations rxrpc_connection_seq_ops = {
  172. .start = rxrpc_connection_seq_start,
  173. .next = rxrpc_connection_seq_next,
  174. .stop = rxrpc_connection_seq_stop,
  175. .show = rxrpc_connection_seq_show,
  176. };
  177. static int rxrpc_connection_seq_open(struct inode *inode, struct file *file)
  178. {
  179. return seq_open(file, &rxrpc_connection_seq_ops);
  180. }
  181. struct file_operations rxrpc_connection_seq_fops = {
  182. .owner = THIS_MODULE,
  183. .open = rxrpc_connection_seq_open,
  184. .read = seq_read,
  185. .llseek = seq_lseek,
  186. .release = seq_release_private,
  187. };