Skip to content

Commit

Permalink
linux: added new constants (e.g. attach BPF to socket)
Browse files Browse the repository at this point in the history
increased default BPF prog load log size (too small)
  • Loading branch information
vavrusa committed Apr 14, 2016
1 parent 36274f3 commit 1f141ca
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 8 deletions.
16 changes: 15 additions & 1 deletion syscall/linux/constants.lua
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ c.SO = strflag(arch.SO or {
PRIORITY = 12,
LINGER = 13,
BSDCOMPAT = 14,
--REUSEPORT = 15, -- new, may not be defined yet
REUSEPORT = 15, -- new, may not be defined yet
PASSCRED = 16,
PEERCRED = 17,
RCVLOWAT = 18,
Expand Down Expand Up @@ -455,9 +455,19 @@ c.SO = strflag(arch.SO or {
WIFI_STATUS = 41,
PEEK_OFF = 42,
NOFCS = 43,
LOCK_FILTER = 44,
SELECT_ERR_QUEUE = 45,
BUSY_POLL = 46,
MAX_PACING_RATE = 47,
BPF_EXTENSIONS = 48,
INCOMING_CPU = 49,
ATTACH_BPF = 50,
ATTACH_REUSEPORT_CBPF = 51,
ATTACH_REUSEPORT_EBPF = 52,
})

c.SO.GET_FILTER = c.SO.ATTACH_FILTER
c.SO.DETACH_BPF = c.SO.DETACH_FILTER

-- Maximum queue length specifiable by listen.
c.SOMAXCONN = 128
Expand Down Expand Up @@ -2065,6 +2075,10 @@ c.BPF = multiflags {
TXA = 0x80,
TO_LE = 0x00,
TO_BE = 0x08,
-- flags
ANY = 0,
NOEXIST = 1,
EXIST = 2,
}

-- eBPF flags
Expand Down
14 changes: 7 additions & 7 deletions syscall/linux/syscalls.lua
Original file line number Diff line number Diff line change
Expand Up @@ -781,9 +781,9 @@ if C.bpf then
function S.bpf(cmd, attr)
return C.bpf(cmd, attr)
end
function S.bpf_prog_load(type, insns, len, license, version)
if not license then license = "GPL" end -- Must stay alive during the syscall
local bpf_log_buf = ffi.new('char [?]', 4096) -- Must stay alive during the syscall
function S.bpf_prog_load(type, insns, len, license, version, log_level)
if not license then license = "GPL" end -- Must stay alive during the syscall
local bpf_log_buf = ffi.new('char [?]', 64*1024) -- Must stay alive during the syscall
if not version then
-- We have no better way to extract current kernel hex-string other
-- than parsing headers, compiling a helper function or reading /proc
Expand All @@ -800,14 +800,14 @@ if C.bpf then
attr[0].insn_cnt = len
attr[0].license = ptr_to_u64(license)
attr[0].log_buf = ptr_to_u64(bpf_log_buf)
attr[0].log_size = 4096
attr[0].log_level = 1
attr[0].log_size = ffi.sizeof(bpf_log_buf)
attr[0].log_level = log_level or 1
attr[0].kern_version = version -- MUST match current kernel version
local fd = S.bpf(c.BPF_CMD.PROG_LOAD, attr)
if fd < 0 then
return nil, t.error(errno()), ffi.string(bpf_log_buf)
end
return fd
return retfd(fd), ffi.string(bpf_log_buf)
end
function S.bpf_map_create(type, key_size, value_size, max_entries)
local attr = t.bpf_attr1()
Expand All @@ -819,7 +819,7 @@ if C.bpf then
if fd < 0 then
return nil, t.error(errno())
end
return fd
return retfd(fd)
end
function S.bpf_map_op(op, fd, key, val_or_next, flags)
local attr = t.bpf_attr1()
Expand Down
14 changes: 14 additions & 0 deletions test/ctest-linux.lua
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ c.BPF.CALL = nil
c.BPF.EXIT = nil
c.BPF.TO_LE = nil
c.BPF.TO_BE = nil
c.BPF.ANY = nil
c.BPF.NOEXIST = nil
c.BPF.EXIST = nil
c.BPF.END = nil
c.BPF.ARSH = nil
c.BPF.XADD = nil
Expand Down Expand Up @@ -304,6 +307,17 @@ c.SO.PEEK_OFF = nil
c.SO.GET_FILTER = nil
c.SO.NOFCS = nil
c.SO.WIFI_STATUS = nil
c.SO.REUSEPORT = nil
c.SO.LOCK_FILTER = nil
c.SO.SELECT_ERR_QUEUE = nil
c.SO.BUSY_POLL = nil
c.SO.MAX_PACING_RATE = nil
c.SO.BPF_EXTENSIONS = nil
c.SO.INCOMING_CPU = nil
c.SO.ATTACH_BPF = nil
c.SO.DETACH_BPF = nil
c.SO.ATTACH_REUSEPORT_CBPF = nil
c.SO.ATTACH_REUSEPORT_EBPF = nil

-- Musl changes some of the syscall constants in its 32/64 bit handling
c.SYS.getdents = nil
Expand Down
10 changes: 10 additions & 0 deletions test/linux-constants.lua
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,13 @@ local function fixup_constants(abi, c)
c.RTA.VIA = nil
c.RTA.MFC_STATS = nil
c.AUDIT_ARCH.AARCH64 = nil
c.SO.MAX_PACING_RATE = nil
c.SO.BPF_EXTENSIONS = nil
c.SO.INCOMING_CPU = nil
c.SO.ATTACH_BPF = nil
c.SO.DETACH_BPF = nil
c.SO.ATTACH_REUSEPORT_CBPF = nil
c.SO.ATTACH_REUSEPORT_EBPF = nil

-- these are not even in linux git head headers or names wrong
c.O.ASYNC = nil
Expand Down Expand Up @@ -228,6 +235,9 @@ local function fixup_constants(abi, c)
c.BPF.XADD = nil
c.BPF.JNE = nil
c.BPF.MOV = nil
c.BPF.ANY = nil
c.BPF.EXIST = nil
c.BPF.NOEXIST = nil

return c
end
Expand Down

0 comments on commit 1f141ca

Please sign in to comment.