dnsproxy icon indicating copy to clipboard operation
dnsproxy copied to clipboard

add support for hyphen separated wildcard domains

Open marriva opened this issue 2 years ago • 2 comments

Hello!

Please add support for wildcards separated by a hyphen as in dnsmasq. For example, *-dev.example.org and *-prod.example.org

I need to use different upstreams for something-dev.example.org and something-prod.example.org

marriva avatar Jul 22 '22 17:07 marriva

Codecov Report

Merging #246 (30823c5) into master (771d486) will increase coverage by 0.01%. The diff coverage is 75.00%.

@@            Coverage Diff             @@
##           master     #246      +/-   ##
==========================================
+ Coverage   70.21%   70.23%   +0.01%     
==========================================
  Files          39       39              
  Lines        2377     2392      +15     
==========================================
+ Hits         1669     1680      +11     
- Misses        509      512       +3     
- Partials      199      200       +1     
Impacted Files Coverage Δ
proxy/upstreams.go 87.50% <75.00%> (-3.23%) :arrow_down:
fastip/fastest.go 78.43% <0.00%> (-1.97%) :arrow_down:
proxy/server_udp.go 58.57% <0.00%> (+2.85%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 771d486...30823c5. Read the comment docs.

codecov-commenter avatar Jul 30 '22 14:07 codecov-commenter

@marriva, hello. The Dnsmasq's documentation states:

Matching of domains is normally done on complete labels, so /google.com/ matches google.com and www.google.com but NOT supergoogle.com. This can be overridden with a * at the start of a pattern only: /*google.com/ will match google.com and www.google.com AND supergoogle.com. The non-wildcard form has priority, so if /google.com/ and /*google.com/ are both specified then google.com and www.google.com will match /google.com/ and /google.com/ will only match supergoogle.com. For historical reasons, the pattern /.google.com/ is equivalent to /google.com/ if you wish to match any subdomain of google.com but NOT google.com itself, use /.google.com/

AFAIK, it doesn't apply any special handling for domains (and patterns) with hyphens. As per the man page, Dnsmasq supports the following wildcard pattern types:

  • domain.tld – matching both domain.tld and *.domain.tld (supported by dnsproxy);
  • *.domain.tld – matching only subdomains of domain.tld (supported by dnsproxy);
  • *domain.tld – matching domain.tld itself and any name having suffix of domain.tld.

Thus the PR seems a bit incomplete in terms of adding support for the last pattern type since it only handles the *-domain.tld case. If we'll accept this, it may be complicated to implement the rest of the logic afterwards so I believe it should be done at once.

@ameshkov, what do you think?

EugeneOne1 avatar Aug 04 '22 16:08 EugeneOne1