diff --git a/ebpfcat/ebpf.py b/ebpfcat/ebpf.py index 4960a2e95c4bca9d0700e86d42bba23c6d7f39d8..84d2a878bec4ed6a711b501c52d059ebf30873d6 100644 --- a/ebpfcat/ebpf.py +++ b/ebpfcat/ebpf.py @@ -759,7 +759,7 @@ class PseudoFd(Expression): self.fd = fd @contextmanager - def calculate(self, dst, long, signed, force): + def calculate(self, dst, long, signed, force=False): with self.ebpf.get_free_register(dst) as dst: self.ebpf.append(Opcode.DW, dst, 1, 0, self.fd) self.ebpf.append(Opcode.W, 0, 0, 0, 0) @@ -771,13 +771,13 @@ class ktime(Expression): self.ebpf = ebpf @contextmanager - def calculate(self, dst, long, signed, force): + def calculate(self, dst, long, signed, force=False): with self.ebpf.get_free_register(dst) as dst: with self.ebpf.save_registers([i for i in range(6) if i != dst]): self.ebpf.call(FuncId.ktime_get_ns) if dst != 0: self.ebpf.r[dst] = self.ebpf.r0 - yield dst, True, False + yield dst, True, False class RegisterDesc: diff --git a/ebpfcat/ebpf_test.py b/ebpfcat/ebpf_test.py index cba423606f02078c63475c42df1a71a6acda8733..8cea647e78f61b32b4ea4ee19c216e9ded462656 100644 --- a/ebpfcat/ebpf_test.py +++ b/ebpfcat/ebpf_test.py @@ -541,12 +541,17 @@ class Tests(TestCase): def test_ktime(self): e = EBPF() + e.r0 = 3 e.r3 = ktime(e) self.assertEqual(e.opcodes, [ - Instruction(opcode=O.REG+O.MOV+O.LONG, dst=6, src=1, off=0, imm=0), + Instruction(opcode=O.LONG+O.MOV, dst=0, src=0, off=0, imm=3), + Instruction(opcode=O.REG+O.MOV+O.LONG, dst=6, src=0, off=0, imm=0), + Instruction(opcode=O.REG+O.MOV+O.LONG, dst=7, src=1, off=0, imm=0), Instruction(opcode=O.CALL, dst=0, src=0, off=0, imm=5), Instruction(opcode=O.REG+O.MOV+O.LONG, dst=3, src=0, off=0, imm=0), - Instruction(opcode=O.REG+O.MOV+O.LONG, dst=1, src=6, off=0, imm=0)]) + Instruction(opcode=O.REG+O.MOV+O.LONG, dst=0, src=6, off=0, imm=0), + Instruction(opcode=O.REG+O.MOV+O.LONG, dst=1, src=7, off=0, imm=0) + ]) def test_xdp(self): e = XDP(license="GPL")