Commit b1a92b9b authored by ale's avatar ale

Use library functions for low-level name mangling in the DNS module

parent dd0d0be0
Pipeline #5663 passed with stages
in 5 minutes
......@@ -13,7 +13,7 @@ import (
const (
zoneTTL = 21600
nsTTL = 3600
recordTTL = 5
recordTTL = 300
maxRecords = 5
)
......@@ -61,7 +61,7 @@ func newDNSZone(lb *loadBalancer, origin string, nameservers []string) *dnsZone
soa: soa,
nameservers: nameservers,
origin: origin,
originNumParts: len(strings.Split(origin, ".")),
originNumParts: dns.CountLabel(origin),
}
}
......@@ -70,8 +70,12 @@ func (d *dnsZone) ServeDNS(w dns.ResponseWriter, req *dns.Msg) {
ednsFromRequest(req, m)
// Only consider the first question.
var name string
q := req.Question[0]
name := d.getQuestionName(q)
if !dns.IsSubDomain(d.origin, q.Name) {
goto nxDomain
}
name = d.stripOrigin(q.Name)
switch {
case name == "" && q.Qtype == dns.TypeSOA:
......@@ -149,9 +153,9 @@ func (d *dnsZone) getNodeIPs(q dns.Question) []net.IP {
}
// Strip the origin from the query.
func (d *dnsZone) getQuestionName(q dns.Question) string {
lx := dns.SplitDomainName(q.Name)
ql := lx[0 : len(lx)-d.originNumParts]
func (d *dnsZone) stripOrigin(name string) string {
lx := dns.SplitDomainName(name)
ql := lx[:len(lx)-d.originNumParts]
return strings.ToLower(strings.Join(ql, "."))
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment