Skip to main content

IfaceMap

Struct IfaceMap 

Source
pub struct IfaceMap { /* private fields */ }
Expand description

Refreshable cache of IPv4 interfaces.

Cheap to clone (Arc-shared internal state). Spawned tasks share a single map and refresh on demand via IfaceMap::refresh_if_stale.

Implementations§

Source§

impl IfaceMap

Source

pub fn new() -> Result<Self>

Build a fresh map by enumerating interfaces now.

Fails when the OS enumeration fails, so an empty map means exactly one thing — the host reported no IPv4 interfaces. It used to mean that or that getifaddrs had errored, and every caller that asks “is there an external NIC here?” read the two as the same answer.

Source

pub fn refresh(&self) -> Result<()>

Force-refresh the snapshot.

The single writer of Inner.ifaces, and it writes only what a successful enumeration returned: on failure the previous snapshot stands rather than being replaced by an empty one, so a transient getifaddrs error cannot blank the fanout list under a running sender.

Source

pub fn refresh_if_stale(&self, max_age: Duration) -> Result<Duration>

Refresh if the snapshot is older than max_age. Returns the snapshot age before any refresh.

Source

pub fn spawn_refresh( &self, reactor: &Reactor, period: Duration, ) -> TaskHandle<()>

Spawn a background tokio task that refreshes the snapshot every period until the returned tokio::task::JoinHandle is aborted. Mirrors pvxs IfMapDaemon (evhelper.cpp:715-758) which polls every 15 s.

Returns the handle so callers that own the runtime can store it for shutdown; dropping it does NOT cancel the task — abort it explicitly. Idempotent: multiple background refreshers on the same map cost extra wakeups but are harmless.

Without this, dynamic infrastructure (DHCP renewals changing the broadcast address; K8s pod network re-attach; VM live migration; cable hot-plug) leaves the snapshot stale, and any sender that derives a broadcast destination from the snapshot ends up sending to the wrong subnet.

Source

pub fn all(&self) -> Vec<IfaceInfo>

Snapshot of all IPv4 interfaces. Includes loopback unless callers filter via IfaceInfo::up_non_loopback.

Source

pub fn up_non_loopback(&self) -> Vec<IfaceInfo>

Snapshot of up, non-loopback IPv4 interfaces — the typical fanout target list for SEARCH/beacon traffic.

Source

pub fn by_index(&self, index: u32) -> Option<IfaceInfo>

Look up an interface by its kernel index. Returns None when the index isn’t known to this snapshot — caller may want to refresh() and retry once.

Source

pub fn route_to(&self, dest: Ipv4Addr) -> Option<IfaceInfo>

Pick the interface index that should originate traffic destined for dest. The selection rules (in priority order):

  1. Subnet match — dest falls within an interface’s (ip, netmask). Returned when present.
  2. Broadcast match — dest equals an interface’s subnet broadcast.
  3. Loopback — 127.0.0.0/8 → loopback interface.
  4. Default route — an interface with a 0.0.0.0 netmask matches any destination; used only as a fallback so it never shadows a specific subnet match.
  5. Otherwise None — caller treats this as “no per-NIC pinning, let the OS route”. For limited broadcast and multicast destinations the caller fanouts across all interfaces explicitly.

Trait Implementations§

Source§

impl Clone for IfaceMap

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

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, 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