1 /* /proc/net/ support for AF_RXRPC 2 * 3 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved. 4 * Written by David Howells (dhowells@redhat.com) 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License 8 * as published by the Free Software Foundation; either version 9 * 2 of the License, or (at your option) any later version. 10 */ 11 12 #include <linux/module.h> 13 #include <net/sock.h> 14 #include <net/af_rxrpc.h> 15 #include "ar-internal.h" 16 17 static const char *const rxrpc_conn_states[RXRPC_CONN__NR_STATES] = { 18 [RXRPC_CONN_UNUSED] = "Unused ", 19 [RXRPC_CONN_CLIENT] = "Client ", 20 [RXRPC_CONN_SERVICE_UNSECURED] = "SvUnsec ", 21 [RXRPC_CONN_SERVICE_CHALLENGING] = "SvChall ", 22 [RXRPC_CONN_SERVICE] = "SvSecure", 23 [RXRPC_CONN_REMOTELY_ABORTED] = "RmtAbort", 24 [RXRPC_CONN_LOCALLY_ABORTED] = "LocAbort", 25 }; 26 27 /* 28 * generate a list of extant and dead calls in /proc/net/rxrpc_calls 29 */ 30 static void *rxrpc_call_seq_start(struct seq_file *seq, loff_t *_pos) 31 { 32 read_lock(&rxrpc_call_lock); 33 return seq_list_start_head(&rxrpc_calls, *_pos); 34 } 35 36 static void *rxrpc_call_seq_next(struct seq_file *seq, void *v, loff_t *pos) 37 { 38 return seq_list_next(v, &rxrpc_calls, pos); 39 } 40 41 static void rxrpc_call_seq_stop(struct seq_file *seq, void *v) 42 { 43 read_unlock(&rxrpc_call_lock); 44 } 45 46 static int rxrpc_call_seq_show(struct seq_file *seq, void *v) 47 { 48 struct rxrpc_local *local; 49 struct rxrpc_sock *rx; 50 struct rxrpc_peer *peer; 51 struct rxrpc_call *call; 52 char lbuff[4 + 4 + 4 + 4 + 5 + 1], rbuff[4 + 4 + 4 + 4 + 5 + 1]; 53 54 if (v == &rxrpc_calls) { 55 seq_puts(seq, 56 "Proto Local Remote " 57 " SvID ConnID CallID End Use State Abort " 58 " UserID\n"); 59 return 0; 60 } 61 62 call = list_entry(v, struct rxrpc_call, link); 63 64 rx = READ_ONCE(call->socket); 65 if (rx) { 66 local = READ_ONCE(rx->local); 67 if (local) 68 sprintf(lbuff, "%pI4:%u", 69 &local->srx.transport.sin.sin_addr, 70 ntohs(local->srx.transport.sin.sin_port)); 71 else 72 strcpy(lbuff, "no_local"); 73 } else { 74 strcpy(lbuff, "no_socket"); 75 } 76 77 peer = call->peer; 78 if (peer) 79 sprintf(rbuff, "%pI4:%u", 80 &peer->srx.transport.sin.sin_addr, 81 ntohs(peer->srx.transport.sin.sin_port)); 82 else 83 strcpy(rbuff, "no_connection"); 84 85 seq_printf(seq, 86 "UDP %-22.22s %-22.22s %4x %08x %08x %s %3u" 87 " %-8.8s %08x %lx\n", 88 lbuff, 89 rbuff, 90 call->service_id, 91 call->cid, 92 call->call_id, 93 rxrpc_is_service_call(call) ? "Svc" : "Clt", 94 atomic_read(&call->usage), 95 rxrpc_call_states[call->state], 96 call->abort_code, 97 call->user_call_ID); 98 99 return 0; 100 } 101 102 static const struct seq_operations rxrpc_call_seq_ops = { 103 .start = rxrpc_call_seq_start, 104 .next = rxrpc_call_seq_next, 105 .stop = rxrpc_call_seq_stop, 106 .show = rxrpc_call_seq_show, 107 }; 108 109 static int rxrpc_call_seq_open(struct inode *inode, struct file *file) 110 { 111 return seq_open(file, &rxrpc_call_seq_ops); 112 } 113 114 const struct file_operations rxrpc_call_seq_fops = { 115 .owner = THIS_MODULE, 116 .open = rxrpc_call_seq_open, 117 .read = seq_read, 118 .llseek = seq_lseek, 119 .release = seq_release, 120 }; 121 122 /* 123 * generate a list of extant virtual connections in /proc/net/rxrpc_conns 124 */ 125 static void *rxrpc_connection_seq_start(struct seq_file *seq, loff_t *_pos) 126 { 127 read_lock(&rxrpc_connection_lock); 128 return seq_list_start_head(&rxrpc_connection_proc_list, *_pos); 129 } 130 131 static void *rxrpc_connection_seq_next(struct seq_file *seq, void *v, 132 loff_t *pos) 133 { 134 return seq_list_next(v, &rxrpc_connection_proc_list, pos); 135 } 136 137 static void rxrpc_connection_seq_stop(struct seq_file *seq, void *v) 138 { 139 read_unlock(&rxrpc_connection_lock); 140 } 141 142 static int rxrpc_connection_seq_show(struct seq_file *seq, void *v) 143 { 144 struct rxrpc_connection *conn; 145 char lbuff[4 + 4 + 4 + 4 + 5 + 1], rbuff[4 + 4 + 4 + 4 + 5 + 1]; 146 147 if (v == &rxrpc_connection_proc_list) { 148 seq_puts(seq, 149 "Proto Local Remote " 150 " SvID ConnID End Use State Key " 151 " Serial ISerial\n" 152 ); 153 return 0; 154 } 155 156 conn = list_entry(v, struct rxrpc_connection, proc_link); 157 158 sprintf(lbuff, "%pI4:%u", 159 &conn->params.local->srx.transport.sin.sin_addr, 160 ntohs(conn->params.local->srx.transport.sin.sin_port)); 161 162 sprintf(rbuff, "%pI4:%u", 163 &conn->params.peer->srx.transport.sin.sin_addr, 164 ntohs(conn->params.peer->srx.transport.sin.sin_port)); 165 166 seq_printf(seq, 167 "UDP %-22.22s %-22.22s %4x %08x %s %3u" 168 " %s %08x %08x %08x\n", 169 lbuff, 170 rbuff, 171 conn->params.service_id, 172 conn->proto.cid, 173 rxrpc_conn_is_service(conn) ? "Svc" : "Clt", 174 atomic_read(&conn->usage), 175 rxrpc_conn_states[conn->state], 176 key_serial(conn->params.key), 177 atomic_read(&conn->serial), 178 conn->hi_serial); 179 180 return 0; 181 } 182 183 static const struct seq_operations rxrpc_connection_seq_ops = { 184 .start = rxrpc_connection_seq_start, 185 .next = rxrpc_connection_seq_next, 186 .stop = rxrpc_connection_seq_stop, 187 .show = rxrpc_connection_seq_show, 188 }; 189 190 191 static int rxrpc_connection_seq_open(struct inode *inode, struct file *file) 192 { 193 return seq_open(file, &rxrpc_connection_seq_ops); 194 } 195 196 const struct file_operations rxrpc_connection_seq_fops = { 197 .owner = THIS_MODULE, 198 .open = rxrpc_connection_seq_open, 199 .read = seq_read, 200 .llseek = seq_lseek, 201 .release = seq_release, 202 }; 203