]> The Tcpdump Group git mirrors - libpcap/commitdiff
ARCNet support, from NetBSD.
authorguy <guy>
Tue, 17 Apr 2001 08:25:21 +0000 (08:25 +0000)
committerguy <guy>
Tue, 17 Apr 2001 08:25:21 +0000 (08:25 +0000)
FILES
arcnet.h [new file with mode: 0644]
gencode.c
gencode.h
grammar.y
scanner.l

diff --git a/FILES b/FILES
index 8c1d3fbb7b84e28f8f1753eab4d7a4c5aa986e87..b1135d9fe4ba17dc4242a842435d7fb28e48bb46 100644 (file)
--- a/FILES
+++ b/FILES
@@ -13,6 +13,7 @@ SUNOS4/nit_if.o.sun3
 SUNOS4/nit_if.o.sun4c.4.0.3c
 VERSION
 aclocal.m4
+arcnet.h
 bpf/net/bpf.h
 bpf/net/bpf_filter.c
 bpf_dump.c
diff --git a/arcnet.h b/arcnet.h
new file mode 100644 (file)
index 0000000..fecd64a
--- /dev/null
+++ b/arcnet.h
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 1982, 1986, 1993
+ *     The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#) $$ (LBL)
+ */
+
+/* RFC 1051 */
+#define        ARCTYPE_IP_OLD          240     /* IP protocol */
+#define        ARCTYPE_ARP_OLD         241     /* address resolution protocol */
+
+/* RFC 1201 */
+#define        ARCTYPE_IP              212     /* IP protocol */
+#define        ARCTYPE_ARP             213     /* address resolution protocol */
+#define        ARCTYPE_REVARP          214     /* reverse addr resolution protocol */
+
+#define        ARCTYPE_ATALK           221     /* Appletalk */
+#define        ARCTYPE_BANIAN          247     /* Banyan Vines */
+#define        ARCTYPE_IPX             250     /* Novell IPX */
+
+#define ARCTYPE_INET6          0xc4    /* IPng */
+#define ARCTYPE_DIAGNOSE       0x80    /* as per ANSI/ATA 878.1 */
index 208c5f242f6d2720d0bb85b262e095fdc04018c3..642a484284215ac421f9eeb6f4bc577f84590c0c 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.150 2001-04-17 08:10:00 guy Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/libpcap/gencode.c,v 1.151 2001-04-17 08:25:21 guy Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -55,6 +55,7 @@ struct rtentry;
 #include "gencode.h"
 #include "ppp.h"
 #include "sll.h"
+#include "arcnet.h"
 #include <pcap-namedb.h>
 #ifdef INET6
 #include <netdb.h>
@@ -141,6 +142,7 @@ static struct block *gen_hostop(bpf_u_int32, bpf_u_int32, int, int, u_int, u_int
 #ifdef INET6
 static struct block *gen_hostop6(struct in6_addr *, struct in6_addr *, int, int, u_int, u_int);
 #endif
+static struct block *gen_ahostop(const u_char *, int);
 static struct block *gen_ehostop(const u_char *, int);
 static struct block *gen_fhostop(const u_char *, int);
 static struct block *gen_thostop(const u_char *, int);
@@ -547,6 +549,11 @@ init_linktype(type)
 
        switch (type) {
 
+       case DLT_ARCNET:
+               off_linktype = 2;
+               off_nl = 6;     /* XXX in reality, variable! */
+               return;
+
        case DLT_EN10MB:
                off_linktype = 12;
                off_nl = 14;
@@ -1310,6 +1317,40 @@ gen_linktype(proto)
                        proto = htonl(proto);
                }
                return (gen_cmp(0, BPF_W, (bpf_int32)proto));
+
+       case DLT_ARCNET:
+               /*
+                * XXX should we check for first fragment if the protocol
+                * uses PHDS?
+                */
+               switch(proto) {
+               default:
+                       return gen_false();
+#ifdef INET6
+               case ETHERTYPE_IPV6:
+                       return(gen_cmp(2, BPF_B,
+                                       (bpf_int32)htonl(ARCTYPE_INET6)));
+#endif /* INET6 */
+               case ETHERTYPE_IP:
+                       b0 = gen_cmp(2, BPF_B, (bpf_int32)htonl(ARCTYPE_IP));
+                       b1 = gen_cmp(2, BPF_B,
+                                       (bpf_int32)htonl(ARCTYPE_IP_OLD));
+                       gen_or(b0, b1);
+                       return(b1);
+               case ETHERTYPE_ARP:
+                       b0 = gen_cmp(2, BPF_B, (bpf_int32)htonl(ARCTYPE_ARP));
+                       b1 = gen_cmp(2, BPF_B,
+                                       (bpf_int32)htonl(ARCTYPE_ARP_OLD));
+                       gen_or(b0, b1);
+                       return(b1);
+               case ETHERTYPE_REVARP:
+                       return(gen_cmp(2, BPF_B,
+                                       (bpf_int32)htonl(ARCTYPE_REVARP)));
+               case ETHERTYPE_ATALK:
+                       return(gen_cmp(2, BPF_B,
+                                       (bpf_int32)htonl(ARCTYPE_ATALK)));
+               }
+               break;
        }
 
        /*
@@ -3557,6 +3598,8 @@ gen_byteop(op, idx, val)
        return b;
 }
 
+static u_char abroadcast[] = { 0x0 };
+
 struct block *
 gen_broadcast(proto)
        int proto;
@@ -3569,6 +3612,8 @@ gen_broadcast(proto)
 
        case Q_DEFAULT:
        case Q_LINK:
+               if (linktype == DLT_ARCNET)
+                       return gen_ahostop(abroadcast, Q_DST);
                if (linktype == DLT_EN10MB)
                        return gen_ehostop(ebroadcast, Q_DST);
                if (linktype == DLT_FDDI)
@@ -3602,6 +3647,10 @@ gen_multicast(proto)
 
        case Q_DEFAULT:
        case Q_LINK:
+               if (linktype == DLT_ARCNET)
+                       /* all ARCnet multicasts use the same address */
+                       return gen_ahostop(abroadcast, Q_DST);
+
                if (linktype == DLT_EN10MB) {
                        /* ether[0] & 1 != 0 */
                        s = new_stmt(BPF_LD|BPF_B|BPF_ABS);
@@ -3679,6 +3728,51 @@ gen_inbound(dir)
        return (b0);
 }
 
+struct block *
+gen_acode(eaddr, q)
+       register const u_char *eaddr;
+       struct qual q;
+{
+       if ((q.addr == Q_HOST || q.addr == Q_DEFAULT) && q.proto == Q_LINK) {
+               if (linktype == DLT_ARCNET)
+                       return gen_ahostop(eaddr, (int)q.dir);
+       }
+       bpf_error("ARCnet address used in non-arc expression");
+       /* NOTREACHED */
+}
+
+static struct block *
+gen_ahostop(eaddr, dir)
+       register const u_char *eaddr;
+       register int dir;
+{
+       register struct block *b0, *b1;
+
+       switch (dir) {
+       /* src comes first, different from Ethernet */
+       case Q_SRC:
+               return gen_bcmp(0, 1, eaddr);
+
+       case Q_DST:
+               return gen_bcmp(1, 1, eaddr);
+
+       case Q_AND:
+               b0 = gen_ahostop(eaddr, Q_SRC);
+               b1 = gen_ahostop(eaddr, Q_DST);
+               gen_and(b0, b1);
+               return b1;
+
+       case Q_DEFAULT:
+       case Q_OR:
+               b0 = gen_ahostop(eaddr, Q_SRC);
+               b1 = gen_ahostop(eaddr, Q_DST);
+               gen_or(b0, b1);
+               return b1;
+       }
+       abort();
+       /* NOTREACHED */
+}
+
 /*
  * support IEEE 802.1Q VLAN trunk over ethernet
  */
index 8dfdcb6305f3e08fa48e4a97abdeaddefe898a49..87d9bf5f63d9730bef7f336852d8513118c40a9d 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.51 2001-02-21 09:33:05 guy Exp $ (LBL)
+ * @(#) $Header: /tcpdump/master/libpcap/gencode.h,v 1.52 2001-04-17 08:25:22 guy Exp $ (LBL)
  */
 
 /* Address qualifiers. */
@@ -173,6 +173,7 @@ void gen_not(struct block *);
 
 struct block *gen_scode(const char *, struct qual);
 struct block *gen_ecode(const u_char *, struct qual);
+struct block *gen_acode(const u_char *, struct qual);
 struct block *gen_mcode(const char *, const char *, int, struct qual);
 #ifdef INET6
 struct block *gen_mcode6(const char *, const char *, int, struct qual);
index 52281b4219ce59476a77ca922ef1b821dcd2311b..1fceb5532a352403db846f35a44554d0b045d1ac 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.68 2001-02-21 09:33:05 guy Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/libpcap/grammar.y,v 1.69 2001-04-17 08:25:23 guy Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -112,7 +112,7 @@ pcap_parse()
 %token  NUM INBOUND OUTBOUND
 %token  LINK
 %token GEQ LEQ NEQ
-%token ID EID HID HID6
+%token ID EID HID HID6 AID
 %token LSH RSH
 %token  LEN
 %token  IPV6 ICMPV6 AH ESP
@@ -124,6 +124,7 @@ pcap_parse()
 
 %type  <s> ID
 %type  <e> EID
+%type  <e> AID
 %type  <s> HID HID6
 %type  <i> NUM
 
@@ -188,6 +189,7 @@ nid:          ID                    { $$.b = gen_scode($1, $$.q = $<blk>0.q); }
 #endif /*INET6*/
                                }
        | EID                   { $$.b = gen_ecode($1, $$.q = $<blk>0.q); }
+       | AID                   { $$.b = gen_acode($1, $$.q = $<blk>0.q); }
        | not id                { gen_not($2.b); $$ = $2; }
        ;
 not:     '!'                   { $$ = $<blk>0; }
index ee317c82bd430db53a6052ff2bca396534ee16bb..f0c733a6b3a227f03fc4c2f50b822927dcbbf5ba 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.75 2001-02-24 18:21:14 mcr Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/libpcap/scanner.l,v 1.76 2001-04-17 08:25:23 guy Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -243,6 +243,8 @@ vlan                return VLAN;
 "=="                   return '=';
 "<<"                   return LSH;
 ">>"                   return RSH;
+${B}                   { yylval.e = pcap_ether_aton(((char *)yytext)+1);
+                         return AID; }
 {N}                    { yylval.i = stoi((char *)yytext); return NUM; }
 ({N}\.{N})|({N}\.{N}\.{N})|({N}\.{N}\.{N}\.{N})        {
                        yylval.s = sdup((char *)yytext); return HID; }