Skip to content

Commit

Permalink
Make the value argument to "gen_ncmp()" a bpf_int32, the same as the
Browse files Browse the repository at this point in the history
value arguments are to other routines.  Do the same with the value
argument to "gen_atmfield_code()".

"gen_load_a()" can return more than one statement; append to the list of
statements it returns with "sappend()", rather than manually appending
to the first statement.

Fix the argument list to one "gen_ncmp()" call, and get rid of the casts
in the other calls, as the arguments already have the right types.

Fix the casts in calls to "gen_atmfield_code()".
  • Loading branch information
yuguy committed May 1, 2005
1 parent eeadab8 commit 6804103
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 21 deletions.
32 changes: 17 additions & 15 deletions gencode.c
Expand Up @@ -21,7 +21,7 @@
*/ */
#ifndef lint #ifndef lint
static const char rcsid[] _U_ = static const char rcsid[] _U_ =
"@(#) $Header: /tcpdump/master/libpcap/gencode.c,v 1.237 2005-05-01 04:13:52 guy Exp $ (LBL)"; "@(#) $Header: /tcpdump/master/libpcap/gencode.c,v 1.238 2005-05-01 08:37:04 guy Exp $ (LBL)";
#endif #endif


#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
Expand Down Expand Up @@ -178,7 +178,7 @@ static struct block *gen_mcmp(enum e_offrel, u_int, u_int, bpf_int32,
bpf_u_int32); bpf_u_int32);
static struct block *gen_bcmp(enum e_offrel, u_int, u_int, const u_char *); static struct block *gen_bcmp(enum e_offrel, u_int, u_int, const u_char *);
static struct block *gen_ncmp(enum e_offrel, bpf_u_int32, bpf_u_int32, static struct block *gen_ncmp(enum e_offrel, bpf_u_int32, bpf_u_int32,
bpf_u_int32, bpf_u_int32, int, bpf_u_int32); bpf_u_int32, bpf_u_int32, int, bpf_int32);
static struct slist *gen_load_a(enum e_offrel, u_int, u_int); static struct slist *gen_load_a(enum e_offrel, u_int, u_int);
static struct block *gen_uncond(int); static struct block *gen_uncond(int);
static inline struct block *gen_true(void); static inline struct block *gen_true(void);
Expand Down Expand Up @@ -608,17 +608,19 @@ gen_bcmp(offrel, offset, size, v)
static struct block * static struct block *
gen_ncmp(offrel, offset, size, mask, jtype, reverse, v) gen_ncmp(offrel, offset, size, mask, jtype, reverse, v)
enum e_offrel offrel; enum e_offrel offrel;
bpf_u_int32 offset, size, mask, jtype, v; bpf_int32 v;
bpf_u_int32 offset, size, mask, jtype;
int reverse; int reverse;
{ {
struct slist *s; struct slist *s, *s2;
struct block *b; struct block *b;


s = gen_load_a(offrel, offset, size); s = gen_load_a(offrel, offset, size);


if (mask != 0xffffffff) { if (mask != 0xffffffff) {
s->next = new_stmt(BPF_ALU|BPF_AND|BPF_K); s2 = new_stmt(BPF_ALU|BPF_AND|BPF_K);
s->next->s.k = mask; s2->s.k = mask;
sappend(s, s2);
} }


b = new_block(JMP(jtype)); b = new_block(JMP(jtype));
Expand Down Expand Up @@ -5812,7 +5814,7 @@ gen_mpls(label_num)
struct block * struct block *
gen_atmfield_code(atmfield, jvalue, jtype, reverse) gen_atmfield_code(atmfield, jvalue, jtype, reverse)
int atmfield; int atmfield;
bpf_u_int32 jvalue; bpf_int32 jvalue;
bpf_u_int32 jtype; bpf_u_int32 jtype;
int reverse; int reverse;
{ {
Expand All @@ -5825,31 +5827,31 @@ gen_atmfield_code(atmfield, jvalue, jtype, reverse)
bpf_error("'vpi' supported only on raw ATM"); bpf_error("'vpi' supported only on raw ATM");
if (off_vpi == (u_int)-1) if (off_vpi == (u_int)-1)
abort(); abort();
b0 = gen_ncmp(OR_LINK, off_vpi, BPF_B, 0xffffffff, (u_int)jtype, b0 = gen_ncmp(OR_LINK, off_vpi, BPF_B, 0xffffffff, jtype,
(u_int)jvalue, reverse); reverse, jvalue);
break; break;


case A_VCI: case A_VCI:
if (!is_atm) if (!is_atm)
bpf_error("'vci' supported only on raw ATM"); bpf_error("'vci' supported only on raw ATM");
if (off_vci == (u_int)-1) if (off_vci == (u_int)-1)
abort(); abort();
b0 = gen_ncmp(OR_LINK, off_vci, BPF_H, 0xffffffff, (u_int)jtype, b0 = gen_ncmp(OR_LINK, off_vci, BPF_H, 0xffffffff, jtype,
reverse, (u_int)jvalue); reverse, jvalue);
break; break;


case A_PROTOTYPE: case A_PROTOTYPE:
if (off_proto == (u_int)-1) if (off_proto == (u_int)-1)
abort(); /* XXX - this isn't on FreeBSD */ abort(); /* XXX - this isn't on FreeBSD */
b0 = gen_ncmp(OR_LINK, off_proto, BPF_B, 0x0f, (u_int)jtype, b0 = gen_ncmp(OR_LINK, off_proto, BPF_B, 0x0f, jtype,
reverse, (u_int)jvalue); reverse, jvalue);
break; break;


case A_MSGTYPE: case A_MSGTYPE:
if (off_payload == (u_int)-1) if (off_payload == (u_int)-1)
abort(); abort();
b0 = gen_ncmp(OR_LINK, off_payload + MSG_TYPE_POS, BPF_B, b0 = gen_ncmp(OR_LINK, off_payload + MSG_TYPE_POS, BPF_B,
0xffffffff, (u_int)jtype, reverse, (u_int)jvalue); 0xffffffff, jtype, reverse, jvalue);
break; break;


case A_CALLREFTYPE: case A_CALLREFTYPE:
Expand All @@ -5858,7 +5860,7 @@ gen_atmfield_code(atmfield, jvalue, jtype, reverse)
if (off_proto == (u_int)-1) if (off_proto == (u_int)-1)
abort(); abort();
b0 = gen_ncmp(OR_LINK, off_proto, BPF_B, 0xffffffff, b0 = gen_ncmp(OR_LINK, off_proto, BPF_B, 0xffffffff,
(u_int)jtype, reverse, (u_int)jvalue); jtype, reverse, jvalue);
break; break;


default: default:
Expand Down
4 changes: 2 additions & 2 deletions gencode.h
Expand Up @@ -18,7 +18,7 @@
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
* *
* @(#) $Header: /tcpdump/master/libpcap/gencode.h,v 1.62 2005-04-23 22:26:52 guy Exp $ (LBL) * @(#) $Header: /tcpdump/master/libpcap/gencode.h,v 1.63 2005-05-01 08:37:06 guy Exp $ (LBL)
*/ */


/* /*
Expand Down Expand Up @@ -280,7 +280,7 @@ struct block *gen_inbound(int);
struct block *gen_vlan(int); struct block *gen_vlan(int);
struct block *gen_mpls(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_atmfield_code(int atmfield, bpf_int32 jvalue, bpf_u_int32 jtype, int reverse);
struct block *gen_atmtype_abbrev(int type); struct block *gen_atmtype_abbrev(int type);
struct block *gen_atmmulti_abbrev(int type); struct block *gen_atmmulti_abbrev(int type);


Expand Down
8 changes: 4 additions & 4 deletions grammar.y
Expand Up @@ -22,7 +22,7 @@
*/ */
#ifndef lint #ifndef lint
static const char rcsid[] _U_ = static const char rcsid[] _U_ =
"@(#) $Header: /tcpdump/master/libpcap/grammar.y,v 1.87 2005-04-19 04:25:01 guy Exp $ (LBL)"; "@(#) $Header: /tcpdump/master/libpcap/grammar.y,v 1.88 2005-05-01 08:37:06 guy Exp $ (LBL)";
#endif #endif


#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
Expand Down Expand Up @@ -414,15 +414,15 @@ atmfield: VPI { $$.atmfieldtype = A_VPI; }
| VCI { $$.atmfieldtype = A_VCI; } | VCI { $$.atmfieldtype = A_VCI; }
; ;
atmvalue: atmfieldvalue atmvalue: atmfieldvalue
| relop NUM { $$.b = gen_atmfield_code($<blk>0.atmfieldtype, (u_int)$2, (u_int)$1, 0); } | relop NUM { $$.b = gen_atmfield_code($<blk>0.atmfieldtype, (bpf_int32)$2, (bpf_u_int32)$1, 0); }
| irelop NUM { $$.b = gen_atmfield_code($<blk>0.atmfieldtype, (u_int)$2, (u_int)$1, 1); } | irelop NUM { $$.b = gen_atmfield_code($<blk>0.atmfieldtype, (bpf_int32)$2, (bpf_u_int32)$1, 1); }
| paren atmlistvalue ')' { $$.b = $2.b; $$.q = qerr; } | paren atmlistvalue ')' { $$.b = $2.b; $$.q = qerr; }
; ;
atmfieldvalue: NUM { atmfieldvalue: NUM {
$$.atmfieldtype = $<blk>0.atmfieldtype; $$.atmfieldtype = $<blk>0.atmfieldtype;
if ($$.atmfieldtype == A_VPI || if ($$.atmfieldtype == A_VPI ||
$$.atmfieldtype == A_VCI) $$.atmfieldtype == A_VCI)
$$.b = gen_atmfield_code($$.atmfieldtype, (u_int) $1, BPF_JEQ, 0); $$.b = gen_atmfield_code($$.atmfieldtype, (bpf_int32) $1, BPF_JEQ, 0);
} }
; ;
atmlistvalue: atmfieldvalue atmlistvalue: atmfieldvalue
Expand Down

0 comments on commit 6804103

Please sign in to comment.