xref: /openbmc/linux/net/rxrpc/proc.c (revision 770b26de)
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));
66770b26deSWei Yongjun 	unsigned long timeout = 0;
673e018dafSDavid Howells 	rxrpc_seq_t tx_hard_ack, rx_hard_ack;
6875b54cb5SDavid Howells 	char lbuff[50], rbuff[50];
698c3e34a4SDavid Howells 
702baec2c3SDavid Howells 	if (v == &rxnet->calls) {
718c3e34a4SDavid Howells 		seq_puts(seq,
7275b54cb5SDavid Howells 			 "Proto Local                                          "
7375b54cb5SDavid Howells 			 " Remote                                         "
748c3e34a4SDavid Howells 			 " SvID ConnID   CallID   End Use State    Abort   "
756b97bd7aSDavid Howells 			 " UserID           TxSeq    TW RxSeq    RW RxSerial RxTimo\n");
768c3e34a4SDavid Howells 		return 0;
778c3e34a4SDavid Howells 	}
788c3e34a4SDavid Howells 
798c3e34a4SDavid Howells 	call = list_entry(v, struct rxrpc_call, link);
808c3e34a4SDavid Howells 
818d94aa38SDavid Howells 	rx = rcu_dereference(call->socket);
82df5d8bf7SDavid Howells 	if (rx) {
83df5d8bf7SDavid Howells 		local = READ_ONCE(rx->local);
84df5d8bf7SDavid Howells 		if (local)
8575b54cb5SDavid Howells 			sprintf(lbuff, "%pISpc", &local->srx.transport);
86df5d8bf7SDavid Howells 		else
87df5d8bf7SDavid Howells 			strcpy(lbuff, "no_local");
88df5d8bf7SDavid Howells 	} else {
89df5d8bf7SDavid Howells 		strcpy(lbuff, "no_socket");
90df5d8bf7SDavid Howells 	}
918c3e34a4SDavid Howells 
92df5d8bf7SDavid Howells 	peer = call->peer;
93df5d8bf7SDavid Howells 	if (peer)
9475b54cb5SDavid Howells 		sprintf(rbuff, "%pISpc", &peer->srx.transport);
95f4e7da8cSDavid Howells 	else
96f4e7da8cSDavid Howells 		strcpy(rbuff, "no_connection");
978c3e34a4SDavid Howells 
98887763bbSDavid Howells 	if (call->state != RXRPC_CALL_SERVER_PREALLOC) {
99887763bbSDavid Howells 		timeout = READ_ONCE(call->expect_rx_by);
100887763bbSDavid Howells 		timeout -= jiffies;
101887763bbSDavid Howells 	}
102887763bbSDavid Howells 
1033e018dafSDavid Howells 	tx_hard_ack = READ_ONCE(call->tx_hard_ack);
1043e018dafSDavid Howells 	rx_hard_ack = READ_ONCE(call->rx_hard_ack);
1058c3e34a4SDavid Howells 	seq_printf(seq,
10675b54cb5SDavid Howells 		   "UDP   %-47.47s %-47.47s %4x %08x %08x %s %3u"
1076b97bd7aSDavid Howells 		   " %-8.8s %08x %lx %08x %02x %08x %02x %08x %06lx\n",
1088c3e34a4SDavid Howells 		   lbuff,
1098c3e34a4SDavid Howells 		   rbuff,
110f4e7da8cSDavid Howells 		   call->service_id,
1118c3e34a4SDavid Howells 		   call->cid,
1128c3e34a4SDavid Howells 		   call->call_id,
113dabe5a79SDavid Howells 		   rxrpc_is_service_call(call) ? "Svc" : "Clt",
1148c3e34a4SDavid Howells 		   atomic_read(&call->usage),
1158c3e34a4SDavid Howells 		   rxrpc_call_states[call->state],
116f5c17aaeSDavid Howells 		   call->abort_code,
1173e018dafSDavid Howells 		   call->user_call_ID,
1183e018dafSDavid Howells 		   tx_hard_ack, READ_ONCE(call->tx_top) - tx_hard_ack,
119887763bbSDavid Howells 		   rx_hard_ack, READ_ONCE(call->rx_top) - rx_hard_ack,
1206b97bd7aSDavid Howells 		   call->rx_serial,
121887763bbSDavid Howells 		   timeout);
1228c3e34a4SDavid Howells 
1238c3e34a4SDavid Howells 	return 0;
1248c3e34a4SDavid Howells }
1258c3e34a4SDavid Howells 
126c3506372SChristoph Hellwig const struct seq_operations rxrpc_call_seq_ops = {
1278c3e34a4SDavid Howells 	.start  = rxrpc_call_seq_start,
1288c3e34a4SDavid Howells 	.next   = rxrpc_call_seq_next,
1298c3e34a4SDavid Howells 	.stop   = rxrpc_call_seq_stop,
1308c3e34a4SDavid Howells 	.show   = rxrpc_call_seq_show,
1318c3e34a4SDavid Howells };
1328c3e34a4SDavid Howells 
1338c3e34a4SDavid Howells /*
1348c3e34a4SDavid Howells  * generate a list of extant virtual connections in /proc/net/rxrpc_conns
1358c3e34a4SDavid Howells  */
1368c3e34a4SDavid Howells static void *rxrpc_connection_seq_start(struct seq_file *seq, loff_t *_pos)
13788f2a825SDavid Howells 	__acquires(rxnet->conn_lock)
1388c3e34a4SDavid Howells {
1392baec2c3SDavid Howells 	struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
1402baec2c3SDavid Howells 
1412baec2c3SDavid Howells 	read_lock(&rxnet->conn_lock);
1422baec2c3SDavid Howells 	return seq_list_start_head(&rxnet->conn_proc_list, *_pos);
1438c3e34a4SDavid Howells }
1448c3e34a4SDavid Howells 
1458c3e34a4SDavid Howells static void *rxrpc_connection_seq_next(struct seq_file *seq, void *v,
1468c3e34a4SDavid Howells 				       loff_t *pos)
1478c3e34a4SDavid Howells {
1482baec2c3SDavid Howells 	struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
1492baec2c3SDavid Howells 
1502baec2c3SDavid Howells 	return seq_list_next(v, &rxnet->conn_proc_list, pos);
1518c3e34a4SDavid Howells }
1528c3e34a4SDavid Howells 
1538c3e34a4SDavid Howells static void rxrpc_connection_seq_stop(struct seq_file *seq, void *v)
15488f2a825SDavid Howells 	__releases(rxnet->conn_lock)
1558c3e34a4SDavid Howells {
1562baec2c3SDavid Howells 	struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
1572baec2c3SDavid Howells 
1582baec2c3SDavid Howells 	read_unlock(&rxnet->conn_lock);
1598c3e34a4SDavid Howells }
1608c3e34a4SDavid Howells 
1618c3e34a4SDavid Howells static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
1628c3e34a4SDavid Howells {
1638c3e34a4SDavid Howells 	struct rxrpc_connection *conn;
1642baec2c3SDavid Howells 	struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
16575b54cb5SDavid Howells 	char lbuff[50], rbuff[50];
1668c3e34a4SDavid Howells 
1672baec2c3SDavid Howells 	if (v == &rxnet->conn_proc_list) {
1688c3e34a4SDavid Howells 		seq_puts(seq,
16975b54cb5SDavid Howells 			 "Proto Local                                          "
17075b54cb5SDavid Howells 			 " Remote                                         "
171a1399f8bSDavid Howells 			 " SvID ConnID   End Use State    Key     "
1728c3e34a4SDavid Howells 			 " Serial   ISerial\n"
1738c3e34a4SDavid Howells 			 );
1748c3e34a4SDavid Howells 		return 0;
1758c3e34a4SDavid Howells 	}
1768c3e34a4SDavid Howells 
1774d028b2cSDavid Howells 	conn = list_entry(v, struct rxrpc_connection, proc_link);
17800e90712SDavid Howells 	if (conn->state == RXRPC_CONN_SERVICE_PREALLOC) {
17900e90712SDavid Howells 		strcpy(lbuff, "no_local");
18000e90712SDavid Howells 		strcpy(rbuff, "no_connection");
18100e90712SDavid Howells 		goto print;
18200e90712SDavid Howells 	}
1838c3e34a4SDavid Howells 
18475b54cb5SDavid Howells 	sprintf(lbuff, "%pISpc", &conn->params.local->srx.transport);
1858c3e34a4SDavid Howells 
18675b54cb5SDavid Howells 	sprintf(rbuff, "%pISpc", &conn->params.peer->srx.transport);
18700e90712SDavid Howells print:
1888c3e34a4SDavid Howells 	seq_printf(seq,
18975b54cb5SDavid Howells 		   "UDP   %-47.47s %-47.47s %4x %08x %s %3u"
1906b97bd7aSDavid Howells 		   " %s %08x %08x %08x %08x %08x %08x %08x\n",
1918c3e34a4SDavid Howells 		   lbuff,
1928c3e34a4SDavid Howells 		   rbuff,
19368d6d1aeSDavid Howells 		   conn->service_id,
19419ffa01cSDavid Howells 		   conn->proto.cid,
19519ffa01cSDavid Howells 		   rxrpc_conn_is_service(conn) ? "Svc" : "Clt",
1968c3e34a4SDavid Howells 		   atomic_read(&conn->usage),
1978c3e34a4SDavid Howells 		   rxrpc_conn_states[conn->state],
19819ffa01cSDavid Howells 		   key_serial(conn->params.key),
1998c3e34a4SDavid Howells 		   atomic_read(&conn->serial),
2006b97bd7aSDavid Howells 		   conn->hi_serial,
2016b97bd7aSDavid Howells 		   conn->channels[0].call_id,
2026b97bd7aSDavid Howells 		   conn->channels[1].call_id,
2036b97bd7aSDavid Howells 		   conn->channels[2].call_id,
2046b97bd7aSDavid Howells 		   conn->channels[3].call_id);
2058c3e34a4SDavid Howells 
2068c3e34a4SDavid Howells 	return 0;
2078c3e34a4SDavid Howells }
2088c3e34a4SDavid Howells 
209c3506372SChristoph Hellwig const struct seq_operations rxrpc_connection_seq_ops = {
2108c3e34a4SDavid Howells 	.start  = rxrpc_connection_seq_start,
2118c3e34a4SDavid Howells 	.next   = rxrpc_connection_seq_next,
2128c3e34a4SDavid Howells 	.stop   = rxrpc_connection_seq_stop,
2138c3e34a4SDavid Howells 	.show   = rxrpc_connection_seq_show,
2148c3e34a4SDavid Howells };
215