Move the code to generate code to check for a particular linktype in the
Linux cooked header into a routine of its own.
This commit is contained in:
parent
f9b1d9732a
commit
a1e08cec1e
152
gencode.c
152
gencode.c
|
@ -21,7 +21,7 @@
|
|||
*/
|
||||
#ifndef lint
|
||||
static const char rcsid[] _U_ =
|
||||
"@(#) $Header: /tcpdump/master/libpcap/gencode.c,v 1.210 2004-10-19 15:55:28 hannes Exp $ (LBL)";
|
||||
"@(#) $Header: /tcpdump/master/libpcap/gencode.c,v 1.211 2004-11-06 22:45:17 guy Exp $ (LBL)";
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
|
@ -165,6 +165,7 @@ static struct block *gen_uncond(int);
|
|||
static inline struct block *gen_true(void);
|
||||
static inline struct block *gen_false(void);
|
||||
static struct block *gen_ether_linktype(int);
|
||||
static struct block *gen_linux_sll_linktype(int);
|
||||
static struct block *gen_linktype(int);
|
||||
static struct block *gen_snap(bpf_u_int32, bpf_u_int32, u_int);
|
||||
static struct block *gen_llc(int);
|
||||
|
@ -1260,79 +1261,11 @@ gen_ether_linktype(proto)
|
|||
}
|
||||
|
||||
static struct block *
|
||||
gen_linktype(proto)
|
||||
gen_linux_sll_linktype(proto)
|
||||
register int proto;
|
||||
{
|
||||
struct block *b0, *b1, *b2;
|
||||
struct block *b0, *b1;
|
||||
|
||||
switch (linktype) {
|
||||
|
||||
case DLT_EN10MB:
|
||||
return gen_ether_linktype(proto);
|
||||
/*NOTREACHED*/
|
||||
break;
|
||||
|
||||
case DLT_C_HDLC:
|
||||
switch (proto) {
|
||||
|
||||
case LLCSAP_ISONS:
|
||||
proto = (proto << 8 | LLCSAP_ISONS);
|
||||
/* fall through */
|
||||
|
||||
default:
|
||||
return gen_cmp(off_linktype, BPF_H, (bpf_int32)proto);
|
||||
/*NOTREACHED*/
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case DLT_IEEE802_11:
|
||||
case DLT_PRISM_HEADER:
|
||||
case DLT_IEEE802_11_RADIO:
|
||||
case DLT_FDDI:
|
||||
case DLT_IEEE802:
|
||||
case DLT_ATM_RFC1483:
|
||||
case DLT_ATM_CLIP:
|
||||
case DLT_IP_OVER_FC:
|
||||
return gen_llc(proto);
|
||||
/*NOTREACHED*/
|
||||
break;
|
||||
|
||||
case DLT_SUNATM:
|
||||
/*
|
||||
* If "is_lane" is set, check for a LANE-encapsulated
|
||||
* version of this protocol, otherwise check for an
|
||||
* LLC-encapsulated version of this protocol.
|
||||
*
|
||||
* We assume LANE means Ethernet, not Token Ring.
|
||||
*/
|
||||
if (is_lane) {
|
||||
/*
|
||||
* Check that the packet doesn't begin with an
|
||||
* LE Control marker. (We've already generated
|
||||
* a test for LANE.)
|
||||
*/
|
||||
b0 = gen_cmp(SUNATM_PKT_BEGIN_POS, BPF_H, 0xFF00);
|
||||
gen_not(b0);
|
||||
|
||||
/*
|
||||
* Now generate an Ethernet test.
|
||||
*/
|
||||
b1 = gen_ether_linktype(proto);
|
||||
gen_and(b0, b1);
|
||||
return b1;
|
||||
} else {
|
||||
/*
|
||||
* Check for LLC encapsulation and then check the
|
||||
* protocol.
|
||||
*/
|
||||
b0 = gen_atmfield_code(A_PROTOTYPE, PT_LLC, BPF_JEQ, 0);
|
||||
b1 = gen_llc(proto);
|
||||
gen_and(b0, b1);
|
||||
return b1;
|
||||
}
|
||||
|
||||
case DLT_LINUX_SLL:
|
||||
switch (proto) {
|
||||
|
||||
case LLCSAP_IP:
|
||||
|
@ -1491,6 +1424,83 @@ gen_linktype(proto)
|
|||
(bpf_int32)proto);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static struct block *
|
||||
gen_linktype(proto)
|
||||
register int proto;
|
||||
{
|
||||
struct block *b0, *b1, *b2;
|
||||
|
||||
switch (linktype) {
|
||||
|
||||
case DLT_EN10MB:
|
||||
return gen_ether_linktype(proto);
|
||||
/*NOTREACHED*/
|
||||
break;
|
||||
|
||||
case DLT_C_HDLC:
|
||||
switch (proto) {
|
||||
|
||||
case LLCSAP_ISONS:
|
||||
proto = (proto << 8 | LLCSAP_ISONS);
|
||||
/* fall through */
|
||||
|
||||
default:
|
||||
return gen_cmp(off_linktype, BPF_H, (bpf_int32)proto);
|
||||
/*NOTREACHED*/
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case DLT_IEEE802_11:
|
||||
case DLT_PRISM_HEADER:
|
||||
case DLT_IEEE802_11_RADIO:
|
||||
case DLT_FDDI:
|
||||
case DLT_IEEE802:
|
||||
case DLT_ATM_RFC1483:
|
||||
case DLT_ATM_CLIP:
|
||||
case DLT_IP_OVER_FC:
|
||||
return gen_llc(proto);
|
||||
/*NOTREACHED*/
|
||||
break;
|
||||
|
||||
case DLT_SUNATM:
|
||||
/*
|
||||
* If "is_lane" is set, check for a LANE-encapsulated
|
||||
* version of this protocol, otherwise check for an
|
||||
* LLC-encapsulated version of this protocol.
|
||||
*
|
||||
* We assume LANE means Ethernet, not Token Ring.
|
||||
*/
|
||||
if (is_lane) {
|
||||
/*
|
||||
* Check that the packet doesn't begin with an
|
||||
* LE Control marker. (We've already generated
|
||||
* a test for LANE.)
|
||||
*/
|
||||
b0 = gen_cmp(SUNATM_PKT_BEGIN_POS, BPF_H, 0xFF00);
|
||||
gen_not(b0);
|
||||
|
||||
/*
|
||||
* Now generate an Ethernet test.
|
||||
*/
|
||||
b1 = gen_ether_linktype(proto);
|
||||
gen_and(b0, b1);
|
||||
return b1;
|
||||
} else {
|
||||
/*
|
||||
* Check for LLC encapsulation and then check the
|
||||
* protocol.
|
||||
*/
|
||||
b0 = gen_atmfield_code(A_PROTOTYPE, PT_LLC, BPF_JEQ, 0);
|
||||
b1 = gen_llc(proto);
|
||||
gen_and(b0, b1);
|
||||
return b1;
|
||||
}
|
||||
|
||||
case DLT_LINUX_SLL:
|
||||
return gen_linux_sll_linktype(proto);
|
||||
/*NOTREACHED*/
|
||||
break;
|
||||
|
||||
|
|
Reference in New Issue