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 17static const char *rxrpc_conn_states[] = { 18 [RXRPC_CONN_UNUSED] = "Unused ", 19 [RXRPC_CONN_CLIENT] = "Client ", 20 [RXRPC_CONN_SERVER_UNSECURED] = "SvUnsec ", 21 [RXRPC_CONN_SERVER_CHALLENGING] = "SvChall ", 22 [RXRPC_CONN_SERVER] = "SvSecure", 23 [RXRPC_CONN_REMOTELY_ABORTED] = "RmtAbort", 24 [RXRPC_CONN_LOCALLY_ABORTED] = "LocAbort", 25 [RXRPC_CONN_NETWORK_ERROR] = "NetError", 26}; 27 28/* 29 * generate a list of extant and dead calls in /proc/net/rxrpc_calls 30 */ 31static void *rxrpc_call_seq_start(struct seq_file *seq, loff_t *_pos) 32{ 33 struct list_head *_p; 34 loff_t pos = *_pos; 35 36 read_lock(&rxrpc_call_lock); 37 if (!pos) 38 return SEQ_START_TOKEN; 39 pos--; 40 41 list_for_each(_p, &rxrpc_calls) 42 if (!pos--) 43 break; 44 45 return _p != &rxrpc_calls ? _p : NULL; 46} 47 48static void *rxrpc_call_seq_next(struct seq_file *seq, void *v, loff_t *pos) 49{ 50 struct list_head *_p; 51 52 (*pos)++; 53 54 _p = v; 55 _p = (v == SEQ_START_TOKEN) ? rxrpc_calls.next : _p->next; 56 57 return _p != &rxrpc_calls ? _p : NULL; 58} 59 60static void rxrpc_call_seq_stop(struct seq_file *seq, void *v) 61{ 62 read_unlock(&rxrpc_call_lock); 63} 64 65static int rxrpc_call_seq_show(struct seq_file *seq, void *v) 66{ 67 struct rxrpc_transport *trans; 68 struct rxrpc_call *call; 69 char lbuff[4 + 4 + 4 + 4 + 5 + 1], rbuff[4 + 4 + 4 + 4 + 5 + 1]; 70 71 if (v == SEQ_START_TOKEN) { 72 seq_puts(seq, 73 "Proto Local Remote " 74 " SvID ConnID CallID End Use State Abort " 75 " UserID\n"); 76 return 0; 77 } 78 79 call = list_entry(v, struct rxrpc_call, link); 80 trans = call->conn->trans; 81 82 sprintf(lbuff, NIPQUAD_FMT":%u", 83 NIPQUAD(trans->local->srx.transport.sin.sin_addr), 84 ntohs(trans->local->srx.transport.sin.sin_port)); 85 86 sprintf(rbuff, NIPQUAD_FMT":%u", 87 NIPQUAD(trans->peer->srx.transport.sin.sin_addr), 88 ntohs(trans->peer->srx.transport.sin.sin_port)); 89 90 seq_printf(seq, 91 "UDP %-22.22s %-22.22s %4x %08x %08x %s %3u" 92 " %-8.8s %08x %lx\n", 93 lbuff, 94 rbuff, 95 ntohs(call->conn->service_id), 96 ntohl(call->conn->cid), 97 ntohl(call->call_id), 98 call->conn->in_clientflag ? "Svc" : "Clt", 99 atomic_read(&call->usage), 100 rxrpc_call_states[call->state], 101 call->abort_code, 102 call->user_call_ID); 103 104 return 0; 105} 106 107static 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, 112}; 113 114static int rxrpc_call_seq_open(struct inode *inode, struct file *file) 115{ 116 return seq_open(file, &rxrpc_call_seq_ops); 117} 118 119struct file_operations rxrpc_call_seq_fops = { 120 .owner = THIS_MODULE, 121 .open = rxrpc_call_seq_open, 122 .read = seq_read, 123 .llseek = seq_lseek, 124 .release = seq_release_private, 125}; 126 127/* 128 * generate a list of extant virtual connections in /proc/net/rxrpc_conns 129 */ 130static void *rxrpc_connection_seq_start(struct seq_file *seq, loff_t *_pos) 131{ 132 struct list_head *_p; 133 loff_t pos = *_pos; 134 135 read_lock(&rxrpc_connection_lock); 136 if (!pos) 137 return SEQ_START_TOKEN; 138 pos--; 139 140 list_for_each(_p, &rxrpc_connections) 141 if (!pos--) 142 break; 143 144 return _p != &rxrpc_connections ? _p : NULL; 145} 146 147static void *rxrpc_connection_seq_next(struct seq_file *seq, void *v, 148 loff_t *pos) 149{ 150 struct list_head *_p; 151 152 (*pos)++; 153 154 _p = v; 155 _p = (v == SEQ_START_TOKEN) ? rxrpc_connections.next : _p->next; 156 157 return _p != &rxrpc_connections ? _p : NULL; 158} 159 160static void rxrpc_connection_seq_stop(struct seq_file *seq, void *v) 161{ 162 read_unlock(&rxrpc_connection_lock); 163} 164 165static int rxrpc_connection_seq_show(struct seq_file *seq, void *v) 166{ 167 struct rxrpc_connection *conn; 168 struct rxrpc_transport *trans; 169 char lbuff[4 + 4 + 4 + 4 + 5 + 1], rbuff[4 + 4 + 4 + 4 + 5 + 1]; 170 171 if (v == SEQ_START_TOKEN) { 172 seq_puts(seq, 173 "Proto Local Remote " 174 " SvID ConnID Calls End Use State Key " 175 " Serial ISerial\n" 176 ); 177 return 0; 178 } 179 180 conn = list_entry(v, struct rxrpc_connection, link); 181 trans = conn->trans; 182 183 sprintf(lbuff, NIPQUAD_FMT":%u", 184 NIPQUAD(trans->local->srx.transport.sin.sin_addr), 185 ntohs(trans->local->srx.transport.sin.sin_port)); 186 187 sprintf(rbuff, NIPQUAD_FMT":%u", 188 NIPQUAD(trans->peer->srx.transport.sin.sin_addr), 189 ntohs(trans->peer->srx.transport.sin.sin_port)); 190 191 seq_printf(seq, 192 "UDP %-22.22s %-22.22s %4x %08x %08x %s %3u" 193 " %s %08x %08x %08x\n", 194 lbuff, 195 rbuff, 196 ntohs(conn->service_id), 197 ntohl(conn->cid), 198 conn->call_counter, 199 conn->in_clientflag ? "Svc" : "Clt", 200 atomic_read(&conn->usage), 201 rxrpc_conn_states[conn->state], 202 key_serial(conn->key), 203 atomic_read(&conn->serial), 204 atomic_read(&conn->hi_serial)); 205 206 return 0; 207} 208 209static struct seq_operations rxrpc_connection_seq_ops = { 210 .start = rxrpc_connection_seq_start, 211 .next = rxrpc_connection_seq_next, 212 .stop = rxrpc_connection_seq_stop, 213 .show = rxrpc_connection_seq_show, 214}; 215 216 217static int rxrpc_connection_seq_open(struct inode *inode, struct file *file) 218{ 219 return seq_open(file, &rxrpc_connection_seq_ops); 220} 221 222struct file_operations rxrpc_connection_seq_fops = { 223 .owner = THIS_MODULE, 224 .open = rxrpc_connection_seq_open, 225 .read = seq_read, 226 .llseek = seq_lseek, 227 .release = seq_release_private, 228}; 229