Skip to main content

netstack3_datagram/
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 netstack3_base::socket::MaybeDualStack;
7use netstack3_base::{Uninstantiable, UninstantiableWrapper};
8
9use crate::internal::datagram::{
10    BoundDatagramSocketMap, DatagramBindingsTypes, DatagramBoundStateContext,
11    DatagramIpSpecificSocketOptions, DatagramSocketMapSpec, DatagramSocketSpec, DualStackConverter,
12    IpExt, IpOptions, NonDualStackConverter,
13};
14use crate::internal::spec_context::{
15    DatagramSpecBoundStateContext, DualStackDatagramSpecBoundStateContext,
16    NonDualStackDatagramSpecBoundStateContext,
17};
18
19impl<
20    I: IpExt,
21    S: DatagramSocketSpec,
22    P: DatagramBoundStateContext<I, BC, S>,
23    BC: DatagramBindingsTypes,
24> DatagramSpecBoundStateContext<I, UninstantiableWrapper<P>, BC> for S
25{
26    type IpSocketsCtx<'a> = P::IpSocketsCtx<'a>;
27    type DualStackContext = P::DualStackContext;
28    type NonDualStackContext = P::NonDualStackContext;
29    fn dual_stack_context(
30        core_ctx: &UninstantiableWrapper<P>,
31    ) -> MaybeDualStack<&Self::DualStackContext, &Self::NonDualStackContext> {
32        core_ctx.uninstantiable_unreachable()
33    }
34    fn dual_stack_context_mut(
35        core_ctx: &mut UninstantiableWrapper<P>,
36    ) -> MaybeDualStack<&mut Self::DualStackContext, &mut Self::NonDualStackContext> {
37        core_ctx.uninstantiable_unreachable()
38    }
39    fn with_bound_sockets<
40        O,
41        F: FnOnce(&mut Self::IpSocketsCtx<'_>, &BoundDatagramSocketMap<I, P::WeakDeviceId, S>) -> O,
42    >(
43        core_ctx: &mut UninstantiableWrapper<P>,
44        _cb: F,
45    ) -> O {
46        core_ctx.uninstantiable_unreachable()
47    }
48    fn with_bound_sockets_mut<
49        O,
50        F: FnOnce(
51            &mut Self::IpSocketsCtx<'_>,
52            &mut BoundDatagramSocketMap<I, P::WeakDeviceId, S>,
53        ) -> O,
54    >(
55        core_ctx: &mut UninstantiableWrapper<P>,
56        _cb: F,
57    ) -> O {
58        core_ctx.uninstantiable_unreachable()
59    }
60    fn with_transport_context<O, F: FnOnce(&mut Self::IpSocketsCtx<'_>) -> O>(
61        core_ctx: &mut UninstantiableWrapper<P>,
62        _cb: F,
63    ) -> O {
64        core_ctx.uninstantiable_unreachable()
65    }
66}
67
68impl<
69    I: IpExt,
70    S: DatagramSocketSpec,
71    P: DatagramBoundStateContext<I, BC, S>,
72    BC: DatagramBindingsTypes,
73> NonDualStackDatagramSpecBoundStateContext<I, UninstantiableWrapper<P>, BC> for S
74{
75    fn nds_converter(
76        core_ctx: &UninstantiableWrapper<P>,
77    ) -> impl NonDualStackConverter<I, P::WeakDeviceId, Self> {
78        core_ctx.uninstantiable_unreachable::<Uninstantiable>()
79    }
80}
81
82impl<
83    I: IpExt,
84    S: DatagramSocketSpec,
85    P: DatagramBoundStateContext<I, BC, S>,
86    BC: DatagramBindingsTypes,
87> DualStackDatagramSpecBoundStateContext<I, UninstantiableWrapper<P>, BC> for S
88{
89    type IpSocketsCtx<'a> = UninstantiableWrapper<P::IpSocketsCtx<'a>>;
90
91    fn dual_stack_enabled(
92        core_ctx: &UninstantiableWrapper<P>,
93        _state: &IpOptions<I, P::WeakDeviceId, S>,
94    ) -> bool {
95        core_ctx.uninstantiable_unreachable()
96    }
97
98    fn to_other_socket_options<'a>(
99        core_ctx: &UninstantiableWrapper<P>,
100        _state: &'a IpOptions<I, P::WeakDeviceId, S>,
101    ) -> &'a DatagramIpSpecificSocketOptions<I::OtherVersion, P::WeakDeviceId> {
102        core_ctx.uninstantiable_unreachable()
103    }
104
105    fn ds_converter(
106        core_ctx: &UninstantiableWrapper<P>,
107    ) -> impl DualStackConverter<I, P::WeakDeviceId, S> {
108        core_ctx.uninstantiable_unreachable::<Uninstantiable>()
109    }
110
111    fn to_other_bound_socket_id(
112        core_ctx: &UninstantiableWrapper<P>,
113        _id: &S::SocketId<I, P::WeakDeviceId>,
114    ) -> <S::SocketMapSpec<I::OtherVersion, P::WeakDeviceId> as DatagramSocketMapSpec<
115        I::OtherVersion,
116        P::WeakDeviceId,
117        S::AddrSpec,
118    >>::BoundSocketId {
119        core_ctx.uninstantiable_unreachable()
120    }
121
122    fn with_both_bound_sockets_mut<
123        O,
124        F: FnOnce(
125            &mut Self::IpSocketsCtx<'_>,
126            &mut BoundDatagramSocketMap<I, P::WeakDeviceId, S>,
127            &mut BoundDatagramSocketMap<I::OtherVersion, P::WeakDeviceId, S>,
128        ) -> O,
129    >(
130        core_ctx: &mut UninstantiableWrapper<P>,
131        _cb: F,
132    ) -> O {
133        core_ctx.uninstantiable_unreachable()
134    }
135
136    fn with_other_bound_sockets_mut<
137        O,
138        F: FnOnce(
139            &mut Self::IpSocketsCtx<'_>,
140            &mut BoundDatagramSocketMap<I::OtherVersion, P::WeakDeviceId, S>,
141        ) -> O,
142    >(
143        core_ctx: &mut UninstantiableWrapper<P>,
144        _cb: F,
145    ) -> O {
146        core_ctx.uninstantiable_unreachable()
147    }
148
149    fn with_transport_context<O, F: FnOnce(&mut Self::IpSocketsCtx<'_>) -> O>(
150        core_ctx: &mut UninstantiableWrapper<P>,
151        _cb: F,
152    ) -> O {
153        core_ctx.uninstantiable_unreachable()
154    }
155}