netstack3_ip/
lib.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//! Netstack3 core IP layer.
6//!
7//! This crate contains the IP layer for netstack3.
8
9#![no_std]
10#![warn(missing_docs, unreachable_patterns, clippy::useless_conversion, clippy::redundant_clone)]
11
12extern crate fakealloc as alloc;
13
14#[path = "."]
15mod internal {
16    #[macro_use]
17    pub(super) mod path_mtu;
18
19    pub(super) mod api;
20    pub(super) mod base;
21    pub(super) mod counters;
22    pub(super) mod device;
23    pub(super) mod fragmentation;
24    pub(super) mod gmp;
25    pub(super) mod icmp;
26    pub(super) mod ipv6;
27    pub(super) mod local_delivery;
28    pub(super) mod multicast_forwarding;
29    pub(super) mod raw;
30    pub(super) mod reassembly;
31    pub(super) mod routing;
32    pub(super) mod sas;
33    pub(super) mod socket;
34    pub(super) mod types;
35    pub(super) mod uninstantiable;
36}
37
38/// Definitions for devices at the IP layer.
39pub mod device {
40    pub use crate::internal::device::api::{
41        AddIpAddrSubnetError, AddrSubnetAndManualConfigEither, DeviceIpAnyApi, DeviceIpApi,
42        SetIpAddressPropertiesError,
43    };
44    pub use crate::internal::device::config::{
45        IpDeviceConfigurationAndFlags, IpDeviceConfigurationHandler, IpDeviceConfigurationUpdate,
46        Ipv4DeviceConfigurationUpdate, Ipv6DeviceConfigurationUpdate, UpdateIpConfigurationError,
47    };
48    pub use crate::internal::device::dad::{
49        DadAddressContext, DadAddressStateRef, DadContext, DadEvent, DadHandler, DadStateRef,
50        DadTimerId,
51    };
52    pub use crate::internal::device::opaque_iid::{IidSecret, OpaqueIid, OpaqueIidNonce};
53    pub use crate::internal::device::route_discovery::{
54        Ipv6DiscoveredRoute, Ipv6DiscoveredRoutesContext, Ipv6RouteDiscoveryBindingsContext,
55        Ipv6RouteDiscoveryContext, Ipv6RouteDiscoveryState,
56    };
57    pub use crate::internal::device::router_solicitation::{
58        RsContext, RsHandler, RsState, RsTimerId, MAX_RTR_SOLICITATION_DELAY,
59        RTR_SOLICITATION_INTERVAL,
60    };
61    pub use crate::internal::device::slaac::{
62        IidGenerationConfiguration, InnerSlaacTimerId, SlaacAddressEntry, SlaacAddressEntryMut,
63        SlaacAddresses, SlaacBindingsContext, SlaacConfigAndState, SlaacConfiguration,
64        SlaacConfigurationUpdate, SlaacContext, SlaacCounters, SlaacState, SlaacTimerId,
65        StableSlaacAddressConfiguration, TemporarySlaacAddressConfiguration,
66        SLAAC_MIN_REGEN_ADVANCE,
67    };
68    pub use crate::internal::device::state::{
69        AddressId, AddressIdIter, AssignedAddressState, CommonAddressConfig,
70        CommonAddressProperties, DefaultHopLimit, DualStackIpDeviceState, IpDeviceAddresses,
71        IpDeviceConfiguration, IpDeviceFlags, IpDeviceMulticastGroups, IpDeviceStateBindingsTypes,
72        IpDeviceStateIpExt, Ipv4AddrConfig, Ipv4AddressEntry, Ipv4AddressState,
73        Ipv4DeviceConfiguration, Ipv6AddrConfig, Ipv6AddrManualConfig, Ipv6AddrSlaacConfig,
74        Ipv6AddressEntry, Ipv6AddressFlags, Ipv6AddressState, Ipv6DadState,
75        Ipv6DeviceConfiguration, Ipv6NetworkLearnedParameters, Lifetime, PreferredLifetime,
76        PrimaryAddressId, SlaacConfig, TemporarySlaacConfig, WeakAddressId,
77    };
78    pub use crate::internal::device::{
79        add_ip_addr_subnet_with_config, clear_ipv4_device_state, clear_ipv6_device_state,
80        del_ip_addr_inner, get_ipv4_addr_subnet, get_ipv6_hop_limit, is_ip_device_enabled,
81        is_ip_multicast_forwarding_enabled, is_ip_unicast_forwarding_enabled, join_ip_multicast,
82        join_ip_multicast_with_config, leave_ip_multicast, leave_ip_multicast_with_config,
83        receive_igmp_packet, AddressRemovedReason, DelIpAddr, IpAddressIdSpec,
84        IpAddressIdSpecContext, IpAddressState, IpDeviceAddressContext, IpDeviceBindingsContext,
85        IpDeviceConfigurationContext, IpDeviceEvent, IpDeviceIpExt, IpDeviceSendContext,
86        IpDeviceStateContext, IpDeviceTimerId, Ipv4DeviceTimerId, Ipv6DeviceConfigurationContext,
87        Ipv6DeviceContext, Ipv6DeviceHandler, Ipv6DeviceTimerId, Ipv6LinkLayerAddr,
88        WithIpDeviceConfigurationMutInner, WithIpv6DeviceConfigurationMutInner,
89    };
90
91    /// IP device test utilities.
92    #[cfg(any(test, feature = "testutils"))]
93    pub mod testutil {
94        pub use crate::internal::device::slaac::testutil::{
95            calculate_slaac_addr_sub, collect_slaac_timers_integration,
96        };
97        pub use crate::internal::device::testutil::{
98            with_assigned_ipv4_addr_subnets, with_assigned_ipv6_addr_subnets,
99        };
100    }
101}
102
103/// Group management protocols.
104pub mod gmp {
105    pub use crate::internal::gmp::igmp::{
106        IgmpConfigMode, IgmpContext, IgmpContextMarker, IgmpCounters, IgmpSendContext,
107        IgmpStateContext, IgmpTimerId, IgmpTypeLayout, IGMP_DEFAULT_UNSOLICITED_REPORT_INTERVAL,
108    };
109    pub use crate::internal::gmp::mld::{
110        MldConfigMode, MldContext, MldContextMarker, MldCounters, MldSendContext, MldStateContext,
111        MldTimerId, MldTypeLayout, MLD_DEFAULT_UNSOLICITED_REPORT_INTERVAL,
112    };
113    pub use crate::internal::gmp::{
114        GmpGroupState, GmpHandler, GmpQueryHandler, GmpState, GmpStateRef, GmpTimerId, IpExt,
115        MulticastGroupSet,
116    };
117}
118
119/// The Internet Control Message Protocol (ICMP).
120pub mod icmp {
121    pub use crate::internal::icmp::{
122        send_icmpv4_host_unreachable, send_icmpv6_address_unreachable, send_ndp_packet,
123        EchoTransportContextMarker, IcmpBindingsContext, IcmpBindingsTypes, IcmpIpTransportContext,
124        IcmpRxCounters, IcmpRxCountersInner, IcmpState, IcmpStateContext, IcmpTxCounters,
125        IcmpTxCountersInner, Icmpv4StateBuilder, InnerIcmpContext, InnerIcmpv4Context, NdpCounters,
126        NdpRxCounters, NdpTxCounters, REQUIRED_NDP_IP_PACKET_HOP_LIMIT,
127    };
128
129    /// ICMP test utilities.
130    #[cfg(any(test, feature = "testutils"))]
131    pub mod testutil {
132        pub use crate::internal::icmp::testutil::{
133            neighbor_advertisement_ip_packet, neighbor_solicitation_ip_packet,
134        };
135    }
136}
137
138/// Marker traits controlling IP context behavior.
139pub mod marker {
140    pub use crate::internal::base::{UseIpSocketContextBlanket, UseTransportIpContextBlanket};
141    pub use crate::internal::socket::{
142        OptionDelegationMarker, UseDeviceIpSocketHandlerBlanket, UseIpSocketHandlerBlanket,
143    };
144}
145
146/// Neighbor Unreachability Detection.
147pub mod nud {
148    pub use crate::internal::device::nud::api::{
149        NeighborApi, NeighborRemovalError, StaticNeighborInsertionError,
150    };
151    pub use crate::internal::device::nud::{
152        confirm_reachable, ConfirmationFlags, Delay, DelegateNudContext, DynamicNeighborState,
153        DynamicNeighborUpdateSource, Event, EventDynamicState, EventKind, EventState, Incomplete,
154        LinkResolutionContext, LinkResolutionNotifier, LinkResolutionResult, NeighborState,
155        NudBindingsContext, NudBindingsTypes, NudConfigContext, NudContext, NudCounters,
156        NudCountersInner, NudHandler, NudIcmpContext, NudIpHandler, NudSenderContext, NudState,
157        NudTimerId, NudUserConfig, NudUserConfigUpdate, Reachable, Stale, UseDelegateNudContext,
158        MAX_ENTRIES,
159    };
160    pub use crate::internal::device::state::RETRANS_TIMER_DEFAULT;
161
162    /// NUD test utilities.
163    #[cfg(any(test, feature = "testutils"))]
164    pub mod testutil {
165        pub use crate::internal::device::nud::testutil::{
166            assert_dynamic_neighbor_state, assert_dynamic_neighbor_with_addr,
167            assert_neighbor_unknown, FakeLinkResolutionNotifier,
168        };
169    }
170}
171
172/// IP Layer definitions supporting sockets.
173pub mod socket {
174    pub use crate::internal::socket::{
175        DefaultIpSocketOptions, DelegatedRouteResolutionOptions, DelegatedSendOptions,
176        DeviceIpSocketHandler, IpSock, IpSockCreateAndSendError, IpSockCreationError,
177        IpSockDefinition, IpSockSendError, IpSocketBindingsContext, IpSocketContext,
178        IpSocketHandler, MmsError, RouteResolutionOptions, SendOneShotIpPacketError, SendOptions,
179        SocketHopLimits,
180    };
181
182    /// IP Socket test utilities.
183    #[cfg(any(test, feature = "testutils"))]
184    pub mod testutil {
185        pub use crate::internal::socket::testutil::{
186            FakeDeviceConfig, FakeDualStackIpSocketCtx, FakeIpSocketCtx, InnerFakeIpSocketCtx,
187        };
188    }
189}
190
191/// Multicast Forwarding
192pub mod multicast_forwarding {
193    pub use crate::internal::multicast_forwarding::api::{
194        MulticastForwardingApi, MulticastForwardingDisabledError,
195    };
196    pub use crate::internal::multicast_forwarding::counters::MulticastForwardingCounters;
197    pub use crate::internal::multicast_forwarding::packet_queue::MulticastForwardingPendingPackets;
198    pub use crate::internal::multicast_forwarding::route::{
199        ForwardMulticastRouteError, MulticastRoute, MulticastRouteKey, MulticastRouteStats,
200        MulticastRouteTarget, MulticastRouteTargets,
201    };
202    pub use crate::internal::multicast_forwarding::state::{
203        MulticastForwardingEnabledState, MulticastForwardingPendingPacketsContext,
204        MulticastForwardingState, MulticastForwardingStateContext, MulticastRouteTable,
205        MulticastRouteTableContext,
206    };
207    pub use crate::internal::multicast_forwarding::{
208        MulticastForwardingBindingsContext, MulticastForwardingBindingsTypes,
209        MulticastForwardingDeviceContext, MulticastForwardingEvent, MulticastForwardingTimerId,
210    };
211}
212
213/// Raw IP sockets.
214pub mod raw {
215    pub use crate::internal::raw::counters::RawIpSocketCounters;
216    pub use crate::internal::raw::filter::RawIpSocketIcmpFilter;
217    pub use crate::internal::raw::protocol::RawIpSocketProtocol;
218    pub use crate::internal::raw::state::{RawIpSocketLockedState, RawIpSocketState};
219    pub use crate::internal::raw::{
220        RawIpSocketApi, RawIpSocketIcmpFilterError, RawIpSocketId, RawIpSocketMap,
221        RawIpSocketMapContext, RawIpSocketSendToError, RawIpSocketStateContext,
222        RawIpSocketsBindingsContext, RawIpSocketsBindingsTypes, WeakRawIpSocketId,
223    };
224}
225
226pub use internal::api::{RouteResolveOptions, RoutesAnyApi, RoutesApi};
227pub use internal::base::{
228    gen_ip_packet_id, receive_ipv4_packet, receive_ipv4_packet_action, receive_ipv6_packet,
229    receive_ipv6_packet_action, resolve_output_route_to_destination, AddressStatus,
230    BaseTransportIpContext, DeviceIpLayerMetadata, DropReason, FilterHandlerProvider, HopLimits,
231    IpDeviceConfirmReachableContext, IpDeviceContext, IpDeviceEgressStateContext,
232    IpDeviceIngressStateContext, IpDeviceMtuContext, IpLayerBindingsContext, IpLayerContext,
233    IpLayerEvent, IpLayerHandler, IpLayerIpExt, IpLayerTimerId, IpPacketDestination,
234    IpRouteTableContext, IpRouteTablesContext, IpSendFrameError, IpSendFrameErrorReason,
235    IpStateContext, IpStateInner, IpTransportContext, IpTransportDispatchContext,
236    Ipv4PresentAddressStatus, Ipv4State, Ipv4StateBuilder, Ipv6PresentAddressStatus, Ipv6State,
237    Ipv6StateBuilder, MulticastMembershipHandler, NdpBindingsContext, ReceivePacketAction,
238    ResolveRouteError, RouterAdvertisementEvent, RoutingTableId, SendIpPacketMeta,
239    TransportIpContext, TransportReceiveError, DEFAULT_HOP_LIMITS, DEFAULT_TTL,
240    IPV6_DEFAULT_SUBNET,
241};
242pub use internal::counters::{IpCounters, Ipv6RxCounters};
243pub use internal::fragmentation::FragmentationCounters;
244pub use internal::local_delivery::{
245    IpHeaderInfo, LocalDeliveryPacketInfo, ReceiveIpPacketMeta, TransparentLocalDelivery,
246};
247pub use internal::path_mtu::{PmtuCache, PmtuContext};
248pub use internal::reassembly::{FragmentContext, FragmentTimerId, IpPacketFragmentCache};
249pub use internal::routing::rules::{
250    BoundDeviceMatcher, MarkMatcher, MarkMatchers, Rule, RuleAction, RuleMatcher, RulesTable,
251    TrafficOriginMatcher,
252};
253pub use internal::routing::{
254    request_context_add_route, request_context_del_routes, AddRouteError, IpRoutingDeviceContext,
255    NonLocalSrcAddrPolicy, PacketOrigin, RoutingTable,
256};
257pub use internal::sas::IpSasHandler;
258pub use internal::types::{
259    AddableEntry, AddableEntryEither, AddableMetric, Destination, Entry, EntryEither, Generation,
260    InternalForwarding, Metric, NextHop, RawMetric, ResolvedRoute, RoutableIpAddr,
261};
262
263/// IP layer test utilities.
264#[cfg(any(test, feature = "testutils"))]
265pub mod testutil {
266    pub use crate::internal::base::testutil::DualStackSendIpPacketMeta;
267    pub use crate::internal::counters::testutil::IpCounterExpectations;
268    pub use crate::internal::local_delivery::testutil::FakeIpHeaderInfo;
269    pub use crate::internal::routing::testutil::{
270        add_route, del_device_routes, del_routes_to_subnet, set_rules,
271    };
272}