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_PREALLOC] = "SvPrealc", 21 [RXRPC_CONN_SERVICE_UNSECURED] = "SvUnsec ", 22 [RXRPC_CONN_SERVICE_CHALLENGING] = "SvChall ", 23 [RXRPC_CONN_SERVICE] = "SvSecure", 24 [RXRPC_CONN_REMOTELY_ABORTED] = "RmtAbort", 25 [RXRPC_CONN_LOCALLY_ABORTED] = "LocAbort", 26 }; 27 28 /* 29 * generate a list of extant and dead calls in /proc/net/rxrpc_calls 30 */ 31 static void *rxrpc_call_seq_start(struct seq_file *seq, loff_t *_pos) 32 { 33 struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq)); 34 35 rcu_read_lock(); 36 read_lock(&rxnet->call_lock); 37 return seq_list_start_head(&rxnet->calls, *_pos); 38 } 39 40 static void *rxrpc_call_seq_next(struct seq_file *seq, void *v, loff_t *pos) 41 { 42 struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq)); 43 44 return seq_list_next(v, &rxnet->calls, pos); 45 } 46 47 static void rxrpc_call_seq_stop(struct seq_file *seq, void *v) 48 { 49 struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq)); 50 51 read_unlock(&rxnet->call_lock); 52 rcu_read_unlock(); 53 } 54 55 static int rxrpc_call_seq_show(struct seq_file *seq, void *v) 56 { 57 struct rxrpc_local *local; 58 struct rxrpc_sock *rx; 59 struct rxrpc_peer *peer; 60 struct rxrpc_call *call; 61 struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq)); 62 rxrpc_seq_t tx_hard_ack, rx_hard_ack; 63 char lbuff[50], rbuff[50]; 64 65 if (v == &rxnet->calls) { 66 seq_puts(seq, 67 "Proto Local " 68 " Remote " 69 " SvID ConnID CallID End Use State Abort " 70 " UserID\n"); 71 return 0; 72 } 73 74 call = list_entry(v, struct rxrpc_call, link); 75 76 rx = rcu_dereference(call->socket); 77 if (rx) { 78 local = READ_ONCE(rx->local); 79 if (local) 80 sprintf(lbuff, "%pISpc", &local->srx.transport); 81 else 82 strcpy(lbuff, "no_local"); 83 } else { 84 strcpy(lbuff, "no_socket"); 85 } 86 87 peer = call->peer; 88 if (peer) 89 sprintf(rbuff, "%pISpc", &peer->srx.transport); 90 else 91 strcpy(rbuff, "no_connection"); 92 93 tx_hard_ack = READ_ONCE(call->tx_hard_ack); 94 rx_hard_ack = READ_ONCE(call->rx_hard_ack); 95 seq_printf(seq, 96 "UDP %-47.47s %-47.47s %4x %08x %08x %s %3u" 97 " %-8.8s %08x %lx %08x %02x %08x %02x\n", 98 lbuff, 99 rbuff, 100 call->service_id, 101 call->cid, 102 call->call_id, 103 rxrpc_is_service_call(call) ? "Svc" : "Clt", 104 atomic_read(&call->usage), 105 rxrpc_call_states[call->state], 106 call->abort_code, 107 call->user_call_ID, 108 tx_hard_ack, READ_ONCE(call->tx_top) - tx_hard_ack, 109 rx_hard_ack, READ_ONCE(call->rx_top) - rx_hard_ack); 110 111 return 0; 112 } 113 114 static const struct seq_operations rxrpc_call_seq_ops = { 115 .start = rxrpc_call_seq_start, 116 .next = rxrpc_call_seq_next, 117 .stop = rxrpc_call_seq_stop, 118 .show = rxrpc_call_seq_show, 119 }; 120 121 static int rxrpc_call_seq_open(struct inode *inode, struct file *file) 122 { 123 return seq_open_net(inode, file, &rxrpc_call_seq_ops, 124 sizeof(struct seq_net_private)); 125 } 126 127 const struct file_operations rxrpc_call_seq_fops = { 128 .open = rxrpc_call_seq_open, 129 .read = seq_read, 130 .llseek = seq_lseek, 131 .release = seq_release, 132 }; 133 134 /* 135 * generate a list of extant virtual connections in /proc/net/rxrpc_conns 136 */ 137 static void *rxrpc_connection_seq_start(struct seq_file *seq, loff_t *_pos) 138 { 139 struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq)); 140 141 read_lock(&rxnet->conn_lock); 142 return seq_list_start_head(&rxnet->conn_proc_list, *_pos); 143 } 144 145 static void *rxrpc_connection_seq_next(struct seq_file *seq, void *v, 146 loff_t *pos) 147 { 148 struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq)); 149 150 return seq_list_next(v, &rxnet->conn_proc_list, pos); 151 } 152 153 static void rxrpc_connection_seq_stop(struct seq_file *seq, void *v) 154 { 155 struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq)); 156 157 read_unlock(&rxnet->conn_lock); 158 } 159 160 static int rxrpc_connection_seq_show(struct seq_file *seq, void *v) 161 { 162 struct rxrpc_connection *conn; 163 struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq)); 164 char lbuff[50], rbuff[50]; 165 166 if (v == &rxnet->conn_proc_list) { 167 seq_puts(seq, 168 "Proto Local " 169 " Remote " 170 " SvID ConnID End Use State Key " 171 " Serial ISerial\n" 172 ); 173 return 0; 174 } 175 176 conn = list_entry(v, struct rxrpc_connection, proc_link); 177 if (conn->state == RXRPC_CONN_SERVICE_PREALLOC) { 178 strcpy(lbuff, "no_local"); 179 strcpy(rbuff, "no_connection"); 180 goto print; 181 } 182 183 sprintf(lbuff, "%pISpc", &conn->params.local->srx.transport); 184 185 sprintf(rbuff, "%pISpc", &conn->params.peer->srx.transport); 186 print: 187 seq_printf(seq, 188 "UDP %-47.47s %-47.47s %4x %08x %s %3u" 189 " %s %08x %08x %08x\n", 190 lbuff, 191 rbuff, 192 conn->service_id, 193 conn->proto.cid, 194 rxrpc_conn_is_service(conn) ? "Svc" : "Clt", 195 atomic_read(&conn->usage), 196 rxrpc_conn_states[conn->state], 197 key_serial(conn->params.key), 198 atomic_read(&conn->serial), 199 conn->hi_serial); 200 201 return 0; 202 } 203 204 static const struct seq_operations rxrpc_connection_seq_ops = { 205 .start = rxrpc_connection_seq_start, 206 .next = rxrpc_connection_seq_next, 207 .stop = rxrpc_connection_seq_stop, 208 .show = rxrpc_connection_seq_show, 209 }; 210 211 212 static int rxrpc_connection_seq_open(struct inode *inode, struct file *file) 213 { 214 return seq_open_net(inode, file, &rxrpc_connection_seq_ops, 215 sizeof(struct seq_net_private)); 216 } 217 218 const struct file_operations rxrpc_connection_seq_fops = { 219 .open = rxrpc_connection_seq_open, 220 .read = seq_read, 221 .llseek = seq_lseek, 222 .release = seq_release, 223 }; 224