]> The Tcpdump Group git mirrors - libpcap/commitdiff
add baseline support for MPLS protocol and per-label filtering
authorhannes <hannes>
Wed, 16 Jun 2004 08:20:28 +0000 (08:20 +0000)
committerhannes <hannes>
Wed, 16 Jun 2004 08:20:28 +0000 (08:20 +0000)
ethertype.h
gencode.c
gencode.h
grammar.y
ppp.h
scanner.l

index 3e75a96416a0fe004a11e09a900fc5b6719842ff..9344e2c967ba46c44f30676635cf30d82f55b5e2 100644 (file)
@@ -18,7 +18,7 @@
  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
- * @(#) $Header: /tcpdump/master/libpcap/ethertype.h,v 1.12 2001-01-14 21:26:52 guy Exp $ (LBL)
+ * @(#) $Header: /tcpdump/master/libpcap/ethertype.h,v 1.13 2004-06-16 08:20:28 hannes Exp $ (LBL)
  */
 
 /*
 #ifndef ETHERTYPE_IPV6
 #define ETHERTYPE_IPV6         0x86dd
 #endif
+#ifndef ETHERTYPE_MPLS
+#define ETHERTYPE_MPLS          0x8847
+#endif
+#ifndef ETHERTYPE_MPLS_MULTI
+#define ETHERTYPE_MPLS_MULTI    0x8848
+#endif
 #ifndef        ETHERTYPE_LOOPBACK
 #define        ETHERTYPE_LOOPBACK      0x9000
 #endif
index 857760eca22fa63f04f8b0bd5d5bf20fba99f159..3dc15f23995eccb459cc548b74fe9db9140dd0fd 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.204 2004-04-07 18:43:29 guy Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/libpcap/gencode.c,v 1.205 2004-06-16 08:20:29 hannes Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -97,7 +97,7 @@ static const char rcsid[] _U_ =
 static jmp_buf top_ctx;
 static pcap_t *bpf_pcap;
 
-/* Hack for updating VLAN offsets. */
+/* Hack for updating VLAN, MPLS offsets. */
 static u_int   orig_linktype = -1U, orig_nl = -1U, orig_nl_nosnap = -1U;
 
 /* XXX */
@@ -5279,6 +5279,74 @@ gen_vlan(vlan_num)
        return (b0);
 }
 
+/*
+ * support for MPLS
+ */
+struct block *
+gen_mpls(label_num)
+       int label_num;
+{
+       struct  block   *b0;
+
+       /*
+        * Change the offsets to point to the type and data fields within
+        * the MPLS packet.  This is somewhat of a kludge.
+        */
+       if (orig_nl == (u_int)-1) {
+               orig_linktype = off_linktype;   /* save original values */
+               orig_nl = off_nl;
+               orig_nl_nosnap = off_nl_nosnap;
+
+               switch (linktype) {
+
+               case DLT_EN10MB:
+                       off_linktype = 16;
+                       off_nl_nosnap = 18;
+                       off_nl = 18;
+                        
+                        b0 = gen_cmp(orig_linktype, BPF_H, (bpf_int32)ETHERTYPE_MPLS);
+                       break;
+
+               case DLT_PPP:
+                       off_linktype = 6;
+                       off_nl_nosnap = 8;
+                       off_nl = 8;
+                        
+                        b0 = gen_cmp(orig_linktype, BPF_H, (bpf_int32)PPP_MPLS_UCAST);
+                       break;
+
+                case DLT_C_HDLC:
+                        off_linktype = 6;
+                       off_nl_nosnap = 8;
+                       off_nl = 8;
+                        
+                        b0 = gen_cmp(orig_linktype, BPF_H, (bpf_int32)ETHERTYPE_MPLS);
+                        break;
+
+                        /* FIXME add other DLT_s ...
+                         * for Frame-Relay/and ATM this may get messy due to SNAP headers
+                         * leave it for now */
+
+               default:
+                       bpf_error("no MPLS support for data link type %d",
+                                 linktype);
+                       /*NOTREACHED*/
+               }
+       }
+
+       /* If a specific MPLS label is requested, check it */
+       if (label_num >= 0) {
+               struct block *b1;
+
+                label_num = label_num << 12; /* label is shifted 12 bits on the wire */
+               b1 = gen_mcmp(orig_nl, BPF_H, (bpf_int32)label_num, 0xfffff000); /* only compare the first 20 bits */
+               gen_and(b0, b1);
+               b0 = b1;
+       }
+
+       return (b0);
+}
+
 struct block *
 gen_atmfield_code(atmfield, jvalue, jtype, reverse)
        int atmfield;
index bd773811b99ec38270b52fed30336f7b4ef9a899..6b97e8921260278065ee873cb5695295c21cb914 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.59 2004-03-28 20:27:14 fenner Exp $ (LBL)
+ * @(#) $Header: /tcpdump/master/libpcap/gencode.h,v 1.60 2004-06-16 08:20:30 hannes Exp $ (LBL)
  */
 
 /*
@@ -273,6 +273,7 @@ struct block *gen_multicast(int);
 struct block *gen_inbound(int);
 
 struct block *gen_vlan(int);
+struct block *gen_mpls(int);
 
 struct block *gen_atmfield_code(int atmfield, bpf_u_int32 jvalue, bpf_u_int32 jtype, int reverse);
 struct block *gen_atmtype_abbrev(int type);
index 8f3939421475fc3095b3b64a91ccacef424faded..1d8d4829ac5fd290a42c847cd5e1d6923b1fb587 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.82 2004-03-28 20:27:14 fenner Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/libpcap/grammar.y,v 1.83 2004-06-16 08:20:29 hannes Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -128,7 +128,7 @@ pcap_parse()
 %token LSH RSH
 %token  LEN
 %token  IPV6 ICMPV6 AH ESP
-%token VLAN
+%token VLAN MPLS
 %token  ISO ESIS CLNP ISIS L1 L2 IIH LSP SNP CSNP PSNP 
 %token  STP
 %token  IPX
@@ -324,6 +324,8 @@ other:        pqual TK_BROADCAST    { $$ = gen_broadcast($1); }
        | OUTBOUND              { $$ = gen_inbound(1); }
        | VLAN pnum             { $$ = gen_vlan($2); }
        | VLAN                  { $$ = gen_vlan(-1); }
+       | MPLS pnum             { $$ = gen_mpls($2); }
+       | MPLS                  { $$ = gen_mpls(-1); }
        | pfvar                 { $$ = $1; }
        ;
 
diff --git a/ppp.h b/ppp.h
index 4353b791fbd22c156a2af5eb9da9c3705cfa2437..6bd4d9683d59f38372b0c9833d5641db431febaf 100644 (file)
--- a/ppp.h
+++ b/ppp.h
@@ -1,4 +1,4 @@
-/* @(#) $Header: /tcpdump/master/libpcap/ppp.h,v 1.8 1999-10-19 15:18:31 itojun Exp $ (LBL) */
+/* @(#) $Header: /tcpdump/master/libpcap/ppp.h,v 1.9 2004-06-16 08:20:28 hannes Exp $ (LBL) */
 /*
  * Point to Point Protocol (PPP) RFC1331
  *
@@ -35,6 +35,8 @@
 #define PPP_HELLO      0x0201  /* 802.1d Hello Packets */
 #define PPP_LUXCOM     0x0231  /* Luxcom */
 #define PPP_SNS                0x0233  /* Sigma Network Systems */
+#define PPP_MPLS_UCAST  0x0281  /* rfc 3032 */
+#define PPP_MPLS_MCAST  0x0283  /* rfc 3022 */
 
 #define PPP_IPCP       0x8021  /* IP Control Protocol */
 #define PPP_OSICP      0x8023  /* OSI Network Layer Control Protocol */
@@ -45,6 +47,7 @@
 #define PPP_STIICP     0x8033  /* Strean Protocol Control Protocol */
 #define PPP_VINESCP    0x8035  /* Banyan Vines Control Protocol */
 #define PPP_IPV6CP     0x8057  /* IPv6 Control Protocol */
+#define PPP_MPLSCP      0x8281  /* rfc 3022 */
 
 #define PPP_LCP                0xc021  /* Link Control Protocol */
 #define PPP_PAP                0xc023  /* Password Authentication Protocol */
index cd2af854131b094a54bab80d215fd0d74dba10f6..f03d04e78a797f19436c13c17f914f21cbe91766 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.98 2004-03-28 20:27:16 fenner Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/libpcap/scanner.l,v 1.99 2004-06-16 08:20:28 hannes Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -260,6 +260,7 @@ inbound             return INBOUND;
 outbound       return OUTBOUND;
 
 vlan           return VLAN;
+mpls           return MPLS;
 
 lane           return LANE;
 llc            return LLC;