Add code to do link level address matching for ARCnet interfaces.

ARCnet link level addresses are encoded as :HH (``:'' followed by a
byte encoded in hexadecimal notation).
This commit is contained in:
is 1999-10-25 16:39:37 +00:00
parent 4cc6f12c09
commit 57a250cc8c
4 changed files with 67 additions and 8 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: gencode.c,v 1.19 1999/10/18 19:44:12 is Exp $ */
/* $NetBSD: gencode.c,v 1.20 1999/10/25 16:39:37 is Exp $ */
/*
* Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
@ -26,7 +26,7 @@
static const char rcsid[] =
"@(#) Header: gencode.c,v 1.93 97/06/12 14:22:47 leres Exp (LBL)";
#else
__RCSID("$NetBSD: gencode.c,v 1.19 1999/10/18 19:44:12 is Exp $");
__RCSID("$NetBSD: gencode.c,v 1.20 1999/10/25 16:39:37 is Exp $");
#endif
#endif
@ -155,6 +155,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_dnhostop(bpf_u_int32, int, u_int);
@ -2711,6 +2712,8 @@ gen_byteop(op, idx, val)
return b;
}
static u_char abroadcast[] = { 0x0 };
struct block *
gen_broadcast(proto)
int proto;
@ -2723,6 +2726,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)
@ -2754,6 +2759,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);
@ -2828,3 +2837,48 @@ gen_inbound(dir)
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 */
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: gencode.h,v 1.7 1999/07/02 16:03:41 simonb Exp $ */
/* $NetBSD: gencode.h,v 1.8 1999/10/25 16:39:37 is Exp $ */
/*
* Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996
@ -166,6 +166,7 @@ struct stmt *gen_joinsp __P((struct stmt **, int));
struct block *gen_protochain __P((int, int, int));
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);

View File

@ -1,5 +1,5 @@
%{
/* $NetBSD: grammar.y,v 1.6 1999/07/02 10:05:22 itojun Exp $ */
/* $NetBSD: grammar.y,v 1.7 1999/10/25 16:39:37 is Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996
@ -28,7 +28,7 @@
static const char rcsid[] =
"@(#) Header: grammar.y,v 1.56 96/11/02 21:54:55 leres Exp (LBL)";
#else
__RCSID("$NetBSD: grammar.y,v 1.6 1999/07/02 10:05:22 itojun Exp $");
__RCSID("$NetBSD: grammar.y,v 1.7 1999/10/25 16:39:37 is Exp $");
#endif
#endif
@ -120,13 +120,14 @@ 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
%type <s> ID
%type <e> EID
%type <e> AID
%type <s> HID HID6
%type <i> NUM
@ -198,6 +199,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; }

View File

@ -1,5 +1,5 @@
%{
/* $NetBSD: scanner.l,v 1.8 1999/07/05 20:01:09 mjacob Exp $ */
/* $NetBSD: scanner.l,v 1.9 1999/10/25 16:39:37 is Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
@ -28,7 +28,7 @@
static const char rcsid[] =
"@(#) Header: scanner.l,v 1.56 97/07/21 13:31:50 leres Exp (LBL)";
#else
__RCSID("$NetBSD: scanner.l,v 1.8 1999/07/05 20:01:09 mjacob Exp $");
__RCSID("$NetBSD: scanner.l,v 1.9 1999/10/25 16:39:37 is Exp $");
#endif
#endif
@ -151,6 +151,8 @@ outbound return OUTBOUND;
"==" 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; }