Skip to content

gobridge: read-only bridge(8) clone — link, vlan, vni, mst, fdb, mdb - #316

Merged
randomizedcoder merged 18 commits into
mainfrom
goip/bridge
Nov 23, 2026
Merged

randomizedcoder merged 18 commits into
mainfrom
goip/bridge

Conversation

@randomizedcoder

Copy link
Copy Markdown
Owner

Summary

gobridge is a Go clone of iproute2's read-only bridge commands. Built increment by increment: captures first, then parsers, then the clone.

  • 6S: internal/wsreplay, the ws-pcap replay core shared by govdpa, gotipc, godevlink and gobridge.
  • 6C / 6X-C / 7C: nlcapgen capture spaces bridge (113 rows), bridgex (63) and bridgefdb/bridgemdb (94 + 74), in pkg/xtcpnl/testdata/7_3_1/ws/. Each was captured twice on one boot, and the two runs matched apart from a named allow-list of timer rows.
  • 6P / 6X-P / 7S / 7P: in pkg/xtcpnl:
    • decoders: bridge link, vlan tables, vnifilter, mdb router ports, the mdb dump and get replies;
    • request builders for the fdb and mdb dumps and gets.
    • Every captured request is rebuilt byte for byte.
  • 6R / 6X-R / 7R: cmd/gobridge and internal/gobridge:
    • link, vlan, vni, mst, fdb show/get and mdb show/get;
    • the options -j -p -s -d -o -t, -batch/-force, -netns and -family.
    • Writes and monitor are refused.
  • Bug records: iproute2 findings B1–B57 and kernel notes K1–K9 are in docs/netlink/upstream/iproute2-bridge-print-paths.md. upstream/bug-classes.md is a checklist that sorts them into bug classes. These are recorded only and not submitted to netdev.

Status and verification ledger (V096–V109, DOC031–DOC034): docs/netlink/gobridge-status.md.

Verification

  • Corpus replay: gobridge replays all 344 ws/bridge* rows byte for byte (stdout, stderr, exit code), plus the 376 older fdb/mdb readbacks.
  • Unit tests: table-driven, covering positive, negative, boundary and corner cases, for the paths no capture reaches.
  • Mutation testing: 10 of 10 mutants killed for fdb and mdb.
  • Live comparison with bridge in the workbench VM:
    • 6X: 28 of 28 commands identical.
    • 7: 169 of 174 identical. The other 5 are mdb -s rows that differ only in a running timer; with the timer masked they match.
  • CI checks: go test ./..., the test-go-race nix check, lint-baseline, netlink-audit and kernel-citation-audit all pass.

🤖 Generated with Claude Code

randomizedcoder and others added 18 commits November 22, 2026 21:29
govdpa, gotipc and godevlink each carried the same ~150-line replay
core. Move it into internal/wsreplay before gobridge makes a fourth
copy. Options carry what differed: the clone's ErrReplay sentinel, the
Canon hook (CanonGenlCmd for devlink's renumbered command enum) and the
two names in the mismatch message. Each clone keeps a thin ReplaySource;
gotipc's keeps Own/Addr/NodeName. The three corpus tests are unchanged.

The three imports guards also gain pkg/strpolicy, which PR #308 put in
xtcpnl's closure after #309's guards were written (failing on main).

TestReplay (14 rows) and TestMismatchAlignment (4 rows), 93.7% cover.
Opens docs/netlink/gobridge.md and gobridge-status.md (increment 6).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
upstream/bug-classes.md sorts the ~70 iproute2 findings recorded so far
into fifteen recurring classes (wrong attribute width, print sign, no
presence/length check, unbounded index, -j ignored, broken JSON on error
paths, varying JSON keys, exit status, argument parsing, message text,
buffers, crashes, output before success, filter logic, kernel quirks),
each with prior examples and a recipe for finding it. Every conversion
increment now opens by applying it; bridge's leads B1-B17 came from it.

Record only: not submitted to netdev.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
bridge(8)'s read-only link, vlan, vni and mst commands over rtnetlink:
44 commands across nine namespace fixtures (bare, br, brglob, brmst,
brmstnov, vxtun, brwide, vnif, brmaster), each plain and -j, plus 25
negatives. Every expectation came from the source and matches live.

The rows confirm bug leads B1 (a port named master cannot be filtered:
its name is re-read as the keyword), B2, B3 ("Dump ternminated"), B5
(vid via atoi), B6, B10 (mst dump aborted by a port without AF_SPEC),
B21, B22 and B24, and add B25 (-j -s keys VLANs "vid", not "vlan") and
B26 ("flags": [] on ranges). -c is -color; compression is -com.

A failed dump's extack rides in NLMSG_DONE, which the ws corpus test now
reads (wsDoneExtack, table-tested).

Two batches on one boot agree on rc, stdout, stderr, message types and
flags; bodies differ only in linkwatch timing, a port timer and the
echoed seq. The fresh-boot batch is still to do: the shared workbench VM
was in use by another session.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ParseBridgeLink decodes AF_BRIDGE RTM_NEWLINK (protinfo, VLAN list,
tunnel map, MST entries), ParseTunnelMsg RTM_NEWTUNNEL (VNI filter
entries and stats), and ParseBrVlanTables RTM_NEWVLAN entries and global
options. They sit on AttrTable, a first-wins tb[] with width-checked
getters, so the gobridge renderer can mirror bridge's reads one for one.
BuildDumpBrVlanRequest and BuildDumpTunnelRequest complete the requests
bridge sends.

The corpus test rebuilds all 214 captured requests byte for byte,
including the by-name lookups, decodes 213 replies and checks 41 -j
outputs against them. Table tests, fuzzers seeded from the corpus, and
benchmarks cover the decoders. New lead B27: bridge casts
IFLA_BRIDGE_VLAN_INFO with no length check. RTM_GETTUNNEL leaves the
netlink universe's exclusions, now that it is captured.

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

internal/gobridge follows bridge/*.c function by function: option and
object dispatch, the show parsers (B1's missing else, atoi vids, ignored
words), print_linkinfo, the three vlan_show paths, global options with
querier state and router ports, vni and mst, over a json_print and
color.c port and libnetlink's dump error paths. It replays all 113
corpus rows byte for byte (stdout, stderr, rc) with every request asked
for, and talks to the kernel when no capture is given.

xtcpnl gains ParseAttrTableFlags, WalkRawAttrs and FindRawAttr for the
printers that depend on NLA_F_NESTED (print_vlan, print_msts).

41 unit rows over a scripted source pin the unit-only leads (B4, B7,
B11-B13, B15, B16, B18-B20, B27); 8 of 9 mutants die, and the survivor
is equivalent. The live diff beside bridge in a VM is still to do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
upstream/iproute2-bridge-print-paths.md records what the bug-class sweep,
the capture and the gobridge clone found in bridge/: a port named master
that no link show spelling can filter (B1), mst show failing on every
bridge with MST off (B10), the "Dump ternminated" typo, atoi VLAN IDs,
headers left on stdout, NULL reads in the vlan option printers (one a
copy-paste guard), unchecked attribute casts, and JSON keys that change
with -s. Each finding has file:line, its class, and the row that shows
it. bridge/ is unchanged in the newest upstream code (GitHub mirrors;
git.kernel.org refused the fetch).

Record only: not submitted to netdev.

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

A second bridge space, bridgex, covers what 6R still refused: -batch
(file and stdin), -force, -netns, -family/-4/-6, and the -s router-port
stats of `vlan global show`. Its 63 rows (23 commands plain and -j, 17
negatives) go to ws/bridgex so 6C's ids stay as captured. A batch row's
last pre step writes b.txt in the row's directory, which keeps the file
beside the capture.

Two batches on one workbench boot: 63/63 OK, every rc as predicted, and
identical output except the temp router's timer in the 6 brrtr -s rows.
They confirm, live:
- B28: the per-object filter statics carry over between batch lines;
- B29: so a second `vid` line is a duparg exit through -force;
- B30: a failed dump's exit(1) ends a -force batch;
- B31: a missing continuation line ends the batch with rc 0;
- B32: words after `-batch FILE` are ignored;
- B33: `bridge -netns` opens "(null)";
- B34: -j router-port "timer" carries the column padding;
- K3: the kernel reports a per-VLAN router port's type from its
  port-wide setting.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Decodes a bridge's multicast router ports: an MDBA_ROUTER payload, the
RTM_GETMDB dump's or the one inside a VLAN's global options, to its
MDBA_ROUTER_PORT entries (ifindex, timer, type, per-family timers, vid).
Strict on widths and framing; unknown types are skipped.

TestParseMdbRouterPorts has 20 table rows (positive, negative, boundary,
corner, each with description and expected). TestWsBridgexRouterPorts
(O4) matches every -j router port in the 6X-C corpus to its decoded
port: name, type and timer text. The captured nest shows the kernel's
K3 at the decoder: a per-VLAN permanent port typed temp-query. Plus a
fuzzer seeded from the captures and a benchmark.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…(6X-R, V103)

gobridge now clones the read-only paths 6R refused:
- -batch FILE / -batch - with -force: do_batch, getcmdline and makeargs
  ported line for line (comments, continuations, quotes, NUL, the
  511-word limit);
- -netns (setns on a locked thread; no mount-namespace remount), and
  -family/-4/-6, which these shows ignore;
- -s router ports in vlan global show (br_print_router_port_stats).

A batch keeps bridge's process state between lines, so the filters are
now per object as bridge.c's statics are, set by a word and never
cleared (B28, B29), and ll_init_map runs once. A command returning -1
(retCode) is "Command failed" and -force goes past it; exit() (exitCode)
ends the batch (B30). The option loop moves out of main.

All 176 corpus rows (6C's 113, 6X-C's 63) replay byte for byte. New
tables: TestGobridgeBatch (26), TestMakeargs (14), TestGetcmdline (13),
TestGobridgeOptions (15), TestRouterPortStats (10), each row with
description and expected. 13 of 13 mutants killed; coverage 82.9%.

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

B28-B36 and a kernel note, K3, in iproute2-bridge-print-paths.md: batch
lines inherit the previous line's filters (B28) so a second vid is a
duparg exit (B29); exit(1) on a failed dump ends a -force batch (B30); a
missing continuation drops the rest with exit 0 (B31); words after
-batch FILE are ignored (B32); -netns with no name opens "(null)", in ip
too (B33); the -j router-port timer keeps its padding (B34) and is read
unchecked (B35); -j -batch prints a stream of arrays (B36). The kernel
types a per-VLAN router port by its port-wide setting (K3).

bug-classes.md gains C16, process state carried between batch lines.
All present in the newest code. Not submitted to netdev.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…l (6X-L, V104)

Live in the workbench VM, the nix-built gobridge and bridge print the
same bytes and exit the same for 28 commands: batches (B28-B32 among
them), -force, router-port stats, -family/-4/-6, and -netns into a real
named namespace, the one path a capture can't see.

The run showed gobridge's -V line was ip's form. bridge prints
"bridge utility, 7.2.0", without the "iproute2-" ip and tc print;
gobridge now does too (two unit rows), and bridge's form is recorded as
B37. Not submitted to netdev.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ridge (7S, V105)

Increment 7 starts from what is on disk: each of the 376 fdb/mdb write
rows in 7_3_0 reads back with `bridge fdb|mdb show dev X`. Four builders
(BuildFdbDumpRequest, BuildFdbGetRequest, BuildMdbDumpRequest,
BuildMdbGetRequest) rebuild all 553 of those dump requests byte for
byte; bridge sends the fdb dump as a 284-byte datagram over a 28-byte
message, pinned. TestGobridgeReadbacks pins the readback counts and
replays them once fdb/mdb show land (7R). gobridge.md gains the
increment 7 plan.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…_NETNSID (7P, V106)

ParseMdbDumpRouters decodes one mdb dump reply whole, its entries and
MDBA_ROUTER's ports; ParseMdbGetReply is mdb_get's answer, exactly one
entry and no router. ParseMdbDump keeps each source's timer beside the
source list (MDBA_MDB_SRCATTR_TIMER), and ParseNeigh reads
NDA_LINK_NETNSID as the kernel's s32. NtfSticky stands in for the
NTF_STICKY x/sys/unix lacks.

Every reply in the 376 fdb/mdb readbacks decodes: 557 AF_BRIDGE
neighbors and 790 mdb entries, and the bridge's dump replies are
RTM_GETMDB where a VXLAN's are RTM_NEWMDB (K5).

No separate ParseFdb, unlike the plan: ParseNeigh already decodes the
fdb attributes, and gobridge renders from bridge's raw tables.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ayed (7R, V107)

fdb.go and mdb.go clone bridge/fdb.c's and bridge/mdb.c's reads
function by function: the strcmp'd show words, the state names, the
per-object statics that outlive a batch line (F2, M3), print_fdb's
order with the REACHABLE "" and the viaIf/viaIfIndex split, fdb_get's
short vlan and VNI check, mdb_show's two dumps and the jsonw_destroy
assert after a failed one under -j, print_mdb_entry with its unaligned
source timers, and mdb_get's group parsing through ll_addr_a2n as
written. Writes and monitor stay refused.

TestGobridgeReadbacks now replays all 376 fdb/mdb readbacks byte for
byte, and TestGobridgeFdbMdbUnit's 47 rows pin what no capture reaches.
10 of 10 mutants are killed. Coverage is 80.5% here and 83.3% once the
7C corpus (next commit) replays too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…replays them (7C, V108)

Two capture spaces, bridgefdb (94 rows) and bridgemdb (74), cover what
the 7_3_0 write rows' readbacks lack: -j, -s, -d, -o, every show filter,
the get forms and batch, over fixed-MAC fixtures. Two batches on one
workbench boot agree byte for byte, except the running timer of the
temp mdb entries in four -s rows.

The captures confirm F2-F5, F7, F13, M1-M3, M5 and K4 live, and showed
four things the first fixtures had wrong: a host join cannot be
permanent; an entry added without a vid lives on every VLAN of the port,
so mdb get needs its vid; a VXLAN entry's src_vni is part of its key
though a non-external device's dump never prints it; and br0's own MLD
report adds an ff02::6a join at a random moment (IPv6 is off on br0).

O3 rebuilds all 207 fdb and mdb requests with the 7S builders; O4 finds
every -j object in the decoded replies. gobridge replays all 344
ws/bridge* rows byte for byte; coverage 83.2%.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The increment 7 bug-class sweep over bridge/fdb.c, bridge/mdb.c and
their lib/ helpers, recorded in iproute2-bridge-print-paths.md. Not
submitted to netdev.

Each finding has its file:line at v7.2.0, its class and the corpus or
unit row that shows it. Among them: filters that leak between batch
lines and hide a later get's answer (B39), fdb show dynamic keeping
static entries (B40), fdb get's short vlan (B47), and an assert abort
on a failed mdb dump under -j (B51). B57 (ll_addr_a2n) is fixed at
HEAD; the rest are present in the newest code.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ical (7L, V109)

Every 7C command, in a namespace per fixture on the workbench VM, plus
six -netns and batch forms. The five that differ are mdb -s rows whose
temp-entry timers were read 10 ms apart; with the timers masked they
are identical. Increment 7 is done.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@randomizedcoder
randomizedcoder merged commit f74ac1b into main Nov 23, 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