1// Copyright 2024 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
45//! A blackhole device receives no traffic and drops all traffic sent through it.
67use core::convert::Infallible as Never;
89use netstack3_base::Device;
1011use crate::internal::base::{BlackholeDeviceCounters, DeviceReceiveFrameSpec};
12use crate::internal::id::{BasePrimaryDeviceId, BaseWeakDeviceId};
13use crate::{BaseDeviceId, DeviceStateSpec};
1415/// A weak device ID identifying a blackhole device.
16///
17/// This device ID is like [`WeakDeviceId`] but specifically for blackhole
18/// devices.
19///
20/// [`WeakDeviceId`]: crate::device::WeakDeviceId
21pub type BlackholeWeakDeviceId<BT> = BaseWeakDeviceId<BlackholeDevice, BT>;
2223/// A strong device ID identifying a blackhole device.
24///
25/// This device ID is like [`DeviceId`] but specifically for blackhole devices.
26///
27/// [`DeviceId`]: crate::device::DeviceId
28pub type BlackholeDeviceId<BT> = BaseDeviceId<BlackholeDevice, BT>;
2930/// The primary reference for a blackhole device.
31pub type BlackholePrimaryDeviceId<BT> = BasePrimaryDeviceId<BlackholeDevice, BT>;
3233/// State for a blackhole device.
34pub struct BlackholeDeviceState {}
3536/// Blackhole device domain.
37#[derive(Copy, Clone)]
38pub enum BlackholeDevice {}
3940impl Device for BlackholeDevice {}
4142impl DeviceStateSpec for BlackholeDevice {
43type State<BT: crate::DeviceLayerTypes> = BlackholeDeviceState;
4445type External<BT: crate::DeviceLayerTypes> = BT::BlackholeDeviceState;
4647type CreationProperties = ();
4849type Counters = BlackholeDeviceCounters;
5051type TimerId<D: netstack3_base::WeakDeviceIdentifier> = Never;
5253fn new_device_state<
54 CC: netstack3_base::CoreTimerContext<Self::TimerId<CC::WeakDeviceId>, BC>
55 + netstack3_base::DeviceIdContext<Self>,
56 BC: crate::DeviceLayerTypes + netstack3_base::TimerContext,
57 >(
58 _bindings_ctx: &mut BC,
59 _self_id: CC::WeakDeviceId,
60 _properties: Self::CreationProperties,
61 ) -> Self::State<BC> {
62 BlackholeDeviceState {}
63 }
6465const IS_LOOPBACK: bool = false;
6667const DEBUG_TYPE: &'static str = "Blackhole";
68}
6970impl DeviceReceiveFrameSpec for BlackholeDevice {
71// Blackhole devices never receive frames from bindings, so make it impossible to
72 // instantiate it.
73type FrameMetadata<D> = Never;
74}