lunatikModule
Names a kernel Lua runtime in a program file.
The compile-time twin of the kernel lunatik: runtime takes the script a runtime runs, as the kernel’s does, and names the runtimelunatik run starts from that script instead of creating
one.
Usage
local xdp = require("bpf.xdp")
local lunatik = require("lunatik")
local struct = require("struct")
local vmlinux = require("bpf.vmlinux")
local action = require("linux.xdp").action
local eth = require("linux.eth")
local iphdr = struct(vmlinux.layout("iphdr"))
local udphdr = struct(vmlinux.layout("udphdr"))
local limits = lunatik.runtime("limits")
return xdp.program(function(ctx)
local p = ctx:packet()
local ip = iphdr:view(p, eth.HLEN)
local port = udphdr:view(p, eth.HLEN + ip.ihl * 4).dest
local verdict = limits:run(port, #p)
if verdict then
return verdict
end
return action.PASS
end, {default = action.PASS})
Naming a kernel Lua runtime in a program file
| runtime (script) | Names the kernel Lua runtime a program calls. |
Naming a kernel Lua runtime in a program file in detail
lunatik bpf, and names a runtime
by the script it runs, which lunatik run starts; a program’s own function calls the runtime’s
run method, and the call lowers to the kfunc of the program’s type, bpf_luaxdp_run in an XDP
program and bpf_luatc_run in a TC one. The call answers the verdict the runtime’s callback
returns, or nil, and the program tests the answer before it reads it. A kernel script the body
requires that itself requires lunatik gets this twin, which holds runtime alone.
- runtime (script)
-
Names the kernel Lua runtime a program calls.
Inside a program’s own function the runtime’s
runmethod is called with numbers,limits:run(a, b), and the call runs the callback the runtime registered with the attach of the program’s type,xdp.attachortc.attach, handing it the program’s context and each argument as a 64-bit integer, in order, which the callback reads asctx:argument():getint64(0),getint64(8)and on. The call answers the verdict the callback returns, ornilwhere the kfunc returns-1: no softirq runtime of that name with a callback attached, a callback that raises, returnsnilor a value outsidelinux.xdp.actionorlinux.tc.action, or one that returnslinux.tc.action.UNSPEC, which is-1. The program tests the answer before it reads it, withif v then,if not v then,v == nilorv ~= nil; every other use is refused at its line, and so are a call of the runtime itself,limits(a), and any other method. An object with such a call loads where the module publishes its BTF (make btf_install).Parameters
- script
string
the script the runtime runs, as
lunatik runtakes it, its path below/lib/modules/lua/without.lua
Returns
-
table
the runtime, whose
runa program callsRaises
<file>:<line>: lunatik.runtime takes a script, the line that called it - script
string
the script the runtime runs, as