pub trait Driver {
// Required methods
fn capabilities(&self) -> Capabilities;
fn hardware_address(&self) -> HardwareAddress;
fn receive(&mut self) -> Option<PacketBuf>;
fn can_transmit(&mut self) -> bool;
fn transmit(&mut self, buf: PacketBuf) -> Result<(), PacketBuf>;
// Provided methods
fn link_state(&mut self) -> LinkState { ... }
fn poll_tx_timestamp(&mut self) -> Option<TxTimestamp> { ... }
}Expand description
A network device driver, sending and receiving raw network frames.
Required Methods§
Sourcefn capabilities(&self) -> Capabilities
fn capabilities(&self) -> Capabilities
Get a description of the device’s capabilities.
Sourcefn hardware_address(&self) -> HardwareAddress
fn hardware_address(&self) -> HardwareAddress
Get the device’s hardware address.
The address kind must match the medium in capabilities:
an Ethernet address for Medium::Ethernet, HardwareAddress::Ip for
Medium::Ip, an IEEE 802.15.4 extended address for Medium::Ieee802154.
The stack reads it once, when the driver is added to it. The stack has its own way to override the address after that.
Sourcefn receive(&mut self) -> Option<PacketBuf>
fn receive(&mut self) -> Option<PacketBuf>
Poll for a received frame.
Returns a buffer holding the received frame if one is available, transferring ownership of it to the caller.
A driver that has per-packet metadata to report, such as an identifier or a
receive timestamp, sets it on the buffer’s PacketMeta here. It travels
with the packet up to the socket that receives it.
Sourcefn can_transmit(&mut self) -> bool
fn can_transmit(&mut self) -> bool
Whether the device can transmit one frame right now.
Devices typically have a transmit packet queue. This returns whether this queue has space to take one more frame.
If this returns true, the next transmit() call must not fail.
In devices where there’s no queue so transmit always succeeds, this
should always return true.
Sourcefn transmit(&mut self, buf: PacketBuf) -> Result<(), PacketBuf>
fn transmit(&mut self, buf: PacketBuf) -> Result<(), PacketBuf>
Queue a frame for transmission, transferring ownership of the buffer to the driver.
The driver holds the buffer until the hardware is done with it, then drops it.
If the frame cannot be queued right now (device busy or queue full), the buffer
is handed back in the Err variant.
The buffer’s PacketMeta is whatever the sending socket attached to the
packet (default for packets the stack generates itself). A driver that
supports transmit timestamping timestamps the frame if
request_timestamp is set, and reports
the result from poll_tx_timestamp tagged with the
packet’s id.
Provided Methods§
Sourcefn link_state(&mut self) -> LinkState
fn link_state(&mut self) -> LinkState
Get the link state.
Devices that cannot tell, or whose link is always up, return
LinkState::Up, which is the default implementation.
Sourcefn poll_tx_timestamp(&mut self) -> Option<TxTimestamp>
fn poll_tx_timestamp(&mut self) -> Option<TxTimestamp>
Poll for the timestamp of an already-transmitted packet.
Returns the transmit timestamp of a packet previously sent with
PacketMeta::request_timestamp set, tagged with that packet’s
PacketMeta::id, or None if no timestamp is available right now.
Transmit timestamps are reported out of band, rather than on the packet like
receive timestamps are, because a packet’s transmit timestamp does not exist yet
when transmit returns: it has not gone out on the wire yet.
Callers must be robust against all of the following:
- Timestamps become available an arbitrary time after
transmitreturned, so this should be polled repeatedly, not just once after sending. - Timestamps may be reported out of order with respect to transmission.
- Timestamps may never arrive at all, e.g. because the hardware ran out of
timestamp slots. Never block waiting for a particular
idto show up without a timeout.
Devices that do not support transmit timestamping always return None, which is
the default implementation.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".