proc.c 5.8 KB

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