Krikri::PluginHelpers::ProcNetTcp
ProcNetTcp - pure logic for parsing /proc/net/tcp (Linux's own
kernel-exposed TCP connection table) and matching active
connections the way wait_for's state: drained needs to. No I/O -
plugins/wait_for.cr reads the actual file and does the polling.
IPv4 (/proc/net/tcp) only - real Ansible's own wait_for also reads
/proc/net/tcp6, but IPv6 host:/exclude_hosts: values are rare
in real drained: usage (almost always gating on a local service's
plain IPv4 default), and the byte-swapped-per-4-byte-word hex
encoding IPv6 addresses use there is meaningfully more involved than
IPv4's - a documented scope cut, not an oversight.
Constants
active_connection_states:'s own default, verified against real Ansible's argument_spec (not every STATE_CODES entry is necessarily in the default set, though in this case all six are).
Real Ansible's own connection-state name -> the two-hex-digit code
/proc/net/tcp itself uses, verified against
ansible/modules/wait_for.py's own get_connection_state_id
function source directly, not guessed from /proc/net/tcp's own
sparse kernel documentation.
Class methods
Counts connections matching state: drained's own criteria: an
active connection state, the target port, a local address that's
either exactly host_hex or the "any address" wildcard (a
service listening on 0.0.0.0 shows every connection's local
address as 0.0.0.0 too, not the specific interface IP - matching
real Ansible's own match_all_ips handling), and a remote
address not in exclude_hexes.
Converts a dotted IPv4 address into /proc/net/tcp's own byte-reversed hex form (verified against this machine's own real /proc/net/tcp output, not assumed: "127.0.0.1" -> "0100007F" - the octets appear reversed because the kernel writes the raw 32-bit address in host byte order, little-endian on every platform Linux's own /proc/net/tcp is read on). Returns nil for anything that isn't a plain dotted-quad (hostnames need DNS resolution, not attempted here - see the class doc above).
Parses /proc/net/tcp's own content (header line included) into Connection records - the raw hex fields, not yet matched against anything.