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