morpheus_network::state::dhcp

Enum DhcpState

Source
pub enum DhcpState {
    Init,
    Discovering {
        start_tsc: TscTimestamp,
    },
    Bound {
        config: DhcpConfig,
        bound_tsc: TscTimestamp,
    },
    Failed {
        error: DhcpError,
    },
}
Expand description

DHCP client state machine.

Tracks DHCP discovery progress and wraps smoltcp’s DHCP socket.

Variants§

§

Init

Initial state - not started

§

Discovering

DHCP discovery in progress

Fields

§start_tsc: TscTimestamp

When discovery started

§

Bound

IP address obtained

Fields

§config: DhcpConfig

DHCP configuration

§bound_tsc: TscTimestamp

When bound

§

Failed

DHCP failed

Fields

§error: DhcpError

Error details

Implementations§

Source§

impl DhcpState

Source

pub fn new() -> Self

Create new DHCP state machine in init state.

Source

pub fn start(&mut self, now_tsc: u64)

Start DHCP discovery.

§Arguments
  • now_tsc: Current TSC timestamp
Source

pub fn step( &mut self, dhcp_config: Option<DhcpConfig>, now_tsc: u64, timeout_ticks: u64, ) -> StepResult

Step the state machine.

§Arguments
  • dhcp_config: Current DHCP config from smoltcp (None if not yet configured)
  • now_tsc: Current TSC value
  • timeout_ticks: DHCP timeout in TSC ticks
§Returns
  • Pending: Still discovering
  • Done: Bound, call config() to get configuration
  • Timeout: Discovery timed out
  • Failed: Discovery failed
Source

pub fn config(&self) -> Option<&DhcpConfig>

Get DHCP configuration (if bound).

Source

pub fn ip(&self) -> Option<Ipv4Addr>

Get assigned IP address (if bound).

Source

pub fn gateway(&self) -> Option<Ipv4Addr>

Get gateway (if bound and available).

Source

pub fn dns(&self) -> Option<Ipv4Addr>

Get DNS server (if bound and available).

Source

pub fn error(&self) -> Option<DhcpError>

Get error (if failed).

Source

pub fn is_terminal(&self) -> bool

Check if DHCP is complete (bound or failed).

Source

pub fn is_bound(&self) -> bool

Check if successfully bound.

Source

pub fn is_discovering(&self) -> bool

Check if still discovering.

Trait Implementations§

Source§

impl Debug for DhcpState

Source§

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

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

impl Default for DhcpState

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.