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) |
| 32 | { |
David Howells | 8d94aa3 | 2016-09-07 09:19:31 +0100 | [diff] [blame] | 33 | rcu_read_lock(); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 34 | read_lock(&rxrpc_call_lock); |
Pavel Emelianov | 60f0438 | 2007-07-09 13:15:14 -0700 | [diff] [blame] | 35 | return seq_list_start_head(&rxrpc_calls, *_pos); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | static void *rxrpc_call_seq_next(struct seq_file *seq, void *v, loff_t *pos) |
| 39 | { |
Pavel Emelianov | 60f0438 | 2007-07-09 13:15:14 -0700 | [diff] [blame] | 40 | return seq_list_next(v, &rxrpc_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) |
| 44 | { |
| 45 | read_unlock(&rxrpc_call_lock); |
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; |
| 52 | struct rxrpc_sock *rx; |
| 53 | struct rxrpc_peer *peer; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 54 | struct rxrpc_call *call; |
David Howells | 3e018da | 2017-01-05 10:38:33 +0000 | [diff] [blame] | 55 | rxrpc_seq_t tx_hard_ack, rx_hard_ack; |
David Howells | 75b54cb | 2016-09-13 08:49:05 +0100 | [diff] [blame] | 56 | char lbuff[50], rbuff[50]; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 57 | |
Pavel Emelianov | 60f0438 | 2007-07-09 13:15:14 -0700 | [diff] [blame] | 58 | if (v == &rxrpc_calls) { |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 59 | seq_puts(seq, |
David Howells | 75b54cb | 2016-09-13 08:49:05 +0100 | [diff] [blame] | 60 | "Proto Local " |
| 61 | " Remote " |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 62 | " SvID ConnID CallID End Use State Abort " |
| 63 | " UserID\n"); |
| 64 | return 0; |
| 65 | } |
| 66 | |
| 67 | call = list_entry(v, struct rxrpc_call, link); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 68 | |
David Howells | 8d94aa3 | 2016-09-07 09:19:31 +0100 | [diff] [blame] | 69 | rx = rcu_dereference(call->socket); |
David Howells | df5d8bf | 2016-08-24 14:31:43 +0100 | [diff] [blame] | 70 | if (rx) { |
| 71 | local = READ_ONCE(rx->local); |
| 72 | if (local) |
David Howells | 75b54cb | 2016-09-13 08:49:05 +0100 | [diff] [blame] | 73 | sprintf(lbuff, "%pISpc", &local->srx.transport); |
David Howells | df5d8bf | 2016-08-24 14:31:43 +0100 | [diff] [blame] | 74 | else |
| 75 | strcpy(lbuff, "no_local"); |
| 76 | } else { |
| 77 | strcpy(lbuff, "no_socket"); |
| 78 | } |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 79 | |
David Howells | df5d8bf | 2016-08-24 14:31:43 +0100 | [diff] [blame] | 80 | peer = call->peer; |
| 81 | if (peer) |
David Howells | 75b54cb | 2016-09-13 08:49:05 +0100 | [diff] [blame] | 82 | sprintf(rbuff, "%pISpc", &peer->srx.transport); |
David Howells | f4e7da8 | 2016-06-17 11:07:55 +0100 | [diff] [blame] | 83 | else |
| 84 | strcpy(rbuff, "no_connection"); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 85 | |
David Howells | 3e018da | 2017-01-05 10:38:33 +0000 | [diff] [blame] | 86 | tx_hard_ack = READ_ONCE(call->tx_hard_ack); |
| 87 | rx_hard_ack = READ_ONCE(call->rx_hard_ack); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 88 | seq_printf(seq, |
David Howells | 75b54cb | 2016-09-13 08:49:05 +0100 | [diff] [blame] | 89 | "UDP %-47.47s %-47.47s %4x %08x %08x %s %3u" |
David Howells | 3e018da | 2017-01-05 10:38:33 +0000 | [diff] [blame] | 90 | " %-8.8s %08x %lx %08x %02x %08x %02x\n", |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 91 | lbuff, |
| 92 | rbuff, |
David Howells | f4e7da8 | 2016-06-17 11:07:55 +0100 | [diff] [blame] | 93 | call->service_id, |
David Howells | 0d12f8a | 2016-03-04 15:53:46 +0000 | [diff] [blame] | 94 | call->cid, |
| 95 | call->call_id, |
David Howells | dabe5a7 | 2016-08-23 15:27:24 +0100 | [diff] [blame] | 96 | rxrpc_is_service_call(call) ? "Svc" : "Clt", |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 97 | atomic_read(&call->usage), |
| 98 | rxrpc_call_states[call->state], |
David Howells | f5c17aa | 2016-08-30 09:49:28 +0100 | [diff] [blame] | 99 | call->abort_code, |
David Howells | 3e018da | 2017-01-05 10:38:33 +0000 | [diff] [blame] | 100 | call->user_call_ID, |
| 101 | tx_hard_ack, READ_ONCE(call->tx_top) - tx_hard_ack, |
| 102 | rx_hard_ack, READ_ONCE(call->rx_top) - rx_hard_ack); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 103 | |
| 104 | return 0; |
| 105 | } |
| 106 | |
Philippe De Muyter | 56b3d97 | 2007-07-10 23:07:31 -0700 | [diff] [blame] | 107 | static 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 | |
| 114 | static int rxrpc_call_seq_open(struct inode *inode, struct file *file) |
| 115 | { |
| 116 | return seq_open(file, &rxrpc_call_seq_ops); |
| 117 | } |
| 118 | |
Jan Engelhardt | 036c2e2 | 2008-01-30 18:55:45 -0800 | [diff] [blame] | 119 | const struct file_operations rxrpc_call_seq_fops = { |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 120 | .owner = THIS_MODULE, |
| 121 | .open = rxrpc_call_seq_open, |
| 122 | .read = seq_read, |
| 123 | .llseek = seq_lseek, |
Pavel Emelyanov | 665bba1 | 2008-02-29 11:39:17 -0800 | [diff] [blame] | 124 | .release = seq_release, |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 125 | }; |
| 126 | |
| 127 | /* |
| 128 | * generate a list of extant virtual connections in /proc/net/rxrpc_conns |
| 129 | */ |
| 130 | static void *rxrpc_connection_seq_start(struct seq_file *seq, loff_t *_pos) |
| 131 | { |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 132 | read_lock(&rxrpc_connection_lock); |
David Howells | 4d028b2 | 2016-08-24 07:30:52 +0100 | [diff] [blame] | 133 | return seq_list_start_head(&rxrpc_connection_proc_list, *_pos); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | static void *rxrpc_connection_seq_next(struct seq_file *seq, void *v, |
| 137 | loff_t *pos) |
| 138 | { |
David Howells | 4d028b2 | 2016-08-24 07:30:52 +0100 | [diff] [blame] | 139 | return seq_list_next(v, &rxrpc_connection_proc_list, pos); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | static void rxrpc_connection_seq_stop(struct seq_file *seq, void *v) |
| 143 | { |
| 144 | read_unlock(&rxrpc_connection_lock); |
| 145 | } |
| 146 | |
| 147 | static int rxrpc_connection_seq_show(struct seq_file *seq, void *v) |
| 148 | { |
| 149 | struct rxrpc_connection *conn; |
David Howells | 75b54cb | 2016-09-13 08:49:05 +0100 | [diff] [blame] | 150 | char lbuff[50], rbuff[50]; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 151 | |
David Howells | 4d028b2 | 2016-08-24 07:30:52 +0100 | [diff] [blame] | 152 | if (v == &rxrpc_connection_proc_list) { |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 153 | seq_puts(seq, |
David Howells | 75b54cb | 2016-09-13 08:49:05 +0100 | [diff] [blame] | 154 | "Proto Local " |
| 155 | " Remote " |
David Howells | a1399f8 | 2016-06-27 14:39:44 +0100 | [diff] [blame] | 156 | " SvID ConnID End Use State Key " |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 157 | " Serial ISerial\n" |
| 158 | ); |
| 159 | return 0; |
| 160 | } |
| 161 | |
David Howells | 4d028b2 | 2016-08-24 07:30:52 +0100 | [diff] [blame] | 162 | conn = list_entry(v, struct rxrpc_connection, proc_link); |
David Howells | 00e9071 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 163 | if (conn->state == RXRPC_CONN_SERVICE_PREALLOC) { |
| 164 | strcpy(lbuff, "no_local"); |
| 165 | strcpy(rbuff, "no_connection"); |
| 166 | goto print; |
| 167 | } |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 168 | |
David Howells | 75b54cb | 2016-09-13 08:49:05 +0100 | [diff] [blame] | 169 | sprintf(lbuff, "%pISpc", &conn->params.local->srx.transport); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 170 | |
David Howells | 75b54cb | 2016-09-13 08:49:05 +0100 | [diff] [blame] | 171 | sprintf(rbuff, "%pISpc", &conn->params.peer->srx.transport); |
David Howells | 00e9071 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 172 | print: |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 173 | seq_printf(seq, |
David Howells | 75b54cb | 2016-09-13 08:49:05 +0100 | [diff] [blame] | 174 | "UDP %-47.47s %-47.47s %4x %08x %s %3u" |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 175 | " %s %08x %08x %08x\n", |
| 176 | lbuff, |
| 177 | rbuff, |
David Howells | 19ffa01 | 2016-04-04 14:00:36 +0100 | [diff] [blame] | 178 | conn->params.service_id, |
| 179 | conn->proto.cid, |
David Howells | 19ffa01 | 2016-04-04 14:00:36 +0100 | [diff] [blame] | 180 | rxrpc_conn_is_service(conn) ? "Svc" : "Clt", |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 181 | atomic_read(&conn->usage), |
| 182 | rxrpc_conn_states[conn->state], |
David Howells | 19ffa01 | 2016-04-04 14:00:36 +0100 | [diff] [blame] | 183 | key_serial(conn->params.key), |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 184 | atomic_read(&conn->serial), |
David Howells | 563ea7d | 2016-08-23 15:27:25 +0100 | [diff] [blame] | 185 | conn->hi_serial); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 186 | |
| 187 | return 0; |
| 188 | } |
| 189 | |
Philippe De Muyter | 56b3d97 | 2007-07-10 23:07:31 -0700 | [diff] [blame] | 190 | static const struct seq_operations rxrpc_connection_seq_ops = { |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 191 | .start = rxrpc_connection_seq_start, |
| 192 | .next = rxrpc_connection_seq_next, |
| 193 | .stop = rxrpc_connection_seq_stop, |
| 194 | .show = rxrpc_connection_seq_show, |
| 195 | }; |
| 196 | |
| 197 | |
| 198 | static int rxrpc_connection_seq_open(struct inode *inode, struct file *file) |
| 199 | { |
| 200 | return seq_open(file, &rxrpc_connection_seq_ops); |
| 201 | } |
| 202 | |
Jan Engelhardt | 036c2e2 | 2008-01-30 18:55:45 -0800 | [diff] [blame] | 203 | const struct file_operations rxrpc_connection_seq_fops = { |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 204 | .owner = THIS_MODULE, |
| 205 | .open = rxrpc_connection_seq_open, |
| 206 | .read = seq_read, |
| 207 | .llseek = seq_lseek, |
Pavel Emelyanov | 665bba1 | 2008-02-29 11:39:17 -0800 | [diff] [blame] | 208 | .release = seq_release, |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 209 | }; |