netstack3_core/
marker.rs

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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
// Copyright 2024 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.

//! Marker traits with blanket implementations.
//!
//! Traits in this module exist to be exported as markers to bindings without
//! exposing the internal traits directly.

use net_types::ip::{Ipv4, Ipv6};
use netstack3_base::{
    AnyDevice, CounterContext, DeviceIdContext, InstantBindingsTypes, ReferenceNotifiers,
    RngContext, TimerBindingsTypes, TracingContext,
};
use netstack3_datagram as datagram;
use netstack3_device::ethernet::{EthernetDeviceId, EthernetLinkDevice, EthernetWeakDeviceId};
use netstack3_device::{self as device, DeviceId, DeviceLayerTypes, WeakDeviceId};
use netstack3_filter::{FilterBindingsContext, FilterBindingsTypes};
use netstack3_icmp_echo::{IcmpEchoBindingsContext, IcmpEchoBindingsTypes, IcmpEchoStateContext};
use netstack3_ip::device::{
    IpDeviceBindingsContext, IpDeviceConfigurationContext, IpDeviceConfigurationHandler,
    IpDeviceIpExt,
};
use netstack3_ip::icmp::{IcmpBindingsContext, IcmpBindingsTypes};
use netstack3_ip::multicast_forwarding::{
    MulticastForwardingBindingsContext, MulticastForwardingBindingsTypes,
    MulticastForwardingStateContext,
};
use netstack3_ip::nud::{NudBindingsContext, NudContext};
use netstack3_ip::raw::{
    RawIpSocketMapContext, RawIpSocketStateContext, RawIpSocketsBindingsContext,
    RawIpSocketsBindingsTypes,
};
use netstack3_ip::socket::IpSocketContext;
use netstack3_ip::{self as ip, IpLayerBindingsContext, IpLayerContext, IpLayerIpExt};
use netstack3_tcp::{self as tcp, TcpBindingsContext, TcpBindingsTypes, TcpContext};
use netstack3_udp::{self as udp, UdpBindingsContext, UdpBindingsTypes, UdpCounters};

use crate::TimerId;

/// A marker for extensions to IP types.
///
/// This trait acts as a marker for [`BaseIpExt`] for both `Self` and
/// `Self::OtherVersion`.
pub trait IpExt: BaseIpExt + datagram::DualStackIpExt<OtherVersion: BaseIpExt> {}

impl<I> IpExt for I where I: BaseIpExt + datagram::DualStackIpExt<OtherVersion: BaseIpExt> {}

/// A marker for extensions to IP types.
pub trait BaseIpExt:
    IpLayerIpExt
    + IpDeviceIpExt
    + netstack3_base::IcmpIpExt
    + ip::device::IpDeviceIpExt
    + tcp::DualStackIpExt
    + datagram::DualStackIpExt
{
}

impl<I> BaseIpExt for I where
    I: ip::IpLayerIpExt
        + IpDeviceIpExt
        + netstack3_base::IcmpIpExt
        + ip::device::IpDeviceIpExt
        + tcp::DualStackIpExt
        + datagram::DualStackIpExt
{
}

/// A marker trait for core context implementations.
///
/// This trait allows bindings to express trait bounds on routines that have IP
/// type parameters. It is an umbrella of all the core contexts that must be
/// implemented by [`crate::context::UnlockedCoreCtx`] to satisfy all the API
/// objects vended by [`crate::api::CoreApi`].
pub trait CoreContext<I, BC>:
    udp::StateContext<I, BC>
    + CounterContext<UdpCounters<I>>
    + TcpContext<I, BC>
    + IcmpEchoStateContext<I, BC>
    + ip::icmp::IcmpStateContext
    + IpLayerContext<I, BC>
    + NudContext<I, EthernetLinkDevice, BC>
    + IpDeviceConfigurationContext<I, BC>
    + IpDeviceConfigurationHandler<I, BC>
    + IpSocketContext<I, BC>
    + DeviceIdContext<AnyDevice, DeviceId = DeviceId<BC>, WeakDeviceId = WeakDeviceId<BC>>
    + DeviceIdContext<
        EthernetLinkDevice,
        DeviceId = EthernetDeviceId<BC>,
        WeakDeviceId = EthernetWeakDeviceId<BC>,
    > + RawIpSocketMapContext<I, BC>
    + RawIpSocketStateContext<I, BC>
    + MulticastForwardingStateContext<I, BC>
where
    I: IpExt,
    BC: IpBindingsContext<I>,
{
}

impl<I, BC, O> CoreContext<I, BC> for O
where
    I: IpExt,
    BC: IpBindingsContext<I>,
    O: udp::StateContext<I, BC>
        + CounterContext<UdpCounters<I>>
        + TcpContext<I, BC>
        + IcmpEchoStateContext<I, BC>
        + ip::icmp::IcmpStateContext
        + IpLayerContext<I, BC>
        + NudContext<I, EthernetLinkDevice, BC>
        + IpDeviceConfigurationContext<I, BC>
        + IpDeviceConfigurationHandler<I, BC>
        + IpSocketContext<I, BC>
        + DeviceIdContext<AnyDevice, DeviceId = DeviceId<BC>, WeakDeviceId = WeakDeviceId<BC>>
        + DeviceIdContext<
            EthernetLinkDevice,
            DeviceId = EthernetDeviceId<BC>,
            WeakDeviceId = EthernetWeakDeviceId<BC>,
        > + RawIpSocketMapContext<I, BC>
        + RawIpSocketStateContext<I, BC>
        + MulticastForwardingStateContext<I, BC>,
{
}

/// A marker trait for all the types stored in core objects that are specified
/// by bindings.
pub trait BindingsTypes:
    InstantBindingsTypes
    + DeviceLayerTypes
    + TcpBindingsTypes
    + FilterBindingsTypes
    + IcmpEchoBindingsTypes
    + IcmpBindingsTypes
    + MulticastForwardingBindingsTypes
    + RawIpSocketsBindingsTypes
    + UdpBindingsTypes
    + TimerBindingsTypes<DispatchId = TimerId<Self>>
{
}

impl<O> BindingsTypes for O where
    O: InstantBindingsTypes
        + DeviceLayerTypes
        + TcpBindingsTypes
        + FilterBindingsTypes
        + IcmpEchoBindingsTypes
        + IcmpBindingsTypes
        + MulticastForwardingBindingsTypes
        + RawIpSocketsBindingsTypes
        + UdpBindingsTypes
        + TimerBindingsTypes<DispatchId = TimerId<Self>>
{
}

/// The execution context provided by bindings for a given IP version.
pub trait IpBindingsContext<I: IpExt>:
    BindingsTypes
    + RngContext
    + UdpBindingsContext<I, DeviceId<Self>>
    + TcpBindingsContext
    + FilterBindingsContext
    + IcmpBindingsContext
    + IcmpEchoBindingsContext<I, DeviceId<Self>>
    + MulticastForwardingBindingsContext<I, DeviceId<Self>>
    + RawIpSocketsBindingsContext<I, DeviceId<Self>>
    + IpDeviceBindingsContext<I, DeviceId<Self>>
    + IpLayerBindingsContext<I, DeviceId<Self>>
    + NudBindingsContext<I, EthernetLinkDevice, EthernetDeviceId<Self>>
    + device::DeviceLayerEventDispatcher
    + device::socket::DeviceSocketBindingsContext<DeviceId<Self>>
    + ReferenceNotifiers
    + TracingContext
    + 'static
{
}

impl<I, BC> IpBindingsContext<I> for BC
where
    I: IpExt,
    BC: BindingsTypes
        + RngContext
        + UdpBindingsContext<I, DeviceId<Self>>
        + TcpBindingsContext
        + FilterBindingsContext
        + IcmpBindingsContext
        + IcmpEchoBindingsContext<I, DeviceId<Self>>
        + MulticastForwardingBindingsContext<I, DeviceId<Self>>
        + RawIpSocketsBindingsContext<I, DeviceId<Self>>
        + IpDeviceBindingsContext<I, DeviceId<Self>>
        + IpLayerBindingsContext<I, DeviceId<Self>>
        + NudBindingsContext<I, EthernetLinkDevice, EthernetDeviceId<Self>>
        + device::DeviceLayerEventDispatcher
        + device::socket::DeviceSocketBindingsContext<DeviceId<Self>>
        + ReferenceNotifiers
        + TracingContext
        + 'static,
{
}

/// The execution context provided by bindings.
pub trait BindingsContext: IpBindingsContext<Ipv4> + IpBindingsContext<Ipv6> {}
impl<BC> BindingsContext for BC where BC: IpBindingsContext<Ipv4> + IpBindingsContext<Ipv6> {}