• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1local ffi = require('ffi')
2
3-- Define basic ctypes
4ffi.cdef [[
5	struct bpf_insn {
6	  uint8_t code;   /* opcode */
7	  uint8_t dst_reg:4;  /* dest register */
8	  uint8_t src_reg:4;  /* source register */
9	  uint16_t off;   /* signed offset */
10	  uint32_t imm;   /* signed immediate constant */
11	};
12]]
13
14-- Inject mock ljsyscall for tests
15package.loaded['syscall'] = {
16	bpf = function() error('mock') end,
17	c = { BPF_MAP = {}, BPF_PROG = {} },
18	abi = { arch = 'x64' },
19}
20
21package.loaded['syscall.helpers'] = {
22	strflag = function (tab)
23		local function flag(cache, str)
24			if type(str) ~= "string" then return str end
25			if #str == 0 then return 0 end
26			local s = str:upper()
27			if #s == 0 then return 0 end
28			local val = rawget(tab, s)
29			if not val then return nil end
30			cache[str] = val
31			return val
32		end
33		return setmetatable(tab, {__index = setmetatable({}, {__index = flag}), __call = function(t, a) return t[a] end})
34	end
35}