From 20937040b8535ab51737146586f8bab3ce689091 Mon Sep 17 00:00:00 2001 From: hannes Date: Thu, 14 Jul 2005 16:01:46 +0000 Subject: per suggestion from Paolo Lucente : centralize the MPLS check into gen_linktype() and backout the specific checks in gen_proto_abrev(), gen_proto(), gen_host() this adds as a by-product support for IPv6 --- gencode.c | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/gencode.c b/gencode.c index 4bd3c7d..e0ef7a7 100644 --- a/gencode.c +++ b/gencode.c @@ -21,7 +21,7 @@ */ #ifndef lint static const char rcsid[] _U_ = - "@(#) $Header: /tcpdump/master/libpcap/gencode.c,v 1.221.2.26 2005-07-11 13:58:52 hannes Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/libpcap/gencode.c,v 1.221.2.27 2005-07-14 16:01:46 hannes Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -1853,6 +1853,23 @@ gen_linktype(proto) { struct block *b0, *b1, *b2; + /* has the linktype been poisoned by MPLS expression ? */ + if (off_linktype == (u_int)-1) { + switch(proto) { + /* FIXME add other L3 proto IDs */ + case ETHERTYPE_IP: + case PPP_IP: + return gen_null(Q_IP); + /* FIXME add other L3 proto IDs */ + case ETHERTYPE_IPV6: + case PPP_IPV6: + return gen_null(Q_IPV6); + default: + bpf_error("unsupported protocol over mpls"); + /* NOTREACHED */ + } + } + switch (linktype) { case DLT_EN10MB: @@ -2450,10 +2467,7 @@ gen_hostop(addr, mask, dir, proto, src_off, dst_off) default: abort(); } - if (off_linktype != (u_int)-1) - b0 = gen_linktype(proto); - else - b0 = gen_null(Q_IP); + b0 = gen_linktype(proto); b1 = gen_mcmp(OR_NET, offset, BPF_W, (bpf_int32)addr, mask); gen_and(b0, b1); return b1; @@ -3438,10 +3452,7 @@ gen_proto_abbrev(proto) break; case Q_IP: - if (off_linktype != (u_int)-1) - b1 = gen_linktype(ETHERTYPE_IP); - else - b1 = gen_null(Q_IP); + b1 = gen_linktype(ETHERTYPE_IP); break; case Q_ARP: @@ -4434,10 +4445,7 @@ gen_proto(v, proto, dir) * So we always check for ETHERTYPE_IP. */ - if (off_linktype != (u_int)-1) - b0 = gen_linktype(ETHERTYPE_IP); - else - b0 = gen_null(Q_IP); + b0 = gen_linktype(ETHERTYPE_IP); #ifndef CHASE_CHAIN b1 = gen_cmp(OR_NET, 9, BPF_B, (bpf_int32)v); #else -- cgit v1.2.3