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