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