Skip to content
Draft
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
22 changes: 7 additions & 15 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ dpdk-sysroot-helper = { path = "./dpdk-sysroot-helper", package = "dataplane-dpd
dplane-rpc = { git = "https://github.com/githedgehog/dplane-rpc.git", version = "1.1.2" }
errno = { path = "./errno", package = "dataplane-errno" }
flow-info = { path = "./flow-info", package = "dataplane-flow-info" }
gateway_config = { git = "https://github.com/githedgehog/gateway-proto", tag = "v0.14.0", version = "0.14.0"}
gateway_config = { git = "https://github.com/githedgehog/gateway-proto", version ="0.15.0", branch = "pr/mvachhar/nat-config" }
hardware = { path = "./hardware", package = "dataplane-hardware" }
id = { path = "./id", package = "dataplane-id" }
interface-manager = { path = "./interface-manager", package = "dataplane-interface-manager" }
Expand Down
73 changes: 62 additions & 11 deletions config/src/converters/grpc/expose.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Open Network Fabric Authors

use ::gateway_config::google;
use gateway_config::config as gateway_config;

use std::convert::TryFrom;

use crate::external::overlay::vpcpeering::VpcExpose;
use crate::external::overlay::vpcpeering::{
VpcExpose, VpcExposeNatConfig, VpcExposeStatefulNat, VpcExposeStatelessNat,
};
use lpm::prefix::{Prefix, PrefixString};

impl TryFrom<&gateway_config::Expose> for VpcExpose {
Expand Down Expand Up @@ -54,6 +58,34 @@ impl TryFrom<&gateway_config::Expose> for VpcExpose {
}
}

if !expose.r#as.is_empty() {
vpc_expose = vpc_expose.make_nat();
if let (Some(grpc_nat), Some(nat)) = (expose.nat.as_ref(), vpc_expose.nat.as_mut()) {
#[allow(clippy::default_constructed_unit_structs)]
match grpc_nat {
gateway_config::expose::Nat::Stateless(_) => {
nat.config =
VpcExposeNatConfig::Stateless(VpcExposeStatelessNat::default());
}
gateway_config::expose::Nat::Stateful(grpc_s) => {
if let Some(nat) = vpc_expose.nat.as_mut() {
nat.config = VpcExposeNatConfig::Stateful(VpcExposeStatefulNat {
idle_timeout: grpc_s
.idle_timeout
.ok_or(
"stateful nat requires idle_timeout, got None".to_string(),
)
.and_then(|t| {
std::time::Duration::try_from(t)
.map_err(|e| format!("Invalid duration: {e}"))
})?,
});
}
}
}
}
}

Ok(vpc_expose)
}
}
Expand All @@ -77,21 +109,40 @@ impl TryFrom<&VpcExpose> for gateway_config::Expose {
ips.push(gateway_config::PeeringIPs { rule: Some(rule) });
}

// Convert AS inclusion rules
for prefix in &expose.as_range {
let rule = gateway_config::peering_as::Rule::Cidr(prefix.to_string());
as_rules.push(gateway_config::PeeringAs { rule: Some(rule) });
}
let nat = if let Some(nat) = expose.nat.as_ref() {
// Convert AS inclusion rules
for prefix in &nat.as_range {
let rule = gateway_config::peering_as::Rule::Cidr(prefix.to_string());
as_rules.push(gateway_config::PeeringAs { rule: Some(rule) });
}

// Convert AS exclusion rules
for prefix in &expose.not_as {
let rule = gateway_config::peering_as::Rule::Not(prefix.to_string());
as_rules.push(gateway_config::PeeringAs { rule: Some(rule) });
}
// Convert AS exclusion rules
for prefix in &nat.not_as {
let rule = gateway_config::peering_as::Rule::Not(prefix.to_string());
as_rules.push(gateway_config::PeeringAs { rule: Some(rule) });
}

match &nat.config {
VpcExposeNatConfig::Stateful(config) => {
let idle_timeout = google::protobuf::Duration::try_from(config.idle_timeout)
.map_err(|e| format!("Unable to convert stateful nat idle timeout: {e}"))?;
Some(gateway_config::expose::Nat::Stateful(
gateway_config::PeeringStatefulNat {
idle_timeout: Some(idle_timeout),
},
))
}
VpcExposeNatConfig::Stateless(_) => Some(gateway_config::expose::Nat::Stateless(
gateway_config::PeeringStatelessNat {},
)),
}
} else {
None
};
Ok(gateway_config::Expose {
ips,
r#as: as_rules,
nat,
})
}
}
6 changes: 6 additions & 0 deletions config/src/converters/grpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,17 @@ mod test {
let vpc1_expose = gateway_config::Expose {
ips: vec![include_ip],
r#as: vec![include_as],
nat: Some(gateway_config::config::expose::Nat::Stateless(
gateway_config::config::PeeringStatelessNat {},
)),
};

let vpc2_expose = gateway_config::Expose {
ips: vec![exclude_ip],
r#as: vec![exclude_as],
nat: Some(gateway_config::config::expose::Nat::Stateless(
gateway_config::config::PeeringStatelessNat {},
)),
};

// Create PeeringEntryFor
Expand Down
28 changes: 15 additions & 13 deletions config/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,22 @@ impl Display for VpcExpose {

writeln!(f)?;

if !self.as_range.is_empty() {
write!(f, "{SEP} as:")?;
self.as_range.iter().for_each(|x| {
let _ = write!(f, " {x}");
});
carriage = true;
}
if let Some(nat) = self.nat.as_ref() {
if !nat.as_range.is_empty() {
write!(f, "{SEP} as:")?;
nat.as_range.iter().for_each(|x| {
let _ = write!(f, " {x}");
});
carriage = true;
}

if !self.not_as.is_empty() {
write!(f, ", excluding")?;
self.not_as.iter().for_each(|x| {
let _ = write!(f, " {x}");
});
carriage = true;
if !nat.not_as.is_empty() {
write!(f, ", excluding")?;
nat.not_as.iter().for_each(|x| {
let _ = write!(f, " {x}");
});
carriage = true;
}
}
if carriage { writeln!(f) } else { Ok(()) }
}
Expand Down
4 changes: 2 additions & 2 deletions config/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ pub enum ConfigError {

// Peering and VpcExpose validation
#[error("All prefixes are excluded in VpcExpose: {0}")]
ExcludedAllPrefixes(VpcExpose),
ExcludedAllPrefixes(Box<VpcExpose>),
#[error("Exclusion prefix {0} not contained within existing allowed prefix")]
OutOfRangeExclusionPrefix(Prefix),
#[error("VPC prefixes overlap: {0} and {1}")]
OverlappingPrefixes(Prefix, Prefix),
#[error("Inconsistent IP version in VpcExpose: {0}")]
InconsistentIpVersion(VpcExpose),
InconsistentIpVersion(Box<VpcExpose>),
// NAT-specific
#[error("Mismatched prefixes sizes for static NAT: {0:?} and {1:?}")]
MismatchedPrefixSizes(PrefixSize, PrefixSize),
Expand Down
8 changes: 4 additions & 4 deletions config/src/external/overlay/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ pub mod test {
.as_range("2::/64".into());
assert_eq!(
expose.validate(),
Err(ConfigError::InconsistentIpVersion(expose.clone()))
Err(ConfigError::InconsistentIpVersion(Box::new(expose.clone())))
);

// Incorrect: mixed IP versions
Expand All @@ -153,7 +153,7 @@ pub mod test {
.as_range("1::/112".into());
assert_eq!(
expose.validate(),
Err(ConfigError::InconsistentIpVersion(expose.clone()))
Err(ConfigError::InconsistentIpVersion(Box::new(expose.clone())))
);

// Incorrect: mixed IP versions
Expand All @@ -164,7 +164,7 @@ pub mod test {
.not_as("2::/120".into());
assert_eq!(
expose.validate(),
Err(ConfigError::InconsistentIpVersion(expose.clone()))
Err(ConfigError::InconsistentIpVersion(Box::new(expose.clone())))
);

// Incorrect: prefix overlapping
Expand Down Expand Up @@ -202,7 +202,7 @@ pub mod test {
.not_as("2.0.128.0/17".into());
assert_eq!(
expose.validate(),
Err(ConfigError::ExcludedAllPrefixes(expose.clone()))
Err(ConfigError::ExcludedAllPrefixes(Box::new(expose.clone())))
);
}

Expand Down
Loading
Loading