Skip to main content

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, IcmpError,
135        IcmpErrorHandler, IcmpHandlerIpExt, IcmpIpTransportContext, IcmpState, IcmpStateContext,
136        Icmpv4Error, Icmpv4StateBuilder, Icmpv6Error, InnerIcmpContext, InnerIcmpv4Context,
137        NdpCounters, NdpMessage, NdpRxCounters, NdpTxCounters, REQUIRED_NDP_IP_PACKET_HOP_LIMIT,
138        send_ndp_packet,
139    };
140
141    /// ICMP test utilities.
142    #[cfg(any(test, feature = "testutils"))]
143    pub mod testutil {
144        pub use crate::internal::icmp::testutil::{
145            neighbor_advertisement_ip_packet, neighbor_solicitation_ip_packet,
146        };
147    }
148}
149
150/// Marker traits controlling IP context behavior.
151pub mod marker {
152    pub use crate::internal::base::{UseIpSocketContextBlanket, UseTransportIpContextBlanket};
153    pub use crate::internal::socket::{
154        OptionDelegationMarker, UseDeviceIpSocketHandlerBlanket, UseIpSocketHandlerBlanket,
155    };
156}
157
158/// Neighbor Unreachability Detection.
159pub mod nud {
160    pub use crate::internal::device::nud::api::{
161        NeighborApi, NeighborRemovalError, StaticNeighborInsertionError, TriggerNeighborProbeError,
162    };
163    pub use crate::internal::device::nud::{
164        ConfirmationFlags, DEFAULT_RETRANS_TIMER, Delay, DelegateNudContext, DynamicNeighborState,
165        DynamicNeighborUpdateSource, Event, EventDynamicState, EventKind, EventState, Incomplete,
166        LinkResolutionContext, LinkResolutionNotifier, LinkResolutionResult, MAX_ENTRIES,
167        NeighborState, NudBindingsContext, NudBindingsTypes, NudConfigContext, NudContext,
168        NudCounters, NudCountersInner, NudHandler, NudIcmpContext, NudIpHandler, NudSenderContext,
169        NudState, NudTimerId, NudUserConfig, NudUserConfigUpdate, Reachable, Stale,
170        UseDelegateNudContext, confirm_reachable,
171    };
172
173    /// NUD test utilities.
174    #[cfg(any(test, feature = "testutils"))]
175    pub mod testutil {
176        pub use crate::internal::device::nud::testutil::{
177            FakeLinkResolutionNotifier, assert_dynamic_neighbor_state,
178            assert_dynamic_neighbor_with_addr, assert_neighbor_unknown,
179        };
180    }
181}
182
183/// IP Layer definitions supporting sockets.
184pub mod socket {
185    pub use crate::internal::socket::{
186        DefaultIpSocketOptions, DelegatedRouteResolutionOptions, DelegatedSendOptions,
187        DeviceIpSocketHandler, IpSock, IpSockCreateAndSendError, IpSockCreationError,
188        IpSockDefinition, IpSockSendError, IpSocketArgs, IpSocketBindingsContext, IpSocketContext,
189        IpSocketHandler, MmsError, RouteResolutionOptions, SendOneShotIpPacketError, SendOptions,
190        SocketHopLimits,
191    };
192
193    /// IP Socket test utilities.
194    #[cfg(any(test, feature = "testutils"))]
195    pub mod testutil {
196        pub use crate::internal::socket::testutil::{
197            FakeDeviceConfig, FakeDualStackIpSocketCtx, FakeIpSocketCtx, InnerFakeIpSocketCtx,
198        };
199    }
200}
201
202/// Multicast Forwarding
203pub mod multicast_forwarding {
204    pub use crate::internal::multicast_forwarding::api::{
205        MulticastForwardingApi, MulticastForwardingDisabledError,
206    };
207    pub use crate::internal::multicast_forwarding::counters::MulticastForwardingCounters;
208    pub use crate::internal::multicast_forwarding::packet_queue::MulticastForwardingPendingPackets;
209    pub use crate::internal::multicast_forwarding::route::{
210        ForwardMulticastRouteError, MulticastRoute, MulticastRouteKey, MulticastRouteStats,
211        MulticastRouteTarget, MulticastRouteTargets,
212    };
213    pub use crate::internal::multicast_forwarding::state::{
214        MulticastForwardingEnabledState, MulticastForwardingPendingPacketsContext,
215        MulticastForwardingState, MulticastForwardingStateContext, MulticastRouteTable,
216        MulticastRouteTableContext,
217    };
218    pub use crate::internal::multicast_forwarding::{
219        MulticastForwardingBindingsContext, MulticastForwardingBindingsTypes,
220        MulticastForwardingDeviceContext, MulticastForwardingEvent, MulticastForwardingTimerId,
221    };
222}
223
224/// Raw IP sockets.
225pub mod raw {
226    pub use crate::internal::raw::counters::RawIpSocketCounters;
227    pub use crate::internal::raw::filter::RawIpSocketIcmpFilter;
228    pub use crate::internal::raw::protocol::RawIpSocketProtocol;
229    pub use crate::internal::raw::state::{RawIpSocketLockedState, RawIpSocketState};
230    pub use crate::internal::raw::{
231        RawIpSocketApi, RawIpSocketIcmpFilterError, RawIpSocketId, RawIpSocketMap,
232        RawIpSocketMapContext, RawIpSocketSendToError, RawIpSocketStateContext,
233        RawIpSocketsBindingsContext, RawIpSocketsBindingsTypes, ReceivePacketError,
234        WeakRawIpSocketId,
235    };
236}
237
238pub use internal::api::{RouteResolveOptions, RoutesAnyApi, RoutesApi, RoutesApiTableId};
239pub use internal::base::{
240    AddressStatus, BaseRoutingTableState, BaseTransportIpContext, DEFAULT_HOP_LIMITS, DEFAULT_TTL,
241    DeviceIpLayerMetadata, DropReason, FilterHandlerProvider, HopLimits, IPV6_DEFAULT_SUBNET,
242    IpDeviceConfirmReachableContext, IpDeviceContext, IpDeviceEgressStateContext,
243    IpDeviceIngressStateContext, IpDeviceMtuContext, IpLayerBindingsContext, IpLayerContext,
244    IpLayerEvent, IpLayerHandler, IpLayerIpExt, IpLayerTimerId, IpPacketDestination,
245    IpRouteTableContext, IpRouteTablesContext, IpSendFrameError, IpSendFrameErrorReason,
246    IpStateContext, IpStateInner, IpTransportContext, IpTransportDispatchContext,
247    Ipv4PresentAddressStatus, Ipv4State, Ipv4StateBuilder, Ipv6PresentAddressStatus, Ipv6State,
248    Ipv6StateBuilder, MarksBindingsContext, MulticastMembershipHandler, NdpBindingsContext,
249    ReceivePacketAction, ResolveRouteError, RouterAdvertisementEvent, RoutingTableCookie,
250    RoutingTableId, SendIpPacketMeta, SocketMetadata, TransportIpContext, gen_ip_packet_id,
251    receive_ipv4_packet, receive_ipv4_packet_action, receive_ipv6_packet,
252    receive_ipv6_packet_action, resolve_output_route_to_destination,
253};
254pub use internal::counters::{IpCounters, Ipv6RxCounters};
255pub use internal::fragmentation::FragmentationCounters;
256pub use internal::local_delivery::{
257    IpHeaderInfo, LocalDeliveryPacketInfo, ReceiveIpPacketMeta, TransparentLocalDelivery,
258};
259pub use internal::path_mtu::{PmtuCache, PmtuContext};
260pub use internal::reassembly::{FragmentContext, FragmentTimerId, IpPacketFragmentCache};
261pub use internal::routing::rules::{
262    Rule, RuleAction, RuleMatcher, RulesTable, TrafficOriginMatcher,
263};
264pub use internal::routing::{
265    AddRouteError, IpRoutingBindingsTypes, IpRoutingDeviceContext, NonLocalSrcAddrPolicy,
266    PacketOrigin, RoutingTable, request_context_add_route, request_context_del_routes,
267};
268pub use internal::sas::IpSasHandler;
269pub use internal::types::{
270    AddableEntry, AddableEntryEither, AddableMetric, Destination, Entry, EntryEither, Generation,
271    InternalForwarding, Metric, NextHop, RawMetric, ResolvedRoute, RoutableIpAddr,
272};
273
274/// IP layer test utilities.
275#[cfg(any(test, feature = "testutils"))]
276pub mod testutil {
277    pub use crate::internal::base::testutil::DualStackSendIpPacketMeta;
278    pub use crate::internal::counters::testutil::IpCounterExpectations;
279    pub use crate::internal::local_delivery::testutil::FakeIpHeaderInfo;
280    pub use crate::internal::routing::testutil::{
281        add_route, del_device_routes, del_routes_to_subnet, set_rules,
282    };
283}