Skip to content

Commit

Permalink
Clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-noland committed Nov 4, 2024
1 parent 1793bf9 commit 28d2ae0
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 145 deletions.
10 changes: 5 additions & 5 deletions dpdk/src/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down Expand Up @@ -779,9 +779,9 @@ pub struct StartedDev {
pub info: DevInfo,
/// The configuration of the device.
pub config: DevConfig,
pub(crate) rx_queues: Vec<RxQueue>,
pub(crate) tx_queues: Vec<TxQueue>,
pub(crate) hairpin_queues: Vec<HairpinQueue>,
pub rx_queues: Vec<RxQueue>,
pub tx_queues: Vec<TxQueue>,
pub hairpin_queues: Vec<HairpinQueue>,
}

impl Dev {
Expand Down
81 changes: 57 additions & 24 deletions dpdk/src/flow/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,8 +27,8 @@ pub struct FlowRule {
_phantom: PhantomData<rte_flow>,
}

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)]
Expand Down Expand Up @@ -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.
Expand All @@ -261,34 +260,34 @@ pub struct Vni(pub u32);

// TODO: expose remaining fields
pub struct VxlanHeader {
vni: Vni,
pub vni: Vni,
}

pub struct UdpPort(pub u16);
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<T> {
Expand Down Expand Up @@ -359,9 +358,9 @@ impl From<EthHeader> 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
}

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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>(T)
where
T: UnsignedNum;

/// An unsigned number (e.g. u8 or u32)
pub trait UnsignedNum: Sealed {}

impl<T> UnsignedNum for T where T: Sealed {}
Expand Down Expand Up @@ -943,7 +980,3 @@ impl From<u128> for BigEndian<u128> {
BigEndian(x.to_be())
}
}

pub struct JumpAction {
group: u32,
}
3 changes: 0 additions & 3 deletions dpdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
6 changes: 5 additions & 1 deletion dpdk/src/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<rte_mbuf>,
Expand Down Expand Up @@ -376,7 +379,6 @@ impl Mbuf {
#[tracing::instrument(level = "trace")]
pub(crate) fn new_from_raw(raw: *mut rte_mbuf) -> Option<Mbuf> {
let raw = match NonNull::new(raw) {
#[cold]
None => {
warn!("Attempted to create Mbuf from null pointer");
return None;
Expand All @@ -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)
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions dpdk/src/queue/hairpin.rs
Original file line number Diff line number Diff line change
@@ -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::*;
Expand Down Expand Up @@ -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!(),
Expand Down
4 changes: 4 additions & 0 deletions dpdk/src/queue/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

36 changes: 3 additions & 33 deletions dpdk/src/queue/rx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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 {
Expand All @@ -76,6 +67,7 @@ pub enum ConfigFailure {
InvalidSocket(errno::Errno),
}

/// DPDK rx queue
#[derive(Debug)]
pub struct RxQueue {
pub(crate) config: RxQueueConfig,
Expand All @@ -93,7 +85,7 @@ impl RxQueue {
/// associated with the device.
pub(crate) fn configure(dev: &dev::Dev, config: RxQueueConfig) -> Result<Self, ConfigFailure> {
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,
Expand Down Expand Up @@ -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);
}
}
2 changes: 0 additions & 2 deletions net/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.");

Expand Down
Loading

0 comments on commit 28d2ae0

Please sign in to comment.