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 ", | |
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", | |
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 | { | |
17926a79 | 33 | read_lock(&rxrpc_call_lock); |
60f0438a | 34 | return seq_list_start_head(&rxrpc_calls, *_pos); |
17926a79 DH |
35 | } |
36 | ||
37 | static void *rxrpc_call_seq_next(struct seq_file *seq, void *v, loff_t *pos) | |
38 | { | |
60f0438a | 39 | return seq_list_next(v, &rxrpc_calls, pos); |
17926a79 DH |
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 | { | |
df5d8bf7 DH |
49 | struct rxrpc_local *local; |
50 | struct rxrpc_sock *rx; | |
51 | struct rxrpc_peer *peer; | |
17926a79 DH |
52 | struct rxrpc_call *call; |
53 | char lbuff[4 + 4 + 4 + 4 + 5 + 1], rbuff[4 + 4 + 4 + 4 + 5 + 1]; | |
54 | ||
60f0438a | 55 | if (v == &rxrpc_calls) { |
17926a79 DH |
56 | seq_puts(seq, |
57 | "Proto Local Remote " | |
58 | " SvID ConnID CallID End Use State Abort " | |
59 | " UserID\n"); | |
60 | return 0; | |
61 | } | |
62 | ||
63 | call = list_entry(v, struct rxrpc_call, link); | |
17926a79 | 64 | |
df5d8bf7 DH |
65 | rx = READ_ONCE(call->socket); |
66 | if (rx) { | |
67 | local = READ_ONCE(rx->local); | |
68 | if (local) | |
69 | sprintf(lbuff, "%pI4:%u", | |
70 | &local->srx.transport.sin.sin_addr, | |
71 | ntohs(local->srx.transport.sin.sin_port)); | |
72 | else | |
73 | strcpy(lbuff, "no_local"); | |
74 | } else { | |
75 | strcpy(lbuff, "no_socket"); | |
76 | } | |
17926a79 | 77 | |
df5d8bf7 DH |
78 | peer = call->peer; |
79 | if (peer) | |
f4e7da8c | 80 | sprintf(rbuff, "%pI4:%u", |
df5d8bf7 DH |
81 | &peer->srx.transport.sin.sin_addr, |
82 | ntohs(peer->srx.transport.sin.sin_port)); | |
f4e7da8c DH |
83 | else |
84 | strcpy(rbuff, "no_connection"); | |
17926a79 DH |
85 | |
86 | seq_printf(seq, | |
87 | "UDP %-22.22s %-22.22s %4x %08x %08x %s %3u" | |
88 | " %-8.8s %08x %lx\n", | |
89 | lbuff, | |
90 | rbuff, | |
f4e7da8c | 91 | call->service_id, |
0d12f8a4 DH |
92 | call->cid, |
93 | call->call_id, | |
dabe5a79 | 94 | rxrpc_is_service_call(call) ? "Svc" : "Clt", |
17926a79 DH |
95 | atomic_read(&call->usage), |
96 | rxrpc_call_states[call->state], | |
dc44b3a0 | 97 | call->remote_abort ?: call->local_abort, |
17926a79 DH |
98 | call->user_call_ID); |
99 | ||
100 | return 0; | |
101 | } | |
102 | ||
56b3d975 | 103 | static const struct seq_operations rxrpc_call_seq_ops = { |
17926a79 DH |
104 | .start = rxrpc_call_seq_start, |
105 | .next = rxrpc_call_seq_next, | |
106 | .stop = rxrpc_call_seq_stop, | |
107 | .show = rxrpc_call_seq_show, | |
108 | }; | |
109 | ||
110 | static int rxrpc_call_seq_open(struct inode *inode, struct file *file) | |
111 | { | |
112 | return seq_open(file, &rxrpc_call_seq_ops); | |
113 | } | |
114 | ||
036c2e27 | 115 | const struct file_operations rxrpc_call_seq_fops = { |
17926a79 DH |
116 | .owner = THIS_MODULE, |
117 | .open = rxrpc_call_seq_open, | |
118 | .read = seq_read, | |
119 | .llseek = seq_lseek, | |
665bba10 | 120 | .release = seq_release, |
17926a79 DH |
121 | }; |
122 | ||
123 | /* | |
124 | * generate a list of extant virtual connections in /proc/net/rxrpc_conns | |
125 | */ | |
126 | static void *rxrpc_connection_seq_start(struct seq_file *seq, loff_t *_pos) | |
127 | { | |
17926a79 | 128 | read_lock(&rxrpc_connection_lock); |
4d028b2c | 129 | return seq_list_start_head(&rxrpc_connection_proc_list, *_pos); |
17926a79 DH |
130 | } |
131 | ||
132 | static void *rxrpc_connection_seq_next(struct seq_file *seq, void *v, | |
133 | loff_t *pos) | |
134 | { | |
4d028b2c | 135 | return seq_list_next(v, &rxrpc_connection_proc_list, pos); |
17926a79 DH |
136 | } |
137 | ||
138 | static void rxrpc_connection_seq_stop(struct seq_file *seq, void *v) | |
139 | { | |
140 | read_unlock(&rxrpc_connection_lock); | |
141 | } | |
142 | ||
143 | static int rxrpc_connection_seq_show(struct seq_file *seq, void *v) | |
144 | { | |
145 | struct rxrpc_connection *conn; | |
17926a79 DH |
146 | char lbuff[4 + 4 + 4 + 4 + 5 + 1], rbuff[4 + 4 + 4 + 4 + 5 + 1]; |
147 | ||
4d028b2c | 148 | if (v == &rxrpc_connection_proc_list) { |
17926a79 DH |
149 | seq_puts(seq, |
150 | "Proto Local Remote " | |
a1399f8b | 151 | " SvID ConnID End Use State Key " |
17926a79 DH |
152 | " Serial ISerial\n" |
153 | ); | |
154 | return 0; | |
155 | } | |
156 | ||
4d028b2c | 157 | conn = list_entry(v, struct rxrpc_connection, proc_link); |
17926a79 | 158 | |
21454aaa | 159 | sprintf(lbuff, "%pI4:%u", |
85f32278 DH |
160 | &conn->params.local->srx.transport.sin.sin_addr, |
161 | ntohs(conn->params.local->srx.transport.sin.sin_port)); | |
17926a79 | 162 | |
21454aaa | 163 | sprintf(rbuff, "%pI4:%u", |
85f32278 DH |
164 | &conn->params.peer->srx.transport.sin.sin_addr, |
165 | ntohs(conn->params.peer->srx.transport.sin.sin_port)); | |
17926a79 DH |
166 | |
167 | seq_printf(seq, | |
a1399f8b | 168 | "UDP %-22.22s %-22.22s %4x %08x %s %3u" |
17926a79 DH |
169 | " %s %08x %08x %08x\n", |
170 | lbuff, | |
171 | rbuff, | |
19ffa01c DH |
172 | conn->params.service_id, |
173 | conn->proto.cid, | |
19ffa01c | 174 | rxrpc_conn_is_service(conn) ? "Svc" : "Clt", |
17926a79 DH |
175 | atomic_read(&conn->usage), |
176 | rxrpc_conn_states[conn->state], | |
19ffa01c | 177 | key_serial(conn->params.key), |
17926a79 | 178 | atomic_read(&conn->serial), |
563ea7d5 | 179 | conn->hi_serial); |
17926a79 DH |
180 | |
181 | return 0; | |
182 | } | |
183 | ||
56b3d975 | 184 | static const struct seq_operations rxrpc_connection_seq_ops = { |
17926a79 DH |
185 | .start = rxrpc_connection_seq_start, |
186 | .next = rxrpc_connection_seq_next, | |
187 | .stop = rxrpc_connection_seq_stop, | |
188 | .show = rxrpc_connection_seq_show, | |
189 | }; | |
190 | ||
191 | ||
192 | static int rxrpc_connection_seq_open(struct inode *inode, struct file *file) | |
193 | { | |
194 | return seq_open(file, &rxrpc_connection_seq_ops); | |
195 | } | |
196 | ||
036c2e27 | 197 | const struct file_operations rxrpc_connection_seq_fops = { |
17926a79 DH |
198 | .owner = THIS_MODULE, |
199 | .open = rxrpc_connection_seq_open, | |
200 | .read = seq_read, | |
201 | .llseek = seq_lseek, | |
665bba10 | 202 | .release = seq_release, |
17926a79 | 203 | }; |