Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 2 | /* /proc/net/ support for AF_RXRPC |
| 3 | * |
| 4 | * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved. |
| 5 | * Written by David Howells (dhowells@redhat.com) |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <linux/module.h> |
| 9 | #include <net/sock.h> |
| 10 | #include <net/af_rxrpc.h> |
| 11 | #include "ar-internal.h" |
| 12 | |
David Howells | bba304d | 2016-06-27 10:32:02 +0100 | [diff] [blame] | 13 | static const char *const rxrpc_conn_states[RXRPC_CONN__NR_STATES] = { |
| 14 | [RXRPC_CONN_UNUSED] = "Unused ", |
David Howells | 9d35d88 | 2022-10-19 09:45:43 +0100 | [diff] [blame] | 15 | [RXRPC_CONN_CLIENT_UNSECURED] = "ClUnsec ", |
David Howells | bba304d | 2016-06-27 10:32:02 +0100 | [diff] [blame] | 16 | [RXRPC_CONN_CLIENT] = "Client ", |
David Howells | 00e9071 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 17 | [RXRPC_CONN_SERVICE_PREALLOC] = "SvPrealc", |
David Howells | bba304d | 2016-06-27 10:32:02 +0100 | [diff] [blame] | 18 | [RXRPC_CONN_SERVICE_UNSECURED] = "SvUnsec ", |
| 19 | [RXRPC_CONN_SERVICE_CHALLENGING] = "SvChall ", |
| 20 | [RXRPC_CONN_SERVICE] = "SvSecure", |
David Howells | a00ce28 | 2022-10-20 09:56:36 +0100 | [diff] [blame] | 21 | [RXRPC_CONN_ABORTED] = "Aborted ", |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 22 | }; |
| 23 | |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 24 | /* |
| 25 | * generate a list of extant and dead calls in /proc/net/rxrpc_calls |
| 26 | */ |
| 27 | 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] | 28 | __acquires(rcu) |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 29 | { |
David Howells | 2baec2c | 2017-05-24 17:02:32 +0100 | [diff] [blame] | 30 | struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq)); |
| 31 | |
David Howells | 8d94aa3 | 2016-09-07 09:19:31 +0100 | [diff] [blame] | 32 | rcu_read_lock(); |
David Howells | ad25f5c | 2022-05-21 08:45:28 +0100 | [diff] [blame] | 33 | return seq_list_start_head_rcu(&rxnet->calls, *_pos); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | static void *rxrpc_call_seq_next(struct seq_file *seq, void *v, loff_t *pos) |
| 37 | { |
David Howells | 2baec2c | 2017-05-24 17:02:32 +0100 | [diff] [blame] | 38 | struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq)); |
| 39 | |
David Howells | ad25f5c | 2022-05-21 08:45:28 +0100 | [diff] [blame] | 40 | return seq_list_next_rcu(v, &rxnet->calls, pos); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | static void rxrpc_call_seq_stop(struct seq_file *seq, void *v) |
David Howells | 88f2a825 | 2018-03-30 21:05:17 +0100 | [diff] [blame] | 44 | __releases(rcu) |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 45 | { |
David Howells | 8d94aa3 | 2016-09-07 09:19:31 +0100 | [diff] [blame] | 46 | rcu_read_unlock(); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | static int rxrpc_call_seq_show(struct seq_file *seq, void *v) |
| 50 | { |
David Howells | df5d8bf | 2016-08-24 14:31:43 +0100 | [diff] [blame] | 51 | struct rxrpc_local *local; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 52 | struct rxrpc_call *call; |
David Howells | 2baec2c | 2017-05-24 17:02:32 +0100 | [diff] [blame] | 53 | struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq)); |
David Howells | 96b4059 | 2022-10-27 11:25:55 +0100 | [diff] [blame] | 54 | enum rxrpc_call_state state; |
Wei Yongjun | 770b26d | 2018-08-02 09:13:33 +0100 | [diff] [blame] | 55 | unsigned long timeout = 0; |
David Howells | a4ea4c4 | 2022-03-31 23:55:08 +0100 | [diff] [blame] | 56 | rxrpc_seq_t acks_hard_ack; |
David Howells | 75b54cb | 2016-09-13 08:49:05 +0100 | [diff] [blame] | 57 | char lbuff[50], rbuff[50]; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 58 | |
David Howells | 2baec2c | 2017-05-24 17:02:32 +0100 | [diff] [blame] | 59 | if (v == &rxnet->calls) { |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 60 | seq_puts(seq, |
David Howells | 75b54cb | 2016-09-13 08:49:05 +0100 | [diff] [blame] | 61 | "Proto Local " |
| 62 | " Remote " |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 63 | " SvID ConnID CallID End Use State Abort " |
David Howells | 5086d9a | 2022-11-11 13:47:35 +0000 | [diff] [blame] | 64 | " DebugId TxSeq TW RxSeq RW RxSerial CW RxTimo\n"); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 65 | return 0; |
| 66 | } |
| 67 | |
| 68 | call = list_entry(v, struct rxrpc_call, link); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 69 | |
David Howells | f3441d4 | 2022-10-20 21:58:36 +0100 | [diff] [blame] | 70 | local = call->local; |
| 71 | if (local) |
| 72 | sprintf(lbuff, "%pISpc", &local->srx.transport); |
David Howells | f4e7da8 | 2016-06-17 11:07:55 +0100 | [diff] [blame] | 73 | else |
David Howells | f3441d4 | 2022-10-20 21:58:36 +0100 | [diff] [blame] | 74 | strcpy(lbuff, "no_local"); |
| 75 | |
| 76 | sprintf(rbuff, "%pISpc", &call->dest_srx.transport); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 77 | |
David Howells | 96b4059 | 2022-10-27 11:25:55 +0100 | [diff] [blame] | 78 | state = rxrpc_call_state(call); |
| 79 | if (state != RXRPC_CALL_SERVER_PREALLOC) { |
David Howells | 887763b | 2018-07-23 17:18:36 +0100 | [diff] [blame] | 80 | timeout = READ_ONCE(call->expect_rx_by); |
David Howells | 887763b | 2018-07-23 17:18:36 +0100 | [diff] [blame] | 81 | timeout -= jiffies; |
| 82 | } |
| 83 | |
David Howells | a4ea4c4 | 2022-03-31 23:55:08 +0100 | [diff] [blame] | 84 | acks_hard_ack = READ_ONCE(call->acks_hard_ack); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 85 | seq_printf(seq, |
David Howells | 75b54cb | 2016-09-13 08:49:05 +0100 | [diff] [blame] | 86 | "UDP %-47.47s %-47.47s %4x %08x %08x %s %3u" |
David Howells | 5086d9a | 2022-11-11 13:47:35 +0000 | [diff] [blame] | 87 | " %-8.8s %08x %08x %08x %02x %08x %02x %08x %02x %06lx\n", |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 88 | lbuff, |
| 89 | rbuff, |
David Howells | f3441d4 | 2022-10-20 21:58:36 +0100 | [diff] [blame] | 90 | call->dest_srx.srx_service, |
David Howells | 0d12f8a | 2016-03-04 15:53:46 +0000 | [diff] [blame] | 91 | call->cid, |
| 92 | call->call_id, |
David Howells | dabe5a7 | 2016-08-23 15:27:24 +0100 | [diff] [blame] | 93 | rxrpc_is_service_call(call) ? "Svc" : "Clt", |
David Howells | a0575429 | 2022-05-21 08:45:22 +0100 | [diff] [blame] | 94 | refcount_read(&call->ref), |
David Howells | 96b4059 | 2022-10-27 11:25:55 +0100 | [diff] [blame] | 95 | rxrpc_call_states[state], |
David Howells | f5c17aa | 2016-08-30 09:49:28 +0100 | [diff] [blame] | 96 | call->abort_code, |
David Howells | 32f71aa | 2020-05-02 13:38:23 +0100 | [diff] [blame] | 97 | call->debug_id, |
David Howells | a4ea4c4 | 2022-03-31 23:55:08 +0100 | [diff] [blame] | 98 | acks_hard_ack, READ_ONCE(call->tx_top) - acks_hard_ack, |
David Howells | 5bbf9533 | 2022-10-17 11:44:22 +0100 | [diff] [blame] | 99 | call->ackr_window, call->ackr_wtop - call->ackr_window, |
David Howells | 6b97bd7 | 2018-07-23 17:18:36 +0100 | [diff] [blame] | 100 | call->rx_serial, |
David Howells | 5086d9a | 2022-11-11 13:47:35 +0000 | [diff] [blame] | 101 | call->cong_cwnd, |
David Howells | 887763b | 2018-07-23 17:18:36 +0100 | [diff] [blame] | 102 | timeout); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 103 | |
| 104 | return 0; |
| 105 | } |
| 106 | |
Christoph Hellwig | c350637 | 2018-04-10 19:42:55 +0200 | [diff] [blame] | 107 | const struct seq_operations rxrpc_call_seq_ops = { |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 108 | .start = rxrpc_call_seq_start, |
| 109 | .next = rxrpc_call_seq_next, |
| 110 | .stop = rxrpc_call_seq_stop, |
| 111 | .show = rxrpc_call_seq_show, |
| 112 | }; |
| 113 | |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 114 | /* |
| 115 | * generate a list of extant virtual connections in /proc/net/rxrpc_conns |
| 116 | */ |
| 117 | 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] | 118 | __acquires(rxnet->conn_lock) |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 119 | { |
David Howells | 2baec2c | 2017-05-24 17:02:32 +0100 | [diff] [blame] | 120 | struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq)); |
| 121 | |
| 122 | read_lock(&rxnet->conn_lock); |
| 123 | return seq_list_start_head(&rxnet->conn_proc_list, *_pos); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | static void *rxrpc_connection_seq_next(struct seq_file *seq, void *v, |
| 127 | loff_t *pos) |
| 128 | { |
David Howells | 2baec2c | 2017-05-24 17:02:32 +0100 | [diff] [blame] | 129 | struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq)); |
| 130 | |
| 131 | return seq_list_next(v, &rxnet->conn_proc_list, pos); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | static void rxrpc_connection_seq_stop(struct seq_file *seq, void *v) |
David Howells | 88f2a825 | 2018-03-30 21:05:17 +0100 | [diff] [blame] | 135 | __releases(rxnet->conn_lock) |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 136 | { |
David Howells | 2baec2c | 2017-05-24 17:02:32 +0100 | [diff] [blame] | 137 | struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq)); |
| 138 | |
| 139 | read_unlock(&rxnet->conn_lock); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | static int rxrpc_connection_seq_show(struct seq_file *seq, void *v) |
| 143 | { |
| 144 | struct rxrpc_connection *conn; |
David Howells | 2baec2c | 2017-05-24 17:02:32 +0100 | [diff] [blame] | 145 | struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq)); |
David Howells | a00ce28 | 2022-10-20 09:56:36 +0100 | [diff] [blame] | 146 | const char *state; |
David Howells | 75b54cb | 2016-09-13 08:49:05 +0100 | [diff] [blame] | 147 | char lbuff[50], rbuff[50]; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 148 | |
David Howells | 2baec2c | 2017-05-24 17:02:32 +0100 | [diff] [blame] | 149 | if (v == &rxnet->conn_proc_list) { |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 150 | seq_puts(seq, |
David Howells | 75b54cb | 2016-09-13 08:49:05 +0100 | [diff] [blame] | 151 | "Proto Local " |
| 152 | " Remote " |
David Howells | 3cec055 | 2022-11-25 12:43:50 +0000 | [diff] [blame] | 153 | " SvID ConnID End Ref Act State Key " |
David Howells | 245500d | 2020-07-01 11:15:32 +0100 | [diff] [blame] | 154 | " Serial ISerial CallId0 CallId1 CallId2 CallId3\n" |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 155 | ); |
| 156 | return 0; |
| 157 | } |
| 158 | |
David Howells | 4d028b2 | 2016-08-24 07:30:52 +0100 | [diff] [blame] | 159 | conn = list_entry(v, struct rxrpc_connection, proc_link); |
David Howells | 00e9071 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 160 | if (conn->state == RXRPC_CONN_SERVICE_PREALLOC) { |
| 161 | strcpy(lbuff, "no_local"); |
| 162 | strcpy(rbuff, "no_connection"); |
| 163 | goto print; |
| 164 | } |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 165 | |
David Howells | 2cc8008 | 2022-10-19 13:49:02 +0100 | [diff] [blame] | 166 | sprintf(lbuff, "%pISpc", &conn->local->srx.transport); |
David Howells | 2cc8008 | 2022-10-19 13:49:02 +0100 | [diff] [blame] | 167 | sprintf(rbuff, "%pISpc", &conn->peer->srx.transport); |
David Howells | 00e9071 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 168 | print: |
David Howells | a00ce28 | 2022-10-20 09:56:36 +0100 | [diff] [blame] | 169 | state = rxrpc_is_conn_aborted(conn) ? |
| 170 | rxrpc_call_completions[conn->completion] : |
| 171 | rxrpc_conn_states[conn->state]; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 172 | seq_printf(seq, |
David Howells | 3cec055 | 2022-11-25 12:43:50 +0000 | [diff] [blame] | 173 | "UDP %-47.47s %-47.47s %4x %08x %s %3u %3d" |
David Howells | 6b97bd7 | 2018-07-23 17:18:36 +0100 | [diff] [blame] | 174 | " %s %08x %08x %08x %08x %08x %08x %08x\n", |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 175 | lbuff, |
| 176 | rbuff, |
David Howells | 68d6d1a | 2017-06-05 14:30:49 +0100 | [diff] [blame] | 177 | conn->service_id, |
David Howells | 19ffa01 | 2016-04-04 14:00:36 +0100 | [diff] [blame] | 178 | conn->proto.cid, |
David Howells | 19ffa01 | 2016-04-04 14:00:36 +0100 | [diff] [blame] | 179 | rxrpc_conn_is_service(conn) ? "Svc" : "Clt", |
David Howells | a0575429 | 2022-05-21 08:45:22 +0100 | [diff] [blame] | 180 | refcount_read(&conn->ref), |
David Howells | 3cec055 | 2022-11-25 12:43:50 +0000 | [diff] [blame] | 181 | atomic_read(&conn->active), |
David Howells | a00ce28 | 2022-10-20 09:56:36 +0100 | [diff] [blame] | 182 | state, |
David Howells | 2cc8008 | 2022-10-19 13:49:02 +0100 | [diff] [blame] | 183 | key_serial(conn->key), |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 184 | atomic_read(&conn->serial), |
David Howells | 6b97bd7 | 2018-07-23 17:18:36 +0100 | [diff] [blame] | 185 | conn->hi_serial, |
| 186 | conn->channels[0].call_id, |
| 187 | conn->channels[1].call_id, |
| 188 | conn->channels[2].call_id, |
| 189 | conn->channels[3].call_id); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 190 | |
| 191 | return 0; |
| 192 | } |
| 193 | |
Christoph Hellwig | c350637 | 2018-04-10 19:42:55 +0200 | [diff] [blame] | 194 | const struct seq_operations rxrpc_connection_seq_ops = { |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 195 | .start = rxrpc_connection_seq_start, |
| 196 | .next = rxrpc_connection_seq_next, |
| 197 | .stop = rxrpc_connection_seq_stop, |
| 198 | .show = rxrpc_connection_seq_show, |
| 199 | }; |
David Howells | bc0e7cf | 2018-10-15 11:31:03 +0100 | [diff] [blame] | 200 | |
| 201 | /* |
| 202 | * generate a list of extant virtual peers in /proc/net/rxrpc/peers |
| 203 | */ |
| 204 | static int rxrpc_peer_seq_show(struct seq_file *seq, void *v) |
| 205 | { |
| 206 | struct rxrpc_peer *peer; |
| 207 | time64_t now; |
| 208 | char lbuff[50], rbuff[50]; |
| 209 | |
| 210 | if (v == SEQ_START_TOKEN) { |
| 211 | seq_puts(seq, |
| 212 | "Proto Local " |
| 213 | " Remote " |
David Howells | 1fc4fa2 | 2022-10-03 18:49:11 +0100 | [diff] [blame] | 214 | " Use SST MTU LastUse RTT RTO\n" |
David Howells | bc0e7cf | 2018-10-15 11:31:03 +0100 | [diff] [blame] | 215 | ); |
| 216 | return 0; |
| 217 | } |
| 218 | |
| 219 | peer = list_entry(v, struct rxrpc_peer, hash_link); |
| 220 | |
| 221 | sprintf(lbuff, "%pISpc", &peer->local->srx.transport); |
| 222 | |
| 223 | sprintf(rbuff, "%pISpc", &peer->srx.transport); |
| 224 | |
| 225 | now = ktime_get_seconds(); |
| 226 | seq_printf(seq, |
| 227 | "UDP %-47.47s %-47.47s %3u" |
David Howells | c410bf01 | 2020-05-11 14:54:34 +0100 | [diff] [blame] | 228 | " %3u %5u %6llus %8u %8u\n", |
David Howells | bc0e7cf | 2018-10-15 11:31:03 +0100 | [diff] [blame] | 229 | lbuff, |
| 230 | rbuff, |
David Howells | a0575429 | 2022-05-21 08:45:22 +0100 | [diff] [blame] | 231 | refcount_read(&peer->ref), |
David Howells | 1fc4fa2 | 2022-10-03 18:49:11 +0100 | [diff] [blame] | 232 | peer->cong_ssthresh, |
David Howells | bc0e7cf | 2018-10-15 11:31:03 +0100 | [diff] [blame] | 233 | peer->mtu, |
| 234 | now - peer->last_tx_at, |
David Howells | c410bf01 | 2020-05-11 14:54:34 +0100 | [diff] [blame] | 235 | peer->srtt_us >> 3, |
| 236 | jiffies_to_usecs(peer->rto_j)); |
David Howells | bc0e7cf | 2018-10-15 11:31:03 +0100 | [diff] [blame] | 237 | |
| 238 | return 0; |
| 239 | } |
| 240 | |
| 241 | static void *rxrpc_peer_seq_start(struct seq_file *seq, loff_t *_pos) |
| 242 | __acquires(rcu) |
| 243 | { |
| 244 | struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq)); |
| 245 | unsigned int bucket, n; |
| 246 | unsigned int shift = 32 - HASH_BITS(rxnet->peer_hash); |
| 247 | void *p; |
| 248 | |
| 249 | rcu_read_lock(); |
| 250 | |
| 251 | if (*_pos >= UINT_MAX) |
| 252 | return NULL; |
| 253 | |
| 254 | n = *_pos & ((1U << shift) - 1); |
| 255 | bucket = *_pos >> shift; |
| 256 | for (;;) { |
| 257 | if (bucket >= HASH_SIZE(rxnet->peer_hash)) { |
| 258 | *_pos = UINT_MAX; |
| 259 | return NULL; |
| 260 | } |
| 261 | if (n == 0) { |
| 262 | if (bucket == 0) |
| 263 | return SEQ_START_TOKEN; |
| 264 | *_pos += 1; |
| 265 | n++; |
| 266 | } |
| 267 | |
| 268 | p = seq_hlist_start_rcu(&rxnet->peer_hash[bucket], n - 1); |
| 269 | if (p) |
| 270 | return p; |
| 271 | bucket++; |
| 272 | n = 1; |
| 273 | *_pos = (bucket << shift) | n; |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | static void *rxrpc_peer_seq_next(struct seq_file *seq, void *v, loff_t *_pos) |
| 278 | { |
| 279 | struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq)); |
| 280 | unsigned int bucket, n; |
| 281 | unsigned int shift = 32 - HASH_BITS(rxnet->peer_hash); |
| 282 | void *p; |
| 283 | |
| 284 | if (*_pos >= UINT_MAX) |
| 285 | return NULL; |
| 286 | |
| 287 | bucket = *_pos >> shift; |
| 288 | |
| 289 | p = seq_hlist_next_rcu(v, &rxnet->peer_hash[bucket], _pos); |
| 290 | if (p) |
| 291 | return p; |
| 292 | |
| 293 | for (;;) { |
| 294 | bucket++; |
| 295 | n = 1; |
| 296 | *_pos = (bucket << shift) | n; |
| 297 | |
| 298 | if (bucket >= HASH_SIZE(rxnet->peer_hash)) { |
| 299 | *_pos = UINT_MAX; |
| 300 | return NULL; |
| 301 | } |
| 302 | if (n == 0) { |
| 303 | *_pos += 1; |
| 304 | n++; |
| 305 | } |
| 306 | |
| 307 | p = seq_hlist_start_rcu(&rxnet->peer_hash[bucket], n - 1); |
| 308 | if (p) |
| 309 | return p; |
| 310 | } |
| 311 | } |
| 312 | |
| 313 | static void rxrpc_peer_seq_stop(struct seq_file *seq, void *v) |
| 314 | __releases(rcu) |
| 315 | { |
| 316 | rcu_read_unlock(); |
| 317 | } |
| 318 | |
| 319 | |
| 320 | const struct seq_operations rxrpc_peer_seq_ops = { |
| 321 | .start = rxrpc_peer_seq_start, |
| 322 | .next = rxrpc_peer_seq_next, |
| 323 | .stop = rxrpc_peer_seq_stop, |
| 324 | .show = rxrpc_peer_seq_show, |
| 325 | }; |
David Howells | 33912c2 | 2022-05-21 08:45:15 +0100 | [diff] [blame] | 326 | |
| 327 | /* |
| 328 | * Generate a list of extant virtual local endpoints in /proc/net/rxrpc/locals |
| 329 | */ |
| 330 | static int rxrpc_local_seq_show(struct seq_file *seq, void *v) |
| 331 | { |
| 332 | struct rxrpc_local *local; |
| 333 | char lbuff[50]; |
| 334 | |
| 335 | if (v == SEQ_START_TOKEN) { |
| 336 | seq_puts(seq, |
| 337 | "Proto Local " |
David Howells | a275da6 | 2022-10-10 08:45:20 +0100 | [diff] [blame] | 338 | " Use Act RxQ\n"); |
David Howells | 33912c2 | 2022-05-21 08:45:15 +0100 | [diff] [blame] | 339 | return 0; |
| 340 | } |
| 341 | |
| 342 | local = hlist_entry(v, struct rxrpc_local, link); |
| 343 | |
| 344 | sprintf(lbuff, "%pISpc", &local->srx.transport); |
| 345 | |
| 346 | seq_printf(seq, |
David Howells | a275da6 | 2022-10-10 08:45:20 +0100 | [diff] [blame] | 347 | "UDP %-47.47s %3u %3u %3u\n", |
David Howells | 33912c2 | 2022-05-21 08:45:15 +0100 | [diff] [blame] | 348 | lbuff, |
David Howells | a0575429 | 2022-05-21 08:45:22 +0100 | [diff] [blame] | 349 | refcount_read(&local->ref), |
David Howells | a275da6 | 2022-10-10 08:45:20 +0100 | [diff] [blame] | 350 | atomic_read(&local->active_users), |
| 351 | local->rx_queue.qlen); |
David Howells | 33912c2 | 2022-05-21 08:45:15 +0100 | [diff] [blame] | 352 | |
| 353 | return 0; |
| 354 | } |
| 355 | |
| 356 | static void *rxrpc_local_seq_start(struct seq_file *seq, loff_t *_pos) |
| 357 | __acquires(rcu) |
| 358 | { |
| 359 | struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq)); |
| 360 | unsigned int n; |
| 361 | |
| 362 | rcu_read_lock(); |
| 363 | |
| 364 | if (*_pos >= UINT_MAX) |
| 365 | return NULL; |
| 366 | |
| 367 | n = *_pos; |
| 368 | if (n == 0) |
| 369 | return SEQ_START_TOKEN; |
| 370 | |
| 371 | return seq_hlist_start_rcu(&rxnet->local_endpoints, n - 1); |
| 372 | } |
| 373 | |
| 374 | static void *rxrpc_local_seq_next(struct seq_file *seq, void *v, loff_t *_pos) |
| 375 | { |
| 376 | struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq)); |
| 377 | |
| 378 | if (*_pos >= UINT_MAX) |
| 379 | return NULL; |
| 380 | |
| 381 | return seq_hlist_next_rcu(v, &rxnet->local_endpoints, _pos); |
| 382 | } |
| 383 | |
| 384 | static void rxrpc_local_seq_stop(struct seq_file *seq, void *v) |
| 385 | __releases(rcu) |
| 386 | { |
| 387 | rcu_read_unlock(); |
| 388 | } |
| 389 | |
| 390 | const struct seq_operations rxrpc_local_seq_ops = { |
| 391 | .start = rxrpc_local_seq_start, |
| 392 | .next = rxrpc_local_seq_next, |
| 393 | .stop = rxrpc_local_seq_stop, |
| 394 | .show = rxrpc_local_seq_show, |
| 395 | }; |
David Howells | b015424 | 2022-05-11 14:01:25 +0100 | [diff] [blame] | 396 | |
| 397 | /* |
| 398 | * Display stats in /proc/net/rxrpc/stats |
| 399 | */ |
| 400 | int rxrpc_stats_show(struct seq_file *seq, void *v) |
| 401 | { |
| 402 | struct rxrpc_net *rxnet = rxrpc_net(seq_file_single_net(seq)); |
| 403 | |
| 404 | seq_printf(seq, |
David Howells | 32cf8ed | 2022-11-11 13:47:35 +0000 | [diff] [blame] | 405 | "Data : send=%u sendf=%u fail=%u\n", |
David Howells | b015424 | 2022-05-11 14:01:25 +0100 | [diff] [blame] | 406 | atomic_read(&rxnet->stat_tx_data_send), |
David Howells | 32cf8ed | 2022-11-11 13:47:35 +0000 | [diff] [blame] | 407 | atomic_read(&rxnet->stat_tx_data_send_frag), |
| 408 | atomic_read(&rxnet->stat_tx_data_send_fail)); |
David Howells | b015424 | 2022-05-11 14:01:25 +0100 | [diff] [blame] | 409 | seq_printf(seq, |
David Howells | 32cf8ed | 2022-11-11 13:47:35 +0000 | [diff] [blame] | 410 | "Data-Tx : nr=%u retrans=%u uf=%u cwr=%u\n", |
David Howells | b015424 | 2022-05-11 14:01:25 +0100 | [diff] [blame] | 411 | atomic_read(&rxnet->stat_tx_data), |
David Howells | 32cf8ed | 2022-11-11 13:47:35 +0000 | [diff] [blame] | 412 | atomic_read(&rxnet->stat_tx_data_retrans), |
| 413 | atomic_read(&rxnet->stat_tx_data_underflow), |
| 414 | atomic_read(&rxnet->stat_tx_data_cwnd_reset)); |
David Howells | b015424 | 2022-05-11 14:01:25 +0100 | [diff] [blame] | 415 | seq_printf(seq, |
| 416 | "Data-Rx : nr=%u reqack=%u jumbo=%u\n", |
| 417 | atomic_read(&rxnet->stat_rx_data), |
| 418 | atomic_read(&rxnet->stat_rx_data_reqack), |
| 419 | atomic_read(&rxnet->stat_rx_data_jumbo)); |
| 420 | seq_printf(seq, |
David Howells | f2a676d | 2022-05-11 14:01:25 +0100 | [diff] [blame] | 421 | "Ack : fill=%u send=%u skip=%u\n", |
| 422 | atomic_read(&rxnet->stat_tx_ack_fill), |
| 423 | atomic_read(&rxnet->stat_tx_ack_send), |
| 424 | atomic_read(&rxnet->stat_tx_ack_skip)); |
| 425 | seq_printf(seq, |
| 426 | "Ack-Tx : req=%u dup=%u oos=%u exw=%u nos=%u png=%u prs=%u dly=%u idl=%u\n", |
| 427 | atomic_read(&rxnet->stat_tx_acks[RXRPC_ACK_REQUESTED]), |
| 428 | atomic_read(&rxnet->stat_tx_acks[RXRPC_ACK_DUPLICATE]), |
| 429 | atomic_read(&rxnet->stat_tx_acks[RXRPC_ACK_OUT_OF_SEQUENCE]), |
| 430 | atomic_read(&rxnet->stat_tx_acks[RXRPC_ACK_EXCEEDS_WINDOW]), |
| 431 | atomic_read(&rxnet->stat_tx_acks[RXRPC_ACK_NOSPACE]), |
| 432 | atomic_read(&rxnet->stat_tx_acks[RXRPC_ACK_PING]), |
| 433 | atomic_read(&rxnet->stat_tx_acks[RXRPC_ACK_PING_RESPONSE]), |
| 434 | atomic_read(&rxnet->stat_tx_acks[RXRPC_ACK_DELAY]), |
| 435 | atomic_read(&rxnet->stat_tx_acks[RXRPC_ACK_IDLE])); |
| 436 | seq_printf(seq, |
| 437 | "Ack-Rx : req=%u dup=%u oos=%u exw=%u nos=%u png=%u prs=%u dly=%u idl=%u\n", |
| 438 | atomic_read(&rxnet->stat_rx_acks[RXRPC_ACK_REQUESTED]), |
| 439 | atomic_read(&rxnet->stat_rx_acks[RXRPC_ACK_DUPLICATE]), |
| 440 | atomic_read(&rxnet->stat_rx_acks[RXRPC_ACK_OUT_OF_SEQUENCE]), |
| 441 | atomic_read(&rxnet->stat_rx_acks[RXRPC_ACK_EXCEEDS_WINDOW]), |
| 442 | atomic_read(&rxnet->stat_rx_acks[RXRPC_ACK_NOSPACE]), |
| 443 | atomic_read(&rxnet->stat_rx_acks[RXRPC_ACK_PING]), |
| 444 | atomic_read(&rxnet->stat_rx_acks[RXRPC_ACK_PING_RESPONSE]), |
| 445 | atomic_read(&rxnet->stat_rx_acks[RXRPC_ACK_DELAY]), |
| 446 | atomic_read(&rxnet->stat_rx_acks[RXRPC_ACK_IDLE])); |
| 447 | seq_printf(seq, |
David Howells | f7fa524 | 2022-08-18 11:52:36 +0100 | [diff] [blame] | 448 | "Why-Req-A: acklost=%u already=%u mrtt=%u ortt=%u\n", |
| 449 | atomic_read(&rxnet->stat_why_req_ack[rxrpc_reqack_ack_lost]), |
| 450 | atomic_read(&rxnet->stat_why_req_ack[rxrpc_reqack_already_on]), |
| 451 | atomic_read(&rxnet->stat_why_req_ack[rxrpc_reqack_more_rtt]), |
| 452 | atomic_read(&rxnet->stat_why_req_ack[rxrpc_reqack_old_rtt])); |
| 453 | seq_printf(seq, |
| 454 | "Why-Req-A: nolast=%u retx=%u slows=%u smtxw=%u\n", |
| 455 | atomic_read(&rxnet->stat_why_req_ack[rxrpc_reqack_no_srv_last]), |
| 456 | atomic_read(&rxnet->stat_why_req_ack[rxrpc_reqack_retrans]), |
| 457 | atomic_read(&rxnet->stat_why_req_ack[rxrpc_reqack_slow_start]), |
| 458 | atomic_read(&rxnet->stat_why_req_ack[rxrpc_reqack_small_txwin])); |
| 459 | seq_printf(seq, |
David Howells | a4ea4c4 | 2022-03-31 23:55:08 +0100 | [diff] [blame] | 460 | "Buffers : txb=%u rxb=%u\n", |
David Howells | 02a1935 | 2022-04-05 21:16:32 +0100 | [diff] [blame] | 461 | atomic_read(&rxrpc_nr_txbuf), |
David Howells | b015424 | 2022-05-11 14:01:25 +0100 | [diff] [blame] | 462 | atomic_read(&rxrpc_n_rx_skbs)); |
David Howells | a275da6 | 2022-10-10 08:45:20 +0100 | [diff] [blame] | 463 | seq_printf(seq, |
| 464 | "IO-thread: loops=%u\n", |
| 465 | atomic_read(&rxnet->stat_io_loop)); |
David Howells | b015424 | 2022-05-11 14:01:25 +0100 | [diff] [blame] | 466 | return 0; |
| 467 | } |
| 468 | |
| 469 | /* |
| 470 | * Clear stats if /proc/net/rxrpc/stats is written to. |
| 471 | */ |
| 472 | int rxrpc_stats_clear(struct file *file, char *buf, size_t size) |
| 473 | { |
| 474 | struct seq_file *m = file->private_data; |
| 475 | struct rxrpc_net *rxnet = rxrpc_net(seq_file_single_net(m)); |
| 476 | |
| 477 | if (size > 1 || (size == 1 && buf[0] != '\n')) |
| 478 | return -EINVAL; |
| 479 | |
| 480 | atomic_set(&rxnet->stat_tx_data, 0); |
| 481 | atomic_set(&rxnet->stat_tx_data_retrans, 0); |
David Howells | 32cf8ed | 2022-11-11 13:47:35 +0000 | [diff] [blame] | 482 | atomic_set(&rxnet->stat_tx_data_underflow, 0); |
| 483 | atomic_set(&rxnet->stat_tx_data_cwnd_reset, 0); |
David Howells | b015424 | 2022-05-11 14:01:25 +0100 | [diff] [blame] | 484 | atomic_set(&rxnet->stat_tx_data_send, 0); |
| 485 | atomic_set(&rxnet->stat_tx_data_send_frag, 0); |
David Howells | 32cf8ed | 2022-11-11 13:47:35 +0000 | [diff] [blame] | 486 | atomic_set(&rxnet->stat_tx_data_send_fail, 0); |
David Howells | b015424 | 2022-05-11 14:01:25 +0100 | [diff] [blame] | 487 | atomic_set(&rxnet->stat_rx_data, 0); |
| 488 | atomic_set(&rxnet->stat_rx_data_reqack, 0); |
| 489 | atomic_set(&rxnet->stat_rx_data_jumbo, 0); |
David Howells | f2a676d | 2022-05-11 14:01:25 +0100 | [diff] [blame] | 490 | |
| 491 | atomic_set(&rxnet->stat_tx_ack_fill, 0); |
| 492 | atomic_set(&rxnet->stat_tx_ack_send, 0); |
| 493 | atomic_set(&rxnet->stat_tx_ack_skip, 0); |
| 494 | memset(&rxnet->stat_tx_acks, 0, sizeof(rxnet->stat_tx_acks)); |
| 495 | memset(&rxnet->stat_rx_acks, 0, sizeof(rxnet->stat_rx_acks)); |
David Howells | f7fa524 | 2022-08-18 11:52:36 +0100 | [diff] [blame] | 496 | |
| 497 | memset(&rxnet->stat_why_req_ack, 0, sizeof(rxnet->stat_why_req_ack)); |
David Howells | a275da6 | 2022-10-10 08:45:20 +0100 | [diff] [blame] | 498 | |
| 499 | atomic_set(&rxnet->stat_io_loop, 0); |
David Howells | b015424 | 2022-05-11 14:01:25 +0100 | [diff] [blame] | 500 | return size; |
| 501 | } |