From e4bb883c608ceed482f9c1961c5197bc9fc64fca Mon Sep 17 00:00:00 2001 From: Yousong Zhou Date: Thu, 18 Oct 2018 15:37:38 +0000 Subject: [PATCH] region-dns: priority, weight for srv records --- pkg/dns/dns.go | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/pkg/dns/dns.go b/pkg/dns/dns.go index a2581e5d24..62fcb22f37 100644 --- a/pkg/dns/dns.go +++ b/pkg/dns/dns.go @@ -308,17 +308,35 @@ func (r *SRegionDNS) queryLocalDnsRecords(req *recordRequest) (recs []msg.Servic ttl = defaultTTL } if req.IsSRV() { - parts := strings.SplitN(ip.Addr, ":", 2) - if len(parts) != 2 { + parts := strings.SplitN(ip.Addr, ":", 4) + if len(parts) < 2 { ylog.Errorf("Invalid SRV records: %q", ip.Addr) - return + continue } - port, e := strconv.Atoi(parts[1]) - if e != nil { - ylog.Errorf("Invalid SRV records: %q", ip.Addr) - return + host := parts[0] + port, err := strconv.Atoi(parts[1]) + if err != nil { + ylog.Errorf("SRV: invalid port: %s", ip.Addr) + continue } - s = msg.Service{Host: parts[0], Port: port, TTL: ttl} + priority := 0 + weight := 100 + if len(parts) >= 3 { + var err error + weight, err = strconv.Atoi(parts[2]) + if err != nil { + ylog.Errorf("SRV: invalid weight: %s", ip.Addr) + continue + } + if len(parts) >= 4 { + priority, err = strconv.Atoi(parts[3]) + if err != nil { + ylog.Errorf("SRV: invalid priority: %s", ip.Addr) + continue + } + } + } + s = msg.Service{Host: host, Port: port, Weight: weight, Priority: priority, TTL: ttl} } else { s = msg.Service{Host: ip.Addr, TTL: ttl} }