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