ar-proc.c 5.0 KB

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