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_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 ",
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 enum rxrpc_call_state state;
55 unsigned long timeout = 0;
56 rxrpc_seq_t acks_hard_ack;
57 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);
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[state],
98 acks_hard_ack, READ_ONCE(call->tx_top) - acks_hard_ack,
99 call->ackr_window, call->ackr_wtop - call->ackr_window,
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));
147 char lbuff[50], rbuff[50];
149 if (v == &rxnet->conn_proc_list) {
153 " SvID ConnID End Ref Act State Key "
154 " Serial ISerial CallId0 CallId1 CallId2 CallId3\n"
159 conn = list_entry(v, struct rxrpc_connection, proc_link);
160 if (conn->state == RXRPC_CONN_SERVICE_PREALLOC) {
161 strcpy(lbuff, "no_local");
162 strcpy(rbuff, "no_connection");
166 sprintf(lbuff, "%pISpc", &conn->local->srx.transport);
167 sprintf(rbuff, "%pISpc", &conn->peer->srx.transport);
169 state = rxrpc_is_conn_aborted(conn) ?
170 rxrpc_call_completions[conn->completion] :
171 rxrpc_conn_states[conn->state];
173 "UDP %-47.47s %-47.47s %4x %08x %s %3u %3d"
174 " %s %08x %08x %08x %08x %08x %08x %08x\n",
179 rxrpc_conn_is_service(conn) ? "Svc" : "Clt",
180 refcount_read(&conn->ref),
181 atomic_read(&conn->active),
183 key_serial(conn->key),
184 atomic_read(&conn->serial),
186 conn->channels[0].call_id,
187 conn->channels[1].call_id,
188 conn->channels[2].call_id,
189 conn->channels[3].call_id);
194 const struct seq_operations rxrpc_connection_seq_ops = {
195 .start = rxrpc_connection_seq_start,
196 .next = rxrpc_connection_seq_next,
197 .stop = rxrpc_connection_seq_stop,
198 .show = rxrpc_connection_seq_show,
202 * generate a list of extant virtual peers in /proc/net/rxrpc/peers
204 static int rxrpc_peer_seq_show(struct seq_file *seq, void *v)
206 struct rxrpc_peer *peer;
208 char lbuff[50], rbuff[50];
210 if (v == SEQ_START_TOKEN) {
214 " Use SST MTU LastUse RTT RTO\n"
219 peer = list_entry(v, struct rxrpc_peer, hash_link);
221 sprintf(lbuff, "%pISpc", &peer->local->srx.transport);
223 sprintf(rbuff, "%pISpc", &peer->srx.transport);
225 now = ktime_get_seconds();
227 "UDP %-47.47s %-47.47s %3u"
228 " %3u %5u %6llus %8u %8u\n",
231 refcount_read(&peer->ref),
234 now - peer->last_tx_at,
236 jiffies_to_usecs(peer->rto_j));
241 static void *rxrpc_peer_seq_start(struct seq_file *seq, loff_t *_pos)
244 struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
245 unsigned int bucket, n;
246 unsigned int shift = 32 - HASH_BITS(rxnet->peer_hash);
251 if (*_pos >= UINT_MAX)
254 n = *_pos & ((1U << shift) - 1);
255 bucket = *_pos >> shift;
257 if (bucket >= HASH_SIZE(rxnet->peer_hash)) {
263 return SEQ_START_TOKEN;
268 p = seq_hlist_start_rcu(&rxnet->peer_hash[bucket], n - 1);
273 *_pos = (bucket << shift) | n;
277 static void *rxrpc_peer_seq_next(struct seq_file *seq, void *v, loff_t *_pos)
279 struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
280 unsigned int bucket, n;
281 unsigned int shift = 32 - HASH_BITS(rxnet->peer_hash);
284 if (*_pos >= UINT_MAX)
287 bucket = *_pos >> shift;
289 p = seq_hlist_next_rcu(v, &rxnet->peer_hash[bucket], _pos);
296 *_pos = (bucket << shift) | n;
298 if (bucket >= HASH_SIZE(rxnet->peer_hash)) {
307 p = seq_hlist_start_rcu(&rxnet->peer_hash[bucket], n - 1);
313 static void rxrpc_peer_seq_stop(struct seq_file *seq, void *v)
320 const struct seq_operations rxrpc_peer_seq_ops = {
321 .start = rxrpc_peer_seq_start,
322 .next = rxrpc_peer_seq_next,
323 .stop = rxrpc_peer_seq_stop,
324 .show = rxrpc_peer_seq_show,
328 * Generate a list of extant virtual local endpoints in /proc/net/rxrpc/locals
330 static int rxrpc_local_seq_show(struct seq_file *seq, void *v)
332 struct rxrpc_local *local;
335 if (v == SEQ_START_TOKEN) {
342 local = hlist_entry(v, struct rxrpc_local, link);
344 sprintf(lbuff, "%pISpc", &local->srx.transport);
347 "UDP %-47.47s %3u %3u %3u\n",
349 refcount_read(&local->ref),
350 atomic_read(&local->active_users),
351 local->rx_queue.qlen);
356 static void *rxrpc_local_seq_start(struct seq_file *seq, loff_t *_pos)
359 struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
364 if (*_pos >= UINT_MAX)
369 return SEQ_START_TOKEN;
371 return seq_hlist_start_rcu(&rxnet->local_endpoints, n - 1);
374 static void *rxrpc_local_seq_next(struct seq_file *seq, void *v, loff_t *_pos)
376 struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
378 if (*_pos >= UINT_MAX)
381 return seq_hlist_next_rcu(v, &rxnet->local_endpoints, _pos);
384 static void rxrpc_local_seq_stop(struct seq_file *seq, void *v)
390 const struct seq_operations rxrpc_local_seq_ops = {
391 .start = rxrpc_local_seq_start,
392 .next = rxrpc_local_seq_next,
393 .stop = rxrpc_local_seq_stop,
394 .show = rxrpc_local_seq_show,
398 * Display stats in /proc/net/rxrpc/stats
400 int rxrpc_stats_show(struct seq_file *seq, void *v)
402 struct rxrpc_net *rxnet = rxrpc_net(seq_file_single_net(seq));
405 "Data : send=%u sendf=%u fail=%u\n",
406 atomic_read(&rxnet->stat_tx_data_send),
407 atomic_read(&rxnet->stat_tx_data_send_frag),
408 atomic_read(&rxnet->stat_tx_data_send_fail));
410 "Data-Tx : nr=%u retrans=%u uf=%u cwr=%u\n",
411 atomic_read(&rxnet->stat_tx_data),
412 atomic_read(&rxnet->stat_tx_data_retrans),
413 atomic_read(&rxnet->stat_tx_data_underflow),
414 atomic_read(&rxnet->stat_tx_data_cwnd_reset));
416 "Data-Rx : nr=%u reqack=%u jumbo=%u\n",
417 atomic_read(&rxnet->stat_rx_data),
418 atomic_read(&rxnet->stat_rx_data_reqack),
419 atomic_read(&rxnet->stat_rx_data_jumbo));
421 "Ack : fill=%u send=%u skip=%u\n",
422 atomic_read(&rxnet->stat_tx_ack_fill),
423 atomic_read(&rxnet->stat_tx_ack_send),
424 atomic_read(&rxnet->stat_tx_ack_skip));
426 "Ack-Tx : req=%u dup=%u oos=%u exw=%u nos=%u png=%u prs=%u dly=%u idl=%u\n",
427 atomic_read(&rxnet->stat_tx_acks[RXRPC_ACK_REQUESTED]),
428 atomic_read(&rxnet->stat_tx_acks[RXRPC_ACK_DUPLICATE]),
429 atomic_read(&rxnet->stat_tx_acks[RXRPC_ACK_OUT_OF_SEQUENCE]),
430 atomic_read(&rxnet->stat_tx_acks[RXRPC_ACK_EXCEEDS_WINDOW]),
431 atomic_read(&rxnet->stat_tx_acks[RXRPC_ACK_NOSPACE]),
432 atomic_read(&rxnet->stat_tx_acks[RXRPC_ACK_PING]),
433 atomic_read(&rxnet->stat_tx_acks[RXRPC_ACK_PING_RESPONSE]),
434 atomic_read(&rxnet->stat_tx_acks[RXRPC_ACK_DELAY]),
435 atomic_read(&rxnet->stat_tx_acks[RXRPC_ACK_IDLE]));
437 "Ack-Rx : req=%u dup=%u oos=%u exw=%u nos=%u png=%u prs=%u dly=%u idl=%u\n",
438 atomic_read(&rxnet->stat_rx_acks[RXRPC_ACK_REQUESTED]),
439 atomic_read(&rxnet->stat_rx_acks[RXRPC_ACK_DUPLICATE]),
440 atomic_read(&rxnet->stat_rx_acks[RXRPC_ACK_OUT_OF_SEQUENCE]),
441 atomic_read(&rxnet->stat_rx_acks[RXRPC_ACK_EXCEEDS_WINDOW]),
442 atomic_read(&rxnet->stat_rx_acks[RXRPC_ACK_NOSPACE]),
443 atomic_read(&rxnet->stat_rx_acks[RXRPC_ACK_PING]),
444 atomic_read(&rxnet->stat_rx_acks[RXRPC_ACK_PING_RESPONSE]),
445 atomic_read(&rxnet->stat_rx_acks[RXRPC_ACK_DELAY]),
446 atomic_read(&rxnet->stat_rx_acks[RXRPC_ACK_IDLE]));
448 "Why-Req-A: acklost=%u already=%u mrtt=%u ortt=%u\n",
449 atomic_read(&rxnet->stat_why_req_ack[rxrpc_reqack_ack_lost]),
450 atomic_read(&rxnet->stat_why_req_ack[rxrpc_reqack_already_on]),
451 atomic_read(&rxnet->stat_why_req_ack[rxrpc_reqack_more_rtt]),
452 atomic_read(&rxnet->stat_why_req_ack[rxrpc_reqack_old_rtt]));
454 "Why-Req-A: nolast=%u retx=%u slows=%u smtxw=%u\n",
455 atomic_read(&rxnet->stat_why_req_ack[rxrpc_reqack_no_srv_last]),
456 atomic_read(&rxnet->stat_why_req_ack[rxrpc_reqack_retrans]),
457 atomic_read(&rxnet->stat_why_req_ack[rxrpc_reqack_slow_start]),
458 atomic_read(&rxnet->stat_why_req_ack[rxrpc_reqack_small_txwin]));
460 "Buffers : txb=%u rxb=%u\n",
461 atomic_read(&rxrpc_nr_txbuf),
462 atomic_read(&rxrpc_n_rx_skbs));
464 "IO-thread: loops=%u\n",
465 atomic_read(&rxnet->stat_io_loop));
470 * Clear stats if /proc/net/rxrpc/stats is written to.
472 int rxrpc_stats_clear(struct file *file, char *buf, size_t size)
474 struct seq_file *m = file->private_data;
475 struct rxrpc_net *rxnet = rxrpc_net(seq_file_single_net(m));
477 if (size > 1 || (size == 1 && buf[0] != '\n'))
480 atomic_set(&rxnet->stat_tx_data, 0);
481 atomic_set(&rxnet->stat_tx_data_retrans, 0);
482 atomic_set(&rxnet->stat_tx_data_underflow, 0);
483 atomic_set(&rxnet->stat_tx_data_cwnd_reset, 0);
484 atomic_set(&rxnet->stat_tx_data_send, 0);
485 atomic_set(&rxnet->stat_tx_data_send_frag, 0);
486 atomic_set(&rxnet->stat_tx_data_send_fail, 0);
487 atomic_set(&rxnet->stat_rx_data, 0);
488 atomic_set(&rxnet->stat_rx_data_reqack, 0);
489 atomic_set(&rxnet->stat_rx_data_jumbo, 0);
491 atomic_set(&rxnet->stat_tx_ack_fill, 0);
492 atomic_set(&rxnet->stat_tx_ack_send, 0);
493 atomic_set(&rxnet->stat_tx_ack_skip, 0);
494 memset(&rxnet->stat_tx_acks, 0, sizeof(rxnet->stat_tx_acks));
495 memset(&rxnet->stat_rx_acks, 0, sizeof(rxnet->stat_rx_acks));
497 memset(&rxnet->stat_why_req_ack, 0, sizeof(rxnet->stat_why_req_ack));
499 atomic_set(&rxnet->stat_io_loop, 0);