diff --git a/Cargo.lock b/Cargo.lock index 3155994cc..9aee3c968 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -135,6 +135,7 @@ name = "aster-network" version = "0.1.0" dependencies = [ "align_ext", + "aster-bigtcp", "aster-rights", "aster-util", "bitflags 1.3.2", @@ -143,7 +144,6 @@ dependencies = [ "int-to-c-enum", "log", "ostd", - "smoltcp", "spin 0.9.8", ] @@ -247,6 +247,7 @@ name = "aster-virtio" version = "0.1.0" dependencies = [ "align_ext", + "aster-bigtcp", "aster-block", "aster-console", "aster-input", @@ -261,7 +262,6 @@ dependencies = [ "int-to-c-enum", "log", "ostd", - "smoltcp", "spin 0.9.8", "typeflags-util", ] diff --git a/kernel/comps/network/Cargo.toml b/kernel/comps/network/Cargo.toml index 0b2abb295..1c2ece6dd 100644 --- a/kernel/comps/network/Cargo.toml +++ b/kernel/comps/network/Cargo.toml @@ -9,24 +9,11 @@ edition = "2021" align_ext = { path = "../../../ostd/libs/align_ext" } aster-util = { path = "../../libs/aster-util" } aster-rights = { path = "../../libs/aster-rights" } +aster-bigtcp = { path = "../../libs/aster-bigtcp" } bitflags = "1.3" bitvec = { version = "1.0.1", default-features = false, features = ["alloc"] } component = { path = "../../libs/comp-sys/component" } int-to-c-enum = { path = "../../libs/int-to-c-enum" } log = "0.4" ostd = { path = "../../../ostd" } -smoltcp = { git = "https://github.com/smoltcp-rs/smoltcp", rev = "dc08e0b", default-features = false, features = [ - "alloc", - "log", - "medium-ethernet", - "medium-ip", - "proto-dhcpv4", - "proto-ipv4", - "proto-igmp", - "socket-icmp", - "socket-udp", - "socket-tcp", - "socket-raw", - "socket-dhcpv4", -] } spin = "0.9.4" diff --git a/kernel/comps/network/src/driver.rs b/kernel/comps/network/src/driver.rs index 688841d13..5dcee6049 100644 --- a/kernel/comps/network/src/driver.rs +++ b/kernel/comps/network/src/driver.rs @@ -2,12 +2,12 @@ use alloc::vec; +use aster_bigtcp::{device, time::Instant}; use ostd::mm::VmWriter; -use smoltcp::{phy, time::Instant}; use crate::{buffer::RxBuffer, AnyNetworkDevice}; -impl phy::Device for dyn AnyNetworkDevice { +impl device::Device for dyn AnyNetworkDevice { type RxToken<'a> = RxToken; type TxToken<'a> = TxToken<'a>; @@ -28,13 +28,13 @@ impl phy::Device for dyn AnyNetworkDevice { } } - fn capabilities(&self) -> phy::DeviceCapabilities { + fn capabilities(&self) -> device::DeviceCapabilities { self.capabilities() } } pub struct RxToken(RxBuffer); -impl phy::RxToken for RxToken { +impl device::RxToken for RxToken { fn consume(self, f: F) -> R where F: FnOnce(&[u8]) -> R, @@ -48,7 +48,7 @@ impl phy::RxToken for RxToken { pub struct TxToken<'a>(&'a mut dyn AnyNetworkDevice); -impl<'a> phy::TxToken for TxToken<'a> { +impl<'a> device::TxToken for TxToken<'a> { fn consume(self, len: usize, f: F) -> R where F: FnOnce(&mut [u8]) -> R, diff --git a/kernel/comps/network/src/lib.rs b/kernel/comps/network/src/lib.rs index 4fb8ab421..b4d3855c7 100644 --- a/kernel/comps/network/src/lib.rs +++ b/kernel/comps/network/src/lib.rs @@ -15,6 +15,7 @@ extern crate alloc; use alloc::{collections::BTreeMap, string::String, sync::Arc, vec::Vec}; use core::{any::Any, fmt::Debug}; +use aster_bigtcp::device::DeviceCapabilities; pub use buffer::{RxBuffer, TxBuffer, RX_BUFFER_POOL, TX_BUFFER_POOL}; use component::{init_component, ComponentInitError}; pub use dma_pool::DmaSegment; @@ -22,7 +23,6 @@ use ostd::{ sync::{LocalIrqDisabled, SpinLock}, Pod, }; -use smoltcp::phy; use spin::Once; #[derive(Debug, Clone, Copy, Pod)] @@ -40,7 +40,7 @@ pub trait AnyNetworkDevice: Send + Sync + Any + Debug { // ================Device Information================= fn mac_addr(&self) -> EthernetAddr; - fn capabilities(&self) -> phy::DeviceCapabilities; + fn capabilities(&self) -> DeviceCapabilities; // ================Device Operation=================== diff --git a/kernel/comps/virtio/Cargo.toml b/kernel/comps/virtio/Cargo.toml index c2c6890f2..a287ac166 100644 --- a/kernel/comps/virtio/Cargo.toml +++ b/kernel/comps/virtio/Cargo.toml @@ -16,6 +16,7 @@ aster-network = { path = "../network" } aster-console = { path = "../console" } aster-util = { path = "../../libs/aster-util" } aster-rights = { path = "../../libs/aster-rights" } +aster-bigtcp = { path = "../../libs/aster-bigtcp" } id-alloc = { path = "../../../ostd/libs/id-alloc" } typeflags-util = { path = "../../libs/typeflags-util" } ostd = { path = "../../../ostd" } @@ -23,17 +24,3 @@ component = { path = "../../libs/comp-sys/component" } log = "0.4" bit_field = "0.10.1" int-to-c-enum = { path = "../../libs/int-to-c-enum" } -smoltcp = { git = "https://github.com/smoltcp-rs/smoltcp", rev = "dc08e0b", default-features = false, features = [ - "alloc", - "log", - "medium-ethernet", - "medium-ip", - "proto-dhcpv4", - "proto-ipv4", - "proto-igmp", - "socket-icmp", - "socket-udp", - "socket-tcp", - "socket-raw", - "socket-dhcpv4", -] } diff --git a/kernel/comps/virtio/src/device/network/device.rs b/kernel/comps/virtio/src/device/network/device.rs index 9d594a374..75f9df9fb 100644 --- a/kernel/comps/virtio/src/device/network/device.rs +++ b/kernel/comps/virtio/src/device/network/device.rs @@ -3,6 +3,7 @@ use alloc::{boxed::Box, string::ToString, sync::Arc}; use core::{fmt::Debug, hint::spin_loop, mem::size_of}; +use aster_bigtcp::device::{DeviceCapabilities, Medium}; use aster_network::{ AnyNetworkDevice, EthernetAddr, RxBuffer, TxBuffer, VirtioNetError, RX_BUFFER_POOL, TX_BUFFER_POOL, @@ -10,7 +11,6 @@ use aster_network::{ use aster_util::slot_vec::SlotVec; use log::debug; use ostd::{sync::SpinLock, trap::TrapFrame}; -use smoltcp::phy::{DeviceCapabilities, Medium}; use super::{config::VirtioNetConfig, header::VirtioNetHdr}; use crate::{ diff --git a/kernel/libs/aster-bigtcp/src/device.rs b/kernel/libs/aster-bigtcp/src/device.rs index 2b0e509e1..f81f5a9eb 100644 --- a/kernel/libs/aster-bigtcp/src/device.rs +++ b/kernel/libs/aster-bigtcp/src/device.rs @@ -1,6 +1,6 @@ // SPDX-License-Identifier: MPL-2.0 -pub use smoltcp::phy::{Device, Loopback, Medium}; +pub use smoltcp::phy::{Device, DeviceCapabilities, Loopback, Medium, RxToken, TxToken}; /// A trait that allows to obtain a mutable reference of [`Device`]. /// diff --git a/kernel/libs/aster-bigtcp/src/lib.rs b/kernel/libs/aster-bigtcp/src/lib.rs index ef6a3be6f..af145ccd3 100644 --- a/kernel/libs/aster-bigtcp/src/lib.rs +++ b/kernel/libs/aster-bigtcp/src/lib.rs @@ -18,6 +18,7 @@ pub mod device; pub mod errors; pub mod iface; pub mod socket; +pub mod time; pub mod wire; extern crate alloc; diff --git a/kernel/libs/aster-bigtcp/src/time.rs b/kernel/libs/aster-bigtcp/src/time.rs new file mode 100644 index 000000000..b5ea52952 --- /dev/null +++ b/kernel/libs/aster-bigtcp/src/time.rs @@ -0,0 +1,3 @@ +// SPDX-License-Identifier: MPL-2.0 + +pub use smoltcp::time::Instant;