#include "rx_stats.h"
#include "rx_event.h"
+#include "rx_peer.h"
#include "rx_conn.h"
#include "rx_call.h"
#include "rx_packet.h"
void *unused, int unused2);
static void rxi_ReapConnections(struct rxevent *unused, void *unused1,
void *unused2, int unused3);
+static struct rx_packet *rxi_SendCallAbort(struct rx_call *call,
+ struct rx_packet *packet,
+ int istack, int force);
+static void rxi_AckAll(struct rx_call *call);
+static struct rx_connection
+ *rxi_FindConnection(osi_socket socket, afs_uint32 host, u_short port,
+ u_short serviceId, afs_uint32 cid,
+ afs_uint32 epoch, int type, u_int securityIndex);
+static struct rx_packet
+ *rxi_ReceiveDataPacket(struct rx_call *call, struct rx_packet *np,
+ int istack, osi_socket socket,
+ afs_uint32 host, u_short port, int *tnop,
+ struct rx_call **newcallp);
+static struct rx_packet
+ *rxi_ReceiveAckPacket(struct rx_call *call, struct rx_packet *np,
+ int istack);
+static struct rx_packet
+ *rxi_ReceiveResponsePacket(struct rx_connection *conn,
+ struct rx_packet *np, int istack);
+static struct rx_packet
+ *rxi_ReceiveChallengePacket(struct rx_connection *conn,
+ struct rx_packet *np, int istack);
+static void rxi_AttachServerProc(struct rx_call *call, osi_socket socket,
+ int *tnop, struct rx_call **newcallp);
+static void rxi_ClearTransmitQueue(struct rx_call *call, int force);
+static void rxi_ClearReceiveQueue(struct rx_call *call);
+static void rxi_ResetCall(struct rx_call *call, int newcall);
+static void rxi_ScheduleKeepAliveEvent(struct rx_call *call);
+static void rxi_ScheduleNatKeepAliveEvent(struct rx_connection *conn);
+static void rxi_ScheduleGrowMTUEvent(struct rx_call *call, int secs);
+static void rxi_KeepAliveOn(struct rx_call *call);
+static void rxi_GrowMTUOn(struct rx_call *call);
+static void rxi_ChallengeOn(struct rx_connection *conn);
#ifdef RX_ENABLE_LOCKS
+static int rxi_CheckCall(struct rx_call *call, int haveCTLock);
static void rxi_SetAcksInTransmitQueue(struct rx_call *call);
+#else
+static int rxi_CheckCall(struct rx_call *call);
#endif
#ifdef AFS_GLOBAL_RXLOCK_KERNEL
static unsigned int rxi_rpc_process_stat_cnt;
/*
- * rxi_busyChannelError is the error to return to the application when a call
- * channel appears busy (inferred from the receipt of RX_PACKET_TYPE_BUSY
- * packets on the channel), and there are other call channels in the
- * connection that are not busy. If 0, we do not return errors upon receiving
- * busy packets; we just keep trying on the same call channel until we hit a
- * timeout.
+ * rxi_busyChannelError is a boolean. It indicates whether or not RX_CALL_BUSY
+ * errors should be reported to the application when a call channel appears busy
+ * (inferred from the receipt of RX_PACKET_TYPE_BUSY packets on the channel),
+ * and there are other call channels in the connection that are not busy.
+ * If 0, we do not return errors upon receiving busy packets; we just keep
+ * trying on the same call channel until we hit a timeout.
*/
static afs_int32 rxi_busyChannelError = 0;
}
/**
- * Sets the error generated when a busy call channel is detected.
+ * Enables or disables the busy call channel error (RX_CALL_BUSY).
*
- * @param[in] error The error to return for a call on a busy channel.
+ * @param[in] onoff Non-zero to enable busy call channel errors.
*
* @pre Neither rx_Init nor rx_InitHost have been called yet
*/
void
-rx_SetBusyChannelError(afs_int32 error)
+rx_SetBusyChannelError(afs_int32 onoff)
{
osi_Assert(rxinit_status != 0);
- rxi_busyChannelError = error;
+ rxi_busyChannelError = onoff ? 1 : 0;
}
/**
rx_SetConnIdleDeadTime(struct rx_connection *conn, int seconds)
{
conn->idleDeadTime = seconds;
+ conn->idleDeadDetection = (seconds ? 1 : 0);
rxi_CheckConnTimeouts(conn);
}
|| call->state == RX_STATE_ACTIVE) {
rxi_SendAck(call, 0, 0, RX_ACK_DELAY, 0);
} else {
- rxi_AckAll(NULL, call, 0);
+ rxi_AckAll(call);
}
}
MUTEX_EXIT(&call->lock);
* effect on overall system performance.
*/
call->state = RX_STATE_RESET;
+ (*call->callNumber)++;
MUTEX_EXIT(&conn->conn_call_lock);
CALL_HOLD(call, RX_CALL_REFCOUNT_BEGIN);
rxi_ResetCall(call, 0);
- (*call->callNumber)++;
if (MUTEX_TRYENTER(&conn->conn_call_lock))
break;
}
if (i < RX_MAXCALLS) {
conn->lastBusy[i] = 0;
+ call->flags &= ~RX_CALL_PEER_BUSY;
break;
}
if (!wait)
SPLVAR;
NETPRI;
+ MUTEX_ENTER(&aconn->conn_call_lock);
for (i = 0; i < RX_MAXCALLS; i++) {
if ((tcall = aconn->call[i]) && (tcall->state == RX_STATE_DALLY))
aint32s[i] = aconn->callNumber[i] + 1;
else
aint32s[i] = aconn->callNumber[i];
}
+ MUTEX_EXIT(&aconn->conn_call_lock);
USERPRI;
return 0;
}
SPLVAR;
NETPRI;
+ MUTEX_ENTER(&aconn->conn_call_lock);
for (i = 0; i < RX_MAXCALLS; i++) {
if ((tcall = aconn->call[i]) && (tcall->state == RX_STATE_DALLY))
aconn->callNumber[i] = aint32s[i] - 1;
else
aconn->callNumber[i] = aint32s[i];
}
+ MUTEX_EXIT(&aconn->conn_call_lock);
USERPRI;
return 0;
}
}
MUTEX_ENTER(&rx_pthread_mutex);
if (tno == rxi_fcfs_thread_num
- || !tcall->queue_item_header.next) {
+ || queue_IsLast(&rx_incomingCallQueue, tcall)) {
MUTEX_EXIT(&rx_pthread_mutex);
/* If we're the fcfs thread , then we'll just use
* this call. If we haven't been able to find an optimal
*
* call->lock amd rx_refcnt_mutex are held upon entry.
* haveCTLock is set when called from rxi_ReapConnections.
+ *
+ * return 1 if the call is freed, 0 if not.
*/
-static void
+static int
rxi_FreeCall(struct rx_call *call, int haveCTLock)
{
int channel = call->channel;
struct rx_connection *conn = call->conn;
+ u_char state = call->state;
-
- if (call->state == RX_STATE_DALLY || call->state == RX_STATE_HOLD)
- (*call->callNumber)++;
/*
* We are setting the state to RX_STATE_RESET to
* ensure that no one else will attempt to use this
MUTEX_EXIT(&rx_refcnt_mutex);
rxi_ResetCall(call, 0);
- MUTEX_ENTER(&conn->conn_call_lock);
- if (call->conn->call[channel] == call)
- call->conn->call[channel] = 0;
- MUTEX_EXIT(&conn->conn_call_lock);
+ if (MUTEX_TRYENTER(&conn->conn_call_lock))
+ {
+ if (state == RX_STATE_DALLY || state == RX_STATE_HOLD)
+ (*call->callNumber)++;
+
+ if (call->conn->call[channel] == call)
+ call->conn->call[channel] = 0;
+ MUTEX_EXIT(&conn->conn_call_lock);
+ } else {
+ /*
+ * We couldn't obtain the conn_call_lock so we can't
+ * disconnect the call from the connection. Set the
+ * call state to dally so that the call can be reused.
+ */
+ MUTEX_ENTER(&rx_refcnt_mutex);
+ call->state = RX_STATE_DALLY;
+ return 0;
+ }
MUTEX_ENTER(&rx_freeCallQueue_lock);
SET_CALL_QUEUE_LOCK(call, &rx_freeCallQueue_lock);
MUTEX_EXIT(&conn->conn_data_lock);
}
MUTEX_ENTER(&rx_refcnt_mutex);
+ return 1;
}
rx_atomic_t rxi_Allocsize = RX_ATOMIC_INIT(0);
pp->host = host; /* set here or in InitPeerParams is zero */
pp->port = port;
MUTEX_INIT(&pp->peer_lock, "peer_lock", MUTEX_DEFAULT, 0);
- queue_Init(&pp->congestionQueue);
queue_Init(&pp->rpcStats);
pp->next = rx_peerHashTable[hashIndex];
rx_peerHashTable[hashIndex] = pp;
* parameter must match the existing index for the connection. If a
* server connection is created, it will be created using the supplied
* index, if the index is valid for this service */
-struct rx_connection *
+static struct rx_connection *
rxi_FindConnection(osi_socket socket, afs_uint32 host,
u_short port, u_short serviceId, afs_uint32 cid,
afs_uint32 epoch, int type, u_int securityIndex)
conn->lastSendTime = clock_Sec(); /* don't GC immediately */
conn->epoch = epoch;
conn->cid = cid & RX_CIDMASK;
- /* conn->serial = conn->lastSerial = 0; */
- /* conn->timeout = 0; */
conn->ackRate = RX_FAST_ACK_RATE;
conn->service = service;
conn->serviceId = serviceId;
conn->nSpecific = 0;
conn->specific = NULL;
rx_SetConnDeadTime(conn, service->connDeadTime);
- rx_SetConnIdleDeadTime(conn, service->idleDeadTime);
- rx_SetServerConnIdleDeadErr(conn, service->idleDeadErr);
+ conn->idleDeadTime = service->idleDeadTime;
+ conn->idleDeadDetection = service->idleDeadErr ? 1 : 0;
for (i = 0; i < RX_MAXCALLS; i++) {
conn->twind[i] = rx_initSendWindow;
conn->rwind[i] = rx_initReceiveWindow;
int channel = call->channel;
int freechannel = 0;
int i;
- afs_uint32 callNumber = *call->callNumber;
+ afs_uint32 callNumber;
MUTEX_EXIT(&call->lock);
MUTEX_ENTER(&conn->conn_call_lock);
+ callNumber = *call->callNumber;
/* Are there any other call slots on this conn that we should try? Look for
* slots that are empty and are either non-busy, or were marked as busy
}
}
- MUTEX_EXIT(&conn->conn_call_lock);
-
MUTEX_ENTER(&call->lock);
/* Since the call->lock and conn->conn_call_lock have been released it is
* rxi_busyChannelError so the application can retry the request,
* presumably on a less-busy call channel. */
- rxi_CallError(call, rxi_busyChannelError);
+ rxi_CallError(call, RX_CALL_BUSY);
}
+ MUTEX_EXIT(&conn->conn_call_lock);
}
/* There are two packet tracing routines available for testing and monitoring
int channel;
afs_uint32 currentCallNumber;
int type;
- int skew;
#ifdef RXDEBUG
char *packetType;
#endif
np->header.seq, np->header.flags, np));
#endif
+ /* Account for connectionless packets */
+ if (rx_stats_active &&
+ ((np->header.type == RX_PACKET_TYPE_VERSION) ||
+ (np->header.type == RX_PACKET_TYPE_DEBUG))) {
+ struct rx_peer *peer;
+
+ /* Try to look up the peer structure, but don't create one */
+ peer = rxi_FindPeer(host, port, 0, 0);
+
+ /* Since this may not be associated with a connection, it may have
+ * no refCount, meaning we could race with ReapConnections
+ */
+
+ if (peer && (peer->refCount > 0)) {
+ MUTEX_ENTER(&peer->peer_lock);
+ hadd32(peer->bytesReceived, np->length);
+ MUTEX_EXIT(&peer->peer_lock);
+ }
+ }
+
if (np->header.type == RX_PACKET_TYPE_VERSION) {
return rxi_ReceiveVersionPacket(np, socket, host, port, 1);
}
return np;
}
+ /* If we're doing statistics, then account for the incoming packet */
+ if (rx_stats_active) {
+ MUTEX_ENTER(&conn->peer->peer_lock);
+ hadd32(conn->peer->bytesReceived, np->length);
+ MUTEX_EXIT(&conn->peer->peer_lock);
+ }
+
/* If the connection is in an error state, send an abort packet and ignore
* the incoming packet */
if (conn->error) {
}
channel = np->header.cid & RX_CHANNELMASK;
+ MUTEX_ENTER(&conn->conn_call_lock);
call = conn->call[channel];
if (call) {
MUTEX_ENTER(&call->lock);
currentCallNumber = conn->callNumber[channel];
+ MUTEX_EXIT(&conn->conn_call_lock);
} else if (type == RX_SERVER_CONNECTION) { /* No call allocated */
- MUTEX_ENTER(&conn->conn_call_lock);
call = conn->call[channel];
if (call) {
MUTEX_ENTER(&call->lock);
- MUTEX_EXIT(&conn->conn_call_lock);
currentCallNumber = conn->callNumber[channel];
+ MUTEX_EXIT(&conn->conn_call_lock);
} else {
call = rxi_NewCall(conn, channel); /* returns locked call */
- MUTEX_EXIT(&conn->conn_call_lock);
*call->callNumber = currentCallNumber = np->header.callNumber;
+ MUTEX_EXIT(&conn->conn_call_lock);
#ifdef RXDEBUG
if (np->header.callNumber == 0)
dpf(("RecPacket call 0 %d %s: %x.%u.%u.%u.%u.%u.%u flags %d, packet %"AFS_PTR_FMT" len %d\n",
* then, since this is a client connection we're getting data for
* it must be for the previous call.
*/
+ MUTEX_EXIT(&conn->conn_call_lock);
if (rx_stats_active)
rx_atomic_inc(&rx_stats.spuriousPacketsRead);
putConnection(conn);
return tp;
}
rxi_ResetCall(call, 0);
+ /*
+ * The conn_call_lock is not held but no one else should be
+ * using this call channel while we are processing this incoming
+ * packet. This assignment should be safe.
+ */
*call->callNumber = np->header.callNumber;
#ifdef RXDEBUG
if (np->header.callNumber == 0)
/* Set remote user defined status from packet */
call->remoteStatus = np->header.userStatus;
- /* Note the gap between the expected next packet and the actual
- * packet that arrived, when the new packet has a smaller serial number
- * than expected. Rioses frequently reorder packets all by themselves,
- * so this will be quite important with very large window sizes.
- * Skew is checked against 0 here to avoid any dependence on the type of
- * inPacketSkew (which may be unsigned). In C, -1 > (unsigned) 0 is always
- * true!
- * The inPacketSkew should be a smoothed running value, not just a maximum. MTUXXX
- * see CalculateRoundTripTime for an example of how to keep smoothed values.
- * I think using a beta of 1/8 is probably appropriate. 93.04.21
- */
- MUTEX_ENTER(&conn->conn_data_lock);
- skew = conn->lastSerial - np->header.serial;
- conn->lastSerial = np->header.serial;
- MUTEX_EXIT(&conn->conn_data_lock);
- if (skew > 0) {
- struct rx_peer *peer;
- peer = conn->peer;
- if (skew > peer->inPacketSkew) {
- dpf(("*** In skew changed from %d to %d\n",
- peer->inPacketSkew, skew));
- peer->inPacketSkew = skew;
- }
- }
-
/* Now do packet type-specific processing */
switch (np->header.type) {
case RX_PACKET_TYPE_DATA:
* appropriate to the call (the call is in the right state, etc.). This
* routine can return a packet to the caller, for re-use */
-struct rx_packet *
+static struct rx_packet *
rxi_ReceiveDataPacket(struct rx_call *call,
struct rx_packet *np, int istack,
osi_socket socket, afs_uint32 host, u_short port,
/* The real smarts of the whole thing. */
-struct rx_packet *
+static struct rx_packet *
rxi_ReceiveAckPacket(struct rx_call *call, struct rx_packet *np,
int istack)
{
afs_uint32 first;
afs_uint32 prev;
afs_uint32 serial;
- /* because there are CM's that are bogus, sending weird values for this. */
- afs_uint32 skew = 0;
int nbytes;
int missing;
int acked;
first = ntohl(ap->firstPacket);
prev = ntohl(ap->previousPacket);
serial = ntohl(ap->serial);
- /* temporarily disabled -- needs to degrade over time
- * skew = ntohs(ap->maxSkew); */
/* Ignore ack packets received out of order */
if (first < call->tfirst ||
size_t len;
len = _snprintf(msg, sizeof(msg),
- "tid[%d] RACK: reason %s serial %u previous %u seq %u skew %d first %u acks %u space %u ",
+ "tid[%d] RACK: reason %s serial %u previous %u seq %u first %u acks %u space %u ",
GetCurrentThreadId(), rx_ack_reason(ap->reason),
ntohl(ap->serial), ntohl(ap->previousPacket),
- (unsigned int)np->header.seq, (unsigned int)skew,
- ntohl(ap->firstPacket), ap->nAcks, ntohs(ap->bufferSpace) );
+ (unsigned int)np->header.seq, ntohl(ap->firstPacket),
+ ap->nAcks, ntohs(ap->bufferSpace) );
if (nAcks) {
int offset;
#else /* AFS_NT40_ENV */
if (rx_Log) {
fprintf(rx_Log,
- "RACK: reason %x previous %u seq %u serial %u skew %d first %u",
+ "RACK: reason %x previous %u seq %u serial %u first %u",
ap->reason, ntohl(ap->previousPacket),
(unsigned int)np->header.seq, (unsigned int)serial,
- (unsigned int)skew, ntohl(ap->firstPacket));
+ ntohl(ap->firstPacket));
if (nAcks) {
int offset;
for (offset = 0; offset < nAcks; offset++)
}
}
- /* Update the outgoing packet skew value to the latest value of
- * the peer's incoming packet skew value. The ack packet, of
- * course, could arrive out of order, but that won't affect things
- * much */
- peer->outPacketSkew = skew;
-
-
clock_GetTime(&now);
/* The transmit queue splits into 4 sections.
}
/* Received a response to a challenge packet */
-struct rx_packet *
+static struct rx_packet *
rxi_ReceiveResponsePacket(struct rx_connection *conn,
struct rx_packet *np, int istack)
{
* back to the server. The server is responsible for retrying the
* challenge if it fails to get a response. */
-struct rx_packet *
+static struct rx_packet *
rxi_ReceiveChallengePacket(struct rx_connection *conn,
struct rx_packet *np, int istack)
{
/* Find an available server process to service the current request in
* the given call structure. If one isn't available, queue up this
* call so it eventually gets one */
-void
+static void
rxi_AttachServerProc(struct rx_call *call,
osi_socket socket, int *tnop,
struct rx_call **newcallp)
if (call->flags & RX_CALL_WAIT_PROC) {
/* Conservative: I don't think this should happen */
call->flags &= ~RX_CALL_WAIT_PROC;
+ rx_atomic_dec(&rx_nWaiting);
if (queue_IsOnQueue(call)) {
queue_Remove(call);
-
- rx_atomic_dec(&rx_nWaiting);
}
}
call->state = RX_STATE_ACTIVE;
* a new call is being prepared (in the case of a client) or a reply
* is being prepared (in the case of a server). Rather than sending
* an ack packet, an ACKALL packet is sent. */
-void
-rxi_AckAll(struct rxevent *event, struct rx_call *call, char *dummy)
+static void
+rxi_AckAll(struct rx_call *call)
{
-#ifdef RX_ENABLE_LOCKS
- if (event) {
- MUTEX_ENTER(&call->lock);
- rxevent_Put(call->delayedAckEvent);
- call->delayedAckEvent = NULL;
- CALL_RELE(call, RX_CALL_REFCOUNT_ACKALL);
- }
- rxi_SendSpecial(call, call->conn, (struct rx_packet *)0,
- RX_PACKET_TYPE_ACKALL, NULL, 0, 0);
- call->flags |= RX_CALL_ACKALL_SENT;
- if (event)
- MUTEX_EXIT(&call->lock);
-#else /* RX_ENABLE_LOCKS */
- if (event) {
- rxevent_Put(call->delayedAckEvent);
- call->delayedAckEvent = NULL;
- }
- rxi_SendSpecial(call, call->conn, (struct rx_packet *)0,
- RX_PACKET_TYPE_ACKALL, NULL, 0, 0);
+ rxi_SendSpecial(call, call->conn, NULL, RX_PACKET_TYPE_ACKALL,
+ NULL, 0, 0);
call->flags |= RX_CALL_ACKALL_SENT;
-#endif /* RX_ENABLE_LOCKS */
}
-void
+static void
rxi_SendDelayedAck(struct rxevent *event, void *arg1, void *unused1,
int unused2)
{
/* Clear out the transmit queue for the current call (all packets have
* been received by peer) */
-void
+static void
rxi_ClearTransmitQueue(struct rx_call *call, int force)
{
#ifdef AFS_GLOBAL_RXLOCK_KERNEL
#endif
}
-void
+static void
rxi_ClearReceiveQueue(struct rx_call *call)
{
if (queue_IsNotEmpty(&call->rq)) {
}
/* Send an abort packet for the specified call */
-struct rx_packet *
+static struct rx_packet *
rxi_SendCallAbort(struct rx_call *call, struct rx_packet *packet,
int istack, int force)
{
- afs_int32 error;
+ afs_int32 error, cerror;
struct clock when, now;
if (!call->error)
return packet;
+ switch (call->error) {
+ case RX_CALL_IDLE:
+ case RX_CALL_BUSY:
+ cerror = RX_CALL_TIMEOUT;
+ break;
+ default:
+ cerror = call->error;
+ }
+
/* Clients should never delay abort messages */
if (rx_IsClientConn(call->conn))
force = 1;
- if (call->abortCode != call->error) {
- call->abortCode = call->error;
+ if (call->abortCode != cerror) {
+ call->abortCode = cerror;
call->abortCount = 0;
}
rxevent_Cancel(&call->delayedAbortEvent, call,
RX_CALL_REFCOUNT_ABORT);
}
- error = htonl(call->error);
+ error = htonl(cerror);
call->abortCount++;
packet =
rxi_SendSpecial(call, call->conn, packet, RX_PACKET_TYPE_ABORT,
* unprotected macros, and may only be reset by non-interrupting code.
*/
-void
+static void
rxi_ResetCall(struct rx_call *call, int newcall)
{
int flags;
}
- rxevent_Cancel(&call->growMTUEvent, call, RX_CALL_REFCOUNT_ALIVE);
+ rxevent_Cancel(&call->growMTUEvent, call, RX_CALL_REFCOUNT_MTU);
if (call->delayedAbortEvent) {
rxevent_Cancel(&call->delayedAbortEvent, call, RX_CALL_REFCOUNT_ABORT);
}
call->flags = 0;
- if ((flags & RX_CALL_PEER_BUSY)) {
+ if (!newcall && (flags & RX_CALL_PEER_BUSY)) {
/* The call channel is still busy; resetting the call doesn't change
- * that */
+ * that. However, if 'newcall' is set, we are processing a call
+ * structure that has either been recycled from the free list, or has
+ * been newly allocated. So, RX_CALL_PEER_BUSY is not relevant if
+ * 'newcall' is set, since it describes a completely different call
+ * channel which we do not care about. */
call->flags |= RX_CALL_PEER_BUSY;
}
osi_rxWakeup(&call->twind);
#endif
+ if (flags & RX_CALL_WAIT_PROC) {
+ rx_atomic_dec(&rx_nWaiting);
+ }
#ifdef RX_ENABLE_LOCKS
/* The following ensures that we don't mess with any queue while some
* other thread might also be doing so. The call_queue_lock field is
MUTEX_ENTER(call->call_queue_lock);
if (queue_IsOnQueue(call)) {
queue_Remove(call);
- if (flags & RX_CALL_WAIT_PROC) {
- rx_atomic_dec(&rx_nWaiting);
- }
}
MUTEX_EXIT(call->call_queue_lock);
CLEAR_CALL_QUEUE_LOCK(call);
#else /* RX_ENABLE_LOCKS */
if (queue_IsOnQueue(call)) {
queue_Remove(call);
- if (flags & RX_CALL_WAIT_PROC)
- rx_atomic_dec(&rx_nWaiting);
}
#endif /* RX_ENABLE_LOCKS */
*/
#ifdef RX_ENABLE_LOCKS
int
-rxi_CheckCall(struct rx_call *call, int haveCTLock)
+static rxi_CheckCall(struct rx_call *call, int haveCTLock)
#else /* RX_ENABLE_LOCKS */
int
-rxi_CheckCall(struct rx_call *call)
+static rxi_CheckCall(struct rx_call *call)
#endif /* RX_ENABLE_LOCKS */
{
struct rx_connection *conn = call->conn;
afs_uint32 fudgeFactor;
int cerror = 0;
int newmtu = 0;
+ int idle_timeout = 0;
+ afs_int32 clock_diff = 0;
+
+ now = clock_Sec();
+
+ /* Large swings in the clock can have a significant impact on
+ * the performance of RX call processing. Forward clock shifts
+ * will result in premature event triggering or timeouts.
+ * Backward shifts can result in calls not completing until
+ * the clock catches up with the original start clock value.
+ *
+ * If a backward clock shift of more than five minutes is noticed,
+ * just fail the call.
+ */
+ if (now < call->lastSendTime)
+ clock_diff = call->lastSendTime - now;
+ if (now < call->startWait)
+ clock_diff = MAX(clock_diff, call->startWait - now);
+ if (now < call->lastReceiveTime)
+ clock_diff = MAX(clock_diff, call->lastReceiveTime - now);
+ if (clock_diff > 5 * 60)
+ {
+ if (call->state == RX_STATE_ACTIVE)
+ rxi_CallError(call, RX_CALL_TIMEOUT);
+ return -1;
+ }
#ifdef AFS_GLOBAL_RXLOCK_KERNEL
if (call->flags & RX_CALL_TQ_BUSY) {
((afs_uint32) call->rtt_dev << 1) + 1023) >> 10;
deadTime = conn->secondsUntilDead + fudgeFactor;
- now = clock_Sec();
/* These are computed to the second (+- 1 second). But that's
* good enough for these values, which should be a significant
* number of seconds. */
rxevent_Cancel(&call->keepAliveEvent, call,
RX_CALL_REFCOUNT_ALIVE);
rxevent_Cancel(&call->growMTUEvent, call,
- RX_CALL_REFCOUNT_ALIVE);
+ RX_CALL_REFCOUNT_MTU);
MUTEX_ENTER(&rx_refcnt_mutex);
- if (call->refCount == 0) {
- rxi_FreeCall(call, haveCTLock);
+ /* if rxi_FreeCall returns 1 it has freed the call */
+ if (call->refCount == 0 &&
+ rxi_FreeCall(call, haveCTLock))
+ {
MUTEX_EXIT(&rx_refcnt_mutex);
- return -2;
+ return -2;
}
MUTEX_EXIT(&rx_refcnt_mutex);
return -1;
* attached process can die reasonably gracefully. */
}
- if (conn->idleDeadTime) {
- idleDeadTime = conn->idleDeadTime + fudgeFactor;
- }
+ if (conn->idleDeadDetection) {
+ if (conn->idleDeadTime) {
+ idleDeadTime = conn->idleDeadTime + fudgeFactor;
+ }
- /* see if we have a non-activity timeout */
- if (call->startWait && idleDeadTime
- && ((call->startWait + idleDeadTime) < now) &&
- (call->flags & RX_CALL_READER_WAIT)) {
- if (call->state == RX_STATE_ACTIVE) {
- cerror = RX_CALL_TIMEOUT;
- goto mtuout;
- }
- }
- if (call->lastSendData && idleDeadTime && (conn->idleDeadErr != 0)
- && ((call->lastSendData + idleDeadTime) < now)) {
- if (call->state == RX_STATE_ACTIVE) {
- cerror = conn->idleDeadErr;
- goto mtuout;
- }
+ if (idleDeadTime) {
+ /* see if we have a non-activity timeout */
+ if (call->startWait && ((call->startWait + idleDeadTime) < now) &&
+ (call->flags & RX_CALL_READER_WAIT)) {
+ if (call->state == RX_STATE_ACTIVE) {
+ cerror = RX_CALL_TIMEOUT;
+ goto mtuout;
+ }
+ }
+
+ if (call->lastSendData && ((call->lastSendData + idleDeadTime) < now)) {
+ if (call->state == RX_STATE_ACTIVE) {
+ cerror = conn->service ? conn->service->idleDeadErr : RX_CALL_IDLE;
+ idle_timeout = 1;
+ goto mtuout;
+ }
+ }
+ }
}
if (conn->hardDeadTime) {
}
return 0;
mtuout:
- if (conn->msgsizeRetryErr && cerror != RX_CALL_TIMEOUT
- && call->lastReceiveTime) {
+ if (conn->msgsizeRetryErr && cerror != RX_CALL_TIMEOUT && !idle_timeout &&
+ call->lastReceiveTime) {
int oldMTU = conn->peer->ifMTU;
/* if we thought we could send more, perhaps things got worse */
}
}
-void
+static void
rxi_ScheduleNatKeepAliveEvent(struct rx_connection *conn)
{
if (!conn->natKeepAliveEvent && conn->secondsUntilNatPing) {
MUTEX_EXIT(&conn->conn_data_lock);
}
-void
-rxi_NatKeepAliveOn(struct rx_connection *conn)
-{
- MUTEX_ENTER(&conn->conn_data_lock);
- /* if it's already attached */
- if (!(conn->flags & RX_CONN_ATTACHWAIT))
- rxi_ScheduleNatKeepAliveEvent(conn);
- else
- conn->flags |= RX_CONN_NAT_PING;
- MUTEX_EXIT(&conn->conn_data_lock);
-}
-
/* When a call is in progress, this routine is called occasionally to
* make sure that some traffic has arrived (or been sent to) the peer.
* If nothing has arrived in a reasonable amount of time, the call is
struct rx_call *call = arg1;
struct rx_connection *conn;
- CALL_RELE(call, RX_CALL_REFCOUNT_ALIVE);
+ CALL_RELE(call, RX_CALL_REFCOUNT_MTU);
MUTEX_ENTER(&call->lock);
if (event == call->growMTUEvent) {
*/
if ((conn->peer->maxPacketSize != 0) &&
(conn->peer->natMTU < RX_MAX_PACKET_SIZE) &&
- (conn->idleDeadErr))
+ conn->idleDeadDetection)
(void)rxi_SendAck(call, NULL, 0, RX_ACK_MTU, 0);
rxi_ScheduleGrowMTUEvent(call, 0);
MUTEX_EXIT(&call->lock);
}
-void
+static void
rxi_ScheduleKeepAliveEvent(struct rx_call *call)
{
if (!call->keepAliveEvent) {
}
}
-void
+static void
rxi_ScheduleGrowMTUEvent(struct rx_call *call, int secs)
{
if (!call->growMTUEvent) {
}
when.sec += secs;
- CALL_HOLD(call, RX_CALL_REFCOUNT_ALIVE);
+ CALL_HOLD(call, RX_CALL_REFCOUNT_MTU);
call->growMTUEvent =
rxevent_Post(&when, &now, rxi_GrowMTUEvent, call, NULL, 0);
}
}
/* N.B. rxi_KeepAliveOff: is defined earlier as a macro */
-void
+static void
rxi_KeepAliveOn(struct rx_call *call)
{
/* Pretend last packet received was received now--i.e. if another
rxi_ScheduleKeepAliveEvent(call);
}
+/*
+ * Solely in order that callers not need to include rx_call.h
+ */
+void
+rx_KeepAliveOff(struct rx_call *call)
+{
+ rxi_KeepAliveOff(call);
+}
void
+rx_KeepAliveOn(struct rx_call *call)
+{
+ rxi_KeepAliveOn(call);
+}
+
+static void
rxi_GrowMTUOn(struct rx_call *call)
{
struct rx_connection *conn = call->conn;
/* This routine is called to send connection abort messages
* that have been delayed to throttle looping clients. */
-void
+static void
rxi_SendDelayedConnAbort(struct rxevent *event, void *arg1, void *unused,
int unused2)
{
* seconds) to ask the client to authenticate itself. The routine
* issues a challenge to the client, which is obtained from the
* security object associated with the connection */
-void
+static void
rxi_ChallengeEvent(struct rxevent *event,
void *arg0, void *arg1, int tries)
{
* security object associated with the connection is asked to create
* the challenge at this time. N.B. rxi_ChallengeOff is a macro,
* defined earlier. */
-void
+static void
rxi_ChallengeOn(struct rx_connection *conn)
{
if (!conn->challengeEvent) {
/* Find all server connections that have not been active for a long time, and
* toss them */
-void
+static void
rxi_ReapConnections(struct rxevent *unused, void *unused1, void *unused2,
int unused3)
{
void
rx_PrintPeerStats(FILE * file, struct rx_peer *peer)
{
- fprintf(file, "Peer %x.%d. " "Burst size %d, " "burst wait %d.%06d.\n",
- ntohl(peer->host), (int)ntohs(peer->port), (int)peer->burstSize,
- (int)peer->burstWait.sec, (int)peer->burstWait.usec);
+ fprintf(file, "Peer %x.%d.\n",
+ ntohl(peer->host), (int)ntohs(peer->port));
fprintf(file,
" Rtt %d, " "total sent %d, " "resent %d\n",
peer->rtt, peer->nSent, peer->reSends);
- fprintf(file,
- " Packet size %d, " "max in packet skew %d, "
- "max out packet skew %d\n", peer->ifMTU, (int)peer->inPacketSkew,
- (int)peer->outPacketSkew);
+ fprintf(file, " Packet size %d\n", peer->ifMTU);
}
#endif
peer->ifMTU = ntohs(peer->ifMTU);
peer->idleWhen = ntohl(peer->idleWhen);
peer->refCount = ntohs(peer->refCount);
- peer->burstWait.sec = ntohl(peer->burstWait.sec);
- peer->burstWait.usec = ntohl(peer->burstWait.usec);
peer->rtt = ntohl(peer->rtt);
peer->rtt_dev = ntohl(peer->rtt_dev);
peer->timeout.sec = 0;
peer->timeout.usec = 0;
peer->nSent = ntohl(peer->nSent);
peer->reSends = ntohl(peer->reSends);
- peer->inPacketSkew = ntohl(peer->inPacketSkew);
- peer->outPacketSkew = ntohl(peer->outPacketSkew);
peer->natMTU = ntohs(peer->natMTU);
peer->maxMTU = ntohs(peer->maxMTU);
peer->maxDgramPackets = ntohs(peer->maxDgramPackets);
peerStats->ifMTU = tp->ifMTU;
peerStats->idleWhen = tp->idleWhen;
peerStats->refCount = tp->refCount;
- peerStats->burstSize = tp->burstSize;
- peerStats->burst = tp->burst;
- peerStats->burstWait.sec = tp->burstWait.sec;
- peerStats->burstWait.usec = tp->burstWait.usec;
+ peerStats->burstSize = 0;
+ peerStats->burst = 0;
+ peerStats->burstWait.sec = 0;
+ peerStats->burstWait.usec = 0;
peerStats->rtt = tp->rtt;
peerStats->rtt_dev = tp->rtt_dev;
peerStats->timeout.sec = 0;
peerStats->timeout.usec = 0;
peerStats->nSent = tp->nSent;
peerStats->reSends = tp->reSends;
- peerStats->inPacketSkew = tp->inPacketSkew;
- peerStats->outPacketSkew = tp->outPacketSkew;
peerStats->natMTU = tp->natMTU;
peerStats->maxMTU = tp->maxMTU;
peerStats->maxDgramPackets = tp->maxDgramPackets;