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

Wildcard domains as per RFC-4592 #1534

Open
cottand opened this issue Feb 3, 2024 · 10 comments
Open

Wildcard domains as per RFC-4592 #1534

cottand opened this issue Feb 3, 2024 · 10 comments

Comments

@cottand
Copy link

cottand commented Feb 3, 2024

Hi!

My understanding is this lib should support RFC-4592 (wildcard domains, as stated in the README). I am trying to use wildcard domains RRs with the following example:

// make a simple fake dns.ResponseWriter
type mockRw struct {
	stored *dns.Msg
}

func (m *mockRw) WriteMsg(msg *dns.Msg) error {
	m.stored = msg
	return nil
}

// returns a handler that returns TXT record
func ServerReplyTXT(txt string) dns.HandlerFunc {
	return func(w dns.ResponseWriter, req *dns.Msg) {
		m := new(dns.Msg)
		m.SetReply(req)

		m.Answer = make([]dns.RR, 1)
		m.Answer[0] = &dns.TXT{Hdr: dns.RR_Header{Name: m.Question[0].Name, Rrtype: dns.TypeTXT, Class: dns.ClassINET, Ttl: 0}, Txt: []string{txt}}
		_ = w.WriteMsg(m)
	}
}


func TestWildcardInLib(t *testing.T) {
	serveMux := dns.NewServeMux()

	serveMux.HandleFunc(".", ServerReplyTXT("root"))
	serveMux.HandleFunc("example.com.", ServerReplyTXT("example"))
	serveMux.HandleFunc("*.example.com.", ServerReplyTXT("wildcard"))

	rw := mockRw{stored: nil}

	msg := new(dns.Msg)
	msg.SetQuestion("banana.example.com", dns.TypeTXT)

	serveMux.ServeDNS(&rw, msg)
	println(rw.stored.Answer[0].String()) // prints: `example`, I expected `wildcard`

}

My understandig of RFC-4592 section 2.2.1 is that the above should print wildcard (because it matches *.example.com) but it prints example instead.

Did I misunderstand the RFC or perhaps am I using the library wrong? I did not find anything else mentioning 'wildcard' in the README and these tests do not seem to be testing matching wildcard domains.

Thanks in advance

@miekg
Copy link
Owner

miekg commented Feb 3, 2024 via email

@cottand
Copy link
Author

cottand commented Feb 3, 2024

Thanks for the quick reply

In that case, do you think it would be fair to either implement it, or remove RFC-4592 from the list of supported RFCs in the README?

Otherwise I would have expected it to work

@miekg
Copy link
Owner

miekg commented Feb 3, 2024 via email

@cottand
Copy link
Author

cottand commented Feb 4, 2024

Ok no worries, I will implement on my end, thank you.

In that case, would you mind clarifying how exactly is this library compliant with RFC-4592? Is there use of wildcards elsewhere?

@miekg
Copy link
Owner

miekg commented Feb 4, 2024

ha, i see we do do DS handling, probably wildcard handling should be done as well

@cottand
Copy link
Author

cottand commented Feb 5, 2024

that's good to hear!

@miekg
Copy link
Owner

miekg commented Feb 7, 2024 via email

@cottand
Copy link
Author

cottand commented Feb 7, 2024

If you point me to the file(s) in CoreDNS I can have a stab a it

@miekg
Copy link
Owner

miekg commented Feb 9, 2024 via email

@cottand
Copy link
Author

cottand commented Feb 12, 2024

See #1536 as step 1. I chose not to add CoreDNS' complexity to the simple match function until I fully understood the code there

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

No branches or pull requests

2 participants