blob: 163d05df339d0738e3551dc746eb77816b3754cc [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)
David Howells88f2a8252018-03-30 21:05:17 +010032 __acquires(rcu)
33 __acquires(rxnet->call_lock)
David Howells17926a72007-04-26 15:48:28 -070034{
David Howells2baec2c2017-05-24 17:02:32 +010035 struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
36
David Howells8d94aa32016-09-07 09:19:31 +010037 rcu_read_lock();
David Howells2baec2c2017-05-24 17:02:32 +010038 read_lock(&rxnet->call_lock);
39 return seq_list_start_head(&rxnet->calls, *_pos);
David Howells17926a72007-04-26 15:48:28 -070040}
41
42static void *rxrpc_call_seq_next(struct seq_file *seq, void *v, loff_t *pos)
43{
David Howells2baec2c2017-05-24 17:02:32 +010044 struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
45
46 return seq_list_next(v, &rxnet->calls, pos);
David Howells17926a72007-04-26 15:48:28 -070047}
48
49static void rxrpc_call_seq_stop(struct seq_file *seq, void *v)
David Howells88f2a8252018-03-30 21:05:17 +010050 __releases(rxnet->call_lock)
51 __releases(rcu)
David Howells17926a72007-04-26 15:48:28 -070052{
David Howells2baec2c2017-05-24 17:02:32 +010053 struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
54
55 read_unlock(&rxnet->call_lock);
David Howells8d94aa32016-09-07 09:19:31 +010056 rcu_read_unlock();
David Howells17926a72007-04-26 15:48:28 -070057}
58
59static int rxrpc_call_seq_show(struct seq_file *seq, void *v)
60{
David Howellsdf5d8bf2016-08-24 14:31:43 +010061 struct rxrpc_local *local;
62 struct rxrpc_sock *rx;
63 struct rxrpc_peer *peer;
David Howells17926a72007-04-26 15:48:28 -070064 struct rxrpc_call *call;
David Howells2baec2c2017-05-24 17:02:32 +010065 struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
David Howells887763b2018-07-23 17:18:36 +010066 unsigned long timeout = 0, nowj;
David Howells3e018da2017-01-05 10:38:33 +000067 rxrpc_seq_t tx_hard_ack, rx_hard_ack;
David Howells75b54cb2016-09-13 08:49:05 +010068 char lbuff[50], rbuff[50];
David Howells17926a72007-04-26 15:48:28 -070069
David Howells2baec2c2017-05-24 17:02:32 +010070 if (v == &rxnet->calls) {
David Howells17926a72007-04-26 15:48:28 -070071 seq_puts(seq,
David Howells75b54cb2016-09-13 08:49:05 +010072 "Proto Local "
73 " Remote "
David Howells17926a72007-04-26 15:48:28 -070074 " SvID ConnID CallID End Use State Abort "
David Howells6b97bd72018-07-23 17:18:36 +010075 " UserID TxSeq TW RxSeq RW RxSerial RxTimo\n");
David Howells17926a72007-04-26 15:48:28 -070076 return 0;
77 }
78
79 call = list_entry(v, struct rxrpc_call, link);
David Howells17926a72007-04-26 15:48:28 -070080
David Howells8d94aa32016-09-07 09:19:31 +010081 rx = rcu_dereference(call->socket);
David Howellsdf5d8bf2016-08-24 14:31:43 +010082 if (rx) {
83 local = READ_ONCE(rx->local);
84 if (local)
David Howells75b54cb2016-09-13 08:49:05 +010085 sprintf(lbuff, "%pISpc", &local->srx.transport);
David Howellsdf5d8bf2016-08-24 14:31:43 +010086 else
87 strcpy(lbuff, "no_local");
88 } else {
89 strcpy(lbuff, "no_socket");
90 }
David Howells17926a72007-04-26 15:48:28 -070091
David Howellsdf5d8bf2016-08-24 14:31:43 +010092 peer = call->peer;
93 if (peer)
David Howells75b54cb2016-09-13 08:49:05 +010094 sprintf(rbuff, "%pISpc", &peer->srx.transport);
David Howellsf4e7da82016-06-17 11:07:55 +010095 else
96 strcpy(rbuff, "no_connection");
David Howells17926a72007-04-26 15:48:28 -070097
David Howells887763b2018-07-23 17:18:36 +010098 if (call->state != RXRPC_CALL_SERVER_PREALLOC) {
99 timeout = READ_ONCE(call->expect_rx_by);
100 nowj = jiffies;
101 timeout -= jiffies;
102 }
103
David Howells3e018da2017-01-05 10:38:33 +0000104 tx_hard_ack = READ_ONCE(call->tx_hard_ack);
105 rx_hard_ack = READ_ONCE(call->rx_hard_ack);
David Howells17926a72007-04-26 15:48:28 -0700106 seq_printf(seq,
David Howells75b54cb2016-09-13 08:49:05 +0100107 "UDP %-47.47s %-47.47s %4x %08x %08x %s %3u"
David Howells6b97bd72018-07-23 17:18:36 +0100108 " %-8.8s %08x %lx %08x %02x %08x %02x %08x %06lx\n",
David Howells17926a72007-04-26 15:48:28 -0700109 lbuff,
110 rbuff,
David Howellsf4e7da82016-06-17 11:07:55 +0100111 call->service_id,
David Howells0d12f8a2016-03-04 15:53:46 +0000112 call->cid,
113 call->call_id,
David Howellsdabe5a72016-08-23 15:27:24 +0100114 rxrpc_is_service_call(call) ? "Svc" : "Clt",
David Howells17926a72007-04-26 15:48:28 -0700115 atomic_read(&call->usage),
116 rxrpc_call_states[call->state],
David Howellsf5c17aa2016-08-30 09:49:28 +0100117 call->abort_code,
David Howells3e018da2017-01-05 10:38:33 +0000118 call->user_call_ID,
119 tx_hard_ack, READ_ONCE(call->tx_top) - tx_hard_ack,
David Howells887763b2018-07-23 17:18:36 +0100120 rx_hard_ack, READ_ONCE(call->rx_top) - rx_hard_ack,
David Howells6b97bd72018-07-23 17:18:36 +0100121 call->rx_serial,
David Howells887763b2018-07-23 17:18:36 +0100122 timeout);
David Howells17926a72007-04-26 15:48:28 -0700123
124 return 0;
125}
126
Christoph Hellwigc3506372018-04-10 19:42:55 +0200127const struct seq_operations rxrpc_call_seq_ops = {
David Howells17926a72007-04-26 15:48:28 -0700128 .start = rxrpc_call_seq_start,
129 .next = rxrpc_call_seq_next,
130 .stop = rxrpc_call_seq_stop,
131 .show = rxrpc_call_seq_show,
132};
133
David Howells17926a72007-04-26 15:48:28 -0700134/*
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)
David Howells88f2a8252018-03-30 21:05:17 +0100138 __acquires(rxnet->conn_lock)
David Howells17926a72007-04-26 15:48:28 -0700139{
David Howells2baec2c2017-05-24 17:02:32 +0100140 struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
141
142 read_lock(&rxnet->conn_lock);
143 return seq_list_start_head(&rxnet->conn_proc_list, *_pos);
David Howells17926a72007-04-26 15:48:28 -0700144}
145
146static void *rxrpc_connection_seq_next(struct seq_file *seq, void *v,
147 loff_t *pos)
148{
David Howells2baec2c2017-05-24 17:02:32 +0100149 struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
150
151 return seq_list_next(v, &rxnet->conn_proc_list, pos);
David Howells17926a72007-04-26 15:48:28 -0700152}
153
154static void rxrpc_connection_seq_stop(struct seq_file *seq, void *v)
David Howells88f2a8252018-03-30 21:05:17 +0100155 __releases(rxnet->conn_lock)
David Howells17926a72007-04-26 15:48:28 -0700156{
David Howells2baec2c2017-05-24 17:02:32 +0100157 struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
158
159 read_unlock(&rxnet->conn_lock);
David Howells17926a72007-04-26 15:48:28 -0700160}
161
162static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
163{
164 struct rxrpc_connection *conn;
David Howells2baec2c2017-05-24 17:02:32 +0100165 struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
David Howells75b54cb2016-09-13 08:49:05 +0100166 char lbuff[50], rbuff[50];
David Howells17926a72007-04-26 15:48:28 -0700167
David Howells2baec2c2017-05-24 17:02:32 +0100168 if (v == &rxnet->conn_proc_list) {
David Howells17926a72007-04-26 15:48:28 -0700169 seq_puts(seq,
David Howells75b54cb2016-09-13 08:49:05 +0100170 "Proto Local "
171 " Remote "
David Howellsa1399f82016-06-27 14:39:44 +0100172 " SvID ConnID End Use State Key "
David Howells17926a72007-04-26 15:48:28 -0700173 " Serial ISerial\n"
174 );
175 return 0;
176 }
177
David Howells4d028b22016-08-24 07:30:52 +0100178 conn = list_entry(v, struct rxrpc_connection, proc_link);
David Howells00e90712016-09-08 11:10:12 +0100179 if (conn->state == RXRPC_CONN_SERVICE_PREALLOC) {
180 strcpy(lbuff, "no_local");
181 strcpy(rbuff, "no_connection");
182 goto print;
183 }
David Howells17926a72007-04-26 15:48:28 -0700184
David Howells75b54cb2016-09-13 08:49:05 +0100185 sprintf(lbuff, "%pISpc", &conn->params.local->srx.transport);
David Howells17926a72007-04-26 15:48:28 -0700186
David Howells75b54cb2016-09-13 08:49:05 +0100187 sprintf(rbuff, "%pISpc", &conn->params.peer->srx.transport);
David Howells00e90712016-09-08 11:10:12 +0100188print:
David Howells17926a72007-04-26 15:48:28 -0700189 seq_printf(seq,
David Howells75b54cb2016-09-13 08:49:05 +0100190 "UDP %-47.47s %-47.47s %4x %08x %s %3u"
David Howells6b97bd72018-07-23 17:18:36 +0100191 " %s %08x %08x %08x %08x %08x %08x %08x\n",
David Howells17926a72007-04-26 15:48:28 -0700192 lbuff,
193 rbuff,
David Howells68d6d1a2017-06-05 14:30:49 +0100194 conn->service_id,
David Howells19ffa012016-04-04 14:00:36 +0100195 conn->proto.cid,
David Howells19ffa012016-04-04 14:00:36 +0100196 rxrpc_conn_is_service(conn) ? "Svc" : "Clt",
David Howells17926a72007-04-26 15:48:28 -0700197 atomic_read(&conn->usage),
198 rxrpc_conn_states[conn->state],
David Howells19ffa012016-04-04 14:00:36 +0100199 key_serial(conn->params.key),
David Howells17926a72007-04-26 15:48:28 -0700200 atomic_read(&conn->serial),
David Howells6b97bd72018-07-23 17:18:36 +0100201 conn->hi_serial,
202 conn->channels[0].call_id,
203 conn->channels[1].call_id,
204 conn->channels[2].call_id,
205 conn->channels[3].call_id);
David Howells17926a72007-04-26 15:48:28 -0700206
207 return 0;
208}
209
Christoph Hellwigc3506372018-04-10 19:42:55 +0200210const struct seq_operations rxrpc_connection_seq_ops = {
David Howells17926a72007-04-26 15:48:28 -0700211 .start = rxrpc_connection_seq_start,
212 .next = rxrpc_connection_seq_next,
213 .stop = rxrpc_connection_seq_stop,
214 .show = rxrpc_connection_seq_show,
215};