Skip to content

Commit

Permalink
Plan 9 from Bell Labs 2003-04-04
Browse files Browse the repository at this point in the history
  • Loading branch information
0intro committed Apr 4, 2003
1 parent 9b40ec7 commit dfffd21
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 37 deletions.
1 change: 1 addition & 0 deletions boot/bootip.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ configip(void)
case -1:
fatal("configuring ip: %r");
case 0:
print("exec-ing ipconfig\n");
exec("/boot/ipconfig", arg);
fatal("execing /ipconfig");
default:
Expand Down
2 changes: 1 addition & 1 deletion ip/ip.h
Original file line number Diff line number Diff line change
Expand Up @@ -440,10 +440,10 @@ enum

struct Routewalk
{
int n;
int o;
int h;
char* p;
char* e;
void* state;
void (*walk)(Route*, Routewalk*);
};
Expand Down
18 changes: 11 additions & 7 deletions ip/ipaux.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,13 +282,16 @@ eipfmt(Fmt *f)
switch(f->r) {
case 'E': /* Ethernet address */
p = va_arg(f->args, uchar*);
return fmtprint(f, efmt, p[0], p[1], p[2], p[3], p[4], p[5]);
snprint(buf, sizeof buf, efmt, p[0], p[1], p[2], p[3], p[4], p[5]);
return fmtstrcpy(f, buf);

case 'I': /* Ip address */
p = va_arg(f->args, uchar*);
common:
if(memcmp(p, v4prefix, 12) == 0)
return fmtprint(f, ifmt, p[12], p[13], p[14], p[15]);
if(memcmp(p, v4prefix, 12) == 0){
snprint(buf, sizeof buf, ifmt, p[12], p[13], p[14], p[15]);
return fmtstrcpy(f, buf);
}

/* find longest elision */
eln = eli = -1;
Expand Down Expand Up @@ -326,7 +329,8 @@ eipfmt(Fmt *f)

case 'V': /* v4 ip address */
p = va_arg(f->args, uchar*);
return fmtprint(f, ifmt, p[0], p[1], p[2], p[3]);
snprint(buf, sizeof buf, ifmt, p[0], p[1], p[2], p[3]);
return fmtstrcpy(f, buf);

case 'M': /* ip mask */
p = va_arg(f->args, uchar*);
Expand All @@ -346,10 +350,10 @@ eipfmt(Fmt *f)
n = 8*16;

/* got one, use /xx format */
return fmtprint(f, "/%d", n);

snprint(buf, sizeof buf, "/%d", n);
return fmtstrcpy(f, buf);
}
return fmtprint(f, "(eipfmt)");
return fmtstrcpy(f, "(eipfmt)");
}

#define CLASS(p) ((*(uchar*)(p))>>6)
Expand Down
53 changes: 24 additions & 29 deletions ip/iproute.c
Original file line number Diff line number Diff line change
Expand Up @@ -617,12 +617,7 @@ routetype(int type, char *p)
*p = 'p';
}

enum
{
Rlinelen= 137,
};

char *rformat = "%-40.40I %-40.40M %-40.40I %4.4s %4.4s %3s\n";
char *rformat = "%-15I %-4M %-15I %4.4s %4.4s %3s\n";

void
convroute(Route *r, uchar *addr, uchar *mask, uchar *gate, char *t, int *nifc)
Expand Down Expand Up @@ -658,21 +653,27 @@ convroute(Route *r, uchar *addr, uchar *mask, uchar *gate, char *t, int *nifc)
static void
sprintroute(Route *r, Routewalk *rw)
{
int nifc;
int nifc, n;
char t[5], *iname, ifbuf[5];
uchar addr[IPaddrlen], mask[IPaddrlen], gate[IPaddrlen];
char *p;

if(rw->o >= 0) {
convroute(r, addr, mask, gate, t, &nifc);
iname = "-";
if(nifc != -1) {
iname = ifbuf;
sprint(ifbuf, "%d", nifc);
}
sprint(rw->p, rformat, addr, mask, gate, t, r->tag, iname);
rw->p += Rlinelen;
convroute(r, addr, mask, gate, t, &nifc);
iname = "-";
if(nifc != -1) {
iname = ifbuf;
sprint(ifbuf, "%d", nifc);
}
rw->o++;
p = seprint(rw->p, rw->e, rformat, addr, mask, gate, t, r->tag, iname);
if(rw->o < 0){
n = p - rw->p;
if(n > -rw->o){
memmove(rw->p, rw->p-rw->o, n+rw->o);
rw->p = p + rw->o;
}
rw->o += n;
} else
rw->p = p;
}

/*
Expand All @@ -683,7 +684,7 @@ rr(Route *r, Routewalk *rw)
{
int h;

if(rw->n <= rw->o)
if(rw->e <= rw->p)
return 0;
if(r == nil)
return 1;
Expand All @@ -709,12 +710,12 @@ void
ipwalkroutes(Fs *f, Routewalk *rw)
{
rlock(&routelock);
if(rw->n > rw->o) {
if(rw->e > rw->p) {
for(rw->h = 0; rw->h < nelem(f->v4root); rw->h++)
if(rr(f->v4root[rw->h], rw) == 0)
break;
}
if(rw->n > rw->o) {
if(rw->e > rw->p) {
for(rw->h = 0; rw->h < nelem(f->v6root); rw->h++)
if(rr(f->v6root[rw->h], rw) == 0)
break;
Expand All @@ -727,20 +728,14 @@ routeread(Fs *f, char *p, ulong offset, int n)
{
Routewalk rw;

if(offset % Rlinelen)
return 0;

rw.p = p;
rw.n = n/Rlinelen;
rw.o = -(offset/Rlinelen);
rw.e = p+n;
rw.o = -offset;
rw.walk = sprintroute;

ipwalkroutes(f, &rw);

if(rw.o < 0)
rw.o = 0;

return rw.o*Rlinelen;
return rw.p - p;
}

/*
Expand Down

0 comments on commit dfffd21

Please sign in to comment.