Skip to content

WIP: fix(netopen): parse/resolve layer + single-open probes (#1894/#1895/#1896/#1897/#1950/#1967) - #2012

Merged
caomengxuan666 merged 8 commits into
masterfrom
fix/netopen-family
Oct 29, 2026
Merged

caomengxuan666 merged 8 commits into
masterfrom
fix/netopen-family

Conversation

@caomengxuan666

@caomengxuan666 caomengxuan666 commented Oct 29, 2026 •

Copy link
Copy Markdown
Member

netopen 一族五单(解析四单 + 双开两面)。逐单 commit + Fixes 行齐备;完整账本见工区 REPORT(~/workspace/fix-netopen/REPORT.md)。

逐单与实测

门账

  • CI(合并头 91a0dc6):Rust tests(Linux/macOS)、goldens、cross-target、ledger tripwire 全 pass,mergeable=MERGEABLE。红二:Shell functionality = rustup 下载超时(基础设施);niu-canary 的 ledger-coverage 步在 master 与全部同期分支同红(全仓过渡态),旧红步 ledger-copies 已转绿。
  • regression 本地直跑 193/0/1 与 CI 基线逐名一致。diffcorpus:306 例无 net 用例、败集不因本簇变化(未重跑,理由见 REPORT)。

Fixes #1894
Fixes #1895
Fixes #1896
Fixes #1897
Fixes #1950
Fixes #1967

GNU netopen resolves the service word through getservbyname /
getaddrinfo (lib/sh/netopen.c:135 getservbyname), whose lookup walks
the services entry's alias column as well as its primary name.
resolve_net_service_port only matched the primary name, so
/dev/tcp/127.0.0.1/www failed with the Servname diagnostic even
though www is http's alias in both /etc/services and the Windows
drivers\etc\services file.

The parser now treats the fields after port/proto as aliases and
matches the service word against them too.

Regression pin: issue_1896_service_alias_resolves_like_getservbyname
(oracle-verified against GNU bash 5.3.20: the alias connects; with
nothing listening it surfaces as Connection refused, not Servname).

Fixes #1896
GNU netopen (lib/sh/netopen.c:282 netopen, :291 strchr) splits the
target at the FIRST slash: the host is the segment before it and the
service is the whole remainder, slashes included. connect_net_stream
split at the LAST slash (rsplit_once), so /dev/tcp/a/b/80 resolved
host a/b with service 80 instead of host a with service b/80 — the
failure was attributed to the wrong component and the service
diagnostic named the wrong word.

Oracle-verified against GNU bash 5.3.20 (TCP and UDP forms):
b/80: Servname not supported for ai_socktype, then
/dev/tcp/a/b/80: Invalid argument, rc=1.

Regression pin: issue_1895_multi_slash_target_splits_at_first_slash.

Fixes #1895
GNU _netopen6 (lib/sh/netopen.c:205) runs getaddrinfo first; on
failure it emits internal_error '{host}: Name or service not known'
(glibc's EAI_NONAME text) BEFORE the caller's redirection_error
line and fails with EINVAL (netopen.c:227), so the user sees two
lines. connect_net_stream instead handed the resolver's std error
to the caller, producing a single '{target}: {std text}' line.

Resolve the host up front (the result set also feeds the connect,
which now tries each resolved address in order like _netopen6's
res loop). A resolution failure — including the empty host, which
getaddrinfo rejects with EAI_NONAME — prints the GNU pre-line and
returns EINVAL. Service resolution still runs first, matching
glibc's precedence when both words are bad (oracle-verified).

Regression pin:
issue_1894_unresolvable_host_reports_name_line_then_invalid_argument
(300-char host name: deterministic local EAI_NONAME, no DNS).

Fixes #1894
_netopen6 (lib/sh/netopen.c:205) creates the socket from the
getaddrinfo result and connects that address, so the local bind of
a UDP netopen inherits the RESOLVED family. connect_net_stream
instead guessed the family from the host spelling (contains ':')
and pre-bound 0.0.0.0:0 for every name without a colon; for a
v6-only host name the subsequent connect to the IPv6 target then
failed with a family mismatch.

Bind [::]:0 or 0.0.0.0:0 by the first resolved address's family
and connect that address.

Regression pin: issue_1897_udp_bind_family_follows_the_resolved_address
(environment-gated per the issue seed: stands down where no v6-only
name / IPv6 loopback exists rather than passing on v4 evidence;
oracle-verified against GNU bash 5.3.20 where both exist).

Fixes #1897
GNU opens a net redirect exactly once — redir.c do_redirections
binds the descriptor the command then reads (the setup-side walk
in builtin_redirects.rs models that open for in-process funnels).
For a /dev/tcp input target the probe walk
(apply_redirect_setup_side_effects -> probe_input_redirect ->
open_input_redirect_impl consume=false) CONNECTED through the
classified ladder and dropped the stream unread: the peer's
greeting was eaten by the phantom connection and the real reader
(the emulated cat body, or the spawned child's setup open) got a
second, reset connection. Against a single-accept server
'cat < /dev/tcp/...' printed nothing and exited 0.

Mirror the rubash#1820 FIFO carve-out at the same layer: a probe
of a net target validates by resolution only and returns the
inert /dev/null stand-in every probe caller drops. The parse /
service / host-resolution failures (and their diagnostic
pre-lines) are shared with the connect path by extracting
resolve_net_target + validate_net_redirect_target out of
connect_net_stream; a refused connection now surfaces at the
bind's one open with the same 'connect: Connection refused'
diagnostic GNU's single open produces.

Regression pins (counting greeting server, self-contained
loopback): issue_1950_cat_input_redirect_opens_exactly_one_connection,
issue_1950_comsub_cat_opens_exactly_one_connection — the peer must
see exactly one connection and the reader must get the greeting.

Fixes #1950
…nnect

Output twin of the input-side fix. ': > /dev/tcp/...' connected
TWICE (setup walk probe create + the no-output pass's mirror
create, both dropped) and 'echo hi > /dev/tcp/...' connected twice
with the payload lost (the ordered-output walk's validation
create drops its File — only the Path is kept in the state — and
the flush open connects again). GNU's do_redirections
(redir.c do_redirection_internal) opens once.

Every validation-only open point on the output side now resolves
instead of connecting, mirroring the #1820 FIFO carve-outs at the
same sites:
- probe_output_redirect / probe_output_redirect_append (setup
  walk arms, compound scope probes): net target -> validate.
- create_redirect_output_prepared (compound prepare phase): net
  target -> validate + inert /dev/null stand-in; the bind phase
  (open_compound_output_redirects -> set_fd_output_file) performs
  the one connect.
- apply_ordered_output_redirects (buffered-builtin route): net
  target takes the validation arm next to the #1868 FIFO one; the
  flush open is the single connect.
- redirect_setup_open_error's ReadWrite arm: a net target no
  longer takes the filesystem probe (which created a file at the
  mapped pseudo-path); resolution only — the funnel's
  open_net_redirect bind connects once.

The mirror create in apply_no_output_builtin_redirects and the
persistent/scoped binds are unchanged: those ARE the one open.

Regression pins (counting greeting server):
issue_1967_null_command_output_redirect_opens_exactly_one_connection,
issue_1967_echo_output_redirect_opens_one_connection_and_delivers
(exactly one connection, and 'hi\n' arrives on it).

Fixes #1967
@caomengxuan666 caomengxuan666 changed the title WIP: fix(netopen): parse/resolve layer (first-slash split, service aliases, host diagnostic, UDP family) + single-open faces WIP: fix(netopen): parse/resolve layer + single-open probes (#1894/#1895/#1896/#1897/#1950/#1967) Oct 29, 2026
Follow-up to the output-side probe fix, found by the counting
pins on the first local run: ': > /dev/tcp/...' and the input
faces were at one connection, but 'echo hi > /dev/tcp/...' still
failed — rc=1, 'echo: write error: No such file or directory',
zero connections. The buffered-output flush records the target
as OutputTarget::Path and both flush arms (OutputFdState::
write_to_fd, write_stage_stream_to_target) opened it with the
filesystem append-open on the mapped pseudo-path, which is not a
file: the walk validated, and the flush then failed ENOENT
without ever connecting (the same failure took the echo-shaped
rubash#1897 pin down with it — the connect fix itself was fine).

Both flush Path arms now dispatch a net target to
open_net_redirect — the flush open is the redirect's ONE open,
consistent with the validation-only walks — and write_to_fd's
empty-output pairing block gains the net twin of its FIFO
pairing (GNU's open happens even when nothing is written).

Fixes #1967
@caomengxuan666
caomengxuan666 marked this pull request as ready for review October 29, 2026 04:21
@caomengxuan666
caomengxuan666 merged commit 4e68f5b into master Oct 29, 2026
14 of 16 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/netopen-family branch October 30, 2026 01:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment