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