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 enum rxrpc_call_state state;
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 state = rxrpc_call_state(call);
79 if (state != RXRPC_CALL_SERVER_PREALLOC) {
80 timeout = READ_ONCE(call->expect_rx_by);
84 acks_hard_ack = READ_ONCE(call->acks_hard_ack);
85 wtmp = atomic64_read_acquire(&call->ackr_window);
87 "UDP %-47.47s %-47.47s %4x %08x %08x %s %3u"
88 " %-8.8s %08x %08x %08x %02x %08x %02x %08x %02x %06lx\n",
91 call->dest_srx.srx_service,
94 rxrpc_is_service_call(call) ? "Svc" : "Clt",
95 refcount_read(&call->ref),
96 rxrpc_call_states[state],
99 acks_hard_ack, READ_ONCE(call->tx_top) - acks_hard_ack,
100 lower_32_bits(wtmp), upper_32_bits(wtmp) - lower_32_bits(wtmp),
108 const struct seq_operations rxrpc_call_seq_ops = {
109 .start = rxrpc_call_seq_start,
110 .next = rxrpc_call_seq_next,
111 .stop = rxrpc_call_seq_stop,
112 .show = rxrpc_call_seq_show,
116 * generate a list of extant virtual connections in /proc/net/rxrpc_conns
118 static void *rxrpc_connection_seq_start(struct seq_file *seq, loff_t *_pos)
119 __acquires(rxnet->conn_lock)
121 struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
123 read_lock(&rxnet->conn_lock);
124 return seq_list_start_head(&rxnet->conn_proc_list, *_pos);
127 static void *rxrpc_connection_seq_next(struct seq_file *seq, void *v,
130 struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
132 return seq_list_next(v, &rxnet->conn_proc_list, pos);
135 static void rxrpc_connection_seq_stop(struct seq_file *seq, void *v)
136 __releases(rxnet->conn_lock)
138 struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
140 read_unlock(&rxnet->conn_lock);
143 static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
145 struct rxrpc_connection *conn;
146 struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
148 char lbuff[50], rbuff[50];
150 if (v == &rxnet->conn_proc_list) {
154 " SvID ConnID End Ref Act State Key "
155 " Serial ISerial CallId0 CallId1 CallId2 CallId3\n"
160 conn = list_entry(v, struct rxrpc_connection, proc_link);
161 if (conn->state == RXRPC_CONN_SERVICE_PREALLOC) {
162 strcpy(lbuff, "no_local");
163 strcpy(rbuff, "no_connection");
167 sprintf(lbuff, "%pISpc", &conn->local->srx.transport);
168 sprintf(rbuff, "%pISpc", &conn->peer->srx.transport);
170 state = rxrpc_is_conn_aborted(conn) ?
171 rxrpc_call_completions[conn->completion] :
172 rxrpc_conn_states[conn->state];
174 "UDP %-47.47s %-47.47s %4x %08x %s %3u %3d"
175 " %s %08x %08x %08x %08x %08x %08x %08x\n",
180 rxrpc_conn_is_service(conn) ? "Svc" : "Clt",
181 refcount_read(&conn->ref),
182 atomic_read(&conn->active),
184 key_serial(conn->key),
185 atomic_read(&conn->serial),
187 conn->channels[0].call_id,
188 conn->channels[1].call_id,
189 conn->channels[2].call_id,
190 conn->channels[3].call_id);
195 const struct seq_operations rxrpc_connection_seq_ops = {
196 .start = rxrpc_connection_seq_start,
197 .next = rxrpc_connection_seq_next,
198 .stop = rxrpc_connection_seq_stop,
199 .show = rxrpc_connection_seq_show,
203 * generate a list of extant virtual peers in /proc/net/rxrpc/peers
205 static int rxrpc_peer_seq_show(struct seq_file *seq, void *v)
207 struct rxrpc_peer *peer;
209 char lbuff[50], rbuff[50];
211 if (v == SEQ_START_TOKEN) {
215 " Use SST MTU LastUse RTT RTO\n"
220 peer = list_entry(v, struct rxrpc_peer, hash_link);
222 sprintf(lbuff, "%pISpc", &peer->local->srx.transport);
224 sprintf(rbuff, "%pISpc", &peer->srx.transport);
226 now = ktime_get_seconds();
228 "UDP %-47.47s %-47.47s %3u"
229 " %3u %5u %6llus %8u %8u\n",
232 refcount_read(&peer->ref),
235 now - peer->last_tx_at,
237 jiffies_to_usecs(peer->rto_j));
242 static void *rxrpc_peer_seq_start(struct seq_file *seq, loff_t *_pos)
245 struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
246 unsigned int bucket, n;
247 unsigned int shift = 32 - HASH_BITS(rxnet->peer_hash);
252 if (*_pos >= UINT_MAX)
255 n = *_pos & ((1U << shift) - 1);
256 bucket = *_pos >> shift;
258 if (bucket >= HASH_SIZE(rxnet->peer_hash)) {
264 return SEQ_START_TOKEN;
269 p = seq_hlist_start_rcu(&rxnet->peer_hash[bucket], n - 1);
274 *_pos = (bucket << shift) | n;
278 static void *rxrpc_peer_seq_next(struct seq_file *seq, void *v, loff_t *_pos)
280 struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
281 unsigned int bucket, n;
282 unsigned int shift = 32 - HASH_BITS(rxnet->peer_hash);
285 if (*_pos >= UINT_MAX)
288 bucket = *_pos >> shift;
290 p = seq_hlist_next_rcu(v, &rxnet->peer_hash[bucket], _pos);
297 *_pos = (bucket << shift) | n;
299 if (bucket >= HASH_SIZE(rxnet->peer_hash)) {
308 p = seq_hlist_start_rcu(&rxnet->peer_hash[bucket], n - 1);
314 static void rxrpc_peer_seq_stop(struct seq_file *seq, void *v)
321 const struct seq_operations rxrpc_peer_seq_ops = {
322 .start = rxrpc_peer_seq_start,
323 .next = rxrpc_peer_seq_next,
324 .stop = rxrpc_peer_seq_stop,
325 .show = rxrpc_peer_seq_show,
329 * Generate a list of extant virtual local endpoints in /proc/net/rxrpc/locals
331 static int rxrpc_local_seq_show(struct seq_file *seq, void *v)
333 struct rxrpc_local *local;
336 if (v == SEQ_START_TOKEN) {
343 local = hlist_entry(v, struct rxrpc_local, link);
345 sprintf(lbuff, "%pISpc", &local->srx.transport);
348 "UDP %-47.47s %3u %3u %3u\n",
350 refcount_read(&local->ref),
351 atomic_read(&local->active_users),
352 local->rx_queue.qlen);
357 static void *rxrpc_local_seq_start(struct seq_file *seq, loff_t *_pos)
360 struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
365 if (*_pos >= UINT_MAX)
370 return SEQ_START_TOKEN;
372 return seq_hlist_start_rcu(&rxnet->local_endpoints, n - 1);
375 static void *rxrpc_local_seq_next(struct seq_file *seq, void *v, loff_t *_pos)
377 struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
379 if (*_pos >= UINT_MAX)
382 return seq_hlist_next_rcu(v, &rxnet->local_endpoints, _pos);
385 static void rxrpc_local_seq_stop(struct seq_file *seq, void *v)
391 const struct seq_operations rxrpc_local_seq_ops = {
392 .start = rxrpc_local_seq_start,
393 .next = rxrpc_local_seq_next,
394 .stop = rxrpc_local_seq_stop,
395 .show = rxrpc_local_seq_show,
399 * Display stats in /proc/net/rxrpc/stats
401 int rxrpc_stats_show(struct seq_file *seq, void *v)
403 struct rxrpc_net *rxnet = rxrpc_net(seq_file_single_net(seq));
406 "Data : send=%u sendf=%u fail=%u\n",
407 atomic_read(&rxnet->stat_tx_data_send),
408 atomic_read(&rxnet->stat_tx_data_send_frag),
409 atomic_read(&rxnet->stat_tx_data_send_fail));
411 "Data-Tx : nr=%u retrans=%u uf=%u cwr=%u\n",
412 atomic_read(&rxnet->stat_tx_data),
413 atomic_read(&rxnet->stat_tx_data_retrans),
414 atomic_read(&rxnet->stat_tx_data_underflow),
415 atomic_read(&rxnet->stat_tx_data_cwnd_reset));
417 "Data-Rx : nr=%u reqack=%u jumbo=%u\n",
418 atomic_read(&rxnet->stat_rx_data),
419 atomic_read(&rxnet->stat_rx_data_reqack),
420 atomic_read(&rxnet->stat_rx_data_jumbo));
422 "Ack : fill=%u send=%u skip=%u\n",
423 atomic_read(&rxnet->stat_tx_ack_fill),
424 atomic_read(&rxnet->stat_tx_ack_send),
425 atomic_read(&rxnet->stat_tx_ack_skip));
427 "Ack-Tx : req=%u dup=%u oos=%u exw=%u nos=%u png=%u prs=%u dly=%u idl=%u\n",
428 atomic_read(&rxnet->stat_tx_acks[RXRPC_ACK_REQUESTED]),
429 atomic_read(&rxnet->stat_tx_acks[RXRPC_ACK_DUPLICATE]),
430 atomic_read(&rxnet->stat_tx_acks[RXRPC_ACK_OUT_OF_SEQUENCE]),
431 atomic_read(&rxnet->stat_tx_acks[RXRPC_ACK_EXCEEDS_WINDOW]),
432 atomic_read(&rxnet->stat_tx_acks[RXRPC_ACK_NOSPACE]),
433 atomic_read(&rxnet->stat_tx_acks[RXRPC_ACK_PING]),
434 atomic_read(&rxnet->stat_tx_acks[RXRPC_ACK_PING_RESPONSE]),
435 atomic_read(&rxnet->stat_tx_acks[RXRPC_ACK_DELAY]),
436 atomic_read(&rxnet->stat_tx_acks[RXRPC_ACK_IDLE]));
438 "Ack-Rx : req=%u dup=%u oos=%u exw=%u nos=%u png=%u prs=%u dly=%u idl=%u\n",
439 atomic_read(&rxnet->stat_rx_acks[RXRPC_ACK_REQUESTED]),
440 atomic_read(&rxnet->stat_rx_acks[RXRPC_ACK_DUPLICATE]),
441 atomic_read(&rxnet->stat_rx_acks[RXRPC_ACK_OUT_OF_SEQUENCE]),
442 atomic_read(&rxnet->stat_rx_acks[RXRPC_ACK_EXCEEDS_WINDOW]),
443 atomic_read(&rxnet->stat_rx_acks[RXRPC_ACK_NOSPACE]),
444 atomic_read(&rxnet->stat_rx_acks[RXRPC_ACK_PING]),
445 atomic_read(&rxnet->stat_rx_acks[RXRPC_ACK_PING_RESPONSE]),
446 atomic_read(&rxnet->stat_rx_acks[RXRPC_ACK_DELAY]),
447 atomic_read(&rxnet->stat_rx_acks[RXRPC_ACK_IDLE]));
449 "Why-Req-A: acklost=%u already=%u mrtt=%u ortt=%u\n",
450 atomic_read(&rxnet->stat_why_req_ack[rxrpc_reqack_ack_lost]),
451 atomic_read(&rxnet->stat_why_req_ack[rxrpc_reqack_already_on]),
452 atomic_read(&rxnet->stat_why_req_ack[rxrpc_reqack_more_rtt]),
453 atomic_read(&rxnet->stat_why_req_ack[rxrpc_reqack_old_rtt]));
455 "Why-Req-A: nolast=%u retx=%u slows=%u smtxw=%u\n",
456 atomic_read(&rxnet->stat_why_req_ack[rxrpc_reqack_no_srv_last]),
457 atomic_read(&rxnet->stat_why_req_ack[rxrpc_reqack_retrans]),
458 atomic_read(&rxnet->stat_why_req_ack[rxrpc_reqack_slow_start]),
459 atomic_read(&rxnet->stat_why_req_ack[rxrpc_reqack_small_txwin]));
461 "Buffers : txb=%u rxb=%u\n",
462 atomic_read(&rxrpc_nr_txbuf),
463 atomic_read(&rxrpc_n_rx_skbs));
465 "IO-thread: loops=%u\n",
466 atomic_read(&rxnet->stat_io_loop));
471 * Clear stats if /proc/net/rxrpc/stats is written to.
473 int rxrpc_stats_clear(struct file *file, char *buf, size_t size)
475 struct seq_file *m = file->private_data;
476 struct rxrpc_net *rxnet = rxrpc_net(seq_file_single_net(m));
478 if (size > 1 || (size == 1 && buf[0] != '\n'))
481 atomic_set(&rxnet->stat_tx_data, 0);
482 atomic_set(&rxnet->stat_tx_data_retrans, 0);
483 atomic_set(&rxnet->stat_tx_data_underflow, 0);
484 atomic_set(&rxnet->stat_tx_data_cwnd_reset, 0);
485 atomic_set(&rxnet->stat_tx_data_send, 0);
486 atomic_set(&rxnet->stat_tx_data_send_frag, 0);
487 atomic_set(&rxnet->stat_tx_data_send_fail, 0);
488 atomic_set(&rxnet->stat_rx_data, 0);
489 atomic_set(&rxnet->stat_rx_data_reqack, 0);
490 atomic_set(&rxnet->stat_rx_data_jumbo, 0);
492 atomic_set(&rxnet->stat_tx_ack_fill, 0);
493 atomic_set(&rxnet->stat_tx_ack_send, 0);
494 atomic_set(&rxnet->stat_tx_ack_skip, 0);
495 memset(&rxnet->stat_tx_acks, 0, sizeof(rxnet->stat_tx_acks));
496 memset(&rxnet->stat_rx_acks, 0, sizeof(rxnet->stat_rx_acks));
498 memset(&rxnet->stat_why_req_ack, 0, sizeof(rxnet->stat_why_req_ack));
500 atomic_set(&rxnet->stat_io_loop, 0);