openbsd-20021119
[openafs.git] / src / rx / rx.c
index 0e5df40..4b71a6a 100644 (file)
@@ -11,7 +11,7 @@
 
 #include <afsconfig.h>
 #ifdef KERNEL
-#include "../afs/param.h"
+#include "afs/param.h"
 #else
 #include <afs/param.h>
 #endif
 RCSID("$Header$");
 
 #ifdef KERNEL
-#include "../afs/sysincludes.h"
-#include "../afs/afsincludes.h"
+#include "afs/sysincludes.h"
+#include "afsincludes.h"
 #ifndef UKERNEL
-#include "../h/types.h"
-#include "../h/time.h"
-#include "../h/stat.h"
+#include "h/types.h"
+#include "h/time.h"
+#include "h/stat.h"
 #ifdef AFS_OSF_ENV
 #include <net/net_globals.h>
 #endif /* AFS_OSF_ENV */
 #ifdef AFS_LINUX20_ENV
-#include "../h/socket.h"
+#include "h/socket.h"
 #endif
-#include "../netinet/in.h"
-#include "../afs/afs_args.h"
-#include "../afs/afs_osi.h"
+#include "netinet/in.h"
+#include "afs/afs_args.h"
+#include "afs/afs_osi.h"
 #if    (defined(AFS_AUX_ENV) || defined(AFS_AIX_ENV))
-#include "../h/systm.h"
+#include "h/systm.h"
 #endif
 #ifdef RXDEBUG
 #undef RXDEBUG     /* turn off debugging */
 #endif /* RXDEBUG */
 #if defined(AFS_SGI_ENV)
-#include "../sys/debug.h"
+#include "sys/debug.h"
 #endif
-#include "../afsint/afsint.h"
+#include "afsint.h"
 #ifdef AFS_ALPHA_ENV
 #undef kmem_alloc
 #undef kmem_free
@@ -52,27 +52,27 @@ RCSID("$Header$");
 #undef register
 #endif /* AFS_ALPHA_ENV */
 #else /* !UKERNEL */
-#include "../afs/sysincludes.h"
-#include "../afs/afsincludes.h"
+#include "afs/sysincludes.h"
+#include "afsincludes.h"
 #endif /* !UKERNEL */
-#include "../afs/lock.h"
-#include "../rx/rx_kmutex.h"
-#include "../rx/rx_kernel.h"
-#include "../rx/rx_clock.h"
-#include "../rx/rx_queue.h"
-#include "../rx/rx.h"
-#include "../rx/rx_globals.h"
-#include "../rx/rx_trace.h"
+#include "afs/lock.h"
+#include "rx_kmutex.h"
+#include "rx_kernel.h"
+#include "rx_clock.h"
+#include "rx_queue.h"
+#include "rx.h"
+#include "rx_globals.h"
+#include "rx_trace.h"
 #define        AFSOP_STOP_RXCALLBACK   210     /* Stop CALLBACK process */
 #define        AFSOP_STOP_AFS          211     /* Stop AFS process */
 #define        AFSOP_STOP_BKG          212     /* Stop BKG process */
-#include "../afsint/afsint.h"
+#include "afsint.h"
 extern afs_int32 afs_termState;
 #ifdef AFS_AIX41_ENV
 #include "sys/lockl.h"
 #include "sys/lock_def.h"
 #endif /* AFS_AIX41_ENV */
-# include "../afsint/rxgen_consts.h"
+# include "rxgen_consts.h"
 #else /* KERNEL */
 # include <sys/types.h>
 # include <errno.h>
@@ -101,13 +101,18 @@ extern afs_int32 afs_termState;
 # include "rx_queue.h"
 # include "rx_globals.h"
 # include "rx_trace.h"
-# include "rx_internal.h"
 # include <afs/rxgen_consts.h>
 #endif /* KERNEL */
 
 int (*registerProgram)() = 0;
 int (*swapNameProgram)() = 0;
 
+/* Local static routines */
+static void rxi_DestroyConnectionNoLock(register struct rx_connection *conn);
+#ifdef RX_ENABLE_LOCKS
+static void rxi_SetAcksInTransmitQueue(register struct rx_call *call);
+#endif
+
 #ifdef AFS_GLOBAL_RXLOCK_KERNEL
 struct rx_tq_debug {
     afs_int32 rxi_start_aborted; /* rxi_start awoke after rxi_Send in error. */
@@ -263,23 +268,31 @@ void rxi_StartUnlocked();
 struct rx_connection *rxLastConn = 0; 
 
 #ifdef RX_ENABLE_LOCKS
-/* The locking hierarchy for rx fine grain locking is composed of five
+/* The locking hierarchy for rx fine grain locking is composed of these
  * tiers:
+ *
+ * rx_connHashTable_lock - synchronizes conn creation, rx_connHashTable access
  * conn_call_lock - used to synchonize rx_EndCall and rx_NewCall
  * call->lock - locks call data fields.
- * Most any other lock - these are all independent of each other.....
- *     rx_freePktQ_lock
+ * These are independent of each other:
  *     rx_freeCallQueue_lock
- *     freeSQEList_lock
- *     rx_connHashTable_lock
- *     rx_serverPool_lock
  *     rxi_keyCreate_lock
+ * rx_serverPool_lock
+ * freeSQEList_lock
+ *
+ * serverQueueEntry->lock
+ * rx_rpc_stats
  * rx_peerHashTable_lock - locked under rx_connHashTable_lock
-
+ * peer->lock - locks peer data fields.
+ * conn_data_lock - that more than one thread is not updating a conn data
+ *                 field at the same time.
+ * rx_freePktQ_lock
+ *
  * lowest level:
- *     peer_lock - locks peer data fields.
- *     conn_data_lock - that more than one thread is not updating a conn data
- *             field at the same time.
+ *     multi_handle->lock
+ *     rxevent_lock
+ *     rx_stats_mutex
+ *
  * Do we need a lock to protect the peer field in the conn structure?
  *      conn->peer was previously a constant for all intents and so has no
  *      lock protecting this field. The multihomed client delta introduced
@@ -294,13 +307,10 @@ struct rx_connection *rxLastConn = 0;
 /* rxdb_fileID is used to identify the lock location, along with line#. */
 static int rxdb_fileID = RXDB_FILE_RX;
 #endif /* RX_LOCKS_DB */
-static void rxi_SetAcksInTransmitQueue();
-void osirx_AssertMine(afs_kmutex_t *lockaddr, char *msg);
 #else /* RX_ENABLE_LOCKS */
 #define SET_CALL_QUEUE_LOCK(C, L)
 #define CLEAR_CALL_QUEUE_LOCK(C)
 #endif /* RX_ENABLE_LOCKS */
-static void rxi_DestroyConnectionNoLock();
 struct rx_serverQueueEntry *rx_waitForPacket = 0;
 
 /* ------------Exported Interfaces------------- */
@@ -325,8 +335,7 @@ struct rx_serverQueueEntry *rx_waitForPacket = 0;
 #define UNLOCK_EPOCH
 #endif /* AFS_PTHREAD_ENV */
 
-void rx_SetEpoch (epoch)
-  afs_uint32 epoch;
+void rx_SetEpoch (afs_uint32 epoch)
 {
     LOCK_EPOCH
     rx_epoch = epoch;
@@ -404,9 +413,9 @@ int rx_Init(u_int port)
 #ifdef RX_LOCKS_DB
     rxdb_init();
 #endif /* RX_LOCKS_DB */
-    MUTEX_INIT(&rx_stats_mutex, "rx_stats_mutex",MUTEX_DEFAULT,0);    
-    MUTEX_INIT(&rx_rpc_stats, "rx_rpc_stats",MUTEX_DEFAULT,0);    
-    MUTEX_INIT(&rx_freePktQ_lock, "rx_freePktQ_lock",MUTEX_DEFAULT,0);    
+    MUTEX_INIT(&rx_stats_mutex, "rx_stats_mutex",MUTEX_DEFAULT,0);
+    MUTEX_INIT(&rx_rpc_stats, "rx_rpc_stats",MUTEX_DEFAULT,0);
+    MUTEX_INIT(&rx_freePktQ_lock, "rx_freePktQ_lock",MUTEX_DEFAULT,0);
     MUTEX_INIT(&freeSQEList_lock, "freeSQEList lock",MUTEX_DEFAULT,0);
     MUTEX_INIT(&rx_freeCallQueue_lock, "rx_freeCallQueue_lock",
               MUTEX_DEFAULT,0);
@@ -423,7 +432,7 @@ int rx_Init(u_int port)
       rx_sleepLock = alloc_spinlock(LAST_HELD_ORDER-10, "rx_sleepLock");
 #endif /* KERNEL && AFS_HPUX110_ENV */
 #else /* RX_ENABLE_LOCKS */
-#if defined(KERNEL) && defined(AFS_GLOBAL_SUNLOCK) && !defined(AFS_HPUX_ENV)
+#if defined(KERNEL) && defined(AFS_GLOBAL_SUNLOCK) && !defined(AFS_HPUX_ENV) && !defined(AFS_OBSD_ENV)
     mutex_init(&afs_rxglobal_lock, "afs_rxglobal_lock", MUTEX_DEFAULT, NULL);
 #endif /* AFS_GLOBAL_SUNLOCK */
 #endif /* RX_ENABLE_LOCKS */
@@ -530,8 +539,7 @@ int rx_Init(u_int port)
 /* This verion of QuotaOK reserves quota if it's ok while the
  * rx_serverPool_lock is held.  Return quota using ReturnToServerPool().
  */
-static int QuotaOK(aservice)
-register struct rx_service *aservice;
+static int QuotaOK(register struct rx_service *aservice)
 {
     /* check if over max quota */
     if (aservice->nRequestsRunning >= aservice->maxProcs) {
@@ -558,8 +566,8 @@ register struct rx_service *aservice;
 
     return 0;
 }
-static void ReturnToServerPool(aservice)
-register struct rx_service *aservice;
+
+static void ReturnToServerPool(register struct rx_service *aservice)
 {
     aservice->nRequestsRunning--;
     MUTEX_ENTER(&rx_stats_mutex);
@@ -569,8 +577,8 @@ register struct rx_service *aservice;
 }
 
 #else /* RX_ENABLE_LOCKS */
-static int QuotaOK(aservice)
-register struct rx_service *aservice; {
+static int QuotaOK(register struct rx_service *aservice)
+{
     int rc=0;
     /* under min quota, we're OK */
     if (aservice->nRequestsRunning < aservice->minProcs) return 1;
@@ -590,8 +598,7 @@ register struct rx_service *aservice; {
 /* Called by rx_StartServer to start up lwp's to service calls.
    NExistingProcs gives the number of procs already existing, and which
    therefore needn't be created. */
-void rxi_StartServerProcs(nExistingProcs)
-    int nExistingProcs;
+void rxi_StartServerProcs(int nExistingProcs)
 {
     register struct rx_service *service;
     register int i;
@@ -625,7 +632,7 @@ void rxi_StartServerProcs(nExistingProcs)
 /* This routine must be called if any services are exported.  If the
  * donateMe flag is set, the calling process is donated to the server
  * process pool */
-void rx_StartServer(donateMe)
+void rx_StartServer(int donateMe)
 {
     register struct rx_service *service;
     register int i, nProcs=0;
@@ -687,13 +694,9 @@ void rx_StartServer(donateMe)
 /* Create a new client connection to the specified service, using the
  * specified security object to implement the security model for this
  * connection. */
-struct rx_connection *
-rx_NewConnection(shost, sport, sservice, securityObject, serviceSecurityIndex)
-    register afs_uint32 shost;     /* Server host */
-    u_short sport;                 /* Server port */
-    u_short sservice;              /* Server service id */
-    register struct rx_securityClass *securityObject;
-    int serviceSecurityIndex;
+struct rx_connection *rx_NewConnection(register afs_uint32 shost, 
+       u_short sport, u_short sservice, 
+       register struct rx_securityClass *securityObject, int serviceSecurityIndex)
 {
     int hashindex;
     afs_int32 cid;
@@ -731,8 +734,8 @@ rx_NewConnection(shost, sport, sservice, securityObject, serviceSecurityIndex)
     conn->ackRate = RX_FAST_ACK_RATE;
     conn->nSpecific = 0;
     conn->specific = NULL;
-    conn->challengeEvent = (struct rxevent *)0;
-    conn->delayedAbortEvent = (struct rxevent *)0;
+    conn->challengeEvent = NULL;
+    conn->delayedAbortEvent = NULL;
     conn->abortCount = 0;
     conn->error = 0;
 
@@ -752,9 +755,7 @@ rx_NewConnection(shost, sport, sservice, securityObject, serviceSecurityIndex)
     return conn;
 }
 
-void rx_SetConnDeadTime(conn, seconds)
-    register struct rx_connection *conn;
-    register int seconds;
+void rx_SetConnDeadTime(register struct rx_connection *conn, register int seconds)
 {
     /* The idea is to set the dead time to a value that allows several
      * keepalives to be dropped without timing out the connection. */
@@ -769,11 +770,8 @@ int rxi_lowConnRefCount = 0;
  * Cleanup a connection that was destroyed in rxi_DestroyConnectioNoLock.
  * NOTE: must not be called with rx_connHashTable_lock held.
  */
-void rxi_CleanupConnection(conn)
-    struct rx_connection *conn;
+void rxi_CleanupConnection(struct rx_connection *conn)
 {
-    int i;
-
     /* Notify the service exporter, if requested, that this connection
      * is being destroyed */
     if (conn->type == RX_SERVER_CONNECTION && conn->service->destroyConnProc)
@@ -807,6 +805,7 @@ void rxi_CleanupConnection(conn)
 
 #ifndef KERNEL
     if (conn->specific) {
+       int i;
        for (i = 0 ; i < conn->nSpecific ; i++) {
            if (conn->specific[i] && rxi_keyCreate_destructor[i])
                (*rxi_keyCreate_destructor[i])(conn->specific[i]);
@@ -826,8 +825,7 @@ void rxi_CleanupConnection(conn)
 }
 
 /* Destroy the specified connection */
-void rxi_DestroyConnection(conn)
-    register struct rx_connection *conn;
+void rxi_DestroyConnection(register struct rx_connection *conn)
 {
     MUTEX_ENTER(&rx_connHashTable_lock);
     rxi_DestroyConnectionNoLock(conn);
@@ -844,8 +842,7 @@ void rxi_DestroyConnection(conn)
 #endif /* RX_ENABLE_LOCKS */
 }
     
-static void rxi_DestroyConnectionNoLock(conn)
-    register struct rx_connection *conn;
+static void rxi_DestroyConnectionNoLock(register struct rx_connection *conn)
 {
     register struct rx_connection **conn_ptr;
     register int havecalls = 0;
@@ -899,9 +896,9 @@ static void rxi_DestroyConnectionNoLock(conn)
                                   RX_CALL_REFCOUNT_DELAY);
                    if (call->state == RX_STATE_PRECALL ||
                        call->state == RX_STATE_ACTIVE) {
-                       rxi_SendDelayedAck(call->delayedAckEvent, call, 0);
+                       rxi_SendAck(call, 0, 0, 0, 0, RX_ACK_DELAY, 0);
                    } else {
-                       rxi_AckAll((struct rxevent *)0, call, 0);
+                       rxi_AckAll(NULL, call, 0);
                    }
                }
                MUTEX_EXIT(&call->lock);
@@ -971,8 +968,7 @@ static void rxi_DestroyConnectionNoLock(conn)
 }
 
 /* Externally available version */
-void rx_DestroyConnection(conn) 
-    register struct rx_connection *conn;
+void rx_DestroyConnection(register struct rx_connection *conn) 
 {
     SPLVAR;
 
@@ -992,8 +988,7 @@ void rx_DestroyConnection(conn)
  * to ensure that we don't get signalle after we found a call in an active
  * state and before we go to sleep.
  */
-struct rx_call *rx_NewCall(conn)
-    register struct rx_connection *conn;
+struct rx_call *rx_NewCall(register struct rx_connection *conn)
 {
     register int i;
     register struct rx_call *call;
@@ -1107,9 +1102,8 @@ struct rx_call *rx_NewCall(conn)
     return call;
 }
 
-int
-rxi_HasActiveCalls(aconn)
-register struct rx_connection *aconn; {
+int rxi_HasActiveCalls(register struct rx_connection *aconn)
+{
     register int i;
     register struct rx_call *tcall;
     SPLVAR;
@@ -1128,10 +1122,9 @@ register struct rx_connection *aconn; {
     return 0;
 }
 
-int
-rxi_GetCallNumberVector(aconn, aint32s)
-register struct rx_connection *aconn;
-register afs_int32 *aint32s; {
+int rxi_GetCallNumberVector(register struct rx_connection *aconn, 
+       register afs_int32 *aint32s)
+{
     register int i;
     register struct rx_call *tcall;
     SPLVAR;
@@ -1147,10 +1140,9 @@ register afs_int32 *aint32s; {
     return 0;
 }
 
-int
-rxi_SetCallNumberVector(aconn, aint32s)
-register struct rx_connection *aconn;
-register afs_int32 *aint32s; {
+int rxi_SetCallNumberVector(register struct rx_connection *aconn, 
+       register afs_int32 *aint32s)
+{
     register int i;
     register struct rx_call *tcall;
     SPLVAR;
@@ -1168,18 +1160,15 @@ register afs_int32 *aint32s; {
 
 /* Advertise a new service.  A service is named locally by a UDP port
  * number plus a 16-bit service id.  Returns (struct rx_service *) 0
- * on a failure. */
-struct rx_service *
-rx_NewService(port, serviceId, serviceName, securityObjects,
-             nSecurityObjects, serviceProc)
-    u_short port;
-    u_short serviceId;
-    char *serviceName; /* Name for identification purposes (e.g. the
-                         * service name might be used for probing for
-                         * statistics) */
-    struct rx_securityClass **securityObjects;
-    int nSecurityObjects;
-    afs_int32 (*serviceProc)();
+ * on a failure. 
+ *
+     char *serviceName;         Name for identification purposes (e.g. the
+                         service name might be used for probing for
+                         statistics) */
+struct rx_service *rx_NewService(u_short port, u_short serviceId, 
+       char *serviceName, 
+       struct rx_securityClass **securityObjects,
+       int nSecurityObjects, afs_int32 (*serviceProc)(struct rx_call *acall))
 {    
     osi_socket socket = OSI_NULLSOCKET;
     register struct rx_service *tservice;    
@@ -1248,6 +1237,7 @@ rx_NewService(port, serviceId, serviceName, securityObjects,
            service->idleDeadTime = 60;
            service->connDeadTime = rx_connDeadTime;
            service->executeRequestProc = serviceProc;
+           service->checkReach = 0;
            rx_services[i] = service;   /* not visible until now */
            AFS_RXGUNLOCK();
            USERPRI;
@@ -1266,10 +1256,7 @@ rx_NewService(port, serviceId, serviceName, securityObjects,
  * non-null, it will be set to the file descriptor that this thread
  * is now listening on. If socketp is null, this routine will never
  * returns. */
-void rxi_ServerProc(threadID, newcall, socketp)
-int threadID;
-struct rx_call *newcall;
-osi_socket *socketp;
+void rxi_ServerProc(int threadID, struct rx_call *newcall, osi_socket *socketp)
 {
     register struct rx_call *call;
     register afs_int32 code;
@@ -1336,7 +1323,7 @@ osi_socket *socketp;
 }
 
 
-void rx_WakeupServerProcs()
+void rx_WakeupServerProcs(void)
 {
     struct rx_serverQueueEntry *np, *tqp;
     SPLVAR;
@@ -1405,11 +1392,7 @@ void rx_WakeupServerProcs()
 /* Sleep until a call arrives.  Returns a pointer to the call, ready
  * for an rx_Read. */
 #ifdef RX_ENABLE_LOCKS
-struct rx_call *
-rx_GetCall(tno, cur_service, socketp)
-int tno;
-struct rx_service *cur_service;
-osi_socket *socketp;
+struct rx_call *rx_GetCall(int tno, struct rx_service *cur_service, osi_socket *socketp)
 {
     struct rx_serverQueueEntry *sq;
     register struct rx_call *call = (struct rx_call *) 0, *choice2;
@@ -1424,7 +1407,7 @@ osi_socket *socketp;
     } else {    /* otherwise allocate a new one and return that */
        MUTEX_EXIT(&freeSQEList_lock);
        sq = (struct rx_serverQueueEntry *) rxi_Alloc(sizeof(struct rx_serverQueueEntry));
-       MUTEX_INIT(&sq->lock, "server Queue lock",MUTEX_DEFAULT,0);     
+       MUTEX_INIT(&sq->lock, "server Queue lock",MUTEX_DEFAULT,0);
        CV_INIT(&sq->cv, "server Queue lock", CV_DEFAULT, 0);
     }
 
@@ -1561,11 +1544,7 @@ osi_socket *socketp;
     return call;
 }
 #else /* RX_ENABLE_LOCKS */
-struct rx_call *
-rx_GetCall(tno, cur_service, socketp)
-  int tno;
-  struct rx_service *cur_service;
-  osi_socket *socketp;
+struct rx_call *rx_GetCall(int tno, struct rx_service *cur_service, osi_socket *socketp)
 {
     struct rx_serverQueueEntry *sq;
     register struct rx_call *call = (struct rx_call *) 0, *choice2;
@@ -1582,7 +1561,7 @@ rx_GetCall(tno, cur_service, socketp)
     } else {    /* otherwise allocate a new one and return that */
        MUTEX_EXIT(&freeSQEList_lock);
        sq = (struct rx_serverQueueEntry *) rxi_Alloc(sizeof(struct rx_serverQueueEntry));
-       MUTEX_INIT(&sq->lock, "server Queue lock",MUTEX_DEFAULT,0);     
+       MUTEX_INIT(&sq->lock, "server Queue lock",MUTEX_DEFAULT,0);
        CV_INIT(&sq->cv, "server Queue lock", CV_DEFAULT, 0);
     }
     MUTEX_ENTER(&sq->lock);
@@ -1713,11 +1692,10 @@ rx_GetCall(tno, cur_service, socketp)
  * good idea to (1) use it immediately after a newcall (clients only)
  * and (2) only use it once.  Other uses currently void your warranty
  */
-void rx_SetArrivalProc(call, proc, handle, arg)
-    register struct rx_call *call;
-    register VOID (*proc)();
-    register VOID *handle;
-    register VOID *arg;
+void rx_SetArrivalProc(register struct rx_call *call, 
+       register VOID (*proc)(register struct rx_call *call,
+        register struct multi_handle *mh, register int index),
+       register VOID *handle, register VOID *arg)
 {
     call->arrivalProc = proc;
     call->arrivalProcHandle = handle;
@@ -1728,9 +1706,7 @@ void rx_SetArrivalProc(call, proc, handle, arg)
  * appropriate, and return the final error code from the conversation
  * to the caller */
 
-afs_int32 rx_EndCall(call, rc)
-    register struct rx_call *call;
-    afs_int32 rc;
+afs_int32 rx_EndCall(register struct rx_call *call, afs_int32 rc)
 {
     register struct rx_connection *conn = call->conn;
     register struct rx_service *service;
@@ -1787,6 +1763,16 @@ afs_int32 rx_EndCall(call, rc)
         || (call->mode == RX_MODE_RECEIVING && call->rnext == 1)) {
            (void) rxi_ReadProc(call, &dummy, 1);
        }
+
+       /* If we had an outstanding delayed ack, be nice to the server
+        * and force-send it now.
+        */
+       if (call->delayedAckEvent) {
+           rxevent_Cancel(call->delayedAckEvent, call, RX_CALL_REFCOUNT_DELAY);
+           call->delayedAckEvent = NULL;
+           rxi_SendDelayedAck(NULL, call, NULL);
+       }
+
        /* We need to release the call lock since it's lower than the
         * conn_call_lock and we don't want to hold the conn_call_lock
         * over the rx_ReadProc call. The conn_call_lock needs to be held
@@ -1860,7 +1846,8 @@ afs_int32 rx_EndCall(call, rc)
  * make to a dead client.
  * This is not quite right, since some calls may still be ongoing and
  * we can't lock them to destroy them. */
-void rx_Finalize() {
+void rx_Finalize(void)
+{
     register struct rx_connection **conn_ptr, **conn_end;
 
     INIT_PTHREAD_LOCKS
@@ -1911,9 +1898,8 @@ void rx_Finalize() {
 
 /* if we wakeup packet waiter too often, can get in loop with two
     AllocSendPackets each waking each other up (from ReclaimPacket calls) */
-void
-rxi_PacketsUnWait() {
-
+void rxi_PacketsUnWait(void)
+{
     if (!rx_waitingForPackets) {
        return;
     }
@@ -1936,9 +1922,8 @@ rxi_PacketsUnWait() {
 
 /* Return this process's service structure for the
  * specified socket and service */
-struct rx_service *rxi_FindService(socket, serviceId)
-    register osi_socket socket;
-    register u_short serviceId;
+struct rx_service *rxi_FindService(register osi_socket socket, 
+       register u_short serviceId)
 {
     register struct rx_service **sp;   
     for (sp = &rx_services[0]; *sp; sp++) {
@@ -1951,9 +1936,8 @@ struct rx_service *rxi_FindService(socket, serviceId)
 /* Allocate a call structure, for the indicated channel of the
  * supplied connection.  The mode and state of the call must be set by
  * the caller. Returns the call with mutex locked. */
-struct rx_call *rxi_NewCall(conn, channel)
-    register struct rx_connection *conn;
-    register int channel;
+struct rx_call *rxi_NewCall(register struct rx_connection *conn,
+       register int channel)
 {
     register struct rx_call *call;
 #ifdef AFS_GLOBAL_RXLOCK_KERNEL
@@ -2039,14 +2023,13 @@ struct rx_call *rxi_NewCall(conn, channel)
  * state, including the call structure, which is placed on the call
  * free list.
  * Call is locked upon entry.
+ * haveCTLock set if called from rxi_ReapConnections
  */
 #ifdef RX_ENABLE_LOCKS
-void rxi_FreeCall(call, haveCTLock)
-    int haveCTLock; /* Set if called from rxi_ReapConnections */
+void rxi_FreeCall(register struct rx_call *call, int haveCTLock)
 #else /* RX_ENABLE_LOCKS */
-void rxi_FreeCall(call)
+void rxi_FreeCall(register struct rx_call *call)
 #endif /* RX_ENABLE_LOCKS */
-    register struct rx_call *call;
 {
     register int channel = call->channel;
     register struct rx_connection *conn = call->conn;
@@ -2105,8 +2088,7 @@ void rxi_FreeCall(call)
 }
 
 afs_int32 rxi_Alloccnt = 0, rxi_Allocsize = 0;
-char *rxi_Alloc(size)
-register size_t size;
+char *rxi_Alloc(register size_t size)
 {
     register char *p;
 
@@ -2138,9 +2120,7 @@ register size_t size;
     return p;
 }
 
-void rxi_Free(addr, size)
-void *addr;
-register size_t size;
+void rxi_Free(void *addr, register size_t size)
 {
 #if defined(AFS_AIX41_ENV) && defined(KERNEL)
     /* Grab the AFS filesystem lock. See afs/osi.h for the lock
@@ -2173,11 +2153,8 @@ register size_t size;
  * The origPeer, if set, is a pointer to a peer structure on which the
  * refcount will be be decremented. This is used to replace the peer
  * structure hanging off a connection structure */
-struct rx_peer *rxi_FindPeer(host, port, origPeer, create)
-    register afs_uint32 host;
-    register u_short port;
-    struct rx_peer *origPeer;
-    int create;
+struct rx_peer *rxi_FindPeer(register afs_uint32 host, 
+       register u_short port, struct rx_peer *origPeer, int create)
 {
     register struct rx_peer *pp;
     int hashIndex;
@@ -2224,21 +2201,12 @@ struct rx_peer *rxi_FindPeer(host, port, origPeer, create)
  * 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 *
-rxi_FindConnection(socket, host, port, serviceId, cid, 
-                  epoch, type, securityIndex)
-    osi_socket socket;
-    register afs_int32 host;
-    register u_short port;
-    u_short serviceId;
-    afs_uint32 cid;
-    afs_uint32 epoch;
-    int type;
-    u_int securityIndex;
+struct rx_connection *rxi_FindConnection(osi_socket socket, 
+       register afs_int32 host, register u_short port, u_short serviceId, 
+       afs_uint32 cid, afs_uint32 epoch, int type, u_int securityIndex)
 {
     int hashindex, flag;
     register struct rx_connection *conn;
-    struct rx_peer *peer;
     hashindex = CONN_HASH(host, port, cid, epoch, type);
     MUTEX_ENTER(&rx_connHashTable_lock);
     rxLastConn ? (conn = rxLastConn, flag = 0) :
@@ -2255,13 +2223,12 @@ rxi_FindConnection(socket, host, port, serviceId, cid,
            MUTEX_EXIT(&rx_connHashTable_lock);
            return (struct rx_connection *) 0;
        }
-       /* epoch's high order bits mean route for security reasons only on
-        * the cid, not the host and port fields.
-        */
-       if (conn->epoch & 0x80000000) break;
-       if (((type == RX_CLIENT_CONNECTION) 
-            || (pp->host == host)) && (pp->port == port))
-         break;
+       if (pp->host == host && pp->port == port)
+           break;
+       if (type == RX_CLIENT_CONNECTION && pp->port == port)
+           break;
+       if (type == RX_CLIENT_CONNECTION && (conn->epoch & 0x80000000))
+           break;
       }
       if ( !flag )
       {
@@ -2293,7 +2260,7 @@ rxi_FindConnection(socket, host, port, serviceId, cid,
        CV_INIT(&conn->conn_call_cv, "conn call cv", CV_DEFAULT, 0);
        conn->next = rx_connHashTable[hashindex];
        rx_connHashTable[hashindex] = conn;
-       peer = conn->peer = rxi_FindPeer(host, port, 0, 1);
+       conn->peer = rxi_FindPeer(host, port, 0, 1);
        conn->type = RX_SERVER_CONNECTION;
        conn->lastSendTime = clock_Sec();   /* don't GC immediately */
        conn->epoch = epoch;
@@ -2316,27 +2283,9 @@ rxi_FindConnection(socket, host, port, serviceId, cid,
        rx_stats.nServerConns++;
        MUTEX_EXIT(&rx_stats_mutex);
     }
-    else
-    {
-    /* Ensure that the peer structure is set up in such a way that
-    ** replies in this connection go back to that remote interface
-    ** from which the last packet was sent out. In case, this packet's
-    ** source IP address does not match the peer struct for this conn,
-    ** then drop the refCount on conn->peer and get a new peer structure.
-    ** We can check the host,port field in the peer structure without the
-    ** rx_peerHashTable_lock because the peer structure has its refCount
-    ** incremented and the only time the host,port in the peer struct gets
-    ** updated is when the peer structure is created.
-    */
-       if (conn->peer->host == host )
-               peer = conn->peer; /* no change to the peer structure */
-       else
-               peer = rxi_FindPeer(host, port, conn->peer, 1);
-    }
 
     MUTEX_ENTER(&conn->conn_data_lock);
     conn->refCount++;
-    conn->peer = peer;
     MUTEX_EXIT(&conn->conn_data_lock);
 
     rxLastConn = conn; /* store this connection as the last conn used */
@@ -2361,13 +2310,9 @@ int (*rx_almostSent)() = 0;
  * sender.  This call returns the packet to the caller if it is finished with
  * it, rather than de-allocating it, just as a small performance hack */
 
-struct rx_packet *rxi_ReceivePacket(np, socket, host, port, tnop, newcallp)
-    register struct rx_packet *np;
-    osi_socket socket;
-    afs_uint32 host;
-    u_short port;
-    int *tnop;
-    struct rx_call **newcallp;
+struct rx_packet *rxi_ReceivePacket(register struct rx_packet *np, 
+       osi_socket socket, afs_uint32 host, u_short port, 
+       int *tnop, struct rx_call **newcallp)
 {
     register struct rx_call *call;
     register struct rx_connection *conn;
@@ -2409,7 +2354,7 @@ struct rx_packet *rxi_ReceivePacket(np, socket, host, port, tnop, newcallp)
        addr.sin_family = AF_INET;
        addr.sin_port = port;
        addr.sin_addr.s_addr = host;
-#if  defined(AFS_OSF_ENV) && defined(_KERNEL)
+#ifdef STRUCT_SOCKADDR_HAS_SA_LEN 
         addr.sin_len = sizeof(addr);
 #endif  /* AFS_OSF_ENV */
        drop = (*rx_justReceived) (np, &addr);
@@ -2590,7 +2535,7 @@ struct rx_packet *rxi_ReceivePacket(np, socket, host, port, tnop, newcallp)
                struct rx_packet *tp;
 
                rxi_CallError(call, RX_CALL_DEAD);
-               tp = rxi_SendSpecial(call, conn, np, RX_PACKET_TYPE_BUSY, (char *) 0, 0, 1);
+               tp = rxi_SendSpecial(call, conn, np, RX_PACKET_TYPE_BUSY, NULL, 0, 1);
                MUTEX_EXIT(&call->lock);
                MUTEX_ENTER(&conn->conn_data_lock);
                conn->refCount--;
@@ -2763,8 +2708,11 @@ struct rx_packet *rxi_ReceivePacket(np, socket, host, port, tnop, newcallp)
            /* Respond immediately to ack packets requesting acknowledgement
              * (ping packets) */
            if (np->header.flags & RX_REQUEST_ACK) {
-               if (call->error) (void) rxi_SendCallAbort(call, 0, 1, 0);
-               else (void) rxi_SendAck(call, 0, 0, 0, 0, RX_ACK_PING_RESPONSE, 1);
+               if (call->error)
+                   (void) rxi_SendCallAbort(call, 0, 1, 0);
+               else
+                   (void) rxi_SendAck(call, 0, 0, np->header.serial, 0,
+                                      RX_ACK_PING_RESPONSE, 1);
            }
            np = rxi_ReceiveAckPacket(call, np, 1);
            break;
@@ -2850,9 +2798,8 @@ int rxi_IsConnInteresting(struct rx_connection *aconn)
    the precall state then ignore all subsequent packets until the call
    is assigned to a thread. */
 
-static TooLow(ap, acall)
-  struct rx_call *acall;
-  struct rx_packet *ap; {
+static int TooLow(struct rx_packet *ap, struct rx_call *acall)
+{
     int rc=0;
     MUTEX_ENTER(&rx_stats_mutex);
     if (((ap->header.seq != 1) &&
@@ -2868,24 +2815,23 @@ static TooLow(ap, acall)
 }
 #endif /* KERNEL */
 
-static void rxi_CheckReachEvent(event, conn, acall)
-    struct rxevent *event;
-    struct rx_connection *conn;
-    struct rx_call *acall;
+static void rxi_CheckReachEvent(struct rxevent *event, 
+       struct rx_connection *conn, struct rx_call *acall)
 {
     struct rx_call *call = acall;
     struct clock when;
     int i, waiting;
 
-    MUTEX_ENTER(&conn->conn_call_lock);
     MUTEX_ENTER(&conn->conn_data_lock);
-    conn->checkReachEvent = (struct rxevent *) 0;
+    conn->checkReachEvent = NULL;
     waiting = conn->flags & RX_CONN_ATTACHWAIT;
     if (event) conn->refCount--;
     MUTEX_EXIT(&conn->conn_data_lock);
 
     if (waiting) {
-       if (!call)
+       if (!call) {
+           MUTEX_ENTER(&conn->conn_call_lock);
+           MUTEX_ENTER(&conn->conn_data_lock);
            for (i=0; i<RX_MAXCALLS; i++) {
                struct rx_call *tc = conn->call[i];
                if (tc && tc->state == RX_STATE_PRECALL) {
@@ -2893,38 +2839,43 @@ static void rxi_CheckReachEvent(event, conn, acall)
                    break;
                }
            }
+           if (!call)
+               /* Indicate that rxi_CheckReachEvent is no longer running by
+                * clearing the flag.  Must be atomic under conn_data_lock to
+                * avoid a new call slipping by: rxi_CheckConnReach holds
+                * conn_data_lock while checking RX_CONN_ATTACHWAIT.
+                */
+               conn->flags &= ~RX_CONN_ATTACHWAIT;
+           MUTEX_EXIT(&conn->conn_data_lock);
+           MUTEX_EXIT(&conn->conn_call_lock);
+       }
 
        if (call) {
            if (call != acall) MUTEX_ENTER(&call->lock);
            rxi_SendAck(call, NULL, 0, 0, 0, RX_ACK_PING, 0);
            if (call != acall) MUTEX_EXIT(&call->lock);
 
-           MUTEX_ENTER(&conn->conn_data_lock);
-           conn->refCount++;
-           MUTEX_EXIT(&conn->conn_data_lock);
            clock_GetTime(&when);
            when.sec += RX_CHECKREACH_TIMEOUT;
-           conn->checkReachEvent =
-               rxevent_Post(&when, rxi_CheckReachEvent, conn, NULL);
+           MUTEX_ENTER(&conn->conn_data_lock);
+           if (!conn->checkReachEvent) {
+               conn->refCount++;
+               conn->checkReachEvent =
+                   rxevent_Post(&when, rxi_CheckReachEvent, conn, NULL);
+           }
+           MUTEX_EXIT(&conn->conn_data_lock);
        }
     }
-    MUTEX_EXIT(&conn->conn_call_lock);
 }
 
-static int rxi_CheckConnReach(conn, call)
-    struct rx_connection *conn;
-    struct rx_call *call;
+static int rxi_CheckConnReach(struct rx_connection *conn, struct rx_call *call)
 {
     struct rx_service *service = conn->service;
     struct rx_peer *peer = conn->peer;
     afs_uint32 now, lastReach;
 
-    MUTEX_ENTER(&rx_serverPool_lock);
-    if (service->nRequestsRunning <= service->maxProcs/2) {
-       MUTEX_EXIT(&rx_serverPool_lock);
+    if (service->checkReach == 0)
        return 0;
-    }
-    MUTEX_EXIT(&rx_serverPool_lock);
 
     now = clock_Sec();
     MUTEX_ENTER(&peer->peer_lock);
@@ -2941,18 +2892,15 @@ static int rxi_CheckConnReach(conn, call)
     conn->flags |= RX_CONN_ATTACHWAIT;
     MUTEX_EXIT(&conn->conn_data_lock);
     if (!conn->checkReachEvent)
-       rxi_CheckReachEvent((struct rxevent *)0, conn, call);
+       rxi_CheckReachEvent(NULL, conn, call);
 
     return 1;
 }
 
 /* try to attach call, if authentication is complete */
-static void TryAttach(acall, socket, tnop, newcallp, reachOverride)
-    register struct rx_call *acall;
-    register osi_socket socket;
-    register int *tnop;
-    register struct rx_call **newcallp;
-    int reachOverride;
+static void TryAttach(register struct rx_call *acall, 
+       register osi_socket socket, register int *tnop, 
+       register struct rx_call **newcallp, int reachOverride)
 {
     struct rx_connection *conn = acall->conn;
 
@@ -2975,16 +2923,9 @@ static void TryAttach(acall, socket, tnop, newcallp, reachOverride)
  * 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 *rxi_ReceiveDataPacket(call, np, istack, socket, host,
-                                       port, tnop, newcallp)
-    register struct rx_call *call;
-    register struct rx_packet *np;
-    int istack;
-    osi_socket socket;
-    afs_uint32 host;
-    u_short port;
-    int *tnop;
-    struct rx_call **newcallp;
+struct rx_packet *rxi_ReceiveDataPacket(register struct rx_call *call, 
+       register struct rx_packet *np, int istack, osi_socket socket, 
+       afs_uint32 host, u_short port, int *tnop, struct rx_call **newcallp)
 {
     int ackNeeded = 0;
     int newPackets = 0;
@@ -3126,7 +3067,7 @@ struct rx_packet *rxi_ReceiveDataPacket(call, np, istack, socket, host,
             * (e.g. multi rx) */
            if (call->arrivalProc) {
                (*call->arrivalProc)(call, call->arrivalProcHandle,
-                                    call->arrivalProcArg);
+                                    (int) call->arrivalProcArg);
                call->arrivalProc = (VOID (*)()) 0;
            }
 
@@ -3326,9 +3267,7 @@ nextloop:;
 static void rxi_ComputeRate();
 #endif
 
-static void rxi_UpdatePeerReach(conn, acall)
-    struct rx_connection *conn;
-    struct rx_call *acall;
+static void rxi_UpdatePeerReach(struct rx_connection *conn, struct rx_call *acall)
 {
     struct rx_peer *peer = conn->peer;
 
@@ -3336,7 +3275,6 @@ static void rxi_UpdatePeerReach(conn, acall)
     peer->lastReachTime = clock_Sec();
     MUTEX_EXIT(&peer->peer_lock);
 
-    MUTEX_ENTER(&conn->conn_call_lock);
     MUTEX_ENTER(&conn->conn_data_lock);
     if (conn->flags & RX_CONN_ATTACHWAIT) {
        int i;
@@ -3348,20 +3286,38 @@ static void rxi_UpdatePeerReach(conn, acall)
            struct rx_call *call = conn->call[i];
            if (call) {
                if (call != acall) MUTEX_ENTER(&call->lock);
-               TryAttach(call, -1, NULL, NULL, 1);
+               TryAttach(call, (osi_socket) -1, NULL, NULL, 1);
                if (call != acall) MUTEX_EXIT(&call->lock);
            }
        }
     } else
        MUTEX_EXIT(&conn->conn_data_lock);
-    MUTEX_EXIT(&conn->conn_call_lock);
+}
+
+/* rxi_ComputePeerNetStats
+ *
+ * Called exclusively by rxi_ReceiveAckPacket to compute network link
+ * estimates (like RTT and throughput) based on ack packets.  Caller
+ * must ensure that the packet in question is the right one (i.e.
+ * serial number matches).
+ */
+static void
+rxi_ComputePeerNetStats(struct rx_call *call, struct rx_packet *p,
+       struct rx_ackPacket *ap, struct rx_packet *np)
+{
+    struct rx_peer *peer = call->conn->peer;
+
+    /* Use RTT if not delayed by client. */
+    if (ap->reason != RX_ACK_DELAY)
+       rxi_ComputeRoundTripTime(p, &p->timeSent, peer);
+#ifdef ADAPT_WINDOW
+    rxi_ComputeRate(peer, call, p, np, ap->reason);
+#endif
 }
 
 /* The real smarts of the whole thing.  */
-struct rx_packet *rxi_ReceiveAckPacket(call, np, istack)
-    register struct rx_call *call;
-    struct rx_packet *np;
-    int istack;
+struct rx_packet *rxi_ReceiveAckPacket(register struct rx_call *call, 
+       struct rx_packet *np, int istack)
 {
     struct rx_ackPacket *ap;
     int nAcks;
@@ -3424,15 +3380,6 @@ struct rx_packet *rxi_ReceiveAckPacket(call, np, istack)
     }
 #endif
 
-    /* if a server connection has been re-created, it doesn't remember what
-       serial # it was up to.  An ack will tell us, since the serial field
-       contains the largest serial received by the other side */
-    MUTEX_ENTER(&conn->conn_data_lock);
-    if ((conn->type == RX_SERVER_CONNECTION) && (conn->serial < serial)) {
-       conn->serial = serial+1;
-    }
-    MUTEX_EXIT(&conn->conn_data_lock);
-
     /* 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
@@ -3448,22 +3395,9 @@ struct rx_packet *rxi_ReceiveAckPacket(call, np, istack)
     for (queue_Scan(&call->tq, tp, nxp, rx_packet)) {
        if (tp->header.seq >= first) break;
        call->tfirst = tp->header.seq + 1;
-       if (tp->header.serial == serial) {
-         /* Use RTT if not delayed by client. */
-         if (ap->reason != RX_ACK_DELAY)
-             rxi_ComputeRoundTripTime(tp, &tp->timeSent, peer);
-#ifdef ADAPT_WINDOW
-         rxi_ComputeRate(peer, call, tp, np, ap->reason);
-#endif
-       }
-       else if (tp->firstSerial == serial) {
-           /* Use RTT if not delayed by client. */
-           if (ap->reason != RX_ACK_DELAY)
-               rxi_ComputeRoundTripTime(tp, &tp->firstSent, peer);
-#ifdef ADAPT_WINDOW
-         rxi_ComputeRate(peer, call, tp, np, ap->reason);
-#endif
-       }
+       if (serial && (tp->header.serial == serial ||
+                      tp->firstSerial == serial))
+           rxi_ComputePeerNetStats(call, tp, ap, np);
 #ifdef AFS_GLOBAL_RXLOCK_KERNEL
     /* XXX Hack. Because we have to release the global rx lock when sending
      * packets (osi_NetSend) we drop all acks while we're traversing the tq
@@ -3516,30 +3450,12 @@ struct rx_packet *rxi_ReceiveAckPacket(call, np, istack)
          * of this packet */
 #ifdef AFS_GLOBAL_RXLOCK_KERNEL
 #ifdef RX_ENABLE_LOCKS
-       if (tp->header.seq >= first) {
-#endif /* RX_ENABLE_LOCKS */
-#endif /* AFS_GLOBAL_RXLOCK_KERNEL */
-       if (tp->header.serial == serial) {
-           /* Use RTT if not delayed by client. */
-           if (ap->reason != RX_ACK_DELAY)
-               rxi_ComputeRoundTripTime(tp, &tp->timeSent, peer);
-#ifdef ADAPT_WINDOW
-         rxi_ComputeRate(peer, call, tp, np, ap->reason);
-#endif
-       }
-       else if ((tp->firstSerial == serial)) {
-           /* Use RTT if not delayed by client. */
-           if (ap->reason != RX_ACK_DELAY)
-               rxi_ComputeRoundTripTime(tp, &tp->firstSent, peer);
-#ifdef ADAPT_WINDOW
-         rxi_ComputeRate(peer, call, tp, np, ap->reason);
-#endif
-       }
-#ifdef AFS_GLOBAL_RXLOCK_KERNEL
-#ifdef RX_ENABLE_LOCKS
-       }
+       if (tp->header.seq >= first)
 #endif /* RX_ENABLE_LOCKS */
 #endif /* AFS_GLOBAL_RXLOCK_KERNEL */
+           if (serial && (tp->header.serial == serial ||
+                          tp->firstSerial == serial))
+               rxi_ComputePeerNetStats(call, tp, ap, np);
 
        /* Set the acknowledge flag per packet based on the
          * information in the ack packet. An acknowlegded packet can
@@ -3832,10 +3748,8 @@ struct rx_packet *rxi_ReceiveAckPacket(call, np, istack)
 }
 
 /* Received a response to a challenge packet */
-struct rx_packet *rxi_ReceiveResponsePacket(conn, np, istack)
-    register struct rx_connection *conn;
-    register struct rx_packet *np;
-    int istack;
+struct rx_packet *rxi_ReceiveResponsePacket(register struct rx_connection *conn, 
+       register struct rx_packet *np, int istack)
 {
     int error;
 
@@ -3870,7 +3784,7 @@ struct rx_packet *rxi_ReceiveResponsePacket(conn, np, istack)
            if (call) {
                MUTEX_ENTER(&call->lock);
                 if (call->state == RX_STATE_PRECALL)
-                    rxi_AttachServerProc(call, -1, NULL, NULL);
+                    rxi_AttachServerProc(call, (osi_socket) -1, NULL, NULL);
                MUTEX_EXIT(&call->lock);
            }
        }
@@ -3889,11 +3803,8 @@ struct rx_packet *rxi_ReceiveResponsePacket(conn, np, istack)
  * back to the server.  The server is responsible for retrying the
  * challenge if it fails to get a response. */
 
-struct rx_packet *
-rxi_ReceiveChallengePacket(conn, np, istack)
-    register struct rx_connection *conn;
-    register struct rx_packet *np;
-    int istack;
+struct rx_packet *rxi_ReceiveChallengePacket(register struct rx_connection *conn, 
+       register struct rx_packet *np, int istack)
 {
     int error;
 
@@ -3919,7 +3830,7 @@ rxi_ReceiveChallengePacket(conn, np, istack)
     }
     else {
        np = rxi_SendSpecial((struct rx_call *)0, conn, np,
-                            RX_PACKET_TYPE_RESPONSE, (char *) 0, -1, istack);
+                            RX_PACKET_TYPE_RESPONSE, NULL, -1, istack);
     }
     return np;
 }
@@ -3928,12 +3839,8 @@ rxi_ReceiveChallengePacket(conn, np, 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 
-rxi_AttachServerProc(call, socket, tnop, newcallp)
-    register struct rx_call *call;
-    register osi_socket socket;
-    register int *tnop;
-    register struct rx_call **newcallp;
+void rxi_AttachServerProc(register struct rx_call *call, 
+       register osi_socket socket, register int *tnop, register struct rx_call **newcallp)
 {
     register struct rx_serverQueueEntry *sq;
     register struct rx_service *service = call->conn->service;
@@ -4036,45 +3943,39 @@ rxi_AttachServerProc(call, socket, tnop, newcallp)
  * 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(event, call, dummy)
-struct rxevent *event;
-register struct rx_call *call;
-char *dummy;
+void rxi_AckAll(struct rxevent *event, register struct rx_call *call, char *dummy)
 {
 #ifdef RX_ENABLE_LOCKS
     if (event) {
        MUTEX_ENTER(&call->lock);
-       call->delayedAckEvent = (struct rxevent *) 0;
+       call->delayedAckEvent = NULL;
        CALL_RELE(call, RX_CALL_REFCOUNT_ACKALL);
     }
     rxi_SendSpecial(call, call->conn, (struct rx_packet *) 0,
-                   RX_PACKET_TYPE_ACKALL, (char *) 0, 0, 0);
+                   RX_PACKET_TYPE_ACKALL, NULL, 0, 0);
     if (event)
        MUTEX_EXIT(&call->lock);
 #else /* RX_ENABLE_LOCKS */
-    if (event) call->delayedAckEvent = (struct rxevent *) 0;
+    if (event) call->delayedAckEvent = NULL;
     rxi_SendSpecial(call, call->conn, (struct rx_packet *) 0,
-                   RX_PACKET_TYPE_ACKALL, (char *) 0, 0, 0);
+                   RX_PACKET_TYPE_ACKALL, NULL, 0, 0);
 #endif /* RX_ENABLE_LOCKS */
 }
 
-void rxi_SendDelayedAck(event, call, dummy)    
-struct rxevent *event;
-register struct rx_call *call;
-char *dummy;
+void rxi_SendDelayedAck(struct rxevent *event, register struct rx_call *call, char *dummy)
 {
 #ifdef RX_ENABLE_LOCKS
     if (event) {
        MUTEX_ENTER(&call->lock);
        if (event == call->delayedAckEvent)
-           call->delayedAckEvent = (struct rxevent *) 0;
+           call->delayedAckEvent = NULL;
        CALL_RELE(call, RX_CALL_REFCOUNT_DELAY);
     }
     (void) rxi_SendAck(call, 0, 0, 0, 0, RX_ACK_DELAY, 0);
     if (event)
        MUTEX_EXIT(&call->lock);
 #else /* RX_ENABLE_LOCKS */
-    if (event) call->delayedAckEvent = (struct rxevent *) 0;
+    if (event) call->delayedAckEvent = NULL;
     (void) rxi_SendAck(call, 0, 0, 0, 0, RX_ACK_DELAY, 0);
 #endif /* RX_ENABLE_LOCKS */
 }
@@ -4084,8 +3985,7 @@ char *dummy;
 /* Set ack in all packets in transmit queue. rxi_Start will deal with
  * clearing them out.
  */
-static void rxi_SetAcksInTransmitQueue(call)
-      register struct rx_call *call;
+static void rxi_SetAcksInTransmitQueue(register struct rx_call *call)
 {
     register struct rx_packet *p, *tp;
     int someAcked = 0;
@@ -4118,9 +4018,7 @@ static void rxi_SetAcksInTransmitQueue(call)
 
 /* Clear out the transmit queue for the current call (all packets have
  * been received by peer) */
-void rxi_ClearTransmitQueue(call, force)
-    register struct rx_call *call;
-    register int force;
+void rxi_ClearTransmitQueue(register struct rx_call *call, register int force)
 {
     register struct rx_packet *p, *tp;
 
@@ -4167,8 +4065,7 @@ void rxi_ClearTransmitQueue(call, force)
 #endif
 }
 
-void rxi_ClearReceiveQueue(call)
-    register struct rx_call *call;
+void rxi_ClearReceiveQueue(register struct rx_call *call)
 {
     register struct rx_packet *p, *tp;
     if (queue_IsNotEmpty(&call->rq)) {
@@ -4187,11 +4084,8 @@ void rxi_ClearReceiveQueue(call)
 }
 
 /* Send an abort packet for the specified call */
-struct rx_packet *rxi_SendCallAbort(call, packet, istack, force)
-    register struct rx_call *call;
-    struct rx_packet *packet;
-    int istack;
-    int force;
+struct rx_packet *rxi_SendCallAbort(register struct rx_call *call, 
+       struct rx_packet *packet, int istack, int force)
 {
   afs_int32 error;
   struct clock when;
@@ -4237,11 +4131,8 @@ struct rx_packet *rxi_SendCallAbort(call, packet, istack, force)
  * NOTE: Called with conn_data_lock held. conn_data_lock is dropped
  *       to send the abort packet.
  */
-struct rx_packet *rxi_SendConnectionAbort(conn, packet, istack, force)
-    register struct rx_connection *conn;
-    struct rx_packet *packet;
-    int istack;
-    int force;
+struct rx_packet *rxi_SendConnectionAbort(register struct rx_connection *conn,
+        struct rx_packet *packet, int istack, int force)
 {
   afs_int32 error;
   struct clock when;
@@ -4279,18 +4170,21 @@ struct rx_packet *rxi_SendConnectionAbort(conn, packet, istack, force)
  * bad authentication responses.  The connection itself is set in
  * error at this point, so that future packets received will be
  * rejected. */
-void rxi_ConnectionError(conn, error)
-    register struct rx_connection *conn;
-    register afs_int32 error;
+void rxi_ConnectionError(register struct rx_connection *conn, 
+       register afs_int32 error)
 {
     if (error) {
        register int i;
+       MUTEX_ENTER(&conn->conn_data_lock);
        if (conn->challengeEvent)
            rxevent_Cancel(conn->challengeEvent, (struct rx_call*)0, 0);
        if (conn->checkReachEvent) {
            rxevent_Cancel(conn->checkReachEvent, (struct rx_call*)0, 0);
            conn->checkReachEvent = 0;
+           conn->flags &= ~RX_CONN_ATTACHWAIT;
+           conn->refCount--;
        }
+       MUTEX_EXIT(&conn->conn_data_lock);
        for (i=0; i<RX_MAXCALLS; i++) {
            struct rx_call *call = conn->call[i];
            if (call) {
@@ -4306,9 +4200,7 @@ void rxi_ConnectionError(conn, error)
     }
 }
 
-void rxi_CallError(call, error)
-    register struct rx_call *call;
-    afs_int32 error;
+void rxi_CallError(register struct rx_call *call, afs_int32 error)
 {
     if (call->error) error = call->error;
 #ifdef RX_GLOBAL_RXLOCK_KERNEL
@@ -4332,9 +4224,7 @@ void rxi_CallError(call, error)
 /* this code requires that call->conn be set properly as a pre-condition. */
 #endif /* ADAPT_WINDOW */
 
-void rxi_ResetCall(call, newcall)
-    register struct rx_call *call;
-    register int newcall;
+void rxi_ResetCall(register struct rx_call *call, register int newcall)
 {
     register int flags;
     register struct rx_peer *peer;
@@ -4342,7 +4232,7 @@ void rxi_ResetCall(call, newcall)
 
     /* Notify anyone who is waiting for asynchronous packet arrival */
     if (call->arrivalProc) {
-       (*call->arrivalProc)(call, call->arrivalProcHandle, call->arrivalProcArg);
+       (*call->arrivalProc)(call, call->arrivalProcHandle, (int) call->arrivalProcArg);
        call->arrivalProc = (VOID (*)()) 0;
     }
 
@@ -4485,14 +4375,17 @@ void rxi_ResetCall(call, newcall)
  * NOW there is a trailer field, after the ack where it will safely be
  * ignored by mundanes, which indicates the maximum size packet this 
  * host can swallow.  */  
-struct rx_packet *rxi_SendAck(call, optionalPacket, seq, serial, pflags, reason, istack)
-    register struct rx_call *call;
-    register struct rx_packet *optionalPacket; /* use to send ack (or null) */
-    int        seq;                    /* Sequence number of the packet we are acking */
-    int        serial;                 /* Serial number of the packet */
-    int        pflags;                 /* Flags field from packet header */
-    int        reason;                 /* Reason an acknowledge was prompted */
-    int istack;
+/*
+    register struct rx_packet *optionalPacket;  use to send ack (or null) 
+    int        seq;                     Sequence number of the packet we are acking 
+    int        serial;                  Serial number of the packet 
+    int        pflags;                  Flags field from packet header 
+    int        reason;                  Reason an acknowledge was prompted 
+*/
+
+struct rx_packet *rxi_SendAck(register struct rx_call *call, 
+       register struct rx_packet *optionalPacket, int seq, int serial, 
+       int pflags, int reason, int istack)
 {
     struct rx_ackPacket *ap;
     register struct rx_packet *rqp;
@@ -4544,7 +4437,7 @@ struct rx_packet *rxi_SendAck(call, optionalPacket, seq, serial, pflags, reason,
 
     /* The skew computation used to be bogus, I think it's better now. */
     /* We should start paying attention to skew.    XXX  */
-    ap->serial = htonl(call->conn->maxSerial);
+    ap->serial = htonl(serial);
     ap->maxSkew        = 0;    /* used to be peer->inPacketSkew */
 
     ap->firstPacket = htonl(call->rnext); /* First packet not yet forwarded to reader */
@@ -4648,15 +4541,9 @@ struct rx_packet *rxi_SendAck(call, optionalPacket, seq, serial, pflags, reason,
 }
 
 /* Send all of the packets in the list in single datagram */
-static void rxi_SendList(call, list, len, istack, moreFlag, now, retryTime, resending)
-  struct rx_call *call;
-  struct rx_packet **list;
-  int len;
-  int istack;
-  int moreFlag;
-  struct clock *now;
-  struct clock *retryTime;
-  int resending;
+static void rxi_SendList(struct rx_call *call, struct rx_packet **list, 
+       int len, int istack, int moreFlag, struct clock *now, 
+       struct clock *retryTime, int resending)
 {
     int i;
     int requestAck = 0;
@@ -4769,14 +4656,9 @@ static void rxi_SendList(call, list, len, istack, moreFlag, now, retryTime, rese
  * We always keep the last list we should have sent so we
  * can set the RX_MORE_PACKETS flags correctly.
  */
-static void rxi_SendXmitList(call, list, len, istack, now, retryTime, resending)
-  struct rx_call *call;
-  struct rx_packet **list;
-  int len;
-  int istack;
-  struct clock *now;
-  struct clock *retryTime;
-  int resending;
+static void rxi_SendXmitList(struct rx_call *call, struct rx_packet **list, 
+       int len, int istack, struct clock *now, struct clock *retryTime, 
+       int resending)
 {
     int i, cnt, lastCnt = 0;
     struct rx_packet **listP, **lastP = 0;
@@ -4864,10 +4746,8 @@ static void rxi_SendXmitList(call, list, len, istack, now, retryTime, resending)
 
 #ifdef RX_ENABLE_LOCKS
 /* Call rxi_Start, below, but with the call lock held. */
-void rxi_StartUnlocked(event, call, istack)
-    struct rxevent *event;
-    register struct rx_call *call;
-    int istack;
+void rxi_StartUnlocked(struct rxevent *event, register struct rx_call *call, 
+       int istack)
 {
     MUTEX_ENTER(&call->lock);
     rxi_Start(event, call, istack);
@@ -4880,10 +4760,8 @@ void rxi_StartUnlocked(event, call, istack)
  * transmission window or burst count are favourable.  This should be
  * better optimized for new packets, the usual case, now that we've
  * got rid of queues of send packets. XXXXXXXXXXX */
-void rxi_Start(event, call, istack)
-    struct rxevent *event;
-    register struct rx_call *call;
-    int istack;
+void rxi_Start(struct rxevent *event, register struct rx_call *call, 
+        int istack)
 {
     struct rx_packet *p;
     register struct rx_packet *nxp;  /* Next pointer for queue_Scan */
@@ -5150,10 +5028,10 @@ void rxi_Start(event, call, istack)
            CALL_HOLD(call, RX_CALL_REFCOUNT_RESEND);
            call->resendEvent = rxevent_Post(&retryTime,
                                             rxi_StartUnlocked,
-                                            (char *)call, istack);
+                                            (void *)call, (void *)istack);
 #else /* RX_ENABLE_LOCKS */
            call->resendEvent = rxevent_Post(&retryTime, rxi_Start,
-                                            (char *)call, (void*)(long)istack);
+                                            (void *)call, (void *)istack);
 #endif /* RX_ENABLE_LOCKS */
          }
        }
@@ -5186,10 +5064,8 @@ void rxi_Start(event, call, istack)
 /* Also adjusts the keep alive parameters for the call, to reflect
  * that we have just sent a packet (so keep alives aren't sent
  * immediately) */
-void rxi_Send(call, p, istack)
-    register struct rx_call *call;             
-    register struct rx_packet *p;
-    int istack;
+void rxi_Send(register struct rx_call *call, register struct rx_packet *p, 
+       int istack)
 {
     register struct rx_connection *conn = call->conn;
 
@@ -5223,14 +5099,13 @@ void rxi_Send(call, p, istack)
  * falls through the cracks (e.g. (error + dally) connections have keepalive
  * turned off.  Returns 0 if conn is well, -1 otherwise.  If otherwise, call
  *  may be freed!
+ * haveCTLock Set if calling from rxi_ReapConnections
  */
 #ifdef RX_ENABLE_LOCKS
-int rxi_CheckCall(call, haveCTLock)
-    int haveCTLock; /* Set if calling from rxi_ReapConnections */
+int rxi_CheckCall(register struct rx_call *call, int haveCTLock)
 #else /* RX_ENABLE_LOCKS */
-int rxi_CheckCall(call)
+int rxi_CheckCall(register struct rx_call *call)
 #endif /* RX_ENABLE_LOCKS */
-    register struct rx_call *call;
 {
     register struct rx_connection *conn = call->conn;
     register struct rx_service *tservice;
@@ -5305,9 +5180,8 @@ int rxi_CheckCall(call)
  * declared dead; if nothing has been sent for a while, we send a
  * keep-alive packet (if we're actually trying to keep the call alive)
  */
-void rxi_KeepAliveEvent(event, call, dummy)
-    struct rxevent *event;
-    register struct rx_call *call;
+void rxi_KeepAliveEvent(struct rxevent *event, register struct rx_call *call, 
+       char *dummy)
 {
     struct rx_connection *conn;
     afs_uint32 now;
@@ -5315,7 +5189,7 @@ void rxi_KeepAliveEvent(event, call, dummy)
     MUTEX_ENTER(&call->lock);
     CALL_RELE(call, RX_CALL_REFCOUNT_ALIVE);
     if (event == call->keepAliveEvent)
-       call->keepAliveEvent = (struct rxevent *) 0;
+       call->keepAliveEvent = NULL;
     now = clock_Sec();
 
 #ifdef RX_ENABLE_LOCKS
@@ -5345,8 +5219,7 @@ void rxi_KeepAliveEvent(event, call, dummy)
 }
 
 
-void rxi_ScheduleKeepAliveEvent(call)
-    register struct rx_call *call;
+void rxi_ScheduleKeepAliveEvent(register struct rx_call *call)
 {
     if (!call->keepAliveEvent) {
       struct clock when;
@@ -5358,8 +5231,7 @@ void rxi_ScheduleKeepAliveEvent(call)
 }
 
 /* N.B. rxi_KeepAliveOff:  is defined earlier as a macro */
-void rxi_KeepAliveOn(call)
-    register struct rx_call *call;
+void rxi_KeepAliveOn(register struct rx_call *call)
 {
     /* Pretend last packet received was received now--i.e. if another
      * packet isn't received within the keep alive time, then the call
@@ -5372,16 +5244,14 @@ void rxi_KeepAliveOn(call)
 
 /* This routine is called to send connection abort messages
  * that have been delayed to throttle looping clients. */
-void rxi_SendDelayedConnAbort(event, conn, dummy)
-    struct rxevent *event;
-    register struct rx_connection *conn;
-    char *dummy;
+void rxi_SendDelayedConnAbort(struct rxevent *event, register struct rx_connection *conn, 
+       char *dummy)
 {
     afs_int32 error;
     struct rx_packet *packet;
 
     MUTEX_ENTER(&conn->conn_data_lock);
-    conn->delayedAbortEvent = (struct rxevent *) 0;
+    conn->delayedAbortEvent = NULL;
     error = htonl(conn->error);
     conn->abortCount++;
     MUTEX_EXIT(&conn->conn_data_lock);
@@ -5396,16 +5266,14 @@ void rxi_SendDelayedConnAbort(event, conn, dummy)
 
 /* This routine is called to send call abort messages
  * that have been delayed to throttle looping clients. */
-void rxi_SendDelayedCallAbort(event, call, dummy)
-    struct rxevent *event;
-    register struct rx_call *call;
-    char *dummy;
+void rxi_SendDelayedCallAbort(struct rxevent *event, register struct rx_call *call,
+        char *dummy)
 {
     afs_int32 error;
     struct rx_packet *packet;
 
     MUTEX_ENTER(&call->lock);
-    call->delayedAbortEvent = (struct rxevent *) 0;
+    call->delayedAbortEvent = NULL;
     error = htonl(call->error);
     call->abortCount++;
     packet = rxi_AllocPacket(RX_PACKET_CLASS_SPECIAL);
@@ -5422,13 +5290,11 @@ void rxi_SendDelayedCallAbort(event, call, dummy)
  * 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 rxi_ChallengeEvent(event, conn, atries)
-    struct rxevent *event;
-    register struct rx_connection *conn;
-    void *atries;
+void rxi_ChallengeEvent(struct rxevent *event, register struct rx_connection *conn, 
+       void *atries)
 {
     int tries = (int) atries;
-    conn->challengeEvent = (struct rxevent *) 0;
+    conn->challengeEvent = NULL;
     if (RXS_CheckAuthentication(conn->securityObject, conn) != 0) {
        register struct rx_packet *packet;
        struct clock when;
@@ -5461,7 +5327,7 @@ void rxi_ChallengeEvent(event, conn, atries)
            /* If there's no packet available, do this later. */
            RXS_GetChallenge(conn->securityObject, conn, packet);
            rxi_SendSpecial((struct rx_call *) 0, conn, packet,
-                           RX_PACKET_TYPE_CHALLENGE, (char *) 0, -1, 0);
+                           RX_PACKET_TYPE_CHALLENGE, NULL, -1, 0);
            rxi_FreePacket(packet);
        }
        clock_GetTime(&when);
@@ -5477,8 +5343,7 @@ void rxi_ChallengeEvent(event, conn, atries)
  * 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 rxi_ChallengeOn(conn)
-    register struct rx_connection *conn;
+void rxi_ChallengeOn(register struct rx_connection *conn)
 {
     if (!conn->challengeEvent) {
        RXS_CreateChallenge(conn->securityObject, conn);
@@ -5491,10 +5356,9 @@ void rxi_ChallengeOn(conn)
  */
 
 /* rxi_ComputeRoundTripTime is called with peer locked. */
-void rxi_ComputeRoundTripTime(p, sentp, peer)
-    register struct clock *sentp;   /* may be null */
-    register struct rx_peer *peer;  /* may be null */
-    register struct rx_packet *p;
+/* sentp and/or peer may be null */
+void rxi_ComputeRoundTripTime(register struct rx_packet *p, 
+       register struct clock *sentp, register struct rx_peer *peer)
 {
        struct clock thisRtt, *rttp = &thisRtt;
 
@@ -5596,7 +5460,7 @@ void rxi_ComputeRoundTripTime(p, sentp, peer)
 
 /* Find all server connections that have not been active for a long time, and
  * toss them */
-void rxi_ReapConnections()
+void rxi_ReapConnections(void)
 {
     struct clock now;
     clock_GetTime(&now);
@@ -5759,8 +5623,7 @@ void rxi_ReapConnections()
  * This is the only rxs module call.  A hold could also be written but no one
  * needs it. */
 
-int rxs_Release (aobj)
-  struct rx_securityClass *aobj;
+int rxs_Release (struct rx_securityClass *aobj)
 {
     return RXS_Close (aobj);
 }
@@ -5778,11 +5641,9 @@ int rxs_Release (aobj)
  * Called with peer and call locked.
  */
 
-static void rxi_ComputeRate(peer, call, p, ackp, ackReason)
-    register struct rx_peer *peer;
-    register struct rx_call *call;
-    struct rx_packet *p, *ackp;
-    u_char ackReason;
+static void rxi_ComputeRate(register struct rx_peer *peer, 
+       register struct rx_call *call, struct rx_packet *p, 
+       struct rx_packet *ackp, u_char ackReason)
 {
     afs_int32 xferSize, xferMs;
     register afs_int32 minTime;
@@ -5926,9 +5787,8 @@ return;
 #ifdef RXDEBUG
 /* Don't call this debugging routine directly; use dpf */
 void 
-rxi_DebugPrint(format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, 
-              a11, a12, a13, a14, a15)
-    char *format;
+rxi_DebugPrint(char *format, int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8, int a9, int a10, 
+              int a11, int a12, int a13, int a14, int a15)
 {
     struct clock now;
     clock_GetTime(&now);
@@ -5945,12 +5805,8 @@ rxi_DebugPrint(format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
  * process (via rxdebug).  Therefore, it needs to do minimal version
  * checking.
  */
-void rx_PrintTheseStats (file, s, size, freePackets, version)
-  FILE *file;
-  struct rx_stats *s;
-  int size;                            /* some idea of version control */
-  afs_int32 freePackets;
-  char version;
+void rx_PrintTheseStats (FILE *file, struct rx_stats *s, int size, 
+       afs_int32 freePackets, char version)
 {
     int i;
 
@@ -6077,17 +5933,14 @@ void rx_PrintTheseStats (file, s, size, freePackets, version)
 }
 
 /* for backward compatibility */
-void rx_PrintStats(file)
-  FILE *file;
+void rx_PrintStats(FILE *file)
 {
     MUTEX_ENTER(&rx_stats_mutex);
     rx_PrintTheseStats (file, &rx_stats, sizeof(rx_stats), rx_nFreePackets, RX_DEBUGI_VERSION);
     MUTEX_EXIT(&rx_stats_mutex);
 }
 
-void rx_PrintPeerStats(file, peer)
-FILE *file;
-struct rx_peer *peer;
+void rx_PrintPeerStats(FILE *file, struct rx_peer *peer)
 {
     fprintf(file,
            "Peer %x.%d.  "
@@ -6132,16 +5985,9 @@ struct rx_peer *peer;
 #define UNLOCK_RX_DEBUG
 #endif /* AFS_PTHREAD_ENV */
 
-static int MakeDebugCall(
-  int socket,
-  afs_uint32 remoteAddr,
-  afs_uint16 remotePort,
-  u_char type,
-  void *inputData,
-  size_t inputLength,
-  void *outputData,
-  size_t outputLength
-)
+static int MakeDebugCall(osi_socket socket, afs_uint32 remoteAddr, 
+       afs_uint16 remotePort, u_char type, void *inputData, size_t inputLength,
+       void *outputData, size_t outputLength)
 {
     static afs_int32 counter = 100;
     afs_int32 endTime;
@@ -6162,6 +6008,9 @@ static int MakeDebugCall(
     taddr.sin_family = AF_INET;
     taddr.sin_port = remotePort;
     taddr.sin_addr.s_addr = remoteAddr;
+#ifdef STRUCT_SOCKADDR_HAS_SA_LEN
+    taddr.sin_len = sizeof(struct sockaddr_in);
+#endif
     while(1) {
        memset(&theader, 0, sizeof(theader));
        theader.epoch = htonl(999);
@@ -6203,13 +6052,8 @@ static int MakeDebugCall(
     return code;
 }
 
-afs_int32 rx_GetServerDebug(
-  int socket,
-  afs_uint32 remoteAddr,
-  afs_uint16 remotePort,
-  struct rx_debugStats *stat,
-  afs_uint32 *supportedValues
-)
+afs_int32 rx_GetServerDebug(osi_socket socket, afs_uint32 remoteAddr, 
+       afs_uint16 remotePort, struct rx_debugStats *stat, afs_uint32 *supportedValues)
 {
     struct rx_debugIn in;
     afs_int32 rc = 0;
@@ -6266,13 +6110,8 @@ afs_int32 rx_GetServerDebug(
     return rc;
 }
 
-afs_int32 rx_GetServerStats(
-  int socket,
-  afs_uint32 remoteAddr,
-  afs_uint16 remotePort,
-  struct rx_stats *stat,
-  afs_uint32 *supportedValues
-)
+afs_int32 rx_GetServerStats(osi_socket socket, afs_uint32 remoteAddr,
+       afs_uint16 remotePort, struct rx_stats *stat, afs_uint32 *supportedValues)
 {
     struct rx_debugIn in;
     afs_int32 *lp = (afs_int32 *) stat;
@@ -6312,13 +6151,8 @@ afs_int32 rx_GetServerStats(
     return rc;
 }
 
-afs_int32 rx_GetServerVersion(
-  int socket,
-  afs_uint32 remoteAddr,
-  afs_uint16 remotePort,
-  size_t version_length,
-  char *version
-)
+afs_int32 rx_GetServerVersion(osi_socket socket, afs_uint32 remoteAddr,
+       afs_uint16 remotePort, size_t version_length, char *version)
 {
     char a[1] = {0};
     return MakeDebugCall(socket,
@@ -6331,16 +6165,9 @@ afs_int32 rx_GetServerVersion(
                         version_length);
 }
 
-afs_int32 rx_GetServerConnections(
-  int socket,
-  afs_uint32 remoteAddr,
-  afs_uint16 remotePort,
-  afs_int32 *nextConnection,
-  int allConnections,
-  afs_uint32 debugSupportedValues,
-  struct rx_debugConn *conn,
-  afs_uint32 *supportedValues
-)
+afs_int32 rx_GetServerConnections(osi_socket socket, afs_uint32 remoteAddr,
+       afs_uint16 remotePort, afs_int32 *nextConnection, int allConnections,
+       afs_uint32 debugSupportedValues, struct rx_debugConn *conn, afs_uint32 *supportedValues)
 {
     struct rx_debugIn in;
     afs_int32 rc = 0;
@@ -6424,15 +6251,9 @@ afs_int32 rx_GetServerConnections(
     return rc;
 }
 
-afs_int32 rx_GetServerPeers(
-  int socket,
-  afs_uint32 remoteAddr,
-  afs_uint16 remotePort,
-  afs_int32 *nextPeer,
-  afs_uint32 debugSupportedValues,
-  struct rx_debugPeer *peer,
-  afs_uint32 *supportedValues
-)
+afs_int32 rx_GetServerPeers(osi_socket socket, afs_uint32 remoteAddr, afs_uint16 remotePort,
+       afs_int32 *nextPeer, afs_uint32 debugSupportedValues, struct rx_debugPeer *peer,
+       afs_uint32 *supportedValues)
 {
     struct rx_debugIn in;
     afs_int32 rc = 0;
@@ -6501,8 +6322,10 @@ void shutdown_rx(void)
 {
     struct rx_serverQueueEntry *np;
     register int i, j;
+#ifndef KERNEL
     register struct rx_call *call;
     register struct rx_serverQueueEntry *sq;
+#endif /* KERNEL */
 
     LOCK_RX_INIT
     if (rxinit_status == 1) {
@@ -6896,16 +6719,9 @@ fail:
  * Returns void.
  */
 
-void rx_IncrementTimeAndCount(
-  struct rx_peer *peer,
-  afs_uint32 rxInterface,
-  afs_uint32 currentFunc,
-  afs_uint32 totalFunc,
-  struct clock *queueTime,
-  struct clock *execTime,
-  afs_hyper_t *bytesSent,
-  afs_hyper_t *bytesRcvd,
-  int isServer)
+void rx_IncrementTimeAndCount(struct rx_peer *peer, afs_uint32 rxInterface,
+       afs_uint32 currentFunc, afs_uint32 totalFunc, struct clock *queueTime,
+       struct clock *execTime, afs_hyper_t *bytesSent, afs_hyper_t *bytesRcvd, int isServer)
 {
 
     MUTEX_ENTER(&rx_rpc_stats);
@@ -6965,11 +6781,8 @@ void rx_IncrementTimeAndCount(
  *
  * Returns void.
  */
-void rx_MarshallProcessRPCStats(
-    afs_uint32 callerVersion,
-    int count,
-    rx_function_entry_v1_t *stats,
-    afs_uint32 **ptrP)
+void rx_MarshallProcessRPCStats(afs_uint32 callerVersion,
+       int count, rx_function_entry_v1_t *stats, afs_uint32 **ptrP)
 {
     int i;
     afs_uint32 *ptr;
@@ -7035,14 +6848,9 @@ void rx_MarshallProcessRPCStats(
  * Returns void.  If successful, stats will != NULL.
  */
 
-int rx_RetrieveProcessRPCStats(
-  afs_uint32 callerVersion,
-  afs_uint32 *myVersion,
-  afs_uint32 *clock_sec,
-  afs_uint32 *clock_usec,
-  size_t *allocSize,
-  afs_uint32 *statCount,
-  afs_uint32 **stats)
+int rx_RetrieveProcessRPCStats(afs_uint32 callerVersion,
+       afs_uint32 *myVersion, afs_uint32 *clock_sec, afs_uint32 *clock_usec,
+       size_t *allocSize, afs_uint32 *statCount, afs_uint32 **stats)
 {
     size_t space = 0;
     afs_uint32 *ptr;
@@ -7137,14 +6945,9 @@ int rx_RetrieveProcessRPCStats(
  * Returns void.  If successful, stats will != NULL.
  */
 
-int rx_RetrievePeerRPCStats(
-  afs_uint32 callerVersion,
-  afs_uint32 *myVersion,
-  afs_uint32 *clock_sec,
-  afs_uint32 *clock_usec,
-  size_t *allocSize,
-  afs_uint32 *statCount,
-  afs_uint32 **stats)
+int rx_RetrievePeerRPCStats(afs_uint32 callerVersion,
+       afs_uint32 *myVersion, afs_uint32 *clock_sec, afs_uint32 *clock_usec,
+       size_t *allocSize, afs_uint32 *statCount, afs_uint32 **stats)
 {
     size_t space = 0;
     afs_uint32 *ptr;
@@ -7244,9 +7047,7 @@ int rx_RetrievePeerRPCStats(
  * Returns void.
  */
 
-void rx_FreeRPCStats(
-  afs_uint32 *stats,
-  size_t allocSize)
+void rx_FreeRPCStats(afs_uint32 *stats, size_t allocSize)
 {
     rxi_Free(stats, allocSize);
 }
@@ -7262,7 +7063,7 @@ void rx_FreeRPCStats(
  * Returns 0 if stats are not enabled != 0 otherwise
  */
 
-int rx_queryProcessRPCStats()
+int rx_queryProcessRPCStats(void)
 {
     int rc;
     MUTEX_ENTER(&rx_rpc_stats);
@@ -7281,7 +7082,7 @@ int rx_queryProcessRPCStats()
  * Returns 0 if stats are not enabled != 0 otherwise
  */
 
-int rx_queryPeerRPCStats()
+int rx_queryPeerRPCStats(void)
 {
     int rc;
     MUTEX_ENTER(&rx_rpc_stats);
@@ -7300,7 +7101,7 @@ int rx_queryPeerRPCStats()
  * Returns void.
  */
 
-void rx_enableProcessRPCStats()
+void rx_enableProcessRPCStats(void)
 {
     MUTEX_ENTER(&rx_rpc_stats);
     rx_enable_stats = 1;
@@ -7318,7 +7119,7 @@ void rx_enableProcessRPCStats()
  * Returns void.
  */
 
-void rx_enablePeerRPCStats()
+void rx_enablePeerRPCStats(void)
 {
     MUTEX_ENTER(&rx_rpc_stats);
     rx_enable_stats = 1;
@@ -7336,7 +7137,7 @@ void rx_enablePeerRPCStats()
  * Returns void.
  */
 
-void rx_disableProcessRPCStats()
+void rx_disableProcessRPCStats(void)
 {
     rx_interface_stat_p rpc_stat, nrpc_stat;
     size_t space;
@@ -7378,7 +7179,7 @@ void rx_disableProcessRPCStats()
  * Returns void.
  */
 
-void rx_disablePeerRPCStats()
+void rx_disablePeerRPCStats(void)
 {
     struct rx_peer **peer_ptr, **peer_end;
     int code;
@@ -7450,8 +7251,7 @@ void rx_disablePeerRPCStats()
  * Returns void.
  */
 
-void rx_clearProcessRPCStats(
-  afs_uint32 clearFlag)
+void rx_clearProcessRPCStats(afs_uint32 clearFlag)
 {
     rx_interface_stat_p rpc_stat, nrpc_stat;
 
@@ -7521,8 +7321,7 @@ void rx_clearProcessRPCStats(
  * Returns void.
  */
 
-void rx_clearPeerRPCStats(
-  afs_uint32 clearFlag)
+void rx_clearPeerRPCStats(afs_uint32 clearFlag)
 {
     rx_interface_stat_p rpc_stat, nrpc_stat;
 
@@ -7600,14 +7399,12 @@ void rx_clearPeerRPCStats(
  */
 static int (*rxi_rxstat_userok)(struct rx_call *call) = NULL;
 
-void rx_SetRxStatUserOk(
-  int (*proc)(struct rx_call *call))
+void rx_SetRxStatUserOk(int (*proc)(struct rx_call *call))
 {
        rxi_rxstat_userok = proc;
 }
 
-int rx_RxStatUserOk(
-  struct rx_call *call)
+int rx_RxStatUserOk(struct rx_call *call)
 {
        if (!rxi_rxstat_userok)
                return 0;