Skip to content

Commit e94febe

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

File tree

4 files changed

+65
-17
lines changed

4 files changed

+65
-17
lines changed

Cargo.lock

Lines changed: 5 additions & 13 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: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
// SPDX-License-Identifier: Apache-2.0
22
// Copyright Open Network Fabric Authors
33

4+
use ::gateway_config::google;
45
use gateway_config::config as gateway_config;
6+
57
use std::convert::TryFrom;
68

7-
use crate::external::overlay::vpcpeering::VpcExpose;
9+
use crate::external::overlay::vpcpeering::{
10+
VpcExpose, VpcExposeNatConfig, VpcExposeStatefulNat, VpcExposeStatelessNat,
11+
};
812
use lpm::prefix::{Prefix, PrefixString};
913

1014
impl TryFrom<&gateway_config::Expose> for VpcExpose {
@@ -54,6 +58,34 @@ impl TryFrom<&gateway_config::Expose> for VpcExpose {
5458
}
5559
}
5660

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

80-
if let Some(nat) = expose.nat.as_ref() {
112+
let nat = if let Some(nat) = expose.nat.as_ref() {
81113
// Convert AS inclusion rules
82114
for prefix in &nat.as_range {
83115
let rule = gateway_config::peering_as::Rule::Cidr(prefix.to_string());
@@ -89,10 +121,28 @@ impl TryFrom<&VpcExpose> for gateway_config::Expose {
89121
let rule = gateway_config::peering_as::Rule::Not(prefix.to_string());
90122
as_rules.push(gateway_config::PeeringAs { rule: Some(rule) });
91123
}
92-
}
124+
125+
match &nat.config {
126+
VpcExposeNatConfig::Stateful(config) => {
127+
let idle_timeout = google::protobuf::Duration::try_from(config.idle_timeout)
128+
.map_err(|e| format!("Unable to convert stateful nat idle timeout: {e}"))?;
129+
Some(gateway_config::expose::Nat::Stateful(
130+
gateway_config::PeeringStatefulNat {
131+
idle_timeout: Some(idle_timeout),
132+
},
133+
))
134+
}
135+
VpcExposeNatConfig::Stateless(_) => Some(gateway_config::expose::Nat::Stateless(
136+
gateway_config::PeeringStatelessNat {},
137+
)),
138+
}
139+
} else {
140+
None
141+
};
93142
Ok(gateway_config::Expose {
94143
ips,
95144
r#as: as_rules,
145+
nat,
96146
})
97147
}
98148
}

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)