Skip to content

nmap C→Rust — M1: sys::net (async TCP connect + DNS via tokio) - #6

Merged
kj299 merged 2 commits into
masterfrom
claude/m1-net
Jul 9, 2026
Merged

kj299 merged 2 commits into
masterfrom
claude/m1-net

Conversation

@kj299

@kj299 kj299 commented Jul 9, 2026

Copy link
Copy Markdown
Owner

What this is

Milestone 1 module sys::net — the first sys-crate module and the first with real async I/O. Provides the connect-scan primitives the (pure) scan engine drives. Built on tokio's safe socket API, so sys still holds zero unsafe for the MVP.

Uses the recommended approach: tokio + system-resolver DNS (fewest new dependencies; both pre-approved in the plan). Swap to hickory-resolver later if desired.

Changes

  • tcp_connect(addr, timeout) — one connect probe → ConnectResult, mapped as nmap's scan_engine_connect.cc does: handshake completes → open (syn-ack); ConnectionRefused → closed (conn-refused); timeout or any other error → filtered (no-response). The I/O is split from a pure verdict helper so every branch is unit-tested deterministically (no network-timing flakiness).
  • resolve_host(host) — forward DNS via the system resolver (tokio's getaddrinfo pool), order-preserving + de-duplicated; IP literals resolve to themselves.
  • Replaces the skeleton OwnedResource demo (the RAII/FFI patterns return with Npcap in M4). tokio added with a minimal feature set.

Verified

  • fmt + clippy(-D warnings) + 5 sys tests (open/closed on loopback, resolve localhost/IP-literal, all verdict branches) + 41 core tests + unsafe-audit (0) — green.
  • supply-chain (cargo audit + cargo deny) clean with tokio + its deps (mio, socket2, libc): advisories/bans/licenses/sources all ok.

Note on test design

A real-network timeout/unreachable test is intentionally omitted — connect timing is environment-dependent and this sandbox even completes connects to non-routable addresses. The timeout→filtered branch is covered deterministically via the pure verdict helper.

🤖 Generated with Claude Code


Generated by Claude Code

claude added 2 commits July 9, 2026 20:16
The sys-side I/O primitives the connect scan drives, on tokio's safe socket API
(no unsafe — unsafe-audit stays 0 for the crate):
- tcp_connect(addr, timeout): handshake -> open (syn-ack), refused -> closed
  (conn-refused), timeout/other -> filtered (no-response), matching
  scan_engine_connect.cc's interpretation. I/O split from a pure `verdict`
  helper so every branch is unit-tested without network-timing flakiness.
- resolve_host: forward DNS via the system resolver (tokio getaddrinfo pool),
  order-preserving + de-duplicated. IP literals resolve to themselves.
- Replaces the skeleton OwnedResource demo; RAII/FFI patterns return in M4
  (Npcap). tokio added with a minimal feature set; supply-chain (deny/audit)
  clean.

Gates: fmt + clippy(-D) + 5 sys tests (open/closed on loopback, resolve,
verdict branches) + 41 core tests + unsafe-audit 0. progress: net -> ported.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01JfEzHqD7a7TKDuUs5GwZ2w
The miri gate failed on the #[tokio::test] network tests: miri interprets code
and cannot execute real socket syscalls (bind/connect/epoll), so it aborts in
the syscall macro. Mark the four I/O tests #[cfg_attr(miri, ignore)] so miri
skips them while still checking the pure `verdict` logic — matching the plan's
"miri over pure logic; ASan/UBSan for the sys layer" split. Normal `cargo test`
still runs all five (the cfg only applies under miri).

Retrospective candidate: async/real-I/O tests need #[cfg_attr(miri, ignore)].

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01JfEzHqD7a7TKDuUs5GwZ2w
@kj299
kj299 marked this pull request as ready for review July 9, 2026 20:39
@kj299
kj299 merged commit dcb2c71 into master Jul 9, 2026
12 checks passed
kj299 added a commit that referenced this pull request Jul 10, 2026
The compounding step for Milestone 1 — patch PLAYBOOK/harnesses and append
LESSONS.md with what the nmap MVP taught the kit. Each edit names the failure it
prevents next time.

LESSONS #6 — scan_c_flaws read only .c/.h and reported nmap's ~9.4k LOC of C++
(.cc) as "0 flaws". Extension set widened to cover C++ (fix already in tree from
PR #2); now pinned with a self-test that iter_c_files yields .cc/.cpp/.hpp and
ignores non-source. Phase 0: confirm the scanner reads the target's languages
before believing a low count.

LESSONS #7 — diff_run.py is case-granular, so an MVP that intentionally renders a
subset of C output can't be diffed raw (every case diverges) or ledgered (the
whole case goes blind). Documented the canonical-projection pattern: wrap both
sides in a filter that emits only the semantic result, canonicalizing both
representations so real regressions still break the match. Phase 4 gate 2.

LESSONS #8 — Miri can't execute real I/O (tokio connect aborts under Miri).
Split the pure decision (verdict) from the syscall and cfg(miri)-ignore the I/O
tests, so "Miri can't run this" never becomes "no Miri coverage." Phase 4 gate 4.

LESSONS #9 — the linear six-gate model implies every module needs a fuzz tick,
but fuzzing is threat-model-scoped (parsers, not renderers/models). And
`cargo fuzz run <t> seeds/<t>` writes discovered inputs back into the seeds dir.
gen_fuzz_target.sh guidance now shows corpus/<t> seeds/<t> (writable, read-only)
and scopes the gate. Phase 4 gate 3.

Meta: 3 of 4 are the same shape as winlsof #2-#4 — a control that inspects less
than its green checkmark implies; the defense (retrospective step 0: run every
harness against the real target and eyeball what it inspected) held again.

check-kit: all harness self-tests + skills integrity green.


Claude-Session: https://claude.ai/code/session_01JfEzHqD7a7TKDuUs5GwZ2w

Co-authored-by: Claude <[email protected]>
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.

2 participants