pub enum BindSpec {
Addr(SocketAddr),
Interface {
interface: String,
port: u16,
},
Role {
role: BindRole,
port: u16,
},
}Expand description
Where a listener binds: a literal socket address, or an interface whose address is learned at boot.
Variants§
Addr(SocketAddr)
127.0.0.1:50051, 0.0.0.0:50051, [::]:50051 — verbatim.
Interface
eth1:50051 — the IPv4 address interface holds when the listener
binds. Refused by name if it holds none.
Role
utility:50051 — the NIC that plays role on THIS box (the lean estate, A19 row 17):
the medium is the same for a box with two NICs and a box laid behind its front with its
utility NIC alone, so it names the role and the box names the NIC
(BindSpec::for_this_box). Never bound as it is.
Implementations§
Source§impl BindSpec
impl BindSpec
Sourcepub fn is_loopback_addr(&self) -> bool
pub fn is_loopback_addr(&self) -> bool
Is this an address, and is it a loopback one? An interface spec is neither — its address is not known yet, and answering “no” for it would be a guess dressed as a fact.
Sourcepub fn for_this_box(
self,
declared: &[String],
exists: impl Fn(&str) -> bool,
) -> Result<BindSpec, String>
pub fn for_this_box( self, declared: &[String], exists: impl Fn(&str) -> bool, ) -> Result<BindSpec, String>
A role becomes this box’s NIC (utility_interface over the interfaces the net
spec declared and the ones the box has); every other spelling is returned unchanged.
Called once, before anything binds.
Sourcepub fn resolve_with<E: Display>(
&self,
lookup: impl FnOnce(&str) -> Result<Option<Ipv4Addr>, E>,
) -> Result<Resolved, String>
pub fn resolve_with<E: Display>( &self, lookup: impl FnOnce(&str) -> Result<Option<Ipv4Addr>, E>, ) -> Result<Resolved, String>
Resolve to the address a listener can actually bind.
lookup answers “what IPv4 does this interface hold” — injected rather
than called directly so this function, which owns every sentence it
produces, is testable without a network stack. gunnar-server passes
pid1::interface_ipv4.
Three outcomes, and the grading is the same law bring_up_network
already applies to GUNNAR_NET — because it is the same distinction:
- an address, or an interface holding one —
Resolved::Bound; - the interface EXISTS and holds no IPv4 —
Resolved::NoAddress. The DECLARATION did not lie; the world declined to answer, exactly like a DHCP timeout.Ok, and the caller decides. On the appliance that is “serve git, refuse to serve a control plane, and say so”, because killing PID 1 there is a reboot loop that takes the git listener with it — and a box in a reboot loop is not more secure than a box with no control plane, it is only less reachable. - the interface is not there at all, or the kernel refused the question
—
Err. The declaration named a NIC this machine does not have, which is a lie a medium told, and it stops the boot the way every other lying declaration does.
No arm anywhere returns a wildcard. That is the whole point.
Trait Implementations§
impl Eq for BindSpec
Source§impl From<SocketAddr> for BindSpec
impl From<SocketAddr> for BindSpec
Source§fn from(addr: SocketAddr) -> Self
fn from(addr: SocketAddr) -> Self
Source§impl FromStr for BindSpec
impl FromStr for BindSpec
Source§fn from_str(s: &str) -> Result<Self, Self::Err>
fn from_str(s: &str) -> Result<Self, Self::Err>
<addr>:<port> or <iface>:<port>.
The address form is tried FIRST and verbatim, so every value that
parsed before this type existed still parses to exactly what it used to
— [::1]:50051 included, whose brackets contain the colons that would
otherwise make the split ambiguous.