Skip to content

Commit 1c7987f

Browse files
committed
WIP: feat: gRPC <-> external for nat config
Signed-off-by: Manish Vachharajani <[email protected]>
1 parent 58db42c commit 1c7987f

File tree

4 files changed

+65
-18
lines changed

4 files changed

+65
-18
lines changed

Cargo.lock

Lines changed: 6 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ dpdk-sysroot-helper = { path = "./dpdk-sysroot-helper", package = "dataplane-dpd
4242
dplane-rpc = { git = "https://github.com/githedgehog/dplane-rpc.git", version = "1.1.2" }
4343
errno = { path = "./errno", package = "dataplane-errno" }
4444
flow-info = { path = "./flow-info", package = "dataplane-flow-info" }
45-
gateway_config = { git = "https://github.com/githedgehog/gateway-proto", tag = "v0.14.0", version = "0.14.0"}
45+
gateway_config = { git = "https://github.com/githedgehog/gateway-proto", version ="0.14.0", branch = "pr/mvachhar/nat-config" }
4646
hardware = { path = "./hardware", package = "dataplane-hardware" }
4747
id = { path = "./id", package = "dataplane-id" }
4848
interface-manager = { path = "./interface-manager", package = "dataplane-interface-manager" }

config/src/converters/grpc/expose.rs

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
use gateway_config::config as gateway_config;
55
use std::convert::TryFrom;
66

7-
use crate::external::overlay::vpcpeering::VpcExpose;
7+
use crate::external::overlay::vpcpeering::{
8+
VpcExpose, VpcExposeNatConfig, VpcExposeStatefulNat, VpcExposeStatelessNat,
9+
};
810
use lpm::prefix::{Prefix, PrefixString};
911

1012
impl TryFrom<&gateway_config::Expose> for VpcExpose {
@@ -54,6 +56,34 @@ impl TryFrom<&gateway_config::Expose> for VpcExpose {
5456
}
5557
}
5658

59+
if !expose.r#as.is_empty() {
60+
vpc_expose = vpc_expose.make_nat();
61+
if let (Some(grpc_nat), Some(nat)) = (expose.nat.as_ref(), vpc_expose.nat.as_mut()) {
62+
#[allow(clippy::default_constructed_unit_structs)]
63+
match grpc_nat {
64+
gateway_config::expose::Nat::Stateless(_) => {
65+
nat.config =
66+
VpcExposeNatConfig::Stateless(VpcExposeStatelessNat::default());
67+
}
68+
gateway_config::expose::Nat::Stateful(grpc_s) => {
69+
if let Some(nat) = vpc_expose.nat.as_mut() {
70+
nat.config = VpcExposeNatConfig::Stateful(VpcExposeStatefulNat {
71+
idle_timeout: grpc_s
72+
.idle_timeout
73+
.ok_or(
74+
"stateful nat requires idle_timeout, got None".to_string(),
75+
)
76+
.and_then(|t| {
77+
std::time::Duration::try_from(t)
78+
.map_err(|e| format!("Invalid duration: {e}"))
79+
})?,
80+
});
81+
}
82+
}
83+
}
84+
}
85+
}
86+
5787
Ok(vpc_expose)
5888
}
5989
}
@@ -77,7 +107,7 @@ impl TryFrom<&VpcExpose> for gateway_config::Expose {
77107
ips.push(gateway_config::PeeringIPs { rule: Some(rule) });
78108
}
79109

80-
if let Some(nat) = expose.nat.as_ref() {
110+
let nat = if let Some(nat) = expose.nat.as_ref() {
81111
// Convert AS inclusion rules
82112
for prefix in &nat.as_range {
83113
let rule = gateway_config::peering_as::Rule::Cidr(prefix.to_string());
@@ -89,10 +119,29 @@ impl TryFrom<&VpcExpose> for gateway_config::Expose {
89119
let rule = gateway_config::peering_as::Rule::Not(prefix.to_string());
90120
as_rules.push(gateway_config::PeeringAs { rule: Some(rule) });
91121
}
92-
}
122+
123+
match nat.config {
124+
VpcExposeNatConfig::Stateful(config) => {
125+
let idle_timeout =
126+
gateway_config::google::protobuf::Duration::try_from(config.idle_timeout)
127+
.map_err(|e| {
128+
format!("Unable to convert stateful nat idle timeout: {}", e)
129+
})?;
130+
Some(gateway_config::expose::Nat::Stateful(
131+
gateway_config::PeeringStatefulNat { idle_timeout },
132+
))
133+
}
134+
VpcExposeNatConfig::Stateless(config) => Some(
135+
gateway_config::expose::Nat::Stateless(gateway_config::PeeringStatelessNat {}),
136+
),
137+
}
138+
} else {
139+
None
140+
};
93141
Ok(gateway_config::Expose {
94142
ips,
95143
r#as: as_rules,
144+
nat,
96145
})
97146
}
98147
}

config/src/converters/grpc/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,11 +266,17 @@ mod test {
266266
let vpc1_expose = gateway_config::Expose {
267267
ips: vec![include_ip],
268268
r#as: vec![include_as],
269+
nat: Some(gateway_config::config::expose::Nat::Stateless(
270+
gateway_config::config::PeeringStatelessNat {},
271+
)),
269272
};
270273

271274
let vpc2_expose = gateway_config::Expose {
272275
ips: vec![exclude_ip],
273276
r#as: vec![exclude_as],
277+
nat: Some(gateway_config::config::expose::Nat::Stateless(
278+
gateway_config::config::PeeringStatelessNat {},
279+
)),
274280
};
275281

276282
// Create PeeringEntryFor

0 commit comments

Comments
 (0)