xref: /openbmc/linux/net/rxrpc/proc.c (revision bc0e7cf4)
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 };
215bc0e7cf4SDavid Howells 
216bc0e7cf4SDavid Howells /*
217bc0e7cf4SDavid Howells  * generate a list of extant virtual peers in /proc/net/rxrpc/peers
218bc0e7cf4SDavid Howells  */
219bc0e7cf4SDavid Howells static int rxrpc_peer_seq_show(struct seq_file *seq, void *v)
220bc0e7cf4SDavid Howells {
221bc0e7cf4SDavid Howells 	struct rxrpc_peer *peer;
222bc0e7cf4SDavid Howells 	time64_t now;
223bc0e7cf4SDavid Howells 	char lbuff[50], rbuff[50];
224bc0e7cf4SDavid Howells 
225bc0e7cf4SDavid Howells 	if (v == SEQ_START_TOKEN) {
226bc0e7cf4SDavid Howells 		seq_puts(seq,
227bc0e7cf4SDavid Howells 			 "Proto Local                                          "
228bc0e7cf4SDavid Howells 			 " Remote                                         "
229bc0e7cf4SDavid Howells 			 " Use CW  MTU   LastUse          RTT Rc\n"
230bc0e7cf4SDavid Howells 			 );
231bc0e7cf4SDavid Howells 		return 0;
232bc0e7cf4SDavid Howells 	}
233bc0e7cf4SDavid Howells 
234bc0e7cf4SDavid Howells 	peer = list_entry(v, struct rxrpc_peer, hash_link);
235bc0e7cf4SDavid Howells 
236bc0e7cf4SDavid Howells 	sprintf(lbuff, "%pISpc", &peer->local->srx.transport);
237bc0e7cf4SDavid Howells 
238bc0e7cf4SDavid Howells 	sprintf(rbuff, "%pISpc", &peer->srx.transport);
239bc0e7cf4SDavid Howells 
240bc0e7cf4SDavid Howells 	now = ktime_get_seconds();
241bc0e7cf4SDavid Howells 	seq_printf(seq,
242bc0e7cf4SDavid Howells 		   "UDP   %-47.47s %-47.47s %3u"
243bc0e7cf4SDavid Howells 		   " %3u %5u %6llus %12llu %2u\n",
244bc0e7cf4SDavid Howells 		   lbuff,
245bc0e7cf4SDavid Howells 		   rbuff,
246bc0e7cf4SDavid Howells 		   atomic_read(&peer->usage),
247bc0e7cf4SDavid Howells 		   peer->cong_cwnd,
248bc0e7cf4SDavid Howells 		   peer->mtu,
249bc0e7cf4SDavid Howells 		   now - peer->last_tx_at,
250bc0e7cf4SDavid Howells 		   peer->rtt,
251bc0e7cf4SDavid Howells 		   peer->rtt_cursor);
252bc0e7cf4SDavid Howells 
253bc0e7cf4SDavid Howells 	return 0;
254bc0e7cf4SDavid Howells }
255bc0e7cf4SDavid Howells 
256bc0e7cf4SDavid Howells static void *rxrpc_peer_seq_start(struct seq_file *seq, loff_t *_pos)
257bc0e7cf4SDavid Howells 	__acquires(rcu)
258bc0e7cf4SDavid Howells {
259bc0e7cf4SDavid Howells 	struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
260bc0e7cf4SDavid Howells 	unsigned int bucket, n;
261bc0e7cf4SDavid Howells 	unsigned int shift = 32 - HASH_BITS(rxnet->peer_hash);
262bc0e7cf4SDavid Howells 	void *p;
263bc0e7cf4SDavid Howells 
264bc0e7cf4SDavid Howells 	rcu_read_lock();
265bc0e7cf4SDavid Howells 
266bc0e7cf4SDavid Howells 	if (*_pos >= UINT_MAX)
267bc0e7cf4SDavid Howells 		return NULL;
268bc0e7cf4SDavid Howells 
269bc0e7cf4SDavid Howells 	n = *_pos & ((1U << shift) - 1);
270bc0e7cf4SDavid Howells 	bucket = *_pos >> shift;
271bc0e7cf4SDavid Howells 	for (;;) {
272bc0e7cf4SDavid Howells 		if (bucket >= HASH_SIZE(rxnet->peer_hash)) {
273bc0e7cf4SDavid Howells 			*_pos = UINT_MAX;
274bc0e7cf4SDavid Howells 			return NULL;
275bc0e7cf4SDavid Howells 		}
276bc0e7cf4SDavid Howells 		if (n == 0) {
277bc0e7cf4SDavid Howells 			if (bucket == 0)
278bc0e7cf4SDavid Howells 				return SEQ_START_TOKEN;
279bc0e7cf4SDavid Howells 			*_pos += 1;
280bc0e7cf4SDavid Howells 			n++;
281bc0e7cf4SDavid Howells 		}
282bc0e7cf4SDavid Howells 
283bc0e7cf4SDavid Howells 		p = seq_hlist_start_rcu(&rxnet->peer_hash[bucket], n - 1);
284bc0e7cf4SDavid Howells 		if (p)
285bc0e7cf4SDavid Howells 			return p;
286bc0e7cf4SDavid Howells 		bucket++;
287bc0e7cf4SDavid Howells 		n = 1;
288bc0e7cf4SDavid Howells 		*_pos = (bucket << shift) | n;
289bc0e7cf4SDavid Howells 	}
290bc0e7cf4SDavid Howells }
291bc0e7cf4SDavid Howells 
292bc0e7cf4SDavid Howells static void *rxrpc_peer_seq_next(struct seq_file *seq, void *v, loff_t *_pos)
293bc0e7cf4SDavid Howells {
294bc0e7cf4SDavid Howells 	struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
295bc0e7cf4SDavid Howells 	unsigned int bucket, n;
296bc0e7cf4SDavid Howells 	unsigned int shift = 32 - HASH_BITS(rxnet->peer_hash);
297bc0e7cf4SDavid Howells 	void *p;
298bc0e7cf4SDavid Howells 
299bc0e7cf4SDavid Howells 	if (*_pos >= UINT_MAX)
300bc0e7cf4SDavid Howells 		return NULL;
301bc0e7cf4SDavid Howells 
302bc0e7cf4SDavid Howells 	bucket = *_pos >> shift;
303bc0e7cf4SDavid Howells 
304bc0e7cf4SDavid Howells 	p = seq_hlist_next_rcu(v, &rxnet->peer_hash[bucket], _pos);
305bc0e7cf4SDavid Howells 	if (p)
306bc0e7cf4SDavid Howells 		return p;
307bc0e7cf4SDavid Howells 
308bc0e7cf4SDavid Howells 	for (;;) {
309bc0e7cf4SDavid Howells 		bucket++;
310bc0e7cf4SDavid Howells 		n = 1;
311bc0e7cf4SDavid Howells 		*_pos = (bucket << shift) | n;
312bc0e7cf4SDavid Howells 
313bc0e7cf4SDavid Howells 		if (bucket >= HASH_SIZE(rxnet->peer_hash)) {
314bc0e7cf4SDavid Howells 			*_pos = UINT_MAX;
315bc0e7cf4SDavid Howells 			return NULL;
316bc0e7cf4SDavid Howells 		}
317bc0e7cf4SDavid Howells 		if (n == 0) {
318bc0e7cf4SDavid Howells 			*_pos += 1;
319bc0e7cf4SDavid Howells 			n++;
320bc0e7cf4SDavid Howells 		}
321bc0e7cf4SDavid Howells 
322bc0e7cf4SDavid Howells 		p = seq_hlist_start_rcu(&rxnet->peer_hash[bucket], n - 1);
323bc0e7cf4SDavid Howells 		if (p)
324bc0e7cf4SDavid Howells 			return p;
325bc0e7cf4SDavid Howells 	}
326bc0e7cf4SDavid Howells }
327bc0e7cf4SDavid Howells 
328bc0e7cf4SDavid Howells static void rxrpc_peer_seq_stop(struct seq_file *seq, void *v)
329bc0e7cf4SDavid Howells 	__releases(rcu)
330bc0e7cf4SDavid Howells {
331bc0e7cf4SDavid Howells 	rcu_read_unlock();
332bc0e7cf4SDavid Howells }
333bc0e7cf4SDavid Howells 
334bc0e7cf4SDavid Howells 
335bc0e7cf4SDavid Howells const struct seq_operations rxrpc_peer_seq_ops = {
336bc0e7cf4SDavid Howells 	.start  = rxrpc_peer_seq_start,
337bc0e7cf4SDavid Howells 	.next   = rxrpc_peer_seq_next,
338bc0e7cf4SDavid Howells 	.stop   = rxrpc_peer_seq_stop,
339bc0e7cf4SDavid Howells 	.show   = rxrpc_peer_seq_show,
340bc0e7cf4SDavid Howells };
341