#[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
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.address: SocketAddrV4This node’s own B/IP address, the MAC address its peers know it by.
subnet: LocalSubnetWhere its local broadcasts go (the subnet’s broadcast address at the network’s port), and the subnet mask a BBMD uses.
mode: ModeHow 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§impl Link
impl Link
Sourcepub const fn groups(&self) -> Groups
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.
Sourcepub fn is_own(&self, address: SocketAddrV4) -> bool
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.
Sourcepub fn is_answerable(&self, source: SocketAddrV4) -> bool
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§impl Link
impl Link
Sourcepub const fn new(
address: SocketAddrV4,
subnet: LocalSubnet,
mode: Mode,
) -> Result<Self, ConfigError>
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.
Sourcepub const fn validate(&self) -> Result<(), ConfigError>
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§impl Link
impl Link
Sourcepub fn receive<'d>(
&self,
datagram: &Datagram<'d>,
now: Instant,
policy: &mut impl Policy,
) -> Received<'d>
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:
- truncated by the OS or the buffer;
- a UDP source that is a group address;
- a destination the host couldn’t report (
Datagram::toisNone); - on a broadcast listener: not sent to the broadcast address, or arrived on another interface;
- the BVLL header: length, type, Length field (Annex J.2);
- 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; - on a broadcast listener, a function that arrived as unicast;
Policy::admit_management, for the four requests it covers;- 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§impl Link
impl Link
Sourcepub fn listener_keeps(&self, datagram: &Datagram<'_>) -> bool
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§impl Link
impl Link
Sourcepub fn max_npdu(&self, cast: Cast) -> usize
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.
Sourcepub fn unicast<'n>(
&self,
to: SocketAddrV4,
npdu: &'n [u8],
) -> Result<Outgoing<'n>, SendRefusal>
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.
Sourcepub fn broadcast<'n>(
&self,
npdu: &'n [u8],
) -> Result<(Outgoing<'n>, bool), SendRefusal>
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.