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