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