proc.c 5.1 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[RXRPC_CONN__NR_STATES] = {
  16. [RXRPC_CONN_UNUSED] = "Unused ",
  17. [RXRPC_CONN_CLIENT] = "Client ",
  18. [RXRPC_CONN_SERVICE_UNSECURED] = "SvUnsec ",
  19. [RXRPC_CONN_SERVICE_CHALLENGING] = "SvChall ",
  20. [RXRPC_CONN_SERVICE] = "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_connection *conn;
  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. sprintf(lbuff, "%pI4:%u",
  55. &call->local->srx.transport.sin.sin_addr,
  56. ntohs(call->local->srx.transport.sin.sin_port));
  57. conn = call->conn;
  58. if (conn)
  59. sprintf(rbuff, "%pI4:%u",
  60. &conn->params.peer->srx.transport.sin.sin_addr,
  61. ntohs(conn->params.peer->srx.transport.sin.sin_port));
  62. else
  63. strcpy(rbuff, "no_connection");
  64. seq_printf(seq,
  65. "UDP %-22.22s %-22.22s %4x %08x %08x %s %3u"
  66. " %-8.8s %08x %lx\n",
  67. lbuff,
  68. rbuff,
  69. call->service_id,
  70. call->cid,
  71. call->call_id,
  72. call->in_clientflag ? "Svc" : "Clt",
  73. atomic_read(&call->usage),
  74. rxrpc_call_states[call->state],
  75. call->remote_abort ?: call->local_abort,
  76. call->user_call_ID);
  77. return 0;
  78. }
  79. static const struct seq_operations rxrpc_call_seq_ops = {
  80. .start = rxrpc_call_seq_start,
  81. .next = rxrpc_call_seq_next,
  82. .stop = rxrpc_call_seq_stop,
  83. .show = rxrpc_call_seq_show,
  84. };
  85. static int rxrpc_call_seq_open(struct inode *inode, struct file *file)
  86. {
  87. return seq_open(file, &rxrpc_call_seq_ops);
  88. }
  89. const struct file_operations rxrpc_call_seq_fops = {
  90. .owner = THIS_MODULE,
  91. .open = rxrpc_call_seq_open,
  92. .read = seq_read,
  93. .llseek = seq_lseek,
  94. .release = seq_release,
  95. };
  96. /*
  97. * generate a list of extant virtual connections in /proc/net/rxrpc_conns
  98. */
  99. static void *rxrpc_connection_seq_start(struct seq_file *seq, loff_t *_pos)
  100. {
  101. read_lock(&rxrpc_connection_lock);
  102. return seq_list_start_head(&rxrpc_connections, *_pos);
  103. }
  104. static void *rxrpc_connection_seq_next(struct seq_file *seq, void *v,
  105. loff_t *pos)
  106. {
  107. return seq_list_next(v, &rxrpc_connections, pos);
  108. }
  109. static void rxrpc_connection_seq_stop(struct seq_file *seq, void *v)
  110. {
  111. read_unlock(&rxrpc_connection_lock);
  112. }
  113. static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
  114. {
  115. struct rxrpc_connection *conn;
  116. char lbuff[4 + 4 + 4 + 4 + 5 + 1], rbuff[4 + 4 + 4 + 4 + 5 + 1];
  117. if (v == &rxrpc_connections) {
  118. seq_puts(seq,
  119. "Proto Local Remote "
  120. " SvID ConnID End Use State Key "
  121. " Serial ISerial\n"
  122. );
  123. return 0;
  124. }
  125. conn = list_entry(v, struct rxrpc_connection, link);
  126. sprintf(lbuff, "%pI4:%u",
  127. &conn->params.local->srx.transport.sin.sin_addr,
  128. ntohs(conn->params.local->srx.transport.sin.sin_port));
  129. sprintf(rbuff, "%pI4:%u",
  130. &conn->params.peer->srx.transport.sin.sin_addr,
  131. ntohs(conn->params.peer->srx.transport.sin.sin_port));
  132. seq_printf(seq,
  133. "UDP %-22.22s %-22.22s %4x %08x %s %3u"
  134. " %s %08x %08x %08x\n",
  135. lbuff,
  136. rbuff,
  137. conn->params.service_id,
  138. conn->proto.cid,
  139. rxrpc_conn_is_service(conn) ? "Svc" : "Clt",
  140. atomic_read(&conn->usage),
  141. rxrpc_conn_states[conn->state],
  142. key_serial(conn->params.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. };