xref: /openbmc/linux/net/rxrpc/proc.c (revision 75b54cb5)
18c3e34a4SDavid Howells /* /proc/net/ support for AF_RXRPC
28c3e34a4SDavid Howells  *
38c3e34a4SDavid Howells  * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
48c3e34a4SDavid Howells  * Written by David Howells (dhowells@redhat.com)
58c3e34a4SDavid Howells  *
68c3e34a4SDavid Howells  * This program is free software; you can redistribute it and/or
78c3e34a4SDavid Howells  * modify it under the terms of the GNU General Public License
88c3e34a4SDavid Howells  * as published by the Free Software Foundation; either version
98c3e34a4SDavid Howells  * 2 of the License, or (at your option) any later version.
108c3e34a4SDavid Howells  */
118c3e34a4SDavid Howells 
128c3e34a4SDavid Howells #include <linux/module.h>
138c3e34a4SDavid Howells #include <net/sock.h>
148c3e34a4SDavid Howells #include <net/af_rxrpc.h>
158c3e34a4SDavid Howells #include "ar-internal.h"
168c3e34a4SDavid Howells 
17bba304dbSDavid Howells static const char *const rxrpc_conn_states[RXRPC_CONN__NR_STATES] = {
188c3e34a4SDavid Howells 	[RXRPC_CONN_UNUSED]			= "Unused  ",
198c3e34a4SDavid Howells 	[RXRPC_CONN_CLIENT]			= "Client  ",
2000e90712SDavid Howells 	[RXRPC_CONN_SERVICE_PREALLOC]		= "SvPrealc",
21bba304dbSDavid Howells 	[RXRPC_CONN_SERVICE_UNSECURED]		= "SvUnsec ",
22bba304dbSDavid Howells 	[RXRPC_CONN_SERVICE_CHALLENGING]	= "SvChall ",
23bba304dbSDavid Howells 	[RXRPC_CONN_SERVICE]			= "SvSecure",
248c3e34a4SDavid Howells 	[RXRPC_CONN_REMOTELY_ABORTED]		= "RmtAbort",
258c3e34a4SDavid Howells 	[RXRPC_CONN_LOCALLY_ABORTED]		= "LocAbort",
268c3e34a4SDavid Howells };
278c3e34a4SDavid Howells 
288c3e34a4SDavid Howells /*
298c3e34a4SDavid Howells  * generate a list of extant and dead calls in /proc/net/rxrpc_calls
308c3e34a4SDavid Howells  */
318c3e34a4SDavid Howells static void *rxrpc_call_seq_start(struct seq_file *seq, loff_t *_pos)
328c3e34a4SDavid Howells {
338d94aa38SDavid Howells 	rcu_read_lock();
348c3e34a4SDavid Howells 	read_lock(&rxrpc_call_lock);
358c3e34a4SDavid Howells 	return seq_list_start_head(&rxrpc_calls, *_pos);
368c3e34a4SDavid Howells }
378c3e34a4SDavid Howells 
388c3e34a4SDavid Howells static void *rxrpc_call_seq_next(struct seq_file *seq, void *v, loff_t *pos)
398c3e34a4SDavid Howells {
408c3e34a4SDavid Howells 	return seq_list_next(v, &rxrpc_calls, pos);
418c3e34a4SDavid Howells }
428c3e34a4SDavid Howells 
438c3e34a4SDavid Howells static void rxrpc_call_seq_stop(struct seq_file *seq, void *v)
448c3e34a4SDavid Howells {
458c3e34a4SDavid Howells 	read_unlock(&rxrpc_call_lock);
468d94aa38SDavid Howells 	rcu_read_unlock();
478c3e34a4SDavid Howells }
488c3e34a4SDavid Howells 
498c3e34a4SDavid Howells static int rxrpc_call_seq_show(struct seq_file *seq, void *v)
508c3e34a4SDavid Howells {
51df5d8bf7SDavid Howells 	struct rxrpc_local *local;
52df5d8bf7SDavid Howells 	struct rxrpc_sock *rx;
53df5d8bf7SDavid Howells 	struct rxrpc_peer *peer;
548c3e34a4SDavid Howells 	struct rxrpc_call *call;
5575b54cb5SDavid Howells 	char lbuff[50], rbuff[50];
568c3e34a4SDavid Howells 
578c3e34a4SDavid Howells 	if (v == &rxrpc_calls) {
588c3e34a4SDavid Howells 		seq_puts(seq,
5975b54cb5SDavid Howells 			 "Proto Local                                          "
6075b54cb5SDavid Howells 			 " Remote                                         "
618c3e34a4SDavid Howells 			 " SvID ConnID   CallID   End Use State    Abort   "
628c3e34a4SDavid Howells 			 " UserID\n");
638c3e34a4SDavid Howells 		return 0;
648c3e34a4SDavid Howells 	}
658c3e34a4SDavid Howells 
668c3e34a4SDavid Howells 	call = list_entry(v, struct rxrpc_call, link);
678c3e34a4SDavid Howells 
688d94aa38SDavid Howells 	rx = rcu_dereference(call->socket);
69df5d8bf7SDavid Howells 	if (rx) {
70df5d8bf7SDavid Howells 		local = READ_ONCE(rx->local);
71df5d8bf7SDavid Howells 		if (local)
7275b54cb5SDavid Howells 			sprintf(lbuff, "%pISpc", &local->srx.transport);
73df5d8bf7SDavid Howells 		else
74df5d8bf7SDavid Howells 			strcpy(lbuff, "no_local");
75df5d8bf7SDavid Howells 	} else {
76df5d8bf7SDavid Howells 		strcpy(lbuff, "no_socket");
77df5d8bf7SDavid Howells 	}
788c3e34a4SDavid Howells 
79df5d8bf7SDavid Howells 	peer = call->peer;
80df5d8bf7SDavid Howells 	if (peer)
8175b54cb5SDavid Howells 		sprintf(rbuff, "%pISpc", &peer->srx.transport);
82f4e7da8cSDavid Howells 	else
83f4e7da8cSDavid Howells 		strcpy(rbuff, "no_connection");
848c3e34a4SDavid Howells 
858c3e34a4SDavid Howells 	seq_printf(seq,
8675b54cb5SDavid Howells 		   "UDP   %-47.47s %-47.47s %4x %08x %08x %s %3u"
878c3e34a4SDavid Howells 		   " %-8.8s %08x %lx\n",
888c3e34a4SDavid Howells 		   lbuff,
898c3e34a4SDavid Howells 		   rbuff,
90f4e7da8cSDavid Howells 		   call->service_id,
918c3e34a4SDavid Howells 		   call->cid,
928c3e34a4SDavid Howells 		   call->call_id,
93dabe5a79SDavid Howells 		   rxrpc_is_service_call(call) ? "Svc" : "Clt",
948c3e34a4SDavid Howells 		   atomic_read(&call->usage),
958c3e34a4SDavid Howells 		   rxrpc_call_states[call->state],
96f5c17aaeSDavid Howells 		   call->abort_code,
978c3e34a4SDavid Howells 		   call->user_call_ID);
988c3e34a4SDavid Howells 
998c3e34a4SDavid Howells 	return 0;
1008c3e34a4SDavid Howells }
1018c3e34a4SDavid Howells 
1028c3e34a4SDavid Howells static const struct seq_operations rxrpc_call_seq_ops = {
1038c3e34a4SDavid Howells 	.start  = rxrpc_call_seq_start,
1048c3e34a4SDavid Howells 	.next   = rxrpc_call_seq_next,
1058c3e34a4SDavid Howells 	.stop   = rxrpc_call_seq_stop,
1068c3e34a4SDavid Howells 	.show   = rxrpc_call_seq_show,
1078c3e34a4SDavid Howells };
1088c3e34a4SDavid Howells 
1098c3e34a4SDavid Howells static int rxrpc_call_seq_open(struct inode *inode, struct file *file)
1108c3e34a4SDavid Howells {
1118c3e34a4SDavid Howells 	return seq_open(file, &rxrpc_call_seq_ops);
1128c3e34a4SDavid Howells }
1138c3e34a4SDavid Howells 
1148c3e34a4SDavid Howells const struct file_operations rxrpc_call_seq_fops = {
1158c3e34a4SDavid Howells 	.owner		= THIS_MODULE,
1168c3e34a4SDavid Howells 	.open		= rxrpc_call_seq_open,
1178c3e34a4SDavid Howells 	.read		= seq_read,
1188c3e34a4SDavid Howells 	.llseek		= seq_lseek,
1198c3e34a4SDavid Howells 	.release	= seq_release,
1208c3e34a4SDavid Howells };
1218c3e34a4SDavid Howells 
1228c3e34a4SDavid Howells /*
1238c3e34a4SDavid Howells  * generate a list of extant virtual connections in /proc/net/rxrpc_conns
1248c3e34a4SDavid Howells  */
1258c3e34a4SDavid Howells static void *rxrpc_connection_seq_start(struct seq_file *seq, loff_t *_pos)
1268c3e34a4SDavid Howells {
1278c3e34a4SDavid Howells 	read_lock(&rxrpc_connection_lock);
1284d028b2cSDavid Howells 	return seq_list_start_head(&rxrpc_connection_proc_list, *_pos);
1298c3e34a4SDavid Howells }
1308c3e34a4SDavid Howells 
1318c3e34a4SDavid Howells static void *rxrpc_connection_seq_next(struct seq_file *seq, void *v,
1328c3e34a4SDavid Howells 				       loff_t *pos)
1338c3e34a4SDavid Howells {
1344d028b2cSDavid Howells 	return seq_list_next(v, &rxrpc_connection_proc_list, pos);
1358c3e34a4SDavid Howells }
1368c3e34a4SDavid Howells 
1378c3e34a4SDavid Howells static void rxrpc_connection_seq_stop(struct seq_file *seq, void *v)
1388c3e34a4SDavid Howells {
1398c3e34a4SDavid Howells 	read_unlock(&rxrpc_connection_lock);
1408c3e34a4SDavid Howells }
1418c3e34a4SDavid Howells 
1428c3e34a4SDavid Howells static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
1438c3e34a4SDavid Howells {
1448c3e34a4SDavid Howells 	struct rxrpc_connection *conn;
14575b54cb5SDavid Howells 	char lbuff[50], rbuff[50];
1468c3e34a4SDavid Howells 
1474d028b2cSDavid Howells 	if (v == &rxrpc_connection_proc_list) {
1488c3e34a4SDavid Howells 		seq_puts(seq,
14975b54cb5SDavid Howells 			 "Proto Local                                          "
15075b54cb5SDavid Howells 			 " Remote                                         "
151a1399f8bSDavid Howells 			 " SvID ConnID   End Use State    Key     "
1528c3e34a4SDavid Howells 			 " Serial   ISerial\n"
1538c3e34a4SDavid Howells 			 );
1548c3e34a4SDavid Howells 		return 0;
1558c3e34a4SDavid Howells 	}
1568c3e34a4SDavid Howells 
1574d028b2cSDavid Howells 	conn = list_entry(v, struct rxrpc_connection, proc_link);
15800e90712SDavid Howells 	if (conn->state == RXRPC_CONN_SERVICE_PREALLOC) {
15900e90712SDavid Howells 		strcpy(lbuff, "no_local");
16000e90712SDavid Howells 		strcpy(rbuff, "no_connection");
16100e90712SDavid Howells 		goto print;
16200e90712SDavid Howells 	}
1638c3e34a4SDavid Howells 
16475b54cb5SDavid Howells 	sprintf(lbuff, "%pISpc", &conn->params.local->srx.transport);
1658c3e34a4SDavid Howells 
16675b54cb5SDavid Howells 	sprintf(rbuff, "%pISpc", &conn->params.peer->srx.transport);
16700e90712SDavid Howells print:
1688c3e34a4SDavid Howells 	seq_printf(seq,
16975b54cb5SDavid Howells 		   "UDP   %-47.47s %-47.47s %4x %08x %s %3u"
1708c3e34a4SDavid Howells 		   " %s %08x %08x %08x\n",
1718c3e34a4SDavid Howells 		   lbuff,
1728c3e34a4SDavid Howells 		   rbuff,
17319ffa01cSDavid Howells 		   conn->params.service_id,
17419ffa01cSDavid Howells 		   conn->proto.cid,
17519ffa01cSDavid Howells 		   rxrpc_conn_is_service(conn) ? "Svc" : "Clt",
1768c3e34a4SDavid Howells 		   atomic_read(&conn->usage),
1778c3e34a4SDavid Howells 		   rxrpc_conn_states[conn->state],
17819ffa01cSDavid Howells 		   key_serial(conn->params.key),
1798c3e34a4SDavid Howells 		   atomic_read(&conn->serial),
180563ea7d5SDavid Howells 		   conn->hi_serial);
1818c3e34a4SDavid Howells 
1828c3e34a4SDavid Howells 	return 0;
1838c3e34a4SDavid Howells }
1848c3e34a4SDavid Howells 
1858c3e34a4SDavid Howells static const struct seq_operations rxrpc_connection_seq_ops = {
1868c3e34a4SDavid Howells 	.start  = rxrpc_connection_seq_start,
1878c3e34a4SDavid Howells 	.next   = rxrpc_connection_seq_next,
1888c3e34a4SDavid Howells 	.stop   = rxrpc_connection_seq_stop,
1898c3e34a4SDavid Howells 	.show   = rxrpc_connection_seq_show,
1908c3e34a4SDavid Howells };
1918c3e34a4SDavid Howells 
1928c3e34a4SDavid Howells 
1938c3e34a4SDavid Howells static int rxrpc_connection_seq_open(struct inode *inode, struct file *file)
1948c3e34a4SDavid Howells {
1958c3e34a4SDavid Howells 	return seq_open(file, &rxrpc_connection_seq_ops);
1968c3e34a4SDavid Howells }
1978c3e34a4SDavid Howells 
1988c3e34a4SDavid Howells const struct file_operations rxrpc_connection_seq_fops = {
1998c3e34a4SDavid Howells 	.owner		= THIS_MODULE,
2008c3e34a4SDavid Howells 	.open		= rxrpc_connection_seq_open,
2018c3e34a4SDavid Howells 	.read		= seq_read,
2028c3e34a4SDavid Howells 	.llseek		= seq_lseek,
2038c3e34a4SDavid Howells 	.release	= seq_release,
2048c3e34a4SDavid Howells };
205