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