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