]> The Tcpdump Group git mirrors - libpcap/commitdiff
Improved VLAN support, from Peter Jeremy - "vlan" filtering keyword,
authorguy <guy>
Sun, 22 Oct 2000 04:15:55 +0000 (04:15 +0000)
committerguy <guy>
Sun, 22 Oct 2000 04:15:55 +0000 (04:15 +0000)
letting you filter based on the VLAN to which a packet belongs, and an
improvement to the printing of VLAN packets (adding an extra space to
separate the VLAN priority and flags from the next stuff printed).

CREDITS
ethertype.h
gencode.c
gencode.h
grammar.y
scanner.l

diff --git a/CREDITS b/CREDITS
index 4222d8a46e370e5bb8c2743dc576fa18d7f32798..a56b76d4d01cdd62d9335d4ecb3dad649b862007 100644 (file)
--- a/CREDITS
+++ b/CREDITS
@@ -20,6 +20,7 @@ Additional people who have contributed patches:
        Love Hörnquist-Ã…strand          <[email protected]>
        Rafal Maszkowski                <[email protected]>
        Rick Jones                      <[email protected]>
+       Peter Jeremy                    <[email protected]>
 
 The original LBL crew:
        Steve McCanne
index f5cb767df9105c28f5f6897414a8f2be78adfd14..3af6f86ceb31e617a0143b9576a0d7b58e8a48ee 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.10 2000-09-23 07:26:27 guy Exp $ (LBL)
+ * @(#) $Header: /tcpdump/master/libpcap/ethertype.h,v 1.11 2000-10-22 04:15:55 guy Exp $ (LBL)
  */
 
 /*
@@ -96,6 +96,9 @@
 #ifndef ETHERTYPE_IPV6
 #define ETHERTYPE_IPV6         0x86dd
 #endif
+#ifndef ETHERTYPE_8021Q
+#define ETHERTYPE_8021Q                0x8100
+#endif
 #ifndef        ETHERTYPE_LOOPBACK
 #define        ETHERTYPE_LOOPBACK      0x9000
 #endif
index ea55dd192ed69d00746bb01b92cded79735e7a9b..af2218da19ad9a6fc0497d761054f63137b41075 100644 (file)
--- a/gencode.c
+++ b/gencode.c
@@ -21,7 +21,7 @@
  */
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/libpcap/gencode.c,v 1.122 2000-10-12 03:53:57 guy Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/libpcap/gencode.c,v 1.123 2000-10-22 04:15:55 guy Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -2926,3 +2926,50 @@ gen_inbound(dir)
                          dir);
        return (b0);
 }
+
+/*
+ * support IEEE 802.1Q VLAN trunk over ethernet
+ */
+struct block *
+gen_vlan(vlan_num)
+       int vlan_num;
+{
+       static u_int    orig_linktype = -1, orig_nl = -1;
+       struct  block   *b0;
+
+       /*
+        * Change the offsets to point to the type and data fields within
+        * the VLAN packet.  This is somewhat of a kludge.
+        */
+       if (orig_nl == (u_int)-1) {
+               orig_linktype = off_linktype;   /* save original values */
+               orig_nl = off_nl;
+
+               switch (linktype) {
+
+               case DLT_EN10MB:
+                       off_linktype = 16;
+                       off_nl = 18;
+                       break;
+
+               default:
+                       bpf_error("no VLAN support for data link type %d",
+                                 linktype);
+                       /*NOTREACHED*/
+               }
+       }
+
+       /* check for VLAN */
+       b0 = gen_cmp(orig_linktype, BPF_H, (bpf_int32)ETHERTYPE_8021Q);
+
+       /* If a specific VLAN is requested, check VLAN id */
+       if (vlan_num >= 0) {
+               struct block *b1;
+
+               b1 = gen_cmp(orig_nl, BPF_H, (bpf_int32)vlan_num);
+               gen_and(b0, b1);
+               b0 = b1;
+       }
+
+       return (b0);
+}
index 51c0e66d98fe7b75923a00a836593b52ca3bd147..8feffb06b119d7b228105319eb0fd6898336a82a 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.41 2000-07-13 06:51:56 guy Exp $ (LBL)
+ * @(#) $Header: /tcpdump/master/libpcap/gencode.h,v 1.42 2000-10-22 04:15:56 guy Exp $ (LBL)
  */
 
 /* Address qualifiers. */
@@ -173,6 +173,8 @@ struct block *gen_broadcast(int);
 struct block *gen_multicast(int);
 struct block *gen_inbound(int);
 
+struct block *gen_vlan(int);
+
 void bpf_optimize(struct block **);
 void bpf_error(const char *, ...)
 #if HAVE___ATTRIBUTE__
index fc8d6e5946125e14c85a258818a49fb8d8291ea4..9932f429d0007a64f999b5d6de7362abee9a7bf3 100644 (file)
--- a/grammar.y
+++ b/grammar.y
@@ -22,7 +22,7 @@
  */
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/libpcap/grammar.y,v 1.60 2000-09-23 07:26:28 guy Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/libpcap/grammar.y,v 1.61 2000-10-22 04:15:56 guy Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -116,6 +116,7 @@ pcap_parse()
 %token LSH RSH
 %token  LEN
 %token  IPV6 ICMPV6 AH ESP
+%token VLAN
 
 %type  <s> ID
 %type  <e> EID
@@ -162,14 +163,7 @@ nid:         ID                    { $$.b = gen_scode($1, $$.q = $<blk>0.q); }
        | HID                   {
                                  /* Decide how to parse HID based on proto */
                                  $$.q = $<blk>0.q;
-                                 switch ($$.q.proto) {
-                                 case Q_DECNET:
-                                       $$.b = gen_ncode($1, 0, $$.q);
-                                       break;
-                                 default:
-                                       $$.b = gen_ncode($1, 0, $$.q);
-                                       break;
-                                 }
+                                 $$.b = gen_ncode($1, 0, $$.q);
                                }
        | HID6 '/' NUM          {
 #ifdef INET6
@@ -271,6 +265,8 @@ other:        pqual TK_BROADCAST    { $$ = gen_broadcast($1); }
        | BYTE NUM byteop NUM   { $$ = gen_byteop($3, $2, $4); }
        | INBOUND               { $$ = gen_inbound(0); }
        | OUTBOUND              { $$ = gen_inbound(1); }
+       | VLAN pnum             { $$ = gen_vlan($2); }
+       | VLAN                  { $$ = gen_vlan(-1); }
        ;
 relop:   '>'                   { $$ = BPF_JGT; }
        | GEQ                   { $$ = BPF_JGE; }
index ff95f42fea469c9b68b0b43d2dd5c670a2fdd94f..03ea14e49bb236e44af6d5a04c22198cf6cbf916 100644 (file)
--- a/scanner.l
+++ b/scanner.l
@@ -22,7 +22,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/libpcap/scanner.l,v 1.66 2000-07-25 05:50:08 guy Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/libpcap/scanner.l,v 1.67 2000-10-22 04:15:56 guy Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -218,6 +218,8 @@ len|length  return LEN;
 inbound                return INBOUND;
 outbound       return OUTBOUND;
 
+vlan           return VLAN;
+
 [ \n\t]                        ;
 [+\-*/:\[\]!<>()&|=]   return yytext[0];
 ">="                   return GEQ;