// ServeDNS implements the plugin.Handler interface.
ServeDNS implements the plugin.Handler interface.
// ServeDNS implements the plugin . Handler interface .
func (mn Meshname) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
	var remoteLookups = make(map[string][]dns.Question)
	a := new(dns.Msg)
	a.SetReply(r)
	a.Authoritative = true
	for _, q := range r.Question {
		labels := dns.SplitDomainName(q.Name)
		if len(labels) < 2 {
			continue
		}
		subDomain := labels[len(labels)-2]
		resolvedAddr, err := _meshname.IPFromDomain(&subDomain)
		if err != nil {
			continue
		}
		remoteLookups[resolvedAddr.String()] = append(remoteLookups[resolvedAddr.String()], q)
	}
	for remoteServer, questions := range remoteLookups {
		rm := new(dns.Msg)
		rm.RecursionDesired = true
		rm.Question = questions
		resp, _, err := mn.dnsClient.Exchange(rm, "["+remoteServer+"]:53") 
		if err != nil {
			continue
		}
		a.Answer = append(a.Answer, resp.Answer...)
		a.Ns = append(a.Ns, resp.Ns...)
		a.Extra = append(a.Extra, resp.Extra...)
	}
	w.WriteMsg(a)
	return 0, nil
}
func ( mn Meshname ) ServeDNS ( ctx context . Context , w dns . ResponseWriter , r * dns . Msg ) ( int , error ) { var remoteLookups = make ( map [ string ] [ ] dns . Question ) a := new ( dns . Msg ) a . SetReply ( r ) a . Authoritative = true for _ , q := range r . Question { labels := dns . SplitDomainName ( q . Name ) if len ( labels ) < 2 { continue } subDomain := labels [ len ( labels ) - 2 ] resolvedAddr , err := _meshname . IPFromDomain ( & subDomain ) if err != nil { continue } remoteLookups [ resolvedAddr . String ( ) ] = append ( remoteLookups [ resolvedAddr . String ( ) ] , q ) } for remoteServer , questions := range remoteLookups { rm := new ( dns . Msg ) rm . RecursionDesired = true rm . Question = questions resp , _ , err := mn . dnsClient . Exchange ( rm , " " + remoteServer + " " ) if err != nil { continue } a . Answer = append ( a . Answer , resp . Answer ... ) a . Ns = append ( a . Ns , resp . Ns ... ) a . Extra = append ( a . Extra , resp . Extra ... ) } w . WriteMsg ( a ) return 0 , nil }
ServeDNS implements the plugin.Handler interface.
ServeDNS implements the plugin . Handler interface .
// s.log.Debugln("Error: invalid domain requested") // s.log.Debugln(err) // no retries // s.log.Debugln(err) // s.log.Debugln(resp.String())