|
@@ -567,6 +567,10 @@ pub enum Cond {
|
|
Greater = BPF_JGT as isize,
|
|
Greater = BPF_JGT as isize,
|
|
/// Jump if `>=`
|
|
/// Jump if `>=`
|
|
GreaterEquals = BPF_JGE as isize,
|
|
GreaterEquals = BPF_JGE as isize,
|
|
|
|
+ /// Jump if `<`
|
|
|
|
+ Lower = BPF_JLT as isize,
|
|
|
|
+ /// Jump if `<=`
|
|
|
|
+ LowerEquals = BPF_JLE as isize,
|
|
/// Jump if `src` & `dst`
|
|
/// Jump if `src` & `dst`
|
|
BitAnd = BPF_JSET as isize,
|
|
BitAnd = BPF_JSET as isize,
|
|
/// Jump if `!=`
|
|
/// Jump if `!=`
|
|
@@ -574,7 +578,11 @@ pub enum Cond {
|
|
/// Jump if `>` (signed)
|
|
/// Jump if `>` (signed)
|
|
GreaterSigned = BPF_JSGT as isize,
|
|
GreaterSigned = BPF_JSGT as isize,
|
|
/// Jump if `>=` (signed)
|
|
/// Jump if `>=` (signed)
|
|
- GreaterEqualsSigned = BPF_JSGE as isize
|
|
|
|
|
|
+ GreaterEqualsSigned = BPF_JSGE as isize,
|
|
|
|
+ /// Jump if `<` (signed)
|
|
|
|
+ LowerSigned = BPF_JSLT as isize,
|
|
|
|
+ /// Jump if `<=` (signed)
|
|
|
|
+ LowerEqualsSigned = BPF_JSLE as isize
|
|
}
|
|
}
|
|
|
|
|
|
/// struct representation of CALL instruction
|
|
/// struct representation of CALL instruction
|
|
@@ -688,6 +696,22 @@ mod tests {
|
|
assert_eq!(program.into_bytes(), &[0x3d, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
|
|
assert_eq!(program.into_bytes(), &[0x3d, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ #[test]
|
|
|
|
+ fn jump_on_dst_lower_than_src() {
|
|
|
|
+ let mut program = BpfCode::new();
|
|
|
|
+ program.jump_conditional(Cond::Lower, Source::Reg).set_dst(0x03).set_src(0x02).push();
|
|
|
|
+
|
|
|
|
+ assert_eq!(program.into_bytes(), &[0xad, 0x23, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ #[test]
|
|
|
|
+ fn jump_on_dst_lower_or_equals_to_src() {
|
|
|
|
+ let mut program = BpfCode::new();
|
|
|
|
+ program.jump_conditional(Cond::LowerEquals, Source::Reg).set_dst(0x04).set_src(0x01).push();
|
|
|
|
+
|
|
|
|
+ assert_eq!(program.into_bytes(), &[0xbd, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
|
|
|
|
+ }
|
|
|
|
+
|
|
#[test]
|
|
#[test]
|
|
fn jump_on_dst_bit_and_with_src_not_equal_zero() {
|
|
fn jump_on_dst_bit_and_with_src_not_equal_zero() {
|
|
let mut program = BpfCode::new();
|
|
let mut program = BpfCode::new();
|
|
@@ -719,6 +743,22 @@ mod tests {
|
|
|
|
|
|
assert_eq!(program.into_bytes(), &[0x7d, 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
|
|
assert_eq!(program.into_bytes(), &[0x7d, 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ #[test]
|
|
|
|
+ fn jump_on_dst_lower_than_src_signed() {
|
|
|
|
+ let mut program = BpfCode::new();
|
|
|
|
+ program.jump_conditional(Cond::LowerSigned, Source::Reg).set_dst(0x04).set_src(0x01).push();
|
|
|
|
+
|
|
|
|
+ assert_eq!(program.into_bytes(), &[0xcd, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ #[test]
|
|
|
|
+ fn jump_on_dst_lower_or_equals_src_signed() {
|
|
|
|
+ let mut program = BpfCode::new();
|
|
|
|
+ program.jump_conditional(Cond::LowerEqualsSigned, Source::Reg).set_dst(0x01).set_src(0x03).push();
|
|
|
|
+
|
|
|
|
+ assert_eq!(program.into_bytes(), &[0xdd, 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
#[cfg(test)]
|
|
#[cfg(test)]
|
|
@@ -757,6 +797,22 @@ mod tests {
|
|
assert_eq!(program.into_bytes(), &[0x35, 0x04, 0x00, 0x00, 0x00, 0x11, 0x22, 0x00]);
|
|
assert_eq!(program.into_bytes(), &[0x35, 0x04, 0x00, 0x00, 0x00, 0x11, 0x22, 0x00]);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ #[test]
|
|
|
|
+ fn jump_on_dst_lower_than_const() {
|
|
|
|
+ let mut program = BpfCode::new();
|
|
|
|
+ program.jump_conditional(Cond::Lower, Source::Imm).set_dst(0x02).set_imm(0x00_11_00_11).push();
|
|
|
|
+
|
|
|
|
+ assert_eq!(program.into_bytes(), &[0xa5, 0x02, 0x00, 0x00, 0x11, 0x00, 0x11, 0x00]);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ #[test]
|
|
|
|
+ fn jump_on_dst_lower_or_equals_to_const() {
|
|
|
|
+ let mut program = BpfCode::new();
|
|
|
|
+ program.jump_conditional(Cond::LowerEquals, Source::Imm).set_dst(0x04).set_imm(0x00_22_11_00).push();
|
|
|
|
+
|
|
|
|
+ assert_eq!(program.into_bytes(), &[0xb5, 0x04, 0x00, 0x00, 0x00, 0x11, 0x22, 0x00]);
|
|
|
|
+ }
|
|
|
|
+
|
|
#[test]
|
|
#[test]
|
|
fn jump_on_dst_bit_and_with_const_not_equal_zero() {
|
|
fn jump_on_dst_bit_and_with_const_not_equal_zero() {
|
|
let mut program = BpfCode::new();
|
|
let mut program = BpfCode::new();
|
|
@@ -788,6 +844,22 @@ mod tests {
|
|
|
|
|
|
assert_eq!(program.into_bytes(), &[0x75, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
|
|
assert_eq!(program.into_bytes(), &[0x75, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ #[test]
|
|
|
|
+ fn jump_on_dst_lower_than_const_signed() {
|
|
|
|
+ let mut program = BpfCode::new();
|
|
|
|
+ program.jump_conditional(Cond::LowerSigned, Source::Imm).set_dst(0x04).push();
|
|
|
|
+
|
|
|
|
+ assert_eq!(program.into_bytes(), &[0xc5, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ #[test]
|
|
|
|
+ fn jump_on_dst_lower_or_equals_src_signed() {
|
|
|
|
+ let mut program = BpfCode::new();
|
|
|
|
+ program.jump_conditional(Cond::LowerEqualsSigned, Source::Imm).set_dst(0x01).push();
|
|
|
|
+
|
|
|
|
+ assert_eq!(program.into_bytes(), &[0xd5, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|