/* * PROTINIT.C * * Packet template initialization routines * **************************************************************************** * * * part of: * * TCP/UDP/ICMP/IP Network kernel for NCSA Telnet * * by Tim Krauskopf * * * * National Center for Supercomputing Applications * * 152 Computing Applications Building * * 605 E. Springfield Ave. * * Champaign, IL 61820 * * * * This program is in the public domain. * * * **************************************************************************** * 'protinit' initializes packets to make them ready for transmission. * For many purposes, pre-initialized packets are created for use by the * protocol routines, especially to save time creating packets for * transmit. * * Important note : Assumes that the hardware has been initialized and has * set all the useful addresses such as the hardware addresses. * * As this is a convenient place for it, this file contains many of the * data declarations for packets which are mostly static (pre-allocated). * Revision history: **************************************************************************** * * 10/87 Initial source release, Tim Krauskopf * 5/88 clean up for 2.3 release, JKM * */ /* * Includes */ #include #include #if defined(MSC) #ifdef __TURBOC__ #include #else #include #endif #endif #include "protocol.h" #include "data.h" #include "externs.h" #include "defines.h" static void setupwindow(struct window *,unsigned int ); /************************************************************************/ /* * protinit () * * Calls all the other packet initialization keep this order as some packet * inits require lower layers already be initialized. * */ void protinit(void) { etherinit(); /* dlayer packets */ arpinit(); /* ARP packets */ ipinit(); /* ip packets */ tcpinit(); /* tcp packets */ udpinit(); /* udp packets */ } /*************************************************************************/ /* * neteventinit () * * Setup all the pointers for the event queue -- makes a circular list which * is required for error messages. ( called from Snetinit () ) * */ void neteventinit (void) { int i; for(i=0; istale=1; udplist[DNRINDEX]->length=0; movebytes(&udplist[DNRINDEX]->udpout,&blankip,sizeof(DLAYER)+sizeof(IPLAYER)); udplist[DNRINDEX]->udpout.i.protocol=PROTUDP; UDP type udplist[DNRINDEX]->tcps.z=0; udplist[DNRINDEX]->tcps.proto=PROTUDP; movebytes(udplist[DNRINDEX]->tcps.source,nnipnum,4); #endif } /**************************************************************************/ /* * tcpinit () * * setup for makeport () * */ void tcpinit(void) { int i; for(i=0; istate==SCLOSED || (q->state==STWAIT && q->out.lasttime+WAITTIMEvs,"Recycled old port.\r\n"); else tprintf(console->vs,"Allocated new port.\r\n"); #endif #endif /* DEBUG */ /* * None available pre-allocated, get a new one, about 8.5 K with a 4K windowsize */ if(p==NULL) { if((p=(struct port *)malloc(sizeof(struct port)))==NULL) { #ifdef TELBIN tprintf(console->vs,"memory allocation error.\r\n"); #endif nnerror(500); return(-1); /* out of room for ports */ } /* end if */ for(i=0; portlist[i]!=NULL; i++) { if(i>=NPORTS) { nnerror(500); return(-1); /* out of room for ports */ } /* end if */ } /* end for */ portlist[i]=p; retval=i; } /* end if */ if(p==NULL) { nnerror(505); return(-1); } movebytes(&p->tcpout,&blankip,sizeof(DLAYER)+sizeof(IPLAYER)); /* static initialization */ p->tcpout.i.tlen=0; p->tcpout.t.urgent=0; /* no urgent data */ p->tcpout.t.hlen=20<<2; /* header length << 2 */ p->tcps.z=0; p->tcps.proto=PROTTCP; movebytes(p->tcps.source,nnipnum,4); setupwindow(&p->in,WINDOWSIZE); /* queuing parameters */ setupwindow(&p->out,WINDOWSIZE); do { /* search for an un-used port */ i=(int)n_clicks(); i|=2048; /* make sure it is at least this large */ i&=0x3fff; /* at least this small */ #ifdef OLD_WAY for(j=0; jin.port; j++); #else for(j=0; jin.port) break; #endif } while(jin.port=i; p->tcpout.t.source=intswap(i); p->tcpout.t.seq=longswap(p->out.nxt); p->state=SCLOSED; p->credit=nncredit; p->sendsize=TSENDSIZE; p->rto=MINRTO; return(retval); } /* * setupwindow ( w, wsize ) * * Configure information about a window *w* * */ static void setupwindow(struct window *w,unsigned int wsize) { w->endbuf=w->where+wsize; w->base=w->endlim=w->where; w->contain=0; /* nothing here yet */ w->lasttime=n_clicks(); w->size=wsize; w->push=0; /* * base this on time of day clock, for uniqueness */ w->ack=w->nxt=((w->lasttime<<12)&0x0fffffff); }