Skip to content

Commit

Permalink
Add ignore-auto-dns to network model
Browse files Browse the repository at this point in the history
  • Loading branch information
jcronenberg committed Jun 13, 2024
1 parent 07aa987 commit f80fdf4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions rust/agama-server/src/network/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,7 @@ pub struct IpConfig {
pub nameservers: Vec<IpAddr>,
#[serde(skip_serializing_if = "Vec::is_empty")]
pub dns_searchlist: Vec<String>,
pub ignore_auto_dns: bool,
pub gateway4: Option<IpAddr>,
pub gateway6: Option<IpAddr>,
pub routes4: Option<Vec<IpRoute>>,
Expand Down
22 changes: 22 additions & 0 deletions rust/agama-server/src/network/nm/dbus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ fn ip_config_to_ipv4_dbus(ip_config: &IpConfig) -> HashMap<&str, zvariant::Value
("address-data", address_data),
("dns-data", dns_data),
("dns-search", ip_config.dns_searchlist.clone().into()),
("ignore-auto-dns", ip_config.ignore_auto_dns.into()),
("method", ip_config.method4.to_string().into()),
]);

Expand Down Expand Up @@ -334,6 +335,7 @@ fn ip_config_to_ipv6_dbus(ip_config: &IpConfig) -> HashMap<&str, zvariant::Value
("address-data", address_data),
("dns-data", dns_data),
("dns-search", ip_config.dns_searchlist.clone().into()),
("ignore-auto-dns", ip_config.ignore_auto_dns.into()),
("method", ip_config.method6.to_string().into()),
]);

Expand Down Expand Up @@ -682,6 +684,10 @@ fn ip_config_from_dbus(conn: &OwnedNestedHash) -> Option<IpConfig> {
ip_config.dns_searchlist.append(&mut searchlist);
}

if let Some(ignore_auto_dns) = ipv4.get("ignore-auto-dns") {
ip_config.ignore_auto_dns = ignore_auto_dns.try_into().ok()?;
}

if let Some(route_data) = ipv4.get("route-data") {
ip_config.routes4 = routes_from_dbus(route_data);
}
Expand Down Expand Up @@ -716,6 +722,10 @@ fn ip_config_from_dbus(conn: &OwnedNestedHash) -> Option<IpConfig> {
ip_config.dns_searchlist.append(&mut searchlist);
}

if let Some(ignore_auto_dns) = ipv6.get("ignore-auto-dns") {
ip_config.ignore_auto_dns = ignore_auto_dns.try_into().ok()?;
}

if let Some(route_data) = ipv6.get("route-data") {
ip_config.routes6 = routes_from_dbus(route_data);
}
Expand Down Expand Up @@ -987,6 +997,7 @@ mod test {
"dns-search".to_string(),
Value::new(vec!["suse.com", "example.com"]).to_owned(),
),
("ignore-auto-dns".to_string(), Value::new(true).to_owned()),
(
"route-data".to_string(),
Value::new(route_v4_data).to_owned(),
Expand Down Expand Up @@ -1073,6 +1084,7 @@ mod test {
assert!(ip_config
.dns_searchlist
.contains(&"example.com".to_string()));
assert!(ip_config.ignore_auto_dns);
assert_eq!(ip_config.method4, Ipv4Method::Auto);
assert_eq!(ip_config.method6, Ipv6Method::Auto);
assert_eq!(
Expand Down Expand Up @@ -1570,6 +1582,11 @@ mod test {
assert_eq!(dns_searchlist.len(), 2);
assert!(dns_searchlist.contains(&"suse.com".to_string()));
assert!(dns_searchlist.contains(&"suse.de".to_string()));
assert!(!ipv4_dbus
.get("ignore-auto-dns")
.unwrap()
.downcast_ref::<bool>()
.unwrap());

let ipv6_dbus = conn_dbus.get("ipv6").unwrap();
let gateway6: &str = ipv6_dbus.get("gateway").unwrap().downcast_ref().unwrap();
Expand Down Expand Up @@ -1608,5 +1625,10 @@ mod test {
assert_eq!(dns_searchlist.len(), 2);
assert!(dns_searchlist.contains(&"suse.com".to_string()));
assert!(dns_searchlist.contains(&"suse.de".to_string()));
assert!(!ipv6_dbus
.get("ignore-auto-dns")
.unwrap()
.downcast_ref::<bool>()
.unwrap());
}
}

0 comments on commit f80fdf4

Please sign in to comment.