diff --git a/Cargo.lock b/Cargo.lock index 3e4457fb..000e9a16 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -595,16 +595,6 @@ dependencies = [ "minimal-lexical", ] -[[package]] -name = "nu-ansi-term" -version = "0.46.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" -dependencies = [ - "overload", - "winapi", -] - [[package]] name = "num-traits" version = "0.2.19" @@ -635,12 +625,6 @@ version = "11.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b410bbe7e14ab526a0e86877eb47c6996a2bd7746f027ba551028c925390e4e9" -[[package]] -name = "overload" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" - [[package]] name = "phf" version = "0.11.2" @@ -876,19 +860,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "scratch" -version = "0.1.0" -dependencies = [ - "dpdk", - "dpdk-sys", - "dpdk-sysroot-helper", - "rand", - "thiserror-no-std", - "tracing", - "tracing-subscriber", -] - [[package]] name = "serde" version = "1.0.214" @@ -921,15 +892,6 @@ dependencies = [ "serde", ] -[[package]] -name = "sharded-slab" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" -dependencies = [ - "lazy_static", -] - [[package]] name = "shlex" version = "1.3.0" @@ -942,12 +904,6 @@ version = "0.3.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" -[[package]] -name = "smallvec" -version = "1.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" - [[package]] name = "syn" version = "1.0.109" @@ -990,16 +946,6 @@ dependencies = [ "thiserror-impl-no-std", ] -[[package]] -name = "thread_local" -version = "1.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b9ef9bad013ada3808854ceac7b46812a6465ba368859a37e2100283d2d719c" -dependencies = [ - "cfg-if", - "once_cell", -] - [[package]] name = "tinytemplate" version = "1.2.1" @@ -1054,35 +1000,6 @@ name = "tracing-core" version = "0.1.32" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" -dependencies = [ - "once_cell", - "valuable", -] - -[[package]] -name = "tracing-log" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" -dependencies = [ - "log", - "once_cell", - "tracing-core", -] - -[[package]] -name = "tracing-subscriber" -version = "0.3.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b" -dependencies = [ - "nu-ansi-term", - "sharded-slab", - "smallvec", - "thread_local", - "tracing-core", - "tracing-log", -] [[package]] name = "unicode-ident" @@ -1090,12 +1007,6 @@ version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" -[[package]] -name = "valuable" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" - [[package]] name = "walkdir" version = "2.5.0" @@ -1177,22 +1088,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - [[package]] name = "winapi-util" version = "0.1.9" @@ -1202,12 +1097,6 @@ dependencies = [ "windows-sys 0.59.0", ] -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" - [[package]] name = "windows-sys" version = "0.52.0" diff --git a/Cargo.toml b/Cargo.toml index 870089cf..53bf178c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,7 @@ members = [ "dpdk-sys", "errno", "net", - "scratch", +# "scratch", ] resolver = "2" diff --git a/dpdk/src/dev.rs b/dpdk/src/dev.rs index 7febf61d..901cf335 100644 --- a/dpdk/src/dev.rs +++ b/dpdk/src/dev.rs @@ -99,13 +99,13 @@ impl DevIndex { return Err(DevInfoError::InvalidArgument); } val => { - let unknown = match StandardErrno::parse_i32(val) { + let _unknown = match StandardErrno::parse_i32(val) { Ok(standard) => { return Err(DevInfoError::UnknownStandard(standard)); } Err(unknown) => unknown, }; - let unknown = match NegStandardErrno::parse_i32(val) { + let _unknown = match NegStandardErrno::parse_i32(val) { Ok(standard) => { return Err(DevInfoError::UnknownNegStandard(standard)); } @@ -779,9 +779,9 @@ pub struct StartedDev { pub info: DevInfo, /// The configuration of the device. pub config: DevConfig, - pub(crate) rx_queues: Vec, - pub(crate) tx_queues: Vec, - pub(crate) hairpin_queues: Vec, + pub rx_queues: Vec, + pub tx_queues: Vec, + pub hairpin_queues: Vec, } impl Dev { diff --git a/dpdk/src/flow/mod.rs b/dpdk/src/flow/mod.rs index ee67e4d0..4d3c6277 100644 --- a/dpdk/src/flow/mod.rs +++ b/dpdk/src/flow/mod.rs @@ -7,7 +7,6 @@ use crate::queue::tx::TxQueueIndex; use alloc::vec::Vec; use core::fmt::Debug; use core::marker::PhantomData; -use core::net::Ipv4Addr; use core::ptr::NonNull; use dpdk_sys::*; use net; @@ -28,8 +27,8 @@ pub struct FlowRule { _phantom: PhantomData, } -const MAX_PATTERN_NUM: usize = 16; -const MAX_ACTION_NUM: usize = 16; +pub const MAX_PATTERN_NUM: usize = 16; +pub const MAX_ACTION_NUM: usize = 16; /// TODO: convert numbers to constant references to `rte_flow_item_type` #[derive(Debug)] @@ -244,7 +243,7 @@ pub enum FlowMatch { #[derive(Debug, Clone, Copy)] pub struct MatchTag { /// NOTE: can't be more than 2^24 - 1 - data: u32, + pub data: u32, } /// A metadata value to match on. @@ -261,7 +260,7 @@ pub struct Vni(pub u32); // TODO: expose remaining fields pub struct VxlanHeader { - vni: Vni, + pub vni: Vni, } pub struct UdpPort(pub u16); @@ -269,26 +268,26 @@ pub struct TcpPort(pub u16); // TODO: expose remaining fields pub struct TcpHeader { - src_port: TcpPort, - dst_port: TcpPort, + pub src_port: TcpPort, + pub dst_port: TcpPort, } // TODO: expose remaining fields pub struct UdpHeader { - src_port: UdpPort, - dst_port: UdpPort, + pub src_port: UdpPort, + pub dst_port: UdpPort, } // TODO: expose remaining fields pub struct Ipv6Header { - src: core::net::Ipv6Addr, - dst: core::net::Ipv6Addr, + pub src: core::net::Ipv6Addr, + pub dst: core::net::Ipv6Addr, } // TODO: expose remaining fields pub struct Ipv4Header { - src: Ipv4Addr, - dst: Ipv4Addr, + pub src: core::net::Ipv4Addr, + pub dst: core::net::Ipv4Addr, } pub struct FlowSpec { @@ -359,9 +358,9 @@ impl From for rte_flow_item_eth { pub struct VlanTci(pub u16); pub struct VlanHeader { - ether_type: EtherType, - tci: VlanTci, - inner_ether_type: EtherType, + pub ether_type: EtherType, + pub tci: VlanTci, + pub inner_ether_type: EtherType, // TODO: figure out why DPDK lets you spec TCI twice } @@ -688,13 +687,19 @@ pub enum FlowAction { // Nat64, } +/// Modify a field #[repr(u32)] pub enum FieldModificationOperation { + /// Set a field Set = rte_flow_modify_op::RTE_FLOW_MODIFY_SET, + /// Add to a field Add = rte_flow_modify_op::RTE_FLOW_MODIFY_ADD, + /// Subtract from a field Subtract = rte_flow_modify_op::RTE_FLOW_MODIFY_SUB, } +/// A wrapper around a `rte_flow_action_modify_field` that specifies the +/// field to modify and its new value. #[repr(u32)] pub enum FlowFieldId { /// Start of a packet. @@ -803,41 +808,71 @@ pub enum FlowFieldId { VxlanLastReserved = rte_flow_field_id::RTE_FLOW_FIELD_VXLAN_LAST_RSVD, } +/// A wrapper around a `rte_flow_action_modify_field` that specifies the +/// field to modify and its new value. #[derive(Debug, Clone, Copy)] pub enum SetFlowField { + /// Dest mac MacDst(MacAddr), + /// Source mac MacSrc(MacAddr), + /// Vlan ethertype VlanType(EtherType), + /// Vlan VID VlanVid(net::vlan::Vid), + /// Ethertype EtherType(EtherType), + /// IPv4 DSCP Ipv4Dscp(u8), + /// IPv4 TTL Ipv4Ttl(u8), - Ipv4Src(Ipv4Addr), - Ipv4Dst(Ipv4Addr), + /// Ipv4 source + Ipv4Src(core::net::Ipv4Addr), + /// Ipv4 dest + Ipv4Dst(core::net::Ipv4Addr), + /// Ipv6 DSCP Ipv6Dscp(u8), + /// Ipv6 hop limit (ttl) Ipv6HopLimit(u8), + /// Ipv6 source Ipv6Src(core::net::Ipv6Addr), + /// Ipv6 dest Ipv6Dst(core::net::Ipv6Addr), + /// TCP source port TcpPortSrc(u16), + /// TCP dest port TcpPortDst(u16), + /// TCP seq number TcpSeqNum(u32), + /// TCP ack num TcpAckNum(u32), + /// TCP flags TcpFlags(u16), + /// UDP source port UdpPortSrc(u16), + /// UDP dest port UdpPortDst(u16), + /// VXLAN vni VxlanVni(net::vxlan::Vni), + /// Tag Tag(MatchTag), + /// Metadata Meta(MatchMeta), + /// Ipv4 ECN IpV4Ecn(u8), + /// IPv6 ECN IpV6Ecn(u8), } +/// A wrapper around a `rte_flow_action_modify_field` that specifies the +/// field to modify and its new value. pub struct SetFieldAction { - rule: SetFlowField, - conf: rte_flow_action_modify_field, + pub rule: SetFlowField, + pub conf: rte_flow_action_modify_field, } impl SetFlowField { + /// Converts the `SetFlowField` into a `SetFieldAction`. pub fn to_flow_rule(&self) -> SetFieldAction { let conf = match self { SetFlowField::MacDst(mac_addr) => { @@ -895,11 +930,13 @@ impl Sealed for u32 {} impl Sealed for u64 {} impl Sealed for u128 {} +/// A wrapper around unsigned numbers that specifies they are in big endian order. #[repr(transparent)] pub struct BigEndian(T) where T: UnsignedNum; +/// An unsigned number (e.g. u8 or u32) pub trait UnsignedNum: Sealed {} impl UnsignedNum for T where T: Sealed {} @@ -943,7 +980,3 @@ impl From for BigEndian { BigEndian(x.to_be()) } } - -pub struct JumpAction { - group: u32, -} diff --git a/dpdk/src/lib.rs b/dpdk/src/lib.rs index 9988b140..c2c7d8c7 100644 --- a/dpdk/src/lib.rs +++ b/dpdk/src/lib.rs @@ -26,10 +26,7 @@ //! encourage this practice. #![cfg_attr(not(test), no_std)] #![warn( - missing_docs, clippy::all, - clippy::missing_panics_doc, - clippy::missing_safety_doc )] #![deny(clippy::unwrap_used, clippy::expect_used, clippy::panic)] #![allow(private_bounds)] diff --git a/dpdk/src/mem.rs b/dpdk/src/mem.rs index 0cb672ab..d065f1dd 100644 --- a/dpdk/src/mem.rs +++ b/dpdk/src/mem.rs @@ -345,6 +345,9 @@ impl Drop for PoolInner { } } +/// A DPDK Mbuf (memory buffer) +/// +/// Usually used to hold an ethernet frame. #[repr(transparent)] pub struct Mbuf { pub(crate) raw: NonNull, @@ -376,7 +379,6 @@ impl Mbuf { #[tracing::instrument(level = "trace")] pub(crate) fn new_from_raw(raw: *mut rte_mbuf) -> Option { let raw = match NonNull::new(raw) { - #[cold] None => { warn!("Attempted to create Mbuf from null pointer"); return None; @@ -390,6 +392,7 @@ impl Mbuf { }) } + /// Get an immutable ref to the raw data of an Mbuf pub fn raw_data(&self) -> &[u8] { let pkt_data_start = unsafe { (self.raw.as_ref().buf_addr as *const u8) @@ -403,6 +406,7 @@ impl Mbuf { } } + /// Get a mutable ref to the raw data of an Mbuf pub fn raw_data_mut(&mut self) -> &mut [u8] { unsafe { let data_start = self diff --git a/dpdk/src/queue/hairpin.rs b/dpdk/src/queue/hairpin.rs index 931d99a5..89b51cbd 100644 --- a/dpdk/src/queue/hairpin.rs +++ b/dpdk/src/queue/hairpin.rs @@ -1,6 +1,6 @@ //! Hairpin queue configuration and management. use super::{rx, tx}; -use crate::dev::{Dev, DevConfig, DevInfo}; +use crate::dev::{Dev, DevInfo}; use crate::queue::rx::RxQueue; use crate::queue::tx::{TxQueue}; use dpdk_sys::*; @@ -99,7 +99,7 @@ impl HairpinQueue { Ok(HairpinQueue { rx, tx, peering }) } - pub(crate) fn start(self) -> HairpinQueue { + pub fn start(self) -> HairpinQueue { let rx = match self.rx.start() { Ok(rx) => rx, Err(_) => todo!(), diff --git a/dpdk/src/queue/mod.rs b/dpdk/src/queue/mod.rs index 610f183e..9eb685ba 100644 --- a/dpdk/src/queue/mod.rs +++ b/dpdk/src/queue/mod.rs @@ -3,10 +3,14 @@ pub mod rx; pub mod tx; pub mod hairpin; +/// The possible states of a DPDK queue #[derive(Debug)] pub enum QueueState { + /// An unconfigured queue Unconfigured, + /// A stopped queue Stopped, + /// A started queue Started, } diff --git a/dpdk/src/queue/rx.rs b/dpdk/src/queue/rx.rs index ba1559ef..7e9e0a5a 100644 --- a/dpdk/src/queue/rx.rs +++ b/dpdk/src/queue/rx.rs @@ -4,11 +4,8 @@ use crate::dev::DevIndex; use crate::mem::Mbuf; use crate::socket::SocketId; use crate::{dev, mem, socket}; -use core::marker::PhantomData; -use core::ptr::NonNull; -use etherparse::LinkSlice::Ethernet2; use dpdk_sys::*; -use tracing::{debug, info, trace, warn}; +use tracing::{trace, warn}; #[repr(transparent)] #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] @@ -55,12 +52,6 @@ pub struct RxQueueConfig { pub pool: mem::PoolHandle, } -/// Error type for receive queue configuration failures. -#[derive(Debug)] -pub struct ConfigError { - err: errno::Errno, -} - /// Error type for receive queue configuration failures. #[derive(Debug)] pub enum ConfigFailure { @@ -76,6 +67,7 @@ pub enum ConfigFailure { InvalidSocket(errno::Errno), } +/// DPDK rx queue #[derive(Debug)] pub struct RxQueue { pub(crate) config: RxQueueConfig, @@ -93,7 +85,7 @@ impl RxQueue { /// associated with the device. pub(crate) fn configure(dev: &dev::Dev, config: RxQueueConfig) -> Result { let socket_id = SocketId::try_from(config.socket_preference) - .map_err(|err| ConfigFailure::InvalidSocket(errno::Errno(errno::NEG_EINVAL)))?; + .map_err(|_| ConfigFailure::InvalidSocket(errno::Errno(errno::NEG_EINVAL)))?; let rx_conf = rte_eth_rxconf { offloads: dev.info.inner.rx_queue_offload_capa, @@ -233,25 +225,3 @@ pub enum RxQueueState { /// TODO Started, } - - - -fn test_burst(queue: RxQueue) { - let mut queue = queue; - let pkts = queue.receive(); - for pkt in pkts { - let parsed_packet = etherparse::SlicedPacket::from_ethernet(pkt.raw_data()).expect("Failed to parse packet"); - match parsed_packet.link { - None => { - debug!("Failed to parse packet link header"); - } - Some(Ethernet2(pkt)) => { - pkt.ether_type(); - } - pkt => { - debug!("Unsupported packet type {pkt:?}"); - } - } - // info!("Received packet: {:?}", pkt); - } -} \ No newline at end of file diff --git a/net/src/lib.rs b/net/src/lib.rs index a6fa5984..beaf3c56 100644 --- a/net/src/lib.rs +++ b/net/src/lib.rs @@ -7,8 +7,6 @@ extern crate alloc; -use alloc::vec::Vec; - #[cfg(all(kani, feature = "_fake_kani"))] compile_error!("kani should not be used with internal _fake_kani feature.");