Skip to content

Commit

Permalink
Chore(NODE-1249): Remove ipv6 name server propagation and hard-code v…
Browse files Browse the repository at this point in the history
…alues into networking code
  • Loading branch information
andrewbattat committed Feb 8, 2024
1 parent 506f148 commit 226246b
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 147 deletions.
2 changes: 0 additions & 2 deletions ic-os/guestos/docs/ConfigStore.adoc
Expand Up @@ -61,8 +61,6 @@ Must be a file of key/value pairs separated by "=" (one per line) with the follo

- *ipv6_gateway*: The default IPv6 gateway, only meaningful if ipv6_address is also provided.

- *name_servers*: The ipv6 name servers to be used. If multiple servers are needed, separate them with spaces. This key is only meaningful if DHCP or SLAAC is not used.

- *hostname*: The hostname, which can be any text in principle but is generally derived from the ID of the physical host (e.g., MAC address).

Note: if this file is not given, the system will fall back to network auto configuration.
Expand Down
1 change: 0 additions & 1 deletion ic-os/guestos/rootfs/opt/ic/bin/generate-replica-config.sh
Expand Up @@ -75,7 +75,6 @@ function read_network_variables() {
"hostname") hostname="${value}" ;;
"ipv6_address") ipv6_address="${value}" ;;
"ipv6_gateway") ipv6_gateway="${value}" ;;
"name_servers") name_servers="${value}" ;;
"ipv4_address") ipv4_address="${value}" ;;
"ipv4_gateway") ipv4_gateway="${value}" ;;
"domain") domain="${value}" ;;
Expand Down
1 change: 0 additions & 1 deletion ic-os/hostos/rootfs/opt/ic/bin/generate-guestos-config.sh
Expand Up @@ -104,7 +104,6 @@ function assemble_config_media() {
cmd+=(--elasticsearch_hosts "$(/opt/ic/bin/fetch-property.sh --key=.logging.hosts --metric=hostos_logging_hosts --config=${DEPLOYMENT})")
cmd+=(--ipv6_address "$(/opt/ic/bin/hostos_tool generate-ipv6-address --node-type GuestOS)")
cmd+=(--ipv6_gateway "${ipv6_gateway}")
cmd+=(--ipv6_name_servers "$(/opt/ic/bin/fetch-property.sh --key=.dns.name_servers --metric=hostos_ipv6_dns_name_servers --config=${DEPLOYMENT})")
if [[ -n "$ipv4_address" && -n "$ipv4_prefix_length" && -n "$ipv4_gateway" && -n "$domain" ]]; then
cmd+=(--ipv4_address "${ipv4_address}/${ipv4_prefix_length}")
cmd+=(--ipv4_gateway "${ipv4_gateway}")
Expand Down
12 changes: 1 addition & 11 deletions ic-os/scripts/build-bootstrap-config-image.sh
Expand Up @@ -27,12 +27,6 @@ options may be specified:
--ipv6_gateway a:b::c
Default IPv6 gateway.
--ipv6_name_servers servers
ipv6 DNS servers to use. Can be multiple servers separated by space (make
sure to quote the argument string so it appears as a single argument to the
script, e.g. --ipv6_name_servers "2606:4700:4700::1111
2606:4700:4700::1001").
--ipv4_address a.b.c.d/n
(optional) The IPv4 address to assign. Must include prefix length (e.g.
18.208.190.35/28).
Expand Down Expand Up @@ -130,7 +124,7 @@ function build_ic_bootstrap_tar() {
local OUT_FILE="$1"
shift

local IPV6_ADDRESS IPV6_GATEWAY IPV6_NAME_SERVERS DOMAIN HOSTNAME
local IPV6_ADDRESS IPV6_GATEWAY DOMAIN HOSTNAME
local IC_CRYPTO IC_REGISTRY_LOCAL_STORE
local NNS_URL NNS_PUBLIC_KEY NODE_OPERATOR_PRIVATE_KEY
local BACKUP_RETENTION_TIME_SECS BACKUP_PURGING_INTERVAL_SECS
Expand All @@ -153,9 +147,6 @@ function build_ic_bootstrap_tar() {
--ipv6_gateway)
IPV6_GATEWAY="$2"
;;
--ipv6_name_servers)
IPV6_NAME_SERVERS="$2"
;;
--ipv4_address)
IPV4_ADDRESS="$2"
;;
Expand Down Expand Up @@ -233,7 +224,6 @@ function build_ic_bootstrap_tar() {
cat >"${BOOTSTRAP_TMPDIR}/network.conf" <<EOF
${IPV6_ADDRESS:+ipv6_address=$IPV6_ADDRESS}
${IPV6_GATEWAY:+ipv6_gateway=$IPV6_GATEWAY}
name_servers=$IPV6_NAME_SERVERS
hostname=$HOSTNAME
${IPV4_ADDRESS:+ipv4_address=$IPV4_ADDRESS}
${IPV4_GATEWAY:+ipv4_gateway=$IPV4_GATEWAY}
Expand Down
3 changes: 0 additions & 3 deletions ic-os/setupos/data/deployment.json.template
Expand Up @@ -8,9 +8,6 @@
"nns": {
"url": "NNS_URL"
},
"dns": {
"name_servers": "2606:4700:4700::1111 2606:4700:4700::1001 2001:4860:4860::8888 2001:4860:4860::8844"
},
"resources": {
"memory": "490"
}
Expand Down
83 changes: 23 additions & 60 deletions rs/ic_os/guestos_tool/src/generate_network_config.rs
Expand Up @@ -8,9 +8,10 @@ use anyhow::{bail, Context, Result};

use config::config_map_from_path;
use network::interfaces::{get_interface_name as get_valid_interface_name, get_interface_paths};
use network::systemd::generate_ipv6_nameserver_list;
use utils::get_command_stdout;

use network::systemd::IPV6_NAME_SERVER_NETWORKD_CONTENTS;

pub static DEFAULT_GUESTOS_NETWORK_CONFIG_PATH: &str = "/boot/config/network.conf";

const IPV4_NAME_SERVER_NETWORKD_CONTENTS: &str =
Expand All @@ -19,7 +20,6 @@ const IPV4_NAME_SERVER_NETWORKD_CONTENTS: &str =
#[derive(Debug)]
struct NetworkInfo {
ipv6_info: Option<IpAddressInfo>,
ipv6_name_servers: Option<String>,
ipv4_info: Option<IpAddressInfo>,
}

Expand Down Expand Up @@ -165,15 +165,8 @@ fn create_network_info(
_ => None,
};

let ipv6_name_servers = network_config_variables
.get("name_servers")
.map(|ipv6_name_servers| ipv6_name_servers.split_whitespace())
.map(generate_ipv6_nameserver_list)
.transpose()?;

Ok(NetworkInfo {
ipv6_info,
ipv6_name_servers,
ipv4_info,
})
}
Expand All @@ -200,13 +193,9 @@ fn generate_networkd_config_contents(
) -> String {
let match_contents = generate_network_config_match_contents(interface_name);
let ipv6_contents = generate_network_config_ipv6_contents(network_info.ipv6_info, disable_dad);
let ipv6_name_servers = generate_network_config_dns_contents(network_info.ipv6_name_servers);
let ipv4_contents = generate_network_config_ipv4_contents(network_info.ipv4_info);

format!(
"{}{}{}\n{}",
match_contents, ipv6_contents, ipv6_name_servers, ipv4_contents
)
format!("{}{}{}", match_contents, ipv6_contents, ipv4_contents)
}

fn generate_network_config_match_contents(interface_name: &str) -> String {
Expand All @@ -232,6 +221,7 @@ fn generate_network_config_ipv6_contents(
Address={ipv6_address}
Gateway={ipv6_gateway}
IPv6AcceptRA=false
{IPV6_NAME_SERVER_NETWORKD_CONTENTS}
"#,
);
if disable_dad {
Expand All @@ -248,10 +238,6 @@ fn generate_network_config_ipv6_contents(
}
}

fn generate_network_config_dns_contents(name_servers: Option<String>) -> String {
name_servers.unwrap_or_default()
}

fn generate_network_config_ipv4_contents(ipv4_info: Option<IpAddressInfo>) -> String {
ipv4_info
.map(|ipv4_info| {
Expand Down Expand Up @@ -319,11 +305,6 @@ mod tests {
let mut network_config_variables = HashMap::new();
network_config_variables.insert("ipv6_address".to_string(), "2001:db8::1/64".to_string());
network_config_variables.insert("ipv6_gateway".to_string(), "2001:db8::1".to_string());
network_config_variables.insert(
"name_servers".to_string(),
"2606:4700:4700::1111 2606:4700:4700::1001 2001:4860:4860::8888 2001:4860:4860::8844"
.to_string(),
);

eprintln!("network_config_variables: {:?}", network_config_variables);

Expand All @@ -340,22 +321,13 @@ mod tests {
let ipv4_info = result.ipv4_info.as_ref().unwrap();
assert_eq!(ipv4_info.address_with_prefix, "192.168.1.100/30");
assert_eq!(ipv4_info.gateway, "192.168.1.1");

assert!(result.ipv6_name_servers.is_some());
let ipv6_name_servers = result.ipv6_name_servers.unwrap();
assert_eq!(ipv6_name_servers, "DNS=2606:4700:4700::1111\nDNS=2606:4700:4700::1001\nDNS=2001:4860:4860::8888\nDNS=2001:4860:4860::8844\n");
}

#[test]
fn test_create_network_info_with_valid_ipv6_and_no_ipv4() {
let mut network_config_variables = HashMap::new();
network_config_variables.insert("ipv6_address".to_string(), "2001:db8::1/64".to_string());
network_config_variables.insert("ipv6_gateway".to_string(), "2001:db8::1".to_string());
network_config_variables.insert(
"name_servers".to_string(),
"2606:4700:4700::1111 2606:4700:4700::1001 2001:4860:4860::8888 2001:4860:4860::8844"
.to_string(),
);

eprintln!("network_config_variables: {:?}", network_config_variables);

Expand All @@ -367,22 +339,13 @@ mod tests {
let ipv6_info = result.ipv6_info.as_ref().unwrap();
assert_eq!(ipv6_info.address_with_prefix, "2001:db8::1/64");
assert_eq!(ipv6_info.gateway, "2001:db8::1");

assert!(result.ipv6_name_servers.is_some());
let ipv6_name_servers = result.ipv6_name_servers.unwrap();
assert_eq!(ipv6_name_servers, "DNS=2606:4700:4700::1111\nDNS=2606:4700:4700::1001\nDNS=2001:4860:4860::8888\nDNS=2001:4860:4860::8844\n");
}

#[test]
fn test_create_network_info_with_invalid_ipv6() {
let mut network_config_variables = HashMap::new();
network_config_variables.insert("ipv6_address".to_string(), "invalid_address".to_string());
network_config_variables.insert("ipv6_gateway".to_string(), "invalid_gateway".to_string());
network_config_variables.insert(
"name_servers".to_string(),
"2606:4700:4700::1111 2606:4700:4700::1001 2001:4860:4860::8888 2001:4860:4860::8844"
.to_string(),
);

let result = create_network_info(&network_config_variables, None);

Expand All @@ -395,11 +358,6 @@ mod tests {
network_config_variables.insert("ipv6_address".to_string(), "invalid_address".to_string());
// ipv6 gateway intentionally omitted:
// network_config_variables.insert("ipv6_gateway".to_string(), "invalid_gateway".to_string());
network_config_variables.insert(
"name_servers".to_string(),
"2606:4700:4700::1111 2606:4700:4700::1001 2001:4860:4860::8888 2001:4860:4860::8844"
.to_string(),
);

let result = create_network_info(&network_config_variables, None);

Expand All @@ -415,7 +373,6 @@ mod tests {

let result = create_network_info(&network_config_variables, None).unwrap();
assert!(result.ipv6_info.is_none());
assert!(result.ipv6_name_servers.is_none());
}

#[test]
Expand Down Expand Up @@ -481,61 +438,67 @@ mod tests {
#[test]
fn test_generate_networkd_config_contents_with_full_networking_info() {
let network_info = NetworkInfo {
ipv6_info: Some(IpAddressInfo::new_ipv6_address("2001:db8::1/64", "2001:db8::1").unwrap()),
ipv6_name_servers: Some("DNS=2606:4700:4700::1111\nDNS=2606:4700:4700::1001\nDNS=2001:4860:4860::8888\nDNS=2001:4860:4860::8844\n".to_string()),
ipv4_info: Some(IpAddressInfo::new_ipv4_address("192.168.1.100", "30", "192.168.1.1").unwrap()),
ipv6_info: Some(
IpAddressInfo::new_ipv6_address("2001:db8::1/64", "2001:db8::1").unwrap(),
),
ipv4_info: Some(
IpAddressInfo::new_ipv4_address("192.168.1.100", "30", "192.168.1.1").unwrap(),
),
};
let interface_name = "enp65s0f1";

let result = generate_networkd_config_contents(network_info, interface_name, false);

let expected_output = "[Match]\nName=enp65s0f1\nVirtualization=!container\n[Network]\nAddress=2001:db8::1/64\nGateway=2001:db8::1\nIPv6AcceptRA=false\nDNS=2606:4700:4700::1111\nDNS=2606:4700:4700::1001\nDNS=2001:4860:4860::8888\nDNS=2001:4860:4860::8844\n\nAddress=192.168.1.100/30\nGateway=192.168.1.1\nDNS=1.1.1.1\nDNS=1.0.0.1\nDNS=8.8.8.8\nDNS=8.8.4.4\n\n";
let expected_output = "[Match]\nName=enp65s0f1\nVirtualization=!container\n[Network]\nAddress=2001:db8::1/64\nGateway=2001:db8::1\nIPv6AcceptRA=false\n\nDNS=2606:4700:4700::1111\nDNS=2606:4700:4700::1001\nDNS=2001:4860:4860::8888\nDNS=2001:4860:4860::8844\n\nAddress=192.168.1.100/30\nGateway=192.168.1.1\nDNS=1.1.1.1\nDNS=1.0.0.1\nDNS=8.8.8.8\nDNS=8.8.4.4\n\n";
assert_eq!(result, expected_output);
}

#[test]
fn test_generate_networkd_config_contents_with_just_ipv6_networking_info() {
let network_info = NetworkInfo {
ipv6_info: Some(IpAddressInfo::new_ipv6_address("2001:db8::1/64", "2001:db8::1").unwrap()),
ipv6_name_servers: Some("DNS=2606:4700:4700::1111\nDNS=2606:4700:4700::1001\nDNS=2001:4860:4860::8888\nDNS=2001:4860:4860::8844\n".to_string()),
ipv6_info: Some(
IpAddressInfo::new_ipv6_address("2001:db8::1/64", "2001:db8::1").unwrap(),
),
ipv4_info: None,
};
let interface_name = "enp65s0f1";

let result = generate_networkd_config_contents(network_info, interface_name, false);

let expected_output = "[Match]\nName=enp65s0f1\nVirtualization=!container\n[Network]\nAddress=2001:db8::1/64\nGateway=2001:db8::1\nIPv6AcceptRA=false\nDNS=2606:4700:4700::1111\nDNS=2606:4700:4700::1001\nDNS=2001:4860:4860::8888\nDNS=2001:4860:4860::8844\n\n";
let expected_output = "[Match]\nName=enp65s0f1\nVirtualization=!container\n[Network]\nAddress=2001:db8::1/64\nGateway=2001:db8::1\nIPv6AcceptRA=false\n\nDNS=2606:4700:4700::1111\nDNS=2606:4700:4700::1001\nDNS=2001:4860:4860::8888\nDNS=2001:4860:4860::8844\n\n";
assert_eq!(result, expected_output);
}

#[test]
fn test_generate_networkd_config_contents_with_full_info_disable_dad() {
let network_info = NetworkInfo {
ipv6_info: Some(IpAddressInfo::new_ipv6_address("2001:db8::1/64", "2001:db8::1").unwrap()),
ipv6_name_servers: Some("DNS=2606:4700:4700::1111\nDNS=2606:4700:4700::1001\nDNS=2001:4860:4860::8888\nDNS=2001:4860:4860::8844\n".to_string()),
ipv4_info: Some(IpAddressInfo::new_ipv4_address("192.168.1.100", "30", "192.168.1.1").unwrap()),
ipv6_info: Some(
IpAddressInfo::new_ipv6_address("2001:db8::1/64", "2001:db8::1").unwrap(),
),
ipv4_info: Some(
IpAddressInfo::new_ipv4_address("192.168.1.100", "30", "192.168.1.1").unwrap(),
),
};
let interface_name = "enp65s0f1";

let result = generate_networkd_config_contents(network_info, interface_name, true);

let expected_output = "[Match]\nName=enp65s0f1\nVirtualization=!container\n[Network]\nAddress=2001:db8::1/64\nGateway=2001:db8::1\nIPv6AcceptRA=false\nIPv6DuplicateAddressDetection=0\nDNS=2606:4700:4700::1111\nDNS=2606:4700:4700::1001\nDNS=2001:4860:4860::8888\nDNS=2001:4860:4860::8844\n\nAddress=192.168.1.100/30\nGateway=192.168.1.1\nDNS=1.1.1.1\nDNS=1.0.0.1\nDNS=8.8.8.8\nDNS=8.8.4.4\n\n";
let expected_output = "[Match]\nName=enp65s0f1\nVirtualization=!container\n[Network]\nAddress=2001:db8::1/64\nGateway=2001:db8::1\nIPv6AcceptRA=false\n\nDNS=2606:4700:4700::1111\nDNS=2606:4700:4700::1001\nDNS=2001:4860:4860::8888\nDNS=2001:4860:4860::8844\n\nIPv6DuplicateAddressDetection=0\nAddress=192.168.1.100/30\nGateway=192.168.1.1\nDNS=1.1.1.1\nDNS=1.0.0.1\nDNS=8.8.8.8\nDNS=8.8.4.4\n\n";
assert_eq!(result, expected_output);
}

#[test]
fn test_generate_networkd_config_contents_with_no_networking_or_nameservers() {
let network_info = NetworkInfo {
ipv6_info: None,
ipv6_name_servers: None,
ipv4_info: None,
};
let interface_name = "enp65s0f1";

let result = generate_networkd_config_contents(network_info, interface_name, false);

let expected_output =
"[Match]\nName=enp65s0f1\nVirtualization=!container\n[Network]\nIPv6AcceptRA=true\n\n";
"[Match]\nName=enp65s0f1\nVirtualization=!container\n[Network]\nIPv6AcceptRA=true\n";
assert_eq!(result, expected_output);
}
}
10 changes: 3 additions & 7 deletions rs/ic_os/hostos_tool/src/main.rs
Expand Up @@ -65,21 +65,17 @@ pub fn main() -> Result<()> {
eprintln!("Network info config: {:?}", &network_info);

let deployment = read_deployment_file(Path::new(&opts.deployment_file));
let (dns_nameservers, deployment_name) = match &deployment {
Ok(deployment) => (
Some(deployment.dns.name_servers.as_str()),
Some(deployment.deployment.name.as_str()),
),
let deployment_name: Option<&str> = match &deployment {
Ok(deployment) => Some(deployment.deployment.name.as_str()),
Err(e) => {
eprintln!("Error retrieving deployment file: {e}. Continuing without it");
(None, None)
None
}
};

generate_network_config(
&network_info,
deployment_name,
dns_nameservers,
NodeType::HostOS,
Path::new(&output_directory),
)
Expand Down
10 changes: 1 addition & 9 deletions rs/ic_os/network/src/lib.rs
Expand Up @@ -21,19 +21,12 @@ pub mod systemd;
pub fn generate_network_config(
network_info: &NetworkInfo,
deployment_name: Option<&str>,
dns_nameservers: Option<&str>,
node_type: NodeType,
output_directory: &Path,
) -> Result<()> {
if let Some(address) = network_info.ipv6_address {
eprintln!("Found ipv6 address in config");
return generate_systemd_config_files(
output_directory,
dns_nameservers,
network_info,
None,
&address,
);
return generate_systemd_config_files(output_directory, network_info, None, &address);
};

let deployment_name = deployment_name
Expand All @@ -52,7 +45,6 @@ pub fn generate_network_config(
let formatted_mac = FormattedMacAddress::from(&mac);
generate_systemd_config_files(
output_directory,
dns_nameservers,
network_info,
Some(&formatted_mac),
&ipv6_address,
Expand Down

0 comments on commit 226246b

Please sign in to comment.