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