proc.c 5.4 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
static const char *const rxrpc_conn_states[RXRPC_CONN__NR_STATES] = {
	[RXRPC_CONN_UNUSED]			= "Unused  ",
	[RXRPC_CONN_CLIENT]			= "Client  ",
20
	[RXRPC_CONN_SERVICE_PREALLOC]		= "SvPrealc",
21 22 23 24 25
	[RXRPC_CONN_SERVICE_UNSECURED]		= "SvUnsec ",
	[RXRPC_CONN_SERVICE_CHALLENGING]	= "SvChall ",
	[RXRPC_CONN_SERVICE]			= "SvSecure",
	[RXRPC_CONN_REMOTELY_ABORTED]		= "RmtAbort",
	[RXRPC_CONN_LOCALLY_ABORTED]		= "LocAbort",
26 27 28 29 30 31 32
};

/*
 * 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)
{
33
	rcu_read_lock();
34
	read_lock(&rxrpc_call_lock);
35
	return seq_list_start_head(&rxrpc_calls, *_pos);
36 37 38 39
}

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

static void rxrpc_call_seq_stop(struct seq_file *seq, void *v)
{
	read_unlock(&rxrpc_call_lock);
46
	rcu_read_unlock();
47 48 49 50
}

static int rxrpc_call_seq_show(struct seq_file *seq, void *v)
{
51 52 53
	struct rxrpc_local *local;
	struct rxrpc_sock *rx;
	struct rxrpc_peer *peer;
54
	struct rxrpc_call *call;
55
	rxrpc_seq_t tx_hard_ack, rx_hard_ack;
D
David Howells 已提交
56
	char lbuff[50], rbuff[50];
57

58
	if (v == &rxrpc_calls) {
59
		seq_puts(seq,
D
David Howells 已提交
60 61
			 "Proto Local                                          "
			 " Remote                                         "
62 63 64 65 66 67 68
			 " SvID ConnID   CallID   End Use State    Abort   "
			 " UserID\n");
		return 0;
	}

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

69
	rx = rcu_dereference(call->socket);
70 71 72
	if (rx) {
		local = READ_ONCE(rx->local);
		if (local)
D
David Howells 已提交
73
			sprintf(lbuff, "%pISpc", &local->srx.transport);
74 75 76 77 78
		else
			strcpy(lbuff, "no_local");
	} else {
		strcpy(lbuff, "no_socket");
	}
79

80 81
	peer = call->peer;
	if (peer)
D
David Howells 已提交
82
		sprintf(rbuff, "%pISpc", &peer->srx.transport);
83 84
	else
		strcpy(rbuff, "no_connection");
85

86 87
	tx_hard_ack = READ_ONCE(call->tx_hard_ack);
	rx_hard_ack = READ_ONCE(call->rx_hard_ack);
88
	seq_printf(seq,
D
David Howells 已提交
89
		   "UDP   %-47.47s %-47.47s %4x %08x %08x %s %3u"
90
		   " %-8.8s %08x %lx %08x %02x %08x %02x\n",
91 92
		   lbuff,
		   rbuff,
93
		   call->service_id,
94 95
		   call->cid,
		   call->call_id,
96
		   rxrpc_is_service_call(call) ? "Svc" : "Clt",
97 98
		   atomic_read(&call->usage),
		   rxrpc_call_states[call->state],
99
		   call->abort_code,
100 101 102
		   call->user_call_ID,
		   tx_hard_ack, READ_ONCE(call->tx_top) - tx_hard_ack,
		   rx_hard_ack, READ_ONCE(call->rx_top) - rx_hard_ack);
103 104 105 106

	return 0;
}

107
static const struct seq_operations rxrpc_call_seq_ops = {
108 109 110 111 112 113 114 115 116 117 118
	.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);
}

119
const struct file_operations rxrpc_call_seq_fops = {
120 121 122 123
	.owner		= THIS_MODULE,
	.open		= rxrpc_call_seq_open,
	.read		= seq_read,
	.llseek		= seq_lseek,
124
	.release	= seq_release,
125 126 127 128 129 130 131 132
};

/*
 * 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);
133
	return seq_list_start_head(&rxrpc_connection_proc_list, *_pos);
134 135 136 137 138
}

static void *rxrpc_connection_seq_next(struct seq_file *seq, void *v,
				       loff_t *pos)
{
139
	return seq_list_next(v, &rxrpc_connection_proc_list, pos);
140 141 142 143 144 145 146 147 148 149
}

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;
D
David Howells 已提交
150
	char lbuff[50], rbuff[50];
151

152
	if (v == &rxrpc_connection_proc_list) {
153
		seq_puts(seq,
D
David Howells 已提交
154 155
			 "Proto Local                                          "
			 " Remote                                         "
156
			 " SvID ConnID   End Use State    Key     "
157 158 159 160 161
			 " Serial   ISerial\n"
			 );
		return 0;
	}

162
	conn = list_entry(v, struct rxrpc_connection, proc_link);
163 164 165 166 167
	if (conn->state == RXRPC_CONN_SERVICE_PREALLOC) {
		strcpy(lbuff, "no_local");
		strcpy(rbuff, "no_connection");
		goto print;
	}
168

D
David Howells 已提交
169
	sprintf(lbuff, "%pISpc", &conn->params.local->srx.transport);
170

D
David Howells 已提交
171
	sprintf(rbuff, "%pISpc", &conn->params.peer->srx.transport);
172
print:
173
	seq_printf(seq,
D
David Howells 已提交
174
		   "UDP   %-47.47s %-47.47s %4x %08x %s %3u"
175 176 177
		   " %s %08x %08x %08x\n",
		   lbuff,
		   rbuff,
178 179 180
		   conn->params.service_id,
		   conn->proto.cid,
		   rxrpc_conn_is_service(conn) ? "Svc" : "Clt",
181 182
		   atomic_read(&conn->usage),
		   rxrpc_conn_states[conn->state],
183
		   key_serial(conn->params.key),
184
		   atomic_read(&conn->serial),
185
		   conn->hi_serial);
186 187 188 189

	return 0;
}

190
static const struct seq_operations rxrpc_connection_seq_ops = {
191 192 193 194 195 196 197 198 199 200 201 202
	.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);
}

203
const struct file_operations rxrpc_connection_seq_fops = {
204 205 206 207
	.owner		= THIS_MODULE,
	.open		= rxrpc_connection_seq_open,
	.read		= seq_read,
	.llseek		= seq_lseek,
208
	.release	= seq_release,
209
};