code wiki / _hdl_build / nx_portdup.nx

nx_portdup.nx

buildroot/runtime/_hdl_build/nx_portdup.nx

10911 B242 linesdepth 2pulls 2 transitivereach 0 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

about

nx_portdup.nx -- detect the WRONG-ANSWER MACHINE: two daemons LISTENING on one port (seq1785450532). WHAT IT CATCHES, and why nothing else did. On 2026-07-30 both nx_mgmt_api AND nx_opaque_login were LISTENING on 127.0.0.1:18098 at the same time. The kernel hands each connection to whichever accepts first, so a VALID control-plane route answered `404 no such route` on some requests and worked on others. Every component was individually healthy -- correct binary, correct source, listener present, health OK -- so the fault was filed for MONTHS as a "transport flake" and blamed on the edge. It was two listeners. The banked fd-scrub note predicted the successor would fail to BIND (EADDRINUSE); the reality is worse, because BOTH hold the socket and there is NO ERROR ANYWHERE to find. WHY A DEDICATED TOOTH: liveness ("is it up?") and health ("does it answer?") are both TRUE during this fault -- the squatter answers, just wrongly. Only the SHAPE of the listen table shows it, and nothing in the ecosystem looked at that shape. FALSE-POSITIVE DISCIPLINE (this is why it is a watch list, not a sweep of every port): DSM legitimately runs SO_REUSEPORT worker pools -- :443, :5000, :5001 each show EIGHT holders by design, and the sovereign edge deliberately co-binds :443 alongside DSM's nginx (a known, accepted arrangement). Flagging those would train the operator to ignore this tooth, so it reports ONLY on ports declared as single-owner in knowledge/portdup_watch.conf. A port not on the list is never judged. nx_portdup check [watchconf] -- exit 1 if any WATCHED port has more than one LISTEN holder nx_portdup list [watchconf] -- holder count for every watched port (no verdict) license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0

dependencies 1 imports · 0 importers

nx_syscalls.nx nx_portdup.nx

imports: nx_syscalls.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main pd_werr sys_write pd_slen sys_exit sys_mmap pd_read sys_openat_rd sys_read sys_close pd_scan pd_hexval sd_is_list pd_eqs pd_puts sys_write ↻ pd_slen ↻ pd_putn sys_mmap ↻ sys_write ↻

structs

none

consts

26const PD_NETCAP: i64 = 2097152
27const PD_CONFCAP: i64 = 65536
28const PD_MAXPORT: i64 = 512
29const PD_NL: i64 = 10
30const PD_HASH: i64 = 35
31const PD_COLON: i64 = 58
32const PD_SPACE: i64 = 32
33const PD_TAB: i64 = 9
34const PD_STDOUT: i64 = 1
35const PD_STDERR: i64 = 2
36const PD_LISTEN_HI: i64 = 48 // '0' of the "0A" state field
37const PD_LISTEN_LO: i64 = 65 // 'A'
38const PD_EXIT_DUP: i64 = 1
39const PD_EXIT_USAGE: i64 = 2
40const PD_EXIT_REFUSED: i64 = 3
41const PD_DEF_CONF: *u8 = "knowledge/portdup_watch.conf" as *u8
42const PD_TCP4: *u8 = "/proc/net/tcp" as *u8
43const PD_TCP6: *u8 = "/proc/net/tcp6" as *u8

functions

45func pd_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
called by 2: pd_putspd_werr
46func pd_puts(s: *u8) -> i64 { sys_write(PD_STDOUT, s, pd_slen(s)); return 0 }
called by 1: main calls 2: sys_writepd_slen
47func pd_werr(s: *u8) -> i64 { sys_write(PD_STDERR, s, pd_slen(s)); return 0 }
called by 1: main calls 2: sys_writepd_slen
48func pd_putn(v: i64) -> i64
called by 1: main calls 2: sys_mmapsys_write
59func pd_eqs(a: *u8, b: *u8) -> i64
called by 1: sd_is_list
65func pd_read(path: *u8, b: *u8, cap: i64) -> i64
called by 1: main calls 3: sys_openat_rdsys_readsys_close
78func pd_hexval(c: i64) -> i64
called by 1: pd_scan
88func pd_scan(buf: *u8, n: i64, ports: *i64, nports: i64, cnt: *i64) -> i64
called by 1: main calls 1: pd_hexval
159func main(argc: i64, argv: *i64) -> i64
242func sd_is_list(v: *u8) -> i64 { if pd_eqs(v, "list" as *u8) == 1 { return 1 } return 0 }
called by 1: main calls 1: pd_eqs