Support domain names and port numbers in dns_nameservers#2376
Support domain names and port numbers in dns_nameservers#2376yadij wants to merge 6 commits intosquid-cache:masterfrom
Conversation
|
Old cache.log would show: new cache.log looks like: |
rousskov
left a comment
There was a problem hiding this comment.
I adjusted PR title to more prominently disclose that this PR adds domain name support and to mention the affected directive name for context.
I plan to come back to this PR once the backlog is dealt with.
There was a problem hiding this comment.
Before we make this code more complex, I recommend changing/fixing this code error handling so that configuration errors trigger an exception (and, hence, become fatal at startup). That change should be done in a dedicated prerequisite PR. It will affect how this code is structured and called/used.
There was a problem hiding this comment.
This setup should be done by the Dns::ConfigRr runner. However that refactoring project for startup runners is stuck awaiting reviewer on a number of prerequisites already.
For now this PR keeps the status-quo behaviour when receiving invalid configurations: log and ignore.
There was a problem hiding this comment.
Have done the Dns::ConfigRr changes in PR #2378. Order of merge does not matter for these two.
Have been experimenting today with what is needed to parse the dns_nameservers and validate immediately instead of just storing for later validation. I am not seeing any particular reason why that change cannot be done as a followup - there is only a few lines of overlap with this PR.
There was a problem hiding this comment.
Please add a test for multiple dns_nameservers parameters on the same directive line.
There was a problem hiding this comment.
Please adjust dns_nameservers description in cf.data.pre to avoid the current possible implication that port numbers are not supported and to disclose that domain names are supported (in addition to IP addresses).
It is probably a good idea to also note
- that domain names specified in
dns_nameserversare resolved without using (previously configured)dns_nameservers; - how repeated/duplicate
dns_nameserversdirective entries are interpreted; - how multiple
dns_nameserversdirectives are interpreted; and - what affect does the order of dns_nameservers` directive entries have.
Edit: GitHub hit this change request while I was writing my review, so I added another, similar one. I deleted the latter after I noticed that this change request was resurrected.
| try { | ||
| static const CharacterSet hostChars = CharacterSet("host", "._-") + CharacterSet::ALPHA + CharacterSet::DIGIT; | ||
| static const CharacterSet ip6Chars = CharacterSet("ip6", ":") + CharacterSet::HEXDIG; | ||
|
|
There was a problem hiding this comment.
Please do not add a yet another code snippet parsing host[:port].
There was a problem hiding this comment.
I have no choice at the moment, the other parsers we have a) do not check the requirements properly, or b) do not parse all the valid cases, or c) are hidden privately inside code that cannot be made a dependency of DNS startup.
The refactor project to update the AnyP::Uri interface for a generically useful parser are stuck awaiting reviewer.
| } | ||
|
|
||
| // Squid extension for servers with custom ports | ||
| int64_t foundPort = 0; |
There was a problem hiding this comment.
Please use std::optional<AnyP::KnownPort> instead of a magic number to handle unspecified ports.
There was a problem hiding this comment.
And how exactly do you propose we access the non-existent value inside this std::optional container in order to pass it to the tokenizer for initialization?
I see your approach in AnyP::Uri::parsePort() uses a temporary local with magic number rawPort = 0 as well in exactly this same way as here.
Upgrade the DNS nameserver configuration parser
to better validate IP/hostname labels.
Add support for IPv6 with brackets and optional
port values. These are not valid for /etc/resolv.conf
content, but may be used by admin in squid.conf
dns_nameservers and Windows registry settings.
Add support for named servers. OS resolver is used
to lookup the configured host name. Currently only
one IP address per host is supported.
Also, polish cache.log output to avoid false claims
of adding a nameserver which is then ignored.
Configuration errors are now displayed as "ERROR"
and each added entry has its origin name/label
logged on the same output line.