diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 4e13e66a47229390e64cb0bd77b1c7637fe7c563..19eb304c801b252e9ca4027d4a9c8cbbdc7218b4 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -2,5 +2,4 @@ test: image: python:3.8-slim script: - cd .. - - python3 -m ebpfcat.ebpf_test -v Tests - - sudo python3 -m ebpfcat.ebpf_test -v KernelTests + - python3 -m ebpfcat.ebpf_test -v diff --git a/bpf.py b/bpf.py index a545eb98b7bbdce794ab6533364e99f4692fdb78..26dca12ebc7e8a34a29d0afaebc1fe534d2d4b0c 100644 --- a/bpf.py +++ b/bpf.py @@ -1,9 +1,19 @@ from ctypes import CDLL, c_int, get_errno, cast, c_void_p, create_string_buffer, c_char_p from enum import Enum from struct import pack, unpack +from platform import machine from os import strerror +try: + SYS_BPF = { + "armv7l": 386, + "x86_64": 321, + }[machine()] +except KeyError: + print("Unknown platform:", machine()) + + class BPFError(OSError): pass @@ -61,7 +71,7 @@ def addrof(ptr): def bpf(cmd, fmt, *args): attr = pack(fmt, *args) attr = create_string_buffer(attr, len(attr)) - ret = libc.syscall(386, c_int(cmd), attr, len(attr)) + ret = libc.syscall(SYS_BPF, c_int(cmd), attr, len(attr)) if ret == -1: raise OSError(get_errno(), strerror(get_errno())) return ret, unpack(fmt, attr.raw)