network
network
¶
Rootless networking helpers.
The slirp4netns gateway and resolv.conf parsing live here so
nothing in the firewall path has to reach into the broader podman_info
package just to derive a host address or DNS server.
slirp4netns_gateway(cidr=None)
¶
Compute the slirp4netns gateway address (CIDR base + 2).
Reads containers.conf for a cidr= override when cidr is None.
Falls back to the default CIDR on malformed input.
Source code in src/terok_shield/podman_info/network.py
host_loopback_addresses(network_mode, gateways=())
¶
The addresses through which a container in network_mode reaches the host's own loopback.
host.containers.internal names them. pasta maps the host's
127.0.0.1 to PASTA_HOST_LOOPBACK_MAP, a constant. slirp4netns,
launched with allow_host_loopback, forwards its gateways there —
the ones the container launched with, as its bundle records them, never
a containers.conf read now: a cidr= changed since moves no
running container's gateway. The shield opens a host service through a
+localhost:PORT grant in the preamble, one port at a time, so any
wider path to these addresses — a break-glass override, a promotion
offering one — would open every port the host listens on locally. An
unrecognised mode has none.
A set, because every caller asks whether an address is one of them or lies around one: how many there are depends on the mode, and no position among them means anything.
Source code in src/terok_shield/podman_info/network.py
parse_slirp4netns_cidr()
¶
Read the slirp4netns CIDR from containers.conf, or return the default.
User config (XDG) is checked first in rootless mode, then system paths.
When running as root, user config is skipped to prevent untrusted
XDG_CONFIG_HOME from influencing firewall rules.
Source code in src/terok_shield/podman_info/network.py
parse_resolv_conf(text)
¶
Extract the first nameserver address from resolv.conf content.
Returns an empty string if no valid nameserver line is found.