Zig, Nim, Crystal, D, Odin, V (C2)
Ready
The hub recognises the services this package fits and proposes the compose part of the change, if any; the source change stays by hand, with the steps and examples in the proposal's review. Nothing changes until a player approves it (Hook proposals). The cheat sheets have the steps by hand.
This package is for services written in Zig, Nim, Crystal, D, Odin or V. Each language gets a thin binding over C1's guarded C binding vbxhook, which is compiled into the service, plus a request wrapper for its most common HTTP server. The binding goes in as a source change: the binding and vbxhook.c are vendored into the service's tree and a few lines are added around the server. The service also gets a read-only compose mount of the hook directory at /opt/vbxtrace. All the safety rules (the tracer check, VBXTRACE=0, switching off after 5 errors, chaos testing) live in vbxhook.c, so they are the same in every language.
Not every service needs this hook. The kernel already links thread-per-connection and forking servers exactly. For those servers the hook only adds request boundaries on keep-alive connections. See Covers.
Covers
| Language | Toolchain tested | Server / framework | Sample | Request index |
|---|---|---|---|---|
| Zig | 0.14.1 (official tarball, sha256-pinned) on Alpine 3.22 (musl); also checked on Debian trixie (glibc) | std.http.Server (HTTP/1.1, keep-alive) | zig-stdhttp | exact (one HttpConnection per connection) |
| Nim | 2.2.4 (nimlang/nim:2.2.4-alpine-regular) | std/asynchttpserver (serve, acceptRequest) | nim-asynchttpserver | exact (per AsyncSocket object) |
| Crystal | 1.17.1 (crystallang/crystal:1.17.1-alpine); the reopened method dates back to 1.12 | HTTP::Server and everything built on it: Kemal 1.15, Lucky, Amber, Athena, Grip | crystal-http, crystal-kemal | exact (per connection fiber) |
| D | LDC 1.41.0 (official tarball, sha256-pinned) on Debian trixie; vibe-core 2.14, vibe-http 1.2.2 | vibe.d (listenHTTP, URLRouter) | d-vibed | exact (per connection task) |
| Odin | dev-2026-10 (official tarball, sha256-pinned) on Debian trixie | core:net TCP servers: raw line protocols, hand-rolled HTTP | odin-raw | raw sessions: always 0; HTTP: a counter you keep per connection |
| V | 0.5.2 (official release zip, sha256-pinned) on Debian trixie | veb (fasthttp backend) | v-veb | exact (per fd + socket inode) |
Some frameworks are not covered yet, each for a reason:
| Framework | Why it is not covered |
|---|---|
| Zig: zap (facil.io), http.zig | zap's Request gives no connection object, no per-connection storage and no close callback; all it has is facil.io's uuid. A counter keyed by that uuid would not be exact when connections come and go. zap also pins Zig versions and builds facil.io. Both can call beginFd / end by hand. |
Zig 0.15 std.http.Server | 0.15 rewrote the server around std.Io.Reader/Writer. The extern fn layer still works; only HttpConnection/Request in vbxtrace.zig need porting. |
| Nim: Jester, Prologue | Jester's default backend is httpbeast, which runs its own epoll loop on several threads and gives the handler no connection. Prologue sits on httpx, which is the same kind of server. With -d:useStdLib, Jester runs on asynchttpserver, but it imports that module itself, so the drop-in import does not reach it. Not sampled; would need a patch inside Jester. |
| D: HTTP/2 in vibe-http | vibe-http's HTTP/2 (opt-in HTTPServerOption.enableHTTP2 over TLS) runs streams in tasks of their own, so no exact per-connection index exists there. traced reports those requests with protocol http2 and request index unknown (REQUEST_INDEX_UNKNOWN) instead of a guess. |
| Odin: odin-http | It is not part of the Odin distribution, and its connection type is internal. A service built on it can call vbx.begin/vbx.end from its handler with the connection's socket. |
V: net.http.Server | Its Handler gets only http.Request: no socket, no peer port, no connection boundary, so request keys cannot be exact. Its workers serve one connection at a time on a thread, so the kernel already links everything per connection. |
What the kernel already links without this hook:
| Server model | Languages / servers | Linked by | Hook adds |
|---|---|---|---|
| thread per connection | Zig std.http.Server with a thread per accepted connection (the usual pattern); Odin core:net with a thread per connection; D with std.socket threads; V net.http.Server workers | the thread holds exactly one client socket | request boundaries on keep-alive connections, raw session boundaries, work handed to other threads |
process per connection (socat fork, xinetd running any of these binaries) | all | process lineage | request boundaries |
| fibers / green threads / event loop: many connections on one thread | Crystal HTTP::Server (fibers), vibe.d (tasks), Nim asynchttpserver (async), veb (fasthttp worker threads, each with many connections) | nothing per request | everything |
How it gets in
On a developer machine: no registry package; copy the files from the hook directory that vulnboxctl hooks install-local puts in ~/.local/share/vulnboxd/trace, as below; see Local development.
The change is always a source change plus a compose mount. Each language's proposal does three things:
- It vendors the language binding (from
/usr/local/lib/vulnboxd/trace/native/<lang>/) together withnative/c/vbxhook.h,native/c/vbxhook.candinclude/vbxtrace.hinto the service tree. - It compiles
vbxhook.cinto the service. Nim and Zig do this through their own build. Crystal, D, Odin and V build an object or archive withccin the Dockerfile. - It adds the wrapper lines around the server and, optionally, the spawn, file and connect helpers.
The mount, the same for every language:
services:
<service>:
+ volumes:
+ - /usr/local/lib/vulnboxd/trace:/opt/vbxtrace:roBy default vbxhook.c dlopen()s /opt/vbxtrace/libvbxtrace-$(uname -m).so at its first call. That needs the mount and a dynamically linked binary. Without the mount the binding simply stays off. If you build a fully static binary, compile vbxhook.c with -DVBXHOOK_STATIC and link libvbxtrace-<arch>.a instead; no mount is needed then (see C1). Glibc older than 2.34 needs -ldl.
In full, vbxhook.c looks for the core in this order: the file named by VBXTRACE_LIB, then /opt/vbxtrace/libvbxtrace-<arch>.so (the mount), then, only with VBXTRACE_DEV=1 and only when the directory and the library belong to root or the user and nobody else can write them, ~/.local/share/vulnboxd/trace (or $XDG_DATA_HOME/vulnboxd/trace) for local development. A setuid or file-capability binary ignores VBXTRACE_LIB and VBXTRACE_DEV.
The hub proposes C2 when it detects the following (per language, from hooks/native/c2/proposals/<lang>.toml):
| Language | Files | Image | Command | Dependencies |
|---|---|---|---|---|
| Zig | build.zig, build.zig.zon, *.zig | zig | zig build, zig build-exe, zig run | |
| Nim | *.nimble, nim.cfg, config.nims, *.nim | ^nimlang/nim, nim | nim c, nimble build | asynchttpserver |
| Crystal | shard.yml, shard.lock, *.cr | ^crystallang/crystal | crystal build, shards build | kemal, lucky, amber, athena, grip |
| D | dub.json, dub.sdl, dub.selections.json, *.d | ^dlang2/, ldc, dmd, gdc | dub build, ldc2, dmd | vibe-d, vibe-http, vibe-core |
| Odin | *.odin, ols.json | odin | odin build, odin run | |
| V | v.mod, *.v | vlang, thevlang/ | v -prod, v run | veb |
Zig
- Copy
native/zig/vbxtrace.zignext tomain.zig. Zig 0.14 refuses imports from outside the root module's directory. - Copy
vbxhook.{h,c}andvbxtrace.hinto./vbxtrace/. - Add to
build.zig:
exe.linkLibC();
exe.linkage = .dynamic; // on musl, Zig links -lc statically by default; a static exe cannot dlopen
exe.addIncludePath(b.path("vbxtrace"));
exe.addCSourceFile(.{ .file = b.path("vbxtrace/vbxhook.c") });(On the command line: zig build-exe -O ReleaseFast -lc -dynamic -I vbxtrace main.zig vbxtrace/vbxhook.c.)
- Serve each connection through the wrapper:
+const vbx = @import("vbxtrace.zig");
-fn handle(req: *std.http.Server.Request) !void {
+fn handle(_: void, req: *vbx.Request) !void { // req.inner: std's Request, req.ctx: the context
...
- var server = std.http.Server.init(conn, &buf);
- while (server.state == .ready) {
- var req = server.receiveHead() catch return;
- handle(&req) catch return;
- }
+ vbx.serve(conn, &buf, {}, handle);You can keep your own loop instead: var hc = vbx.HttpConnection.init(conn, &buf), then hc.receiveHead(), req.respond(...) and defer req.end(). Full example: proposals/zig-stdhttp.diff.
Nim
Copy native/nim/ (vbxtrace.nim and vbxtrace/asynchttp.nim) and vbxhook.{h,c} and vbxtrace.h all into the service's source directory. vbxtrace.nim compiles vbxhook.c itself with {.compile.}. To keep the files elsewhere, pass -d:vbxhookC=<path to vbxhook.c> -d:vbxhookInc=<dir>. Then swap one import:
-import std/[asyncdispatch, asynchttpserver, osproc]
+import std/[asyncdispatch, osproc]
+import vbxtrace, vbxtrace/asynchttp # vulnboxd request tracing (replaces std/asynchttpserver)
...
- let p = startProcess("/bin/ping", args = ["-c", "1", req.url.query], options = {poUsePath})
+ let p = startProcess(ctx(req), "/bin/ping", args = ["-c", "1", req.url.query], options = {poUsePath})vbxtrace/asynchttp re-exports asynchttpserver, replacing three procs with tracing versions: serve, acceptRequest and respond. Nothing else in the service changes. Example: proposals/nim-asynchttpserver.diff.
Crystal
- Copy
native/crystal/vbxtrace.crandvbxhook.{h,c}andvbxtrace.htosrc/vbxtrace/. - Build the object that
vbxtrace.crlinks (through@[Link(ldflags: "#{__DIR__}/vbxhook.o")]). The officialcrystallang/crystalimages includecc.
-RUN crystal build --release -o /app/notes src/server.cr
+RUN cc -O2 -c -Isrc/vbxtrace -o src/vbxtrace/vbxhook.o src/vbxtrace/vbxhook.c \
+ && crystal build --release -o /app/notes src/server.cr- Put the handler first in the chain:
require "http/server"
+require "./vbxtrace/vbxtrace" # vulnboxd request tracing
-server = HTTP::Server.new([HTTP::LogHandler.new]) do |ctx|
+server = HTTP::Server.new([Vbxtrace::Handler.new, HTTP::LogHandler.new]) do |ctx|
...
- Process.run("ping", ["-c", "1", ctx.request.query.to_s], output: output)
+ Vbxtrace.process_run("ping", ["-c", "1", ctx.request.query.to_s], output: output)For Kemal, add use Vbxtrace::Handler.new, 0 before Kemal.run (older Kemal versions: add_handler Vbxtrace::Handler.new, 0). For Lucky, put Vbxtrace::Handler.new first in the middleware array of src/app_server.cr. Drop --static (or use the static variant). Example: proposals/crystal-http.diff.
D (vibe.d)
- Copy
native/d/vbxtrace.dandvbxtrace_vibe.dandvbxhook.{h,c}andvbxtrace.hinto./vbxtrace/. - Add to
dub.sdl(dub.jsontakes the same keys):
sourcePaths "source" "vbxtrace"
importPaths "source" "vbxtrace"
preBuildCommands "cc -O2 -c -I$PACKAGE_DIR/vbxtrace -o $PACKAGE_DIR/vbxtrace/vbxhook.o $PACKAGE_DIR/vbxtrace/vbxhook.c"
sourceFiles "vbxtrace/vbxhook.o"- Wrap the handler:
+import vbxtrace; // vulnboxd request tracing
+import vbxtrace_vibe;
...
- listenHTTP(settings, router);
+ listenHTTP(settings, traced(settings, router));traced accepts every handler shape that listenHTTP does: delegates, functions, their scope variants, and HTTPServerRequestHandler objects such as URLRouter. Example: proposals/d-vibed.diff.
Odin
- Copy
native/odin/vbxtrace.odininto./vbxtrace/(a package of its own). - Build
vbxtrace/vbxhook.a, which the bindingforeign imports:
RUN cc -O2 -c -Ivbxtrace -o /tmp/vbxhook.o vbxtrace/vbxhook.c && ar rcs vbxtrace/vbxhook.a /tmp/vbxhook.o- Wrap each accepted connection:
+import vbx "vbxtrace" // vulnboxd request tracing
handle :: proc(client: net.TCP_Socket) {
defer net.close(client)
+ ctx := vbx.begin(client, 0, vbx.PROTO_RAW)
+ defer vbx.end(ctx, 0)
...
- f, err := os.open("/data/log", {.Write, .Create, .Append})
+ f, err := vbx.open(ctx, "/data/log", {.Write, .Create, .Append})For a hand-rolled HTTP server, call vbx.begin(client, requests, vbx.PROTO_HTTP1) and vbx.end(ctx, status) once per request, with requests counted per connection (see the sample's serve_http). Example: proposals/odin-tcp.diff.
V (veb)
- Copy
native/v/vbxtrace/(vbxtrace.v,vebhook/) to./vbxtrace/next tomain.v, and copyvbxhook.h,vbxhook.candvbxtrace.hinto it. - Build
vbxtrace/vbxhook.o, whichvbxtrace.vlinks through#flag @DIR/vbxhook.o:
RUN cc -O2 -c -Ivbxtrace -o vbxtrace/vbxhook.o vbxtrace/vbxhook.c- Add three hooks to the veb app:
+import vbxtrace // vulnboxd request tracing
+import vbxtrace.vebhook
...
+pub fn (mut ctx Context) before_request() {
+ vebhook.begin(mut ctx.Context)
+}
+
+pub fn (mut ctx Context) not_found() veb.Result {
+ return vebhook.not_found(mut ctx.Context)
+}
...
mut app := &App{}
+ app.use(handler: fn (mut ctx Context) bool {
+ return vebhook.after(mut ctx.Context)
+ }, after: true)If the app already has before_request or not_found, call vebhook.begin or vebhook.end(404) from them. Register the after-middleware last. Example: proposals/v-veb.diff.
What it records
Every language reports the same events through vbxhook. The tables show where each event comes from.
| Event | Join key |
|---|---|
request_begin / request_end | local port + peer address and port of the accepted socket (from getsockname/getpeername on its fd, or the explicit keys where noted), request index on the connection, protocol |
spawned | child pid |
connected | local port of the outgoing socket (from the fd) |
opened | pid + fd, plus the open(2) flags (0x241 = O_WRONLY|O_CREAT|O_TRUNC; O_CLOEXEC, which every runtime adds, is not reported) |
handoff, context_enter/context_exit | context ids |
Zig
| Event | Emitted from |
|---|---|
request_begin | HttpConnection.receiveHead() after std's receiveHead succeeds: vbxh_begin_fd(stream fd, connection's counter, http1) |
request_end | Request.end() (serve calls it in a defer) with the status of the last respond/respondStreaming, or 0 if nothing was sent |
spawned | vbx.spawn / vbx.spawnAndWait (std.process.Child.spawn, child.id) |
opened | vbx.createFile (flags from CreateFlags: access mode | O_CREAT | O_TRUNC | O_EXCL; the default .{} is 0x241), vbx.openFile (access mode only) |
connected | vbx.tcpConnectToAddress, vbx.tcpConnectToHost |
handoff + enter/exit | vbx.spawnThread(ctx, config, f, args) (std.Thread.spawn) |
Nim
| Event | Emitted from |
|---|---|
request_begin | the wrapped callback of serve/acceptRequest: beginRequest(req.client.getFd(), index) |
request_end | after the callback's future completes, with the code passed to respond. A callback that raises ends with 500 if nothing was sent, and the error propagates. A request answered without respond (writing to req.client directly) ends with 0. |
spawned | startProcess(ctx, ...) (osproc.startProcess, processID) |
opened | open(ctx, filename, mode) (system.open, getFileHandle; flags from FileMode: fmWrite = 0x241, fmAppend = 0x441, …) |
connected | dial(ctx, ...) (net.dial), dialAsync(ctx, ...) (asyncnet.dial) |
handoff + enter/exit | handoff(ctx) + withContext(child): ... for threads / spawn |
There is also a lower-level API for other servers: beginRequest(fd, index), beginRequest(localPort, peerIp, peerPort, index), endRequest, withRequest(fd, index, status): ... (synchronous servers), current()/setCurrent().
Crystal
| Event | Emitted from |
|---|---|
request_begin | Vbxtrace::Handler#call: vbxh_begin_fd(connection socket fd, fiber's counter, http1). Outside HTTP::Server#handle_client (a custom server feeding RequestProcessor), it falls back to request.local_address / remote_address with request index unknown (REQUEST_INDEX_UNKNOWN), since no connection boundary is visible there. |
request_end | after call_next, with context.response.status_code. If the chain raises, the request ends with 500, which is what HTTP::Server answers, and the exception is re-raised unchanged. |
spawned | Vbxtrace.process (Process.new, process.pid), Vbxtrace.process_run (the same, then wait) |
opened | Vbxtrace.file_open(path, mode) (File.open; "w" = 0x241, "a" = 0x441, "r+" = 0x2, …) |
connected | Vbxtrace.tcp_connect (TCPSocket.new), Vbxtrace.connected(socket) |
handoff + enter/exit | Vbxtrace.spawn { ... } instead of spawn |
| raw sessions | Vbxtrace.session(socket) { ... } for TCPServer services: protocol raw, index 0, status 0 |
D (vibe.d)
| Event | Emitted from |
|---|---|
request_begin | TracedHandler.handleRequest: vbxh_begin_str(settings.port, req.clientAddress, its port, task-local counter, http1). vibe.d does not give the request handler the connection's fd, so the peer comes from clientAddress, which vibe-http copies from the accepted TCPConnection, and the local port from the settings the server listens with. It is only computed while a tracer is attached. |
request_end | after the wrapped handler: res.statusCode, or 404 if no handler wrote a response (vibe.d then answers 404 itself). HTTPStatusException ends with its status and other exceptions with 500 (vibe.d's answers); the exception is rethrown. |
spawned | vbxtrace.spawnProcess(ctx, ...) (std.process.spawnProcess, pid.processID) |
opened | openFile(ctx, name, mode) (std.stdio.File; flags from the fopen mode) |
connected | vbxtrace_vibe.connected(ctx, conn) after connectTCP (TCPConnection.fd); vbxtrace.connected(ctx, socket) for std.socket |
handoff + enter/exit | tracedTask(work) instead of runTask(work) |
Odin
| Event | Emitted from |
|---|---|
request_begin | vbx.begin(client, index, protocol): vbxh_begin_fd on the accepted net.TCP_Socket. It also sets the thread's current request. |
request_end | vbx.end(ctx, status): 0 for raw sessions, the HTTP status otherwise |
spawned | vbx.process_start(ctx, desc) (os.process_start, p.pid) |
opened | vbx.open(ctx, name, flags, perm) (os.open, os.fd; Linux flags from File_Flags: {.Write, .Create, .Trunc} = 0x241) |
connected | vbx.dial_tcp_endpoint, vbx.dial_tcp_hostname |
handoff + enter/exit | vbx.spawn_thread(ctx, data, fn) (thread.create_and_start_with_poly_data); vbx.handoff / vbx.enter / vbx.exit for pools |
V (veb)
| Event | Emitted from |
|---|---|
request_begin | vebhook.begin from Context.before_request(): vbxh_begin_fd(client fd, conn_request_index(fd), http1). veb keeps the client fd in a private Context.client_fd; the binding reads it through compile-time reflection ($for f in veb.Context.fields). If a veb version has no such field, the fd reads as -1 and the hook stays silent instead of guessing. |
request_end | vebhook.after (the last global after-middleware) with ctx.res.status_code; vebhook.not_found with 404 |
spawned | vbxtrace.process_run(ctx, mut p) (os.Process.run, p.pid) |
opened | vbxtrace.create(ctx, path) (os.create, 0x241), vbxtrace.open_file(ctx, path, mode) |
connected | vbxtrace.dial_tcp(ctx, address) (net.dial_tcp, conn.sock.handle) |
handoff + enter/exit | vbxtrace.handoff(ctx), then vbxtrace.enter/vbxtrace.exit around work you spawn |
Request index
| Language | How the index is counted | Why it is exact |
|---|---|---|
| Zig | HttpConnection.requests, starting at 0 | one HttpConnection per accepted connection |
| Nim | a table keyed by the request's AsyncSocket object; the entry holds a reference to the socket, and entries of closed sockets are dropped when the next new connection arrives | asynchttpserver serves a connection's requests one after another on one AsyncSocket, which lives exactly as long as the connection; holding the reference keeps its address from being reused while the entry exists |
| Crystal | fields on Fiber (vbx_conn_fd, vbx_conn_requests), set and reset in a reopened HTTP::Server#handle_client | HTTP::Server runs handle_client once per connection in a fiber of its own and processes every keep-alive request of the connection in it |
| D | TaskLocal!uint | vibe-http serves each accepted connection in a task of its own (listenTCP → runTask), and handles its requests sequentially inside it; vibe-core clears task-local storage when a task ends, so a pooled fiber starts the next connection at 0 |
| Odin | your counter per connection (raw sessions: always 0) | the server code owns the connection |
| V | conn_request_index(fd): a slot per fd (up to 65535) holding the socket's inode number and a counter; a different inode means a new connection, so the counter resets | a socket's inode number is unique while the socket exists; a connection's requests are handled one at a time, so its slot is never written concurrently |
Where a binding cannot know the index exactly, it passes VBXH_REQUEST_INDEX_UNKNOWN (each binding has the constant: Zig request_index_unknown, Nim RequestIndexUnknown, Crystal Vbxtrace::REQUEST_INDEX_UNKNOWN, D REQUEST_INDEX_UNKNOWN, Odin REQUEST_INDEX_UNKNOWN, V vbxtrace.request_index_unknown). vulnboxd then links the request only through other exact facts, never by guessing. Pass it too from your own code when you cannot count per connection.
Requests the server rejects before the handler runs, such as a malformed request line or a 400 from the parser, are not counted. Those servers close the connection afterwards, so no later index is affected.
Context following
| Language | Mechanism | Follows automatically | Needs handoff |
|---|---|---|---|
| Zig | vbxhook's per-thread slot: receiveHead sets it, end() clears it; vbx.current(), or pass req.ctx | everything on the connection's thread | new threads (vbx.spawnThread does it), std.Thread.Pool jobs (vbx.handoff before queueing, vbx.enter/vbx.exit in the job) |
| Nim | passed through the request: ctx(req) finds the connection's current request (one request at a time per connection). Async code must not use the thread slot across await; synchronous servers can (withRequest, current()). | every await inside the callback, since ctx(req) is looked up per call | work moved to threads / spawn (handoff + withContext) |
| Crystal | Fiber#vbx_ctx, set by the handler for the duration of the chain; Vbxtrace.current | everything on the request's fiber, across every blocking IO (fibers yield and resume transparently) | fibers started with spawn (fiber-local state is not inherited): use Vbxtrace.spawn |
| D | TaskLocal!ulong; vbxtrace_vibe.current() | everything in the request's task, across vibe's yields | runTask / runWorkerTask (task-locals are not inherited): tracedTask; std.parallelism / threads: handoff + enter/exit |
| Odin | vbxhook's per-thread slot (vbx.begin sets it, vbx.end clears it), or pass the id | everything on the connection's thread | other threads: vbx.spawn_thread; thread.Pool tasks: vbx.handoff + vbx.enter/vbx.exit |
| V | vbxhook's per-thread slot: a veb request runs from before_request to the after-middleware on one fasthttp worker thread; vbxtrace.current() | everything inside the handler | spawned threads: vbxtrace.handoff + vbxtrace.enter/vbxtrace.exit |
Known gaps
All languages. Only calls made through the helpers are linked to a request. A raw posix.open, fork, connect or C library call, or a database driver's own socket, is linked only the way the kernel links it: exactly on thread-per-connection servers, not at all on fiber/async servers. Call spawned/opened/connected explicitly after such calls. A fully static binary keeps the hook off unless you build the static variant. io_uring-based I/O is not covered (as in C1).
| Language | Gaps |
|---|---|
| Zig | only the 0.14.x std.http.Server helper; zap and http.zig not wrapped (see Covers); if std.Thread.spawn fails inside spawnThread, the handoff was already emitted with no enter; HTTP/1 only |
| Nim | Jester/httpbeast and Prologue/httpx not covered; requests answered without respond end with status 0; the per-connection table purges closed sockets only when a new connection arrives (bounded by the number of connections open at that moment) |
| Crystal | the per-connection index relies on reopening the private HTTP::Server#handle_client (checked against 1.12–1.17; a future rename makes the handler fall back to the request's addresses with index unknown, so re-check after upgrading Crystal). With -Dpreview_mt and execution contexts, fiber-local state is still right, because it lives on the fiber. |
| D | no fd: keys come from req.clientAddress and settings.port. Behind a bindAddresses list with different ports per address, pass the right settings. HTTP/2 requests are reported with index unknown. |
| Odin | no HTTP framework wrapper (Odin has no standard HTTP server); the request index of hand-rolled HTTP is yours to count |
| V | reads veb's private client_fd by reflection, so re-check after upgrading V (the hook goes silent rather than wrong). A request that a before-middleware answers on its own (returning false) or a user after-middleware cuts short never reaches vebhook.after; it is closed with status 0 when that worker thread starts its next request. veb's static file serving never calls before_request, so static files are not reported. Requests on fds ≥ 65536 (or when fstat fails) are reported with index unknown. net.http.Server not covered. |
Safety
What is wrapped: nothing is hooked behind the service's back. The binding is a set of functions the service calls. Each wrapper calls the language API first and reports afterwards, passing the API's result, error or exception through unchanged. It only reports on success.
| Guard | every event goes through vbxhook.c. It does nothing unless the core is loaded, the binding is not disabled, and a tracer is attached (vbx_v1_enabled()). While no tracer is attached, a call costs a few loads. |
| Internal errors | counted in vbxhook.c: a missing core symbol, getsockname/getpeername failing, an unparsable address. After 5 the binding switches off for the process. Each binding exposes the count (errors()). |
VBXTRACE=0 | read by vbxhook.c at its first call: the binding stays off for the process |
| No new failure modes | the C functions never raise, block, allocate or change errno. No language binding raises, panics or allocates without bound on the hook path, and none changes a request, a response or a status. |
| Exceptions | Crystal, D and Nim end the request with the status the server answers (500, or the HTTPStatusException's status in D) and re-raise unchanged. Zig ends with the status already sent, or 0, when the handler returns an error. |
| Chaos test | with VBXTRACE_CHAOS=1, every call into the core fails inside the guard. Every sample's responses are byte-identical to the normal run. |
Overhead will be measured in the performance phase; no numbers are published for this package yet.
Without a tracer, the hook adds two or three calls per request, each of which returns after a single load. V adds one fstat per request (the connection index); Nim adds a table lookup.
Turning it off
Set VBXTRACE=0 in the service's environment and restart it, or revert the change that added the hook; vulnboxd's rollback covers a hook that breaks a service.
Removing the /opt/vbxtrace mount also turns it off: dlopen fails and the binding stays off for good, at no cost. To remove the hook completely, revert the diff: delete the vendored directory (vbxtrace.zig, vbxtrace.nim + vbxtrace/, src/vbxtrace/, vbxtrace/), the vbxhook.c build step (build.zig lines, the cc line in the Dockerfile, the dub preBuildCommands/sourceFiles), and the wrapper lines. The helpers are thin wrappers, so replacing Vbxtrace.process_run( with Process.run( (and so on) restores the original calls.
Troubleshooting
- Are the probes there?
readelf -n /usr/local/lib/vulnboxd/trace/libvbxtrace-x86_64.solists them, and so doessudo bpftrace -l 'usdt:/usr/local/lib/vulnboxd/trace/libvbxtrace-x86_64.so:*'. - Is the hook loaded?
grep vbxtrace /proc/<pid>/mapsshows the core once the first request (or the binding'sinit()at startup) has loaded it. Every binding'sinit()/load()returns true when the core loaded (Zigvbx.init(), Nimvbxtrace.init(), CrystalVbxtrace.init, Dvbxtrace.init(), Odinvbx.init(), Vvbxtrace.load()), andactive()is true while a tracer is attached.errors() >= 5means the binding switched itself off. - Which links did a flow get? The hub shows each link's method; this package's are
hook:C2. - The binary is static, so the hook silently stays off. Check with
ldd <binary>(it must showlibc.so.6orld-musl).- Zig on musl links static by default with
-lc: use-dynamic/exe.linkage = .dynamic. - Crystal: remove
--static. - Nim: remove
--passL:-static. - Or build the static variant:
-DVBXHOOK_STATICpluslibvbxtrace-<arch>.a.
- Zig on musl links static by default with
vbxtrace.h: No such file or directorywhen compilingvbxhook.c: the-Ifor the directory holdingvbxtrace.h(andvbxhook.h) is missing. Nim:-d:vbxhookInc=<dir>.- Undefined
dlopen/dlsymon glibc < 2.34: add-ldl.- Zig:
exe.linkSystemLibrary("dl"). - Nim:
--passL:-ldl. - Crystal:
@[Link("dl")]. - D:
libs "dl". - Odin:
-extra-linker-flags:-ldl. - V:
#flag -ldl.
- Zig:
- Undefined
vbxh_*symbols. The object was not built or not linked.- Crystal looks for
vbxhook.onext tovbxtrace.cr. - Odin looks for
vbxhook.anext tovbxtrace.odin. - V looks for
vbxhook.oinvbxtrace/. - D: check
sourceFiles.
- Crystal looks for
- Zig: "import of file outside module path".
vbxtrace.zigmust sit inside the root module's directory. - Nim: "ambiguous call" for
serve/respond. The service imports bothstd/asynchttpserverandvbxtrace/asynchttp. Remove the std import;vbxtrace/asynchttpre-exports everything else. - Crystal: every request has index 0 and no fd. The handler is not running inside
HTTP::Server#handle_client: a custom server, or a Crystal version that renamed it. Check thatrequire "./vbxtrace/vbxtrace"comes afterrequire "http/server". - D: wrong local port.
tracedtakes the port from the settings object passed to it. Pass the same settings aslistenHTTP. - V: no events at all.
vebhook.client_fd(ctx)returns -1: this veb version has noclient_fdfield (or uses a different backend). The hook then stays silent by design.