Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ members = [
"dpdk",
"dpdk-sys",
"dpdk-sysroot-helper",
"dpdk-test-macros",
"errno",
"flow-entry",
"flow-filter",
Expand Down Expand Up @@ -68,6 +69,7 @@ config = { path = "./config", package = "dataplane-config", features = [] }
dpdk = { path = "./dpdk", package = "dataplane-dpdk", features = [] }
dpdk-sys = { path = "./dpdk-sys", package = "dataplane-dpdk-sys", features = [] }
dpdk-sysroot-helper = { path = "./dpdk-sysroot-helper", package = "dataplane-dpdk-sysroot-helper", features = [] }
dpdk-test-macros = { path = "./dpdk-test-macros", package = "dataplane-dpdk-test-macros", features = [] }
dplane-rpc = { git = "https://github.com/githedgehog/dplane-rpc.git", branch = "pr/daniel-noland/bumps", features = [] }
errno = { path = "./errno", package = "dataplane-errno", features = [] }
flow-entry = { path = "./flow-entry", package = "dataplane-flow-entry", features = [] }
Expand Down
15 changes: 15 additions & 0 deletions dpdk-test-macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "dataplane-dpdk-test-macros"
edition.workspace = true
license.workspace = true
publish.workspace = true
version.workspace = true

[lib]
proc-macro = true

[dependencies]
proc-macro-crate = { workspace = true, default-features = true }
proc-macro2 = { workspace = true, default-features = true }
quote = { workspace = true, default-features = true }
syn = { workspace = true, default-features = true, features = ["full"] }
39 changes: 39 additions & 0 deletions dpdk-test-macros/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Open Network Fabric Authors

use proc_macro::TokenStream;
use proc_macro_crate::{FoundCrate, crate_name};
use proc_macro2::{Span, TokenStream as TokenStream2};
use quote::quote;
use syn::{Ident, ItemFn, parse_macro_input, parse_quote};
fn dpdk_crate_path() -> TokenStream2 {
match crate_name("dataplane-dpdk") {
Ok(FoundCrate::Itself) => quote! { crate },
Ok(FoundCrate::Name(name)) => {
let ident = Ident::new(&name, Span::call_site());
quote! { ::#ident }
}
Err(_) => {
let ident = Ident::new("dataplane_dpdk", Span::call_site());
quote! { ::#ident }
}
}
}

#[proc_macro_attribute]
pub fn with_eal(args: TokenStream, input: TokenStream) -> TokenStream {
if !args.is_empty() {
let err: TokenStream2 =
syn::Error::new(Span::call_site(), "#[with_eal] takes no arguments").to_compile_error();
return err.into();
}

let mut input_fn = parse_macro_input!(input as ItemFn);
let dpdk = dpdk_crate_path();
let init_stmt: syn::Stmt = parse_quote! {
let _eal = #dpdk::test_support::start_eal();
};
input_fn.block.stmts.insert(0, init_stmt);

quote! { #input_fn }.into()
}
8 changes: 5 additions & 3 deletions dpdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@ version.workspace = true
[features]
default = ["serde"]
serde = ["dep:serde"]
test = ["dep:id", "dep:nix", "dep:dpdk-test-macros"]

[dependencies]

concurrency = { workspace = true }
dpdk-sys = { workspace = true }
dpdk-test-macros = { workspace = true, optional = true }
errno = { workspace = true }
id = { workspace = true, optional = true }
net = { workspace = true }
nix = { workspace = true, optional = true, features = ["sched"] }

serde = { workspace = true, optional = true, features = ["std"] }
thiserror = { workspace = true }
Expand All @@ -24,7 +28,5 @@ tracing = { workspace = true, features = ["attributes"] }
dpdk-sysroot-helper = { workspace = true }

[dev-dependencies]
id = { workspace = true }

bolero = { workspace = true, default-features = false, features = ["std"] }
nix = { workspace = true, features = ["sched"] }
dataplane-dpdk = { path = ".", features = ["test"] }
43 changes: 26 additions & 17 deletions dpdk/src/acl/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ use super::rule::Rule;
/// while DPDK strides through rules at `rule_size = size_of::<Rule<5>>()` over
/// `Rule<3>`-sized slots -- the exact OOB read the const generic is meant to
/// rule out. Keeping `N` on the type closes that gap statically and is
/// consistent with how [`AclBuildConfig<N>`] is parameterised.
/// consistent with how [`AclBuildConfig<N>`] is parameterized.
///
/// # Construction
///
Expand Down Expand Up @@ -905,34 +905,30 @@ impl<const N: usize> AclBuildConfig<N> {
})
}

/// Compute the buffer-size requirement at construction time.
/// Compute DPDK's minimum input buffer size.
///
/// See [`min_input_size`][AclBuildConfig::min_input_size] for the
/// formula and rationale. Factored out so that `new` can call it
/// once and cache the result; the public accessor returns the cached
/// value.
///
/// Precondition: all fields' `offset + 4` fit in `u32`. This is
/// guaranteed by the `FieldExtentOverflow` check in
/// [`new`][AclBuildConfig::new], so the plain `+` below cannot
/// overflow.
fn compute_min_input_size(field_defs: &[FieldDef; N]) -> usize {
/// `offset + 4` must fit in `u32`; [`AclBuildConfig::new`] validates this.
#[must_use]
pub const fn compute_min_input_size(field_defs: &[FieldDef; N]) -> usize {
let mut max_load_end: u32 = 0;
Comment on lines +908 to 913
for def in field_defs {
let mut i = 0;
while i < N {
let def = &field_defs[i];
let ii = def.input_index();
let mut group_offset = def.offset();
for other in field_defs {
let mut j = 0;
while j < N {
let other = &field_defs[j];
if other.input_index() == ii && other.offset() < group_offset {
group_offset = other.offset();
}
j += 1;
}
// No saturation: `new`'s FieldExtentOverflow check has
// already verified `def.offset() + 4 <= u32::MAX` for every
// def, and `group_offset <= def.offset()`.
let load_end = group_offset + 4;
if load_end > max_load_end {
max_load_end = load_end;
}
i += 1;
}
max_load_end as usize
}
Expand Down Expand Up @@ -1425,6 +1421,19 @@ mod tests {
);
}

#[test]
fn compute_min_input_size_works_in_const_context() {
const DEFS: [FieldDef; 2] = [
FieldDef::new(FieldType::Bitmask, FieldSize::One, 0, 0, 0),
FieldDef::new(FieldType::Mask, FieldSize::Four, 1, 9, 100),
];
const MIN_INPUT_SIZE: usize = AclBuildConfig::compute_min_input_size(&DEFS);
assert_eq!(MIN_INPUT_SIZE, 104);

let cfg = AclBuildConfig::new(1, DEFS, 0).expect("config should validate");
assert_eq!(cfg.min_input_size(), MIN_INPUT_SIZE);
}

/// Property: `AclCreateParams::new` accepts a name iff it is non-empty
/// ASCII without interior NUL bytes and of length `<= MAX_ACL_NAME_LEN`.
/// Verifies the four error variants are mutually exclusive and that the
Expand Down
Loading
Loading