]> The Tcpdump Group git mirrors - libpcap/commitdiff
From Florent Drouin: add support for filtering on MTP2 frame types.
authorguy <guy>
Thu, 21 Dec 2006 19:45:03 +0000 (19:45 +0000)
committerguy <guy>
Thu, 21 Dec 2006 19:45:03 +0000 (19:45 +0000)
CREDITS
gencode.c
gencode.h
grammar.y
scanner.l

diff --git a/CREDITS b/CREDITS
index af937a7f77636110e36d3aeb1258cef015bf7684..d63f67330b43bbed7beeaf26ea4639ea03f5d43e 100644 (file)
--- a/CREDITS
+++ b/CREDITS
@@ -32,6 +32,7 @@ Additional people who have contributed patches:
        Dug Song                        <[email protected]>
        Eric Anderson                   <[email protected]>
         Erik de Castro Lopo             <[email protected]>
+       Florent Drouin                  <[email protected]>
        Franz Schaefer                  <[email protected]>
        Gianluca Varenni                <[email protected]>
        Gilbert Hoyek                   <[email protected]>
index 324749293d7f46f4889d1d2fbea6d3552bdbd100..fcc9c1cc02a851da07a20961556f70a55491ab51 100644 (file)
--- 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.44 2006-10-13 08:56:07 guy Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/libpcap/gencode.c,v 1.221.2.45 2006-12-21 19:45:03 guy Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -724,6 +724,11 @@ static u_int off_vpi;
 static u_int off_vci;
 static u_int off_proto;
 
+/*
+ * These are offsets for the MTP2 fields.
+ */
+static u_int off_li;
+
 /*
  * These are offsets for the MTP3 fields.
  */
@@ -790,6 +795,7 @@ init_linktype(p)
        /*
         * And assume we're not doing SS7.
         */
+       off_li = -1;
        off_sio = -1;
        off_opc = -1;
        off_dpc = -1;
@@ -1217,6 +1223,7 @@ init_linktype(p)
                return;
 
        case DLT_MTP2:
+               off_li = 2;
                off_sio = 3;
                off_opc = 4;
                off_dpc = 4;
@@ -6748,6 +6755,47 @@ gen_atmtype_abbrev(type)
        return b1;
 }
 
+/* 
+ * Filtering for MTP2 messages based on li value
+ * FISU, length is null
+ * LSU, length is 1 or 2
+ * MSU, length is 3 or more
+ */
+struct block *
+gen_mtp2type_abbrev(type)
+       int type;
+{
+       struct block *b0, *b1;
+
+       switch (type) {
+
+       case M_FISU:
+               if (linktype != DLT_MTP2)
+                       bpf_error("'fisu' supported only on MTP2");
+               /* gen_ncmp(offrel, offset, size, mask, jtype, reverse, value) */
+               b0 = gen_ncmp(OR_PACKET, off_li, BPF_B, 0x3f, BPF_JEQ, 0, 0);
+               break;
+
+       case M_LSU:
+               if (linktype != DLT_MTP2)
+                       bpf_error("'lsu' supported only on MTP2");
+               b0 = gen_ncmp(OR_PACKET, off_li, BPF_B, 0x3f, BPF_JGT, 1, 2);
+               b1 = gen_ncmp(OR_PACKET, off_li, BPF_B, 0x3f, BPF_JGT, 0, 0);
+               gen_and(b1, b0);
+               break;
+
+       case M_MSU:
+               if (linktype != DLT_MTP2)
+                       bpf_error("'msu' supported only on MTP2");
+               b0 = gen_ncmp(OR_PACKET, off_li, BPF_B, 0x3f, BPF_JGT, 0, 2);
+               break;
+
+       default:
+               abort();
+       }
+       return b0;
+}
+
 struct block *
 gen_mtp3field_code(mtp3field, jvalue, jtype, reverse)
        int mtp3field;
index 75c3e4863e20d7e0c6d6b5d9595e983b1f3cf06f..ceba77c058b2d5eabf09cb93e6321746a4eec4f6 100644 (file)
--- a/gencode.h
+++ b/gencode.h
@@ -18,7 +18,7 @@
  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
- * @(#) $Header: /tcpdump/master/libpcap/gencode.h,v 1.60.2.8 2006-10-24 17:00:48 hannes Exp $ (LBL)
+ * @(#) $Header: /tcpdump/master/libpcap/gencode.h,v 1.60.2.9 2006-12-21 19:45:04 guy Exp $ (LBL)
  */
 
 /*
                                   end-to-end circuits, ILMI circuits or
                                   connection signalling circuit. */
 
-/*MTP3 field types */
-#define M_SIO 1
-#define M_OPC 2
-#define M_DPC 3
-#define M_SLS 4
+/* MTP2 types */
+#define M_FISU         22      /* FISU */
+#define M_LSU          23      /* LSU */
+#define M_MSU          24      /* MSU */
+
+/* MTP3 field types */
+#define M_SIO          1
+#define M_OPC          2
+#define M_DPC          3
+#define M_SLS          4
 
 
 struct slist;
@@ -296,6 +301,7 @@ struct block *gen_atmfield_code(int atmfield, bpf_int32 jvalue, bpf_u_int32 jtyp
 struct block *gen_atmtype_abbrev(int type);
 struct block *gen_atmmulti_abbrev(int type);
 
+struct block *gen_mtp2type_abbrev(int type);
 struct block *gen_mtp3field_code(int mtp3field, bpf_u_int32 jvalue, bpf_u_int32 jtype, int reverse);
 
 struct block *gen_pf_ifname(const char *);
index 0babac27487393ce77a65eebdaad2f479ee5fd5b..f08ae5626d055a0ed0e34693cf763b8cbf0cc20d 100644 (file)
--- a/grammar.y
+++ b/grammar.y
@@ -22,7 +22,7 @@
  */
 #ifndef lint
 static const char rcsid[] _U_ =
-    "@(#) $Header: /tcpdump/master/libpcap/grammar.y,v 1.86.2.5 2005-09-05 09:08:06 guy Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/libpcap/grammar.y,v 1.86.2.6 2006-12-21 19:45:04 guy Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -113,8 +113,9 @@ pcap_parse()
 %type  <i>     atmtype atmmultitype
 %type  <blk>   atmfield
 %type  <blk>   atmfieldvalue atmvalue atmlistvalue
-%type   <blk>   mtp3field
-%type   <blk>   mtp3fieldvalue mtp3value mtp3listvalue
+%type  <i>     mtp2type
+%type  <blk>   mtp3field
+%type  <blk>   mtp3fieldvalue mtp3value mtp3listvalue
 
 
 %token  DST SRC HOST GATEWAY
@@ -140,7 +141,8 @@ pcap_parse()
 %token OAM OAMF4 CONNECTMSG METACONNECT
 %token VPI VCI
 %token RADIO
-%token  SIO OPC DPC SLS
+%token FISU LSU MSU
+%token SIO OPC DPC SLS
 
 %type  <s> ID
 %type  <e> EID
@@ -261,6 +263,7 @@ rterm:        head id               { $$ = $2; }
        | atmtype               { $$.b = gen_atmtype_abbrev($1); $$.q = qerr; }
        | atmmultitype          { $$.b = gen_atmmulti_abbrev($1); $$.q = qerr; }
        | atmfield atmvalue     { $$.b = $2.b; $$.q = qerr; }
+       | mtp2type              { $$.b = gen_mtp2type_abbrev($1); $$.q = qerr; }
        | mtp3field mtp3value   { $$.b = $2.b; $$.q = qerr; }
        ;
 /* protocol level qualifiers */
@@ -439,6 +442,11 @@ atmfieldvalue: NUM {
 atmlistvalue: atmfieldvalue
        | atmlistvalue or atmfieldvalue { gen_or($1.b, $3.b); $$ = $3; }
        ;
+       /* MTP2 types quantifier */
+mtp2type: FISU                 { $$ = M_FISU; }
+       | LSU                   { $$ = M_LSU; }
+       | MSU                   { $$ = M_MSU; }
+       ;
        /* MTP3 field types quantifier */
 mtp3field: SIO                 { $$.mtp3fieldtype = M_SIO; }
        | OPC                   { $$.mtp3fieldtype = M_OPC; }
index 9494b417e77f2e265e4d795407530f135e341e03..a84494aed9a352bcca4670513d0e3529e9d255fb 100644 (file)
--- a/scanner.l
+++ b/scanner.l
@@ -22,7 +22,7 @@
 
 #ifndef lint
 static const char rcsid[] _U_ =
-    "@(#) $Header: /tcpdump/master/libpcap/scanner.l,v 1.99.2.6 2005-11-09 23:49:48 guy Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/libpcap/scanner.l,v 1.99.2.7 2006-12-21 19:45:04 guy Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -288,6 +288,9 @@ srnr|subrulenum     return PF_SRNR;
 reason         return PF_REASON;
 action         return PF_ACTION;
 
+fisu           return FISU;
+lsu            return LSU;
+msu            return MSU;
 sio            return SIO;
 opc            return OPC;
 dpc            return DPC;