From: Otto Moerbeek Date: Thu, 30 Oct 2025 12:57:50 +0000 (+0100) Subject: Tweaks and add a command to get default config parameter values X-Git-Tag: rec-5.4.0-alpha1~108^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5941446db2e6183ed309415629c4aefcde040e39;p=thirdparty%2Fpdns.git Tweaks and add a command to get default config parameter values Signed-off-by: Otto Moerbeek --- diff --git a/pdns/recursordist/docs/manpages/rec_control.1.rst b/pdns/recursordist/docs/manpages/rec_control.1.rst index fb0469d9ee..6750a0f22b 100644 --- a/pdns/recursordist/docs/manpages/rec_control.1.rst +++ b/pdns/recursordist/docs/manpages/rec_control.1.rst @@ -172,8 +172,15 @@ get-ntas get-tas Get a list of the currently configured Trust Anchors. -get-parameter *KEY* [*KEY*]... - Retrieves the specified configuration parameter(s). +get-parameter [*KEY*]... + Retrieves the configuration parameter(s). + If YAML configuration is active, *KEY* is of the form ``section[.name]`` + and no keys produces a full dump. + +get-default-parameter [*KEY*]... + Retrieves the default values of configuration parameter(s). + If YAML configuration is active, *KEY* is of the form ``section[.name]`` + and no keys produces a full dump. get-proxymapping-stats Get the list of proxy-mapped subnets and associated counters. diff --git a/pdns/recursordist/rec-rust-lib/cxxsupport.cc b/pdns/recursordist/rec-rust-lib/cxxsupport.cc index 0c7a7cb918..0bc466a55b 100644 --- a/pdns/recursordist/rec-rust-lib/cxxsupport.cc +++ b/pdns/recursordist/rec-rust-lib/cxxsupport.cc @@ -687,7 +687,7 @@ std::string pdns::settings::rec::defaultsToYaml(bool postProcess) for (const auto& entry : map) { vec.emplace_back(entry.second); } - const auto defs = std::string(pdns::rust::settings::rec::map_to_yaml_string(vec)); + auto defs = std::string(pdns::rust::settings::rec::map_to_yaml_string(vec)); if (!postProcess) { return defs; diff --git a/pdns/recursordist/rec-rust-lib/rust-bridge-in.rs b/pdns/recursordist/rec-rust-lib/rust-bridge-in.rs index 5851c748a7..af9c8778cc 100644 --- a/pdns/recursordist/rec-rust-lib/rust-bridge-in.rs +++ b/pdns/recursordist/rec-rust-lib/rust-bridge-in.rs @@ -403,7 +403,7 @@ extern "Rust" { // Prdoduce a YAML formatted string given a data structure known to Serde fn to_yaml_string(self: &Recursorsettings) -> Result; - fn get_value(self: &Recursorsettings, field: &[String], defaults: &str) -> Result; + fn get_value(self: &Recursorsettings, field: &[String], defaults: &str, with_comment: bool) -> Result; // When doing a conversion of old-style to YAML style we use a vector of OldStyle structs fn map_to_yaml_string(map: &Vec) -> Result; fn forward_zones_to_yaml_string(vec: &Vec) -> Result; diff --git a/pdns/recursordist/rec-rust-lib/rust/src/bridge.rs b/pdns/recursordist/rec-rust-lib/rust/src/bridge.rs index 3d4a3f1fc5..c6c94c68e1 100644 --- a/pdns/recursordist/rec-rust-lib/rust/src/bridge.rs +++ b/pdns/recursordist/rec-rust-lib/rust/src/bridge.rs @@ -1000,7 +1000,7 @@ impl Recursorsettings { serde_yaml::Value::Mapping(map) } - pub fn get_value(&self, field: &[String], defaults: &str) -> Result { + pub fn get_value(&self, field: &[String], defaults: &str, with_comment: bool) -> Result { let value = serde_yaml::to_value(self); let value = match value { Ok(value) => value, @@ -1018,9 +1018,14 @@ impl Recursorsettings { Ok(value) => { let map = Self::buildnestedmaps(field, &value); let res = serde_yaml::to_string(&map).unwrap(); - let name = field.join("."); - let msg = format!("# {}: not explicitly set, default value(s) listed below:\n{}", name, res); - Ok(msg) + if with_comment { + let name = field.join("."); + let msg = format!("# {}: not explicitly set, default value(s) listed below:\n{}", name, res); + Ok(msg) + } + else { + Ok(res) + } }, Err(x) => Err(x) } diff --git a/pdns/recursordist/rec_channel_rec.cc b/pdns/recursordist/rec_channel_rec.cc index 627be97794..b91d10d9d4 100644 --- a/pdns/recursordist/rec_channel_rec.cc +++ b/pdns/recursordist/rec_channel_rec.cc @@ -299,8 +299,8 @@ static Answer doGetParameter(ArgIterator begin, ArgIterator end) { std::stringstream ret; int err = 0; - if (!g_yamlSettings) { + if (!g_yamlSettings) { for (auto i = begin; i != end; ++i) { if (::arg().parmIsset(*i)) { const auto& parm = arg()[*i]; @@ -314,9 +314,50 @@ static Answer doGetParameter(ArgIterator begin, ArgIterator end) } else { auto settings = g_yamlStruct.lock(); - ret << "# YAML settings active" << endl; if (begin == end) { - auto yaml = settings->get_value({}, pdns::settings::rec::defaultsToYaml(false)); + auto yaml = settings->get_value({}, pdns::settings::rec::defaultsToYaml(false), true); + ret << std::string(yaml); + } + else { + for (auto i = begin; i != end; ++i) { + rust::Vec<::rust::String> field; + stringtok(field, *i, "."); + rust::Slice slice{field}; + try { + auto yaml = settings->get_value(slice, pdns::settings::rec::defaultsToYaml(false), true); + ret << std::string(yaml); + } + catch (const std::exception& stdex) { + ret << std::string(stdex.what()) << endl; + err = 1; + } + } + } + } + return {err, ret.str()}; +} + +static Answer doGetDefaultParameter(ArgIterator begin, ArgIterator end) +{ + std::stringstream ret; + int err = 0; + + if (!g_yamlSettings) { + for (auto i = begin; i != end; ++i) { + if (::arg().parmIsset(*i)) { + ret << *i << '=' << ::arg().getDefault(*i) << endl; + } + else { + ret << *i << " not known" << endl; + err = 1; + } + } + } + else { + auto settings = g_yamlStruct.lock(); + auto defaults = pdns::rust::settings::rec::parse_yaml_string(""); + if (begin == end) { + auto yaml = pdns::settings::rec::defaultsToYaml(false); ret << std::string(yaml); } else { @@ -325,7 +366,7 @@ static Answer doGetParameter(ArgIterator begin, ArgIterator end) stringtok(field, *i, "."); rust::Slice slice{field}; try { - auto yaml = settings->get_value(slice, pdns::settings::rec::defaultsToYaml(false)); + auto yaml = defaults.get_value(slice, pdns::settings::rec::defaultsToYaml(false), false); ret << std::string(yaml); } catch (const std::exception& stdex) { @@ -1963,7 +2004,8 @@ static RecursorControlChannel::Answer help(ArgIterator /* begin */, ArgIterator {"get-dont-throttle-netmasks", "Get the list of netmasks that are not allowed to be throttled"}, {"get-ntas", "Get all configured Negative Trust Anchors"}, {"get-tas", "Get all configured Trust Anchors"}, - {"get-parameter [key1] [key2] ..", "Get configuration parameters"}, + {"get-parameter [key1] ..", "Get configuration parameters"}, + {"get-default-parameter [key1] ..", "Get default configuration parameters"}, {"get-proxymapping-stats", "Get proxy mapping statistics"}, {"get-qtypelist", "Get QType statistics. Note queries from cache aren't being counted yet"}, {"get-remotelogger-stats", "Get remote logger statistics"}, @@ -2148,6 +2190,7 @@ RecursorControlChannel::Answer RecursorControlParser::getAnswer(int socket, cons {"get-all", getAllStats}, {"get", doGet}, {"get-parameter", doGetParameter}, + {"get-default-parameter", doGetDefaultParameter}, {"quit", [&](ArgIterator, ArgIterator) -> Answer { *command = doExit; return {0, "bye\n"}; }}, {"version", [&](ArgIterator, ArgIterator) -> Answer { return {0, getPDNSVersion() + "\n"}; }}, {"quit-nicely", [&](ArgIterator, ArgIterator) -> Answer { *command = doExitNicely; return {0, "bye nicely\n"}; }},