Skip to main content

Link

Struct Link 

Source
#[non_exhaustive]
pub struct Link { pub address: SocketAddrV4, pub subnet: LocalSubnet, pub mode: Mode, pub budget: Option<u16>, }
Expand description

A B/IP node’s link: everything its receive and send decisions read. They are pure, so a host can share one copy among threads and decide without a lock.

It is #[non_exhaustive], so a new setting isn’t a breaking change: outside this crate, start from Link::new and set the fields to change. Node::new checks the result with Link::validate.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§address: SocketAddrV4

This node’s own B/IP address, the MAC address its peers know it by.

§subnet: LocalSubnet

Where its local broadcasts go (the subnet’s broadcast address at the network’s port), and the subnet mask a BBMD uses.

§mode: Mode

How it takes part in the network.

§budget: Option<u16>

The longest datagram it sends, in octets, or None to send any NPDU the codec can carry. See Link::max_npdu.

Implementations§

Source

pub const fn groups(&self) -> Groups

The link’s group destinations, with the IP of the node’s own B/IP address as its interface.

A host bound to the wildcard address may judge a destination by its bind address (0.0.0.0) instead, as the Tokio transport’s is_group_destination does. The two differ only where the configured broadcast IP is the node’s own IP, a misconfiguration: this one then takes a sender from that IP, which the own-echo rule drops at the node’s port.

Source

pub fn is_own(&self, address: SocketAddrV4) -> bool

Whether address is this node’s own B/IP address.

The one test for the node’s own echo, so an address the node is also reached at (a NAT router’s global address) can join it here.

Source

pub fn is_answerable(&self, source: SocketAddrV4) -> bool

Whether a reply to source could reach a peer: not the unspecified address, not port 0, not a group address, and not this node.

Source

pub const fn new( address: SocketAddrV4, subnet: LocalSubnet, mode: Mode, ) -> Result<Self, ConfigError>

A link in mode, with the default budget of MAX_DATAGRAM octets, checked by Link::validate.

Source

pub const fn validate(&self) -> Result<(), ConfigError>

Check the configuration: a nonzero own port, a usable foreign-device registration, a budget of at least MIN_BUDGET octets, and no multicast group (a class D LocalSubnet::broadcast) in Mode::Foreign. A normal node with a group is a B/IP-M member, and a BBMD with one serves the group (Annex J.8.3).

Source

pub fn receive<'d>( &self, datagram: &Datagram<'d>, now: Instant, policy: &mut impl Policy, ) -> Received<'d>

Decide what to do with one datagram.

The rules run in this order, and a dropped datagram is Discarded under the first it fails:

  1. truncated by the OS or the buffer;
  2. a UDP source that is a group address;
  3. a destination the host couldn’t report (Datagram::to is None);
  4. on a broadcast listener: not sent to the broadcast address, or arrived on another interface;
  5. the BVLL header: length, type, Length field (Annex J.2);
  6. the function against the destination (Addressed); for a foreign device, a Forwarded-NPDU sent to its own address is unicast, even where that address is its broadcast one too;
  7. on a broadcast listener, a function that arrived as unicast;
  8. Policy::admit_management, for the four requests it covers;
  9. the payload against the function’s layout.

Then each function is dispatched by mode. Every one of the six BBMD-only requests that arrived by unicast gets its own NAK (BvlcFunction::nak), unless Mode::Bbmd claims it, from any source a reply can reach (Link::is_answerable). Write-BDT is refused in every mode, and so is a malformed BBMD-only request.

Source

pub fn listener_keeps(&self, datagram: &Datagram<'_>) -> bool

Whether receive would get past its broadcast listener rules (4 and 7) with datagram: false exactly when it would drop it as Discard::ListenerMismatch. A datagram another socket read, or one with no reported destination, passes. A host that reports a listener’s datagrams somewhere before the node acts on them, as a frame tap does, asks this so that it reports only what the node keeps (#1856). It reads the frame’s header only; a frame that doesn’t decode passes, for receive to count as malformed.

Source

pub fn max_npdu(&self, cast: Cast) -> usize

The longest NPDU sent as cast.

With a budget, a unicast’s datagram is the NPDU plus the 4-octet header, and a broadcast’s, once a BBMD forwards it as a Forwarded-NPDU, 6 octets more; either way at most MAX_NPDU (Table 6-1). Without one, what the Length field can state.

Source

pub fn unicast<'n>( &self, to: SocketAddrV4, npdu: &'n [u8], ) -> Result<Outgoing<'n>, SendRefusal>

An Original-Unicast-NPDU carrying npdu to to (Annex J.3).

to must be one node’s address: a group address of this link (Groups::contains) is refused with SendRefusal::GroupDestination. A receiver that checks the destination drops an Original-Unicast-NPDU sent to a group, so it would reach no one, or nodes that should have ignored it (#1677). Another subnet’s directed broadcast address isn’t known here, so it isn’t caught; a receiver’s destination check still drops it.

Source

pub fn broadcast<'n>( &self, npdu: &'n [u8], ) -> Result<(Outgoing<'n>, bool), SendRefusal>

A local broadcast of npdu, by mode: an Original-Broadcast-NPDU to the subnet’s broadcast address for a normal node or a BBMD (Annex J.4.1), and a Distribute-Broadcast-To-Network to its BBMD for a foreign device (Annex J.2.10). The flag is set for a BBMD, which also forwards its own broadcast (Tables::own_broadcast).

A foreign device asks Node::admit_broadcast first.

Trait Implementations§

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§

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

Formats the value using the given formatter. Read more
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

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

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.