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

Zone network configuration service #4677

Merged
merged 21 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
14 changes: 14 additions & 0 deletions Cargo.lock

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

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ members = [
"wicket",
"wicketd",
"workspace-hack",
"zone-network-setup",
]

default-members = [
Expand Down Expand Up @@ -135,6 +136,7 @@ default-members = [
"wicket-dbg",
"wicket",
"wicketd",
"zone-network-setup",
]
resolver = "2"

Expand Down Expand Up @@ -166,7 +168,7 @@ chacha20poly1305 = "0.10.1"
ciborium = "0.2.1"
cfg-if = "1.0"
chrono = { version = "0.4", features = [ "serde" ] }
clap = { version = "4.4", features = ["derive", "env", "wrap_help"] }
clap = { version = "4.4", features = ["cargo", "derive", "env", "wrap_help"] }
cookie = "0.18"
criterion = { version = "0.5.1", features = [ "async_tokio" ] }
crossbeam = "0.8"
Expand Down
110 changes: 110 additions & 0 deletions illumos-utils/src/ipadm.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

//! Utilities for managing IP interfaces.

use crate::zone::IPADM;
use crate::{execute, ExecutionError, PFEXEC};
use std::net::Ipv6Addr;

/// Wraps commands for interacting with interfaces.
pub struct Ipadm {}

#[cfg_attr(any(test, feature = "testing"), mockall::automock, allow(dead_code))]
impl Ipadm {
// Remove current IP interface and create a new temporary one.
pub fn set_temp_interface_for_datalink(
datalink: &str,
) -> Result<(), ExecutionError> {
let mut cmd = std::process::Command::new(PFEXEC);
let cmd = cmd.args(&[IPADM, "delete-if", datalink]);
// First we remove IP interface if it already exists. If it doesn't
// exist and the command returns an error we continue anyway as
// the next step is to create it.
let _ = execute(cmd);

let mut cmd = std::process::Command::new(PFEXEC);
let cmd = cmd.args(&[IPADM, "create-if", "-t", datalink]);
execute(cmd)?;
Ok(())
}

// Set MTU to 9000 on both IPv4 and IPv6
pub fn set_interface_mtu(datalink: &str) -> Result<(), ExecutionError> {
let mut cmd = std::process::Command::new(PFEXEC);
let cmd = cmd.args(&[
IPADM,
"set-ifprop",
"-t",
"-p",
"mtu=9000",
"-m",
"ipv4",
datalink,
]);
execute(cmd)?;

let mut cmd = std::process::Command::new(PFEXEC);
let cmd = cmd.args(&[
IPADM,
"set-ifprop",
"-t",
"-p",
"mtu=9000",
"-m",
"ipv6",
datalink,
]);
execute(cmd)?;
Ok(())
}

pub fn create_static_and_autoconfigured_addrs(
datalink: &str,
listen_addr: &Ipv6Addr,
) -> Result<(), ExecutionError> {
// Create auto-configured address on the IP interface if it doesn't already exist
let addrobj = format!("{}/ll", datalink);
let mut cmd = std::process::Command::new(PFEXEC);
let cmd = cmd.args(&[IPADM, "show-addr", &addrobj]);
match execute(cmd) {
Err(_) => {
let mut cmd = std::process::Command::new(PFEXEC);
let cmd = cmd.args(&[
IPADM,
"create-addr",
"-t",
"-T",
"addrconf",
&addrobj,
]);
execute(cmd)?;
}
Ok(_) => (),
};

// Create static address on the IP interface if it doesn't already exist
let addrobj = format!("{}/omicron6", datalink);
let mut cmd = std::process::Command::new(PFEXEC);
let cmd = cmd.args(&[IPADM, "show-addr", &addrobj]);
match execute(cmd) {
Err(_) => {
let mut cmd = std::process::Command::new(PFEXEC);
let cmd = cmd.args(&[
IPADM,
"create-addr",
"-t",
"-T",
"static",
"-a",
&listen_addr.to_string(),
&addrobj,
]);
execute(cmd)?;
}
Ok(_) => (),
};
Ok(())
}
}
2 changes: 2 additions & 0 deletions illumos-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ pub mod dkio;
pub mod dladm;
pub mod dumpadm;
pub mod fstyp;
pub mod ipadm;
pub mod libc;
pub mod link;
pub mod opte;
pub mod route;
pub mod running_zone;
pub mod scf;
pub mod svc;
Expand Down
47 changes: 47 additions & 0 deletions illumos-utils/src/route.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

//! Utilities for manipulating the routing tables.

use crate::zone::ROUTE;
use crate::{execute, ExecutionError, PFEXEC};
use std::net::Ipv6Addr;

/// Wraps commands for interacting with routing tables.
pub struct Route {}

#[cfg_attr(any(test, feature = "testing"), mockall::automock, allow(dead_code))]
impl Route {
pub fn ensure_default_route_with_gateway(
gateway: &Ipv6Addr,
) -> Result<(), ExecutionError> {
// Add the desired route if it doesn't already exist
let destination = "default";
let mut cmd = std::process::Command::new(PFEXEC);
let cmd = cmd.args(&[
ROUTE,
"get",
citrus-it marked this conversation as resolved.
Show resolved Hide resolved
"-inet6",
destination,
"-inet6",
&gateway.to_string(),
]);
match execute(cmd) {
Err(_) => {
citrus-it marked this conversation as resolved.
Show resolved Hide resolved
let mut cmd = std::process::Command::new(PFEXEC);
let cmd = cmd.args(&[
ROUTE,
"add",
"-inet6",
destination,
"-inet6",
&gateway.to_string(),
]);
execute(cmd)?;
}
Ok(_) => (),
};
Ok(())
}
}
1 change: 1 addition & 0 deletions illumos-utils/src/zone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub const IPADM: &str = "/usr/sbin/ipadm";
pub const SVCADM: &str = "/usr/sbin/svcadm";
pub const SVCCFG: &str = "/usr/sbin/svccfg";
pub const ZLOGIN: &str = "/usr/sbin/zlogin";
pub const ROUTE: &str = "/usr/sbin/route";

// TODO: These could become enums
pub const ZONE_PREFIX: &str = "oxz_";
Expand Down
19 changes: 16 additions & 3 deletions package-manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ output.type = "zone"
service_name = "clickhouse"
only_for_targets.image = "standard"
source.type = "composite"
source.packages = [ "clickhouse_svc.tar.gz", "internal-dns-cli.tar.gz" ]
source.packages = [ "clickhouse_svc.tar.gz", "internal-dns-cli.tar.gz", "zone-network-setup.tar.gz" ]
output.type = "zone"

[package.clickhouse_svc]
Expand All @@ -140,7 +140,7 @@ setup_hint = "Run `./tools/ci_download_clickhouse` to download the necessary bin
service_name = "clickhouse_keeper"
only_for_targets.image = "standard"
source.type = "composite"
source.packages = [ "clickhouse_keeper_svc.tar.gz", "internal-dns-cli.tar.gz" ]
source.packages = [ "clickhouse_keeper_svc.tar.gz", "internal-dns-cli.tar.gz", "zone-network-setup.tar.gz" ]
output.type = "zone"

[package.clickhouse_keeper_svc]
Expand All @@ -161,7 +161,7 @@ setup_hint = "Run `./tools/ci_download_clickhouse` to download the necessary bin
service_name = "cockroachdb"
only_for_targets.image = "standard"
source.type = "composite"
source.packages = [ "cockroachdb-service.tar.gz", "internal-dns-cli.tar.gz" ]
source.packages = [ "cockroachdb-service.tar.gz", "internal-dns-cli.tar.gz", "zone-network-setup.tar.gz" ]
output.type = "zone"

[package.cockroachdb-service]
Expand Down Expand Up @@ -601,3 +601,16 @@ source.packages = [
"sp-sim-softnpu.tar.gz"
]
output.type = "zone"

[package.zone-network-setup]
service_name = "zone-network-setup"
only_for_targets.image = "standard"
source.type = "local"
source.rust.binary_names = ["zone-networking"]
source.rust.release = true
source.paths = [
{ from = "smf/zone-network-setup/manifest.xml", to = "/var/svc/manifest/site/zone-network-setup/manifest.xml" },
{ from = "smf/zone-network-setup/method_script.sh", to = "/opt/oxide/lib/svc/manifest/zone-network-setup.sh" },
citrus-it marked this conversation as resolved.
Show resolved Hide resolved
]
output.type = "zone"
output.intermediate_only = true
Loading
Loading