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 178c3e34a4SDavid Howells static const char *const rxrpc_conn_states[] = { 188c3e34a4SDavid Howells [RXRPC_CONN_UNUSED] = "Unused ", 198c3e34a4SDavid Howells [RXRPC_CONN_CLIENT] = "Client ", 208c3e34a4SDavid Howells [RXRPC_CONN_SERVER_UNSECURED] = "SvUnsec ", 218c3e34a4SDavid Howells [RXRPC_CONN_SERVER_CHALLENGING] = "SvChall ", 228c3e34a4SDavid Howells [RXRPC_CONN_SERVER] = "SvSecure", 238c3e34a4SDavid Howells [RXRPC_CONN_REMOTELY_ABORTED] = "RmtAbort", 248c3e34a4SDavid Howells [RXRPC_CONN_LOCALLY_ABORTED] = "LocAbort", 258c3e34a4SDavid Howells [RXRPC_CONN_NETWORK_ERROR] = "NetError", 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 { 338c3e34a4SDavid Howells read_lock(&rxrpc_call_lock); 348c3e34a4SDavid Howells return seq_list_start_head(&rxrpc_calls, *_pos); 358c3e34a4SDavid Howells } 368c3e34a4SDavid Howells 378c3e34a4SDavid Howells static void *rxrpc_call_seq_next(struct seq_file *seq, void *v, loff_t *pos) 388c3e34a4SDavid Howells { 398c3e34a4SDavid Howells return seq_list_next(v, &rxrpc_calls, pos); 408c3e34a4SDavid Howells } 418c3e34a4SDavid Howells 428c3e34a4SDavid Howells static void rxrpc_call_seq_stop(struct seq_file *seq, void *v) 438c3e34a4SDavid Howells { 448c3e34a4SDavid Howells read_unlock(&rxrpc_call_lock); 458c3e34a4SDavid Howells } 468c3e34a4SDavid Howells 478c3e34a4SDavid Howells static int rxrpc_call_seq_show(struct seq_file *seq, void *v) 488c3e34a4SDavid Howells { 498c3e34a4SDavid Howells struct rxrpc_transport *trans; 508c3e34a4SDavid Howells struct rxrpc_call *call; 518c3e34a4SDavid Howells char lbuff[4 + 4 + 4 + 4 + 5 + 1], rbuff[4 + 4 + 4 + 4 + 5 + 1]; 528c3e34a4SDavid Howells 538c3e34a4SDavid Howells if (v == &rxrpc_calls) { 548c3e34a4SDavid Howells seq_puts(seq, 558c3e34a4SDavid Howells "Proto Local Remote " 568c3e34a4SDavid Howells " SvID ConnID CallID End Use State Abort " 578c3e34a4SDavid Howells " UserID\n"); 588c3e34a4SDavid Howells return 0; 598c3e34a4SDavid Howells } 608c3e34a4SDavid Howells 618c3e34a4SDavid Howells call = list_entry(v, struct rxrpc_call, link); 628c3e34a4SDavid Howells trans = call->conn->trans; 638c3e34a4SDavid Howells 648c3e34a4SDavid Howells sprintf(lbuff, "%pI4:%u", 658c3e34a4SDavid Howells &trans->local->srx.transport.sin.sin_addr, 668c3e34a4SDavid Howells ntohs(trans->local->srx.transport.sin.sin_port)); 678c3e34a4SDavid Howells 688c3e34a4SDavid Howells sprintf(rbuff, "%pI4:%u", 698c3e34a4SDavid Howells &trans->peer->srx.transport.sin.sin_addr, 708c3e34a4SDavid Howells ntohs(trans->peer->srx.transport.sin.sin_port)); 718c3e34a4SDavid Howells 728c3e34a4SDavid Howells seq_printf(seq, 738c3e34a4SDavid Howells "UDP %-22.22s %-22.22s %4x %08x %08x %s %3u" 748c3e34a4SDavid Howells " %-8.8s %08x %lx\n", 758c3e34a4SDavid Howells lbuff, 768c3e34a4SDavid Howells rbuff, 778c3e34a4SDavid Howells call->conn->service_id, 788c3e34a4SDavid Howells call->cid, 798c3e34a4SDavid Howells call->call_id, 808c3e34a4SDavid Howells call->conn->in_clientflag ? "Svc" : "Clt", 818c3e34a4SDavid Howells atomic_read(&call->usage), 828c3e34a4SDavid Howells rxrpc_call_states[call->state], 838c3e34a4SDavid Howells call->remote_abort ?: call->local_abort, 848c3e34a4SDavid Howells call->user_call_ID); 858c3e34a4SDavid Howells 868c3e34a4SDavid Howells return 0; 878c3e34a4SDavid Howells } 888c3e34a4SDavid Howells 898c3e34a4SDavid Howells static const struct seq_operations rxrpc_call_seq_ops = { 908c3e34a4SDavid Howells .start = rxrpc_call_seq_start, 918c3e34a4SDavid Howells .next = rxrpc_call_seq_next, 928c3e34a4SDavid Howells .stop = rxrpc_call_seq_stop, 938c3e34a4SDavid Howells .show = rxrpc_call_seq_show, 948c3e34a4SDavid Howells }; 958c3e34a4SDavid Howells 968c3e34a4SDavid Howells static int rxrpc_call_seq_open(struct inode *inode, struct file *file) 978c3e34a4SDavid Howells { 988c3e34a4SDavid Howells return seq_open(file, &rxrpc_call_seq_ops); 998c3e34a4SDavid Howells } 1008c3e34a4SDavid Howells 1018c3e34a4SDavid Howells const struct file_operations rxrpc_call_seq_fops = { 1028c3e34a4SDavid Howells .owner = THIS_MODULE, 1038c3e34a4SDavid Howells .open = rxrpc_call_seq_open, 1048c3e34a4SDavid Howells .read = seq_read, 1058c3e34a4SDavid Howells .llseek = seq_lseek, 1068c3e34a4SDavid Howells .release = seq_release, 1078c3e34a4SDavid Howells }; 1088c3e34a4SDavid Howells 1098c3e34a4SDavid Howells /* 1108c3e34a4SDavid Howells * generate a list of extant virtual connections in /proc/net/rxrpc_conns 1118c3e34a4SDavid Howells */ 1128c3e34a4SDavid Howells static void *rxrpc_connection_seq_start(struct seq_file *seq, loff_t *_pos) 1138c3e34a4SDavid Howells { 1148c3e34a4SDavid Howells read_lock(&rxrpc_connection_lock); 1158c3e34a4SDavid Howells return seq_list_start_head(&rxrpc_connections, *_pos); 1168c3e34a4SDavid Howells } 1178c3e34a4SDavid Howells 1188c3e34a4SDavid Howells static void *rxrpc_connection_seq_next(struct seq_file *seq, void *v, 1198c3e34a4SDavid Howells loff_t *pos) 1208c3e34a4SDavid Howells { 1218c3e34a4SDavid Howells return seq_list_next(v, &rxrpc_connections, pos); 1228c3e34a4SDavid Howells } 1238c3e34a4SDavid Howells 1248c3e34a4SDavid Howells static void rxrpc_connection_seq_stop(struct seq_file *seq, void *v) 1258c3e34a4SDavid Howells { 1268c3e34a4SDavid Howells read_unlock(&rxrpc_connection_lock); 1278c3e34a4SDavid Howells } 1288c3e34a4SDavid Howells 1298c3e34a4SDavid Howells static int rxrpc_connection_seq_show(struct seq_file *seq, void *v) 1308c3e34a4SDavid Howells { 1318c3e34a4SDavid Howells struct rxrpc_connection *conn; 1328c3e34a4SDavid Howells struct rxrpc_transport *trans; 1338c3e34a4SDavid Howells char lbuff[4 + 4 + 4 + 4 + 5 + 1], rbuff[4 + 4 + 4 + 4 + 5 + 1]; 1348c3e34a4SDavid Howells 1358c3e34a4SDavid Howells if (v == &rxrpc_connections) { 1368c3e34a4SDavid Howells seq_puts(seq, 1378c3e34a4SDavid Howells "Proto Local Remote " 1388c3e34a4SDavid Howells " SvID ConnID Calls End Use State Key " 1398c3e34a4SDavid Howells " Serial ISerial\n" 1408c3e34a4SDavid Howells ); 1418c3e34a4SDavid Howells return 0; 1428c3e34a4SDavid Howells } 1438c3e34a4SDavid Howells 1448c3e34a4SDavid Howells conn = list_entry(v, struct rxrpc_connection, link); 1458c3e34a4SDavid Howells trans = conn->trans; 1468c3e34a4SDavid Howells 1478c3e34a4SDavid Howells sprintf(lbuff, "%pI4:%u", 1488c3e34a4SDavid Howells &trans->local->srx.transport.sin.sin_addr, 1498c3e34a4SDavid Howells ntohs(trans->local->srx.transport.sin.sin_port)); 1508c3e34a4SDavid Howells 1518c3e34a4SDavid Howells sprintf(rbuff, "%pI4:%u", 1528c3e34a4SDavid Howells &trans->peer->srx.transport.sin.sin_addr, 1538c3e34a4SDavid Howells ntohs(trans->peer->srx.transport.sin.sin_port)); 1548c3e34a4SDavid Howells 1558c3e34a4SDavid Howells seq_printf(seq, 1568c3e34a4SDavid Howells "UDP %-22.22s %-22.22s %4x %08x %08x %s %3u" 1578c3e34a4SDavid Howells " %s %08x %08x %08x\n", 1588c3e34a4SDavid Howells lbuff, 1598c3e34a4SDavid Howells rbuff, 1608c3e34a4SDavid Howells conn->service_id, 1618c3e34a4SDavid Howells conn->cid, 1628c3e34a4SDavid Howells conn->call_counter, 1638c3e34a4SDavid Howells conn->in_clientflag ? "Svc" : "Clt", 1648c3e34a4SDavid Howells atomic_read(&conn->usage), 1658c3e34a4SDavid Howells rxrpc_conn_states[conn->state], 1668c3e34a4SDavid Howells key_serial(conn->key), 1678c3e34a4SDavid Howells atomic_read(&conn->serial), 1688c3e34a4SDavid Howells atomic_read(&conn->hi_serial)); 1698c3e34a4SDavid Howells 1708c3e34a4SDavid Howells return 0; 1718c3e34a4SDavid Howells } 1728c3e34a4SDavid Howells 1738c3e34a4SDavid Howells static const struct seq_operations rxrpc_connection_seq_ops = { 1748c3e34a4SDavid Howells .start = rxrpc_connection_seq_start, 1758c3e34a4SDavid Howells .next = rxrpc_connection_seq_next, 1768c3e34a4SDavid Howells .stop = rxrpc_connection_seq_stop, 1778c3e34a4SDavid Howells .show = rxrpc_connection_seq_show, 1788c3e34a4SDavid Howells }; 1798c3e34a4SDavid Howells 1808c3e34a4SDavid Howells 1818c3e34a4SDavid Howells static int rxrpc_connection_seq_open(struct inode *inode, struct file *file) 1828c3e34a4SDavid Howells { 1838c3e34a4SDavid Howells return seq_open(file, &rxrpc_connection_seq_ops); 1848c3e34a4SDavid Howells } 1858c3e34a4SDavid Howells 1868c3e34a4SDavid Howells const struct file_operations rxrpc_connection_seq_fops = { 1878c3e34a4SDavid Howells .owner = THIS_MODULE, 1888c3e34a4SDavid Howells .open = rxrpc_connection_seq_open, 1898c3e34a4SDavid Howells .read = seq_read, 1908c3e34a4SDavid Howells .llseek = seq_lseek, 1918c3e34a4SDavid Howells .release = seq_release, 1928c3e34a4SDavid Howells }; 193