18c3e34a4SDavid Howells /* /proc/net/ support for AF_RXRPC 28c3e34a4SDavid Howells * 38c3e34a4SDavid Howells * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved. 48c3e34a4SDavid Howells * Written by David Howells (dhowells@redhat.com) 58c3e34a4SDavid Howells * 68c3e34a4SDavid Howells * This program is free software; you can redistribute it and/or 78c3e34a4SDavid Howells * modify it under the terms of the GNU General Public License 88c3e34a4SDavid Howells * as published by the Free Software Foundation; either version 98c3e34a4SDavid Howells * 2 of the License, or (at your option) any later version. 108c3e34a4SDavid Howells */ 118c3e34a4SDavid Howells 128c3e34a4SDavid Howells #include <linux/module.h> 138c3e34a4SDavid Howells #include <net/sock.h> 148c3e34a4SDavid Howells #include <net/af_rxrpc.h> 158c3e34a4SDavid Howells #include "ar-internal.h" 168c3e34a4SDavid Howells 17bba304dbSDavid Howells static const char *const rxrpc_conn_states[RXRPC_CONN__NR_STATES] = { 188c3e34a4SDavid Howells [RXRPC_CONN_UNUSED] = "Unused ", 198c3e34a4SDavid Howells [RXRPC_CONN_CLIENT] = "Client ", 2000e90712SDavid Howells [RXRPC_CONN_SERVICE_PREALLOC] = "SvPrealc", 21bba304dbSDavid Howells [RXRPC_CONN_SERVICE_UNSECURED] = "SvUnsec ", 22bba304dbSDavid Howells [RXRPC_CONN_SERVICE_CHALLENGING] = "SvChall ", 23bba304dbSDavid Howells [RXRPC_CONN_SERVICE] = "SvSecure", 248c3e34a4SDavid Howells [RXRPC_CONN_REMOTELY_ABORTED] = "RmtAbort", 258c3e34a4SDavid Howells [RXRPC_CONN_LOCALLY_ABORTED] = "LocAbort", 268c3e34a4SDavid Howells }; 278c3e34a4SDavid Howells 288c3e34a4SDavid Howells /* 298c3e34a4SDavid Howells * generate a list of extant and dead calls in /proc/net/rxrpc_calls 308c3e34a4SDavid Howells */ 318c3e34a4SDavid Howells static void *rxrpc_call_seq_start(struct seq_file *seq, loff_t *_pos) 328c3e34a4SDavid Howells { 332baec2c3SDavid Howells struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq)); 342baec2c3SDavid Howells 358d94aa38SDavid Howells rcu_read_lock(); 362baec2c3SDavid Howells read_lock(&rxnet->call_lock); 372baec2c3SDavid Howells return seq_list_start_head(&rxnet->calls, *_pos); 388c3e34a4SDavid Howells } 398c3e34a4SDavid Howells 408c3e34a4SDavid Howells static void *rxrpc_call_seq_next(struct seq_file *seq, void *v, loff_t *pos) 418c3e34a4SDavid Howells { 422baec2c3SDavid Howells struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq)); 432baec2c3SDavid Howells 442baec2c3SDavid Howells return seq_list_next(v, &rxnet->calls, pos); 458c3e34a4SDavid Howells } 468c3e34a4SDavid Howells 478c3e34a4SDavid Howells static void rxrpc_call_seq_stop(struct seq_file *seq, void *v) 488c3e34a4SDavid Howells { 492baec2c3SDavid Howells struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq)); 502baec2c3SDavid Howells 512baec2c3SDavid Howells read_unlock(&rxnet->call_lock); 528d94aa38SDavid Howells rcu_read_unlock(); 538c3e34a4SDavid Howells } 548c3e34a4SDavid Howells 558c3e34a4SDavid Howells static int rxrpc_call_seq_show(struct seq_file *seq, void *v) 568c3e34a4SDavid Howells { 57df5d8bf7SDavid Howells struct rxrpc_local *local; 58df5d8bf7SDavid Howells struct rxrpc_sock *rx; 59df5d8bf7SDavid Howells struct rxrpc_peer *peer; 608c3e34a4SDavid Howells struct rxrpc_call *call; 612baec2c3SDavid Howells struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq)); 623e018dafSDavid Howells rxrpc_seq_t tx_hard_ack, rx_hard_ack; 6375b54cb5SDavid Howells char lbuff[50], rbuff[50]; 648c3e34a4SDavid Howells 652baec2c3SDavid Howells if (v == &rxnet->calls) { 668c3e34a4SDavid Howells seq_puts(seq, 6775b54cb5SDavid Howells "Proto Local " 6875b54cb5SDavid Howells " Remote " 698c3e34a4SDavid Howells " SvID ConnID CallID End Use State Abort " 708c3e34a4SDavid Howells " UserID\n"); 718c3e34a4SDavid Howells return 0; 728c3e34a4SDavid Howells } 738c3e34a4SDavid Howells 748c3e34a4SDavid Howells call = list_entry(v, struct rxrpc_call, link); 758c3e34a4SDavid Howells 768d94aa38SDavid Howells rx = rcu_dereference(call->socket); 77df5d8bf7SDavid Howells if (rx) { 78df5d8bf7SDavid Howells local = READ_ONCE(rx->local); 79df5d8bf7SDavid Howells if (local) 8075b54cb5SDavid Howells sprintf(lbuff, "%pISpc", &local->srx.transport); 81df5d8bf7SDavid Howells else 82df5d8bf7SDavid Howells strcpy(lbuff, "no_local"); 83df5d8bf7SDavid Howells } else { 84df5d8bf7SDavid Howells strcpy(lbuff, "no_socket"); 85df5d8bf7SDavid Howells } 868c3e34a4SDavid Howells 87df5d8bf7SDavid Howells peer = call->peer; 88df5d8bf7SDavid Howells if (peer) 8975b54cb5SDavid Howells sprintf(rbuff, "%pISpc", &peer->srx.transport); 90f4e7da8cSDavid Howells else 91f4e7da8cSDavid Howells strcpy(rbuff, "no_connection"); 928c3e34a4SDavid Howells 933e018dafSDavid Howells tx_hard_ack = READ_ONCE(call->tx_hard_ack); 943e018dafSDavid Howells rx_hard_ack = READ_ONCE(call->rx_hard_ack); 958c3e34a4SDavid Howells seq_printf(seq, 9675b54cb5SDavid Howells "UDP %-47.47s %-47.47s %4x %08x %08x %s %3u" 973e018dafSDavid Howells " %-8.8s %08x %lx %08x %02x %08x %02x\n", 988c3e34a4SDavid Howells lbuff, 998c3e34a4SDavid Howells rbuff, 100f4e7da8cSDavid Howells call->service_id, 1018c3e34a4SDavid Howells call->cid, 1028c3e34a4SDavid Howells call->call_id, 103dabe5a79SDavid Howells rxrpc_is_service_call(call) ? "Svc" : "Clt", 1048c3e34a4SDavid Howells atomic_read(&call->usage), 1058c3e34a4SDavid Howells rxrpc_call_states[call->state], 106f5c17aaeSDavid Howells call->abort_code, 1073e018dafSDavid Howells call->user_call_ID, 1083e018dafSDavid Howells tx_hard_ack, READ_ONCE(call->tx_top) - tx_hard_ack, 1093e018dafSDavid Howells rx_hard_ack, READ_ONCE(call->rx_top) - rx_hard_ack); 1108c3e34a4SDavid Howells 1118c3e34a4SDavid Howells return 0; 1128c3e34a4SDavid Howells } 1138c3e34a4SDavid Howells 1148c3e34a4SDavid Howells static const struct seq_operations rxrpc_call_seq_ops = { 1158c3e34a4SDavid Howells .start = rxrpc_call_seq_start, 1168c3e34a4SDavid Howells .next = rxrpc_call_seq_next, 1178c3e34a4SDavid Howells .stop = rxrpc_call_seq_stop, 1188c3e34a4SDavid Howells .show = rxrpc_call_seq_show, 1198c3e34a4SDavid Howells }; 1208c3e34a4SDavid Howells 1218c3e34a4SDavid Howells static int rxrpc_call_seq_open(struct inode *inode, struct file *file) 1228c3e34a4SDavid Howells { 1232baec2c3SDavid Howells return seq_open_net(inode, file, &rxrpc_call_seq_ops, 1242baec2c3SDavid Howells sizeof(struct seq_net_private)); 1258c3e34a4SDavid Howells } 1268c3e34a4SDavid Howells 1278c3e34a4SDavid Howells const struct file_operations rxrpc_call_seq_fops = { 1288c3e34a4SDavid Howells .owner = THIS_MODULE, 1298c3e34a4SDavid Howells .open = rxrpc_call_seq_open, 1308c3e34a4SDavid Howells .read = seq_read, 1318c3e34a4SDavid Howells .llseek = seq_lseek, 1328c3e34a4SDavid Howells .release = seq_release, 1338c3e34a4SDavid Howells }; 1348c3e34a4SDavid Howells 1358c3e34a4SDavid Howells /* 1368c3e34a4SDavid Howells * generate a list of extant virtual connections in /proc/net/rxrpc_conns 1378c3e34a4SDavid Howells */ 1388c3e34a4SDavid Howells static void *rxrpc_connection_seq_start(struct seq_file *seq, loff_t *_pos) 1398c3e34a4SDavid Howells { 1402baec2c3SDavid Howells struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq)); 1412baec2c3SDavid Howells 1422baec2c3SDavid Howells read_lock(&rxnet->conn_lock); 1432baec2c3SDavid Howells return seq_list_start_head(&rxnet->conn_proc_list, *_pos); 1448c3e34a4SDavid Howells } 1458c3e34a4SDavid Howells 1468c3e34a4SDavid Howells static void *rxrpc_connection_seq_next(struct seq_file *seq, void *v, 1478c3e34a4SDavid Howells loff_t *pos) 1488c3e34a4SDavid Howells { 1492baec2c3SDavid Howells struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq)); 1502baec2c3SDavid Howells 1512baec2c3SDavid Howells return seq_list_next(v, &rxnet->conn_proc_list, pos); 1528c3e34a4SDavid Howells } 1538c3e34a4SDavid Howells 1548c3e34a4SDavid Howells static void rxrpc_connection_seq_stop(struct seq_file *seq, void *v) 1558c3e34a4SDavid Howells { 1562baec2c3SDavid Howells struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq)); 1572baec2c3SDavid Howells 1582baec2c3SDavid Howells read_unlock(&rxnet->conn_lock); 1598c3e34a4SDavid Howells } 1608c3e34a4SDavid Howells 1618c3e34a4SDavid Howells static int rxrpc_connection_seq_show(struct seq_file *seq, void *v) 1628c3e34a4SDavid Howells { 1638c3e34a4SDavid Howells struct rxrpc_connection *conn; 1642baec2c3SDavid Howells struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq)); 16575b54cb5SDavid Howells char lbuff[50], rbuff[50]; 1668c3e34a4SDavid Howells 1672baec2c3SDavid Howells if (v == &rxnet->conn_proc_list) { 1688c3e34a4SDavid Howells seq_puts(seq, 16975b54cb5SDavid Howells "Proto Local " 17075b54cb5SDavid Howells " Remote " 171a1399f8bSDavid Howells " SvID ConnID End Use State Key " 1728c3e34a4SDavid Howells " Serial ISerial\n" 1738c3e34a4SDavid Howells ); 1748c3e34a4SDavid Howells return 0; 1758c3e34a4SDavid Howells } 1768c3e34a4SDavid Howells 1774d028b2cSDavid Howells conn = list_entry(v, struct rxrpc_connection, proc_link); 17800e90712SDavid Howells if (conn->state == RXRPC_CONN_SERVICE_PREALLOC) { 17900e90712SDavid Howells strcpy(lbuff, "no_local"); 18000e90712SDavid Howells strcpy(rbuff, "no_connection"); 18100e90712SDavid Howells goto print; 18200e90712SDavid Howells } 1838c3e34a4SDavid Howells 18475b54cb5SDavid Howells sprintf(lbuff, "%pISpc", &conn->params.local->srx.transport); 1858c3e34a4SDavid Howells 18675b54cb5SDavid Howells sprintf(rbuff, "%pISpc", &conn->params.peer->srx.transport); 18700e90712SDavid Howells print: 1888c3e34a4SDavid Howells seq_printf(seq, 18975b54cb5SDavid Howells "UDP %-47.47s %-47.47s %4x %08x %s %3u" 1908c3e34a4SDavid Howells " %s %08x %08x %08x\n", 1918c3e34a4SDavid Howells lbuff, 1928c3e34a4SDavid Howells rbuff, 19368d6d1aeSDavid Howells conn->service_id, 19419ffa01cSDavid Howells conn->proto.cid, 19519ffa01cSDavid Howells rxrpc_conn_is_service(conn) ? "Svc" : "Clt", 1968c3e34a4SDavid Howells atomic_read(&conn->usage), 1978c3e34a4SDavid Howells rxrpc_conn_states[conn->state], 19819ffa01cSDavid Howells key_serial(conn->params.key), 1998c3e34a4SDavid Howells atomic_read(&conn->serial), 200563ea7d5SDavid Howells conn->hi_serial); 2018c3e34a4SDavid Howells 2028c3e34a4SDavid Howells return 0; 2038c3e34a4SDavid Howells } 2048c3e34a4SDavid Howells 2058c3e34a4SDavid Howells static const struct seq_operations rxrpc_connection_seq_ops = { 2068c3e34a4SDavid Howells .start = rxrpc_connection_seq_start, 2078c3e34a4SDavid Howells .next = rxrpc_connection_seq_next, 2088c3e34a4SDavid Howells .stop = rxrpc_connection_seq_stop, 2098c3e34a4SDavid Howells .show = rxrpc_connection_seq_show, 2108c3e34a4SDavid Howells }; 2118c3e34a4SDavid Howells 2128c3e34a4SDavid Howells 2138c3e34a4SDavid Howells static int rxrpc_connection_seq_open(struct inode *inode, struct file *file) 2148c3e34a4SDavid Howells { 2152baec2c3SDavid Howells return seq_open_net(inode, file, &rxrpc_connection_seq_ops, 2162baec2c3SDavid Howells sizeof(struct seq_net_private)); 2178c3e34a4SDavid Howells } 2188c3e34a4SDavid Howells 2198c3e34a4SDavid Howells const struct file_operations rxrpc_connection_seq_fops = { 2208c3e34a4SDavid Howells .owner = THIS_MODULE, 2218c3e34a4SDavid Howells .open = rxrpc_connection_seq_open, 2228c3e34a4SDavid Howells .read = seq_read, 2238c3e34a4SDavid Howells .llseek = seq_lseek, 2248c3e34a4SDavid Howells .release = seq_release, 2258c3e34a4SDavid Howells }; 226