2007-04-27 06:48:28 +08:00
|
|
|
/* /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"
|
|
|
|
|
2016-06-27 17:32:02 +08:00
|
|
|
static const char *const rxrpc_conn_states[RXRPC_CONN__NR_STATES] = {
|
|
|
|
[RXRPC_CONN_UNUSED] = "Unused ",
|
|
|
|
[RXRPC_CONN_CLIENT] = "Client ",
|
2016-09-08 18:10:12 +08:00
|
|
|
[RXRPC_CONN_SERVICE_PREALLOC] = "SvPrealc",
|
2016-06-27 17:32:02 +08:00
|
|
|
[RXRPC_CONN_SERVICE_UNSECURED] = "SvUnsec ",
|
|
|
|
[RXRPC_CONN_SERVICE_CHALLENGING] = "SvChall ",
|
|
|
|
[RXRPC_CONN_SERVICE] = "SvSecure",
|
|
|
|
[RXRPC_CONN_REMOTELY_ABORTED] = "RmtAbort",
|
|
|
|
[RXRPC_CONN_LOCALLY_ABORTED] = "LocAbort",
|
2007-04-27 06:48:28 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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)
|
|
|
|
{
|
2016-09-07 16:19:31 +08:00
|
|
|
rcu_read_lock();
|
2007-04-27 06:48:28 +08:00
|
|
|
read_lock(&rxrpc_call_lock);
|
2007-07-10 04:15:14 +08:00
|
|
|
return seq_list_start_head(&rxrpc_calls, *_pos);
|
2007-04-27 06:48:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void *rxrpc_call_seq_next(struct seq_file *seq, void *v, loff_t *pos)
|
|
|
|
{
|
2007-07-10 04:15:14 +08:00
|
|
|
return seq_list_next(v, &rxrpc_calls, pos);
|
2007-04-27 06:48:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void rxrpc_call_seq_stop(struct seq_file *seq, void *v)
|
|
|
|
{
|
|
|
|
read_unlock(&rxrpc_call_lock);
|
2016-09-07 16:19:31 +08:00
|
|
|
rcu_read_unlock();
|
2007-04-27 06:48:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int rxrpc_call_seq_show(struct seq_file *seq, void *v)
|
|
|
|
{
|
2016-08-24 21:31:43 +08:00
|
|
|
struct rxrpc_local *local;
|
|
|
|
struct rxrpc_sock *rx;
|
|
|
|
struct rxrpc_peer *peer;
|
2007-04-27 06:48:28 +08:00
|
|
|
struct rxrpc_call *call;
|
|
|
|
char lbuff[4 + 4 + 4 + 4 + 5 + 1], rbuff[4 + 4 + 4 + 4 + 5 + 1];
|
|
|
|
|
2007-07-10 04:15:14 +08:00
|
|
|
if (v == &rxrpc_calls) {
|
2007-04-27 06:48:28 +08:00
|
|
|
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);
|
|
|
|
|
2016-09-07 16:19:31 +08:00
|
|
|
rx = rcu_dereference(call->socket);
|
2016-08-24 21:31:43 +08:00
|
|
|
if (rx) {
|
|
|
|
local = READ_ONCE(rx->local);
|
|
|
|
if (local)
|
|
|
|
sprintf(lbuff, "%pI4:%u",
|
|
|
|
&local->srx.transport.sin.sin_addr,
|
|
|
|
ntohs(local->srx.transport.sin.sin_port));
|
|
|
|
else
|
|
|
|
strcpy(lbuff, "no_local");
|
|
|
|
} else {
|
|
|
|
strcpy(lbuff, "no_socket");
|
|
|
|
}
|
2007-04-27 06:48:28 +08:00
|
|
|
|
2016-08-24 21:31:43 +08:00
|
|
|
peer = call->peer;
|
|
|
|
if (peer)
|
2016-06-17 18:07:55 +08:00
|
|
|
sprintf(rbuff, "%pI4:%u",
|
2016-08-24 21:31:43 +08:00
|
|
|
&peer->srx.transport.sin.sin_addr,
|
|
|
|
ntohs(peer->srx.transport.sin.sin_port));
|
2016-06-17 18:07:55 +08:00
|
|
|
else
|
|
|
|
strcpy(rbuff, "no_connection");
|
2007-04-27 06:48:28 +08:00
|
|
|
|
|
|
|
seq_printf(seq,
|
|
|
|
"UDP %-22.22s %-22.22s %4x %08x %08x %s %3u"
|
|
|
|
" %-8.8s %08x %lx\n",
|
|
|
|
lbuff,
|
|
|
|
rbuff,
|
2016-06-17 18:07:55 +08:00
|
|
|
call->service_id,
|
2016-03-04 23:53:46 +08:00
|
|
|
call->cid,
|
|
|
|
call->call_id,
|
2016-08-23 22:27:24 +08:00
|
|
|
rxrpc_is_service_call(call) ? "Svc" : "Clt",
|
2007-04-27 06:48:28 +08:00
|
|
|
atomic_read(&call->usage),
|
|
|
|
rxrpc_call_states[call->state],
|
2016-08-30 16:49:28 +08:00
|
|
|
call->abort_code,
|
2007-04-27 06:48:28 +08:00
|
|
|
call->user_call_ID);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-07-11 14:07:31 +08:00
|
|
|
static const struct seq_operations rxrpc_call_seq_ops = {
|
2007-04-27 06:48:28 +08:00
|
|
|
.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);
|
|
|
|
}
|
|
|
|
|
2008-01-31 10:55:45 +08:00
|
|
|
const struct file_operations rxrpc_call_seq_fops = {
|
2007-04-27 06:48:28 +08:00
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.open = rxrpc_call_seq_open,
|
|
|
|
.read = seq_read,
|
|
|
|
.llseek = seq_lseek,
|
2008-03-01 03:39:17 +08:00
|
|
|
.release = seq_release,
|
2007-04-27 06:48:28 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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);
|
2016-08-24 14:30:52 +08:00
|
|
|
return seq_list_start_head(&rxrpc_connection_proc_list, *_pos);
|
2007-04-27 06:48:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void *rxrpc_connection_seq_next(struct seq_file *seq, void *v,
|
|
|
|
loff_t *pos)
|
|
|
|
{
|
2016-08-24 14:30:52 +08:00
|
|
|
return seq_list_next(v, &rxrpc_connection_proc_list, pos);
|
2007-04-27 06:48:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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];
|
|
|
|
|
2016-08-24 14:30:52 +08:00
|
|
|
if (v == &rxrpc_connection_proc_list) {
|
2007-04-27 06:48:28 +08:00
|
|
|
seq_puts(seq,
|
|
|
|
"Proto Local Remote "
|
rxrpc: Call channels should have separate call number spaces
Each channel on a connection has a separate, independent number space from
which to allocate callNumber values. It is entirely possible, for example,
to have a connection with four active calls, each with call number 1.
Note that the callNumber values for any particular channel don't have to
start at 1, but they are supposed to increment monotonically for that
channel from a client's perspective and may not be reused once the call
number is transmitted (until the epoch cycles all the way back round).
Currently, however, call numbers are allocated on a per-connection basis
and, further, are held in an rb-tree. The rb-tree is redundant as the four
channel pointers in the rxrpc_connection struct are entirely capable of
pointing to all the calls currently in progress on a connection.
To this end, make the following changes:
(1) Handle call number allocation independently per channel.
(2) Get rid of the conn->calls rb-tree. This is overkill as a connection
may have a maximum of four calls in progress at any one time. Use the
pointers in the channels[] array instead, indexed by the channel
number from the packet.
(3) For each channel, save the result of the last call that was in
progress on that channel in conn->channels[] so that the final ACK or
ABORT packet can be replayed if necessary. Any call earlier than that
is just ignored. If we've seen the next call number in a packet, the
last one is most definitely defunct.
(4) When generating a RESPONSE packet for a connection, the call number
counter for each channel must be included in it.
(5) When parsing a RESPONSE packet for a connection, the call number
counters contained therein should be used to set the minimum expected
call numbers on each channel.
To do in future commits:
(1) Replay terminal packets based on the last call stored in
conn->channels[].
(2) Connections should be retired before the callNumber space on any
channel runs out.
(3) A server is expected to disregard or reject any new incoming call that
has a call number less than the current call number counter. The call
number counter for that channel must be advanced to the new call
number.
Note that the server cannot just require that the next call that it
sees on a channel be exactly the call number counter + 1 because then
there's a scenario that could cause a problem: The client transmits a
packet to initiate a connection, the network goes out, the server
sends an ACK (which gets lost), the client sends an ABORT (which also
gets lost); the network then reconnects, the client then reuses the
call number for the next call (it doesn't know the server already saw
the call number), but the server thinks it already has the first
packet of this call (it doesn't know that the client doesn't know that
it saw the call number the first time).
Signed-off-by: David Howells <dhowells@redhat.com>
2016-06-27 21:39:44 +08:00
|
|
|
" SvID ConnID End Use State Key "
|
2007-04-27 06:48:28 +08:00
|
|
|
" Serial ISerial\n"
|
|
|
|
);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-08-24 14:30:52 +08:00
|
|
|
conn = list_entry(v, struct rxrpc_connection, proc_link);
|
2016-09-08 18:10:12 +08:00
|
|
|
if (conn->state == RXRPC_CONN_SERVICE_PREALLOC) {
|
|
|
|
strcpy(lbuff, "no_local");
|
|
|
|
strcpy(rbuff, "no_connection");
|
|
|
|
goto print;
|
|
|
|
}
|
2007-04-27 06:48:28 +08:00
|
|
|
|
2008-10-31 15:54:56 +08:00
|
|
|
sprintf(lbuff, "%pI4:%u",
|
2016-04-04 21:00:36 +08:00
|
|
|
&conn->params.local->srx.transport.sin.sin_addr,
|
|
|
|
ntohs(conn->params.local->srx.transport.sin.sin_port));
|
2007-04-27 06:48:28 +08:00
|
|
|
|
2008-10-31 15:54:56 +08:00
|
|
|
sprintf(rbuff, "%pI4:%u",
|
2016-04-04 21:00:36 +08:00
|
|
|
&conn->params.peer->srx.transport.sin.sin_addr,
|
|
|
|
ntohs(conn->params.peer->srx.transport.sin.sin_port));
|
2016-09-08 18:10:12 +08:00
|
|
|
print:
|
2007-04-27 06:48:28 +08:00
|
|
|
seq_printf(seq,
|
rxrpc: Call channels should have separate call number spaces
Each channel on a connection has a separate, independent number space from
which to allocate callNumber values. It is entirely possible, for example,
to have a connection with four active calls, each with call number 1.
Note that the callNumber values for any particular channel don't have to
start at 1, but they are supposed to increment monotonically for that
channel from a client's perspective and may not be reused once the call
number is transmitted (until the epoch cycles all the way back round).
Currently, however, call numbers are allocated on a per-connection basis
and, further, are held in an rb-tree. The rb-tree is redundant as the four
channel pointers in the rxrpc_connection struct are entirely capable of
pointing to all the calls currently in progress on a connection.
To this end, make the following changes:
(1) Handle call number allocation independently per channel.
(2) Get rid of the conn->calls rb-tree. This is overkill as a connection
may have a maximum of four calls in progress at any one time. Use the
pointers in the channels[] array instead, indexed by the channel
number from the packet.
(3) For each channel, save the result of the last call that was in
progress on that channel in conn->channels[] so that the final ACK or
ABORT packet can be replayed if necessary. Any call earlier than that
is just ignored. If we've seen the next call number in a packet, the
last one is most definitely defunct.
(4) When generating a RESPONSE packet for a connection, the call number
counter for each channel must be included in it.
(5) When parsing a RESPONSE packet for a connection, the call number
counters contained therein should be used to set the minimum expected
call numbers on each channel.
To do in future commits:
(1) Replay terminal packets based on the last call stored in
conn->channels[].
(2) Connections should be retired before the callNumber space on any
channel runs out.
(3) A server is expected to disregard or reject any new incoming call that
has a call number less than the current call number counter. The call
number counter for that channel must be advanced to the new call
number.
Note that the server cannot just require that the next call that it
sees on a channel be exactly the call number counter + 1 because then
there's a scenario that could cause a problem: The client transmits a
packet to initiate a connection, the network goes out, the server
sends an ACK (which gets lost), the client sends an ABORT (which also
gets lost); the network then reconnects, the client then reuses the
call number for the next call (it doesn't know the server already saw
the call number), but the server thinks it already has the first
packet of this call (it doesn't know that the client doesn't know that
it saw the call number the first time).
Signed-off-by: David Howells <dhowells@redhat.com>
2016-06-27 21:39:44 +08:00
|
|
|
"UDP %-22.22s %-22.22s %4x %08x %s %3u"
|
2007-04-27 06:48:28 +08:00
|
|
|
" %s %08x %08x %08x\n",
|
|
|
|
lbuff,
|
|
|
|
rbuff,
|
2016-04-04 21:00:36 +08:00
|
|
|
conn->params.service_id,
|
|
|
|
conn->proto.cid,
|
|
|
|
rxrpc_conn_is_service(conn) ? "Svc" : "Clt",
|
2007-04-27 06:48:28 +08:00
|
|
|
atomic_read(&conn->usage),
|
|
|
|
rxrpc_conn_states[conn->state],
|
2016-04-04 21:00:36 +08:00
|
|
|
key_serial(conn->params.key),
|
2007-04-27 06:48:28 +08:00
|
|
|
atomic_read(&conn->serial),
|
2016-08-23 22:27:25 +08:00
|
|
|
conn->hi_serial);
|
2007-04-27 06:48:28 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-07-11 14:07:31 +08:00
|
|
|
static const struct seq_operations rxrpc_connection_seq_ops = {
|
2007-04-27 06:48:28 +08:00
|
|
|
.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);
|
|
|
|
}
|
|
|
|
|
2008-01-31 10:55:45 +08:00
|
|
|
const struct file_operations rxrpc_connection_seq_fops = {
|
2007-04-27 06:48:28 +08:00
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.open = rxrpc_connection_seq_open,
|
|
|
|
.read = seq_read,
|
|
|
|
.llseek = seq_lseek,
|
2008-03-01 03:39:17 +08:00
|
|
|
.release = seq_release,
|
2007-04-27 06:48:28 +08:00
|
|
|
};
|