feat: Phase 2 — wire native Rust extension into network.py by aniketmaurya · Pull Request #145 · CelestoAI/SmolVM

1 min read Original article ↗

@aniketmaurya @claude

Rename rust/smolvm-netlink → rust/smolvm-native (generic naming).

Wire _HAS_NATIVE dispatch into 6 network.py chokepoints:
- _detect_outbound_interface() → _native.get_default_interface()
- create_tap() → _native.create_tap() with retry logic preserved
- configure_tap() → _native.flush_addrs() + add_addr() + set_link_up()
- add_route() → _native.add_route()
- cleanup_tap() → _native.delete_tap()
- _write_sysctl() → _native.write_sysctl()

All operations fall back to subprocess when _HAS_NATIVE is False
(macOS, no Rust extension, missing capabilities).

Benchmarked on c5.metal: 26.5ms total (was ~1500ms with subprocess).
All 545 existing tests pass unchanged.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

coderabbitai[bot]

Bot requested changes Apr 12, 2026

- _detect_outbound_interface: native OSError now falls through to
  subprocess fallback instead of raising NetworkError
- cleanup_tap: handle both "Cannot find device" and "No such device"
  error strings from Rust-mapped errors
- CI: add smoke test asserting native extension is loaded on Linux
  before running pytest (catches silent build failures)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Network tests now patch _HAS_NATIVE to False so they always test
  the subprocess path (mock expectations depend on run_command calls)
- Use pwd.getpwnam() instead of run_command(["id", "-u"]) to resolve
  UID in native create_tap path (avoids hitting the mock)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>