1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* /proc/net/ support for AF_RXRPC
4 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
5 * Written by David Howells (dhowells@redhat.com)
8 #include <linux/module.h>
10 #include <net/af_rxrpc.h>
11 #include "ar-internal.h"
13 static 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",
25 * generate a list of extant and dead calls in /proc/net/rxrpc_calls
27 static void *rxrpc_call_seq_start(struct seq_file *seq, loff_t *_pos)
30 struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
33 return seq_list_start_head_rcu(&rxnet->calls, *_pos);
36 static void *rxrpc_call_seq_next(struct seq_file *seq, void *v, loff_t *pos)
38 struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
40 return seq_list_next_rcu(v, &rxnet->calls, pos);
43 static void rxrpc_call_seq_stop(struct seq_file *seq, void *v)
49 static int rxrpc_call_seq_show(struct seq_file *seq, void *v)
51 struct rxrpc_local *local;
52 struct rxrpc_call *call;
53 struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
54 unsigned long timeout = 0;
55 rxrpc_seq_t acks_hard_ack;
56 char lbuff[50], rbuff[50];
59 if (v == &rxnet->calls) {
63 " SvID ConnID CallID End Use State Abort "
64 " DebugId TxSeq TW RxSeq RW RxSerial CW RxTimo\n");
68 call = list_entry(v, struct rxrpc_call, link);
72 sprintf(lbuff, "%pISpc", &local->srx.transport);
74 strcpy(lbuff, "no_local");
76 sprintf(rbuff, "%pISpc", &call->dest_srx.transport);
78 if (call->state != RXRPC_CALL_SERVER_PREALLOC) {
79 timeout = READ_ONCE(call->expect_rx_by);
83 acks_hard_ack = READ_ONCE(call->acks_hard_ack);
84 wtmp = atomic64_read_acquire(&call->ackr_window);
86 "UDP %-47.47s %-47.47s %4x %08x %08x %s %3u"
87 " %-8.8s %08x %08x %08x %02x %08x %02x %08x %02x %06lx\n",
90 call->dest_srx.srx_service,
93 rxrpc_is_service_call(call) ? "Svc" : "Clt",
94 refcount_read(&call->ref),
95 rxrpc_call_states[call->state],
98 acks_hard_ack, READ_ONCE(call->tx_top) - acks_hard_ack,
99 lower_32_bits(wtmp), upper_32_bits(wtmp) - lower_32_bits(wtmp),
107 const struct seq_operations rxrpc_call_seq_ops = {
108 .start = rxrpc_call_seq_start,
109 .next = rxrpc_call_seq_next,
110 .stop = rxrpc_call_seq_stop,
111 .show = rxrpc_call_seq_show,
115 * generate a list of extant virtual connections in /proc/net/rxrpc_conns
117 static void *rxrpc_connection_seq_start(struct seq_file *seq, loff_t *_pos)
118 __acquires(rxnet->conn_lock)
120 struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
122 read_lock(&rxnet->conn_lock);
123 return seq_list_start_head(&rxnet->conn_proc_list, *_pos);
126 static void *rxrpc_connection_seq_next(struct seq_file *seq, void *v,
129 struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
131 return seq_list_next(v, &rxnet->conn_proc_list, pos);
134 static void rxrpc_connection_seq_stop(struct seq_file *seq, void *v)
135 __releases(rxnet->conn_lock)
137 struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
139 read_unlock(&rxnet->conn_lock);
142 static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
144 struct rxrpc_connection *conn;
145 struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
146 char lbuff[50], rbuff[50];
148 if (v == &rxnet->conn_proc_list) {
152 " SvID ConnID End Ref Act State Key "
153 " Serial ISerial CallId0 CallId1 CallId2 CallId3\n"
158 conn = list_entry(v, struct rxrpc_connection, proc_link);
159 if (conn->state == RXRPC_CONN_SERVICE_PREALLOC) {
160 strcpy(lbuff, "no_local");
161 strcpy(rbuff, "no_connection");
165 sprintf(lbuff, "%pISpc", &conn->local->srx.transport);
167 sprintf(rbuff, "%pISpc", &conn->peer->srx.transport);
170 "UDP %-47.47s %-47.47s %4x %08x %s %3u %3d"
171 " %s %08x %08x %08x %08x %08x %08x %08x\n",
176 rxrpc_conn_is_service(conn) ? "Svc" : "Clt",
177 refcount_read(&conn->ref),
178 atomic_read(&conn->active),
179 rxrpc_conn_states[conn->state],
180 key_serial(conn->key),
181 atomic_read(&conn->serial),
183 conn->channels[0].call_id,
184 conn->channels[1].call_id,
185 conn->channels[2].call_id,
186 conn->channels[3].call_id);
191 const struct seq_operations rxrpc_connection_seq_ops = {
192 .start = rxrpc_connection_seq_start,
193 .next = rxrpc_connection_seq_next,
194 .stop = rxrpc_connection_seq_stop,
195 .show = rxrpc_connection_seq_show,
199 * generate a list of extant virtual peers in /proc/net/rxrpc/peers
201 static int rxrpc_peer_seq_show(struct seq_file *seq, void *v)
203 struct rxrpc_peer *peer;
205 char lbuff[50], rbuff[50];
207 if (v == SEQ_START_TOKEN) {
211 " Use SST MTU LastUse RTT RTO\n"
216 peer = list_entry(v, struct rxrpc_peer, hash_link);
218 sprintf(lbuff, "%pISpc", &peer->local->srx.transport);
220 sprintf(rbuff, "%pISpc", &peer->srx.transport);
222 now = ktime_get_seconds();
224 "UDP %-47.47s %-47.47s %3u"
225 " %3u %5u %6llus %8u %8u\n",
228 refcount_read(&peer->ref),
231 now - peer->last_tx_at,
233 jiffies_to_usecs(peer->rto_j));
238 static void *rxrpc_peer_seq_start(struct seq_file *seq, loff_t *_pos)
241 struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
242 unsigned int bucket, n;
243 unsigned int shift = 32 - HASH_BITS(rxnet->peer_hash);
248 if (*_pos >= UINT_MAX)
251 n = *_pos & ((1U << shift) - 1);
252 bucket = *_pos >> shift;
254 if (bucket >= HASH_SIZE(rxnet->peer_hash)) {
260 return SEQ_START_TOKEN;
265 p = seq_hlist_start_rcu(&rxnet->peer_hash[bucket], n - 1);
270 *_pos = (bucket << shift) | n;
274 static void *rxrpc_peer_seq_next(struct seq_file *seq, void *v, loff_t *_pos)
276 struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
277 unsigned int bucket, n;
278 unsigned int shift = 32 - HASH_BITS(rxnet->peer_hash);
281 if (*_pos >= UINT_MAX)
284 bucket = *_pos >> shift;
286 p = seq_hlist_next_rcu(v, &rxnet->peer_hash[bucket], _pos);
293 *_pos = (bucket << shift) | n;
295 if (bucket >= HASH_SIZE(rxnet->peer_hash)) {
304 p = seq_hlist_start_rcu(&rxnet->peer_hash[bucket], n - 1);
310 static void rxrpc_peer_seq_stop(struct seq_file *seq, void *v)
317 const struct seq_operations rxrpc_peer_seq_ops = {
318 .start = rxrpc_peer_seq_start,
319 .next = rxrpc_peer_seq_next,
320 .stop = rxrpc_peer_seq_stop,
321 .show = rxrpc_peer_seq_show,
325 * Generate a list of extant virtual local endpoints in /proc/net/rxrpc/locals
327 static int rxrpc_local_seq_show(struct seq_file *seq, void *v)
329 struct rxrpc_local *local;
332 if (v == SEQ_START_TOKEN) {
339 local = hlist_entry(v, struct rxrpc_local, link);
341 sprintf(lbuff, "%pISpc", &local->srx.transport);
344 "UDP %-47.47s %3u %3u %3u\n",
346 refcount_read(&local->ref),
347 atomic_read(&local->active_users),
348 local->rx_queue.qlen);
353 static void *rxrpc_local_seq_start(struct seq_file *seq, loff_t *_pos)
356 struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
361 if (*_pos >= UINT_MAX)
366 return SEQ_START_TOKEN;
368 return seq_hlist_start_rcu(&rxnet->local_endpoints, n - 1);
371 static void *rxrpc_local_seq_next(struct seq_file *seq, void *v, loff_t *_pos)
373 struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
375 if (*_pos >= UINT_MAX)
378 return seq_hlist_next_rcu(v, &rxnet->local_endpoints, _pos);
381 static void rxrpc_local_seq_stop(struct seq_file *seq, void *v)
387 const struct seq_operations rxrpc_local_seq_ops = {
388 .start = rxrpc_local_seq_start,
389 .next = rxrpc_local_seq_next,
390 .stop = rxrpc_local_seq_stop,
391 .show = rxrpc_local_seq_show,
395 * Display stats in /proc/net/rxrpc/stats
397 int rxrpc_stats_show(struct seq_file *seq, void *v)
399 struct rxrpc_net *rxnet = rxrpc_net(seq_file_single_net(seq));
402 "Data : send=%u sendf=%u fail=%u\n",
403 atomic_read(&rxnet->stat_tx_data_send),
404 atomic_read(&rxnet->stat_tx_data_send_frag),
405 atomic_read(&rxnet->stat_tx_data_send_fail));
407 "Data-Tx : nr=%u retrans=%u uf=%u cwr=%u\n",
408 atomic_read(&rxnet->stat_tx_data),
409 atomic_read(&rxnet->stat_tx_data_retrans),
410 atomic_read(&rxnet->stat_tx_data_underflow),
411 atomic_read(&rxnet->stat_tx_data_cwnd_reset));
413 "Data-Rx : nr=%u reqack=%u jumbo=%u\n",
414 atomic_read(&rxnet->stat_rx_data),
415 atomic_read(&rxnet->stat_rx_data_reqack),
416 atomic_read(&rxnet->stat_rx_data_jumbo));
418 "Ack : fill=%u send=%u skip=%u\n",
419 atomic_read(&rxnet->stat_tx_ack_fill),
420 atomic_read(&rxnet->stat_tx_ack_send),
421 atomic_read(&rxnet->stat_tx_ack_skip));
423 "Ack-Tx : req=%u dup=%u oos=%u exw=%u nos=%u png=%u prs=%u dly=%u idl=%u\n",
424 atomic_read(&rxnet->stat_tx_acks[RXRPC_ACK_REQUESTED]),
425 atomic_read(&rxnet->stat_tx_acks[RXRPC_ACK_DUPLICATE]),
426 atomic_read(&rxnet->stat_tx_acks[RXRPC_ACK_OUT_OF_SEQUENCE]),
427 atomic_read(&rxnet->stat_tx_acks[RXRPC_ACK_EXCEEDS_WINDOW]),
428 atomic_read(&rxnet->stat_tx_acks[RXRPC_ACK_NOSPACE]),
429 atomic_read(&rxnet->stat_tx_acks[RXRPC_ACK_PING]),
430 atomic_read(&rxnet->stat_tx_acks[RXRPC_ACK_PING_RESPONSE]),
431 atomic_read(&rxnet->stat_tx_acks[RXRPC_ACK_DELAY]),
432 atomic_read(&rxnet->stat_tx_acks[RXRPC_ACK_IDLE]));
434 "Ack-Rx : req=%u dup=%u oos=%u exw=%u nos=%u png=%u prs=%u dly=%u idl=%u\n",
435 atomic_read(&rxnet->stat_rx_acks[RXRPC_ACK_REQUESTED]),
436 atomic_read(&rxnet->stat_rx_acks[RXRPC_ACK_DUPLICATE]),
437 atomic_read(&rxnet->stat_rx_acks[RXRPC_ACK_OUT_OF_SEQUENCE]),
438 atomic_read(&rxnet->stat_rx_acks[RXRPC_ACK_EXCEEDS_WINDOW]),
439 atomic_read(&rxnet->stat_rx_acks[RXRPC_ACK_NOSPACE]),
440 atomic_read(&rxnet->stat_rx_acks[RXRPC_ACK_PING]),
441 atomic_read(&rxnet->stat_rx_acks[RXRPC_ACK_PING_RESPONSE]),
442 atomic_read(&rxnet->stat_rx_acks[RXRPC_ACK_DELAY]),
443 atomic_read(&rxnet->stat_rx_acks[RXRPC_ACK_IDLE]));
445 "Why-Req-A: acklost=%u already=%u mrtt=%u ortt=%u\n",
446 atomic_read(&rxnet->stat_why_req_ack[rxrpc_reqack_ack_lost]),
447 atomic_read(&rxnet->stat_why_req_ack[rxrpc_reqack_already_on]),
448 atomic_read(&rxnet->stat_why_req_ack[rxrpc_reqack_more_rtt]),
449 atomic_read(&rxnet->stat_why_req_ack[rxrpc_reqack_old_rtt]));
451 "Why-Req-A: nolast=%u retx=%u slows=%u smtxw=%u\n",
452 atomic_read(&rxnet->stat_why_req_ack[rxrpc_reqack_no_srv_last]),
453 atomic_read(&rxnet->stat_why_req_ack[rxrpc_reqack_retrans]),
454 atomic_read(&rxnet->stat_why_req_ack[rxrpc_reqack_slow_start]),
455 atomic_read(&rxnet->stat_why_req_ack[rxrpc_reqack_small_txwin]));
457 "Buffers : txb=%u rxb=%u\n",
458 atomic_read(&rxrpc_nr_txbuf),
459 atomic_read(&rxrpc_n_rx_skbs));
461 "IO-thread: loops=%u\n",
462 atomic_read(&rxnet->stat_io_loop));
467 * Clear stats if /proc/net/rxrpc/stats is written to.
469 int rxrpc_stats_clear(struct file *file, char *buf, size_t size)
471 struct seq_file *m = file->private_data;
472 struct rxrpc_net *rxnet = rxrpc_net(seq_file_single_net(m));
474 if (size > 1 || (size == 1 && buf[0] != '\n'))
477 atomic_set(&rxnet->stat_tx_data, 0);
478 atomic_set(&rxnet->stat_tx_data_retrans, 0);
479 atomic_set(&rxnet->stat_tx_data_underflow, 0);
480 atomic_set(&rxnet->stat_tx_data_cwnd_reset, 0);
481 atomic_set(&rxnet->stat_tx_data_send, 0);
482 atomic_set(&rxnet->stat_tx_data_send_frag, 0);
483 atomic_set(&rxnet->stat_tx_data_send_fail, 0);
484 atomic_set(&rxnet->stat_rx_data, 0);
485 atomic_set(&rxnet->stat_rx_data_reqack, 0);
486 atomic_set(&rxnet->stat_rx_data_jumbo, 0);
488 atomic_set(&rxnet->stat_tx_ack_fill, 0);
489 atomic_set(&rxnet->stat_tx_ack_send, 0);
490 atomic_set(&rxnet->stat_tx_ack_skip, 0);
491 memset(&rxnet->stat_tx_acks, 0, sizeof(rxnet->stat_tx_acks));
492 memset(&rxnet->stat_rx_acks, 0, sizeof(rxnet->stat_rx_acks));
494 memset(&rxnet->stat_why_req_ack, 0, sizeof(rxnet->stat_why_req_ack));
496 atomic_set(&rxnet->stat_io_loop, 0);