Skip to content

Commit

Permalink
Review feedback
Browse files Browse the repository at this point in the history
- Add const-assert that VNI search range is valid
- Rename `Vpc::with_random_vni()`
  • Loading branch information
bnaecker committed Oct 20, 2023
1 parent 9bea92c commit 229cf13
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion nexus/db-model/src/vpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl IncompleteVpc {
///
/// This is used to retry insertion of a VPC in the case where we can't find
/// an available VNI.
pub fn with_new_vni(self) -> Self {
pub fn with_random_vni(self) -> Self {
Self { vni: Vni(external::Vni::random()), ..self }
}
}
Expand Down
1 change: 1 addition & 0 deletions nexus/db-queries/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ serde_urlencoded.workspace = true
serde_with.workspace = true
sled-agent-client.workspace = true
slog.workspace = true
static_assertions.workspace = true
steno.workspace = true
thiserror.workspace = true
tokio = { workspace = true, features = [ "full" ] }
Expand Down
2 changes: 1 addition & 1 deletion nexus/db-queries/src/db/datastore/vpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ impl DataStore {
Ok(Some(vpcs)) => return Ok(vpcs),
Err(e) => return Err(e),
Ok(None) => {
vpc = vpc.with_new_vni();
vpc = vpc.with_random_vni();
debug!(
opctx.log,
"VNI exhaustion detected while inserting VPC, retrying";
Expand Down
7 changes: 7 additions & 0 deletions nexus/db-queries/src/db/queries/vpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,13 @@ pub const MAX_VNI_SEARCH_RANGE_SIZE: u32 = 2048;
#[cfg(test)]
pub const MAX_VNI_SEARCH_RANGE_SIZE: u32 = 10;

// Ensure that we cannot search a range that extends beyond the valid guest VNI
// range.
static_assertions::const_assert!(
MAX_VNI_SEARCH_RANGE_SIZE
<= (external::Vni::MAX_VNI - external::Vni::MIN_GUEST_VNI)
);

impl VniShifts {
fn new(vni: Vni) -> Self {
let base_u32 = u32::from(vni.0);
Expand Down

0 comments on commit 229cf13

Please sign in to comment.