Skip to content

dnsdist: Warn on unsupported parameters #10115

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

Merged
merged 7 commits into from
Feb 8, 2023

Conversation

cmouse
Copy link
Contributor

@cmouse cmouse commented Feb 22, 2021

Short description

Change behavior of many commands to actually check the passed in vars / parameters that they are consumed fully. If they are not, we assume that they were not supported, and indicate first failing var / parameter.

Checklist

I have:

  • read the CONTRIBUTING.md document
  • compiled this code
  • tested this code
  • included documentation (including possible behaviour changes)
  • documented the code
  • added or modified regression test(s)
  • added or modified unit test(s)

@omoerbeek
Copy link
Member

This idea would be nice for the recursor as well. Some general thoughts:
The three lines

 if (vars->count("idleTimeout")) {
        frontend->d_idleTimeout = boost::get<int>((*vars)["idleTimeout"]);
        vars->erase("idleTimeout");
 }

are repeated over and over again.
I'd love to see a function in the line of

getOptionalValue<int>(frontend->d_idleTimeout , vars, "idleTimeout");

to avoid the repeating.
Also, the exceptions thrown mean that previously working config (with typos) now cause startup failure. That is likely too much, a warning would be better imo.

@rgacogne rgacogne added this to the dnsdist-1.7.0 milestone Mar 4, 2021
@cmouse cmouse force-pushed the dnsdist-params branch 4 times, most recently from a0f2735 to f9ee369 Compare March 8, 2021 21:14
@cmouse
Copy link
Contributor Author

cmouse commented Mar 8, 2021

Tested that it does indeed print warning

> pc = newPacketCache(100, {dontAget=true})
Unknown key 'dontAget' given - ignored

@cmouse cmouse force-pushed the dnsdist-params branch 2 times, most recently from 4d10b80 to ea1d2d3 Compare March 9, 2021 09:44
@cmouse cmouse force-pushed the dnsdist-params branch 4 times, most recently from 2705f81 to 8bc710d Compare March 24, 2021 08:53
@cmouse cmouse changed the title dnsdist: Fail on unsupported parameters dnsdist: Warn on unsupported parameters Mar 24, 2021
Copy link
Member

@rgacogne rgacogne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we often pass a copy of the variables, so we need to fix that at least. The general concept is awesome and the code looks good.

@cmouse cmouse force-pushed the dnsdist-params branch 2 times, most recently from fc8bf8c to 31e4642 Compare March 25, 2021 13:46
@cmouse cmouse requested a review from rgacogne May 3, 2021 09:30
@cmouse cmouse force-pushed the dnsdist-params branch from 364bfd7 to 3a21cb1 Compare May 3, 2021 09:30
Copy link
Member

@rgacogne rgacogne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love the general idea, and the implementation looks good! A few issues remain and I would not mind a rebase on the current master to ensure the checks are still valid, but other than that I'd like to merge it soon!


ComboAddress serverAddr;
std::string serverAddressStr;
if(auto addrStr = boost::get<string>(&pvars)) {
serverAddressStr = *addrStr;
if(qps) {
vars["qps"] = std::to_string(*qps);
(*vars)["qps"] = std::to_string(*qps);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does that work? I would expect that de-referencing an unset boost::optional would be a problem.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have to try.

getOptionalValue<bool>(vars, "mustResolve", ret->mustResolve);
getOptionalValue<bool>(vars, "useClientSubnet", ret->useECS);
getOptionalValue<bool>(vars, "useProxyProtocol", ret->useProxyProtocol);
getOptionalValue<bool>(vars, "disableZeroScoping", ret->disableZeroScope);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
getOptionalValue<bool>(vars, "disableZeroScoping", ret->disableZeroScope);
getOptionalValue<bool>(vars, "disableZeroScope", ret->disableZeroScope);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm. that would also change the parameter name no?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the name is currently disableZeroScope?

boost::algorithm::to_lower(frontend->d_provider);
}

getOptionalValue<std::string>(vars, "provider", frontend->d_provider);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the to_lower part gone?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so it seems.

@rgacogne rgacogne modified the milestones: dnsdist-1.7.0, dnsdist-1.8.0 Nov 2, 2021
@rgacogne rgacogne self-requested a review November 30, 2022 17:00
@rgacogne rgacogne self-assigned this Nov 30, 2022
@rgacogne
Copy link
Member

I'm in the process of (painfully, but that's on me) rebasing this pull request on master, just FYI.

@rgacogne
Copy link
Member

Rebased to fix conflicts.

@rgacogne rgacogne requested a review from chbruyand January 30, 2023 13:24
@rgacogne
Copy link
Member

Rebased on master, and ready to be merged. A second review would be nice to have to make sure I did not mess up :)

Copy link
Member

@chbruyand chbruyand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could unify a bit some integer values processing. Otherwise this lgtm and feels like a really good feature.

if (vars.count("checkTimeout")) {
config.checkTimeout = std::stoi(boost::get<string>(vars["checkTimeout"]));
if (getOptionalValue<std::string>(vars, "checkClass", valueStr) > 0) {
config.checkClass = std::stoi(valueStr);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As done a bit later, do we want to guard potential conversion exceptions for optional values ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm also wondering if there is a good reason to not directly getOptionalValue<int>(vars, "checkClass", config.checkClass)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm also wondering if there is a good reason to not directly getOptionalValue<int>(vars, "checkClass", config.checkClass)

Wouldn't that fail because the Lua wrapper used the string type for that variable? We could extend the variant to allow integers, but then we need to change all the existing types and make sure the conversion works properly. One drawback that I did not notice before with the new code is that if we pass a string when we expect an integer, it is no longer considered a parsing error and we don't even warn, except at the end to say something like newServer: Unknown key 'checkClass' given - ignored, which is confusing: the key exists, but the type is wrong.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pushed a new commit with better handling of numerical values, comments welcome!

As suggested by Charles-Henri Bruyand (thanks!).
@chbruyand chbruyand self-requested a review February 8, 2023 10:26
Copy link
Member

@chbruyand chbruyand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

@rgacogne rgacogne merged commit 597a91a into PowerDNS:master Feb 8, 2023
@cmouse cmouse deleted the dnsdist-params branch April 12, 2023 08:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants