From 12193e38495b06989841e6d549e7466309a16dab Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Wed, 25 Mar 1992 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1992-03-25 --- boot/boot.c | 10 +++- boot/boot.h | 1 + boot/key.c | 38 +++++-------- boot/settime.c | 2 +- boot/userpasswd.c | 12 ++-- gnot/main.c | 11 +++- port/devarp.c | 24 +++----- port/devmnt.c | 3 +- port/ipdat.h | 5 +- port/portdat.h | 1 + port/tcpif.c | 2 + port/tcpinput.c | 138 ++++++++++++++++++++++------------------------ power/devduart.c | 2 +- power/main.c | 4 +- power/trap.c | 4 +- ss/main.c | 2 +- 16 files changed, 125 insertions(+), 134 deletions(-) diff --git a/boot/boot.c b/boot/boot.c index cd590674ed2ec7d7d54c123c5a6d18da2b6b974e..4072a5d2d63a784277f3e3457c452641b9d2b8f7 100644 --- a/boot/boot.c +++ b/boot/boot.c @@ -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(); diff --git a/boot/boot.h b/boot/boot.h index 027dd2699990c5c7a5bd9a7d14cfc7e0a00731df..3af29a86f08372d2bd44d6b1c23368f7c2c2d2b3 100644 --- a/boot/boot.h +++ b/boot/boot.h @@ -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); diff --git a/boot/key.c b/boot/key.c index c009fe6c67d131108a12b1dcedc0a825e5278b1b..4e0e8ea7a4ed4afe431008881b034879ebd25da0 100644 --- a/boot/key.c +++ b/boot/key.c @@ -3,23 +3,14 @@ #include #include <../boot/boot.h> -static uchar -cksum(char *key) -{ - int i, nvsum; - - nvsum = 0; - for(i=0; i 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; diff --git a/gnot/main.c b/gnot/main.c index 64b05b661670fae241a167422c1a73db5a033a5b..f920058a2951a53e7f2ba997e5ef673312e6c975 100644 --- a/gnot/main.c +++ b/gnot/main.c @@ -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; } diff --git a/port/devarp.c b/port/devarp.c index 4389757e8e42d3618644980a404b9283e54b0ba5..8a2a1c3d19c5f7f10db9158c1d2662dfdccf0b31 100644 --- a/port/devarp.c +++ b/port/devarp.c @@ -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; } } diff --git a/port/devmnt.c b/port/devmnt.c index daf00ed6d4dfe01f5ab119b250d3ea65391a37da..fa18dd30e09e3ab854d9fb0e5f603211db5fb8a7 100644 --- a/port/devmnt.c +++ b/port/devmnt.c @@ -178,7 +178,8 @@ mntattach(char *muxattach) if(waserror()) { close(m->c); - mntpntfree(m); + if(decref(m) == 0) + mntpntfree(m); nexterror(); } diff --git a/port/ipdat.h b/port/ipdat.h index 69a2b34722f99f907f3cdaac911c87c0c2ab9188..9d9c99a0d2ef831f238528ab9a66238f7de61f6d 100644 --- a/port/ipdat.h +++ b/port/ipdat.h @@ -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); diff --git a/port/portdat.h b/port/portdat.h index f2c23f2948fada1736b18d595d075b7e15aaea55..e4d0ffc5aa2485f85aa9325651843782594d8410 100644 --- a/port/portdat.h +++ b/port/portdat.h @@ -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 diff --git a/port/tcpif.c b/port/tcpif.c index 965d452a768217814e8df11799c4bdd0c5da521b..830c6657b01de8138866c4f6fb7e91abeaf62f3c 100644 --- a/port/tcpif.c +++ b/port/tcpif.c @@ -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; diff --git a/port/tcpinput.c b/port/tcpinput.c index 77958cc130908ee6fa03f8697013125590c93a41..b5e8908fb839b51fc249eeaac95cf26bfa5b3e4c 100644 --- a/port/tcpinput.c +++ b/port/tcpinput.c @@ -31,6 +31,54 @@ tcpinit(void) r->next = 0; } +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) { @@ -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)) @@ -362,54 +412,6 @@ done: qunlock(tcb); } -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) { @@ -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; @@ -809,15 +812,6 @@ close_self(Ipconv *s, char reason[]) setstate(s, Closed); } -int -iss(void) -{ - static int seq; - - seq += 250000; - return seq; -} - int seq_within(int x, int low, int high) { diff --git a/power/devduart.c b/power/devduart.c index c471484cea8dc9b6979d4e5f6a1756c5d005055c..3651f798abfdf8c75251f7ecef86bc34460181e0 100644 --- a/power/devduart.c +++ b/power/devduart.c @@ -335,7 +335,7 @@ duartxintr(Duartport *dp) { Duart *duart; IOQ *cq; - char ch; + int ch; cq = dp->oq; lock(cq); diff --git a/power/main.c b/power/main.c index 93575fcbb5a0329b6efe0895f447a5d94da65272..040838d0b7314f21e6d2abc8de207875c8b9c2c6 100644 --- a/power/main.c +++ b/power/main.c @@ -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; } /* diff --git a/power/trap.c b/power/trap.c index 593be50fb709ea931e8a6a4f803c08c09db298a3..2119fa25ee674d4660d963683439fdf922b5279b 100644 --- a/power/trap.c +++ b/power/trap.c @@ -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); } /* diff --git a/ss/main.c b/ss/main.c index 006535c90d0a855092a3a256fb8490168cf58d8f..ce2dbd4bbf37dfe7ff56e92c09d556a76b2cf9e2 100644 --- a/ss/main.c +++ b/ss/main.c @@ -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;