xref: /openbmc/linux/net/rxrpc/proc.c (revision c3506372)
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)
3288f2a825SDavid Howells 	__acquires(rcu)
3388f2a825SDavid Howells 	__acquires(rxnet->call_lock)
348c3e34a4SDavid Howells {
352baec2c3SDavid Howells 	struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
362baec2c3SDavid Howells 
378d94aa38SDavid Howells 	rcu_read_lock();
382baec2c3SDavid Howells 	read_lock(&rxnet->call_lock);
392baec2c3SDavid Howells 	return seq_list_start_head(&rxnet->calls, *_pos);
408c3e34a4SDavid Howells }
418c3e34a4SDavid Howells 
428c3e34a4SDavid Howells static void *rxrpc_call_seq_next(struct seq_file *seq, void *v, loff_t *pos)
438c3e34a4SDavid Howells {
442baec2c3SDavid Howells 	struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
452baec2c3SDavid Howells 
462baec2c3SDavid Howells 	return seq_list_next(v, &rxnet->calls, pos);
478c3e34a4SDavid Howells }
488c3e34a4SDavid Howells 
498c3e34a4SDavid Howells static void rxrpc_call_seq_stop(struct seq_file *seq, void *v)
5088f2a825SDavid Howells 	__releases(rxnet->call_lock)
5188f2a825SDavid Howells 	__releases(rcu)
528c3e34a4SDavid Howells {
532baec2c3SDavid Howells 	struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
542baec2c3SDavid Howells 
552baec2c3SDavid Howells 	read_unlock(&rxnet->call_lock);
568d94aa38SDavid Howells 	rcu_read_unlock();
578c3e34a4SDavid Howells }
588c3e34a4SDavid Howells 
598c3e34a4SDavid Howells static int rxrpc_call_seq_show(struct seq_file *seq, void *v)
608c3e34a4SDavid Howells {
61df5d8bf7SDavid Howells 	struct rxrpc_local *local;
62df5d8bf7SDavid Howells 	struct rxrpc_sock *rx;
63df5d8bf7SDavid Howells 	struct rxrpc_peer *peer;
648c3e34a4SDavid Howells 	struct rxrpc_call *call;
652baec2c3SDavid Howells 	struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
663e018dafSDavid Howells 	rxrpc_seq_t tx_hard_ack, rx_hard_ack;
6775b54cb5SDavid Howells 	char lbuff[50], rbuff[50];
688c3e34a4SDavid Howells 
692baec2c3SDavid Howells 	if (v == &rxnet->calls) {
708c3e34a4SDavid Howells 		seq_puts(seq,
7175b54cb5SDavid Howells 			 "Proto Local                                          "
7275b54cb5SDavid Howells 			 " Remote                                         "
738c3e34a4SDavid Howells 			 " SvID ConnID   CallID   End Use State    Abort   "
748c3e34a4SDavid Howells 			 " UserID\n");
758c3e34a4SDavid Howells 		return 0;
768c3e34a4SDavid Howells 	}
778c3e34a4SDavid Howells 
788c3e34a4SDavid Howells 	call = list_entry(v, struct rxrpc_call, link);
798c3e34a4SDavid Howells 
808d94aa38SDavid Howells 	rx = rcu_dereference(call->socket);
81df5d8bf7SDavid Howells 	if (rx) {
82df5d8bf7SDavid Howells 		local = READ_ONCE(rx->local);
83df5d8bf7SDavid Howells 		if (local)
8475b54cb5SDavid Howells 			sprintf(lbuff, "%pISpc", &local->srx.transport);
85df5d8bf7SDavid Howells 		else
86df5d8bf7SDavid Howells 			strcpy(lbuff, "no_local");
87df5d8bf7SDavid Howells 	} else {
88df5d8bf7SDavid Howells 		strcpy(lbuff, "no_socket");
89df5d8bf7SDavid Howells 	}
908c3e34a4SDavid Howells 
91df5d8bf7SDavid Howells 	peer = call->peer;
92df5d8bf7SDavid Howells 	if (peer)
9375b54cb5SDavid Howells 		sprintf(rbuff, "%pISpc", &peer->srx.transport);
94f4e7da8cSDavid Howells 	else
95f4e7da8cSDavid Howells 		strcpy(rbuff, "no_connection");
968c3e34a4SDavid Howells 
973e018dafSDavid Howells 	tx_hard_ack = READ_ONCE(call->tx_hard_ack);
983e018dafSDavid Howells 	rx_hard_ack = READ_ONCE(call->rx_hard_ack);
998c3e34a4SDavid Howells 	seq_printf(seq,
10075b54cb5SDavid Howells 		   "UDP   %-47.47s %-47.47s %4x %08x %08x %s %3u"
1013e018dafSDavid Howells 		   " %-8.8s %08x %lx %08x %02x %08x %02x\n",
1028c3e34a4SDavid Howells 		   lbuff,
1038c3e34a4SDavid Howells 		   rbuff,
104f4e7da8cSDavid Howells 		   call->service_id,
1058c3e34a4SDavid Howells 		   call->cid,
1068c3e34a4SDavid Howells 		   call->call_id,
107dabe5a79SDavid Howells 		   rxrpc_is_service_call(call) ? "Svc" : "Clt",
1088c3e34a4SDavid Howells 		   atomic_read(&call->usage),
1098c3e34a4SDavid Howells 		   rxrpc_call_states[call->state],
110f5c17aaeSDavid Howells 		   call->abort_code,
1113e018dafSDavid Howells 		   call->user_call_ID,
1123e018dafSDavid Howells 		   tx_hard_ack, READ_ONCE(call->tx_top) - tx_hard_ack,
1133e018dafSDavid Howells 		   rx_hard_ack, READ_ONCE(call->rx_top) - rx_hard_ack);
1148c3e34a4SDavid Howells 
1158c3e34a4SDavid Howells 	return 0;
1168c3e34a4SDavid Howells }
1178c3e34a4SDavid Howells 
118c3506372SChristoph Hellwig const struct seq_operations rxrpc_call_seq_ops = {
1198c3e34a4SDavid Howells 	.start  = rxrpc_call_seq_start,
1208c3e34a4SDavid Howells 	.next   = rxrpc_call_seq_next,
1218c3e34a4SDavid Howells 	.stop   = rxrpc_call_seq_stop,
1228c3e34a4SDavid Howells 	.show   = rxrpc_call_seq_show,
1238c3e34a4SDavid Howells };
1248c3e34a4SDavid Howells 
1258c3e34a4SDavid Howells /*
1268c3e34a4SDavid Howells  * generate a list of extant virtual connections in /proc/net/rxrpc_conns
1278c3e34a4SDavid Howells  */
1288c3e34a4SDavid Howells static void *rxrpc_connection_seq_start(struct seq_file *seq, loff_t *_pos)
12988f2a825SDavid Howells 	__acquires(rxnet->conn_lock)
1308c3e34a4SDavid Howells {
1312baec2c3SDavid Howells 	struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
1322baec2c3SDavid Howells 
1332baec2c3SDavid Howells 	read_lock(&rxnet->conn_lock);
1342baec2c3SDavid Howells 	return seq_list_start_head(&rxnet->conn_proc_list, *_pos);
1358c3e34a4SDavid Howells }
1368c3e34a4SDavid Howells 
1378c3e34a4SDavid Howells static void *rxrpc_connection_seq_next(struct seq_file *seq, void *v,
1388c3e34a4SDavid Howells 				       loff_t *pos)
1398c3e34a4SDavid Howells {
1402baec2c3SDavid Howells 	struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
1412baec2c3SDavid Howells 
1422baec2c3SDavid Howells 	return seq_list_next(v, &rxnet->conn_proc_list, pos);
1438c3e34a4SDavid Howells }
1448c3e34a4SDavid Howells 
1458c3e34a4SDavid Howells static void rxrpc_connection_seq_stop(struct seq_file *seq, void *v)
14688f2a825SDavid Howells 	__releases(rxnet->conn_lock)
1478c3e34a4SDavid Howells {
1482baec2c3SDavid Howells 	struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
1492baec2c3SDavid Howells 
1502baec2c3SDavid Howells 	read_unlock(&rxnet->conn_lock);
1518c3e34a4SDavid Howells }
1528c3e34a4SDavid Howells 
1538c3e34a4SDavid Howells static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
1548c3e34a4SDavid Howells {
1558c3e34a4SDavid Howells 	struct rxrpc_connection *conn;
1562baec2c3SDavid Howells 	struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
15775b54cb5SDavid Howells 	char lbuff[50], rbuff[50];
1588c3e34a4SDavid Howells 
1592baec2c3SDavid Howells 	if (v == &rxnet->conn_proc_list) {
1608c3e34a4SDavid Howells 		seq_puts(seq,
16175b54cb5SDavid Howells 			 "Proto Local                                          "
16275b54cb5SDavid Howells 			 " Remote                                         "
163a1399f8bSDavid Howells 			 " SvID ConnID   End Use State    Key     "
1648c3e34a4SDavid Howells 			 " Serial   ISerial\n"
1658c3e34a4SDavid Howells 			 );
1668c3e34a4SDavid Howells 		return 0;
1678c3e34a4SDavid Howells 	}
1688c3e34a4SDavid Howells 
1694d028b2cSDavid Howells 	conn = list_entry(v, struct rxrpc_connection, proc_link);
17000e90712SDavid Howells 	if (conn->state == RXRPC_CONN_SERVICE_PREALLOC) {
17100e90712SDavid Howells 		strcpy(lbuff, "no_local");
17200e90712SDavid Howells 		strcpy(rbuff, "no_connection");
17300e90712SDavid Howells 		goto print;
17400e90712SDavid Howells 	}
1758c3e34a4SDavid Howells 
17675b54cb5SDavid Howells 	sprintf(lbuff, "%pISpc", &conn->params.local->srx.transport);
1778c3e34a4SDavid Howells 
17875b54cb5SDavid Howells 	sprintf(rbuff, "%pISpc", &conn->params.peer->srx.transport);
17900e90712SDavid Howells print:
1808c3e34a4SDavid Howells 	seq_printf(seq,
18175b54cb5SDavid Howells 		   "UDP   %-47.47s %-47.47s %4x %08x %s %3u"
1828c3e34a4SDavid Howells 		   " %s %08x %08x %08x\n",
1838c3e34a4SDavid Howells 		   lbuff,
1848c3e34a4SDavid Howells 		   rbuff,
18568d6d1aeSDavid Howells 		   conn->service_id,
18619ffa01cSDavid Howells 		   conn->proto.cid,
18719ffa01cSDavid Howells 		   rxrpc_conn_is_service(conn) ? "Svc" : "Clt",
1888c3e34a4SDavid Howells 		   atomic_read(&conn->usage),
1898c3e34a4SDavid Howells 		   rxrpc_conn_states[conn->state],
19019ffa01cSDavid Howells 		   key_serial(conn->params.key),
1918c3e34a4SDavid Howells 		   atomic_read(&conn->serial),
192563ea7d5SDavid Howells 		   conn->hi_serial);
1938c3e34a4SDavid Howells 
1948c3e34a4SDavid Howells 	return 0;
1958c3e34a4SDavid Howells }
1968c3e34a4SDavid Howells 
197c3506372SChristoph Hellwig const struct seq_operations rxrpc_connection_seq_ops = {
1988c3e34a4SDavid Howells 	.start  = rxrpc_connection_seq_start,
1998c3e34a4SDavid Howells 	.next   = rxrpc_connection_seq_next,
2008c3e34a4SDavid Howells 	.stop   = rxrpc_connection_seq_stop,
2018c3e34a4SDavid Howells 	.show   = rxrpc_connection_seq_show,
2028c3e34a4SDavid Howells };
203