aix-warning-cleanup-20051015
[openafs.git] / src / rx / rx_kcommon.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 /*
11  * rx_kcommon.c - Common kernel RX code for all system types.
12  */
13
14 #include <afsconfig.h>
15 #include "afs/param.h"
16
17 RCSID
18     ("$Header$");
19
20 #include "rx/rx_kcommon.h"
21
22 #ifdef AFS_HPUX110_ENV
23 #include "h/tihdr.h"
24 #include <xti.h>
25 #endif
26 #include "afsint.h"
27
28 #ifndef RXK_LISTENER_ENV
29 int (*rxk_PacketArrivalProc) (struct rx_packet * ahandle, struct sockaddr_in * afrom, struct socket *arock, afs_int32 asize);   /* set to packet allocation procedure */
30 int (*rxk_GetPacketProc) (struct rx_packet **ahandle, int asize);
31 #endif
32
33 osi_socket *rxk_NewSocketHost(afs_uint32 ahost, short aport);
34 extern struct interfaceAddr afs_cb_interface;
35
36 rxk_ports_t rxk_ports;
37 rxk_portRocks_t rxk_portRocks;
38
39 int rxk_initDone = 0;
40
41 #if !defined(AFS_SUN5_ENV) && !defined(AFS_SGI62_ENV)
42 #define ADDRSPERSITE 16
43 static afs_uint32 myNetAddrs[ADDRSPERSITE];
44 static int myNetMTUs[ADDRSPERSITE];
45 static int numMyNetAddrs = 0;
46 #endif
47
48 #if defined(AFS_DARWIN80_ENV)
49 #define sobind sock_bind
50 #define soclose sock_close
51 #endif
52
53 /* add a port to the monitored list, port # is in network order */
54 static int
55 rxk_AddPort(u_short aport, char *arock)
56 {
57     int i;
58     unsigned short *tsp, ts;
59     int zslot;
60
61     zslot = -1;                 /* look for an empty slot simultaneously */
62     for (i = 0, tsp = rxk_ports; i < MAXRXPORTS; i++, tsp++) {
63         if (((ts = *tsp) == 0) && (zslot == -1))
64             zslot = i;
65         if (ts == aport) {
66             return 0;
67         }
68     }
69     /* otherwise allocate a new port slot */
70     if (zslot < 0)
71         return E2BIG;           /* all full */
72     rxk_ports[zslot] = aport;
73     rxk_portRocks[zslot] = arock;
74     return 0;
75 }
76
77 /* remove as port from the monitored list, port # is in network order */
78 int
79 rxk_DelPort(u_short aport)
80 {
81     register int i;
82     register unsigned short *tsp;
83
84     for (i = 0, tsp = rxk_ports; i < MAXRXPORTS; i++, tsp++) {
85         if (*tsp == aport) {
86             /* found it, adjust ref count and free the port reference if all gone */
87             *tsp = 0;
88             return 0;
89         }
90     }
91     /* otherwise port not found */
92     return ENOENT;
93 }
94
95 void
96 rxk_shutdownPorts(void)
97 {
98     int i;
99     for (i = 0; i < MAXRXPORTS; i++) {
100         if (rxk_ports[i]) {
101             rxk_ports[i] = 0;
102 #if ! defined(AFS_SUN5_ENV) && ! defined(UKERNEL) && ! defined(RXK_LISTENER_ENV)
103             soclose((struct socket *)rxk_portRocks[i]);
104 #endif
105             rxk_portRocks[i] = NULL;
106         }
107     }
108 }
109
110 osi_socket
111 rxi_GetHostUDPSocket(u_int host, u_short port)
112 {
113     osi_socket *sockp;
114     sockp = (osi_socket *)rxk_NewSocketHost(host, port);
115     if (sockp == (osi_socket *)0)
116         return OSI_NULLSOCKET;
117     rxk_AddPort(port, (char *)sockp);
118     return (osi_socket) sockp;
119 }
120
121 osi_socket
122 rxi_GetUDPSocket(u_short port)
123 {
124     return rxi_GetHostUDPSocket(htonl(INADDR_ANY), port);
125 }
126
127 void
128 osi_Panic(msg, a1, a2, a3)
129      char *msg;
130 {
131     if (!msg)
132         msg = "Unknown AFS panic";
133
134     dpf((msg, a1, a2, a3));
135 #ifdef AFS_LINUX24_ENV
136     BUG();
137 #else
138     panic(msg);
139 #endif
140 }
141
142 /*
143  * osi_utoa() - write the NUL-terminated ASCII decimal form of the given
144  * unsigned long value into the given buffer.  Returns 0 on success,
145  * and a value less than 0 on failure.  The contents of the buffer is
146  * defined only on success.
147  */
148
149 int
150 osi_utoa(char *buf, size_t len, unsigned long val)
151 {
152     long k;                     /* index of first byte of string value */
153
154     /* we definitely need room for at least one digit and NUL */
155
156     if (len < 2) {
157         return -1;
158     }
159
160     /* compute the string form from the high end of the buffer */
161
162     buf[len - 1] = '\0';
163     for (k = len - 2; k >= 0; k--) {
164         buf[k] = val % 10 + '0';
165         val /= 10;
166
167         if (val == 0)
168             break;
169     }
170
171     /* did we finish converting val to string form? */
172
173     if (val != 0) {
174         return -2;
175     }
176
177     /* this should never happen */
178
179     if (k < 0) {
180         return -3;
181     }
182
183     /* this should never happen */
184
185     if (k >= len) {
186         return -4;
187     }
188
189     /* if necessary, relocate string to beginning of buf[] */
190
191     if (k > 0) {
192
193         /*
194          * We need to achieve the effect of calling
195          *
196          * memmove(buf, &buf[k], len - k);
197          *
198          * However, since memmove() is not available in all
199          * kernels, we explicitly do an appropriate copy.
200          */
201
202         char *dst = buf;
203         char *src = buf + k;
204
205         while ((*dst++ = *src++) != '\0')
206             continue;
207     }
208
209     return 0;
210 }
211
212 /*
213  * osi_AssertFailK() -- used by the osi_Assert() macro.
214  *
215  * It essentially does
216  *
217  * osi_Panic("assertion failed: %s, file: %s, line: %d", expr, file, line);
218  *
219  * Since the kernel version of osi_Panic() only passes its first
220  * argument to the native panic(), we construct a single string and hand
221  * that to osi_Panic().
222  */
223 void
224 osi_AssertFailK(const char *expr, const char *file, int line)
225 {
226     static const char msg0[] = "assertion failed: ";
227     static const char msg1[] = ", file: ";
228     static const char msg2[] = ", line: ";
229     static const char msg3[] = "\n";
230
231     /*
232      * These buffers add up to 1K, which is a pleasantly nice round
233      * value, but probably not vital.
234      */
235     char buf[1008];
236     char linebuf[16];
237
238     /* check line number conversion */
239
240     if (osi_utoa(linebuf, sizeof linebuf, line) < 0) {
241         osi_Panic("osi_AssertFailK: error in osi_utoa()\n");
242     }
243
244     /* okay, panic */
245
246 #define ADDBUF(BUF, STR)                                        \
247         if (strlen(BUF) + strlen((char *)(STR)) + 1 <= sizeof BUF) {    \
248                 strcat(BUF, (char *)(STR));                             \
249         }
250
251     buf[0] = '\0';
252     ADDBUF(buf, msg0);
253     ADDBUF(buf, expr);
254     ADDBUF(buf, msg1);
255     ADDBUF(buf, file);
256     ADDBUF(buf, msg2);
257     ADDBUF(buf, linebuf);
258     ADDBUF(buf, msg3);
259
260 #undef ADDBUF
261
262     osi_Panic(buf);
263 }
264
265 #ifndef UKERNEL
266 /* This is the server process request loop. Kernel server
267  * processes never become listener threads */
268 void
269 rx_ServerProc(void)
270 {
271     int threadID;
272
273     rxi_MorePackets(rx_maxReceiveWindow + 2);   /* alloc more packets */
274     rxi_dataQuota += rx_initSendWindow; /* Reserve some pkts for hard times */
275     /* threadID is used for making decisions in GetCall.  Get it by bumping
276      * number of threads handling incoming calls */
277     threadID = rxi_availProcs++;
278
279 #ifdef RX_ENABLE_LOCKS
280     AFS_GUNLOCK();
281 #endif /* RX_ENABLE_LOCKS */
282     rxi_ServerProc(threadID, NULL, NULL);
283 #ifdef RX_ENABLE_LOCKS
284     AFS_GLOCK();
285 #endif /* RX_ENABLE_LOCKS */
286 }
287 #endif /* !UKERNEL */
288
289 #ifndef RXK_LISTENER_ENV
290 /* asize includes the Rx header */
291 static int
292 MyPacketProc(struct rx_packet **ahandle, int asize)
293 {
294     struct rx_packet *tp;
295
296     /* If this is larger than we expected, increase rx_maxReceiveDataSize */
297     /* If we can't scrounge enough cbufs, then we have to drop the packet,
298      * but we should set a flag so we magic up some more at our leisure.
299      */
300
301     if ((asize >= 0) && (asize <= RX_MAX_PACKET_SIZE)) {
302         tp = rxi_AllocPacket(RX_PACKET_CLASS_RECEIVE);
303         if (tp && (tp->length + RX_HEADER_SIZE) < asize) {
304             if (0 <
305                 rxi_AllocDataBuf(tp, asize - (tp->length + RX_HEADER_SIZE),
306                                  RX_PACKET_CLASS_RECV_CBUF)) {
307                 rxi_FreePacket(tp);
308                 tp = NULL;
309                 MUTEX_ENTER(&rx_stats_mutex);
310                 rx_stats.noPacketBuffersOnRead++;
311                 MUTEX_EXIT(&rx_stats_mutex);
312             }
313         }
314     } else {
315         /*
316          * XXX if packet is too long for our buffer,
317          * should do this at a higher layer and let other
318          * end know we're losing.
319          */
320         MUTEX_ENTER(&rx_stats_mutex);
321         rx_stats.bogusPacketOnRead++;
322         MUTEX_EXIT(&rx_stats_mutex);
323         /* I DON"T LIKE THIS PRINTF -- PRINTFS MAKE THINGS VERY VERY SLOOWWW */
324         dpf(("rx: packet dropped: bad ulen=%d\n", asize));
325         tp = NULL;
326     }
327
328     if (!tp)
329         return -1;
330     /* otherwise we have a packet, set appropriate values */
331     *ahandle = tp;
332     return 0;
333 }
334
335 static int
336 MyArrivalProc(struct rx_packet *ahandle,
337               struct sockaddr_in *afrom,
338               struct socket *arock,
339               afs_int32 asize)
340 {
341     /* handle basic rx packet */
342     ahandle->length = asize - RX_HEADER_SIZE;
343     rxi_DecodePacketHeader(ahandle);
344     ahandle =
345         rxi_ReceivePacket(ahandle, arock,
346                           afrom->sin_addr.s_addr, afrom->sin_port, NULL,
347                           NULL);
348
349     /* free the packet if it has been returned */
350     if (ahandle)
351         rxi_FreePacket(ahandle);
352     return 0;
353 }
354 #endif /* !RXK_LISTENER_ENV */
355
356 void
357 rxi_StartListener(void)
358 {
359     /* if kernel, give name of appropriate procedures */
360 #ifndef RXK_LISTENER_ENV
361     rxk_GetPacketProc = MyPacketProc;
362     rxk_PacketArrivalProc = MyArrivalProc;
363     rxk_init();
364 #endif
365 }
366
367 /* Called from rxi_FindPeer, when initializing a clear rx_peer structure,
368   to get interesting information. */
369 void
370 rxi_InitPeerParams(register struct rx_peer *pp)
371 {
372     u_short rxmtu;
373     afs_int32 i, mtu;
374
375 #ifdef  ADAPT_MTU
376 #ifndef AFS_SUN5_ENV
377 #ifdef AFS_USERSPACE_IP_ADDR
378     i = rxi_Findcbi(pp->host);
379     if (i == -1) {
380         pp->timeout.sec = 3;
381         /* pp->timeout.usec = 0; */
382         pp->ifMTU = RX_REMOTE_PACKET_SIZE;
383     } else {
384         pp->timeout.sec = 2;
385         /* pp->timeout.usec = 0; */
386         pp->ifMTU = MIN(RX_MAX_PACKET_SIZE, rx_MyMaxSendSize);
387     }
388     if (i != -1) {
389         mtu = ntohl(afs_cb_interface.mtu[i]);
390         /* Diminish the packet size to one based on the MTU given by
391          * the interface. */
392         if (mtu > (RX_IPUDP_SIZE + RX_HEADER_SIZE)) {
393             rxmtu = mtu - RX_IPUDP_SIZE;
394             if (rxmtu < pp->ifMTU)
395                 pp->ifMTU = rxmtu;
396         }
397     } else {                    /* couldn't find the interface, so assume the worst */
398         pp->ifMTU = RX_REMOTE_PACKET_SIZE;
399     }
400 #else /* AFS_USERSPACE_IP_ADDR */
401 #ifdef AFS_DARWIN80_ENV
402     ifnet_t ifn;
403 #else
404     struct ifnet *ifn;
405 #endif
406
407 #if !defined(AFS_SGI62_ENV)
408     if (numMyNetAddrs == 0)
409         (void)rxi_GetIFInfo();
410 #endif
411
412     ifn = rxi_FindIfnet(pp->host, NULL);
413     if (ifn) {
414         pp->timeout.sec = 2;
415         /* pp->timeout.usec = 0; */
416         pp->ifMTU = MIN(RX_MAX_PACKET_SIZE, rx_MyMaxSendSize);
417 #ifdef IFF_POINTOPOINT
418         if (ifnet_flags(ifn) & IFF_POINTOPOINT) {
419             /* wish we knew the bit rate and the chunk size, sigh. */
420             pp->timeout.sec = 4;
421             pp->ifMTU = RX_PP_PACKET_SIZE;
422         }
423 #endif /* IFF_POINTOPOINT */
424         /* Diminish the packet size to one based on the MTU given by
425          * the interface. */
426         if (ifnet_mtu(ifn) > (RX_IPUDP_SIZE + RX_HEADER_SIZE)) {
427             rxmtu = ifnet_mtu(ifn) - RX_IPUDP_SIZE;
428             if (rxmtu < pp->ifMTU)
429                 pp->ifMTU = rxmtu;
430         }
431     } else {                    /* couldn't find the interface, so assume the worst */
432         pp->timeout.sec = 3;
433         /* pp->timeout.usec = 0; */
434         pp->ifMTU = RX_REMOTE_PACKET_SIZE;
435     }
436 #endif /* else AFS_USERSPACE_IP_ADDR */
437 #else /* AFS_SUN5_ENV */
438     mtu = rxi_FindIfMTU(pp->host);
439
440     if (mtu <= 0) {
441         pp->timeout.sec = 3;
442         /* pp->timeout.usec = 0; */
443         pp->ifMTU = RX_REMOTE_PACKET_SIZE;
444     } else {
445         pp->timeout.sec = 2;
446         /* pp->timeout.usec = 0; */
447         pp->ifMTU = MIN(RX_MAX_PACKET_SIZE, rx_MyMaxSendSize);
448     }
449
450     if (mtu > 0) {
451         /* Diminish the packet size to one based on the MTU given by
452          * the interface. */
453         if (mtu > (RX_IPUDP_SIZE + RX_HEADER_SIZE)) {
454             rxmtu = mtu - RX_IPUDP_SIZE;
455             if (rxmtu < pp->ifMTU)
456                 pp->ifMTU = rxmtu;
457         }
458     } else {                    /* couldn't find the interface, so assume the worst */
459         pp->ifMTU = RX_REMOTE_PACKET_SIZE;
460     }
461 #endif /* AFS_SUN5_ENV */
462 #else /* ADAPT_MTU */
463     pp->rateFlag = 2;           /* start timing after two full packets */
464     pp->timeout.sec = 2;
465     pp->ifMTU = OLD_MAX_PACKET_SIZE;
466 #endif /* else ADAPT_MTU */
467     pp->ifMTU = rxi_AdjustIfMTU(pp->ifMTU);
468     pp->maxMTU = OLD_MAX_PACKET_SIZE;   /* for compatibility with old guys */
469     pp->natMTU = MIN(pp->ifMTU, OLD_MAX_PACKET_SIZE);
470     pp->ifDgramPackets =
471         MIN(rxi_nDgramPackets,
472             rxi_AdjustDgramPackets(RX_MAX_FRAGS, pp->ifMTU));
473     pp->maxDgramPackets = 1;
474
475     /* Initialize slow start parameters */
476     pp->MTU = MIN(pp->natMTU, pp->maxMTU);
477     pp->cwind = 1;
478     pp->nDgramPackets = 1;
479     pp->congestSeq = 0;
480 }
481
482
483 /* The following code is common to several system types, but not all. The
484  * separate ones are found in the system specific subdirectories.
485  */
486
487
488 #if ! defined(AFS_AIX_ENV) && ! defined(AFS_SUN5_ENV) && ! defined(UKERNEL) && ! defined(AFS_LINUX20_ENV) && !defined (AFS_DARWIN_ENV) && !defined (AFS_XBSD_ENV)
489 /* Routine called during the afsd "-shutdown" process to put things back to
490  * the initial state.
491  */
492 static struct protosw parent_proto;     /* udp proto switch */
493
494 void
495 shutdown_rxkernel(void)
496 {
497     register struct protosw *tpro, *last;
498     last = inetdomain.dom_protoswNPROTOSW;
499     for (tpro = inetdomain.dom_protosw; tpro < last; tpro++)
500         if (tpro->pr_protocol == IPPROTO_UDP) {
501             /* restore original udp protocol switch */
502             memcpy((void *)tpro, (void *)&parent_proto, sizeof(parent_proto));
503             memset((void *)&parent_proto, 0, sizeof(parent_proto));
504             rxk_initDone = 0;
505             rxk_shutdownPorts();
506             return;
507         }
508     dpf(("shutdown_rxkernel: no udp proto"));
509 }
510 #endif /* !AIX && !SUN && !NCR  && !UKERNEL */
511
512 #if !defined(AFS_SUN5_ENV) && !defined(AFS_SGI62_ENV)
513 /* Determine what the network interfaces are for this machine. */
514
515 #ifdef AFS_USERSPACE_IP_ADDR
516 int
517 rxi_GetcbiInfo(void)
518 {
519     int i, j, different = 0;
520     int rxmtu, maxmtu;
521     afs_uint32 ifinaddr;
522     afs_uint32 addrs[ADDRSPERSITE];
523     int mtus[ADDRSPERSITE];
524
525     memset((void *)addrs, 0, sizeof(addrs));
526     memset((void *)mtus, 0, sizeof(mtus));
527
528     for (i = 0; i < afs_cb_interface.numberOfInterfaces; i++) {
529         if (!afs_cb_interface.mtu[i])
530             afs_cb_interface.mtu[i] = htonl(1500);
531         rxmtu = (ntohl(afs_cb_interface.mtu[i]) - RX_IPUDP_SIZE);
532         ifinaddr = ntohl(afs_cb_interface.addr_in[i]);
533         if (myNetAddrs[i] != ifinaddr)
534             different++;
535
536         mtus[i] = rxmtu;
537         rxmtu = rxi_AdjustIfMTU(rxmtu);
538         maxmtu =
539             rxmtu * rxi_nRecvFrags + ((rxi_nRecvFrags - 1) * UDP_HDR_SIZE);
540         maxmtu = rxi_AdjustMaxMTU(rxmtu, maxmtu);
541         addrs[i++] = ifinaddr;
542         if ((ifinaddr != 0x7f000001) && (maxmtu > rx_maxReceiveSize)) {
543             rx_maxReceiveSize = MIN(RX_MAX_PACKET_SIZE, maxmtu);
544             rx_maxReceiveSize = MIN(rx_maxReceiveSize, rx_maxReceiveSizeUser);
545         }
546     }
547
548     rx_maxJumboRecvSize =
549         RX_HEADER_SIZE + (rxi_nDgramPackets * RX_JUMBOBUFFERSIZE) +
550         ((rxi_nDgramPackets - 1) * RX_JUMBOHEADERSIZE);
551     rx_maxJumboRecvSize = MAX(rx_maxJumboRecvSize, rx_maxReceiveSize);
552
553     if (different) {
554         for (j = 0; j < i; j++) {
555             myNetMTUs[j] = mtus[j];
556             myNetAddrs[j] = addrs[j];
557         }
558     }
559     return different;
560 }
561
562
563 /* Returns the afs_cb_interface inxex which best matches address.
564  * If none is found, we return -1.
565  */
566 afs_int32
567 rxi_Findcbi(afs_uint32 addr)
568 {
569     int j;
570     afs_uint32 myAddr, thisAddr, netMask, subnetMask;
571     afs_int32 rvalue = -1;
572     int match_value = 0;
573
574     if (numMyNetAddrs == 0)
575         (void)rxi_GetcbiInfo();
576
577     myAddr = ntohl(addr);
578
579     if (IN_CLASSA(myAddr))
580         netMask = IN_CLASSA_NET;
581     else if (IN_CLASSB(myAddr))
582         netMask = IN_CLASSB_NET;
583     else if (IN_CLASSC(myAddr))
584         netMask = IN_CLASSC_NET;
585     else
586         netMask = 0;
587
588     for (j = 0; j < afs_cb_interface.numberOfInterfaces; j++) {
589         thisAddr = ntohl(afs_cb_interface.addr_in[j]);
590         subnetMask = ntohl(afs_cb_interface.subnetmask[j]);
591         if ((myAddr & netMask) == (thisAddr & netMask)) {
592             if ((myAddr & subnetMask) == (thisAddr & subnetMask)) {
593                 if (myAddr == thisAddr) {
594                     match_value = 4;
595                     rvalue = j;
596                     break;
597                 }
598                 if (match_value < 3) {
599                     match_value = 3;
600                     rvalue = j;
601                 }
602             } else {
603                 if (match_value < 2) {
604                     match_value = 2;
605                     rvalue = j;
606                 }
607             }
608         }
609     }
610
611     return (rvalue);
612 }
613
614 #else /* AFS_USERSPACE_IP_ADDR */
615
616 #if !defined(AFS_AIX41_ENV) && !defined(AFS_DUX40_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_XBSD_ENV)
617 #define IFADDR2SA(f) (&((f)->ifa_addr))
618 #else /* AFS_AIX41_ENV */
619 #define IFADDR2SA(f) ((f)->ifa_addr)
620 #endif
621
622 int
623 rxi_GetIFInfo(void)
624 {
625     int i = 0;
626     int different = 0;
627
628     register int rxmtu, maxmtu;
629     afs_uint32 addrs[ADDRSPERSITE];
630     int mtus[ADDRSPERSITE];
631     afs_uint32 ifinaddr;
632 #if defined(AFS_DARWIN80_ENV)
633     errno_t t;
634     int cnt=0;
635     ifaddr_t *ifads, ifad;
636     register ifnet_t ifn;
637     struct sockaddr sout;
638     struct sockaddr_in *sin;
639 #else
640     struct ifaddr *ifad;        /* ifnet points to a if_addrlist of ifaddrs */
641     register struct ifnet *ifn;
642 #endif
643
644     memset(addrs, 0, sizeof(addrs));
645     memset(mtus, 0, sizeof(mtus));
646
647 #if defined(AFS_DARWIN80_ENV)
648     t = ifnet_get_address_list_family(NULL, &ifads, AF_INET);
649     if (t == 0) {
650         rxmtu = ifnet_mtu(ifn) - RX_IPUDP_SIZE;
651         while((ifads[cnt] != NULL) && cnt < ADDRSPERSITE) {
652             t = ifaddr_address(ifads[cnt], &sout, sizeof(sout));
653             sin = (struct sockaddr_in *)&sout;
654             ifinaddr = ntohl(sin->sin_addr.s_addr);
655             if (myNetAddrs[i] != ifinaddr) {
656                 different++;
657             }
658             mtus[i] = rxmtu;
659             rxmtu = rxi_AdjustIfMTU(rxmtu);
660             maxmtu =
661                 rxmtu * rxi_nRecvFrags +
662                 ((rxi_nRecvFrags - 1) * UDP_HDR_SIZE);
663             maxmtu = rxi_AdjustMaxMTU(rxmtu, maxmtu);
664             addrs[i++] = ifinaddr;
665             if ((ifinaddr != 0x7f000001) && (maxmtu > rx_maxReceiveSize)) {
666                 rx_maxReceiveSize = MIN(RX_MAX_PACKET_SIZE, maxmtu);
667                 rx_maxReceiveSize =
668                     MIN(rx_maxReceiveSize, rx_maxReceiveSizeUser);
669             }
670             cnt++;
671         }
672         ifnet_free_address_list(ifads);
673     }
674 #else
675 #if defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
676     TAILQ_FOREACH(ifn, &ifnet, if_link) {
677         if (i >= ADDRSPERSITE)
678             break;
679 #elif defined(AFS_OBSD_ENV)
680     for (ifn = ifnet.tqh_first; i < ADDRSPERSITE && ifn != NULL;
681          ifn = ifn->if_list.tqe_next) {
682 #else
683     for (ifn = ifnet; ifn != NULL && i < ADDRSPERSITE; ifn = ifn->if_next) {
684 #endif
685         rxmtu = (ifn->if_mtu - RX_IPUDP_SIZE);
686 #if defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
687         TAILQ_FOREACH(ifad, &ifn->if_addrhead, ifa_link) {
688             if (i >= ADDRSPERSITE)
689                 break;
690 #elif defined(AFS_OBSD_ENV)
691         for (ifad = ifn->if_addrlist.tqh_first;
692              ifad != NULL && i < ADDRSPERSITE;
693              ifad = ifad->ifa_list.tqe_next) {
694 #else
695         for (ifad = ifn->if_addrlist; ifad != NULL && i < ADDRSPERSITE;
696              ifad = ifad->ifa_next) {
697 #endif
698             if (IFADDR2SA(ifad)->sa_family == AF_INET) {
699                 ifinaddr =
700                     ntohl(((struct sockaddr_in *)IFADDR2SA(ifad))->sin_addr.
701                           s_addr);
702                 if (myNetAddrs[i] != ifinaddr) {
703                     different++;
704                 }
705                 mtus[i] = rxmtu;
706                 rxmtu = rxi_AdjustIfMTU(rxmtu);
707                 maxmtu =
708                     rxmtu * rxi_nRecvFrags +
709                     ((rxi_nRecvFrags - 1) * UDP_HDR_SIZE);
710                 maxmtu = rxi_AdjustMaxMTU(rxmtu, maxmtu);
711                 addrs[i++] = ifinaddr;
712                 if ((ifinaddr != 0x7f000001) && (maxmtu > rx_maxReceiveSize)) {
713                     rx_maxReceiveSize = MIN(RX_MAX_PACKET_SIZE, maxmtu);
714                     rx_maxReceiveSize =
715                         MIN(rx_maxReceiveSize, rx_maxReceiveSizeUser);
716                 }
717             }
718         }
719     }
720 #endif
721
722     rx_maxJumboRecvSize =
723         RX_HEADER_SIZE + rxi_nDgramPackets * RX_JUMBOBUFFERSIZE +
724         (rxi_nDgramPackets - 1) * RX_JUMBOHEADERSIZE;
725     rx_maxJumboRecvSize = MAX(rx_maxJumboRecvSize, rx_maxReceiveSize);
726
727     if (different) {
728         int j;
729         for (j = 0; j < i; j++) {
730             myNetMTUs[j] = mtus[j];
731             myNetAddrs[j] = addrs[j];
732         }
733     }
734     return different;
735 }
736
737 #if defined(AFS_DARWIN60_ENV) || defined(AFS_XBSD_ENV)
738 /* Returns ifnet which best matches address */
739 #ifdef AFS_DARWIN80_ENV
740 ifnet_t
741 #else
742 struct ifnet *
743 #endif
744 rxi_FindIfnet(afs_uint32 addr, afs_uint32 * maskp)
745 {
746     struct sockaddr_in s, sr;
747 #ifdef AFS_DARWIN80_ENV
748     ifaddr_t ifad;
749 #else
750     struct ifaddr *ifad;
751 #endif
752
753     s.sin_family = AF_INET;
754     s.sin_addr.s_addr = addr;
755 #ifdef AFS_DARWIN80_ENV
756     ifad = ifaddr_withnet((struct sockaddr *)&s);
757 #else
758     ifad = ifa_ifwithnet((struct sockaddr *)&s);
759 #endif
760
761 #ifdef AFS_DARWIN80_ENV
762     if (ifad && maskp) {
763         ifaddr_netmask(ifad, (struct sockaddr *)&sr, sizeof(sr));
764         *maskp = sr.sin_addr.s_addr;
765     }
766     return (ifad ? ifaddr_ifnet(ifad) : NULL);
767 #else
768     if (ifad && maskp)
769         *maskp = ((struct sockaddr_in *)ifad->ifa_netmask)->sin_addr.s_addr;
770     return (ifad ? ifad->ifa_ifp : NULL);
771 #endif
772 }
773
774 #else /* DARWIN60 || XBSD */
775
776 /* Returns ifnet which best matches address */
777 struct ifnet *
778 rxi_FindIfnet(afs_uint32 addr, afs_uint32 * maskp)
779 {
780     int match_value = 0;
781     extern struct in_ifaddr *in_ifaddr;
782     struct in_ifaddr *ifa, *ifad = NULL;
783
784     addr = ntohl(addr);
785
786 #if defined(AFS_DARWIN_ENV)
787     for (ifa = TAILQ_FIRST(&in_ifaddrhead); ifa;
788          ifa = TAILQ_NEXT(ifa, ia_link)) {
789 #else
790     for (ifa = in_ifaddr; ifa; ifa = ifa->ia_next) {
791 #endif
792         if ((addr & ifa->ia_netmask) == ifa->ia_net) {
793             if ((addr & ifa->ia_subnetmask) == ifa->ia_subnet) {
794                 if (IA_SIN(ifa)->sin_addr.s_addr == addr) {     /* ie, ME!!!  */
795                     match_value = 4;
796                     ifad = ifa;
797                     goto done;
798                 }
799                 if (match_value < 3) {
800                     ifad = ifa;
801                     match_value = 3;
802                 }
803             } else {
804                 if (match_value < 2) {
805                     ifad = ifa;
806                     match_value = 2;
807                 }
808             }
809         }                       /* if net matches */
810     }                           /* for all in_ifaddrs */
811
812   done:
813     if (ifad && maskp)
814         *maskp = ifad->ia_subnetmask;
815     return (ifad ? ifad->ia_ifp : NULL);
816 }
817 #endif /* else DARWIN60 || XBSD */
818 #endif /* else AFS_USERSPACE_IP_ADDR */
819 #endif /* !SUN5 && !SGI62 */
820
821
822 /* rxk_NewSocket, rxk_FreeSocket and osi_NetSend are from the now defunct
823  * afs_osinet.c. One could argue that rxi_NewSocket could go into the
824  * system specific subdirectories for all systems. But for the moment,
825  * most of it is simple to follow common code.
826  */
827 #if !defined(UKERNEL)
828 #if !defined(AFS_SUN5_ENV) && !defined(AFS_LINUX20_ENV)
829 /* rxk_NewSocket creates a new socket on the specified port. The port is
830  * in network byte order.
831  */
832 osi_socket *
833 rxk_NewSocketHost(afs_uint32 ahost, short aport)
834 {
835     register afs_int32 code;
836 #ifdef AFS_DARWIN80_ENV
837     socket_t newSocket;
838 #else
839     struct socket *newSocket;
840 #endif
841 #if (!defined(AFS_HPUX1122_ENV) && !defined(AFS_FBSD50_ENV))
842     struct mbuf *nam;
843 #endif
844     struct sockaddr_in myaddr;
845 #ifdef AFS_HPUX110_ENV
846     /* prototype copied from kernel source file streams/str_proto.h */
847     extern MBLKP allocb_wait(int, int);
848     MBLKP bindnam;
849     int addrsize = sizeof(struct sockaddr_in);
850     struct file *fp;
851     extern struct fileops socketops;
852 #endif
853 #ifdef AFS_SGI65_ENV
854     bhv_desc_t bhv;
855 #endif
856
857     AFS_STATCNT(osi_NewSocket);
858 #if (defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)) && defined(KERNEL_FUNNEL)
859     thread_funnel_switch(KERNEL_FUNNEL, NETWORK_FUNNEL);
860 #endif
861     AFS_ASSERT_GLOCK();
862     AFS_GUNLOCK();
863 #if     defined(AFS_HPUX102_ENV)
864 #if     defined(AFS_HPUX110_ENV)
865     /* we need a file associated with the socket so sosend in NetSend 
866      * will not fail */
867     /* blocking socket */
868     code = socreate(AF_INET, &newSocket, SOCK_DGRAM, 0, 0);
869     fp = falloc();
870     if (!fp)
871         goto bad;
872     fp->f_flag = FREAD | FWRITE;
873     fp->f_type = DTYPE_SOCKET;
874     fp->f_ops = &socketops;
875
876     fp->f_data = (void *)newSocket;
877     newSocket->so_fp = (void *)fp;
878
879 #else /* AFS_HPUX110_ENV */
880     code = socreate(AF_INET, &newSocket, SOCK_DGRAM, 0, SS_NOWAIT);
881 #endif /* else AFS_HPUX110_ENV */
882 #elif defined(AFS_SGI65_ENV) || defined(AFS_OBSD_ENV)
883     code = socreate(AF_INET, &newSocket, SOCK_DGRAM, IPPROTO_UDP);
884 #elif defined(AFS_FBSD50_ENV)
885     code = socreate(AF_INET, &newSocket, SOCK_DGRAM, IPPROTO_UDP,
886                     afs_osi_credp, curthread);
887 #elif defined(AFS_FBSD40_ENV)
888     code = socreate(AF_INET, &newSocket, SOCK_DGRAM, IPPROTO_UDP, curproc);
889 #elif defined(AFS_DARWIN80_ENV)
890     code = sock_socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP, NULL, NULL, &newSocket);
891 #else
892     code = socreate(AF_INET, &newSocket, SOCK_DGRAM, 0);
893 #endif /* AFS_HPUX102_ENV */
894     if (code)
895         goto bad;
896
897     memset(&myaddr, 0, sizeof myaddr);
898     myaddr.sin_family = AF_INET;
899     myaddr.sin_port = aport;
900     myaddr.sin_addr.s_addr = ahost;
901 #ifdef STRUCT_SOCKADDR_HAS_SA_LEN
902     myaddr.sin_len = sizeof(myaddr);
903 #endif
904
905 #ifdef AFS_HPUX110_ENV
906     bindnam = allocb_wait((addrsize + SO_MSGOFFSET + 1), BPRI_MED);
907     if (!bindnam) {
908         setuerror(ENOBUFS);
909         goto bad;
910     }
911     memcpy((caddr_t) bindnam->b_rptr + SO_MSGOFFSET, (caddr_t) & myaddr,
912            addrsize);
913     bindnam->b_wptr = bindnam->b_rptr + (addrsize + SO_MSGOFFSET + 1);
914
915     code = sobind(newSocket, bindnam, addrsize);
916     if (code) {
917         soclose(newSocket);
918 #if !defined(AFS_HPUX1122_ENV)
919         m_freem(nam);
920 #endif
921         goto bad;
922     }
923
924     freeb(bindnam);
925 #else /* AFS_HPUX110_ENV */
926 #if defined(AFS_DARWIN80_ENV)
927     { 
928        int buflen = 50000;
929        int i,code2;
930        for (i=0;i<2;i++) {
931            code = sock_setsockopt(newSocket, SOL_SOCKET, SO_SNDBUF,
932                                   &buflen, sizeof(buflen));
933            code2 = sock_setsockopt(newSocket, SOL_SOCKET, SO_RCVBUF,
934                                   &buflen, sizeof(buflen));
935            if (!code && !code2)
936                break;
937            if (i == 2)
938               osi_Panic("osi_NewSocket: last attempt to reserve 32K failed!\n");
939            buflen = 32766;
940        }
941     }
942 #else
943     code = soreserve(newSocket, 50000, 50000);
944     if (code) {
945         code = soreserve(newSocket, 32766, 32766);
946         if (code)
947             osi_Panic("osi_NewSocket: last attempt to reserve 32K failed!\n");
948     }
949 #endif
950 #if defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
951 #if defined(AFS_FBSD50_ENV)
952     code = sobind(newSocket, (struct sockaddr *)&myaddr, curthread);
953 #elif defined(AFS_FBSD40_ENV)
954     code = sobind(newSocket, (struct sockaddr *)&myaddr, curproc);
955 #else
956     code = sobind(newSocket, (struct sockaddr *)&myaddr);
957 #endif
958     if (code) {
959         dpf(("sobind fails (%d)\n", (int)code));
960         soclose(newSocket);
961         AFS_GLOCK();
962         goto bad;
963     }
964 #else /* defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) */
965 #ifdef  AFS_OSF_ENV
966     nam = m_getclr(M_WAIT, MT_SONAME);
967 #else /* AFS_OSF_ENV */
968     nam = m_get(M_WAIT, MT_SONAME);
969 #endif
970     if (nam == NULL) {
971 #if defined(KERNEL_HAVE_UERROR)
972         setuerror(ENOBUFS);
973 #endif
974         goto bad;
975     }
976     nam->m_len = sizeof(myaddr);
977     memcpy(mtod(nam, caddr_t), &myaddr, sizeof(myaddr));
978 #ifdef AFS_SGI65_ENV
979     BHV_PDATA(&bhv) = (void *)newSocket;
980     code = sobind(&bhv, nam);
981     m_freem(nam);
982 #else
983     code = sobind(newSocket, nam);
984 #endif
985     if (code) {
986         dpf(("sobind fails (%d)\n", (int)code));
987         soclose(newSocket);
988 #ifndef AFS_SGI65_ENV
989         m_freem(nam);
990 #endif
991         goto bad;
992     }
993 #endif /* else AFS_DARWIN_ENV */
994 #endif /* else AFS_HPUX110_ENV */
995
996     AFS_GLOCK();
997 #if defined(AFS_DARWIN_ENV) && defined(KERNEL_FUNNEL)
998     thread_funnel_switch(NETWORK_FUNNEL, KERNEL_FUNNEL);
999 #endif
1000     return (osi_socket *)newSocket;
1001
1002   bad:
1003     AFS_GLOCK();
1004 #if defined(AFS_DARWIN_ENV) && defined(KERNEL_FUNNEL)
1005     thread_funnel_switch(NETWORK_FUNNEL, KERNEL_FUNNEL);
1006 #endif
1007     return (osi_socket *)0;
1008 }
1009
1010 osi_socket *
1011 rxk_NewSocket(short aport)
1012 {
1013     return rxk_NewSocketHost(0, aport);
1014 }
1015
1016 /* free socket allocated by rxk_NewSocket */
1017 int
1018 rxk_FreeSocket(register struct socket *asocket)
1019 {
1020     AFS_STATCNT(osi_FreeSocket);
1021 #if defined(AFS_DARWIN_ENV) && defined(KERNEL_FUNNEL)
1022     thread_funnel_switch(KERNEL_FUNNEL, NETWORK_FUNNEL);
1023 #endif
1024 #ifdef AFS_HPUX110_ENV
1025     if (asocket->so_fp) {
1026         struct file *fp = asocket->so_fp;
1027 #if !defined(AFS_HPUX1123_ENV)
1028         /* 11.23 still has falloc, but not FPENTRYFREE ! 
1029          * so for now if we shutdown, we will waist a file 
1030          * structure */
1031         FPENTRYFREE(fp);
1032         asocket->so_fp = NULL;
1033 #endif
1034     }
1035 #endif /* AFS_HPUX110_ENV */
1036     soclose(asocket);
1037 #if defined(AFS_DARWIN_ENV) && defined(KERNEL_FUNNEL)
1038     thread_funnel_switch(NETWORK_FUNNEL, KERNEL_FUNNEL);
1039 #endif
1040     return 0;
1041 }
1042 #endif /* !SUN5 && !LINUX20 */
1043
1044 #if defined(RXK_LISTENER_ENV) || defined(AFS_SUN5_ENV)
1045 /*
1046  * Run RX event daemon every second (5 times faster than rest of systems)
1047  */
1048 void
1049 afs_rxevent_daemon(void)
1050 {
1051     struct clock temp;
1052     SPLVAR;
1053
1054     while (1) {
1055 #ifdef RX_ENABLE_LOCKS
1056         AFS_GUNLOCK();
1057 #endif /* RX_ENABLE_LOCKS */
1058         NETPRI;
1059         rxevent_RaiseEvents(&temp);
1060         USERPRI;
1061 #ifdef RX_ENABLE_LOCKS
1062         AFS_GLOCK();
1063 #endif /* RX_ENABLE_LOCKS */
1064 #ifdef RX_KERNEL_TRACE
1065         afs_Trace1(afs_iclSetp, CM_TRACE_TIMESTAMP, ICL_TYPE_STRING,
1066                    "before afs_osi_Wait()");
1067 #endif
1068         afs_osi_Wait(500, NULL, 0);
1069 #ifdef RX_KERNEL_TRACE
1070         afs_Trace1(afs_iclSetp, CM_TRACE_TIMESTAMP, ICL_TYPE_STRING,
1071                    "after afs_osi_Wait()");
1072 #endif
1073         if (afs_termState == AFSOP_STOP_RXEVENT) {
1074 #ifdef RXK_LISTENER_ENV
1075             afs_termState = AFSOP_STOP_RXK_LISTENER;
1076 #else
1077             afs_termState = AFSOP_STOP_COMPLETE;
1078 #endif
1079             osi_rxWakeup(&afs_termState);
1080             return;
1081         }
1082     }
1083 }
1084 #endif
1085
1086 #ifdef RXK_LISTENER_ENV
1087
1088 /* rxk_ReadPacket returns 1 if valid packet, 0 on error. */
1089 int
1090 rxk_ReadPacket(osi_socket so, struct rx_packet *p, int *host, int *port)
1091 {
1092     int code;
1093     struct sockaddr_in from;
1094     int nbytes;
1095     afs_int32 rlen;
1096     register afs_int32 tlen;
1097     afs_int32 savelen;          /* was using rlen but had aliasing problems */
1098     rx_computelen(p, tlen);
1099     rx_SetDataSize(p, tlen);    /* this is the size of the user data area */
1100
1101     tlen += RX_HEADER_SIZE;     /* now this is the size of the entire packet */
1102     rlen = rx_maxJumboRecvSize; /* this is what I am advertising.  Only check
1103                                  * it once in order to avoid races.  */
1104     tlen = rlen - tlen;
1105     if (tlen > 0) {
1106         tlen = rxi_AllocDataBuf(p, tlen, RX_PACKET_CLASS_RECV_CBUF);
1107         if (tlen > 0) {
1108             tlen = rlen - tlen;
1109         } else
1110             tlen = rlen;
1111     } else
1112         tlen = rlen;
1113
1114     /* add some padding to the last iovec, it's just to make sure that the 
1115      * read doesn't return more data than we expect, and is done to get around
1116      * our problems caused by the lack of a length field in the rx header. */
1117     savelen = p->wirevec[p->niovecs - 1].iov_len;
1118     p->wirevec[p->niovecs - 1].iov_len = savelen + RX_EXTRABUFFERSIZE;
1119
1120     nbytes = tlen + sizeof(afs_int32);
1121 #ifdef RX_KERNEL_TRACE
1122     if (ICL_SETACTIVE(afs_iclSetp)) {
1123         AFS_GLOCK();
1124         afs_Trace1(afs_iclSetp, CM_TRACE_TIMESTAMP, ICL_TYPE_STRING,
1125                    "before osi_NetRecive()");
1126         AFS_GUNLOCK();
1127     }
1128 #endif
1129     code = osi_NetReceive(rx_socket, &from, p->wirevec, p->niovecs, &nbytes);
1130
1131 #ifdef RX_KERNEL_TRACE
1132     if (ICL_SETACTIVE(afs_iclSetp)) {
1133         AFS_GLOCK();
1134         afs_Trace1(afs_iclSetp, CM_TRACE_TIMESTAMP, ICL_TYPE_STRING,
1135                    "after osi_NetRecive()");
1136         AFS_GUNLOCK();
1137     }
1138 #endif
1139     /* restore the vec to its correct state */
1140     p->wirevec[p->niovecs - 1].iov_len = savelen;
1141
1142     if (!code) {
1143         p->length = nbytes - RX_HEADER_SIZE;;
1144         if ((nbytes > tlen) || (p->length & 0x8000)) {  /* Bogus packet */
1145             if (nbytes > 0)
1146                 rxi_MorePackets(rx_initSendWindow);
1147             else {
1148                 MUTEX_ENTER(&rx_stats_mutex);
1149                 rx_stats.bogusPacketOnRead++;
1150                 rx_stats.bogusHost = from.sin_addr.s_addr;
1151                 MUTEX_EXIT(&rx_stats_mutex);
1152                 dpf(("B: bogus packet from [%x,%d] nb=%d",
1153                      from.sin_addr.s_addr, from.sin_port, nbytes));
1154             }
1155             return -1;
1156         } else {
1157             /* Extract packet header. */
1158             rxi_DecodePacketHeader(p);
1159
1160             *host = from.sin_addr.s_addr;
1161             *port = from.sin_port;
1162             if (p->header.type > 0 && p->header.type < RX_N_PACKET_TYPES) {
1163                 MUTEX_ENTER(&rx_stats_mutex);
1164                 rx_stats.packetsRead[p->header.type - 1]++;
1165                 MUTEX_EXIT(&rx_stats_mutex);
1166             }
1167
1168             /* Free any empty packet buffers at the end of this packet */
1169             rxi_TrimDataBufs(p, 1);
1170
1171             return 0;
1172         }
1173     } else
1174         return code;
1175 }
1176
1177 /* rxk_Listener() 
1178  *
1179  * Listen for packets on socket. This thread is typically started after
1180  * rx_Init has called rxi_StartListener(), but nevertheless, ensures that
1181  * the start state is set before proceeding.
1182  *
1183  * Note that this thread is outside the AFS global lock for much of
1184  * it's existence.
1185  *
1186  * In many OS's, the socket receive code sleeps interruptibly. That's not what
1187  * we want here. So we need to either block all signals (including SIGKILL
1188  * and SIGSTOP) or reset the thread's signal state to unsignalled when the
1189  * OS's socket receive routine returns as a result of a signal.
1190  */
1191 int rxk_ListenerPid;            /* Used to signal process to wakeup at shutdown */
1192
1193 #ifdef AFS_SUN5_ENV
1194 /*
1195  * Run the listener as a kernel thread.
1196  */
1197 void
1198 rxk_Listener(void)
1199 {
1200     extern id_t syscid;
1201     void rxk_ListenerProc(void);
1202     if (thread_create
1203         (NULL, DEFAULTSTKSZ, rxk_ListenerProc, 0, 0, &p0, TS_RUN,
1204          minclsyspri) == NULL)
1205         osi_Panic("rxk_Listener: failed to start listener thread!\n");
1206 }
1207
1208 void
1209 rxk_ListenerProc(void)
1210 #else /* AFS_SUN5_ENV */
1211 void
1212 rxk_Listener(void)
1213 #endif                          /* AFS_SUN5_ENV */
1214 {
1215     struct rx_packet *rxp = NULL;
1216     int code;
1217     int host, port;
1218
1219 #ifdef AFS_LINUX20_ENV
1220     rxk_ListenerPid = current->pid;
1221 #endif
1222 #ifdef AFS_SUN5_ENV
1223     rxk_ListenerPid = 1;        /* No PID, just a flag that we're alive */
1224 #endif /* AFS_SUN5_ENV */
1225 #ifdef AFS_XBSD_ENV
1226     rxk_ListenerPid = curproc->p_pid;
1227 #endif /* AFS_FBSD_ENV */
1228 #ifdef AFS_DARWIN80_ENV
1229     rxk_ListenerPid = proc_selfpid();
1230 #elif defined(AFS_DARWIN_ENV)
1231     rxk_ListenerPid = current_proc()->p_pid;
1232 #endif
1233 #if defined(RX_ENABLE_LOCKS) && !defined(AFS_SUN5_ENV)
1234     AFS_GUNLOCK();
1235 #endif /* RX_ENABLE_LOCKS && !AFS_SUN5_ENV */
1236     while (afs_termState != AFSOP_STOP_RXK_LISTENER) {
1237         if (rxp) {
1238             rxi_RestoreDataBufs(rxp);
1239         } else {
1240             rxp = rxi_AllocPacket(RX_PACKET_CLASS_RECEIVE);
1241             if (!rxp)
1242                 osi_Panic("rxk_Listener: No more Rx buffers!\n");
1243         }
1244         if (!(code = rxk_ReadPacket(rx_socket, rxp, &host, &port))) {
1245             rxp = rxi_ReceivePacket(rxp, rx_socket, host, port, 0, 0);
1246         }
1247     }
1248
1249 #ifdef RX_ENABLE_LOCKS
1250     AFS_GLOCK();
1251 #endif /* RX_ENABLE_LOCKS */
1252     if (afs_termState == AFSOP_STOP_RXK_LISTENER) {
1253         afs_termState = AFSOP_STOP_COMPLETE;
1254         osi_rxWakeup(&afs_termState);
1255     }
1256     rxk_ListenerPid = 0;
1257 #if defined(AFS_LINUX22_ENV) || defined(AFS_SUN5_ENV)
1258     osi_rxWakeup(&rxk_ListenerPid);
1259 #endif
1260 #ifdef AFS_SUN5_ENV
1261     AFS_GUNLOCK();
1262 #endif /* AFS_SUN5_ENV */
1263 }
1264
1265 #if !defined(AFS_LINUX20_ENV) && !defined(AFS_SUN5_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_XBSD_ENV)
1266 /* The manner of stopping the rx listener thread may vary. Most unix's should
1267  * be able to call soclose.
1268  */
1269 void
1270 osi_StopListener(void)
1271 {
1272     soclose(rx_socket);
1273 }
1274 #endif
1275 #endif /* RXK_LISTENER_ENV */
1276
1277 #endif /* !NCR && !UKERNEL */