linux-disable-pmtu-discovery-20041009
[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 afs_uint32 rxi_NetAddrs[ADDRSPERSITE];  /* host order */
265 static int myNetMTUs[ADDRSPERSITE];
266 static int myNetMasks[ADDRSPERSITE];
267 static int myNetFlags[ADDRSPERSITE];
268 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     if (rxi_numNetAddrs > 0)
276         return htonl(rxi_NetAddrs[0]);
277     else
278         return 0;
279 }
280
281 /* 
282 ** return number of addresses 
283 ** and the addresses themselves in the buffer
284 ** maxSize - max number of interfaces to return.
285 */
286 int
287 rx_getAllAddr(afs_int32 * buffer, int maxSize)
288 {
289     int count = 0;
290     for (count = 0; count < rxi_numNetAddrs && maxSize > 0;
291          count++, maxSize--)
292         buffer[count] = htonl(rxi_NetAddrs[count]);
293
294     return count;
295 }
296
297 #endif
298
299 #ifdef AFS_NT40_ENV
300
301 void
302 rx_GetIFInfo(void)
303 {
304     LOCK_IF_INIT;
305     if (Inited) {
306         UNLOCK_IF_INIT;
307         return;
308     } else {
309         u_int maxsize;
310         u_int rxsize;
311         int npackets, ncbufs;
312         afs_uint32 i;
313
314         Inited = 1;
315         UNLOCK_IF_INIT;
316         rxi_numNetAddrs = ADDRSPERSITE;
317
318         LOCK_IF;
319         (void)syscfg_GetIFInfo(&rxi_numNetAddrs, rxi_NetAddrs,
320                                myNetMasks, myNetMTUs, myNetFlags);
321
322         for (i = 0; i < rxi_numNetAddrs; i++) {
323             rxsize = rxi_AdjustIfMTU(myNetMTUs[i] - RX_IPUDP_SIZE);
324             maxsize =
325                 rxi_nRecvFrags * rxsize + (rxi_nRecvFrags - 1) * UDP_HDR_SIZE;
326             maxsize = rxi_AdjustMaxMTU(rxsize, maxsize);
327             if (rx_maxReceiveSize < maxsize) {
328                 rx_maxReceiveSize = MIN(RX_MAX_PACKET_SIZE, maxsize);
329                 rx_maxReceiveSize =
330                     MIN(rx_maxReceiveSize, rx_maxReceiveSizeUser);
331             }
332
333         }
334         UNLOCK_IF;
335         ncbufs = (rx_maxJumboRecvSize - RX_FIRSTBUFFERSIZE);
336         if (ncbufs > 0) {
337             ncbufs = ncbufs / RX_CBUFFERSIZE;
338             npackets = rx_initSendWindow - 1;
339             rxi_MorePackets(npackets * (ncbufs + 1));
340         }
341     }
342 }
343
344 #endif
345
346 static afs_uint32
347 fudge_netmask(afs_uint32 addr)
348 {
349     afs_uint32 msk;
350
351     if (IN_CLASSA(addr))
352         msk = IN_CLASSA_NET;
353     else if (IN_CLASSB(addr))
354         msk = IN_CLASSB_NET;
355     else if (IN_CLASSC(addr))
356         msk = IN_CLASSC_NET;
357     else
358         msk = 0;
359
360     return msk;
361 }
362
363
364
365 #if !defined(AFS_AIX_ENV) && !defined(AFS_NT40_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_DJGPP_ENV)
366 int
367 rxi_syscall(a3, a4, a5)
368      afs_uint32 a3, a4;
369      void *a5;
370 {
371     afs_uint32 rcode;
372     void (*old) ();
373
374     old = (void (*)())signal(SIGSYS, SIG_IGN);
375
376 #if defined(AFS_SGI_ENV)
377     rcode = afs_syscall(a3, a4, a5);
378 #else
379     rcode = syscall(AFS_SYSCALL, 28 /* AFSCALL_CALL */ , a3, a4, a5);
380 #endif /* AFS_SGI_ENV */
381
382     signal(SIGSYS, old);
383
384     return rcode;
385 }
386 #endif /* AFS_AIX_ENV */
387
388 #ifndef AFS_NT40_ENV
389 void
390 rx_GetIFInfo(void)
391 {
392     int s;
393     int i, j, len, res;
394 #ifndef AFS_DJGPP_ENV
395     struct ifconf ifc;
396     struct ifreq ifs[ADDRSPERSITE];
397     struct ifreq *ifr;
398 #ifdef  AFS_AIX41_ENV
399     char buf[BUFSIZ], *cp, *cplim;
400 #endif
401     struct sockaddr_in *a;
402 #endif /* AFS_DJGPP_ENV */
403
404     LOCK_IF_INIT;
405     if (Inited) {
406         UNLOCK_IF_INIT;
407         return;
408     }
409     Inited = 1;
410     UNLOCK_IF_INIT;
411     LOCK_IF;
412     rxi_numNetAddrs = 0;
413     memset(rxi_NetAddrs, 0, sizeof(rxi_NetAddrs));
414     memset(myNetFlags, 0, sizeof(myNetFlags));
415     memset(myNetMTUs, 0, sizeof(myNetMTUs));
416     memset(myNetMasks, 0, sizeof(myNetMasks));
417     UNLOCK_IF;
418     s = socket(AF_INET, SOCK_DGRAM, 0);
419     if (s < 0)
420         return;
421
422 #ifndef AFS_DJGPP_ENV
423 #ifdef  AFS_AIX41_ENV
424     ifc.ifc_len = sizeof(buf);
425     ifc.ifc_buf = buf;
426     ifr = ifc.ifc_req;
427 #else
428     ifc.ifc_len = sizeof(ifs);
429     ifc.ifc_buf = (caddr_t) & ifs[0];
430     memset(&ifs[0], 0, sizeof(ifs));
431 #endif
432     res = ioctl(s, SIOCGIFCONF, &ifc);
433     if (res < 0) {
434         /* fputs(stderr, "ioctl error IFCONF\n"); */
435         close(s);
436         return;
437     }
438
439     LOCK_IF;
440 #ifdef  AFS_AIX41_ENV
441 #define size(p) MAX((p).sa_len, sizeof(p))
442     cplim = buf + ifc.ifc_len;  /*skip over if's with big ifr_addr's */
443     for (cp = buf; cp < cplim;
444          cp += sizeof(ifr->ifr_name) + MAX(a->sin_len, sizeof(*a))) {
445         if (rxi_numNetAddrs >= ADDRSPERSITE)
446             break;
447
448         ifr = (struct ifreq *)cp;
449 #else
450     len = ifc.ifc_len / sizeof(struct ifreq);
451     if (len > ADDRSPERSITE)
452         len = ADDRSPERSITE;
453
454     for (i = 0; i < len; ++i) {
455         ifr = &ifs[i];
456         res = ioctl(s, SIOCGIFADDR, ifr);
457 #endif
458         if (res < 0) {
459             /* fputs(stderr, "ioctl error IFADDR\n");
460              * perror(ifr->ifr_name);   */
461             continue;
462         }
463         a = (struct sockaddr_in *)&ifr->ifr_addr;
464         if (a->sin_family != AF_INET)
465             continue;
466         rxi_NetAddrs[rxi_numNetAddrs] = ntohl(a->sin_addr.s_addr);
467         if (rxi_NetAddrs[rxi_numNetAddrs] == 0x7f000001) {
468             /* we don't really care about "localhost" */
469             continue;
470         }
471         for (j = 0; j < rxi_numNetAddrs; j++) {
472             if (rxi_NetAddrs[j] == rxi_NetAddrs[rxi_numNetAddrs])
473                 break;
474         }
475         if (j < rxi_numNetAddrs)
476             continue;
477
478         /* fprintf(stderr, "if %s addr=%x\n", ifr->ifr_name,
479          * rxi_NetAddrs[rxi_numNetAddrs]); */
480
481 #ifdef SIOCGIFFLAGS
482         res = ioctl(s, SIOCGIFFLAGS, ifr);
483         if (res == 0) {
484             myNetFlags[rxi_numNetAddrs] = ifr->ifr_flags;
485 #ifdef IFF_LOOPBACK
486             /* Handle aliased loopbacks as well. */
487             if (ifr->ifr_flags & IFF_LOOPBACK)
488                 continue;
489 #endif
490             /* fprintf(stderr, "if %s flags=%x\n", 
491              * ifr->ifr_name, ifr->ifr_flags); */
492         } else {                /*
493                                  * fputs(stderr, "ioctl error IFFLAGS\n");
494                                  * perror(ifr->ifr_name); */
495         }
496 #endif /* SIOCGIFFLAGS */
497
498 #if !defined(AFS_AIX_ENV)  && !defined(AFS_LINUX20_ENV)
499         /* this won't run on an AIX system w/o a cache manager */
500         rxi_syscallp = rxi_syscall;
501 #endif
502
503         /* If I refer to kernel extensions that aren't loaded on AIX, the 
504          * program refuses to load and run, so I simply can't include the 
505          * following code.  Fortunately, AIX is the one operating system in
506          * which the subsequent ioctl works reliably. */
507         if (rxi_syscallp) {
508             if ((*rxi_syscallp) (20 /*AFSOP_GETMTU */ ,
509                                  htonl(rxi_NetAddrs[rxi_numNetAddrs]),
510                                  &(myNetMTUs[rxi_numNetAddrs]))) {
511                 /* fputs(stderr, "syscall error GETMTU\n");
512                  * perror(ifr->ifr_name); */
513                 myNetMTUs[rxi_numNetAddrs] = 0;
514             }
515             if ((*rxi_syscallp) (42 /*AFSOP_GETMASK */ ,
516                                  htonl(rxi_NetAddrs[rxi_numNetAddrs]),
517                                  &(myNetMasks[rxi_numNetAddrs]))) {
518                 /* fputs(stderr, "syscall error GETMASK\n");
519                  * perror(ifr->ifr_name); */
520                 myNetMasks[rxi_numNetAddrs] = 0;
521             } else
522                 myNetMasks[rxi_numNetAddrs] =
523                     ntohl(myNetMasks[rxi_numNetAddrs]);
524             /* fprintf(stderr, "if %s mask=0x%x\n", 
525              * ifr->ifr_name, myNetMasks[rxi_numNetAddrs]); */
526         }
527
528         if (myNetMTUs[rxi_numNetAddrs] == 0) {
529             myNetMTUs[rxi_numNetAddrs] = OLD_MAX_PACKET_SIZE + RX_IPUDP_SIZE;
530 #ifdef SIOCGIFMTU
531             res = ioctl(s, SIOCGIFMTU, ifr);
532             if ((res == 0) && (ifr->ifr_metric > 128)) {        /* sanity check */
533                 myNetMTUs[rxi_numNetAddrs] = ifr->ifr_metric;
534                 /* fprintf(stderr, "if %s mtu=%d\n", 
535                  * ifr->ifr_name, ifr->ifr_metric); */
536             } else {
537                 /* fputs(stderr, "ioctl error IFMTU\n");
538                  * perror(ifr->ifr_name); */
539             }
540 #endif
541         }
542
543         if (myNetMasks[rxi_numNetAddrs] == 0) {
544             myNetMasks[rxi_numNetAddrs] =
545                 fudge_netmask(rxi_NetAddrs[rxi_numNetAddrs]);
546 #ifdef SIOCGIFNETMASK
547             res = ioctl(s, SIOCGIFNETMASK, ifr);
548             if ((res == 0)) {
549                 a = (struct sockaddr_in *)&ifr->ifr_addr;
550                 myNetMasks[rxi_numNetAddrs] = ntohl(a->sin_addr.s_addr);
551                 /* fprintf(stderr, "if %s subnetmask=0x%x\n", 
552                  * ifr->ifr_name, myNetMasks[rxi_numNetAddrs]); */
553             } else {
554                 /* fputs(stderr, "ioctl error IFMASK\n");
555                  * perror(ifr->ifr_name); */
556             }
557 #endif
558         }
559
560         if (rxi_NetAddrs[rxi_numNetAddrs] != 0x7f000001) {      /* ignore lo0 */
561             int maxsize;
562             maxsize =
563                 rxi_nRecvFrags * (myNetMTUs[rxi_numNetAddrs] - RX_IP_SIZE);
564             maxsize -= UDP_HDR_SIZE;    /* only the first frag has a UDP hdr */
565             if (rx_maxReceiveSize < maxsize)
566                 rx_maxReceiveSize = MIN(RX_MAX_PACKET_SIZE, maxsize);
567             ++rxi_numNetAddrs;
568         }
569     }
570     UNLOCK_IF;
571     close(s);
572
573     /* have to allocate at least enough to allow a single packet to reach its
574      * maximum size, so ReadPacket will work.  Allocate enough for a couple
575      * of packets to do so, for good measure */
576     {
577         int npackets, ncbufs;
578
579         rx_maxJumboRecvSize =
580             RX_HEADER_SIZE + rxi_nDgramPackets * RX_JUMBOBUFFERSIZE +
581             (rxi_nDgramPackets - 1) * RX_JUMBOHEADERSIZE;
582         rx_maxJumboRecvSize = MAX(rx_maxJumboRecvSize, rx_maxReceiveSize);
583         ncbufs = (rx_maxJumboRecvSize - RX_FIRSTBUFFERSIZE);
584         if (ncbufs > 0) {
585             ncbufs = ncbufs / RX_CBUFFERSIZE;
586             npackets = rx_initSendWindow - 1;
587             rxi_MorePackets(npackets * (ncbufs + 1));
588         }
589     }
590 #else /* AFS_DJGPP_ENV */
591     close(s);
592     return;
593 #endif /* AFS_DJGPP_ENV */
594 }
595 #endif /* AFS_NT40_ENV */
596
597 /* Called from rxi_FindPeer, when initializing a clear rx_peer structure,
598  * to get interesting information.
599  * Curiously enough, the rx_peerHashTable_lock currently protects the
600  * Inited variable (and hence rx_GetIFInfo). When the fs suite uses
601  * pthreads, this issue will need to be revisited.
602  */
603
604 void
605 rxi_InitPeerParams(struct rx_peer *pp)
606 {
607     afs_uint32 ppaddr;
608     u_short rxmtu;
609     int ix;
610
611
612
613     LOCK_IF_INIT;
614     if (!Inited) {
615         UNLOCK_IF_INIT;
616         /*
617          * there's a race here since more than one thread could call
618          * rx_GetIFInfo.  The race stops in rx_GetIFInfo.
619          */
620         rx_GetIFInfo();
621     } else {
622         UNLOCK_IF_INIT;
623     }
624
625 #ifdef ADAPT_MTU
626     /* try to second-guess IP, and identify which link is most likely to
627      * be used for traffic to/from this host. */
628     ppaddr = ntohl(pp->host);
629
630     pp->ifMTU = 0;
631     pp->timeout.sec = 2;
632     pp->rateFlag = 2;           /* start timing after two full packets */
633     /* I don't initialize these, because I presume they are bzero'd... 
634      * pp->burstSize pp->burst pp->burstWait.sec pp->burstWait.usec
635      * pp->timeout.usec */
636
637     LOCK_IF;
638     for (ix = 0; ix < rxi_numNetAddrs; ++ix) {
639         if ((rxi_NetAddrs[ix] & myNetMasks[ix]) == (ppaddr & myNetMasks[ix])) {
640 #ifdef IFF_POINTOPOINT
641             if (myNetFlags[ix] & IFF_POINTOPOINT)
642                 pp->timeout.sec = 4;
643 #endif /* IFF_POINTOPOINT */
644             rxmtu = myNetMTUs[ix] - RX_IPUDP_SIZE;
645             if (rxmtu < RX_MIN_PACKET_SIZE)
646                 rxmtu = RX_MIN_PACKET_SIZE;
647             if (pp->ifMTU < rxmtu)
648                 pp->ifMTU = MIN(rx_MyMaxSendSize, rxmtu);
649         }
650     }
651     UNLOCK_IF;
652     if (!pp->ifMTU) {           /* not local */
653         pp->timeout.sec = 3;
654         pp->ifMTU = MIN(rx_MyMaxSendSize, RX_REMOTE_PACKET_SIZE);
655     }
656 #else /* ADAPT_MTU */
657     pp->rateFlag = 2;           /* start timing after two full packets */
658     pp->timeout.sec = 2;
659     pp->ifMTU = MIN(rx_MyMaxSendSize, OLD_MAX_PACKET_SIZE);
660 #endif /* ADAPT_MTU */
661     pp->ifMTU = rxi_AdjustIfMTU(pp->ifMTU);
662     pp->maxMTU = OLD_MAX_PACKET_SIZE;   /* for compatibility with old guys */
663     pp->natMTU = MIN((int)pp->ifMTU, OLD_MAX_PACKET_SIZE);
664     pp->maxDgramPackets =
665         MIN(rxi_nDgramPackets,
666             rxi_AdjustDgramPackets(RX_MAX_FRAGS, pp->ifMTU));
667     pp->ifDgramPackets =
668         MIN(rxi_nDgramPackets,
669             rxi_AdjustDgramPackets(RX_MAX_FRAGS, pp->ifMTU));
670     pp->maxDgramPackets = 1;
671     /* Initialize slow start parameters */
672     pp->MTU = MIN(pp->natMTU, pp->maxMTU);
673     pp->cwind = 1;
674     pp->nDgramPackets = 1;
675     pp->congestSeq = 0;
676 }
677
678 /* Don't expose jumobgram internals. */
679 void
680 rx_SetNoJumbo(void)
681 {
682     rx_maxReceiveSize = OLD_MAX_PACKET_SIZE;
683     rxi_nSendFrags = rxi_nRecvFrags = 1;
684 }
685
686 /* Override max MTU.  If rx_SetNoJumbo is called, it must be 
687    called before calling rx_SetMaxMTU since SetNoJumbo clobbers rx_maxReceiveSize */
688 void
689 rx_SetMaxMTU(int mtu)
690 {
691     rx_MyMaxSendSize = rx_maxReceiveSizeUser = rx_maxReceiveSize = mtu;
692 }