static struct block *gen_jmp(compiler_state_t *, int, bpf_u_int32,
struct slist *);
static struct block *gen_set(compiler_state_t *, bpf_u_int32, struct slist *);
+static struct block *gen_unset(compiler_state_t *, bpf_u_int32, struct slist *);
static struct block *gen_ncmp(compiler_state_t *, enum e_offrel, u_int,
u_int, bpf_u_int32, int, int, bpf_u_int32);
static struct slist *gen_load_absoffsetrel(compiler_state_t *, bpf_abs_offset *,
return gen_jmp(cstate, BPF_JSET, v, stmts);
}
+static struct block *
+gen_unset(compiler_state_t *cstate, bpf_u_int32 v, struct slist *stmts)
+{
+ struct block *b = gen_set(cstate, v, stmts);
+ gen_not(b);
+ return b;
+}
+
/*
* AND the field of size "size" at offset "offset" relative to the header
* specified by "offrel" with "mask", and compare it with the value "v"
* be clear for I frames.
*/
s = gen_load_a(cstate, OR_LLC, 2, BPF_B);
- b1 = new_block(cstate, JMP(BPF_JSET));
- b1->s.k = 0x01;
- b1->stmts = s;
- gen_not(b1);
+ b1 = gen_unset(cstate, 0x01, s);
+
gen_and(b0, b1);
return b1;
}
* "!(link[1] & 0x01)".
*/
s = gen_load_a(cstate, OR_LINKHDR, 1, BPF_B);
- b2 = new_block(cstate, JMP(BPF_JSET));
- b2->s.k = 0x01; /* To DS */
- b2->stmts = s;
- gen_not(b2);
+ b2 = gen_unset(cstate, IEEE80211_FC1_DIR_TODS, s);
/*
* If To DS is not set, the SA is at 16.
* Now check for data frames with From DS not set.
*/
s = gen_load_a(cstate, OR_LINKHDR, 1, BPF_B);
- b2 = new_block(cstate, JMP(BPF_JSET));
- b2->s.k = 0x02; /* From DS */
- b2->stmts = s;
- gen_not(b2);
+ b2 = gen_unset(cstate, IEEE80211_FC1_DIR_FROMDS, s);
/*
* If From DS isn't set, the SA is at 10.
* I.e, check "!(link[0] & 0x08)".
*/
s = gen_load_a(cstate, OR_LINKHDR, 0, BPF_B);
- b2 = new_block(cstate, JMP(BPF_JSET));
- b2->s.k = 0x08;
- b2->stmts = s;
- gen_not(b2);
+ b2 = gen_unset(cstate, IEEE80211_FC0_TYPE_DATA, s);
/*
* For management frames, the SA is at 10.
* I.e., check "!(link[0] & 0x04)".
*/
s = gen_load_a(cstate, OR_LINKHDR, 0, BPF_B);
- b1 = new_block(cstate, JMP(BPF_JSET));
- b1->s.k = 0x04;
- b1->stmts = s;
- gen_not(b1);
+ b1 = gen_unset(cstate, IEEE80211_FC0_TYPE_CTL, s);
/*
* AND that with the checks for data and management
* "!(link[1] & 0x01)".
*/
s = gen_load_a(cstate, OR_LINKHDR, 1, BPF_B);
- b2 = new_block(cstate, JMP(BPF_JSET));
- b2->s.k = 0x01; /* To DS */
- b2->stmts = s;
- gen_not(b2);
+ b2 = gen_unset(cstate, IEEE80211_FC1_DIR_TODS, s);
/*
* If To DS is not set, the DA is at 4.
* I.e, check "!(link[0] & 0x08)".
*/
s = gen_load_a(cstate, OR_LINKHDR, 0, BPF_B);
- b2 = new_block(cstate, JMP(BPF_JSET));
- b2->s.k = 0x08;
- b2->stmts = s;
- gen_not(b2);
+ b2 = gen_unset(cstate, IEEE80211_FC0_TYPE_DATA, s);
/*
* For management frames, the DA is at 4.
* I.e., check "!(link[0] & 0x04)".
*/
s = gen_load_a(cstate, OR_LINKHDR, 0, BPF_B);
- b1 = new_block(cstate, JMP(BPF_JSET));
- b1->s.k = 0x04;
- b1->stmts = s;
- gen_not(b1);
+ b1 = gen_unset(cstate, IEEE80211_FC0_TYPE_CTL, s);
/*
* AND that with the checks for data and management
gen_ipfrag(compiler_state_t *cstate)
{
struct slist *s;
- struct block *b;
/* not IPv4 frag other than the first frag */
s = gen_load_a(cstate, OR_LINKPL, 6, BPF_H);
- b = new_block(cstate, JMP(BPF_JSET));
- b->s.k = 0x1fff;
- b->stmts = s;
- gen_not(b);
-
- return b;
+ return gen_unset(cstate, 0x1fff, s);
}
/*
* "!(link[1] & 0x01)".
*/
s = gen_load_a(cstate, OR_LINKHDR, 1, BPF_B);
- b2 = new_block(cstate, JMP(BPF_JSET));
- b2->s.k = 0x01; /* To DS */
- b2->stmts = s;
- gen_not(b2);
+ b2 = gen_unset(cstate, IEEE80211_FC1_DIR_TODS, s);
/*
* If To DS is not set, the DA is at 4.
* I.e, check "!(link[0] & 0x08)".
*/
s = gen_load_a(cstate, OR_LINKHDR, 0, BPF_B);
- b2 = new_block(cstate, JMP(BPF_JSET));
- b2->s.k = 0x08;
- b2->stmts = s;
- gen_not(b2);
+ b2 = gen_unset(cstate, IEEE80211_FC0_TYPE_DATA, s);
/*
* For management frames, the DA is at 4.
* I.e., check "!(link[0] & 0x04)".
*/
s = gen_load_a(cstate, OR_LINKHDR, 0, BPF_B);
- b1 = new_block(cstate, JMP(BPF_JSET));
- b1->s.k = 0x04;
- b1->stmts = s;
- gen_not(b1);
+ b1 = gen_unset(cstate, IEEE80211_FC0_TYPE_CTL, s);
/*
* AND that with the checks for data and management