1 /* proc.c: /proc interface for RxRPC
3 * Copyright (C) 2002 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
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.
12 #include <linux/sched.h>
13 #include <linux/slab.h>
14 #include <linux/module.h>
15 #include <linux/proc_fs.h>
16 #include <linux/seq_file.h>
17 #include <rxrpc/rxrpc.h>
18 #include <rxrpc/transport.h>
19 #include <rxrpc/peer.h>
20 #include <rxrpc/connection.h>
21 #include <rxrpc/call.h>
22 #include <rxrpc/message.h>
25 static struct proc_dir_entry *proc_rxrpc;
27 static int rxrpc_proc_transports_open(struct inode *inode, struct file *file);
28 static void *rxrpc_proc_transports_start(struct seq_file *p, loff_t *pos);
29 static void *rxrpc_proc_transports_next(struct seq_file *p, void *v, loff_t *pos);
30 static void rxrpc_proc_transports_stop(struct seq_file *p, void *v);
31 static int rxrpc_proc_transports_show(struct seq_file *m, void *v);
33 static struct seq_operations rxrpc_proc_transports_ops = {
34 .start = rxrpc_proc_transports_start,
35 .next = rxrpc_proc_transports_next,
36 .stop = rxrpc_proc_transports_stop,
37 .show = rxrpc_proc_transports_show,
40 static struct file_operations rxrpc_proc_transports_fops = {
41 .open = rxrpc_proc_transports_open,
44 .release = seq_release,
47 static int rxrpc_proc_peers_open(struct inode *inode, struct file *file);
48 static void *rxrpc_proc_peers_start(struct seq_file *p, loff_t *pos);
49 static void *rxrpc_proc_peers_next(struct seq_file *p, void *v, loff_t *pos);
50 static void rxrpc_proc_peers_stop(struct seq_file *p, void *v);
51 static int rxrpc_proc_peers_show(struct seq_file *m, void *v);
53 static struct seq_operations rxrpc_proc_peers_ops = {
54 .start = rxrpc_proc_peers_start,
55 .next = rxrpc_proc_peers_next,
56 .stop = rxrpc_proc_peers_stop,
57 .show = rxrpc_proc_peers_show,
60 static struct file_operations rxrpc_proc_peers_fops = {
61 .open = rxrpc_proc_peers_open,
64 .release = seq_release,
67 static int rxrpc_proc_conns_open(struct inode *inode, struct file *file);
68 static void *rxrpc_proc_conns_start(struct seq_file *p, loff_t *pos);
69 static void *rxrpc_proc_conns_next(struct seq_file *p, void *v, loff_t *pos);
70 static void rxrpc_proc_conns_stop(struct seq_file *p, void *v);
71 static int rxrpc_proc_conns_show(struct seq_file *m, void *v);
73 static struct seq_operations rxrpc_proc_conns_ops = {
74 .start = rxrpc_proc_conns_start,
75 .next = rxrpc_proc_conns_next,
76 .stop = rxrpc_proc_conns_stop,
77 .show = rxrpc_proc_conns_show,
80 static struct file_operations rxrpc_proc_conns_fops = {
81 .open = rxrpc_proc_conns_open,
84 .release = seq_release,
87 static int rxrpc_proc_calls_open(struct inode *inode, struct file *file);
88 static void *rxrpc_proc_calls_start(struct seq_file *p, loff_t *pos);
89 static void *rxrpc_proc_calls_next(struct seq_file *p, void *v, loff_t *pos);
90 static void rxrpc_proc_calls_stop(struct seq_file *p, void *v);
91 static int rxrpc_proc_calls_show(struct seq_file *m, void *v);
93 static struct seq_operations rxrpc_proc_calls_ops = {
94 .start = rxrpc_proc_calls_start,
95 .next = rxrpc_proc_calls_next,
96 .stop = rxrpc_proc_calls_stop,
97 .show = rxrpc_proc_calls_show,
100 static struct file_operations rxrpc_proc_calls_fops = {
101 .open = rxrpc_proc_calls_open,
104 .release = seq_release,
107 static const char *rxrpc_call_states7[] = {
120 static const char *rxrpc_call_error_states7[] = {
128 /*****************************************************************************/
130 * initialise the /proc/net/rxrpc/ directory
132 int rxrpc_proc_init(void)
134 struct proc_dir_entry *p;
136 proc_rxrpc = proc_mkdir("rxrpc", proc_net);
139 proc_rxrpc->owner = THIS_MODULE;
141 p = create_proc_entry("calls", 0, proc_rxrpc);
144 p->proc_fops = &rxrpc_proc_calls_fops;
145 p->owner = THIS_MODULE;
147 p = create_proc_entry("connections", 0, proc_rxrpc);
150 p->proc_fops = &rxrpc_proc_conns_fops;
151 p->owner = THIS_MODULE;
153 p = create_proc_entry("peers", 0, proc_rxrpc);
156 p->proc_fops = &rxrpc_proc_peers_fops;
157 p->owner = THIS_MODULE;
159 p = create_proc_entry("transports", 0, proc_rxrpc);
162 p->proc_fops = &rxrpc_proc_transports_fops;
163 p->owner = THIS_MODULE;
168 remove_proc_entry("connections", proc_rxrpc);
170 remove_proc_entry("calls", proc_rxrpc);
172 remove_proc_entry("rxrpc", proc_net);
175 } /* end rxrpc_proc_init() */
177 /*****************************************************************************/
179 * clean up the /proc/net/rxrpc/ directory
181 void rxrpc_proc_cleanup(void)
183 remove_proc_entry("transports", proc_rxrpc);
184 remove_proc_entry("peers", proc_rxrpc);
185 remove_proc_entry("connections", proc_rxrpc);
186 remove_proc_entry("calls", proc_rxrpc);
188 remove_proc_entry("rxrpc", proc_net);
190 } /* end rxrpc_proc_cleanup() */
192 /*****************************************************************************/
194 * open "/proc/net/rxrpc/transports" which provides a summary of extant transports
196 static int rxrpc_proc_transports_open(struct inode *inode, struct file *file)
201 ret = seq_open(file, &rxrpc_proc_transports_ops);
205 m = file->private_data;
206 m->private = PDE(inode)->data;
209 } /* end rxrpc_proc_transports_open() */
211 /*****************************************************************************/
213 * set up the iterator to start reading from the transports list and return the first item
215 static void *rxrpc_proc_transports_start(struct seq_file *m, loff_t *_pos)
217 struct list_head *_p;
220 /* lock the list against modification */
221 down_read(&rxrpc_proc_transports_sem);
223 /* allow for the header line */
225 return SEQ_START_TOKEN;
228 /* find the n'th element in the list */
229 list_for_each(_p, &rxrpc_proc_transports)
233 return _p != &rxrpc_proc_transports ? _p : NULL;
234 } /* end rxrpc_proc_transports_start() */
236 /*****************************************************************************/
238 * move to next call in transports list
240 static void *rxrpc_proc_transports_next(struct seq_file *p, void *v, loff_t *pos)
242 struct list_head *_p;
247 _p = (v == SEQ_START_TOKEN) ? rxrpc_proc_transports.next : _p->next;
249 return _p != &rxrpc_proc_transports ? _p : NULL;
250 } /* end rxrpc_proc_transports_next() */
252 /*****************************************************************************/
254 * clean up after reading from the transports list
256 static void rxrpc_proc_transports_stop(struct seq_file *p, void *v)
258 up_read(&rxrpc_proc_transports_sem);
260 } /* end rxrpc_proc_transports_stop() */
262 /*****************************************************************************/
264 * display a header line followed by a load of call lines
266 static int rxrpc_proc_transports_show(struct seq_file *m, void *v)
268 struct rxrpc_transport *trans =
269 list_entry(v, struct rxrpc_transport, proc_link);
271 /* display header on line 1 */
272 if (v == SEQ_START_TOKEN) {
273 seq_puts(m, "LOCAL USE\n");
277 /* display one transport per line on subsequent lines */
278 seq_printf(m, "%5hu %3d\n",
280 atomic_read(&trans->usage)
284 } /* end rxrpc_proc_transports_show() */
286 /*****************************************************************************/
288 * open "/proc/net/rxrpc/peers" which provides a summary of extant peers
290 static int rxrpc_proc_peers_open(struct inode *inode, struct file *file)
295 ret = seq_open(file, &rxrpc_proc_peers_ops);
299 m = file->private_data;
300 m->private = PDE(inode)->data;
303 } /* end rxrpc_proc_peers_open() */
305 /*****************************************************************************/
307 * set up the iterator to start reading from the peers list and return the
310 static void *rxrpc_proc_peers_start(struct seq_file *m, loff_t *_pos)
312 struct list_head *_p;
315 /* lock the list against modification */
316 down_read(&rxrpc_peers_sem);
318 /* allow for the header line */
320 return SEQ_START_TOKEN;
323 /* find the n'th element in the list */
324 list_for_each(_p, &rxrpc_peers)
328 return _p != &rxrpc_peers ? _p : NULL;
329 } /* end rxrpc_proc_peers_start() */
331 /*****************************************************************************/
333 * move to next conn in peers list
335 static void *rxrpc_proc_peers_next(struct seq_file *p, void *v, loff_t *pos)
337 struct list_head *_p;
342 _p = (v == SEQ_START_TOKEN) ? rxrpc_peers.next : _p->next;
344 return _p != &rxrpc_peers ? _p : NULL;
345 } /* end rxrpc_proc_peers_next() */
347 /*****************************************************************************/
349 * clean up after reading from the peers list
351 static void rxrpc_proc_peers_stop(struct seq_file *p, void *v)
353 up_read(&rxrpc_peers_sem);
355 } /* end rxrpc_proc_peers_stop() */
357 /*****************************************************************************/
359 * display a header line followed by a load of conn lines
361 static int rxrpc_proc_peers_show(struct seq_file *m, void *v)
363 struct rxrpc_peer *peer = list_entry(v, struct rxrpc_peer, proc_link);
366 /* display header on line 1 */
367 if (v == SEQ_START_TOKEN) {
368 seq_puts(m, "LOCAL REMOTE USAGE CONNS TIMEOUT"
373 /* display one peer per line on subsequent lines */
375 if (!list_empty(&peer->timeout.link))
376 timeout = (signed long) peer->timeout.timo_jif -
377 (signed long) jiffies;
379 seq_printf(m, "%5hu %08x %5d %5d %8ld %5Zu %7lu\n",
381 ntohl(peer->addr.s_addr),
382 atomic_read(&peer->usage),
383 atomic_read(&peer->conn_count),
390 } /* end rxrpc_proc_peers_show() */
392 /*****************************************************************************/
394 * open "/proc/net/rxrpc/connections" which provides a summary of extant
397 static int rxrpc_proc_conns_open(struct inode *inode, struct file *file)
402 ret = seq_open(file, &rxrpc_proc_conns_ops);
406 m = file->private_data;
407 m->private = PDE(inode)->data;
410 } /* end rxrpc_proc_conns_open() */
412 /*****************************************************************************/
414 * set up the iterator to start reading from the conns list and return the
417 static void *rxrpc_proc_conns_start(struct seq_file *m, loff_t *_pos)
419 struct list_head *_p;
422 /* lock the list against modification */
423 down_read(&rxrpc_conns_sem);
425 /* allow for the header line */
427 return SEQ_START_TOKEN;
430 /* find the n'th element in the list */
431 list_for_each(_p, &rxrpc_conns)
435 return _p != &rxrpc_conns ? _p : NULL;
436 } /* end rxrpc_proc_conns_start() */
438 /*****************************************************************************/
440 * move to next conn in conns list
442 static void *rxrpc_proc_conns_next(struct seq_file *p, void *v, loff_t *pos)
444 struct list_head *_p;
449 _p = (v == SEQ_START_TOKEN) ? rxrpc_conns.next : _p->next;
451 return _p != &rxrpc_conns ? _p : NULL;
452 } /* end rxrpc_proc_conns_next() */
454 /*****************************************************************************/
456 * clean up after reading from the conns list
458 static void rxrpc_proc_conns_stop(struct seq_file *p, void *v)
460 up_read(&rxrpc_conns_sem);
462 } /* end rxrpc_proc_conns_stop() */
464 /*****************************************************************************/
466 * display a header line followed by a load of conn lines
468 static int rxrpc_proc_conns_show(struct seq_file *m, void *v)
470 struct rxrpc_connection *conn;
473 conn = list_entry(v, struct rxrpc_connection, proc_link);
475 /* display header on line 1 */
476 if (v == SEQ_START_TOKEN) {
478 "LOCAL REMOTE RPORT SRVC CONN END SERIALNO "
484 /* display one conn per line on subsequent lines */
486 if (!list_empty(&conn->timeout.link))
487 timeout = (signed long) conn->timeout.timo_jif -
488 (signed long) jiffies;
491 "%5hu %08x %5hu %04hx %08x %-3.3s %08x %08x %5Zu %8ld\n",
493 ntohl(conn->addr.sin_addr.s_addr),
494 ntohs(conn->addr.sin_port),
495 ntohs(conn->service_id),
496 ntohl(conn->conn_id),
497 conn->out_clientflag ? "CLT" : "SRV",
498 conn->serial_counter,
505 } /* end rxrpc_proc_conns_show() */
507 /*****************************************************************************/
509 * open "/proc/net/rxrpc/calls" which provides a summary of extant calls
511 static int rxrpc_proc_calls_open(struct inode *inode, struct file *file)
516 ret = seq_open(file, &rxrpc_proc_calls_ops);
520 m = file->private_data;
521 m->private = PDE(inode)->data;
524 } /* end rxrpc_proc_calls_open() */
526 /*****************************************************************************/
528 * set up the iterator to start reading from the calls list and return the
531 static void *rxrpc_proc_calls_start(struct seq_file *m, loff_t *_pos)
533 struct list_head *_p;
536 /* lock the list against modification */
537 down_read(&rxrpc_calls_sem);
539 /* allow for the header line */
541 return SEQ_START_TOKEN;
544 /* find the n'th element in the list */
545 list_for_each(_p, &rxrpc_calls)
549 return _p != &rxrpc_calls ? _p : NULL;
550 } /* end rxrpc_proc_calls_start() */
552 /*****************************************************************************/
554 * move to next call in calls list
556 static void *rxrpc_proc_calls_next(struct seq_file *p, void *v, loff_t *pos)
558 struct list_head *_p;
563 _p = (v == SEQ_START_TOKEN) ? rxrpc_calls.next : _p->next;
565 return _p != &rxrpc_calls ? _p : NULL;
566 } /* end rxrpc_proc_calls_next() */
568 /*****************************************************************************/
570 * clean up after reading from the calls list
572 static void rxrpc_proc_calls_stop(struct seq_file *p, void *v)
574 up_read(&rxrpc_calls_sem);
576 } /* end rxrpc_proc_calls_stop() */
578 /*****************************************************************************/
580 * display a header line followed by a load of call lines
582 static int rxrpc_proc_calls_show(struct seq_file *m, void *v)
584 struct rxrpc_call *call = list_entry(v, struct rxrpc_call, call_link);
586 /* display header on line 1 */
587 if (v == SEQ_START_TOKEN) {
589 "LOCAL REMOT SRVC CONN CALL DIR USE "
590 " L STATE OPCODE ABORT ERRNO\n"
595 /* display one call per line on subsequent lines */
597 "%5hu %5hu %04hx %08x %08x %s %3u%c"
598 " %c %-7.7s %6d %08x %5d\n",
599 call->conn->trans->port,
600 ntohs(call->conn->addr.sin_port),
601 ntohs(call->conn->service_id),
602 ntohl(call->conn->conn_id),
603 ntohl(call->call_id),
604 call->conn->service ? "SVC" : "CLT",
605 atomic_read(&call->usage),
606 waitqueue_active(&call->waitq) ? 'w' : ' ',
607 call->app_last_rcv ? 'Y' : '-',
608 (call->app_call_state!=RXRPC_CSTATE_ERROR ?
609 rxrpc_call_states7[call->app_call_state] :
610 rxrpc_call_error_states7[call->app_err_state]),
612 call->app_abort_code,
617 } /* end rxrpc_proc_calls_show() */