Add condition eval and basic if example - workin

This commit is contained in:
Pragyansh Chaturvedi
2025-09-10 04:05:07 +05:30
parent 357ad7cb99
commit aeb9a45175
3 changed files with 95 additions and 43 deletions

View File

@ -1,9 +1,10 @@
from pythonbpf import bpf, map, section, bpfglobal, compile
from pythonbpf.helpers import bpf_ktime_get_ns
from pythonbpf.helpers import ktime
from pythonbpf.maps import HashMap
from ctypes import c_void_p, c_int64, c_int32, c_uint64
@bpf
@map
def last() -> HashMap:
@ -24,13 +25,16 @@ def hello_again(ctx: c_void_p) -> c_int64:
print("exited")
key = 0
tsp = last().lookup(key)
if tsp:
delta = (bpf_ktime_get_ns() - tsp.value)
if delta < 1000000000:
print("execve called within last second")
last().delete(key)
ts = bpf_ktime_get_ns()
last().update(key, ts)
# if tsp:
# delta = (bpf_ktime_get_ns() - tsp.value)
# if delta < 1000000000:
# print("execve called within last second")
# last().delete(key)
if True:
print("we prevailed")
# ts = ktime()
ktime()
# last().update(key, ts)
return c_int64(0)
@ -39,4 +43,5 @@ def hello_again(ctx: c_void_p) -> c_int64:
def LICENSE() -> str:
return "GPL"
compile()