windows-pcache-20050310
[openafs.git] / src / rx / rx_user.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 /* rx_user.c contains routines specific to the user space UNIX implementation of rx */
11
12 #include <afsconfig.h>
13 #include <afs/param.h>
14
15 RCSID
16     ("$Header$");
17
18 # include <sys/types.h>
19 # include <errno.h>
20 # include <signal.h>
21 #ifdef AFS_NT40_ENV
22 # include <WINNT/syscfg.h>
23 #else
24 # include <sys/socket.h>
25 # include <sys/file.h>
26 # include <netdb.h>
27 # include <sys/stat.h>
28 # include <netinet/in.h>
29 # include <sys/time.h>
30 # include <net/if.h>
31 # include <sys/ioctl.h>
32 #endif
33 # include <fcntl.h>
34 #if !defined(AFS_AIX_ENV) && !defined(AFS_NT40_ENV) && !defined(AFS_DJGPP_ENV)
35 # include <sys/syscall.h>
36 #endif
37 #include <afs/afs_args.h>
38 #include <afs/afsutil.h>
39 #ifdef HAVE_STRING_H
40 #include <string.h>
41 #else
42 #ifdef HAVE_STRINGS_H
43 #include <strings.h>
44 #endif
45 #endif
46
47 #ifndef IPPORT_USERRESERVED
48 /* If in.h doesn't define this, define it anyway.  Unfortunately, defining
49    this doesn't put the code into the kernel to restrict kernel assigned
50    port numbers to numbers below IPPORT_USERRESERVED...  */
51 #define IPPORT_USERRESERVED 5000
52 # endif
53
54 #ifndef AFS_NT40_ENV
55 # include <sys/time.h>
56 #endif
57 # include "rx.h"
58 # include "rx_globals.h"
59
60 #ifdef AFS_PTHREAD_ENV
61 #include <assert.h>
62
63 /*
64  * The rx_if_init_mutex mutex protects the following global variables:
65  * Inited
66  */
67
68 pthread_mutex_t rx_if_init_mutex;
69 #define LOCK_IF_INIT assert(pthread_mutex_lock(&rx_if_init_mutex)==0)
70 #define UNLOCK_IF_INIT assert(pthread_mutex_unlock(&rx_if_init_mutex)==0)
71
72 /*
73  * The rx_if_mutex mutex protects the following global variables:
74  * myNetFlags
75  * myNetMTUs
76  * myNetMasks
77  */
78
79 pthread_mutex_t rx_if_mutex;
80 #define LOCK_IF assert(pthread_mutex_lock(&rx_if_mutex)==0)
81 #define UNLOCK_IF assert(pthread_mutex_unlock(&rx_if_mutex)==0)
82 #else
83 #define LOCK_IF_INIT
84 #define UNLOCK_IF_INIT
85 #define LOCK_IF
86 #define UNLOCK_IF
87 #endif /* AFS_PTHREAD_ENV */
88
89
90 /*
91  * Make a socket for receiving/sending IP packets.  Set it into non-blocking
92  * and large buffering modes.  If port isn't specified, the kernel will pick
93  * one.  Returns the socket (>= 0) on success.  Returns OSI_NULLSOCKET on
94  * failure. Port must be in network byte order. 
95  */
96 osi_socket
97 rxi_GetHostUDPSocket(u_int ahost, u_short port)
98 {
99     int binds, code = 0;
100     osi_socket socketFd = OSI_NULLSOCKET;
101     struct sockaddr_in taddr;
102     char *name = "rxi_GetUDPSocket: ";
103 #ifdef AFS_LINUX22_ENV
104     int pmtu=IP_PMTUDISC_DONT;
105 #endif
106
107 #if !defined(AFS_NT40_ENV) && !defined(AFS_DJGPP_ENV)
108     if (ntohs(port) >= IPPORT_RESERVED && ntohs(port) < IPPORT_USERRESERVED) {
109 /*      (osi_Msg "%s*WARNING* port number %d is not a reserved port number.  Use port numbers above %d\n", name, port, IPPORT_USERRESERVED);
110 */ ;
111     }
112     if (ntohs(port) > 0 && ntohs(port) < IPPORT_RESERVED && geteuid() != 0) {
113         (osi_Msg
114          "%sport number %d is a reserved port number which may only be used by root.  Use port numbers above %d\n",
115          name, ntohs(port), IPPORT_USERRESERVED);
116         goto error;
117     }
118 #endif
119     socketFd = socket(AF_INET, SOCK_DGRAM, 0);
120
121     if (socketFd < 0) {
122         perror("socket");
123         goto error;
124     }
125
126     taddr.sin_addr.s_addr = ahost;
127     taddr.sin_family = AF_INET;
128     taddr.sin_port = (u_short) port;
129 #ifdef STRUCT_SOCKADDR_HAS_SA_LEN
130     taddr.sin_len = sizeof(struct sockaddr_in);
131 #endif
132 #define MAX_RX_BINDS 10
133     for (binds = 0; binds < MAX_RX_BINDS; binds++) {
134         if (binds)
135             rxi_Delay(10);
136         code = bind(socketFd, (struct sockaddr *)&taddr, sizeof(taddr));
137         if (!code)
138             break;
139     }
140     if (code) {
141         perror("bind");
142         (osi_Msg "%sbind failed\n", name);
143         goto error;
144     }
145 #if !defined(AFS_NT40_ENV) && !defined(AFS_DJGPP_ENV)
146     /*
147      * Set close-on-exec on rx socket 
148      */
149     fcntl(socketFd, F_SETFD, 1);
150 #endif
151
152 #ifndef AFS_DJGPP_ENV
153     /* Use one of three different ways of getting a socket buffer expanded to
154      * a reasonable size.
155      */
156     {
157         int greedy = 0;
158         int len1, len2;
159
160         len1 = 32766;
161         len2 = rx_UdpBufSize;
162         greedy =
163             (setsockopt
164              (socketFd, SOL_SOCKET, SO_RCVBUF, (char *)&len2,
165               sizeof(len2)) >= 0);
166         if (!greedy) {
167             len2 = 32766;       /* fall back to old size... uh-oh! */
168         }
169
170         greedy =
171             (setsockopt
172              (socketFd, SOL_SOCKET, SO_SNDBUF, (char *)&len1,
173               sizeof(len1)) >= 0)
174             &&
175             (setsockopt
176              (socketFd, SOL_SOCKET, SO_RCVBUF, (char *)&len2,
177               sizeof(len2)) >= 0);
178         if (!greedy)
179             (osi_Msg "%s*WARNING* Unable to increase buffering on socket\n",
180              name);
181         MUTEX_ENTER(&rx_stats_mutex);
182         rx_stats.socketGreedy = greedy;
183         MUTEX_EXIT(&rx_stats_mutex);
184     }
185 #endif /* AFS_DJGPP_ENV */
186
187 #ifdef AFS_LINUX22_ENV
188     setsockopt(socketFd, SOL_IP, IP_MTU_DISCOVER, &pmtu, sizeof(pmtu));
189 #endif
190
191     if (rxi_Listen(socketFd) < 0) {
192         goto error;
193     }
194
195     return socketFd;
196
197   error:
198 #ifdef AFS_NT40_ENV
199     if (socketFd >= 0)
200         closesocket(socketFd);
201 #else
202     if (socketFd >= 0)
203         close(socketFd);
204 #endif
205
206     return OSI_NULLSOCKET;
207 }
208
209 osi_socket
210 rxi_GetUDPSocket(u_short port)
211 {
212     return rxi_GetHostUDPSocket(htonl(INADDR_ANY), port);
213 }
214
215 void
216 osi_Panic(char *msg, int a1, int a2, int a3)
217 {
218     (osi_Msg "Fatal Rx error: ");
219     (osi_Msg msg, a1, a2, a3);
220     fflush(stderr);
221     fflush(stdout);
222     afs_abort();
223 }
224
225 /*
226  * osi_AssertFailU() -- used by the osi_Assert() macro.
227  */
228
229 void
230 osi_AssertFailU(const char *expr, const char *file, int line)
231 {
232     osi_Panic("assertion failed: %s, file: %s, line: %d\n", (int)expr,
233               (int)file, line);
234 }
235
236 #ifdef  AFS_AIX32_ENV
237 #ifndef osi_Alloc
238 static const char memZero;
239 char *
240 osi_Alloc(afs_int32 x)
241 {
242     /* 
243      * 0-length allocs may return NULL ptr from osi_kalloc, so we special-case
244      * things so that NULL returned iff an error occurred 
245      */
246     if (x == 0)
247         return &memZero;
248     return ((char *)malloc(x));
249 }
250
251 void
252 osi_Free(char *x, afs_int32 size)
253 {
254     if (x == &memZero)
255         return;
256     free((char *)x);
257 }
258 #endif
259 #endif /* AFS_AIX32_ENV */
260
261 #define ADDRSPERSITE    16
262
263
264 static afs_uint32 rxi_NetAddrs[ADDRSPERSITE];   /* host order */
265 static int myNetMTUs[ADDRSPERSITE];
266 static int myNetMasks[ADDRSPERSITE];
267 static int myNetFlags[ADDRSPERSITE];
268 static u_int rxi_numNetAddrs;
269 static int Inited = 0;
270
271 #if defined(AFS_NT40_ENV) || defined(AFS_DJGPP_ENV)
272 int
273 rxi_getaddr(void)
274 {
275     /* The IP address list can change so we must query for it */
276     rx_GetIFInfo();
277
278     /* we don't want to use the loopback adapter which is first */
279     /* this is a bad bad hack */
280     if (rxi_numNetAddrs > 1)
281         return htonl(rxi_NetAddrs[1]);  
282     else if (rxi_numNetAddrs > 0)
283         return htonl(rxi_NetAddrs[0]);
284     else
285         return 0;
286 }
287
288 /* 
289 ** return number of addresses 
290 ** and the addresses themselves in the buffer
291 ** maxSize - max number of interfaces to return.
292 */
293 int
294 rx_getAllAddr(afs_int32 * buffer, int maxSize)
295 {
296     int count = 0, offset = 0;
297
298     /* The IP address list can change so we must query for it */
299     rx_GetIFInfo();
300
301     /* we don't want to use the loopback adapter which is first */
302     /* this is a bad bad hack */
303     if ( rxi_numNetAddrs > 1 )
304         offset = 1;
305
306     for (count = 0; offset < rxi_numNetAddrs && maxSize > 0;
307          count++, offset++, maxSize--)
308         buffer[count] = htonl(rxi_NetAddrs[offset]);
309
310     return count;
311 }
312 #endif
313
314 #ifdef AFS_NT40_ENV
315 void
316 rx_GetIFInfo(void)
317 {
318     u_int maxsize;
319     u_int rxsize;
320     int npackets, ncbufs;
321     afs_uint32 i;
322
323     LOCK_IF_INIT;
324     Inited = 1;
325     UNLOCK_IF_INIT;
326
327     LOCK_IF;
328     rxi_numNetAddrs = ADDRSPERSITE;
329     (void)syscfg_GetIFInfo(&rxi_numNetAddrs, rxi_NetAddrs,
330                            myNetMasks, myNetMTUs, myNetFlags);
331
332     for (i = 0; i < rxi_numNetAddrs; i++) {
333         rxsize = rxi_AdjustIfMTU(myNetMTUs[i] - RX_IPUDP_SIZE);
334         maxsize =
335             rxi_nRecvFrags * rxsize + (rxi_nRecvFrags - 1) * UDP_HDR_SIZE;
336         maxsize = rxi_AdjustMaxMTU(rxsize, maxsize);
337         if (rx_maxReceiveSize < maxsize) {
338             rx_maxReceiveSize = MIN(RX_MAX_PACKET_SIZE, maxsize);
339             rx_maxReceiveSize =
340                 MIN(rx_maxReceiveSize, rx_maxReceiveSizeUser);
341         }
342
343     }
344     UNLOCK_IF;
345     ncbufs = (rx_maxJumboRecvSize - RX_FIRSTBUFFERSIZE);
346     if (ncbufs > 0) {
347         ncbufs = ncbufs / RX_CBUFFERSIZE;
348         npackets = rx_initSendWindow - 1;
349         rxi_MorePackets(npackets * (ncbufs + 1));
350     }
351 }
352 #endif
353
354 static afs_uint32
355 fudge_netmask(afs_uint32 addr)
356 {
357     afs_uint32 msk;
358
359     if (IN_CLASSA(addr))
360         msk = IN_CLASSA_NET;
361     else if (IN_CLASSB(addr))
362         msk = IN_CLASSB_NET;
363     else if (IN_CLASSC(addr))
364         msk = IN_CLASSC_NET;
365     else
366         msk = 0;
367
368     return msk;
369 }
370
371
372
373 #if !defined(AFS_AIX_ENV) && !defined(AFS_NT40_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_DJGPP_ENV)
374 int
375 rxi_syscall(a3, a4, a5)
376      afs_uint32 a3, a4;
377      void *a5;
378 {
379     afs_uint32 rcode;
380     void (*old) ();
381
382     old = (void (*)())signal(SIGSYS, SIG_IGN);
383
384 #if defined(AFS_SGI_ENV)
385     rcode = afs_syscall(a3, a4, a5);
386 #else
387     rcode = syscall(AFS_SYSCALL, 28 /* AFSCALL_CALL */ , a3, a4, a5);
388 #endif /* AFS_SGI_ENV */
389
390     signal(SIGSYS, old);
391
392     return rcode;
393 }
394 #endif /* AFS_AIX_ENV */
395
396 #ifndef AFS_NT40_ENV
397 void
398 rx_GetIFInfo(void)
399 {
400     int s;
401     int i, j, len, res;
402 #ifndef AFS_DJGPP_ENV
403     struct ifconf ifc;
404     struct ifreq ifs[ADDRSPERSITE];
405     struct ifreq *ifr;
406 #ifdef  AFS_AIX41_ENV
407     char buf[BUFSIZ], *cp, *cplim;
408 #endif
409     struct sockaddr_in *a;
410 #endif /* AFS_DJGPP_ENV */
411
412     LOCK_IF_INIT;
413     if (Inited) {
414         UNLOCK_IF_INIT;
415         return;
416     }
417     Inited = 1;
418     UNLOCK_IF_INIT;
419     LOCK_IF;
420     rxi_numNetAddrs = 0;
421     memset(rxi_NetAddrs, 0, sizeof(rxi_NetAddrs));
422     memset(myNetFlags, 0, sizeof(myNetFlags));
423     memset(myNetMTUs, 0, sizeof(myNetMTUs));
424     memset(myNetMasks, 0, sizeof(myNetMasks));
425     UNLOCK_IF;
426     s = socket(AF_INET, SOCK_DGRAM, 0);
427     if (s < 0)
428         return;
429
430 #ifndef AFS_DJGPP_ENV
431 #ifdef  AFS_AIX41_ENV
432     ifc.ifc_len = sizeof(buf);
433     ifc.ifc_buf = buf;
434     ifr = ifc.ifc_req;
435 #else
436     ifc.ifc_len = sizeof(ifs);
437     ifc.ifc_buf = (caddr_t) & ifs[0];
438     memset(&ifs[0], 0, sizeof(ifs));
439 #endif
440     res = ioctl(s, SIOCGIFCONF, &ifc);
441     if (res < 0) {
442         /* fputs(stderr, "ioctl error IFCONF\n"); */
443         close(s);
444         return;
445     }
446
447     LOCK_IF;
448 #ifdef  AFS_AIX41_ENV
449 #define size(p) MAX((p).sa_len, sizeof(p))
450     cplim = buf + ifc.ifc_len;  /*skip over if's with big ifr_addr's */
451     for (cp = buf; cp < cplim;
452          cp += sizeof(ifr->ifr_name) + MAX(a->sin_len, sizeof(*a))) {
453         if (rxi_numNetAddrs >= ADDRSPERSITE)
454             break;
455
456         ifr = (struct ifreq *)cp;
457 #else
458     len = ifc.ifc_len / sizeof(struct ifreq);
459     if (len > ADDRSPERSITE)
460         len = ADDRSPERSITE;
461
462     for (i = 0; i < len; ++i) {
463         ifr = &ifs[i];
464         res = ioctl(s, SIOCGIFADDR, ifr);
465 #endif
466         if (res < 0) {
467             /* fputs(stderr, "ioctl error IFADDR\n");
468              * perror(ifr->ifr_name);   */
469             continue;
470         }
471         a = (struct sockaddr_in *)&ifr->ifr_addr;
472         if (a->sin_family != AF_INET)
473             continue;
474         rxi_NetAddrs[rxi_numNetAddrs] = ntohl(a->sin_addr.s_addr);
475         if (rxi_NetAddrs[rxi_numNetAddrs] == 0x7f000001) {
476             /* we don't really care about "localhost" */
477             continue;
478         }
479         for (j = 0; j < rxi_numNetAddrs; j++) {
480             if (rxi_NetAddrs[j] == rxi_NetAddrs[rxi_numNetAddrs])
481                 break;
482         }
483         if (j < rxi_numNetAddrs)
484             continue;
485
486         /* fprintf(stderr, "if %s addr=%x\n", ifr->ifr_name,
487          * rxi_NetAddrs[rxi_numNetAddrs]); */
488
489 #ifdef SIOCGIFFLAGS
490         res = ioctl(s, SIOCGIFFLAGS, ifr);
491         if (res == 0) {
492             myNetFlags[rxi_numNetAddrs] = ifr->ifr_flags;
493 #ifdef IFF_LOOPBACK
494             /* Handle aliased loopbacks as well. */
495             if (ifr->ifr_flags & IFF_LOOPBACK)
496                 continue;
497 #endif
498             /* fprintf(stderr, "if %s flags=%x\n", 
499              * ifr->ifr_name, ifr->ifr_flags); */
500         } else {                /*
501                                  * fputs(stderr, "ioctl error IFFLAGS\n");
502                                  * perror(ifr->ifr_name); */
503         }
504 #endif /* SIOCGIFFLAGS */
505
506 #if !defined(AFS_AIX_ENV)  && !defined(AFS_LINUX20_ENV)
507         /* this won't run on an AIX system w/o a cache manager */
508         rxi_syscallp = rxi_syscall;
509 #endif
510
511         /* If I refer to kernel extensions that aren't loaded on AIX, the 
512          * program refuses to load and run, so I simply can't include the 
513          * following code.  Fortunately, AIX is the one operating system in
514          * which the subsequent ioctl works reliably. */
515         if (rxi_syscallp) {
516             if ((*rxi_syscallp) (20 /*AFSOP_GETMTU */ ,
517                                  htonl(rxi_NetAddrs[rxi_numNetAddrs]),
518                                  &(myNetMTUs[rxi_numNetAddrs]))) {
519                 /* fputs(stderr, "syscall error GETMTU\n");
520                  * perror(ifr->ifr_name); */
521                 myNetMTUs[rxi_numNetAddrs] = 0;
522             }
523             if ((*rxi_syscallp) (42 /*AFSOP_GETMASK */ ,
524                                  htonl(rxi_NetAddrs[rxi_numNetAddrs]),
525                                  &(myNetMasks[rxi_numNetAddrs]))) {
526                 /* fputs(stderr, "syscall error GETMASK\n");
527                  * perror(ifr->ifr_name); */
528                 myNetMasks[rxi_numNetAddrs] = 0;
529             } else
530                 myNetMasks[rxi_numNetAddrs] =
531                     ntohl(myNetMasks[rxi_numNetAddrs]);
532             /* fprintf(stderr, "if %s mask=0x%x\n", 
533              * ifr->ifr_name, myNetMasks[rxi_numNetAddrs]); */
534         }
535
536         if (myNetMTUs[rxi_numNetAddrs] == 0) {
537             myNetMTUs[rxi_numNetAddrs] = OLD_MAX_PACKET_SIZE + RX_IPUDP_SIZE;
538 #ifdef SIOCGIFMTU
539             res = ioctl(s, SIOCGIFMTU, ifr);
540             if ((res == 0) && (ifr->ifr_metric > 128)) {        /* sanity check */
541                 myNetMTUs[rxi_numNetAddrs] = ifr->ifr_metric;
542                 /* fprintf(stderr, "if %s mtu=%d\n", 
543                  * ifr->ifr_name, ifr->ifr_metric); */
544             } else {
545                 /* fputs(stderr, "ioctl error IFMTU\n");
546                  * perror(ifr->ifr_name); */
547             }
548 #endif
549         }
550
551         if (myNetMasks[rxi_numNetAddrs] == 0) {
552             myNetMasks[rxi_numNetAddrs] =
553                 fudge_netmask(rxi_NetAddrs[rxi_numNetAddrs]);
554 #ifdef SIOCGIFNETMASK
555             res = ioctl(s, SIOCGIFNETMASK, ifr);
556             if ((res == 0)) {
557                 a = (struct sockaddr_in *)&ifr->ifr_addr;
558                 myNetMasks[rxi_numNetAddrs] = ntohl(a->sin_addr.s_addr);
559                 /* fprintf(stderr, "if %s subnetmask=0x%x\n", 
560                  * ifr->ifr_name, myNetMasks[rxi_numNetAddrs]); */
561             } else {
562                 /* fputs(stderr, "ioctl error IFMASK\n");
563                  * perror(ifr->ifr_name); */
564             }
565 #endif
566         }
567
568         if (rxi_NetAddrs[rxi_numNetAddrs] != 0x7f000001) {      /* ignore lo0 */
569             int maxsize;
570             maxsize =
571                 rxi_nRecvFrags * (myNetMTUs[rxi_numNetAddrs] - RX_IP_SIZE);
572             maxsize -= UDP_HDR_SIZE;    /* only the first frag has a UDP hdr */
573             if (rx_maxReceiveSize < maxsize)
574                 rx_maxReceiveSize = MIN(RX_MAX_PACKET_SIZE, maxsize);
575             ++rxi_numNetAddrs;
576         }
577     }
578     UNLOCK_IF;
579     close(s);
580
581     /* have to allocate at least enough to allow a single packet to reach its
582      * maximum size, so ReadPacket will work.  Allocate enough for a couple
583      * of packets to do so, for good measure */
584     {
585         int npackets, ncbufs;
586
587         rx_maxJumboRecvSize =
588             RX_HEADER_SIZE + rxi_nDgramPackets * RX_JUMBOBUFFERSIZE +
589             (rxi_nDgramPackets - 1) * RX_JUMBOHEADERSIZE;
590         rx_maxJumboRecvSize = MAX(rx_maxJumboRecvSize, rx_maxReceiveSize);
591         ncbufs = (rx_maxJumboRecvSize - RX_FIRSTBUFFERSIZE);
592         if (ncbufs > 0) {
593             ncbufs = ncbufs / RX_CBUFFERSIZE;
594             npackets = rx_initSendWindow - 1;
595             rxi_MorePackets(npackets * (ncbufs + 1));
596         }
597     }
598 #else /* AFS_DJGPP_ENV */
599     close(s);
600     return;
601 #endif /* AFS_DJGPP_ENV */
602 }
603 #endif /* AFS_NT40_ENV */
604
605 /* Called from rxi_FindPeer, when initializing a clear rx_peer structure,
606  * to get interesting information.
607  * Curiously enough, the rx_peerHashTable_lock currently protects the
608  * Inited variable (and hence rx_GetIFInfo). When the fs suite uses
609  * pthreads, this issue will need to be revisited.
610  */
611
612 void
613 rxi_InitPeerParams(struct rx_peer *pp)
614 {
615     afs_uint32 ppaddr;
616     u_short rxmtu;
617     int ix;
618
619
620
621     LOCK_IF_INIT;
622     if (!Inited) {
623         UNLOCK_IF_INIT;
624         /*
625          * there's a race here since more than one thread could call
626          * rx_GetIFInfo.  The race stops in rx_GetIFInfo.
627          */
628         rx_GetIFInfo();
629     } else {
630         UNLOCK_IF_INIT;
631     }
632
633 #ifdef ADAPT_MTU
634     /* try to second-guess IP, and identify which link is most likely to
635      * be used for traffic to/from this host. */
636     ppaddr = ntohl(pp->host);
637
638     pp->ifMTU = 0;
639     pp->timeout.sec = 2;
640     pp->rateFlag = 2;           /* start timing after two full packets */
641     /* I don't initialize these, because I presume they are bzero'd... 
642      * pp->burstSize pp->burst pp->burstWait.sec pp->burstWait.usec
643      * pp->timeout.usec */
644
645     LOCK_IF;
646     for (ix = 0; ix < rxi_numNetAddrs; ++ix) {
647         if ((rxi_NetAddrs[ix] & myNetMasks[ix]) == (ppaddr & myNetMasks[ix])) {
648 #ifdef IFF_POINTOPOINT
649             if (myNetFlags[ix] & IFF_POINTOPOINT)
650                 pp->timeout.sec = 4;
651 #endif /* IFF_POINTOPOINT */
652             rxmtu = myNetMTUs[ix] - RX_IPUDP_SIZE;
653             if (rxmtu < RX_MIN_PACKET_SIZE)
654                 rxmtu = RX_MIN_PACKET_SIZE;
655             if (pp->ifMTU < rxmtu)
656                 pp->ifMTU = MIN(rx_MyMaxSendSize, rxmtu);
657         }
658     }
659     UNLOCK_IF;
660     if (!pp->ifMTU) {           /* not local */
661         pp->timeout.sec = 3;
662         pp->ifMTU = MIN(rx_MyMaxSendSize, RX_REMOTE_PACKET_SIZE);
663     }
664 #else /* ADAPT_MTU */
665     pp->rateFlag = 2;           /* start timing after two full packets */
666     pp->timeout.sec = 2;
667     pp->ifMTU = MIN(rx_MyMaxSendSize, OLD_MAX_PACKET_SIZE);
668 #endif /* ADAPT_MTU */
669     pp->ifMTU = rxi_AdjustIfMTU(pp->ifMTU);
670     pp->maxMTU = OLD_MAX_PACKET_SIZE;   /* for compatibility with old guys */
671     pp->natMTU = MIN((int)pp->ifMTU, OLD_MAX_PACKET_SIZE);
672     pp->maxDgramPackets =
673         MIN(rxi_nDgramPackets,
674             rxi_AdjustDgramPackets(RX_MAX_FRAGS, pp->ifMTU));
675     pp->ifDgramPackets =
676         MIN(rxi_nDgramPackets,
677             rxi_AdjustDgramPackets(RX_MAX_FRAGS, pp->ifMTU));
678     pp->maxDgramPackets = 1;
679     /* Initialize slow start parameters */
680     pp->MTU = MIN(pp->natMTU, pp->maxMTU);
681     pp->cwind = 1;
682     pp->nDgramPackets = 1;
683     pp->congestSeq = 0;
684 }
685
686 /* Don't expose jumobgram internals. */
687 void
688 rx_SetNoJumbo(void)
689 {
690     rx_maxReceiveSize = OLD_MAX_PACKET_SIZE;
691     rxi_nSendFrags = rxi_nRecvFrags = 1;
692 }
693
694 /* Override max MTU.  If rx_SetNoJumbo is called, it must be 
695    called before calling rx_SetMaxMTU since SetNoJumbo clobbers rx_maxReceiveSize */
696 void
697 rx_SetMaxMTU(int mtu)
698 {
699     rx_MyMaxSendSize = rx_maxReceiveSizeUser = rx_maxReceiveSize = mtu;
700 }