Skip to content

Commit eef5fff

Browse files
committed
bpf-rs: rest of jmp insns
Signed-off-by: Milan <milan@mdaverde.com>
1 parent 8705711 commit eef5fff

File tree

1 file changed

+29
-19
lines changed

1 file changed

+29
-19
lines changed

bpf-rs/src/insns.rs

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,11 @@
1414
//! have been added over time, resulting in different versions of the eBPF instruction set. We will denote
1515
//! if an operation is part of the v2 or v3 instruction set.
1616
//!
17-
//! For more info, see [Paul Chaignon's blog post](https://pchaigno.github.io/bpf/2021/10/20/ebpf-instruction-sets.html)
17+
//! For more info, see [BPF Design Q&A](https://www.kernel.org/doc/html/latest/bpf/bpf_design_QA.html#q-why-bpf-jlt-and-bpf-jle-instructions-were-not-introduced-in-the-beginning)
18+
//! and [Paul Chaignon's blog post](https://pchaigno.github.io/bpf/2021/10/20/ebpf-instruction-sets.html)
1819
//!
1920
use libbpf_sys as sys;
20-
use libbpf_sys::{
21-
bpf_insn, BPF_JLT, BPF_JNE, _BPF_ALU64_IMM, _BPF_EXIT_INSN, _BPF_JMP32_IMM, _BPF_JMP_IMM,
22-
_BPF_MOV64_IMM,
23-
};
2421
use num_enum::{IntoPrimitive, TryFromPrimitive};
25-
use sys::BPF_JA;
2622

2723
/// Instruction classes
2824
///
@@ -120,28 +116,42 @@ pub enum AluOp {
120116
#[derive(Debug, TryFromPrimitive, IntoPrimitive, Clone, Copy, PartialEq, Eq, Hash)]
121117
pub enum JmpOp {
122118
/// Only allowed with the BPF_JMP instruction class
123-
JA = BPF_JA as u8,
124-
JNE = BPF_JNE as u8,
119+
JA = sys::BPF_JA as u8,
120+
JEQ = sys::BPF_JEQ as u8,
121+
JGT = sys::BPF_JGT as u8,
122+
JGE = sys::BPF_JGE as u8,
123+
JSET = sys::BPF_JSET as u8,
124+
JNE = sys::BPF_JNE as u8,
125+
JSGT = sys::BPF_JSGT as u8,
126+
JSGE = sys::BPF_JSGE as u8,
127+
CALL = sys::BPF_CALL as u8,
128+
EXIT = sys::BPF_EXIT as u8,
125129
/// Part of [ISA v2](./#instruction-set-isa-versions)
126-
JLT = BPF_JLT as u8,
130+
JLT = sys::BPF_JLT as u8,
131+
/// Part of [ISA v2](./#instruction-set-isa-versions)
132+
JLE = sys::BPF_JLE as u8,
133+
/// Part of [ISA v2](./#instruction-set-isa-versions)
134+
JSLT = sys::BPF_JSLT as u8,
135+
/// Part of [ISA v2](./#instruction-set-isa-versions)
136+
JSLE = sys::BPF_JSLE as u8,
127137
}
128138

129-
pub fn mov64_imm(reg: Register, imm: i32) -> bpf_insn {
130-
unsafe { _BPF_MOV64_IMM(reg.into(), imm) }
139+
pub fn mov64_imm(reg: Register, imm: i32) -> sys::bpf_insn {
140+
unsafe { sys::_BPF_MOV64_IMM(reg.into(), imm) }
131141
}
132142

133-
pub fn alu64_imm(op: AluOp, reg: Register, imm: i32) -> bpf_insn {
134-
unsafe { _BPF_ALU64_IMM(op.into(), reg.into(), imm) }
143+
pub fn alu64_imm(op: AluOp, reg: Register, imm: i32) -> sys::bpf_insn {
144+
unsafe { sys::_BPF_ALU64_IMM(op.into(), reg.into(), imm) }
135145
}
136146

137-
pub fn jmp_imm(jmp: JmpOp, reg: Register, imm: i32, off: i16) -> bpf_insn {
138-
unsafe { _BPF_JMP_IMM(jmp.into(), reg.into(), imm, off) }
147+
pub fn jmp_imm(jmp: JmpOp, reg: Register, imm: i32, off: i16) -> sys::bpf_insn {
148+
unsafe { sys::_BPF_JMP_IMM(jmp.into(), reg.into(), imm, off) }
139149
}
140150

141-
pub fn jmp32_imm(jmp: JmpOp, reg: Register, imm: i32, off: i16) -> bpf_insn {
142-
unsafe { _BPF_JMP32_IMM(jmp.into(), reg.into(), imm, off) }
151+
pub fn jmp32_imm(jmp: JmpOp, reg: Register, imm: i32, off: i16) -> sys::bpf_insn {
152+
unsafe { sys::_BPF_JMP32_IMM(jmp.into(), reg.into(), imm, off) }
143153
}
144154

145-
pub fn exit() -> bpf_insn {
146-
unsafe { _BPF_EXIT_INSN() }
155+
pub fn exit() -> sys::bpf_insn {
156+
unsafe { sys::_BPF_EXIT_INSN() }
147157
}

0 commit comments

Comments
 (0)