Skip to content

goip: ip tunnel, ip -6 tunnel and ip tuntap show (increment 8) - #321

Merged
randomizedcoder merged 8 commits into
mainfrom
goip/tunnel
Nov 24, 2026
Merged

randomizedcoder merged 8 commits into
mainfrom
goip/tunnel

Conversation

@randomizedcoder

Copy link
Copy Markdown
Owner

goip now runs ip [-4|-6] tunnel show|list|lst, ip tunl and ip tuntap|tap show, and matches iproute2 7.2.0 byte for byte. These commands need ioctl, sysfs and procfs answers that netlink doesn't carry, so the increment adds a sidecar for them.

Changes

  • internal/tnlsys + cmd/tnlsnap (8S):
    • tnlsnap runs ip under ptrace and records each tunnel ioctl with its exact input, plus the sysfs props and the /proc tun-fd walk.
    • goip replays the recording with GOIP_TNLSYS. An unrecorded question is a replay error, not a guessed answer.
  • Captures (8C): 217 rows in ws/tunnel and ws/tuntap, each with a tnlsys sidecar.
  • Parsers (8P): ip_tunnel_parm, ip6_tnl_parm2, PRL, 6rd and sysfs parsers in pkg/xtcpnl, with fuzz targets and benchmarks.
  • goip (8R): obj_tunnel.go, obj_tunnel6.go, obj_tuntap.go and render/tunnel.go.
    • The object goip called tunl6 is renamed tunl, which is what ip has.
    • Writes (add, change, del, prl, 6rd, tuntap add/del) are refused as not implemented.
  • Upstream findings (8B): docs/netlink/upstream/iproute2-tunnel-tuntap.md, with T1–T25 for iproute2 and K1–K2 for the kernel. Recorded only, not submitted to netdev.
  • Fixes found before push:
    • V006: a tnlsnap test read the host's /sys, which the nix sandbox doesn't have.
    • V007: the ptrace loop treated a thread that vanished mid-stop as fatal; it now skips the thread.

Verification

  • Corpus replay: all 195 replayable rows match ip's stdout, stderr and exit code. The other 22 aren't replayed: 12 batch rows, 2 -p rows and 8 writes.
  • Live on the workbench VM: goip and ip ran the same 195 commands and agreed on every one.
  • Unit tests and coverage: table-driven tests; all 10 planned mutants killed; coverage of the new files 83–96%.
  • Checks: full go test ./... and nix test-go-race pass at ef74024. lint-baseline, netlink-audit and kernel-citation-audit pass.

Ledger: docs/netlink/goip-tunnel-status.md (V001–V007, DOC001).

🤖 Generated with Claude Code

randomizedcoder and others added 8 commits November 23, 2026 14:53
…IP_TNLSYS (8S, V001)

ip tunnel and ip tuntap ask the kernel outside netlink: SIOCGETTUNNEL,
SIOCGETPRL and SIOCGET6RD ioctls, /sys/class/net tun props and a /proc
walk. internal/tnlsys is the seam: Live asks the kernel (with a spill
window, since ip6gre writes 76 bytes into whatever it is given), and
Snapshot answers from a JSON sidecar keyed by each ioctl's exact input,
because a fallback device answers per the parameters passed.

tnlsnap records the sidecar by running ip under ptrace (threads
followed), plus the tun props and the tun descriptor walk. goip's
runCtx.sys comes from GOIP_TNLSYS, an empty snapshot under GOIP_REPLAY,
or Live.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rows (8C, V002)

Two capture spaces: tunnel (171 rows: ip tunnel and ip -6 tunnel show,
plain and -j, the list, named and mode paths, filters, batch and 27
negatives) and tuntap (46 rows, including -d with python TUNSETIFF
holders and a holder in another namespace). Each row carries a tnlsys
readback: tnlsnap traces ip again and records its ioctls, the tun props
and, when ip would walk it, /proc.

Two batches on one workbench boot agree byte for byte except for the
holder pids of the eight -d rows with holders, and every sidecar's
traced run matches the captured ip.

The batches found two recorder faults, fixed here. The spill kept ip's
own stack past the kernel's write, so the tracer now fills the window
with 0xA5, cuts at the last changed byte and restores the rest; gre6x's
spill is exactly the 24 bytes ip6gre writes past 52. The /proc walk ran
for every row and picked up other rows' holders, so it now runs only
when ip would walk it, mirroring ip.c's option loop and object order.

goip's hermetic import test now allows internal/tnlsys, which 8S added
without updating it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ParseIPTunnelParm, ParseIP6TnlParm2, ParseTunnelPRL, ParseTunnel6RD and
ParseSysfsLong (read_prop's strtol check). Table tests, fuzz targets,
benchmarks, and an O-check: all 958 corpus SIOCGETTUNNEL answers decode
and the 554 with a link in the row's dump agree with its info data.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…R, V004)

goip now runs `ip tunnel`, `ip -6 tunnel`, `ip tunl` and `ip tuntap|tap`
as iproute2 7.2.0 does: do_iptunnel's mode pre-scan, both parse_args,
the named path (text even under -j) and do_tunnels_list with its bare
stats and newlines, ip6tunnel's no-newline named path, and print_tuntap
with read_prop's messages and show_processes. Ioctls, sysfs and /proc go
through runCtx.sys.

All 195 replayable ws/tunnel and ws/tuntap rows match ip's stdout and
exit status byte for byte, -d pids included; batches, -p and writes are
left out and counted. The wrong tunl6 row becomes ip.c's tunl alias.
Shared C helpers and keyword constants move from goip_write files to
untagged ones so the read build has them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…, DOC001)

Records 23 iproute2 findings and 2 kernel notes from increment 8, each
with its v7.2.0 file:line, the corpus row or unit row that pins it, and
its status at HEAD: a stack overflow on `ip tunnel show gre*` for an
ip6gre device (fixed upstream after 7.3.0, the garbage line remains), a
double fclose in read_prop, an uninitialized encaplimit byte, -s text
inside -j, and filters that match the wrong tunnels. Not submitted to
netdev. T21 is refuted; nlcapgen's comment that asserted it is fixed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On the workbench VM, goip and ip 7.2.0 ran every 8C read command over
the 8C fixtures, each in its own netns with real tun holders, and agreed
on stdout and exit status in all 195, holder pids included.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The nix test sandbox has no /sys/class/net, so test-go-race failed in
TestRunIP. snapshotIP now reads a package-level liveSys, which the test
points at an empty fake tree.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The full go test ./... failed cmd/tnlsnap TestRunIP with "trace: regs:
no such process", 77 of 800 runs under load. A thread of the
multithreaded Go helper can be killed by its sibling's exit_group
between Wait4 and PTRACE_GETREGS; ptrace(2) says a tracee can vanish
at any stop. The tracer now drops such a thread and keeps waiting.
TestThreadGone pins the rule; the stress run passes 800 of 800.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@randomizedcoder
randomizedcoder merged commit d0f7d4e into main Nov 24, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant