Skip to content

Commit 23b6147

Browse files
committed
Add NAT settings.
1 parent 109ff91 commit 23b6147

File tree

4 files changed

+30
-6
lines changed

4 files changed

+30
-6
lines changed

scripts/deploy-test-contract

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ DEPLOYMENT_FILE=$(mktemp -t timeboost-deployment-XXXXX)
1313

1414
# Fund manager account && create deployment file
1515
cast send --value 1ether -r "$URL" --private-key "$FAUCET_PRIVATE_KEY" "$MANAGER_ADDRESS"
16-
env RUST_LOG=info cargo run --release --bin deploy -- \
16+
env RUST_LOG=info target/release/deploy \
1717
-m "$MANAGER_MNEMONIC" \
1818
-i "$MANAGER_ACCOUNT_INDEX" \
1919
-u "$URL" \
@@ -23,7 +23,7 @@ env RUST_LOG=info cargo run --release --bin deploy -- \
2323
km_addr=$(sed -nr 's/^key_manager.*=.*"(.+)"/\1/p' "$DEPLOYMENT_FILE")
2424

2525
# Update the contract
26-
env RUST_LOG=info cargo run --release --bin register -- \
26+
env RUST_LOG=info target/release/register \
2727
-m "$MANAGER_MNEMONIC" \
2828
-i "$MANAGER_ACCOUNT_INDEX" \
2929
-u "$URL" \

test-configs/linux/net.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
[nat]
2+
table = "nat"
3+
device = "eth0"
4+
cidr = "10.0.0.0/8"
5+
16
[bridge]
27
name = "bridge"
38
cidr = "10.0.1.0/16"

test-utils/src/binaries/net-setup.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![cfg_attr(rustfmt, rustfmt_skip)]
2+
13
use std::{fs, path::PathBuf};
24

35
use anyhow::{Result, ensure};
@@ -45,6 +47,15 @@ fn main() -> Result<()> {
4547
dev.delay(&d.delay, &d.jitter)?
4648
}
4749
}
50+
if let Some(nat) = c.nat {
51+
run_command(TRACE, ["iptables",
52+
"-t", &nat.table,
53+
"-A", "POSTROUTING",
54+
"-s", &nat.cidr.to_string(),
55+
"-o", &nat.device,
56+
"-j", "MASQUERADE"
57+
])?
58+
}
4859
}
4960
Command::Delete { config } => {
5061
let t = fs::read(&config)?;
@@ -53,7 +64,10 @@ fn main() -> Result<()> {
5364
for d in c.device {
5465
Device::new(&d).delete()?
5566
}
56-
b.delete()?
67+
b.delete()?;
68+
if let Some(nat) = c.nat {
69+
run_command(TRACE, ["iptables", "-t", &nat.table, "-F"])?
70+
}
5771
}
5872
}
5973
Ok(())
@@ -77,7 +91,6 @@ impl Device {
7791
}
7892
}
7993

80-
#[rustfmt::skip]
8194
fn create(&self, b: &Bridge) -> Result<()> {
8295
ensure!(b.net.contains(&self.cidr));
8396
run_command(TRACE, ["ip", "netns", "add", &self.space])?;
@@ -91,7 +104,6 @@ impl Device {
91104
run_command(TRACE, ["ip", "netns", "exec", &self.space, "ip", "route", "add", "default", "via", &b.net.addr().to_string()])
92105
}
93106

94-
#[rustfmt::skip]
95107
fn delay(&self, delay: &Span, jitter: &Span) -> Result<()> {
96108
let d = format!("{}ms", delay.get_milliseconds());
97109
let j = format!("{}ms", jitter.get_milliseconds());
@@ -113,7 +125,6 @@ struct Bridge {
113125
net: Ipv4Net,
114126
}
115127

116-
#[rustfmt::skip]
117128
impl Bridge {
118129
fn new(name: &str, ip: Ipv4Net) -> Self {
119130
Self { name: name.to_string(), net: ip }

test-utils/src/net.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use serde::Deserialize;
66
pub struct Config {
77
pub bridge: BridgeConfig,
88
pub device: Vec<DeviceConfig>,
9+
pub nat: Option<NatConfig>,
910
}
1011

1112
#[derive(Deserialize)]
@@ -27,6 +28,13 @@ pub struct DeviceConfig {
2728
pub jitter: Span,
2829
}
2930

31+
#[derive(Deserialize)]
32+
pub struct NatConfig {
33+
pub table: String,
34+
pub device: String,
35+
pub cidr: Ipv4Net,
36+
}
37+
3038
impl DeviceConfig {
3139
pub fn namespace(&self) -> String {
3240
format!("ns-{}", self.name)

0 commit comments

Comments
 (0)