Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /* /proc/net/ support for AF_RXRPC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Written by David Howells (dhowells@redhat.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <net/sock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <net/af_rxrpc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include "ar-internal.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) static const char *const rxrpc_conn_states[RXRPC_CONN__NR_STATES] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 	[RXRPC_CONN_UNUSED]			= "Unused  ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 	[RXRPC_CONN_CLIENT]			= "Client  ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 	[RXRPC_CONN_SERVICE_PREALLOC]		= "SvPrealc",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 	[RXRPC_CONN_SERVICE_UNSECURED]		= "SvUnsec ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 	[RXRPC_CONN_SERVICE_CHALLENGING]	= "SvChall ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 	[RXRPC_CONN_SERVICE]			= "SvSecure",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 	[RXRPC_CONN_REMOTELY_ABORTED]		= "RmtAbort",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 	[RXRPC_CONN_LOCALLY_ABORTED]		= "LocAbort",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  * generate a list of extant and dead calls in /proc/net/rxrpc_calls
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) static void *rxrpc_call_seq_start(struct seq_file *seq, loff_t *_pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	__acquires(rcu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	__acquires(rxnet->call_lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	read_lock(&rxnet->call_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	return seq_list_start_head(&rxnet->calls, *_pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) static void *rxrpc_call_seq_next(struct seq_file *seq, void *v, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	return seq_list_next(v, &rxnet->calls, pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) static void rxrpc_call_seq_stop(struct seq_file *seq, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	__releases(rxnet->call_lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	__releases(rcu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	read_unlock(&rxnet->call_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) static int rxrpc_call_seq_show(struct seq_file *seq, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	struct rxrpc_local *local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	struct rxrpc_sock *rx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	struct rxrpc_peer *peer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	struct rxrpc_call *call;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	unsigned long timeout = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	rxrpc_seq_t tx_hard_ack, rx_hard_ack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	char lbuff[50], rbuff[50];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	if (v == &rxnet->calls) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		seq_puts(seq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 			 "Proto Local                                          "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 			 " Remote                                         "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 			 " SvID ConnID   CallID   End Use State    Abort   "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 			 " DebugId  TxSeq    TW RxSeq    RW RxSerial RxTimo\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	call = list_entry(v, struct rxrpc_call, link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	rx = rcu_dereference(call->socket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	if (rx) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		local = READ_ONCE(rx->local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		if (local)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 			sprintf(lbuff, "%pISpc", &local->srx.transport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 			strcpy(lbuff, "no_local");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		strcpy(lbuff, "no_socket");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	peer = call->peer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	if (peer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		sprintf(rbuff, "%pISpc", &peer->srx.transport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		strcpy(rbuff, "no_connection");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	if (call->state != RXRPC_CALL_SERVER_PREALLOC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		timeout = READ_ONCE(call->expect_rx_by);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		timeout -= jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	tx_hard_ack = READ_ONCE(call->tx_hard_ack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	rx_hard_ack = READ_ONCE(call->rx_hard_ack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	seq_printf(seq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 		   "UDP   %-47.47s %-47.47s %4x %08x %08x %s %3u"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		   " %-8.8s %08x %08x %08x %02x %08x %02x %08x %06lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 		   lbuff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		   rbuff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		   call->service_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		   call->cid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		   call->call_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		   rxrpc_is_service_call(call) ? "Svc" : "Clt",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		   atomic_read(&call->usage),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		   rxrpc_call_states[call->state],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		   call->abort_code,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		   call->debug_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		   tx_hard_ack, READ_ONCE(call->tx_top) - tx_hard_ack,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		   rx_hard_ack, READ_ONCE(call->rx_top) - rx_hard_ack,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		   call->rx_serial,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 		   timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) const struct seq_operations rxrpc_call_seq_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	.start  = rxrpc_call_seq_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	.next   = rxrpc_call_seq_next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	.stop   = rxrpc_call_seq_stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	.show   = rxrpc_call_seq_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)  * generate a list of extant virtual connections in /proc/net/rxrpc_conns
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) static void *rxrpc_connection_seq_start(struct seq_file *seq, loff_t *_pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	__acquires(rxnet->conn_lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	read_lock(&rxnet->conn_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	return seq_list_start_head(&rxnet->conn_proc_list, *_pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) static void *rxrpc_connection_seq_next(struct seq_file *seq, void *v,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 				       loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	return seq_list_next(v, &rxnet->conn_proc_list, pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) static void rxrpc_connection_seq_stop(struct seq_file *seq, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	__releases(rxnet->conn_lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	read_unlock(&rxnet->conn_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	struct rxrpc_connection *conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	char lbuff[50], rbuff[50];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	if (v == &rxnet->conn_proc_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		seq_puts(seq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 			 "Proto Local                                          "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 			 " Remote                                         "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 			 " SvID ConnID   End Use State    Key     "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 			 " Serial   ISerial  CallId0  CallId1  CallId2  CallId3\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 			 );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	conn = list_entry(v, struct rxrpc_connection, proc_link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	if (conn->state == RXRPC_CONN_SERVICE_PREALLOC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 		strcpy(lbuff, "no_local");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 		strcpy(rbuff, "no_connection");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		goto print;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	sprintf(lbuff, "%pISpc", &conn->params.local->srx.transport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	sprintf(rbuff, "%pISpc", &conn->params.peer->srx.transport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) print:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	seq_printf(seq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		   "UDP   %-47.47s %-47.47s %4x %08x %s %3u"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		   " %s %08x %08x %08x %08x %08x %08x %08x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 		   lbuff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		   rbuff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		   conn->service_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		   conn->proto.cid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		   rxrpc_conn_is_service(conn) ? "Svc" : "Clt",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		   atomic_read(&conn->usage),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		   rxrpc_conn_states[conn->state],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		   key_serial(conn->params.key),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		   atomic_read(&conn->serial),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		   conn->hi_serial,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		   conn->channels[0].call_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		   conn->channels[1].call_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 		   conn->channels[2].call_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		   conn->channels[3].call_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) const struct seq_operations rxrpc_connection_seq_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	.start  = rxrpc_connection_seq_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	.next   = rxrpc_connection_seq_next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	.stop   = rxrpc_connection_seq_stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	.show   = rxrpc_connection_seq_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)  * generate a list of extant virtual peers in /proc/net/rxrpc/peers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) static int rxrpc_peer_seq_show(struct seq_file *seq, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	struct rxrpc_peer *peer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	time64_t now;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	char lbuff[50], rbuff[50];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	if (v == SEQ_START_TOKEN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		seq_puts(seq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 			 "Proto Local                                          "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 			 " Remote                                         "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 			 " Use  CW   MTU LastUse      RTT      RTO\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 			 );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	peer = list_entry(v, struct rxrpc_peer, hash_link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	sprintf(lbuff, "%pISpc", &peer->local->srx.transport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	sprintf(rbuff, "%pISpc", &peer->srx.transport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	now = ktime_get_seconds();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	seq_printf(seq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 		   "UDP   %-47.47s %-47.47s %3u"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		   " %3u %5u %6llus %8u %8u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 		   lbuff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 		   rbuff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 		   atomic_read(&peer->usage),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 		   peer->cong_cwnd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 		   peer->mtu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 		   now - peer->last_tx_at,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 		   peer->srtt_us >> 3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 		   jiffies_to_usecs(peer->rto_j));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) static void *rxrpc_peer_seq_start(struct seq_file *seq, loff_t *_pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	__acquires(rcu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	unsigned int bucket, n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	unsigned int shift = 32 - HASH_BITS(rxnet->peer_hash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	void *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	if (*_pos >= UINT_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	n = *_pos & ((1U << shift) - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	bucket = *_pos >> shift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	for (;;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 		if (bucket >= HASH_SIZE(rxnet->peer_hash)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 			*_pos = UINT_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 			return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 		if (n == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 			if (bucket == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 				return SEQ_START_TOKEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 			*_pos += 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 			n++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 		p = seq_hlist_start_rcu(&rxnet->peer_hash[bucket], n - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 		if (p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 			return p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 		bucket++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 		n = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 		*_pos = (bucket << shift) | n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) static void *rxrpc_peer_seq_next(struct seq_file *seq, void *v, loff_t *_pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	unsigned int bucket, n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	unsigned int shift = 32 - HASH_BITS(rxnet->peer_hash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	void *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	if (*_pos >= UINT_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	bucket = *_pos >> shift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	p = seq_hlist_next_rcu(v, &rxnet->peer_hash[bucket], _pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	if (p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 		return p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	for (;;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 		bucket++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 		n = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 		*_pos = (bucket << shift) | n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 		if (bucket >= HASH_SIZE(rxnet->peer_hash)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 			*_pos = UINT_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 			return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 		if (n == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 			*_pos += 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 			n++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 		p = seq_hlist_start_rcu(&rxnet->peer_hash[bucket], n - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 		if (p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 			return p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) static void rxrpc_peer_seq_stop(struct seq_file *seq, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	__releases(rcu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) const struct seq_operations rxrpc_peer_seq_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	.start  = rxrpc_peer_seq_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	.next   = rxrpc_peer_seq_next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	.stop   = rxrpc_peer_seq_stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	.show   = rxrpc_peer_seq_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) };