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

Fixed wild card name matching #174

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open

Conversation

qnt-dmitry
Copy link

I found the problem with wildcards and fixed it. Please merge it to the main stream.

@coveralls
Copy link

coveralls commented Aug 21, 2019

Coverage Status

Coverage decreased (-0.2%) to 90.377% when pulling 17f4513 on quantnet-golovin:master into 19069f5 on joohoi:master.

@echarlie
Copy link

echarlie commented Oct 23, 2019

Based on some quick testing (since I'd like this functionality, too), this only works for one level of wildcarded labels. e.g. *.my.host.tld. AAAA 2600::, I will get a response for label.my.host.tld., however will not get a response for another.label.my.host.tld.

I made a half-hearted attempt to solve this with this patch to your pr:

diff --cc dns.go
index 1a7e0e0,dcfda8d..0000000
--- a/dns.go
+++ b/dns.go
@@@ -130,8 -107,26 +130,33 @@@ func (d *DNSServer) readQuery(m *dns.Ms
                        m.Ns = append(m.Ns, d.SOA)
                }
        }
 -
  }
  
+ func (d *DNSServer) getRecordByDomainName(domainName string) (Records, bool) {
+       lowerName := strings.ToLower(domainName)
+       domain, ok := d.Domains[lowerName]
+       if ok {
+               return domain, ok
+       } else {
 -              split := strings.SplitAfterN(lowerName, ".", 2)
 -              split[0] = "*"
 -              wildName := strings.Join(split, ".")
 -              domain, ok := d.Domains[wildName]
 -              for i := 0; i < len(domain.Records); i++ {
++              split := strings.Split(lowerName, ".")
++              for j := 0; j < len(split); j++ {
++                      split[0] = "*"
++                      wildName := strings.Join(split, ".")
++                      domain, ok := d.Domains[wildName]
++                      for i := 0; i < len(domain.Records); i++ {
+                       domain.Records[i].Header().Name = lowerName
++                      }
++                      if ok {
++                              return domain, ok
++                      } else {
++                              newsplit := append(split[:0], split[1:]...)
++                              split = newsplit
++                      }
+               }
                return domain, ok
+       }
+ }
+ 
  func (d *DNSServer) getRecord(q dns.Question) ([]dns.RR, error) {
        var rr []dns.RR
        var cnames []dns.RR

@qnt-dmitry
Copy link
Author

@echarlie I added your changes.

@ckidow
Copy link

ckidow commented Jan 22, 2020

Looking Forward for a merge into master :-)

@tjhiggins
Copy link

+1

@kpd200081
Copy link

How about adding tests for this?

@joohoi
Copy link
Owner

joohoi commented Jan 11, 2021

Hi, sorry it took a while to get around to reviewing this. The PR looks good, but I'd really like to see test cases included.

@phoerious
Copy link

Giving this a small bump. Anyone working on tests?

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.

8 participants