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