Commit | Line | Data |
---|---|---|
17926a79 DH |
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 | ||
bba304db DH |
17 | static const char *const rxrpc_conn_states[RXRPC_CONN__NR_STATES] = { |
18 | [RXRPC_CONN_UNUSED] = "Unused ", | |
19 | [RXRPC_CONN_CLIENT] = "Client ", | |
00e90712 | 20 | [RXRPC_CONN_SERVICE_PREALLOC] = "SvPrealc", |
bba304db DH |
21 | [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", | |
17926a79 DH |
26 | }; |
27 | ||
17926a79 DH |
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 | { | |
8d94aa38 | 33 | rcu_read_lock(); |
17926a79 | 34 | read_lock(&rxrpc_call_lock); |
60f0438a | 35 | return seq_list_start_head(&rxrpc_calls, *_pos); |
17926a79 DH |
36 | } |
37 | ||
38 | static void *rxrpc_call_seq_next(struct seq_file *seq, void *v, loff_t *pos) | |
39 | { | |
60f0438a | 40 | return seq_list_next(v, &rxrpc_calls, pos); |
17926a79 DH |
41 | } |
42 | ||
43 | static void rxrpc_call_seq_stop(struct seq_file *seq, void *v) | |
44 | { | |
45 | read_unlock(&rxrpc_call_lock); | |
8d94aa38 | 46 | rcu_read_unlock(); |
17926a79 DH |
47 | } |
48 | ||
49 | static int rxrpc_call_seq_show(struct seq_file *seq, void *v) | |
50 | { | |
df5d8bf7 DH |
51 | struct rxrpc_local *local; |
52 | struct rxrpc_sock *rx; | |
53 | struct rxrpc_peer *peer; | |
17926a79 DH |
54 | struct rxrpc_call *call; |
55 | char lbuff[4 + 4 + 4 + 4 + 5 + 1], rbuff[4 + 4 + 4 + 4 + 5 + 1]; | |
56 | ||
60f0438a | 57 | if (v == &rxrpc_calls) { |
17926a79 DH |
58 | 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); | |
17926a79 | 66 | |
8d94aa38 | 67 | rx = rcu_dereference(call->socket); |
df5d8bf7 DH |
68 | 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 | } | |
17926a79 | 79 | |
df5d8bf7 DH |
80 | peer = call->peer; |
81 | if (peer) | |
f4e7da8c | 82 | sprintf(rbuff, "%pI4:%u", |
df5d8bf7 DH |
83 | &peer->srx.transport.sin.sin_addr, |
84 | ntohs(peer->srx.transport.sin.sin_port)); | |
f4e7da8c DH |
85 | else |
86 | strcpy(rbuff, "no_connection"); | |
17926a79 DH |
87 | |
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, | |
f4e7da8c | 93 | call->service_id, |
0d12f8a4 DH |
94 | call->cid, |
95 | call->call_id, | |
dabe5a79 | 96 | rxrpc_is_service_call(call) ? "Svc" : "Clt", |
17926a79 DH |
97 | atomic_read(&call->usage), |
98 | rxrpc_call_states[call->state], | |
f5c17aae | 99 | call->abort_code, |
17926a79 DH |
100 | call->user_call_ID); |
101 | ||
102 | return 0; | |
103 | } | |
104 | ||
56b3d975 | 105 | static const struct seq_operations rxrpc_call_seq_ops = { |
17926a79 DH |
106 | .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 | ||
112 | static int rxrpc_call_seq_open(struct inode *inode, struct file *file) | |
113 | { | |
114 | return seq_open(file, &rxrpc_call_seq_ops); | |
115 | } | |
116 | ||
036c2e27 | 117 | const struct file_operations rxrpc_call_seq_fops = { |
17926a79 DH |
118 | .owner = THIS_MODULE, |
119 | .open = rxrpc_call_seq_open, | |
120 | .read = seq_read, | |
121 | .llseek = seq_lseek, | |
665bba10 | 122 | .release = seq_release, |
17926a79 DH |
123 | }; |
124 | ||
125 | /* | |
126 | * generate a list of extant virtual connections in /proc/net/rxrpc_conns | |
127 | */ | |
128 | static void *rxrpc_connection_seq_start(struct seq_file *seq, loff_t *_pos) | |
129 | { | |
17926a79 | 130 | read_lock(&rxrpc_connection_lock); |
4d028b2c | 131 | return seq_list_start_head(&rxrpc_connection_proc_list, *_pos); |
17926a79 DH |
132 | } |
133 | ||
134 | static void *rxrpc_connection_seq_next(struct seq_file *seq, void *v, | |
135 | loff_t *pos) | |
136 | { | |
4d028b2c | 137 | return seq_list_next(v, &rxrpc_connection_proc_list, pos); |
17926a79 DH |
138 | } |
139 | ||
140 | static void rxrpc_connection_seq_stop(struct seq_file *seq, void *v) | |
141 | { | |
142 | read_unlock(&rxrpc_connection_lock); | |
143 | } | |
144 | ||
145 | static int rxrpc_connection_seq_show(struct seq_file *seq, void *v) | |
146 | { | |
147 | struct rxrpc_connection *conn; | |
17926a79 DH |
148 | char lbuff[4 + 4 + 4 + 4 + 5 + 1], rbuff[4 + 4 + 4 + 4 + 5 + 1]; |
149 | ||
4d028b2c | 150 | if (v == &rxrpc_connection_proc_list) { |
17926a79 DH |
151 | seq_puts(seq, |
152 | "Proto Local Remote " | |
a1399f8b | 153 | " SvID ConnID End Use State Key " |
17926a79 DH |
154 | " Serial ISerial\n" |
155 | ); | |
156 | return 0; | |
157 | } | |
158 | ||
4d028b2c | 159 | conn = list_entry(v, struct rxrpc_connection, proc_link); |
00e90712 DH |
160 | if (conn->state == RXRPC_CONN_SERVICE_PREALLOC) { |
161 | strcpy(lbuff, "no_local"); | |
162 | strcpy(rbuff, "no_connection"); | |
163 | goto print; | |
164 | } | |
17926a79 | 165 | |
21454aaa | 166 | sprintf(lbuff, "%pI4:%u", |
85f32278 DH |
167 | &conn->params.local->srx.transport.sin.sin_addr, |
168 | ntohs(conn->params.local->srx.transport.sin.sin_port)); | |
17926a79 | 169 | |
21454aaa | 170 | sprintf(rbuff, "%pI4:%u", |
85f32278 DH |
171 | &conn->params.peer->srx.transport.sin.sin_addr, |
172 | ntohs(conn->params.peer->srx.transport.sin.sin_port)); | |
00e90712 | 173 | print: |
17926a79 | 174 | seq_printf(seq, |
a1399f8b | 175 | "UDP %-22.22s %-22.22s %4x %08x %s %3u" |
17926a79 DH |
176 | " %s %08x %08x %08x\n", |
177 | lbuff, | |
178 | rbuff, | |
19ffa01c DH |
179 | conn->params.service_id, |
180 | conn->proto.cid, | |
19ffa01c | 181 | rxrpc_conn_is_service(conn) ? "Svc" : "Clt", |
17926a79 DH |
182 | atomic_read(&conn->usage), |
183 | rxrpc_conn_states[conn->state], | |
19ffa01c | 184 | key_serial(conn->params.key), |
17926a79 | 185 | atomic_read(&conn->serial), |
563ea7d5 | 186 | conn->hi_serial); |
17926a79 DH |
187 | |
188 | return 0; | |
189 | } | |
190 | ||
56b3d975 | 191 | static const struct seq_operations rxrpc_connection_seq_ops = { |
17926a79 DH |
192 | .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 | ||
199 | static int rxrpc_connection_seq_open(struct inode *inode, struct file *file) | |
200 | { | |
201 | return seq_open(file, &rxrpc_connection_seq_ops); | |
202 | } | |
203 | ||
036c2e27 | 204 | const struct file_operations rxrpc_connection_seq_fops = { |
17926a79 DH |
205 | .owner = THIS_MODULE, |
206 | .open = rxrpc_connection_seq_open, | |
207 | .read = seq_read, | |
208 | .llseek = seq_lseek, | |
665bba10 | 209 | .release = seq_release, |
17926a79 | 210 | }; |