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