Skip to content

Commit

Permalink
setup/teardown: also go through port forwarding when no mapping
Browse files Browse the repository at this point in the history
Use an empty vec if port_bindings is None, so we can always go through
port binding setup and teardown as long as an IP is set.

This is a requirement to setup port forwarding for DNS requests when
binding aardvark-dns to an ephemeral port as that defines its own port
forwarding.

Signed-off-by: Dominique Martinet <[email protected]>
  • Loading branch information
martinetd committed Jul 1, 2022
1 parent a3299c1 commit 39e9d0f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 24 deletions.
17 changes: 5 additions & 12 deletions src/commands/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,21 +123,14 @@ impl Setup {
network_hash_name: id_network_hash.clone(),
};
firewall_driver.setup_network(sn)?;
let port_bindings = network_options.port_mappings.clone();
match port_bindings {
match per_network_opts.static_ips.as_ref() {
None => {}
Some(i) => {
let container_ips =
per_network_opts.static_ips.as_ref().ok_or_else(|| {
std::io::Error::new(
std::io::ErrorKind::Other,
"no container ip provided",
)
})?;
Some(container_ips) => {
let port_bindings = network_options.port_mappings.clone();
let networks = network.subnets.as_ref().ok_or_else(|| {
std::io::Error::new(
std::io::ErrorKind::Other,
"no network address provided",
"IP assigned but no network address provided",
)
})?;
let mut has_ipv4 = false;
Expand Down Expand Up @@ -167,7 +160,7 @@ impl Setup {
let spf = PortForwardConfig {
net: network.clone(),
container_id: network_options.container_id.clone(),
port_mappings: i.clone(),
port_mappings: port_bindings.unwrap_or(vec![]),
network_name: (*net_name).clone(),
network_hash_name: id_network_hash.clone(),
container_ip_v4: addr_v4,
Expand Down
17 changes: 5 additions & 12 deletions src/commands/teardown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,21 +100,14 @@ impl Teardown {
);

if !network.internal {
let port_bindings = network_options.port_mappings.clone();
match port_bindings {
match per_network_opts.static_ips.as_ref() {
None => {}
Some(i) => {
let container_ips =
per_network_opts.static_ips.as_ref().ok_or_else(|| {
std::io::Error::new(
std::io::ErrorKind::Other,
"no container ip provided",
)
})?;
Some(container_ips) => {
let port_bindings = network_options.port_mappings.clone();
let networks = network.subnets.as_ref().ok_or_else(|| {
std::io::Error::new(
std::io::ErrorKind::Other,
"no network address provided",
"IP assigned but no network address provided",
)
})?;

Expand Down Expand Up @@ -145,7 +138,7 @@ impl Teardown {
let spf = PortForwardConfig {
net: network.clone(),
container_id: network_options.container_id.clone(),
port_mappings: i.clone(),
port_mappings: port_bindings.unwrap_or(vec![]),
network_name: (*net_name).clone(),
network_hash_name: id_network_hash.clone(),
container_ip_v4: addr_v4,
Expand Down

0 comments on commit 39e9d0f

Please sign in to comment.