netstack3_core/
marker.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
5//! Marker traits with blanket implementations.
6//!
7//! Traits in this module exist to be exported as markers to bindings without
8//! exposing the internal traits directly.
9
10use net_types::ip::{Ipv4, Ipv6};
11use netstack3_base::{
12    AnyDevice, DeviceIdContext, InstantBindingsTypes, ReferenceNotifiers, RngContext,
13    TimerBindingsTypes, TxMetadataBindingsTypes,
14};
15use netstack3_datagram as datagram;
16use netstack3_device::ethernet::{
17    EthernetDeviceEventBindingsContext, EthernetDeviceId, EthernetLinkDevice, EthernetWeakDeviceId,
18};
19use netstack3_device::{self as device, DeviceId, DeviceLayerTypes, WeakDeviceId};
20use netstack3_filter::{FilterBindingsContext, FilterBindingsTypes, SocketOpsFilterBindingContext};
21use netstack3_icmp_echo::{IcmpEchoBindingsContext, IcmpEchoBindingsTypes, IcmpEchoStateContext};
22use netstack3_ip::device::{
23    IpDeviceBindingsContext, IpDeviceConfigurationContext, IpDeviceConfigurationHandler,
24    IpDeviceIpExt,
25};
26use netstack3_ip::icmp::{IcmpBindingsContext, IcmpBindingsTypes};
27use netstack3_ip::multicast_forwarding::{
28    MulticastForwardingBindingsContext, MulticastForwardingBindingsTypes,
29    MulticastForwardingStateContext,
30};
31use netstack3_ip::nud::{NudBindingsContext, NudContext};
32use netstack3_ip::raw::{
33    RawIpSocketMapContext, RawIpSocketStateContext, RawIpSocketsBindingsContext,
34    RawIpSocketsBindingsTypes,
35};
36use netstack3_ip::socket::IpSocketContext;
37use netstack3_ip::{
38    self as ip, IpLayerBindingsContext, IpLayerContext, IpLayerIpExt, IpRoutingBindingsTypes,
39    NdpBindingsContext,
40};
41use netstack3_tcp::{self as tcp, TcpBindingsContext, TcpBindingsTypes, TcpContext};
42use netstack3_udp::{self as udp, UdpBindingsContext, UdpBindingsTypes, UdpCounterContext};
43
44use crate::TimerId;
45use crate::transport::CoreTxMetadata;
46
47/// A marker for extensions to IP types.
48///
49/// This trait acts as a marker for [`BaseIpExt`] for both `Self` and
50/// `Self::OtherVersion`.
51pub trait IpExt: BaseIpExt + datagram::DualStackIpExt<OtherVersion: BaseIpExt> {}
52
53impl<I> IpExt for I where I: BaseIpExt + datagram::DualStackIpExt<OtherVersion: BaseIpExt> {}
54
55/// A marker for extensions to IP types.
56pub trait BaseIpExt:
57    IpLayerIpExt
58    + IpDeviceIpExt
59    + netstack3_base::IcmpIpExt
60    + ip::device::IpDeviceIpExt
61    + tcp::DualStackIpExt
62    + datagram::DualStackIpExt
63{
64}
65
66impl<I> BaseIpExt for I where
67    I: ip::IpLayerIpExt
68        + IpDeviceIpExt
69        + netstack3_base::IcmpIpExt
70        + ip::device::IpDeviceIpExt
71        + tcp::DualStackIpExt
72        + datagram::DualStackIpExt
73{
74}
75
76/// A marker trait for core context implementations.
77///
78/// This trait allows bindings to express trait bounds on routines that have IP
79/// type parameters. It is an umbrella of all the core contexts that must be
80/// implemented by [`crate::context::UnlockedCoreCtx`] to satisfy all the API
81/// objects vended by [`crate::api::CoreApi`].
82pub trait CoreContext<I, BC>:
83    udp::StateContext<I, BC>
84    + UdpCounterContext<I, WeakDeviceId<BC>, BC>
85    + TcpContext<I, BC>
86    + IcmpEchoStateContext<I, BC>
87    + ip::icmp::IcmpStateContext
88    + IpLayerContext<I, BC>
89    + NudContext<I, EthernetLinkDevice, BC>
90    + IpDeviceConfigurationContext<I, BC>
91    + IpDeviceConfigurationHandler<I, BC>
92    + IpSocketContext<I, BC>
93    + DeviceIdContext<AnyDevice, DeviceId = DeviceId<BC>, WeakDeviceId = WeakDeviceId<BC>>
94    + DeviceIdContext<
95        EthernetLinkDevice,
96        DeviceId = EthernetDeviceId<BC>,
97        WeakDeviceId = EthernetWeakDeviceId<BC>,
98    > + RawIpSocketMapContext<I, BC>
99    + RawIpSocketStateContext<I, BC>
100    + MulticastForwardingStateContext<I, BC>
101where
102    I: IpExt,
103    BC: IpBindingsContext<I>,
104{
105}
106
107impl<I, BC, O> CoreContext<I, BC> for O
108where
109    I: IpExt,
110    BC: IpBindingsContext<I>,
111    O: udp::StateContext<I, BC>
112        + UdpCounterContext<I, WeakDeviceId<BC>, BC>
113        + TcpContext<I, BC>
114        + IcmpEchoStateContext<I, BC>
115        + ip::icmp::IcmpStateContext
116        + IpLayerContext<I, BC>
117        + NudContext<I, EthernetLinkDevice, BC>
118        + IpDeviceConfigurationContext<I, BC>
119        + IpDeviceConfigurationHandler<I, BC>
120        + IpSocketContext<I, BC>
121        + DeviceIdContext<AnyDevice, DeviceId = DeviceId<BC>, WeakDeviceId = WeakDeviceId<BC>>
122        + DeviceIdContext<
123            EthernetLinkDevice,
124            DeviceId = EthernetDeviceId<BC>,
125            WeakDeviceId = EthernetWeakDeviceId<BC>,
126        > + RawIpSocketMapContext<I, BC>
127        + RawIpSocketStateContext<I, BC>
128        + MulticastForwardingStateContext<I, BC>,
129{
130}
131
132/// A marker trait for all the types stored in core objects that are specified
133/// by bindings.
134pub trait BindingsTypes:
135    InstantBindingsTypes
136    + DeviceLayerTypes
137    + TcpBindingsTypes
138    + FilterBindingsTypes
139    + IcmpEchoBindingsTypes
140    + IcmpBindingsTypes
141    + MulticastForwardingBindingsTypes
142    + RawIpSocketsBindingsTypes
143    + UdpBindingsTypes
144    + TimerBindingsTypes<DispatchId = TimerId<Self>>
145    + TxMetadataBindingsTypes<TxMetadata = CoreTxMetadata<Self>>
146    + IpRoutingBindingsTypes
147{
148}
149
150impl<O> BindingsTypes for O where
151    O: InstantBindingsTypes
152        + DeviceLayerTypes
153        + TcpBindingsTypes
154        + FilterBindingsTypes
155        + IcmpEchoBindingsTypes
156        + IcmpBindingsTypes
157        + MulticastForwardingBindingsTypes
158        + RawIpSocketsBindingsTypes
159        + UdpBindingsTypes
160        + TimerBindingsTypes<DispatchId = TimerId<Self>>
161        + TxMetadataBindingsTypes<TxMetadata = CoreTxMetadata<Self>>
162        + IpRoutingBindingsTypes
163{
164}
165
166/// The execution context provided by bindings for a given IP version.
167pub trait IpBindingsContext<I: IpExt>:
168    BindingsTypes
169    + RngContext
170    + UdpBindingsContext<I, DeviceId<Self>>
171    + TcpBindingsContext<DeviceId<Self>>
172    + FilterBindingsContext
173    + SocketOpsFilterBindingContext<DeviceId<Self>>
174    + IcmpBindingsContext
175    + IcmpEchoBindingsContext<I, DeviceId<Self>>
176    + MulticastForwardingBindingsContext<I, DeviceId<Self>>
177    + RawIpSocketsBindingsContext<I, DeviceId<Self>>
178    + IpDeviceBindingsContext<I, DeviceId<Self>>
179    + IpLayerBindingsContext<I, DeviceId<Self>>
180    + NudBindingsContext<I, EthernetLinkDevice, EthernetDeviceId<Self>>
181    + device::DeviceLayerEventDispatcher
182    + device::socket::DeviceSocketBindingsContext<DeviceId<Self>>
183    + ReferenceNotifiers
184    + 'static
185{
186}
187
188impl<I, BC> IpBindingsContext<I> for BC
189where
190    I: IpExt,
191    BC: BindingsTypes
192        + RngContext
193        + UdpBindingsContext<I, DeviceId<Self>>
194        + TcpBindingsContext<DeviceId<Self>>
195        + FilterBindingsContext
196        + SocketOpsFilterBindingContext<DeviceId<Self>>
197        + IcmpBindingsContext
198        + IcmpEchoBindingsContext<I, DeviceId<Self>>
199        + MulticastForwardingBindingsContext<I, DeviceId<Self>>
200        + RawIpSocketsBindingsContext<I, DeviceId<Self>>
201        + IpDeviceBindingsContext<I, DeviceId<Self>>
202        + IpLayerBindingsContext<I, DeviceId<Self>>
203        + NudBindingsContext<I, EthernetLinkDevice, EthernetDeviceId<Self>>
204        + device::DeviceLayerEventDispatcher
205        + device::socket::DeviceSocketBindingsContext<DeviceId<Self>>
206        + ReferenceNotifiers
207        + 'static,
208{
209}
210
211/// The execution context provided by bindings.
212pub trait BindingsContext:
213    IpBindingsContext<Ipv4>
214    + IpBindingsContext<Ipv6>
215    + NdpBindingsContext<DeviceId<Self>>
216    + EthernetDeviceEventBindingsContext<EthernetDeviceId<Self>>
217{
218}
219impl<BC> BindingsContext for BC where
220    BC: IpBindingsContext<Ipv4>
221        + IpBindingsContext<Ipv6>
222        + NdpBindingsContext<DeviceId<Self>>
223        + EthernetDeviceEventBindingsContext<EthernetDeviceId<Self>>
224{
225}