diff options
author | rsc <devnull@localhost> | 2006-02-14 19:42:28 +0000 |
---|---|---|
committer | rsc <devnull@localhost> | 2006-02-14 19:42:28 +0000 |
commit | a38a183626848f897085b4d2e54dad6d39146948 (patch) | |
tree | 208277c8824b8db08878f5f5d65fb1e484099ead /src/cmd/ip | |
parent | 2eef1fa31676e58b0038f1c02dcc8df5e23149e6 (diff) | |
download | plan9port-a38a183626848f897085b4d2e54dad6d39146948.tar.gz plan9port-a38a183626848f897085b4d2e54dad6d39146948.tar.bz2 plan9port-a38a183626848f897085b4d2e54dad6d39146948.zip |
fixes
Diffstat (limited to 'src/cmd/ip')
-rwxr-xr-x | src/cmd/ip/snoopy/arp.c | 2 | ||||
-rwxr-xr-x | src/cmd/ip/snoopy/bootp.c | 1 | ||||
-rwxr-xr-x | src/cmd/ip/snoopy/dat.h | 1 | ||||
-rwxr-xr-x | src/cmd/ip/snoopy/dhcp.c | 13 | ||||
-rwxr-xr-x | src/cmd/ip/snoopy/dump.c | 19 | ||||
-rwxr-xr-x | src/cmd/ip/snoopy/ether.c | 2 | ||||
-rwxr-xr-x | src/cmd/ip/snoopy/filter.y | 33 | ||||
-rwxr-xr-x | src/cmd/ip/snoopy/hdlc.c | 1 | ||||
-rwxr-xr-x | src/cmd/ip/snoopy/icmp.c | 1 | ||||
-rwxr-xr-x | src/cmd/ip/snoopy/icmp6.c | 1 | ||||
-rwxr-xr-x | src/cmd/ip/snoopy/il.c | 1 | ||||
-rwxr-xr-x | src/cmd/ip/snoopy/ip.c | 1 | ||||
-rwxr-xr-x | src/cmd/ip/snoopy/ip6.c | 1 | ||||
-rwxr-xr-x | src/cmd/ip/snoopy/main.c | 161 | ||||
-rwxr-xr-x | src/cmd/ip/snoopy/ninep.c | 19 | ||||
-rwxr-xr-x | src/cmd/ip/snoopy/ospf.c | 24 | ||||
-rwxr-xr-x | src/cmd/ip/snoopy/ppp.c | 6 | ||||
-rwxr-xr-x | src/cmd/ip/snoopy/pppoe_disc.c | 2 | ||||
-rwxr-xr-x | src/cmd/ip/snoopy/rtcp.c | 20 | ||||
-rwxr-xr-x | src/cmd/ip/snoopy/rtp.c | 20 | ||||
-rwxr-xr-x | src/cmd/ip/snoopy/tcp.c | 1 | ||||
-rwxr-xr-x | src/cmd/ip/snoopy/udp.c | 1 |
22 files changed, 187 insertions, 144 deletions
diff --git a/src/cmd/ip/snoopy/arp.c b/src/cmd/ip/snoopy/arp.c index 3433ebc6..061a6d9d 100755 --- a/src/cmd/ip/snoopy/arp.c +++ b/src/cmd/ip/snoopy/arp.c @@ -112,6 +112,7 @@ Proto arp = p_filter, p_seprint, nil, + nil, p_fields, defaultframer, }; @@ -123,6 +124,7 @@ Proto rarp = p_filter, p_seprint, nil, + nil, p_fields, defaultframer, }; diff --git a/src/cmd/ip/snoopy/bootp.c b/src/cmd/ip/snoopy/bootp.c index 1adfdad1..31b2b0e0 100755 --- a/src/cmd/ip/snoopy/bootp.c +++ b/src/cmd/ip/snoopy/bootp.c @@ -171,6 +171,7 @@ Proto bootp = p_filter, p_seprint, p_mux, + "%#.8lux", p_fields, defaultframer, }; diff --git a/src/cmd/ip/snoopy/dat.h b/src/cmd/ip/snoopy/dat.h index a4258c25..49734a78 100755 --- a/src/cmd/ip/snoopy/dat.h +++ b/src/cmd/ip/snoopy/dat.h @@ -18,6 +18,7 @@ struct Proto int (*filter)(Filter*, Msg*); int (*seprint)(Msg*); Mux* mux; + char* valfmt; Field* field; int (*framer)(int, uchar*, int); }; diff --git a/src/cmd/ip/snoopy/dhcp.c b/src/cmd/ip/snoopy/dhcp.c index 8b7649cf..2d041f8b 100755 --- a/src/cmd/ip/snoopy/dhcp.c +++ b/src/cmd/ip/snoopy/dhcp.c @@ -106,15 +106,7 @@ enum static void p_compile(Filter *f) { - sysfatal("unknown bootp field: %s", f->s); -} - -static int -p_filter(Filter *f, Msg *m) -{ - USED(f); - USED(m); - return 0; + sysfatal("unknown dhcp field: %s", f->s); } /* @@ -474,10 +466,11 @@ Proto dhcp = { "dhcp", p_compile, - p_filter, + nil, p_seprint, nil, nil, + nil, defaultframer, }; diff --git a/src/cmd/ip/snoopy/dump.c b/src/cmd/ip/snoopy/dump.c index 5174e4fc..227ac641 100755 --- a/src/cmd/ip/snoopy/dump.c +++ b/src/cmd/ip/snoopy/dump.c @@ -5,20 +5,6 @@ #include "dat.h" #include "protos.h" -static void -p_compile(Filter *f) -{ - USED(f); -} - -static int -p_filter(Filter *f, Msg *m) -{ - USED(f); - USED(m); - return 0; -} - static char tohex[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' @@ -83,10 +69,11 @@ p_seprint(Msg *m) Proto dump = { "dump", - p_compile, - p_filter, + nil, + nil, p_seprint, nil, nil, + nil, defaultframer, }; diff --git a/src/cmd/ip/snoopy/ether.c b/src/cmd/ip/snoopy/ether.c index 62ec485d..7e1f0a7f 100755 --- a/src/cmd/ip/snoopy/ether.c +++ b/src/cmd/ip/snoopy/ether.c @@ -23,6 +23,7 @@ static Mux p_mux[] = {"ip6", 0x86dd, } , {"pppoe_disc", 0x8863, }, {"pppoe_sess", 0x8864, }, + {"eapol", 0x888e, }, {0} }; @@ -116,6 +117,7 @@ Proto ether = p_filter, p_seprint, p_mux, + "%#.4lux", p_fields, defaultframer }; diff --git a/src/cmd/ip/snoopy/filter.y b/src/cmd/ip/snoopy/filter.y index d34bfc7c..10b6ddef 100755 --- a/src/cmd/ip/snoopy/filter.y +++ b/src/cmd/ip/snoopy/filter.y @@ -12,6 +12,7 @@ char *yyend; /* end of buffer to be parsed */ %term LOR %term LAND %term WORD +%term NE %right '!' %left '|' %left '&' @@ -27,6 +28,14 @@ expr : WORD { $$ = $1; } | WORD '=' WORD { $2->l = $1; $2->r = $3; $$ = $2; } + | WORD NE WORD + { $2->l = newfilter(); + $2->l->op = '='; + $2->l->l = $1; + $2->l->r = $3; + $2->op = '!'; + $$ = $2; + } | WORD '(' expr ')' { $1->l = $3; free($2); free($4); $$ = $1; } | '(' expr ')' @@ -84,17 +93,18 @@ yylex(void) } yylp++; - if(*yylp == c) - switch(c){ - case '&': - c = LAND; - yylp++; - break; - case '|': - c = LOR; - yylp++; - break; - } + if(c == '!' && *yylp == '='){ + c = NE; + yylp++; + } + else if(c == '&' && *yylp == '&'){ + c = LAND; + yylp++; + } + else if(c == '|' && *yylp == '|'){ + c = LOR; + yylp++; + } yylval->op = c; return c; } @@ -103,5 +113,6 @@ void yyerror(char *e) { USED(e); +// longjmp(errjmp, 1); sysfatal("error parsing filter"); } diff --git a/src/cmd/ip/snoopy/hdlc.c b/src/cmd/ip/snoopy/hdlc.c index bed0c35a..fdf2aaac 100755 --- a/src/cmd/ip/snoopy/hdlc.c +++ b/src/cmd/ip/snoopy/hdlc.c @@ -169,6 +169,7 @@ Proto hdlc = p_filter, p_seprint, p_mux, + "%#.4lux", nil, p_framer, }; diff --git a/src/cmd/ip/snoopy/icmp.c b/src/cmd/ip/snoopy/icmp.c index cf286d87..274c955e 100755 --- a/src/cmd/ip/snoopy/icmp.c +++ b/src/cmd/ip/snoopy/icmp.c @@ -191,6 +191,7 @@ Proto icmp = p_filter, p_seprint, p_mux, + "%lud", p_fields, defaultframer, }; diff --git a/src/cmd/ip/snoopy/icmp6.c b/src/cmd/ip/snoopy/icmp6.c index 9c154f88..ad33610f 100755 --- a/src/cmd/ip/snoopy/icmp6.c +++ b/src/cmd/ip/snoopy/icmp6.c @@ -423,6 +423,7 @@ Proto icmp6 = p_filter, p_seprint, p_mux, + "%lud", p_fields, defaultframer, }; diff --git a/src/cmd/ip/snoopy/il.c b/src/cmd/ip/snoopy/il.c index d75a80cd..46bd2811 100755 --- a/src/cmd/ip/snoopy/il.c +++ b/src/cmd/ip/snoopy/il.c @@ -141,6 +141,7 @@ Proto il = p_filter, p_seprint, p_mux, + "%lud", p_fields, defaultframer, }; diff --git a/src/cmd/ip/snoopy/ip.c b/src/cmd/ip/snoopy/ip.c index e321e2fe..fe836eba 100755 --- a/src/cmd/ip/snoopy/ip.c +++ b/src/cmd/ip/snoopy/ip.c @@ -231,6 +231,7 @@ Proto ip = p_filter, p_seprint, p_mux, + "%lud", p_fields, defaultframer, }; diff --git a/src/cmd/ip/snoopy/ip6.c b/src/cmd/ip/snoopy/ip6.c index 7fdc9679..eea4ba0d 100755 --- a/src/cmd/ip/snoopy/ip6.c +++ b/src/cmd/ip/snoopy/ip6.c @@ -304,6 +304,7 @@ Proto ip6 = p_filter, p_seprint, p_mux, + "%lud", p_fields, defaultframer, }; diff --git a/src/cmd/ip/snoopy/main.c b/src/cmd/ip/snoopy/main.c index 73c1e27b..cf43e5c0 100755 --- a/src/cmd/ip/snoopy/main.c +++ b/src/cmd/ip/snoopy/main.c @@ -35,14 +35,21 @@ void mkprotograph(void); Proto* findproto(char *name); Filter* compile(Filter *f); void printfilter(Filter *f, char *tag); -void printhelp(void); +void printhelp(char*); void tracepkt(uchar*, int); void pcaphdr(void); void +printusage(void) +{ + fprint(2, "usage: %s [-CDdpst] [-N n] [-f filter] [-h first-header] path\n", argv0); + fprint(2, " for protocol help: %s -? [proto]\n", argv0); +} + +void usage(void) { - fprint(2, "usage: %s [-std?] [-c] [-N n] [-f filter] [-h first-header] path", argv0); + printusage(); exits("usage"); } @@ -74,20 +81,19 @@ main(int argc, char **argv) mkprotograph(); ARGBEGIN{ + default: + usage(); case '?': - printhelp(); + printusage(); + printhelp(ARGF()); exits(0); break; case 'N': - p = ARGF(); - if(p == nil) - usage(); + p = EARGF(usage()); Nflag = atoi(p); break; case 'f': - p = ARGF(); - if(p == nil) - usage(); + p = EARGF(usage()); yyinit(p); yyparse(); break; @@ -95,9 +101,7 @@ main(int argc, char **argv) sflag = 1; break; case 'h': - p = ARGF(); - if(p == nil) - usage(); + p = EARGF(usage()); root = findproto(p); if(root == nil) sysfatal("unknown protocol: %s", p); @@ -123,22 +127,28 @@ main(int argc, char **argv) if(pcap) pcaphdr(); + if(argc > 1) + usage(); + if(argc == 0) file = nil; else file = argv[0]; if(tiflag){ + if(file == nil) + sysfatal("must specify file with -t"); fd = open(file, OREAD); if(fd < 0) sysfatal("opening %s: %r", file); }else{ fd = opendevice(file, pflag); if(fd < 0) - sysfatal("opening device %s: %r", file ? file : "(all)"); + sysfatal("opening device %s: %r", file); } if(root == nil) root = ðer; + filter = compile(filter); if(tiflag){ @@ -215,7 +225,7 @@ _filterpkt(Filter *f, Msg *m) return 0; m->needroot = 0; }else{ - if(m->pr != nil && !(m->pr->filter)(f, m)) + if(m->pr && (m->pr->filter==nil || !(m->pr->filter)(f, m))) return 0; } if(f->l == nil) @@ -313,13 +323,10 @@ void printpkt(char *p, char *e, uchar *ps, uchar *pe) { Msg m; - uvlong dt; - Tm tm; - - tm = *localtime(pkttime/1000000000LL); - m.p = seprint(p, e, "%02d/%02d/%04d %02d:%02d:%02d.%09lld", - tm.mon+1, tm.mday, tm.year+1900, tm.hour, tm.min, tm.sec, - pkttime%1000000000LL); + ulong dt; + + dt = (pkttime-starttime)/1000000LL; + m.p = seprint(p, e, "%6.6uld ms ", dt); m.ps = ps; m.pe = pe; m.e = e; @@ -635,14 +642,20 @@ _compile(Filter *f, Proto *last) _compile(f->r, last); break; case WORD: - if(last != nil) + if(last != nil){ + if(last->compile == nil) + sysfatal("unknown %s subprotocol: %s", f->pr->name, f->s); (*last->compile)(f); + } if(f->l) _compile(f->l, f->pr); break; case '=': if(last == nil) sysfatal("internal error: compilewalk: badly formed tree"); + + if(last->compile == nil) + sysfatal("unknown %s field: %s", f->pr->name, f->s); (*last->compile)(f); break; default: @@ -759,9 +772,9 @@ _pf(Filter *f) case WORD: fprint(2, "%s", f->s); if(f->l != nil){ - fprint(2, "( "); + fprint(2, "("); _pf(f->l); - fprint(2, " )"); + fprint(2, ")"); } break; case LAND: @@ -794,24 +807,96 @@ printfilter(Filter *f, char *tag) } void -printhelp(void) +cat(void) +{ + char buf[1024]; + int n; + + while((n = read(0, buf, sizeof buf)) > 0) + write(1, buf, n); +} + +static int fd1 = -1; +void +startmc(void) +{ + int p[2]; + + if(fd1 == -1) + fd1 = dup(1, -1); + + if(pipe(p) < 0) + return; + switch(fork()){ + case -1: + return; + default: + close(p[0]); + dup(p[1], 1); + if(p[1] != 1) + close(p[1]); + return; + case 0: + close(p[1]); + dup(p[0], 0); + if(p[0] != 0) + close(p[0]); + execl("/bin/mc", "mc", nil); + cat(); + _exits(0); + } +} + +void +stopmc(void) { + close(1); + dup(fd1, 1); + waitpid(); +} + +void +printhelp(char *name) +{ + int len; Proto *pr, **l; Mux *m; Field *f; - - for(l = protos; *l != nil; l++){ - pr = *l; - if(pr->field != nil){ - print("%s's filter attr:\n", pr->name); - for(f = pr->field; f->name != nil; f++) - print("\t%s\t- %s\n", f->name, f->help); - } - if(pr->mux != nil){ - print("%s's subprotos:\n", pr->name); - for(m = pr->mux; m->name != nil; m++) - print("\t%s\n", m->name); - } + char fmt[40]; + + if(name == nil){ + print("protocols:\n"); + startmc(); + for(l=protos; (pr=*l) != nil; l++) + print(" %s\n", pr->name); + stopmc(); + return; + } + + pr = findproto(name); + if(pr == nil){ + print("unknown protocol %s\n", name); + return; + } + + if(pr->field){ + print("%s's filter attributes:\n", pr->name); + len = 0; + for(f=pr->field; f->name; f++) + if(len < strlen(f->name)) + len = strlen(f->name); + startmc(); + for(f=pr->field; f->name; f++) + print(" %-*s - %s\n", len, f->name, f->help); + stopmc(); + } + if(pr->mux){ + print("%s's subprotos:\n", pr->name); + startmc(); + snprint(fmt, sizeof fmt, " %s %%s\n", pr->valfmt); + for(m=pr->mux; m->name != nil; m++) + print(fmt, m->val, m->name); + stopmc(); } } diff --git a/src/cmd/ip/snoopy/ninep.c b/src/cmd/ip/snoopy/ninep.c index 8e7a8d4e..a3e40d34 100755 --- a/src/cmd/ip/snoopy/ninep.c +++ b/src/cmd/ip/snoopy/ninep.c @@ -5,20 +5,6 @@ #include "dat.h" #include "protos.h" -static void -p_compile(Filter *f) -{ - sysfatal("unknown ninep field: %s", f->s); -} - -static int -p_filter(Filter *f, Msg *m) -{ - USED(f); - USED(m); - return 0; -} - static int p_seprint(Msg *m) { @@ -46,10 +32,11 @@ p_seprint(Msg *m) Proto ninep = { "ninep", - p_compile, - p_filter, + nil, + nil, p_seprint, nil, nil, + nil, defaultframer, }; diff --git a/src/cmd/ip/snoopy/ospf.c b/src/cmd/ip/snoopy/ospf.c index 35ed55e1..10da17cd 100755 --- a/src/cmd/ip/snoopy/ospf.c +++ b/src/cmd/ip/snoopy/ospf.c @@ -90,11 +90,10 @@ struct Ospfhello }; char* -seprintospfhello(char *p, char *e, void *a, int x) +seprintospfhello(char *p, char *e, void *a) { Ospfhello *h = a; - USED(x); return seprint(p, e, "%s(mask %V interval %d opt %ux pri %ux deadt %d designated %V bdesignated %V)", ospftype[OSPFhello], h->mask, NetS(h->interval), h->options, h->pri, @@ -328,20 +327,6 @@ seprintospflsack(char *p, char *e, void *a, int len) return seprint(p, e, ")"); } -static void -p_compile(Filter *f) -{ - sysfatal("unknown ospf field: %s", f->s); -} - -static int -p_filter(Filter *f, Msg *m) -{ - USED(f); - USED(m); - return 0; -} - int p_seprint(Msg *m) { @@ -369,7 +354,7 @@ p_seprint(Msg *m) switch (ospf->type) { case OSPFhello: - p = seprintospfhello(p, e, ospf->data, x); + p = seprintospfhello(p, e, ospf->data); break; case OSPFdd: p = seprintospfdatadesc(p, e, ospf->data, x); @@ -395,10 +380,11 @@ Default: Proto ospf = { "ospf", - p_compile, - p_filter, + nil, + nil, p_seprint, nil, nil, + nil, defaultframer, }; diff --git a/src/cmd/ip/snoopy/ppp.c b/src/cmd/ip/snoopy/ppp.c index 5c497a8c..3c36e437 100755 --- a/src/cmd/ip/snoopy/ppp.c +++ b/src/cmd/ip/snoopy/ppp.c @@ -569,6 +569,7 @@ Proto ppp = p_filter, p_seprint, p_mux, + "%#.4lux", nil, defaultframer, }; @@ -581,6 +582,7 @@ Proto ppp_ipcp = p_seprintipcp, nil, nil, + nil, defaultframer, }; @@ -592,6 +594,7 @@ Proto ppp_lcp = p_seprintlcp, nil, nil, + nil, defaultframer, }; @@ -603,6 +606,7 @@ Proto ppp_ccp = p_seprintccp, nil, nil, + nil, defaultframer, }; @@ -614,6 +618,7 @@ Proto ppp_chap = p_seprintchap, nil, nil, + nil, defaultframer, }; @@ -625,5 +630,6 @@ Proto ppp_comp = p_seprintcomp, nil, nil, + nil, defaultframer, }; diff --git a/src/cmd/ip/snoopy/pppoe_disc.c b/src/cmd/ip/snoopy/pppoe_disc.c index 4f17ebd7..c8a5aeba 100755 --- a/src/cmd/ip/snoopy/pppoe_disc.c +++ b/src/cmd/ip/snoopy/pppoe_disc.c @@ -155,6 +155,7 @@ Proto pppoe_disc = p_filter, p_seprintdisc, p_mux, + "%lud", p_fields, defaultframer }; @@ -166,6 +167,7 @@ Proto pppoe_sess = p_filter, p_seprintsess, p_mux, + "%lud", p_fields, defaultframer }; diff --git a/src/cmd/ip/snoopy/rtcp.c b/src/cmd/ip/snoopy/rtcp.c index 1036caaf..939f78db 100755 --- a/src/cmd/ip/snoopy/rtcp.c +++ b/src/cmd/ip/snoopy/rtcp.c @@ -31,21 +31,6 @@ enum{ REPORTLEN = 24, }; - -static void -p_compile(Filter *f) -{ - sysfatal("unknown rtcp field: %s", f->s); -} - -static int -p_filter(Filter *f, Msg *m) -{ - USED(f); - USED(m); - return 0; -} - static int p_seprint(Msg *m) { @@ -88,10 +73,11 @@ p_seprint(Msg *m) Proto rtcp = { "rtcp", - p_compile, - p_filter, + nil, + nil, p_seprint, nil, nil, + nil, defaultframer, }; diff --git a/src/cmd/ip/snoopy/rtp.c b/src/cmd/ip/snoopy/rtp.c index 1e8e5ab8..e9160711 100755 --- a/src/cmd/ip/snoopy/rtp.c +++ b/src/cmd/ip/snoopy/rtp.c @@ -17,21 +17,6 @@ enum{ RTPLEN = 12, // Minimum size of an RTP header }; - -static void -p_compile(Filter *f) -{ - sysfatal("unknown rtp field: %s", f->s); -} - -static int -p_filter(Filter *f, Msg *m) -{ - USED(f); - USED(m); - return 0; -} - static int p_seprint(Msg *m) { @@ -67,10 +52,11 @@ p_seprint(Msg *m) Proto rtp = { "rtp", - p_compile, - p_filter, + nil, + nil, p_seprint, nil, nil, + nil, defaultframer, }; diff --git a/src/cmd/ip/snoopy/tcp.c b/src/cmd/ip/snoopy/tcp.c index 31ad5663..1e7f0793 100755 --- a/src/cmd/ip/snoopy/tcp.c +++ b/src/cmd/ip/snoopy/tcp.c @@ -216,6 +216,7 @@ Proto tcp = p_filter, p_seprint, p_mux, + "%lud", p_fields, defaultframer, }; diff --git a/src/cmd/ip/snoopy/udp.c b/src/cmd/ip/snoopy/udp.c index 43d2b6f6..a83c6f13 100755 --- a/src/cmd/ip/snoopy/udp.c +++ b/src/cmd/ip/snoopy/udp.c @@ -126,6 +126,7 @@ Proto udp = p_filter, p_seprint, p_mux, + "%lud", p_fields, defaultframer, }; |