1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// Copyright 2024 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

//! Netstack3 core device layer.
//!
//! This crate contains the device layer for netstack3.

#![no_std]
#![deny(missing_docs, unreachable_patterns, clippy::useless_conversion, clippy::redundant_clone)]

extern crate fakealloc as alloc;

#[path = "."]
mod internal {
    pub(super) mod api;
    pub(super) mod arp;
    pub(super) mod base;
    pub(super) mod config;
    pub(super) mod ethernet;
    pub(super) mod id;
    pub(super) mod loopback;
    pub(super) mod pure_ip;
    pub(super) mod queue;
    pub(super) mod socket;
    pub(super) mod state;
}

/// Ethernet devices.
pub mod ethernet {
    pub use crate::internal::base::EthernetDeviceCounters;
    pub use crate::internal::ethernet::{
        get_mac, get_mtu, join_link_multicast, leave_link_multicast, send_as_ethernet_frame_to_dst,
        send_ip_frame, set_mtu, DynamicEthernetDeviceState, EthernetCreationProperties,
        EthernetIpLinkDeviceDynamicStateContext, EthernetIpLinkDeviceStaticStateContext,
        EthernetLinkDevice, EthernetTimerId, MaxEthernetFrameSize, RecvEthernetFrameMeta,
        StaticEthernetDeviceState,
    };
    pub use crate::internal::id::{
        EthernetDeviceId, EthernetPrimaryDeviceId, EthernetWeakDeviceId,
    };
}

/// Loopback devices.
pub mod loopback {
    pub use crate::internal::loopback::{
        send_ip_frame, LoopbackCreationProperties, LoopbackDevice, LoopbackDeviceId,
        LoopbackPrimaryDeviceId, LoopbackRxQueueMeta, LoopbackTxQueueMeta, LoopbackWeakDeviceId,
    };
}

/// Marker traits controlling Device context behavior.
pub mod marker {
    pub use crate::internal::ethernet::UseArpFrameMetadataBlanket;
}

/// Pure IP devices.
pub mod pure_ip {
    pub use crate::internal::base::PureIpDeviceCounters;
    pub use crate::internal::pure_ip::{
        get_mtu, send_ip_frame, set_mtu, DynamicPureIpDeviceState, PureIpDevice,
        PureIpDeviceCreationProperties, PureIpDeviceId, PureIpDeviceReceiveFrameMetadata,
        PureIpDeviceStateContext, PureIpDeviceTxQueueFrameMetadata, PureIpHeaderParams,
        PureIpPrimaryDeviceId, PureIpWeakDeviceId,
    };
}

/// Device sockets.
pub mod socket {
    pub use crate::internal::socket::{
        AllSockets, AnyDeviceSockets, DeviceSocketAccessor, DeviceSocketApi,
        DeviceSocketBindingsContext, DeviceSocketContext, DeviceSocketId, DeviceSocketMetadata,
        DeviceSocketTypes, DeviceSockets, EthernetFrame, EthernetHeaderParams, Frame,
        HeldDeviceSockets, HeldSockets, IpFrame, ParseSentFrameError, PrimaryDeviceSocketId,
        Protocol, ReceivedFrame, SentFrame, SocketId, SocketInfo, SocketState, SocketStateAccessor,
        Target, TargetDevice, WeakDeviceSocketId,
    };
}

/// Device RX and TX queueing.
pub mod queue {
    pub use crate::internal::queue::api::{ReceiveQueueApi, TransmitQueueApi};
    pub use crate::internal::queue::rx::{
        ReceiveDequeContext, ReceiveQueueBindingsContext, ReceiveQueueContext, ReceiveQueueHandler,
        ReceiveQueueState, ReceiveQueueTypes,
    };
    pub use crate::internal::queue::tx::{
        BufVecU8Allocator, TransmitDequeueContext, TransmitQueueBindingsContext,
        TransmitQueueCommon, TransmitQueueConfiguration, TransmitQueueContext,
        TransmitQueueHandler, TransmitQueueState,
    };
    pub use crate::internal::queue::{BatchSize, DequeueState, ReceiveQueueFullError};
}

pub use internal::api::{DeviceAnyApi, DeviceApi};
pub use internal::arp::{
    ArpConfigContext, ArpContext, ArpCounters, ArpNudCtx, ArpSenderContext, ArpState,
};
pub use internal::base::{
    DeviceClassMatcher, DeviceCollectionContext, DeviceCounters, DeviceIdAndNameMatcher,
    DeviceLayerEventDispatcher, DeviceLayerState, DeviceLayerStateTypes, DeviceLayerTimerId,
    DeviceLayerTypes, DeviceSendFrameError, Devices, DevicesIter, Ipv6DeviceLinkLayerAddr,
    OriginTracker, OriginTrackerContext,
};
pub use internal::config::{
    ArpConfiguration, ArpConfigurationUpdate, DeviceConfiguration, DeviceConfigurationContext,
    DeviceConfigurationUpdate, DeviceConfigurationUpdateError, NdpConfiguration,
    NdpConfigurationUpdate,
};
pub use internal::id::{BaseDeviceId, DeviceId, DeviceProvider, WeakDeviceId};
pub use internal::state::{DeviceStateSpec, IpLinkDeviceState, IpLinkDeviceStateInner};

/// Device layer test utilities.
#[cfg(any(test, feature = "testutils"))]
pub mod testutil {
    pub use crate::internal::ethernet::testutil::IPV6_MIN_IMPLIED_MAX_FRAME_SIZE;
}