Import Upstream version 1.8.5
[hcoop/debian/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_DUX40_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 #ifdef AFS_OSF_ENV
940 nam = m_getclr(M_WAIT, MT_SONAME);
941 #else /* AFS_OSF_ENV */
942 nam = m_get(M_WAIT, MT_SONAME);
943 #endif
944 if (nam == NULL) {
945 #if defined(KERNEL_HAVE_UERROR)
946 setuerror(ENOBUFS);
947 #endif
948 goto bad;
949 }
950 nam->m_len = sizeof(myaddr);
951 memcpy(mtod(nam, caddr_t), &myaddr, sizeof(myaddr));
952 #if defined(AFS_SGI65_ENV)
953 BHV_PDATA(&bhv) = (void *)newSocket;
954 code = sobind(&bhv, nam);
955 m_freem(nam);
956 #elif defined(AFS_OBSD44_ENV) || defined(AFS_NBSD40_ENV)
957 code = sobind(newSocket, nam, osi_curproc());
958 #else
959 code = sobind(newSocket, nam);
960 #endif
961 if (code) {
962 dpf(("sobind fails (%d)\n", (int)code));
963 soclose(newSocket);
964 #ifndef AFS_SGI65_ENV
965 m_freem(nam);
966 #endif
967 goto bad;
968 }
969 #endif /* else AFS_DARWIN_ENV */
970 #endif /* else AFS_HPUX110_ENV */
971
972 AFS_GLOCK();
973 #if defined(AFS_DARWIN_ENV) && defined(KERNEL_FUNNEL)
974 thread_funnel_switch(NETWORK_FUNNEL, KERNEL_FUNNEL);
975 #endif
976 return (osi_socket *)newSocket;
977
978 bad:
979 AFS_GLOCK();
980 #if defined(AFS_DARWIN_ENV) && defined(KERNEL_FUNNEL)
981 thread_funnel_switch(NETWORK_FUNNEL, KERNEL_FUNNEL);
982 #endif
983 return (osi_socket *)0;
984 }
985
986 osi_socket *
987 rxk_NewSocket(short aport)
988 {
989 return rxk_NewSocketHost(0, aport);
990 }
991
992 /* free socket allocated by rxk_NewSocket */
993 int
994 rxk_FreeSocket(struct socket *asocket)
995 {
996 AFS_STATCNT(osi_FreeSocket);
997 #if defined(AFS_DARWIN_ENV) && defined(KERNEL_FUNNEL)
998 thread_funnel_switch(KERNEL_FUNNEL, NETWORK_FUNNEL);
999 #endif
1000 #ifdef AFS_HPUX110_ENV
1001 if (asocket->so_fp) {
1002 struct file *fp = asocket->so_fp;
1003 #if !defined(AFS_HPUX1123_ENV)
1004 /* 11.23 still has falloc, but not FPENTRYFREE !
1005 * so for now if we shutdown, we will waist a file
1006 * structure */
1007 FPENTRYFREE(fp);
1008 asocket->so_fp = NULL;
1009 #endif
1010 }
1011 #endif /* AFS_HPUX110_ENV */
1012 soclose(asocket);
1013 #if defined(AFS_DARWIN_ENV) && defined(KERNEL_FUNNEL)
1014 thread_funnel_switch(NETWORK_FUNNEL, KERNEL_FUNNEL);
1015 #endif
1016 return 0;
1017 }
1018 #endif /* !SUN5 && !LINUX20 */
1019
1020 #if defined(RXK_LISTENER_ENV) || defined(AFS_SUN5_ENV) || defined(RXK_UPCALL_ENV)
1021 #ifdef RXK_TIMEDSLEEP_ENV
1022 /* Shutting down should wake us up, as should an earlier event. */
1023 void
1024 rxi_ReScheduleEvents(void)
1025 {
1026 /* needed to allow startup */
1027 int glock = ISAFS_GLOCK();
1028 if (!glock)
1029 AFS_GLOCK();
1030 osi_rxWakeup(&afs_termState);
1031 if (!glock)
1032 AFS_GUNLOCK();
1033 }
1034 #endif
1035 /*
1036 * Run RX event daemon every second (5 times faster than rest of systems)
1037 */
1038 void
1039 afs_rxevent_daemon(void)
1040 {
1041 struct clock temp;
1042 SPLVAR;
1043
1044 while (1) {
1045 #ifdef RX_ENABLE_LOCKS
1046 AFS_GUNLOCK();
1047 #endif /* RX_ENABLE_LOCKS */
1048 NETPRI;
1049 rxevent_RaiseEvents(&temp);
1050 USERPRI;
1051 #ifdef RX_ENABLE_LOCKS
1052 AFS_GLOCK();
1053 #endif /* RX_ENABLE_LOCKS */
1054 #ifdef RX_KERNEL_TRACE
1055 afs_Trace1(afs_iclSetp, CM_TRACE_TIMESTAMP, ICL_TYPE_STRING,
1056 "before afs_osi_Wait()");
1057 #endif
1058 #ifdef RXK_TIMEDSLEEP_ENV
1059 afs_osi_TimedSleep(&afs_termState, MAX(500, ((temp.sec * 1000) +
1060 (temp.usec / 1000))), 0);
1061 #else
1062 afs_osi_Wait(500, NULL, 0);
1063 #endif
1064 #ifdef RX_KERNEL_TRACE
1065 afs_Trace1(afs_iclSetp, CM_TRACE_TIMESTAMP, ICL_TYPE_STRING,
1066 "after afs_osi_Wait()");
1067 #endif
1068 if (afs_termState == AFSOP_STOP_RXEVENT) {
1069 #ifdef RXK_LISTENER_ENV
1070 afs_termState = AFSOP_STOP_RXK_LISTENER;
1071 #elif defined(AFS_SUN510_ENV) || defined(RXK_UPCALL_ENV)
1072 afs_termState = AFSOP_STOP_NETIF;
1073 #else
1074 afs_termState = AFSOP_STOP_COMPLETE;
1075 #endif
1076 osi_rxWakeup(&afs_termState);
1077 return;
1078 }
1079 }
1080 }
1081 #endif
1082
1083 #ifdef RXK_LISTENER_ENV
1084
1085 /* rxk_ReadPacket returns 1 if valid packet, 0 on error. */
1086 int
1087 rxk_ReadPacket(osi_socket so, struct rx_packet *p, int *host, int *port)
1088 {
1089 int code;
1090 struct sockaddr_in from;
1091 int nbytes;
1092 afs_int32 rlen;
1093 afs_int32 tlen;
1094 afs_int32 savelen; /* was using rlen but had aliasing problems */
1095 rx_computelen(p, tlen);
1096 rx_SetDataSize(p, tlen); /* this is the size of the user data area */
1097
1098 tlen += RX_HEADER_SIZE; /* now this is the size of the entire packet */
1099 rlen = rx_maxJumboRecvSize; /* this is what I am advertising. Only check
1100 * it once in order to avoid races. */
1101 tlen = rlen - tlen;
1102 if (tlen > 0) {
1103 tlen = rxi_AllocDataBuf(p, tlen, RX_PACKET_CLASS_RECV_CBUF);
1104 if (tlen > 0) {
1105 tlen = rlen - tlen;
1106 } else
1107 tlen = rlen;
1108 } else
1109 tlen = rlen;
1110
1111 /* add some padding to the last iovec, it's just to make sure that the
1112 * read doesn't return more data than we expect, and is done to get around
1113 * our problems caused by the lack of a length field in the rx header. */
1114 savelen = p->wirevec[p->niovecs - 1].iov_len;
1115 p->wirevec[p->niovecs - 1].iov_len = savelen + RX_EXTRABUFFERSIZE;
1116
1117 nbytes = tlen + sizeof(afs_int32);
1118 #ifdef RX_KERNEL_TRACE
1119 if (ICL_SETACTIVE(afs_iclSetp)) {
1120 AFS_GLOCK();
1121 afs_Trace1(afs_iclSetp, CM_TRACE_TIMESTAMP, ICL_TYPE_STRING,
1122 "before osi_NetRecive()");
1123 AFS_GUNLOCK();
1124 }
1125 #endif
1126 code = osi_NetReceive(rx_socket, &from, p->wirevec, p->niovecs, &nbytes);
1127
1128 #ifdef RX_KERNEL_TRACE
1129 if (ICL_SETACTIVE(afs_iclSetp)) {
1130 AFS_GLOCK();
1131 afs_Trace1(afs_iclSetp, CM_TRACE_TIMESTAMP, ICL_TYPE_STRING,
1132 "after osi_NetRecive()");
1133 AFS_GUNLOCK();
1134 }
1135 #endif
1136 /* restore the vec to its correct state */
1137 p->wirevec[p->niovecs - 1].iov_len = savelen;
1138
1139 if (!code) {
1140 p->length = nbytes - RX_HEADER_SIZE;;
1141 if ((nbytes > tlen) || (p->length & 0x8000)) { /* Bogus packet */
1142 if (nbytes <= 0) {
1143 if (rx_stats_active) {
1144 MUTEX_ENTER(&rx_stats_mutex);
1145 rx_atomic_inc(&rx_stats.bogusPacketOnRead);
1146 rx_stats.bogusHost = from.sin_addr.s_addr;
1147 MUTEX_EXIT(&rx_stats_mutex);
1148 }
1149 dpf(("B: bogus packet from [%x,%d] nb=%d\n",
1150 from.sin_addr.s_addr, from.sin_port, nbytes));
1151 }
1152 return -1;
1153 } else {
1154 /* Extract packet header. */
1155 rxi_DecodePacketHeader(p);
1156
1157 *host = from.sin_addr.s_addr;
1158 *port = from.sin_port;
1159 if (p->header.type > 0 && p->header.type < RX_N_PACKET_TYPES) {
1160 if (rx_stats_active) {
1161 rx_atomic_inc(&rx_stats.packetsRead[p->header.type - 1]);
1162 }
1163 }
1164
1165 #ifdef RX_TRIMDATABUFS
1166 /* Free any empty packet buffers at the end of this packet */
1167 rxi_TrimDataBufs(p, 1);
1168 #endif
1169 return 0;
1170 }
1171 } else
1172 return code;
1173 }
1174
1175 /* rxk_Listener()
1176 *
1177 * Listen for packets on socket. This thread is typically started after
1178 * rx_Init has called rxi_StartListener(), but nevertheless, ensures that
1179 * the start state is set before proceeding.
1180 *
1181 * Note that this thread is outside the AFS global lock for much of
1182 * it's existence.
1183 *
1184 * In many OS's, the socket receive code sleeps interruptibly. That's not what
1185 * we want here. So we need to either block all signals (including SIGKILL
1186 * and SIGSTOP) or reset the thread's signal state to unsignalled when the
1187 * OS's socket receive routine returns as a result of a signal.
1188 */
1189 int rxk_ListenerPid; /* Used to signal process to wakeup at shutdown */
1190 #ifdef AFS_LINUX20_ENV
1191 struct task_struct *rxk_ListenerTask;
1192 #endif
1193
1194 void
1195 rxk_Listener(void)
1196 {
1197 struct rx_packet *rxp = NULL;
1198 int code;
1199 int host, port;
1200
1201 #ifdef AFS_LINUX20_ENV
1202 rxk_ListenerPid = current->pid;
1203 rxk_ListenerTask = current;
1204 allow_signal(SIGKILL); /* Allowed, but blocked until shutdown */
1205 #endif
1206 #ifdef AFS_SUN5_ENV
1207 rxk_ListenerPid = 1; /* No PID, just a flag that we're alive */
1208 #endif /* AFS_SUN5_ENV */
1209 #ifdef AFS_XBSD_ENV
1210 rxk_ListenerPid = curproc->p_pid;
1211 #endif /* AFS_FBSD_ENV */
1212 #ifdef AFS_DARWIN80_ENV
1213 rxk_ListenerPid = proc_selfpid();
1214 #elif defined(AFS_DARWIN_ENV)
1215 rxk_ListenerPid = current_proc()->p_pid;
1216 #endif
1217 #ifdef RX_ENABLE_LOCKS
1218 AFS_GUNLOCK();
1219 #endif /* RX_ENABLE_LOCKS */
1220 while (afs_termState != AFSOP_STOP_RXK_LISTENER) {
1221 /* See if a check for additional packets was issued */
1222 rx_CheckPackets();
1223
1224 if (rxp) {
1225 rxi_RestoreDataBufs(rxp);
1226 } else {
1227 rxp = rxi_AllocPacket(RX_PACKET_CLASS_RECEIVE);
1228 if (!rxp)
1229 osi_Panic("rxk_Listener: No more Rx buffers!\n");
1230 }
1231 if (!(code = rxk_ReadPacket(rx_socket, rxp, &host, &port))) {
1232 rxp = rxi_ReceivePacket(rxp, rx_socket, host, port, 0, 0);
1233 }
1234 }
1235
1236 #ifdef RX_ENABLE_LOCKS
1237 AFS_GLOCK();
1238 #endif /* RX_ENABLE_LOCKS */
1239 if (afs_termState == AFSOP_STOP_RXK_LISTENER) {
1240 #ifdef AFS_SUN510_ENV
1241 afs_termState = AFSOP_STOP_NETIF;
1242 #else
1243 afs_termState = AFSOP_STOP_COMPLETE;
1244 #endif
1245 osi_rxWakeup(&afs_termState);
1246 }
1247 rxk_ListenerPid = 0;
1248 #ifdef AFS_LINUX20_ENV
1249 rxk_ListenerTask = 0;
1250 osi_rxWakeup(&rxk_ListenerTask);
1251 #endif
1252 #if defined(AFS_SUN5_ENV) || defined(AFS_FBSD_ENV)
1253 osi_rxWakeup(&rxk_ListenerPid);
1254 #endif
1255 }
1256
1257 #if !defined(AFS_LINUX20_ENV) && !defined(AFS_SUN5_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_XBSD_ENV)
1258 /* The manner of stopping the rx listener thread may vary. Most unix's should
1259 * be able to call soclose.
1260 */
1261 void
1262 osi_StopListener(void)
1263 {
1264 soclose(rx_socket);
1265 }
1266 #endif
1267 #endif /* RXK_LISTENER_ENV */
1268 #endif /* !NCR && !UKERNEL */
1269
1270 #if !defined(AFS_LINUX26_ENV)
1271 void
1272 #if defined(AFS_AIX_ENV)
1273 osi_Panic(char *msg, void *a1, void *a2, void *a3)
1274 #else
1275 osi_Panic(char *msg, ...)
1276 #endif
1277 {
1278 #ifdef AFS_AIX_ENV
1279 if (!msg)
1280 msg = "Unknown AFS panic";
1281 /*
1282 * we should probably use the errsave facility here. it is not
1283 * varargs-aware
1284 */
1285
1286 printf(msg, a1, a2, a3);
1287 panic(msg);
1288 #elif defined(AFS_SGI_ENV)
1289 va_list ap;
1290
1291 /* Solaris has vcmn_err, Sol10 01/06 may have issues. Beware. */
1292 if (!msg) {
1293 cmn_err(CE_PANIC, "Unknown AFS panic");
1294 } else {
1295 va_start(ap, msg);
1296 icmn_err(CE_PANIC, msg, ap);
1297 va_end(ap);
1298 }
1299 #elif defined(AFS_DARWIN80_ENV) || defined(AFS_LINUX22_ENV) || defined(AFS_FBSD_ENV) || defined(UKERNEL)
1300 char buf[256];
1301 va_list ap;
1302 if (!msg)
1303 msg = "Unknown AFS panic";
1304
1305 va_start(ap, msg);
1306 vsnprintf(buf, sizeof(buf), msg, ap);
1307 va_end(ap);
1308 printf("%s", buf);
1309 panic("%s", buf);
1310 #else
1311 va_list ap;
1312 if (!msg)
1313 msg = "Unknown AFS panic";
1314
1315 va_start(ap, msg);
1316 vprintf(msg, ap);
1317 va_end(ap);
1318 # ifdef AFS_LINUX20_ENV
1319 * ((char *) 0) = 0;
1320 # else
1321 panic("%s", msg);
1322 # endif
1323 #endif
1324 }
1325 #endif