Skip to content

Commit

Permalink
Create /etc/inet/hosts as part of zone networking setup
Browse files Browse the repository at this point in the history
  • Loading branch information
citrus-it committed Jan 10, 2024
1 parent b9545be commit 2514d41
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions zone-network-setup/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ slog.workspace = true
dropshot.workspace = true
tokio.workspace = true
omicron-workspace-hack.workspace = true
zone.workspace = true
21 changes: 20 additions & 1 deletion zone-network-setup/src/bin/zone-networking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ use illumos_utils::route::Route;
use omicron_common::cmd::fatal;
use omicron_common::cmd::CmdError;
use slog::info;
use std::fs;
use std::net::Ipv6Addr;

pub const HOSTS_FILE: &str = "/etc/inet/hosts";

fn parse_ipv6(s: &str) -> anyhow::Result<Ipv6Addr> {
if s == "unknown" {
return Err(anyhow!("ERROR: Missing input value"));
Expand Down Expand Up @@ -67,11 +70,14 @@ async fn do_run() -> Result<(), CmdError> {
)
.get_matches();

let zonename =
zone::current().await.expect("Could not determine local zone name");
let datalink: &String = matches.get_one("datalink").unwrap();
let static_addr: &Ipv6Addr = matches.get_one("static_addr").unwrap();
let gateway: &Ipv6Addr = matches.get_one("gateway").unwrap();

// TODO: remove when https://github.com/oxidecomputer/stlouis/issues/435 is addressed
// TODO: remove when https://github.com/oxidecomputer/stlouis/issues/435 is
// addressed
info!(&log, "Ensuring a temporary IP interface is created"; "data link" => ?datalink);
Ipadm::set_temp_interface_for_datalink(&datalink)
.map_err(|err| CmdError::Failure(anyhow!(err)))?;
Expand All @@ -88,5 +94,18 @@ async fn do_run() -> Result<(), CmdError> {
Route::ensure_default_route_with_gateway(gateway)
.map_err(|err| CmdError::Failure(anyhow!(err)))?;

info!(&log, "Populating hosts file for zone"; "zonename" => ?zonename);
fs::write(
HOSTS_FILE,
format!(
r#"
::1 localhost loghost
127.0.0.1 localhost loghost
{static_addr} {zonename}.local {zonename}
"#
),
)
.map_err(|err| CmdError::Failure(anyhow!(err)))?;

Ok(())
}

0 comments on commit 2514d41

Please sign in to comment.