summaryrefslogtreecommitdiff
path: root/sys/src/cmd/ip
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@felloff.net>2022-09-18 12:35:47 +0000
committercinap_lenrek <cinap_lenrek@felloff.net>2022-09-18 12:35:47 +0000
commit373daa759c0548af932a49d1806eb6c937459e02 (patch)
treec52ccf047226e1333db824906b7372a1403c7eaf /sys/src/cmd/ip
parent73c37d2db941b91006fb10b7bc76dfbbe1ad72ba (diff)
snoopy: add "ippkt" protocol to demux ip packet interfaces without media header.
When using a packet interface, such as /net/ipifc/x as the packet-soucre, there is no media header and the ip protocol version has to be determined from the first byte. The ippkt protocol solves this, allowing one to decode both ipv4 and ipv6, such as: snoopy -h ippkt /net/ipifc/2
Diffstat (limited to 'sys/src/cmd/ip')
-rw-r--r--sys/src/cmd/ip/snoopy/ippkt.c82
-rw-r--r--sys/src/cmd/ip/snoopy/mkfile1
2 files changed, 83 insertions, 0 deletions
diff --git a/sys/src/cmd/ip/snoopy/ippkt.c b/sys/src/cmd/ip/snoopy/ippkt.c
new file mode 100644
index 000000000..c87d0e9f2
--- /dev/null
+++ b/sys/src/cmd/ip/snoopy/ippkt.c
@@ -0,0 +1,82 @@
+#include <u.h>
+#include <libc.h>
+#include <ip.h>
+#include "dat.h"
+#include "protos.h"
+
+static Mux p_mux[] =
+{
+ {"ip", 0x40, },
+ {"ip6", 0x60, },
+ {0}
+};
+
+enum
+{
+ Ot, /* ip type */
+};
+
+static Field p_fields[] =
+{
+ {"t", Fnum, Ot, "ip type" },
+ {0}
+};
+
+static void
+p_compile(Filter *f)
+{
+ Mux *m;
+
+ if(f->op == '='){
+ compile_cmp(ippkt.name, f, p_fields);
+ return;
+ }
+ for(m = p_mux; m->name != nil; m++)
+ if(strcmp(f->s, m->name) == 0){
+ f->pr = m->pr;
+ f->ulv = m->val;
+ f->subop = Ot;
+ return;
+ }
+ sysfatal("unknown ippkt field or protocol: %s", f->s);
+}
+
+static int
+p_filter(Filter *f, Msg *m)
+{
+ if(m->ps >= m->pe)
+ return 0;
+
+ switch(f->subop){
+ case Ot:
+ return (m->ps[0]&0xF0) == f->ulv;
+ }
+ return 0;
+}
+
+static int
+p_seprint(Msg *m)
+{
+ uint t;
+
+ if(m->ps >= m->pe)
+ return -1;
+
+ t = m->ps[0]&0xF0;
+ demux(p_mux, t, t, m, &dump);
+
+ m->p = seprint(m->p, m->e, "t=%2.2ux", t);
+ return 0;
+}
+
+Proto ippkt =
+{
+ "ippkt",
+ p_compile,
+ p_filter,
+ p_seprint,
+ p_mux,
+ "%#.2lux",
+ p_fields,
+ defaultframer
+};
diff --git a/sys/src/cmd/ip/snoopy/mkfile b/sys/src/cmd/ip/snoopy/mkfile
index c4d42bb82..00d901de0 100644
--- a/sys/src/cmd/ip/snoopy/mkfile
+++ b/sys/src/cmd/ip/snoopy/mkfile
@@ -20,6 +20,7 @@ PROTOS=\
eapol_key\
ether\
ipmux\
+ ippkt\
gre\
hdlc\
icmp6\