Ejemplo n.º 1
0
/*------------------------------------------------------------------------
 *  tfinsert - add a new TCP segment fragment to a TCB sequence queue
 *------------------------------------------------------------------------
 */
int
tfinsert(struct tcb *ptcb, tcpseq seq, unsigned datalen)
{
	struct	tcpfrag	*tf;

	if (datalen == 0)
		return OK;
	tf = (struct tcpfrag *)getmem(sizeof(struct tcpfrag));
	tf->tf_seq = seq;
	tf->tf_len = datalen;
	if (ptcb->tcb_rsegq < 0)
		ptcb->tcb_rsegq = newq(NTCPFRAG, QF_WAIT);
	if (enq(ptcb->tcb_rsegq, tf, -tf->tf_seq) < 0)
		freemem(tf, sizeof(struct tcpfrag));
	return OK;
}
Ejemplo n.º 2
0
//**************************************************************************
//
//==========================================================================
void ArcBallCam::spin(float x, float y, float z)
//==========================================================================
{
	// printf("\nstart was %g %g %g %g\n",start.x,start.y,start.z,start.w);
	// first, get rid of anything cached
	start = now * start;
	now = Quat();

	float iw = x*x + y*y + z*z;
	if (iw<1)
		iw = sqrt(1-iw);
	else
		iw = 0;
	Quat newq(x,y,z,iw);

	newq.renorm();
	start = newq * start;
	// printf(" (no norm) %g %g %g %g\n",start.x,start.y,start.z,start.w);
	start.renorm();
	// printf("start is %g %g %g %g\n",start.x,start.y,start.z,start.w);
}
Ejemplo n.º 3
0
/*------------------------------------------------------------------------
 *  ipreass  -  reassemble an IP datagram, if necessary
 *	returns packet, if complete; 0 otherwise
 *------------------------------------------------------------------------
 */
struct ep *
ipreass(struct ep *pep)
{
	struct	ep	*pep2;
	struct	ip	*pip;
	int		firstfree;
	int		i;

	pip = (struct ip *)pep->ep_data;

	wait(ipfmutex);

	if ((pip->ip_fragoff & (IP_FRAGOFF|IP_MF)) == 0) {
		signal(ipfmutex);
		return pep;
	}
	IpReasmReqds++;
	firstfree = -1;
	for (i=0; i<IP_FQSIZE; ++i) {
		struct	ipfq	*piq = &ipfqt[i];

		if (piq->ipf_state == IPFF_FREE) {
			if (firstfree == -1)
				firstfree = i;
			continue;
		}
		if (piq->ipf_id != pip->ip_id)
			continue;
		if (piq->ipf_src != pip->ip_src)
			continue;
		/* found a match */
		if (ipfadd(piq, pep) == 0) {
			signal(ipfmutex);
			return 0;
		}
		pep2 = ipfjoin(piq);
		signal(ipfmutex);
		return pep2;
		
	}
	/* no match */

	if (firstfree < 0) {
		/* no room-- drop */
		freebuf(pep);
		signal(ipfmutex);
		return 0;
	}
	ipfqt[firstfree].ipf_q = newq(IP_FQSIZE, QF_WAIT);
	if (ipfqt[firstfree].ipf_q < 0) {
		freebuf(pep);
		signal(ipfmutex);
		return 0;
	}
	ipfqt[firstfree].ipf_src = pip->ip_src;
	ipfqt[firstfree].ipf_id = pip->ip_id;
	ipfqt[firstfree].ipf_ttl = IP_FTTL;
	ipfqt[firstfree].ipf_state = IPFF_VALID;
	ipfadd(&ipfqt[firstfree], pep);
	signal(ipfmutex);
	return 0;
}
Ejemplo n.º 4
0
/*------------------------------------------------------------------------
 *  netstart - initialize net
 *------------------------------------------------------------------------
 */
int
netstart(int userpid)
{
	char str[128];
	char *str1 = "sleeping 30 secs to get routes...";
	char *str2 = "\ndone.\n";
	unsigned long	now;
	int		i;

	if (clkruns == FALSE)
		panic("net: no clock");

	/* initialize ports */

	for (i=0 ; i<UPPS ; i++)
		upqs[i].up_valid = FALSE;
	udpmutex = screate(1);

	arpinit();
	ipfinit();	/* init the IP frag queue */

	/* these need a command to set/clear them. FIX ME!!! */
	gateway = 1;
	IpForwarding = 1;	/* == 2 if not a gateway */
	IfNumber = Net.nif - 1;

	/* bsdbrc = 1; */ /* uncomment to use 0's broadcast */

	if (gateway) {
		IPaddr	gw;
		initgate();
		gw = dot2ip(DEFRTR);
		rtadd(RT_DEFAULT, RT_DEFAULT, gw, RTM_INF-1, 1, RT_INF);
	} else
		inithost();
	rtadd(RT_LOOPBACK, ip_maskall, RT_LOOPBACK, 0, NI_LOCAL, RT_INF);

	for (i=0; i<Net.nif; ++i) {
		nif[i].ni_ipinq = newq(NI_INQSZ, QF_NOWAIT);
		nif[i].ni_hwtype = AR_HARDWARE;		/* for ARP */
		/* no OTHER's for now */
		if (i < 2)
			nif[i].ni_state = NIS_UP;
	}

	/*
	 * wait()'s synchronize to insure initialization is done
	 * before proceeding.
	 */

	resume(create(slowtimer, STSTK, STPRI, STNAM, STARGC));
	wait(Net.sema);
	resume(create(ipproc, IPSTK, IPPRI, IPNAM, IPARGC));
	wait(Net.sema);
	resume(create(tcptimer, TMSTK, TMPRI, TMNAM, TMARGC));
	wait(Net.sema);
	resume(create(tcpinp, TCPISTK, TCPIPRI, TCPINAM, TCPIARGC));
	wait(Net.sema);
	resume(create(tcpout, TCPOSTK, TCPOPRI, TCPONAM, TCPOARGC));
	wait(Net.sema);


	if (!gateway) {
		write(CONSOLE, str1, strlen(str1));
		sleep(30);
		write(CONSOLE, str2, strlen(str2));
	}

	/* get addrs & names */
	for (i=0; i<Net.nif; ++i) {
		IPaddr junk;
		char junk2[64];

		if (i == NI_LOCAL)
			continue;
		if (nif[i].ni_state != NIS_UP)
			continue;
		junk = getiaddr(i);
		sprintf(str,
		"if%d IP %s ha %02x:%02x:%02x:%02x:%02x:%02x ",
			i,
			ip2dot(junk2, nif[i].ni_ip),
			nif[i].ni_hwa.ha_addr[0]&0xff,
			nif[i].ni_hwa.ha_addr[1]&0xff,
			nif[i].ni_hwa.ha_addr[2]&0xff,
			nif[i].ni_hwa.ha_addr[3]&0xff,
			nif[i].ni_hwa.ha_addr[4]&0xff,
			nif[i].ni_hwa.ha_addr[5]&0xff);
		write(CONSOLE, str, strlen(str));
		sprintf(str, "br %02x:%02x:%02x:%02x:%02x:%02x\n",
			nif[i].ni_hwb.ha_addr[0]&0xff,
			nif[i].ni_hwb.ha_addr[1]&0xff,
			nif[i].ni_hwb.ha_addr[2]&0xff,
			nif[i].ni_hwb.ha_addr[3]&0xff,
			nif[i].ni_hwb.ha_addr[4]&0xff,
			nif[i].ni_hwb.ha_addr[5]&0xff);
		write(CONSOLE, str, strlen(str));

		icmp(ICT_MASKRQ, 0, nif[i].ni_brc, 0, 0);
		recvtim(30);	/* wait for an answer */
		getiname(i, junk2);
	}
	getutim(&now);

#ifdef	MULTICAST
	hginit();
#endif	/* MULTICAST */
#ifdef RIP
	resume(create(rip, RIPISTK, RIPPRI, RIPNAM, RIPARGC));
#endif	/* RIP */
#ifdef	OSPF
	resume(create(ospf, OSPFSTK, OSPFPRI, OSPFNAM, 0));
#endif /* OSPF */
#ifdef	SNMP
	resume(create(snmpd, SNMPSTK, SNMPPRI, SNMPDNAM, 0));
#endif	/* SNMP */

	rwho();
	resume(create(FINGERD, FNGDSTK, FNGDPRI, FNGDNAM, FNGDARGC));
	resume(create(ECHOD, ECHOSTK, ECHOPRI, ECHODNAM, 0));
	resume(create(udpecho, 1000, 50, "udpecho", 0));

	resume(userpid);
}