David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 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 | |
| 12 | #include <linux/module.h> |
| 13 | #include <net/sock.h> |
| 14 | #include <net/af_rxrpc.h> |
| 15 | #include "ar-internal.h" |
| 16 | |
David Howells | bba304d | 2016-06-27 10:32:02 +0100 | [diff] [blame] | 17 | static const char *const rxrpc_conn_states[RXRPC_CONN__NR_STATES] = { |
| 18 | [RXRPC_CONN_UNUSED] = "Unused ", |
| 19 | [RXRPC_CONN_CLIENT] = "Client ", |
David Howells | 00e9071 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 20 | [RXRPC_CONN_SERVICE_PREALLOC] = "SvPrealc", |
David Howells | bba304d | 2016-06-27 10:32:02 +0100 | [diff] [blame] | 21 | [RXRPC_CONN_SERVICE_UNSECURED] = "SvUnsec ", |
| 22 | [RXRPC_CONN_SERVICE_CHALLENGING] = "SvChall ", |
| 23 | [RXRPC_CONN_SERVICE] = "SvSecure", |
| 24 | [RXRPC_CONN_REMOTELY_ABORTED] = "RmtAbort", |
| 25 | [RXRPC_CONN_LOCALLY_ABORTED] = "LocAbort", |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 26 | }; |
| 27 | |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 28 | /* |
| 29 | * generate a list of extant and dead calls in /proc/net/rxrpc_calls |
| 30 | */ |
| 31 | static void *rxrpc_call_seq_start(struct seq_file *seq, loff_t *_pos) |
David Howells | 88f2a825 | 2018-03-30 21:05:17 +0100 | [diff] [blame] | 32 | __acquires(rcu) |
| 33 | __acquires(rxnet->call_lock) |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 34 | { |
David Howells | 2baec2c | 2017-05-24 17:02:32 +0100 | [diff] [blame] | 35 | struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq)); |
| 36 | |
David Howells | 8d94aa3 | 2016-09-07 09:19:31 +0100 | [diff] [blame] | 37 | rcu_read_lock(); |
David Howells | 2baec2c | 2017-05-24 17:02:32 +0100 | [diff] [blame] | 38 | read_lock(&rxnet->call_lock); |
| 39 | return seq_list_start_head(&rxnet->calls, *_pos); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | static void *rxrpc_call_seq_next(struct seq_file *seq, void *v, loff_t *pos) |
| 43 | { |
David Howells | 2baec2c | 2017-05-24 17:02:32 +0100 | [diff] [blame] | 44 | struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq)); |
| 45 | |
| 46 | return seq_list_next(v, &rxnet->calls, pos); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | static void rxrpc_call_seq_stop(struct seq_file *seq, void *v) |
David Howells | 88f2a825 | 2018-03-30 21:05:17 +0100 | [diff] [blame] | 50 | __releases(rxnet->call_lock) |
| 51 | __releases(rcu) |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 52 | { |
David Howells | 2baec2c | 2017-05-24 17:02:32 +0100 | [diff] [blame] | 53 | struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq)); |
| 54 | |
| 55 | read_unlock(&rxnet->call_lock); |
David Howells | 8d94aa3 | 2016-09-07 09:19:31 +0100 | [diff] [blame] | 56 | rcu_read_unlock(); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | static int rxrpc_call_seq_show(struct seq_file *seq, void *v) |
| 60 | { |
David Howells | df5d8bf | 2016-08-24 14:31:43 +0100 | [diff] [blame] | 61 | struct rxrpc_local *local; |
| 62 | struct rxrpc_sock *rx; |
| 63 | struct rxrpc_peer *peer; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 64 | struct rxrpc_call *call; |
David Howells | 2baec2c | 2017-05-24 17:02:32 +0100 | [diff] [blame] | 65 | struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq)); |
David Howells | 887763b | 2018-07-23 17:18:36 +0100 | [diff] [blame^] | 66 | unsigned long timeout = 0, nowj; |
David Howells | 3e018da | 2017-01-05 10:38:33 +0000 | [diff] [blame] | 67 | rxrpc_seq_t tx_hard_ack, rx_hard_ack; |
David Howells | 75b54cb | 2016-09-13 08:49:05 +0100 | [diff] [blame] | 68 | char lbuff[50], rbuff[50]; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 69 | |
David Howells | 2baec2c | 2017-05-24 17:02:32 +0100 | [diff] [blame] | 70 | if (v == &rxnet->calls) { |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 71 | seq_puts(seq, |
David Howells | 75b54cb | 2016-09-13 08:49:05 +0100 | [diff] [blame] | 72 | "Proto Local " |
| 73 | " Remote " |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 74 | " SvID ConnID CallID End Use State Abort " |
David Howells | 887763b | 2018-07-23 17:18:36 +0100 | [diff] [blame^] | 75 | " UserID TxSeq TW RxSeq RW RxTimo\n"); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 76 | return 0; |
| 77 | } |
| 78 | |
| 79 | call = list_entry(v, struct rxrpc_call, link); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 80 | |
David Howells | 8d94aa3 | 2016-09-07 09:19:31 +0100 | [diff] [blame] | 81 | rx = rcu_dereference(call->socket); |
David Howells | df5d8bf | 2016-08-24 14:31:43 +0100 | [diff] [blame] | 82 | if (rx) { |
| 83 | local = READ_ONCE(rx->local); |
| 84 | if (local) |
David Howells | 75b54cb | 2016-09-13 08:49:05 +0100 | [diff] [blame] | 85 | sprintf(lbuff, "%pISpc", &local->srx.transport); |
David Howells | df5d8bf | 2016-08-24 14:31:43 +0100 | [diff] [blame] | 86 | else |
| 87 | strcpy(lbuff, "no_local"); |
| 88 | } else { |
| 89 | strcpy(lbuff, "no_socket"); |
| 90 | } |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 91 | |
David Howells | df5d8bf | 2016-08-24 14:31:43 +0100 | [diff] [blame] | 92 | peer = call->peer; |
| 93 | if (peer) |
David Howells | 75b54cb | 2016-09-13 08:49:05 +0100 | [diff] [blame] | 94 | sprintf(rbuff, "%pISpc", &peer->srx.transport); |
David Howells | f4e7da8 | 2016-06-17 11:07:55 +0100 | [diff] [blame] | 95 | else |
| 96 | strcpy(rbuff, "no_connection"); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 97 | |
David Howells | 887763b | 2018-07-23 17:18:36 +0100 | [diff] [blame^] | 98 | if (call->state != RXRPC_CALL_SERVER_PREALLOC) { |
| 99 | timeout = READ_ONCE(call->expect_rx_by); |
| 100 | nowj = jiffies; |
| 101 | timeout -= jiffies; |
| 102 | } |
| 103 | |
David Howells | 3e018da | 2017-01-05 10:38:33 +0000 | [diff] [blame] | 104 | tx_hard_ack = READ_ONCE(call->tx_hard_ack); |
| 105 | rx_hard_ack = READ_ONCE(call->rx_hard_ack); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 106 | seq_printf(seq, |
David Howells | 75b54cb | 2016-09-13 08:49:05 +0100 | [diff] [blame] | 107 | "UDP %-47.47s %-47.47s %4x %08x %08x %s %3u" |
David Howells | 887763b | 2018-07-23 17:18:36 +0100 | [diff] [blame^] | 108 | " %-8.8s %08x %lx %08x %02x %08x %02x %06lx\n", |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 109 | lbuff, |
| 110 | rbuff, |
David Howells | f4e7da8 | 2016-06-17 11:07:55 +0100 | [diff] [blame] | 111 | call->service_id, |
David Howells | 0d12f8a | 2016-03-04 15:53:46 +0000 | [diff] [blame] | 112 | call->cid, |
| 113 | call->call_id, |
David Howells | dabe5a7 | 2016-08-23 15:27:24 +0100 | [diff] [blame] | 114 | rxrpc_is_service_call(call) ? "Svc" : "Clt", |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 115 | atomic_read(&call->usage), |
| 116 | rxrpc_call_states[call->state], |
David Howells | f5c17aa | 2016-08-30 09:49:28 +0100 | [diff] [blame] | 117 | call->abort_code, |
David Howells | 3e018da | 2017-01-05 10:38:33 +0000 | [diff] [blame] | 118 | call->user_call_ID, |
| 119 | tx_hard_ack, READ_ONCE(call->tx_top) - tx_hard_ack, |
David Howells | 887763b | 2018-07-23 17:18:36 +0100 | [diff] [blame^] | 120 | rx_hard_ack, READ_ONCE(call->rx_top) - rx_hard_ack, |
| 121 | timeout); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 122 | |
| 123 | return 0; |
| 124 | } |
| 125 | |
Christoph Hellwig | c350637 | 2018-04-10 19:42:55 +0200 | [diff] [blame] | 126 | const struct seq_operations rxrpc_call_seq_ops = { |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 127 | .start = rxrpc_call_seq_start, |
| 128 | .next = rxrpc_call_seq_next, |
| 129 | .stop = rxrpc_call_seq_stop, |
| 130 | .show = rxrpc_call_seq_show, |
| 131 | }; |
| 132 | |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 133 | /* |
| 134 | * generate a list of extant virtual connections in /proc/net/rxrpc_conns |
| 135 | */ |
| 136 | static void *rxrpc_connection_seq_start(struct seq_file *seq, loff_t *_pos) |
David Howells | 88f2a825 | 2018-03-30 21:05:17 +0100 | [diff] [blame] | 137 | __acquires(rxnet->conn_lock) |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 138 | { |
David Howells | 2baec2c | 2017-05-24 17:02:32 +0100 | [diff] [blame] | 139 | struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq)); |
| 140 | |
| 141 | read_lock(&rxnet->conn_lock); |
| 142 | return seq_list_start_head(&rxnet->conn_proc_list, *_pos); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | static void *rxrpc_connection_seq_next(struct seq_file *seq, void *v, |
| 146 | loff_t *pos) |
| 147 | { |
David Howells | 2baec2c | 2017-05-24 17:02:32 +0100 | [diff] [blame] | 148 | struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq)); |
| 149 | |
| 150 | return seq_list_next(v, &rxnet->conn_proc_list, pos); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | static void rxrpc_connection_seq_stop(struct seq_file *seq, void *v) |
David Howells | 88f2a825 | 2018-03-30 21:05:17 +0100 | [diff] [blame] | 154 | __releases(rxnet->conn_lock) |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 155 | { |
David Howells | 2baec2c | 2017-05-24 17:02:32 +0100 | [diff] [blame] | 156 | struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq)); |
| 157 | |
| 158 | read_unlock(&rxnet->conn_lock); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | static int rxrpc_connection_seq_show(struct seq_file *seq, void *v) |
| 162 | { |
| 163 | struct rxrpc_connection *conn; |
David Howells | 2baec2c | 2017-05-24 17:02:32 +0100 | [diff] [blame] | 164 | struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq)); |
David Howells | 75b54cb | 2016-09-13 08:49:05 +0100 | [diff] [blame] | 165 | char lbuff[50], rbuff[50]; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 166 | |
David Howells | 2baec2c | 2017-05-24 17:02:32 +0100 | [diff] [blame] | 167 | if (v == &rxnet->conn_proc_list) { |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 168 | seq_puts(seq, |
David Howells | 75b54cb | 2016-09-13 08:49:05 +0100 | [diff] [blame] | 169 | "Proto Local " |
| 170 | " Remote " |
David Howells | a1399f8 | 2016-06-27 14:39:44 +0100 | [diff] [blame] | 171 | " SvID ConnID End Use State Key " |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 172 | " Serial ISerial\n" |
| 173 | ); |
| 174 | return 0; |
| 175 | } |
| 176 | |
David Howells | 4d028b2 | 2016-08-24 07:30:52 +0100 | [diff] [blame] | 177 | conn = list_entry(v, struct rxrpc_connection, proc_link); |
David Howells | 00e9071 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 178 | if (conn->state == RXRPC_CONN_SERVICE_PREALLOC) { |
| 179 | strcpy(lbuff, "no_local"); |
| 180 | strcpy(rbuff, "no_connection"); |
| 181 | goto print; |
| 182 | } |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 183 | |
David Howells | 75b54cb | 2016-09-13 08:49:05 +0100 | [diff] [blame] | 184 | sprintf(lbuff, "%pISpc", &conn->params.local->srx.transport); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 185 | |
David Howells | 75b54cb | 2016-09-13 08:49:05 +0100 | [diff] [blame] | 186 | sprintf(rbuff, "%pISpc", &conn->params.peer->srx.transport); |
David Howells | 00e9071 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 187 | print: |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 188 | seq_printf(seq, |
David Howells | 75b54cb | 2016-09-13 08:49:05 +0100 | [diff] [blame] | 189 | "UDP %-47.47s %-47.47s %4x %08x %s %3u" |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 190 | " %s %08x %08x %08x\n", |
| 191 | lbuff, |
| 192 | rbuff, |
David Howells | 68d6d1a | 2017-06-05 14:30:49 +0100 | [diff] [blame] | 193 | conn->service_id, |
David Howells | 19ffa01 | 2016-04-04 14:00:36 +0100 | [diff] [blame] | 194 | conn->proto.cid, |
David Howells | 19ffa01 | 2016-04-04 14:00:36 +0100 | [diff] [blame] | 195 | rxrpc_conn_is_service(conn) ? "Svc" : "Clt", |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 196 | atomic_read(&conn->usage), |
| 197 | rxrpc_conn_states[conn->state], |
David Howells | 19ffa01 | 2016-04-04 14:00:36 +0100 | [diff] [blame] | 198 | key_serial(conn->params.key), |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 199 | atomic_read(&conn->serial), |
David Howells | 563ea7d | 2016-08-23 15:27:25 +0100 | [diff] [blame] | 200 | conn->hi_serial); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 201 | |
| 202 | return 0; |
| 203 | } |
| 204 | |
Christoph Hellwig | c350637 | 2018-04-10 19:42:55 +0200 | [diff] [blame] | 205 | const struct seq_operations rxrpc_connection_seq_ops = { |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 206 | .start = rxrpc_connection_seq_start, |
| 207 | .next = rxrpc_connection_seq_next, |
| 208 | .stop = rxrpc_connection_seq_stop, |
| 209 | .show = rxrpc_connection_seq_show, |
| 210 | }; |