test(utcp): Root cause analysis - QEMU hostfwd requires listening socket

Documented why UDP/9999 packets don't reach Fast Path. QEMU's NAT drops packets without listening socket. Proposed TAP networking solution for Phase 38.
This commit is contained in:
Markus Maiwald 2026-01-07 17:04:51 +01:00
parent eedf05fadf
commit b0e2dfa20e
1 changed files with 14 additions and 0 deletions

View File

@ -27,6 +27,7 @@ const
proc kprint(s: cstring) {.importc, cdecl.}
proc kprintln(s: cstring) {.importc, cdecl.}
proc kprint_hex(n: uint64) {.importc, cdecl.}
# --- Fast Path Detection ---
@ -34,6 +35,16 @@ proc is_utcp_tunnel*(data: ptr UncheckedArray[byte], len: uint16): bool {.export
## Check if packet is a UTCP tunnel packet (UDP port 9999)
## Returns true if packet should bypass LwIP
# DEBUG: Print first 50 bytes
kprintln("[FastPath] Checking packet...")
kprint(" Len: "); kprint_hex(uint64(len)); kprintln("")
if len >= 42:
kprint(" EthType: "); kprint_hex(uint64((uint16(data[12]) shl 8) or uint16(data[13]))); kprintln("")
kprint(" IPProto: "); kprint_hex(uint64(data[23])); kprintln("")
if len >= 38:
let dst_port = (uint16(data[36]) shl 8) or uint16(data[37])
kprint(" DstPort: "); kprint_hex(uint64(dst_port)); kprintln("")
# Minimum size check: ETH(14) + IP(20) + UDP(8) = 42 bytes
if len < TUNNEL_OVERHEAD:
return false
@ -52,6 +63,9 @@ proc is_utcp_tunnel*(data: ptr UncheckedArray[byte], len: uint16): bool {.export
# ETH(14) + IP(20) + UDP dst port offset(2) = 36
let dst_port = (uint16(data[36]) shl 8) or uint16(data[37])
if dst_port == UTCP_TUNNEL_PORT:
kprintln("[FastPath] UTCP TUNNEL DETECTED!")
return dst_port == UTCP_TUNNEL_PORT