From 2387cf3d28f3a9b308b4e7ca76a6a38e7c8a65f3 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Sun, 7 Apr 1991 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1991-04-07 --- port/stnoether.c | 91 +++++++++++++++++++----------------------------- power/dat.h | 4 ++- power/mem.h | 2 ++ ss/dat.h | 4 ++- 4 files changed, 43 insertions(+), 58 deletions(-) diff --git a/port/stnoether.c b/port/stnoether.c index 14b71448e33ed7cf75393516d069dc767768768d..0ce78186c97ad9d0e8d43774a6c62cdd027f8f8a 100644 --- a/port/stnoether.c +++ b/port/stnoether.c @@ -25,21 +25,8 @@ static void noetheroput(Queue*, Block*); /* * ethernet header of a packet */ -typedef struct Etherhdr Etherhdr; - -struct Etherhdr { - uchar d[6]; - uchar s[6]; - uchar type[2]; - uchar circuit[3]; /* circuit number */ - uchar flag; - uchar mid; /* message id */ - uchar ack; /* piggy back ack */ - uchar remain[2]; /* count of remaing bytes of data */ - uchar sum[2]; /* checksum (0 means none) */ -}; -#define EHDRSIZE 24 -#define EMAXBODY (1514-HDRSIZE) /* maximum ethernet packet body */ +#define EHDRSIZE (ETHERHDRSIZE + NO_HDRSIZE) +#define EMAXBODY (ETHERMAXTU - EHDRSIZE) /* maximum ethernet packet body */ #define ETHER_TYPE 0x900 /* most significant byte last */ /* @@ -61,9 +48,9 @@ Qinfo noetherinfo = void noetherconnect(Noconv *cp, char *ea) { - Etherhdr *eh; + Etherpkt *eh; - eh = (Etherhdr *)cp->media->rptr; + eh = (Etherpkt*)cp->media->rptr; etherparse(eh->d, ea); eh->type[0] = ETHER_TYPE>>8; eh->type[1] = ETHER_TYPE & 0xff; @@ -75,7 +62,7 @@ noetherconnect(Noconv *cp, char *ea) static void noetheropen(Queue *q, Stream *s) { - nonetnewifc(q, s, 1514, ETHERMINMTU, 14, noetherconnect); + nonetnewifc(q, s, ETHERMAXTU, ETHERMINTU, ETHERHDRSIZE, noetherconnect); } /* @@ -86,7 +73,7 @@ noetherclose(Queue *q) { Noifc *ifc; - ifc = (Noifc *)(q->ptr); + ifc = (Noifc*)q->ptr; nonetfreeifc(ifc); } @@ -98,7 +85,7 @@ noetheroput(Queue *q, Block *bp) { Noifc *ifc; - ifc = (Noifc *)(q->ptr); + ifc = (Noifc*)q->ptr; if(bp->type != M_DATA){ if(streamparse("config", bp)){ if(*bp->rptr == 0) @@ -119,7 +106,8 @@ noetheroput(Queue *q, Block *bp) void noetherbad(Noifc *ifc, Block *bp, int circuit) { - Etherhdr *eh, *neh; + Etherpkt *eh, *neh; + Nohdr *nh, *nnh; Block *nbp; int r; Noconv *cp, *ep; @@ -127,29 +115,18 @@ noetherbad(Noifc *ifc, Block *bp, int circuit) /* * crack the packet header */ - eh = (Etherhdr *)bp->rptr; + eh = (Etherpkt*)bp->rptr; + nh = (Nohdr*)eh->data; print("bad %.2ux%.2ux%.2ux%.2ux%.2ux%.2ux c %d m %d f %d\n", eh->s[0], eh->s[1], eh->s[2], eh->s[3], eh->s[4], - eh->s[5], circuit, eh->mid, eh->flag); - if(eh->flag & NO_RESET) + eh->s[5], circuit, nh->mid, nh->flag); + if(nh->flag & NO_RESET) goto out; -ep = &ifc->conv[conf.nnoconv]; -for(cp = &ifc->conv[0]; cp < ep; cp++){ - qlock(cp); - if(cp->media){ - neh = (Etherhdr *)(cp->media->rptr); - print("%lux %.2ux%.2ux%.2ux%.2ux%.2ux%.2ux %s c %d\n", neh, - neh->s[0], neh->s[1], neh->s[2], neh->s[3], neh->s[4], - neh->s[5], cp->raddr, cp->rcvcircuit); - } - qunlock(cp); -} - /* * only one reset per message */ - r = (eh->remain[1]<<8) | eh->remain[0]; + r = (nh->remain[1]<<8) | nh->remain[0]; if(r<0) goto out; @@ -161,13 +138,14 @@ for(cp = &ifc->conv[0]; cp < ep; cp++){ nbp->flags |= S_DELIM; nbp->wptr = nbp->rptr + 60; memset(bp->rptr, 0, 60); - neh = (Etherhdr *)nbp->rptr; - memmove(neh, eh, sizeof(Etherhdr)); - neh->circuit[0] ^= 1; - neh->remain[0] = neh->remain[1] = 0; - neh->flag = NO_HANGUP | NO_RESET; - neh->ack = eh->mid; - neh->mid = eh->ack; + neh = (Etherpkt *)nbp->rptr; + nnh = (Nohdr*)neh->data; + memmove(neh, eh, EHDRSIZE); + nnh->circuit[0] ^= 1; + nnh->remain[0] = nnh->remain[1] = 0; + nnh->flag = NO_HANGUP | NO_RESET; + nnh->ack = nh->mid; + nnh->mid = nh->ack; memmove(neh->s, eh->d, sizeof(neh->s)); memmove(neh->d, eh->s, sizeof(neh->d)); nonetcksum(nbp, 14); @@ -189,8 +167,8 @@ noetheriput(Queue *q, Block *bp) Noifc *ifc; int circuit; Noconv *cp, *ep; - Etherhdr *h; - Etherhdr *ph; + Etherpkt *eh, *peh; + Nohdr *nh; ulong s; Block *nbp; int next; @@ -201,12 +179,13 @@ noetheriput(Queue *q, Block *bp) return; } - ifc = (Noifc *)(q->ptr); - h = (Etherhdr *)(bp->rptr); - circuit = (h->circuit[2]<<16) | (h->circuit[1]<<8) | h->circuit[0]; - s = (h->sum[1]<<8) | h->sum[0]; - if(s && s!=nonetcksum(bp, 14)){ -/* print("checksum error %ux %ux\n", s, (h->sum[1]<<8) | h->sum[0]); /**/ + ifc = (Noifc*)q->ptr; + eh = (Etherpkt*)bp->rptr; + nh = (Nohdr*)eh->data; + circuit = (nh->circuit[2]<<16) | (nh->circuit[1]<<8) | nh->circuit[0]; + s = (nh->sum[1]<<8) | nh->sum[0]; + if(s && s!=nonetcksum(bp, ETHERHDRSIZE)){ +/* print("checksum error %ux %ux\n", s, (nh->sum[1]<<8) | nh->sum[0]); /**/ freeb(bp); return; } @@ -218,9 +197,9 @@ noetheriput(Queue *q, Block *bp) for(cp = &ifc->conv[0]; cp < ep; cp++){ if(circuit==cp->rcvcircuit){ qlock(cp); - ph = (Etherhdr *)(cp->media->rptr); + peh = (Etherpkt*)cp->media->rptr; if(circuit == cp->rcvcircuit - && memcmp(ph->d, h->s, sizeof(h->s)) == 0){ + && memcmp(peh->d, eh->s, sizeof(eh->s)) == 0){ bp->rptr += ifc->hsize; nonetrcvmsg(cp, bp); qunlock(cp); @@ -233,7 +212,7 @@ noetheriput(Queue *q, Block *bp) /* * if not a new call, then its misaddressed */ - if((h->flag & NO_NEWCALL) == 0){ + if((nh->flag & NO_NEWCALL) == 0){ noetherbad(ifc, bp, circuit); return; } @@ -252,7 +231,7 @@ noetheriput(Queue *q, Block *bp) } clp = &ifc->call[ifc->wptr]; sprint(clp->raddr, "%.2ux%.2ux%.2ux%.2ux%.2ux%.2ux", - h->s[0], h->s[1], h->s[2], h->s[3], h->s[4], h->s[5]); + eh->s[0], eh->s[1], eh->s[2], eh->s[3], eh->s[4], eh->s[5]); clp->circuit = circuit^1; bp->rptr += ifc->hsize; clp->msg = bp; diff --git a/power/dat.h b/power/dat.h index 2b6e519318cd232c2fc5c1bb24ccf504d49f566c..6fe5ae70f1c91675a89bad55b1ce2946b99157b0 100644 --- a/power/dat.h +++ b/power/dat.h @@ -515,7 +515,9 @@ struct Etherpkt { uchar data[1500]; uchar crc[4]; }; -#define ETHERMINMTU 60 /* minimum transmit size */ +#define ETHERMINTU 60 /* minimum transmit size */ +#define ETHERMAXTU 1514 /* maximum transmit size */ +#define ETHERHDRSIZE 14 /* size of an ethernet header */ /* * LANCE CSR3 (bus control bits) diff --git a/power/mem.h b/power/mem.h index 337765d664aad328a77a121552b2977e0bfb393c..2c57a4cc5702c2c6d7999dd118790f91c43de46d 100644 --- a/power/mem.h +++ b/power/mem.h @@ -133,3 +133,5 @@ #define CUNK15 15 /* undefined 15 */ #define NSEG 5 + +#define isphys(x) ((ulong)(x) & KZERO) diff --git a/ss/dat.h b/ss/dat.h index 2a953d0636a500cd45eed206899367be73efa71f..309aca30fc54d0be7cb6edc6a4b10fa4a2f45646 100644 --- a/ss/dat.h +++ b/ss/dat.h @@ -512,7 +512,9 @@ struct Etherpkt { uchar data[1500]; uchar crc[4]; }; -#define ETHERMINMTU 60 /* minimum transmit size */ +#define ETHERMINTU 60 /* minimum transmit size */ +#define ETHERMAXTU 1514 /* maximum transmit size */ +#define ETHERHDRSIZE 14 /* size of an ethernet header */ #define NSTUB 32 struct Service