proc.c 5.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/* /proc/net/ support for AF_RXRPC
 *
 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
 * Written by David Howells (dhowells@redhat.com)
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version
 * 2 of the License, or (at your option) any later version.
 */

#include <linux/module.h>
#include <net/sock.h>
#include <net/af_rxrpc.h>
#include "ar-internal.h"

17 18 19 20 21 22 23 24 25
static const char *const rxrpc_conn_states[RXRPC_CONN__NR_STATES] = {
	[RXRPC_CONN_UNUSED]			= "Unused  ",
	[RXRPC_CONN_CLIENT]			= "Client  ",
	[RXRPC_CONN_SERVICE_UNSECURED]		= "SvUnsec ",
	[RXRPC_CONN_SERVICE_CHALLENGING]	= "SvChall ",
	[RXRPC_CONN_SERVICE]			= "SvSecure",
	[RXRPC_CONN_REMOTELY_ABORTED]		= "RmtAbort",
	[RXRPC_CONN_LOCALLY_ABORTED]		= "LocAbort",
	[RXRPC_CONN_NETWORK_ERROR]		= "NetError",
26 27 28 29 30 31 32 33
};

/*
 * generate a list of extant and dead calls in /proc/net/rxrpc_calls
 */
static void *rxrpc_call_seq_start(struct seq_file *seq, loff_t *_pos)
{
	read_lock(&rxrpc_call_lock);
34
	return seq_list_start_head(&rxrpc_calls, *_pos);
35 36 37 38
}

static void *rxrpc_call_seq_next(struct seq_file *seq, void *v, loff_t *pos)
{
39
	return seq_list_next(v, &rxrpc_calls, pos);
40 41 42 43 44 45 46 47 48
}

static void rxrpc_call_seq_stop(struct seq_file *seq, void *v)
{
	read_unlock(&rxrpc_call_lock);
}

static int rxrpc_call_seq_show(struct seq_file *seq, void *v)
{
49
	struct rxrpc_connection *conn;
50 51 52
	struct rxrpc_call *call;
	char lbuff[4 + 4 + 4 + 4 + 5 + 1], rbuff[4 + 4 + 4 + 4 + 5 + 1];

53
	if (v == &rxrpc_calls) {
54 55 56 57 58 59 60 61 62
		seq_puts(seq,
			 "Proto Local                  Remote                "
			 " SvID ConnID   CallID   End Use State    Abort   "
			 " UserID\n");
		return 0;
	}

	call = list_entry(v, struct rxrpc_call, link);

H
Harvey Harrison 已提交
63
	sprintf(lbuff, "%pI4:%u",
64 65
		&call->socket->local->srx.transport.sin.sin_addr,
		ntohs(call->socket->local->srx.transport.sin.sin_port));
66

67 68 69 70 71 72 73
	conn = call->conn;
	if (conn)
		sprintf(rbuff, "%pI4:%u",
			&conn->params.peer->srx.transport.sin.sin_addr,
			ntohs(conn->params.peer->srx.transport.sin.sin_port));
	else
		strcpy(rbuff, "no_connection");
74 75 76 77 78 79

	seq_printf(seq,
		   "UDP   %-22.22s %-22.22s %4x %08x %08x %s %3u"
		   " %-8.8s %08x %lx\n",
		   lbuff,
		   rbuff,
80
		   call->service_id,
81 82
		   call->cid,
		   call->call_id,
83
		   rxrpc_is_service_call(call) ? "Svc" : "Clt",
84 85
		   atomic_read(&call->usage),
		   rxrpc_call_states[call->state],
86
		   call->remote_abort ?: call->local_abort,
87 88 89 90 91
		   call->user_call_ID);

	return 0;
}

92
static const struct seq_operations rxrpc_call_seq_ops = {
93 94 95 96 97 98 99 100 101 102 103
	.start  = rxrpc_call_seq_start,
	.next   = rxrpc_call_seq_next,
	.stop   = rxrpc_call_seq_stop,
	.show   = rxrpc_call_seq_show,
};

static int rxrpc_call_seq_open(struct inode *inode, struct file *file)
{
	return seq_open(file, &rxrpc_call_seq_ops);
}

104
const struct file_operations rxrpc_call_seq_fops = {
105 106 107 108
	.owner		= THIS_MODULE,
	.open		= rxrpc_call_seq_open,
	.read		= seq_read,
	.llseek		= seq_lseek,
109
	.release	= seq_release,
110 111 112 113 114 115 116 117
};

/*
 * generate a list of extant virtual connections in /proc/net/rxrpc_conns
 */
static void *rxrpc_connection_seq_start(struct seq_file *seq, loff_t *_pos)
{
	read_lock(&rxrpc_connection_lock);
118
	return seq_list_start_head(&rxrpc_connections, *_pos);
119 120 121 122 123
}

static void *rxrpc_connection_seq_next(struct seq_file *seq, void *v,
				       loff_t *pos)
{
124
	return seq_list_next(v, &rxrpc_connections, pos);
125 126 127 128 129 130 131 132 133 134 135 136
}

static void rxrpc_connection_seq_stop(struct seq_file *seq, void *v)
{
	read_unlock(&rxrpc_connection_lock);
}

static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
{
	struct rxrpc_connection *conn;
	char lbuff[4 + 4 + 4 + 4 + 5 + 1], rbuff[4 + 4 + 4 + 4 + 5 + 1];

137
	if (v == &rxrpc_connections) {
138 139
		seq_puts(seq,
			 "Proto Local                  Remote                "
140
			 " SvID ConnID   End Use State    Key     "
141 142 143 144 145 146 147
			 " Serial   ISerial\n"
			 );
		return 0;
	}

	conn = list_entry(v, struct rxrpc_connection, link);

H
Harvey Harrison 已提交
148
	sprintf(lbuff, "%pI4:%u",
149 150
		&conn->params.local->srx.transport.sin.sin_addr,
		ntohs(conn->params.local->srx.transport.sin.sin_port));
151

H
Harvey Harrison 已提交
152
	sprintf(rbuff, "%pI4:%u",
153 154
		&conn->params.peer->srx.transport.sin.sin_addr,
		ntohs(conn->params.peer->srx.transport.sin.sin_port));
155 156

	seq_printf(seq,
157
		   "UDP   %-22.22s %-22.22s %4x %08x %s %3u"
158 159 160
		   " %s %08x %08x %08x\n",
		   lbuff,
		   rbuff,
161 162 163
		   conn->params.service_id,
		   conn->proto.cid,
		   rxrpc_conn_is_service(conn) ? "Svc" : "Clt",
164 165
		   atomic_read(&conn->usage),
		   rxrpc_conn_states[conn->state],
166
		   key_serial(conn->params.key),
167
		   atomic_read(&conn->serial),
168
		   conn->hi_serial);
169 170 171 172

	return 0;
}

173
static const struct seq_operations rxrpc_connection_seq_ops = {
174 175 176 177 178 179 180 181 182 183 184 185
	.start  = rxrpc_connection_seq_start,
	.next   = rxrpc_connection_seq_next,
	.stop   = rxrpc_connection_seq_stop,
	.show   = rxrpc_connection_seq_show,
};


static int rxrpc_connection_seq_open(struct inode *inode, struct file *file)
{
	return seq_open(file, &rxrpc_connection_seq_ops);
}

186
const struct file_operations rxrpc_connection_seq_fops = {
187 188 189 190
	.owner		= THIS_MODULE,
	.open		= rxrpc_connection_seq_open,
	.read		= seq_read,
	.llseek		= seq_lseek,
191
	.release	= seq_release,
192
};