123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617 |
- /* proc.c: /proc interface for RxRPC
- *
- * Copyright (C) 2002 Red Hat, Inc. All Rights Reserved.
- * Written by David Howells (dhowells@redhat.com)
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version
- * 2 of the License, or (at your option) any later version.
- */
- #include <linux/sched.h>
- #include <linux/slab.h>
- #include <linux/module.h>
- #include <linux/proc_fs.h>
- #include <linux/seq_file.h>
- #include <rxrpc/rxrpc.h>
- #include <rxrpc/transport.h>
- #include <rxrpc/peer.h>
- #include <rxrpc/connection.h>
- #include <rxrpc/call.h>
- #include <rxrpc/message.h>
- #include "internal.h"
- static struct proc_dir_entry *proc_rxrpc;
- static int rxrpc_proc_transports_open(struct inode *inode, struct file *file);
- static void *rxrpc_proc_transports_start(struct seq_file *p, loff_t *pos);
- static void *rxrpc_proc_transports_next(struct seq_file *p, void *v, loff_t *pos);
- static void rxrpc_proc_transports_stop(struct seq_file *p, void *v);
- static int rxrpc_proc_transports_show(struct seq_file *m, void *v);
- static struct seq_operations rxrpc_proc_transports_ops = {
- .start = rxrpc_proc_transports_start,
- .next = rxrpc_proc_transports_next,
- .stop = rxrpc_proc_transports_stop,
- .show = rxrpc_proc_transports_show,
- };
- static struct file_operations rxrpc_proc_transports_fops = {
- .open = rxrpc_proc_transports_open,
- .read = seq_read,
- .llseek = seq_lseek,
- .release = seq_release,
- };
- static int rxrpc_proc_peers_open(struct inode *inode, struct file *file);
- static void *rxrpc_proc_peers_start(struct seq_file *p, loff_t *pos);
- static void *rxrpc_proc_peers_next(struct seq_file *p, void *v, loff_t *pos);
- static void rxrpc_proc_peers_stop(struct seq_file *p, void *v);
- static int rxrpc_proc_peers_show(struct seq_file *m, void *v);
- static struct seq_operations rxrpc_proc_peers_ops = {
- .start = rxrpc_proc_peers_start,
- .next = rxrpc_proc_peers_next,
- .stop = rxrpc_proc_peers_stop,
- .show = rxrpc_proc_peers_show,
- };
- static struct file_operations rxrpc_proc_peers_fops = {
- .open = rxrpc_proc_peers_open,
- .read = seq_read,
- .llseek = seq_lseek,
- .release = seq_release,
- };
- static int rxrpc_proc_conns_open(struct inode *inode, struct file *file);
- static void *rxrpc_proc_conns_start(struct seq_file *p, loff_t *pos);
- static void *rxrpc_proc_conns_next(struct seq_file *p, void *v, loff_t *pos);
- static void rxrpc_proc_conns_stop(struct seq_file *p, void *v);
- static int rxrpc_proc_conns_show(struct seq_file *m, void *v);
- static struct seq_operations rxrpc_proc_conns_ops = {
- .start = rxrpc_proc_conns_start,
- .next = rxrpc_proc_conns_next,
- .stop = rxrpc_proc_conns_stop,
- .show = rxrpc_proc_conns_show,
- };
- static struct file_operations rxrpc_proc_conns_fops = {
- .open = rxrpc_proc_conns_open,
- .read = seq_read,
- .llseek = seq_lseek,
- .release = seq_release,
- };
- static int rxrpc_proc_calls_open(struct inode *inode, struct file *file);
- static void *rxrpc_proc_calls_start(struct seq_file *p, loff_t *pos);
- static void *rxrpc_proc_calls_next(struct seq_file *p, void *v, loff_t *pos);
- static void rxrpc_proc_calls_stop(struct seq_file *p, void *v);
- static int rxrpc_proc_calls_show(struct seq_file *m, void *v);
- static struct seq_operations rxrpc_proc_calls_ops = {
- .start = rxrpc_proc_calls_start,
- .next = rxrpc_proc_calls_next,
- .stop = rxrpc_proc_calls_stop,
- .show = rxrpc_proc_calls_show,
- };
- static struct file_operations rxrpc_proc_calls_fops = {
- .open = rxrpc_proc_calls_open,
- .read = seq_read,
- .llseek = seq_lseek,
- .release = seq_release,
- };
- static const char *rxrpc_call_states7[] = {
- "complet",
- "error ",
- "rcv_op ",
- "rcv_arg",
- "got_arg",
- "snd_rpl",
- "fin_ack",
- "snd_arg",
- "rcv_rpl",
- "got_rpl"
- };
- static const char *rxrpc_call_error_states7[] = {
- "no_err ",
- "loc_abt",
- "rmt_abt",
- "loc_err",
- "rmt_err"
- };
- /*****************************************************************************/
- /*
- * initialise the /proc/net/rxrpc/ directory
- */
- int rxrpc_proc_init(void)
- {
- struct proc_dir_entry *p;
- proc_rxrpc = proc_mkdir("rxrpc", proc_net);
- if (!proc_rxrpc)
- goto error;
- proc_rxrpc->owner = THIS_MODULE;
- p = create_proc_entry("calls", 0, proc_rxrpc);
- if (!p)
- goto error_proc;
- p->proc_fops = &rxrpc_proc_calls_fops;
- p->owner = THIS_MODULE;
- p = create_proc_entry("connections", 0, proc_rxrpc);
- if (!p)
- goto error_calls;
- p->proc_fops = &rxrpc_proc_conns_fops;
- p->owner = THIS_MODULE;
- p = create_proc_entry("peers", 0, proc_rxrpc);
- if (!p)
- goto error_calls;
- p->proc_fops = &rxrpc_proc_peers_fops;
- p->owner = THIS_MODULE;
- p = create_proc_entry("transports", 0, proc_rxrpc);
- if (!p)
- goto error_conns;
- p->proc_fops = &rxrpc_proc_transports_fops;
- p->owner = THIS_MODULE;
- return 0;
- error_conns:
- remove_proc_entry("connections", proc_rxrpc);
- error_calls:
- remove_proc_entry("calls", proc_rxrpc);
- error_proc:
- remove_proc_entry("rxrpc", proc_net);
- error:
- return -ENOMEM;
- } /* end rxrpc_proc_init() */
- /*****************************************************************************/
- /*
- * clean up the /proc/net/rxrpc/ directory
- */
- void rxrpc_proc_cleanup(void)
- {
- remove_proc_entry("transports", proc_rxrpc);
- remove_proc_entry("peers", proc_rxrpc);
- remove_proc_entry("connections", proc_rxrpc);
- remove_proc_entry("calls", proc_rxrpc);
- remove_proc_entry("rxrpc", proc_net);
- } /* end rxrpc_proc_cleanup() */
- /*****************************************************************************/
- /*
- * open "/proc/net/rxrpc/transports" which provides a summary of extant transports
- */
- static int rxrpc_proc_transports_open(struct inode *inode, struct file *file)
- {
- struct seq_file *m;
- int ret;
- ret = seq_open(file, &rxrpc_proc_transports_ops);
- if (ret < 0)
- return ret;
- m = file->private_data;
- m->private = PDE(inode)->data;
- return 0;
- } /* end rxrpc_proc_transports_open() */
- /*****************************************************************************/
- /*
- * set up the iterator to start reading from the transports list and return the first item
- */
- static void *rxrpc_proc_transports_start(struct seq_file *m, loff_t *_pos)
- {
- struct list_head *_p;
- loff_t pos = *_pos;
- /* lock the list against modification */
- down_read(&rxrpc_proc_transports_sem);
- /* allow for the header line */
- if (!pos)
- return SEQ_START_TOKEN;
- pos--;
- /* find the n'th element in the list */
- list_for_each(_p, &rxrpc_proc_transports)
- if (!pos--)
- break;
- return _p != &rxrpc_proc_transports ? _p : NULL;
- } /* end rxrpc_proc_transports_start() */
- /*****************************************************************************/
- /*
- * move to next call in transports list
- */
- static void *rxrpc_proc_transports_next(struct seq_file *p, void *v, loff_t *pos)
- {
- struct list_head *_p;
- (*pos)++;
- _p = v;
- _p = (v == SEQ_START_TOKEN) ? rxrpc_proc_transports.next : _p->next;
- return _p != &rxrpc_proc_transports ? _p : NULL;
- } /* end rxrpc_proc_transports_next() */
- /*****************************************************************************/
- /*
- * clean up after reading from the transports list
- */
- static void rxrpc_proc_transports_stop(struct seq_file *p, void *v)
- {
- up_read(&rxrpc_proc_transports_sem);
- } /* end rxrpc_proc_transports_stop() */
- /*****************************************************************************/
- /*
- * display a header line followed by a load of call lines
- */
- static int rxrpc_proc_transports_show(struct seq_file *m, void *v)
- {
- struct rxrpc_transport *trans =
- list_entry(v, struct rxrpc_transport, proc_link);
- /* display header on line 1 */
- if (v == SEQ_START_TOKEN) {
- seq_puts(m, "LOCAL USE\n");
- return 0;
- }
- /* display one transport per line on subsequent lines */
- seq_printf(m, "%5hu %3d\n",
- trans->port,
- atomic_read(&trans->usage)
- );
- return 0;
- } /* end rxrpc_proc_transports_show() */
- /*****************************************************************************/
- /*
- * open "/proc/net/rxrpc/peers" which provides a summary of extant peers
- */
- static int rxrpc_proc_peers_open(struct inode *inode, struct file *file)
- {
- struct seq_file *m;
- int ret;
- ret = seq_open(file, &rxrpc_proc_peers_ops);
- if (ret < 0)
- return ret;
- m = file->private_data;
- m->private = PDE(inode)->data;
- return 0;
- } /* end rxrpc_proc_peers_open() */
- /*****************************************************************************/
- /*
- * set up the iterator to start reading from the peers list and return the
- * first item
- */
- static void *rxrpc_proc_peers_start(struct seq_file *m, loff_t *_pos)
- {
- struct list_head *_p;
- loff_t pos = *_pos;
- /* lock the list against modification */
- down_read(&rxrpc_peers_sem);
- /* allow for the header line */
- if (!pos)
- return SEQ_START_TOKEN;
- pos--;
- /* find the n'th element in the list */
- list_for_each(_p, &rxrpc_peers)
- if (!pos--)
- break;
- return _p != &rxrpc_peers ? _p : NULL;
- } /* end rxrpc_proc_peers_start() */
- /*****************************************************************************/
- /*
- * move to next conn in peers list
- */
- static void *rxrpc_proc_peers_next(struct seq_file *p, void *v, loff_t *pos)
- {
- struct list_head *_p;
- (*pos)++;
- _p = v;
- _p = (v == SEQ_START_TOKEN) ? rxrpc_peers.next : _p->next;
- return _p != &rxrpc_peers ? _p : NULL;
- } /* end rxrpc_proc_peers_next() */
- /*****************************************************************************/
- /*
- * clean up after reading from the peers list
- */
- static void rxrpc_proc_peers_stop(struct seq_file *p, void *v)
- {
- up_read(&rxrpc_peers_sem);
- } /* end rxrpc_proc_peers_stop() */
- /*****************************************************************************/
- /*
- * display a header line followed by a load of conn lines
- */
- static int rxrpc_proc_peers_show(struct seq_file *m, void *v)
- {
- struct rxrpc_peer *peer = list_entry(v, struct rxrpc_peer, proc_link);
- signed long timeout;
- /* display header on line 1 */
- if (v == SEQ_START_TOKEN) {
- seq_puts(m, "LOCAL REMOTE USAGE CONNS TIMEOUT"
- " MTU RTT(uS)\n");
- return 0;
- }
- /* display one peer per line on subsequent lines */
- timeout = 0;
- if (!list_empty(&peer->timeout.link))
- timeout = (signed long) peer->timeout.timo_jif -
- (signed long) jiffies;
- seq_printf(m, "%5hu %08x %5d %5d %8ld %5Zu %7lu\n",
- peer->trans->port,
- ntohl(peer->addr.s_addr),
- atomic_read(&peer->usage),
- atomic_read(&peer->conn_count),
- timeout,
- peer->if_mtu,
- (long) peer->rtt
- );
- return 0;
- } /* end rxrpc_proc_peers_show() */
- /*****************************************************************************/
- /*
- * open "/proc/net/rxrpc/connections" which provides a summary of extant
- * connections
- */
- static int rxrpc_proc_conns_open(struct inode *inode, struct file *file)
- {
- struct seq_file *m;
- int ret;
- ret = seq_open(file, &rxrpc_proc_conns_ops);
- if (ret < 0)
- return ret;
- m = file->private_data;
- m->private = PDE(inode)->data;
- return 0;
- } /* end rxrpc_proc_conns_open() */
- /*****************************************************************************/
- /*
- * set up the iterator to start reading from the conns list and return the
- * first item
- */
- static void *rxrpc_proc_conns_start(struct seq_file *m, loff_t *_pos)
- {
- struct list_head *_p;
- loff_t pos = *_pos;
- /* lock the list against modification */
- down_read(&rxrpc_conns_sem);
- /* allow for the header line */
- if (!pos)
- return SEQ_START_TOKEN;
- pos--;
- /* find the n'th element in the list */
- list_for_each(_p, &rxrpc_conns)
- if (!pos--)
- break;
- return _p != &rxrpc_conns ? _p : NULL;
- } /* end rxrpc_proc_conns_start() */
- /*****************************************************************************/
- /*
- * move to next conn in conns list
- */
- static void *rxrpc_proc_conns_next(struct seq_file *p, void *v, loff_t *pos)
- {
- struct list_head *_p;
- (*pos)++;
- _p = v;
- _p = (v == SEQ_START_TOKEN) ? rxrpc_conns.next : _p->next;
- return _p != &rxrpc_conns ? _p : NULL;
- } /* end rxrpc_proc_conns_next() */
- /*****************************************************************************/
- /*
- * clean up after reading from the conns list
- */
- static void rxrpc_proc_conns_stop(struct seq_file *p, void *v)
- {
- up_read(&rxrpc_conns_sem);
- } /* end rxrpc_proc_conns_stop() */
- /*****************************************************************************/
- /*
- * display a header line followed by a load of conn lines
- */
- static int rxrpc_proc_conns_show(struct seq_file *m, void *v)
- {
- struct rxrpc_connection *conn;
- signed long timeout;
- conn = list_entry(v, struct rxrpc_connection, proc_link);
- /* display header on line 1 */
- if (v == SEQ_START_TOKEN) {
- seq_puts(m,
- "LOCAL REMOTE RPORT SRVC CONN END SERIALNO "
- "CALLNO MTU TIMEOUT"
- "\n");
- return 0;
- }
- /* display one conn per line on subsequent lines */
- timeout = 0;
- if (!list_empty(&conn->timeout.link))
- timeout = (signed long) conn->timeout.timo_jif -
- (signed long) jiffies;
- seq_printf(m,
- "%5hu %08x %5hu %04hx %08x %-3.3s %08x %08x %5Zu %8ld\n",
- conn->trans->port,
- ntohl(conn->addr.sin_addr.s_addr),
- ntohs(conn->addr.sin_port),
- ntohs(conn->service_id),
- ntohl(conn->conn_id),
- conn->out_clientflag ? "CLT" : "SRV",
- conn->serial_counter,
- conn->call_counter,
- conn->mtu_size,
- timeout
- );
- return 0;
- } /* end rxrpc_proc_conns_show() */
- /*****************************************************************************/
- /*
- * open "/proc/net/rxrpc/calls" which provides a summary of extant calls
- */
- static int rxrpc_proc_calls_open(struct inode *inode, struct file *file)
- {
- struct seq_file *m;
- int ret;
- ret = seq_open(file, &rxrpc_proc_calls_ops);
- if (ret < 0)
- return ret;
- m = file->private_data;
- m->private = PDE(inode)->data;
- return 0;
- } /* end rxrpc_proc_calls_open() */
- /*****************************************************************************/
- /*
- * set up the iterator to start reading from the calls list and return the
- * first item
- */
- static void *rxrpc_proc_calls_start(struct seq_file *m, loff_t *_pos)
- {
- struct list_head *_p;
- loff_t pos = *_pos;
- /* lock the list against modification */
- down_read(&rxrpc_calls_sem);
- /* allow for the header line */
- if (!pos)
- return SEQ_START_TOKEN;
- pos--;
- /* find the n'th element in the list */
- list_for_each(_p, &rxrpc_calls)
- if (!pos--)
- break;
- return _p != &rxrpc_calls ? _p : NULL;
- } /* end rxrpc_proc_calls_start() */
- /*****************************************************************************/
- /*
- * move to next call in calls list
- */
- static void *rxrpc_proc_calls_next(struct seq_file *p, void *v, loff_t *pos)
- {
- struct list_head *_p;
- (*pos)++;
- _p = v;
- _p = (v == SEQ_START_TOKEN) ? rxrpc_calls.next : _p->next;
- return _p != &rxrpc_calls ? _p : NULL;
- } /* end rxrpc_proc_calls_next() */
- /*****************************************************************************/
- /*
- * clean up after reading from the calls list
- */
- static void rxrpc_proc_calls_stop(struct seq_file *p, void *v)
- {
- up_read(&rxrpc_calls_sem);
- } /* end rxrpc_proc_calls_stop() */
- /*****************************************************************************/
- /*
- * display a header line followed by a load of call lines
- */
- static int rxrpc_proc_calls_show(struct seq_file *m, void *v)
- {
- struct rxrpc_call *call = list_entry(v, struct rxrpc_call, call_link);
- /* display header on line 1 */
- if (v == SEQ_START_TOKEN) {
- seq_puts(m,
- "LOCAL REMOT SRVC CONN CALL DIR USE "
- " L STATE OPCODE ABORT ERRNO\n"
- );
- return 0;
- }
- /* display one call per line on subsequent lines */
- seq_printf(m,
- "%5hu %5hu %04hx %08x %08x %s %3u%c"
- " %c %-7.7s %6d %08x %5d\n",
- call->conn->trans->port,
- ntohs(call->conn->addr.sin_port),
- ntohs(call->conn->service_id),
- ntohl(call->conn->conn_id),
- ntohl(call->call_id),
- call->conn->service ? "SVC" : "CLT",
- atomic_read(&call->usage),
- waitqueue_active(&call->waitq) ? 'w' : ' ',
- call->app_last_rcv ? 'Y' : '-',
- (call->app_call_state!=RXRPC_CSTATE_ERROR ?
- rxrpc_call_states7[call->app_call_state] :
- rxrpc_call_error_states7[call->app_err_state]),
- call->app_opcode,
- call->app_abort_code,
- call->app_errno
- );
- return 0;
- } /* end rxrpc_proc_calls_show() */
|