code: func (d *DNSServer) resolveCNAME(cfg *dnsConfig, name string, maxRecursionLevel int) []dns.RR {
  	// If the CNAME record points to a Consul address, resolve it internally
  	// Convert query to lowercase because DNS is case insensitive; d.domain is
  	// already converted
  
  	if strings.HasSuffix(strings.ToLower(name), "."+d.domain) {
  		if maxRecursionLevel < 1 {
  			d.logger.Printf("[ERR] dns: Infinite recursion detected for %s, won't perform any CNAME resolution.", name)
  			return nil
  		}
  		req := &dns.Msg{}
  		resp := &dns.Msg{}
  
  		req.SetQuestion(name, dns.TypeANY)
  		d.doDispatch("udp", nil, req, resp, maxRecursionLevel-1)
  
  		return resp.Answer
  	}
  
  	// Do nothing if we don't have a recursor
  	if len(cfg.Recursors) == 0 {
  		return nil
  	}
  
  	// Ask for any A records
  	m := new(dns.Msg)
  	m.SetQuestion(name, dns.TypeA)
  
  	// Make a DNS lookup request
  	c := &dns.Client{Net: "udp", Timeout: cfg.RecursorTimeout}
  	var r *dns.Msg
  	var rtt time.Duration
  	var err error
  	for _, recursor := range cfg.Recursors {
  		r, rtt, err = c.Exchange(m, recursor)
  		if err == nil {
  			d.logger.Printf("[DEBUG] dns: cname recurse RTT for %v (%v)", name, rtt)
  			return r.Answer
  		}
  		d.logger.Printf("[ERR] dns: cname recurse failed for %v: %v", name, err)
  	}
  	d.logger.Printf("[ERR] dns: all resolvers failed for %v", name)
  	return nil
  }
docs: // resolveCNAME is used to recursively resolve CNAME records