netstack3_ip/
uninstantiable.rs

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.
4
5use explicit::UnreachableExt as _;
6use net_types::SpecifiedAddr;
7use netstack3_base::{
8    AnyDevice, DeviceIdContext, IpExt, Mms, TxMetadataBindingsTypes, Uninstantiable,
9    UninstantiableWrapper,
10};
11use netstack3_filter::{FilterIpExt, Tuple};
12
13use crate::internal::base::{BaseTransportIpContext, HopLimits, IpLayerIpExt};
14use crate::internal::device::Ipv6LinkLayerAddr;
15use crate::internal::socket::{
16    DeviceIpSocketHandler, IpSock, IpSockCreationError, IpSockSendError, IpSocketArgs,
17    IpSocketHandler, MmsError, RouteResolutionOptions,
18};
19
20impl<I: IpExt, C, P: DeviceIdContext<AnyDevice>> BaseTransportIpContext<I, C>
21    for UninstantiableWrapper<P>
22{
23    type DevicesWithAddrIter<'s> = UninstantiableWrapper<core::iter::Empty<P::DeviceId>>;
24    fn with_devices_with_assigned_addr<O, F: FnOnce(Self::DevicesWithAddrIter<'_>) -> O>(
25        &mut self,
26        _addr: SpecifiedAddr<I::Addr>,
27        _cb: F,
28    ) -> O {
29        self.uninstantiable_unreachable()
30    }
31    fn get_default_hop_limits(&mut self, _device: Option<&Self::DeviceId>) -> HopLimits {
32        self.uninstantiable_unreachable()
33    }
34    fn get_original_destination(&mut self, _tuple: &Tuple<I>) -> Option<(I::Addr, u16)> {
35        self.uninstantiable_unreachable()
36    }
37}
38
39impl<I: IpExt + FilterIpExt, BC: TxMetadataBindingsTypes, P: DeviceIdContext<AnyDevice>>
40    IpSocketHandler<I, BC> for UninstantiableWrapper<P>
41{
42    fn new_ip_socket<O>(
43        &mut self,
44        _ctx: &mut BC,
45        _args: IpSocketArgs<'_, Self::DeviceId, I, O>,
46    ) -> Result<IpSock<I, Self::WeakDeviceId>, IpSockCreationError> {
47        self.uninstantiable_unreachable()
48    }
49
50    fn send_ip_packet<S, O>(
51        &mut self,
52        _ctx: &mut BC,
53        _socket: &IpSock<I, Self::WeakDeviceId>,
54        _body: S,
55        _options: &O,
56        _tx_metadata: BC::TxMetadata,
57    ) -> Result<(), IpSockSendError> {
58        self.uninstantiable_unreachable()
59    }
60
61    fn confirm_reachable<O>(
62        &mut self,
63        _bindings_ctx: &mut BC,
64        _socket: &IpSock<I, Self::WeakDeviceId>,
65        _options: &O,
66    ) {
67        self.uninstantiable_unreachable()
68    }
69}
70
71impl<I: IpLayerIpExt, C, P: DeviceIpSocketHandler<I, C>> DeviceIpSocketHandler<I, C>
72    for UninstantiableWrapper<P>
73{
74    fn get_mms<O: RouteResolutionOptions<I>>(
75        &mut self,
76        _bindings_ctx: &mut C,
77        _ip_sock: &IpSock<I, Self::WeakDeviceId>,
78        _options: &O,
79    ) -> Result<Mms, MmsError> {
80        self.uninstantiable_unreachable()
81    }
82}
83
84impl Ipv6LinkLayerAddr for Uninstantiable {
85    fn as_bytes(&self) -> &[u8] {
86        self.uninstantiable_unreachable()
87    }
88
89    fn eui64_iid(&self) -> [u8; 8] {
90        self.uninstantiable_unreachable()
91    }
92}