Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
a768e71
fix(ipparse): make bit53 band/bor/bxor variadic
jperon Nov 10, 2026
0b18d66
fix(sha): correct SHA-256 constants, variadic XOR and HMAC double-feed
jperon Nov 10, 2026
0a6c8e6
test(lunatik): restore package state after mocking crypto
jperon Nov 10, 2026
53d8581
test(lunatik): align crypto stubs with Lunatik API
jperon Nov 10, 2026
8d98d00
test: add byte-equivalence tests for pack fallback
jperon Nov 10, 2026
c2aa0bb
perf(ipparse): compile pack formats into specialized emitters
jperon Nov 10, 2026
2e04346
test: report pack_compat summary
jperon Nov 10, 2026
7ea169d
test: run fallback-only pack cases only on the fallback
jperon Nov 10, 2026
89ea2fc
test(dns): byte-exact round-trip coverage
jperon Nov 10, 2026
7c299e8
perf(dns): single-concat pack and direct byte reads in labels
jperon Nov 10, 2026
be01ad9
test(lunatik): run portable parse/pack suites inside the kernel
jperon Nov 10, 2026
4d00af5
test(sha): make the long-message vector deterministic and kernel-port…
jperon Nov 10, 2026
2afeae5
test(pack_compat): cover long formats, mixed strings/padding and 64-b…
jperon Nov 10, 2026
e34ca7a
perf(ipparse): write pack bytes into a shared buffer instead of per-f…
jperon Nov 10, 2026
b0ffad1
fix(vmtest): propagate resolved build paths to the guest
jperon Nov 10, 2026
dffaaf6
fix(vmtest): ignore build and .venv symlinks
jperon Nov 10, 2026
8b8d3d4
fix(vmtest): use a per-run VM scratch directory
jperon Nov 10, 2026
4134386
fix(vmtest): document guest paths and per-run scratch dir
jperon Nov 10, 2026
a5c1d81
fix(quic): encode 8-byte varints without math.floor on native integers
jperon Nov 10, 2026
333d2ae
test(pack_compat): load the portable entrypoint instead of LuaJIT-onl…
jperon Nov 10, 2026
6a5ced1
fix(tcp_stream): use a portable integer clock
jperon Nov 10, 2026
6c9508e
test(varint): run 2^62-1 round-trip whenever native integers exist
jperon Nov 10, 2026
d292002
perf(pack_compat): avoid tail-call returns in pack
jperon Nov 10, 2026
e4908ee
perf(pack_compat): single trailing string fast path
jperon Nov 10, 2026
5b2cfbd
perf(pack_compat): reuse a module-level argument array
jperon Nov 10, 2026
04385ba
fix(crypto): recognize all Lunatik EBADMSG error-name forms
jperon Nov 10, 2026
c49f527
fix(tcp_stream): reject clock_hz without an explicit clock
jperon Nov 10, 2026
9bedb8f
fix(bit_compat): add pure-Lua 32-bit bitwise fallback for Lua 5.1
jperon Nov 10, 2026
d6df7db
fix(pack_compat_lib): make FFI optional with pure-Lua fallback
jperon Nov 10, 2026
1c63144
test: use Lua 5.1-compatible decimal string escapes
jperon Nov 10, 2026
3c7a21c
vmtest: pin Lunatik to upstream v5.1 tag and commit
jperon Nov 10, 2026
ad582ec
ci: upload the VM console and output logs on failure
jperon Nov 10, 2026
f228ca9
ci: run the userspace suite under LuaJIT, Lua 5.1, 5.4 and 5.5
jperon Nov 10, 2026
35d4657
ci: add a non-blocking Lunatik master/ref test job
jperon Nov 10, 2026
84237ca
fix(crypto): handle Lunatik v5.1 nil,error AEAD decrypt convention
jperon Nov 10, 2026
ec0dcc0
test(bit_compat): skip bit_pure cases where math.floor is absent
jperon Nov 10, 2026
a374571
test(pack_compat): split floating-point cases into their own module
jperon Nov 10, 2026
f4f405e
fix(fun): flatten protected so ipparse.fun loads under the C-stack guard
jperon Nov 10, 2026
7bb2b08
test(lunatik): preload ipparse.fun at first level in portable suite
jperon Nov 10, 2026
25799f5
fix(pack_compat): avoid UB casting negative doubles to uint64
jperon Nov 10, 2026
e5a2b8c
fix(fun): revalidate bidirectional reverse-lookup cache
jperon Nov 10, 2026
fb8ff28
ci: make the Lua 5.1 userspace job blocking
jperon Nov 10, 2026
b3fa8b9
ci: give nix-shell a nixpkgs channel in the userspace job
jperon Nov 10, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 106 additions & 12 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,52 @@
# Unified test pipeline:
# - userspace: fast LuaJIT run of the ipparse suite (no VM)
# - userspace: fast Lua suite (LuaJIT, 5.1, 5.4, 5.5) of the ipparse tests
# (no VM)
# - kernel: full suite (userspace + lunatik kernel modules) inside a
# virtme-ng microVM on the pinned LTS kernel (tools/vmtest/)
# - kernel-lunatik-head: same as kernel, but against a Lunatik ref supplied
# via workflow_dispatch (default: upstream master); non-blocking.
#
# Lunatik upgrade procedure:
# 1. run kernel-lunatik-head with lunatik_ref=<new tag>;
# 2. once green, update LUNATIK_REF and LUNATIK_COMMIT in
# tools/vmtest/versions.env to that tag and its commit.
name: test

on:
push:
branches: [master]
pull_request:
workflow_dispatch:
inputs:
lunatik_ref:
description: Lunatik ref to test in kernel-lunatik-head
required: false
default: master
type: string

jobs:
userspace:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
lua: [luajit, lua5.1, lua5.4, lua5.5]
steps:
- uses: actions/checkout@v6
- name: Install LuaJIT + MoonScript
run: |
sudo apt-get update
sudo apt-get install -y luajit luarocks
sudo luarocks install moonscript
- uses: cachix/install-nix-action@v31
with:
nix_path: nixpkgs=channel:nixos-unstable
- name: Compile MoonScript sources
run: nix-shell -p luajitPackages.moonscript --run "make -C ipparse all"
- name: Run test suite
run: make -C ipparse test
run: |
case "${{ matrix.lua }}" in
luajit) pkg=luajit; bin=luajit ;;
lua5.1) pkg=lua5_1; bin=lua ;;
lua5.4) pkg=lua5_4; bin=lua ;;
lua5.5) pkg=lua5_5; bin=lua ;;
esac
nix-shell -p "$pkg" --run "make -C ipparse test-nobuild LUA=$bin"

kernel:
runs-on: ubuntu-latest
Expand All @@ -44,11 +70,17 @@ jobs:
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm || true

- name: Read pinned kernel version
id: pinned
run: |
. tools/vmtest/versions.env
echo "kernel=$KERNEL_VERSION" >> "$GITHUB_OUTPUT"

- name: Restore kernel build cache
uses: actions/cache@v5
with:
path: tools/vmtest/build/linux-*
key: vmtest-kernel-${{ hashFiles('tools/vmtest/versions.env', 'tools/vmtest/kernel.fragment') }}
key: vmtest-kernel-${{ steps.pinned.outputs.kernel }}-${{ hashFiles('tools/vmtest/kernel.fragment') }}

- name: Restore ccache
uses: actions/cache@v5
Expand All @@ -58,16 +90,78 @@ jobs:
restore-keys: vmtest-ccache-

- name: Run full suite in VM
env:
VMTEST_RW_DIR: ${{ runner.temp }}/vmtest-rw
run: make vm-test

- name: Collect dmesg on failure
- name: Upload logs on failure
if: failure()
run: dmesg > vm-dmesg.log 2>/dev/null || true
uses: actions/upload-artifact@v7
with:
name: vm-logs
path: |
${{ runner.temp }}/vmtest-rw/console.log
${{ runner.temp }}/vmtest-rw/out
if-no-files-found: ignore

kernel-lunatik-head:
runs-on: ubuntu-latest
continue-on-error: true
env:
LUNATIK_REF: ${{ github.event.inputs.lunatik_ref || 'master' }}
LUNATIK_COMMIT: ''
steps:
- uses: actions/checkout@v6

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y \
build-essential flex bison bc libelf-dev libssl-dev dwarves \
ccache cpio zstd qemu-system-x86 busybox-static \
python3-venv rustc cargo \
luajit luarocks lua5.4 git curl kmod \
libbpf-dev pkg-config
sudo luarocks install moonscript

- name: Enable KVM on the runner
run: |
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666"' \
| sudo tee /etc/udev/rules.d/99-kvm.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm || true

- name: Read pinned kernel version
id: pinned
run: |
. tools/vmtest/versions.env
echo "kernel=$KERNEL_VERSION" >> "$GITHUB_OUTPUT"

- name: Restore kernel build cache
uses: actions/cache@v5
with:
path: tools/vmtest/build/linux-*
key: vmtest-kernel-${{ steps.pinned.outputs.kernel }}-${{ hashFiles('tools/vmtest/kernel.fragment') }}

- name: Restore ccache
uses: actions/cache@v5
with:
path: ~/.cache/ccache
key: vmtest-ccache-${{ hashFiles('tools/vmtest/versions.env') }}
restore-keys: vmtest-ccache-

- name: Run full suite in VM
env:
LUNATIK_SRC: ${{ runner.temp }}/lunatik-head
VMTEST_RW_DIR: ${{ runner.temp }}/vmtest-rw-head
run: make vm-test

- name: Upload logs on failure
if: failure()
uses: actions/upload-artifact@v7
with:
name: vm-logs
path: vm-dmesg.log
name: vm-logs-lunatik-head
path: |
${{ runner.temp }}/vmtest-rw-head/console.log
${{ runner.temp }}/vmtest-rw-head/out
if-no-files-found: ignore
7 changes: 4 additions & 3 deletions ipparse/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

NAME = ipparse
LUA_MODULE_DIR = /lib/modules/lua
LUA ?= luajit


all:
Expand All @@ -24,10 +25,10 @@ uninstall:
test: all test-nobuild

test-nobuild:
cd .. && LUA_PATH="./?.lua;./?/init.lua" luajit ipparse/tests/run_all.lua
cd .. && LUA_PATH="./?.lua;./?/init.lua" $(LUA) ipparse/tests/run_all.lua

example: all
cd .. && LUA_PATH="./?.lua;./?/init.lua" luajit ipparse/examples/parse_real_quic.lua
cd .. && LUA_PATH="./?.lua;./?/init.lua" $(LUA) ipparse/examples/parse_real_quic.lua

test-lunatik: all
@$(MAKE) install
Expand All @@ -47,7 +48,7 @@ test-lunatik-run:
@start=$$(dmesg | wc -l); \
echo "Running kernel Lunatik crypto tests..."; \
status=0; \
for test in ipparse/tests/lib/crypto/test_lunatik_kernel_quic_session_e2e ipparse/tests/lib/crypto/test_lunatik_kernel ipparse/tests/lib/crypto/test_lunatik_kernel_quic_simple ipparse/tests/lib/crypto/test_lunatik_kernel_quic_comprehensive ipparse/tests/lib/crypto/test_lunatik_kernel_integration ipparse/tests/lib/crypto/test_lunatik_kernel_crypto_pipeline ipparse/tests/lib/crypto/test_lunatik_kernel_quic_google_capture; do \
for test in ipparse/tests/lib/crypto/test_lunatik_kernel_quic_session_e2e ipparse/tests/lib/crypto/test_lunatik_kernel ipparse/tests/lib/crypto/test_lunatik_kernel_quic_simple ipparse/tests/lib/crypto/test_lunatik_kernel_quic_comprehensive ipparse/tests/lib/crypto/test_lunatik_kernel_integration ipparse/tests/lib/crypto/test_lunatik_kernel_crypto_pipeline ipparse/tests/lib/crypto/test_lunatik_kernel_quic_google_capture ipparse/tests/test_lunatik_kernel_portable; do \
echo "Running $$test..."; \
if lunatik run "$$test"; then \
: ; \
Expand Down
30 changes: 21 additions & 9 deletions ipparse/fun.moon
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@ memoN = =>
bidirmt_gen = ->
_mem = setmetatable {}, __mode: "kv"
(val) =>
if _k = _mem[val]
return _k
_k = _mem[val]
-- rawget (not @[_k]) validates without re-entering __index, which would
-- recurse on an absent key.
return _k if _k and rawget(@, _k) == val
for k, v in pairs @
if v == val
_mem[val] = k
Expand Down Expand Up @@ -269,6 +271,15 @@ _ = nil
-- on the hot path (per-packet), and a vararg implementation would allocate a
-- table and call `unpack` on every invocation. The trade-off is a hard limit
-- of 26 arguments and 26 return values.
--
-- Implementation note: the error handler and the returned function are defined
-- as flat locals rather than inline in the `xpcall` call. The Lua parser is
-- recursive in C, and Lunatik runs on a 16 KiB kernel stack with a C-call
-- guard derived from the stack actually consumed: inline function expressions
-- nested two deep here pushed `require "ipparse.fun"` over that guard when the
-- module was loaded one `require` level deeper than the top level. Defining
-- them at block level reduces the parser's C recursion; the API and semantics
-- are unchanged.
-- @tparam function fn
-- @tparam[opt] function op
-- @treturn function A new, protected function (max 26 args/returns).
Expand All @@ -278,15 +289,16 @@ _ = nil
-- -- @treturn ...any|nil Results from `fn` or `op` (see main description for conditions).
protected = (fn, op) ->
leak_debug = _ and _.leak_debug
(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z) ->
ok, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z = xpcall (
-> fn a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z
), (err) ->
print err
print debug.traceback! if leak_debug
op! if op
onerror = (err) ->
print err
print debug.traceback! if leak_debug
op! if op
run = (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z) ->
call = -> fn a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z
ok, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z = xpcall call, onerror
if ok
a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z
run


--- The main export table for the `fun` module.
Expand Down
45 changes: 32 additions & 13 deletions ipparse/l4/quic/frames.moon
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ pack: sp, unpack: su = require "ipparse.lib.pack_compat"
:bidirectional = require"ipparse.fun"
{:band, :bor, :bnot, :lshift, :rshift} = require"ipparse.lib.bit_compat"

-- True when values are native 64-bit integers (Lua 5.3+/Lunatik kernel), where
-- bitwise shifts cover the full 64-bit range and floats/math.floor may be absent.
-- False on LuaJIT, where numbers are doubles and bit ops are 32-bit.
native_int = math.floor == nil or math.type ~= nil

--- QUIC Frame Types
-- Mapping of frame type codes to their names
frame_types = bidirectional {
Expand Down Expand Up @@ -126,19 +131,33 @@ encode_varint = (value) ->
band(value, 0xFF)
)
else
high = math.floor(value / 4294967296)
low = value % 4294967296
-- Same issue: encode manually with top 2 bits = 11
string.char(
bor(0xC0, band(math.floor(high / 16777216), 0x3F))
band(math.floor(high / 65536), 0xFF)
band(math.floor(high / 256), 0xFF)
band(high, 0xFF)
band(math.floor(low / 16777216), 0xFF)
band(math.floor(low / 65536), 0xFF)
band(math.floor(low / 256), 0xFF)
band(low, 0xFF)
)
if native_int
-- Native 64-bit integers: drive the byte split with shifts/masks only
-- (no floats, no math.floor, no division).
string.char(
bor(0xC0, band(rshift(value, 56), 0x3F))
band(rshift(value, 48), 0xFF)
band(rshift(value, 40), 0xFF)
band(rshift(value, 32), 0xFF)
band(rshift(value, 24), 0xFF)
band(rshift(value, 16), 0xFF)
band(rshift(value, 8), 0xFF)
band(value, 0xFF)
)
else
-- LuaJIT: doubles with 32-bit bit ops, so split high/low by division.
high = math.floor(value / 4294967296)
low = value % 4294967296
string.char(
bor(0xC0, band(math.floor(high / 16777216), 0x3F))
band(math.floor(high / 65536), 0xFF)
band(math.floor(high / 256), 0xFF)
band(high, 0xFF)
band(math.floor(low / 16777216), 0xFF)
band(math.floor(low / 65536), 0xFF)
band(math.floor(low / 256), 0xFF)
band(low, 0xFF)
)

--- Parses a PADDING frame
-- PADDING frames consist only of the frame type (0x00)
Expand Down
29 changes: 25 additions & 4 deletions ipparse/l4/tcp_stream.moon
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,31 @@
-- true (each segment with payload is immediately complete). When provided,
-- feed returns nil until the predicate passes, then auto-clears the session.
-- @tparam[opt] table opts Options: `max_buf` (bytes per session, default 1 MiB),
-- `max_sessions` (default 1024).
-- `max_sessions` (default 1024), `clock` (zero-arg function returning an
-- integer instant in fixed units) and `clock_hz` (units per second, default
-- 1 when `clock` is given; `clock_hz` without `clock` is an error).
-- @treturn table State with :feed, :clear, :reset and :purge methods.
-- @raise Error at creation when no clock is available and none is provided.
new = (check_complete=(-> true), opts={}) ->
max_buf = opts.max_buf or 0x100000
max_sessions = opts.max_sessions or 1024
clock = opts.clock
clock_hz = opts.clock_hz
if clock
clock_hz = clock_hz or 1
else
error "tcp_stream: opts.clock_hz requires opts.clock" if clock_hz
if os and os.time
clock = os.time
clock_hz = 1
else
ok, linux = pcall require, "linux"
if ok and linux and linux.time
clock = linux.time
clock_hz = 1000000000
else
error "tcp_stream: no clock available (pass opts.clock/opts.clock_hz)"
clock_hz = 1 if not clock_hz
sessions = {}
count = 0

Expand Down Expand Up @@ -56,7 +76,7 @@ new = (check_complete=(-> true), opts={}) ->
first_seg = entry == nil
if first_seg
drop_oldest! if count >= max_sessions
entry = { segments: {payload}, total: #payload, :init_seq, timestamp: os.time! }
entry = { segments: {payload}, total: #payload, :init_seq, timestamp: clock! }
sessions[key] = entry
count += 1
else
Expand Down Expand Up @@ -87,9 +107,10 @@ new = (check_complete=(-> true), opts={}) ->
--- Purge sessions older than max_age seconds.
-- @tparam[opt=300] number max_age
purge: (max_age=300) ->
now = os.time!
now = clock!
threshold = max_age * clock_hz
for key, entry in pairs sessions
if now - entry.timestamp > max_age
if now - entry.timestamp > threshold
drop key
}

Expand Down
Loading
Loading