nx_pages_vhost.nx
buildroot/runtime/nx_pages_vhost.nx
about
nx_pages_vhost.nx -- multi-virtual-host routing primitive. D1.1 of
the NISHI_DEPLOY_ROADMAP -- the first composition piece that lets one
nx_pages_daemon serve multiple domains from one ELF. Replaces the
equivalent of nginx's `server { server_name X; root Y; }` blocks.
Design contract:
- Caller pre-allocates an NxVHostTable with N vhosts.
- Each NxVHost binds a domain name to a filesystem doc root.
- nx_vhost_dispatch(req_buf, req, table, ...) reads the parsed
request's Host header and returns the matched vhost's doc-root
range. Case-insensitive match per RFC 7230 ยง5.4.
- Wildcard fallback supported via a designated catch-all vhost
(used for the default-server-block equivalent).
Per [[NISHI_DEPLOY_ROADMAP]] D1.1. Composes nx_http.nx http_get_header.
nx_safety_envelope:
intended_use: "Multi-vhost HTTP routing for nx_pages_daemon"
sil_target: SIL1
asil_target: QM
evidence: [case_insensitive_per_RFC_7230_section_5.4,
bounded_table_no_recursion,
sealed_enum_verdict]
hazard_register: [bug-vhost-injection-via-Host-header-CR-LF,
bug-default-vhost-shadows-explicit-match]
verdict: NOT_YET_EVALUATED
dependencies 3 imports · 6 importers
imports: nx_syscalls.nxnx_tier.nxnx_http.nx
imported by: nx_pages_config.nxnx_pages_config_test.nxnx_pages_daemon.nxnx_pages_https_daemon.nxnx_pages_vhost_debug.nxnx_pages_vhost_test.nx
structs
| 54 | struct NxVHostTable |
consts
| 33 | const NX_VHOST_OK: nx_int = 0 // matched explicit vhost |
| 34 | const NX_VHOST_FALLBACK: nx_int = 1 // matched catch-all |
| 35 | const NX_VHOST_NO_MATCH: nx_int = 2 // no vhost AND no fallback |
| 36 | const NX_VHOST_NO_HOST_HDR: nx_int = 3 // request had no Host: header |
| 37 | const NX_VHOST_BAD_ARG: nx_int = 4 // null table / negative count |
| 45 | const NX_VHOST_STRIDE: i64 = 4 |
| 46 | const NX_VHOST_HNAME_OFF: i64 = 0 |
| 47 | const NX_VHOST_HNAME_LEN: i64 = 1 |
| 48 | const NX_VHOST_ROOT_OFF: i64 = 2 |
| 49 | const NX_VHOST_ROOT_LEN: i64 = 3 |
functions
| 65 | func _vh_lc(b: i64) -> i64 called by 1: _vh_eq_ci |
| 72 | func _vh_eq_ci(a: *u8, a_off: i64, a_len: i64, |
| 89 | func _vh_strip_port(buf: *u8, off: i64, len: i64) -> i64 called by 1: nx_vhost_dispatch |
| 111 | func nx_vhost_table_init(t: *NxVHostTable, arena: *u8, arena_len: i64, |
| 125 | func _vh_arena_push_cstr(t: *NxVHostTable, cursor: *i64, s: *u8) -> i64 called by 1: nx_vhost_add |
| 142 | func nx_vhost_add(t: *NxVHostTable, cursor: *i64, |
| 163 | func nx_vhost_set_fallback(t: *NxVHostTable, idx: i64) -> i64 |
| 176 | func nx_vhost_dispatch(req_buf: *u8, req: *HttpRequest, |