blob: f79f260c6ddce66254ee86997d70b14d4b455a67 [file] [log] [blame]
David Howells17926a72007-04-26 15:48:28 -07001/* /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 Howellsbba304d2016-06-27 10:32:02 +010017static const char *const rxrpc_conn_states[RXRPC_CONN__NR_STATES] = {
18 [RXRPC_CONN_UNUSED] = "Unused ",
19 [RXRPC_CONN_CLIENT] = "Client ",
David Howells00e90712016-09-08 11:10:12 +010020 [RXRPC_CONN_SERVICE_PREALLOC] = "SvPrealc",
David Howellsbba304d2016-06-27 10:32:02 +010021 [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 Howells17926a72007-04-26 15:48:28 -070026};
27
David Howells17926a72007-04-26 15:48:28 -070028/*
29 * generate a list of extant and dead calls in /proc/net/rxrpc_calls
30 */
31static void *rxrpc_call_seq_start(struct seq_file *seq, loff_t *_pos)
32{
David Howells2baec2c2017-05-24 17:02:32 +010033 struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
34
David Howells8d94aa32016-09-07 09:19:31 +010035 rcu_read_lock();
David Howells2baec2c2017-05-24 17:02:32 +010036 read_lock(&rxnet->call_lock);
37 return seq_list_start_head(&rxnet->calls, *_pos);
David Howells17926a72007-04-26 15:48:28 -070038}
39
40static void *rxrpc_call_seq_next(struct seq_file *seq, void *v, loff_t *pos)
41{
David Howells2baec2c2017-05-24 17:02:32 +010042 struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
43
44 return seq_list_next(v, &rxnet->calls, pos);
David Howells17926a72007-04-26 15:48:28 -070045}
46
47static void rxrpc_call_seq_stop(struct seq_file *seq, void *v)
48{
David Howells2baec2c2017-05-24 17:02:32 +010049 struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
50
51 read_unlock(&rxnet->call_lock);
David Howells8d94aa32016-09-07 09:19:31 +010052 rcu_read_unlock();
David Howells17926a72007-04-26 15:48:28 -070053}
54
55static int rxrpc_call_seq_show(struct seq_file *seq, void *v)
56{
David Howellsdf5d8bf2016-08-24 14:31:43 +010057 struct rxrpc_local *local;
58 struct rxrpc_sock *rx;
59 struct rxrpc_peer *peer;
David Howells17926a72007-04-26 15:48:28 -070060 struct rxrpc_call *call;
David Howells2baec2c2017-05-24 17:02:32 +010061 struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
David Howells3e018da2017-01-05 10:38:33 +000062 rxrpc_seq_t tx_hard_ack, rx_hard_ack;
David Howells75b54cb2016-09-13 08:49:05 +010063 char lbuff[50], rbuff[50];
David Howells17926a72007-04-26 15:48:28 -070064
David Howells2baec2c2017-05-24 17:02:32 +010065 if (v == &rxnet->calls) {
David Howells17926a72007-04-26 15:48:28 -070066 seq_puts(seq,
David Howells75b54cb2016-09-13 08:49:05 +010067 "Proto Local "
68 " Remote "
David Howells17926a72007-04-26 15:48:28 -070069 " SvID ConnID CallID End Use State Abort "
70 " UserID\n");
71 return 0;
72 }
73
74 call = list_entry(v, struct rxrpc_call, link);
David Howells17926a72007-04-26 15:48:28 -070075
David Howells8d94aa32016-09-07 09:19:31 +010076 rx = rcu_dereference(call->socket);
David Howellsdf5d8bf2016-08-24 14:31:43 +010077 if (rx) {
78 local = READ_ONCE(rx->local);
79 if (local)
David Howells75b54cb2016-09-13 08:49:05 +010080 sprintf(lbuff, "%pISpc", &local->srx.transport);
David Howellsdf5d8bf2016-08-24 14:31:43 +010081 else
82 strcpy(lbuff, "no_local");
83 } else {
84 strcpy(lbuff, "no_socket");
85 }
David Howells17926a72007-04-26 15:48:28 -070086
David Howellsdf5d8bf2016-08-24 14:31:43 +010087 peer = call->peer;
88 if (peer)
David Howells75b54cb2016-09-13 08:49:05 +010089 sprintf(rbuff, "%pISpc", &peer->srx.transport);
David Howellsf4e7da82016-06-17 11:07:55 +010090 else
91 strcpy(rbuff, "no_connection");
David Howells17926a72007-04-26 15:48:28 -070092
David Howells3e018da2017-01-05 10:38:33 +000093 tx_hard_ack = READ_ONCE(call->tx_hard_ack);
94 rx_hard_ack = READ_ONCE(call->rx_hard_ack);
David Howells17926a72007-04-26 15:48:28 -070095 seq_printf(seq,
David Howells75b54cb2016-09-13 08:49:05 +010096 "UDP %-47.47s %-47.47s %4x %08x %08x %s %3u"
David Howells3e018da2017-01-05 10:38:33 +000097 " %-8.8s %08x %lx %08x %02x %08x %02x\n",
David Howells17926a72007-04-26 15:48:28 -070098 lbuff,
99 rbuff,
David Howellsf4e7da82016-06-17 11:07:55 +0100100 call->service_id,
David Howells0d12f8a2016-03-04 15:53:46 +0000101 call->cid,
102 call->call_id,
David Howellsdabe5a72016-08-23 15:27:24 +0100103 rxrpc_is_service_call(call) ? "Svc" : "Clt",
David Howells17926a72007-04-26 15:48:28 -0700104 atomic_read(&call->usage),
105 rxrpc_call_states[call->state],
David Howellsf5c17aa2016-08-30 09:49:28 +0100106 call->abort_code,
David Howells3e018da2017-01-05 10:38:33 +0000107 call->user_call_ID,
108 tx_hard_ack, READ_ONCE(call->tx_top) - tx_hard_ack,
109 rx_hard_ack, READ_ONCE(call->rx_top) - rx_hard_ack);
David Howells17926a72007-04-26 15:48:28 -0700110
111 return 0;
112}
113
Philippe De Muyter56b3d972007-07-10 23:07:31 -0700114static const struct seq_operations rxrpc_call_seq_ops = {
David Howells17926a72007-04-26 15:48:28 -0700115 .start = rxrpc_call_seq_start,
116 .next = rxrpc_call_seq_next,
117 .stop = rxrpc_call_seq_stop,
118 .show = rxrpc_call_seq_show,
119};
120
121static int rxrpc_call_seq_open(struct inode *inode, struct file *file)
122{
David Howells2baec2c2017-05-24 17:02:32 +0100123 return seq_open_net(inode, file, &rxrpc_call_seq_ops,
124 sizeof(struct seq_net_private));
David Howells17926a72007-04-26 15:48:28 -0700125}
126
Jan Engelhardt036c2e22008-01-30 18:55:45 -0800127const struct file_operations rxrpc_call_seq_fops = {
David Howells17926a72007-04-26 15:48:28 -0700128 .open = rxrpc_call_seq_open,
129 .read = seq_read,
130 .llseek = seq_lseek,
Pavel Emelyanov665bba12008-02-29 11:39:17 -0800131 .release = seq_release,
David Howells17926a72007-04-26 15:48:28 -0700132};
133
134/*
135 * generate a list of extant virtual connections in /proc/net/rxrpc_conns
136 */
137static void *rxrpc_connection_seq_start(struct seq_file *seq, loff_t *_pos)
138{
David Howells2baec2c2017-05-24 17:02:32 +0100139 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 Howells17926a72007-04-26 15:48:28 -0700143}
144
145static void *rxrpc_connection_seq_next(struct seq_file *seq, void *v,
146 loff_t *pos)
147{
David Howells2baec2c2017-05-24 17:02:32 +0100148 struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
149
150 return seq_list_next(v, &rxnet->conn_proc_list, pos);
David Howells17926a72007-04-26 15:48:28 -0700151}
152
153static void rxrpc_connection_seq_stop(struct seq_file *seq, void *v)
154{
David Howells2baec2c2017-05-24 17:02:32 +0100155 struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
156
157 read_unlock(&rxnet->conn_lock);
David Howells17926a72007-04-26 15:48:28 -0700158}
159
160static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
161{
162 struct rxrpc_connection *conn;
David Howells2baec2c2017-05-24 17:02:32 +0100163 struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
David Howells75b54cb2016-09-13 08:49:05 +0100164 char lbuff[50], rbuff[50];
David Howells17926a72007-04-26 15:48:28 -0700165
David Howells2baec2c2017-05-24 17:02:32 +0100166 if (v == &rxnet->conn_proc_list) {
David Howells17926a72007-04-26 15:48:28 -0700167 seq_puts(seq,
David Howells75b54cb2016-09-13 08:49:05 +0100168 "Proto Local "
169 " Remote "
David Howellsa1399f82016-06-27 14:39:44 +0100170 " SvID ConnID End Use State Key "
David Howells17926a72007-04-26 15:48:28 -0700171 " Serial ISerial\n"
172 );
173 return 0;
174 }
175
David Howells4d028b22016-08-24 07:30:52 +0100176 conn = list_entry(v, struct rxrpc_connection, proc_link);
David Howells00e90712016-09-08 11:10:12 +0100177 if (conn->state == RXRPC_CONN_SERVICE_PREALLOC) {
178 strcpy(lbuff, "no_local");
179 strcpy(rbuff, "no_connection");
180 goto print;
181 }
David Howells17926a72007-04-26 15:48:28 -0700182
David Howells75b54cb2016-09-13 08:49:05 +0100183 sprintf(lbuff, "%pISpc", &conn->params.local->srx.transport);
David Howells17926a72007-04-26 15:48:28 -0700184
David Howells75b54cb2016-09-13 08:49:05 +0100185 sprintf(rbuff, "%pISpc", &conn->params.peer->srx.transport);
David Howells00e90712016-09-08 11:10:12 +0100186print:
David Howells17926a72007-04-26 15:48:28 -0700187 seq_printf(seq,
David Howells75b54cb2016-09-13 08:49:05 +0100188 "UDP %-47.47s %-47.47s %4x %08x %s %3u"
David Howells17926a72007-04-26 15:48:28 -0700189 " %s %08x %08x %08x\n",
190 lbuff,
191 rbuff,
David Howells68d6d1a2017-06-05 14:30:49 +0100192 conn->service_id,
David Howells19ffa012016-04-04 14:00:36 +0100193 conn->proto.cid,
David Howells19ffa012016-04-04 14:00:36 +0100194 rxrpc_conn_is_service(conn) ? "Svc" : "Clt",
David Howells17926a72007-04-26 15:48:28 -0700195 atomic_read(&conn->usage),
196 rxrpc_conn_states[conn->state],
David Howells19ffa012016-04-04 14:00:36 +0100197 key_serial(conn->params.key),
David Howells17926a72007-04-26 15:48:28 -0700198 atomic_read(&conn->serial),
David Howells563ea7d2016-08-23 15:27:25 +0100199 conn->hi_serial);
David Howells17926a72007-04-26 15:48:28 -0700200
201 return 0;
202}
203
Philippe De Muyter56b3d972007-07-10 23:07:31 -0700204static const struct seq_operations rxrpc_connection_seq_ops = {
David Howells17926a72007-04-26 15:48:28 -0700205 .start = rxrpc_connection_seq_start,
206 .next = rxrpc_connection_seq_next,
207 .stop = rxrpc_connection_seq_stop,
208 .show = rxrpc_connection_seq_show,
209};
210
211
212static int rxrpc_connection_seq_open(struct inode *inode, struct file *file)
213{
David Howells2baec2c2017-05-24 17:02:32 +0100214 return seq_open_net(inode, file, &rxrpc_connection_seq_ops,
215 sizeof(struct seq_net_private));
David Howells17926a72007-04-26 15:48:28 -0700216}
217
Jan Engelhardt036c2e22008-01-30 18:55:45 -0800218const struct file_operations rxrpc_connection_seq_fops = {
David Howells17926a72007-04-26 15:48:28 -0700219 .open = rxrpc_connection_seq_open,
220 .read = seq_read,
221 .llseek = seq_lseek,
Pavel Emelyanov665bba12008-02-29 11:39:17 -0800222 .release = seq_release,
David Howells17926a72007-04-26 15:48:28 -0700223};