1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Copyright 2022 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

//! Groups trait implementations for uninstantiable types.

use explicit::UnreachableExt as _;

use netstack3_base::{CounterContext, Uninstantiable, UninstantiableWrapper, WeakDeviceIdentifier};

use crate::internal::base::TcpCounters;
use crate::internal::socket::{
    AsThisStack, DemuxState, DualStackBaseIpExt, DualStackDemuxIdConverter, DualStackIpExt,
    TcpBindingsTypes, TcpDemuxContext, TcpDualStackContext, TcpSocketId,
};

impl<
        I: DualStackIpExt,
        D: WeakDeviceIdentifier,
        BT: TcpBindingsTypes,
        P: TcpDemuxContext<I, D, BT>,
    > TcpDemuxContext<I, D, BT> for UninstantiableWrapper<P>
{
    type IpTransportCtx<'a> = P::IpTransportCtx<'a>;
    fn with_demux<O, F: FnOnce(&DemuxState<I, D, BT>) -> O>(&mut self, _cb: F) -> O {
        self.uninstantiable_unreachable()
    }
    fn with_demux_mut<O, F: FnOnce(&mut DemuxState<I, D, BT>) -> O>(&mut self, _cb: F) -> O {
        self.uninstantiable_unreachable()
    }
}

impl<P> AsThisStack<P> for UninstantiableWrapper<P> {
    fn as_this_stack(&mut self) -> &mut P {
        self.uninstantiable_unreachable()
    }
}

impl<I: DualStackIpExt> DualStackDemuxIdConverter<I> for Uninstantiable {
    fn convert<D: WeakDeviceIdentifier, BT: TcpBindingsTypes>(
        &self,
        _id: TcpSocketId<I, D, BT>,
    ) -> <I::OtherVersion as DualStackBaseIpExt>::DemuxSocketId<D, BT> {
        self.uninstantiable_unreachable()
    }
}

impl<
        I: DualStackIpExt,
        D: WeakDeviceIdentifier,
        BT: TcpBindingsTypes,
        P: TcpDualStackContext<I::OtherVersion, D, BT>,
    > TcpDualStackContext<I, D, BT> for UninstantiableWrapper<P>
where
    for<'a> P::DualStackIpTransportCtx<'a>: CounterContext<TcpCounters<I>>,
{
    type DualStackIpTransportCtx<'a> = P::DualStackIpTransportCtx<'a>;
    fn other_demux_id_converter(&self) -> impl DualStackDemuxIdConverter<I> {
        self.uninstantiable_unreachable::<Uninstantiable>()
    }

    fn dual_stack_enabled(&self, _ip_options: &I::DualStackIpOptions) -> bool {
        self.uninstantiable_unreachable()
    }

    fn set_dual_stack_enabled(&self, _ip_options: &mut I::DualStackIpOptions, _value: bool) {
        self.uninstantiable_unreachable()
    }

    fn with_both_demux_mut<
        O,
        F: FnOnce(&mut DemuxState<I, D, BT>, &mut DemuxState<I::OtherVersion, D, BT>) -> O,
    >(
        &mut self,
        _cb: F,
    ) -> O {
        self.uninstantiable_unreachable()
    }
}