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