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_sock *rx;
53 struct rxrpc_peer *peer;
54 struct rxrpc_call *call;
55 struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
56 unsigned long timeout = 0;
57 rxrpc_seq_t acks_hard_ack;
58 char lbuff[50], rbuff[50];
61 if (v == &rxnet->calls) {
65 " SvID ConnID CallID End Use State Abort "
66 " DebugId TxSeq TW RxSeq RW RxSerial RxTimo\n");
70 call = list_entry(v, struct rxrpc_call, link);
72 rx = rcu_dereference(call->socket);
74 local = READ_ONCE(rx->local);
76 sprintf(lbuff, "%pISpc", &local->srx.transport);
78 strcpy(lbuff, "no_local");
80 strcpy(lbuff, "no_socket");
85 sprintf(rbuff, "%pISpc", &peer->srx.transport);
87 strcpy(rbuff, "no_connection");
89 if (call->state != RXRPC_CALL_SERVER_PREALLOC) {
90 timeout = READ_ONCE(call->expect_rx_by);
94 acks_hard_ack = READ_ONCE(call->acks_hard_ack);
95 wtmp = atomic64_read_acquire(&call->ackr_window);
97 "UDP %-47.47s %-47.47s %4x %08x %08x %s %3u"
98 " %-8.8s %08x %08x %08x %02x %08x %02x %08x %06lx\n",
104 rxrpc_is_service_call(call) ? "Svc" : "Clt",
105 refcount_read(&call->ref),
106 rxrpc_call_states[call->state],
109 acks_hard_ack, READ_ONCE(call->tx_top) - acks_hard_ack,
110 lower_32_bits(wtmp), upper_32_bits(wtmp) - lower_32_bits(wtmp),
117 const struct seq_operations rxrpc_call_seq_ops = {
118 .start = rxrpc_call_seq_start,
119 .next = rxrpc_call_seq_next,
120 .stop = rxrpc_call_seq_stop,
121 .show = rxrpc_call_seq_show,
125 * generate a list of extant virtual connections in /proc/net/rxrpc_conns
127 static void *rxrpc_connection_seq_start(struct seq_file *seq, loff_t *_pos)
128 __acquires(rxnet->conn_lock)
130 struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
132 read_lock(&rxnet->conn_lock);
133 return seq_list_start_head(&rxnet->conn_proc_list, *_pos);
136 static void *rxrpc_connection_seq_next(struct seq_file *seq, void *v,
139 struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
141 return seq_list_next(v, &rxnet->conn_proc_list, pos);
144 static void rxrpc_connection_seq_stop(struct seq_file *seq, void *v)
145 __releases(rxnet->conn_lock)
147 struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
149 read_unlock(&rxnet->conn_lock);
152 static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
154 struct rxrpc_connection *conn;
155 struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
156 char lbuff[50], rbuff[50];
158 if (v == &rxnet->conn_proc_list) {
162 " SvID ConnID End Use State Key "
163 " Serial ISerial CallId0 CallId1 CallId2 CallId3\n"
168 conn = list_entry(v, struct rxrpc_connection, proc_link);
169 if (conn->state == RXRPC_CONN_SERVICE_PREALLOC) {
170 strcpy(lbuff, "no_local");
171 strcpy(rbuff, "no_connection");
175 sprintf(lbuff, "%pISpc", &conn->local->srx.transport);
177 sprintf(rbuff, "%pISpc", &conn->peer->srx.transport);
180 "UDP %-47.47s %-47.47s %4x %08x %s %3u"
181 " %s %08x %08x %08x %08x %08x %08x %08x\n",
186 rxrpc_conn_is_service(conn) ? "Svc" : "Clt",
187 refcount_read(&conn->ref),
188 rxrpc_conn_states[conn->state],
189 key_serial(conn->key),
190 atomic_read(&conn->serial),
192 conn->channels[0].call_id,
193 conn->channels[1].call_id,
194 conn->channels[2].call_id,
195 conn->channels[3].call_id);
200 const struct seq_operations rxrpc_connection_seq_ops = {
201 .start = rxrpc_connection_seq_start,
202 .next = rxrpc_connection_seq_next,
203 .stop = rxrpc_connection_seq_stop,
204 .show = rxrpc_connection_seq_show,
208 * generate a list of extant virtual peers in /proc/net/rxrpc/peers
210 static int rxrpc_peer_seq_show(struct seq_file *seq, void *v)
212 struct rxrpc_peer *peer;
214 char lbuff[50], rbuff[50];
216 if (v == SEQ_START_TOKEN) {
220 " Use SST MTU LastUse RTT RTO\n"
225 peer = list_entry(v, struct rxrpc_peer, hash_link);
227 sprintf(lbuff, "%pISpc", &peer->local->srx.transport);
229 sprintf(rbuff, "%pISpc", &peer->srx.transport);
231 now = ktime_get_seconds();
233 "UDP %-47.47s %-47.47s %3u"
234 " %3u %5u %6llus %8u %8u\n",
237 refcount_read(&peer->ref),
240 now - peer->last_tx_at,
242 jiffies_to_usecs(peer->rto_j));
247 static void *rxrpc_peer_seq_start(struct seq_file *seq, loff_t *_pos)
250 struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
251 unsigned int bucket, n;
252 unsigned int shift = 32 - HASH_BITS(rxnet->peer_hash);
257 if (*_pos >= UINT_MAX)
260 n = *_pos & ((1U << shift) - 1);
261 bucket = *_pos >> shift;
263 if (bucket >= HASH_SIZE(rxnet->peer_hash)) {
269 return SEQ_START_TOKEN;
274 p = seq_hlist_start_rcu(&rxnet->peer_hash[bucket], n - 1);
279 *_pos = (bucket << shift) | n;
283 static void *rxrpc_peer_seq_next(struct seq_file *seq, void *v, loff_t *_pos)
285 struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
286 unsigned int bucket, n;
287 unsigned int shift = 32 - HASH_BITS(rxnet->peer_hash);
290 if (*_pos >= UINT_MAX)
293 bucket = *_pos >> shift;
295 p = seq_hlist_next_rcu(v, &rxnet->peer_hash[bucket], _pos);
302 *_pos = (bucket << shift) | n;
304 if (bucket >= HASH_SIZE(rxnet->peer_hash)) {
313 p = seq_hlist_start_rcu(&rxnet->peer_hash[bucket], n - 1);
319 static void rxrpc_peer_seq_stop(struct seq_file *seq, void *v)
326 const struct seq_operations rxrpc_peer_seq_ops = {
327 .start = rxrpc_peer_seq_start,
328 .next = rxrpc_peer_seq_next,
329 .stop = rxrpc_peer_seq_stop,
330 .show = rxrpc_peer_seq_show,
334 * Generate a list of extant virtual local endpoints in /proc/net/rxrpc/locals
336 static int rxrpc_local_seq_show(struct seq_file *seq, void *v)
338 struct rxrpc_local *local;
341 if (v == SEQ_START_TOKEN) {
348 local = hlist_entry(v, struct rxrpc_local, link);
350 sprintf(lbuff, "%pISpc", &local->srx.transport);
353 "UDP %-47.47s %3u %3u\n",
355 refcount_read(&local->ref),
356 atomic_read(&local->active_users));
361 static void *rxrpc_local_seq_start(struct seq_file *seq, loff_t *_pos)
364 struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
369 if (*_pos >= UINT_MAX)
374 return SEQ_START_TOKEN;
376 return seq_hlist_start_rcu(&rxnet->local_endpoints, n - 1);
379 static void *rxrpc_local_seq_next(struct seq_file *seq, void *v, loff_t *_pos)
381 struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
383 if (*_pos >= UINT_MAX)
386 return seq_hlist_next_rcu(v, &rxnet->local_endpoints, _pos);
389 static void rxrpc_local_seq_stop(struct seq_file *seq, void *v)
395 const struct seq_operations rxrpc_local_seq_ops = {
396 .start = rxrpc_local_seq_start,
397 .next = rxrpc_local_seq_next,
398 .stop = rxrpc_local_seq_stop,
399 .show = rxrpc_local_seq_show,
403 * Display stats in /proc/net/rxrpc/stats
405 int rxrpc_stats_show(struct seq_file *seq, void *v)
407 struct rxrpc_net *rxnet = rxrpc_net(seq_file_single_net(seq));
410 "Data : send=%u sendf=%u\n",
411 atomic_read(&rxnet->stat_tx_data_send),
412 atomic_read(&rxnet->stat_tx_data_send_frag));
414 "Data-Tx : nr=%u retrans=%u\n",
415 atomic_read(&rxnet->stat_tx_data),
416 atomic_read(&rxnet->stat_tx_data_retrans));
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));
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));
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]));
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]));
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]));
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]));
462 "Buffers : txb=%u rxb=%u\n",
463 atomic_read(&rxrpc_nr_txbuf),
464 atomic_read(&rxrpc_n_rx_skbs));
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_send, 0);
482 atomic_set(&rxnet->stat_tx_data_send_frag, 0);
483 atomic_set(&rxnet->stat_rx_data, 0);
484 atomic_set(&rxnet->stat_rx_data_reqack, 0);
485 atomic_set(&rxnet->stat_rx_data_jumbo, 0);
487 atomic_set(&rxnet->stat_tx_ack_fill, 0);
488 atomic_set(&rxnet->stat_tx_ack_send, 0);
489 atomic_set(&rxnet->stat_tx_ack_skip, 0);
490 memset(&rxnet->stat_tx_acks, 0, sizeof(rxnet->stat_tx_acks));
491 memset(&rxnet->stat_rx_acks, 0, sizeof(rxnet->stat_rx_acks));
493 memset(&rxnet->stat_why_req_ack, 0, sizeof(rxnet->stat_why_req_ack));