/*
* 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 "rx/rx_kcommon.h"
+#include "rx_atomic.h"
+#include "rx_stats.h"
#ifdef AFS_HPUX110_ENV
#include "h/tihdr.h"
sockp = (osi_socket *)rxk_NewSocketHost(host, port);
if (sockp == (osi_socket *)0)
return OSI_NULLSOCKET;
- rxk_AddPort(port, (char *)sockp);
+ rxk_AddPort(port, (char *)sockp);
return (osi_socket) sockp;
}
{
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();
pp->timeout.sec = 2;
/* pp->timeout.usec = 0; */
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. */
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;
pp->timeout.sec = 2;
/* pp->timeout.usec = 0; */
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)) {
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 */
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);
}
((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);
TAILQ_FOREACH(ifn, &ifnet, if_link) {
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
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) {
((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);
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)
return (ifad ? rx_ifaddr_ifnet(ifad) : NULL);
}
-#else /* DARWIN60 || XBSD */
+#else /* DARWIN || XBSD */
/* Returns ifnet which best matches address */
rx_ifnet_t
*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 */
#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;
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);
#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)
code = sock_socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP, NULL, NULL, &newSocket);
+#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 */
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)
freeb(bindnam);
#else /* AFS_HPUX110_ENV */
#if defined(AFS_DARWIN80_ENV)
- {
+ {
int buflen = 50000;
int i,code2;
for (i=0;i<2;i++) {
}
#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) */
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);
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;
} 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;
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);
}
*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]);
}
}
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
AFS_GUNLOCK();
#endif /* RX_ENABLE_LOCKS && !AFS_SUN5_ENV */
while (afs_termState != AFSOP_STOP_RXK_LISTENER) {
+ /* See if a check for additional packets was issued */
+ rx_CheckPackets();
+
if (rxp) {
rxi_RestoreDataBufs(rxp);
} else {
va_start(ap, msg);
vsnprintf(buf, sizeof(buf), msg, ap);
va_end(ap);
- printf(buf);
+ printf("%s", buf);
panic(buf);
#else
va_list ap;
vprintf(msg, ap);
va_end(ap);
# ifdef AFS_LINUX20_ENV
- * ((char *) 0) = 0;
+ * ((char *) 0) = 0;
# else
panic(msg);
# endif