Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create /etc/inet/hosts as part of zone networking setup #4802

Merged
merged 1 commit into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(())
}
Loading