Skip to main content

netstack3_device/
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 device layer.
6//!
7//! This crate contains the device 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    pub(super) mod api;
23    pub(super) mod arp;
24    pub(super) mod base;
25    pub(super) mod blackhole;
26    pub(super) mod config;
27    pub(super) mod ethernet;
28    pub(super) mod gro;
29    pub(super) mod id;
30    pub(super) mod loopback;
31    pub(super) mod pure_ip;
32    pub(super) mod queue;
33    pub(super) mod socket;
34    pub(super) mod state;
35}
36
37/// Blackhole devices.
38pub mod blackhole {
39    pub use crate::internal::base::BlackholeDeviceCounters;
40    pub use crate::internal::blackhole::{
41        BlackholeDevice, BlackholeDeviceId, BlackholePrimaryDeviceId, BlackholeWeakDeviceId,
42    };
43}
44
45/// Ethernet devices.
46pub mod ethernet {
47    pub use crate::internal::base::EthernetDeviceCounters;
48    pub use crate::internal::ethernet::{
49        DynamicEthernetDeviceState, EthernetCreationProperties, EthernetDeviceEvent,
50        EthernetDeviceEventBindingsContext, EthernetIpLinkDeviceDynamicStateContext,
51        EthernetIpLinkDeviceStaticStateContext, EthernetLinkDevice, EthernetTimerId,
52        MaxEthernetFrameSize, RecvEthernetFrameMeta, StaticEthernetDeviceState, get_mac, get_mtu,
53        join_link_multicast, leave_link_multicast, send_as_ethernet_frame_to_dst, send_ip_frame,
54        set_mtu,
55    };
56    pub use crate::internal::id::{
57        EthernetDeviceId, EthernetPrimaryDeviceId, EthernetWeakDeviceId,
58    };
59}
60
61/// Loopback devices.
62pub mod loopback {
63    pub use crate::internal::loopback::{
64        LoopbackCreationProperties, LoopbackDevice, LoopbackDeviceId, LoopbackPrimaryDeviceId,
65        LoopbackRxQueueMeta, LoopbackTxQueueMeta, LoopbackWeakDeviceId, send_ip_frame,
66    };
67}
68
69/// Marker traits controlling Device context behavior.
70pub mod marker {
71    pub use crate::internal::ethernet::UseArpFrameMetadataBlanket;
72}
73
74/// Pure IP devices.
75pub mod pure_ip {
76    pub use crate::internal::base::PureIpDeviceCounters;
77    pub use crate::internal::pure_ip::{
78        DynamicPureIpDeviceState, PureIpDevice, PureIpDeviceCreationProperties, PureIpDeviceId,
79        PureIpDeviceReceiveFrameMetadata, PureIpDeviceStateContext,
80        PureIpDeviceTxQueueFrameMetadata, PureIpHeaderParams, PureIpPrimaryDeviceId,
81        PureIpWeakDeviceId, get_mtu, send_ip_frame, set_mtu,
82    };
83}
84
85/// Device sockets.
86pub mod socket {
87    pub use crate::internal::socket::{
88        AllSockets, AnyDeviceSockets, DeviceSocketAccessor, DeviceSocketApi,
89        DeviceSocketBindingsContext, DeviceSocketContext, DeviceSocketCounters, DeviceSocketId,
90        DeviceSocketMetadata, DeviceSocketTypes, DeviceSockets, EthernetFrame,
91        EthernetHeaderParams, Frame, HeldDeviceSockets, HeldSockets, IpFrame, ParseSentFrameError,
92        PrimaryDeviceSocketId, Protocol, ReceiveFrameError, ReceivedFrame, SentFrame, SocketId,
93        SocketInfo, SocketState, SocketStateAccessor, Target, TargetDevice, WeakDeviceSocketId,
94    };
95}
96
97/// Device RX and TX queueing.
98pub mod queue {
99    pub use crate::internal::queue::api::{ReceiveQueueApi, TransmitQueueApi};
100    pub use crate::internal::queue::rx::{
101        ReceiveDequeContext, ReceiveQueueBindingsContext, ReceiveQueueContext, ReceiveQueueHandler,
102        ReceiveQueueState, ReceiveQueueTypes,
103    };
104    pub use crate::internal::queue::tx::{
105        BufVecU8Allocator, TransmitDequeueContext, TransmitQueueBindingsContext,
106        TransmitQueueCommon, TransmitQueueConfiguration, TransmitQueueContext,
107        TransmitQueueHandler, TransmitQueueState, TxBufferAllocator, TxQueuePacketMetadataCommon,
108    };
109    pub use crate::internal::queue::{
110        BatchSize, DequeueState, DeviceBufferSpec, ReceiveQueueFullError,
111    };
112}
113
114pub use internal::api::{DeviceAnyApi, DeviceApi};
115pub use internal::arp::{
116    ARP_OVERRIDE_LOCK_TIME, ArpConfigContext, ArpContext, ArpCounters, ArpIpLayerContext,
117    ArpNudCtx, ArpSenderContext, ArpState, send_arp_request,
118};
119pub use internal::base::{
120    DeviceBufferBindingsTypes, DeviceClassMatcher, DeviceCollectionContext, DeviceCounters,
121    DeviceIdAndNameMatcher, DeviceLayerEventDispatcher, DeviceLayerState, DeviceLayerStateTypes,
122    DeviceLayerTimerId, DeviceLayerTypes, DeviceSendFrameError, Devices, DevicesIter,
123    Ipv6DeviceLinkLayerAddr, OriginTracker, OriginTrackerContext,
124};
125pub use internal::config::{
126    ArpConfiguration, ArpConfigurationUpdate, DeviceConfiguration, DeviceConfigurationContext,
127    DeviceConfigurationUpdate, DeviceConfigurationUpdateError, NdpConfiguration,
128    NdpConfigurationUpdate,
129};
130pub use internal::gro::{
131    BufferSlice, GroBufferDestination, GroBufferStorage, GroFrameType, GroInputItem, GroIter,
132    GroOutputBuffers, GroOutputItem, MaybeContiguousBuffer,
133};
134pub use internal::id::{BaseDeviceId, DeviceId, DeviceProvider, WeakDeviceId};
135pub use internal::state::{
136    DeviceStateSpec, DeviceTxOffloadSpecContext, IpLinkDeviceState, IpLinkDeviceStateInner,
137};
138
139/// Device layer test utilities.
140#[cfg(any(test, feature = "testutils"))]
141pub mod testutil {
142    pub use crate::internal::base::testutil::DeviceCounterExpectations;
143    pub use crate::internal::ethernet::testutil::IPV6_MIN_IMPLIED_MAX_FRAME_SIZE;
144}