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