blob: d529d1b4021c097b17062b4a7700900633f5e034 [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 Howells8d94aa32016-09-07 09:19:31 +010033 rcu_read_lock();
David Howells17926a72007-04-26 15:48:28 -070034 read_lock(&rxrpc_call_lock);
Pavel Emelianov60f04382007-07-09 13:15:14 -070035 return seq_list_start_head(&rxrpc_calls, *_pos);
David Howells17926a72007-04-26 15:48:28 -070036}
37
38static void *rxrpc_call_seq_next(struct seq_file *seq, void *v, loff_t *pos)
39{
Pavel Emelianov60f04382007-07-09 13:15:14 -070040 return seq_list_next(v, &rxrpc_calls, pos);
David Howells17926a72007-04-26 15:48:28 -070041}
42
43static void rxrpc_call_seq_stop(struct seq_file *seq, void *v)
44{
45 read_unlock(&rxrpc_call_lock);
David Howells8d94aa32016-09-07 09:19:31 +010046 rcu_read_unlock();
David Howells17926a72007-04-26 15:48:28 -070047}
48
49static int rxrpc_call_seq_show(struct seq_file *seq, void *v)
50{
David Howellsdf5d8bf2016-08-24 14:31:43 +010051 struct rxrpc_local *local;
52 struct rxrpc_sock *rx;
53 struct rxrpc_peer *peer;
David Howells17926a72007-04-26 15:48:28 -070054 struct rxrpc_call *call;
55 char lbuff[4 + 4 + 4 + 4 + 5 + 1], rbuff[4 + 4 + 4 + 4 + 5 + 1];
56
Pavel Emelianov60f04382007-07-09 13:15:14 -070057 if (v == &rxrpc_calls) {
David Howells17926a72007-04-26 15:48:28 -070058 seq_puts(seq,
59 "Proto Local Remote "
60 " SvID ConnID CallID End Use State Abort "
61 " UserID\n");
62 return 0;
63 }
64
65 call = list_entry(v, struct rxrpc_call, link);
David Howells17926a72007-04-26 15:48:28 -070066
David Howells8d94aa32016-09-07 09:19:31 +010067 rx = rcu_dereference(call->socket);
David Howellsdf5d8bf2016-08-24 14:31:43 +010068 if (rx) {
69 local = READ_ONCE(rx->local);
70 if (local)
71 sprintf(lbuff, "%pI4:%u",
72 &local->srx.transport.sin.sin_addr,
73 ntohs(local->srx.transport.sin.sin_port));
74 else
75 strcpy(lbuff, "no_local");
76 } else {
77 strcpy(lbuff, "no_socket");
78 }
David Howells17926a72007-04-26 15:48:28 -070079
David Howellsdf5d8bf2016-08-24 14:31:43 +010080 peer = call->peer;
81 if (peer)
David Howellsf4e7da82016-06-17 11:07:55 +010082 sprintf(rbuff, "%pI4:%u",
David Howellsdf5d8bf2016-08-24 14:31:43 +010083 &peer->srx.transport.sin.sin_addr,
84 ntohs(peer->srx.transport.sin.sin_port));
David Howellsf4e7da82016-06-17 11:07:55 +010085 else
86 strcpy(rbuff, "no_connection");
David Howells17926a72007-04-26 15:48:28 -070087
88 seq_printf(seq,
89 "UDP %-22.22s %-22.22s %4x %08x %08x %s %3u"
90 " %-8.8s %08x %lx\n",
91 lbuff,
92 rbuff,
David Howellsf4e7da82016-06-17 11:07:55 +010093 call->service_id,
David Howells0d12f8a2016-03-04 15:53:46 +000094 call->cid,
95 call->call_id,
David Howellsdabe5a72016-08-23 15:27:24 +010096 rxrpc_is_service_call(call) ? "Svc" : "Clt",
David Howells17926a72007-04-26 15:48:28 -070097 atomic_read(&call->usage),
98 rxrpc_call_states[call->state],
David Howellsf5c17aa2016-08-30 09:49:28 +010099 call->abort_code,
David Howells17926a72007-04-26 15:48:28 -0700100 call->user_call_ID);
101
102 return 0;
103}
104
Philippe De Muyter56b3d972007-07-10 23:07:31 -0700105static const struct seq_operations rxrpc_call_seq_ops = {
David Howells17926a72007-04-26 15:48:28 -0700106 .start = rxrpc_call_seq_start,
107 .next = rxrpc_call_seq_next,
108 .stop = rxrpc_call_seq_stop,
109 .show = rxrpc_call_seq_show,
110};
111
112static int rxrpc_call_seq_open(struct inode *inode, struct file *file)
113{
114 return seq_open(file, &rxrpc_call_seq_ops);
115}
116
Jan Engelhardt036c2e22008-01-30 18:55:45 -0800117const struct file_operations rxrpc_call_seq_fops = {
David Howells17926a72007-04-26 15:48:28 -0700118 .owner = THIS_MODULE,
119 .open = rxrpc_call_seq_open,
120 .read = seq_read,
121 .llseek = seq_lseek,
Pavel Emelyanov665bba12008-02-29 11:39:17 -0800122 .release = seq_release,
David Howells17926a72007-04-26 15:48:28 -0700123};
124
125/*
126 * generate a list of extant virtual connections in /proc/net/rxrpc_conns
127 */
128static void *rxrpc_connection_seq_start(struct seq_file *seq, loff_t *_pos)
129{
David Howells17926a72007-04-26 15:48:28 -0700130 read_lock(&rxrpc_connection_lock);
David Howells4d028b22016-08-24 07:30:52 +0100131 return seq_list_start_head(&rxrpc_connection_proc_list, *_pos);
David Howells17926a72007-04-26 15:48:28 -0700132}
133
134static void *rxrpc_connection_seq_next(struct seq_file *seq, void *v,
135 loff_t *pos)
136{
David Howells4d028b22016-08-24 07:30:52 +0100137 return seq_list_next(v, &rxrpc_connection_proc_list, pos);
David Howells17926a72007-04-26 15:48:28 -0700138}
139
140static void rxrpc_connection_seq_stop(struct seq_file *seq, void *v)
141{
142 read_unlock(&rxrpc_connection_lock);
143}
144
145static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
146{
147 struct rxrpc_connection *conn;
David Howells17926a72007-04-26 15:48:28 -0700148 char lbuff[4 + 4 + 4 + 4 + 5 + 1], rbuff[4 + 4 + 4 + 4 + 5 + 1];
149
David Howells4d028b22016-08-24 07:30:52 +0100150 if (v == &rxrpc_connection_proc_list) {
David Howells17926a72007-04-26 15:48:28 -0700151 seq_puts(seq,
152 "Proto Local Remote "
David Howellsa1399f82016-06-27 14:39:44 +0100153 " SvID ConnID End Use State Key "
David Howells17926a72007-04-26 15:48:28 -0700154 " Serial ISerial\n"
155 );
156 return 0;
157 }
158
David Howells4d028b22016-08-24 07:30:52 +0100159 conn = list_entry(v, struct rxrpc_connection, proc_link);
David Howells00e90712016-09-08 11:10:12 +0100160 if (conn->state == RXRPC_CONN_SERVICE_PREALLOC) {
161 strcpy(lbuff, "no_local");
162 strcpy(rbuff, "no_connection");
163 goto print;
164 }
David Howells17926a72007-04-26 15:48:28 -0700165
Harvey Harrison21454aa2008-10-31 00:54:56 -0700166 sprintf(lbuff, "%pI4:%u",
David Howells85f32272016-04-04 14:00:36 +0100167 &conn->params.local->srx.transport.sin.sin_addr,
168 ntohs(conn->params.local->srx.transport.sin.sin_port));
David Howells17926a72007-04-26 15:48:28 -0700169
Harvey Harrison21454aa2008-10-31 00:54:56 -0700170 sprintf(rbuff, "%pI4:%u",
David Howells85f32272016-04-04 14:00:36 +0100171 &conn->params.peer->srx.transport.sin.sin_addr,
172 ntohs(conn->params.peer->srx.transport.sin.sin_port));
David Howells00e90712016-09-08 11:10:12 +0100173print:
David Howells17926a72007-04-26 15:48:28 -0700174 seq_printf(seq,
David Howellsa1399f82016-06-27 14:39:44 +0100175 "UDP %-22.22s %-22.22s %4x %08x %s %3u"
David Howells17926a72007-04-26 15:48:28 -0700176 " %s %08x %08x %08x\n",
177 lbuff,
178 rbuff,
David Howells19ffa012016-04-04 14:00:36 +0100179 conn->params.service_id,
180 conn->proto.cid,
David Howells19ffa012016-04-04 14:00:36 +0100181 rxrpc_conn_is_service(conn) ? "Svc" : "Clt",
David Howells17926a72007-04-26 15:48:28 -0700182 atomic_read(&conn->usage),
183 rxrpc_conn_states[conn->state],
David Howells19ffa012016-04-04 14:00:36 +0100184 key_serial(conn->params.key),
David Howells17926a72007-04-26 15:48:28 -0700185 atomic_read(&conn->serial),
David Howells563ea7d2016-08-23 15:27:25 +0100186 conn->hi_serial);
David Howells17926a72007-04-26 15:48:28 -0700187
188 return 0;
189}
190
Philippe De Muyter56b3d972007-07-10 23:07:31 -0700191static const struct seq_operations rxrpc_connection_seq_ops = {
David Howells17926a72007-04-26 15:48:28 -0700192 .start = rxrpc_connection_seq_start,
193 .next = rxrpc_connection_seq_next,
194 .stop = rxrpc_connection_seq_stop,
195 .show = rxrpc_connection_seq_show,
196};
197
198
199static int rxrpc_connection_seq_open(struct inode *inode, struct file *file)
200{
201 return seq_open(file, &rxrpc_connection_seq_ops);
202}
203
Jan Engelhardt036c2e22008-01-30 18:55:45 -0800204const struct file_operations rxrpc_connection_seq_fops = {
David Howells17926a72007-04-26 15:48:28 -0700205 .owner = THIS_MODULE,
206 .open = rxrpc_connection_seq_open,
207 .read = seq_read,
208 .llseek = seq_lseek,
Pavel Emelyanov665bba12008-02-29 11:39:17 -0800209 .release = seq_release,
David Howells17926a72007-04-26 15:48:28 -0700210};