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_ABORTED] = "Aborted ",
24 * generate a list of extant and dead calls in /proc/net/rxrpc_calls
26 static void *rxrpc_call_seq_start(struct seq_file *seq, loff_t *_pos)
29 struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
32 return seq_list_start_head_rcu(&rxnet->calls, *_pos);
35 static void *rxrpc_call_seq_next(struct seq_file *seq, void *v, loff_t *pos)
37 struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
39 return seq_list_next_rcu(v, &rxnet->calls, pos);
42 static void rxrpc_call_seq_stop(struct seq_file *seq, void *v)
48 static int rxrpc_call_seq_show(struct seq_file *seq, void *v)
50 struct rxrpc_local *local;
51 struct rxrpc_call *call;
52 struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
53 unsigned long timeout = 0;
54 rxrpc_seq_t acks_hard_ack;
55 char lbuff[50], rbuff[50];
58 if (v == &rxnet->calls) {
62 " SvID ConnID CallID End Use State Abort "
63 " DebugId TxSeq TW RxSeq RW RxSerial CW RxTimo\n");
67 call = list_entry(v, struct rxrpc_call, link);
71 sprintf(lbuff, "%pISpc", &local->srx.transport);
73 strcpy(lbuff, "no_local");
75 sprintf(rbuff, "%pISpc", &call->dest_srx.transport);
77 if (call->state != RXRPC_CALL_SERVER_PREALLOC) {
78 timeout = READ_ONCE(call->expect_rx_by);
82 acks_hard_ack = READ_ONCE(call->acks_hard_ack);
83 wtmp = atomic64_read_acquire(&call->ackr_window);
85 "UDP %-47.47s %-47.47s %4x %08x %08x %s %3u"
86 " %-8.8s %08x %08x %08x %02x %08x %02x %08x %02x %06lx\n",
89 call->dest_srx.srx_service,
92 rxrpc_is_service_call(call) ? "Svc" : "Clt",
93 refcount_read(&call->ref),
94 rxrpc_call_states[call->state],
97 acks_hard_ack, READ_ONCE(call->tx_top) - acks_hard_ack,
98 lower_32_bits(wtmp), upper_32_bits(wtmp) - lower_32_bits(wtmp),
106 const struct seq_operations rxrpc_call_seq_ops = {
107 .start = rxrpc_call_seq_start,
108 .next = rxrpc_call_seq_next,
109 .stop = rxrpc_call_seq_stop,
110 .show = rxrpc_call_seq_show,
114 * generate a list of extant virtual connections in /proc/net/rxrpc_conns
116 static void *rxrpc_connection_seq_start(struct seq_file *seq, loff_t *_pos)
117 __acquires(rxnet->conn_lock)
119 struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
121 read_lock(&rxnet->conn_lock);
122 return seq_list_start_head(&rxnet->conn_proc_list, *_pos);
125 static void *rxrpc_connection_seq_next(struct seq_file *seq, void *v,
128 struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
130 return seq_list_next(v, &rxnet->conn_proc_list, pos);
133 static void rxrpc_connection_seq_stop(struct seq_file *seq, void *v)
134 __releases(rxnet->conn_lock)
136 struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
138 read_unlock(&rxnet->conn_lock);
141 static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
143 struct rxrpc_connection *conn;
144 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);
166 sprintf(rbuff, "%pISpc", &conn->peer->srx.transport);
168 state = rxrpc_is_conn_aborted(conn) ?
169 rxrpc_call_completions[conn->completion] :
170 rxrpc_conn_states[conn->state];
172 "UDP %-47.47s %-47.47s %4x %08x %s %3u %3d"
173 " %s %08x %08x %08x %08x %08x %08x %08x\n",
178 rxrpc_conn_is_service(conn) ? "Svc" : "Clt",
179 refcount_read(&conn->ref),
180 atomic_read(&conn->active),
182 key_serial(conn->key),
183 atomic_read(&conn->serial),
185 conn->channels[0].call_id,
186 conn->channels[1].call_id,
187 conn->channels[2].call_id,
188 conn->channels[3].call_id);
193 const struct seq_operations rxrpc_connection_seq_ops = {
194 .start = rxrpc_connection_seq_start,
195 .next = rxrpc_connection_seq_next,
196 .stop = rxrpc_connection_seq_stop,
197 .show = rxrpc_connection_seq_show,
201 * generate a list of extant virtual peers in /proc/net/rxrpc/peers
203 static int rxrpc_peer_seq_show(struct seq_file *seq, void *v)
205 struct rxrpc_peer *peer;
207 char lbuff[50], rbuff[50];
209 if (v == SEQ_START_TOKEN) {
213 " Use SST MTU LastUse RTT RTO\n"
218 peer = list_entry(v, struct rxrpc_peer, hash_link);
220 sprintf(lbuff, "%pISpc", &peer->local->srx.transport);
222 sprintf(rbuff, "%pISpc", &peer->srx.transport);
224 now = ktime_get_seconds();
226 "UDP %-47.47s %-47.47s %3u"
227 " %3u %5u %6llus %8u %8u\n",
230 refcount_read(&peer->ref),
233 now - peer->last_tx_at,
235 jiffies_to_usecs(peer->rto_j));
240 static void *rxrpc_peer_seq_start(struct seq_file *seq, loff_t *_pos)
243 struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
244 unsigned int bucket, n;
245 unsigned int shift = 32 - HASH_BITS(rxnet->peer_hash);
250 if (*_pos >= UINT_MAX)
253 n = *_pos & ((1U << shift) - 1);
254 bucket = *_pos >> shift;
256 if (bucket >= HASH_SIZE(rxnet->peer_hash)) {
262 return SEQ_START_TOKEN;
267 p = seq_hlist_start_rcu(&rxnet->peer_hash[bucket], n - 1);
272 *_pos = (bucket << shift) | n;
276 static void *rxrpc_peer_seq_next(struct seq_file *seq, void *v, loff_t *_pos)
278 struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
279 unsigned int bucket, n;
280 unsigned int shift = 32 - HASH_BITS(rxnet->peer_hash);
283 if (*_pos >= UINT_MAX)
286 bucket = *_pos >> shift;
288 p = seq_hlist_next_rcu(v, &rxnet->peer_hash[bucket], _pos);
295 *_pos = (bucket << shift) | n;
297 if (bucket >= HASH_SIZE(rxnet->peer_hash)) {
306 p = seq_hlist_start_rcu(&rxnet->peer_hash[bucket], n - 1);
312 static void rxrpc_peer_seq_stop(struct seq_file *seq, void *v)
319 const struct seq_operations rxrpc_peer_seq_ops = {
320 .start = rxrpc_peer_seq_start,
321 .next = rxrpc_peer_seq_next,
322 .stop = rxrpc_peer_seq_stop,
323 .show = rxrpc_peer_seq_show,
327 * Generate a list of extant virtual local endpoints in /proc/net/rxrpc/locals
329 static int rxrpc_local_seq_show(struct seq_file *seq, void *v)
331 struct rxrpc_local *local;
334 if (v == SEQ_START_TOKEN) {
341 local = hlist_entry(v, struct rxrpc_local, link);
343 sprintf(lbuff, "%pISpc", &local->srx.transport);
346 "UDP %-47.47s %3u %3u %3u\n",
348 refcount_read(&local->ref),
349 atomic_read(&local->active_users),
350 local->rx_queue.qlen);
355 static void *rxrpc_local_seq_start(struct seq_file *seq, loff_t *_pos)
358 struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
363 if (*_pos >= UINT_MAX)
368 return SEQ_START_TOKEN;
370 return seq_hlist_start_rcu(&rxnet->local_endpoints, n - 1);
373 static void *rxrpc_local_seq_next(struct seq_file *seq, void *v, loff_t *_pos)
375 struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
377 if (*_pos >= UINT_MAX)
380 return seq_hlist_next_rcu(v, &rxnet->local_endpoints, _pos);
383 static void rxrpc_local_seq_stop(struct seq_file *seq, void *v)
389 const struct seq_operations rxrpc_local_seq_ops = {
390 .start = rxrpc_local_seq_start,
391 .next = rxrpc_local_seq_next,
392 .stop = rxrpc_local_seq_stop,
393 .show = rxrpc_local_seq_show,
397 * Display stats in /proc/net/rxrpc/stats
399 int rxrpc_stats_show(struct seq_file *seq, void *v)
401 struct rxrpc_net *rxnet = rxrpc_net(seq_file_single_net(seq));
404 "Data : send=%u sendf=%u fail=%u\n",
405 atomic_read(&rxnet->stat_tx_data_send),
406 atomic_read(&rxnet->stat_tx_data_send_frag),
407 atomic_read(&rxnet->stat_tx_data_send_fail));
409 "Data-Tx : nr=%u retrans=%u uf=%u cwr=%u\n",
410 atomic_read(&rxnet->stat_tx_data),
411 atomic_read(&rxnet->stat_tx_data_retrans),
412 atomic_read(&rxnet->stat_tx_data_underflow),
413 atomic_read(&rxnet->stat_tx_data_cwnd_reset));
415 "Data-Rx : nr=%u reqack=%u jumbo=%u\n",
416 atomic_read(&rxnet->stat_rx_data),
417 atomic_read(&rxnet->stat_rx_data_reqack),
418 atomic_read(&rxnet->stat_rx_data_jumbo));
420 "Ack : fill=%u send=%u skip=%u\n",
421 atomic_read(&rxnet->stat_tx_ack_fill),
422 atomic_read(&rxnet->stat_tx_ack_send),
423 atomic_read(&rxnet->stat_tx_ack_skip));
425 "Ack-Tx : req=%u dup=%u oos=%u exw=%u nos=%u png=%u prs=%u dly=%u idl=%u\n",
426 atomic_read(&rxnet->stat_tx_acks[RXRPC_ACK_REQUESTED]),
427 atomic_read(&rxnet->stat_tx_acks[RXRPC_ACK_DUPLICATE]),
428 atomic_read(&rxnet->stat_tx_acks[RXRPC_ACK_OUT_OF_SEQUENCE]),
429 atomic_read(&rxnet->stat_tx_acks[RXRPC_ACK_EXCEEDS_WINDOW]),
430 atomic_read(&rxnet->stat_tx_acks[RXRPC_ACK_NOSPACE]),
431 atomic_read(&rxnet->stat_tx_acks[RXRPC_ACK_PING]),
432 atomic_read(&rxnet->stat_tx_acks[RXRPC_ACK_PING_RESPONSE]),
433 atomic_read(&rxnet->stat_tx_acks[RXRPC_ACK_DELAY]),
434 atomic_read(&rxnet->stat_tx_acks[RXRPC_ACK_IDLE]));
436 "Ack-Rx : req=%u dup=%u oos=%u exw=%u nos=%u png=%u prs=%u dly=%u idl=%u\n",
437 atomic_read(&rxnet->stat_rx_acks[RXRPC_ACK_REQUESTED]),
438 atomic_read(&rxnet->stat_rx_acks[RXRPC_ACK_DUPLICATE]),
439 atomic_read(&rxnet->stat_rx_acks[RXRPC_ACK_OUT_OF_SEQUENCE]),
440 atomic_read(&rxnet->stat_rx_acks[RXRPC_ACK_EXCEEDS_WINDOW]),
441 atomic_read(&rxnet->stat_rx_acks[RXRPC_ACK_NOSPACE]),
442 atomic_read(&rxnet->stat_rx_acks[RXRPC_ACK_PING]),
443 atomic_read(&rxnet->stat_rx_acks[RXRPC_ACK_PING_RESPONSE]),
444 atomic_read(&rxnet->stat_rx_acks[RXRPC_ACK_DELAY]),
445 atomic_read(&rxnet->stat_rx_acks[RXRPC_ACK_IDLE]));
447 "Why-Req-A: acklost=%u already=%u mrtt=%u ortt=%u\n",
448 atomic_read(&rxnet->stat_why_req_ack[rxrpc_reqack_ack_lost]),
449 atomic_read(&rxnet->stat_why_req_ack[rxrpc_reqack_already_on]),
450 atomic_read(&rxnet->stat_why_req_ack[rxrpc_reqack_more_rtt]),
451 atomic_read(&rxnet->stat_why_req_ack[rxrpc_reqack_old_rtt]));
453 "Why-Req-A: nolast=%u retx=%u slows=%u smtxw=%u\n",
454 atomic_read(&rxnet->stat_why_req_ack[rxrpc_reqack_no_srv_last]),
455 atomic_read(&rxnet->stat_why_req_ack[rxrpc_reqack_retrans]),
456 atomic_read(&rxnet->stat_why_req_ack[rxrpc_reqack_slow_start]),
457 atomic_read(&rxnet->stat_why_req_ack[rxrpc_reqack_small_txwin]));
459 "Buffers : txb=%u rxb=%u\n",
460 atomic_read(&rxrpc_nr_txbuf),
461 atomic_read(&rxrpc_n_rx_skbs));
463 "IO-thread: loops=%u\n",
464 atomic_read(&rxnet->stat_io_loop));
469 * Clear stats if /proc/net/rxrpc/stats is written to.
471 int rxrpc_stats_clear(struct file *file, char *buf, size_t size)
473 struct seq_file *m = file->private_data;
474 struct rxrpc_net *rxnet = rxrpc_net(seq_file_single_net(m));
476 if (size > 1 || (size == 1 && buf[0] != '\n'))
479 atomic_set(&rxnet->stat_tx_data, 0);
480 atomic_set(&rxnet->stat_tx_data_retrans, 0);
481 atomic_set(&rxnet->stat_tx_data_underflow, 0);
482 atomic_set(&rxnet->stat_tx_data_cwnd_reset, 0);
483 atomic_set(&rxnet->stat_tx_data_send, 0);
484 atomic_set(&rxnet->stat_tx_data_send_frag, 0);
485 atomic_set(&rxnet->stat_tx_data_send_fail, 0);
486 atomic_set(&rxnet->stat_rx_data, 0);
487 atomic_set(&rxnet->stat_rx_data_reqack, 0);
488 atomic_set(&rxnet->stat_rx_data_jumbo, 0);
490 atomic_set(&rxnet->stat_tx_ack_fill, 0);
491 atomic_set(&rxnet->stat_tx_ack_send, 0);
492 atomic_set(&rxnet->stat_tx_ack_skip, 0);
493 memset(&rxnet->stat_tx_acks, 0, sizeof(rxnet->stat_tx_acks));
494 memset(&rxnet->stat_rx_acks, 0, sizeof(rxnet->stat_rx_acks));
496 memset(&rxnet->stat_why_req_ack, 0, sizeof(rxnet->stat_why_req_ack));
498 atomic_set(&rxnet->stat_io_loop, 0);