Skip to main content

BindSpec

Enum BindSpec 

Source
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.

Fields

§interface: String

The interface name, e.g. eth1.

§port: u16

The port to bind on it.

§

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.

Fields

§role: BindRole

The role, e.g. BindRole::Utility.

§port: u16

The port to bind on its NIC.

Implementations§

Source§

impl BindSpec

Source

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.

Source

pub fn port(&self) -> u16

The port, whichever spelling this is.

Source

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.

Source

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§

Source§

impl Clone for BindSpec

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BindSpec

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for BindSpec

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for BindSpec

Source§

impl From<SocketAddr> for BindSpec

Source§

fn from(addr: SocketAddr) -> Self

Converts to this type from the input type.
Source§

impl FromStr for BindSpec

Source§

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.

Source§

type Err = String

The associated error which can be returned from parsing.
Source§

impl PartialEq for BindSpec

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for BindSpec

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more