dect
/
libpcap
Archived
13
0
Fork 0

Added more code in the compilation for the PPI linktype: now we generate

code that discards non-802.11 packets.
A couple of mods to remove some compilation warnings with VC6.
This commit is contained in:
gianluca 2007-06-14 18:49:30 +00:00
parent 9c308a3a48
commit ec63ab312c
1 changed files with 33 additions and 36 deletions

View File

@ -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.281 2007-06-14 18:14:06 gianluca Exp $ (LBL)"; "@(#) $Header: /tcpdump/master/libpcap/gencode.c,v 1.282 2007-06-14 18:49:30 gianluca Exp $ (LBL)";
#endif #endif
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
@ -100,8 +100,12 @@ static const char rcsid[] _U_ =
static jmp_buf top_ctx; static jmp_buf top_ctx;
static pcap_t *bpf_pcap; static pcap_t *bpf_pcap;
#ifdef WIN32
/* Hack for updating VLAN, MPLS, and PPPoE offsets. */ /* Hack for updating VLAN, MPLS, and PPPoE offsets. */
static u_int orig_linktype = (u_int)-1, orig_nl = (u_int)-1, label_stack_depth = (u_int)-1;
#else
static u_int orig_linktype = -1U, orig_nl = -1U, label_stack_depth = -1U; static u_int orig_linktype = -1U, orig_nl = -1U, label_stack_depth = -1U;
#endif
/* XXX */ /* XXX */
#ifdef PCAP_FDDIPAD #ifdef PCAP_FDDIPAD
@ -478,6 +482,7 @@ void
finish_parse(p) finish_parse(p)
struct block *p; struct block *p;
{ {
insert_load_llprefixlen(p);
backpatch(p, gen_retblk(snaplen)); backpatch(p, gen_retblk(snaplen));
p->sense = !p->sense; p->sense = !p->sense;
backpatch(p, gen_retblk(0)); backpatch(p, gen_retblk(0));
@ -498,7 +503,6 @@ finish_parse(p)
* require the length of that header, doing more for that * require the length of that header, doing more for that
* header length isn't really worth the effort. * header length isn't really worth the effort.
*/ */
insert_load_llprefixlen(root);
} }
void void
@ -1011,18 +1015,12 @@ init_linktype(p)
/* /*
* TODO GV
*
* At the moment we treat PPI as normal Radiotap encoded * At the moment we treat PPI as normal Radiotap encoded
* packets. The difference is in the function that generates * packets. The difference is in the function that generates
* the code at the beginning to compute the header length. * the code at the beginning to compute the header length.
* Since this code generator of PPI supports bare 802.11 * Since this code generator of PPI supports bare 802.11
* encapsulation only (i.e. the encapsulated DLT should be * encapsulation only (i.e. the encapsulated DLT should be
* DLT_IEEE802_11) we should generate code to check for this. * DLT_IEEE802_11) we generate code to check for this too.
* Unfortunately given the current structure of the code generator,
* generating the proper JMP(x) code to be prepended is problematic.
* We just ignore the DLT in the PPI header.
*
*/ */
case DLT_PPI: case DLT_PPI:
case DLT_IEEE802_11_RADIO: case DLT_IEEE802_11_RADIO:
@ -1913,24 +1911,21 @@ insert_radiotap_load_llprefixlen(b)
} }
/* /*
* TODO GV
*
* At the moment we treat PPI as normal Radiotap encoded * At the moment we treat PPI as normal Radiotap encoded
* packets. The difference is in the function that generates * packets. The difference is in the function that generates
* the code at the beginning to compute the header length. * the code at the beginning to compute the header length.
* Since this code generator of PPI supports bare 802.11 * Since this code generator of PPI supports bare 802.11
* encapsulation only (i.e. the encapsulated DLT should be * encapsulation only (i.e. the encapsulated DLT should be
* DLT_IEEE802_11) we should generate code to check for this. * DLT_IEEE802_11) we generate code to check for this too.
* Unfortunately given the current structure of the code generator,
* generating the proper JMP(x) code to be prepended is problematic.
* We just ignore the DLT in the PPI header.
*
*/ */
static void static void
insert_ppi_load_llprefixlen(b) insert_ppi_load_llprefixlen(b)
struct block *b; struct block *b;
{ {
struct slist *s1, *s2; struct slist *s1, *s2;
struct slist *s_load_dlt;
struct block *new_b;
struct block temp;
/* /*
* Prepend to the statements in this block code to load the * Prepend to the statements in this block code to load the
@ -1938,7 +1933,7 @@ insert_ppi_load_llprefixlen(b)
* to hold that length, if one has been assigned. * to hold that length, if one has been assigned.
*/ */
if (reg_ll_size != -1) { if (reg_ll_size != -1) {
/* /*
* The 2 bytes at offsets of 2 and 3 from the beginning * The 2 bytes at offsets of 2 and 3 from the beginning
* of the radiotap header are the length of the radiotap * of the radiotap header are the length of the radiotap
* header; unfortunately, it's little-endian, so we have * header; unfortunately, it's little-endian, so we have
@ -1987,6 +1982,20 @@ insert_ppi_load_llprefixlen(b)
*/ */
sappend(s1, b->stmts); sappend(s1, b->stmts);
b->stmts = s1; b->stmts = s1;
temp = *b;
/* Create the statements that check for the DLT
*/
s_load_dlt = new_stmt(BPF_LD|BPF_W|BPF_ABS);
s_load_dlt->s.k = 4;
new_b = new_block(JMP(BPF_JEQ));
new_b->stmts = s_load_dlt;
new_b->s.k = SWAPLONG(DLT_IEEE802_11);
gen_and(new_b,b);
} }
} }
@ -1997,18 +2006,12 @@ insert_load_llprefixlen(b)
switch (linktype) { switch (linktype) {
/* /*
* TODO GV
*
* At the moment we treat PPI as normal Radiotap encoded * At the moment we treat PPI as normal Radiotap encoded
* packets. The difference is in the function that generates * packets. The difference is in the function that generates
* the code at the beginning to compute the header length. * the code at the beginning to compute the header length.
* Since this code generator of PPI supports bare 802.11 * Since this code generator of PPI supports bare 802.11
* encapsulation only (i.e. the encapsulated DLT should be * encapsulation only (i.e. the encapsulated DLT should be
* DLT_IEEE802_11) we should generate code to check for this. * DLT_IEEE802_11) we generate code to check for this too.
* Unfortunately given the current structure of the code generator,
* generating the proper JMP(x) code to be prepended is problematic.
* We just ignore the DLT in the PPI header.
*
*/ */
case DLT_PPI: case DLT_PPI:
insert_ppi_load_llprefixlen(b); insert_ppi_load_llprefixlen(b);
@ -2044,18 +2047,12 @@ gen_radiotap_llprefixlen(void)
} }
/* /*
* TODO GV
*
* At the moment we treat PPI as normal Radiotap encoded * At the moment we treat PPI as normal Radiotap encoded
* packets. The difference is in the function that generates * packets. The difference is in the function that generates
* the code at the beginning to compute the header length. * the code at the beginning to compute the header length.
* Since this code generator of PPI supports bare 802.11 * Since this code generator of PPI supports bare 802.11
* encapsulation only (i.e. the encapsulated DLT should be * encapsulation only (i.e. the encapsulated DLT should be
* DLT_IEEE802_11) we should generate code to check for this. * DLT_IEEE802_11) we generate code to check for this too.
* Unfortunately given the current structure of the code generator,
* generating the proper JMP(x) code to be prepended is problematic.
* We just ignore the DLT in the PPI header.
*
*/ */
static struct slist * static struct slist *
gen_ppi_llprefixlen(void) gen_ppi_llprefixlen(void)
@ -3306,22 +3303,22 @@ gen_dnhostop(addr, dir)
tmp = gen_mcmp(OR_NET, 2, BPF_H, tmp = gen_mcmp(OR_NET, 2, BPF_H,
(bpf_int32)ntohs(0x0681), (bpf_int32)ntohs(0x07FF)); (bpf_int32)ntohs(0x0681), (bpf_int32)ntohs(0x07FF));
b1 = gen_cmp(OR_NET, 2 + 1 + offset_lh, b1 = gen_cmp(OR_NET, 2 + 1 + offset_lh,
BPF_H, (bpf_int32)ntohs(addr)); BPF_H, (bpf_int32)ntohs((u_short)addr));
gen_and(tmp, b1); gen_and(tmp, b1);
/* Check for pad = 0, long header case */ /* Check for pad = 0, long header case */
tmp = gen_mcmp(OR_NET, 2, BPF_B, (bpf_int32)0x06, (bpf_int32)0x7); tmp = gen_mcmp(OR_NET, 2, BPF_B, (bpf_int32)0x06, (bpf_int32)0x7);
b2 = gen_cmp(OR_NET, 2 + offset_lh, BPF_H, (bpf_int32)ntohs(addr)); b2 = gen_cmp(OR_NET, 2 + offset_lh, BPF_H, (bpf_int32)ntohs((u_short)addr));
gen_and(tmp, b2); gen_and(tmp, b2);
gen_or(b2, b1); gen_or(b2, b1);
/* Check for pad = 1, short header case */ /* Check for pad = 1, short header case */
tmp = gen_mcmp(OR_NET, 2, BPF_H, tmp = gen_mcmp(OR_NET, 2, BPF_H,
(bpf_int32)ntohs(0x0281), (bpf_int32)ntohs(0x07FF)); (bpf_int32)ntohs(0x0281), (bpf_int32)ntohs(0x07FF));
b2 = gen_cmp(OR_NET, 2 + 1 + offset_sh, BPF_H, (bpf_int32)ntohs(addr)); b2 = gen_cmp(OR_NET, 2 + 1 + offset_sh, BPF_H, (bpf_int32)ntohs((u_short)addr));
gen_and(tmp, b2); gen_and(tmp, b2);
gen_or(b2, b1); gen_or(b2, b1);
/* Check for pad = 0, short header case */ /* Check for pad = 0, short header case */
tmp = gen_mcmp(OR_NET, 2, BPF_B, (bpf_int32)0x02, (bpf_int32)0x7); tmp = gen_mcmp(OR_NET, 2, BPF_B, (bpf_int32)0x02, (bpf_int32)0x7);
b2 = gen_cmp(OR_NET, 2 + offset_sh, BPF_H, (bpf_int32)ntohs(addr)); b2 = gen_cmp(OR_NET, 2 + offset_sh, BPF_H, (bpf_int32)ntohs((u_short)addr));
gen_and(tmp, b2); gen_and(tmp, b2);
gen_or(b2, b1); gen_or(b2, b1);