Skip to content
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

add support for hyphen separated wildcard domains #246

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

marriva
Copy link

@marriva marriva commented Jul 22, 2022

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

@codecov-commenter
Copy link

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%) ⬇️
fastip/fastest.go 78.43% <0.00%> (-1.97%) ⬇️
proxy/server_udp.go 58.57% <0.00%> (+2.85%) ⬆️

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.

Copy link
Member

@ameshkov ameshkov left a comment

Choose a reason for hiding this comment

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

Hi, thank you for the contribution!

Could you please also add unit-tests for that?

Sample configurations for the test:

conf := []string{
		"0.0.0.1",
		"[/a.x/]0.0.0.2",
		"[/*-b.a.x/]0.0.0.3",
		"[/b.a.x/]0.0.0.4",
		"[/*-c.b.a.x/]0.0.0.5",
		"[/c.b.a.x/]#",
	}
conf := []string{
		"0.0.0.1",
		"[/a.x/]0.0.0.2",
		"[/*.a.x/]0.0.0.3",
		"[/*-b.a.x/]0.0.0.4",
		"[/b.a.x/]0.0.0.5",
	}
"[/*-a.b.c/]0.0.0.1", 
"[/*-.b.c/]0.0.0.2", 
"[/*.b-x.c/]0.0.0.3"

@EugeneOne1
Copy link
Member

EugeneOne1 commented Aug 4, 2022

@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?

Copy link

@Nuttapon-Makchoos Nuttapon-Makchoos left a comment

Choose a reason for hiding this comment

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

Copy link

@Nuttapon-Makchoos Nuttapon-Makchoos left a comment

Choose a reason for hiding this comment

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

Copy link

@Nuttapon-Makchoos Nuttapon-Makchoos left a comment

Choose a reason for hiding this comment

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants