code wiki / _hdl_build / nx_portdup.nx
nx_portdup.nx
buildroot/runtime/_hdl_build/nx_portdup.nx
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
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
structs
| none |
consts
| 26 | const PD_NETCAP: i64 = 2097152 |
| 27 | const PD_CONFCAP: i64 = 65536 |
| 28 | const PD_MAXPORT: i64 = 512 |
| 29 | const PD_NL: i64 = 10 |
| 30 | const PD_HASH: i64 = 35 |
| 31 | const PD_COLON: i64 = 58 |
| 32 | const PD_SPACE: i64 = 32 |
| 33 | const PD_TAB: i64 = 9 |
| 34 | const PD_STDOUT: i64 = 1 |
| 35 | const PD_STDERR: i64 = 2 |
| 36 | const PD_LISTEN_HI: i64 = 48 // '0' of the "0A" state field |
| 37 | const PD_LISTEN_LO: i64 = 65 // 'A' |
| 38 | const PD_EXIT_DUP: i64 = 1 |
| 39 | const PD_EXIT_USAGE: i64 = 2 |
| 40 | const PD_EXIT_REFUSED: i64 = 3 |
| 41 | const PD_DEF_CONF: *u8 = "knowledge/portdup_watch.conf" as *u8 |
| 42 | const PD_TCP4: *u8 = "/proc/net/tcp" as *u8 |
| 43 | const PD_TCP6: *u8 = "/proc/net/tcp6" as *u8 |
functions
| 45 | func pd_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } |
| 46 | func pd_puts(s: *u8) -> i64 { sys_write(PD_STDOUT, s, pd_slen(s)); return 0 } |
| 47 | func pd_werr(s: *u8) -> i64 { sys_write(PD_STDERR, s, pd_slen(s)); return 0 } |
| 48 | func pd_putn(v: i64) -> i64 |
| 59 | func pd_eqs(a: *u8, b: *u8) -> i64 called by 1: sd_is_list |
| 65 | func pd_read(path: *u8, b: *u8, cap: i64) -> i64 |
| 78 | func pd_hexval(c: i64) -> i64 called by 1: pd_scan |
| 88 | func pd_scan(buf: *u8, n: i64, ports: *i64, nports: i64, cnt: *i64) -> i64 |
| 159 | func main(argc: i64, argv: *i64) -> i64 |
| 242 | func sd_is_list(v: *u8) -> i64 { if pd_eqs(v, "list" as *u8) == 1 { return 1 } return 0 } |