~kris/9p

9hist

12193e38495b06989841e6d549e7466309a16dab — David du Colombier 34 years ago 5bd4b44
Plan 9 from Bell Labs 1992-03-25
M boot/boot.c => boot/boot.c +7 -3
@@ 12,7 12,7 @@ char	cputype[NAMELEN];
char	terminal[NAMELEN];
char	sys[2*NAMELEN];
char	username[NAMELEN];
char 	*sauth = "";
char	*sauth;

int mflag;
int fflag;


@@ 95,8 95,12 @@ main(int argc, char *argv[])
	 */
	if(bind("/", "/", MREPL) < 0)
		fatal("bind");
	if(mount(fd, "/", MAFTER|MCREATE, "", sauth) < 0)
		fatal("mount");
	sauth = "";
	if(mount(fd, "/", MAFTER|MCREATE, "", sauth) < 0){
		sauth = "any";
		if(mount(fd, "/", MAFTER|MCREATE, "", sauth) < 0)
			fatal("mount");
	}
	close(fd);
	newkernel();


M boot/boot.h => boot/boot.h +1 -0
@@ 20,6 20,7 @@ extern void	(*pword)(int, Method*);
extern char	sys[2*NAMELEN];
extern char	terminal[NAMELEN];
extern char	username[NAMELEN];
extern char	*sauth;

/* libc equivalent */
extern int	cache(int);

M boot/key.c => boot/key.c +15 -23
@@ 3,23 3,14 @@
#include <auth.h>
#include <../boot/boot.h>

static uchar
cksum(char *key)
{
	int i, nvsum;

	nvsum = 0;
	for(i=0; i<DESKEYLEN; i++)
		nvsum += key[i];
	return nvsum & 0xff;
}
char defpass[] = {0x64, 0x3e, 0x4d, 0x13, 0x32, 0x00, 0x0b, 0xe1, 0xce};

void
key(int islocal, Method *mp)
{
	char password[20], key[DESKEYLEN];
	uchar nvsum;
	int prompt, fd;
	Nvrsafe safe;
	char password[20];
	int prompt, fd, i;

	USED(islocal);
	USED(mp);


@@ 31,30 22,31 @@ key(int islocal, Method *mp)
		warning("can't open nvram");
	}
	if(seek(fd, 1024+900, 0) < 0
	|| read(fd, key, DESKEYLEN) != DESKEYLEN
	|| read(fd, &nvsum, 1) != 1)
	|| read(fd, &safe, sizeof safe) != sizeof safe)
		warning("can't read nvram key");

	if(prompt){
		do
			getpasswd(password, sizeof password);
		while(!passtokey(key, password));
	}else if(cksum(key) != nvsum){
		warning("bad nvram key; using password boofhead");
		passtokey(key, "boofhead");
		while(!passtokey(safe.machkey, password));
	}else if(nvcsum(safe.machkey, DESKEYLEN) != safe.machsum){
		warning("bad nvram key; using default password");
		/* Just so its not plain text in the binary */
		for(i=0; i<sizeof(defpass); i++)
			defpass[i] = (defpass[i]-19)^(17*(i+3));
		passtokey(safe.machkey, defpass);
	}
	nvsum = cksum(key);
	safe.machsum = nvcsum(safe.machkey, DESKEYLEN);
	if(kflag){
		if(seek(fd, 1024+900, 0) < 0
		|| write(fd, key, DESKEYLEN) != DESKEYLEN
		|| write(fd, &nvsum, 1) != 1)
		|| write(fd, &safe, sizeof safe) != sizeof safe)
			warning("can't write key to nvram");
	}
	close(fd);
	fd = open("#c/key", OWRITE);
	if(fd < 0)
		warning("can't open #c/key");
	else if(write(fd, key, DESKEYLEN) != DESKEYLEN)
	else if(write(fd, safe.machkey, DESKEYLEN) != DESKEYLEN)
		warning("can't set #c/key");
	close(fd);
}

M boot/settime.c => boot/settime.c +1 -1
@@ 34,7 34,7 @@ settime(int islocal)
		f = open("#s/boot", ORDWR);
		if(f < 0)
			return;
		if(mount(f, "/n/boot", MREPL, "", "") < 0){
		if(mount(f, "/n/boot", MREPL, "", sauth) < 0){
			close(f);
			return;
		}

M boot/userpasswd.c => boot/userpasswd.c +5 -7
@@ 4,7 4,9 @@
#include <../boot/boot.h>

char	password[NAMELEN];
#ifdef asdf
extern	char *sauth;
#endif asdf

/*
 *  get/set user name and password.  verify password with auth server.


@@ 20,12 22,6 @@ userpasswd(int islocal, Method *mp)
	if(*username == 0 || strcmp(username, "none") == 0){
		strcpy(username, "none");
		outin("user", username, sizeof(username));
		/* Hack to do authentication testing */
		p = utfrrune(username, '!');
		if(p && p > username) {
			*p = '\0';
			sauth = "any";
		}
	}
	crfd = fd = -1;
	while(strcmp(username, "none") != 0 && !islocal){


@@ 41,7 37,9 @@ userpasswd(int islocal, Method *mp)
		if(crfd < 0)
			fatal("can't open crypt file");
		write(crfd, "E", 1);
		fd = (*mp->auth)();
		fd = -1;
		if(mp->auth)
			fd = (*mp->auth)();
		if(fd < 0){
			warning("password not checked!");
			break;

M gnot/main.c => gnot/main.c +8 -3
@@ 67,9 67,12 @@ unloadboot(void)
{
	char s[64];

	strncpy(bootuser, BOOT->user, NAMELEN);
	memmove(bootline, BOOT->line, 64);
	memmove(s, BOOT->server, 64);
	memmove(bootuser, BOOT->user, sizeof(bootuser)-1);
	bootuser[sizeof(bootuser)-1] = 0;
	memmove(bootline, BOOT->line, sizeof(bootline)-1);
	bootline[sizeof(bootline)-1] = 0;
	memmove(s, BOOT->server, sizeof(s) - 1);
	s[sizeof(s)-1] = 0;
	switch(BOOT->device){
	case 'a':
		sprint(bootserver, "19200!%s", s);


@@ 81,6 84,8 @@ unloadboot(void)
		sprint(bootserver, "incon!%s", s);
		break;
	default:
		/* older boot ROM's don't zero out BOOT->user if it isn't set. */
		memset(bootuser, 0, sizeof(bootuser));
		sprint(bootserver, "scsi!%s", s);
		break;
	}

M port/devarp.c => port/devarp.c +8 -16
@@ 382,9 382,10 @@ arplookup(uchar *ip, uchar *et)
void
arpflush(void)
{
	Arpcache *ap;
	Arpcache *ap, *ep;

	for(ap = arplruhead; ap; ap = ap->frwd)
	ep = &arp[conf.arp];
	for(ap = arp; ap < ep; ap++)
		ap->status = ARP_FREE;
}



@@ 444,22 445,14 @@ int
arpdelete(char *addr)
{
	Arpcache *ap;
	char enetaddr[6], buf[20], *ptr;
	int i;

	ptr = buf + 2;
	strncpy(ptr, addr, (sizeof buf) - 2);

	for(i = 0; i < 6 && addr != (char *)1; i++) {
		ptr[-2] = '0';
		ptr[-1] = 'x';
		enetaddr[i] = atoi(ptr-2);
		ptr = strchr(ptr, ':')+1;
	}
	uchar ip[4];
	Ipaddr i;

	i = ipparse(addr);
	hnputl(ip, i);	
	lock(&larphash);
	for(ap = arplruhead; ap; ap = ap->frwd) {
		if(memcmp(ap->et, ptr, sizeof(ap->et)) == 0) {
		if(memcmp(ap->eip, ip, sizeof(ap->eip)) == 0) {
			ap->status = ARP_FREE;
			break;
		}


@@ 483,7 476,6 @@ arplinkhead(Arpcache *ap)
		
		ap->frwd = arplruhead;
		ap->prev = 0;

		arplruhead = ap;
	}
}

M port/devmnt.c => port/devmnt.c +2 -1
@@ 178,7 178,8 @@ mntattach(char *muxattach)

	if(waserror()) {
		close(m->c);
		mntpntfree(m);
		if(decref(m) == 0)
			mntpntfree(m);
		nexterror();
	}


M port/ipdat.h => port/ipdat.h +2 -3
@@ 428,7 428,7 @@ struct Ipfrag
#define PRIVPORTALLOC	600		/* First priveleged port allocated */
#define PORTMAX		30000		/* Last port to allocte */

/* Stuff to go in funs.h someday */
/* IP function declarations */
Ipifc   *newipifc(uchar, void (*)(Ipconv *, Block*), Ipconv *, int, int, int, char*);
void	closeipifc(Ipifc*);
ushort	ip_csum(uchar*);


@@ 467,9 467,8 @@ int	inb_window(Tcpctl *, int);
Block	*htontcp(Tcp *, Block *, Tcphdr *);
void	start_timer(Timer *);
void	stop_timer(Timer *);
int	copyupb(Block **, uchar *, int);
int	pullb(Block **, int);
void	init_tcpctl(Ipconv *);
int	iss(void);
int	seq_within(int, int, int);
int	seq_lt(int, int);
int	seq_le(int, int);

M port/portdat.h => port/portdat.h +1 -0
@@ 697,6 697,7 @@ extern  Image	swapimage;
extern  char	eve[];
extern	int	nrdy;
extern	char	sysname[NAMELEN];
extern	int	cpuserver;

#define	CHDIR		0x80000000L
#define	CHAPPEND 	0x40000000L

M port/tcpif.c => port/tcpif.c +2 -0
@@ 64,6 64,7 @@ notsyner(void *ic)
{
	return ((Tcpctl*)ic)->state != Syn_sent;
}

void
tcpstart(Ipconv *s, int mode, ushort window, char tos)
{


@@ 82,6 83,7 @@ tcpstart(Ipconv *s, int mode, ushort window, char tos)
		tcb->flags |= CLONE;
		setstate(s, Listen);
		break;

	case TCP_ACTIVE:
		/* Send SYN, go into SYN_SENT state */
		tcb->flags |= ACTIVE;

M port/tcpinput.c => port/tcpinput.c +66 -72
@@ 32,6 32,54 @@ tcpinit(void)
}

void
reset(Ipaddr source, Ipaddr dest, char tos, ushort length, Tcp *seg)
{
	Block *hbp;
	Port tmp;
	char rflags;
	Tcphdr ph;

	if(seg->flags & RST)
		return;

	hnputl(ph.tcpsrc, dest);
	hnputl(ph.tcpdst, source);
	ph.proto = IP_TCPPROTO;
	hnputs(ph.tcplen, TCP_HDRSIZE);

	/* Swap port numbers */
	tmp = seg->dest;
	seg->dest = seg->source;
	seg->source = tmp;

	rflags = RST;

	/* convince the other end that this reset is in band */
	if(seg->flags & ACK) {
		seg->seq = seg->ack;
		seg->ack = 0;
	}
	else {
		rflags |= ACK;
		seg->ack = seg->seq;
		seg->seq = 0;
		if(seg->flags & SYN)
			seg->ack++;
		seg->ack += length;
		if(seg->flags & FIN)
			seg->ack++;
	}
	seg->flags = rflags;
	seg->wnd = 0;
	seg->up = 0;
	seg->mss = 0;
	if((hbp = htontcp(seg, 0, &ph)) == 0)
		return;

	PUTNEXT(Ipoutput, hbp);
}

void
tcp_input(Ipconv *ipc, Block *bp)
{
	Ipconv *s, *e, *new;


@@ 65,7 113,8 @@ tcp_input(Ipconv *ipc, Block *bp)
	bp = btrim(bp, hdrlen+TCP_PKT, length);
	if(bp == 0)
		return;

	
	/* Look for a connection, failing that attempt to establish a listen */
	s = ip_conn(ipc, seg.dest, seg.source, source, IP_TCPPROTO);
	if (s == 0) {
		if((seg.flags & SYN) == 0)


@@ 109,7 158,10 @@ tcp_input(Ipconv *ipc, Block *bp)
		reset(source, dest, tos, length, &seg);
		return;
	}
process:	
process:
	/* The rest of the input state machine is run with the control block
	 * locked
	 */
	tcb = &s->tcpctl;
	qlock(tcb);



@@ 190,9 242,7 @@ process:
		goto done;
	}

	/* If we have no opens and the other end is sending data then
	 * reply with a reset
	 */
	/* If we dont understand answer with a rst */
	if(length)
	if(s->readq == 0) {
		freeb(bp);


@@ 276,7 326,7 @@ process:
		if((seg.flags&URG) && seg.up) {
			if(seq_gt(seg.up + seg.seq, tcb->rcv.up)) {
				tcb->rcv.up = seg.up + seg.seq;
				copyupb(&bp, 0, seg.up);
				pullb(&bp, seg.up);
			}
		} 
		else if(seq_gt(tcb->rcv.nxt, tcb->rcv.up))


@@ 363,54 413,6 @@ done:
}

void
reset(Ipaddr source, Ipaddr dest, char tos, ushort length, Tcp *seg)
{
	Block *hbp;
	Port tmp;
	char rflags;
	Tcphdr ph;

	if(seg->flags & RST)
		return;

	hnputl(ph.tcpsrc, dest);
	hnputl(ph.tcpdst, source);
	ph.proto = IP_TCPPROTO;
	hnputs(ph.tcplen, TCP_HDRSIZE);

	/* Swap port numbers */
	tmp = seg->dest;
	seg->dest = seg->source;
	seg->source = tmp;

	rflags = RST;

	/* convince the other end that this reset is in band */
	if(seg->flags & ACK) {
		seg->seq = seg->ack;
		seg->ack = 0;
	}
	else {
		rflags |= ACK;
		seg->ack = seg->seq;
		seg->seq = 0;
		if(seg->flags & SYN)
			seg->ack++;
		seg->ack += length;
		if(seg->flags & FIN)
			seg->ack++;
	}
	seg->flags = rflags;
	seg->wnd = 0;
	seg->up = 0;
	seg->mss = 0;
	if((hbp = htontcp(seg, 0, &ph)) == 0)
		return;

	PUTNEXT(Ipoutput, hbp);
}

void
update(Ipconv *s, Tcp *seg)
{
	ushort acked;


@@ 484,7 486,7 @@ update(Ipconv *s, Tcp *seg)
		tcb->sndcnt--;
	}

	copyupb(&tcb->sndq, 0, acked);
	pullb(&tcb->sndq, acked);

	tcb->sndcnt -= acked;
	tcb->snd.una = seg->ack;


@@ 542,8 544,13 @@ proc_syn(Ipconv *s, char tos, Tcp *seg)
void
send_syn(Tcpctl *tcb)
{
	tcb->iss = iss();
	tcb->rttseq = tcb->snd.wl2 = tcb->snd.una = tcb->iss;
	static int start;

	start += 250000;
	tcb->iss = start;
	tcb->rttseq = tcb->iss;
	tcb->snd.wl2 = tcb->iss;
	tcb->snd.una = tcb->iss;
	tcb->snd.ptr = tcb->snd.nxt = tcb->rttseq;
	tcb->sndcnt++;
	tcb->flags |= FORCE;


@@ 660,7 667,7 @@ trim(Tcpctl *tcb, Tcp *seg, Block **bp, ushort *length)
			dupcnt--;
		}
		if(dupcnt > 0){
			copyupb(bp, 0, (ushort)dupcnt);
			pullb(bp, (ushort)dupcnt);
			seg->seq += dupcnt;
			*length -= dupcnt;



@@ 685,7 692,7 @@ trim(Tcpctl *tcb, Tcp *seg, Block **bp, ushort *length)
}

int
copyupb(Block **bph, uchar *data, int count)
pullb(Block **bph, int count)
{
	int n, bytes;
	Block *bp;


@@ 697,10 704,6 @@ copyupb(Block **bph, uchar *data, int count)
	while(*bph && count != 0) {
		bp = *bph;
		n = MIN(count, BLEN(bp));
		if(data && n) {
			memmove(data, bp->rptr, n);
			data += n;
		}
		bytes += n;
		count -= n;
		bp->rptr += n;


@@ 810,15 813,6 @@ close_self(Ipconv *s, char reason[])
}

int
iss(void)
{
	static int seq;

	seq += 250000;
	return seq;
}

int
seq_within(int x, int low, int high)
{
	if(low <= high){

M power/devduart.c => power/devduart.c +1 -1
@@ 335,7 335,7 @@ duartxintr(Duartport *dp)
{
	Duart *duart;
	IOQ *cq;
	char ch;
	int ch;

	cq = dp->oq;
	lock(cq);

M power/main.c => power/main.c +2 -2
@@ 570,7 570,7 @@ confinit(void)
	conf.nmntbuf = conf.nproc;
	conf.nmnthdr = conf.nproc;
	conf.nstream = 2 * conf.nproc;
	conf.nalarm = 500;
	conf.nalarm = 2500;
	conf.nmount = 500;
	conf.nsrv = 20;
	conf.nurp = 25;


@@ 589,7 589,7 @@ confinit(void)
		panic("confinit");

	conf.copymode = 1;		/* copy on reference */
	conf.cntrlp = 1;
	conf.cntrlp = cpuserver;
}

/*

M power/trap.c => power/trap.c +3 -1
@@ 298,7 298,9 @@ intr(Ureg *ur)
		 *  if nothing else, what the hell?
		 */
		if(!any && bogies++<10){
			print("bogus intr lvl 5 pend %lux on %d\n", npend, m->machno);/**/
			if(0)
			print("bogus intr lvl 5 pend %lux on %d\n", npend, m->machno);
			USED(npend);
			delay(100);
		}
		/*

M ss/main.c => ss/main.c +1 -1
@@ 17,7 17,7 @@ main(void)
	int a;

	u = 0;
	memset(&edata, 0, (char*)&end-(char*)&edata);
	memset(edata, 0, (char*)end-(char*)edata);

	machinit();
	active.exiting = 0;