From a61ead367a8c829ecc15859353cc84961e007926 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Tue, 10 Mar 1998 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1998-03-10 --- ip/devip.c | 16 +++++++++++++--- ip/ip.h | 2 ++ ip/ipifc.c | 40 ++++++++++++++++++++++++++++++++++++---- ip/iproute.c | 39 ++++++++++++++++++++++----------------- port/devproc.c | 42 +++++++++++++++++++++++++++++++++++++++--- 5 files changed, 112 insertions(+), 27 deletions(-) diff --git a/ip/devip.c b/ip/devip.c index 6fbec42314d29c1b32b83b593843dfca5fad1372..ffc12be53c3b1354a7b288a459dc05e220706e5a 100644 --- a/ip/devip.c +++ b/ip/devip.c @@ -16,6 +16,7 @@ enum Qarp= Qtopbase, Qiproute, Qiprouter, + Qipselftab, Qlog, Qprotodir, /* directory for a protocol */ @@ -107,7 +108,9 @@ ip1gen(Chan *c, int i, Dir *dp) { Qid q; char *p; + int prot; + prot = 0666; switch(i) { default: return -1; @@ -119,6 +122,11 @@ ip1gen(Chan *c, int i, Dir *dp) p = "iproute"; q = (Qid){QID(0, 0, Qiproute), 0}; break; + case Qipselftab: + p = "ipselftab"; + prot = 0444; + q = (Qid){QID(0, 0, Qipselftab), 0}; + break; case Qiprouter: p = "iprouter"; q = (Qid){QID(0, 0, Qiprouter), 0}; @@ -128,7 +136,7 @@ ip1gen(Chan *c, int i, Dir *dp) q = (Qid){QID(0, 0, Qlog), 0}; break; } - devdir(c, q, p, 0, network, 0666, dp); + devdir(c, q, p, 0, network, prot, dp); return 1; } @@ -154,6 +162,7 @@ ipgen(Chan *c, Dirtab*, int, int s, Dir *dp) case Qlog: case Qiproute: case Qiprouter: + case Qipselftab: return ip1gen(c, TYPE(c->qid), dp); case Qprotodir: if(s < fs.p[PROTO(c->qid)]->ac) { @@ -295,6 +304,7 @@ ipopen(Chan* c, int omode) case Qremote: case Qlocal: case Qstats: + case Qipselftab: if(omode != OREAD) error(Eperm); break; @@ -464,8 +474,8 @@ ipread(Chan *ch, void *a, long n, ulong offset) return arpread(a, offset, n); case Qiproute: return routeread(a, offset, n); - case Qiprouter: - return iprouterread(a, n); + case Qipselftab: + return ipselftabread(a, offset, n); case Qlog: return netlogread(a, offset, n); case Qctl: diff --git a/ip/ip.h b/ip/ip.h index d8f939af0cbfee24c445e541f0c211843c76a5c0..fff75a24c12ab870f204ca236afb7609ea336999 100644 --- a/ip/ip.h +++ b/ip/ip.h @@ -340,6 +340,7 @@ extern Route* v4lookup(uchar *a); extern Route* v6lookup(uchar *a); extern long routeread(char*, ulong, int); extern long routewrite(Chan*, char*, int); +extern void routetype(int, char*); /* * arp.c @@ -432,6 +433,7 @@ extern void ipifcremmulti(Conv *c, uchar *ma, uchar *ia); extern void ipifcaddmulti(Conv *c, uchar *ma, uchar *ia); extern char* ipifcrem(Ipifc *ifc, char **argv, int argc, int dolock); extern char* ipifcadd(Ipifc *ifc, char **argv, int argc); +extern long ipselftabread(char *a, ulong offset, int n); /* * ip.c diff --git a/ip/ipifc.c b/ip/ipifc.c index 88a224b122cf14bf53694487bc76a428071a4125..e8d16b235ebc3f2ca1a3fcd5cd59a0d0aedab6d4 100644 --- a/ip/ipifc.c +++ b/ip/ipifc.c @@ -749,15 +749,15 @@ remselfcache(Ipifc *ifc, Iplifc *lifc, uchar *a) *l_self = link->selflink; iplinkfree(link); + if(p->link != nil) + goto out; + /* remove from routing table */ if(isv4(a)) v4delroute(a+IPv4off, IPallbits+IPv4off); else v6delroute(a, IPallbits); - if(p->link != nil) - goto out; - /* no more links, remove from hash and free */ *l = p->next; ipselffree(p); @@ -783,12 +783,44 @@ dumpselftab(void) continue; count = 0; for(; p != nil && count++ < 6; p = p->next) - print("(%i %d %lux)", p->a, p->type, p); + print("(%I %d %lux)", p->a, p->type, p); print("\n"); } qunlock(&selftab); } +static char *stformat = "%-32.32I %2.2d %4.4s\n"; +enum +{ + Nstformat= 41, +}; + +long +ipselftabread(char *cp, ulong offset, int n) +{ + int i, m, nifc; + Ipself *p; + Iplink *link; + char state[8]; + + m = 0; + qlock(&selftab); + for(i = 0; i < NHASH && m < n; i++){ + for(p = selftab.hash[i]; p != nil && m < n; p = p->next){ + if(offset == 0){ + nifc = 0; + for(link = p->link; link; link = link->selflink) + nifc++; + routetype(p->type, state); + m += snprint(cp + m, n - m, stformat, p->a, nifc, state); + } + offset -= Nstformat; + } + } + qunlock(&selftab); + return m; +} + /* * returns diff --git a/ip/iproute.c b/ip/iproute.c index e801a7767ad4d37791d4ea63e2cc0149289dbd47..c2dfe9fbe0d49f6f0956f07bfa35cf3fc77a6908 100644 --- a/ip/iproute.c +++ b/ip/iproute.c @@ -544,6 +544,27 @@ next: ; return q; } +void +routetype(int type, char *p) +{ + memset(p, ' ', 4); + p[4] = 0; + if(type & Rv4) + *p++ = '4'; + else + *p++ = '6'; + if(type & Rifc) + *p++ = 'i'; + if(type & Runi) + *p++ = 'u'; + else if(type & Rbcast) + *p++ = 'b'; + else if(type & Rmulti) + *p++ = 'm'; + if(type & Rptpt) + *p = 'p'; +} + enum { Rlinelen= 89, @@ -555,7 +576,6 @@ void convroute(Route *r, uchar *addr, uchar *mask, uchar *gate, char *t, int *nifc) { int i; - char *p = t; if(r->type & Rv4){ memmove(addr, v4prefix, IPv4off); @@ -572,22 +592,7 @@ convroute(Route *r, uchar *addr, uchar *mask, uchar *gate, char *t, int *nifc) memmove(gate, r->v6.gate, IPaddrlen); } - memset(t, ' ', 4); - t[4] = 0; - if(r->type & Rv4) - *p++ = '4'; - else - *p++ = '6'; - if(r->type & Rifc) - *p++ = 'i'; - if(r->type & Runi) - *p++ = 'u'; - else if(r->type & Rbcast) - *p++ = 'b'; - else if(r->type & Rmulti) - *p++ = 'm'; - if(r->type & Rptpt) - *p = 'p'; + routetype(r->type, t); if(r->ifc) *nifc = r->ifc->conv->x; diff --git a/port/devproc.c b/port/devproc.c index 7f714dbb3bdd0fc93d3d47eaac69335197518446..5ccfdddb52f9c408fa55be0f86f2757ee7fb46eb 100644 --- a/port/devproc.c +++ b/port/devproc.c @@ -24,12 +24,14 @@ enum Qtext, Qwait, Qprofile, + Qfd, }; #define STATSIZE (2*NAMELEN+12+9*12) Dirtab procdir[] = { "ctl", {Qctl}, 0, 0000, + "fd", {Qfd}, 0, 0000, "fpregs", {Qfpregs}, sizeof(FPsave), 0000, "kregs", {Qkregs}, sizeof(Ureg), 0000, "mem", {Qmem}, 0, 0000, @@ -57,10 +59,10 @@ char *sname[]={ "Text", "Data", "Bss", "Stack", "Shared", "Phys", "Shdata", "Map * 32 bits of pid, for consistency checking * If notepg, c->pgrpid.path is pgrp slot, .vers is noteid. */ -#define QSHIFT 4 /* location in qid of proc slot # */ +#define QSHIFT 5 /* location in qid of proc slot # */ -#define QID(q) (((q).path&0x0000000F)>>0) -#define SLOT(q) ((((q).path&0x07FFFFFF0)>>QSHIFT)-1) +#define QID(q) (((q).path&0x0000001F)>>0) +#define SLOT(q) ((((q).path&0x07FFFFFE0)>>QSHIFT)-1) #define PID(q) ((q).vers) #define NOTEID(q) ((q).vers) @@ -183,6 +185,7 @@ procopen(Chan *c, int omode) case Qkregs: case Qsegment: case Qprofile: + case Qfd: if(omode != OREAD) error(Eperm); break; @@ -242,6 +245,37 @@ procwstat(Chan *c, char *db) p->procmode = d.mode&0777; } +static int +procfds(Fgrp *f, char *va, int count, long offset) +{ + Chan *c; + int n, i; + + n = 0; + for(i = 0; i <= f->maxfd; i++) { + c = f->fd[i]; + if(c == nil) + continue; + n += snprint(va+n, count-n, "%3d %.2s %.8lux.%.8d %8d ", + i, + &"r w rw"[(c->mode&3)<<1], + c->qid.path, c->qid.vers, + c->offset); + n += ptpath(c->path, va+n, count-n); + n += snprint(va+n, count-n, "\n"); + if(offset > 0) { + offset -= n; + if(offset < 0) { + memmove(va, va+n+offset, -offset); + n = -offset; + } + else + n = 0; + } + } + return n; +} + static void procclose(Chan * c) { @@ -483,6 +517,8 @@ procread(Chan *c, void *va, long n, ulong offset) return a - (char*)va; case Qnoteid: return readnum(offset, va, n, p->noteid, NUMSIZE); + case Qfd: + return procfds(p->fgrp, va, n, offset); } error(Egreg); return 0; /* not reached */