2007-04-27 06:48:28 +08:00
|
|
|
/* connection-level event handling
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2016-06-03 03:08:52 +08:00
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
|
2007-04-27 06:48:28 +08:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/net.h>
|
|
|
|
#include <linux/skbuff.h>
|
|
|
|
#include <linux/errqueue.h>
|
|
|
|
#include <linux/udp.h>
|
|
|
|
#include <linux/in.h>
|
|
|
|
#include <linux/in6.h>
|
|
|
|
#include <linux/icmp.h>
|
|
|
|
#include <net/sock.h>
|
|
|
|
#include <net/af_rxrpc.h>
|
|
|
|
#include <net/ip.h>
|
|
|
|
#include "ar-internal.h"
|
|
|
|
|
2016-08-23 22:27:25 +08:00
|
|
|
/*
|
|
|
|
* Retransmit terminal ACK or ABORT of the previous call.
|
|
|
|
*/
|
|
|
|
static void rxrpc_conn_retransmit(struct rxrpc_connection *conn,
|
|
|
|
struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
|
|
|
|
struct rxrpc_channel *chan;
|
|
|
|
struct msghdr msg;
|
|
|
|
struct kvec iov;
|
|
|
|
struct {
|
|
|
|
struct rxrpc_wire_header whdr;
|
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
__be32 code;
|
|
|
|
} abort;
|
|
|
|
struct {
|
|
|
|
struct rxrpc_ackpacket ack;
|
2016-08-24 20:06:14 +08:00
|
|
|
u8 padding[3];
|
2016-08-23 22:27:25 +08:00
|
|
|
struct rxrpc_ackinfo info;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
} __attribute__((packed)) pkt;
|
|
|
|
size_t len;
|
|
|
|
u32 serial, mtu, call_id;
|
|
|
|
|
|
|
|
_enter("%d", conn->debug_id);
|
|
|
|
|
|
|
|
chan = &conn->channels[sp->hdr.cid & RXRPC_CHANNELMASK];
|
|
|
|
|
|
|
|
/* If the last call got moved on whilst we were waiting to run, just
|
|
|
|
* ignore this packet.
|
|
|
|
*/
|
|
|
|
call_id = READ_ONCE(chan->last_call);
|
|
|
|
/* Sync with __rxrpc_disconnect_call() */
|
|
|
|
smp_rmb();
|
|
|
|
if (call_id != sp->hdr.callNumber)
|
|
|
|
return;
|
|
|
|
|
|
|
|
msg.msg_name = &conn->params.peer->srx.transport;
|
|
|
|
msg.msg_namelen = conn->params.peer->srx.transport_len;
|
|
|
|
msg.msg_control = NULL;
|
|
|
|
msg.msg_controllen = 0;
|
|
|
|
msg.msg_flags = 0;
|
|
|
|
|
|
|
|
pkt.whdr.epoch = htonl(sp->hdr.epoch);
|
|
|
|
pkt.whdr.cid = htonl(sp->hdr.cid);
|
|
|
|
pkt.whdr.callNumber = htonl(sp->hdr.callNumber);
|
|
|
|
pkt.whdr.seq = 0;
|
|
|
|
pkt.whdr.type = chan->last_type;
|
|
|
|
pkt.whdr.flags = conn->out_clientflag;
|
|
|
|
pkt.whdr.userStatus = 0;
|
|
|
|
pkt.whdr.securityIndex = conn->security_ix;
|
|
|
|
pkt.whdr._rsvd = 0;
|
|
|
|
pkt.whdr.serviceId = htons(chan->last_service_id);
|
|
|
|
|
|
|
|
len = sizeof(pkt.whdr);
|
|
|
|
switch (chan->last_type) {
|
|
|
|
case RXRPC_PACKET_TYPE_ABORT:
|
|
|
|
pkt.abort.code = htonl(chan->last_abort);
|
|
|
|
len += sizeof(pkt.abort);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RXRPC_PACKET_TYPE_ACK:
|
|
|
|
mtu = conn->params.peer->if_mtu;
|
|
|
|
mtu -= conn->params.peer->hdrsize;
|
|
|
|
pkt.ack.bufferSpace = 0;
|
|
|
|
pkt.ack.maxSkew = htons(skb->priority);
|
|
|
|
pkt.ack.firstPacket = htonl(chan->last_seq);
|
|
|
|
pkt.ack.previousPacket = htonl(chan->last_seq - 1);
|
|
|
|
pkt.ack.serial = htonl(sp->hdr.serial);
|
|
|
|
pkt.ack.reason = RXRPC_ACK_DUPLICATE;
|
|
|
|
pkt.ack.nAcks = 0;
|
|
|
|
pkt.info.rxMTU = htonl(rxrpc_rx_mtu);
|
|
|
|
pkt.info.maxMTU = htonl(mtu);
|
|
|
|
pkt.info.rwind = htonl(rxrpc_rx_window_size);
|
|
|
|
pkt.info.jumbo_max = htonl(rxrpc_rx_jumbo_max);
|
|
|
|
len += sizeof(pkt.ack) + sizeof(pkt.info);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Resync with __rxrpc_disconnect_call() and check that the last call
|
|
|
|
* didn't get advanced whilst we were filling out the packets.
|
|
|
|
*/
|
|
|
|
smp_rmb();
|
|
|
|
if (READ_ONCE(chan->last_call) != call_id)
|
|
|
|
return;
|
|
|
|
|
|
|
|
iov.iov_base = &pkt;
|
|
|
|
iov.iov_len = len;
|
|
|
|
|
|
|
|
serial = atomic_inc_return(&conn->serial);
|
|
|
|
pkt.whdr.serial = htonl(serial);
|
|
|
|
|
|
|
|
switch (chan->last_type) {
|
|
|
|
case RXRPC_PACKET_TYPE_ABORT:
|
|
|
|
_proto("Tx ABORT %%%u { %d } [re]", serial, conn->local_abort);
|
|
|
|
break;
|
|
|
|
case RXRPC_PACKET_TYPE_ACK:
|
|
|
|
_proto("Tx ACK %%%u [re]", serial);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
kernel_sendmsg(conn->params.local->socket, &msg, &iov, 1, len);
|
|
|
|
_leave("");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-04-27 06:48:28 +08:00
|
|
|
/*
|
|
|
|
* pass a connection-level abort onto all calls on that connection
|
|
|
|
*/
|
|
|
|
static void rxrpc_abort_calls(struct rxrpc_connection *conn, int state,
|
|
|
|
u32 abort_code)
|
|
|
|
{
|
|
|
|
struct rxrpc_call *call;
|
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
|
|
|
int i;
|
2007-04-27 06:48:28 +08:00
|
|
|
|
|
|
|
_enter("{%d},%x", conn->debug_id, abort_code);
|
|
|
|
|
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
|
|
|
spin_lock(&conn->channel_lock);
|
2007-04-27 06:48:28 +08:00
|
|
|
|
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
|
|
|
for (i = 0; i < RXRPC_MAXCALLS; i++) {
|
|
|
|
call = rcu_dereference_protected(
|
|
|
|
conn->channels[i].call,
|
|
|
|
lockdep_is_held(&conn->channel_lock));
|
2016-08-30 16:49:28 +08:00
|
|
|
if (call) {
|
|
|
|
write_lock_bh(&call->state_lock);
|
|
|
|
if (call->state <= RXRPC_CALL_COMPLETE) {
|
|
|
|
call->state = state;
|
|
|
|
if (state == RXRPC_CALL_LOCALLY_ABORTED) {
|
|
|
|
call->local_abort = conn->local_abort;
|
|
|
|
set_bit(RXRPC_CALL_EV_CONN_ABORT,
|
|
|
|
&call->events);
|
|
|
|
} else {
|
|
|
|
call->remote_abort = conn->remote_abort;
|
|
|
|
set_bit(RXRPC_CALL_EV_RCVD_ABORT,
|
|
|
|
&call->events);
|
|
|
|
}
|
|
|
|
rxrpc_queue_call(call);
|
2016-04-08 00:23:30 +08:00
|
|
|
}
|
2016-08-30 16:49:28 +08:00
|
|
|
write_unlock_bh(&call->state_lock);
|
2007-04-27 06:48:28 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
spin_unlock(&conn->channel_lock);
|
2007-04-27 06:48:28 +08:00
|
|
|
_leave("");
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* generate a connection-level abort
|
|
|
|
*/
|
|
|
|
static int rxrpc_abort_connection(struct rxrpc_connection *conn,
|
|
|
|
u32 error, u32 abort_code)
|
|
|
|
{
|
2016-03-04 23:53:46 +08:00
|
|
|
struct rxrpc_wire_header whdr;
|
2007-04-27 06:48:28 +08:00
|
|
|
struct msghdr msg;
|
|
|
|
struct kvec iov[2];
|
|
|
|
__be32 word;
|
|
|
|
size_t len;
|
2016-03-04 23:53:46 +08:00
|
|
|
u32 serial;
|
2007-04-27 06:48:28 +08:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
_enter("%d,,%u,%u", conn->debug_id, error, abort_code);
|
|
|
|
|
|
|
|
/* generate a connection-level abort */
|
|
|
|
spin_lock_bh(&conn->state_lock);
|
|
|
|
if (conn->state < RXRPC_CONN_REMOTELY_ABORTED) {
|
|
|
|
conn->state = RXRPC_CONN_LOCALLY_ABORTED;
|
|
|
|
conn->error = error;
|
|
|
|
spin_unlock_bh(&conn->state_lock);
|
|
|
|
} else {
|
|
|
|
spin_unlock_bh(&conn->state_lock);
|
|
|
|
_leave(" = 0 [already dead]");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
rxrpc_abort_calls(conn, RXRPC_CALL_LOCALLY_ABORTED, abort_code);
|
|
|
|
|
2016-04-04 21:00:36 +08:00
|
|
|
msg.msg_name = &conn->params.peer->srx.transport;
|
|
|
|
msg.msg_namelen = conn->params.peer->srx.transport_len;
|
2007-04-27 06:48:28 +08:00
|
|
|
msg.msg_control = NULL;
|
|
|
|
msg.msg_controllen = 0;
|
|
|
|
msg.msg_flags = 0;
|
|
|
|
|
2016-04-04 21:00:36 +08:00
|
|
|
whdr.epoch = htonl(conn->proto.epoch);
|
|
|
|
whdr.cid = htonl(conn->proto.cid);
|
2016-03-04 23:53:46 +08:00
|
|
|
whdr.callNumber = 0;
|
|
|
|
whdr.seq = 0;
|
|
|
|
whdr.type = RXRPC_PACKET_TYPE_ABORT;
|
|
|
|
whdr.flags = conn->out_clientflag;
|
|
|
|
whdr.userStatus = 0;
|
|
|
|
whdr.securityIndex = conn->security_ix;
|
|
|
|
whdr._rsvd = 0;
|
2016-04-04 21:00:36 +08:00
|
|
|
whdr.serviceId = htons(conn->params.service_id);
|
2007-04-27 06:48:28 +08:00
|
|
|
|
2016-04-08 00:23:30 +08:00
|
|
|
word = htonl(conn->local_abort);
|
2007-04-27 06:48:28 +08:00
|
|
|
|
2016-03-04 23:53:46 +08:00
|
|
|
iov[0].iov_base = &whdr;
|
|
|
|
iov[0].iov_len = sizeof(whdr);
|
2007-04-27 06:48:28 +08:00
|
|
|
iov[1].iov_base = &word;
|
|
|
|
iov[1].iov_len = sizeof(word);
|
|
|
|
|
|
|
|
len = iov[0].iov_len + iov[1].iov_len;
|
|
|
|
|
2016-03-04 23:53:46 +08:00
|
|
|
serial = atomic_inc_return(&conn->serial);
|
|
|
|
whdr.serial = htonl(serial);
|
2016-04-08 00:23:30 +08:00
|
|
|
_proto("Tx CONN ABORT %%%u { %d }", serial, conn->local_abort);
|
2007-04-27 06:48:28 +08:00
|
|
|
|
2016-04-04 21:00:36 +08:00
|
|
|
ret = kernel_sendmsg(conn->params.local->socket, &msg, iov, 2, len);
|
2007-04-27 06:48:28 +08:00
|
|
|
if (ret < 0) {
|
|
|
|
_debug("sendmsg failed: %d", ret);
|
|
|
|
return -EAGAIN;
|
|
|
|
}
|
|
|
|
|
|
|
|
_leave(" = 0");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* mark a call as being on a now-secured channel
|
|
|
|
* - must be called with softirqs disabled
|
|
|
|
*/
|
2008-12-11 07:18:31 +08:00
|
|
|
static void rxrpc_call_is_secure(struct rxrpc_call *call)
|
2007-04-27 06:48:28 +08:00
|
|
|
{
|
|
|
|
_enter("%p", call);
|
|
|
|
if (call) {
|
|
|
|
read_lock(&call->state_lock);
|
|
|
|
if (call->state < RXRPC_CALL_COMPLETE &&
|
2016-03-04 23:53:46 +08:00
|
|
|
!test_and_set_bit(RXRPC_CALL_EV_SECURED, &call->events))
|
[AF_RXRPC]: Add an interface to the AF_RXRPC module for the AFS filesystem to use
Add an interface to the AF_RXRPC module so that the AFS filesystem module can
more easily make use of the services available. AFS still opens a socket but
then uses the action functions in lieu of sendmsg() and registers an intercept
functions to grab messages before they're queued on the socket Rx queue.
This permits AFS (or whatever) to:
(1) Avoid the overhead of using the recvmsg() call.
(2) Use different keys directly on individual client calls on one socket
rather than having to open a whole slew of sockets, one for each key it
might want to use.
(3) Avoid calling request_key() at the point of issue of a call or opening of
a socket. This is done instead by AFS at the point of open(), unlink() or
other VFS operation and the key handed through.
(4) Request the use of something other than GFP_KERNEL to allocate memory.
Furthermore:
(*) The socket buffer markings used by RxRPC are made available for AFS so
that it can interpret the cooked RxRPC messages itself.
(*) rxgen (un)marshalling abort codes are made available.
The following documentation for the kernel interface is added to
Documentation/networking/rxrpc.txt:
=========================
AF_RXRPC KERNEL INTERFACE
=========================
The AF_RXRPC module also provides an interface for use by in-kernel utilities
such as the AFS filesystem. This permits such a utility to:
(1) Use different keys directly on individual client calls on one socket
rather than having to open a whole slew of sockets, one for each key it
might want to use.
(2) Avoid having RxRPC call request_key() at the point of issue of a call or
opening of a socket. Instead the utility is responsible for requesting a
key at the appropriate point. AFS, for instance, would do this during VFS
operations such as open() or unlink(). The key is then handed through
when the call is initiated.
(3) Request the use of something other than GFP_KERNEL to allocate memory.
(4) Avoid the overhead of using the recvmsg() call. RxRPC messages can be
intercepted before they get put into the socket Rx queue and the socket
buffers manipulated directly.
To use the RxRPC facility, a kernel utility must still open an AF_RXRPC socket,
bind an addess as appropriate and listen if it's to be a server socket, but
then it passes this to the kernel interface functions.
The kernel interface functions are as follows:
(*) Begin a new client call.
struct rxrpc_call *
rxrpc_kernel_begin_call(struct socket *sock,
struct sockaddr_rxrpc *srx,
struct key *key,
unsigned long user_call_ID,
gfp_t gfp);
This allocates the infrastructure to make a new RxRPC call and assigns
call and connection numbers. The call will be made on the UDP port that
the socket is bound to. The call will go to the destination address of a
connected client socket unless an alternative is supplied (srx is
non-NULL).
If a key is supplied then this will be used to secure the call instead of
the key bound to the socket with the RXRPC_SECURITY_KEY sockopt. Calls
secured in this way will still share connections if at all possible.
The user_call_ID is equivalent to that supplied to sendmsg() in the
control data buffer. It is entirely feasible to use this to point to a
kernel data structure.
If this function is successful, an opaque reference to the RxRPC call is
returned. The caller now holds a reference on this and it must be
properly ended.
(*) End a client call.
void rxrpc_kernel_end_call(struct rxrpc_call *call);
This is used to end a previously begun call. The user_call_ID is expunged
from AF_RXRPC's knowledge and will not be seen again in association with
the specified call.
(*) Send data through a call.
int rxrpc_kernel_send_data(struct rxrpc_call *call, struct msghdr *msg,
size_t len);
This is used to supply either the request part of a client call or the
reply part of a server call. msg.msg_iovlen and msg.msg_iov specify the
data buffers to be used. msg_iov may not be NULL and must point
exclusively to in-kernel virtual addresses. msg.msg_flags may be given
MSG_MORE if there will be subsequent data sends for this call.
The msg must not specify a destination address, control data or any flags
other than MSG_MORE. len is the total amount of data to transmit.
(*) Abort a call.
void rxrpc_kernel_abort_call(struct rxrpc_call *call, u32 abort_code);
This is used to abort a call if it's still in an abortable state. The
abort code specified will be placed in the ABORT message sent.
(*) Intercept received RxRPC messages.
typedef void (*rxrpc_interceptor_t)(struct sock *sk,
unsigned long user_call_ID,
struct sk_buff *skb);
void
rxrpc_kernel_intercept_rx_messages(struct socket *sock,
rxrpc_interceptor_t interceptor);
This installs an interceptor function on the specified AF_RXRPC socket.
All messages that would otherwise wind up in the socket's Rx queue are
then diverted to this function. Note that care must be taken to process
the messages in the right order to maintain DATA message sequentiality.
The interceptor function itself is provided with the address of the socket
and handling the incoming message, the ID assigned by the kernel utility
to the call and the socket buffer containing the message.
The skb->mark field indicates the type of message:
MARK MEANING
=============================== =======================================
RXRPC_SKB_MARK_DATA Data message
RXRPC_SKB_MARK_FINAL_ACK Final ACK received for an incoming call
RXRPC_SKB_MARK_BUSY Client call rejected as server busy
RXRPC_SKB_MARK_REMOTE_ABORT Call aborted by peer
RXRPC_SKB_MARK_NET_ERROR Network error detected
RXRPC_SKB_MARK_LOCAL_ERROR Local error encountered
RXRPC_SKB_MARK_NEW_CALL New incoming call awaiting acceptance
The remote abort message can be probed with rxrpc_kernel_get_abort_code().
The two error messages can be probed with rxrpc_kernel_get_error_number().
A new call can be accepted with rxrpc_kernel_accept_call().
Data messages can have their contents extracted with the usual bunch of
socket buffer manipulation functions. A data message can be determined to
be the last one in a sequence with rxrpc_kernel_is_data_last(). When a
data message has been used up, rxrpc_kernel_data_delivered() should be
called on it..
Non-data messages should be handled to rxrpc_kernel_free_skb() to dispose
of. It is possible to get extra refs on all types of message for later
freeing, but this may pin the state of a call until the message is finally
freed.
(*) Accept an incoming call.
struct rxrpc_call *
rxrpc_kernel_accept_call(struct socket *sock,
unsigned long user_call_ID);
This is used to accept an incoming call and to assign it a call ID. This
function is similar to rxrpc_kernel_begin_call() and calls accepted must
be ended in the same way.
If this function is successful, an opaque reference to the RxRPC call is
returned. The caller now holds a reference on this and it must be
properly ended.
(*) Reject an incoming call.
int rxrpc_kernel_reject_call(struct socket *sock);
This is used to reject the first incoming call on the socket's queue with
a BUSY message. -ENODATA is returned if there were no incoming calls.
Other errors may be returned if the call had been aborted (-ECONNABORTED)
or had timed out (-ETIME).
(*) Record the delivery of a data message and free it.
void rxrpc_kernel_data_delivered(struct sk_buff *skb);
This is used to record a data message as having been delivered and to
update the ACK state for the call. The socket buffer will be freed.
(*) Free a message.
void rxrpc_kernel_free_skb(struct sk_buff *skb);
This is used to free a non-DATA socket buffer intercepted from an AF_RXRPC
socket.
(*) Determine if a data message is the last one on a call.
bool rxrpc_kernel_is_data_last(struct sk_buff *skb);
This is used to determine if a socket buffer holds the last data message
to be received for a call (true will be returned if it does, false
if not).
The data message will be part of the reply on a client call and the
request on an incoming call. In the latter case there will be more
messages, but in the former case there will not.
(*) Get the abort code from an abort message.
u32 rxrpc_kernel_get_abort_code(struct sk_buff *skb);
This is used to extract the abort code from a remote abort message.
(*) Get the error number from a local or network error message.
int rxrpc_kernel_get_error_number(struct sk_buff *skb);
This is used to extract the error number from a message indicating either
a local error occurred or a network error occurred.
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-04-27 06:50:17 +08:00
|
|
|
rxrpc_queue_call(call);
|
2007-04-27 06:48:28 +08:00
|
|
|
read_unlock(&call->state_lock);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* connection-level Rx packet processor
|
|
|
|
*/
|
|
|
|
static int rxrpc_process_event(struct rxrpc_connection *conn,
|
|
|
|
struct sk_buff *skb,
|
|
|
|
u32 *_abort_code)
|
|
|
|
{
|
|
|
|
struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
|
2016-03-04 23:53:46 +08:00
|
|
|
__be32 wtmp;
|
|
|
|
u32 abort_code;
|
2007-04-27 06:48:28 +08:00
|
|
|
int loop, ret;
|
|
|
|
|
2009-06-17 04:36:44 +08:00
|
|
|
if (conn->state >= RXRPC_CONN_REMOTELY_ABORTED) {
|
|
|
|
kleave(" = -ECONNABORTED [%u]", conn->state);
|
2007-04-27 06:48:28 +08:00
|
|
|
return -ECONNABORTED;
|
2009-06-17 04:36:44 +08:00
|
|
|
}
|
2007-04-27 06:48:28 +08:00
|
|
|
|
2016-03-04 23:53:46 +08:00
|
|
|
_enter("{%d},{%u,%%%u},", conn->debug_id, sp->hdr.type, sp->hdr.serial);
|
2009-06-17 04:36:44 +08:00
|
|
|
|
2007-04-27 06:48:28 +08:00
|
|
|
switch (sp->hdr.type) {
|
2016-08-23 22:27:25 +08:00
|
|
|
case RXRPC_PACKET_TYPE_DATA:
|
|
|
|
case RXRPC_PACKET_TYPE_ACK:
|
|
|
|
rxrpc_conn_retransmit(conn, skb);
|
|
|
|
rxrpc_free_skb(skb);
|
|
|
|
return 0;
|
|
|
|
|
2007-04-27 06:48:28 +08:00
|
|
|
case RXRPC_PACKET_TYPE_ABORT:
|
2016-03-04 23:53:46 +08:00
|
|
|
if (skb_copy_bits(skb, 0, &wtmp, sizeof(wtmp)) < 0)
|
2007-04-27 06:48:28 +08:00
|
|
|
return -EPROTO;
|
2016-03-04 23:53:46 +08:00
|
|
|
abort_code = ntohl(wtmp);
|
|
|
|
_proto("Rx ABORT %%%u { ac=%d }", sp->hdr.serial, abort_code);
|
2007-04-27 06:48:28 +08:00
|
|
|
|
|
|
|
conn->state = RXRPC_CONN_REMOTELY_ABORTED;
|
|
|
|
rxrpc_abort_calls(conn, RXRPC_CALL_REMOTELY_ABORTED,
|
2016-03-04 23:53:46 +08:00
|
|
|
abort_code);
|
2007-04-27 06:48:28 +08:00
|
|
|
return -ECONNABORTED;
|
|
|
|
|
|
|
|
case RXRPC_PACKET_TYPE_CHALLENGE:
|
2016-04-08 00:23:58 +08:00
|
|
|
return conn->security->respond_to_challenge(conn, skb,
|
|
|
|
_abort_code);
|
2007-04-27 06:48:28 +08:00
|
|
|
|
|
|
|
case RXRPC_PACKET_TYPE_RESPONSE:
|
|
|
|
ret = conn->security->verify_response(conn, skb, _abort_code);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = conn->security->init_connection_security(conn);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
2016-06-27 05:55:24 +08:00
|
|
|
ret = conn->security->prime_packet_security(conn);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
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
|
|
|
spin_lock(&conn->channel_lock);
|
2007-04-27 06:48:28 +08:00
|
|
|
spin_lock(&conn->state_lock);
|
|
|
|
|
2016-06-27 17:32:02 +08:00
|
|
|
if (conn->state == RXRPC_CONN_SERVICE_CHALLENGING) {
|
|
|
|
conn->state = RXRPC_CONN_SERVICE;
|
2007-04-27 06:48:28 +08:00
|
|
|
for (loop = 0; loop < RXRPC_MAXCALLS; loop++)
|
2016-06-28 00:11:19 +08:00
|
|
|
rxrpc_call_is_secure(
|
|
|
|
rcu_dereference_protected(
|
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
|
|
|
conn->channels[loop].call,
|
|
|
|
lockdep_is_held(&conn->channel_lock)));
|
2007-04-27 06:48:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
spin_unlock(&conn->state_lock);
|
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
|
|
|
spin_unlock(&conn->channel_lock);
|
2007-04-27 06:48:28 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
default:
|
2009-06-17 04:36:44 +08:00
|
|
|
_leave(" = -EPROTO [%u]", sp->hdr.type);
|
2007-04-27 06:48:28 +08:00
|
|
|
return -EPROTO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* set up security and issue a challenge
|
|
|
|
*/
|
|
|
|
static void rxrpc_secure_connection(struct rxrpc_connection *conn)
|
|
|
|
{
|
|
|
|
u32 abort_code;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
_enter("{%d}", conn->debug_id);
|
|
|
|
|
|
|
|
ASSERT(conn->security_ix != 0);
|
|
|
|
|
2016-04-04 21:00:36 +08:00
|
|
|
if (!conn->params.key) {
|
2007-04-27 06:48:28 +08:00
|
|
|
_debug("set up security");
|
|
|
|
ret = rxrpc_init_server_conn_security(conn);
|
|
|
|
switch (ret) {
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
case -ENOENT:
|
|
|
|
abort_code = RX_CALL_DEAD;
|
|
|
|
goto abort;
|
|
|
|
default:
|
|
|
|
abort_code = RXKADNOAUTH;
|
|
|
|
goto abort;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (conn->security->issue_challenge(conn) < 0) {
|
|
|
|
abort_code = RX_CALL_DEAD;
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto abort;
|
|
|
|
}
|
|
|
|
|
|
|
|
_leave("");
|
|
|
|
return;
|
|
|
|
|
|
|
|
abort:
|
|
|
|
_debug("abort %d, %d", ret, abort_code);
|
|
|
|
rxrpc_abort_connection(conn, -ret, abort_code);
|
|
|
|
_leave(" [aborted]");
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* connection-level event processor
|
|
|
|
*/
|
|
|
|
void rxrpc_process_connection(struct work_struct *work)
|
|
|
|
{
|
|
|
|
struct rxrpc_connection *conn =
|
|
|
|
container_of(work, struct rxrpc_connection, processor);
|
|
|
|
struct sk_buff *skb;
|
|
|
|
u32 abort_code = RX_PROTOCOL_ERROR;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
_enter("{%d}", conn->debug_id);
|
|
|
|
|
2016-06-27 17:32:03 +08:00
|
|
|
if (test_and_clear_bit(RXRPC_CONN_EV_CHALLENGE, &conn->events))
|
2007-04-27 06:48:28 +08:00
|
|
|
rxrpc_secure_connection(conn);
|
|
|
|
|
|
|
|
/* go through the conn-level event packets, releasing the ref on this
|
|
|
|
* connection that each one has when we've finished with it */
|
|
|
|
while ((skb = skb_dequeue(&conn->rx_queue))) {
|
2016-08-23 22:27:24 +08:00
|
|
|
rxrpc_see_skb(skb);
|
2007-04-27 06:48:28 +08:00
|
|
|
ret = rxrpc_process_event(conn, skb, &abort_code);
|
|
|
|
switch (ret) {
|
|
|
|
case -EPROTO:
|
|
|
|
case -EKEYEXPIRED:
|
|
|
|
case -EKEYREJECTED:
|
|
|
|
goto protocol_error;
|
|
|
|
case -EAGAIN:
|
|
|
|
goto requeue_and_leave;
|
|
|
|
case -ECONNABORTED:
|
|
|
|
default:
|
|
|
|
rxrpc_free_skb(skb);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
rxrpc_put_connection(conn);
|
|
|
|
_leave("");
|
|
|
|
return;
|
|
|
|
|
|
|
|
requeue_and_leave:
|
|
|
|
skb_queue_head(&conn->rx_queue, skb);
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
protocol_error:
|
|
|
|
if (rxrpc_abort_connection(conn, -ret, abort_code) < 0)
|
|
|
|
goto requeue_and_leave;
|
|
|
|
rxrpc_free_skb(skb);
|
|
|
|
_leave(" [EPROTO]");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
[AF_RXRPC]: Add an interface to the AF_RXRPC module for the AFS filesystem to use
Add an interface to the AF_RXRPC module so that the AFS filesystem module can
more easily make use of the services available. AFS still opens a socket but
then uses the action functions in lieu of sendmsg() and registers an intercept
functions to grab messages before they're queued on the socket Rx queue.
This permits AFS (or whatever) to:
(1) Avoid the overhead of using the recvmsg() call.
(2) Use different keys directly on individual client calls on one socket
rather than having to open a whole slew of sockets, one for each key it
might want to use.
(3) Avoid calling request_key() at the point of issue of a call or opening of
a socket. This is done instead by AFS at the point of open(), unlink() or
other VFS operation and the key handed through.
(4) Request the use of something other than GFP_KERNEL to allocate memory.
Furthermore:
(*) The socket buffer markings used by RxRPC are made available for AFS so
that it can interpret the cooked RxRPC messages itself.
(*) rxgen (un)marshalling abort codes are made available.
The following documentation for the kernel interface is added to
Documentation/networking/rxrpc.txt:
=========================
AF_RXRPC KERNEL INTERFACE
=========================
The AF_RXRPC module also provides an interface for use by in-kernel utilities
such as the AFS filesystem. This permits such a utility to:
(1) Use different keys directly on individual client calls on one socket
rather than having to open a whole slew of sockets, one for each key it
might want to use.
(2) Avoid having RxRPC call request_key() at the point of issue of a call or
opening of a socket. Instead the utility is responsible for requesting a
key at the appropriate point. AFS, for instance, would do this during VFS
operations such as open() or unlink(). The key is then handed through
when the call is initiated.
(3) Request the use of something other than GFP_KERNEL to allocate memory.
(4) Avoid the overhead of using the recvmsg() call. RxRPC messages can be
intercepted before they get put into the socket Rx queue and the socket
buffers manipulated directly.
To use the RxRPC facility, a kernel utility must still open an AF_RXRPC socket,
bind an addess as appropriate and listen if it's to be a server socket, but
then it passes this to the kernel interface functions.
The kernel interface functions are as follows:
(*) Begin a new client call.
struct rxrpc_call *
rxrpc_kernel_begin_call(struct socket *sock,
struct sockaddr_rxrpc *srx,
struct key *key,
unsigned long user_call_ID,
gfp_t gfp);
This allocates the infrastructure to make a new RxRPC call and assigns
call and connection numbers. The call will be made on the UDP port that
the socket is bound to. The call will go to the destination address of a
connected client socket unless an alternative is supplied (srx is
non-NULL).
If a key is supplied then this will be used to secure the call instead of
the key bound to the socket with the RXRPC_SECURITY_KEY sockopt. Calls
secured in this way will still share connections if at all possible.
The user_call_ID is equivalent to that supplied to sendmsg() in the
control data buffer. It is entirely feasible to use this to point to a
kernel data structure.
If this function is successful, an opaque reference to the RxRPC call is
returned. The caller now holds a reference on this and it must be
properly ended.
(*) End a client call.
void rxrpc_kernel_end_call(struct rxrpc_call *call);
This is used to end a previously begun call. The user_call_ID is expunged
from AF_RXRPC's knowledge and will not be seen again in association with
the specified call.
(*) Send data through a call.
int rxrpc_kernel_send_data(struct rxrpc_call *call, struct msghdr *msg,
size_t len);
This is used to supply either the request part of a client call or the
reply part of a server call. msg.msg_iovlen and msg.msg_iov specify the
data buffers to be used. msg_iov may not be NULL and must point
exclusively to in-kernel virtual addresses. msg.msg_flags may be given
MSG_MORE if there will be subsequent data sends for this call.
The msg must not specify a destination address, control data or any flags
other than MSG_MORE. len is the total amount of data to transmit.
(*) Abort a call.
void rxrpc_kernel_abort_call(struct rxrpc_call *call, u32 abort_code);
This is used to abort a call if it's still in an abortable state. The
abort code specified will be placed in the ABORT message sent.
(*) Intercept received RxRPC messages.
typedef void (*rxrpc_interceptor_t)(struct sock *sk,
unsigned long user_call_ID,
struct sk_buff *skb);
void
rxrpc_kernel_intercept_rx_messages(struct socket *sock,
rxrpc_interceptor_t interceptor);
This installs an interceptor function on the specified AF_RXRPC socket.
All messages that would otherwise wind up in the socket's Rx queue are
then diverted to this function. Note that care must be taken to process
the messages in the right order to maintain DATA message sequentiality.
The interceptor function itself is provided with the address of the socket
and handling the incoming message, the ID assigned by the kernel utility
to the call and the socket buffer containing the message.
The skb->mark field indicates the type of message:
MARK MEANING
=============================== =======================================
RXRPC_SKB_MARK_DATA Data message
RXRPC_SKB_MARK_FINAL_ACK Final ACK received for an incoming call
RXRPC_SKB_MARK_BUSY Client call rejected as server busy
RXRPC_SKB_MARK_REMOTE_ABORT Call aborted by peer
RXRPC_SKB_MARK_NET_ERROR Network error detected
RXRPC_SKB_MARK_LOCAL_ERROR Local error encountered
RXRPC_SKB_MARK_NEW_CALL New incoming call awaiting acceptance
The remote abort message can be probed with rxrpc_kernel_get_abort_code().
The two error messages can be probed with rxrpc_kernel_get_error_number().
A new call can be accepted with rxrpc_kernel_accept_call().
Data messages can have their contents extracted with the usual bunch of
socket buffer manipulation functions. A data message can be determined to
be the last one in a sequence with rxrpc_kernel_is_data_last(). When a
data message has been used up, rxrpc_kernel_data_delivered() should be
called on it..
Non-data messages should be handled to rxrpc_kernel_free_skb() to dispose
of. It is possible to get extra refs on all types of message for later
freeing, but this may pin the state of a call until the message is finally
freed.
(*) Accept an incoming call.
struct rxrpc_call *
rxrpc_kernel_accept_call(struct socket *sock,
unsigned long user_call_ID);
This is used to accept an incoming call and to assign it a call ID. This
function is similar to rxrpc_kernel_begin_call() and calls accepted must
be ended in the same way.
If this function is successful, an opaque reference to the RxRPC call is
returned. The caller now holds a reference on this and it must be
properly ended.
(*) Reject an incoming call.
int rxrpc_kernel_reject_call(struct socket *sock);
This is used to reject the first incoming call on the socket's queue with
a BUSY message. -ENODATA is returned if there were no incoming calls.
Other errors may be returned if the call had been aborted (-ECONNABORTED)
or had timed out (-ETIME).
(*) Record the delivery of a data message and free it.
void rxrpc_kernel_data_delivered(struct sk_buff *skb);
This is used to record a data message as having been delivered and to
update the ACK state for the call. The socket buffer will be freed.
(*) Free a message.
void rxrpc_kernel_free_skb(struct sk_buff *skb);
This is used to free a non-DATA socket buffer intercepted from an AF_RXRPC
socket.
(*) Determine if a data message is the last one on a call.
bool rxrpc_kernel_is_data_last(struct sk_buff *skb);
This is used to determine if a socket buffer holds the last data message
to be received for a call (true will be returned if it does, false
if not).
The data message will be part of the reply on a client call and the
request on an incoming call. In the latter case there will be more
messages, but in the former case there will not.
(*) Get the abort code from an abort message.
u32 rxrpc_kernel_get_abort_code(struct sk_buff *skb);
This is used to extract the abort code from a remote abort message.
(*) Get the error number from a local or network error message.
int rxrpc_kernel_get_error_number(struct sk_buff *skb);
This is used to extract the error number from a message indicating either
a local error occurred or a network error occurred.
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-04-27 06:50:17 +08:00
|
|
|
/*
|
|
|
|
* put a packet up for transport-level abort
|
|
|
|
*/
|
|
|
|
void rxrpc_reject_packet(struct rxrpc_local *local, struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
CHECK_SLAB_OKAY(&local->usage);
|
|
|
|
|
|
|
|
skb_queue_tail(&local->reject_queue, skb);
|
2016-06-27 17:32:02 +08:00
|
|
|
rxrpc_queue_local(local);
|
[AF_RXRPC]: Add an interface to the AF_RXRPC module for the AFS filesystem to use
Add an interface to the AF_RXRPC module so that the AFS filesystem module can
more easily make use of the services available. AFS still opens a socket but
then uses the action functions in lieu of sendmsg() and registers an intercept
functions to grab messages before they're queued on the socket Rx queue.
This permits AFS (or whatever) to:
(1) Avoid the overhead of using the recvmsg() call.
(2) Use different keys directly on individual client calls on one socket
rather than having to open a whole slew of sockets, one for each key it
might want to use.
(3) Avoid calling request_key() at the point of issue of a call or opening of
a socket. This is done instead by AFS at the point of open(), unlink() or
other VFS operation and the key handed through.
(4) Request the use of something other than GFP_KERNEL to allocate memory.
Furthermore:
(*) The socket buffer markings used by RxRPC are made available for AFS so
that it can interpret the cooked RxRPC messages itself.
(*) rxgen (un)marshalling abort codes are made available.
The following documentation for the kernel interface is added to
Documentation/networking/rxrpc.txt:
=========================
AF_RXRPC KERNEL INTERFACE
=========================
The AF_RXRPC module also provides an interface for use by in-kernel utilities
such as the AFS filesystem. This permits such a utility to:
(1) Use different keys directly on individual client calls on one socket
rather than having to open a whole slew of sockets, one for each key it
might want to use.
(2) Avoid having RxRPC call request_key() at the point of issue of a call or
opening of a socket. Instead the utility is responsible for requesting a
key at the appropriate point. AFS, for instance, would do this during VFS
operations such as open() or unlink(). The key is then handed through
when the call is initiated.
(3) Request the use of something other than GFP_KERNEL to allocate memory.
(4) Avoid the overhead of using the recvmsg() call. RxRPC messages can be
intercepted before they get put into the socket Rx queue and the socket
buffers manipulated directly.
To use the RxRPC facility, a kernel utility must still open an AF_RXRPC socket,
bind an addess as appropriate and listen if it's to be a server socket, but
then it passes this to the kernel interface functions.
The kernel interface functions are as follows:
(*) Begin a new client call.
struct rxrpc_call *
rxrpc_kernel_begin_call(struct socket *sock,
struct sockaddr_rxrpc *srx,
struct key *key,
unsigned long user_call_ID,
gfp_t gfp);
This allocates the infrastructure to make a new RxRPC call and assigns
call and connection numbers. The call will be made on the UDP port that
the socket is bound to. The call will go to the destination address of a
connected client socket unless an alternative is supplied (srx is
non-NULL).
If a key is supplied then this will be used to secure the call instead of
the key bound to the socket with the RXRPC_SECURITY_KEY sockopt. Calls
secured in this way will still share connections if at all possible.
The user_call_ID is equivalent to that supplied to sendmsg() in the
control data buffer. It is entirely feasible to use this to point to a
kernel data structure.
If this function is successful, an opaque reference to the RxRPC call is
returned. The caller now holds a reference on this and it must be
properly ended.
(*) End a client call.
void rxrpc_kernel_end_call(struct rxrpc_call *call);
This is used to end a previously begun call. The user_call_ID is expunged
from AF_RXRPC's knowledge and will not be seen again in association with
the specified call.
(*) Send data through a call.
int rxrpc_kernel_send_data(struct rxrpc_call *call, struct msghdr *msg,
size_t len);
This is used to supply either the request part of a client call or the
reply part of a server call. msg.msg_iovlen and msg.msg_iov specify the
data buffers to be used. msg_iov may not be NULL and must point
exclusively to in-kernel virtual addresses. msg.msg_flags may be given
MSG_MORE if there will be subsequent data sends for this call.
The msg must not specify a destination address, control data or any flags
other than MSG_MORE. len is the total amount of data to transmit.
(*) Abort a call.
void rxrpc_kernel_abort_call(struct rxrpc_call *call, u32 abort_code);
This is used to abort a call if it's still in an abortable state. The
abort code specified will be placed in the ABORT message sent.
(*) Intercept received RxRPC messages.
typedef void (*rxrpc_interceptor_t)(struct sock *sk,
unsigned long user_call_ID,
struct sk_buff *skb);
void
rxrpc_kernel_intercept_rx_messages(struct socket *sock,
rxrpc_interceptor_t interceptor);
This installs an interceptor function on the specified AF_RXRPC socket.
All messages that would otherwise wind up in the socket's Rx queue are
then diverted to this function. Note that care must be taken to process
the messages in the right order to maintain DATA message sequentiality.
The interceptor function itself is provided with the address of the socket
and handling the incoming message, the ID assigned by the kernel utility
to the call and the socket buffer containing the message.
The skb->mark field indicates the type of message:
MARK MEANING
=============================== =======================================
RXRPC_SKB_MARK_DATA Data message
RXRPC_SKB_MARK_FINAL_ACK Final ACK received for an incoming call
RXRPC_SKB_MARK_BUSY Client call rejected as server busy
RXRPC_SKB_MARK_REMOTE_ABORT Call aborted by peer
RXRPC_SKB_MARK_NET_ERROR Network error detected
RXRPC_SKB_MARK_LOCAL_ERROR Local error encountered
RXRPC_SKB_MARK_NEW_CALL New incoming call awaiting acceptance
The remote abort message can be probed with rxrpc_kernel_get_abort_code().
The two error messages can be probed with rxrpc_kernel_get_error_number().
A new call can be accepted with rxrpc_kernel_accept_call().
Data messages can have their contents extracted with the usual bunch of
socket buffer manipulation functions. A data message can be determined to
be the last one in a sequence with rxrpc_kernel_is_data_last(). When a
data message has been used up, rxrpc_kernel_data_delivered() should be
called on it..
Non-data messages should be handled to rxrpc_kernel_free_skb() to dispose
of. It is possible to get extra refs on all types of message for later
freeing, but this may pin the state of a call until the message is finally
freed.
(*) Accept an incoming call.
struct rxrpc_call *
rxrpc_kernel_accept_call(struct socket *sock,
unsigned long user_call_ID);
This is used to accept an incoming call and to assign it a call ID. This
function is similar to rxrpc_kernel_begin_call() and calls accepted must
be ended in the same way.
If this function is successful, an opaque reference to the RxRPC call is
returned. The caller now holds a reference on this and it must be
properly ended.
(*) Reject an incoming call.
int rxrpc_kernel_reject_call(struct socket *sock);
This is used to reject the first incoming call on the socket's queue with
a BUSY message. -ENODATA is returned if there were no incoming calls.
Other errors may be returned if the call had been aborted (-ECONNABORTED)
or had timed out (-ETIME).
(*) Record the delivery of a data message and free it.
void rxrpc_kernel_data_delivered(struct sk_buff *skb);
This is used to record a data message as having been delivered and to
update the ACK state for the call. The socket buffer will be freed.
(*) Free a message.
void rxrpc_kernel_free_skb(struct sk_buff *skb);
This is used to free a non-DATA socket buffer intercepted from an AF_RXRPC
socket.
(*) Determine if a data message is the last one on a call.
bool rxrpc_kernel_is_data_last(struct sk_buff *skb);
This is used to determine if a socket buffer holds the last data message
to be received for a call (true will be returned if it does, false
if not).
The data message will be part of the reply on a client call and the
request on an incoming call. In the latter case there will be more
messages, but in the former case there will not.
(*) Get the abort code from an abort message.
u32 rxrpc_kernel_get_abort_code(struct sk_buff *skb);
This is used to extract the abort code from a remote abort message.
(*) Get the error number from a local or network error message.
int rxrpc_kernel_get_error_number(struct sk_buff *skb);
This is used to extract the error number from a message indicating either
a local error occurred or a network error occurred.
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-04-27 06:50:17 +08:00
|
|
|
}
|
|
|
|
|
2007-04-27 06:48:28 +08:00
|
|
|
/*
|
|
|
|
* reject packets through the local endpoint
|
|
|
|
*/
|
2016-04-04 21:00:35 +08:00
|
|
|
void rxrpc_reject_packets(struct rxrpc_local *local)
|
2007-04-27 06:48:28 +08:00
|
|
|
{
|
|
|
|
union {
|
|
|
|
struct sockaddr sa;
|
|
|
|
struct sockaddr_in sin;
|
|
|
|
} sa;
|
|
|
|
struct rxrpc_skb_priv *sp;
|
2016-03-04 23:53:46 +08:00
|
|
|
struct rxrpc_wire_header whdr;
|
2007-04-27 06:48:28 +08:00
|
|
|
struct sk_buff *skb;
|
|
|
|
struct msghdr msg;
|
|
|
|
struct kvec iov[2];
|
|
|
|
size_t size;
|
|
|
|
__be32 code;
|
|
|
|
|
|
|
|
_enter("%d", local->debug_id);
|
|
|
|
|
2016-03-04 23:53:46 +08:00
|
|
|
iov[0].iov_base = &whdr;
|
|
|
|
iov[0].iov_len = sizeof(whdr);
|
2007-04-27 06:48:28 +08:00
|
|
|
iov[1].iov_base = &code;
|
|
|
|
iov[1].iov_len = sizeof(code);
|
2016-03-04 23:53:46 +08:00
|
|
|
size = sizeof(whdr) + sizeof(code);
|
2007-04-27 06:48:28 +08:00
|
|
|
|
|
|
|
msg.msg_name = &sa;
|
|
|
|
msg.msg_control = NULL;
|
|
|
|
msg.msg_controllen = 0;
|
|
|
|
msg.msg_flags = 0;
|
|
|
|
|
|
|
|
memset(&sa, 0, sizeof(sa));
|
|
|
|
sa.sa.sa_family = local->srx.transport.family;
|
|
|
|
switch (sa.sa.sa_family) {
|
|
|
|
case AF_INET:
|
|
|
|
msg.msg_namelen = sizeof(sa.sin);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
msg.msg_namelen = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-03-04 23:53:46 +08:00
|
|
|
memset(&whdr, 0, sizeof(whdr));
|
|
|
|
whdr.type = RXRPC_PACKET_TYPE_ABORT;
|
2007-04-27 06:48:28 +08:00
|
|
|
|
|
|
|
while ((skb = skb_dequeue(&local->reject_queue))) {
|
2016-08-23 22:27:24 +08:00
|
|
|
rxrpc_see_skb(skb);
|
2007-04-27 06:48:28 +08:00
|
|
|
sp = rxrpc_skb(skb);
|
|
|
|
switch (sa.sa.sa_family) {
|
|
|
|
case AF_INET:
|
|
|
|
sa.sin.sin_port = udp_hdr(skb)->source;
|
|
|
|
sa.sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
|
|
|
|
code = htonl(skb->priority);
|
|
|
|
|
2016-03-04 23:53:46 +08:00
|
|
|
whdr.epoch = htonl(sp->hdr.epoch);
|
|
|
|
whdr.cid = htonl(sp->hdr.cid);
|
|
|
|
whdr.callNumber = htonl(sp->hdr.callNumber);
|
|
|
|
whdr.serviceId = htons(sp->hdr.serviceId);
|
|
|
|
whdr.flags = sp->hdr.flags;
|
|
|
|
whdr.flags ^= RXRPC_CLIENT_INITIATED;
|
|
|
|
whdr.flags &= RXRPC_CLIENT_INITIATED;
|
2007-04-27 06:48:28 +08:00
|
|
|
|
|
|
|
kernel_sendmsg(local->socket, &msg, iov, 2, size);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
rxrpc_free_skb(skb);
|
|
|
|
}
|
|
|
|
|
|
|
|
_leave("");
|
|
|
|
}
|