Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
36 changes: 36 additions & 0 deletions docs/netlink/gobridge-status.md

Large diffs are not rendered by default.

38 changes: 35 additions & 3 deletions docs/netlink/gobridge.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,9 @@ changed the fixtures: MST can only be enabled while no port has VLANs, so `brmst
rc);
- the `cmds[]` dispatch, with `help` for every object;
- the writes (`link set`, `vlan add/del/set`, `vlan global set`, `vni add/del`,
`mst set`, `fdb add/append/replace/del/flush`, `mdb add/replace/del/flush`) and
`monitor` → `notImplemented` (rc 255). `fdb` and `mdb` were refused whole until
increment 7 (7R) cloned their `show` and `get`.
`mst set`, `fdb add/append/replace/del/flush`, `mdb add/replace/del/flush`) →
`notImplemented` (rc 255). `fdb` and `mdb` were refused whole until increment 7 (7R)
cloned their `show` and `get`; `monitor` until increment 25 (25R, `monitor.go`).
- **One file per object:** `link.go`, `vlan.go` (show/compressed/details/stats/tunnelshow/
global), `vni.go` and `mst.go`. Each mirrors its `bridge/*.c` printer: column widths,
the `-com` range printing, the headers printed before the dump, and the `-s` stats blocks.
Expand Down Expand Up @@ -670,3 +670,35 @@ path leaves JSON writer depth > 0 → assert", if it isn't already covered by C6
Run gobridge next to `bridge` in a named netns in the guest, over the `fdbF`, `fdbVx`, `mdbM` and `mdbVx`
fixtures: every 7C read command plus batch. The target is all identical, with exceptions named. A divergence is
fixed with a unit row added.

## Increment 25 — `bridge monitor` (V110–V114, DOC035)

`bridge monitor`, live and `file F`, with `-t`, `-j`, `-d`, `-s` and the batch forms, byte for byte. This finishes
gobridge's read side; only the writes are still refused. Planned 2026-12-03, after tc's increment 24, going
bottom-up. Leads are in [upstream/iproute2-bridge-monitor.md](upstream/iproute2-bridge-monitor.md) (B58-B76,
K10-K17), not submitted to netdev. The ledger rows in [gobridge-status.md](gobridge-status.md) have the detail.

| task | what | ledger |
|---|---|---|
| 25X | `nlmon.TstampText` (from goip); `xtcp2-nl-tcmon` made a generator; `xtcp2-nl-brmon-ws`, ready when the monitor's own socket (found by inode) is idle in recvmsg; `nix/checks/nlcap-brmon-ws.nix` | V110 |
| 25C | `ws/brmonitor`, 44 rows: 18 live over five fixtures, 12 file and batch rows over the live rows' own notifications, 14 negatives | V111 |
| 25P | `xtcpnl.BrEventKind`; `TestWsBrMonitor` decodes all 307 bridge events | V112 |
| 25R | `monitor.go` and `source_monitor.go`; corpus replay, 31 unit rows, a file fuzz, 8 mutants | V113 |
| 25B | the doc's HEAD check, summary and checklist; extension lines in [upstream/iproute2-bridge-print-paths.md](upstream/iproute2-bridge-print-paths.md) | DOC035 |
| 25L | gobridge next to `bridge` 7.2.0 on the workbench, every `brmonitor` row | V114 |

**How the clone is put together:**

- **Words:** do_monitor's order and matching (`f` is `file`; `vni` and `all` need the whole word). A selector
zeroes the bind mask, and `all` restores `~RTMGRP_TC` with vlan, vni and the banner.
- **Live:** `MonitorSource.Subscribe` is rtnl_open on the mask, with `AddGroup` for BRVLAN (33) and TUNNEL (35).
ll_init_map runs on the monitor's socket, then `nlmon` listens.
- **Replay:** a replay subscription plays the capture's notifications and answers the monitor's own dump from it.
- **File:** `nlmon.ReadFile`, every record to accept_msg. There's no ll_init_map, so names come from the main
source.
- **Printing:** accept_msg dispatches on `xtcpnl.BrEventKind` to the show printers. Each calls `printHeaders`
after its filters, as C does.
- **Batch state carried as bridge carries it:** the closed rth (B63), `prefix_banner` (B62), and a `-t` counter
that every show zeroes (B64).
- **Crashes:** the crash bridge has on a crafted file (B20 through `monitor file`) is refused by name, as 6R's
are.
269 changes: 269 additions & 0 deletions docs/netlink/upstream/iproute2-bridge-monitor.md

Large diffs are not rendered by default.

23 changes: 23 additions & 0 deletions docs/netlink/upstream/iproute2-bridge-print-paths.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
- B28-B34, B36 and B37 come from 6X ([gobridge.md](../gobridge.md#6x--the-rest-of-the-read-only-surface-v101v104-doc033)): batch mode, `-netns` and router ports, captured in `pkg/xtcpnl/testdata/7_3_1/ws/bridgex/` (rows named `bridgex/...`). B35 is latent, with a unit row in `internal/gobridge/batch_test.go`.
- B38-B57 come from increment 7 (fdb and mdb, [below](#increment-7-fdb-and-mdb-b38-b57-k4-k9)). B38, B39, B40, B41, B43, B45, B47, B49, B50, B55, B56 and B57 are captured in `pkg/xtcpnl/testdata/7_3_1/ws/bridgefdb/` and `ws/bridgemdb/` (rows named `fdb ...`/`mdb ...` below). B42, B44, B46, B48, B51, B52, B53 and B54 are latent, with unit rows in `internal/gobridge/fdbmdb_test.go`.
- K1-K9 are in the kernel, not iproute2.
- `bridge monitor` (increment 25) has its own doc, [iproute2-bridge-monitor.md](iproute2-bridge-monitor.md), with B58-B76
and K10-K17. Its cases of B20, B28, B29 and B30 are "Extended in increment 25" lines below.
- B14 and the lead M11 are dropped (see the end).

## Contents
Expand Down Expand Up @@ -69,6 +71,7 @@
- [Dropped: B14, M11](#dropped-b14-m11)
- [Still present in the latest code](#still-present-in-the-latest-code)
- [How xtcp2 handles them](#how-xtcp2-handles-them)
- Increment 25, `bridge monitor` (B58-B76, K10-K17): in [iproute2-bridge-monitor.md](iproute2-bridge-monitor.md)

## Summary

Expand Down Expand Up @@ -177,6 +180,9 @@ None of the show loops has a final `else`: `brlink_show`, `vlan_show` (`vlan.c:1

- `vni.c:376`: `fprintf(stderr, "Dump ternminated\n")`. This is reachable: `bridge vni show dev d1`, where `d1` is not a VXLAN device, is refused by the kernel (EINVAL, extack "The device is not a vxlan device"), and bridge prints the typo (ng-021).
- `mst.c:141`: `perror("Cannon send dump request")`, on a send failure only.
- **At HEAD (checked in increment 25, 25B):** `1392041d` (2026-11-26, "bridge: vni: fix typo in error message")
fixes vni.c's "Dump ternminated". `mst.c:141`'s "Cannon send dump request" is still there at the mirror's `main`,
`d7e038f99479`. gobridge keeps 7.2.0's text, which the corpus pins (ng-021).

## B4. `mst show` exits 255 on a failed dump; the other objects exit 1

Expand Down Expand Up @@ -277,6 +283,8 @@ The fix is `return 0` for a message without `AF_SPEC`, and testing the filter fi

The kernel always sends these today, so all three are latent. `gobridge` exits 139 with stdout lost, as bridge would (unit rows B18, B19, B20).

- **Extended in increment 25:** B20 is reachable without the kernel through `bridge monitor file F`, which hands every record to `print_vlan_rtm` (`monitor.c:63`, B65). A 36-byte file of one `RTM_NEWVLAN` record whose `BRIDGE_VLANDB_ENTRY` holds an 8-byte attribute but no `ENTRY_INFO` gets bridge to the NULL read: exit 139, stdout lost (checked with nixpkgs' `bridge` 7.2.0: rc 139 and 0 bytes of output to a file, nothing on a terminal). `FuzzGobridgeMonitorFile` found it (seed `internal/gobridge/testdata/fuzz/FuzzGobridgeMonitorFile/8ef34ef20cf93c8e`), and the fuzz oracle accepts 139 for it. Because `monitor file` reads any file, the latent NULL read becomes a crash a user can trigger with a crafted capture. See [iproute2-bridge-monitor.md](iproute2-bridge-monitor.md#b65-b66-b75-file-mode).

## B21. `vlan global` dispatches with `strcmp`

`do_vlan` matches its sub-commands by prefix (`matches`), so `bridge vlan sh` works. `vlan_global` (`vlan.c:1325-1338`) uses `strcmp`, so `bridge vlan global sh` prints the vlan usage and exits 255 (ng-009). `do_vni` uses `strcmp` throughout (`bridge vni sh`, ng-008), so prefixes work for some objects and not others.
Expand Down Expand Up @@ -329,6 +337,11 @@ so an error happens to clear it; nothing else does.
**Fix sketch:** reset the filters at the top of each `*_show`, and test duplicates with a
local flag, as `filter_dev` already is.

- **Extended in increment 25:** the statics reach `bridge monitor`, whose printers are the shows'. After
`fdb show dev d1`, a `monitor file m.bin` line prints d1's fdb events without `dev d1` and drops the delete on d2
(B69, brmonitor/ec-027). `monitor ... all` adds a static of its own, `prefix_banner`, which a later `monitor` line
inherits (B62, ec-028). See [iproute2-bridge-monitor.md](iproute2-bridge-monitor.md#b62b64-b69-b74-state-that-outlives-its-command).

## B30. A failed dump ends a `-force` batch

`-force` is meant to keep a batch going past a failed command: `do_batch` breaks on a
Expand All @@ -340,6 +353,12 @@ never runs and no "Command failed" is printed (ng-007). `mst show` returns -1 (B
`-force` batch does go past it (ng-005). Usage, `duparg` and `incomplete_command` exit
too (ng-008: `link help`).

- **Extended in increment 25:** `bridge monitor` makes every later dump line fail this way. `do_monitor` closes the
batch's socket (`rtnl_close(&rth)`), so the next show's dump request fails with
`Cannot send dump request: Bad file descriptor` and `exit(1)` (B63, brmonitor/ng-012). A missing file in
`monitor file` exits -1, which ends a `-force` batch too (ng-014). See
[iproute2-bridge-monitor.md](iproute2-bridge-monitor.md#b62b64-b69-b74-state-that-outlives-its-command).

## B31. A missing continuation line ends the batch with exit 0

When the last line ends in `\`, `getcmdline` prints "Missing continuation line" and
Expand Down Expand Up @@ -633,6 +652,10 @@ M11 (increment 7) was that `print_router_entries` keeps `brifname`, a pointer in
- For B28-B36 and the files they live in (`bridge/bridge.c`, `bridge/mdb.c`, `lib/utils.c` `getcmdline`/`makeargs`/`do_batch`, `lib/namespace.c` `netns_switch`): `git log v7.2.0..87cb3f41` holds `fde561a2` and `e11870d5`, which free leaked buffers in `getcmdline` (B31's path; its exit status is unchanged), and `552d9842` (`resolve_address`), which is unrelated. On the GitHub mirror, `lib/namespace.c`'s newest commit, `d6a1612b` (a pid fallback in `netns_get_fd`, not `netns_switch`), is in `v7.2.0`, as are `bridge/bridge.c`'s and `bridge/mdb.c`'s newest. B28-B36 are present in the newest code, and so is B37 (`bridge/bridge.c` unchanged since `v7.2.0`).
- For B38-B57 (increment 7): `git log v7.2.0..87cb3f41 -- bridge/` is still empty. On the GitHub mirror, the newest commit touching `bridge/fdb.c` or `bridge/mdb.c` is `b468824a`, which is in `v7.2.0`. B38-B56 are present in the newest code. In the helpers: `lib/json_writer.c` changed after `v7.2.0` (`c4c9a7fa`, pretty arrays and separators), but `jsonw_destroy`'s `assert(self->depth == 0)` is still there (line 122), so B51 stands. The `lib/libnetlink.c` commits after `v7.2.0` change neither the extack nor the error printing. **B57 is fixed at HEAD** by `5faf18f6`, which rewrote `ll_addr_a2n`; it is recorded for 7.2.0, the version the corpus pins.
- Upstream's `bridge/` history, read from the GitHub mirrors (`iproute2/iproute2`, `shemminger/iproute2`) because git.kernel.org refused the fetch: the newest commit is `66d16c41` "bridge: whitespace cleanup" (2026-06-28), which is already in `v7.2.0`. Every finding above is present in the newest code.
- Rechecked in increment 25 (2026-12-04) against the mirror's `main`, `d7e038f99479`, 98 commits past `v7.2.0`: in `bridge/`,
the only change is `1392041d` (2026-11-26), which fixes vni.c's "Dump ternminated", so B3 is half fixed at HEAD.
`bridge/` is otherwise identical to `v7.2.0`. See [iproute2-bridge-monitor.md](iproute2-bridge-monitor.md#head-check)
for the `lib/` commits.

## How xtcp2 handles them

Expand Down
2 changes: 2 additions & 0 deletions internal/gobridge/fdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func (r *runner) doFdb(args []string) error {
if err := r.initMap(); err != nil {
return err
}
r.timestamp = 0 // every show resets -t, so a later monitor line prints no stamps (B64)
if len(args) == 0 {
return r.fdbShow(nil)
}
Expand Down Expand Up @@ -324,6 +325,7 @@ func (r *runner) printFdb(m Msg) (int, error) {
if r.fdbDynamic && state&unix.NUD_PERMANENT != 0 {
return 0, nil
}
r.printHeaders("[NEIGH]")
o := r.o
o.openObject("")
if m.Type == unix.RTM_DELNEIGH {
Expand Down
35 changes: 23 additions & 12 deletions internal/gobridge/gobridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
// function each piece follows.
//
// Scope is the reads: link, vlan (show, -d, -s, -com, tunnelshow, global
// show with -s router ports), vni, mst, fdb (show, get) and mdb (show,
// get), alone or in a -batch (file or stdin, -force), with -netns,
// -family, -4 and -6. A batch keeps bridge's process state between
// lines, its leftover filters included (B28-B32, F2, M3). Every write
// (link set, vlan add/del/set, vlan global set, vni add/del, mst set,
// fdb add/append/replace/del/flush, mdb add/replace/del/flush) and
// monitor are refused. gobridge never writes.
// show with -s router ports), vni, mst, fdb (show, get), mdb (show, get)
// and monitor (live, or file, with -t), alone or in a -batch (file or
// stdin, -force), with -netns, -family, -4 and -6. A batch keeps bridge's
// process state between lines, its leftover filters included (B28-B32,
// F2, M3), and monitor's banner, closed socket and stamp counter
// (B62-B64). Every write (link set, vlan add/del/set, vlan global set,
// vni add/del, mst set, fdb add/append/replace/del/flush, mdb
// add/replace/del/flush) is refused. gobridge never writes.
package gobridge

import (
Expand All @@ -31,6 +32,7 @@ import (
"os"
"strconv"
"strings"
"time"

"github.com/randomizedcoder/xtcp2/pkg/cint"
)
Expand All @@ -49,8 +51,7 @@ type retCode int

func (e retCode) Error() string { return "return " + strconv.Itoa(int(e)) }

// errNotImplemented is a command gobridge does not clone (a write or
// monitor).
// errNotImplemented is a command gobridge does not clone: a write.
var errNotImplemented = errors.New("gobridge: not implemented")

// runner is bridge's globals: the output, the option counters, the
Expand Down Expand Up @@ -85,6 +86,13 @@ type runner struct {
mdbVlan int32 // mdb.c filter_vlan
vlanCurIdx int64 // vlan.c vlan_rtm_cur_ifidx; -1 for none
llInited bool // ll_init_map's initialized: one link dump a process

// monitor.c and bridge.c's monitor state, as long-lived as the rest.
timestamp int // bridge.c timestamp: -t counts, every show zeroes it (B64)
prefixBanner bool // monitor.c prefix_banner: set by all, never reset (B62)
now func() time.Time // print_timestamp's clock
mainSrc Source // the source main opened, which a live monitor subscribes on
rthClosed bool // do_monitor has closed rth (B63)
}

func (r *runner) errf(format string, a ...any) {
Expand All @@ -108,7 +116,7 @@ type config struct {

func run(cfg config, args []string, stdout, stderr io.Writer) int {
w := bufio.NewWriter(stdout)
r := &runner{o: newOut(w), stderr: stderr, vlanCurIdx: -1}
r := &runner{o: newOut(w), stderr: stderr, vlanCurIdx: -1, now: nowFunc()}
err := r.main(cfg, args)
if errors.Is(err, errSegv) {
return 139 // bridge died: its buffered stdout never reached the pipe
Expand Down Expand Up @@ -197,6 +205,7 @@ func (r *runner) main(cfg config, args []string) error {
}()
r.src = s
}
r.mainSrc = r.src
if st.batch {
// Words after -batch FILE are never looked at (B32).
return r.batch(st.batchFile, cfg.stdin, st.force)
Expand Down Expand Up @@ -238,7 +247,9 @@ func (r *runner) options(args []string, st *options) ([]string, error) {
case matches(opt, "-oneline"):
r.o.sl = "\\"
case matches(opt, "-timestamp"):
// do_link, do_vlan and do_vni reset it; mst never prints one.
// ++timestamp; do_link, do_fdb, do_mdb, do_vlan and do_vni
// zero it, so only monitor prints a stamp (B64).
r.timestamp++
case matches(opt, "-family"):
if len(args) < 2 {
return nil, r.usage()
Expand Down Expand Up @@ -317,7 +328,7 @@ func (r *runner) doCmd(obj string, args []string) error {
{"mst", r.doMst},
{"vlan", r.doVlan},
{wordVni, r.doVni},
{"monitor", r.refuse("monitor")},
{"monitor", r.doMonitor},
{helpWord, func([]string) error { return r.usage() }},
} {
if matches(obj, c.name) {
Expand Down
3 changes: 2 additions & 1 deletion internal/gobridge/imports_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ var gobridgeMayImport = map[string]string{
modulePath + "/pkg/cint": "the C integer conversions bridge's prints make (int of a u32, s64 of a u64)",
modulePath + "/internal/jsonw": "jsonw_puts, the string escaper shared with the other json_writer ports; stdlib only",
modulePath + "/internal/wsreplay": "the ws pcap replay core shared with the other read-only clones; xtcpnl only",
modulePath + "/internal/nlmon": "the monitor core shared with goip and gotc: rtnl_listen, rtnl_from_file and both stamps; xtcpnl only",
}

// gobridgeClosure is the first-party closure of gobridge's non-test files.
var gobridgeClosure = []string{
modulePath + "/cmd/gobridge", modulePath + "/internal/gobridge",
modulePath + "/pkg/xtcpnl", modulePath + "/internal/jsonw", modulePath + "/internal/wsreplay",
modulePath + "/pkg/cint",
modulePath + "/internal/nlmon", modulePath + "/pkg/cint",
// Reached through xtcpnl's congestion-name decoder; stdlib only.
modulePath + "/pkg/strpolicy",
// Reached through xtcpnl's inet_diag decoders; see internal/gordma.
Expand Down
2 changes: 2 additions & 0 deletions internal/gobridge/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ func (r *runner) doLink(args []string) error {
if err := r.initMap(); err != nil {
return err
}
r.timestamp = 0 // every show resets -t, so a later monitor line prints no stamps (B64)
if len(args) > 0 {
switch {
case matches(args[0], "set"), matches(args[0], "change"):
Expand Down Expand Up @@ -156,6 +157,7 @@ func (r *runner) printLinkinfo(m Msg) (int, error) {
if !ok || !validIfName(name) {
return -1, nil
}
r.printHeaders("[LINK]")
o := r.o
o.openObject("")
if m.Type == unix.RTM_DELLINK {
Expand Down
38 changes: 37 additions & 1 deletion internal/gobridge/mdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func (r *runner) doMdb(args []string) error {
if err := r.initMap(); err != nil {
return err
}
r.timestamp = 0 // every show resets -t, so a later monitor line prints no stamps (B64)
if len(args) == 0 {
return r.mdbShow(nil)
}
Expand Down Expand Up @@ -171,6 +172,12 @@ func (r *runner) printMdbs(m Msg) (int, error) {
if !tb.Has(xtcpnl.MdbaMdb) {
return 0, nil
}
return r.mdbEntries(tb, ifindex)
}

// mdbEntries is print_mdb_entries: every MDBA_MDB_ENTRY_INFO of every
// entry under MDBA_MDB.
func (r *runner) mdbEntries(tb xtcpnl.AttrTable, ifindex uint32) (int, error) {
var perr error
err := xtcpnl.WalkRawAttrs(tb.Bytes(xtcpnl.MdbaMdb), func(_ uint16, ent []byte) {
if perr != nil {
Expand Down Expand Up @@ -425,13 +432,42 @@ func (r *runner) printRtrs(m Msg) (int, error) {
if !tb.Has(xtcpnl.MdbaRouter) {
return 0, nil
}
return r.routerEntries(tb, ifindex, m.Type)
}

// printMdbMon is print_mdb_mon, bridge monitor's: the stamp and banner
// after the dev filter, "Deleted " once for the message, then its entries
// and router ports, whatever -d says.
func (r *runner) printMdbMon(m Msg) (int, error) {
tb, ifindex, rc, ok := r.parseMdbNlmsg(m)
if !ok {
return rc, nil
}
r.printHeaders("[MDB]")
if m.Type == unix.RTM_DELMDB {
r.o.boolean(printAny, "deleted", "Deleted ", true)
}
if tb.Has(xtcpnl.MdbaMdb) {
if rc, err := r.mdbEntries(tb, ifindex); rc < 0 || err != nil {
return rc, err
}
}
if tb.Has(xtcpnl.MdbaRouter) {
return r.routerEntries(tb, ifindex, m.Type)
}
return 0, nil
}

// routerEntries is print_router_entries: a bridge's (RTM_GETMDB) router
// ports only under -d; otherwise the first port as a line.
func (r *runner) routerEntries(tb xtcpnl.AttrTable, ifindex uint32, typ uint16) (int, error) {
br, err := r.indexToName(ifindex)
if err != nil {
return -1, err
}
router := tb.Bytes(xtcpnl.MdbaRouter)
o := r.o
if m.Type == unix.RTM_GETMDB {
if typ == unix.RTM_GETMDB {
if r.details {
if err := r.routerPorts(router, br); err != nil {
return -1, err
Expand Down
Loading