nm: Support dns-data
in NetworkManager 1.41
The NetworkManager 1.41 introduced `dns-data` and deprecating `dns` DBUS propriety. Without this patch, we will not able to purge DNS on NM 1.41 as we always merge unknown DNS propriety which in this case `dns-data`. The `dns-data` is effective if `dns` is not mentioned, hence we cannot purge DNS in NM 1.41+. We cannot simply set empty array in `dns` which take priority over `dns-data` when applying because IPv4 and IPv6 dns setting has different dbus signature which require at lease one dns server to determine. This patch only enable the querying support on `dns-data`, but still use old `dns` property when applying to achieve backwards compatibility, and drop `dns-data` when applying also. The integration test case `test_dns_edit_nameserver_with_static_gateway` reproduced the problem and could confirm the fix. Signed-off-by: Gris Ge <fge@redhat.com>
This commit is contained in:
parent
7a87f6315c
commit
89d2fb0b69
@ -1,17 +1,4 @@
|
||||
// Copyright 2021 Red Hat, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
use std::convert::TryFrom;
|
||||
use std::net::{Ipv4Addr, Ipv6Addr};
|
||||
@ -84,6 +71,12 @@ pub(crate) fn parse_nm_dns(
|
||||
Ok(dns_srvs)
|
||||
}
|
||||
|
||||
pub(crate) fn parse_nm_dns_data(
|
||||
value: zvariant::OwnedValue,
|
||||
) -> Result<Vec<String>, NmError> {
|
||||
Ok(Vec::<String>::try_from(value)?)
|
||||
}
|
||||
|
||||
pub(crate) fn parse_nm_dns_search(
|
||||
value: zvariant::OwnedValue,
|
||||
) -> Result<Vec<String>, NmError> {
|
||||
|
@ -1,17 +1,4 @@
|
||||
// Copyright 2021 Red Hat, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::convert::TryFrom;
|
||||
@ -23,7 +10,7 @@ use serde::Deserialize;
|
||||
use super::super::{
|
||||
connection::dns::{
|
||||
nm_ip_dns_search_to_value, nm_ip_dns_to_value, parse_nm_dns,
|
||||
parse_nm_dns_search,
|
||||
parse_nm_dns_data, parse_nm_dns_search,
|
||||
},
|
||||
connection::route::{
|
||||
nm_ip_routes_to_value, parse_nm_ip_route_data, NmIpRoute,
|
||||
@ -133,7 +120,6 @@ impl TryFrom<DbusDictionary> for NmSettingIp {
|
||||
.unwrap_or_default(),
|
||||
route_rules: _from_map!(v, "routing-rules", parse_nm_ip_rule_data)?
|
||||
.unwrap_or_default(),
|
||||
dns: _from_map!(v, "dns", parse_nm_dns)?,
|
||||
dns_search: _from_map!(v, "dns-search", parse_nm_dns_search)?,
|
||||
dns_priority: _from_map!(v, "dns-priority", i32::try_from)?,
|
||||
ignore_auto_dns: _from_map!(v, "ignore-auto-dns", bool::try_from)?,
|
||||
@ -155,6 +141,14 @@ impl TryFrom<DbusDictionary> for NmSettingIp {
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
if v.contains_key("dns-data") {
|
||||
setting.dns = _from_map!(v, "dns-data", parse_nm_dns_data)?;
|
||||
// NM 1.41 deprecated `dns` property in the favor of `dns-data`
|
||||
v.remove("dns");
|
||||
} else {
|
||||
setting.dns = _from_map!(v, "dns", parse_nm_dns)?;
|
||||
}
|
||||
|
||||
// NM deprecated `addresses` property in the favor of `addresss-data`
|
||||
v.remove("addresses");
|
||||
// NM deprecated `routes` property in the favor of `routes-data`
|
||||
@ -211,6 +205,10 @@ impl ToDbusValue for NmSettingIp {
|
||||
ret.insert("routing-rules", nm_ip_rules_to_value(&self.route_rules)?);
|
||||
if let Some(dns_servers) = self.dns.as_ref() {
|
||||
if !dns_servers.is_empty() {
|
||||
// We still use the `dns` instead of `dns-data` as the
|
||||
// `dns-data` is only supported by NM 1.41+ which is not widely
|
||||
// available yet. And we do not know the NM version yet in this
|
||||
// function context.
|
||||
ret.insert("dns", nm_ip_dns_to_value(dns_servers)?);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user