Linux Audio

Check our new training course

Loading...
v5.4
  1// SPDX-License-Identifier: GPL-2.0-or-later
  2/* /proc/net/ support for AF_RXRPC
  3 *
  4 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
  5 * Written by David Howells (dhowells@redhat.com)
  6 */
  7
  8#include <linux/module.h>
  9#include <net/sock.h>
 10#include <net/af_rxrpc.h>
 11#include "ar-internal.h"
 12
 13static const char *const rxrpc_conn_states[RXRPC_CONN__NR_STATES] = {
 14	[RXRPC_CONN_UNUSED]			= "Unused  ",
 
 15	[RXRPC_CONN_CLIENT]			= "Client  ",
 16	[RXRPC_CONN_SERVICE_PREALLOC]		= "SvPrealc",
 17	[RXRPC_CONN_SERVICE_UNSECURED]		= "SvUnsec ",
 18	[RXRPC_CONN_SERVICE_CHALLENGING]	= "SvChall ",
 19	[RXRPC_CONN_SERVICE]			= "SvSecure",
 20	[RXRPC_CONN_REMOTELY_ABORTED]		= "RmtAbort",
 21	[RXRPC_CONN_LOCALLY_ABORTED]		= "LocAbort",
 22};
 23
 24/*
 25 * generate a list of extant and dead calls in /proc/net/rxrpc_calls
 26 */
 27static void *rxrpc_call_seq_start(struct seq_file *seq, loff_t *_pos)
 28	__acquires(rcu)
 29	__acquires(rxnet->call_lock)
 30{
 31	struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
 32
 33	rcu_read_lock();
 34	read_lock(&rxnet->call_lock);
 35	return seq_list_start_head(&rxnet->calls, *_pos);
 36}
 37
 38static void *rxrpc_call_seq_next(struct seq_file *seq, void *v, loff_t *pos)
 39{
 40	struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
 41
 42	return seq_list_next(v, &rxnet->calls, pos);
 43}
 44
 45static void rxrpc_call_seq_stop(struct seq_file *seq, void *v)
 46	__releases(rxnet->call_lock)
 47	__releases(rcu)
 48{
 49	struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
 50
 51	read_unlock(&rxnet->call_lock);
 52	rcu_read_unlock();
 53}
 54
 55static int rxrpc_call_seq_show(struct seq_file *seq, void *v)
 56{
 57	struct rxrpc_local *local;
 58	struct rxrpc_sock *rx;
 59	struct rxrpc_peer *peer;
 60	struct rxrpc_call *call;
 61	struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
 
 62	unsigned long timeout = 0;
 63	rxrpc_seq_t tx_hard_ack, rx_hard_ack;
 64	char lbuff[50], rbuff[50];
 
 65
 66	if (v == &rxnet->calls) {
 67		seq_puts(seq,
 68			 "Proto Local                                          "
 69			 " Remote                                         "
 70			 " SvID ConnID   CallID   End Use State    Abort   "
 71			 " UserID           TxSeq    TW RxSeq    RW RxSerial RxTimo\n");
 72		return 0;
 73	}
 74
 75	call = list_entry(v, struct rxrpc_call, link);
 76
 77	rx = rcu_dereference(call->socket);
 78	if (rx) {
 79		local = READ_ONCE(rx->local);
 80		if (local)
 81			sprintf(lbuff, "%pISpc", &local->srx.transport);
 82		else
 83			strcpy(lbuff, "no_local");
 84	} else {
 85		strcpy(lbuff, "no_socket");
 86	}
 87
 88	peer = call->peer;
 89	if (peer)
 90		sprintf(rbuff, "%pISpc", &peer->srx.transport);
 91	else
 92		strcpy(rbuff, "no_connection");
 
 
 93
 94	if (call->state != RXRPC_CALL_SERVER_PREALLOC) {
 
 95		timeout = READ_ONCE(call->expect_rx_by);
 96		timeout -= jiffies;
 97	}
 98
 99	tx_hard_ack = READ_ONCE(call->tx_hard_ack);
100	rx_hard_ack = READ_ONCE(call->rx_hard_ack);
101	seq_printf(seq,
102		   "UDP   %-47.47s %-47.47s %4x %08x %08x %s %3u"
103		   " %-8.8s %08x %lx %08x %02x %08x %02x %08x %06lx\n",
104		   lbuff,
105		   rbuff,
106		   call->service_id,
107		   call->cid,
108		   call->call_id,
109		   rxrpc_is_service_call(call) ? "Svc" : "Clt",
110		   atomic_read(&call->usage),
111		   rxrpc_call_states[call->state],
112		   call->abort_code,
113		   call->user_call_ID,
114		   tx_hard_ack, READ_ONCE(call->tx_top) - tx_hard_ack,
115		   rx_hard_ack, READ_ONCE(call->rx_top) - rx_hard_ack,
116		   call->rx_serial,
 
117		   timeout);
118
119	return 0;
120}
121
122const struct seq_operations rxrpc_call_seq_ops = {
123	.start  = rxrpc_call_seq_start,
124	.next   = rxrpc_call_seq_next,
125	.stop   = rxrpc_call_seq_stop,
126	.show   = rxrpc_call_seq_show,
127};
128
129/*
130 * generate a list of extant virtual connections in /proc/net/rxrpc_conns
131 */
132static void *rxrpc_connection_seq_start(struct seq_file *seq, loff_t *_pos)
133	__acquires(rxnet->conn_lock)
134{
135	struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
136
137	read_lock(&rxnet->conn_lock);
138	return seq_list_start_head(&rxnet->conn_proc_list, *_pos);
139}
140
141static void *rxrpc_connection_seq_next(struct seq_file *seq, void *v,
142				       loff_t *pos)
143{
144	struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
145
146	return seq_list_next(v, &rxnet->conn_proc_list, pos);
147}
148
149static void rxrpc_connection_seq_stop(struct seq_file *seq, void *v)
150	__releases(rxnet->conn_lock)
151{
152	struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
153
154	read_unlock(&rxnet->conn_lock);
155}
156
157static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
158{
159	struct rxrpc_connection *conn;
160	struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
 
161	char lbuff[50], rbuff[50];
162
163	if (v == &rxnet->conn_proc_list) {
164		seq_puts(seq,
165			 "Proto Local                                          "
166			 " Remote                                         "
167			 " SvID ConnID   End Use State    Key     "
168			 " Serial   ISerial\n"
169			 );
170		return 0;
171	}
172
173	conn = list_entry(v, struct rxrpc_connection, proc_link);
174	if (conn->state == RXRPC_CONN_SERVICE_PREALLOC) {
175		strcpy(lbuff, "no_local");
176		strcpy(rbuff, "no_connection");
177		goto print;
178	}
179
180	sprintf(lbuff, "%pISpc", &conn->params.local->srx.transport);
181
182	sprintf(rbuff, "%pISpc", &conn->params.peer->srx.transport);
183print:
 
 
 
184	seq_printf(seq,
185		   "UDP   %-47.47s %-47.47s %4x %08x %s %3u"
186		   " %s %08x %08x %08x %08x %08x %08x %08x\n",
187		   lbuff,
188		   rbuff,
189		   conn->service_id,
190		   conn->proto.cid,
191		   rxrpc_conn_is_service(conn) ? "Svc" : "Clt",
192		   atomic_read(&conn->usage),
193		   rxrpc_conn_states[conn->state],
194		   key_serial(conn->params.key),
 
195		   atomic_read(&conn->serial),
196		   conn->hi_serial,
197		   conn->channels[0].call_id,
198		   conn->channels[1].call_id,
199		   conn->channels[2].call_id,
200		   conn->channels[3].call_id);
201
202	return 0;
203}
204
205const struct seq_operations rxrpc_connection_seq_ops = {
206	.start  = rxrpc_connection_seq_start,
207	.next   = rxrpc_connection_seq_next,
208	.stop   = rxrpc_connection_seq_stop,
209	.show   = rxrpc_connection_seq_show,
210};
211
212/*
213 * generate a list of extant virtual peers in /proc/net/rxrpc/peers
214 */
215static int rxrpc_peer_seq_show(struct seq_file *seq, void *v)
216{
217	struct rxrpc_peer *peer;
218	time64_t now;
219	char lbuff[50], rbuff[50];
220
221	if (v == SEQ_START_TOKEN) {
222		seq_puts(seq,
223			 "Proto Local                                          "
224			 " Remote                                         "
225			 " Use CW  MTU   LastUse          RTT Rc\n"
226			 );
227		return 0;
228	}
229
230	peer = list_entry(v, struct rxrpc_peer, hash_link);
231
232	sprintf(lbuff, "%pISpc", &peer->local->srx.transport);
233
234	sprintf(rbuff, "%pISpc", &peer->srx.transport);
235
236	now = ktime_get_seconds();
237	seq_printf(seq,
238		   "UDP   %-47.47s %-47.47s %3u"
239		   " %3u %5u %6llus %12llu %2u\n",
240		   lbuff,
241		   rbuff,
242		   atomic_read(&peer->usage),
243		   peer->cong_cwnd,
244		   peer->mtu,
245		   now - peer->last_tx_at,
246		   peer->rtt,
247		   peer->rtt_cursor);
248
249	return 0;
250}
251
252static void *rxrpc_peer_seq_start(struct seq_file *seq, loff_t *_pos)
253	__acquires(rcu)
254{
255	struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
256	unsigned int bucket, n;
257	unsigned int shift = 32 - HASH_BITS(rxnet->peer_hash);
258	void *p;
259
260	rcu_read_lock();
261
262	if (*_pos >= UINT_MAX)
263		return NULL;
264
265	n = *_pos & ((1U << shift) - 1);
266	bucket = *_pos >> shift;
267	for (;;) {
268		if (bucket >= HASH_SIZE(rxnet->peer_hash)) {
269			*_pos = UINT_MAX;
270			return NULL;
271		}
272		if (n == 0) {
273			if (bucket == 0)
274				return SEQ_START_TOKEN;
275			*_pos += 1;
276			n++;
277		}
278
279		p = seq_hlist_start_rcu(&rxnet->peer_hash[bucket], n - 1);
280		if (p)
281			return p;
282		bucket++;
283		n = 1;
284		*_pos = (bucket << shift) | n;
285	}
286}
287
288static void *rxrpc_peer_seq_next(struct seq_file *seq, void *v, loff_t *_pos)
289{
290	struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
291	unsigned int bucket, n;
292	unsigned int shift = 32 - HASH_BITS(rxnet->peer_hash);
293	void *p;
294
295	if (*_pos >= UINT_MAX)
296		return NULL;
297
298	bucket = *_pos >> shift;
299
300	p = seq_hlist_next_rcu(v, &rxnet->peer_hash[bucket], _pos);
301	if (p)
302		return p;
303
304	for (;;) {
305		bucket++;
306		n = 1;
307		*_pos = (bucket << shift) | n;
308
309		if (bucket >= HASH_SIZE(rxnet->peer_hash)) {
310			*_pos = UINT_MAX;
311			return NULL;
312		}
313		if (n == 0) {
314			*_pos += 1;
315			n++;
316		}
317
318		p = seq_hlist_start_rcu(&rxnet->peer_hash[bucket], n - 1);
319		if (p)
320			return p;
321	}
322}
323
324static void rxrpc_peer_seq_stop(struct seq_file *seq, void *v)
325	__releases(rcu)
326{
327	rcu_read_unlock();
328}
329
330
331const struct seq_operations rxrpc_peer_seq_ops = {
332	.start  = rxrpc_peer_seq_start,
333	.next   = rxrpc_peer_seq_next,
334	.stop   = rxrpc_peer_seq_stop,
335	.show   = rxrpc_peer_seq_show,
336};
v6.2
  1// SPDX-License-Identifier: GPL-2.0-or-later
  2/* /proc/net/ support for AF_RXRPC
  3 *
  4 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
  5 * Written by David Howells (dhowells@redhat.com)
  6 */
  7
  8#include <linux/module.h>
  9#include <net/sock.h>
 10#include <net/af_rxrpc.h>
 11#include "ar-internal.h"
 12
 13static const char *const rxrpc_conn_states[RXRPC_CONN__NR_STATES] = {
 14	[RXRPC_CONN_UNUSED]			= "Unused  ",
 15	[RXRPC_CONN_CLIENT_UNSECURED]		= "ClUnsec ",
 16	[RXRPC_CONN_CLIENT]			= "Client  ",
 17	[RXRPC_CONN_SERVICE_PREALLOC]		= "SvPrealc",
 18	[RXRPC_CONN_SERVICE_UNSECURED]		= "SvUnsec ",
 19	[RXRPC_CONN_SERVICE_CHALLENGING]	= "SvChall ",
 20	[RXRPC_CONN_SERVICE]			= "SvSecure",
 21	[RXRPC_CONN_ABORTED]			= "Aborted ",
 
 22};
 23
 24/*
 25 * generate a list of extant and dead calls in /proc/net/rxrpc_calls
 26 */
 27static void *rxrpc_call_seq_start(struct seq_file *seq, loff_t *_pos)
 28	__acquires(rcu)
 
 29{
 30	struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
 31
 32	rcu_read_lock();
 33	return seq_list_start_head_rcu(&rxnet->calls, *_pos);
 
 34}
 35
 36static void *rxrpc_call_seq_next(struct seq_file *seq, void *v, loff_t *pos)
 37{
 38	struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
 39
 40	return seq_list_next_rcu(v, &rxnet->calls, pos);
 41}
 42
 43static void rxrpc_call_seq_stop(struct seq_file *seq, void *v)
 
 44	__releases(rcu)
 45{
 
 
 
 46	rcu_read_unlock();
 47}
 48
 49static int rxrpc_call_seq_show(struct seq_file *seq, void *v)
 50{
 51	struct rxrpc_local *local;
 
 
 52	struct rxrpc_call *call;
 53	struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
 54	enum rxrpc_call_state state;
 55	unsigned long timeout = 0;
 56	rxrpc_seq_t acks_hard_ack;
 57	char lbuff[50], rbuff[50];
 58	u64 wtmp;
 59
 60	if (v == &rxnet->calls) {
 61		seq_puts(seq,
 62			 "Proto Local                                          "
 63			 " Remote                                         "
 64			 " SvID ConnID   CallID   End Use State    Abort   "
 65			 " DebugId  TxSeq    TW RxSeq    RW RxSerial CW RxTimo\n");
 66		return 0;
 67	}
 68
 69	call = list_entry(v, struct rxrpc_call, link);
 70
 71	local = call->local;
 72	if (local)
 73		sprintf(lbuff, "%pISpc", &local->srx.transport);
 
 
 
 
 
 
 
 
 
 
 
 74	else
 75		strcpy(lbuff, "no_local");
 76
 77	sprintf(rbuff, "%pISpc", &call->dest_srx.transport);
 78
 79	state = rxrpc_call_state(call);
 80	if (state != RXRPC_CALL_SERVER_PREALLOC) {
 81		timeout = READ_ONCE(call->expect_rx_by);
 82		timeout -= jiffies;
 83	}
 84
 85	acks_hard_ack = READ_ONCE(call->acks_hard_ack);
 86	wtmp   = atomic64_read_acquire(&call->ackr_window);
 87	seq_printf(seq,
 88		   "UDP   %-47.47s %-47.47s %4x %08x %08x %s %3u"
 89		   " %-8.8s %08x %08x %08x %02x %08x %02x %08x %02x %06lx\n",
 90		   lbuff,
 91		   rbuff,
 92		   call->dest_srx.srx_service,
 93		   call->cid,
 94		   call->call_id,
 95		   rxrpc_is_service_call(call) ? "Svc" : "Clt",
 96		   refcount_read(&call->ref),
 97		   rxrpc_call_states[state],
 98		   call->abort_code,
 99		   call->debug_id,
100		   acks_hard_ack, READ_ONCE(call->tx_top) - acks_hard_ack,
101		   lower_32_bits(wtmp), upper_32_bits(wtmp) - lower_32_bits(wtmp),
102		   call->rx_serial,
103		   call->cong_cwnd,
104		   timeout);
105
106	return 0;
107}
108
109const struct seq_operations rxrpc_call_seq_ops = {
110	.start  = rxrpc_call_seq_start,
111	.next   = rxrpc_call_seq_next,
112	.stop   = rxrpc_call_seq_stop,
113	.show   = rxrpc_call_seq_show,
114};
115
116/*
117 * generate a list of extant virtual connections in /proc/net/rxrpc_conns
118 */
119static void *rxrpc_connection_seq_start(struct seq_file *seq, loff_t *_pos)
120	__acquires(rxnet->conn_lock)
121{
122	struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
123
124	read_lock(&rxnet->conn_lock);
125	return seq_list_start_head(&rxnet->conn_proc_list, *_pos);
126}
127
128static void *rxrpc_connection_seq_next(struct seq_file *seq, void *v,
129				       loff_t *pos)
130{
131	struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
132
133	return seq_list_next(v, &rxnet->conn_proc_list, pos);
134}
135
136static void rxrpc_connection_seq_stop(struct seq_file *seq, void *v)
137	__releases(rxnet->conn_lock)
138{
139	struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
140
141	read_unlock(&rxnet->conn_lock);
142}
143
144static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
145{
146	struct rxrpc_connection *conn;
147	struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
148	const char *state;
149	char lbuff[50], rbuff[50];
150
151	if (v == &rxnet->conn_proc_list) {
152		seq_puts(seq,
153			 "Proto Local                                          "
154			 " Remote                                         "
155			 " SvID ConnID   End Ref Act State    Key     "
156			 " Serial   ISerial  CallId0  CallId1  CallId2  CallId3\n"
157			 );
158		return 0;
159	}
160
161	conn = list_entry(v, struct rxrpc_connection, proc_link);
162	if (conn->state == RXRPC_CONN_SERVICE_PREALLOC) {
163		strcpy(lbuff, "no_local");
164		strcpy(rbuff, "no_connection");
165		goto print;
166	}
167
168	sprintf(lbuff, "%pISpc", &conn->local->srx.transport);
169	sprintf(rbuff, "%pISpc", &conn->peer->srx.transport);
 
170print:
171	state = rxrpc_is_conn_aborted(conn) ?
172		rxrpc_call_completions[conn->completion] :
173		rxrpc_conn_states[conn->state];
174	seq_printf(seq,
175		   "UDP   %-47.47s %-47.47s %4x %08x %s %3u %3d"
176		   " %s %08x %08x %08x %08x %08x %08x %08x\n",
177		   lbuff,
178		   rbuff,
179		   conn->service_id,
180		   conn->proto.cid,
181		   rxrpc_conn_is_service(conn) ? "Svc" : "Clt",
182		   refcount_read(&conn->ref),
183		   atomic_read(&conn->active),
184		   state,
185		   key_serial(conn->key),
186		   atomic_read(&conn->serial),
187		   conn->hi_serial,
188		   conn->channels[0].call_id,
189		   conn->channels[1].call_id,
190		   conn->channels[2].call_id,
191		   conn->channels[3].call_id);
192
193	return 0;
194}
195
196const struct seq_operations rxrpc_connection_seq_ops = {
197	.start  = rxrpc_connection_seq_start,
198	.next   = rxrpc_connection_seq_next,
199	.stop   = rxrpc_connection_seq_stop,
200	.show   = rxrpc_connection_seq_show,
201};
202
203/*
204 * generate a list of extant virtual peers in /proc/net/rxrpc/peers
205 */
206static int rxrpc_peer_seq_show(struct seq_file *seq, void *v)
207{
208	struct rxrpc_peer *peer;
209	time64_t now;
210	char lbuff[50], rbuff[50];
211
212	if (v == SEQ_START_TOKEN) {
213		seq_puts(seq,
214			 "Proto Local                                          "
215			 " Remote                                         "
216			 " Use SST   MTU LastUse      RTT      RTO\n"
217			 );
218		return 0;
219	}
220
221	peer = list_entry(v, struct rxrpc_peer, hash_link);
222
223	sprintf(lbuff, "%pISpc", &peer->local->srx.transport);
224
225	sprintf(rbuff, "%pISpc", &peer->srx.transport);
226
227	now = ktime_get_seconds();
228	seq_printf(seq,
229		   "UDP   %-47.47s %-47.47s %3u"
230		   " %3u %5u %6llus %8u %8u\n",
231		   lbuff,
232		   rbuff,
233		   refcount_read(&peer->ref),
234		   peer->cong_ssthresh,
235		   peer->mtu,
236		   now - peer->last_tx_at,
237		   peer->srtt_us >> 3,
238		   jiffies_to_usecs(peer->rto_j));
239
240	return 0;
241}
242
243static void *rxrpc_peer_seq_start(struct seq_file *seq, loff_t *_pos)
244	__acquires(rcu)
245{
246	struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
247	unsigned int bucket, n;
248	unsigned int shift = 32 - HASH_BITS(rxnet->peer_hash);
249	void *p;
250
251	rcu_read_lock();
252
253	if (*_pos >= UINT_MAX)
254		return NULL;
255
256	n = *_pos & ((1U << shift) - 1);
257	bucket = *_pos >> shift;
258	for (;;) {
259		if (bucket >= HASH_SIZE(rxnet->peer_hash)) {
260			*_pos = UINT_MAX;
261			return NULL;
262		}
263		if (n == 0) {
264			if (bucket == 0)
265				return SEQ_START_TOKEN;
266			*_pos += 1;
267			n++;
268		}
269
270		p = seq_hlist_start_rcu(&rxnet->peer_hash[bucket], n - 1);
271		if (p)
272			return p;
273		bucket++;
274		n = 1;
275		*_pos = (bucket << shift) | n;
276	}
277}
278
279static void *rxrpc_peer_seq_next(struct seq_file *seq, void *v, loff_t *_pos)
280{
281	struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
282	unsigned int bucket, n;
283	unsigned int shift = 32 - HASH_BITS(rxnet->peer_hash);
284	void *p;
285
286	if (*_pos >= UINT_MAX)
287		return NULL;
288
289	bucket = *_pos >> shift;
290
291	p = seq_hlist_next_rcu(v, &rxnet->peer_hash[bucket], _pos);
292	if (p)
293		return p;
294
295	for (;;) {
296		bucket++;
297		n = 1;
298		*_pos = (bucket << shift) | n;
299
300		if (bucket >= HASH_SIZE(rxnet->peer_hash)) {
301			*_pos = UINT_MAX;
302			return NULL;
303		}
304		if (n == 0) {
305			*_pos += 1;
306			n++;
307		}
308
309		p = seq_hlist_start_rcu(&rxnet->peer_hash[bucket], n - 1);
310		if (p)
311			return p;
312	}
313}
314
315static void rxrpc_peer_seq_stop(struct seq_file *seq, void *v)
316	__releases(rcu)
317{
318	rcu_read_unlock();
319}
320
321
322const struct seq_operations rxrpc_peer_seq_ops = {
323	.start  = rxrpc_peer_seq_start,
324	.next   = rxrpc_peer_seq_next,
325	.stop   = rxrpc_peer_seq_stop,
326	.show   = rxrpc_peer_seq_show,
327};
328
329/*
330 * Generate a list of extant virtual local endpoints in /proc/net/rxrpc/locals
331 */
332static int rxrpc_local_seq_show(struct seq_file *seq, void *v)
333{
334	struct rxrpc_local *local;
335	char lbuff[50];
336
337	if (v == SEQ_START_TOKEN) {
338		seq_puts(seq,
339			 "Proto Local                                          "
340			 " Use Act RxQ\n");
341		return 0;
342	}
343
344	local = hlist_entry(v, struct rxrpc_local, link);
345
346	sprintf(lbuff, "%pISpc", &local->srx.transport);
347
348	seq_printf(seq,
349		   "UDP   %-47.47s %3u %3u %3u\n",
350		   lbuff,
351		   refcount_read(&local->ref),
352		   atomic_read(&local->active_users),
353		   local->rx_queue.qlen);
354
355	return 0;
356}
357
358static void *rxrpc_local_seq_start(struct seq_file *seq, loff_t *_pos)
359	__acquires(rcu)
360{
361	struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
362	unsigned int n;
363
364	rcu_read_lock();
365
366	if (*_pos >= UINT_MAX)
367		return NULL;
368
369	n = *_pos;
370	if (n == 0)
371		return SEQ_START_TOKEN;
372
373	return seq_hlist_start_rcu(&rxnet->local_endpoints, n - 1);
374}
375
376static void *rxrpc_local_seq_next(struct seq_file *seq, void *v, loff_t *_pos)
377{
378	struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
379
380	if (*_pos >= UINT_MAX)
381		return NULL;
382
383	return seq_hlist_next_rcu(v, &rxnet->local_endpoints, _pos);
384}
385
386static void rxrpc_local_seq_stop(struct seq_file *seq, void *v)
387	__releases(rcu)
388{
389	rcu_read_unlock();
390}
391
392const struct seq_operations rxrpc_local_seq_ops = {
393	.start  = rxrpc_local_seq_start,
394	.next   = rxrpc_local_seq_next,
395	.stop   = rxrpc_local_seq_stop,
396	.show   = rxrpc_local_seq_show,
397};
398
399/*
400 * Display stats in /proc/net/rxrpc/stats
401 */
402int rxrpc_stats_show(struct seq_file *seq, void *v)
403{
404	struct rxrpc_net *rxnet = rxrpc_net(seq_file_single_net(seq));
405
406	seq_printf(seq,
407		   "Data     : send=%u sendf=%u fail=%u\n",
408		   atomic_read(&rxnet->stat_tx_data_send),
409		   atomic_read(&rxnet->stat_tx_data_send_frag),
410		   atomic_read(&rxnet->stat_tx_data_send_fail));
411	seq_printf(seq,
412		   "Data-Tx  : nr=%u retrans=%u uf=%u cwr=%u\n",
413		   atomic_read(&rxnet->stat_tx_data),
414		   atomic_read(&rxnet->stat_tx_data_retrans),
415		   atomic_read(&rxnet->stat_tx_data_underflow),
416		   atomic_read(&rxnet->stat_tx_data_cwnd_reset));
417	seq_printf(seq,
418		   "Data-Rx  : nr=%u reqack=%u jumbo=%u\n",
419		   atomic_read(&rxnet->stat_rx_data),
420		   atomic_read(&rxnet->stat_rx_data_reqack),
421		   atomic_read(&rxnet->stat_rx_data_jumbo));
422	seq_printf(seq,
423		   "Ack      : fill=%u send=%u skip=%u\n",
424		   atomic_read(&rxnet->stat_tx_ack_fill),
425		   atomic_read(&rxnet->stat_tx_ack_send),
426		   atomic_read(&rxnet->stat_tx_ack_skip));
427	seq_printf(seq,
428		   "Ack-Tx   : req=%u dup=%u oos=%u exw=%u nos=%u png=%u prs=%u dly=%u idl=%u\n",
429		   atomic_read(&rxnet->stat_tx_acks[RXRPC_ACK_REQUESTED]),
430		   atomic_read(&rxnet->stat_tx_acks[RXRPC_ACK_DUPLICATE]),
431		   atomic_read(&rxnet->stat_tx_acks[RXRPC_ACK_OUT_OF_SEQUENCE]),
432		   atomic_read(&rxnet->stat_tx_acks[RXRPC_ACK_EXCEEDS_WINDOW]),
433		   atomic_read(&rxnet->stat_tx_acks[RXRPC_ACK_NOSPACE]),
434		   atomic_read(&rxnet->stat_tx_acks[RXRPC_ACK_PING]),
435		   atomic_read(&rxnet->stat_tx_acks[RXRPC_ACK_PING_RESPONSE]),
436		   atomic_read(&rxnet->stat_tx_acks[RXRPC_ACK_DELAY]),
437		   atomic_read(&rxnet->stat_tx_acks[RXRPC_ACK_IDLE]));
438	seq_printf(seq,
439		   "Ack-Rx   : req=%u dup=%u oos=%u exw=%u nos=%u png=%u prs=%u dly=%u idl=%u\n",
440		   atomic_read(&rxnet->stat_rx_acks[RXRPC_ACK_REQUESTED]),
441		   atomic_read(&rxnet->stat_rx_acks[RXRPC_ACK_DUPLICATE]),
442		   atomic_read(&rxnet->stat_rx_acks[RXRPC_ACK_OUT_OF_SEQUENCE]),
443		   atomic_read(&rxnet->stat_rx_acks[RXRPC_ACK_EXCEEDS_WINDOW]),
444		   atomic_read(&rxnet->stat_rx_acks[RXRPC_ACK_NOSPACE]),
445		   atomic_read(&rxnet->stat_rx_acks[RXRPC_ACK_PING]),
446		   atomic_read(&rxnet->stat_rx_acks[RXRPC_ACK_PING_RESPONSE]),
447		   atomic_read(&rxnet->stat_rx_acks[RXRPC_ACK_DELAY]),
448		   atomic_read(&rxnet->stat_rx_acks[RXRPC_ACK_IDLE]));
449	seq_printf(seq,
450		   "Why-Req-A: acklost=%u already=%u mrtt=%u ortt=%u\n",
451		   atomic_read(&rxnet->stat_why_req_ack[rxrpc_reqack_ack_lost]),
452		   atomic_read(&rxnet->stat_why_req_ack[rxrpc_reqack_already_on]),
453		   atomic_read(&rxnet->stat_why_req_ack[rxrpc_reqack_more_rtt]),
454		   atomic_read(&rxnet->stat_why_req_ack[rxrpc_reqack_old_rtt]));
455	seq_printf(seq,
456		   "Why-Req-A: nolast=%u retx=%u slows=%u smtxw=%u\n",
457		   atomic_read(&rxnet->stat_why_req_ack[rxrpc_reqack_no_srv_last]),
458		   atomic_read(&rxnet->stat_why_req_ack[rxrpc_reqack_retrans]),
459		   atomic_read(&rxnet->stat_why_req_ack[rxrpc_reqack_slow_start]),
460		   atomic_read(&rxnet->stat_why_req_ack[rxrpc_reqack_small_txwin]));
461	seq_printf(seq,
462		   "Buffers  : txb=%u rxb=%u\n",
463		   atomic_read(&rxrpc_nr_txbuf),
464		   atomic_read(&rxrpc_n_rx_skbs));
465	seq_printf(seq,
466		   "IO-thread: loops=%u\n",
467		   atomic_read(&rxnet->stat_io_loop));
468	return 0;
469}
470
471/*
472 * Clear stats if /proc/net/rxrpc/stats is written to.
473 */
474int rxrpc_stats_clear(struct file *file, char *buf, size_t size)
475{
476	struct seq_file *m = file->private_data;
477	struct rxrpc_net *rxnet = rxrpc_net(seq_file_single_net(m));
478
479	if (size > 1 || (size == 1 && buf[0] != '\n'))
480		return -EINVAL;
481
482	atomic_set(&rxnet->stat_tx_data, 0);
483	atomic_set(&rxnet->stat_tx_data_retrans, 0);
484	atomic_set(&rxnet->stat_tx_data_underflow, 0);
485	atomic_set(&rxnet->stat_tx_data_cwnd_reset, 0);
486	atomic_set(&rxnet->stat_tx_data_send, 0);
487	atomic_set(&rxnet->stat_tx_data_send_frag, 0);
488	atomic_set(&rxnet->stat_tx_data_send_fail, 0);
489	atomic_set(&rxnet->stat_rx_data, 0);
490	atomic_set(&rxnet->stat_rx_data_reqack, 0);
491	atomic_set(&rxnet->stat_rx_data_jumbo, 0);
492
493	atomic_set(&rxnet->stat_tx_ack_fill, 0);
494	atomic_set(&rxnet->stat_tx_ack_send, 0);
495	atomic_set(&rxnet->stat_tx_ack_skip, 0);
496	memset(&rxnet->stat_tx_acks, 0, sizeof(rxnet->stat_tx_acks));
497	memset(&rxnet->stat_rx_acks, 0, sizeof(rxnet->stat_rx_acks));
498
499	memset(&rxnet->stat_why_req_ack, 0, sizeof(rxnet->stat_why_req_ack));
500
501	atomic_set(&rxnet->stat_io_loop, 0);
502	return size;
503}