From c8c1fe59696c51a162f1d846fe1d2b988b5ac175 Mon Sep 17 00:00:00 2001 From: Andy Fiddaman Date: Wed, 10 Jan 2024 13:58:50 +0000 Subject: [PATCH] Create /etc/inet/hosts as part of zone networking setup --- Cargo.lock | 1 + zone-network-setup/Cargo.toml | 1 + zone-network-setup/src/bin/zone-networking.rs | 21 ++++++++++++++++++- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 7db604dcb5..bcfcdc3082 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10310,6 +10310,7 @@ dependencies = [ "omicron-workspace-hack", "slog", "tokio", + "zone", ] [[package]] diff --git a/zone-network-setup/Cargo.toml b/zone-network-setup/Cargo.toml index 10eec5c554..28854b82f7 100644 --- a/zone-network-setup/Cargo.toml +++ b/zone-network-setup/Cargo.toml @@ -13,3 +13,4 @@ slog.workspace = true dropshot.workspace = true tokio.workspace = true omicron-workspace-hack.workspace = true +zone.workspace = true diff --git a/zone-network-setup/src/bin/zone-networking.rs b/zone-network-setup/src/bin/zone-networking.rs index b955ca856a..f3d18832c5 100644 --- a/zone-network-setup/src/bin/zone-networking.rs +++ b/zone-network-setup/src/bin/zone-networking.rs @@ -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 { if s == "unknown" { return Err(anyhow!("ERROR: Missing input value")); @@ -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)))?; @@ -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(()) }