7 typedef struct Hdr Hdr;
10 uchar vihl; /* Version and header length */
11 uchar tos; /* Type of service */
12 uchar length[2]; /* packet length */
13 uchar id[2]; /* ip->identification */
14 uchar frag[2]; /* Fragment information */
15 uchar ttl; /* Time to live */
16 uchar proto; /* Protocol */
17 uchar cksum[2]; /* Header checksum */
18 uchar src[4]; /* IP source */
19 uchar dst[4]; /* IP destination */
24 IPHDR = 20, /* sizeof(Iphdr) */
25 IP_VER = 0x40, /* Using IP version 4 */
26 IP_DF = 0x4000, /* Don't fragment */
27 IP_MF = 0x2000, /* More fragments */
41 { "bbn-rcc-mon", 10, },
101 { "br-sat-mon", 76, },
107 { "secure-vmtp", 82, },
110 { "nsfnet-igp", 85, },
115 { "sprite-rpc", 90, },
133 Od, /* destination */
134 Osd, /* source or destination */
138 static Field p_fields[] =
140 {"s", Fv4ip, Os, "source address", } ,
141 {"d", Fv4ip, Od, "destination address", } ,
142 {"a", Fv4ip, Osd, "source|destination address",} ,
143 {"sd", Fv4ip, Osd, "source|destination address",} ,
144 {"t", Fnum, Ot, "sub protocol number", } ,
154 compile_cmp(ip.name, f, p_fields);
157 for(m = p_mux; m->name != nil; m++)
158 if(strcmp(f->s, m->name) == 0){
164 sysfatal("unknown ip field or protocol: %s", f->s);
168 p_filter(Filter *f, Msg *m)
172 if(m->pe - m->ps < IPHDR)
176 m->ps += (h->vihl & 0xf) << 2;
180 return NetL(h->src) == f->ulv;
182 return NetL(h->dst) == f->ulv;
184 return NetL(h->src) == f->ulv || NetL(h->dst) == f->ulv;
186 return h->proto == f->ulv;
197 if(m->pe - m->ps < IPHDR)
201 /* next protocol, just dump unless this is the first fragment */
204 if((f & ~(IP_DF|IP_MF)) == 0)
205 demux(p_mux, h->proto, h->proto, m, &dump);
207 /* truncate the message if there's extra */
208 len = NetS(h->length);
209 if(len < m->pe - m->ps)
213 m->ps += (h->vihl &0xf) << 2;
215 m->p = seprint(m->p, m->e, "s=%V d=%V id=%4.4ux frag=%4.4ux ttl=%3d pr=%d ln=%d",
216 h->src, h->dst, NetS(h->id), NetS(h->frag), h->ttl, h->proto,