proc.c 5.2 KB

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