proc.c 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  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. };
  185. /*
  186. * generate a list of extant virtual peers in /proc/net/rxrpc/peers
  187. */
  188. static int rxrpc_peer_seq_show(struct seq_file *seq, void *v)
  189. {
  190. struct rxrpc_peer *peer;
  191. time64_t now;
  192. char lbuff[50], rbuff[50];
  193. if (v == SEQ_START_TOKEN) {
  194. seq_puts(seq,
  195. "Proto Local "
  196. " Remote "
  197. " Use CW MTU LastUse RTT Rc\n"
  198. );
  199. return 0;
  200. }
  201. peer = list_entry(v, struct rxrpc_peer, hash_link);
  202. sprintf(lbuff, "%pISpc", &peer->local->srx.transport);
  203. sprintf(rbuff, "%pISpc", &peer->srx.transport);
  204. now = ktime_get_seconds();
  205. seq_printf(seq,
  206. "UDP %-47.47s %-47.47s %3u"
  207. " %3u %5u %6llus %12llu %2u\n",
  208. lbuff,
  209. rbuff,
  210. atomic_read(&peer->usage),
  211. peer->cong_cwnd,
  212. peer->mtu,
  213. now - peer->last_tx_at,
  214. peer->rtt,
  215. peer->rtt_cursor);
  216. return 0;
  217. }
  218. static void *rxrpc_peer_seq_start(struct seq_file *seq, loff_t *_pos)
  219. __acquires(rcu)
  220. {
  221. struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
  222. unsigned int bucket, n;
  223. unsigned int shift = 32 - HASH_BITS(rxnet->peer_hash);
  224. void *p;
  225. rcu_read_lock();
  226. if (*_pos >= UINT_MAX)
  227. return NULL;
  228. n = *_pos & ((1U << shift) - 1);
  229. bucket = *_pos >> shift;
  230. for (;;) {
  231. if (bucket >= HASH_SIZE(rxnet->peer_hash)) {
  232. *_pos = UINT_MAX;
  233. return NULL;
  234. }
  235. if (n == 0) {
  236. if (bucket == 0)
  237. return SEQ_START_TOKEN;
  238. *_pos += 1;
  239. n++;
  240. }
  241. p = seq_hlist_start_rcu(&rxnet->peer_hash[bucket], n - 1);
  242. if (p)
  243. return p;
  244. bucket++;
  245. n = 1;
  246. *_pos = (bucket << shift) | n;
  247. }
  248. }
  249. static void *rxrpc_peer_seq_next(struct seq_file *seq, void *v, loff_t *_pos)
  250. {
  251. struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
  252. unsigned int bucket, n;
  253. unsigned int shift = 32 - HASH_BITS(rxnet->peer_hash);
  254. void *p;
  255. if (*_pos >= UINT_MAX)
  256. return NULL;
  257. bucket = *_pos >> shift;
  258. p = seq_hlist_next_rcu(v, &rxnet->peer_hash[bucket], _pos);
  259. if (p)
  260. return p;
  261. for (;;) {
  262. bucket++;
  263. n = 1;
  264. *_pos = (bucket << shift) | n;
  265. if (bucket >= HASH_SIZE(rxnet->peer_hash)) {
  266. *_pos = UINT_MAX;
  267. return NULL;
  268. }
  269. if (n == 0) {
  270. *_pos += 1;
  271. n++;
  272. }
  273. p = seq_hlist_start_rcu(&rxnet->peer_hash[bucket], n - 1);
  274. if (p)
  275. return p;
  276. }
  277. }
  278. static void rxrpc_peer_seq_stop(struct seq_file *seq, void *v)
  279. __releases(rcu)
  280. {
  281. rcu_read_unlock();
  282. }
  283. const struct seq_operations rxrpc_peer_seq_ops = {
  284. .start = rxrpc_peer_seq_start,
  285. .next = rxrpc_peer_seq_next,
  286. .stop = rxrpc_peer_seq_stop,
  287. .show = rxrpc_peer_seq_show,
  288. };