Skip to content

Light Cleanup [Spring Cleaning 2/N]#720

Open
taspelund wants to merge 10 commits intomainfrom
trey/light-cleanup
Open

Light Cleanup [Spring Cleaning 2/N]#720
taspelund wants to merge 10 commits intomainfrom
trey/light-cleanup

Conversation

@taspelund
Copy link
Copy Markdown
Contributor

@taspelund taspelund commented Apr 25, 2026

Second round of splits from #648

Minor changes:

  • set TCP_NODELAY on BGP connections
  • LoopbackIpManager bug fixes
  • EPIPE handling in mgadm/ddmadm
  • Fix a small conversion bug in BGP RHAI policy
  • Cleanup a couple instances of shared state in BGP tests (so things will work under cargo test in addition to cargo nextest)

See each commit for specifics

Three tests failed under cargo test (thread-per-test) but passed
under cargo nextest (process-per-test) due to shared global state
in the channel-based test network simulation:

1. unnumbered_peering_helper() leaked dispatcher threads by not
   returning dispatcher handles to callers. Leaked threads would
   periodically re-bind to addresses in the global NET endpoint
   map, stealing entries from concurrently running tests.

2. The simulated Network had no unbind mechanism, so endpoint
   entries persisted after a Listener was dropped, leaving stale
   state for subsequent tests.

3. Several tests used hardcoded scope_ids (2, 3) for link-local
   addresses, causing collisions in the shared NET endpoint map
   when tests ran as concurrent threads in the same process.

Fix by:
- Adding Network::unbind() and Listener::Drop to clean up NET
  endpoint entries when a listener goes out of scope
- Returning dispatchers from unnumbered_peering_helper() so all
  callers can shut them down during test cleanup
- Switching hardcoded scope_ids to next_scope_id() for unique
  per-test addresses, matching the newer test infrastructure
Fix PolicyAction::from_str() to convert "deny" into Self::Deny instead
of Self::Allow.
@taspelund taspelund requested a review from rcgoodfellow April 25, 2026 00:01
@taspelund taspelund self-assigned this Apr 25, 2026
@taspelund taspelund added Bug testing bgp Border Gateway Protocol mgd Maghemite daemon rust Pull requests that update rust code labels Apr 25, 2026
When stdout is piped into a program that closes early (e.g.
`mgadm bgp status neighbors 47 | head`), Rust's println!
macro panics on the resulting EPIPE, causing a SIGABRT.

Add println_nopipe!/print_nopipe!/eprintln_nopipe!/eprint_nopipe!
macros to mg-common that silently exit on BrokenPipe instead of
panicking. Use them throughout mgadm's print calls. Also catch
EPIPE errors propagated via ? from TabWriter writeln/flush paths
at both mgadm and ddmadm main() boundaries.

Add clippy disallowed_macros entries for std::println, std::print,
std::eprintln, and std::eprint in clippy.toml so future code is
steered to the wrappers. Migrate the remaining workspace callsites
(xtask, mg-admin-client, mg-ddm-verify, plus test scaffolding in
bgp, rdb, mgd, bfd, and mg-tests) to the wrappers.

Fixes #567

Signed-off-by: Trey Aspelund <trey@oxidecomputer.com>
We skipped both 127.0.0.1 and ::1 during install, but were not skipping
::1 during uninstall. Let's make that symmetric.
Move from using an installed bool to using a u32 to track the number of
intra-process users of an IP, which prevents early uninstalls.
Move loopback-skipping logic (127.0.0.1 / ::1) into a dedicated function
and make a few methods private that don't need to be public.
If an installation fails for one of the requested IPs, rollback the IPs.
Removes an unused uninstall() method.
@taspelund taspelund force-pushed the trey/light-cleanup branch from 9d709e0 to 49a9983 Compare April 25, 2026 00:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bgp Border Gateway Protocol Bug mgd Maghemite daemon rust Pull requests that update rust code testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant