|
14 | 14 | //! have been added over time, resulting in different versions of the eBPF instruction set. We will denote
|
15 | 15 | //! if an operation is part of the v2 or v3 instruction set.
|
16 | 16 | //!
|
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) |
18 | 19 | //!
|
19 | 20 | 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 |
| -}; |
24 | 21 | use num_enum::{IntoPrimitive, TryFromPrimitive};
|
25 |
| -use sys::BPF_JA; |
26 | 22 |
|
27 | 23 | /// Instruction classes
|
28 | 24 | ///
|
@@ -120,28 +116,42 @@ pub enum AluOp {
|
120 | 116 | #[derive(Debug, TryFromPrimitive, IntoPrimitive, Clone, Copy, PartialEq, Eq, Hash)]
|
121 | 117 | pub enum JmpOp {
|
122 | 118 | /// 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, |
125 | 129 | /// 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, |
127 | 137 | }
|
128 | 138 |
|
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) } |
131 | 141 | }
|
132 | 142 |
|
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) } |
135 | 145 | }
|
136 | 146 |
|
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) } |
139 | 149 | }
|
140 | 150 |
|
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) } |
143 | 153 | }
|
144 | 154 |
|
145 |
| -pub fn exit() -> bpf_insn { |
146 |
| - unsafe { _BPF_EXIT_INSN() } |
| 155 | +pub fn exit() -> sys::bpf_insn { |
| 156 | + unsafe { sys::_BPF_EXIT_INSN() } |
147 | 157 | }
|
0 commit comments