Remove dead code from rxi_FindIfnet()
[openafs.git] / src / rx / rx_kcommon.c
index 7aa71a9..64d95e9 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Copyright 2000, International Business Machines Corporation and others.
  * All Rights Reserved.
- * 
+ *
  * This software has been released under the terms of the IBM Public
  * License.  For details, see the LICENSE file in the top-level source
  * directory or online at http://www.openafs.org/dl/license10.html
  */
 
 #include <afsconfig.h>
-#include "afs/param.h"
+#include <afs/param.h>
 
 
 #include "rx/rx_kcommon.h"
+#include "rx_atomic.h"
+#include "rx_stats.h"
 
 #ifdef AFS_HPUX110_ENV
 #include "h/tihdr.h"
@@ -122,46 +124,6 @@ rxi_GetUDPSocket(u_short port)
     return rxi_GetHostUDPSocket(htonl(INADDR_ANY), port);
 }
 
-#if !defined(AFS_LINUX26_ENV)
-void
-#if defined(AFS_AIX_ENV) || defined(AFS_SGI_ENV)
-osi_Panic(char *msg, void *a1, void *a2, void *a3)
-#else
-osi_Panic(char *msg, ...)
-#endif
-{
-#if defined(AFS_AIX_ENV) || defined(AFS_SGI_ENV)
-    if (!msg)
-        msg = "Unknown AFS panic";
-    printf(msg, a1, a2, a3);
-    panic(msg);
-#elif (defined(AFS_DARWIN80_ENV) && !defined(AFS_DARWIN90_ENV)) || (defined(AFS_LINUX22_ENV) && !defined(AFS_LINUX_26_ENV))
-    char buf[256];
-    va_list ap;
-    if (!msg)
-       msg = "Unknown AFS panic";
-
-    va_start(ap, msg);
-    vsnprintf(buf, sizeof(buf), msg, ap);
-    va_end(ap);
-    printf(buf);
-    panic(buf);
-#else
-    va_list ap;
-    if (!msg)
-       msg = "Unknown AFS panic";
-
-    va_start(ap, msg);
-    vprintf(msg, ap);
-    va_end(ap);
-# ifdef AFS_LINUX20_ENV
-    * ((char *) 0) = 0; 
-# else
-    panic(msg);
-# endif
-#endif
-}
-
 /*
  * osi_utoa() - write the NUL-terminated ASCII decimal form of the given
  * unsigned long value into the given buffer.  Returns 0 on success,
@@ -232,6 +194,7 @@ osi_utoa(char *buf, size_t len, unsigned long val)
     return 0;
 }
 
+#ifndef AFS_LINUX26_ENV
 /*
  * osi_AssertFailK() -- used by the osi_Assert() macro.
  *
@@ -284,12 +247,6 @@ osi_AssertFailK(const char *expr, const char *file, int line)
 
     osi_Panic("%s", buf);
 }
-#else
-void
-osi_AssertFailK(const char *expr, const char *file, int line)
-{
-    printk(KERN_CRIT "assertion failed: %s, file: %s, line: %d\n", expr, file, line);
-}
 #endif
 
 #ifndef UKERNEL
@@ -300,12 +257,13 @@ rx_ServerProc(void *unused)
 {
     int threadID;
 
-/* jaltman - rxi_dataQuota is protected by a mutex everywhere else */
     rxi_MorePackets(rx_maxReceiveWindow + 2);  /* alloc more packets */
+    MUTEX_ENTER(&rx_quota_mutex);
     rxi_dataQuota += rx_initSendWindow;        /* Reserve some pkts for hard times */
     /* threadID is used for making decisions in GetCall.  Get it by bumping
      * number of threads handling incoming calls */
     threadID = rxi_availProcs++;
+    MUTEX_EXIT(&rx_quota_mutex);
 
 #ifdef RX_ENABLE_LOCKS
     AFS_GUNLOCK();
@@ -340,9 +298,7 @@ MyPacketProc(struct rx_packet **ahandle, int asize)
                rxi_FreePacket(tp);
                tp = NULL;
                 if (rx_stats_active) {
-                    MUTEX_ENTER(&rx_stats_mutex);
-                    rx_stats.noPacketBuffersOnRead++;
-                    MUTEX_EXIT(&rx_stats_mutex);
+                   rx_atomic_inc(&rx_stats.noPacketBuffersOnRead);
                 }
            }
        }
@@ -353,9 +309,7 @@ MyPacketProc(struct rx_packet **ahandle, int asize)
         * end know we're losing.
         */
         if (rx_stats_active) {
-            MUTEX_ENTER(&rx_stats_mutex);
-            rx_stats.bogusPacketOnRead++;
-            MUTEX_EXIT(&rx_stats_mutex);
+           rx_atomic_inc(&rx_stats.bogusPacketOnRead);
         }
        /* I DON"T LIKE THIS PRINTF -- PRINTFS MAKE THINGS VERY VERY SLOOWWW */
        dpf(("rx: packet dropped: bad ulen=%d\n", asize));
@@ -393,8 +347,8 @@ MyArrivalProc(struct rx_packet *ahandle,
 void
 rxi_StartListener(void)
 {
+#if !defined(RXK_LISTENER_ENV) && !defined(RXK_UPCALL_ENV)
     /* if kernel, give name of appropriate procedures */
-#ifndef RXK_LISTENER_ENV
     rxk_GetPacketProc = MyPacketProc;
     rxk_PacketArrivalProc = MyArrivalProc;
     rxk_init();
@@ -416,15 +370,11 @@ rxi_InitPeerParams(struct rx_peer *pp)
 
     i = rxi_Findcbi(pp->host);
     if (i == -1) {
-       pp->timeout.sec = 3;
-       /* pp->timeout.usec = 0; */
+       rx_rto_setPeerTimeoutSecs(pp, 3);
        pp->ifMTU = MIN(RX_REMOTE_PACKET_SIZE, rx_MyMaxSendSize);
     } else {
-       pp->timeout.sec = 2;
-       /* pp->timeout.usec = 0; */
+       rx_rto_setPeerTimeoutSecs(pp, 2);
        pp->ifMTU = MIN(RX_MAX_PACKET_SIZE, rx_MyMaxSendSize);
-    }
-    if (i != -1) {
        mtu = ntohl(afs_cb_interface.mtu[i]);
        /* Diminish the packet size to one based on the MTU given by
         * the interface. */
@@ -433,8 +383,6 @@ rxi_InitPeerParams(struct rx_peer *pp)
            if (rxmtu < pp->ifMTU)
                pp->ifMTU = rxmtu;
        }
-    } else {                   /* couldn't find the interface, so assume the worst */
-       pp->ifMTU = MIN(RX_REMOTE_PACKET_SIZE, rx_MyMaxSendSize);
     }
 #  else /* AFS_USERSPACE_IP_ADDR */
     rx_ifnet_t ifn;
@@ -446,13 +394,12 @@ rxi_InitPeerParams(struct rx_peer *pp)
 
     ifn = rxi_FindIfnet(pp->host, NULL);
     if (ifn) {
-       pp->timeout.sec = 2;
-       /* pp->timeout.usec = 0; */
+       rx_rto_setPeerTimeoutSecs(pp, 2);
        pp->ifMTU = MIN(RX_MAX_PACKET_SIZE, rx_MyMaxSendSize);
 #   ifdef IFF_POINTOPOINT
        if (rx_ifnet_flags(ifn) & IFF_POINTOPOINT) {
            /* wish we knew the bit rate and the chunk size, sigh. */
-           pp->timeout.sec = 4;
+           rx_rto_setPeerTimeoutSecs(pp, 4);
            pp->ifMTU = RX_PP_PACKET_SIZE;
        }
 #   endif /* IFF_POINTOPOINT */
@@ -464,8 +411,7 @@ rxi_InitPeerParams(struct rx_peer *pp)
                pp->ifMTU = rxmtu;
        }
     } else {                   /* couldn't find the interface, so assume the worst */
-       pp->timeout.sec = 3;
-       /* pp->timeout.usec = 0; */
+       rx_rto_setPeerTimeoutSecs(pp, 3);
        pp->ifMTU = MIN(RX_REMOTE_PACKET_SIZE, rx_MyMaxSendSize);
     }
 #  endif /* else AFS_USERSPACE_IP_ADDR */
@@ -475,16 +421,12 @@ rxi_InitPeerParams(struct rx_peer *pp)
     mtu = rxi_FindIfMTU(pp->host);
 
     if (mtu <= 0) {
-       pp->timeout.sec = 3;
-       /* pp->timeout.usec = 0; */
+       rx_rto_setPeerTimeoutSecs(pp, 3);
        pp->ifMTU = MIN(RX_REMOTE_PACKET_SIZE, rx_MyMaxSendSize);
     } else {
-       pp->timeout.sec = 2;
-       /* pp->timeout.usec = 0; */
+       rx_rto_setPeerTimeoutSecs(pp, 2);
        pp->ifMTU = MIN(RX_MAX_PACKET_SIZE, rx_MyMaxSendSize);
-    }
 
-    if (mtu > 0) {
        /* Diminish the packet size to one based on the MTU given by
         * the interface. */
        if (mtu > (RX_IPUDP_SIZE + RX_HEADER_SIZE)) {
@@ -492,13 +434,10 @@ rxi_InitPeerParams(struct rx_peer *pp)
            if (rxmtu < pp->ifMTU)
                pp->ifMTU = rxmtu;
        }
-    } else {                   /* couldn't find the interface, so assume the worst */
-       pp->ifMTU = MIN(RX_REMOTE_PACKET_SIZE,rx_MyMaxSendSize);
     }
 # endif /* AFS_SUN5_ENV */
 #else /* ADAPT_MTU */
-    pp->rateFlag = 2;          /* start timing after two full packets */
-    pp->timeout.sec = 2;
+    rx_rto_setPeerTimeoutSecs(pp, 2);
     pp->ifMTU = OLD_MAX_PACKET_SIZE;
 #endif /* else ADAPT_MTU */
     pp->ifMTU = rxi_AdjustIfMTU(pp->ifMTU);
@@ -542,7 +481,7 @@ shutdown_rxkernel(void)
            rxk_shutdownPorts();
            return;
        }
-    dpf(("shutdown_rxkernel: no udp proto"));
+    dpf(("shutdown_rxkernel: no udp proto\n"));
 }
 #endif /* !AIX && !SUN && !NCR  && !UKERNEL */
 
@@ -578,7 +517,7 @@ rxi_GetcbiInfo(void)
            rxmtu * rxi_nRecvFrags + ((rxi_nRecvFrags - 1) * UDP_HDR_SIZE);
        maxmtu = rxi_AdjustMaxMTU(rxmtu, maxmtu);
        addrs[i++] = ifinaddr;
-       if ((ifinaddr != 0x7f000001) && (maxmtu > rx_maxReceiveSize)) {
+       if (!rx_IsLoopbackAddr(ifinaddr) && (maxmtu > rx_maxReceiveSize)) {
            rx_maxReceiveSize = MIN(RX_MAX_PACKET_SIZE, maxmtu);
            rx_maxReceiveSize = MIN(rx_maxReceiveSize, rx_maxReceiveSizeUser);
        }
@@ -704,9 +643,9 @@ rxi_GetIFInfo(void)
                            ((rxi_nRecvFrags - 1) * UDP_HDR_SIZE);
                        maxmtu = rxi_AdjustMaxMTU(rxmtu, maxmtu);
                        addrs[i++] = ifinaddr;
-                       if ((ifinaddr != 0x7f000001) && 
+                       if (!rx_IsLoopbackAddr(ifinaddr) &&
                            (maxmtu > rx_maxReceiveSize)) {
-                           rx_maxReceiveSize = 
+                           rx_maxReceiveSize =
                                MIN(RX_MAX_PACKET_SIZE, maxmtu);
                            rx_maxReceiveSize =
                                MIN(rx_maxReceiveSize, rx_maxReceiveSizeUser);
@@ -721,10 +660,14 @@ rxi_GetIFInfo(void)
     }
 #else
 #if defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
+#if defined(AFS_FBSD80_ENV)
+    TAILQ_FOREACH(ifn, &V_ifnet, if_link) {
+#else
     TAILQ_FOREACH(ifn, &ifnet, if_link) {
+#endif
        if (i >= ADDRSPERSITE)
            break;
-#elif defined(AFS_OBSD_ENV)
+#elif defined(AFS_OBSD_ENV) || defined(AFS_NBSD_ENV)
     for (ifn = ifnet.tqh_first; i < ADDRSPERSITE && ifn != NULL;
         ifn = ifn->if_list.tqe_next) {
 #else
@@ -735,7 +678,7 @@ rxi_GetIFInfo(void)
        TAILQ_FOREACH(ifad, &ifn->if_addrhead, ifa_link) {
            if (i >= ADDRSPERSITE)
                break;
-#elif defined(AFS_OBSD_ENV)
+#elif defined(AFS_OBSD_ENV) || defined(AFS_NBSD_ENV)
        for (ifad = ifn->if_addrlist.tqh_first;
             ifad != NULL && i < ADDRSPERSITE;
             ifad = ifad->ifa_list.tqe_next) {
@@ -757,7 +700,7 @@ rxi_GetIFInfo(void)
                    ((rxi_nRecvFrags - 1) * UDP_HDR_SIZE);
                maxmtu = rxi_AdjustMaxMTU(rxmtu, maxmtu);
                addrs[i++] = ifinaddr;
-               if ((ifinaddr != 0x7f000001) && (maxmtu > rx_maxReceiveSize)) {
+               if (!rx_IsLoopbackAddr(ifinaddr) && (maxmtu > rx_maxReceiveSize)) {
                    rx_maxReceiveSize = MIN(RX_MAX_PACKET_SIZE, maxmtu);
                    rx_maxReceiveSize =
                        MIN(rx_maxReceiveSize, rx_maxReceiveSizeUser);
@@ -782,7 +725,7 @@ rxi_GetIFInfo(void)
     return different;
 }
 
-#if defined(AFS_DARWIN60_ENV) || defined(AFS_XBSD_ENV)
+#if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
 /* Returns ifnet which best matches address */
 rx_ifnet_t
 rxi_FindIfnet(afs_uint32 addr, afs_uint32 * maskp)
@@ -801,7 +744,7 @@ rxi_FindIfnet(afs_uint32 addr, afs_uint32 * maskp)
     return (ifad ? rx_ifaddr_ifnet(ifad) : NULL);
 }
 
-#else /* DARWIN60 || XBSD */
+#else /* DARWIN || XBSD */
 
 /* Returns ifnet which best matches address */
 rx_ifnet_t
@@ -813,12 +756,7 @@ rxi_FindIfnet(afs_uint32 addr, afs_uint32 * maskp)
 
     addr = ntohl(addr);
 
-#if defined(AFS_DARWIN_ENV)
-    for (ifa = TAILQ_FIRST(&in_ifaddrhead); ifa;
-        ifa = TAILQ_NEXT(ifa, ia_link)) {
-#else
     for (ifa = in_ifaddr; ifa; ifa = ifa->ia_next) {
-#endif
        if ((addr & ifa->ia_netmask) == ifa->ia_net) {
            if ((addr & ifa->ia_subnetmask) == ifa->ia_subnet) {
                if (IA_SIN(ifa)->sin_addr.s_addr == addr) {     /* ie, ME!!!  */
@@ -844,7 +782,7 @@ rxi_FindIfnet(afs_uint32 addr, afs_uint32 * maskp)
        *maskp = ifad->ia_subnetmask;
     return (ifad ? ifad->ia_ifp : NULL);
 }
-#endif /* else DARWIN60 || XBSD */
+#endif /* else DARWIN || XBSD */
 #endif /* else AFS_USERSPACE_IP_ADDR */
 #endif /* !SUN5 && !SGI62 */
 
@@ -868,7 +806,7 @@ rxk_NewSocketHost(afs_uint32 ahost, short aport)
 #else
     struct socket *newSocket;
 #endif
-#if (!defined(AFS_HPUX1122_ENV) && !defined(AFS_FBSD50_ENV))
+#if (!defined(AFS_HPUX1122_ENV) && !defined(AFS_FBSD_ENV))
     struct mbuf *nam;
 #endif
     struct sockaddr_in myaddr;
@@ -892,7 +830,7 @@ rxk_NewSocketHost(afs_uint32 ahost, short aport)
     AFS_GUNLOCK();
 #if    defined(AFS_HPUX102_ENV)
 #if     defined(AFS_HPUX110_ENV)
-    /* we need a file associated with the socket so sosend in NetSend 
+    /* we need a file associated with the socket so sosend in NetSend
      * will not fail */
     /* blocking socket */
     code = socreate(AF_INET, &newSocket, SOCK_DGRAM, 0, 0);
@@ -911,14 +849,20 @@ rxk_NewSocketHost(afs_uint32 ahost, short aport)
 #endif /* else AFS_HPUX110_ENV */
 #elif defined(AFS_SGI65_ENV) || defined(AFS_OBSD_ENV)
     code = socreate(AF_INET, &newSocket, SOCK_DGRAM, IPPROTO_UDP);
-#elif defined(AFS_FBSD50_ENV)
+#elif defined(AFS_FBSD_ENV)
     code = socreate(AF_INET, &newSocket, SOCK_DGRAM, IPPROTO_UDP,
                    afs_osi_credp, curthread);
-#elif defined(AFS_FBSD40_ENV)
-    code = socreate(AF_INET, &newSocket, SOCK_DGRAM, IPPROTO_UDP, curproc);
 #elif defined(AFS_DARWIN80_ENV)
+#ifdef RXK_LISTENER_ENV
     code = sock_socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP, NULL, NULL, &newSocket);
 #else
+    code = sock_socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP, rx_upcall, NULL, &newSocket);
+#endif
+#elif defined(AFS_NBSD50_ENV)
+    code = socreate(AF_INET, &newSocket, SOCK_DGRAM, 0, osi_curproc(), NULL);
+#elif defined(AFS_NBSD40_ENV)
+    code = socreate(AF_INET, &newSocket, SOCK_DGRAM, 0, osi_curproc());
+#else
     code = socreate(AF_INET, &newSocket, SOCK_DGRAM, 0);
 #endif /* AFS_HPUX102_ENV */
     if (code)
@@ -941,8 +885,11 @@ rxk_NewSocketHost(afs_uint32 ahost, short aport)
     memcpy((caddr_t) bindnam->b_rptr + SO_MSGOFFSET, (caddr_t) & myaddr,
           addrsize);
     bindnam->b_wptr = bindnam->b_rptr + (addrsize + SO_MSGOFFSET + 1);
-
+#if defined(AFS_NBSD40_ENV)
+    code = sobind(newSocket, bindnam, addrsize, osi_curproc());
+#else
     code = sobind(newSocket, bindnam, addrsize);
+#endif
     if (code) {
        soclose(newSocket);
 #if !defined(AFS_HPUX1122_ENV)
@@ -954,7 +901,7 @@ rxk_NewSocketHost(afs_uint32 ahost, short aport)
     freeb(bindnam);
 #else /* AFS_HPUX110_ENV */
 #if defined(AFS_DARWIN80_ENV)
-    { 
+    {
        int buflen = 50000;
        int i,code2;
        for (i=0;i<2;i++) {
@@ -970,25 +917,28 @@ rxk_NewSocketHost(afs_uint32 ahost, short aport)
        }
     }
 #else
+#if defined(AFS_NBSD_ENV)
+    solock(newSocket);
+#endif
     code = soreserve(newSocket, 50000, 50000);
     if (code) {
        code = soreserve(newSocket, 32766, 32766);
        if (code)
            osi_Panic("osi_NewSocket: last attempt to reserve 32K failed!\n");
     }
+#if defined(AFS_NBSD_ENV)
+    sounlock(newSocket);
+#endif
 #endif
 #if defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
-#if defined(AFS_FBSD50_ENV)
+#if defined(AFS_FBSD_ENV)
     code = sobind(newSocket, (struct sockaddr *)&myaddr, curthread);
-#elif defined(AFS_FBSD40_ENV)
-    code = sobind(newSocket, (struct sockaddr *)&myaddr, curproc);
 #else
     code = sobind(newSocket, (struct sockaddr *)&myaddr);
 #endif
     if (code) {
        dpf(("sobind fails (%d)\n", (int)code));
        soclose(newSocket);
-       AFS_GLOCK();
        goto bad;
     }
 #else /* defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) */
@@ -1009,7 +959,7 @@ rxk_NewSocketHost(afs_uint32 ahost, short aport)
     BHV_PDATA(&bhv) = (void *)newSocket;
     code = sobind(&bhv, nam);
     m_freem(nam);
-#elif defined(AFS_OBSD44_ENV)
+#elif defined(AFS_OBSD44_ENV) || defined(AFS_NBSD40_ENV)
     code = sobind(newSocket, nam, osi_curproc());
 #else
     code = sobind(newSocket, nam);
@@ -1057,8 +1007,8 @@ rxk_FreeSocket(struct socket *asocket)
     if (asocket->so_fp) {
        struct file *fp = asocket->so_fp;
 #if !defined(AFS_HPUX1123_ENV)
-       /* 11.23 still has falloc, but not FPENTRYFREE ! 
-        * so for now if we shutdown, we will waist a file 
+       /* 11.23 still has falloc, but not FPENTRYFREE !
+        * so for now if we shutdown, we will waist a file
         * structure */
        FPENTRYFREE(fp);
        asocket->so_fp = NULL;
@@ -1073,8 +1023,8 @@ rxk_FreeSocket(struct socket *asocket)
 }
 #endif /* !SUN5 && !LINUX20 */
 
-#if defined(RXK_LISTENER_ENV) || defined(AFS_SUN5_ENV)
-#ifdef AFS_DARWIN80_ENV
+#if defined(RXK_LISTENER_ENV) || defined(AFS_SUN5_ENV) || defined(RXK_UPCALL_ENV)
+#ifdef RXK_TIMEDSLEEP_ENV
 /* Shutting down should wake us up, as should an earlier event. */
 void
 rxi_ReScheduleEvents(void)
@@ -1111,9 +1061,9 @@ afs_rxevent_daemon(void)
        afs_Trace1(afs_iclSetp, CM_TRACE_TIMESTAMP, ICL_TYPE_STRING,
                   "before afs_osi_Wait()");
 #endif
-#ifdef AFS_DARWIN80_ENV
-       afs_osi_TimedSleep(&afs_termState, ((temp.sec * 1000) +
-                                           (temp.usec / 1000)), 0);
+#ifdef RXK_TIMEDSLEEP_ENV
+       afs_osi_TimedSleep(&afs_termState, MAX(500, ((temp.sec * 1000) +
+                                                    (temp.usec / 1000))), 0);
 #else
        afs_osi_Wait(500, NULL, 0);
 #endif
@@ -1124,13 +1074,11 @@ afs_rxevent_daemon(void)
        if (afs_termState == AFSOP_STOP_RXEVENT) {
 #ifdef RXK_LISTENER_ENV
            afs_termState = AFSOP_STOP_RXK_LISTENER;
-#else
-#ifdef AFS_SUN510_ENV
+#elif defined(AFS_SUN510_ENV) || defined(RXK_UPCALL_ENV)
            afs_termState = AFSOP_STOP_NETIF;
 #else
            afs_termState = AFSOP_STOP_COMPLETE;
 #endif
-#endif
            osi_rxWakeup(&afs_termState);
            return;
        }
@@ -1166,7 +1114,7 @@ rxk_ReadPacket(osi_socket so, struct rx_packet *p, int *host, int *port)
     } else
        tlen = rlen;
 
-    /* add some padding to the last iovec, it's just to make sure that the 
+    /* add some padding to the last iovec, it's just to make sure that the
      * read doesn't return more data than we expect, and is done to get around
      * our problems caused by the lack of a length field in the rx header. */
     savelen = p->wirevec[p->niovecs - 1].iov_len;
@@ -1200,11 +1148,11 @@ rxk_ReadPacket(osi_socket so, struct rx_packet *p, int *host, int *port)
            if (nbytes <= 0) {
                 if (rx_stats_active) {
                     MUTEX_ENTER(&rx_stats_mutex);
-                    rx_stats.bogusPacketOnRead++;
+                    rx_atomic_inc(&rx_stats.bogusPacketOnRead);
                     rx_stats.bogusHost = from.sin_addr.s_addr;
                     MUTEX_EXIT(&rx_stats_mutex);
                 }
-               dpf(("B: bogus packet from [%x,%d] nb=%d",
+               dpf(("B: bogus packet from [%x,%d] nb=%d\n",
                     from.sin_addr.s_addr, from.sin_port, nbytes));
            }
            return -1;
@@ -1216,9 +1164,7 @@ rxk_ReadPacket(osi_socket so, struct rx_packet *p, int *host, int *port)
            *port = from.sin_port;
            if (p->header.type > 0 && p->header.type < RX_N_PACKET_TYPES) {
                 if (rx_stats_active) {
-                    MUTEX_ENTER(&rx_stats_mutex);
-                    rx_stats.packetsRead[p->header.type - 1]++;
-                    MUTEX_EXIT(&rx_stats_mutex);
+                    rx_atomic_inc(&rx_stats.packetsRead[p->header.type - 1]);
                 }
            }
 
@@ -1232,7 +1178,7 @@ rxk_ReadPacket(osi_socket so, struct rx_packet *p, int *host, int *port)
        return code;
 }
 
-/* rxk_Listener() 
+/* rxk_Listener()
  *
  * Listen for packets on socket. This thread is typically started after
  * rx_Init has called rxi_StartListener(), but nevertheless, ensures that
@@ -1251,27 +1197,8 @@ int rxk_ListenerPid;             /* Used to signal process to wakeup at shutdown */
 struct task_struct *rxk_ListenerTask;
 #endif
 
-#ifdef AFS_SUN5_ENV
-/*
- * Run the listener as a kernel thread.
- */
-void
-rxk_Listener(void)
-{
-    extern id_t syscid;
-    void rxk_ListenerProc(void);
-    if (thread_create
-       (NULL, DEFAULTSTKSZ, rxk_ListenerProc, 0, 0, &p0, TS_RUN,
-        minclsyspri) == NULL)
-       osi_Panic("rxk_Listener: failed to start listener thread!\n");
-}
-
-void
-rxk_ListenerProc(void)
-#else /* AFS_SUN5_ENV */
 void
 rxk_Listener(void)
-#endif                         /* AFS_SUN5_ENV */
 {
     struct rx_packet *rxp = NULL;
     int code;
@@ -1292,10 +1219,13 @@ rxk_Listener(void)
 #elif defined(AFS_DARWIN_ENV)
     rxk_ListenerPid = current_proc()->p_pid;
 #endif
-#if defined(RX_ENABLE_LOCKS) && !defined(AFS_SUN5_ENV)
+#ifdef RX_ENABLE_LOCKS
     AFS_GUNLOCK();
-#endif /* RX_ENABLE_LOCKS && !AFS_SUN5_ENV */
+#endif /* RX_ENABLE_LOCKS */
     while (afs_termState != AFSOP_STOP_RXK_LISTENER) {
+        /* See if a check for additional packets was issued */
+        rx_CheckPackets();
+
        if (rxp) {
            rxi_RestoreDataBufs(rxp);
        } else {
@@ -1324,12 +1254,9 @@ rxk_Listener(void)
     rxk_ListenerTask = 0;
     osi_rxWakeup(&rxk_ListenerTask);
 #endif
-#if defined(AFS_SUN5_ENV)
+#if defined(AFS_SUN5_ENV) || defined(AFS_FBSD_ENV)
     osi_rxWakeup(&rxk_ListenerPid);
 #endif
-#ifdef AFS_SUN5_ENV
-    AFS_GUNLOCK();
-#endif /* AFS_SUN5_ENV */
 }
 
 #if !defined(AFS_LINUX20_ENV) && !defined(AFS_SUN5_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_XBSD_ENV)
@@ -1343,5 +1270,61 @@ osi_StopListener(void)
 }
 #endif
 #endif /* RXK_LISTENER_ENV */
-
 #endif /* !NCR && !UKERNEL */
+
+#if !defined(AFS_LINUX26_ENV)
+void
+#if defined(AFS_AIX_ENV)
+osi_Panic(char *msg, void *a1, void *a2, void *a3)
+#else
+osi_Panic(char *msg, ...)
+#endif
+{
+#ifdef AFS_AIX_ENV
+    if (!msg)
+       msg = "Unknown AFS panic";
+    /*
+     * we should probably use the errsave facility here. it is not
+     * varargs-aware
+     */
+
+    printf(msg, a1, a2, a3);
+    panic(msg);
+#elif defined(AFS_SGI_ENV)
+    va_list ap;
+
+    /* Solaris has vcmn_err, Sol10 01/06 may have issues. Beware. */
+    if (!msg) {
+       cmn_err(CE_PANIC, "Unknown AFS panic");
+    } else {
+       va_start(ap, msg);
+       icmn_err(CE_PANIC, msg, ap);
+       va_end(ap);
+    }
+#elif defined(AFS_DARWIN80_ENV) || (defined(AFS_LINUX22_ENV) && !defined(AFS_LINUX_26_ENV))
+    char buf[256];
+    va_list ap;
+    if (!msg)
+       msg = "Unknown AFS panic";
+
+    va_start(ap, msg);
+    vsnprintf(buf, sizeof(buf), msg, ap);
+    va_end(ap);
+    printf("%s", buf);
+    panic(buf);
+#else
+    va_list ap;
+    if (!msg)
+       msg = "Unknown AFS panic";
+
+    va_start(ap, msg);
+    vprintf(msg, ap);
+    va_end(ap);
+# ifdef AFS_LINUX20_ENV
+    * ((char *) 0) = 0;
+# else
+    panic(msg);
+# endif
+#endif
+}
+#endif