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

Add more dns options to network settings #1330

Merged
merged 4 commits into from
Jul 17, 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
12 changes: 12 additions & 0 deletions rust/agama-lib/share/profile.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,18 @@
"type": "string"
}
},
"dns_searchlist": {
"type": "array",
"items": {
"description": "DNS search domains",
"type": "string",
"additionalProperties": false
}
},
"ignore_auto_dns": {
"description": "Whether DNS options provided via DHCP are used or not",
"type": "boolean"
},
"wireless": {
"type": "object",
"title": "Wireless configuration",
Expand Down
12 changes: 12 additions & 0 deletions rust/agama-lib/src/network/proxies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,18 @@ trait IP {
fn nameservers(&self) -> zbus::Result<Vec<String>>;
#[dbus_proxy(property)]
fn set_nameservers(&self, value: &[&str]) -> zbus::Result<()>;

/// DNS searchlist property
#[dbus_proxy(property)]
fn dns_searchlist(&self) -> zbus::Result<Vec<String>>;
#[dbus_proxy(property)]
fn set_dns_searchlist(&self, value: &[&str]) -> zbus::Result<()>;

/// Ignore auto DNS property
#[dbus_proxy(property)]
fn ignore_auto_dns(&self) -> zbus::Result<bool>;
#[dbus_proxy(property)]
fn set_ignore_auto_dns(&self, value: bool) -> zbus::Result<()>;
}

#[dbus_proxy(
Expand Down
4 changes: 4 additions & 0 deletions rust/agama-lib/src/network/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ pub struct NetworkConnection {
pub addresses: Vec<IpInet>,
#[serde(skip_serializing_if = "Vec::is_empty", default)]
pub nameservers: Vec<IpAddr>,
#[serde(skip_serializing_if = "Vec::is_empty", default)]
pub dns_searchlist: Vec<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub ignore_auto_dns: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub wireless: Option<WirelessSettings>,
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down
12 changes: 12 additions & 0 deletions rust/agama-server/src/network/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,10 @@ impl TryFrom<NetworkConnection> for Connection {
connection.status = status;
}

if let Some(ignore_auto_dns) = conn.ignore_auto_dns {
connection.ip_config.ignore_auto_dns = ignore_auto_dns;
}

if let Some(wireless_config) = conn.wireless {
let config = WirelessConfig::try_from(wireless_config)?;
connection.config = config.into();
Expand All @@ -597,6 +601,7 @@ impl TryFrom<NetworkConnection> for Connection {

connection.ip_config.addresses = conn.addresses;
connection.ip_config.nameservers = conn.nameservers;
connection.ip_config.dns_searchlist = conn.dns_searchlist;
connection.ip_config.gateway4 = conn.gateway4;
connection.ip_config.gateway6 = conn.gateway6;
connection.interface = conn.interface;
Expand All @@ -616,6 +621,8 @@ impl TryFrom<Connection> for NetworkConnection {
let method6 = Some(conn.ip_config.method6.to_string());
let mac_address = (!mac.is_empty()).then_some(mac);
let nameservers = conn.ip_config.nameservers;
let dns_searchlist = conn.ip_config.dns_searchlist;
let ignore_auto_dns = Some(conn.ip_config.ignore_auto_dns);
let addresses = conn.ip_config.addresses;
let gateway4 = conn.ip_config.gateway4;
let gateway6 = conn.ip_config.gateway6;
Expand All @@ -631,6 +638,8 @@ impl TryFrom<Connection> for NetworkConnection {
gateway4,
gateway6,
nameservers,
dns_searchlist,
ignore_auto_dns,
mac_address,
interface,
addresses,
Expand Down Expand Up @@ -759,6 +768,9 @@ pub struct IpConfig {
pub addresses: Vec<IpInet>,
#[serde(skip_serializing_if = "Vec::is_empty")]
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
97 changes: 97 additions & 0 deletions rust/agama-server/src/network/nm/dbus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@ fn ip_config_to_ipv4_dbus(ip_config: &IpConfig) -> HashMap<&str, zvariant::Value
let mut ipv4_dbus = HashMap::from([
("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 @@ -342,6 +344,8 @@ fn ip_config_to_ipv6_dbus(ip_config: &IpConfig) -> HashMap<&str, zvariant::Value
let mut ipv6_dbus = HashMap::from([
("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 @@ -718,6 +722,24 @@ fn ip_config_from_dbus(conn: &OwnedNestedHash) -> Option<IpConfig> {
ip_config.nameservers.append(&mut servers);
}

if let Some(dns_search) = ipv4.get("dns-search") {
let searchlist: Vec<String> = dns_search
.downcast_ref::<zbus::zvariant::Array>()?
.iter()
.flat_map(|x| x.downcast_ref::<str>())
.map(|x| x.to_string())
.collect();
for searchdomain in searchlist {
if !ip_config.dns_searchlist.contains(&searchdomain) {
ip_config.dns_searchlist.push(searchdomain);
}
}
}

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 All @@ -742,6 +764,24 @@ fn ip_config_from_dbus(conn: &OwnedNestedHash) -> Option<IpConfig> {
ip_config.nameservers.append(&mut servers);
}

if let Some(dns_search) = ipv6.get("dns-search") {
let searchlist: Vec<String> = dns_search
.downcast_ref::<zbus::zvariant::Array>()?
.iter()
.flat_map(|x| x.downcast_ref::<str>())
.map(|x| x.to_string())
.collect();
for searchdomain in searchlist {
if !ip_config.dns_searchlist.contains(&searchdomain) {
ip_config.dns_searchlist.push(searchdomain);
}
}
}

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 @@ -1005,6 +1045,11 @@ mod test {
"dns-data".to_string(),
Value::new(vec!["192.168.0.2"]).to_owned(),
),
(
"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 @@ -1037,6 +1082,10 @@ mod test {
"dns-data".to_string(),
Value::new(vec!["::ffff:c0a8:102"]).to_owned(),
),
(
"dns-search".to_string(),
Value::new(vec!["suse.com", "suse.de"]).to_owned(),
),
(
"route-data".to_string(),
Value::new(route_v6_data).to_owned(),
Expand Down Expand Up @@ -1081,6 +1130,13 @@ mod test {
"::ffff:c0a8:102".parse::<IpAddr>().unwrap()
]
);
assert_eq!(ip_config.dns_searchlist.len(), 3);
assert!(ip_config.dns_searchlist.contains(&"suse.com".to_string()));
assert!(ip_config.dns_searchlist.contains(&"suse.de".to_string()));
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 @@ -1506,6 +1562,7 @@ mod test {
next_hop: Some(IpAddr::from_str("2001:db8::1").unwrap()),
metric: Some(100),
}]),
dns_searchlist: vec!["suse.com".to_string(), "suse.de".to_string()],
..Default::default()
};
let mac_address = MacAddress::from_str("FD:CB:A9:87:65:43").unwrap();
Expand Down Expand Up @@ -1562,6 +1619,26 @@ mod test {
assert!(route4_hashmap.contains_key("metric"));
assert_eq!(route4_hashmap["metric"], Value::from(100_u32));
}
let dns_searchlist_array: Array = ipv4_dbus
.get("dns-search")
.unwrap()
.downcast_ref::<Value>()
.unwrap()
.try_into()
.unwrap();
let dns_searchlist: Vec<String> = dns_searchlist_array
.iter()
.flat_map(|x| x.downcast_ref::<str>())
.map(|x| x.to_string())
.collect();
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 All @@ -1585,5 +1662,25 @@ mod test {
assert!(route6_hashmap.contains_key("metric"));
assert_eq!(route6_hashmap["metric"], Value::from(100_u32));
}
let dns_searchlist_array: Array = ipv6_dbus
.get("dns-search")
.unwrap()
.downcast_ref::<Value>()
.unwrap()
.try_into()
.unwrap();
let dns_searchlist: Vec<String> = dns_searchlist_array
.iter()
.flat_map(|x| x.downcast_ref::<str>())
.map(|x| x.to_string())
.collect();
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());
}
}
6 changes: 6 additions & 0 deletions rust/package/agama.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
-------------------------------------------------------------------
Wed Jul 17 11:15:33 UTC 2024 - Jorik Cronenberg <[email protected]>

- Add dns search domains and ignore-auto-dns to network settings
(gh#openSUSE/agama#1330).

-------------------------------------------------------------------
Tue Jul 16 11:56:29 UTC 2024 - Josef Reidinger <[email protected]>

Expand Down