Plan 9 from Bell Labs’s /usr/web/sources/extra/9hist/port/stip.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


## diffname port/stip.c 1991/0424
## diff -e /dev/null /n/bootesdump/1991/0424/sys/src/9/port/stip.c
0a
/*
 *  ethernet specific multiplexor for ip
 *
 *  this line discipline gets pushed onto an ethernet channel
 *  to demultiplex/multiplex ip conversations.
 */
#include	"u.h"
#include	"lib.h"
#include	"mem.h"
#include	"dat.h"
#include	"fns.h"
#include	"io.h"
#include	"errno.h"
#include	"arp.h"
#include 	"ipdat.h"

#define DPRINT if(pip)print
int pip = 0;
int ipcksum = 1;
extern Ipifc *ipifc;
int Id = 1;

Fragq		*flisthead;
Fragq		*fragfree;
QLock		fraglock;

Queue 		*Etherq;

Ipaddr		Myip;
Ipaddr		Mymask;

/* Predeclaration */
static void	ipetherclose(Queue*);
static void	ipetheriput(Queue*, Block*);
static void	ipetheropen(Queue*, Stream*);
static void	ipetheroput(Queue*, Block*);

/*
 *  the ethernet multiplexor stream module definition
 */
Qinfo ipinfo =
{
	ipetheriput,
	ipetheroput,
	ipetheropen,
	ipetherclose,
	"internet"
};

void
initfrag(int size)
{
	Fragq *fq, *eq;

	fragfree = (Fragq*)ialloc(sizeof(Fragq) * size, 0);

	eq = &fragfree[size];
	for(fq = fragfree; fq < eq; fq++)
		fq->next = fq+1;

	fragfree[size-1].next = 0;
}

/*
 *  set up an ether interface
 */
static void
ipetheropen(Queue *q, Stream *s)
{
	/* First open is by ipconfig and sets up channel
	 * to ethernet
	 */
	if(!Etherq)
		Etherq = WR(q);

	DPRINT("ipetheropen EQ %lux dev=%d id=%d RD %lux WR %lux\n",
		Etherq, s->dev, s->id, RD(q), WR(q));
}

/*
 * newipifc - Attach to or Create a new protocol interface
 */

Ipifc *
newipifc(uchar ptcl, void (*recvfun)(Ipconv *, Block *bp),
	 Ipconv *con, int max, int min, int hdrsize, char *name)
{
	Ipifc *ifc, *free;
 
	free = 0;
	for(ifc = ipifc; ifc < &ipifc[conf.ipif]; ifc++) {
		qlock(ifc);
		if(ifc->protocol == ptcl) {
			ifc->ref++;
			qunlock(ifc);
			return(ifc);
		}
		if(!free && ifc->ref == 0) {
			ifc->ref = 1;
			free = ifc;
		}
		else
			qunlock(ifc);
	}

	if(!free)
		error(Enoifc);

	free->iprcv = recvfun;

	/* If media supports large transfer units limit maxmtu
	 * to max ip size */
	if(max > IP_MAX)
		max = IP_MAX;
	free->maxmtu = max;
	free->minmtu = min;
	free->hsize = hdrsize;
	free->connections = con;

	free->protocol = ptcl;
	strncpy(free->name, name, NAMELEN);

	qunlock(free);
	return(free);
}

static void
ipetherclose(Queue *q)
{
	if(q == Etherq) {
		print("stip: Clearing ether channel\n");
		Etherq = 0;
	}

	DPRINT("ipetherclose RD %lux WR %lux\n", RD(q), WR(q));
}

void
closeipifc(Ipifc *ifc)
{
	/* If this is the last reference to the protocol multiplexor
	 * cancel upcalls from this stream
	 */
	qlock(ifc);
	if(--ifc->ref == 0) {
		ifc->protocol = 0;
		ifc->name[0] = 0;
	}
	qunlock(ifc);
}

static void
ipetheroput(Queue *q, Block *bp)
{
	Etherhdr *eh, *feh;
	int	 lid, len, seglen, chunk, dlen, blklen, offset;
	Ipifc	 *ifp;
	ushort	 fragoff;
	Block	 *xp, *nb;
	uchar 	 *ptr;

	if(bp->type != M_DATA){
		/* Allow one setting of the ip address */
		if(!Myip && streamparse("setip", bp)) {
			ptr = bp->rptr;
			Myip = ipparse((char *)ptr);
			Mymask = classmask[Myip>>30];
			while(*ptr != ' ' && *ptr)
				ptr++;
			if(*ptr)
				Mymask = ipparse((char *)ptr);
			freeb(bp);
		}
		else
			PUTNEXT(Etherq, bp);
		return;
	}

	ifp = (Ipifc *)(q->ptr);

	/* Number of bytes in ip and media header to write */
	len = blen(bp);

	/* Fill out the ip header */
	eh = (Etherhdr *)(bp->rptr);
	eh->vihl = IP_VER|IP_HLEN;
	eh->tos = 0;
	eh->ttl = 255;

	/* If we dont need to fragment just send it */
	if(len <= ifp->maxmtu) {
		hnputs(eh->length, len-ETHER_HDR);
		eh->frag[0] = 0;
		eh->frag[1] = 0;
		eh->cksum[0] = 0;
		eh->cksum[1] = 0;
		hnputs(eh->cksum, ip_csum(&eh->vihl));

		/* Finally put in the ethernet level information */
		hnputs(eh->type, ET_IP);
		if(!arp_lookup(eh->dst, eh->d)) {
			freeb(bp);
			return;
		}

		PUTNEXT(Etherq, bp);
		return;
	}

	if(eh->frag[0] & (IP_DF>>8))
		goto drop;

	seglen = (ifp->minmtu - (ETHER_HDR+ETHER_IPHDR)) & ~7;
	if(seglen < 8)
		goto drop;

	/* Make prototype output header */
	hnputs(eh->type, ET_IP);
	if(!arp_lookup(eh->dst, eh->d)) {
		freeb(bp);
		return;
	}
	
	dlen = len - (ETHER_HDR+ETHER_IPHDR);
	xp = bp;
	lid = Id++;

	offset = ETHER_HDR+ETHER_IPHDR;
	while(xp && offset && offset >= BLEN(xp)) {
		offset -= BLEN(xp);
		xp = xp->next;
	}
	xp->rptr += offset;

	for(fragoff = 0; fragoff < dlen; fragoff += seglen) {
		nb = allocb(ETHER_HDR+ETHER_IPHDR+seglen);
		feh = (Etherhdr *)(nb->rptr);

		memmove(nb->wptr, eh, ETHER_HDR+ETHER_IPHDR);
		nb->wptr += ETHER_HDR+ETHER_IPHDR;

		if((fragoff + seglen) >= dlen) {
			seglen = dlen - fragoff;
			hnputs(feh->frag, fragoff>>3);
		}
		else {	
			hnputs(feh->frag, (fragoff>>3)|IP_MF);
		}

		hnputs(feh->length, seglen + ETHER_IPHDR);
		hnputs(feh->id, lid);

		/* Copy up the data area */
		chunk = seglen;
		while(chunk) {
			if(!xp) {
				freeb(nb);
				goto drop;
			}
			blklen = MIN(BLEN(xp), chunk);
			memmove(nb->wptr, xp->rptr, blklen);
			nb->wptr += blklen;
			xp->rptr += blklen;
			chunk -= blklen;
			if(xp->rptr == xp->wptr)
				xp = xp->next;
		} 
				
		feh->cksum[0] = 0;
		feh->cksum[1] = 0;
		hnputs(feh->cksum, ip_csum(&feh->vihl));

		nb->flags |= S_DELIM;
		PUTNEXT(Etherq, nb);
	}

drop:
	freeb(bp);	
}


/*
 *  Input a packet and use the ip protocol to select the correct
 *  device to pass it to.
 *
 */
static void
ipetheriput(Queue *q, Block *bp)
{
	Ipifc 	 *ep, *ifp;
	Etherhdr *h;
	ushort   frag;

	if(bp->type != M_DATA){
		PUTNEXT(q, bp);
		return;
	}

	h = (Etherhdr *)(bp->rptr);

	/* Ensure we have enough data to process */
	if(BLEN(bp) < (ETHER_HDR+ETHER_IPHDR)) {
		bp = pullup(bp, ETHER_HDR+ETHER_IPHDR);
		if(!bp)
			return;
	}

	if(ipcksum && ip_csum(&h->vihl)) {
		print("ip: checksum error (from %d.%d.%d.%d ?)\n",
		      h->src[0], h->src[1], h->src[2], h->src[3]);
		goto drop;
	}

	/* Check header length and version */
	if(h->vihl != (IP_VER|IP_HLEN))
		goto drop;

	frag = nhgets(h->frag);
	if(frag) {
		h->tos = frag & IP_MF ? 1 : 0;
		bp = ip_reassemble(frag, bp, h);
		if(!bp)
			return;
	}

	/*
 	 * Look for an ip interface attached to this protocol
	 */
	ep = &ipifc[conf.ipif];
	for(ifp = ipifc; ifp < ep; ifp++) {
		if(ifp->protocol == h->proto) {
			(*ifp->iprcv)(ifp->connections, bp);
			return;
		}
	}
			
drop:
	freeb(bp);
}

Block *
ip_reassemble(int offset, Block *bp, Etherhdr *ip)
{
	Fragq *f;
	Ipaddr src, dst;
	ushort id;
	Block *bl, **l, *last, *prev;
	int ovlap, len, fragsize;

	src = nhgetl(ip->src);
	dst = nhgetl(ip->dst);
	id = nhgets(ip->id);

	for(f = flisthead; f; f = f->next) {
		if(f->src == src && f->dst == dst && f->id == id)
			break;
	}

	if(!ip->tos && (offset & ~(IP_MF|IP_DF)) == 0) {
		if(f) {
			qlock(f);
			ipfragfree(f);
		}
		return(bp);
	}

	BLKFRAG(bp)->foff = offset<<3;
	BLKFRAG(bp)->flen = nhgets(ip->length) - ETHER_IPHDR; /* Ip data length */
	bp->flags &= ~S_DELIM;

	/* First fragment allocates a reassembly queue */
	if(f == 0) {
		f = ipfragallo();
		if(f == 0) {
			freeb(bp);
			return 0;
		}
		qlock(f);
		f->id = id;
		f->src = src;
		f->dst = dst;

		f->blist = bp;
		/* Check lance has handed us a contiguous buffer */
		if(bp->next)
			panic("ip: reass ?");

		qunlock(f);
		return 0;
	}
	qlock(f);

	prev = 0;
	l = &f->blist;
	for(bl = f->blist; bl && BLKFRAG(bp)->foff > BLKFRAG(bl)->foff; bl = bl->next) {
		prev = bl;
		l = &bl->next;
	}

	/* Check overlap of a previous fragment - trim away as necessary */
	if(prev) {
		ovlap = BLKFRAG(prev)->foff + BLKFRAG(prev)->flen - BLKFRAG(bp)->foff;
		if(ovlap > 0) {
			if(ovlap > BLKFRAG(bp)->flen) {
				freeb(bp);
				qunlock(f);
				return 0;
			}
			BLKFRAG(bp)->flen -= ovlap;
		}
	}

	/* Link onto assembly queue */
	bp->next = *l;
	*l = bp;

	/* Check to see if suceeding segments overlap */
	if(bp->next) {
		l = &bp->next;
		end = BLKFRAG(bp)->foff + BLKFRAG(bp)->flen;
		/* Take completely covered segements out */
		while(*l && (ovlap = (end - BLKFRAG(*l)->foff)) > 0) {
			if(ovlap < BLKFRAG(*l)->flen) {
				BLKFRAG(*l)->flen -= ovlap;
				(*l)->rptr += ovlap;
				break;
			}	
			last = *l;
			freeb(*l);
			*l = last;
		}
	}

	/* Now look for a completed queue */
	for(bl = f->blist; bl; bl = bl->next) {
		if((BLKIP(bl)->frag[0]&(IP_MF>>8)) == 0)
			goto complete;
		if(bl->next == 0 ||
		   BLKFRAG(bl)->foff+BLKFRAG(bl)->flen != BLKFRAG(bl->next)->foff)
			break;
	}
	qunlock(f);
	return 0;
	
complete:
	bl = f->blist;
	last = bl;
	len = nhgets(BLKIP(bl)->length);
	bl->wptr = bl->rptr + len + ETHER_HDR;

	/* Pullup all the fragment headers and return a complete packet */
	for(bl = bl->next; bl; bl = bl->next) {
		fragsize = BLKFRAG(bl)->flen;
		len += fragsize;
		bl->rptr += (ETHER_HDR+ETHER_IPHDR);
		bl->wptr = bl->rptr + fragsize;
		last = bl;
	}

	last->flags |= S_DELIM;
	bl = f->blist;
	f->blist = 0;
	ipfragfree(f);

	ip = BLKIP(bl);
	hnputs(ip->length, len);

	return(bl);		
}

/*
 * ipfragfree - Free a list of fragments, fragment list must be locked
 */

void
ipfragfree(Fragq *frag)
{
	Block *f, *next;
	Fragq *fl, **l;

	for(f = frag->blist; f; f = next) {
		next = f->next;
		freeb(f);
	}

	frag->src = 0;
	frag->id = 0;
	qunlock(frag);

	qlock(&fraglock);

	l = &flisthead;
	for(fl = *l; fl; fl = fl->next) {
		if(fl == frag) {
			*l = frag->next;
			break;
		}
		l = &fl->next;
	}

	frag->next = fragfree;
	fragfree = frag;

	qunlock(&fraglock);


}

/*
 * ipfragallo - allocate a reassembly queue
 */
Fragq *
ipfragallo(void)
{
	Fragq *f;

	qlock(&fraglock);
	if(!fragfree) {
		qunlock(&fraglock);
		print("ipfragallo: no queue\n");
		return 0;
	}
	f = fragfree;
	fragfree = f->next;
	f->next = flisthead;
	flisthead = f;

	qunlock(&fraglock);
	return f;

}

/*
 * ip_csum - Compute internet header checksums
 */
ushort
ip_csum(uchar *addr)
{
	int len;
	ulong sum = 0;

	len = (addr[0]&0xf)<<2;

	while(len > 0) {
		sum += addr[0]<<8 | addr[1] ;
		len -= 2;
		addr += 2;
	}

	sum = (sum & 0xffff) + (sum >> 16);
	sum = (sum & 0xffff) + (sum >> 16);

	return (sum^0xffff);
}

/*
 * ipparse - Parse an ip address out of a string
 */

Ipaddr classmask[4] = {
	0xff000000,
	0xff000000,
	0xffff0000,
	0xffffff00
};

Ipaddr
ipparse(char *ipa)
{
	Ipaddr address = 0;
	int shift;
	Ipaddr net;

	shift = 24;

	while(shift >= 0 && ipa != (char *)1) {
		address |= atoi(ipa) << shift;
		shift -= 8;
		ipa = strchr(ipa, '.')+1;
	}
	net = address & classmask[address>>30];

	shift += 8;
	return net | ((address & ~classmask[address>>30])>>shift);
}

/* 
 * XXX debugging code !
 */
void
ppkt(Block *bp)
{
	uchar *x;
	int len, cnt = 0;
	Block *xp;
	uchar ch;

	if(bp)
		print("ppkt: %lux len %d\n", bp, blen(bp));
	else
		print("ppkt: Null packet pointer\n");

	xp = bp;
	while(bp) {
		len = BLEN(bp);
		x = bp->rptr;
		while(len--) {
			if(cnt%64 == 0)
				print("\n%.04d: ", cnt);
			print("%.02x ", *x++);
			cnt++;
		}
		bp = bp->next;
	}
	bp = xp;
	cnt = 0;
	while(bp) {
		len = BLEN(bp);
		x = bp->rptr;
		while(len--) {
			if(cnt%64 == 0)
				print("\n%.04d: ", cnt);
			ch = *x++;
			print("%c  ", ch < ' ' || ch >= 0x7f ? '.' : ch);
			cnt++;
		}
		bp = bp->next;
	}
	print("\n");

}
.
## diffname port/stip.c 1991/0430
## diff -e /n/bootesdump/1991/0424/sys/src/9/port/stip.c /n/bootesdump/1991/0430/sys/src/9/port/stip.c
130,135d
74a
		s->opens++;		/* Hold this queue in place */
	}
.
73c
	if(!Etherq) {
.
## diffname port/stip.c 1991/0504
## diff -e /n/bootesdump/1991/0430/sys/src/9/port/stip.c /n/bootesdump/1991/0504/sys/src/9/port/stip.c
75a
		s->inuse++;
.
## diffname port/stip.c 1991/0906
## diff -e /n/bootesdump/1991/0504/sys/src/9/port/stip.c /n/bootesdump/1991/0906/sys/src/9/port/stip.c
582,627d
304a
	/* Look to see if its for me before we waste time checksuming it */
	if(memcmp(h->dst, Netmyip, sizeof(Netmyip)) != 0)
		goto drop;

.
163a
			Netmyip[0] = (Myip>>24)&0xff;
			Netmyip[1] = (Myip>>16)&0xff;
			Netmyip[2] = (Myip>>8)&0xff;
			Netmyip[3] = Myip&0xff;
.
30a
uchar		Netmyip[4];	/* In Network byte order */
.
## diffname port/stip.c 1991/1023
## diff -e /n/bootesdump/1991/0906/sys/src/9/port/stip.c /n/bootesdump/1991/1023/sys/src/9/port/stip.c
558d
## diffname port/stip.c 1991/1027
## diff -e /n/bootesdump/1991/1023/sys/src/9/port/stip.c /n/bootesdump/1991/1027/sys/src/9/port/stip.c
276c
		arpsendpkt(feh->dst, feh->d, Etherq, nb);
.
274d
221,224d
203,208c
		arpsendpkt(eh->dst, eh->d, Etherq, bp);
.
## diffname port/stip.c 1991/1029
## diff -e /n/bootesdump/1991/1027/sys/src/9/port/stip.c /n/bootesdump/1991/1029/sys/src/9/port/stip.c
268d
266c
		PUTNEXT(Etherq, nb);
.
203c
		PUTNEXT(Etherq, bp);
.
201c
		/* Finally put in the type and pass down to the arp layer */
.
## diffname port/stip.c 1991/1106
## diff -e /n/bootesdump/1991/1029/sys/src/9/port/stip.c /n/bootesdump/1991/1106/sys/src/9/port/stip.c
330d
325c
	for(ifp = ipifc; ifp < ep; ifp++)
.
## diffname port/stip.c 1991/1115
## diff -e /n/bootesdump/1991/1106/sys/src/9/port/stip.c /n/bootesdump/1991/1115/sys/src/9/port/stip.c
133a
	USED(q);
.
## diffname port/stip.c 1991/1120
## diff -e /n/bootesdump/1991/1115/sys/src/9/port/stip.c /n/bootesdump/1991/1120/sys/src/9/port/stip.c
134c
	Ipconv *ipc;

	ipc = (Ipconv *)(q->ptr);
	if(ipc)
		ipc->ref = 0;
.
77a
	} else {
		ipc = &ipconv[s->dev][s->id];
		RD(q)->ptr = (void *)ipc;
		WR(q)->ptr = (void *)ipc;
		ipc->ref = 1;
.
70a
	Ipconv *ipc;

.
## diffname port/stip.c 1991/1125
## diff -e /n/bootesdump/1991/1120/sys/src/9/port/stip.c /n/bootesdump/1991/1125/sys/src/9/port/stip.c
312c
	if(memcmp(h->dst, Netmyip, sizeof(Netmyip)) != 0 &&
	   memcmp(h->dst, bcast, sizeof(bcast)) != 0)
.
31a
uchar		bcast[4] = { 0xff, 0xff, 0xff, 0xff };
.
## diffname port/stip.c 1991/1126
## diff -e /n/bootesdump/1991/1125/sys/src/9/port/stip.c /n/bootesdump/1991/1126/sys/src/9/port/stip.c
348a
int
ipforme(uchar *addr)
{
	Ipaddr haddr;

	if(memcmp(addr, Netmyip, sizeof(Netmyip)) == 0)
		return 1;

	haddr = nhgetl(addr);

	/* My subnet broadcast */
	if((haddr&Mymask) == (Myip&Mymask))
		return 1;

	/* My network broadcast */
	if((haddr&Mynetmask) == (Myip&Mynetmask))
		return 1;

	/* Real ip broadcast */
	if(haddr == 0)
		return 1;

	/* Old style 255.255.255.255 address */
	if(haddr == ~0)
		return 1;

	return 0;
}
.
316a

.
313,314c
	if(ipforme(h->dst) == 0)
.
186a
			/*
			 * Temporary Until we understand real subnets
			 */
			Mynetmask = Mymask;
.
146a
	}
.
145c
	if(ipc){
		netdisown(ipc->net, ipc->index);
.
30a
Ipaddr		Mynetmask;
.
## diffname port/stip.c 1991/1216
## diff -e /n/bootesdump/1991/1126/sys/src/9/port/stip.c /n/bootesdump/1991/1216/sys/src/9/port/stip.c
569a
	f->age = TK2MS(MACHP(0)->ticks)/1000 + 600;
.
214a
		hnputs(eh->id, Id++);
.
## diffname port/stip.c 1991/1219
## diff -e /n/bootesdump/1991/1216/sys/src/9/port/stip.c /n/bootesdump/1991/1219/sys/src/9/port/stip.c
231c
	seglen = (ifp->maxmtu - (ETHER_HDR+ETHER_IPHDR)) & ~7;
.
## diffname port/stip.c 1992/0101
## diff -e /n/bootesdump/1991/1219/sys/src/9/port/stip.c /n/bootesdump/1992/0101/sys/src/9/port/stip.c
575d
571c
	f->age = TK2MS(MACHP(0)->ticks) + 30000;
.
562,565c
	while(fragfree == 0) {
		for(f = flisthead; f; f = f->next)
			if(canqlock(f)) {
				qunlock(&fraglock);
				ipfragfree(f);
				break;
			}
		qlock(&fraglock);
.
549,550d
531a
	frag->blist = 0;
.
525,528c
	freeb(frag->blist);
.
522d
488c

.
482,484c

		pktposn += BLKFRAG(bl)->flen;
.
479a
		if(BLKFRAG(bl)->foff != pktposn)
			break;
.
478c
	pktposn = 0;
.
418,421d
404c
		if(f != 0) {
.
401a
	qunlock(&fraglock);
.
399c
		if(f->src == src)
		if(f->dst == dst)
		if(f->id == id)
.
397a
	qlock(&fraglock);
.
392c
	int ovlap, len, fragsize, pktposn;
.
## diffname port/stip.c 1992/0102
## diff -e /n/bootesdump/1992/0101/sys/src/9/port/stip.c /n/bootesdump/1992/0102/sys/src/9/port/stip.c
525c
	if(frag->blist)
		freeb(frag->blist);
.
## diffname port/stip.c 1992/0107
## diff -e /n/bootesdump/1992/0102/sys/src/9/port/stip.c /n/bootesdump/1992/0107/sys/src/9/port/stip.c
566d
562,563c
				ipfragfree(f, 0);
.
547c
	if(lockq)
		qunlock(&fraglock);
.
533c
	if(lockq)
		qlock(&fraglock);
.
521c
ipfragfree(Fragq *frag, int lockq)
.
508c
	ipfragfree(f, 1);
.
428,430d
410c
			ipfragfree(f, 1);
.
393a
	/* Check lance has handed us a contiguous buffer */
	if(bp->next)
		panic("ip: reass ?");

.
316c
		if(bp == 0)
.
## diffname port/stip.c 1992/0111
## diff -e /n/bootesdump/1992/0107/sys/src/9/port/stip.c /n/bootesdump/1992/0111/sys/src/9/port/stip.c
13c
#include	"../port/error.h"
.
## diffname port/stip.c 1992/0211
## diff -e /n/bootesdump/1992/0111/sys/src/9/port/stip.c /n/bootesdump/1992/0211/sys/src/9/port/stip.c
190,192d
178c
		if(streamparse("setip", bp)) {
			if(strncmp(eve, u->p->user, sizeof(eve)) != 0)
				error(Eperm);
.
## diffname port/stip.c 1992/0213
## diff -e /n/bootesdump/1992/0211/sys/src/9/port/stip.c /n/bootesdump/1992/0213/sys/src/9/port/stip.c
383a

.
374,381d
370,371c
	/* if we haven't set an address yet, accept anything we get */
	if(Myip[Myself] == 0)
.
366,368c
	/* try my address plus all the forms of ip broadcast */
	for(p = Myip; p < &Myip[7]; p++)
		if(haddr == *p);
			return 1;
.
361,363d
359a
	Ipaddr *p;
.
355a
void
ipsetaddrs(void)
{
	Myip[1] = ~0;					/* local broadcast */
	Myip[2] = 0;					/* local broadcast - old */
	Myip[Mysubnet] = Myip[Myself] | ~Mynetmask;	/* subnet broadcast */
	Myip[Mysubnet+1] = Myip[Myself] & Mynetmask;	/* subnet broadcast - old */
	Myip[Mynet] = Myip[Myself] | ~Mymask;		/* net broadcast */
	Myip[Mynet+1] = Myip[Myself] & Mymask;		/* net broadcast - old */
}

.
193a
			ipsetaddrs();
.
191,192c
				Mynetmask = ipparse((char *)ptr);
			else
				Mynetmask = Mymask;
.
182,187c
			Myip[Myself] = ipparse((char *)ptr);
			Netmyip[0] = (Myip[Myself]>>24)&0xff;
			Netmyip[1] = (Myip[Myself]>>16)&0xff;
			Netmyip[2] = (Myip[Myself]>>8)&0xff;
			Netmyip[3] = Myip[Myself]&0xff;
			Mymask = classmask[Myip[Myself]>>30];
.
81a
		ipsetaddrs();
.
39a
static void	ipsetaddrs(void);
.
33a
Ipaddr		Me[7];		/* possible addresses for me */
.
29c
Ipaddr		Myip[4];
.
## diffname port/stip.c 1992/0214
## diff -e /n/bootesdump/1992/0213/sys/src/9/port/stip.c /n/bootesdump/1992/0214/sys/src/9/port/stip.c
364c
	Myip[Mybcast] = ~0;				/* local broadcast */
.
41d
34d
29c
Ipaddr		Myip[7];
.
## diffname port/stip.c 1992/0304
## diff -e /n/bootesdump/1992/0214/sys/src/9/port/stip.c /n/bootesdump/1992/0304/sys/src/9/port/stip.c
478c
			last = (*l)->next;
.
## diffname port/stip.c 1992/0307
## diff -e /n/bootesdump/1992/0304/sys/src/9/port/stip.c /n/bootesdump/1992/0307/sys/src/9/port/stip.c
473a
				fragstat.succall++;
.
472c
		while(*l){
			ovlap = end - BLKFRAG(*l)->foff;
			if(ovlap <= 0)
				break;
			fragstat.succ++;
.
454c
			fragstat.prev++;
			if(ovlap >= BLKFRAG(bp)->flen) {
				fragstat.prevall++;
.
389a
typedef struct Fragstat	Fragstat;
struct Fragstat
{
	ulong	prev;
	ulong	prevall;
	ulong	succ;
	ulong	succall;
};
Fragstat fragstat;

.
## diffname port/stip.c 1992/0319
## diff -e /n/bootesdump/1992/0307/sys/src/9/port/stip.c /n/bootesdump/1992/0319/sys/src/9/port/stip.c
494c
			}
.
479c
	/* Check to see if succeeding segments overlap */
.
407a
	int end;
.
## diffname port/stip.c 1992/0321
## diff -e /n/bootesdump/1992/0319/sys/src/9/port/stip.c /n/bootesdump/1992/0321/sys/src/9/port/stip.c
8c
#include	"../port/lib.h"
.
## diffname port/stip.c 1992/0326
## diff -e /n/bootesdump/1992/0321/sys/src/9/port/stip.c /n/bootesdump/1992/0326/sys/src/9/port/stip.c
501a
	/*
	 *  look for a complete packet.  if we get to a fragment
	 *  without IP_MF set, we're done.
	 */
.
496a
			(*l)->next = 0;
.
492a
				BLKFRAG(*l)->foff += ovlap;
.
472c
			BLKFRAG(prev)->flen -= ovlap;
.
453a
	/*
	 *  find the new fragment's position in the queue
	 */
.
426a
	/*
	 *  if this isn't a fragmented packet, accept it
	 *  and get rid of any fragments that might go
	 *  with it.
	 */
.
417a
	/*
	 *  find a reassembly queue for this fragment
	 */
.
## diffname port/stip.c 1992/0622
## diff -e /n/bootesdump/1992/0326/sys/src/9/port/stip.c /n/bootesdump/1992/0622/sys/src/9/port/stip.c
58c
	fragfree = (Fragq*)xalloc(sizeof(Fragq) * size);
.
## diffname port/stip.c 1992/0623
## diff -e /n/bootesdump/1992/0622/sys/src/9/port/stip.c /n/bootesdump/1992/0623/sys/src/9/port/stip.c
148c
		netdisown(ipc);
.
## diffname port/stip.c 1992/0626
## diff -e /n/bootesdump/1992/0623/sys/src/9/port/stip.c /n/bootesdump/1992/0626/sys/src/9/port/stip.c
354c
	}

.
348,351c
	for(ifp = ipifc; ; ifp++){
		ifc = *ifp;
		if(ifc == 0)
			break;
		if(ifc->protocol == h->proto) {
			(*ifc->iprcv)(ifc, bp);
.
304c
	Ipifc 	 *ifc, **ifp;
.
153,166d
137,138c
	qunlock(ifc);
.
134,135c
	ifc->protocol = ptcl;
	ifc->inited = 1;
.
129,132c
	ifc->maxmtu = max;
	ifc->minmtu = min;
	ifc->hsize = hdrsize;
.
120,124d
102,118c
	qlock(ifc);
	ifc->iprcv = recvfun;
.
97,100c
void
initipifc(Ipifc *ifc, uchar ptcl, void (*recvfun)(Ipifc*, Block *bp), int max,
	int min, int hdrsize, char *name)
.
95c
 *  initipifc - set parameters of an ip protocol interface
.
84c
		ipc = ipcreateconv(ipifc[s->dev], s->id);
.
20d
## diffname port/stip.c 1992/0711
## diff -e /n/bootesdump/1992/0626/sys/src/9/port/stip.c /n/bootesdump/1992/0711/sys/src/9/port/stip.c
98c
	int min, int hdrsize)
.
## diffname port/stip.c 1992/0724
## diff -e /n/bootesdump/1992/0711/sys/src/9/port/stip.c /n/bootesdump/1992/0724/sys/src/9/port/stip.c
469a
				/* move up ether+ip hdrs */
				memmove((*l)->rptr + ovlap, (*l)->rptr,
					 ETHER_HDR+ETHER_IPHDR);
.
## diffname port/stip.c 1992/0913
## diff -e /n/bootesdump/1992/0724/sys/src/9/port/stip.c /n/bootesdump/1992/0913/sys/src/9/port/stip.c
405c
		return bp;
.
392d
387,390c
	for(f = flisthead; f; f = f->next)
		if(f->src == src && f->dst == dst && f->id == id)
.
375c
	/* Check ethrnet has handed us a contiguous buffer */
.
## diffname port/stip.c 1993/0123
## diff -e /n/bootesdump/1992/0913/sys/src/9/port/stip.c /n/bootesdump/1993/0123/sys/src/9/port/stip.c
459c
			ovlap = fend - BLKFRAG(*l)->foff;
.
456c
		fend = BLKFRAG(bp)->foff + BLKFRAG(bp)->flen;
.
373c
	int fend;
.
## diffname port/stip.c 1993/0501
## diff -e /n/bootesdump/1993/0123/sys/src/9/port/stip.c /n/fornaxdump/1993/0501/sys/src/brazil/port/stip.c
459c
			ovlap = end - BLKFRAG(*l)->foff;
.
456c
		end = BLKFRAG(bp)->foff + BLKFRAG(bp)->flen;
.
373c
	int end;
.
142c
			if(strncmp(eve, up->user, sizeof(eve)) != 0)
.
## diffname port/stip.c 1993/0804 # deleted
## diff -e /n/fornaxdump/1993/0501/sys/src/brazil/port/stip.c /n/fornaxdump/1993/0804/sys/src/brazil/port/stip.c
1,635d

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].