Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
72bf3a6
fix(ip6): export pack so ip.pack can dispatch to IPv6
jperon Nov 10, 2026
b05f86a
fix(ip6): parse optional mask in s2net6
jperon Nov 10, 2026
15fc357
fix(ip6): always recompute vtf in pack from header fields
jperon Nov 10, 2026
a2f3a30
fix(ip6): emit 0xFFFF for zero UDP checksum
jperon Nov 10, 2026
705567c
fix(ip4): default options to empty string in new
jperon Nov 10, 2026
90b9de1
fix(ip4,tcp): drop raw flag keys so __newindex is honoured
jperon Nov 10, 2026
174f6fa
fix(ip4,tcp): reject header lengths below their minimum in parse
jperon Nov 10, 2026
876c08b
fix(dns): return numeric opcode, z and rcode header values
jperon Nov 10, 2026
d5ee166
fix(dns): store ra and unknown header fields, guard pack size prefix
jperon Nov 10, 2026
f3255e2
fix(dns): assign unknown EDNS option data
jperon Nov 10, 2026
c1934de
fix(dns): pack client_subnet fields without unpack
jperon Nov 10, 2026
a8eb810
fix(dns): use RFC class values for NONE and ANY
jperon Nov 10, 2026
4098c8f
fix(quic): pack long-header version as 32 bits
jperon Nov 10, 2026
b783a98
fix(quic): store unknown header fields via rawset in __newindex
jperon Nov 10, 2026
c624cd5
fix(quic): return error instead of raising in remove_header_protection
jperon Nov 10, 2026
19e0ddb
fix(quic): use 32-bit versions in version negotiation payload
jperon Nov 10, 2026
48efd14
fix(init): process the tail of lbin2hex input
jperon Nov 10, 2026
417b968
fix(init): make hex2bin return only the converted string
jperon Nov 10, 2026
350cb98
fix(fun): stop protected from always leaking a traceback
jperon Nov 10, 2026
df8f0ef
chore(fun): document weak caches and real zero_indexed behaviour
jperon Nov 10, 2026
bbf332d
fix(pack_compat): raise on truncated input in unpack fallback
jperon Nov 10, 2026
caec22f
fix(tls): return nil on truncated TLS record, handshake and ClientHello
jperon Nov 10, 2026
e3df0a2
fix(quic): reuse robust sni_from_tls from session
jperon Nov 10, 2026
b956bd6
fix(quic): reject short header shorter than its DCID
jperon Nov 10, 2026
cdaa4fa
fix(pcap): stop infinite loop on malformed block lengths
jperon Nov 10, 2026
9953493
fix(pcap): compute 64-bit EPB timestamp without lshift
jperon Nov 10, 2026
1b38a51
fix(pcap): remove broken pcapng writer
jperon Nov 10, 2026
85ce23e
chore(pack-compat): drop unused write_uint and FFI prototypes
jperon Nov 10, 2026
1700dd9
chore(crypto/lunatik): remove unused close_tfm
jperon Nov 10, 2026
33aa959
chore(examples): drop obsolete ffi_stub module
jperon Nov 10, 2026
5bd7979
chore(tests): drop stale out-of-tree pack.moon
jperon Nov 10, 2026
7194532
fix(lib/bit53): sign-extend arshift for negative values
jperon Nov 10, 2026
425521d
fix(l7/tls/handshake): correct message_types per IANA registry
jperon Nov 10, 2026
7d1c4f4
fix(lib/hkdf): support crypto.shash in hmac_hex; move tests out
jperon Nov 10, 2026
a376379
perf(l4/quic/frames): dispatch frames through a module-level parser t…
jperon Nov 10, 2026
aa291e9
perf(l4/quic/frames): coalesce consecutive PADDING bytes into one frame
jperon Nov 10, 2026
7daa465
perf(l4.tcp,l3.ip4): avoid bidirectional flag lookup in hot metamethods
jperon Nov 10, 2026
60849f3
perf(fun): avoid per-call closure in protected when xpcall forwards args
jperon Nov 10, 2026
7802434
perf(l3): avoid dynamic pack formats in checksum6 and contains_ip
jperon Nov 10, 2026
2d80890
perf(l4/udp): serialize payload once in pack
jperon Nov 10, 2026
b66d29d
perf(l7/dns): reuse metatables for parsed EDNS option data
jperon Nov 10, 2026
f4fe16c
perf(lib/bit53): fast paths for 2-argument band/bor/bxor
jperon Nov 10, 2026
c985512
fix(init): rewrite bin2hex without multi-return unpack
jperon Nov 10, 2026
8050b35
fix(l3/fragmented_ip4): rewrite reassembly on pure Lua strings
jperon Nov 10, 2026
118a4aa
chore(l3/ip4): drop obsolete fragmented_ip4 test block
jperon Nov 10, 2026
657e3d8
fix(l3/fragmented_ip4): bound eviction queue to pending flows
jperon Nov 10, 2026
66b05f9
perf(crypto): avoid per-packet closures in lunatik backend
jperon Nov 10, 2026
7a10954
perf(hkdf): reuse crypto hkdf and shash transforms
jperon Nov 10, 2026
8de50fb
perf(hkdf): add binary expand variants, skip hex round-trips
jperon Nov 10, 2026
83cb320
test(coverage): add cumulated LuaJIT/Lua 5.4 luacov harness
jperon Nov 10, 2026
853a7fb
test(coverage): record cumulated coverage baseline (74%)
jperon Nov 10, 2026
30be274
ci: add non-blocking cumulative coverage job
jperon Nov 10, 2026
3c22f8d
chore(agents): document make coverage, baseline and CI job
jperon Nov 10, 2026
7856245
chore(lint): drop unused imports across protocol modules
jperon Nov 10, 2026
6b92472
refactor(l7/dns,l4/quic/frames): reuse shared need_bytes helper
jperon Nov 10, 2026
461e586
chore(l4/quic/v1): point initial_salt at keys.INITIAL_SALT
jperon Nov 10, 2026
ff5d90a
refactor(l7/quic/session): stop forcing module reloads
jperon Nov 10, 2026
6429fb0
chore(lib): translate French comments and tidy stale headers
jperon Nov 10, 2026
1d89b34
chore(crypto): drop unused sizes and hoist padding cdef
jperon Nov 10, 2026
6482e87
fix(quic): load ipparse/fun first at shallow require depth
jperon Nov 10, 2026
24f0420
chore(tests): exercise FFI crypto backends in coverage
jperon Nov 10, 2026
a15f949
chore(ci): run FFI crypto backends in LuaJIT jobs
jperon Nov 10, 2026
0726d8f
chore(docs): document optional OpenSSL and mbedTLS test libraries
jperon Nov 10, 2026
4435c61
test(pack_compat): cover every format option, integer limits and pack…
jperon Nov 10, 2026
64cac20
test(pack_compat_float): cover f/d/n options, middle fields and packsize
jperon Nov 10, 2026
7357e8c
fix(pack_compat_lib): raise on truncated float input under FFI
jperon Nov 10, 2026
2cf83a5
test(bit_compat): cover fallback shifts and backend selection
jperon Nov 10, 2026
5d1b173
test(l4/quic/frames): cover every frame parser, truncation and varint…
jperon Nov 10, 2026
7274aff
test(l4/quic/protection): cover packet number recovery and simulated …
jperon Nov 10, 2026
922b0e7
test(lib/pcap): cover filtering, file parsing and verbose logging
jperon Nov 10, 2026
a4cfacc
fix(lib/pcap): do not crash logging a QUIC short header without DCID
jperon Nov 10, 2026
32d303b
test(l7/tls): cover handshake and record packing, ciphers and extensions
jperon Nov 10, 2026
842bd4c
test(l4/tcp_stream): cover empty payloads, clear and default purge age
jperon Nov 10, 2026
b00a133
test(fun): cover iter helpers, generate, memo nil keys and table shor…
jperon Nov 10, 2026
f771d93
test(init): cover dump, need_bytes bounds and hexdump options
jperon Nov 10, 2026
d5784e3
fix(init): align hexdump ASCII column on incomplete lines
jperon Nov 10, 2026
6215f46
test(coverage): raise the cumulated coverage baseline to 89%
jperon Nov 10, 2026
e62d216
test(pack_compat): run the 4096-byte chunking test on the fallback only
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
45 changes: 43 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
# 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.
# - coverage: cumulative LuaJIT + Lua 5.4 luacov report, compared against
# ipparse/tests/coverage_baseline; non-blocking (warns only).
#
# Lunatik upgrade procedure:
# 1. run kernel-lunatik-head with lunatik_ref=<new tag>;
Expand Down Expand Up @@ -40,13 +42,52 @@ jobs:
run: nix-shell -p luajitPackages.moonscript --run "make -C ipparse all"
- name: Run test suite
run: |
has_ffi=""
case "${{ matrix.lua }}" in
luajit) pkg=luajit; bin=luajit ;;
luajit) pkg=luajit; bin=luajit; has_ffi=1 ;;
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"
if [ -n "$has_ffi" ]; then
# LuaJIT has FFI: make the optional crypto backends loadable so
# their tests run instead of being skipped.
nix-shell -p "$pkg" openssl mbedtls --run \
"export LD_LIBRARY_PATH=\"\$(ipparse/tests/ffi_libs.sh)\${LD_LIBRARY_PATH:+:\$LD_LIBRARY_PATH}\" && make -C ipparse test-nobuild LUA=$bin"
else
nix-shell -p "$pkg" --run "make -C ipparse test-nobuild LUA=$bin"
fi

coverage:
runs-on: ubuntu-latest
continue-on-error: true
steps:
- uses: actions/checkout@v6
- 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: Measure coverage
run: |
nix-shell -p 'luajit.withPackages (p: [p.luacov])' \
'lua5_4.withPackages (p: [p.luacov])' \
openssl mbedtls \
--run 'make -C ipparse coverage-nobuild' > coverage.out
total=$(grep -E '^COVERAGE_TOTAL=' coverage.out | tail -n 1 | cut -d= -f2)
baseline=$(cat ipparse/tests/coverage_baseline)
{
echo "## Test coverage"
echo ""
echo "Total: ${total}% (baseline: ${baseline}%)"
echo ""
echo '```'
sed -n '/^Summary$/,$p' coverage.out
echo '```'
} >> "$GITHUB_STEP_SUMMARY"
if awk -v t="$total" -v b="$baseline" 'BEGIN { exit !(t < b) }'; then
echo "::warning title=Test coverage::Coverage ${total}% is below the baseline ${baseline}%"
fi

kernel:
runs-on: ubuntu-latest
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
*.o
vmlinux.h*
*.zip
luacov.stats.out
luacov.report.out
6 changes: 6 additions & 0 deletions ipparse/.luacov
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
return {
statsfile = "luacov.stats.out",
reportfile = "luacov.report.out",
include = { "ipparse/" },
exclude = { "ipparse/tests/", "ipparse/examples/", "sha2$", "_ports$" },
}
9 changes: 9 additions & 0 deletions ipparse/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ ldoc . # Generate HTML docs in doc/ (uses config.ld)
- Functional style: `fun.moon` primitives (`iter`, `memo`, `bidirectional`, …).
- `bidirectional` tables map both `name→value` and `value→name`.

## Test coverage

`make coverage` runs the suite under LuaJIT and Lua 5.4 with luacov and prints
a cumulative report. `tests/coverage_baseline` holds the reference total; the
non-blocking CI `coverage` job warns (without failing) when it drops below it.
OpenSSL and mbedTLS are optional: when they are loadable (e.g. add openssl
mbedtls to the nix-shell, as `tests/ffi_libs.sh` expects) the FFI crypto
backends run, otherwise their tests skip themselves.

See `.agents/moonscript.md` for MoonScript syntax, fat-arrow, scoping pitfalls.
See `.agents/architecture.md` for the parse/pack/new contract and OOP pattern.

Expand Down
5 changes: 5 additions & 0 deletions ipparse/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ test: all test-nobuild
test-nobuild:
cd .. && LUA_PATH="./?.lua;./?/init.lua" $(LUA) ipparse/tests/run_all.lua

coverage: all coverage-nobuild

coverage-nobuild:
./tests/coverage.sh

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

Expand Down
4 changes: 0 additions & 4 deletions ipparse/examples/parse_real_quic.moon
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ do
"#{module_root}/?/init.lua"
}, ";"

ok_ffi = pcall require, "ffi"
unless ok_ffi
package.preload.ffi = -> require "ipparse.lib.ffi_stub"

pack_compat = require "ipparse.lib.pack_compat"
pack_compat.inject!

Expand Down
37 changes: 27 additions & 10 deletions ipparse/fun.moon
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ unpack or= table.unpack
--- Creates a memoized version of a single-argument function.
-- The cache uses the input argument as the key.
-- If the argument is `nil` or not provided, the original function is called directly without caching.
-- The cache is a weak table on purpose: entries may be dropped by the garbage collector, trading recomputation for bounded memory.
-- @treturn function The memoized function.
-- @usage
-- -- The memoized function takes:
Expand All @@ -34,6 +35,7 @@ memo = =>
--- Creates a memoized version of a multi-argument function.
-- The cache is hierarchical, using arguments as keys at successive levels.
-- `nil` arguments are handled by using a special internal `_nil` placeholder.
-- The cache is a weak table on purpose: entries may be dropped by the garbage collector, trading recomputation for bounded memory.
-- @treturn function The memoized function.
-- @usage
-- -- The memoized function takes:
Expand Down Expand Up @@ -83,12 +85,12 @@ bidirmt_gen = ->
bidirectional = => setmetatable @, __index: bidirmt_gen!

--- Modifies an array-like table in-place to make it zero-indexed.
-- It copies `@[i+1]` to `@[i]` for `i` from `0` to `#@-1`.
-- The original 1-indexed elements are preserved.
-- It copies `@[i+1]` to `@[i]` for `i` from `0` to `#@`, shifting every
-- element down by one index and clearing the last slot.
-- @treturn table self
-- @usage
-- local arr = {"a", "b", "c"} -- arr[1]="a", arr[2]="b", arr[3]="c"
-- fun.zero_indexed(arr) -- arr[0]="a", arr[1]="b", arr[2]="c" (original elements still there)
-- fun.zero_indexed(arr) -- arr[0]="a", arr[1]="b", arr[2]="c", arr[3]=nil
zero_indexed = =>
@[i] = @[i+1] for i = 0, #@
@
Expand Down Expand Up @@ -262,6 +264,11 @@ opairs = (f=(a,b) -> if type(a) == type(b) then a < b else "#{a}" < "#{b}") =>

_ = nil

-- Detected once at load time: xpcall forwards extra arguments on Lua 5.2+ and
-- LuaJIT, but not on Lua 5.1 PUC. Kept as a flat local so `protected` does not
-- need a nested probe function.
xpcall_passes_args = select(2, xpcall(((x) -> x), (-> true), true)) == true

--- Wraps a function call in `xpcall` to catch errors.
-- If an error occurs, it prints the error. When `leak_debug` is true, it also prints a full traceback.
--- Calls an optional `op` function on error.
Expand All @@ -280,6 +287,11 @@ _ = nil
-- 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.
--
-- Implementation note: when the runtime's `xpcall` forwards extra arguments
-- (`xpcall_passes_args`, true on Lua 5.2+/LuaJIT), `fn` is passed to `xpcall`
-- directly with its arguments, avoiding the per-call `call` closure. On Lua
-- 5.1 PUC the closure form is kept as a fallback.
-- @tparam function fn
-- @tparam[opt] function op
-- @treturn function A new, protected function (max 26 args/returns).
Expand All @@ -288,17 +300,22 @@ _ = nil
-- -- @tparam ...any ... Arguments for the original `fn`.
-- -- @treturn ...any|nil Results from `fn` or `op` (see main description for conditions).
protected = (fn, op) ->
leak_debug = _ and _.leak_debug
leak_debug = _ and rawget(_, "leak_debug")
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
if xpcall_passes_args
(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, onerror, 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
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
else
(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


--- The main export table for the `fun` module.
Expand Down
15 changes: 9 additions & 6 deletions ipparse/init.moon
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ if path = (...)\match"(.*)%.[^%.]-" -- Add subdirectory to package.path if appl
path = package.path\match"^[^%?]+" .. path
package.path ..= ";"..path.."/?.lua;"..path.."/?/init.lua"

:char, :format, :gsub, :rep, :sub = string
:byte, :char, :format, :gsub, :rep, :sub = string
unpack: su = require "ipparse.lib.pack_compat" -- string.unpack is absent on LuaJIT/Lua 5.1
:concat = table
:opairs = require"ipparse.fun"
Expand Down Expand Up @@ -37,29 +37,31 @@ need_bytes = (off, len) =>
--- Converts a binary string to a hexadecimal string.
-- @tparam string s Binary string.
-- @treturn string Hexadecimal representation (lowercase).
bin2hex = (s) -> format rep("%.2x", #s), su rep("B", #s), s
bin2hex = (s) -> (gsub s, ".", (c) -> format "%.2x", byte c)

--- Converts a binary string to its hexadecimal representation in chunks.
-- Kept for backward compatibility; identical to `bin2hex`.
-- @tparam string self The binary string to convert.
-- @treturn string A string containing the hexadecimal representation of the input.
lbin2hex = => concat [bin2hex sub(@, i+1, i+128) for i = 0, #@-128, 128]
lbin2hex = bin2hex

--- Converts a hexadecimal string to binary.
-- @tparam string hex Hexadecimal string (even length).
-- @treturn string Binary representation.
hex2bin = => gsub @, "%x%x", => char tonumber @, 16
hex2bin = => (gsub @, "%x%x", => char tonumber @, 16)


--- Produces a formatted hexadecimal and ASCII dump of the input data.
-- Each row contains `cols` columns of `len` bytes, with both hex and ASCII representations.
-- Non-printable ASCII bytes are shown as `.` in the ASCII section.
-- The function handles incomplete rows and aligns output accordingly.
-- Incomplete rows pad the hex section so the ASCII column stays aligned.
-- @tparam[opt=1] number off The starting offset in the input data.
-- @tparam[opt=8] number len The number of bytes per row.
-- @tparam[opt=2] number cols The number of columns per row.
-- @tparam[opt="%.2x"] string f The format string for each byte.
-- @treturn string A string containing the formatted hex and ASCII dump.
hexdump = (off=1, len=8, cols=2, f="%.2x") =>
width = cols * len * #format(f, 0) + cols - 1
res = {}
for i = off, #@, len * cols
row = sub @, i, i + len * cols - 1
Expand All @@ -68,7 +70,8 @@ hexdump = (off=1, len=8, cols=2, f="%.2x") =>
part = sub row, j, j + len - 1
hex[#hex+1] = format(rep(f, #part), su(rep("B", #part), part))
ascii[#ascii+1] = filterascii part
res[#res+1] = format("%04x: %s %s", i-1, concat(hex, " "), concat(ascii, rep(" ", len - #ascii[#ascii])))
hexstr = concat hex, " "
res[#res+1] = format("%04x: %s%s %s", i-1, hexstr, rep(" ", width - #hexstr), concat ascii)
concat res, "\n"


Expand Down
Loading
Loading