class DeviceAdapter
Defined at line 55 of file ../../src/connectivity/network/tun/network-tun/device_adapter.h
An entity that instantiates a `NetworkDeviceInterface` and provides an implementations of
`fuchsia.hardware.network.device.NetworkDeviceImpl` that grants access to the buffers exchanged
with the interface.
`DeviceAdapter` is used to provide the business logic of virtual NetworkDevice implementations
both for `tun.Device` and `tun.DevicePair` device classes.
`DeviceAdapter` maintains the buffer nomenclature used by the DeviceInterface, that is: A "Tx"
buffer is a buffer that contains data that is expected to be sent over a link, and an "Rx" buffer
is free space that can be used to write data received over a link and push it back to
applications.
Public Methods
zx::result<std::unique_ptr<DeviceAdapter>> Create (const DeviceInterfaceDispatchers & dispatchers, fdf::UnownedUnsynchronizedDispatcher && netdev_dispatcher, DeviceAdapterParent * parent)
Creates a new `DeviceAdapter` with `parent`, that will serve its requests through
`netdev_dispatcher`. `dispatchers` is passed on to the the network-device library.
Defined at line 29 of file ../../src/connectivity/network/tun/network-tun/device_adapter.cc
zx_status_t Bind (fidl::ServerEnd<fuchsia_hardware_network::Device> req)
Binds `req` to this adapter's `NetworkDeviceInterface`.
Defined at line 53 of file ../../src/connectivity/network/tun/network-tun/device_adapter.cc
zx_status_t BindPort (uint8_t port_id, fidl::ServerEnd<fuchsia_hardware_network::Port> req)
Binds `req` to the port with `port_id` in this adapter's `NetworkDeviceInterface`.
Defined at line 57 of file ../../src/connectivity/network/tun/network-tun/device_adapter.cc
fdf::ClientEnd<fuchsia_hardware_network_driver::NetworkDeviceImpl> BindDriver ()
Binds a new driver connection and returns the client end.
Defined at line 62 of file ../../src/connectivity/network/tun/network-tun/device_adapter.cc
void Init (fuchsia_hardware_network_driver::wire::NetworkDeviceImplInitRequest * request, fdf::Arena & arena, InitCompleter::Sync & completer)
NetworkDeviceImpl protocol:
Defined at line 69 of file ../../src/connectivity/network/tun/network-tun/device_adapter.cc
void Start (fdf::Arena & arena, StartCompleter::Sync & completer)
Defined at line 76 of file ../../src/connectivity/network/tun/network-tun/device_adapter.cc
void Stop (fdf::Arena & arena, StopCompleter::Sync & completer)
Defined at line 88 of file ../../src/connectivity/network/tun/network-tun/device_adapter.cc
const fdf::UnownedUnsynchronizedDispatcher & netdevice_dispatcher ()
Defined at line 140 of file ../../src/connectivity/network/tun/network-tun/device_adapter.h
void Teardown (fit::function<void ()> callback)
Tears down this adapter and calls `callback` when teardown is finished.
Tearing down causes all client channels to be closed.
There are no guarantees over which thread `callback` is called.
It is invalid to attempt to tear down a device that is already tearing down or is already torn
down.
Defined at line 393 of file ../../src/connectivity/network/tun/network-tun/device_adapter.cc
void TeardownSync ()
Same as `Teardown`, but blocks until teardown is complete.
Defined at line 397 of file ../../src/connectivity/network/tun/network-tun/device_adapter.cc
void GetInfo (fdf::Arena & arena, GetInfoCompleter::Sync & completer)
Defined at line 163 of file ../../src/connectivity/network/tun/network-tun/device_adapter.cc
void QueueTx (fuchsia_hardware_network_driver::wire::NetworkDeviceImplQueueTxRequest * request, fdf::Arena & arena, QueueTxCompleter::Sync & completer)
Defined at line 180 of file ../../src/connectivity/network/tun/network-tun/device_adapter.cc
void QueueRxSpace (fuchsia_hardware_network_driver::wire::NetworkDeviceImplQueueRxSpaceRequest * request, fdf::Arena & arena, QueueRxSpaceCompleter::Sync & completer)
Defined at line 207 of file ../../src/connectivity/network/tun/network-tun/device_adapter.cc
void PrepareVmo (fuchsia_hardware_network_driver::wire::NetworkDeviceImplPrepareVmoRequest * request, fdf::Arena & arena, PrepareVmoCompleter::Sync & completer)
Defined at line 260 of file ../../src/connectivity/network/tun/network-tun/device_adapter.cc
void ReleaseVmo (fuchsia_hardware_network_driver::wire::NetworkDeviceImplReleaseVmoRequest * request, fdf::Arena & arena, ReleaseVmoCompleter::Sync & completer)
Defined at line 267 of file ../../src/connectivity/network/tun/network-tun/device_adapter.cc
bool TryGetTxBuffer (fit::callback<zx_status_t (TxBuffer &, size_t)> callback)
Attempts to get a pending transmit buffer containing data expected to reach the network from
the pool of pending buffers.
The second argument given to `callback` is the number of remaining pending buffers (not
including the one given to it).
Returns `true` if a buffer was successfully allocated. The buffer given to `callback` is
discarded from the list of pending buffers and marked as pending for return.
Defined at line 277 of file ../../src/connectivity/network/tun/network-tun/device_adapter.cc
void RetainTxBuffers (fit::function<zx_status_t (TxBuffer &)> func)
Calls `func` with all currently enqueued tx buffers.
If `func` returns a value different than `ZX_OK`, the buffer is returned to the device
implementation with that error.
Defined at line 295 of file ../../src/connectivity/network/tun/network-tun/device_adapter.cc
zx::result<size_t> WriteRxFrame (PortAdapter & port, fuchsia_hardware_network::wire::FrameType frame_type, const uint8_t * data, size_t count, const std::optional<fuchsia_net_tun::wire::FrameMetadata> & meta)
Attempts to write `data` and `meta` into an available rx buffer and return it to the
`NetworkDeviceInterface`.
Returns the number of remaining available buffers.
Returns `ZX_ERR_BAD_STATE` if the device is offline, or `ZX_ERR_SHOULD_WAIT` if there are no
buffers available to write `data` into
Defined at line 310 of file ../../src/connectivity/network/tun/network-tun/device_adapter.cc
zx::result<size_t> WriteRxFrame (PortAdapter & port, fuchsia_hardware_network::wire::FrameType frame_type, const fidl::VectorView<uint8_t> & data, const std::optional<fuchsia_net_tun::wire::FrameMetadata> & meta)
Defined at line 339 of file ../../src/connectivity/network/tun/network-tun/device_adapter.cc
zx::result<size_t> WriteRxFrame (PortAdapter & port, fuchsia_hardware_network::wire::FrameType frame_type, const std::vector<uint8_t> & data, const std::optional<fuchsia_net_tun::wire::FrameMetadata> & meta)
Defined at line 346 of file ../../src/connectivity/network/tun/network-tun/device_adapter.cc
void CopyTo (DeviceAdapter * other, bool return_failed_buffers)
Copies all pending tx buffers from `this` consuming any available rx buffers from `other`.
If `return_failed_buffers` is `true`, all buffers from `this` that couldn't be immediately
copied into available buffers from `other` will be returned to applications in a failure state,
otherwise buffers from `this` will remain in the available buffer pool.
Defined at line 353 of file ../../src/connectivity/network/tun/network-tun/device_adapter.cc
void OnPortStatusChanged (uint8_t port_id, const PortStatus & new_status)
Handles status change notifications from port with `port_id`.
Defined at line 514 of file ../../src/connectivity/network/tun/network-tun/device_adapter.cc
zx_status_t AddPort (PortAdapter & port)
Adds |port| to the device.
Defined at line 527 of file ../../src/connectivity/network/tun/network-tun/device_adapter.cc
void RemovePort (uint8_t port_id)
Removes port with |port_id|.
Defined at line 548 of file ../../src/connectivity/network/tun/network-tun/device_adapter.cc
zx_status_t DelegateRxLease (fuchsia_hardware_network::wire::DelegatedRxLease lease)
Delegates |lease| up the receive path.
Defined at line 556 of file ../../src/connectivity/network/tun/network-tun/device_adapter.cc